The exact precision computation
The five natural inputs of the precision computation are signed encodings, decoded in the fixed order \((n,\kappa,a,l,j)\).
DefinitionThe signed encoding of integers#✓
The signed encoding \(\operatorname{enc}:\mathbb Z\to\mathbb N\) and its decoding \(\operatorname{dec}:\mathbb N\to\mathbb Z\) are $\(\operatorname{enc}(n)=\begin{cases}2n,&n\ge0,\\-2n-1,&n<0,\end{cases}\qquad \operatorname{dec}(c)=\begin{cases}c/2,&c\text{ even},\\-(c+1)/2,&c\text{ odd}.\end{cases}\)$ A tuple \(c=(c_0,c_1,c_2,c_3,c_4)\in\mathbb N^5\) of precision inputs decodes, in this fixed order, to \((n,\kappa,a,l,j)=(\operatorname{dec}c_0,\dots,\operatorname{dec}c_4)\in\mathbb Z^5\).
This is a definition. The order \((n,\kappa,a,l,j)\) is the order in which the ordinary-value relation links its five signed codes to the precision inputs.
def enc (n : ℤ) : ℕ := if 0 ≤ n then 2 * n.toNat else 2 * (-n).toNat - 1
def dec (c : ℕ) : ℤ := if c % 2 = 0 then ((c / 2 : ℕ) : ℤ) else -(((c + 1) / 2 : ℕ) : ℤ)
def decode5 (c : Fin 5 → ℕ) : Fin 5 → ℤ := fun i => dec (c i)
def dec (c : ℕ) : ℤ := if c % 2 = 0 then ((c / 2 : ℕ) : ℤ) else -(((c + 1) / 2 : ℕ) : ℤ)
ZInQKernel/Compiler/Precision/Encoding.lean:19
TheoremThe signed encoding is a bijection#✓
\(\operatorname{dec}(\operatorname{enc}(n))=n\) for every \(n\in\mathbb Z\) and \(\operatorname{enc}(\operatorname{dec}(c))=c\) for every \(c\in\mathbb N\). Moreover \(\operatorname{enc}(n)\) is even exactly when \(n\ge0\), and \(|\operatorname{dec}(c)|=\lceil c/2\rceil\).
Proof sketch. Case analysis on the sign of \(n\) and the parity of \(c\): \(2n\) is even with half \(n\); \(-2n-1\) is odd for \(n<0\) and \(-((-2n-1)+1)/2=n\); conversely \(c=2h\) decodes to \(h\ge0\) and \(c=2h+1\) to \(-(h+1)<0\), which encodes to \(2h+1\).
theorem dec_enc (n : ℤ) : dec (enc n) = n
theorem enc_dec (c : ℕ) : enc (dec c) = c
def encEquiv : ℤ ≃ ℕ where
toFun := enc
invFun := dec
left_inv := dec_enc
right_inv := enc_dec
def dec (c : ℕ) : ℤ := if c % 2 = 0 then ((c / 2 : ℕ) : ℤ) else -(((c + 1) / 2 : ℕ) : ℤ)
ZInQKernel/Compiler/Precision/Encoding.lean:19
def enc (n : ℤ) : ℕ := if 0 ≤ n then 2 * n.toNat else 2 * (-n).toNat - 1
ZInQKernel/Compiler/Precision/Encoding.lean:16
theorem dec_enc (n : ℤ) : dec (enc n) = n
ZInQKernel/Compiler/Precision/Encoding.lean:40
theorem enc_dec (c : ℕ) : enc (dec c) = c
ZInQKernel/Compiler/Precision/Encoding.lean:44
Uses 1 · Used by 2
The local parameter \(z=-x/y\) is defined at multiples of \(P_0\) that are affine with nonzero ordinate; at such an index \(k\) it gives the components \(u_k,v_k\), the size \(\epsilon_k=|u_k|+|v_k|\), and the trace ratio \(r(a,j)\).
DefinitionThe local parameter z on multiples of the generator#✓
Let \(E:y^2=x^3+Ax\) over \(K_0\) with \(A=-d^2\), and \(P_0\) the fixed point.
- For an affine point \(P=(x,y)\in E(K_0)\) with \(y\ne0\) put \(z(P)=-x/y\in K_0\). Such a point has \(x\ne0\) (if \(x=0\) then \(y^2=0\)), so \(z(P)\ne0\); and \(z(-P)=-z(P)\).
- An index \(k\in\mathbb Z\) is admissible if \([k]P_0\) is an affine point with nonzero ordinate. For admissible \(k\) write $\(z_k=z([k]P_0)=u_k+v_ks\quad(u_k,v_k\in\mathbb Q),\qquad \epsilon_k=|u_k|+|v_k|>0 .\)$
- For admissible \(a\) and \(j\) put $\(r(a,j)=\tfrac12\operatorname{Tr}_{K_0/\mathbb Q}\frac{z_j}{z_a}\in\mathbb Q,\)$ the rational component of \(z_j/z_a\).
This is a definition. The manuscript defines \(z\) on nonzero multiples of \(P_0\), where it is well defined because \(P_0\) has infinite order (no nonzero multiple is the identity or a point of order two); admissibility makes this explicit, so that the precision relation and its computation do not depend on the generator theorem.
noncomputable def zPt : genCurve.toAffine.Point → K0
| .zero => 0
| .some x y _ => -x / y
theorem zPt_ne_zero {x y : K0} (h : genCurve.toAffine.Nonsingular x y) (hy : y ≠ 0) :
zPt (.some x y h) ≠ 0
def Admissible (k : ℤ) : Prop :=
∃ (x y : K0) (h : genCurve.toAffine.Nonsingular x y), k • genP0 = .some x y h ∧ y ≠ 0
def genCurve : WeierstrassCurve K0 where
a₁ := 0
a₂ := 0
a₃ := 0
a₄ := -genD ^ 2
a₆ := 0
ZInQKernel/Hypotheses/MordellWeil.lean:34
abbrev K0 : Type := QuadraticAlgebra ℚ 2 0
ZInQKernel/Hypotheses/MordellWeil.lean:25
noncomputable def zPt : genCurve.toAffine.Point → K0
| .zero => 0
| .some x y _ => -x / y
ZInQKernel/Compiler/Precision/ZCoordinate.lean:23
def genP0 : genCurve.toAffine.Point := Point.mk genP0_equation
ZInQKernel/Model/Field/Curve.lean:118
Uses 3 · Used by 5
The precision exponent uses the six-contact constant for the primes up to \(324\), written as an explicit natural-number expression; it is never evaluated.
DefinitionThe precision height constant#✓
The following natural numbers are defined by their displayed expressions and are never evaluated: $\(\begin{aligned} F_0&=324!, & D&=F_0\,3^{256F_0^4}, & G_0&=116064000000, & E_0&=10(DG_0)^2,\\ Q_0&=D^{DE_0}, & B_{\rm cm}&=D^2\,3^{21000D^2}+1, & C_{\rm cm}&=2B_{\rm cm}+4096(1028+5D+84000D^2), \end{aligned}\)$ $\(A^{(0)}_{\rm ht}=2\cdot10^{13}\cdot\max\bigl(1,\ C_{\rm cm},\ Q_0^{17}\bigr).\)$ With \(F(u)=u(u+15)(u+20)(u+24)(u+30)(u+60)\) and \(\mathcal C=\{0,-15,-20,-24,-30,-60\}\), the precision bound of \((n,\kappa)\in\mathbb Z^2\) is the natural number $\(\mathcal B(n,\kappa)=A^{(0)}_{\rm ht}\,|\kappa F(n)|^{24}.\)$
This is a definition. \(A^{(0)}_{\rm ht}\) is the six-contact constant \(H_6(S_{\rm ht})\) for \(S_{\rm ht}=\{p\le324\}\); the identification is a separate statement. Its symbol \(F_0\) is distinct from the polynomial \(F\).
noncomputable def Q0 : ℕ := qFn heightD heightE0
noncomputable def A0 : ℕ := h6Fn heightCcm Q0
def sixF (u : ℤ) : ℤ := u * (u + 15) * (u + 20) * (u + 24) * (u + 30) * (u + 60)
def qFn (d e : ℕ) : ℕ := d ^ (d * e)
ZInQKernel/Compiler/Precision/HeightConstant.lean:45
noncomputable def heightD : ℕ := heightF0 * 3 ^ (256 * heightF0 ^ 4)
ZInQKernel/Hypotheses/Height.lean:133
noncomputable def heightE0 : ℕ := 10 * (heightD * heightG0) ^ 2
ZInQKernel/Hypotheses/Height.lean:139
def h6Fn (c q : ℕ) : ℕ := 2 * 10 ^ 13 * max 1 (max c (q ^ 17))
ZInQKernel/Compiler/Precision/HeightConstant.lean:48
noncomputable def heightCcm : ℕ := 2 * heightBcm + 4096 * (1028 + 5 * heightD + 84000 * heightD ^ 2)
ZInQKernel/Hypotheses/Height.lean:145
noncomputable def Q0 : ℕ := qFn heightD heightE0
ZInQKernel/Compiler/Precision/HeightConstant.lean:76
TheoremThe precision constant is the six-contact constant#✓
Let \(S_{\rm ht}\) be the set of primes at most \(324\). Then \(\max(D,\max S_{\rm ht},10^{12})=D\), and the six-contact constant at this argument is the precision constant: $\(H_6(S_{\rm ht})=H_6(S_{\rm ht};D)=2\cdot10^{13}\max(1,C_{\rm cm},Q_D^{17})=A^{(0)}_{\rm ht},\)$ where \(Q_D=D^{DE_0}\) is computed as a real power. Consequently, for all \((n,\kappa)\in\mathbb Z^2\), \(\mathcal B(n,\kappa)=H_6(S_{\rm ht})\,|\kappa F(n)|^{24}\) is the bound \(B(n,\kappa)\) of the ordinary-value relation, and \(R=D\) is an admissible argument of the six-contact estimate for \(S_{\rm ht}\).
Proof sketch. \(\max S_{\rm ht}=317\), and \(D\ge F_0=324!>10^{12}\), so the maximum is \(D\) (no evaluation of \(D\) is needed: \(324!\ge10^{12}\) is a small finite check, for instance \(324!\ge20!>10^{12}\)). The real power \(D^{D E_0}\) with natural base and natural exponent equals the natural power, so \(Q_D=Q_0\), and the remaining expressions agree term by term.
theorem A0_eq_heightH6 : (A0 : ℝ) = heightH6 (heightD : ℝ)
theorem max_heightD_heightPrimes :
max (heightD : ℝ) (max ((heightPrimes.sup id : ℕ) : ℝ) ((10 : ℝ) ^ 12)) = heightD
theorem bound_eq_heightH6 (n κ : ℤ) :
(bound n κ : ℝ) = heightH6 (heightD : ℝ) * |((κ * sixF n : ℤ) : ℝ)| ^ 24
noncomputable def A0 : ℕ := h6Fn heightCcm Q0
ZInQKernel/Compiler/Precision/HeightConstant.lean:79
noncomputable def heightH6 (R : ℝ) : ℝ :=
2 * 10 ^ 13 * max 1 (max (heightCcm : ℝ) (heightQ R ^ 17))
ZInQKernel/Hypotheses/Height.lean:152
noncomputable def heightD : ℕ := heightF0 * 3 ^ (256 * heightF0 ^ 4)
ZInQKernel/Hypotheses/Height.lean:133
def heightPrimes : Finset ℕ := (Finset.range 325).filter Nat.Prime
ZInQKernel/Compiler/Precision/HeightConstant.lean:116
noncomputable def bound (n κ : ℤ) : ℕ := A0 * (κ * sixF n).natAbs ^ 24
ZInQKernel/Compiler/Precision/HeightConstant.lean:89
def sixF (u : ℤ) : ℤ := u * (u + 15) * (u + 20) * (u + 24) * (u + 30) * (u + 60)
ZInQKernel/Compiler/Precision/HeightConstant.lean:86
The relation itself consists of the early tests, admissibility, and two strict tests. Given that \(P_0\) has infinite order, admissibility follows from the early tests; the model chapter proves this unconditionally (nonzero multiples of the generator).
DefinitionThe precision relation#✓
For \(c\in\mathbb N^5\) let \((n,\kappa,a,l,j)\in\mathbb Z^5\) be its signed decoding. The precision relation \(\operatorname{accepts}(c)\) holds if and only if all of the following hold:
- (early tests) \(n\notin\mathcal C=\{0,-15,-20,-24,-30,-60\}\), \(\kappa\ne0\), \(a\ge1\), \(l\ge1\) and \(j=na\);
- (admissibility) \(l\), \(a\) and \(j\) are admissible indices;
- (closeness) \(|r(a,j)-n|<\epsilon_l\);
- (precision) \(4\epsilon_l<4^{-\mathcal B(n,\kappa)}\), that is \(4\,\epsilon_l\cdot4^{\mathcal B(n,\kappa)}<1\), with \(\mathcal B(n,\kappa)=A^{(0)}_{\rm ht}|\kappa F(n)|^{24}\).
Both final tests are strict inequalities between rational numbers (equivalently, between real numbers). This is the predicate called \(\operatorname{accepts\_naturals}\) in equation (C.4).
This is a definition. Item 2 is implicit in the manuscript, which defines \(z\) only on nonzero multiples of \(P_0\); given the generator theorem it follows from item 1, so the relation is the manuscript's on every input where the latter is meaningful.
def accepts (c : Fin 5 → ℕ) : Prop :=
acceptsInt (dec (c 0)) (dec (c 1)) (dec (c 2)) (dec (c 3)) (dec (c 4))
def acceptsInt (n κ a l j : ℤ) : Prop :=
EarlyTestsInt n κ a l j ∧ (Admissible l ∧ Admissible a ∧ Admissible j) ∧
CloseTestInt n a l j ∧ PrecisionTestInt n κ l
theorem accepts_iff (c : Fin 5 → ℕ) :
accepts c ↔
(dec (c 0) ∉ contacts ∧ dec (c 1) ≠ 0 ∧ 1 ≤ dec (c 2) ∧ 1 ≤ dec (c 3) ∧
dec (c 4) = dec (c 0) * dec (c 2)) ∧
(Admissible (dec (c 3)) ∧ Admissible (dec (c 2)) ∧ Admissible (dec (c 4))) ∧
|rRatio (dec (c 2)) (dec (c 4)) - dec (c 0)| < epsIdx (dec (c 3)) ∧
4 * epsIdx (dec (c 3)) * 4 ^ bound (dec (c 0)) (dec (c 1)) < 1
def acceptsInt (n κ a l j : ℤ) : Prop :=
EarlyTestsInt n κ a l j ∧ (Admissible l ∧ Admissible a ∧ Admissible j) ∧
CloseTestInt n a l j ∧ PrecisionTestInt n κ l
ZInQKernel/Compiler/Precision/Relation.lean:33
def dec (c : ℕ) : ℤ := if c % 2 = 0 then ((c / 2 : ℕ) : ℤ) else -(((c + 1) / 2 : ℕ) : ℤ)
ZInQKernel/Compiler/Precision/Encoding.lean:19
def EarlyTestsInt (n κ a l j : ℤ) : Prop :=
n ∉ contacts ∧ κ ≠ 0 ∧ 1 ≤ a ∧ 1 ≤ l ∧ j = n * a
ZInQKernel/Compiler/Precision/Relation.lean:23
def Admissible (k : ℤ) : Prop :=
∃ (x y : K0) (h : genCurve.toAffine.Nonsingular x y), k • genP0 = .some x y h ∧ y ≠ 0
ZInQKernel/Compiler/Precision/ZCoordinate.lean:56
def CloseTestInt (n a l j : ℤ) : Prop := |rRatio a j - n| < epsIdx l
ZInQKernel/Compiler/Precision/Relation.lean:27
def PrecisionTestInt (n κ l : ℤ) : Prop := 4 * epsIdx l * 4 ^ bound n κ < 1
ZInQKernel/Compiler/Precision/Relation.lean:30
def accepts (c : Fin 5 → ℕ) : Prop :=
acceptsInt (dec (c 0)) (dec (c 1)) (dec (c 2)) (dec (c 3)) (dec (c 4))
ZInQKernel/Compiler/Precision/Relation.lean:44
def contacts : Finset ℤ := {0, -15, -20, -24, -30, -60}
ZInQKernel/Compiler/Precision/HeightConstant.lean:92
noncomputable def rRatio (a j : ℤ) : ℚ := (zIdx j / zIdx a).re
ZInQKernel/Compiler/Precision/ZCoordinate.lean:66
noncomputable def epsIdx (k : ℤ) : ℚ := |(zIdx k).re| + |(zIdx k).im|
ZInQKernel/Compiler/Precision/ZCoordinate.lean:63
noncomputable def bound (n κ : ℤ) : ℕ := A0 * (κ * sixF n).natAbs ^ 24
ZInQKernel/Compiler/Precision/HeightConstant.lean:89
Uses 3 · Used by 9
TheoremAdmissibility of nonzero indices#✓
Assume \(P_0\) has infinite order in \(E(K_0)\). Then every \(k\in\mathbb Z\setminus\{0\}\) is admissible. Consequently, for \(c\in\mathbb N^5\) passing the early tests of the precision relation, the indices \(l,a,j\) are admissible, and \(\operatorname{accepts}(c)\) holds if and only if the closeness and precision tests hold.
Proof sketch. For \(k\ne0\), \([k]P_0\ne O\) since \(P_0\) has infinite order. If its ordinate were \(0\) then \([k]P_0=-[k]P_0\), so \([2k]P_0=O\) with \(2k\ne0\), again impossible. For inputs passing the early tests, \(l,a\ge1\) and \(j=na\ne0\) because \(n\ne0\) (\(0\in\mathcal C\)) and \(a\ne0\).
theorem admissible_of_ne_zero {k : ℤ} (hk : k ≠ 0) : Admissible k
theorem accepts_iff_tests (c : Fin 5 → ℕ) (hc : EarlyTests c) :
accepts c ↔
CloseTestInt (dec (c 0)) (dec (c 2)) (dec (c 3)) (dec (c 4)) ∧
PrecisionTestInt (dec (c 0)) (dec (c 1)) (dec (c 3))
def Admissible (k : ℤ) : Prop :=
∃ (x y : K0) (h : genCurve.toAffine.Nonsingular x y), k • genP0 = .some x y h ∧ y ≠ 0
ZInQKernel/Compiler/Precision/ZCoordinate.lean:56
def EarlyTests (c : Fin 5 → ℕ) : Prop :=
EarlyTestsInt (dec (c 0)) (dec (c 1)) (dec (c 2)) (dec (c 3)) (dec (c 4))
ZInQKernel/Compiler/Precision/Relation.lean:38
def accepts (c : Fin 5 → ℕ) : Prop :=
acceptsInt (dec (c 0)) (dec (c 1)) (dec (c 2)) (dec (c 3)) (dec (c 4))
ZInQKernel/Compiler/Precision/Relation.lean:44
def CloseTestInt (n a l j : ℤ) : Prop := |rRatio a j - n| < epsIdx l
ZInQKernel/Compiler/Precision/Relation.lean:27
def dec (c : ℕ) : ℤ := if c % 2 = 0 then ((c / 2 : ℕ) : ℤ) else -(((c + 1) / 2 : ℕ) : ℤ)
ZInQKernel/Compiler/Precision/Encoding.lean:19
def PrecisionTestInt (n κ l : ℤ) : Prop := 4 * epsIdx l * 4 ^ bound n κ < 1
ZInQKernel/Compiler/Precision/Relation.lean:30
Informally uses
Sources
Uses 2 · Informal links 1
Exact evaluation
The second strict test compares \(\epsilon_l=U/V\) with \(4^{-\mathcal B}\); it becomes an integer comparison with the finite cap \(L=\lfloor(V-1)/(4U)\rfloor\). Saturating every operation at \(L+1\) computes the comparison exactly without evaluating \(\mathcal B\).
TheoremThe precision threshold as an integer comparison#✓
Let \(U,V\) be positive natural numbers, \(\epsilon=U/V\), and \(B\in\mathbb N\). Then $\(4\epsilon<4^{-B}\iff4U\cdot4^B<V\iff4^B\le\left\lfloor\frac{V-1}{4U}\right\rfloor .\)$
Proof sketch. Multiply by the positive number \(V4^B\) for the first equivalence. For the second, for positive \(a\) and \(D\) and natural \(x\), \(ax<D\iff ax\le D-1\iff x\le\lfloor(D-1)/a\rfloor\), applied with \(a=4U\), \(x=4^B\), \(D=V\).
theorem four_eps_lt_iff_nat (U V B : ℕ) (hV : 0 < V) :
4 * ((U : ℚ) / V) < ((4 : ℚ) ^ B)⁻¹ ↔ 4 * U * 4 ^ B < V
theorem four_eps_lt_iff (U V B : ℕ) (hU : 0 < U) (hV : 0 < V) :
4 * ((U : ℚ) / V) < ((4 : ℚ) ^ B)⁻¹ ↔ 4 ^ B ≤ (V - 1) / (4 * U)
theorem four_eps_mul_pow_lt_one_iff (U V B : ℕ) (hU : 0 < U) (hV : 0 < V) :
4 * ((U : ℚ) / V) * 4 ^ B < 1 ↔ 4 ^ B ≤ (V - 1) / (4 * U)
Used by 1
TheoremSaturated arithmetic#✓
For \(L\in\mathbb N\) let \(\sigma_L(x)=\min(x,L+1)\) on \(\mathbb N\). For all natural \(x,y,n\):
- \(\sigma_L(x)\le L\iff x\le L\), and more generally \(\sigma_L(x)\le k\iff x\le k\) for \(k\le L\); \(\sigma_L(\sigma_L(x))=\sigma_L(x)\); \(\sigma_L(0)=0\), \(\sigma_L(1)=1\);
- \(\sigma_L(\sigma_L(x)+\sigma_L(y))=\sigma_L(x+y)\), \(\sigma_L(\sigma_L(x)\cdot\sigma_L(y))=\sigma_L(xy)\) and \(\sigma_L(\max(\sigma_L(x),\sigma_L(y)))=\sigma_L(\max(x,y))\);
- \(\sigma_L(\sigma_L(x)^n)=\sigma_L(x^n)\);
- if \(L\ge1\), then \(\sigma_L(x^{\sigma_L(n)})=\sigma_L(x^n)\), hence \(\sigma_L(\sigma_L(x)^{\sigma_L(n)})=\sigma_L(x^n)\);
- \(\sigma_L((n+1)!)=\sigma_L(\sigma_L(n!)\cdot(n+1))\), so factorials are computed exactly by iterating saturated multiplication.
Item 4 is where bases zero and one and exponent zero are separate cases: for \(x\ge2\) an exponent above \(L\) already gives \(x^n>L\).
Proof sketch. Items 1-3 and 5 by cases on whether the arguments exceed \(L\): if \(x\ge L+1\) and \(y\ge1\) then \(xy\ge L+1\), and \(\sigma_L(x)\cdot y\ge L+1\); if \(y=0\) both sides are \(0\); item 3 by induction on \(n\) from item 2. Item 4: if \(n\le L+1\) nothing changes; otherwise \(\sigma_L(n)=L+1\) and, for \(x=0\), \(0^n=0^{L+1}=0\) (both exponents positive), for \(x=1\) both powers are \(1\), and for \(x\ge2\) both \(x^n\) and \(x^{L+1}\) exceed \(L\) because \(x^e>e\) for \(e\ge0\).
theorem saturatedArithmetic (L : ℕ) :
(∀ x, saturate L x ≤ L ↔ x ≤ L) ∧ (∀ x k, k ≤ L → (saturate L x ≤ k ↔ x ≤ k)) ∧
(∀ x, saturate L (saturate L x) = saturate L x) ∧ saturate L 0 = 0 ∧ saturate L 1 = 1 ∧
(∀ x y, saturate L (saturate L x + saturate L y) = saturate L (x + y)) ∧
(∀ x y, saturate L (saturate L x * saturate L y) = saturate L (x * y)) ∧
(∀ x y, saturate L (max (saturate L x) (saturate L y)) = saturate L (max x y)) ∧
(∀ x n, saturate L (saturate L x ^ n) = saturate L (x ^ n)) ∧
(1 ≤ L → ∀ x n, saturate L (x ^ saturate L n) = saturate L (x ^ n)) ∧
(1 ≤ L → ∀ x n, saturate L (saturate L x ^ saturate L n) = saturate L (x ^ n)) ∧
(∀ n, saturate L (n + 1).factorial = saturate L (saturate L n.factorial * (n + 1)))
@[expose] def saturate (L x : Nat) : Nat := min x (L + 1)
lean/ZInQ/PrecisionArithmetic.lean:36
Used by 2
TheoremCapped multiplication and binary exponentiation#✓
For \(L\in\mathbb N\) define capped multiplication by \(\mathrm{cmul}_L(a,b)=0\) if \(a=0\) or \(b=0\), \(L+1\) if \(a>\lfloor L/b\rfloor\), and \(ab\) otherwise; and capped binary exponentiation \(\mathrm{cpow}_L(x,e)\) by: \(1\) if \(e=0\); \(x\) if \(x\le1\); otherwise run the loop with state \((\beta,e,\pi)\) starting from \((x,e,1)\): if \(e=0\) return \(\pi\); if \(\beta>L\) return \(L+1\); put \(\pi'=\mathrm{cmul}_L(\pi,\beta)\) if \(e\) is odd and \(\pi'=\pi\) otherwise; if \(e\) is odd and \(\pi'=L+1\) return \(L+1\); if \(\lfloor e/2\rfloor=0\) return \(\pi'\); else continue with \((\mathrm{cmul}_L(\beta,\beta),\lfloor e/2\rfloor,\pi')\). Then for all natural \(L,a,b,x,e\): $\(\mathrm{cmul}_L(a,b)=\sigma_L(ab),\qquad\mathrm{cpow}_L(x,e)=\sigma_L(x^e),\)$ and \(\mathrm{cpow}_L(x,e)\le L\iff x^e\le L\). The loop terminates because \(e\) halves.
Proof sketch. For \(b>0\), \(a>\lfloor L/b\rfloor\iff ab>L\). For the loop, prove by strong induction on \(e\) the invariant \(\mathrm{loop}(\beta,e,\pi)=\sigma_L(\pi\beta^e)\) for \(\beta\ge1\), \(1\le\pi\le L+1\), using \(\beta^e=\beta^{e\bmod2}(\beta^2)^{\lfloor e/2\rfloor}\) and the saturation identities; the early returns are justified because \(\beta>L\) or \(\pi'=L+1\) force \(\sigma_L(\pi\beta^e)=L+1\). The initial cases are \(x^0=1\), \(0^e=0\), \(1^e=1\) for \(e>0\).
theorem cappedArithmetic (L : ℕ) :
(∀ a b, cappedMul L a b = saturate L (a * b)) ∧
(∀ x e, cappedPower L x e = saturate L (x ^ e)) ∧
(∀ x e, cappedPower L x e ≤ L ↔ x ^ e ≤ L)
@[expose] def cappedMul (L a b : Nat) : Nat :=
if a = 0 ∨ b = 0 then 0
else if a > L / b then L + 1 else a * b
lean/ZInQ/PrecisionAlgorithms.lean:37
@[expose] def saturate (L x : Nat) : Nat := min x (L + 1)
lean/ZInQ/PrecisionArithmetic.lean:36
@[expose] def cappedPower (L base exponent : Nat) : Nat :=
if exponent = 0 then 1
else if base ≤ 1 then base
else cappedPowerLoop L base exponent 1
lean/ZInQ/PrecisionAlgorithms.lean:81
Uses 1 · Used by 2
TheoremThe capped precision test#✓
Expressions. Natural-number expressions are built from natural literals with \(+\), \(\cdot\), \(\max\), powers \(e_1^{e_2}\) and factorials \(e!\); \([\![e]\!]\in\mathbb N\) is the value. For \(L\in\mathbb N\) the capped value \(\langle e\rangle_L\) is defined by recursion on \(e\): \(\langle c\rangle_L=\sigma_L(c)\) for a literal \(c\); \(\langle e_1+e_2\rangle_L=\sigma_L(\langle e_1\rangle_L+\langle e_2\rangle_L)\); \(\langle e_1\cdot e_2\rangle_L=\mathrm{cmul}_L(\langle e_1\rangle_L,\langle e_2\rangle_L)\); \(\langle\max(e_1,e_2)\rangle_L=\sigma_L(\max(\langle e_1\rangle_L,\langle e_2\rangle_L))\); \(\langle e_1^{e_2}\rangle_L=\mathrm{cpow}_L(\langle e_1\rangle_L,\langle e_2\rangle_L)\); and \(\langle e!\rangle_L=f_L(\langle e\rangle_L)\), where \(f_L(0)=1\) and \(f_L(n+1)=\mathrm{cmul}_L(f_L(n),\sigma_L(n+1))\) (a loop of \(n\) capped multiplications).
The precision expressions. Let \(e_A\) be the expression of the precision height constant written with the literals displayed there: \(e_{F_0}=324!\), \(e_D=e_{F_0}\cdot3^{256\cdot e_{F_0}^4}\), \(e_{G_0}=116064000000\), \(e_{E_0}=10\cdot(e_D\cdot e_{G_0})^2\), \(e_{Q_0}=e_D^{\,e_D\cdot e_{E_0}}\), \(e_{B}=e_D^2\cdot3^{21000\cdot e_D^2}+1\), \(e_{C}=2\cdot e_B+4096\cdot(1028+5\cdot e_D+84000\cdot e_D^2)\) and \(e_A=2\cdot10^{13}\cdot\max(1,\max(e_C,e_{Q_0}^{17}))\) (here \(10^{13}\) is the literal \(10000000000000\)). So \([\![e_A]\!]=A^{(0)}_{\rm ht}\).
Let \(L\ge1\) and \(M\in\mathbb N\). Put $\(\beta=\mathrm{cmul}_L\bigl(\langle e_A\rangle_L,\ \mathrm{cpow}_L(\sigma_L(M),24)\bigr)\)$ and run the division-by-four loop: \(x_0=L\), \(x_{i+1}=\lfloor x_i/4\rfloor\), stopping after \(\beta\) steps. Then:
- \(\langle e\rangle_L=\sigma_L([\![e]\!])\) for every expression \(e\); in particular \(\langle e_A\rangle_L=\sigma_L(A^{(0)}_{\rm ht})\);
- \(\beta=\sigma_L(A^{(0)}_{\rm ht}M^{24})\);
- \(x_\beta=\lfloor L/4^\beta\rfloor\), and \(x_\beta\ge1\iff4^{A^{(0)}_{\rm ht}M^{24}}\le L\).
Moreover \(\beta\le L+1\), so the loop takes at most \(L+1\) steps, and every capped value \(\langle e\rangle_L\) is at most \(L+1\): nothing astronomically large is computed.
Proof sketch. (1) Induction on \(e\). Literals by definition. For \(+\), \(\max\): the saturation identities \(\sigma_L(\sigma_L(x)+\sigma_L(y))=\sigma_L(x+y)\) and the same for \(\max\). For \(\cdot\): \(\mathrm{cmul}_L(a,b)=\sigma_L(ab)\), then \(\sigma_L(\sigma_L(x)\sigma_L(y))=\sigma_L(xy)\). For powers: \(\mathrm{cpow}_L(a,b)=\sigma_L(a^b)\) and \(\sigma_L(\sigma_L(x)^{\sigma_L(n)})=\sigma_L(x^n)\), which needs \(L\ge1\). For factorials: by induction on \(n\), \(f_L(n)=\sigma_L(n!)\) (item 5 of the saturation statement), and \(f_L(\sigma_L(n))=\sigma_L(n!)\) because for \(n\ge L+1\) both \(n!\) and \((L+1)!\) are at least \(L+1\). (2) By (1), the capped power and the capped product, \(\beta=\sigma_L(\sigma_L(A^{(0)}_{\rm ht})\cdot\sigma_L(M^{24}))=\sigma_L(A^{(0)}_{\rm ht}M^{24})\). (3) \(\lfloor\lfloor x/4\rfloor/4^i\rfloor=\lfloor x/4^{i+1}\rfloor\) gives \(x_i=\lfloor L/4^i\rfloor\), and \(\lfloor L/4^\beta\rfloor\ge1\iff4^\beta\le L\). Put \(B=A^{(0)}_{\rm ht}M^{24}\). If \(B\le L\) then \(\beta=B\). Otherwise \(\beta=L+1\), and both \(4^{L+1}\le L\) and \(4^B\le L\) are false, since \(4^x>x\) for every \(x\) and \(B>L\).
theorem NExpr.capped_eq (L : ℕ) (hL : 1 ≤ L) (e : NExpr) : e.capped L = saturate L e.eval
theorem cappedBound_eq (L M : ℕ) (hL : 1 ≤ L) : cappedBound L M = saturate L (A0 * M ^ 24)
theorem precision_test_iff (L M : ℕ) (hL : 1 ≤ L) :
1 ≤ divFourLoop L (cappedBound L M) ↔ 4 ^ (A0 * M ^ 24) ≤ L
inductive NExpr
| lit (c : ℕ)
| add (a b : NExpr)
| mul (a b : NExpr)
| max (a b : NExpr)
| pow (a b : NExpr)
| fact (a : NExpr)
deriving DecidableEq, Repr
ZInQKernel/Compiler/Precision/CappedTest.lean:22
@[expose] def saturate (L x : Nat) : Nat := min x (L + 1)
lean/ZInQ/PrecisionArithmetic.lean:36
def cappedBound (L M : ℕ) : ℕ :=
cappedMul L (NExpr.eA.capped L) (cappedPower L (saturate L M) 24)
ZInQKernel/Compiler/Precision/CappedTest.lean:158
noncomputable def A0 : ℕ := h6Fn heightCcm Q0
ZInQKernel/Compiler/Precision/HeightConstant.lean:79
def divFourLoop (x : ℕ) : ℕ → ℕ
| 0 => x
| β + 1 => divFourLoop (x / 4) β
ZInQKernel/Compiler/Precision/CappedTest.lean:162
Uses 3 · Used by 3
Field divisions are guarded by the norm, which vanishes only at zero. Points are handled in Jacobian coordinates over \(\mathbb Z[s]\), with explicit identities for doubling and addition and their exceptional branches, and a finite check that the fixed projective point is \(P_0\); scalar multiplication halves its counter.
TheoremElements of norm zero#✓
For \(u,v\in\mathbb Q\), if \(u^2-2v^2=0\) then \(u=v=0\). Equivalently, an element \(z\) of \(K_0\) with \(\operatorname N(z)=0\) is zero, and for \(Y\in\mathbb Z[s]\) with \(Y\ne0\) the integer \(\operatorname N(Y)=Y\bar Y\) is nonzero. Hence every division by an element of \(K_0\) in the precision computation can be guarded by the exact test \(\operatorname N\ne0\) on integer components.
Proof sketch. If \(v\ne0\) then \((u/v)^2=2\), contradicting the irrationality of \(\sqrt2\). Equivalently, after clearing denominators a primitive integer solution of \(a^2=2b^2\) has \(a\) even, then \(b\) even, a contradiction. So \(v=0\) and then \(u=0\).
theorem rat_eq_zero_of_sq_sub_two_sq {u v : ℚ} (h : u ^ 2 - 2 * v ^ 2 = 0) : u = 0 ∧ v = 0
theorem intNorm_ne_zero {g h : ℤ} (hne : (g, h) ≠ (0, 0)) : g ^ 2 - 2 * h ^ 2 ≠ 0
Uses 1 · Used by 1
TheoremJacobian formulas on the weighted model#✓
Let \(R\) be a commutative ring and \(A\in R\); write \(\mathcal E(X,Y,Z)=Y^2-X^3-AXZ^4\). Define the Jacobian doubling and addition $\(\mathrm{dbl}(X,Y,Z)=(M^2-2S,\ M(S-X_3)-8Y^4,\ 2YZ),\quad M=3X^2+AZ^4,\ S=4XY^2,\ X_3=M^2-2S,\)$ and, for \(P_1=(X_1,Y_1,Z_1)\), \(P_2=(X_2,Y_2,Z_2)\), with \(U_1=X_1Z_2^2\), \(U_2=X_2Z_1^2\), \(S_1=Y_1Z_2^3\), \(S_2=Y_2Z_1^3\), \(H=U_2-U_1\), \(\Lambda=S_2-S_1\), $\(\mathrm{add}(P_1,P_2)=\bigl(\Lambda^2-H^3-2U_1H^2,\ \Lambda(U_1H^2-X_3)-S_1H^3,\ HZ_1Z_2\bigr),\)$ \(X_3\) being the first coordinate. Then the following polynomial identities hold:
- \(\mathcal E(\mathrm{dbl}(X,Y,Z))\) lies in the ideal generated by \(\mathcal E(X,Y,Z)\);
- \(\mathcal E(\mathrm{add}(P_1,P_2))\) lies in the ideal generated by \(\mathcal E(P_1)\) and \(\mathcal E(P_2)\);
- for doubling over a field of characteristic \(\ne2\) with \(YZ\ne0\), with \(x=X/Z^2\), \(y=Y/Z^3\) and \(\lambda=(3x^2+A)/(2y)=M/Z_3\) where \(Z_3=2YZ\): \(X_3/Z_3^2=\lambda^2-2x\), by the identity \(X_3=M^2-2xZ_3^2\) (as \(xZ_3^2=4XY^2=S\));
- \(Y_3/Z_3^3=\lambda(x-X_3/Z_3^2)-y\) for doubling, by the identity \(Y_3=M(XZ_3^2/Z^2-X_3)-8Y^4\) with \(Z_3^2/Z^2=4Y^2\);
- for addition over a field with \(Z_1Z_2H\ne0\), with \(x_i=X_i/Z_i^2\), \(y_i=Y_i/Z_i^3\) and \(\lambda=(y_2-y_1)/(x_2-x_1)=\Lambda/Z_3\): \(X_3/Z_3^2=\lambda^2-x_1-x_2\), by the identity \(X_3=\Lambda^2-H^2(U_1+U_2)\) and \((x_1+x_2)Z_3^2=(U_1+U_2)H^2\);
- \(Y_3/Z_3^3=\lambda(x_1-X_3/Z_3^2)-y_1\) for addition, by \(x_1Z_3^2=U_1H^2\) and \(y_1Z_3^3=S_1H^3\);
- (equal abscissas) over a field with \(Z_1Z_2\ne0\): \(H=0\iff x_1=x_2\), and then \(\Lambda=0\iff y_1=y_2\); for points of the curve over a field of characteristic \(\ne2\), the sum is the doubling if \(\Lambda=0\) and the identity \(O\) otherwise (opposite points);
- (zero ordinate) over a field of characteristic \(\ne2\), if \(Y=0\) and \(Z\ne0\) the point has order two and its double is \(O\); negation is \((X,Y,Z)\mapsto(X,-Y,Z)\).
Together these say that the Jacobian formulas, with the branches 7 and 8 and \(Z=0\) for \(O\), compute the chord-and-tangent law of \(E\) on representatives. They are polynomial identities, independent of the generator theorem. That the fixed projective point is the affine \(P_0\) is the separate finite check on the fixed Jacobian point.
The manuscript reports nine polynomial identities for the nonexceptional projective formulas and the preservation of \(Y^2=X^3+AXZ^4\) without listing them; the list above is the set this chapter uses.
Proof sketch. Items 1-6 are identities in polynomial rings over \(\mathbb Z\), checked by ring normalization (items 1 and 2 with explicit cofactors, found by polynomial division by \(\mathcal E\)). Item 7: \(U_1=U_2\) iff \(x_1=x_2\) after dividing by \(Z_1^2Z_2^2\), and likewise for \(S_i\); on the curve, equal abscissas give \(y_2=\pm y_1\). Item 8 is \(-(x,0)=(x,0)\).
theorem curveE_jdbl (A : R) (P : JTriple R) : curveE A (jdbl A P) = 64 * P.Y ^ 6 * curveE A P
theorem curveE_jadd (A : R) (P Q : JTriple R) :
curveE A (jadd P Q) = addCofactor₁ A P Q * curveE A P + addCofactor₂ A P Q * curveE A Q
theorem jdbl_affine (A : F) (P : JTriple F) (h2 : (2 : F) ≠ 0) (hY : P.Y ≠ 0) (hZ : P.Z ≠ 0) :
let x := P.X / P.Z ^ 2
let y := P.Y / P.Z ^ 3
let l := (3 * x ^ 2 + A) / (2 * y)
(jdbl A P).Z ≠ 0 ∧ l = (3 * P.X ^ 2 + A * P.Z ^ 4) / (jdbl A P).Z ∧
(jdbl A P).X / (jdbl A P).Z ^ 2 = l ^ 2 - 2 * x ∧
(jdbl A P).Y / (jdbl A P).Z ^ 3 = l * (x - (jdbl A P).X / (jdbl A P).Z ^ 2) - y
@[ext] structure JTriple (R : Type*) where
X : R
Y : R
Z : R
deriving DecidableEq, Repr
ZInQKernel/Compiler/Precision/Jacobian.lean:22
def curveE (A : R) (P : JTriple R) : R := P.Y ^ 2 - P.X ^ 3 - A * P.X * P.Z ^ 4
ZInQKernel/Compiler/Precision/Jacobian.lean:35
def jdbl (A : R) (P : JTriple R) : JTriple R :=
let M := 3 * P.X ^ 2 + A * P.Z ^ 4
let S := 4 * P.X * P.Y ^ 2
let X3 := M ^ 2 - 2 * S
⟨X3, M * (S - X3) - 8 * P.Y ^ 4, 2 * P.Y * P.Z⟩
ZInQKernel/Compiler/Precision/Jacobian.lean:39
def jadd (P Q : JTriple R) : JTriple R :=
let U1 := P.X * Q.Z ^ 2
let S1 := P.Y * Q.Z ^ 3
let H := jH P Q
let Λ := jΛ P Q
let X3 := Λ ^ 2 - H ^ 3 - 2 * U1 * H ^ 2
⟨X3, Λ * (U1 * H ^ 2 - X3) - S1 * H ^ 3, H * P.Z * Q.Z⟩
ZInQKernel/Compiler/Precision/Jacobian.lean:52
def addCofactor₁ (A : R) (P Q : JTriple R) : R :=
Q.Z ^ 6 * (P.X * Q.Z ^ 2 - Q.X * P.Z ^ 2) ^ 3 *
(A * Q.X * P.Z ^ 6 * Q.Z ^ 4 - P.X ^ 3 * Q.Z ^ 6 + 3 * P.X * Q.X ^ 2 * P.Z ^ 4 * Q.Z ^ 2 -
Q.X ^ 3 * P.Z ^ 6 + P.Y ^ 2 * Q.Z ^ 6 - 2 * P.Y * Q.Y * P.Z ^ 3 * Q.Z ^ 3)
ZInQKernel/Compiler/Precision/Jacobian.lean:103
def addCofactor₂ (A : R) (P Q : JTriple R) : R :=
-(P.Z ^ 6 * (P.X * Q.Z ^ 2 - Q.X * P.Z ^ 2) ^ 3 *
(A * P.X * P.Z ^ 4 * Q.Z ^ 6 - P.X ^ 3 * Q.Z ^ 6 + 3 * P.X ^ 2 * Q.X * P.Z ^ 2 * Q.Z ^ 4 -
Q.X ^ 3 * P.Z ^ 6 - 2 * P.Y * Q.Y * P.Z ^ 3 * Q.Z ^ 3 + Q.Y ^ 2 * P.Z ^ 6))
ZInQKernel/Compiler/Precision/Jacobian.lean:109
Uses 1 · Used by 1
TheoremThe fixed Jacobian point#✓
In \(\mathbb Z[s]\), \(s^2=2\), with \(A=-11243+7950s\), the triple $\((X_0,Y_0,Z_0)=(3282-2320s,\ -247440+174966s,\ 4)\)$ satisfies \(Y_0^2=X_0^3+AX_0Z_0^4\), and in \(K_0\) $\(\frac{X_0}{Z_0^2}=\frac{3282-2320s}{16}=\frac{1641-1160s}{8}=x(P_0),\qquad \frac{Y_0}{Z_0^3}=\frac{-247440+174966s}{64}=\frac{-123720+87483s}{32}=y(P_0).\)$ So the fixed projective point of the precision computation is the affine point \(P_0\).
This is a finite computation on six explicit integers: both sides of the curve equation equal \(122452755912-86587174080s\), and the two quotients are the displayed coordinates of \(P_0\) (\(3282=2\cdot1641\), \(2320=2\cdot1160\), \(247440=2\cdot123720\), \(174966=2\cdot87483\), \(Z_0^2=16\), \(Z_0^3=64\)). It does not use the generator theorem.
theorem curveE_P0J : curveE Acoef P0J = 0
theorem P0J_affine :
Zs.toK0 P0J.X / Zs.toK0 P0J.Z ^ 2 = genX0 ∧ Zs.toK0 P0J.Y / Zs.toK0 P0J.Z ^ 3 = genY0
theorem rep_P0J : Rep (-genD ^ 2) (P0J.map Zs.toK0) genP0
def curveE (A : R) (P : JTriple R) : R := P.Y ^ 2 - P.X ^ 3 - A * P.X * P.Z ^ 4
ZInQKernel/Compiler/Precision/Jacobian.lean:35
def Acoef : Zs := ⟨-11243, 7950⟩
ZInQKernel/Compiler/Precision/JacobianGenerator.lean:20
def P0J : JTriple Zs := ⟨⟨3282, -2320⟩, ⟨-247440, 174966⟩, ⟨4, 0⟩⟩
ZInQKernel/Compiler/Precision/JacobianGenerator.lean:23
noncomputable abbrev Zs.toK0 : Zs →+* K0 := algebraMap Zs K0
ZInQKernel/Model/Field/Basic.lean:162
def genX0 : K0 := ⟨1641 / 8, -145⟩
ZInQKernel/Model/Field/Curve.lean:95
def genY0 : K0 := ⟨-15465 / 4, 87483 / 32⟩
ZInQKernel/Model/Field/Curve.lean:98
def Rep (A : F) (T : JTriple F) (P : (shortCurve A).toAffine.Point) : Prop :=
(T.Z = 0 ∧ P = 0) ∨
(T.Z ≠ 0 ∧ ∃ h : (shortCurve A).toAffine.Nonsingular (T.X / T.Z ^ 2) (T.Y / T.Z ^ 3),
P = .some _ _ h)
ZInQKernel/Compiler/Precision/Jacobian.lean:259
def genD : K0 := ⟨75, -53⟩
ZInQKernel/Hypotheses/MordellWeil.lean:31
def genP0 : genCurve.toAffine.Point := Point.mk genP0_equation
ZInQKernel/Model/Field/Curve.lean:118
Uses 2 · Used by 1
TheoremScalar multiplication by halving#✓
A Jacobian representative of a point of \(E(K_0)\) is a triple \((X,Y,Z)\in\mathbb Z[s]^3\) representing \(O\) when \(Z=0\) and the affine point \((X/Z^2,Y/Z^3)\) when \(Z\ne0\) (which then lies on \(E\) whenever \(\mathcal E(X,Y,Z)=0\)). Let \(\oplus\) be the branching addition: if one argument has \(Z=0\) return the other; otherwise compute \(H,\Lambda\); if \(H\ne0\) return \(\mathrm{add}\); if \(H=0\) and \(\Lambda=0\) return \(\mathrm{dbl}\) (or \(O\) if \(Y=0\)); if \(H=0\) and \(\Lambda\ne0\) return \(O\). Let \(\mathrm{dbl}^\ast\) be doubling with \(O\mapsto O\) and zero ordinate \(\mapsto O\).
For \(k\in\mathbb N\) define \(\mathrm{mul}(k)\) by the loop with state \((\Pi,\Theta,e)\) starting at \((O,P^{\rm J}_0,k)\), where \(P^{\rm J}_0=(3282-2320s,-247440+174966s,4)\) and \(O=(1,1,0)\): while \(e>0\), if \(e\) is odd replace \(\Pi\) by \(\Pi\oplus\Theta\); replace \(\Theta\) by \(\mathrm{dbl}^\ast(\Theta)\) and \(e\) by \(\lfloor e/2\rfloor\); return \(\Pi\). For a negative integer \(k\) let \(\mathrm{mul}(k)\) be the negation \((X,-Y,Z)\) of \(\mathrm{mul}(-k)\).
Then for every \(k\in\mathbb Z\) the loop terminates and \(\mathrm{mul}(k)\) is a Jacobian representative of \([k]P_0\) satisfying \(\mathcal E=0\); in particular \([k]P_0=O\) if and only if the third coordinate is \(0\), and otherwise its ordinate is zero if and only if the second coordinate is \(0\).
Proof sketch. Termination: \(e\) halves. Invariant: \(\Pi\) and \(\Theta\) represent points \(\pi,\theta\) on \(E\) with \(\pi+[e]\theta=[k]P_0\); it holds initially because \(O=(1,1,0)\) represents \(O\) and \(P^{\rm J}_0\) represents \(P_0\) (the fixed Jacobian point) and is preserved because \(\oplus\) and \(\mathrm{dbl}^\ast\) represent the group law (Jacobian formulas, items 1-8): if \(e\) is odd, \(\pi+[e]\theta=(\pi+\theta)+[e-1]\theta\), and \([2\lfloor e/2\rfloor]\theta=[\lfloor e/2\rfloor](2\theta)\). At \(e=0\), \(\pi=[k]P_0\). Negation represents \(-P\). The last claim: for \(Z\ne0\), \(y=Y/Z^3\).
theorem rep_jmul (k : ℤ) : Rep (-genD ^ 2) ((jmul k).map Zs.toK0) (k • genP0)
theorem jmul_eq_some {k : ℤ} (hZ : (jmul k).Z ≠ 0) :
∃ h : genCurve.toAffine.Nonsingular (Zs.toK0 (jmul k).X / Zs.toK0 (jmul k).Z ^ 2)
(Zs.toK0 (jmul k).Y / Zs.toK0 (jmul k).Z ^ 3), k • genP0 = .some _ _ h
theorem admissible_iff_jmul (k : ℤ) : Admissible k ↔ (jmul k).Z ≠ 0 ∧ (jmul k).Y ≠ 0
def Rep (A : F) (T : JTriple F) (P : (shortCurve A).toAffine.Point) : Prop :=
(T.Z = 0 ∧ P = 0) ∨
(T.Z ≠ 0 ∧ ∃ h : (shortCurve A).toAffine.Nonsingular (T.X / T.Z ^ 2) (T.Y / T.Z ^ 3),
P = .some _ _ h)
ZInQKernel/Compiler/Precision/Jacobian.lean:259
def genD : K0 := ⟨75, -53⟩
ZInQKernel/Hypotheses/MordellWeil.lean:31
def jmul (k : ℤ) : JTriple Zs := if 0 ≤ k then jmulNat k.toNat else jneg (jmulNat (-k).toNat)
ZInQKernel/Compiler/Precision/ScalarMul.lean:93
noncomputable abbrev Zs.toK0 : Zs →+* K0 := algebraMap Zs K0
ZInQKernel/Model/Field/Basic.lean:162
def genP0 : genCurve.toAffine.Point := Point.mk genP0_equation
ZInQKernel/Model/Field/Curve.lean:118
def genCurve : WeierstrassCurve K0 where
a₁ := 0
a₂ := 0
a₃ := 0
a₄ := -genD ^ 2
a₆ := 0
ZInQKernel/Hypotheses/MordellWeil.lean:34
def Admissible (k : ℤ) : Prop :=
∃ (x y : K0) (h : genCurve.toAffine.Nonsingular x y), k • genP0 = .some x y h ∧ y ≠ 0
ZInQKernel/Compiler/Precision/ZCoordinate.lean:56
Uses 3 · Used by 3
The decision program assembles these steps, and it computes the relation on every input.
DefinitionThe exact decision program#✓
The decision program is the total function \(\mathrm{decide}:\mathbb N^5\to\{\mathrm{true},\mathrm{false}\}\) computed by the following steps on \(c\in\mathbb N^5\); every quantity is an integer, an element of \(\mathbb Z[s]\) (a pair of integers) or a natural number, and every test is exact.
- Decode \((n,\kappa,a,l,j)\). Return false unless \(n\notin\mathcal C\), \(\kappa\ne0\), \(a\ge1\), \(l\ge1\) and \(j=na\).
- For \(k\in\{l,a,j\}\) compute the Jacobian representative \((X_k,Y_k,Z_k)=\mathrm{mul}(k)\). Return false if some \(Z_k=0\) or some \(Y_k=0\).
- For \(k\in\{l,a,j\}\) put \(\nu_k=-X_kZ_k\bar Y_k\in\mathbb Z[s]\) and \(N_k=Y_k\bar Y_k\in\mathbb Z\), so that \(z_k=\nu_k/N_k\), with \(N_k\ne0\). Write \(\nu_l=p+p's\) and put \(U=|p|+|p'|\), \(V=|N_l|\), so that \(\epsilon_l=U/V\) with \(U,V>0\).
- Put \(\delta=N_j\operatorname N(\nu_a)\in\mathbb Z\setminus\{0\}\) and let \(\theta\) be the rational component of \(\nu_j\bar\nu_aN_a\in\mathbb Z[s]\), so that \(r(a,j)=\theta/\delta\). Return false unless \(|\theta-n\delta|\cdot V<U\cdot|\delta|\).
- Put \(L=\lfloor(V-1)/(4U)\rfloor\). Return false if \(L=0\). Otherwise, with \(M=|\kappa F(n)|\), compute \(\beta=\mathrm{cmul}_L(\langle e_A\rangle_L,\mathrm{cpow}_L(\sigma_L(M),24))\) and run the division-by-four loop from \(L\) for \(\beta\) steps; return true if and only if the final value is at least \(1\).
This is a definition. It follows the description of the reference program S21: exact quadratic-field arithmetic on integer pairs, capped integer operations, a halving scalar loop, a precision loop dividing by four and a bounded factorial iteration. The source S21 itself is not available in this repository, so this program is specified here rather than transcribed.
def decide5 (c : Fin 5 → ℕ) : Bool :=
decideInt (dec (c 0)) (dec (c 1)) (dec (c 2)) (dec (c 3)) (dec (c 4))
def decideInt (n κ a l j : ℤ) : Bool :=
if EarlyTestsInt n κ a l j then
let Tl := jmul l
let Ta := jmul a
let Tj := jmul j
if Tl.Z = 0 ∨ Ta.Z = 0 ∨ Tj.Z = 0 ∨ Tl.Y = 0 ∨ Ta.Y = 0 ∨ Tj.Y = 0 then false
else
let U := epsU Tl
let V := epsV Tl
let δ := ratioDen Ta Tj
let θ := ratioNum Ta Tj
if |θ - n * δ| * (V : ℤ) < (U : ℤ) * |δ| then
⋯
ZInQKernel/Compiler/Precision/Decision.lean:48
def dec (c : ℕ) : ℤ := if c % 2 = 0 then ((c / 2 : ℕ) : ℤ) else -(((c + 1) / 2 : ℕ) : ℤ)
ZInQKernel/Compiler/Precision/Encoding.lean:19
Sources
Uses 3 · Used by 2
TheoremCorrectness of the decision program#✓
For every \(c\in\mathbb N^5\), \(\mathrm{decide}(c)=\mathrm{true}\iff\operatorname{accepts}(c)\). The program terminates on every input, including every early rejection.
Proof sketch. Step 1 is item 1 of the relation (signed decoding). Step 2: by the scalar-multiplication statement, \(Z_k=0\) iff \([k]P_0=O\) and, for \(Z_k\ne0\), \(Y_k=0\) iff the ordinate vanishes; so step 2 passes iff \(l,a,j\) are admissible. Step 3: \(z_k=-x/y=-X_kZ_k/Y_k=\nu_k/N_k\) with \(N_k=\operatorname N(Y_k)\ne0\) by the norm-zero statement; \(\epsilon_l=(|p|+|p'|)/|N_l|\), and \(U>0\) because \(z_l\ne0\). Step 4: \(z_j/z_a=\nu_j\bar\nu_aN_a/(N_j\operatorname N(\nu_a))\), with \(\nu_a\ne0\) so \(\operatorname N(\nu_a)\ne0\); then \(|\theta/\delta-n|<U/V\) is the displayed integer inequality after multiplying by \(|\delta|V>0\). Step 5: by the threshold statement, \(4\epsilon_l<4^{-\mathcal B}\) iff \(4^{\mathcal B}\le L\); if \(L=0\) this is false since \(4^{\mathcal B}\ge1\); if \(L\ge1\) the capped precision test computes exactly this comparison with \(\mathcal B=A^{(0)}_{\rm ht}M^{24}\). Termination: the scalar loop halves, the factorial and capped-power loops are bounded, and the precision loop runs at most \(L+1\) steps.
theorem decide5_iff (c : Fin 5 → ℕ) : decide5 c = true ↔ accepts c
theorem decideInt_iff (n κ a l j : ℤ) : decideInt n κ a l j = true ↔ acceptsInt n κ a l j
def decide5 (c : Fin 5 → ℕ) : Bool :=
decideInt (dec (c 0)) (dec (c 1)) (dec (c 2)) (dec (c 3)) (dec (c 4))
ZInQKernel/Compiler/Precision/Decision.lean:69
def accepts (c : Fin 5 → ℕ) : Prop :=
acceptsInt (dec (c 0)) (dec (c 1)) (dec (c 2)) (dec (c 3)) (dec (c 4))
ZInQKernel/Compiler/Precision/Relation.lean:44
def decideInt (n κ a l j : ℤ) : Bool :=
if EarlyTestsInt n κ a l j then
let Tl := jmul l
let Ta := jmul a
let Tj := jmul j
if Tl.Z = 0 ∨ Ta.Z = 0 ∨ Tj.Z = 0 ∨ Tl.Y = 0 ∨ Ta.Y = 0 ∨ Tj.Y = 0 then false
else
let U := epsU Tl
let V := epsV Tl
let δ := ratioDen Ta Tj
let θ := ratioNum Ta Tj
if |θ - n * δ| * (V : ℤ) < (U : ℤ) * |δ| then
⋯
ZInQKernel/Compiler/Precision/Decision.lean:48
def acceptsInt (n κ a l j : ℤ) : Prop :=
EarlyTestsInt n κ a l j ∧ (Admissible l ∧ Admissible a ∧ Admissible j) ∧
CloseTestInt n a l j ∧ PrecisionTestInt n κ l
ZInQKernel/Compiler/Precision/Relation.lean:33
Sources
Uses 7 · Used by 1
Loading dependency explorer…
The dependency explorer needs JavaScript and its graph data.