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 NormNum/Pow.lean
.
TODO #
- Adapt the
norm_num
extensions forNat.mod
andInt.emod
to efficiently evaluate expressions of the forma ^ b % m
usingevalNatPowMod
.
theorem
Mathlib.Meta.NormNum.IsNatPowModT.run'
{p : Prop}
{a : ℕ}
{b : ℕ}
{m : ℕ}
{c : ℕ}
(self : Mathlib.Meta.NormNum.IsNatPowModT p a b m c)
:
p → (a.pow b).mod m = c
theorem
Mathlib.Meta.NormNum.IsNatPowModT.run
{a : ℕ}
{m : ℕ}
{b : ℕ}
{c : ℕ}
(p : Mathlib.Meta.NormNum.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 : Mathlib.Meta.NormNum.IsNatPowModT p a b m c)
(h2 : Mathlib.Meta.NormNum.IsNatPowModT ((a.pow b).mod m = c) a b' m c')
:
Mathlib.Meta.NormNum.IsNatPowModT p a b' m c'
theorem
Mathlib.Meta.NormNum.IsNatPowModT.bit0
{a : ℕ}
{b : ℕ}
{m : ℕ}
{c : ℕ}
:
Mathlib.Meta.NormNum.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 : ℕ}
:
Mathlib.Meta.NormNum.IsNatPowModT ((a.pow b).mod m = c) a (2 * b + 1) m ((c.mul ((c.mul a).mod m)).mod m)
partial def
Mathlib.Meta.NormNum.evalNatPowMod.go
(depth : ℕ)
(a : Q(ℕ))
(m : Q(ℕ))
(b₀ : Q(ℕ))
(c₀ : Q(ℕ))
(b : Q(ℕ))
(p : Q(Prop))
(hp : «$p» =Q ((«$a».pow «$b₀»).mod «$m» = «$c₀»))
:
(c : Q(ℕ)) × Q(Mathlib.Meta.NormNum.IsNatPowModT «$p» «$a» «$b» «$m» «$c»)
Invariants: a ^ b₀ % m = c₀
, depth > 0
, b >>> depth = b₀