TITLE: If $f:X\to Y$ and $g:Y\to X$ are embeddings, show that $X=X_1\sqcup X_2,Y=Y_1\sqcup Y_2$ s.t. $f|X_1:X_1\cong Y_1, g|Y_2:Y_2\cong X_2$
QUESTION [6 upvotes]: I have to prove

If $f:X\to Y$ and $g:Y\to X$ are embeddings, show that there are $X_1,X_2,Y_1,Y_2$ s.t. $X=X_1\sqcup X_2,Y=Y_1\sqcup Y_2$ (where $\sqcup$ denotes a disjoint union of sets) and $f|X_1:X_1\cong Y_1, g|Y_2:Y_2\cong X_2$

My first confusion is that this really doesn't seem to be about topology, but just about set-theory. Regardless, here is my idea:
We must have 
$$f(X_1)=Y-Y_2$$
$$g(Y_2)=X-X_1$$
Now by solving this like a linear system we find
$$f(X_1)=Y-g^{-1}(X-X_1)=g^{-1}(X_1)$$
Which suggests to me the following construction: construct a set $X_1$ as follows:
$$X_1^0=X-g(Y)$$
$$X_1^{n+1}=X_1^n\bigcup g(f(X_1^n))$$
Now I'm don't know anything about transfinite recursion, which I believe is what we need to utilise here in order to conclude that this proces does in fact specify a set $X_1$.
Now we set $X_2=X-X_1$, $Y_1=f(X_1)$, $Y_2=Y-Y_1$. Now we only need to show that $f(X_1)=Y_1$ and $g(Y_2)=X_2$. The first one is true by definition and for the second one:
$x\in g(Y_2)$. Suppose $x\not\in X_2$, so $x\in X_1$. Then either $x\in X_1^0$, which is not possible since $x\in g(Y)$. Or $x\in X_1^n$ for $n>N$. However, then we can write $x=g(f(x'))$ for some $x'\in X_1^N\subset X_1$, so $x\in g(f(X_1))=g(Y_1)$, which is a contradiction, since $g$ is injective and $Y_2=Y-Y_1$.
$x\in X_2$. Suppose $g^{-1}(x)\not\in Y_2$, so $g^{-1}(x)\in Y_1=f(X_1)$. So then $x=g(f(x'))$ for some $x'\in X_1$. But then also $x\in X_1$ by construction of $X_1$, which is a contradiction.

I think this is kind of correct, but not completely. My main problem with it is that I'm not sure if $X_1$ is well defined.
I'm also a bit confused by the fact that this seems to just be a set-theory question, not at all a topology question. Is this true? I know that if $f:X\to f(X)\subset Y$ is a homeomorphism, then $f|A:A\to f(A)\subset Y$ is also a homeomorphism, so the fact that $f,g$ are homeomorphisms doesn't seem that relevant...
So any comment on the correctness of this proof would be much appreciated.

REPLY [2 votes]: Theorem (Cantor–Bernstein, also known as Cantor–Bernstein–Schöder). Let $X, Y$ be sets. If there exists $f: X \to Y$ injective and $g: Y \to X$ injective, then there exists a bijection between $X$ and $Y$.
There are various proofs of the theorem including your construction. But these proofs in fact prove more: the bijection is such that $X = X_1 \sqcup X_2$, $Y = Y_1 \sqcup Y_2$ and $f$ bijectively maps $X_1$ onto $Y_1$ and $g$ bijectively maps $Y_2$ onto $X_2$. That is your proposition without topology.
As you have observed, the topological part is easy: if $X, Y$ are also topological spaces and $f, g$ are embeddings, then the bijections between the parts are homeomorphisms.
So proving your proposition reduces to proving Cantor–Bernstein in one way or another, which is a standard thing.