Documentation

LeanPool.GKPCarry.ModularPrefix

Modular evaluation of ternary prefixes #

A ternary prefix depends only on a residue modulo a power of three. The binary-digit modular exponentiation function below lets the finite certificate evaluate those residues without first constructing the enormous value 4 ^ m.

theorem GKPCarry.count_append_replicate_zero {value : } (hvalue : value 0) (digits : List ) (count : ) :
List.count value (digits ++ List.replicate count 0) = List.count value digits

Taking depth ternary digits preserves exactly the nonzero digits of the residue modulo 3 ^ depth.

The two-2 prefix predicate can be checked on a modular residue.

def GKPCarry.powModDigits (base modulus : ) :

Modular exponentiation over a little-endian list of binary digits.

Equations
Instances For
    def GKPCarry.powMod (base exponent modulus : ) :

    Modular exponentiation by repeated squaring over binary exponent digits.

    Equations
    Instances For
      theorem GKPCarry.powModDigits_eq_pow_mod (base modulus : ) (digits : List ) (hdigits : digitdigits, digit < 2) :
      powModDigits base modulus digits = base ^ Nat.ofDigits 2 digits % modulus
      theorem GKPCarry.powMod_eq_pow_mod (base exponent modulus : ) :
      powMod base exponent modulus = base ^ exponent % modulus

      powMod computes the ordinary power modulo modulus.