The areas / V34. The tactics of Mathlib
Mathlib.Tactic.ReduceModChar
24 declarations. Mathlib docs · Source
theorem Tactic.ReduceModChar.TypeToCharPResult.intLike.inj E1 #
∀ {u : Lean.Level} {α : Q(Type u)} {n : Q(ℕ)} {instRing : Q(Ring «$α»)} {instCharP : Q(CharP «$α» «$n»)} {n_1 : Q(ℕ)}
{instRing_1 : Q(Ring «$α»)} {instCharP_1 : Q(CharP «$α» «$n_1»)},
Tactic.ReduceModChar.TypeToCharPResult.intLike n instRing instCharP =
Tactic.ReduceModChar.TypeToCharPResult.intLike n_1 instRing_1 instCharP_1 →
n = n_1 ∧ instRing = instRing_1 ∧ instCharP = instCharP_1
theorem Tactic.ReduceModChar.TypeToCharPResult.intLike.injEq E0 #
∀ {u : Lean.Level} {α : Q(Type u)} (n : Q(ℕ)) (instRing : Q(Ring «$α»)) (instCharP : Q(CharP «$α» «$n»)) (n_1 : Q(ℕ))
(instRing_1 : Q(Ring «$α»)) (instCharP_1 : Q(CharP «$α» «$n_1»)),
(Tactic.ReduceModChar.TypeToCharPResult.intLike n instRing instCharP =
Tactic.ReduceModChar.TypeToCharPResult.intLike n_1 instRing_1 instCharP_1) =
(n = n_1 ∧ instRing = instRing_1 ∧ instCharP = instCharP_1)
def Tactic.ReduceModChar.TypeToCharPResult.ctorIdx E1 #
{u : Lean.Level} → {α : Q(Type u)} → Tactic.ReduceModChar.TypeToCharPResult α → ℕ
abbrev Tactic.ReduceModChar.TypeToCharPResult.ctorElimType E1 #
{u : Lean.Level} → {α : Q(Type u)} → {motive : Tactic.ReduceModChar.TypeToCharPResult α → Sort u} → ℕ → Sort (max 1 u)
theorem Tactic.ReduceModChar.CharP.isInt_of_mod E1 #
∀ {e' r : ℤ} {α : Type u_1} [inst : Ring α] {n n' : ℕ},
CharP α n →
∀ {e : α},
Mathlib.Meta.NormNum.IsInt e e' →
Mathlib.Meta.NormNum.IsNat n n' → Mathlib.Meta.NormNum.IsInt (e' % ↑n') r → Mathlib.Meta.NormNum.IsInt e r
theorem Tactic.ReduceModChar.CharP.isNat_pow E1 #
∀ {α : Type u_1} [inst : Semiring α] {f : α → ℕ → α} {a : α} {a' b b' c n n' : ℕ},
CharP α n →
f = HPow.hPow →
Mathlib.Meta.NormNum.IsNat a a' →
Mathlib.Meta.NormNum.IsNat b b' →
Mathlib.Meta.NormNum.IsNat n n' → (a'.pow b').mod n' = c → Mathlib.Meta.NormNum.IsNat (f a b) c
def Tactic.ReduceModChar.normBareNumeral E1 #
{u : Lean.Level} →
{α : Q(Type u)} →
(n n' : Q(ℕ)) →
Q(Mathlib.Meta.NormNum.IsNat «$n» «$n'») →
(e : Q(«$α»)) → (x : Q(Ring «$α»)) → Q(CharP «$α» «$n») → Lean.MetaM (Mathlib.Meta.NormNum.Result e)
Evaluates e to an integer using norm_num and reduces the result modulo n.
opaque Tactic.ReduceModChar.normPow E1 #
{u : Lean.Level} →
{α : Q(Type u)} →
(n n' : Q(ℕ)) →
Q(Mathlib.Meta.NormNum.IsNat «$n» «$n'») →
(e : Q(«$α»)) → (x : Q(Ring «$α»)) → Q(CharP «$α» «$n») → Lean.MetaM (Mathlib.Meta.NormNum.Result e)
Given an expression of the form a ^ b in a ring of characteristic n, reduces a
modulo n recursively and then calculates a ^ b using fast modular exponentiation.
opaque Tactic.ReduceModChar.normIntNumeral' E1 #
{u : Lean.Level} →
{α : Q(Type u)} →
(n n' : Q(ℕ)) →
Q(Mathlib.Meta.NormNum.IsNat «$n» «$n'») →
(e : Q(«$α»)) → (x : Q(Ring «$α»)) → Q(CharP «$α» «$n») → Lean.MetaM (Mathlib.Meta.NormNum.Result e)
If e is of the form a ^ b, reduce it using fast modular exponentiation, otherwise
reduce it using norm_num.
theorem Tactic.ReduceModChar.CharP.intCast_eq_mod E1 #
∀ (R : Type u_1) [inst : Ring R] (p : ℕ) [CharP R p] (k : ℤ), ↑k = ↑(k % ↑p)
def Tactic.ReduceModChar.normIntNumeral E1 #
{u : Lean.Level} →
{α : Q(Type u)} →
(n : Q(ℕ)) → (e : Q(«$α»)) → (x : Q(Ring «$α»)) → Q(CharP «$α» «$n») → Lean.MetaM (Mathlib.Meta.NormNum.Result e)
Given an integral expression e : t such that t is a ring of characteristic n,
reduce e modulo n.
theorem Tactic.ReduceModChar.CharP.neg_eq_sub_one_mul E1 #
∀ {α : Type u_1} [inst : Ring α] (n : ℕ),
CharP α n → ∀ (b : α) (a : ℕ) (a' : α), Mathlib.Meta.NormNum.IsNat (↑n - 1) a → ↑a = a' → -b = a' * b
def Tactic.ReduceModChar.normNeg E1 #
{u : Lean.Level} →
{α : Q(Type u)} →
(n : Q(ℕ)) → Q(«$α») → (_instRing : Q(Ring «$α»)) → Q(CharP «$α» «$n») → Lean.MetaM Lean.Meta.Simp.Result
Given an expression (-e) : t such that t is a ring of characteristic n,
simplify this to (n - 1) * e.
This should be called only when normIntNumeral fails, because normIntNumeral would otherwise
be more useful by evaluating -e mod n to an actual numeral.
theorem Tactic.ReduceModChar.CharP.neg_mul_eq_sub_one_mul E1 #
∀ {α : Type u_1} [inst : Ring α] (n : ℕ),
CharP α n →
∀ (a b : α) (na : ℕ) (na' : α), Mathlib.Meta.NormNum.IsNat ((↑n - 1) * a) na → ↑na = na' → -(a * b) = na' * b
def Tactic.ReduceModChar.normNegCoeffMul E1 #
{u : Lean.Level} →
{α : Q(Type u)} →
(n : Q(ℕ)) → Q(«$α») → (_instRing : Q(Ring «$α»)) → Q(CharP «$α» «$n») → Lean.MetaM Lean.Meta.Simp.Result
Given an expression -(a * b) : t such that t is a ring of characteristic n,
and a is a numeral, simplify this to ((n - 1) * a) * b.
inductive Tactic.ReduceModChar.TypeToCharPResult E1 #
{u : Lean.Level} → Q(Type u) → Type
A TypeToCharPResult α indicates if α can be determined to be a ring of characteristic p.
ctor Tactic.ReduceModChar.TypeToCharPResult.intLike E0 #
{u : Lean.Level} →
{α : Q(Type u)} →
(n : Q(ℕ)) → (instRing : Q(Ring «$α»)) → Q(CharP «$α» «$n») → Tactic.ReduceModChar.TypeToCharPResult α
ctor Tactic.ReduceModChar.TypeToCharPResult.failure E0 #
{u : Lean.Level} → {α : Q(Type u)} → Tactic.ReduceModChar.TypeToCharPResult α
instance Tactic.ReduceModChar.instInhabitedTypeToCharPResult E0 #
{u : Lean.Level} → {α : Q(Type u)} → Inhabited (Tactic.ReduceModChar.TypeToCharPResult α)
opaque Tactic.ReduceModChar.typeToCharP E1 #
{u : Lean.Level} → optParam Bool false → (t : Q(Type u)) → Lean.MetaM (Tactic.ReduceModChar.TypeToCharPResult t)
Determine the characteristic of a ring from the type.
This should be fast, so this pattern-matches on the type, rather than searching for a
CharP instance.
Use typeToCharP (expensive := true) to do more work in finding the characteristic,
in particular it will search for a CharP instance in the context.
def Tactic.ReduceModChar.matchAndNorm E1 #
optParam Bool false → Lean.Expr → Lean.MetaM Lean.Meta.Simp.Result
Given an expression e, determine whether it is a numeric expression in characteristic n,
and if so, reduce e modulo n.
This is not a norm_num plugin because it does not match on the syntax of e,
rather it matches on the type of e.
Use matchAndNorm (expensive := true) to do more work in finding the characteristic of
the type of e.
def Tactic.ReduceModChar.derive E1 #
optParam Bool false → Lean.Expr → Lean.MetaM Lean.Meta.Simp.Result
Reduce all numeric subexpressions of e modulo their characteristic.
Use derive (expensive := true) to do more work in finding the characteristic of
the type of e.
def Tactic.ReduceModChar.reduce_mod_char E1 #
Lean.ParserDescr
The tactic reduce_mod_char looks for numeric expressions in characteristic p
and reduces these to lie between 0 and p.
For example:
example : (5 : ZMod 4) = 1 := by reduce_mod_char
example : (X ^ 2 - 3 * X + 4 : (ZMod 4)[X]) = X ^ 2 + X := by reduce_mod_char
It also handles negation, turning it into multiplication by p - 1,
and similarly subtraction.
This tactic uses the type of the subexpression to figure out if it is indeed of positive
characteristic, for improved performance compared to trying to synthesise a CharP instance.
The variant reduce_mod_char! also tries to use CharP R n hypotheses in the context.
(Limitations of the typeclass system mean the tactic can't search for a CharP R n instance if
n is not yet known; use have : CharP R n := inferInstance; reduce_mod_char! as a workaround.)
def Tactic.ReduceModChar.reduce_mod_char! E1 #
Lean.ParserDescr
The tactic reduce_mod_char looks for numeric expressions in characteristic p
and reduces these to lie between 0 and p.
For example:
example : (5 : ZMod 4) = 1 := by reduce_mod_char
example : (X ^ 2 - 3 * X + 4 : (ZMod 4)[X]) = X ^ 2 + X := by reduce_mod_char
It also handles negation, turning it into multiplication by p - 1,
and similarly subtraction.
This tactic uses the type of the subexpression to figure out if it is indeed of positive
characteristic, for improved performance compared to trying to synthesise a CharP instance.
The variant reduce_mod_char! also tries to use CharP R n hypotheses in the context.
(Limitations of the typeclass system mean the tactic can't search for a CharP R n instance if
n is not yet known; use have : CharP R n := inferInstance; reduce_mod_char! as a workaround.)