AFTD Auto-Formalizing Theoretical Domains

evenFoldDiag_length

theoremverified

For any non-empty list d, the diagonal of the even fold of d with parameter δ has length 2 * |d|.

Statement

theorem evenFoldDiag_length {R : Type*} [Sub R] [Add R] (d : List R) (δ : R) (h : d ≠ []) :
    (evenFoldDiag d δ).length = 2 * d.length
Source
arXiv:2611.28952, Section 1.1, (3)
Verified
25 Nov 2026
Axioms
Quot.soundpropext
Built on 1
  • evenFoldDiagThe diagonal sequence of the even fold of a tridiagonal pair with parameter δ: for a diagonal list d, if d reverses to dn :: drest, it is…

Read back from the Lean

For any type $R$ equipped with subtraction (Sub R) and addition (Add R), any list $d$ of elements of $R$, and any element $\delta : R$, if $d$ is non-empty ($d \neq []$), then the length of evenFoldDiag d δ equals $2 \times d.\text{length}$.

Written by a model that saw only the Lean, never the English above. If the two disagree, that is worth a challenge.

The proof, explained

The proof unfolds the definition of `evenFoldDiag`, which matches on the reversed list $d.reverse$. Since $d$ is assumed non-empty, the case where $d.reverse = []$ is immediately ruled out by contradiction. In the non-empty case $d.reverse = dn :: drest$, the length of $d$ is shown to be $|drest| + 1$ by taking lengths of both sides. Finally, expanding the length of the concatenated output list and simplifying via linear integer arithmetic confirms that the total length is $2 \cdot |d|$.

  1. The reversed list $d.reverse$ cannot be empty, so it must decompose as $dn :: drest$.

    Unfolding the definition of `evenFoldDiag`, its value is given by pattern matching on the reversed list $d.reverse$. In the case where $d.reverse = []$, simplifying shows that $d = []$, which directly contradicts the hypothesis $h : d \ne []$.

    lines 4–8

      unfold evenFoldDiag
      cases hr : d.reverse with
      | nil =>
        have : d = [] := by simpa using hr
        contradiction
  2. In the non-empty case $d.reverse = dn :: drest$, the length of $d$ satisfies $|d| = |drest| + 1$.

    Applying the list length function to both sides of the equality $d.reverse = dn :: drest$ using `congr_arg` gives $|d.reverse| = |dn :: drest|$. Rewriting with `List.length_reverse` on the left and `List.length_cons` on the right establishes that $|d| = |drest| + 1$.

    lines 9–13

    uses congr_arg, List.length_reverse, List.length_cons

      | cons dn drest =>
        have hd : d.length = drest.length + 1 := by
          have := congr_arg List.length hr
          simp only [List.length_reverse, List.length_cons] at this
          exact this
  3. The length of `evenFoldDiag d δ` is $2 \cdot |d|$.

    When $d.reverse = dn :: drest$, `evenFoldDiag d δ` unfolds to $drest.reverse ++ (dn - δ) :: (dn + δ) :: drest$. Expanding its length using `List.length_append`, `List.length_cons`, and `List.length_reverse` reduces the length to $|drest| + (|drest| + 1 + 1)$. Linear integer arithmetic (`omega`) finishes the proof using the relation $|d| = |drest| + 1$, since $|drest| + |drest| + 2 = 2 \cdot (|drest| + 1) = 2 \cdot |d|$.

    lines 14–15

    uses List.length_append, List.length_cons, List.length_reverse

        simp only [List.length_append, List.length_cons, List.length_reverse]
        omega
congr_arg
Applying a function to equal arguments yields equal values: if $a_1 = a_2$, then $f(a_1) = f(a_2)$.
List.length_append
The length of the concatenation of two lists is the sum of their lengths: $|as ++ bs| = |as| + |bs|$.
List.length_cons
Prepending an element to a list increases its length by 1: $|a :: as| = |as| + 1$.
List.length_reverse
Reversing a list preserves its length: $|as.reverse| = |as|$.

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

/-- Length of the diagonal of an even fold. -/theorem evenFoldDiag_length {R : Type*} [Sub R] [Add R] (d : List R) (δ : R) (h : d ≠ []) :    (evenFoldDiag d δ).length = 2 * d.length := by  unfold evenFoldDiag  cases hr : d.reverse with  | nil =>    have : d = [] := by simpa using hr    contradiction  | cons dn drest =>    have hd : d.length = drest.length + 1 := by      have := congr_arg List.length hr      simp only [List.length_reverse, List.length_cons] at this      exact this    simp only [List.length_append, List.length_cons, List.length_reverse]    omega
See it in the graphDiscuss this resultChallenge it