norm_num handling for expressions of the form a ^ b % m. #
These expressions can often be evaluated efficiently in cases where first evaluating a ^ b and
then reducing mod m is not feasible. We provide a function evalNatPowMod which is used by the
reduce_mod_char tactic to efficiently evaluate powers in rings with positive characteristic.
The approach taken here is identical to (and copied from) the development in
Mathlib/Tactic/NormNum/Pow.lean.
TODO #
- Adapt the
norm_numextensions forNat.modandInt.emodto efficiently evaluate expressions of the forma ^ b % musingevalNatPowMod.
Represents and proves equalities of the form a^b % m = c for natural numbers.
- run' : p โ (a.pow b).mod m = c
Instances For
theorem
Mathlib.Meta.NormNum.IsNatPowModT.run
{a m : โ}
{b c : โ}
(p : IsNatPowModT ((a.pow 1).mod m = a.mod m) a b m c)
:
(a.pow b).mod m = c
theorem
Mathlib.Meta.NormNum.IsNatPowModT.trans
{p : Prop}
{a b m c b' c' : โ}
(h1 : IsNatPowModT p a b m c)
(h2 : IsNatPowModT ((a.pow b).mod m = c) a b' m c')
:
IsNatPowModT p a b' m c'
theorem
Mathlib.Meta.NormNum.IsNatPowModT.bit0
{a b m : โ}
{c : โ}
:
IsNatPowModT ((a.pow b).mod m = c) a (2 * b) m ((c.mul c).mod m)
theorem
Mathlib.Meta.NormNum.natPow_zero_natMod_succ_succ
{a : โ}
{m : โ}
:
(a.pow 0).mod m.succ.succ = 1
theorem
Mathlib.Meta.NormNum.IsNatPowModT.bit1
{a b m : โ}
{c : โ}
:
IsNatPowModT ((a.pow b).mod m = c) a (2 * b + 1) m ((c.mul ((c.mul a).mod m)).mod m)
def
Mathlib.Meta.NormNum.evalNatPowMod
(a b m : Q(โ))
:
(c : Q(โ)) ร Q((ยซ$aยป.pow ยซ$bยป).mod ยซ$mยป = ยซ$cยป)
Evaluates and proves a^b % m for natural numbers using fast modular exponentiation.