fact stringlengths 6 3.84k | type stringclasses 11
values | library stringclasses 32
values | imports listlengths 1 14 | filename stringlengths 20 95 | symbolic_name stringlengths 1 90 | docstring stringlengths 7 20k ⌀ |
|---|---|---|---|---|---|---|
List.range_succ_eq_map' {n nn n' : ℕ} (pn : NormNum.IsNat n nn) (pn' : nn = Nat.succ n') :
List.range n = 0 :: List.map Nat.succ (List.range n') := by
rw [pn.out, Nat.cast_id, pn', List.range_succ_eq_map]
set_option linter.unusedVariables false in | lemma | Tactic | [
"Mathlib.Tactic.NormNum.Basic",
"Mathlib.Data.List.FinRange",
"Mathlib.Algebra.BigOperators.Group.Finset.Basic"
] | Mathlib/Tactic/NormNum/BigOperators.lean | List.range_succ_eq_map' | null |
partial List.proveNilOrCons {u : Level} {α : Q(Type u)} (s : Q(List $α)) :
MetaM (List.ProveNilOrConsResult s) :=
s.withApp fun e a =>
match (e, e.constName, a) with
| (_, ``EmptyCollection.emptyCollection, _) => haveI : $s =Q {} := ⟨⟩; pure (.nil q(.refl []))
| (_, ``List.nil, _) => haveI : $s =Q [] := ⟨⟩;... | def | Tactic | [
"Mathlib.Tactic.NormNum.Basic",
"Mathlib.Data.List.FinRange",
"Mathlib.Algebra.BigOperators.Group.Finset.Basic"
] | Mathlib/Tactic/NormNum/BigOperators.lean | List.proveNilOrCons | Either show the expression `s : Q(List α)` is Nil, or remove one element from it.
Fails if we cannot determine which of the alternatives apply to the expression. |
Multiset.ProveZeroOrConsResult {α : Q(Type u)} (s : Q(Multiset $α))
/-- The set is zero. -/
| zero (pf : Q($s = 0))
/-- The set equals `a` inserted into the strict subset `s'`. -/
| cons (a : Q($α)) (s' : Q(Multiset $α)) (pf : Q($s = Multiset.cons $a $s')) | inductive | Tactic | [
"Mathlib.Tactic.NormNum.Basic",
"Mathlib.Data.List.FinRange",
"Mathlib.Algebra.BigOperators.Group.Finset.Basic"
] | Mathlib/Tactic/NormNum/BigOperators.lean | Multiset.ProveZeroOrConsResult | This represents the result of trying to determine whether the given expression
`s : Q(Multiset $α)` is either empty or consists of an element inserted into a strict subset. |
Multiset.ProveZeroOrConsResult.uncheckedCast {α : Q(Type u)} {β : Q(Type v)}
(s : Q(Multiset $α)) (t : Q(Multiset $β)) :
Multiset.ProveZeroOrConsResult s → Multiset.ProveZeroOrConsResult t
| .zero pf => .zero pf
| .cons a s' pf => .cons a s' pf | def | Tactic | [
"Mathlib.Tactic.NormNum.Basic",
"Mathlib.Data.List.FinRange",
"Mathlib.Algebra.BigOperators.Group.Finset.Basic"
] | Mathlib/Tactic/NormNum/BigOperators.lean | Multiset.ProveZeroOrConsResult.uncheckedCast | If `s` unifies with `t`, convert a result for `s` to a result for `t`.
If `s` does not unify with `t`, this results in a type-incorrect proof. |
Multiset.ProveZeroOrConsResult.eq_trans {α : Q(Type u)} {s t : Q(Multiset $α)}
(eq : Q($s = $t)) :
Multiset.ProveZeroOrConsResult t → Multiset.ProveZeroOrConsResult s
| .zero pf => .zero q(Eq.trans $eq $pf)
| .cons a s' pf => .cons a s' q(Eq.trans $eq $pf) | def | Tactic | [
"Mathlib.Tactic.NormNum.Basic",
"Mathlib.Data.List.FinRange",
"Mathlib.Algebra.BigOperators.Group.Finset.Basic"
] | Mathlib/Tactic/NormNum/BigOperators.lean | Multiset.ProveZeroOrConsResult.eq_trans | If `s = t` and we can get the result for `t`, then we can get the result for `s`. |
Multiset.insert_eq_cons {α : Type*} (a : α) (s : Multiset α) :
insert a s = Multiset.cons a s :=
rfl | lemma | Tactic | [
"Mathlib.Tactic.NormNum.Basic",
"Mathlib.Data.List.FinRange",
"Mathlib.Algebra.BigOperators.Group.Finset.Basic"
] | Mathlib/Tactic/NormNum/BigOperators.lean | Multiset.insert_eq_cons | null |
Multiset.range_zero' {n : ℕ} (pn : NormNum.IsNat n 0) :
Multiset.range n = 0 := by rw [pn.out, Nat.cast_zero, Multiset.range_zero] | lemma | Tactic | [
"Mathlib.Tactic.NormNum.Basic",
"Mathlib.Data.List.FinRange",
"Mathlib.Algebra.BigOperators.Group.Finset.Basic"
] | Mathlib/Tactic/NormNum/BigOperators.lean | Multiset.range_zero' | null |
Multiset.range_succ' {n nn n' : ℕ} (pn : NormNum.IsNat n nn) (pn' : nn = Nat.succ n') :
Multiset.range n = n' ::ₘ Multiset.range n' := by
rw [pn.out, Nat.cast_id, pn', Multiset.range_succ] | lemma | Tactic | [
"Mathlib.Tactic.NormNum.Basic",
"Mathlib.Data.List.FinRange",
"Mathlib.Algebra.BigOperators.Group.Finset.Basic"
] | Mathlib/Tactic/NormNum/BigOperators.lean | Multiset.range_succ' | null |
partial Multiset.proveZeroOrCons {α : Q(Type u)} (s : Q(Multiset $α)) :
MetaM (Multiset.ProveZeroOrConsResult s) :=
match s.getAppFnArgs with
| (``EmptyCollection.emptyCollection, _) => haveI : $s =Q {} := ⟨⟩; pure (.zero q(rfl))
| (``Zero.zero, _) => haveI : $s =Q 0 := ⟨⟩; pure (.zero q(rfl))
| (``Multiset... | def | Tactic | [
"Mathlib.Tactic.NormNum.Basic",
"Mathlib.Data.List.FinRange",
"Mathlib.Algebra.BigOperators.Group.Finset.Basic"
] | Mathlib/Tactic/NormNum/BigOperators.lean | Multiset.proveZeroOrCons | Either show the expression `s : Q(Multiset α)` is Zero, or remove one element from it.
Fails if we cannot determine which of the alternatives apply to the expression. |
Finset.ProveEmptyOrConsResult {α : Q(Type u)} (s : Q(Finset $α))
/-- The set is empty. -/
| empty (pf : Q($s = ∅))
/-- The set equals `a` inserted into the strict subset `s'`. -/
| cons (a : Q($α)) (s' : Q(Finset $α)) (h : Q($a ∉ $s')) (pf : Q($s = Finset.cons $a $s' $h)) | inductive | Tactic | [
"Mathlib.Tactic.NormNum.Basic",
"Mathlib.Data.List.FinRange",
"Mathlib.Algebra.BigOperators.Group.Finset.Basic"
] | Mathlib/Tactic/NormNum/BigOperators.lean | Finset.ProveEmptyOrConsResult | This represents the result of trying to determine whether the given expression
`s : Q(Finset $α)` is either empty or consists of an element inserted into a strict subset. |
Finset.ProveEmptyOrConsResult.uncheckedCast {α : Q(Type u)} {β : Q(Type v)}
(s : Q(Finset $α)) (t : Q(Finset $β)) :
Finset.ProveEmptyOrConsResult s → Finset.ProveEmptyOrConsResult t
| .empty pf => .empty pf
| .cons a s' h pf => .cons a s' h pf | def | Tactic | [
"Mathlib.Tactic.NormNum.Basic",
"Mathlib.Data.List.FinRange",
"Mathlib.Algebra.BigOperators.Group.Finset.Basic"
] | Mathlib/Tactic/NormNum/BigOperators.lean | Finset.ProveEmptyOrConsResult.uncheckedCast | If `s` unifies with `t`, convert a result for `s` to a result for `t`.
If `s` does not unify with `t`, this results in a type-incorrect proof. |
Finset.ProveEmptyOrConsResult.eq_trans {α : Q(Type u)} {s t : Q(Finset $α)}
(eq : Q($s = $t)) :
Finset.ProveEmptyOrConsResult t → Finset.ProveEmptyOrConsResult s
| .empty pf => .empty q(Eq.trans $eq $pf)
| .cons a s' h pf => .cons a s' h q(Eq.trans $eq $pf) | def | Tactic | [
"Mathlib.Tactic.NormNum.Basic",
"Mathlib.Data.List.FinRange",
"Mathlib.Algebra.BigOperators.Group.Finset.Basic"
] | Mathlib/Tactic/NormNum/BigOperators.lean | Finset.ProveEmptyOrConsResult.eq_trans | If `s = t` and we can get the result for `t`, then we can get the result for `s`. |
Finset.insert_eq_cons {α : Type*} [DecidableEq α] (a : α) (s : Finset α) (h : a ∉ s) :
insert a s = Finset.cons a s h := by
simp | lemma | Tactic | [
"Mathlib.Tactic.NormNum.Basic",
"Mathlib.Data.List.FinRange",
"Mathlib.Algebra.BigOperators.Group.Finset.Basic"
] | Mathlib/Tactic/NormNum/BigOperators.lean | Finset.insert_eq_cons | null |
Finset.range_zero' {n : ℕ} (pn : NormNum.IsNat n 0) :
Finset.range n = {} := by rw [pn.out, Nat.cast_zero, Finset.range_zero] | lemma | Tactic | [
"Mathlib.Tactic.NormNum.Basic",
"Mathlib.Data.List.FinRange",
"Mathlib.Algebra.BigOperators.Group.Finset.Basic"
] | Mathlib/Tactic/NormNum/BigOperators.lean | Finset.range_zero' | null |
Finset.range_succ' {n nn n' : ℕ} (pn : NormNum.IsNat n nn) (pn' : nn = Nat.succ n') :
Finset.range n = Finset.cons n' (Finset.range n') Finset.notMem_range_self := by
rw [pn.out, Nat.cast_id, pn', Finset.range_add_one, Finset.insert_eq_cons] | lemma | Tactic | [
"Mathlib.Tactic.NormNum.Basic",
"Mathlib.Data.List.FinRange",
"Mathlib.Algebra.BigOperators.Group.Finset.Basic"
] | Mathlib/Tactic/NormNum/BigOperators.lean | Finset.range_succ' | null |
Finset.univ_eq_elems {α : Type*} [Fintype α] (elems : Finset α)
(complete : ∀ x : α, x ∈ elems) :
Finset.univ = elems := by
ext x; simpa using complete x | lemma | Tactic | [
"Mathlib.Tactic.NormNum.Basic",
"Mathlib.Data.List.FinRange",
"Mathlib.Algebra.BigOperators.Group.Finset.Basic"
] | Mathlib/Tactic/NormNum/BigOperators.lean | Finset.univ_eq_elems | null |
partial Finset.proveEmptyOrCons {α : Q(Type u)} (s : Q(Finset $α)) :
MetaM (ProveEmptyOrConsResult s) :=
match s.getAppFnArgs with
| (``EmptyCollection.emptyCollection, _) => haveI : $s =Q {} := ⟨⟩; pure (.empty q(rfl))
| (``Finset.cons, #[_, (a : Q($α)), (s' : Q(Finset $α)), (h : Q($a ∉ $s'))]) =>
haveI ... | def | Tactic | [
"Mathlib.Tactic.NormNum.Basic",
"Mathlib.Data.List.FinRange",
"Mathlib.Algebra.BigOperators.Group.Finset.Basic"
] | Mathlib/Tactic/NormNum/BigOperators.lean | Finset.proveEmptyOrCons | Either show the expression `s : Q(Finset α)` is empty, or remove one element from it.
Fails if we cannot determine which of the alternatives apply to the expression. |
Result.eq_trans {α : Q(Type u)} {a b : Q($α)} (eq : Q($a = $b)) : Result b → Result a
| .isBool true proof =>
have a : Q(Prop) := a
have b : Q(Prop) := b
have eq : Q($a = $b) := eq
have proof : Q($b) := proof
Result.isTrue (x := a) q($eq ▸ $proof)
| .isBool false proof =>
have a : Q(Prop) :=... | def | Tactic | [
"Mathlib.Tactic.NormNum.Basic",
"Mathlib.Data.List.FinRange",
"Mathlib.Algebra.BigOperators.Group.Finset.Basic"
] | Mathlib/Tactic/NormNum/BigOperators.lean | Result.eq_trans | If `a = b` and we can evaluate `b`, then we can evaluate `a`. |
protected Finset.sum_empty {β α : Type*} [CommSemiring β] (f : α → β) :
IsNat (Finset.sum ∅ f) 0 :=
⟨by simp⟩ | lemma | Tactic | [
"Mathlib.Tactic.NormNum.Basic",
"Mathlib.Data.List.FinRange",
"Mathlib.Algebra.BigOperators.Group.Finset.Basic"
] | Mathlib/Tactic/NormNum/BigOperators.lean | Finset.sum_empty | null |
protected Finset.prod_empty {β α : Type*} [CommSemiring β] (f : α → β) :
IsNat (Finset.prod ∅ f) 1 :=
⟨by simp⟩ | lemma | Tactic | [
"Mathlib.Tactic.NormNum.Basic",
"Mathlib.Data.List.FinRange",
"Mathlib.Algebra.BigOperators.Group.Finset.Basic"
] | Mathlib/Tactic/NormNum/BigOperators.lean | Finset.prod_empty | null |
partial evalFinsetBigop {α : Q(Type u)} {β : Q(Type v)}
(op : Q(Finset $α → ($α → $β) → $β))
(f : Q($α → $β))
(res_empty : Result q($op Finset.empty $f))
(res_cons : {a : Q($α)} -> {s' : Q(Finset $α)} -> {h : Q($a ∉ $s')} ->
Result (α := β) q($f $a) -> Result (α := β) q($op $s' $f) ->
MetaM ... | def | Tactic | [
"Mathlib.Tactic.NormNum.Basic",
"Mathlib.Data.List.FinRange",
"Mathlib.Algebra.BigOperators.Group.Finset.Basic"
] | Mathlib/Tactic/NormNum/BigOperators.lean | evalFinsetBigop | Evaluate a big operator applied to a finset by repeating `proveEmptyOrCons` until
we exhaust all elements of the set. |
@[norm_num @Finset.prod _ _ _ _ _]
partial evalFinsetProd : NormNumExt where eval {u β} e := do
let .app (.app (.app (.app (.app (.const ``Finset.prod [v, _]) α) β') _) s) f ←
whnfR e | failure
guard <| ← withNewMCtxDepth <| isDefEq β β'
have α : Q(Type v) := α
have s : Q(Finset $α) := s
have f : Q($α → $... | def | Tactic | [
"Mathlib.Tactic.NormNum.Basic",
"Mathlib.Data.List.FinRange",
"Mathlib.Algebra.BigOperators.Group.Finset.Basic"
] | Mathlib/Tactic/NormNum/BigOperators.lean | evalFinsetProd | `norm_num` plugin for evaluating products of finsets.
If your finset is not supported, you can add it to the match in `Finset.proveEmptyOrCons`. |
@[norm_num @Finset.sum _ _ _ _ _]
partial evalFinsetSum : NormNumExt where eval {u β} e := do
let .app (.app (.app (.app (.app (.const ``Finset.sum [v, _]) α) β') _) s) f ←
whnfR e | failure
guard <| ← withNewMCtxDepth <| isDefEq β β'
have α : Q(Type v) := α
have s : Q(Finset $α) := s
have f : Q($α → $β) ... | def | Tactic | [
"Mathlib.Tactic.NormNum.Basic",
"Mathlib.Data.List.FinRange",
"Mathlib.Algebra.BigOperators.Group.Finset.Basic"
] | Mathlib/Tactic/NormNum/BigOperators.lean | evalFinsetSum | `norm_num` plugin for evaluating sums of finsets.
If your finset is not supported, you can add it to the match in `Finset.proveEmptyOrCons`. |
NormNumExt where
/-- The extension should be run in the `pre` phase when used as simp plugin. -/
pre := true
/-- The extension should be run in the `post` phase when used as simp plugin. -/
post := true
/-- Attempts to prove an expression is equal to some explicit number of the relevant type. -/
eval {u : L... | structure | Tactic | [
"Mathlib.Lean.Expr.Rat",
"Mathlib.Tactic.Hint",
"Mathlib.Tactic.NormNum.Result",
"Mathlib.Util.AtLocation",
"Mathlib.Util.Qq",
"Lean.Elab.Tactic.Location"
] | Mathlib/Tactic/NormNum/Core.lean | NormNumExt | Attribute for identifying `norm_num` extensions. -/
syntax (name := norm_num) "norm_num " term,+ : attr
namespace Mathlib
namespace Meta.NormNum
initialize registerTraceClass `Tactic.norm_num
/--
An extension for `norm_num`. |
mkNormNumExt (n : Name) : ImportM NormNumExt := do
let { env, opts, .. } ← read
IO.ofExcept <| unsafe env.evalConstCheck NormNumExt opts ``NormNumExt n | def | Tactic | [
"Mathlib.Lean.Expr.Rat",
"Mathlib.Tactic.Hint",
"Mathlib.Tactic.NormNum.Result",
"Mathlib.Util.AtLocation",
"Mathlib.Util.Qq",
"Lean.Elab.Tactic.Location"
] | Mathlib/Tactic/NormNum/Core.lean | mkNormNumExt | Read a `norm_num` extension from a declaration of the right type. |
Entry := Array (Array DiscrTree.Key) × Name | abbrev | Tactic | [
"Mathlib.Lean.Expr.Rat",
"Mathlib.Tactic.Hint",
"Mathlib.Tactic.NormNum.Result",
"Mathlib.Util.AtLocation",
"Mathlib.Util.Qq",
"Lean.Elab.Tactic.Location"
] | Mathlib/Tactic/NormNum/Core.lean | Entry | Each `norm_num` extension is labelled with a collection of patterns
which determine the expressions to which it should be applied. |
NormNums where
/-- The tree of `norm_num` extensions. -/
tree : DiscrTree NormNumExt := {}
/-- Erased `norm_num`s. -/
erased : PHashSet Name := {}
deriving Inhabited | structure | Tactic | [
"Mathlib.Lean.Expr.Rat",
"Mathlib.Tactic.Hint",
"Mathlib.Tactic.NormNum.Result",
"Mathlib.Util.AtLocation",
"Mathlib.Util.Qq",
"Lean.Elab.Tactic.Location"
] | Mathlib/Tactic/NormNum/Core.lean | NormNums | The state of the `norm_num` extension environment |
derive {α : Q(Type u)} (e : Q($α)) (post := false) : MetaM (Result e) := do
if e.isRawNatLit then
let lit : Q(ℕ) := e
return .isNat (q(instAddMonoidWithOneNat) : Q(AddMonoidWithOne ℕ))
lit (q(IsNat.raw_refl $lit) : Expr)
profileitM Exception "norm_num" (← getOptions) do
let s ← saveState
let n... | def | Tactic | [
"Mathlib.Lean.Expr.Rat",
"Mathlib.Tactic.Hint",
"Mathlib.Tactic.NormNum.Result",
"Mathlib.Util.AtLocation",
"Mathlib.Util.Qq",
"Lean.Elab.Tactic.Location"
] | Mathlib/Tactic/NormNum/Core.lean | derive | Environment extensions for `norm_num` declarations -/
initialize normNumExt : ScopedEnvExtension Entry (Entry × NormNumExt) NormNums ←
-- we only need this to deduplicate entries in the DiscrTree
have : BEq NormNumExt := ⟨fun _ _ ↦ false⟩
/- Insert `v : NormNumExt` into the tree `dt` on all key sequences given in... |
deriveNat {α : Q(Type u)} (e : Q($α))
(_inst : Q(AddMonoidWithOne $α) := by with_reducible assumption) :
MetaM ((lit : Q(ℕ)) × Q(IsNat $e $lit)) := do
let .isNat _ lit proof ← derive e | failure
pure ⟨lit, proof⟩ | def | Tactic | [
"Mathlib.Lean.Expr.Rat",
"Mathlib.Tactic.Hint",
"Mathlib.Tactic.NormNum.Result",
"Mathlib.Util.AtLocation",
"Mathlib.Util.Qq",
"Lean.Elab.Tactic.Location"
] | Mathlib/Tactic/NormNum/Core.lean | deriveNat | Run each registered `norm_num` extension on a typed expression `e : α`,
returning a typed expression `lit : ℕ`, and a proof of `isNat e lit`. |
deriveInt {α : Q(Type u)} (e : Q($α))
(_inst : Q(Ring $α) := by with_reducible assumption) :
MetaM ((lit : Q(ℤ)) × Q(IsInt $e $lit)) := do
let some ⟨_, lit, proof⟩ := (← derive e).toInt | failure
pure ⟨lit, proof⟩ | def | Tactic | [
"Mathlib.Lean.Expr.Rat",
"Mathlib.Tactic.Hint",
"Mathlib.Tactic.NormNum.Result",
"Mathlib.Util.AtLocation",
"Mathlib.Util.Qq",
"Lean.Elab.Tactic.Location"
] | Mathlib/Tactic/NormNum/Core.lean | deriveInt | Run each registered `norm_num` extension on a typed expression `e : α`,
returning a typed expression `lit : ℤ`, and a proof of `IsInt e lit` in expression form. |
deriveRat {α : Q(Type u)} (e : Q($α))
(_inst : Q(DivisionRing $α) := by with_reducible assumption) :
MetaM (ℚ × (n : Q(ℤ)) × (d : Q(ℕ)) × Q(IsRat $e $n $d)) := do
let some res := (← derive e).toRat' | failure
pure res | def | Tactic | [
"Mathlib.Lean.Expr.Rat",
"Mathlib.Tactic.Hint",
"Mathlib.Tactic.NormNum.Result",
"Mathlib.Util.AtLocation",
"Mathlib.Util.Qq",
"Lean.Elab.Tactic.Location"
] | Mathlib/Tactic/NormNum/Core.lean | deriveRat | Run each registered `norm_num` extension on a typed expression `e : α`,
returning a rational number, typed expressions `n : ℤ` and `d : ℕ` for the numerator and
denominator, and a proof of `IsRat e n d` in expression form. |
deriveBool (p : Q(Prop)) : MetaM ((b : Bool) × BoolResult p b) := do
let .isBool b prf ← derive q($p) | failure
pure ⟨b, prf⟩ | def | Tactic | [
"Mathlib.Lean.Expr.Rat",
"Mathlib.Tactic.Hint",
"Mathlib.Tactic.NormNum.Result",
"Mathlib.Util.AtLocation",
"Mathlib.Util.Qq",
"Lean.Elab.Tactic.Location"
] | Mathlib/Tactic/NormNum/Core.lean | deriveBool | Run each registered `norm_num` extension on a typed expression `p : Prop`,
and returning the truth or falsity of `p' : Prop` from an equivalence `p ↔ p'`. |
deriveBoolOfIff (p p' : Q(Prop)) (hp : Q($p ↔ $p')) :
MetaM ((b : Bool) × BoolResult p' b) := do
let ⟨b, pb⟩ ← deriveBool p
match b with
| true => return ⟨true, q(Iff.mp $hp $pb)⟩
| false => return ⟨false, q((Iff.not $hp).mp $pb)⟩ | def | Tactic | [
"Mathlib.Lean.Expr.Rat",
"Mathlib.Tactic.Hint",
"Mathlib.Tactic.NormNum.Result",
"Mathlib.Util.AtLocation",
"Mathlib.Util.Qq",
"Lean.Elab.Tactic.Location"
] | Mathlib/Tactic/NormNum/Core.lean | deriveBoolOfIff | Run each registered `norm_num` extension on a typed expression `p : Prop`,
and returning the truth or falsity of `p' : Prop` from an equivalence `p ↔ p'`. |
eval (e : Expr) (post := false) : MetaM Simp.Result := do
if e.isExplicitNumber then return { expr := e }
let ⟨_, _, e⟩ ← inferTypeQ' e
(← derive e post).toSimpResult | def | Tactic | [
"Mathlib.Lean.Expr.Rat",
"Mathlib.Tactic.Hint",
"Mathlib.Tactic.NormNum.Result",
"Mathlib.Util.AtLocation",
"Mathlib.Util.Qq",
"Lean.Elab.Tactic.Location"
] | Mathlib/Tactic/NormNum/Core.lean | eval | Run each registered `norm_num` extension on an expression,
returning a `Simp.Result`. |
NormNums.eraseCore (d : NormNums) (declName : Name) : NormNums :=
{ d with erased := d.erased.insert declName } | def | Tactic | [
"Mathlib.Lean.Expr.Rat",
"Mathlib.Tactic.Hint",
"Mathlib.Tactic.NormNum.Result",
"Mathlib.Util.AtLocation",
"Mathlib.Util.Qq",
"Lean.Elab.Tactic.Location"
] | Mathlib/Tactic/NormNum/Core.lean | NormNums.eraseCore | Erases a name marked `norm_num` by adding it to the state's `erased` field and
removing it from the state's list of `Entry`s. |
NormNums.erase {m : Type → Type} [Monad m] [MonadError m] (d : NormNums) (declName : Name) :
m NormNums := do
unless d.tree.values.any (·.name == declName) && ! d.erased.contains declName
do
throwError "'{declName}' does not have [norm_num] attribute"
return d.eraseCore declName
initialize registerBuiltin... | def | Tactic | [
"Mathlib.Lean.Expr.Rat",
"Mathlib.Tactic.Hint",
"Mathlib.Tactic.NormNum.Result",
"Mathlib.Util.AtLocation",
"Mathlib.Util.Qq",
"Lean.Elab.Tactic.Location"
] | Mathlib/Tactic/NormNum/Core.lean | NormNums.erase | Erase a name marked as a `norm_num` attribute.
Check that it does in fact have the `norm_num` attribute by making sure it names a `NormNumExt`
found somewhere in the state's tree, and is not erased. |
tryNormNum (post := false) (e : Expr) : SimpM Simp.Step := do
try
return .done (← eval e post)
catch _ =>
return .continue
variable (ctx : Simp.Context) (useSimp := true) in
mutual
/-- A discharger which calls `norm_num`. -/
partial def discharge (e : Expr) : SimpM (Option Expr) := do (← deriveSimp e).o... | def | Tactic | [
"Mathlib.Lean.Expr.Rat",
"Mathlib.Tactic.Hint",
"Mathlib.Tactic.NormNum.Result",
"Mathlib.Util.AtLocation",
"Mathlib.Util.Qq",
"Lean.Elab.Tactic.Location"
] | Mathlib/Tactic/NormNum/Core.lean | tryNormNum | A simp plugin which calls `NormNum.eval`. |
getSimpContext (cfg args : Syntax) (simpOnly := false) : TacticM Simp.Context := do
let config ← elabSimpConfigCore cfg
let simpTheorems ←
if simpOnly then simpOnlyBuiltins.foldlM (·.addConst ·) {} else getSimpTheorems
let { ctx, .. } ←
elabSimpArgs args[0] (eraseLocal := false) (kind := .simp) (simprocs ... | def | Tactic | [
"Mathlib.Lean.Expr.Rat",
"Mathlib.Tactic.Hint",
"Mathlib.Tactic.NormNum.Result",
"Mathlib.Util.AtLocation",
"Mathlib.Util.Qq",
"Lean.Elab.Tactic.Location"
] | Mathlib/Tactic/NormNum/Core.lean | getSimpContext | Constructs a simp context from the simp argument syntax. |
elabNormNum (cfg args loc : Syntax) (simpOnly := false) (useSimp := true) :
TacticM Unit := withMainContext do
let ctx ← getSimpContext cfg args (!useSimp || simpOnly)
let loc := expandOptLocation loc
transformAtNondepPropLocation (fun e ctx ↦ deriveSimp ctx useSimp e) "norm_num" loc
(failIfUnchanged := f... | def | Tactic | [
"Mathlib.Lean.Expr.Rat",
"Mathlib.Tactic.Hint",
"Mathlib.Tactic.NormNum.Result",
"Mathlib.Util.AtLocation",
"Mathlib.Util.Qq",
"Lean.Elab.Tactic.Location"
] | Mathlib/Tactic/NormNum/Core.lean | elabNormNum | Elaborates a call to `norm_num only? [args]` or `norm_num1`.
* `args`: the `(simpArgs)?` syntax for simp arguments
* `loc`: the `(location)?` syntax for the optional location argument
* `simpOnly`: true if `only` was used in `norm_num`
* `useSimp`: false if `norm_num1` was used, in which case only the structural parts
... |
@[tactic normNum1Conv] elabNormNum1Conv : Tactic := fun _ ↦ withMainContext do
let ctx ← getSimpContext mkNullNode mkNullNode true
Conv.applySimpResult (← deriveSimp ctx (← instantiateMVars (← Conv.getLhs)) (useSimp := false))
@[inherit_doc normNum] syntax (name := normNumConv)
"norm_num" optConfig &" only"? (s... | def | Tactic | [
"Mathlib.Lean.Expr.Rat",
"Mathlib.Tactic.Hint",
"Mathlib.Tactic.NormNum.Result",
"Mathlib.Util.AtLocation",
"Mathlib.Util.Qq",
"Lean.Elab.Tactic.Location"
] | Mathlib/Tactic/NormNum/Core.lean | elabNormNum1Conv | Normalize numerical expressions. Supports the operations `+` `-` `*` `/` `⁻¹` `^` and `%`
over numerical types such as `ℕ`, `ℤ`, `ℚ`, `ℝ`, `ℂ` and some general algebraic types,
and can prove goals of the form `A = B`, `A ≠ B`, `A < B` and `A ≤ B`, where `A` and `B` are
numerical expressions. It also has a relatively si... |
@[tactic normNumConv] elabNormNumConv : Tactic := fun stx ↦ withMainContext do
let ctx ← getSimpContext stx[1] stx[3] !stx[2].isNone
Conv.applySimpResult (← deriveSimp ctx (← instantiateMVars (← Conv.getLhs)) (useSimp := true)) | def | Tactic | [
"Mathlib.Lean.Expr.Rat",
"Mathlib.Tactic.Hint",
"Mathlib.Tactic.NormNum.Result",
"Mathlib.Util.AtLocation",
"Mathlib.Util.Qq",
"Lean.Elab.Tactic.Location"
] | Mathlib/Tactic/NormNum/Core.lean | elabNormNumConv | Elaborator for `norm_num` conv tactic. |
isInt_ediv_zero : ∀ {a b r : ℤ}, IsInt a r → IsNat b (nat_lit 0) → IsNat (a / b) (nat_lit 0)
| _, _, _, ⟨rfl⟩, ⟨rfl⟩ => ⟨by simp [Int.ediv_zero]⟩ | lemma | Tactic | [
"Mathlib.Tactic.NormNum.Basic",
"Mathlib.Tactic.NormNum.Ineq"
] | Mathlib/Tactic/NormNum/DivMod.lean | isInt_ediv_zero | null |
isInt_ediv {a b q m a' : ℤ} {b' r : ℕ}
(ha : IsInt a a') (hb : IsNat b b')
(hm : q * b' = m) (h : r + m = a') (h₂ : Nat.blt r b' = true) :
IsInt (a / b) q := ⟨by
obtain ⟨⟨rfl⟩, ⟨rfl⟩⟩ := ha, hb
simp only [Nat.blt_eq] at h₂; simp only [← h, ← hm, Int.cast_id]
rw [Int.add_mul_ediv_right _ _ (Int.ofNat_n... | lemma | Tactic | [
"Mathlib.Tactic.NormNum.Basic",
"Mathlib.Tactic.NormNum.Ineq"
] | Mathlib/Tactic/NormNum/DivMod.lean | isInt_ediv | null |
isInt_ediv_neg {a b q q' : ℤ} (h : IsInt (a / -b) q) (hq : -q = q') : IsInt (a / b) q' :=
⟨by rw [Int.cast_id, ← hq, ← @Int.cast_id q, ← h.out, ← Int.ediv_neg, Int.neg_neg]⟩ | lemma | Tactic | [
"Mathlib.Tactic.NormNum.Basic",
"Mathlib.Tactic.NormNum.Ineq"
] | Mathlib/Tactic/NormNum/DivMod.lean | isInt_ediv_neg | null |
isNat_neg_of_isNegNat {a : ℤ} {b : ℕ} (h : IsInt a (.negOfNat b)) : IsNat (-a) b :=
⟨by simp [h.out]⟩
attribute [local instance] monadLiftOptionMetaM in | lemma | Tactic | [
"Mathlib.Tactic.NormNum.Basic",
"Mathlib.Tactic.NormNum.Ineq"
] | Mathlib/Tactic/NormNum/DivMod.lean | isNat_neg_of_isNegNat | null |
@[norm_num (_ : ℤ) / _, Int.ediv _ _]
partial evalIntDiv : NormNumExt where eval {u α} e := do
let .app (.app f (a : Q(ℤ))) (b : Q(ℤ)) ← whnfR e | failure
guard <|← withNewMCtxDepth <| isDefEq f q(HDiv.hDiv (α := ℤ))
haveI' : u =QL 0 := ⟨⟩; haveI' : $α =Q ℤ := ⟨⟩
haveI' : $e =Q ($a / $b) := ⟨⟩
let rℤ : Q(Ring... | def | Tactic | [
"Mathlib.Tactic.NormNum.Basic",
"Mathlib.Tactic.NormNum.Ineq"
] | Mathlib/Tactic/NormNum/DivMod.lean | evalIntDiv | The `norm_num` extension which identifies expressions of the form `Int.ediv a b`,
such that `norm_num` successfully recognises both `a` and `b`. |
isInt_emod_zero : ∀ {a b r : ℤ}, IsInt a r → IsNat b (nat_lit 0) → IsInt (a % b) r
| _, _, _, e, ⟨rfl⟩ => by simp [e] | lemma | Tactic | [
"Mathlib.Tactic.NormNum.Basic",
"Mathlib.Tactic.NormNum.Ineq"
] | Mathlib/Tactic/NormNum/DivMod.lean | isInt_emod_zero | null |
isInt_emod {a b q m a' : ℤ} {b' r : ℕ}
(ha : IsInt a a') (hb : IsNat b b')
(hm : q * b' = m) (h : r + m = a') (h₂ : Nat.blt r b' = true) :
IsNat (a % b) r := ⟨by
obtain ⟨⟨rfl⟩, ⟨rfl⟩⟩ := ha, hb
simp only [← h, ← hm, Int.add_mul_emod_self_right]
rw [Int.emod_eq_of_lt] <;> [simp; simpa using h₂]⟩ | lemma | Tactic | [
"Mathlib.Tactic.NormNum.Basic",
"Mathlib.Tactic.NormNum.Ineq"
] | Mathlib/Tactic/NormNum/DivMod.lean | isInt_emod | null |
isInt_emod_neg {a b : ℤ} {r : ℕ} (h : IsNat (a % -b) r) : IsNat (a % b) r :=
⟨by rw [← Int.emod_neg, h.out]⟩
attribute [local instance] monadLiftOptionMetaM in | lemma | Tactic | [
"Mathlib.Tactic.NormNum.Basic",
"Mathlib.Tactic.NormNum.Ineq"
] | Mathlib/Tactic/NormNum/DivMod.lean | isInt_emod_neg | null |
@[norm_num (_ : ℤ) % _, Int.emod _ _]
partial evalIntMod : NormNumExt where eval {u α} e := do
let .app (.app f (a : Q(ℤ))) (b : Q(ℤ)) ← whnfR e | failure
guard <|← withNewMCtxDepth <| isDefEq f q(HMod.hMod (α := ℤ))
haveI' : u =QL 0 := ⟨⟩; haveI' : $α =Q ℤ := ⟨⟩
haveI' : $e =Q ($a % $b) := ⟨⟩
let rℤ : Q(Ring... | def | Tactic | [
"Mathlib.Tactic.NormNum.Basic",
"Mathlib.Tactic.NormNum.Ineq"
] | Mathlib/Tactic/NormNum/DivMod.lean | evalIntMod | The `norm_num` extension which identifies expressions of the form `Int.emod a b`,
such that `norm_num` successfully recognises both `a` and `b`. |
isInt_dvd_true : {a b : ℤ} → {a' b' c : ℤ} →
IsInt a a' → IsInt b b' → Int.mul a' c = b' → a ∣ b
| _, _, _, _, _, ⟨rfl⟩, ⟨rfl⟩, rfl => ⟨_, rfl⟩ | theorem | Tactic | [
"Mathlib.Tactic.NormNum.Basic",
"Mathlib.Tactic.NormNum.Ineq"
] | Mathlib/Tactic/NormNum/DivMod.lean | isInt_dvd_true | null |
isInt_dvd_false : {a b : ℤ} → {a' b' : ℤ} →
IsInt a a' → IsInt b b' → Int.emod b' a' != 0 → ¬a ∣ b
| _, _, _, _, ⟨rfl⟩, ⟨rfl⟩, e => mt Int.emod_eq_zero_of_dvd (by simpa using e)
attribute [local instance] monadLiftOptionMetaM in | theorem | Tactic | [
"Mathlib.Tactic.NormNum.Basic",
"Mathlib.Tactic.NormNum.Ineq"
] | Mathlib/Tactic/NormNum/DivMod.lean | isInt_dvd_false | null |
@[norm_num (_ : ℤ) ∣ _] evalIntDvd : NormNumExt where eval {u α} e := do
let .app (.app f (a : Q(ℤ))) (b : Q(ℤ)) ← whnfR e | failure
haveI' : u =QL 0 := ⟨⟩; haveI' : $α =Q Prop := ⟨⟩
haveI' : $e =Q ($a ∣ $b) := ⟨⟩
guard <|← withNewMCtxDepth <| isDefEq f q(Dvd.dvd (α := ℤ))
let rℤ : Q(Ring ℤ) := q(Int.instRing... | def | Tactic | [
"Mathlib.Tactic.NormNum.Basic",
"Mathlib.Tactic.NormNum.Ineq"
] | Mathlib/Tactic/NormNum/DivMod.lean | evalIntDvd | The `norm_num` extension which identifies expressions of the form `(a : ℤ) ∣ b`,
such that `norm_num` successfully recognises both `a` and `b`. |
isNat_eq_false [AddMonoidWithOne α] [CharZero α] : {a b : α} → {a' b' : ℕ} →
IsNat a a' → IsNat b b' → Nat.beq a' b' = false → ¬a = b
| _, _, _, _, ⟨rfl⟩, ⟨rfl⟩, h => by simpa using Nat.ne_of_beq_eq_false h | theorem | Tactic | [
"Mathlib.Tactic.NormNum.Inv"
] | Mathlib/Tactic/NormNum/Eq.lean | isNat_eq_false | null |
isInt_eq_false [Ring α] [CharZero α] : {a b : α} → {a' b' : ℤ} →
IsInt a a' → IsInt b b' → decide (a' = b') = false → ¬a = b
| _, _, _, _, ⟨rfl⟩, ⟨rfl⟩, h => by simpa using of_decide_eq_false h | theorem | Tactic | [
"Mathlib.Tactic.NormNum.Inv"
] | Mathlib/Tactic/NormNum/Eq.lean | isInt_eq_false | null |
NNRat.invOf_denom_swap [Semiring α] (n₁ n₂ : ℕ) (a₁ a₂ : α)
[Invertible a₁] [Invertible a₂] : n₁ * ⅟a₁ = n₂ * ⅟a₂ ↔ n₁ * a₂ = n₂ * a₁ := by
rw [mul_invOf_eq_iff_eq_mul_right, ← Nat.commute_cast, mul_assoc,
← mul_left_eq_iff_eq_invOf_mul, Nat.commute_cast] | theorem | Tactic | [
"Mathlib.Tactic.NormNum.Inv"
] | Mathlib/Tactic/NormNum/Eq.lean | NNRat.invOf_denom_swap | null |
isNNRat_eq_false [Semiring α] [CharZero α] : {a b : α} → {na nb : ℕ} → {da db : ℕ} →
IsNNRat a na da → IsNNRat b nb db →
decide (Nat.mul na db = Nat.mul nb da) = false → ¬a = b
| _, _, _, _, _, _, ⟨_, rfl⟩, ⟨_, rfl⟩, h => by
rw [NNRat.invOf_denom_swap]; exact mod_cast of_decide_eq_false h | theorem | Tactic | [
"Mathlib.Tactic.NormNum.Inv"
] | Mathlib/Tactic/NormNum/Eq.lean | isNNRat_eq_false | null |
Rat.invOf_denom_swap [Ring α] (n₁ n₂ : ℤ) (a₁ a₂ : α)
[Invertible a₁] [Invertible a₂] : n₁ * ⅟a₁ = n₂ * ⅟a₂ ↔ n₁ * a₂ = n₂ * a₁ := by
rw [mul_invOf_eq_iff_eq_mul_right, ← Int.commute_cast, mul_assoc,
← mul_left_eq_iff_eq_invOf_mul, Int.commute_cast] | theorem | Tactic | [
"Mathlib.Tactic.NormNum.Inv"
] | Mathlib/Tactic/NormNum/Eq.lean | Rat.invOf_denom_swap | null |
isRat_eq_false [Ring α] [CharZero α] : {a b : α} → {na nb : ℤ} → {da db : ℕ} →
IsRat a na da → IsRat b nb db →
decide (Int.mul na (.ofNat db) = Int.mul nb (.ofNat da)) = false → ¬a = b
| _, _, _, _, _, _, ⟨_, rfl⟩, ⟨_, rfl⟩, h => by
rw [Rat.invOf_denom_swap]; exact mod_cast of_decide_eq_false h
attribute ... | theorem | Tactic | [
"Mathlib.Tactic.NormNum.Inv"
] | Mathlib/Tactic/NormNum/Eq.lean | isRat_eq_false | null |
@[norm_num _ = _] evalEq : NormNumExt where eval {v β} e := do
haveI' : v =QL 0 := ⟨⟩; haveI' : $β =Q Prop := ⟨⟩
let .app (.app f a) b ← whnfR e | failure
let ⟨u, α, a⟩ ← inferTypeQ' a
have b : Q($α) := b
haveI' : $e =Q ($a = $b) := ⟨⟩
guard <|← withNewMCtxDepth <| isDefEq f q(Eq (α := $α))
let ra ← deriv... | def | Tactic | [
"Mathlib.Tactic.NormNum.Inv"
] | Mathlib/Tactic/NormNum/Eq.lean | evalEq | The `norm_num` extension which identifies expressions of the form `a = b`,
such that `norm_num` successfully recognises both `a` and `b`. |
int_gcd_helper' {d : ℕ} {x y : ℤ} (a b : ℤ) (h₁ : (d : ℤ) ∣ x) (h₂ : (d : ℤ) ∣ y)
(h₃ : x * a + y * b = d) : Int.gcd x y = d := by
refine Nat.dvd_antisymm ?_ (Int.natCast_dvd_natCast.1 (Int.dvd_coe_gcd h₁ h₂))
rw [← Int.natCast_dvd_natCast, ← h₃]
apply dvd_add
· exact (Int.gcd_dvd_left ..).mul_right _
· e... | theorem | Tactic | [
"Mathlib.Algebra.Ring.Divisibility.Basic",
"Mathlib.Data.Int.GCD",
"Mathlib.Tactic.NormNum"
] | Mathlib/Tactic/NormNum/GCD.lean | int_gcd_helper' | null |
nat_gcd_helper_dvd_left (x y : ℕ) (h : y % x = 0) : Nat.gcd x y = x :=
Nat.gcd_eq_left (Nat.dvd_of_mod_eq_zero h) | theorem | Tactic | [
"Mathlib.Algebra.Ring.Divisibility.Basic",
"Mathlib.Data.Int.GCD",
"Mathlib.Tactic.NormNum"
] | Mathlib/Tactic/NormNum/GCD.lean | nat_gcd_helper_dvd_left | null |
nat_gcd_helper_dvd_right (x y : ℕ) (h : x % y = 0) : Nat.gcd x y = y :=
Nat.gcd_eq_right (Nat.dvd_of_mod_eq_zero h) | theorem | Tactic | [
"Mathlib.Algebra.Ring.Divisibility.Basic",
"Mathlib.Data.Int.GCD",
"Mathlib.Tactic.NormNum"
] | Mathlib/Tactic/NormNum/GCD.lean | nat_gcd_helper_dvd_right | null |
nat_gcd_helper_2 (d x y a b : ℕ) (hu : x % d = 0) (hv : y % d = 0)
(h : x * a = y * b + d) : Nat.gcd x y = d := by
rw [← Int.gcd_natCast_natCast]
apply int_gcd_helper' a (-b)
(Int.natCast_dvd_natCast.mpr (Nat.dvd_of_mod_eq_zero hu))
(Int.natCast_dvd_natCast.mpr (Nat.dvd_of_mod_eq_zero hv))
rw [mul_neg... | theorem | Tactic | [
"Mathlib.Algebra.Ring.Divisibility.Basic",
"Mathlib.Data.Int.GCD",
"Mathlib.Tactic.NormNum"
] | Mathlib/Tactic/NormNum/GCD.lean | nat_gcd_helper_2 | null |
nat_gcd_helper_1 (d x y a b : ℕ) (hu : x % d = 0) (hv : y % d = 0)
(h : y * b = x * a + d) : Nat.gcd x y = d :=
(Nat.gcd_comm _ _).trans <| nat_gcd_helper_2 _ _ _ _ _ hv hu h | theorem | Tactic | [
"Mathlib.Algebra.Ring.Divisibility.Basic",
"Mathlib.Data.Int.GCD",
"Mathlib.Tactic.NormNum"
] | Mathlib/Tactic/NormNum/GCD.lean | nat_gcd_helper_1 | null |
nat_gcd_helper_1' (x y a b : ℕ) (h : y * b = x * a + 1) :
Nat.gcd x y = 1 :=
nat_gcd_helper_1 1 _ _ _ _ (Nat.mod_one _) (Nat.mod_one _) h | theorem | Tactic | [
"Mathlib.Algebra.Ring.Divisibility.Basic",
"Mathlib.Data.Int.GCD",
"Mathlib.Tactic.NormNum"
] | Mathlib/Tactic/NormNum/GCD.lean | nat_gcd_helper_1' | null |
nat_gcd_helper_2' (x y a b : ℕ) (h : x * a = y * b + 1) :
Nat.gcd x y = 1 :=
nat_gcd_helper_2 1 _ _ _ _ (Nat.mod_one _) (Nat.mod_one _) h | theorem | Tactic | [
"Mathlib.Algebra.Ring.Divisibility.Basic",
"Mathlib.Data.Int.GCD",
"Mathlib.Tactic.NormNum"
] | Mathlib/Tactic/NormNum/GCD.lean | nat_gcd_helper_2' | null |
nat_lcm_helper (x y d m : ℕ) (hd : Nat.gcd x y = d)
(d0 : Nat.beq d 0 = false)
(dm : x * y = d * m) : Nat.lcm x y = m :=
mul_right_injective₀ (Nat.ne_of_beq_eq_false d0) <| by
dsimp only
rw [← dm, ← hd, Nat.gcd_mul_lcm] | theorem | Tactic | [
"Mathlib.Algebra.Ring.Divisibility.Basic",
"Mathlib.Data.Int.GCD",
"Mathlib.Tactic.NormNum"
] | Mathlib/Tactic/NormNum/GCD.lean | nat_lcm_helper | null |
int_gcd_helper {x y : ℤ} {x' y' d : ℕ}
(hx : x.natAbs = x') (hy : y.natAbs = y') (h : Nat.gcd x' y' = d) :
Int.gcd x y = d := by subst_vars; rw [Int.gcd_def] | theorem | Tactic | [
"Mathlib.Algebra.Ring.Divisibility.Basic",
"Mathlib.Data.Int.GCD",
"Mathlib.Tactic.NormNum"
] | Mathlib/Tactic/NormNum/GCD.lean | int_gcd_helper | null |
int_lcm_helper {x y : ℤ} {x' y' d : ℕ}
(hx : x.natAbs = x') (hy : y.natAbs = y') (h : Nat.lcm x' y' = d) :
Int.lcm x y = d := by subst_vars; rw [Int.lcm_def]
open Qq Lean Elab.Tactic Mathlib.Meta.NormNum | theorem | Tactic | [
"Mathlib.Algebra.Ring.Divisibility.Basic",
"Mathlib.Data.Int.GCD",
"Mathlib.Tactic.NormNum"
] | Mathlib/Tactic/NormNum/GCD.lean | int_lcm_helper | null |
isNat_gcd : {x y nx ny z : ℕ} →
IsNat x nx → IsNat y ny → Nat.gcd nx ny = z → IsNat (Nat.gcd x y) z
| _, _, _, _, _, ⟨rfl⟩, ⟨rfl⟩, rfl => ⟨rfl⟩ | theorem | Tactic | [
"Mathlib.Algebra.Ring.Divisibility.Basic",
"Mathlib.Data.Int.GCD",
"Mathlib.Tactic.NormNum"
] | Mathlib/Tactic/NormNum/GCD.lean | isNat_gcd | null |
isNat_lcm : {x y nx ny z : ℕ} →
IsNat x nx → IsNat y ny → Nat.lcm nx ny = z → IsNat (Nat.lcm x y) z
| _, _, _, _, _, ⟨rfl⟩, ⟨rfl⟩, rfl => ⟨rfl⟩ | theorem | Tactic | [
"Mathlib.Algebra.Ring.Divisibility.Basic",
"Mathlib.Data.Int.GCD",
"Mathlib.Tactic.NormNum"
] | Mathlib/Tactic/NormNum/GCD.lean | isNat_lcm | null |
isInt_gcd : {x y nx ny : ℤ} → {z : ℕ} →
IsInt x nx → IsInt y ny → Int.gcd nx ny = z → IsNat (Int.gcd x y) z
| _, _, _, _, _, ⟨rfl⟩, ⟨rfl⟩, rfl => ⟨rfl⟩ | theorem | Tactic | [
"Mathlib.Algebra.Ring.Divisibility.Basic",
"Mathlib.Data.Int.GCD",
"Mathlib.Tactic.NormNum"
] | Mathlib/Tactic/NormNum/GCD.lean | isInt_gcd | null |
isInt_lcm : {x y nx ny : ℤ} → {z : ℕ} →
IsInt x nx → IsInt y ny → Int.lcm nx ny = z → IsNat (Int.lcm x y) z
| _, _, _, _, _, ⟨rfl⟩, ⟨rfl⟩, rfl => ⟨rfl⟩ | theorem | Tactic | [
"Mathlib.Algebra.Ring.Divisibility.Basic",
"Mathlib.Data.Int.GCD",
"Mathlib.Tactic.NormNum"
] | Mathlib/Tactic/NormNum/GCD.lean | isInt_lcm | null |
proveNatGCD (ex ey : Q(ℕ)) : (ed : Q(ℕ)) × Q(Nat.gcd $ex $ey = $ed) :=
match ex.natLit!, ey.natLit! with
| 0, _ => have : $ex =Q nat_lit 0 := ⟨⟩; ⟨ey, q(Nat.gcd_zero_left $ey)⟩
| _, 0 => have : $ey =Q nat_lit 0 := ⟨⟩; ⟨ex, q(Nat.gcd_zero_right $ex)⟩
| 1, _ => have : $ex =Q nat_lit 1 := ⟨⟩; ⟨q(nat_lit 1), q(Nat.... | def | Tactic | [
"Mathlib.Algebra.Ring.Divisibility.Basic",
"Mathlib.Data.Int.GCD",
"Mathlib.Tactic.NormNum"
] | Mathlib/Tactic/NormNum/GCD.lean | proveNatGCD | Given natural number literals `ex` and `ey`, return their GCD as a natural number literal
and an equality proof. Panics if `ex` or `ey` aren't natural number literals. |
@[norm_num Nat.gcd _ _]
evalNatGCD : NormNumExt where eval {u α} e := do
let .app (.app _ (x : Q(ℕ))) (y : Q(ℕ)) ← Meta.whnfR e | failure
haveI' : u =QL 0 := ⟨⟩; haveI' : $α =Q ℕ := ⟨⟩
haveI' : $e =Q Nat.gcd $x $y := ⟨⟩
let sℕ : Q(AddMonoidWithOne ℕ) := q(instAddMonoidWithOneNat)
let ⟨ex, p⟩ ← deriveNat x sℕ
... | def | Tactic | [
"Mathlib.Algebra.Ring.Divisibility.Basic",
"Mathlib.Data.Int.GCD",
"Mathlib.Tactic.NormNum"
] | Mathlib/Tactic/NormNum/GCD.lean | evalNatGCD | Evaluate the `Nat.gcd` function. |
proveNatLCM (ex ey : Q(ℕ)) : (ed : Q(ℕ)) × Q(Nat.lcm $ex $ey = $ed) :=
match ex.natLit!, ey.natLit! with
| 0, _ =>
show (ed : Q(ℕ)) × Q(Nat.lcm 0 $ey = $ed) from ⟨q(nat_lit 0), q(Nat.lcm_zero_left $ey)⟩
| _, 0 =>
show (ed : Q(ℕ)) × Q(Nat.lcm $ex 0 = $ed) from ⟨q(nat_lit 0), q(Nat.lcm_zero_right $ex)⟩
| ... | def | Tactic | [
"Mathlib.Algebra.Ring.Divisibility.Basic",
"Mathlib.Data.Int.GCD",
"Mathlib.Tactic.NormNum"
] | Mathlib/Tactic/NormNum/GCD.lean | proveNatLCM | Given natural number literals `ex` and `ey`, return their LCM as a natural number literal
and an equality proof. Panics if `ex` or `ey` aren't natural number literals. |
@[norm_num Nat.lcm _ _]
evalNatLCM : NormNumExt where eval {u α} e := do
let .app (.app _ (x : Q(ℕ))) (y : Q(ℕ)) ← Meta.whnfR e | failure
haveI' : u =QL 0 := ⟨⟩; haveI' : $α =Q ℕ := ⟨⟩
haveI' : $e =Q Nat.lcm $x $y := ⟨⟩
let sℕ : Q(AddMonoidWithOne ℕ) := q(instAddMonoidWithOneNat)
let ⟨ex, p⟩ ← deriveNat x sℕ
... | def | Tactic | [
"Mathlib.Algebra.Ring.Divisibility.Basic",
"Mathlib.Data.Int.GCD",
"Mathlib.Tactic.NormNum"
] | Mathlib/Tactic/NormNum/GCD.lean | evalNatLCM | Evaluates the `Nat.lcm` function. |
proveIntGCD (ex ey : Q(ℤ)) : (ed : Q(ℕ)) × Q(Int.gcd $ex $ey = $ed) :=
let ⟨ex', hx⟩ := rawIntLitNatAbs ex
let ⟨ey', hy⟩ := rawIntLitNatAbs ey
let ⟨ed, pf⟩ := proveNatGCD ex' ey'
⟨ed, q(int_gcd_helper $hx $hy $pf)⟩ | def | Tactic | [
"Mathlib.Algebra.Ring.Divisibility.Basic",
"Mathlib.Data.Int.GCD",
"Mathlib.Tactic.NormNum"
] | Mathlib/Tactic/NormNum/GCD.lean | proveIntGCD | Given two integers, return their GCD and an equality proof.
Panics if `ex` or `ey` aren't integer literals. |
@[norm_num Int.gcd _ _]
evalIntGCD : NormNumExt where eval {u α} e := do
let .app (.app _ (x : Q(ℤ))) (y : Q(ℤ)) ← Meta.whnfR e | failure
let ⟨ex, p⟩ ← deriveInt x _
let ⟨ey, q⟩ ← deriveInt y _
haveI' : u =QL 0 := ⟨⟩; haveI' : $α =Q ℕ := ⟨⟩
haveI' : $e =Q Int.gcd $x $y := ⟨⟩
let ⟨ed, pf⟩ := proveIntGCD ex e... | def | Tactic | [
"Mathlib.Algebra.Ring.Divisibility.Basic",
"Mathlib.Data.Int.GCD",
"Mathlib.Tactic.NormNum"
] | Mathlib/Tactic/NormNum/GCD.lean | evalIntGCD | Evaluates the `Int.gcd` function. |
proveIntLCM (ex ey : Q(ℤ)) : (ed : Q(ℕ)) × Q(Int.lcm $ex $ey = $ed) :=
let ⟨ex', hx⟩ := rawIntLitNatAbs ex
let ⟨ey', hy⟩ := rawIntLitNatAbs ey
let ⟨ed, pf⟩ := proveNatLCM ex' ey'
⟨ed, q(int_lcm_helper $hx $hy $pf)⟩ | def | Tactic | [
"Mathlib.Algebra.Ring.Divisibility.Basic",
"Mathlib.Data.Int.GCD",
"Mathlib.Tactic.NormNum"
] | Mathlib/Tactic/NormNum/GCD.lean | proveIntLCM | Given two integers, return their LCM and an equality proof.
Panics if `ex` or `ey` aren't integer literals. |
@[norm_num Int.lcm _ _]
evalIntLCM : NormNumExt where eval {u α} e := do
let .app (.app _ (x : Q(ℤ))) (y : Q(ℤ)) ← Meta.whnfR e | failure
let ⟨ex, p⟩ ← deriveInt x _
let ⟨ey, q⟩ ← deriveInt y _
haveI' : u =QL 0 := ⟨⟩; haveI' : $α =Q ℕ := ⟨⟩
haveI' : $e =Q Int.lcm $x $y := ⟨⟩
let ⟨ed, pf⟩ := proveIntLCM ex e... | def | Tactic | [
"Mathlib.Algebra.Ring.Divisibility.Basic",
"Mathlib.Data.Int.GCD",
"Mathlib.Tactic.NormNum"
] | Mathlib/Tactic/NormNum/GCD.lean | evalIntLCM | Evaluates the `Int.lcm` function. |
isInt_ratNum : ∀ {q : ℚ} {n : ℤ} {n' : ℕ} {d : ℕ},
IsRat q n d → n.natAbs = n' → n'.gcd d = 1 → IsInt q.num n
| _, n, _, d, ⟨hi, rfl⟩, rfl, h => by
constructor
have : 0 < d := Nat.pos_iff_ne_zero.mpr <| by simpa using hi.ne_zero
simp_rw [Rat.mul_num, Rat.den_intCast, invOf_eq_inv,
Rat.inv_natCas... | theorem | Tactic | [
"Mathlib.Algebra.Ring.Divisibility.Basic",
"Mathlib.Data.Int.GCD",
"Mathlib.Tactic.NormNum"
] | Mathlib/Tactic/NormNum/GCD.lean | isInt_ratNum | null |
isNat_ratDen : ∀ {q : ℚ} {n : ℤ} {n' : ℕ} {d : ℕ},
IsRat q n d → n.natAbs = n' → n'.gcd d = 1 → IsNat q.den d
| _, n, _, d, ⟨hi, rfl⟩, rfl, h => by
constructor
have : 0 < d := Nat.pos_iff_ne_zero.mpr <| by simpa using hi.ne_zero
simp_rw [Rat.mul_den, Rat.den_intCast, invOf_eq_inv,
Rat.inv_natCas... | theorem | Tactic | [
"Mathlib.Algebra.Ring.Divisibility.Basic",
"Mathlib.Data.Int.GCD",
"Mathlib.Tactic.NormNum"
] | Mathlib/Tactic/NormNum/GCD.lean | isNat_ratDen | null |
@[nolint unusedHavesSuffices, norm_num Rat.num _]
evalRatNum : NormNumExt where eval {u α} e := do
let .proj _ _ (q : Q(ℚ)) ← Meta.whnfR e | failure
have : u =QL 0 := ⟨⟩; have : $α =Q ℤ := ⟨⟩; have : $e =Q Rat.num $q := ⟨⟩
let ⟨q', n, d, eq⟩ ← deriveRat q (_inst := q(inferInstance))
let ⟨n', hn⟩ := rawIntLitNat... | def | Tactic | [
"Mathlib.Algebra.Ring.Divisibility.Basic",
"Mathlib.Data.Int.GCD",
"Mathlib.Tactic.NormNum"
] | Mathlib/Tactic/NormNum/GCD.lean | evalRatNum | Evaluates the `Rat.num` function. |
@[nolint unusedHavesSuffices, norm_num Rat.den _]
evalRatDen : NormNumExt where eval {u α} e := do
let .proj _ _ (q : Q(ℚ)) ← Meta.whnfR e | failure
have : u =QL 0 := ⟨⟩; have : $α =Q ℕ := ⟨⟩; have : $e =Q Rat.den $q := ⟨⟩
let ⟨q', n, d, eq⟩ ← deriveRat q (_inst := q(inferInstance))
let ⟨n', hn⟩ := rawIntLitNat... | def | Tactic | [
"Mathlib.Algebra.Ring.Divisibility.Basic",
"Mathlib.Data.Int.GCD",
"Mathlib.Tactic.NormNum"
] | Mathlib/Tactic/NormNum/GCD.lean | evalRatDen | Evaluates the `Rat.den` function. |
inferOrderedSemiring (α : Q(Type u)) : MetaM <|
(_ : Q(Semiring $α)) × (_ : Q(PartialOrder $α)) × Q(IsOrderedRing $α) :=
let go := do
let semiring ← synthInstanceQ q(Semiring $α)
let partialOrder ← synthInstanceQ q(PartialOrder $α)
let isOrderedRing ← synthInstanceQ q(IsOrderedRing $α)
return ⟨sem... | def | Tactic | [
"Mathlib.Tactic.NormNum.Eq",
"Mathlib.Algebra.Order.Field.Defs",
"Mathlib.Algebra.Order.Invertible",
"Mathlib.Algebra.Order.Monoid.WithTop",
"Mathlib.Algebra.Order.Ring.Cast"
] | Mathlib/Tactic/NormNum/Ineq.lean | inferOrderedSemiring | Helper function to synthesize typed `Semiring α` `PartialOrder α` `IsOrderedSemiring α`
expressions. |
inferOrderedRing (α : Q(Type u)) : MetaM <|
(_ : Q(Ring $α)) × (_ : Q(PartialOrder $α)) × Q(IsOrderedRing $α) :=
let go := do
let ring ← synthInstanceQ q(Ring $α)
let partialOrder ← synthInstanceQ q(PartialOrder $α)
let isOrderedRing ← synthInstanceQ q(IsOrderedRing $α)
return ⟨ring, partialOrder,... | def | Tactic | [
"Mathlib.Tactic.NormNum.Eq",
"Mathlib.Algebra.Order.Field.Defs",
"Mathlib.Algebra.Order.Invertible",
"Mathlib.Algebra.Order.Monoid.WithTop",
"Mathlib.Algebra.Order.Ring.Cast"
] | Mathlib/Tactic/NormNum/Ineq.lean | inferOrderedRing | Helper function to synthesize typed `Ring α` `PartialOrder α` `IsOrderedSemiring α`
expressions. |
inferLinearOrderedSemifield (α : Q(Type u)) : MetaM <|
(_ : Q(Semifield $α)) × (_ : Q(LinearOrder $α)) × Q(IsStrictOrderedRing $α) :=
let go := do
let semifield ← synthInstanceQ q(Semifield $α)
let linearOrder ← synthInstanceQ q(LinearOrder $α)
let isStrictOrderedRing ← synthInstanceQ q(IsStrictOrdere... | def | Tactic | [
"Mathlib.Tactic.NormNum.Eq",
"Mathlib.Algebra.Order.Field.Defs",
"Mathlib.Algebra.Order.Invertible",
"Mathlib.Algebra.Order.Monoid.WithTop",
"Mathlib.Algebra.Order.Ring.Cast"
] | Mathlib/Tactic/NormNum/Ineq.lean | inferLinearOrderedSemifield | Helper function to synthesize typed `Semifield α` `LinearOrder α` `IsStrictOrderedRing α`
expressions. |
inferLinearOrderedField (α : Q(Type u)) : MetaM <|
(_ : Q(Field $α)) × (_ : Q(LinearOrder $α)) × Q(IsStrictOrderedRing $α) :=
let go := do
let field ← synthInstanceQ q(Field $α)
let linearOrder ← synthInstanceQ q(LinearOrder $α)
let isStrictOrderedRing ← synthInstanceQ q(IsStrictOrderedRing $α)
re... | def | Tactic | [
"Mathlib.Tactic.NormNum.Eq",
"Mathlib.Algebra.Order.Field.Defs",
"Mathlib.Algebra.Order.Invertible",
"Mathlib.Algebra.Order.Monoid.WithTop",
"Mathlib.Algebra.Order.Ring.Cast"
] | Mathlib/Tactic/NormNum/Ineq.lean | inferLinearOrderedField | Helper function to synthesize typed `Field α` `LinearOrder α` `IsStrictOrderedRing α`
expressions. |
isNat_le_true [Semiring α] [PartialOrder α] [IsOrderedRing α] : {a b : α} → {a' b' : ℕ} →
IsNat a a' → IsNat b b' → Nat.ble a' b' = true → a ≤ b
| _, _, _, _, ⟨rfl⟩, ⟨rfl⟩, h => Nat.mono_cast (Nat.le_of_ble_eq_true h) | theorem | Tactic | [
"Mathlib.Tactic.NormNum.Eq",
"Mathlib.Algebra.Order.Field.Defs",
"Mathlib.Algebra.Order.Invertible",
"Mathlib.Algebra.Order.Monoid.WithTop",
"Mathlib.Algebra.Order.Ring.Cast"
] | Mathlib/Tactic/NormNum/Ineq.lean | isNat_le_true | null |
isNat_lt_false [Semiring α] [PartialOrder α] [IsOrderedRing α] {a b : α} {a' b' : ℕ}
(ha : IsNat a a') (hb : IsNat b b') (h : Nat.ble b' a' = true) : ¬a < b :=
not_lt_of_ge (isNat_le_true hb ha h) | theorem | Tactic | [
"Mathlib.Tactic.NormNum.Eq",
"Mathlib.Algebra.Order.Field.Defs",
"Mathlib.Algebra.Order.Invertible",
"Mathlib.Algebra.Order.Monoid.WithTop",
"Mathlib.Algebra.Order.Ring.Cast"
] | Mathlib/Tactic/NormNum/Ineq.lean | isNat_lt_false | null |
isNNRat_le_true [Semiring α] [LinearOrder α] [IsStrictOrderedRing α] :
{a b : α} → {na nb : ℕ} → {da db : ℕ} →
IsNNRat a na da → IsNNRat b nb db →
decide (Nat.mul na (db) ≤ Nat.mul nb (da)) → a ≤ b
| _, _, _, _, da, db, ⟨_, rfl⟩, ⟨_, rfl⟩, h => by
have h := (Nat.cast_le (α := α)).mpr <| of_decide_eq_t... | theorem | Tactic | [
"Mathlib.Tactic.NormNum.Eq",
"Mathlib.Algebra.Order.Field.Defs",
"Mathlib.Algebra.Order.Invertible",
"Mathlib.Algebra.Order.Monoid.WithTop",
"Mathlib.Algebra.Order.Ring.Cast"
] | Mathlib/Tactic/NormNum/Ineq.lean | isNNRat_le_true | null |
isNNRat_lt_true [Semiring α] [LinearOrder α] [IsStrictOrderedRing α] [Nontrivial α] :
{a b : α} → {na nb : ℕ} → {da db : ℕ} →
IsNNRat a na da → IsNNRat b nb db → decide (na * db < nb * da) → a < b
| _, _, _, _, da, db, ⟨_, rfl⟩, ⟨_, rfl⟩, h => by
have h := (Nat.cast_lt (α := α)).mpr <| of_decide_eq_true h... | theorem | Tactic | [
"Mathlib.Tactic.NormNum.Eq",
"Mathlib.Algebra.Order.Field.Defs",
"Mathlib.Algebra.Order.Invertible",
"Mathlib.Algebra.Order.Monoid.WithTop",
"Mathlib.Algebra.Order.Ring.Cast"
] | Mathlib/Tactic/NormNum/Ineq.lean | isNNRat_lt_true | null |
isNNRat_le_false [Semiring α] [LinearOrder α] [IsStrictOrderedRing α] [Nontrivial α]
{a b : α} {na nb : ℕ} {da db : ℕ}
(ha : IsNNRat a na da) (hb : IsNNRat b nb db) (h : decide (nb * da < na * db)) : ¬a ≤ b :=
not_le_of_gt (isNNRat_lt_true hb ha h) | theorem | Tactic | [
"Mathlib.Tactic.NormNum.Eq",
"Mathlib.Algebra.Order.Field.Defs",
"Mathlib.Algebra.Order.Invertible",
"Mathlib.Algebra.Order.Monoid.WithTop",
"Mathlib.Algebra.Order.Ring.Cast"
] | Mathlib/Tactic/NormNum/Ineq.lean | isNNRat_le_false | null |
isNNRat_lt_false [Semiring α] [LinearOrder α] [IsStrictOrderedRing α]
{a b : α} {na nb : ℕ} {da db : ℕ}
(ha : IsNNRat a na da) (hb : IsNNRat b nb db) (h : decide (nb * da ≤ na * db)) : ¬a < b :=
not_lt_of_ge (isNNRat_le_true hb ha h) | theorem | Tactic | [
"Mathlib.Tactic.NormNum.Eq",
"Mathlib.Algebra.Order.Field.Defs",
"Mathlib.Algebra.Order.Invertible",
"Mathlib.Algebra.Order.Monoid.WithTop",
"Mathlib.Algebra.Order.Ring.Cast"
] | Mathlib/Tactic/NormNum/Ineq.lean | isNNRat_lt_false | null |
isRat_le_true [Ring α] [LinearOrder α] [IsStrictOrderedRing α] :
{a b : α} → {na nb : ℤ} → {da db : ℕ} →
IsRat a na da → IsRat b nb db →
decide (Int.mul na (.ofNat db) ≤ Int.mul nb (.ofNat da)) → a ≤ b
| _, _, _, _, da, db, ⟨_, rfl⟩, ⟨_, rfl⟩, h => by
have h := Int.cast_mono (R := α) <| of_decide_eq_t... | theorem | Tactic | [
"Mathlib.Tactic.NormNum.Eq",
"Mathlib.Algebra.Order.Field.Defs",
"Mathlib.Algebra.Order.Invertible",
"Mathlib.Algebra.Order.Monoid.WithTop",
"Mathlib.Algebra.Order.Ring.Cast"
] | Mathlib/Tactic/NormNum/Ineq.lean | isRat_le_true | null |
isRat_lt_true [Ring α] [LinearOrder α] [IsStrictOrderedRing α] [Nontrivial α] :
{a b : α} → {na nb : ℤ} → {da db : ℕ} →
IsRat a na da → IsRat b nb db → decide (na * db < nb * da) → a < b
| _, _, _, _, da, db, ⟨_, rfl⟩, ⟨_, rfl⟩, h => by
have h := Int.cast_strictMono (R := α) <| of_decide_eq_true h
hav... | theorem | Tactic | [
"Mathlib.Tactic.NormNum.Eq",
"Mathlib.Algebra.Order.Field.Defs",
"Mathlib.Algebra.Order.Invertible",
"Mathlib.Algebra.Order.Monoid.WithTop",
"Mathlib.Algebra.Order.Ring.Cast"
] | Mathlib/Tactic/NormNum/Ineq.lean | isRat_lt_true | null |
isRat_le_false [Ring α] [LinearOrder α] [IsStrictOrderedRing α] [Nontrivial α]
{a b : α} {na nb : ℤ} {da db : ℕ}
(ha : IsRat a na da) (hb : IsRat b nb db) (h : decide (nb * da < na * db)) : ¬a ≤ b :=
not_le_of_gt (isRat_lt_true hb ha h) | theorem | Tactic | [
"Mathlib.Tactic.NormNum.Eq",
"Mathlib.Algebra.Order.Field.Defs",
"Mathlib.Algebra.Order.Invertible",
"Mathlib.Algebra.Order.Monoid.WithTop",
"Mathlib.Algebra.Order.Ring.Cast"
] | Mathlib/Tactic/NormNum/Ineq.lean | isRat_le_false | null |
isRat_lt_false [Ring α] [LinearOrder α] [IsStrictOrderedRing α]
{a b : α} {na nb : ℤ} {da db : ℕ}
(ha : IsRat a na da) (hb : IsRat b nb db) (h : decide (nb * da ≤ na * db)) : ¬a < b :=
not_lt_of_ge (isRat_le_true hb ha h)
/-! # (In)equalities -/ | theorem | Tactic | [
"Mathlib.Tactic.NormNum.Eq",
"Mathlib.Algebra.Order.Field.Defs",
"Mathlib.Algebra.Order.Invertible",
"Mathlib.Algebra.Order.Monoid.WithTop",
"Mathlib.Algebra.Order.Ring.Cast"
] | Mathlib/Tactic/NormNum/Ineq.lean | isRat_lt_false | null |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.