Algorithm for fixed points of morphisms - visualization

Here you can find an interactive visualizer demonstrating how an algorithm works deciding whether a given word is a fixed point of a nontrivial morphism. (It replaces an older Java applet written by Vojtěch Matocha.)

The algorithm was published by Š. Holub here (see the paper for related references).

A more detailed complexity analysis (by Š. Holub and V. Matocha) is available here.

Tomasz Kociumaka, Jakub Radoszewski, Wojciech Rytter and Tomasz Wale� showed that the algorithm can be modified to run in linear time.

The algorithm constructs a morphism fixing the input word with the minimal number of non-erased letters.

Any feedback or bug report is welcome. Please write to

The problem

Given a word w, we want to construct a stabilizer of w, that is, a morphism f satisfying f(w)=w. Such a stabilizer always trivially exists, namely the identity. We are therefore interested in the question whether there is a nontrivial morphism fixing w.

An important fact is that we can (and will) limit ourselves to idempotent stabilizers, that is, morphisms satisfying

f(f(X))=f(X)
for each non-erased letter X. An idempotent stabilizer maps each letter X to a word in which X occurs exactly once.

In addition, we would like to construct the "least trivial" morphism fixing w, namely the morphism with minimal possible support (the set of non-erased letters). It turns out that such a minimal stabilizer is "almost" unique.

Ambiguity of the solution

The minimal stabilizer is ambivalent in two respects

Output panels

The visualizer yields a graphical representation of the algorithm (the canvas in the center) and three textual outputs. The input word may consist of up to 60 alphanumeric characters; press Enter or the RUN button to start. The buttons below the input field insert the examples described on this page.

The three textual outputs are the following:

  1. The Minimal Morphism panel (bottom left) shows the standard minimal stabilizer, which is defined by the following two rules, corresponding to the two above ambiguities:
    • the leftmost "twin" is used
    • left-expansion of a non-erased letter is preferred
    Erased letters are listed with the image ε (the empty word). The panel also displays a badge saying whether the word is (morphically) PRIMITIVE — the minimal stabilizer is the identity — or IMPRIMITIVE.
  2. The All Morphisms panel (bottom right), an "advanced" one, gives a representation of all possible minimal stabilizers.
    For the first example above, the panel yields:
    B, C ABACA
    showing that the word ABACA has two possible preimages.
    For the second above example the panel yields:
    B BP1     P1 ≤ AA
    D P1-1AAD
    E P1-1AAE
    C CP1
    The condition P1 ≤ AA says that the word P1 is a prefix of AA. It can therefore have three different values:
    P1=AA
    P1 is empty
    P1=A
    yielding the three possible minimal stabilizers above respectively.
    Note that the standard minimal stabilizer has P1 empty.
    Below the parametric representation, the panel offers a button for each possible choice of the prefix values (for the example above: P1=ε, P1=A, P1=AA). Clicking a button displays the corresponding concrete minimal stabilizer and updates the factorization shown in the graphics and in the FACT line of the log accordingly.
    To see a more complex example try the visualization with the word
    DHFFAGGBFFAGGBFFCGGEDHFFCGGBFFAGGBFFCGGE
  3. The Algorithm Log (left sidebar) records the run of the algorithm. The log consists of pairs of lines, each of them corresponding to several graphical steps described below. Clicking a log line moves the graphics to the corresponding step.
    The log then gives so called morphic factorization of the input word, corresponding to the discovered standard minimal stabilizer. This is simply the factorization into images of letters from the support. This factorization is shown also graphically (the last step of the visualization), in the log it is given by the FACT line with the list of cuts (that is, positions delimiting images of support letters).
Basic idea of the algorithm (construction rules)

The algorithm works by detecting obligatory left and right positions; and obligatory expanding letters, that is, letters that have to be in the support (cannot be erased).
Positions are borders between two consecutive letters (including the first position 0 and the last position whose number is the length of the word). Numbers of positions are shown in the visualization.
The terms left and right position are relative to a given stabilizer and describe whether a given position lies to the left or to the right from the support letter by which it is "produced".
For example, in the stabilizer B ABAA of the word ABAAABAA the positions 0,1,4,5 are left, and positions 2,3,4,6,7,8 are right. Note that the position 4 is both left and right due the fact that it is a cut (a border position between two images).

Another fundamental concept is the neighborhood of a letter. The neighborhood of a letter in the word w is the largest possible extension of the letter which is "compatible" with the word w, or, in other terms, the largest context of the letter in w. Clearly, the image of a letter by a stabilizer is limited by its neighborhood.

Obligatory left and right positions are now defined by the following rules for positions

  1. The first position and the last position are both left and right.
  2. The position just to the left of an expanding letter is a left position, and the position just to the right of an expanding letter is a right position.
  3. Left border of a neighborhood of an expanding letter is a right position, and right border of a neighborhood of an expanding letter is a left position (yes, it is crosswise in this case).
  4. Neighborhoods of different occurences of the same expanding letter are synchronized. That is, they have the same structure of left and right positions.
Obligatory left and right positions are marked in the visualization by blue dots (below the word) and green dots (above the word) respectively.

In order to define obligatory expanding letters, we need two more notions. A stretch factor is a factor between a left position and a right position. The weight of a letter is the number of its occurrences in w. We now have the following rules for expanding letters:

  1. Each stretch factor contains an expanding letter. The letter within a stretch factor that has minimum weight must be expanding. (NB: The weight is the number of ocurrences in the whole word w, not just in the stretch factor in question!)
  2. If more letters have the same minimum weight, then any of them can be chosen (standard choice is the leftmost one).
Steps of the visualization
The algorithm, and likewise the visualization, proceeds in rounds consisting of following steps, which are recorded in the Algorithm Log and visualized graphically (the current step is named in the status box next to the navigation buttons): Previous two steps are recorded in the log by a line of the following form:
SF (4,7) => new exp. char A
which says:
The factor between positions 4 and 7 is a stretch factor which does not contain any expanding letter. This forces A to become a new expanding letter because it is the (leftmost) letter in the stretch factor with minimum weight.
This is reported by a line like:
NBHD A = (2,5)
which means:
The neighborhood of A spans 2 letters to the left from A and 5 letters to the right from A (therefore it has length 8, A included).

The graphical steps can be browsed using the FIRST/PREV/NEXT/LAST buttons below the canvas, or with the arrow keys.

Note that the algorithm starts by marking the first and the last position as both left and right (rule 1), whence the first stretch factor leading to the choice of the first expanding letter is always the whole word.

The above mentioned paper by Tomasz Kociumaka, Jakub Radoszewski, Wojciech Rytter and Tomasz Wale� essentially shows that not all steps described here are necessary in order to obtain the resulting factorization.