Documentation

Atlas.EllipticCurves.code.PointCounting

structure InsepAxioms {R : Type u_1} [Ring R] (IsInsep : RProp) :
Type u_1

Abstract axiomatization of the inseparability predicate on a ring $R$ (intended to be the endomorphism ring of an elliptic curve), specifying the structural properties needed to prove Lemma 7.1. It posits a distinguished inseparable element $\pi$ (Frobenius) through which every inseparable endomorphism factors, closure under multiplication by $\pi$, and closure under negation.

  • π : R

    The distinguished inseparable element (Frobenius).

  • π_insep : IsInsep self.π

    The element $\pi$ is itself inseparable.

  • factor (α : R) : IsInsep α∃ (γ : R), α = γ * self.π

    Every inseparable element factors as $\gamma \cdot \pi$ for some $\gamma$.

  • mul_π_insep (γ : R) : IsInsep (γ * self.π)

    Any product $\gamma \cdot \pi$ is inseparable.

  • neg_insep (α : R) : IsInsep αIsInsep (-α)

    The set of inseparable elements is closed under negation.

Instances For
    theorem inseparable_add_iff {R : Type u_1} [Ring R] {IsInsep : RProp} (ax : InsepAxioms IsInsep) {α β : R} ( : IsInsep α) :
    IsInsep (α + β) IsInsep β

    Lemma 7.1 (additive complement of inseparables): if $\alpha$ is inseparable, then $\alpha + \beta$ is inseparable iff $\beta$ is. Both directions reduce to factoring through $\pi$.

    theorem separable_add_iff {R : Type u_1} [Ring R] {IsInsep : RProp} (ax : InsepAxioms IsInsep) {α β : R} ( : IsInsep α) :
    ¬IsInsep (α + β) ¬IsInsep β

    Lemma 7.1 (contrapositive form): if $\alpha$ is inseparable, then $\alpha + \beta$ is separable iff $\beta$ is separable.

    The predicate "$\varphi$ is an inseparable endomorphism" on the endomorphism ring of an elliptic curve $E/F$, as a Prop-valued function on EllipticCurve.EndomorphismRing E.

    Instances For

      The endomorphism ring of an elliptic curve satisfies the abstract inseparability axioms InsepAxioms, with the distinguished inseparable element being the Frobenius endomorphism.

      Instances For

        Lemma 7.1 specialized to the endomorphism ring of an elliptic curve: if $\alpha$ is an inseparable endomorphism, then $\alpha + \beta$ is inseparable iff $\beta$ is.

        noncomputable def Hasse.pointEquiv {F : Type u} [Field F] {W : WeierstrassCurve.Affine F} :
        W.Point Option { p : F × F // W.Nonsingular p.1 p.2 }

        An equivalence between the points of a Weierstrass curve and Option-of-nonsingular affine pairs: the point at infinity corresponds to none and each affine point $(x, y)$ to some ⟨(x, y), h⟩.

        Instances For
          @[implicit_reducible]
          noncomputable instance Hasse.pointFintypeInst {F : Type u} [Field F] [Fintype F] {W : WeierstrassCurve.Affine F} :

          The point set $W(F)$ of a Weierstrass curve over a finite field is itself finite, transported across pointEquiv from the (finite) type of optional nonsingular affine pairs.

          noncomputable def Hasse.numPoints {F : Type u} [Field F] [Fintype F] (W : WeierstrassCurve.Affine F) :

          The number $\#E(\mathbb{F}_q)$ of $\mathbb{F}_q$-rational points (including the point at infinity) of a Weierstrass curve over a finite field.

          Instances For
            noncomputable def Hasse.traceFrobenius {F : Type u} [Field F] [Fintype F] (W : WeierstrassCurve.Affine F) :

            The trace of Frobenius $t = q + 1 - \#E(\mathbb{F}_q)$ for an elliptic curve $E$ over $\mathbb{F}_q$. By Hasse's theorem, $|t| \leq 2\sqrt{q}$.

            Instances For

              Rearrangement of the definition of the trace of Frobenius: $\#E(\mathbb{F}_q) = q + 1 - t$.

              theorem Hasse.endomorphism_degree_eq_quadratic_form {F : Type u} [Field F] [Fintype F] [DecidableEq F] (W : WeierstrassCurve.Affine F) (r s : ) :
              ∃ (n : ), n = r ^ 2 * (Fintype.card F) - r * s * traceFrobenius W + s ^ 2

              The degree of the endomorphism $r \cdot [F] - s \cdot \mathrm{id}$ (where $[F]$ is the Frobenius) equals the quadratic form $r^2 q - r s t + s^2$, and this degree is a natural number. This is the key positivity input for Hasse's bound.

              theorem Hasse.degree_formula_nonneg {F : Type u} [Field F] [Fintype F] [DecidableEq F] (W : WeierstrassCurve.Affine F) (r s : ) :
              0 r ^ 2 * (Fintype.card F) - r * s * traceFrobenius W + s ^ 2

              The quadratic form $r^2 q - r s t + s^2$ is nonnegative for all integers $r, s$, since it equals a degree of an isogeny by endomorphism_degree_eq_quadratic_form.

              Substituting $(r, s) = (t, 2q)$ in degree_formula_nonneg yields the discriminant bound $t^2 \leq 4 q$, which is the algebraic heart of Hasse's theorem.

              theorem Hasse.quadratic_form_nonneg {F : Type u} [Field F] [Fintype F] [DecidableEq F] (W : WeierstrassCurve.Affine F) (x : ) :
              (Fintype.card F) * x ^ 2 - (traceFrobenius W) * x + 1 0

              The real quadratic $q x^2 - t x + 1$ is nonnegative for all $x \in \mathbb{R}$: a direct consequence of the discriminant bound $t^2 \leq 4 q$ via completing the square.

              The Hasse bound on the square of the trace of Frobenius: $t^2 \leq 4 q$ for any elliptic curve over $\mathbb{F}_q$.

              Hasse's bound (Theorem 7.3) on the absolute value of the trace of Frobenius: $|t| \leq 2\sqrt{q}$. Obtained by taking square roots in $t^2 \leq 4q$.

              theorem Hasse.hasse_theorem {F : Type u} [Field F] [Fintype F] [DecidableEq F] (W : WeierstrassCurve.Affine F) (hq : 0 < Fintype.card F) :
              |(numPoints W) - (Fintype.card F) - 1| 2 * (Fintype.card F)

              Theorem 7.3 (Hasse): for an elliptic curve $E/\mathbb{F}_q$, $|\#E(\mathbb{F}_q) - (q + 1)| \leq 2 \sqrt{q}$. Equivalently, the trace of Frobenius $t = q + 1 - \#E(\mathbb{F}_q)$ satisfies $|t| \leq 2\sqrt{q}$.

              theorem Hasse.numPoints_in_hasse_interval {F : Type u} [Field F] [Fintype F] [DecidableEq F] (W : WeierstrassCurve.Affine F) (hq : 0 < Fintype.card F) :
              ((Fintype.card F) - 1) ^ 2 (numPoints W) (numPoints W) ((Fintype.card F) + 1) ^ 2

              Reformulation of Hasse's bound as the two-sided interval enclosure $(\sqrt{q} - 1)^2 \leq \#E(\mathbb{F}_q) \leq (\sqrt{q} + 1)^2$, which is the form used in Mestre's argument.

              Hasse's bound stated for an elliptic curve $W$ over $\mathbb{F}_q$: the hypothesis 0 < q is automatic since $\mathbb{F}_q$ is finite and nonempty.

              noncomputable def GroupExponent.groupExponent (G : Type u_1) [Group G] :

              The exponent of a group $G$: the least $n$ such that $g^n = 1$ for all $g \in G$ (equivalent to the LCM of orders of elements when $G$ is finite).

              Instances For
                noncomputable def oneOverSqHom :

                The completely multiplicative monoid-with-zero homomorphism $\mathbb{N} \to \mathbb{R}$ sending $n \mapsto 1/n^2$ (and $0 \mapsto 0$). Used to express $\zeta(2)$ as the Euler product $\sum_n 1/n^2 = \prod_p (1 - p^{-2})^{-1}$.

                Instances For
                  theorem oneOverSqHom_eq (n : ) :
                  oneOverSqHom n = 1 / n ^ 2

                  The value of oneOverSqHom at $n$ is $1/n^2$ (which is $0$ when $n = 0$).

                  Norm-summability of $\sum 1/n^2$: a prerequisite for invoking Mathlib's Euler product machinery for $\zeta(2)$.

                  theorem eulerProduct_zeta2 :
                  HasProd (fun (p : Nat.Primes) => (1 - 1 / p ^ 2)⁻¹) (Real.pi ^ 2 / 6)

                  The Euler product for $\zeta(2)$: $\prod_p (1 - p^{-2})^{-1} = \pi^2 / 6$, the Basel formula. This is the analytic input to Theorem 7.6.

                  theorem eulerFactor_ge_one (p : Nat.Primes) :
                  1 (1 - 1 / p ^ 2)⁻¹

                  Each Euler factor $(1 - p^{-2})^{-1}$ is at least $1$ since the geometric series expansion $\sum_k p^{-2k}$ starts with $1$.

                  theorem partialInvProduct_le (s : Finset Nat.Primes) :
                  ps, (1 - 1 / p ^ 2)⁻¹ Real.pi ^ 2 / 6

                  Any finite partial product $\prod_{p \in s} (1 - p^{-2})^{-1}$ is bounded above by the full Euler product $\pi^2 / 6$, since the partial products are monotonically increasing toward the full product.

                  noncomputable def GroupExponentBound.numGoodPairs (G : Type u_1) [CommGroup G] [Fintype G] :

                  The number of "good" pairs $(g_1, g_2) \in G \times G$ such that $\mathrm{lcm}(\mathrm{ord}(g_1), \mathrm{ord}(g_2))$ equals the exponent of $G$. This counts pairs that together generate a cyclic subgroup of order equal to the exponent.

                  Instances For
                    noncomputable def GroupExponentBound.probLcmEqExponent (G : Type u_1) [CommGroup G] [Fintype G] :

                    The probability that two random elements of $G$ have orders whose LCM equals the exponent of $G$: $|\text{good pairs}| / |G|^2$.

                    Instances For
                      theorem GroupExponentBound.lcm_orderOf_map_dvd {G : Type u_1} {H : Type u_2} [Group G] [Group H] (φ : G →* H) (α β : G) :
                      (orderOf (φ α)).lcm (orderOf (φ β)) (orderOf α).lcm (orderOf β)

                      For any group homomorphism $\varphi : G \to H$ and any two elements $\alpha, \beta \in G$, $\mathrm{lcm}(\mathrm{ord}(\varphi \alpha), \mathrm{ord}(\varphi \beta))$ divides $\mathrm{lcm}(\mathrm{ord}(\alpha), \mathrm{ord}(\beta))$, since each individual order of an image divides the corresponding source order.

                      Comparison lemma: the LCM-equals-exponent probability for the cyclic group $\mathbb{Z}/N$ (with $N = \mathrm{exp}(G)$) is at most the corresponding probability for $G$ itself. This reduces the lower bound for general groups to the cyclic case.

                      theorem GroupExponentBound.prob_cyclic_eq_prod (n : ) (hn : 2 n) [NeZero n] :
                      probLcmEqExponent (Multiplicative (ZMod n)) = pn.primeFactors, (1 - 1 / p ^ 2)

                      Exact formula for the cyclic case: the probability that two random elements of $\mathbb{Z}/n$ have orders whose LCM is $n$ equals $\prod_{p \mid n} (1 - p^{-2})$, a finite truncation of the Euler product for $1/\zeta(2) = 6/\pi^2$.

                      Combining prob_cyclic_le and prob_cyclic_eq_prod: for any nontrivial finite abelian group $G$, the LCM-equals-exponent probability is bounded below by the truncated Euler product over the prime factors of the exponent.

                      theorem GroupExponentBound.finite_euler_product_gt (n : ) (hn : 2 n) :
                      6 / Real.pi ^ 2 < pn.primeFactors, (1 - 1 / p ^ 2)

                      For any $n \geq 2$, the finite truncation $\prod_{p \mid n} (1 - p^{-2})$ strictly exceeds $6/\pi^2 = 1/\zeta(2)$. This uses the existence of some prime $q$ not dividing $n$ to produce a strict inequality when comparing the truncation to the full Euler product.

                      Any nontrivial group has exponent at least $2$ (since a nontrivial element has order $\geq 2$).

                      Theorem 7.6 for nontrivial groups: the probability that the LCM of the orders of two random elements equals the exponent strictly exceeds $6/\pi^2$. Combines prob_ge_euler_product with finite_euler_product_gt.

                      A trivial real-analytic fact used to handle the trivial-group edge case in Theorem 7.6: $6/\pi^2 < 1$.

                      Theorem 7.6 (full statement): for any finite abelian group $G$, the probability that two random elements have orders with LCM equal to the group exponent strictly exceeds $6/\pi^2$. The trivial-group case is handled separately.

                      theorem BSGSOrder.nat_div_dvd_div {q a b : } (hqa : q a) (hab : a b) :
                      a / q b / q

                      If $q$ divides $a$ and $a$ divides $b$, then $a/q$ divides $b/q$.

                      @[irreducible]
                      noncomputable def BSGSOrder.stripPrimeFactor {G : Type u_1} [AddGroup G] [DecidableEq G] (P : G) (p : ) (hp : 1 < p) :

                      Iteratively divide $m$ by $p$ as long as the smaller multiple $m/p$ still annihilates the point $P$. This is the key subroutine in Algorithm 7.4 (order computation): given any annihilator $m$, it strips the prime $p$ to obtain a smaller annihilator.

                      Instances For
                        noncomputable def BSGSOrder.computeOrder {G : Type u_1} [AddGroup G] [DecidableEq G] (P : G) :
                        List

                        Algorithm 7.4: compute the order of a point $P$ in an additive group given a known multiple $m$ and a list of primes containing all prime factors of the order. Strips each prime in turn via stripPrimeFactor.

                        Instances For
                          theorem BSGSOrder.stripPrimeFactor_nsmul {G : Type u_1} [AddGroup G] [DecidableEq G] (P : G) (p : ) (hp : 1 < p) (m : ) (hm : m P = 0) :
                          stripPrimeFactor P p hp m P = 0

                          Soundness of stripPrimeFactor: the stripped value remains an annihilator of $P$.

                          theorem BSGSOrder.stripPrimeFactor_dvd {G : Type u_1} [AddGroup G] [DecidableEq G] (P : G) (p : ) (hp : 1 < p) (m : ) :

                          The result of stripPrimeFactor divides the original $m$, since each iterative step replaces $m$ by a divisor $m/p$.

                          theorem BSGSOrder.stripPrimeFactor_prime_stripped {G : Type u_1} [AddGroup G] [DecidableEq G] (P : G) (p : ) (hp : 1 < p) (m : ) (hm_pos : 0 < m) (hm_ann : m P = 0) :
                          p stripPrimeFactor P p hp m → (stripPrimeFactor P p hp m / p) P 0

                          After stripping, the result is "prime-stripped": if $p$ still divides $\mathrm{strip}(m)$, then $\mathrm{strip}(m)/p$ no longer annihilates $P$ (otherwise we would have continued stripping).

                          theorem BSGSOrder.computeOrder_nsmul {G : Type u_1} [AddGroup G] [DecidableEq G] (P : G) (ps : List ) (m : ) (hm : m P = 0) :
                          computeOrder P ps m P = 0

                          Soundness of computeOrder: the output still annihilates $P$.

                          theorem BSGSOrder.computeOrder_dvd {G : Type u_1} [AddGroup G] [DecidableEq G] (P : G) (ps : List ) (m : ) :
                          computeOrder P ps m m

                          The result of computeOrder always divides the input multiple $m$.

                          theorem BSGSOrder.computeOrder_correct_aux {G : Type u_1} [AddGroup G] [DecidableEq G] (P : G) (ps : List ) (hps : pps, Nat.Prime p) (m : ) (hm_pos : 0 < m) (hm_ann : m P = 0) (q : ) (hq_prime : Nat.Prime q) (hq_dvd : q computeOrder P ps m) (hq_src : q ps (m / q) P 0) :
                          (computeOrder P ps m / q) P 0

                          Correctness lemma for computeOrder: if a prime $q$ divides the output, then $\mathrm{output}/q$ does not annihilate $P$ (i.e. the output is the true order whenever the prime list is complete). This is the inductive auxiliary used to prove that computeOrder returns exactly $\mathrm{ord}(P)$.

                          Two Weierstrass curves $E'$ and $E$ over $F$ are twists of each other if there is a field extension $L/F$ over which they become isomorphic via a Weierstrass variable change.

                          Instances For

                            The quadratic twist of a short Weierstrass curve $W : y^2 = x^3 + a_4 x + a_6$ by $s \in F$: the curve $y^2 = x^3 + (s^2 a_4) x + (s^3 a_6)$.

                            Instances For
                              @[simp]

                              The coefficient $a_1$ of a quadratic twist is $0$.

                              @[simp]

                              The coefficient $a_2$ of a quadratic twist is $0$.

                              @[simp]

                              The coefficient $a_3$ of a quadratic twist is $0$.

                              @[simp]

                              The coefficient $a_4$ of a quadratic twist by $s$ is $s^2 \cdot W.a_4$.

                              @[simp]

                              The coefficient $a_6$ of a quadratic twist by $s$ is $s^3 \cdot W.a_6$.

                              noncomputable def QuadraticTwist.twistNumPoints {F : Type u_1} [Field F] [Fintype F] [DecidableEq F] (W : WeierstrassCurve.Affine F) :

                              The number of points on the quadratic twist of $W$ over $\mathbb{F}_q$, defined via the relation $\#E + \#E^{\mathrm{twist}} = 2q + 2$.

                              Instances For

                                The classical relation $\#E(\mathbb{F}_q) + \#E^{\mathrm{twist}}(\mathbb{F}_q) = 2q + 2$ between an elliptic curve and its quadratic twist.

                                def Mestre.HasUniqueMultipleIn (N : ) (lo hi : ) :

                                The predicate "$N$ has a unique positive multiple in the closed interval $[\mathit{lo}, \mathit{hi}]$": there is exactly one positive integer $k$ such that $\mathit{lo} \leq k N \leq \mathit{hi}$. Mestre's theorem uses this to pin down the number of points from a known annihilator.

                                Instances For
                                  theorem Mestre.mestre_inequality_of_bounds (p m n M N : ) (hp : 0 < p) (hm : 0 < m) (hn : 0 < n) (hM : 0 < M) (hN : 0 < N) (hbound : m ^ 2 * n ^ 2 64 * p) (hMN_lt : M * N < 16 * p) (hmnMN_ge : m * n * (M * N) (p - 1) ^ 4) :
                                  16384 * p ^ 3 > (p - 1) ^ 8

                                  Core algebraic inequality in Mestre's proof: given a bound $m^2 n^2 \leq 64 p$ and suitable interval containment hypotheses, derive $16384 p^3 > (\sqrt{p} - 1)^8$. The contradiction with inequality_fails_large_p produces the desired uniqueness for large $p$.

                                  theorem Mestre.poly_bound_132 (s : ) (hs : 132 s) :
                                  (s - 1) ^ 4 128 * s ^ 3

                                  For $s \geq 132$, the elementary polynomial inequality $(s - 1)^4 \geq 128 s^3$ holds. Used to verify that $(\sqrt{p} - 1)^8 \geq 16384 p^3$ when $p \geq 132^2 = 17424$.

                                  theorem Mestre.inequality_large_case (p : ) (hp : 17424 p) :
                                  (p - 1) ^ 8 16384 * p ^ 3

                                  For $p \geq 17424 = 132^2$, the inequality $(\sqrt{p} - 1)^8 \geq 16384 p^3$ holds, established by squaring poly_bound_132 and rewriting $(\sqrt p)^2 = p$.

                                  theorem Mestre.int_bound_small_range (p : ) (h1 : 17413 p) (h2 : p 17423) :
                                  (p - 263) ^ 4 16384 * p ^ 3

                                  An integer-level inequality for $p$ in the narrow range $17413 \leq p \leq 17423$: $(p - 263)^4 \geq 16384 p^3$. Verified by nlinarith from squared lower bounds.

                                  theorem Mestre.inequality_small_case (p : ) (h1 : 17413 p) (h2 : p < 17424) :
                                  (p - 1) ^ 8 16384 * p ^ 3

                                  The boundary range $17413 \leq p < 17424$ where inequality_large_case does not yet apply: handled by the integer arithmetic lemma int_bound_small_range lifted to the reals via $(\sqrt p - 1)^2 > p - 263$.

                                  theorem Mestre.inequality_fails_large_p (p : ) (hp : 17413 p) :
                                  (p - 1) ^ 8 16384 * p ^ 3

                                  For all $p \geq 17413$, $(\sqrt{p} - 1)^8 \geq 16384 p^3$, combining the small range $17413 \leq p < 17424$ and the large range $p \geq 17424$. This rules out the "non-unique multiple" case for sufficiently large $p$ in Mestre's argument.

                                  theorem Mestre.not_unique_implies_lt_width (N p : ) (hN_pos : 0 < N) (hp_prime : Nat.Prime p) (hp_gt4 : 4 < p) (h_has_multiple : ∃ (k : ), 0 < k (p - 1) ^ 2 k * N k * N (p + 1) ^ 2) (h_not_unique : ¬HasUniqueMultipleIn N ((p - 1) ^ 2) ((p + 1) ^ 2)) :
                                  N < 4 * p

                                  If $N$ has at least one positive multiple in the Hasse interval $[(\sqrt p - 1)^2, (\sqrt p + 1)^2]$ but the multiple is not unique, then $N < 4 \sqrt p$ (the width of the interval). The strict inequality uses the irrationality of $\sqrt{p}$ for primes $p$.

                                  theorem Mestre.computer_search_mestre (p n m N_E M_Et : ) (hp_prime : Nat.Prime p) (hp_gt : 229 < p) (hp_lt : p < 17413) (hn_pos : 0 < n) (hm_pos : 0 < m) (hN_pos : 0 < N_E) (hM_pos : 0 < M_Et) (hbound : m ^ 2 * n ^ 2 64 * p) (hE_in_hasse : (p - 1) ^ 2 n * N_E n * N_E (p + 1) ^ 2) (hEt_in_hasse : (p - 1) ^ 2 m * M_Et m * M_Et (p + 1) ^ 2) :
                                  HasUniqueMultipleIn N_E ((p - 1) ^ 2) ((p + 1) ^ 2) HasUniqueMultipleIn M_Et ((p - 1) ^ 2) ((p + 1) ^ 2)

                                  Bounded range case of Mestre's theorem ($229 < p < 17413$), to be discharged by a finite computer search. Asserts that under the bound $m^2 n^2 \leq 64 p$, one of the two annihilators $N_E, M_{E^t}$ has a unique multiple in the Hasse interval.

                                  theorem Mestre.theorem_7_7_combinatorial (p n m N_E M_Et : ) (hp_prime : Nat.Prime p) (hp_gt : 229 < p) (hn_pos : 0 < n) (hm_pos : 0 < m) (hN_pos : 0 < N_E) (hM_pos : 0 < M_Et) (hbound : m ^ 2 * n ^ 2 64 * p) (hE_in_hasse : (p - 1) ^ 2 n * N_E n * N_E (p + 1) ^ 2) (hEt_in_hasse : (p - 1) ^ 2 m * M_Et m * M_Et (p + 1) ^ 2) :
                                  HasUniqueMultipleIn N_E ((p - 1) ^ 2) ((p + 1) ^ 2) HasUniqueMultipleIn M_Et ((p - 1) ^ 2) ((p + 1) ^ 2)

                                  Combinatorial reformulation of Mestre's theorem (Theorem 7.7): under the constraint $m^2 n^2 \leq 64 p$, at least one of the two annihilators $N_E, M_{E^t}$ has a unique multiple in the Hasse interval. Splits into a small-$p$ case (handled by computer search) and a large-$p$ case (handled by the inequality inequality_fails_large_p).

                                  For an elliptic curve $E/\mathbb{F}_q$, there exists a positive integer $n$ dividing the exponent of $E(\mathbb{F}_q)$ such that $n \cdot \mathrm{exp}(E) = \#E(\mathbb{F}_q)$. This is the "smallest invariant factor" appearing in the elementary divisor decomposition $E(\mathbb{F}_q) \cong \mathbb{Z}/n \times \mathbb{Z}/\mathrm{exp}$.

                                  Combined bound on the smallest invariant factors of a curve $E/\mathbb{F}_p$ and one of its quadratic twists $E^s$: the product $m^2 n^2$ of their squared smallest invariant factors is bounded by $64p$. This bound comes from analyzing the matrix of the Frobenius endomorphism on $E$ and $E^s$ and is the key ingredient in Mestre's theorem allowing one of $E, E^s$ to have a unique multiple in the Hasse interval.

                                  theorem Mestre.theorem_7_7 {F : Type u_1} [Field F] [Fintype F] [DecidableEq F] (W : WeierstrassCurve.Affine F) (s : F) (hp_prime : Nat.Prime (Fintype.card F)) (hp_gt : 229 < Fintype.card F) :
                                  have p := Fintype.card F; have Et := QuadraticTwist.quadraticTwistCurve W s; have expE := AddMonoid.exponent W.Point; have expEt := AddMonoid.exponent Et.Point; HasUniqueMultipleIn expE ((p - 1) ^ 2) ((p + 1) ^ 2) HasUniqueMultipleIn expEt ((p - 1) ^ 2) ((p + 1) ^ 2)

                                  Mestre's theorem (Theorem 7.7): for an elliptic curve $E/\mathbb{F}_p$ with $p > 229$ prime, at least one of $E$ or any quadratic twist $E^s$ has the property that its group exponent has a unique multiple in the Hasse interval $[(\sqrt p - 1)^2, (\sqrt p + 1)^2]$. This is the key fact enabling efficient point counting: it ensures that computing the exponent of $E(\mathbb{F}_p)$ or $E^s(\mathbb{F}_p)$ determines the group order uniquely.