A code χ is not primitivity preserving if there is a primitive list ws ε lists χ whose concatenation is imprimitive. We formalize a full characterization of such codes in the binary case in the proof assistant Isabelle/HOL. Part of the formalization, interesting on its own, is a description of {x,y}- interpretations of the square xx if lenght y <= lenght x. We also provide a formalized parametric solution of the related equation x(j) y(k) = z(l).
The core of the theory is an investigation of imprimitive words which are concatenations of copies of two noncommuting words (such a pair of words is called a binary code). We follow the article [Barbin-Le Rest, Le Rest, 85] (mainly Théorème 2.1 and Lemme 3.1), while substantially optimizing the proof. See also [J.-C. Spehner. Quelques problèmes d'extension, de conjugaison et de présentation des sous-monoïdes d'un monoïde libre. PhD thesis, Université Paris VII, 1976] for an earlier result on this question, and [Maňuch, 01] for another proof.