Exercise 2 on p. 7 of Notes on Logic by Roger Lyndon asks the reader to prove for the semigroup $E$ the following theorem:
$ef=gh$ implies either $e=gk$ and $h=kf$ for some $k$ or else $g=ek$ and $f=kh$ for some $k$.
I understand that because of the unique decomposition of a string and associativity it's possible, but cannot express in math symbols properly.
My approach
$ef=gh=z_1\dots z_n$ where $z_1,\dots z_n$- primes.
$gh=(z_1\dots z_k)(z_{k+1}\dots z_n)$
$ef=(z_1\dots z_k\dots z_l)(z_{l+1}\dots z_n)$
$ef=(z_1\dots z_k)(z_{k+1}\dots z_l)(z_{l+1}\dots z_n)=g(kf)=gh$
The semigroup $E$ is defined to be the set of all "expressions" from a set of symbols $S$, where an expression is a string of the form $s_1\dots s_n$ with $n\geq 0$ and each $s_i\in S$. The semigroup operation is concatenation.
Suppose $e,f,g,h\in E$ with $ef = gh$. Your approach is correct: write $ef = gh$ as $s_1\dots s_n$. Then there is some $\ell,m\leq n$ such that $e = s_1\dots s_\ell$, $f = s_{\ell+1}\dots s_n$, $g = s_1\dots s_m$, and $h = s_{m+1}\dots s_n$.
Case 1: $\ell\leq m$. Then letting $k = s_{\ell+1}\dots s_m$, we have $g = (s_1\dots s_\ell)(s_{\ell+1}\dots s_m) = ek$ and $f = (s_{\ell+1}\dots s_m)(s_{m+1}\dots s_n) = kh$.
Case 2: $m<\ell$. Then letting $k = s_{m+1}\dots s_\ell$, we have $e = (s_1\dots s_m)(s_{m+1}\dots s_\ell) = gk$ and $h = (s_{m+1}\dots s_\ell)(s_{\ell+1}\dots s_n) = kf$.