If $A$ and $B$ are nonempty sets, prove that $A \times B = B \times A$ if and only if $A = B$ 
If $A$ and $B$ are nonempty sets, prove that $A \times B = B \times A$ if and only if $A = B$.

Proving the first direction of this is easy. That is, if $A = B$ then it is obvious that $A^2 = A^2$. I am wondering how to prove the other direction now. Maybe proving it by contradiction will be easier than directly.
 A: Simple enough:
For each $a$ in $A$, choose a $b$ in $B$.  Then $(a,b)$ is in $A\times B$.  Since $A\times B = B\times A$ we have $(a,b)$ is in $B\times A$.  So $a$ is in $B$.
This shows that $A$ is a subset of $B$.  Interchanging $A$ with $B$, we also infer $B$ is a subset of $A$.  So $A=B$.
A: Suppose $A\neq B$
Case $1: A\subseteq B$, since $A\neq B$ we have $y\in B$ so that $y\not\in A$, take any $x\in A$. Then $(x,y)\in A\times B$. On the other hand $(x,y)\not\in B\times A$, since $y\not\in A$. This shows $A\times B \neq B\times A$.
Case $2: A\not \subseteq B$, then there is $x$ so that $x\in A$ but $x\not \in B$, take any $y\in B$. Then $(x,y)\in A\times B$, but $(x,y)\not\in B\times A$, since $x\not\in B$. This shows $A\times B \neq B\times A$,
A: Let $x\in A$ be arbitrary. Then there exists a $y\in B$ such that $(x,y)\in A\times B$. Since $A\times B = B\times A$, then $(x,y)\in B\times A$. This implies that $x\in B$. Hence $A\subseteq B$. Similarly, you can show that $B\subseteq A$.
So, since $A\subseteq B$ and $B\subseteq A$, it follows that $A=B$.
A: 
Theorem:$$(A \times B)=(B \times A) \leftrightarrow (A= \emptyset \vee B =\emptyset \vee A=B)$$
  Proof: $$"\to" \, \text{ by Contradiction}$$ Supppose that $\emptyset \neq A \neq B \neq \emptyset$, we have $$ A \nsubseteq B \vee B \nsubseteq A \to \exists x \in A:(x \notin B) \vee \exists s \in B:(s \notin A)  \to $$ $$ \to (x,y) \in (A \times B) \, [\text{with } y \in B\neq \emptyset] \, \vee \, (r,s) \in (A \times B) \,[\text{with } r \in A \neq \emptyset] \to$$ $$ \to (x,y) \in (B\times A) \, \vee \, (r,s) \in(B\times A)\,[\text{because} (A\times B)=(B \times A)] \to $$$$\to x \in B \, \vee \, s \in A \,\text{ (which contradicts our assumptions } x \notin B, s\notin A) $$
  $$"\leftarrow"$$
  Suppose $A=B$, we have $$(A \times B)=(A \times A)=(B\times B)=(B\times A)$$
  Suppose $A =\emptyset \vee B = \emptyset$, we have $$(A \times B)=\emptyset=(B \times A)$$

