Documentation

Atlas.EllipticCurves.code.PrimalityProving

theorem fermat_little_theorem (p : ) [Fact (Nat.Prime p)] (a : ZMod p) :
a ^ p = a

Fermat's little theorem in ZMod p: for any element a, we have a ^ p = a when p is prime.

theorem totient_eq_sub_one_iff_prime (N : ) (hN : 2 N) :

Euler's criterion for primality: an integer N ≥ 2 is prime iff its Euler totient equals N - 1.

def IsCarmichael (N : ) :

N is a Carmichael number if it is a composite integer greater than 1 for which every unit a in ZMod N satisfies a ^ (N - 1) = 1.

Instances For
    noncomputable def millerRabinS (N : ) :

    The exponent s in the Miller-Rabin decomposition N - 1 = 2^s * d, defined as the 2-adic valuation of N - 1.

    Instances For
      noncomputable def millerRabinD (N : ) :

      The odd part d in the Miller-Rabin decomposition N - 1 = 2^s * d.

      Instances For

        The Miller-Rabin decomposition: N - 1 = 2 ^ millerRabinS N * millerRabinD N.

        theorem sq_chain_dichotomy {R : Type u_1} [CommRing R] [IsDomain R] (x : R) (n : ) (h : x ^ 2 ^ n = 1) :
        x = 1 i < n, x ^ 2 ^ i = -1

        In an integral domain, if x ^ (2 ^ n) = 1, then either x = 1 or there exists i < n such that x ^ (2 ^ i) = -1. This is the algebraic core of the Miller-Rabin "square-root chain" argument.

        theorem lemma_11_6 (p : ) (hp : Nat.Prime p) (a : ZMod p) (ha : a 0) :
        Xor' (a ^ millerRabinD p = 1) (∃ i < millerRabinS p, a ^ (2 ^ i * millerRabinD p) = -1)

        Lemma 11.6 (Sutherland): writing a prime p = 2^s t + 1 with t odd, for any integer a nonzero mod p, exactly one of the following holds: (i) a^t ≡ 1 (mod p); (ii) a^{2^i t} ≡ -1 (mod p) for some 0 ≤ i < s.

        An integer a is a Miller-Rabin witness for the compositeness of N if a is nonzero mod N, a^d ≢ 1, and a^(2^r · d) ≢ -1 for every 0 ≤ r < s, where N - 1 = 2^s · d with d odd.

        Instances For
          noncomputable def millerRabinWitnessSet (N : ) :

          The set of Miller-Rabin witnesses in [1, N-1].

          Instances For
            noncomputable def millerRabinLiarSet (N : ) :

            The set of Miller-Rabin liars (non-witnesses) in [1, N-1].

            Instances For

              The Miller-Rabin witness set and liar set together partition [1, N-1].

              theorem zmod_ne_zero_of_mem_Icc {N : } (hN : N > 1) {a : } (ha : a Finset.Icc 1 (N - 1)) :
              a 0

              A residue from [1, N-1] is nonzero in ZMod N whenever N > 1.

              theorem millerRabin_liar_coprime {N : } (hN : N > 1) {a : } (ha_mem : a millerRabinLiarSet N) :

              Any Miller-Rabin liar for N (with N > 1) is coprime to N.

              theorem millerRabin_liar_bound (N : ) (hN_odd : ¬2 N) (hN_composite : ¬Nat.Prime N) (hN_gt : N > 1) :

              Miller-Rabin liar bound: for an odd composite N > 1, at most one quarter of the elements of [1, N-1] are liars.

              theorem monier_rabin (N : ) (hN_odd : ¬2 N) (hN_composite : ¬Nat.Prime N) (hN_gt : N > 1) :

              Theorem 11.8 (Monier-Rabin): For an odd composite integer N > 1, at least 3/4 of the integers in [1, N-1] are Miller-Rabin witnesses.

              @[irreducible]
              def twoAdicVal :

              The 2-adic valuation of a natural number, computed recursively by dividing by 2 while the input is even.

              Instances For
                @[irreducible]

                2 ^ twoAdicVal n divides n.

                theorem twoAdicVal_decomp (n : ) :
                n = 2 ^ twoAdicVal n * (n / 2 ^ twoAdicVal n)

                n = 2 ^ twoAdicVal n * (n / 2 ^ twoAdicVal n): extracting the 2-adic factor of n.

                def millerRabinStep (N a : ) :

                One iteration of the Miller-Rabin primality test for a candidate N with a base a: succeeds iff a^d ≡ 1 or a^(2^r · d) ≡ -1 for some r < s, where N - 1 = 2^s · d.

                Instances For
                  def millerRabinTest (N : ) (witnesses : List ) :

                  The full Miller-Rabin test: run millerRabinStep on each witness in the list and report true iff every one returns true.

                  Instances For
                    theorem pow_two_pow_eq_one_or_neg_one {R : Type u_1} [Ring R] [NoZeroDivisors R] {x : R} {n : } (hx : x ^ 2 ^ n = 1) :
                    x = 1 r < n, x ^ 2 ^ r = -1

                    In a ring with no zero divisors, if x ^ 2^n = 1, then x = 1 or there exists r < n such that x ^ 2^r = -1.

                    The Miller-Rabin decomposition (restatement): N - 1 = 2 ^ millerRabinS N * millerRabinD N.

                    theorem millerRabinStep_true_of_prime (p : ) [hp : Fact (Nat.Prime p)] {a : } (ha : a 0) :

                    The Miller-Rabin step always returns true on a true prime p with any base nonzero mod p.

                    def IsZeroModN (Pz : ) (N : ) :

                    A projective z-coordinate Pz is zero modulo N if N divides Pz.

                    Instances For
                      def IsNonzeroModN (Pz : ) (N : ) :

                      A projective z-coordinate Pz is nonzero modulo N if N does not divide Pz.

                      Instances For
                        def IsStronglyNonzeroModN (Pz : ) (N : ) :

                        A projective z-coordinate Pz is strongly nonzero modulo N if gcd(Pz, N) = 1.

                        Instances For
                          theorem not_dvd_of_stronglyNonzeroModN {Pz : } {N p : } (hstr : IsStronglyNonzeroModN Pz N) (hp : Nat.Prime p) (hpN : p N) :
                          ¬p Pz

                          If Pz is strongly nonzero mod N and p is a prime divisor of N, then p ∤ Pz.

                          theorem isNonzeroModN_of_isStronglyNonzeroModN {Pz : } {N : } (hstr : IsStronglyNonzeroModN Pz N) (hN : 1 < N) :

                          Strongly nonzero mod N implies nonzero mod N, provided N > 1.

                          When N is prime, "strongly nonzero mod N" coincides with "nonzero mod N".

                          theorem fourth_root_mono {p N : } (hp2 : p ^ 2 N) :
                          (p + 1) ^ 2 (N + 1) ^ 2

                          Monotonicity used in the Goldwasser-Kilian bound: if p ^ 2 ≤ N, then (√p + 1)^2 ≤ (√√N + 1)^2.

                          structure GoldwasserKilianHyp (W : WeierstrassCurve ) (N M : ) (zMP : ) (zMlP : ) :

                          The hypotheses of the Goldwasser-Kilian primality criterion (Theorem 11.13 of Sutherland): N, M > 1, M > (N^{1/4}+1)^2, N coprime to the discriminant of W, the multiple MP is zero mod N, and (M/ℓ)P is strongly nonzero mod N for every prime ℓ ∣ M.

                          Instances For
                            theorem disc_ne_zero_of_coprime_dvd (W : WeierstrassCurve ) (N p : ) (hcop : N.Coprime W.Δ.natAbs) (hp : Nat.Prime p) (hpN : p N) :

                            If N is coprime to the discriminant of W and p is a prime divisor of N, then the discriminant maps to a nonzero element of ZMod p.

                            theorem reduction_point_nsmul_properties (W : WeierstrassCurve ) (N M : ) (zMP : ) (zMlP : ) (hM : M > 1) (hcop : N.Coprime W.Δ.natAbs) (hzero : IsZeroModN zMP N) (hstrong : ∀ ( : ), Nat.Prime MIsStronglyNonzeroModN (zMlP ) N) (p : ) (hp : Nat.Prime p) (hpN : p N) [Fact (Nat.Prime p)] :
                            ∃ (Pbar : (W.map (Int.castRingHom (ZMod p))).toAffine.Point), M Pbar = 0 ∀ ( : ), Nat.Prime M → (M / ) Pbar 0

                            Under the Goldwasser-Kilian hypotheses, for any prime p ∣ N, the reduction of the point modulo p is annihilated by M and not by M/ℓ for any prime ℓ ∣ M.

                            theorem reduction_point_has_order (W : WeierstrassCurve ) (N M : ) (zMP : ) (zMlP : ) (hM : M > 1) (hcop : N.Coprime W.Δ.natAbs) (hzero : IsZeroModN zMP N) (hstrong : ∀ ( : ), Nat.Prime MIsStronglyNonzeroModN (zMlP ) N) (p : ) (hp : Nat.Prime p) (hpN : p N) [Fact (Nat.Prime p)] :
                            ∃ (Pbar : (W.map (Int.castRingHom (ZMod p))).toAffine.Point), addOrderOf Pbar = M

                            Under the Goldwasser-Kilian hypotheses, for any prime p ∣ N, the reduction of the point modulo p has additive order exactly M.

                            theorem hasse_order_bound_from_GK (W : WeierstrassCurve ) (N M : ) (zMP : ) (zMlP : ) (hyp : GoldwasserKilianHyp W N M zMP zMlP) (p : ) (hp : Nat.Prime p) (hpN : p N) :
                            M (p + 1) ^ 2

                            Under the Goldwasser-Kilian hypotheses, for every prime p ∣ N the order parameter M is bounded by the Hasse interval upper bound (√p + 1)^2.

                            theorem goldwasser_kilian (W : WeierstrassCurve ) (N M : ) (zMP : ) (zMlP : ) (hN : N > 1) (hM : M > 1) (hMbound : M > (N + 1) ^ 2) (hcop : N.Coprime W.Δ.natAbs) (hzero : N zMP) (hstrong : ∀ ( : ), Nat.Prime M(zMlP ).gcd N = 1) :

                            Theorem 11.13 (Goldwasser-Kilian, Sutherland): Let E/ℚ be an elliptic curve and M, N > 1 with M > (N^{1/4}+1)^2 and N coprime to Δ(E). If MP is zero mod N and (M/ℓ)P is strongly nonzero mod N for every prime ℓ ∣ M, then N is prime.