Prove that if $xy=yz$ then $ \exists u,v \in A^*$ and $\exists p \in \mathbb{N} $ such that $x=uv$, $z=vu$ and $y=(uv)^pu$. $A^*$ is the set of all words that can be formed over the alphabet $A$. By $xy$, I mean the concatenation between the word $x$ and word $y$. $x, y, z \in A^*$.
I have tried to do this, but my proof looks informal. There are 3 cases:
Case 1: $|x| < |y|$ (length of $x$ is smaller than the length of $y$). In this case $x=uv$ and $z=vu$ and $p=1$, so $y=(uv)^1u=uvu$. So, the statement is true for the case 1.
Case 2: $|x| = |y|$. In this case we can take $u=\lambda$ (the empty word) and $u=v$, $z=v$ and $y=(\lambda v)^p \lambda=v^p$. For $p=1$ the statement holds.
Case 3: $|x| > |y|$. Here I can apply the same reasoning as I did in the previous case, for $p>1$. And the statement also holds.
What is the right way to do this proof?
There is a largest $p\in\Bbb N$ such that $y=x^pu$ for some $u\in A^*$. (This $p$ could of course be $0$.) Then $$x^{p+1}u=xy=yz=x^puz\;,$$ so $xu=uz$. The maximality of $p$ ensures that $x$ is not an initial segment of $u$, so $u$ must be an initial segment of $x$, and therefore $x=uv$ for some $v\in A^*$. Then $ux=xu=uvu$, so $z=vu$, and $y=x^pu=(uv)^pu$.