Prove that a and b commute if and only if they are powers of the same word Two words $a$ and $b$ commute if $ab=ba$. 

How to demonstrate that $a$ and $b$ commute if and only if they are powers of 
the same word ?

$ab=ba \Leftrightarrow \exists \space  \tau  \in \Sigma^{*} \mid a=\tau^{k} and \space b=\tau^{k'}$

The demonstration in this direction is trivial: 

$\space \exists \space  \tau  \in \Sigma^{*} \mid a=\tau^{k} and \space b=\tau^{k'} \Rightarrow ab=ba$

But I don't manage to find an elegant solution for the other direction.
If $ab=ba$ then the word $w = ab$ satisfies $R^{|a|}(w) = w$, where $R$ is the right-rotation operator, and $R^{|a|}$ just applies this operator $a$ times. Since $R^{|w|}(w) = w$, Bezout's identity implies that $R^{(|a|,|w|)}(w) = w$, where $g = (|a|,|w|)$ is the greatest common divisor of $|a|$ and $|w|$. Since $g \mid |w|$, we see that $w = z^{|w|/g}$ for some word $z$ of length $g$. Since $g \mid |a|$, we see that $a = z^{|a|/g}$ and $b = z^{|b|/g}$.