The fewest fragments of an avoidable four-letter formula
Result page Proof blueprint → Paper PDF Verification archive
An endless 0-1 string avoids a formula such as ABA.BAB.ACA when no choice of blocks for the letters puts every fragment in it. Given that five formulas cannot be avoided, Lean proves the same for every four-letter formula with every fragment shaped XYX, never XXX, and at most 8 fragments.
If none of the formulas of M₁ to M₅ is 2-avoidable, then for every arc mask with at most 8 arrows the formula of its diagram is not 2-avoidable; and with no assumption, the diagrams on 4 vertices with at least one arrow fall into exactly 217 classes, every arc mask holds one of S₁, G₂ to G₆ and S₁₀ or fits inside one of M₁ to M₅, and every class with at most 8 arrows holds none of those seven.
Ochem and Rosenfeld (2021) proved that the xyx-formula with all 12 fragments on four letters is 2-avoidable, their Theorem 23, and listed among things attempted without success to "Improve Theorem 23 by showing that some xyx-formula on 4 variables and fewer fragments is 2-avoidable." The site's answer is that 9 fragments suffice and 8 do not. The Lean traced here checks the counting half of "8 do not", and the step from five outside searches to the whole of it.
9 fragments suffice and 8 do not, for four-variable xyx-formulas with no fragment XXX
Walkthrough: 3 of 7 main results in Lean; in the Lean traced here, 1 more lacks its arc counts, 1 takes the searches as a hypothesis and 2 are outside it
Ochem and Rosenfeld’s Lemma 18 is proved again in Lean, and their reading of a formula as a digraph is the Lean definition. The descent method and Narayana’s word are used here only by programs outside the Lean traced here, which defines Narayana’s word and its two binary images but proves nothing about what they avoid.
Published inputs
- Ochem & Rosenfeld (2021, Section 5 and Lemma 18) (Re-proved in Lean): Wrote each fragment XYX as an arc X → Y of a digraph, and proved that a map keeping arcs carries occurrences back, so adding arcs keeps a formula 2-avoidable.
- Ochem & Rosenfeld (2021, Theorem 23) (Assumed outside Lean): Cassaigne’s descent method, as they used it for their Theorem 23; every descent prover here applies that one method.
- Shallit (2025) & OEIS Foundation Inc. (Assumed outside Lean): Narayana’s word, the fixed point of 0 ↦ 01, 1 ↦ 2, 2 ↦ 0, whose two binary images α(nar) and γ(nar) serve here as extra witness words.
What this paper adds
- Census, dichotomy & descent soundness (no assumption): 217 classes of digraphs; Seven below or five above; At most 8 arcs; Soundness of two-move descent
- Eight fragments are too few (Theorem 1): From five searches to every 8-arc digraph
- Computer searches outside the Lean traced here (Theorem 2, Proposition 7): Five exhaustive trees for M₁ to M₅; Descent proofs that 9 fragments suffice
9 fragments suffice and 8 do not (no fragment XXX; both halves rest here on searches outside the Lean traced)
Read as asking about formulas with no fragment XXX, the fewest fragments of a 2-avoidable xyx-formula on 4 variables (one that some endless 0-1 string avoids) is 9. The fixed point of a binary morphism σ avoids ABA.BAB.ACA.CAC.BCB.CBC.ADA.BDB.CDC, and every such formula with at most 8 fragments occurs in every binary word of 165 letters.
Of the 7 main results, the Lean traced here proves 3 with no assumption (Lemmas 3, 5 and 6: the 217 classes, the at-most-8-arc reduction and descent soundness). Lemma 4, the seven-or-five dichotomy, is in Lean except its parenthesis that each of the seven digraphs has 9 or 10 arcs: Lean proves that every class holding one of the seven has at least 9 arcs, but no Lean theorem traced here states the arc counts of the seven. Theorem 1 is Lean + certificate: Lean proves it assuming none of M₁ to M₅ is 2-avoidable, which the searches of Proposition 7 supply. Theorem 2 (9 suffice, by descent provers) and Proposition 7 (the five searches) are outside the Lean traced here. In the Lean traced here neither half of the theorem is proved without a hypothesis.
Listed as open in the paper
- A proof of Theorem 2 by hand or by a method other than descent.
- The fewest fragments among connected digraphs on 5 vertices, at most 10 by the transitive tournament TT₅.
Adjacent prior work (not used as inputs)
- Ochem & Rosenfeld (2021, Theorems 19 and 23, Section 7): Proved that the 12-fragment formula of the complete digraph on 4 vertices is 2-avoidable (Theorem 23) and that ABA.BAB.ACA.CBC is not (Theorem 19), and listed among problems attempted without success finding a 2-avoidable xyx-formula on 4 variables with fewer fragments.
- Ochem & Rosenfeld (2017) (not fully read); Gamard, Ochem, Richomme & Séébold (2018) (not fully read); Currie, Mol & Rampersad (2018) (not fully read): Related families of formulas, on two variables, circular formulas, and avoidance bases with reversal; their full texts were not read.
Nine fragments as nine arrows
Write each fragment XYX as an arrow X → Y. The nine-fragment formula ABA.BAB.ACA.CAC.BCB.CBC.ADA.BDB.CDC has the arrows 01, 02, 03, 10, 12, 13, 20, 21, 23 when A, B, C, D are 0, 1, 2, 3, the leading nine of the 12 positions, so its arc mask is 2⁹ − 1 = 511: this is S₁. To see an occurrence, take a different nine-fragment formula, ABA.ACA.ADA.BAB.BCB.CAC.CDC.DAD.DBD, which is the diagram G₅, and the string 01101001101101, with A = 1, B = 0, C = 10, D = 01. Then ABA = 101 is letters 3 to 5, CDC = 100110 is letters 5 to 10 and DBD = 01001 is letters 4 to 8; the other six fragments are in it too.
Diagrams, formulas and avoiding
Each arrow X → Y of a diagram stands for the fragment XYX, so an xyx-formula on four letters is a diagram on 4 vertices with no arrow from a vertex to itself. A string contains the formula when some non-empty block for each vertex puts every fragment in it as a factor, and the formula is 2-avoidable when some endless 0-1 string contains no occurrence. If a diagram can be relabelled into a larger one, avoiding the smaller formula avoids the larger, so adding arrows keeps a formula 2-avoidable.
2-avoidability passes to a larger diagram
If H can be relabelled into G and H is 2-avoidable, then so is G.
theorem XYXAvoid.avoidable2_of_emb {V₁ : Type u_1} {V₂ : Type u_2} {H : LooplessDigraph V₁} {G : LooplessDigraph V₂} (e : DigraphEmb H G) (hH : Avoidable2 H) : Avoidable2 G- Relabelling H so that every arrow of H is an arrow of G
- Same diagram up to relabelling
- A relabelling is an arrow-keeping map
- Arrow-keeping maps compose
- A same-diagram matching keeps arrows
- A same-diagram matching can be reversed
- A factor of a string
- A factor of an endless string
- The start of an endless string
- Arrow diagram
- Arrow-keeping map
- Occurrence of a formula in a string
- Occurrence of a formula in an endless string
- A string avoids a formula
- An endless string avoids a formula
- 2-avoidable
A string that avoids H avoids G when H maps into G
If there is an arrow-keeping map from H to G and W avoids the formula of H, then W avoids the formula of G.
theorem XYXAvoid.avoidsInf_of_hom {V₁ : Type u_1} {V₂ : Type u_2} {α : Type u_3} {H : LooplessDigraph V₁} {G : LooplessDigraph V₂} (φ : DigraphHom H G) {W : ℕ → α} (hav : AvoidsDigraphInf H W) : AvoidsDigraphInf G W2-avoidability passes along an arrow-keeping map
If there is an arrow-keeping map from H to G and the formula of H is 2-avoidable, then so is the formula of G.
theorem XYXAvoid.avoidable2_of_hom {V₁ : Type u_1} {V₂ : Type u_2} {H : LooplessDigraph V₁} {G : LooplessDigraph V₂} (φ : DigraphHom H G) (hH : Avoidable2 H) : Avoidable2 G
Diagrams as 12-digit numbers
A diagram on the vertices 0 to 3 has 12 possible arrows, so Lean records it as an arc mask, a number from 0 to 4,095 whose binary digits say which arrows are present. Every diagram on 4 vertices is the diagram of a mask up to relabelling, and each of the 24 relabellings of the vertices acts on masks by moving digits with their arrows.
Every diagram on 4 vertices has a mask
Every arrow diagram on 4 vertices is, up to relabelling, the diagram of some arc mask.
theorem XYXAvoid.exists_mask_iso (G : LooplessDigraph (Fin 4)) : ∃ m, Nonempty (DigraphIso (maskToDigraph m) G)
- Arc mask
- Powers of 2 up to 2¹¹
- Arrow i is present
- Packing 12 yes-or-no answers
- Packing the low digits
- The arrow at position i
- The position of an arrow
- The diagram of a mask
- The mask of a diagram
- Number of arrows
- Sending 0, 1, 2, 3 to any vertices a, b, c, d
- The 24 relabellings
- The reverse relabelling
- Relabelling k as a matching
- Where relabelling moves an arrow
- Where the reverse relabelling moves an arrow
- Relabelling a mask
- Relabelling a mask, as an arc mask
The reverse relabelling restores a mask
Relabelling a mask by k and then by its reverse gives the mask back.
theorem XYXAvoid.permMask_inv (k : Fin 24) (m : Mask4) : permMask (perm4InvIdx k) (permMask k m) = m
There are 217 classes with an arrow
The canonical mask of a mask is the smallest of its 24 relabellings, and Lean lists 218 canonical masks. Their classes share no mask, and Lean evaluates that their sizes add up to 4,096, so every mask is a relabelling of exactly one of them. Leaving out the empty diagram, there are 217 classes with at least one arrow.
There are 217 classes with at least one arrow
Up to relabelling, there are exactly 217 arrow diagrams on 4 vertices with at least one arrow.
theorem XYXAvoid.card_classes_4 : nonemptyClasses4.card = 217
- The smallest relabelling
- Canonical mask
Some relabelling gives the canonical mask
Some relabelling of m equals its canonical mask.
theorem XYXAvoid.exists_permMask_eq_canon4 (m : Mask4) : ∃ k, permMask k m = canon4 m
Relabelling does not change the canonical mask
A mask and any relabelling of it have the same canonical mask.
theorem XYXAvoid.canon4_permMask (k : Fin 24) (m : Mask4) : canon4 (permMask k m) = canon4 m
- The 218 canonical masks
- Removing repeated numbers
- Fast relabelling
- All relabellings of a mask
- The set of relabellings
The 218 classes hold 4,096 masks in all
The numbers of different relabellings of the 218 listed masks add up to 4,096.
theorem XYXAvoid.canon218Nat_orbit_sum : (List.map (fun c => (orbitListNat c).length) canon218Nat).sum = 4096
- The 218 canonical masks, as arc masks
- The set of the 218 canonical masks
The set of canonical masks has 218 members
The set made from the list has 218 members.
theorem XYXAvoid.canon218Finset_card : canon218Finset.card = 218
A listed mask is its own canonical mask
For each listed mask, the canonical mask is the mask itself.
theorem XYXAvoid.canon4_eq_self_of_mem_canon218 {c : Mask4} (hc : c ∈ canon218Finset) : canon4 c = cDifferent listed masks have no relabelling in common
Two different listed masks share no relabelling.
theorem XYXAvoid.orbitFinset_disjoint {c₁ : Mask4} {c₂ : Mask4} (hc₁ : c₁ ∈ canon218Finset) (hc₂ : c₂ ∈ canon218Finset) (hne : c₁ ≠ c₂) : Disjoint (orbitFinset c₁) (orbitFinset c₂)Every mask is a relabelling of a listed one
The relabellings of the 218 listed masks are all 4,096 masks.
theorem XYXAvoid.biUnion_orbitFinset_eq_univ : canon218Finset.biUnion orbitFinset = Finset.univ
Every canonical mask is listed
The canonical mask of any mask is one of the 218.
theorem XYXAvoid.canon4_mem_canon218 (m : Mask4) : canon4 m ∈ canon218Finset
The canonical masks are exactly the 218
The canonical masks of all 4,096 masks form exactly the listed set.
theorem XYXAvoid.image_canon4_eq_canon218 : Finset.image canon4 Finset.univ = canon218Finset
- All diagrams on 4 vertices, up to relabelling
- All diagrams with an arrow, up to relabelling
Every diagram holds one of 7 or fits inside one of 5
Lean names seven diagrams, S₁, G₂ to G₆ and S₁₀, and five, M₁ to M₅, and checks that none of the seven fits inside any of the five. For each of the 217 classes a listed witness shows that one of the seven fits inside it, for 12 classes, or that it fits inside one of the five, for 205. Every class among the 12 has at least 9 arrows, so every class with at most 8 arrows holds none of the seven.
Every mask holds one of the 7 or fits inside one of the 5
Every one of the 4,096 masks either holds one of S₁, G₂ to G₆ and S₁₀ after relabelling, or fits inside one of M₁ to M₅ after relabelling.
theorem XYXAvoid.mask4_dichotomy (m : Mask4) : isAboveMin7 m ∨ isBelowMax5 m
- Strictly increasing list
- A one-pass check that one list is two others merged
- Every arrow of one mask is in the other
- Fast arrow inclusion
- One diagram fits inside another
- Checking that one diagram fits inside another
- Fitting inside can be decided
Fitting inside is transitive
If m₁ fits inside m₂ and m₂ inside m₃, then m₁ fits inside m₃.
theorem XYXAvoid.embedsMask_trans {m₁ : Mask4} {m₂ : Mask4} {m₃ : Mask4} (h12 : embedsMask m₁ m₂) (h23 : embedsMask m₂ m₃) : embedsMask m₁ m₃Relabelling the smaller diagram keeps fitting
If a relabelling of m₁ fits inside m₂, so does m₁.
theorem XYXAvoid.embedsMask_of_perm_left {m₁ : Mask4} {m₂ : Mask4} (k : Fin 24) (h : embedsMask (permMask k m₁) m₂) : embedsMask m₁ m₂Relabelling the larger diagram keeps fitting
If m₁ fits inside a relabelling of m₂, it fits inside m₂.
theorem XYXAvoid.embedsMask_of_perm_right {m₁ : Mask4} {m₂ : Mask4} (k : Fin 24) (h : embedsMask m₁ (permMask k m₂)) : embedsMask m₁ m₂Fitting inside is relabelling into
A mask fits inside another exactly when its diagram can be relabelled into the other's diagram.
theorem XYXAvoid.embedsMask_iff_nonempty_emb (m₁ : Mask4) (m₂ : Mask4) : embedsMask m₁ m₂ ↔ Nonempty (DigraphEmb (maskToDigraph m₁) (maskToDigraph m₂))
- The diagram S₁
- The diagram G₂
- The diagram G₃
- The diagram G₄
- The diagram G₅
- The diagram G₆
- The diagram S₁₀
- The diagram M₁
- The diagram M₂
- The diagram M₃
- The diagram M₄
- The diagram M₅
- The 7 diagrams S₁, G₂ to G₆ and S₁₀
- The 5 diagrams M₁ to M₅
- The 5 diagrams M₁ to M₅, as diagrams
None of the 7 fits inside any of M₁ to M₅
No diagram of S₁, G₂ to G₆ and S₁₀ fits inside any of M₁ to M₅.
theorem XYXAvoid.no_min7_embeds_max5 (i : Fin 7) (j : Fin 5) : ¬embedsMask (min7Masks i) (max5Masks j)
- Witnesses for 12 classes
- Witnesses for 205 classes
The 12 witnesses check out
For each of the 12 witnesses, the named diagram, relabelled, has all its arrows in the mask; Lean evaluates it.
theorem XYXAvoid.avoidWits12_valid : (avoidWits12.all fun x => match x with | (c, mi, pi) => subMaskFast (permMaskFast ↑pi ↑(min7Masks mi)) c) = trueThe 205 witnesses check out
For each of the 205 witnesses, the mask, relabelled, has all its arrows in the named one of M₁ to M₅.
- The 12 witness masks, each holding one of the 7
- The 205 witness masks, each fitting inside one of the 5
Every canonical mask other than 0 is among the 12 or the 205
Each of the 217 canonical masks other than 0 is in the list of 12 or the list of 205.
- Holds one of the 7 diagrams S₁, G₂ to G₆ and S₁₀
- Fits inside one of M₁ to M₅
- Holding one of the 7 can be decided
Each of the 12 holds one of the 7
Each of the 12 masks holds one of S₁, G₂ to G₆ and S₁₀.
Each of the 205 fits inside one of the 5
Each of the 205 masks fits inside one of M₁ to M₅.
- Classes holding one of the 7
- Classes holding none of the 7
A class holding one of the 7 has at least 9 arrows
Each of the 12 classes that hold one of S₁, G₂ to G₆ and S₁₀ has at least 9 arrows.
A class with at most 8 arrows holds none of the 7
Every class other than 0 with at most 8 arrows holds none of S₁, G₂ to G₆ and S₁₀.
theorem XYXAvoid.all_le8_arcs_unavoidable {c : Mask4} (hc : c ∈ nonemptyClasses4) (h8 : arcCount ↑c ≤ 8) : c ∈ unavoidableClasses4
Eight fragments are too few, given M₁ to M₅
The Lean traced here takes as an assumption that none of the formulas of M₁ to M₅ is 2-avoidable, which five exhaustive searches outside it support. A mask with at most 8 arrows cannot hold one of the seven, since relabelling keeps the number of arrows, so it fits inside one of M₁ to M₅. Its formula would then be 2-avoidable only if that larger one were, so it is not.
If M₁ to M₅ are not 2-avoidable, no 4-vertex diagram with at most 8 arrows is
Suppose none of the formulas of M₁ to M₅ is 2-avoidable. Then for every mask with at most 8 arrows, the formula of its diagram is not 2-avoidable.
theorem XYXAvoid.r10_2_1_le8_unavoidable (h_max5 : ∀ (j : Fin 5), ¬Avoidable2 (max5Graph j)) (m : Mask4) (h8 : arcCount ↑m ≤ 8) : ¬Avoidable2 (maskToDigraph m)
Why a closed list of states rules out an occurrence
The other half, that a nine-fragment formula is 2-avoidable, is outside the Lean traced here. It is shown by descent, which keeps a list of states, each a system of demands an occurrence must meet, with a count such as the number of blocks not yet fixed. The Lean traced here proves the logical form of such a proof: if every occurrence would satisfy the starting state at its total block length, and every satisfied state of the list leads to one with a lower count, or with the same count and a smaller size, then there is no occurrence. It does not read the lists themselves.
A closed list of states in which the count falls, or stays the same while the size falls, proves avoidance
Give each state a count. Suppose every occurrence of G in W satisfies a starting state of a list at its total block length, and every satisfied state of the list leads to one with a lower count, satisfied at some size, possibly a larger one, or with the same count, satisfied at a smaller size. Then W avoids G.
theorem XYXAvoid.freeze_or_desub_soundness {V : Type u_1} {α : Type u_2} {State : Type u_3} [Fintype V] (G : LooplessDigraph V) (W : ℕ → α) (freeVars : State → ℕ) (Sat : State → ℕ → Prop) (Cert : Set State) (s₀ : State) (hstart : s₀ ∈ Cert) (hinit : ∀ (h : V → List α), (∀ (v : V), h v ≠ []) → (∀ (u v : V), G.adj u v → IsFactorInf (h u ++ h v ++ h u) W) → Sat s₀ (occMeasure h)) (hclosed : ∀ s ∈ Cert, ∀ (μ : ℕ), Sat s μ → (∃ s' ∈ Cert, freeVars s' < freeVars s ∧ ∃ μ', Sat s' μ') ∨ ∃ s' ∈ Cert, freeVars s' = freeVars s ∧ ∃ μ' < μ, Sat s' μ') : AvoidsDigraphInf G WIn a closed list of shrinking states, no state is ever satisfied
Suppose every state of a list that is satisfied at some size leads to a state of the list satisfied at a smaller size. Then no state of the list is satisfied at any size, because sizes cannot shrink forever.
- Total block length