MathOverflow will be down for maintenance for approximately 3 hours, starting Monday evening (06/24/2013) at approximately 9:00 PM Eastern time (UTC-4).

3 added 582 characters in body

Two finitely generated free semigroups of different ranks have different elementary theories. Indeed, the set of elements $x$ such that $\forall z,t \neg(x=zt)$ is exactly the set of generators of the free semigroup. So the rank of a finitely generated free semigroup is elementary definable.

For the free Abelian group of rank $n$ the formula distinguishing it from any free Abelian group of rank $\gt n$ is this:

$$\exists x_1,...,x_{2^n} \forall y \exists z: yx_1=z^2 \vee yx_2=z^2 \vee ... \vee yx_{2^n}=z^2$$ (we enumerate the subsets of the set of generators and for the subset number $i$ we denote the product of generators from that subset by $x_i$). It is easy to see that this formula holds in every free Abelian group of rank $\le n$ and does not hold if the rank is $\gt n$. For $n=1$ this is the same formula as in the answer of Henry Wilton.

The standard reference for elementary classification of Abelian groups is Szmielew, W. Elementary properties of Abelian groups. Fund. Math. 41 (1955), 203–271. A shorter proof can be found in Kargapolov, M. I. On the elementary theory of Abelian groups. Algebra i Logika Sem. 1 1962/1963 no. 6, 26–36 and Eklof, Paul C.; Fischer, Edward R. The elementary theory of abelian groups. Ann. Math. Logic 4 (1972), 115–171 and Zakon, Elias Model-completeness and elementary properties of torsion free abelian groups. Canad. J. Math. 26 (1974), 829–840 (for torsion-free groups).

Two finitely generated free semigroups of different ranks have different elementary theories. Indeed, the set of elements $x$ such that $\forall z,t \neg(x=zt)$ is exactly the set of generators of the free semigroup. So the rank of a finitely generated free semigroup is elementary definable.
For the free Abelian group of rank $n$ the formula distinguishing it from any free Abelian group of rank $\gt n$ is this:
$$\exists x_1,...,x_{2^n} \forall y \exists z: yx_1=z^2 \vee yx_2=z^2 \vee ... \vee yx_{2^n}=z^2$$ (we enumerate the subsets of the set of generators and for the subset number $i$ we denote the product of generators from that subset by $x_i$). It is easy to see that this formula holds in every free Abelian group of rank $\le n$ and does not hold if the rank is $\gt n$. For $n=1$ this is the same formula as in the answer of Henry Wilton.
Two finitely generated free semigroups of different ranks have different elementary theories. Indeed, the set of elements $x$ such that $\forall z,t \neg(x=zt)$ is exactly the set of generators of the free semigroup. So the rank of a finitely generated free semigroup is elementary definable.