I tried to prove the following:
Let $\mathbb N$ denote the positive natural numbers. Let $X_n = \{0,2\}$ with the discrete topology and let $X = \prod_{n \in \mathbb N} X_n$. Define a function $f:X \to [0,1]$ by setting $f(x) = \sum_{n=1}^\infty {x(n) \over 3^n}$. Prove that $f$ is injective and continuous. The image $f(X)$ is called the Cantor set and consists of all real numbers $a \in [0,1]$ which can be represented as triadic decimals $a = \sum_{n=1}^\infty {a_n \over 3^n}$ such that $a_n \in \{0,2\}$ for all $n$. Given $a \in f(X)$ define $g(a)(n) = a_n$ so that $g(a) \in X$. Prove that $g$ is a homeomorphism of $f(X)$ with $X$.
can you please read my proof and tell me if I made any mistakes? This is my proof:
To show $f$ is injective one shows that $x \neq y$ implies $f(x) \neq f(y)$. If $x \neq y$ then there is at least one $n$ such that $x(n) \neq y(n)$. Let $n$ be the smallest such $n$ and assume without loss of generality that $x(n) = 0 < 2 = y(n)$. If we denote $f(x) = X_{<n} + x(n) + X_{>n}$ and $f(y) = Y_{<n} + y(n) + Y_{>n}$ then since $Y_{<n}=X_{<n}$, $f(x)$ can only be equal to $f(y)$ if $X_{>n} = Y_{>n} + {2 \over 3^n}$, or equivalently, ${2 \over 3^n} = X_{>n} - Y_{>n}$. Since $X_{>n} - Y_{>n}$ is a sum of ${2 \over 3^k}$ for $k > n$, $f(x)=f(y)$ only if ${2 \over 3^n} = \sum_{k>n} {a_k \over 3^k}$ for $a_k \in \{0,2\}$. But as an easy computation shows, $$ \sum_{k = n+1}^\infty {a_k \over 3^k} \le \sum_{k = n+1}^\infty {2 \over 3^k} = {1 \over 3^n} < {2 \over 3^n}$$
For the next part: To show that $f$ is continuous it is enough to show that the inverse image of $(y-\delta, y+\delta) \cap [0,1]$ for $y,\delta$ arbitrary is open. Let $y \in [0,1] , \delta > 0$ be arbitrary. Note that $f^{-1} ( [0,1] \cap (y-\delta , y + \delta)) = f^{-1}([0,1]) \cap f^{-1}((y-\delta, y + \delta)) = f^{-1}((y-\delta, y + \delta)) $. Let $x$ be any point in $f^{-1}((y-\delta, y + \delta)) $ and let $n$ be such that ${2 \over 3^n } + |y- f(x)|< \delta $. Now let $O$ be the set consisting of the singleton sets $\{x(k)\}$ for the first $n$ components and of $\{0,2\}$ otherwise. Then $O$ is open and contains $x$. Also, $f(O) \subseteq (y-\delta, y + \delta)$ since for $x' \in O$, $|y - f(x')| \le |y-f(x)| + |f(x) - f(x')| < |y-f(x)| + {2 \over 3^n} < \delta$ hence $f$ is continuous.
The last part of the proof:
$g$ and $f$ are inverse functions so that they are bijective. It only remains to be shown that $f$ is open. To this end, let $O$ be an open set in $X$. Then it is enough to show that $f(O)$ is open when $O$ is equal to $\{0,2\}$ in all but finitely many components. Let $f(x) = y \in f(O)$ and let $n$ be the largest index such that $O_n \neq \{0,2\}$. Then for $\delta = {1 \over 3^n}$, $f(x) \in (f(x)-\delta, f(x) + \delta) \subset f(O)$.