The Gilbreath triangle of iterated absolute differences
Definitiongilbreath_triangleLet be the increasing enumeration of the primes, indexed from . For a sequence let be its sequence of absolute differences of consecutive terms, and let be the -fold iterate of , with .
The rows of the Gilbreath triangle are
Row is the sequence of primes, row is the sequence of prime gaps, and each later row is the sequence of absolute differences of the row above it. Differences are formed in and then taken in absolute value, so no truncated natural subtraction occurs. Alongside the three definitions the file records the structural identities , , , , , and .
import Mathlib
namespace Gilbreath
/-- One step of the Gilbreath triangle: the sequence of absolute differences of
consecutive terms of `a`, i.e. `absDiff a n = |a (n + 1) - a n|`. -/
def absDiff (a : ℕ → ℕ) : ℕ → ℕ := fun n => Int.natAbs ((a (n + 1) : ℤ) - (a n : ℤ))
/-- `iterAbsDiff a k` is the `k`-th iterated absolute-difference row of `a`:
row `0` is `a` itself and each subsequent row is `absDiff` of the previous one. -/
def iterAbsDiff (a : ℕ → ℕ) : ℕ → (ℕ → ℕ)
| 0 => a
| k + 1 => absDiff (iterAbsDiff a k)
/-- Row `k` of Gilbreath's triangle. Row `0` is the increasing sequence of all
primes, `d 0 n = Nat.nth Nat.Prime n` (so `d 0 0 = 2`, `d 0 1 = 3`, ...), and
row `k + 1` is the sequence of absolute differences of consecutive entries of
row `k`. -/
noncomputable def d (k : ℕ) : ℕ → ℕ := iterAbsDiff (fun n => Nat.nth Nat.Prime n) k
@[simp] theorem iterAbsDiff_zero (a : ℕ → ℕ) : iterAbsDiff a 0 = a := rfl
@[simp] theorem iterAbsDiff_succ (a : ℕ → ℕ) (k : ℕ) :
iterAbsDiff a (k + 1) = absDiff (iterAbsDiff a k) := rfl
@[simp] theorem d_zero_apply (n : ℕ) : d 0 n = Nat.nth Nat.Prime n := rfl
@[simp] theorem d_succ (k : ℕ) : d (k + 1) = absDiff (d k) := rfl
theorem d_succ_apply (k n : ℕ) : d (k + 1) n = Int.natAbs ((d k (n + 1) : ℤ) - (d k n : ℤ)) :=
rfl
/-- Peeling one difference off the front instead of the back. -/
theorem iterAbsDiff_succ' (a : ℕ → ℕ) (k : ℕ) :
iterAbsDiff a (k + 1) = iterAbsDiff (absDiff a) k := by
induction k with
| zero => rfl
| succ k ih => rw [iterAbsDiff_succ (k := k + 1), ih, iterAbsDiff_succ]
/-- Iterating the difference operator starting from row `k` lands on row `k + j`. -/
theorem iterAbsDiff_d (k j : ℕ) : iterAbsDiff (d k) j = d (k + j) := by
induction j with
| zero => simp
| succ j ih => rw [iterAbsDiff_succ, ih, ← Nat.add_assoc, d_succ]
end Gilbreath
Read-back
What the Lean code literally says, in plain math · self-authored by the drafting agent (non-blind, not an independent auditor)
Disclosure — this read-back is not independent. It was written by the same agent that drafted the Lean statements in this proposal, at the mission owner's explicit instruction, rather than blind by a separate auditor. It is therefore self-testimony, not independent testimony, and the usual protection against an unfaithful formalization — a reader who does not know what the code is supposed to say — is absent here. An independent read-back is recommended before this item is confirmed.
This file fixes, for the rest of the mission, three objects and six identities about them.
First, for an arbitrary function it defines a new function by
where the subtraction is performed after casting both values into the integers and the absolute value is then taken back into the naturals; so is the ordinary absolute difference and never a truncated natural subtraction. It is defined at every index , including .
Second, for and it defines by recursion on : and . The zeroth iterate is itself, not its first difference.
Third, for it defines as applied to the function , where denotes the -th prime in increasing order counted from (Mathlib's enumeration of the primes, for which ). Hence for every , and . Every is a total function defined at every index. This definition is marked noncomputable: it names a mathematical object, and no evaluation algorithm is claimed.
The six accompanying identities assert exactly: for every ; for every and ; for every ; for every ; for every and ; for every and (differencing once first, then iterating times, agrees with iterating times and then differencing); and for all . All of these are proved in the file; none is assumed.
Confirmed by the mission captain (proposal self-audit).