From a KMP prefix table to a Z-array #
prefixWord assigns a representative index to each position, reading the prefix table from
left to right. A positive proper border forces its last letter to equal the last letter of the
corresponding prefix. A zero entry leaves the position free to introduce a fresh letter.
fromPrefix_computePrefix proves that the existing Z algorithm on this word recovers the Z-array
of every original word realizing the table. Representatives may distinguish equal original
letters. They preserve every match against the start of the word.
The abstract of Bland, Kucherov and Smyth describes conversion between
their prefix table (the Z-array here) and their border array (the KMP prefix table here).
We use zero-based arrays, including z[0] = n for a nonempty word. prefixTableEquiv pairs
the two executable conversions on tables realized over any fixed alphabet.
Conversion from the KMP table recovers the Z-array for every input word, including the empty word.
Z-tables and KMP prefix tables realizable over the same alphabet are in bijection. Both directions compute on the numeric table alone. A word witnessing realizability is used only to prove that the outputs belong to the stated ranges and that the conversions are inverse.