The alpha and power formulas

The alpha sequence \(U_n=\alpha_b(n)\) satisfies \(U_0=0\), \(U_1=1\), \(U_{n+2}=bU_{n+1}-U_n\). It grows for \(b\ge2\), its matrix powers have determinant one, and it is congruent in its parameter, with \(\alpha_2(n)=n\).

DefinitionThe alpha sequence#✓

For a natural number \(b\) the alpha sequence \(U_n=\alpha_b(n)\in\mathbb Z\), \(n\in\mathbb N\), is defined by $\(U_0=0,\qquad U_1=1,\qquad U_{n+2}=b\,U_{n+1}-U_n\quad(n\ge0).\)$ It is integer-valued for every \(b\) (its values may be negative when \(b\in\{0,1\}\)). The matrix $\(M_b=\begin{pmatrix}b&-1\\1&0\end{pmatrix}\)$ drives the recurrence: \(M_b\,(U_n,U_{n-1})^{\mathsf T}=(U_{n+1},U_n)^{\mathsf T}\) for \(n\ge1\). When an index may be negative, the sequence is extended by \(U_{-j}=-U_j\), which is consistent with the recurrence.

This is a definition. It is the sequence of the Archive of Formal Proofs development used by the manuscript; \(U_{n+1}\) is the Chebyshev polynomial of the second kind \(S_n\) (normalized by \(S_{n+2}=XS_{n+1}-S_n\), \(S_0=1\), \(S_{-1}=0\)) evaluated at \(b\). Only natural parameters \(b\) occur in this chapter, and every natural-valued use (a witness of the alpha formula) is justified by the growth lemma for \(b\ge2\).

@[expose] def alphaZ (B : Nat) : Nat → Int
  | 0 => 0
  | 1 => 1
  | n + 2 => (B : Int) * alphaZ B (n + 1) - alphaZ B n
def alphaInt (b : ℕ) (n : ℤ) : ℤ :=
  if 0 ≤ n then alphaZ b n.toNat else -alphaZ b (-n).toNat
theorem alphaInt_neg (b : ℕ) (n : ℤ) : alphaInt b (-n) = -alphaInt b n
Used by 10

TheoremGrowth of the alpha sequence#✓

Let \(b\ge2\) be a natural number and \(U_n=\alpha_b(n)\). Then for every \(n\in\mathbb N\) $\(0\le U_n,\qquad U_n+1\le U_{n+1},\qquad n\le U_n .\)$ In particular the sequence is strictly increasing and \(U_n\ge1\) for \(n\ge1\). Moreover, for all natural \(c\ge1\) and \(n\), $\(c^n\le\alpha_{c+1}(n+1),\)$ and for \(b\ge3\), \(\alpha_b(n+1)\le b^n\).

The manuscript states the first group of inequalities for \(b\ge3\); the proof works for \(b\ge2\), and \(\alpha_2(n)=n\) shows that \(b=2\) is the boundary case.

Proof sketch. Joint induction on \(n\) for the pair \(0\le U_n\), \(U_n+1\le U_{n+1}\): the base is \(U_0=0\), \(U_1=1\); in the step, \(U_{n+2}-U_{n+1}=(b-2)U_{n+1}+(U_{n+1}-U_n)\ge0+1\) because \(b\ge2\) and \(U_{n+1}\ge0\). Summing the increments gives \(U_n\ge n\). For \(c^n\le\alpha_{c+1}(n+1)\) induct on \(n\) using \(\alpha_{c+1}(n+2)=(c+1)\alpha_{c+1}(n+1)-\alpha_{c+1}(n)\ge c\,\alpha_{c+1}(n+1)\), which holds because \(\alpha_{c+1}(n)\le\alpha_{c+1}(n+1)\). The upper bound \(\alpha_b(n+1)\le b^n\) is the same induction with \(\alpha_b(n+2)\le b\,\alpha_b(n+1)\).

theorem alphaZ_growth (b : ℕ) (hb : 2 ≤ b) (n : ℕ) :
    0 ≤ alphaZ b n ∧ alphaZ b n + 1 ≤ alphaZ b (n + 1) ∧ (n : ℤ) ≤ alphaZ b n
theorem alphaZ_exponential_bounds (b c n : ℕ) :
    (1 ≤ c → (c : ℤ) ^ n ≤ alphaZ (c + 1) (n + 1)) ∧
      (3 ≤ b → alphaZ b (n + 1) ≤ (b : ℤ) ^ n)
Uses 1 · Used by 7

TheoremMatrix powers and the quadratic identity#✓

Let \(b\) be a natural number, \(U_n=\alpha_b(n)\) and \(M=M_b\). Then:

  1. for every \(n\ge1\), $\(M^n=\begin{pmatrix}U_{n+1}&-U_n\\U_n&-U_{n-1}\end{pmatrix},\qquad\det M^n=1;\)$
  2. for every \(n\in\mathbb N\), \(U_n^2+U_{n+1}^2-b\,U_nU_{n+1}=1\); equivalently, for \(n\ge1\), \(U_n^2-bU_nU_{n-1}+U_{n-1}^2=1\);
  3. for every \(n\), \(U_n\) and \(U_{n+1}\) are coprime in \(\mathbb Z\) and are not both even;
  4. (addition formula) for all \(m,n\in\mathbb N\), \(U_{m+n+1}=U_{m+1}U_{n+1}-U_mU_n\).

Proof sketch. Item 1 by induction on \(n\) from \(M^{n+1}=M\cdot M^n\) and the recurrence; \(\det M=1\). The determinant reads \(U_n^2-U_{n+1}U_{n-1}=1\), and substituting \(U_{n+1}=bU_n-U_{n-1}\) gives item 2 (which can also be proved directly by induction, the left side being invariant under \((U_n,U_{n+1})\mapsto(U_{n+1},bU_{n+1}-U_n)\)). Item 3: item 2 is the Bezout relation \(U_n(U_n-bU_{n+1})+U_{n+1}\cdot U_{n+1}=1\), and reducing it modulo \(2\) excludes two even terms. Item 4 by two-step induction on \(n\), or from the lower-left entry of \(M^{m+n}=M^mM^n\).

theorem alphaMat_pow (b n : ℕ) (hn : 1 ≤ n) :
    alphaMat b ^ n =
      !![alphaZ b (n + 1), -alphaZ b n; alphaZ b n, -alphaZ b (n - 1)]
theorem alphaZ_quadratic (b n : ℕ) :
    alphaZ b n ^ 2 + alphaZ b (n + 1) ^ 2 - (b : ℤ) * alphaZ b n * alphaZ b (n + 1) = 1
theorem alphaZ_addition (b m n : ℕ) :
    alphaZ b (m + n + 1) = alphaZ b (m + 1) * alphaZ b (n + 1) - alphaZ b m * alphaZ b n
Uses 1 · Used by 5

TheoremParameter congruence of the alpha sequence#✓

Let \(b,b',d\) be natural numbers with \(b\equiv b'\pmod d\). Then for every \(n\in\mathbb N\) $\(\alpha_b(n)\equiv\alpha_{b'}(n)\pmod d .\)$ In particular \(\alpha_2(n)=n\) for every \(n\), and therefore \(\alpha_b(n)\equiv n\pmod d\) whenever \(b\equiv2\pmod d\).

This is congruence in the parameter, not merely between indices: it transports residues from the parameter \(w\) of the alpha formula to the parameters \(b\) (modulo \(v\)) and \(2\) (modulo \(u\)).

Proof sketch. Induct on \(n\) with the statements for \(n\) and \(n+1\) together: \(\alpha_b(n+2)=b\,\alpha_b(n+1)-\alpha_b(n)\) and each factor is congruent to its counterpart for \(b'\). For \(b=2\) the recurrence \(U_{n+2}=2U_{n+1}-U_n\) with \(U_0=0\), \(U_1=1\) has the solution \(U_n=n\). The case \(d=0\) is the trivial case \(b=b'\).

theorem alphaZ_modEq_of_modEq {b b' d : ℕ} (h : b ≡ b' [MOD d]) (n : ℕ) :
    alphaZ b n ≡ alphaZ b' n [ZMOD d]
theorem alphaZ_modEq_index {b d : ℕ} (h : b ≡ 2 [MOD d]) (n : ℕ) :
    alphaZ b n ≡ n [ZMOD d]
Uses 1 · Used by 2

Natural solutions of \(x^2+y^2=1+bxy\) are adjacent pairs, by descent. Divisibility of alpha values follows divisibility of indices, with the square refinement (C.1). Modulo the companion \(v=U_{m+1}-U_{m-1}\) the sequence is periodic up to sign and reflection. Odd values are unbounded.

TheoremNatural solutions of the alpha Pell equation#✓

  1. (Unordered) Let \(b>2\) and \(x,y\in\mathbb N\) with \(x^2+y^2=1+bxy\). Then there is \(n\in\mathbb N\) with \(\{x,y\}=\{\alpha_b(n),\alpha_b(n+1)\}\); in particular \(x=\alpha_b(n')\) for some \(n'\in\mathbb N\).
  2. (Ordered) Let \(b\) be any natural number and \(r<s\) natural numbers with \(s^2+r^2=1+bsr\). Then there is \(m>0\) with \(r=\alpha_b(m-1)\) and \(s=\alpha_b(m)\).
  3. Conversely, for \(b\ge2\) every pair \((\alpha_b(n),\alpha_b(n+1))\) consists of natural numbers, satisfies the equation, and has \(\alpha_b(n)<\alpha_b(n+1)\).

No ordering assumption on the pair in item 1 is needed.

Proof sketch. In item 1, \(x\ne y\), since \(2x^2=1+bx^2\) is impossible for \(b\ge2\); order the pair as \(X>Y\). Item 2 is proved by strong induction on the smaller entry \(Y=r\): if \(Y=0\) then \(X^2=1\) and \((X,Y)=(1,0)=(U_1,U_0)\). Otherwise put \(Z=bY-X\in\mathbb Z\). Vieta's relation for the quadratic in \(X\) gives \(XZ=Y^2-1\); hence \(Z\ge0\) (as \(Y\ge1\)) and \(Z<Y\) (as \(X>Y\)), and \((Y,Z)\) satisfies the same equation with \(Y>Z\). By induction \((Z,Y)=(U_{m-1},U_m)\) for some \(m>0\), and then \(X=bY-Z=U_{m+1}\). Item 1 follows from item 2 applied to the ordered pair. Item 3 is the growth lemma and the quadratic identity.

theorem alphaZ_pell_unordered {b x y : ℕ} (hb : 2 < b) (h : x ^ 2 + y ^ 2 = 1 + b * x * y) :
    ∃ n : ℕ, ((x : ℤ) = alphaZ b n ∧ (y : ℤ) = alphaZ b (n + 1)) ∨
      ((x : ℤ) = alphaZ b (n + 1) ∧ (y : ℤ) = alphaZ b n)
theorem alphaZ_pell_ordered (b : ℕ) {r s : ℕ} (hrs : r < s)
    (h : s ^ 2 + r ^ 2 = 1 + b * s * r) :
    ∃ m : ℕ, 0 < m ∧ (r : ℤ) = alphaZ b (m - 1) ∧ (s : ℤ) = alphaZ b m
theorem alphaZ_pell_converse (b : ℕ) (hb : 2 ≤ b) (n : ℕ) :
    ∃ x y : ℕ, (x : ℤ) = alphaZ b n ∧ (y : ℤ) = alphaZ b (n + 1) ∧ x < y ∧
      x ^ 2 + y ^ 2 = 1 + b * x * y
Uses 3 · Used by 1

TheoremDivisibility of alpha values#✓

Let \(b>2\) be a natural number and \(U_n=\alpha_b(n)\).

  1. For \(k>0\) and every \(m\in\mathbb N\): \(U_k\mid U_m\iff k\mid m\).
  2. (Equation (C.1)) For every \(k\in\mathbb N\) and every \(m>0\): $\(U_k^2\mid U_m\iff kU_k\mid m .\)$ For \(k=0\) both sides are false.

Divisibility is in \(\mathbb Z\); all values involved are natural by the growth lemma.

Proof sketch. (1) Reducing \(M^k\) modulo \(U_k\) gives the scalar matrix \(U_{k+1}I\) up to the entry \(-U_{k-1}\equiv U_{k+1}\) (from the recurrence \(U_{k+1}+U_{k-1}=bU_k\)), which is invertible modulo \(U_k\) by coprimality of adjacent terms. Equivalently, by the addition formula \(U_{k+n}=U_{k}U_{n+1}-U_{k-1}U_n\), so \(U_k\mid U_{k+n}\iff U_k\mid U_n\) (as \(\gcd(U_k,U_{k-1})=1\)). Removing periods of length \(k\) reduces to \(m<k\), where \(0\le U_m<U_k\) by strict growth, so \(U_k\mid U_m\) iff \(U_m=0\) iff \(m=0\). (2) For \(k=0\): \(U_0^2=0\) divides \(U_m\ge m>0\) never, and \(0\mid m\) never. For \(k>0\), both sides imply \(k\mid m\) (the left by (1) since \(U_k\mid U_m\)); write \(m=kq\) with \(q\ge1\). From \(M^k\equiv U_kM-U_{k-1}I\) entrywise (the recurrence gives \(M^k=U_kM-U_{k-1}I\) exactly), $\(M^{kq}=(U_kM-U_{k-1}I)^q\equiv(-U_{k-1})^qI+qU_k(-U_{k-1})^{q-1}M\pmod{U_k^2},\)$ whose lower-left entry gives \(U_m\equiv qU_k(-U_{k-1})^{q-1}\pmod{U_k^2}\). Since \(\gcd(U_k,U_{k-1})=1\), \(U_k^2\mid U_m\iff U_k\mid q\iff kU_k\mid kq=m\); this includes \(U_k=1\).

theorem alphaZ_dvd_alphaZ_iff (b k m : ℕ) (hb : 2 < b) (hk : 0 < k) :
    alphaZ b k ∣ alphaZ b m ↔ k ∣ m
theorem alphaZ_sq_dvd_alphaZ_iff (b k m : ℕ) (hb : 2 < b) (hm : 0 < m) :
    alphaZ b k ^ 2 ∣ alphaZ b m ↔ (k : ℤ) * alphaZ b k ∣ (m : ℤ)
Uses 3 · Used by 2

TheoremPeriod and reflection modulo the companion#✓

Let \(b>2\) be a natural number, \(U_n=\alpha_b(n)\), \(m>0\), and put $\(v=U_{m+1}-U_{m-1}=\operatorname{tr}(M_b^m)=bU_m-2U_{m-1}.\)$

  1. (Folding) Every \(n\in\mathbb N\) can be written as \(n=2lm+j\), or as \(n=2lm-j\) with \(0<j<2lm\), for some \(l\in\mathbb N\) and \(0\le j\le m\).
  2. (Period and reflection) For all \(l,j\in\mathbb N\), $\(U_{j+2lm}\equiv(-1)^lU_j\pmod v,\qquad U_{2lm-j}\equiv-(-1)^lU_j\pmod v\ \ (0<j<2lm).\)$ Consequently, for \(n\) folded as in item 1, \(U_n\equiv\pm U_j\pmod v\).
  3. (Bounds) If \(b>3\) then \(2U_j<v\) for every \(0\le j\le m\); in particular \(v>2U_m\).

The value sign in item 2 need not equal the index sign. In the manuscript's notation, \(n=2lm+\varepsilon j\) with \(\varepsilon\in\{1,-1\}\) and \(U_n\equiv(-1)^l\varepsilon U_j\).

Proof sketch. (1) Take \(l\) with \(2lm\le n<2(l+1)m\) and fold to the nearer of \(2lm\) and \(2(l+1)m\). (2) \(M^m\) has determinant \(1\) and trace \(v\), so by Cayley-Hamilton \(M^{2m}=vM^m-I\equiv-I\pmod v\), hence \(M^{2lm}\equiv(-1)^lI\). The lower-left entry of \(M^{j+2lm}=M^jM^{2lm}\) gives the period congruence. For the reflection, the lower-left entry of \(M^{2lm}M^{-j}\), where \(M^{-j}\) is the inverse matrix (entries in \(\mathbb Z\) since \(\det M=1\)), equals \(U_{2lm-j}\) and is congruent to \((-1)^l\cdot(-U_j)\). In terms of the recurrence alone: the identity \(U_{n+2m}+U_n=vU_{n+m}\) (the addition formula) gives the period, and \(U_{N-j}=U_N(-U_{j-1})+(-U_{N-1})(-U_j)\) with \(N=2lm\), \(U_N\equiv0\), \(U_{N-1}\equiv-(-1)^l\), gives the reflection. (3) For \(j\le m\), \(2U_j\le2U_m\), and \(v-2U_m=(b-2)U_m-2U_{m-1}\ge2(U_m-U_{m-1})>0\) when \(b\ge4\), using strict growth.

theorem alphaZ_period (b m j l : ℕ) (hb : 2 < b) :
    (alphaZ b (m + 1) - alphaZ b (m - 1)) ∣ alphaZ b (j + 2 * l * m) - (-1) ^ l * alphaZ b j
theorem alphaZ_reflection (b m j l : ℕ) (hb : 2 < b) (hj : 0 < j) (hjlt : j < 2 * l * m) :
    (alphaZ b (m + 1) - alphaZ b (m - 1)) ∣ alphaZ b (2 * l * m - j) - -((-1) ^ l * alphaZ b j)
theorem alphaZ_folded_residue (b m n l j : ℕ) (hb : 2 < b)
    (hf : n = 2 * l * m + j ∨ (n = 2 * l * m - j ∧ 0 < j ∧ j < 2 * l * m)) :
    (alphaZ b (m + 1) - alphaZ b (m - 1)) ∣ alphaZ b n - alphaZ b j ∨
      (alphaZ b (m + 1) - alphaZ b (m - 1)) ∣ alphaZ b n + alphaZ b j
Uses 3 · Used by 2

TheoremOdd alpha values are unbounded#✓

Let \(b>3\) and \(a\in\mathbb N\). There is \(k>0\) such that \(u=\alpha_b(k)\) is odd and \(u>2a\); moreover \(t=\alpha_b(k+1)\) satisfies \(u<t\) and \(u^2+t^2=1+but\).

Proof sketch. Of the adjacent terms \(\alpha_b(2a+1)\) and \(\alpha_b(2a+2)\) at least one is odd (adjacent terms are not both even), and both exceed \(2a\) since \(\alpha_b(n)\ge n\). Take \(k\) the corresponding index. The last two claims are strict growth and the quadratic identity.

theorem alphaZ_large_odd (b a : ℕ) (hb : 3 < b) :
    ∃ k : ℕ, 0 < k ∧ Odd (alphaZ b k) ∧ 2 * (a : ℤ) < alphaZ b k ∧
      alphaZ b k < alphaZ b (k + 1) ∧
      alphaZ b k ^ 2 + alphaZ b (k + 1) ^ 2 = 1 + (b : ℤ) * alphaZ b k * alphaZ b (k + 1)
Uses 3 · Used by 1

The alpha formula (C.2) has eight witnesses and fifteen conditions; it holds exactly when \(b>3\) and \(X=\alpha_b(N)\).

DefinitionThe alpha formula#✓

For natural numbers \(X,b,N\), the alpha formula \(\mathrm{Alpha}(X,b,N)\) is the statement that there are natural numbers \(r,s,t,u,v,w,x,y\) satisfying the fifteen conditions (C.2): $\(\begin{gathered} b>3,\quad u^2+t^2=1+but,\quad s^2+r^2=1+bsr,\quad r<s,\quad u^2\mid s,\quad v+2r=bs,\\ w\equiv b\pmod v,\quad w\equiv2\pmod u,\quad w>2,\quad x^2+y^2=1+wxy,\\ 2X<u,\quad 2X<v,\quad x\equiv X\pmod v,\quad 2N<u,\quad x\equiv N\pmod u . \end{gathered}\)$ Here \(p\equiv q\pmod M\) means \(p\bmod M=q\bmod M\) for natural numbers (so for \(M=0\) it means \(p=q\)), and \(p\mid q\) is divisibility in \(\mathbb N\).

The compiler emits this system as the alpha macro: each strict inequality, divisibility and congruence is replaced by an equation with fresh natural witnesses (see the equational gadgets), and the macro introduces its eight witnesses in the order \(r,s,t,u,v,w,x,y\). The conditions are exactly the alpha equations of the AFP development, with \(a=X\) and \(c=N\); equation order and the orientation of each equality are immaterial.

This is a definition.

def AlphaEqns (X b N : ℕ) : Prop :=
  ∃ r s t u v w x y : ℕ, 3 < b ∧ u ^ 2 + t ^ 2 = 1 + b * u * t ∧
    s ^ 2 + r ^ 2 = 1 + b * s * r ∧ r < s ∧ u ^ 2 ∣ s ∧ v + 2 * r = b * s ∧
    w % v = b % v ∧ w % u = 2 % u ∧ 2 < w ∧ x ^ 2 + y ^ 2 = 1 + w * x * y ∧
    2 * X < u ∧ 2 * X < v ∧ x % v = X % v ∧ 2 * N < u ∧ x % u = N % u
Lean

The AFP development states these conditions as Exp_Matrices.alpha_equations.

Sources
Used by 3

TheoremSoundness of the alpha formula#✓

For all natural numbers \(X,b,N\): if \(\mathrm{Alpha}(X,b,N)\) holds then \(b>3\) and \(X=\alpha_b(N)\).

Proof sketch. Fix witnesses \(r,s,t,u,v,w,x,y\).

  1. Shapes. From \(u^2+t^2=1+but\) and \(b>2\), \(u=\alpha_b(k)\) for some \(k\) (unordered Pell classification); \(u>2X\ge0\) gives \(u\ge1\), hence \(k>0\). From \(s^2+r^2=1+bsr\) with \(r<s\), \((r,s)=(\alpha_b(m-1),\alpha_b(m))\) with \(m>0\) (ordered classification). From \(x^2+y^2=1+wxy\) and \(w>2\), \(x=\alpha_w(n)\) for some \(n\in\mathbb N\).
  2. \(u\mid m\). \(u^2\mid s\) is \(\alpha_b(k)^2\mid\alpha_b(m)\) with \(m>0\); by (C.1) \(k\,\alpha_b(k)\mid m\), so \(u\mid m\).
  3. Residues. \(v+2r=bs\) identifies \(v=\alpha_b(m+1)-\alpha_b(m-1)\) (the companion). Parameter congruence with \(w\equiv b\pmod v\) gives \(x\equiv\alpha_b(n)\pmod v\); with \(w\equiv2\pmod u\) and \(\alpha_2(n)=n\) it gives \(x\equiv n\pmod u\).
  4. Recover \(X\). Fold \(n\) as \(n=2lm\pm j\) with \(0\le j\le m\). By period and reflection, \(\alpha_b(n)\equiv\pm\alpha_b(j)\pmod v\), so \(X\equiv x\equiv\pm\alpha_b(j)\pmod v\). Both \(X\) and \(\alpha_b(j)\) are nonnegative and below \(v/2\) (\(2X<v\) by hypothesis, \(2\alpha_b(j)<v\) by the companion bound for \(b>3\), \(j\le m\)), so \(v\mid X-\alpha_b(j)\) or \(v\mid X+\alpha_b(j)\) forces \(X=\alpha_b(j)\) (in the second case both are \(0\)).
  5. Recover \(N\). \(j\le\alpha_b(j)=X\), so \(2j\le2X<u\); also \(2N<u\). Since \(u\mid m\), the folded form gives \(n\equiv\pm j\pmod u\), and \(N\equiv x\equiv n\pmod u\). Two residues below \(u/2\) that agree up to sign modulo \(u\) are equal: \(N=j\). Hence \(X=\alpha_b(N)\).

The natural-subtraction case \(n=2lm-j\) requires \(0<j<2lm\), which the folding lemma supplies.

theorem alphaEqns_sound {X b N : ℕ} (h : AlphaEqns X b N) :
    3 < b ∧ (X : ℤ) = alphaZ b N
Uses 7 · Used by 4

TheoremCompleteness of the alpha formula#✓

For all natural numbers \(b,N\) with \(b>3\), the formula \(\mathrm{Alpha}(\alpha_b(N),b,N)\) holds; that is, the fifteen conditions have natural witnesses with \(X=\alpha_b(N)\). This includes \(N=X=0\).

Together with soundness: for natural \(X,b,N\), \(\mathrm{Alpha}(X,b,N)\iff(b>3\wedge X=\alpha_b(N))\).

Proof sketch. Put \(X=\alpha_b(N)\in\mathbb N\).

  1. Choose \(k>0\) with \(u=\alpha_b(k)\) odd and \(u>2X\) (odd alpha values are unbounded); put \(t=\alpha_b(k+1)\), so \(u^2+t^2=1+but\).
  2. Put \(m=ku>0\), \(s=\alpha_b(m)\), \(r=\alpha_b(m-1)\); then \(r<s\) and \(s^2+r^2=1+bsr\). By (C.1), \(u^2\mid s\) because \(ku\mid m\).
  3. Put \(v=bs-2r\); then \(v\in\mathbb N\), \(v+2r=bs\) and \(v>2s\) (companion bound, \(b>3\)).
  4. Bounds. \(2X<u\) by choice; \(s=\alpha_b(m)\ge\alpha_b(k)=u\) since \(m\ge k\), so \(2X<u\le s<v\); and \(2N\le2\alpha_b(N)=2X<u\).
  5. Coprimality. \(\gcd(u,v)=1\): a common prime divisor \(p\) is odd (\(u\) is odd), divides \(s\) (as \(u\mid s\)) and hence \(2r=bs-v\), hence \(r\); but \(r,s\) are adjacent alpha values, which are coprime.
  6. CRT. With \(u,v>0\) coprime, choose \(w>2\) with \(w\equiv2\pmod u\) and \(w\equiv b\pmod v\).
  7. Put \(x=\alpha_w(N)\), \(y=\alpha_w(N+1)\) (natural since \(w\ge2\)). Then \(x^2+y^2=1+wxy\), and by parameter congruence \(x\equiv\alpha_b(N)=X\pmod v\) and \(x\equiv\alpha_2(N)=N\pmod u\).

All fifteen conditions hold.

theorem alphaEqns_complete (b N : ℕ) (hb : 3 < b) :
    AlphaEqns (alphaZ b N).toNat b N
theorem alphaEqns_iff (X b N : ℕ) : AlphaEqns X b N ↔ 3 < b ∧ (X : ℤ) = alphaZ b N
Uses 9 · Used by 3

The power formula (C.3) separates the base zero and expresses \(P=Q^R\) through three alpha formulas and one congruence.

DefinitionThe power formula#✓

For natural numbers \(P,Q,R\), the power formula \(\mathrm{Pow}(P,Q,R)\) is the disjunction of three branches:

  1. \(Q=0\), \(R=0\) and \(P=1\);
  2. \(Q=0\), \(0<R\) and \(P=0\);
  3. \(0<Q\) and there are natural numbers \(b,m,a_0,a_1,a_2\) with (C.3) $\(\mathrm{Alpha}(a_0,Q+4,R+1),\quad b=a_0+Q^2+2,\quad m+Q^2+1=bQ,\quad P<m,\)$ $\(\mathrm{Alpha}(a_1,b,R),\quad \mathrm{Alpha}(a_2,b,R+1),\quad P+ba_1\equiv Qa_1+a_2\pmod m .\)$

The compiler's power macro introduces \(b,m,a_0,a_1,a_2\) in this order (before the witnesses of the inner macros), writes the strict inequalities \(0<R\), \(0<Q\), \(P<m\) and the congruence with the equational gadgets, and writes the three alpha formulas as alpha macros; the three branches are joined by a disjunction, each branch being a conjunction. The third branch is the AFP development's representation of exponentiation.

This is a definition.

def PowEqns (P Q R : ℕ) : Prop :=
  (Q = 0 ∧ R = 0 ∧ P = 1) ∨ (Q = 0 ∧ 0 < R ∧ P = 0) ∨
    (0 < Q ∧ ∃ b m a0 a1 a2 : ℕ, AlphaEqns a0 (Q + 4) (R + 1) ∧ b = a0 + Q ^ 2 + 2 ∧
      m + Q ^ 2 + 1 = b * Q ∧ P < m ∧ AlphaEqns a1 b R ∧ AlphaEqns a2 b (R + 1) ∧
      (P + b * a1) % m = (Q * a1 + a2) % m)
Lean

The third branch is Exponential_Relation.exp_repr of the AFP development.

Sources
Uses 1 · Used by 1

TheoremThe power formula expresses exponentiation#✓

For all natural numbers \(P,Q,R\): $\(\mathrm{Pow}(P,Q,R)\iff P=Q^R,\)$ with \(0^0=1\). This includes \(R=0\), \(Q=1\) and the base \(Q=0\).

Proof sketch. If \(Q=0\) the third branch is excluded and the first two say exactly \(P=0^R\). Let \(Q\ge1\); only the third branch can hold.

Forward. By alpha soundness, \(a_0=\alpha_{Q+4}(R+1)\); then \(b=a_0+Q^2+2\ge4\), so the two other alpha formulas give \(a_1=\alpha_b(R)\), \(a_2=\alpha_b(R+1)\). By growth, \(a_0\ge(Q+3)^R\), and therefore \(m=bQ-Q^2-1=(a_0+Q^2+2)Q-Q^2-1>Q^R\), so \(m>0\). Put \(U=\alpha_b\) and \(E_R=QU_R-bU_R+U_{R+1}\). Then \(E_0=1\) and, by the recurrence, \(E_{R+1}-Q^{R+1}=Q(E_R-Q^R)+(bQ-Q^2-1)U_R\), so \(m\mid E_R-Q^R\) for every \(R\) (as integers; this needs no sign or size hypothesis). The congruence \(P+ba_1\equiv Qa_1+a_2\pmod m\) says \(P\equiv E_R\equiv Q^R\pmod m\); since \(0\le P<m\) and \(0\le Q^R<m\), \(P=Q^R\).

Backward. Given \(P=Q^R\) with \(Q\ge1\), take \(a_0=\alpha_{Q+4}(R+1)\), \(b=a_0+Q^2+2\), \(m=bQ-Q^2-1\) (natural, and \(m>Q^R=P\)), \(a_1=\alpha_b(R)\), \(a_2=\alpha_b(R+1)\); alpha completeness supplies the three alpha formulas (\(Q+4>3\), \(b>3\)), and the congruence holds by the divisibility above (in natural numbers, \(P+ba_1\) and \(Qa_1+a_2\) have equal remainders modulo \(m\) because \(Qa_1+a_2-ba_1=E_R\) is congruent to \(P\)).

theorem powEqns_iff (P Q R : ℕ) : PowEqns P Q R ↔ P = Q ^ R
Uses 4 · Used by 2

Binomial coefficients are base-\(2^{N+1}\) digits of a power, odd binomial coefficients detect bit inclusion and disjointness, and three disjointness conditions express the bitwise AND.

TheoremBinomial coefficients as base-B digits#✓

For natural numbers \(C,N,K\) the following are equivalent:

  1. there are natural numbers \(\beta,\tau,\pi,q,r\) with $\(\beta=2^{N+1},\quad\tau=(\beta+1)^N,\quad\pi=\beta^K,\quad C<\beta,\quad r<\pi,\quad \tau=\pi(\beta q+C)+r;\)$
  2. \(C=\binom NK\) (with \(\binom NK=0\) for \(K>N\)).

In particular, with \(\beta=2^{N+1}\), the \(K\)-th base-\(\beta\) digit of \((1+\beta)^N\) is \(\binom NK\), including the cases \(N=0\), \(K=0\) and \(K>N\). In the compiler the three powers are power macros and the witnesses are introduced in the order \(\beta,\tau,\pi,q,r\).

Proof sketch. Each \(\binom Nj\le2^N<\beta\), so the binomial theorem \((1+\beta)^N=\sum_{j\le N}\binom Nj\beta^j\) is the base-\(\beta\) expansion of \(\tau\), with digit \(\binom NK\) at place \(K\) (zero for \(K>N\)). For positive \(\beta\) and \(\pi\), the existence of \(q,r\) with \(C<\beta\), \(r<\pi\) and \(\tau=\pi(\beta q+C)+r\) is equivalent to \(C=\lfloor\tau/\pi\rfloor\bmod\beta\) (uniqueness of division with remainder, twice). Hence \(C\) is the digit at place \(K\).

theorem binomial_digit_iff_choose (C N K : ℕ) :
    (∃ β τ π q r : ℕ, β = 2 ^ (N + 1) ∧ τ = (β + 1) ^ N ∧ π = β ^ K ∧ C < β ∧ r < π ∧
      τ = π * (β * q + C) + r) ↔ C = Nat.choose N K
Lean

The compiler's witness names, in order: binomial_base, binomial_total, binomial_place, binomial_quotient, binomial_remainder.

Sources
Used by 1

TheoremLucas's criterion for bit inclusion and disjointness#✓

For natural numbers \(a,b\) write \(a\mathbin{\mathrm{AND}}b\) for the bitwise conjunction of their binary expansions, and say \(a\) is masked by \(b\) when \(a\mathbin{\mathrm{AND}}b=a\) (every set bit of \(a\) is set in \(b\)). Then:

  1. \(\binom ba\) is odd if and only if \(a\) is masked by \(b\);
  2. \(\binom{a+b}a\) is odd if and only if \(a\mathbin{\mathrm{AND}}b=0\).

Proof sketch. (1) Lucas's theorem at the prime \(2\): \(\binom ba\equiv\binom{b\bmod2}{a\bmod2}\binom{\lfloor b/2\rfloor}{\lfloor a/2\rfloor}\pmod2\), and \(\binom{\beta}{\alpha}\) for bits \(\alpha,\beta\) is \(0\) exactly when \(\alpha=1,\beta=0\); induct on \(b\). Equivalently, \((1+t)^b=\prod_{i:\,\mathrm{bit}_i(b)=1}(1+t^{2^i})\) over \(\mathbb F_2\). (2) By (1) it suffices that \(a\) is masked by \(a+b\) iff \(a\mathbin{\mathrm{AND}}b=0\). If the bits are disjoint the addition has no carries and \(a+b=a\mathbin{\mathrm{OR}}b\). Otherwise, at the least position where both \(a\) and \(b\) have a set bit there is no incoming carry (below it at most one summand has each bit set, so no carry is generated), so that bit of \(a+b\) is \(0\) while the bit of \(a\) is \(1\).

theorem lucas_choose_odd_iff_masked (a b : ℕ) : Odd (Nat.choose b a) ↔ a &&& b = a
theorem lucas_choose_add_odd_iff_disjoint (a b : ℕ) :
    Odd (Nat.choose (a + b) a) ↔ a &&& b = 0
Used by 2

TheoremThe bitwise AND gadget#✓

For natural numbers \(z,x,y\) the following are equivalent:

  1. there are natural numbers \(a,b\) with \(x=z+a\), \(y=z+b\) and \(z\mathbin{\mathrm{AND}}a=z\mathbin{\mathrm{AND}}b=a\mathbin{\mathrm{AND}}b=0\);
  2. \(z=x\mathbin{\mathrm{AND}}y\).

In the compiler, each of the three disjointness conditions is the orthogonality macro (\(\binom{p+q}p\) odd, through the binomial-digit gadget and an odd-witness equation), and the witnesses are introduced in the order \(a,b\).

Proof sketch. (1)\(\Rightarrow\)(2): disjointness makes the additions carry-free, so \(x=z\mathbin{\mathrm{OR}}a\) and \(y=z\mathbin{\mathrm{OR}}b\), and with \(z,a,b\) pairwise disjoint, \((z\mathbin{\mathrm{OR}}a)\mathbin{\mathrm{AND}}(z\mathbin{\mathrm{OR}}b)=z\). (2)\(\Rightarrow\)(1): take \(a=x-z\) and \(b=y-z\), the bit differences \(x\mathbin{\mathrm{AND\,NOT}}y\) and \(y\mathbin{\mathrm{AND\,NOT}}x\); they are disjoint from \(z\) and from each other.

theorem bitAnd_gadget_iff (z x y : ℕ) :
    (∃ a b : ℕ, x = z + a ∧ y = z + b ∧ z &&& a = 0 ∧ z &&& b = 0 ∧ a &&& b = 0) ↔
      z = x &&& y
theorem bitAnd_macro_iff (z x y : ℕ) :
    NaturalBitwiseMacros.bit_and z x y ↔ z = x &&& y
Lean

The compiler's witness names, in order: and_left_only, and_right_only.

Sources
Used by 1
16 fully proved

The dependency explorer needs JavaScript and its graph data.

Download the complete graph data.