AFTD Auto-Formalizing Theoretical Domains

alpha_lexical_lt_append_parity

theoremverified

Prepending an even-length common sequence preserves alternating lexical order, while prepending an odd-length common sequence reverses it.

Statement

theorem alpha_lexical_lt_append_parity (u x y : List ℕ) :
    alpha_lexical_lt (u ++ x) (u ++ y) ↔
      if u.length % 2 = 0 then alpha_lexical_lt x y else alpha_lexical_lt y x
Source
Common-prefix cancellation helper for OP-392, arXiv:2610.24758; alternating order as in arXiv:0810.5205.
Verified
18 Nov 2026
Axioms
Classical.choiceQuot.soundpropext
Built on 2
  • alpha_lexical_ltThe source alternating lexicographic order on positive integer sequences.
  • alpha_lexical_lt_cons_samePrepending the same head to both sequences reverses the alternating lexical order on their tails.
Used by 2

The proof, explained

The proof proceeds by structural induction on the common prefix u, generalizing x and y. The base case u = [] holds immediately because the empty prefix has length 0 (even) and leaves the lists unchanged. For the inductive step u = h :: t, prepending the common head h reverses the alternating lexical order, transforming the comparison into one between t ++ y and t ++ x. Applying the induction hypothesis to the swapped lists and analyzing the parity of t's length completes the proof, as incrementing the length by 1 flips the comparison order.

  1. The theorem holds for the base case where u is the empty list.

    We proceed by structural induction on u, generalizing x and y. When u = [], prepending [] leaves both lists unchanged ([] ++ x = x and [] ++ y = y), and [].length = 0. Since 0 % 2 = 0, the if-condition is true, so the right-hand side simplifies to alpha_lexical_lt x y, which matches the left-hand side. The simp tactic discharges this base case.

    lines 4–5

      induction u generalizing x y with
      | nil => simp
  2. In the inductive step u = h :: t, the goal reduces to showing that the conditional parity expression for t with swapped arguments matches the conditional parity expression for h :: t.

    For u = h :: t, the term h :: t ++ x is associative as h :: (t ++ x) via List.cons_append. By alpha_lexical_lt_cons_same, prepending the common head h reverses the alternating lexical order, transforming alpha_lexical_lt (h :: t ++ x) (h :: t ++ y) into alpha_lexical_lt (t ++ y) (t ++ x). Rewriting with the induction hypothesis ih (applied to y and x) turns this into a conditional on whether t.length % 2 = 0, with branches swapped. Finally, List.length_cons rewrites (h :: t).length as t.length + 1.

    lines 6–9

    uses List.cons_append, alpha_lexical_lt_cons_same, List.length_cons

      | cons h t ih =>
        simp only [List.cons_append, alpha_lexical_lt_cons_same]
        rw [ih]
        simp only [List.length_cons]
  3. The parity conditional expressions agree whether the length of t is even or odd, completing the inductive step.

    By Nat.mod_two_eq_zero_or_one, the length of t modulo 2 is either 0 or 1: • If t.length % 2 = 0 (even), then (t.length + 1) % 2 = 1 by linear arithmetic (omega). The left-hand condition t.length % 2 = 0 holds, selecting alpha_lexical_lt y x, while the right-hand condition (t.length + 1) % 2 = 0 is false, also selecting alpha_lexical_lt y x. • If t.length % 2 = 1 (odd), then (t.length + 1) % 2 = 0 by linear arithmetic (omega). The left-hand condition is false, selecting alpha_lexical_lt x y, while the right-hand condition is true, also selecting alpha_lexical_lt x y. In each branch, simp substitutes these parity values to show that both sides reduce to the exact same comparison.

    lines 10–14

    uses Nat.mod_two_eq_zero_or_one

        rcases Nat.mod_two_eq_zero_or_one t.length with h0 | h1
        · have hs : (t.length + 1) % 2 = 1 := by omega
          simp [h0, hs]
        · have hs : (t.length + 1) % 2 = 0 := by omega
          simp [h1, hs]
List.cons_append
Prepending an element to the concatenation of two lists is equal to prepending it to the first list before concatenation: (a :: as) ++ bs = a :: (as ++ bs).
alpha_lexical_lt_cons_same
Prepending the same head element to two lists reverses their strict alternating lexical order: x :: xs <_α x :: ys ↔ ys <_α xs.
List.length_cons
The length of a list with an element prepended is one more than the original list's length: (a :: as).length = as.length + 1.
Nat.mod_two_eq_zero_or_one
Every natural number modulo 2 is either 0 or 1 (any natural number is either even or odd).

Written by a model (gemini-3.8-flash) from the Lean proof and the goal states Lean reported at each step. Lean verified the proof; this explanation is a reading aid and is not itself machine-checked.

Lean source view module on GitHub

theorem alpha_lexical_lt_append_parity (u x y : List ℕ) :    alpha_lexical_lt (u ++ x) (u ++ y) ↔      if u.length % 2 = 0 then alpha_lexical_lt x y else alpha_lexical_lt y x := by  induction u generalizing x y with  | nil => simp  | cons h t ih =>    simp only [List.cons_append, alpha_lexical_lt_cons_same]    rw [ih]    simp only [List.length_cons]    rcases Nat.mod_two_eq_zero_or_one t.length with h0 | h1    · have hs : (t.length + 1) % 2 = 1 := by omega      simp [h0, hs]    · have hs : (t.length + 1) % 2 = 0 := by omega      simp [h1, hs]
See it in the graphDiscuss this resultChallenge it