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
@[norm_num NNReal.sqrt _] evalNNRealSqrt : NormNumExt where eval {u α} e := do match u, α, e with | 0, ~q(NNReal), ~q(NNReal.sqrt $x) => match ← derive x with | .isBool _ _ => failure | .isNat sℝ ex pf => let x := ex.natLit! let y := Nat.sqrt x unless y * y = x do failure have ey : Q(ℕ) := mkRawNatLit y have pf₁ : Q($ey * $ey = $ex) := (q(Eq.refl $ex) : Expr) assumeInstancesCommute return .isNat sℝ ey q(isNat_nnrealSqrt $pf $pf₁) | .isNegNat _ ex pf => failure | .isNNRat sℝ eq n' ed pf => let n : ℕ := n'.natLit! let d : ℕ := ed.natLit! let sn := Nat.sqrt n let sd := Nat.sqrt d unless sn * sn = n ∧ sd * sd = d do failure have esn : Q(ℕ) := mkRawNatLit sn have esd : Q(ℕ) := mkRawNatLit sd have hn : Q($esn * $esn = $n') := (q(Eq.refl $n') : Expr) have hd : Q($esd * $esd = $ed) := (q(Eq.refl $ed) : Expr) assumeInstancesCommute return .isNNRat q($sℝ) (sn / sd) _ q($esd) q(isNNRat_nnrealSqrt_of_isNNRat $hn $hd $pf) | .isNegNNRat sℝ eq en ed pf => failure | _ => failure
def
Tactic
[ "Mathlib.Data.Real.Sqrt" ]
Mathlib/Tactic/NormNum/RealSqrt.lean
evalNNRealSqrt
`norm_num` extension that evaluates the function `NNReal.sqrt`.
instAddMonoidWithOneNat : AddMonoidWithOne ℕ := inferInstance
def
Tactic
[ "Mathlib.Algebra.Field.Defs", "Mathlib.Algebra.GroupWithZero.Invertible", "Mathlib.Data.Sigma.Basic", "Mathlib.Algebra.Ring.Nat", "Mathlib.Data.Int.Cast.Basic", "Qq.MetaM" ]
Mathlib/Tactic/NormNum/Result.lean
instAddMonoidWithOneNat
A shortcut (non)instance for `AddMonoidWithOne ℕ` to shrink generated proofs.
instAddMonoidWithOne' {α : Type u} [Semiring α] : AddMonoidWithOne α := inferInstance
def
Tactic
[ "Mathlib.Algebra.Field.Defs", "Mathlib.Algebra.GroupWithZero.Invertible", "Mathlib.Data.Sigma.Basic", "Mathlib.Algebra.Ring.Nat", "Mathlib.Data.Int.Cast.Basic", "Qq.MetaM" ]
Mathlib/Tactic/NormNum/Result.lean
instAddMonoidWithOne'
A shortcut (non)instance for `AddMonoidWithOne α` from `Semiring α` to shrink generated proofs.
instAddMonoidWithOne {α : Type u} [Ring α] : AddMonoidWithOne α := inferInstance
def
Tactic
[ "Mathlib.Algebra.Field.Defs", "Mathlib.Algebra.GroupWithZero.Invertible", "Mathlib.Data.Sigma.Basic", "Mathlib.Algebra.Ring.Nat", "Mathlib.Data.Int.Cast.Basic", "Qq.MetaM" ]
Mathlib/Tactic/NormNum/Result.lean
instAddMonoidWithOne
A shortcut (non)instance for `AddMonoidWithOne α` from `Ring α` to shrink generated proofs.
instAtLeastTwo (n : ℕ) : Nat.AtLeastTwo (n + 2) := inferInstance
lemma
Tactic
[ "Mathlib.Algebra.Field.Defs", "Mathlib.Algebra.GroupWithZero.Invertible", "Mathlib.Data.Sigma.Basic", "Mathlib.Algebra.Ring.Nat", "Mathlib.Data.Int.Cast.Basic", "Qq.MetaM" ]
Mathlib/Tactic/NormNum/Result.lean
instAtLeastTwo
A shortcut (non)instance for `Nat.AtLeastTwo (n + 2)` to shrink generated proofs.
inferAddMonoidWithOne (α : Q(Type u)) : MetaM Q(AddMonoidWithOne $α) := return ← synthInstanceQ q(AddMonoidWithOne $α) <|> throwError "not an AddMonoidWithOne"
def
Tactic
[ "Mathlib.Algebra.Field.Defs", "Mathlib.Algebra.GroupWithZero.Invertible", "Mathlib.Data.Sigma.Basic", "Mathlib.Algebra.Ring.Nat", "Mathlib.Data.Int.Cast.Basic", "Qq.MetaM" ]
Mathlib/Tactic/NormNum/Result.lean
inferAddMonoidWithOne
Helper function to synthesize a typed `AddMonoidWithOne α` expression.
inferSemiring (α : Q(Type u)) : MetaM Q(Semiring $α) := return ← synthInstanceQ q(Semiring $α) <|> throwError "not a semiring"
def
Tactic
[ "Mathlib.Algebra.Field.Defs", "Mathlib.Algebra.GroupWithZero.Invertible", "Mathlib.Data.Sigma.Basic", "Mathlib.Algebra.Ring.Nat", "Mathlib.Data.Int.Cast.Basic", "Qq.MetaM" ]
Mathlib/Tactic/NormNum/Result.lean
inferSemiring
Helper function to synthesize a typed `Semiring α` expression.
inferRing (α : Q(Type u)) : MetaM Q(Ring $α) := return ← synthInstanceQ q(Ring $α) <|> throwError "not a ring"
def
Tactic
[ "Mathlib.Algebra.Field.Defs", "Mathlib.Algebra.GroupWithZero.Invertible", "Mathlib.Data.Sigma.Basic", "Mathlib.Algebra.Ring.Nat", "Mathlib.Data.Int.Cast.Basic", "Qq.MetaM" ]
Mathlib/Tactic/NormNum/Result.lean
inferRing
Helper function to synthesize a typed `Ring α` expression.
mkRawIntLit (n : ℤ) : Q(ℤ) := let lit : Q(ℕ) := mkRawNatLit n.natAbs if 0 ≤ n then q(.ofNat $lit) else q(.negOfNat $lit)
def
Tactic
[ "Mathlib.Algebra.Field.Defs", "Mathlib.Algebra.GroupWithZero.Invertible", "Mathlib.Data.Sigma.Basic", "Mathlib.Algebra.Ring.Nat", "Mathlib.Data.Int.Cast.Basic", "Qq.MetaM" ]
Mathlib/Tactic/NormNum/Result.lean
mkRawIntLit
Represent an integer as a "raw" typed expression. This uses `.lit (.natVal n)` internally to represent a natural number, rather than the preferred `OfNat.ofNat` form. We use this internally to avoid unnecessary typeclass searches. This function is the inverse of `Expr.intLit!`.
mkRawRatLit (q : ℚ) : Q(ℚ) := let nlit : Q(ℤ) := mkRawIntLit q.num let dlit : Q(ℕ) := mkRawNatLit q.den q(mkRat $nlit $dlit)
def
Tactic
[ "Mathlib.Algebra.Field.Defs", "Mathlib.Algebra.GroupWithZero.Invertible", "Mathlib.Data.Sigma.Basic", "Mathlib.Algebra.Ring.Nat", "Mathlib.Data.Int.Cast.Basic", "Qq.MetaM" ]
Mathlib/Tactic/NormNum/Result.lean
mkRawRatLit
Represent an integer as a "raw" typed expression. This `.lit (.natVal n)` internally to represent a natural number, rather than the preferred `OfNat.ofNat` form. We use this internally to avoid unnecessary typeclass searches.
rawIntLitNatAbs (n : Q(ℤ)) : (m : Q(ℕ)) × Q(Int.natAbs $n = $m) := if n.isAppOfArity ``Int.ofNat 1 then have m : Q(ℕ) := n.appArg! ⟨m, show Q(Int.natAbs (Int.ofNat $m) = $m) from q(Int.natAbs_natCast $m)⟩ else if n.isAppOfArity ``Int.negOfNat 1 then have m : Q(ℕ) := n.appArg! ⟨m, show Q(Int.natAbs (Int.negOfNat $m) = $m) from q(Int.natAbs_neg $m)⟩ else panic! "not a raw integer literal"
def
Tactic
[ "Mathlib.Algebra.Field.Defs", "Mathlib.Algebra.GroupWithZero.Invertible", "Mathlib.Data.Sigma.Basic", "Mathlib.Algebra.Ring.Nat", "Mathlib.Data.Int.Cast.Basic", "Qq.MetaM" ]
Mathlib/Tactic/NormNum/Result.lean
rawIntLitNatAbs
Extract the raw natlit representing the absolute value of a raw integer literal (of the type produced by `Mathlib.Meta.NormNum.mkRawIntLit`) along with an equality proof.
mkOfNat (α : Q(Type u)) (_sα : Q(AddMonoidWithOne $α)) (lit : Q(ℕ)) : MetaM ((a' : Q($α)) × Q($lit = $a')) := do if α.isConstOf ``Nat then let a' : Q(ℕ) := q(OfNat.ofNat $lit : ℕ) pure ⟨a', (q(Eq.refl $a') : Expr)⟩ else if α.isConstOf ``Int then let a' : Q(ℤ) := q(OfNat.ofNat $lit : ℤ) pure ⟨a', (q(Eq.refl $a') : Expr)⟩ else if α.isConstOf ``Rat then let a' : Q(ℚ) := q(OfNat.ofNat $lit : ℚ) pure ⟨a', (q(Eq.refl $a') : Expr)⟩ else let some n := lit.rawNatLit? | failure match n with | 0 => pure ⟨q(0 : $α), (q(Nat.cast_zero (R := $α)) : Expr)⟩ | 1 => pure ⟨q(1 : $α), (q(Nat.cast_one (R := $α)) : Expr)⟩ | k+2 => let k : Q(ℕ) := mkRawNatLit k let _x : Q(Nat.AtLeastTwo $lit) := (q(instAtLeastTwo $k) : Expr) let a' : Q($α) := q(OfNat.ofNat $lit) pure ⟨a', (q(Eq.refl $a') : Expr)⟩
def
Tactic
[ "Mathlib.Algebra.Field.Defs", "Mathlib.Algebra.GroupWithZero.Invertible", "Mathlib.Data.Sigma.Basic", "Mathlib.Algebra.Ring.Nat", "Mathlib.Data.Int.Cast.Basic", "Qq.MetaM" ]
Mathlib/Tactic/NormNum/Result.lean
mkOfNat
Constructs an `ofNat` application `a'` with the canonical instance, together with a proof that the instance is equal to the result of `Nat.cast` on the given `AddMonoidWithOne` instance. This function is performance-critical, as many higher level tactics have to construct numerals. So rather than using typeclass search we hardcode the (relatively small) set of solutions to the typeclass problem.
IsNat {α : Type u} [AddMonoidWithOne α] (a : α) (n : ℕ) : Prop where /-- The element is equal to the coercion of the natural number. -/ out : a = n
structure
Tactic
[ "Mathlib.Algebra.Field.Defs", "Mathlib.Algebra.GroupWithZero.Invertible", "Mathlib.Data.Sigma.Basic", "Mathlib.Algebra.Ring.Nat", "Mathlib.Data.Int.Cast.Basic", "Qq.MetaM" ]
Mathlib/Tactic/NormNum/Result.lean
IsNat
Assert that an element of a semiring is equal to the coercion of some natural number.
IsNat.raw_refl (n : ℕ) : IsNat n n := ⟨rfl⟩
theorem
Tactic
[ "Mathlib.Algebra.Field.Defs", "Mathlib.Algebra.GroupWithZero.Invertible", "Mathlib.Data.Sigma.Basic", "Mathlib.Algebra.Ring.Nat", "Mathlib.Data.Int.Cast.Basic", "Qq.MetaM" ]
Mathlib/Tactic/NormNum/Result.lean
IsNat.raw_refl
null
@[simp] _root_.Nat.rawCast {α : Type u} [AddMonoidWithOne α] (n : ℕ) : α := n
def
Tactic
[ "Mathlib.Algebra.Field.Defs", "Mathlib.Algebra.GroupWithZero.Invertible", "Mathlib.Data.Sigma.Basic", "Mathlib.Algebra.Ring.Nat", "Mathlib.Data.Int.Cast.Basic", "Qq.MetaM" ]
Mathlib/Tactic/NormNum/Result.lean
_root_.Nat.rawCast
A "raw nat cast" is an expression of the form `(Nat.rawCast lit : α)` where `lit` is a raw natural number literal. These expressions are used by tactics like `ring` to decrease the number of typeclass arguments required in each use of a number literal at type `α`.
IsNat.to_eq {α : Type u} [AddMonoidWithOne α] {n} : {a a' : α} → IsNat a n → n = a' → a = a' | _, _, ⟨rfl⟩, rfl => rfl
theorem
Tactic
[ "Mathlib.Algebra.Field.Defs", "Mathlib.Algebra.GroupWithZero.Invertible", "Mathlib.Data.Sigma.Basic", "Mathlib.Algebra.Ring.Nat", "Mathlib.Data.Int.Cast.Basic", "Qq.MetaM" ]
Mathlib/Tactic/NormNum/Result.lean
IsNat.to_eq
null
IsNat.to_raw_eq {a : α} {n : ℕ} [AddMonoidWithOne α] : IsNat (a : α) n → a = n.rawCast | ⟨e⟩ => e
theorem
Tactic
[ "Mathlib.Algebra.Field.Defs", "Mathlib.Algebra.GroupWithZero.Invertible", "Mathlib.Data.Sigma.Basic", "Mathlib.Algebra.Ring.Nat", "Mathlib.Data.Int.Cast.Basic", "Qq.MetaM" ]
Mathlib/Tactic/NormNum/Result.lean
IsNat.to_raw_eq
null
IsNat.of_raw (α) [AddMonoidWithOne α] (n : ℕ) : IsNat (n.rawCast : α) n := ⟨rfl⟩ @[elab_as_elim]
theorem
Tactic
[ "Mathlib.Algebra.Field.Defs", "Mathlib.Algebra.GroupWithZero.Invertible", "Mathlib.Data.Sigma.Basic", "Mathlib.Algebra.Ring.Nat", "Mathlib.Data.Int.Cast.Basic", "Qq.MetaM" ]
Mathlib/Tactic/NormNum/Result.lean
IsNat.of_raw
null
isNat.natElim {p : ℕ → Prop} : {n : ℕ} → {n' : ℕ} → IsNat n n' → p n' → p n | _, _, ⟨rfl⟩, h => h
theorem
Tactic
[ "Mathlib.Algebra.Field.Defs", "Mathlib.Algebra.GroupWithZero.Invertible", "Mathlib.Data.Sigma.Basic", "Mathlib.Algebra.Ring.Nat", "Mathlib.Data.Int.Cast.Basic", "Qq.MetaM" ]
Mathlib/Tactic/NormNum/Result.lean
isNat.natElim
null
IsInt [Ring α] (a : α) (n : ℤ) : Prop where /-- The element is equal to the coercion of the integer. -/ out : a = n
structure
Tactic
[ "Mathlib.Algebra.Field.Defs", "Mathlib.Algebra.GroupWithZero.Invertible", "Mathlib.Data.Sigma.Basic", "Mathlib.Algebra.Ring.Nat", "Mathlib.Data.Int.Cast.Basic", "Qq.MetaM" ]
Mathlib/Tactic/NormNum/Result.lean
IsInt
Assert that an element of a ring is equal to the coercion of some integer.
@[simp] _root_.Int.rawCast [Ring α] (n : ℤ) : α := n
def
Tactic
[ "Mathlib.Algebra.Field.Defs", "Mathlib.Algebra.GroupWithZero.Invertible", "Mathlib.Data.Sigma.Basic", "Mathlib.Algebra.Ring.Nat", "Mathlib.Data.Int.Cast.Basic", "Qq.MetaM" ]
Mathlib/Tactic/NormNum/Result.lean
_root_.Int.rawCast
A "raw int cast" is an expression of the form: * `(Nat.rawCast lit : α)` where `lit` is a raw natural number literal * `(Int.rawCast (Int.negOfNat lit) : α)` where `lit` is a nonzero raw natural number literal (That is, we only actually use this function for negative integers.) This representation is used by tactics like `ring` to decrease the number of typeclass arguments required in each use of a number literal at type `α`.
IsInt.to_isNat {α} [Ring α] : ∀ {a : α} {n}, IsInt a (.ofNat n) → IsNat a n | _, _, ⟨rfl⟩ => ⟨by simp⟩
theorem
Tactic
[ "Mathlib.Algebra.Field.Defs", "Mathlib.Algebra.GroupWithZero.Invertible", "Mathlib.Data.Sigma.Basic", "Mathlib.Algebra.Ring.Nat", "Mathlib.Data.Int.Cast.Basic", "Qq.MetaM" ]
Mathlib/Tactic/NormNum/Result.lean
IsInt.to_isNat
null
IsNat.to_isInt {α} [Ring α] : ∀ {a : α} {n}, IsNat a n → IsInt a (.ofNat n) | _, _, ⟨rfl⟩ => ⟨by simp⟩
theorem
Tactic
[ "Mathlib.Algebra.Field.Defs", "Mathlib.Algebra.GroupWithZero.Invertible", "Mathlib.Data.Sigma.Basic", "Mathlib.Algebra.Ring.Nat", "Mathlib.Data.Int.Cast.Basic", "Qq.MetaM" ]
Mathlib/Tactic/NormNum/Result.lean
IsNat.to_isInt
null
IsInt.to_raw_eq {a : α} {n : ℤ} [Ring α] : IsInt (a : α) n → a = n.rawCast | ⟨e⟩ => e
theorem
Tactic
[ "Mathlib.Algebra.Field.Defs", "Mathlib.Algebra.GroupWithZero.Invertible", "Mathlib.Data.Sigma.Basic", "Mathlib.Algebra.Ring.Nat", "Mathlib.Data.Int.Cast.Basic", "Qq.MetaM" ]
Mathlib/Tactic/NormNum/Result.lean
IsInt.to_raw_eq
null
IsInt.of_raw (α) [Ring α] (n : ℤ) : IsInt (n.rawCast : α) n := ⟨rfl⟩
theorem
Tactic
[ "Mathlib.Algebra.Field.Defs", "Mathlib.Algebra.GroupWithZero.Invertible", "Mathlib.Data.Sigma.Basic", "Mathlib.Algebra.Ring.Nat", "Mathlib.Data.Int.Cast.Basic", "Qq.MetaM" ]
Mathlib/Tactic/NormNum/Result.lean
IsInt.of_raw
null
IsInt.neg_to_eq {α} [Ring α] {n} : {a a' : α} → IsInt a (.negOfNat n) → n = a' → a = -a' | _, _, ⟨rfl⟩, rfl => by simp [Int.negOfNat_eq, Int.cast_neg]
theorem
Tactic
[ "Mathlib.Algebra.Field.Defs", "Mathlib.Algebra.GroupWithZero.Invertible", "Mathlib.Data.Sigma.Basic", "Mathlib.Algebra.Ring.Nat", "Mathlib.Data.Int.Cast.Basic", "Qq.MetaM" ]
Mathlib/Tactic/NormNum/Result.lean
IsInt.neg_to_eq
null
IsInt.nonneg_to_eq {α} [Ring α] {n} {a a' : α} (h : IsInt a (.ofNat n)) (e : n = a') : a = a' := h.to_isNat.to_eq e
theorem
Tactic
[ "Mathlib.Algebra.Field.Defs", "Mathlib.Algebra.GroupWithZero.Invertible", "Mathlib.Data.Sigma.Basic", "Mathlib.Algebra.Ring.Nat", "Mathlib.Data.Int.Cast.Basic", "Qq.MetaM" ]
Mathlib/Tactic/NormNum/Result.lean
IsInt.nonneg_to_eq
null
IsRat [Ring α] (a : α) (num : ℤ) (denom : ℕ) : Prop | mk (inv : Invertible (denom : α)) (eq : a = num * ⅟(denom : α))
inductive
Tactic
[ "Mathlib.Algebra.Field.Defs", "Mathlib.Algebra.GroupWithZero.Invertible", "Mathlib.Data.Sigma.Basic", "Mathlib.Algebra.Ring.Nat", "Mathlib.Data.Int.Cast.Basic", "Qq.MetaM" ]
Mathlib/Tactic/NormNum/Result.lean
IsRat
Assert that an element of a ring is equal to `num / denom` (and `denom` is invertible so that this makes sense). We will usually also have `num` and `denom` coprime, although this is not part of the definition.
IsNNRat [Semiring α] (a : α) (num : ℕ) (denom : ℕ) : Prop | mk (inv : Invertible (denom : α)) (eq : a = num * ⅟(denom : α))
inductive
Tactic
[ "Mathlib.Algebra.Field.Defs", "Mathlib.Algebra.GroupWithZero.Invertible", "Mathlib.Data.Sigma.Basic", "Mathlib.Algebra.Ring.Nat", "Mathlib.Data.Int.Cast.Basic", "Qq.MetaM" ]
Mathlib/Tactic/NormNum/Result.lean
IsNNRat
Assert that an element of a semiring is equal to `num / denom` (and `denom` is invertible so that this makes sense). We will usually also have `num` and `denom` coprime, although this is not part of the definition.
@[simp] _root_.NNRat.rawCast [DivisionSemiring α] (n : ℕ) (d : ℕ) : α := n / d
def
Tactic
[ "Mathlib.Algebra.Field.Defs", "Mathlib.Algebra.GroupWithZero.Invertible", "Mathlib.Data.Sigma.Basic", "Mathlib.Algebra.Ring.Nat", "Mathlib.Data.Int.Cast.Basic", "Qq.MetaM" ]
Mathlib/Tactic/NormNum/Result.lean
_root_.NNRat.rawCast
A "raw nnrat cast" is an expression of the form: * `(Nat.rawCast lit : α)` where `lit` is a raw natural number literal * `(NNRat.rawCast n d : α)` where `n` is a raw nat literal, `d` is a raw nat literal, and `d` is not `1` or `0`. This representation is used by tactics like `ring` to decrease the number of typeclass arguments required in each use of a number literal at type `α`.
@[simp] _root_.Rat.rawCast [DivisionRing α] (n : ℤ) (d : ℕ) : α := n / d
def
Tactic
[ "Mathlib.Algebra.Field.Defs", "Mathlib.Algebra.GroupWithZero.Invertible", "Mathlib.Data.Sigma.Basic", "Mathlib.Algebra.Ring.Nat", "Mathlib.Data.Int.Cast.Basic", "Qq.MetaM" ]
Mathlib/Tactic/NormNum/Result.lean
_root_.Rat.rawCast
A "raw rat cast" is an expression of the form: * `(Nat.rawCast lit : α)` where `lit` is a raw natural number literal * `(Int.rawCast (Int.negOfNat lit) : α)` where `lit` is a nonzero raw natural number literal * `(NNRat.rawCast n d : α)` where `n` is a raw nat literal, `d` is a raw nat literal, and `d` is not `1` or `0`. * `(Rat.rawCast (Int.negOfNat n) d : α)` where `n` is a raw nat literal, `d` is a raw nat literal, `n` is not `0`, and `d` is not `1` or `0`. This representation is used by tactics like `ring` to decrease the number of typeclass arguments required in each use of a number literal at type `α`.
IsNNRat.to_isNat {α} [Semiring α] : ∀ {a : α} {n}, IsNNRat a (n) (nat_lit 1) → IsNat a n | _, num, ⟨inv, rfl⟩ => have := @invertibleOne α _; ⟨by simp⟩
theorem
Tactic
[ "Mathlib.Algebra.Field.Defs", "Mathlib.Algebra.GroupWithZero.Invertible", "Mathlib.Data.Sigma.Basic", "Mathlib.Algebra.Ring.Nat", "Mathlib.Data.Int.Cast.Basic", "Qq.MetaM" ]
Mathlib/Tactic/NormNum/Result.lean
IsNNRat.to_isNat
null
IsRat.to_isNNRat {α} [Ring α] : ∀ {a : α} {n d}, IsRat a (.ofNat n) (d) → IsNNRat a n d | _, _, _, ⟨inv, rfl⟩ => ⟨inv, by simp⟩
theorem
Tactic
[ "Mathlib.Algebra.Field.Defs", "Mathlib.Algebra.GroupWithZero.Invertible", "Mathlib.Data.Sigma.Basic", "Mathlib.Algebra.Ring.Nat", "Mathlib.Data.Int.Cast.Basic", "Qq.MetaM" ]
Mathlib/Tactic/NormNum/Result.lean
IsRat.to_isNNRat
null
IsNat.to_isNNRat {α} [Semiring α] : ∀ {a : α} {n}, IsNat a n → IsNNRat a (n) (nat_lit 1) | _, _, ⟨rfl⟩ => ⟨⟨1, by simp, by simp⟩, by simp⟩
theorem
Tactic
[ "Mathlib.Algebra.Field.Defs", "Mathlib.Algebra.GroupWithZero.Invertible", "Mathlib.Data.Sigma.Basic", "Mathlib.Algebra.Ring.Nat", "Mathlib.Data.Int.Cast.Basic", "Qq.MetaM" ]
Mathlib/Tactic/NormNum/Result.lean
IsNat.to_isNNRat
null
IsNNRat.to_isRat {α} [Ring α] : ∀ {a : α} {n d}, IsNNRat a n d → IsRat a (.ofNat n) d | _, _, _, ⟨inv, rfl⟩ => ⟨inv, by simp⟩
theorem
Tactic
[ "Mathlib.Algebra.Field.Defs", "Mathlib.Algebra.GroupWithZero.Invertible", "Mathlib.Data.Sigma.Basic", "Mathlib.Algebra.Ring.Nat", "Mathlib.Data.Int.Cast.Basic", "Qq.MetaM" ]
Mathlib/Tactic/NormNum/Result.lean
IsNNRat.to_isRat
null
IsRat.to_isInt {α} [Ring α] : ∀ {a : α} {n}, IsRat a n (nat_lit 1) → IsInt a n | _, _, ⟨inv, rfl⟩ => have := @invertibleOne α _; ⟨by simp⟩
theorem
Tactic
[ "Mathlib.Algebra.Field.Defs", "Mathlib.Algebra.GroupWithZero.Invertible", "Mathlib.Data.Sigma.Basic", "Mathlib.Algebra.Ring.Nat", "Mathlib.Data.Int.Cast.Basic", "Qq.MetaM" ]
Mathlib/Tactic/NormNum/Result.lean
IsRat.to_isInt
null
IsInt.to_isRat {α} [Ring α] : ∀ {a : α} {n}, IsInt a n → IsRat a n (nat_lit 1) | _, _, ⟨rfl⟩ => ⟨⟨1, by simp, by simp⟩, by simp⟩
theorem
Tactic
[ "Mathlib.Algebra.Field.Defs", "Mathlib.Algebra.GroupWithZero.Invertible", "Mathlib.Data.Sigma.Basic", "Mathlib.Algebra.Ring.Nat", "Mathlib.Data.Int.Cast.Basic", "Qq.MetaM" ]
Mathlib/Tactic/NormNum/Result.lean
IsInt.to_isRat
null
IsNNRat.to_raw_eq {n d : ℕ} [DivisionSemiring α] : ∀ {a}, IsNNRat (a : α) n d → a = NNRat.rawCast n d | _, ⟨inv, rfl⟩ => by simp [div_eq_mul_inv]
theorem
Tactic
[ "Mathlib.Algebra.Field.Defs", "Mathlib.Algebra.GroupWithZero.Invertible", "Mathlib.Data.Sigma.Basic", "Mathlib.Algebra.Ring.Nat", "Mathlib.Data.Int.Cast.Basic", "Qq.MetaM" ]
Mathlib/Tactic/NormNum/Result.lean
IsNNRat.to_raw_eq
null
IsRat.to_raw_eq {n : ℤ} {d : ℕ} [DivisionRing α] : ∀ {a}, IsRat (a : α) n d → a = Rat.rawCast n d | _, ⟨inv, rfl⟩ => by simp [div_eq_mul_inv]
theorem
Tactic
[ "Mathlib.Algebra.Field.Defs", "Mathlib.Algebra.GroupWithZero.Invertible", "Mathlib.Data.Sigma.Basic", "Mathlib.Algebra.Ring.Nat", "Mathlib.Data.Int.Cast.Basic", "Qq.MetaM" ]
Mathlib/Tactic/NormNum/Result.lean
IsRat.to_raw_eq
null
IsRat.neg_to_eq {α} [DivisionRing α] {n d} : {a n' d' : α} → IsRat a (.negOfNat n) d → n = n' → d = d' → a = -(n' / d') | _, _, _, ⟨_, rfl⟩, rfl, rfl => by simp [div_eq_mul_inv]
theorem
Tactic
[ "Mathlib.Algebra.Field.Defs", "Mathlib.Algebra.GroupWithZero.Invertible", "Mathlib.Data.Sigma.Basic", "Mathlib.Algebra.Ring.Nat", "Mathlib.Data.Int.Cast.Basic", "Qq.MetaM" ]
Mathlib/Tactic/NormNum/Result.lean
IsRat.neg_to_eq
null
IsNNRat.to_eq {α} [DivisionSemiring α] {n d} : {a n' d' : α} → IsNNRat a n d → n = n' → d = d' → a = n' / d' | _, _, _, ⟨_, rfl⟩, rfl, rfl => by simp [div_eq_mul_inv]
theorem
Tactic
[ "Mathlib.Algebra.Field.Defs", "Mathlib.Algebra.GroupWithZero.Invertible", "Mathlib.Data.Sigma.Basic", "Mathlib.Algebra.Ring.Nat", "Mathlib.Data.Int.Cast.Basic", "Qq.MetaM" ]
Mathlib/Tactic/NormNum/Result.lean
IsNNRat.to_eq
null
IsNNRat.of_raw (α) [DivisionSemiring α] (n : ℕ) (d : ℕ) (h : (d : α) ≠ 0) : IsNNRat (NNRat.rawCast n d : α) n d := have := invertibleOfNonzero h ⟨this, by simp [div_eq_mul_inv]⟩
theorem
Tactic
[ "Mathlib.Algebra.Field.Defs", "Mathlib.Algebra.GroupWithZero.Invertible", "Mathlib.Data.Sigma.Basic", "Mathlib.Algebra.Ring.Nat", "Mathlib.Data.Int.Cast.Basic", "Qq.MetaM" ]
Mathlib/Tactic/NormNum/Result.lean
IsNNRat.of_raw
null
IsRat.of_raw (α) [DivisionRing α] (n : ℤ) (d : ℕ) (h : (d : α) ≠ 0) : IsRat (Rat.rawCast n d : α) n d := have := invertibleOfNonzero h ⟨this, by simp [div_eq_mul_inv]⟩
theorem
Tactic
[ "Mathlib.Algebra.Field.Defs", "Mathlib.Algebra.GroupWithZero.Invertible", "Mathlib.Data.Sigma.Basic", "Mathlib.Algebra.Ring.Nat", "Mathlib.Data.Int.Cast.Basic", "Qq.MetaM" ]
Mathlib/Tactic/NormNum/Result.lean
IsRat.of_raw
null
IsNNRat.den_nz {α} [DivisionSemiring α] {a n d} : IsNNRat (a : α) n d → (d : α) ≠ 0 | ⟨_, _⟩ => Invertible.ne_zero (d : α)
theorem
Tactic
[ "Mathlib.Algebra.Field.Defs", "Mathlib.Algebra.GroupWithZero.Invertible", "Mathlib.Data.Sigma.Basic", "Mathlib.Algebra.Ring.Nat", "Mathlib.Data.Int.Cast.Basic", "Qq.MetaM" ]
Mathlib/Tactic/NormNum/Result.lean
IsNNRat.den_nz
null
IsRat.den_nz {α} [DivisionRing α] {a n d} : IsRat (a : α) n d → (d : α) ≠ 0 | ⟨_, _⟩ => Invertible.ne_zero (d : α)
theorem
Tactic
[ "Mathlib.Algebra.Field.Defs", "Mathlib.Algebra.GroupWithZero.Invertible", "Mathlib.Data.Sigma.Basic", "Mathlib.Algebra.Ring.Nat", "Mathlib.Data.Int.Cast.Basic", "Qq.MetaM" ]
Mathlib/Tactic/NormNum/Result.lean
IsRat.den_nz
null
Result' where /-- Untyped version of `Result.isBool`. -/ | isBool (val : Bool) (proof : Expr) /-- Untyped version of `Result.isNat`. -/ | isNat (inst lit proof : Expr) /-- Untyped version of `Result.isNegNat`. -/ | isNegNat (inst lit proof : Expr) /-- Untyped version of `Result.isNNRat`. -/ | isNNRat (inst : Expr) (q : Rat) (n d proof : Expr) /-- Untyped version of `Result.isNegNNRat`. -/ | isNegNNRat (inst : Expr) (q : Rat) (n d proof : Expr) deriving Inhabited
inductive
Tactic
[ "Mathlib.Algebra.Field.Defs", "Mathlib.Algebra.GroupWithZero.Invertible", "Mathlib.Data.Sigma.Basic", "Mathlib.Algebra.Ring.Nat", "Mathlib.Data.Int.Cast.Basic", "Qq.MetaM" ]
Mathlib/Tactic/NormNum/Result.lean
Result'
The result of `norm_num` running on an expression `x` of type `α`. Untyped version of `Result`.
@[nolint unusedArguments] Result {α : Q(Type u)} (x : Q($α)) := Result'
def
Tactic
[ "Mathlib.Algebra.Field.Defs", "Mathlib.Algebra.GroupWithZero.Invertible", "Mathlib.Data.Sigma.Basic", "Mathlib.Algebra.Ring.Nat", "Mathlib.Data.Int.Cast.Basic", "Qq.MetaM" ]
Mathlib/Tactic/NormNum/Result.lean
Result
The result of `norm_num` running on an expression `x` of type `α`.
@[match_pattern, inline] Result.isTrue {x : Q(Prop)} : ∀ (proof : Q($x)), Result q($x) := Result'.isBool true
def
Tactic
[ "Mathlib.Algebra.Field.Defs", "Mathlib.Algebra.GroupWithZero.Invertible", "Mathlib.Data.Sigma.Basic", "Mathlib.Algebra.Ring.Nat", "Mathlib.Data.Int.Cast.Basic", "Qq.MetaM" ]
Mathlib/Tactic/NormNum/Result.lean
Result.isTrue
The result is `proof : x`, where `x` is a (true) proposition.
@[match_pattern, inline] Result.isFalse {x : Q(Prop)} : ∀ (proof : Q(¬$x)), Result q($x) := Result'.isBool false
def
Tactic
[ "Mathlib.Algebra.Field.Defs", "Mathlib.Algebra.GroupWithZero.Invertible", "Mathlib.Data.Sigma.Basic", "Mathlib.Algebra.Ring.Nat", "Mathlib.Data.Int.Cast.Basic", "Qq.MetaM" ]
Mathlib/Tactic/NormNum/Result.lean
Result.isFalse
The result is `proof : ¬x`, where `x` is a (false) proposition.
@[match_pattern, inline] Result.isNat {α : Q(Type u)} {x : Q($α)} : ∀ (inst : Q(AddMonoidWithOne $α) := by assumption) (lit : Q(ℕ)) (proof : Q(IsNat $x $lit)), Result x := Result'.isNat
def
Tactic
[ "Mathlib.Algebra.Field.Defs", "Mathlib.Algebra.GroupWithZero.Invertible", "Mathlib.Data.Sigma.Basic", "Mathlib.Algebra.Ring.Nat", "Mathlib.Data.Int.Cast.Basic", "Qq.MetaM" ]
Mathlib/Tactic/NormNum/Result.lean
Result.isNat
The result is `lit : ℕ` (a raw nat literal) and `proof : isNat x lit`.
@[match_pattern, inline] Result.isNegNat {α : Q(Type u)} {x : Q($α)} : ∀ (inst : Q(Ring $α) := by assumption) (lit : Q(ℕ)) (proof : Q(IsInt $x (.negOfNat $lit))), Result x := Result'.isNegNat
def
Tactic
[ "Mathlib.Algebra.Field.Defs", "Mathlib.Algebra.GroupWithZero.Invertible", "Mathlib.Data.Sigma.Basic", "Mathlib.Algebra.Ring.Nat", "Mathlib.Data.Int.Cast.Basic", "Qq.MetaM" ]
Mathlib/Tactic/NormNum/Result.lean
Result.isNegNat
The result is `-lit` where `lit` is a raw nat literal and `proof : isInt x (.negOfNat lit)`.
@[match_pattern, inline] Result.isNNRat {α : Q(Type u)} {x : Q($α)} : ∀ (inst : Q(DivisionSemiring $α) := by assumption) (q : Rat) (n : Q(ℕ)) (d : Q(ℕ)) (proof : Q(IsNNRat $x $n $d)), Result x := Result'.isNNRat
def
Tactic
[ "Mathlib.Algebra.Field.Defs", "Mathlib.Algebra.GroupWithZero.Invertible", "Mathlib.Data.Sigma.Basic", "Mathlib.Algebra.Ring.Nat", "Mathlib.Data.Int.Cast.Basic", "Qq.MetaM" ]
Mathlib/Tactic/NormNum/Result.lean
Result.isNNRat
The result is `proof : IsNNRat x n d`, where `n` a raw nat literal, `d` is a raw nat literal (not 0 or 1), `n` and `d` are coprime, and `q` is the value of `n / d`.
@[match_pattern, inline] Result.isNegNNRat {α : Q(Type u)} {x : Q($α)} : ∀ (inst : Q(DivisionRing $α) := by assumption) (q : Rat) (n : Q(ℕ)) (d : Q(ℕ)) (proof : Q(IsRat $x (.negOfNat $n) $d)), Result x := Result'.isNegNNRat
def
Tactic
[ "Mathlib.Algebra.Field.Defs", "Mathlib.Algebra.GroupWithZero.Invertible", "Mathlib.Data.Sigma.Basic", "Mathlib.Algebra.Ring.Nat", "Mathlib.Data.Int.Cast.Basic", "Qq.MetaM" ]
Mathlib/Tactic/NormNum/Result.lean
Result.isNegNNRat
The result is `proof : IsRat x n d`, where `n` is `.negOfNat lit` with `lit` a raw nat literal, `d` is a raw nat literal (not 0 or 1), `n` and `d` are coprime, and `q` is the value of `n / d`.
Result.toRat {α : Q(Type u)} {e : Q($α)} : Result e → Option Rat | .isBool .. => none | .isNat _ lit _ => some lit.natLit! | .isNegNat _ lit _ => some (-lit.natLit!) | .isNNRat _ q .. => some q | .isNegNNRat _ q .. => some q
def
Tactic
[ "Mathlib.Algebra.Field.Defs", "Mathlib.Algebra.GroupWithZero.Invertible", "Mathlib.Data.Sigma.Basic", "Mathlib.Algebra.Ring.Nat", "Mathlib.Data.Int.Cast.Basic", "Qq.MetaM" ]
Mathlib/Tactic/NormNum/Result.lean
Result.toRat
The result is `z : ℤ` and `proof : isNat x z`. -/ -- Note the independent arguments `z : Q(ℤ)` and `n : ℤ`. -- We ensure these are "the same" when calling. def Result.isInt {α : Q(Type u)} {x : Q($α)} (inst : Q(Ring $α) := by assumption) (z : Q(ℤ)) (n : ℤ) (proof : Q(IsInt $x $z)) : Result x := have lit : Q(ℕ) := z.appArg! if 0 ≤ n then let proof : Q(IsInt $x (.ofNat $lit)) := proof .isNat q(instAddMonoidWithOne) lit q(IsInt.to_isNat $proof) else .isNegNat inst lit proof /-- The result is `q : NNRat` and `proof : isNNRat x q`. -/ -- Note the independent arguments `q : Q(ℚ)` and `n : ℚ`. -- We ensure these are "the same" when calling. def Result.isNNRat' {α : Q(Type u)} {x : Q($α)} (inst : Q(DivisionSemiring $α) := by assumption) (q : Rat) (n : Q(ℕ)) (d : Q(ℕ)) (proof : Q(IsNNRat $x $n $d)) : Result x := if q.den = 1 then haveI : nat_lit 1 =Q $d := ⟨⟩ .isNat q(instAddMonoidWithOne') n q(IsNNRat.to_isNat $proof) else .isNNRat inst q n d proof /-- The result is `q : ℚ` and `proof : isRat x q`. -/ -- Note the independent arguments `q : Q(ℚ)` and `n : ℚ`. -- We ensure these are "the same" when calling. def Result.isRat {α : Q(Type u)} {x : Q($α)} (inst : Q(DivisionRing $α) := by assumption) (q : ℚ) (n : Q(ℤ)) (d : Q(ℕ)) (proof : Q(IsRat $x $n $d)) : Result x := have lit : Q(ℕ) := n.appArg! if q.den = 1 then have proof : Q(IsRat $x $n (nat_lit 1)) := proof .isInt q(DivisionRing.toRing) n q.num q(IsRat.to_isInt $proof) else if 0 ≤ q then let proof : Q(IsRat $x (.ofNat $lit) $d) := proof .isNNRat q(DivisionRing.toDivisionSemiring) q lit d q(IsRat.to_isNNRat $proof) else .isNegNNRat inst q lit d proof instance {α : Q(Type u)} {x : Q($α)} : ToMessageData (Result x) where toMessageData | .isBool true proof => m!"isTrue ({proof})" | .isBool false proof => m!"isFalse ({proof})" | .isNat _ lit proof => m!"isNat {lit} ({proof})" | .isNegNat _ lit proof => m!"isNegNat {lit} ({proof})" | .isNNRat _ q _ _ proof => m!"isNNRat {q} ({proof})" | .isNegNNRat _ q _ _ proof => m!"isNegNNRat {q} ({proof})" /-- Returns the rational number that is the result of `norm_num` evaluation.
Result.toRatNZ {α : Q(Type u)} {e : Q($α)} : Result e → Option (Rat × Option Expr) | .isBool .. => none | .isNat _ lit _ => some (lit.natLit!, none) | .isNegNat _ lit _ => some (-lit.natLit!, none) | .isNNRat _ q _ _ p => some (q, q(IsNNRat.den_nz $p)) | .isNegNNRat _ q _ _ p => some (q, q(IsRat.den_nz $p))
def
Tactic
[ "Mathlib.Algebra.Field.Defs", "Mathlib.Algebra.GroupWithZero.Invertible", "Mathlib.Data.Sigma.Basic", "Mathlib.Algebra.Ring.Nat", "Mathlib.Data.Int.Cast.Basic", "Qq.MetaM" ]
Mathlib/Tactic/NormNum/Result.lean
Result.toRatNZ
Returns the rational number that is the result of `norm_num` evaluation, along with a proof that the denominator is nonzero in the `isRat` case.
Result.toInt {α : Q(Type u)} {e : Q($α)} (_i : Q(Ring $α) := by with_reducible assumption) : Result e → Option (ℤ × (lit : Q(ℤ)) × Q(IsInt $e $lit)) | .isNat _ lit proof => do have proof : Q(@IsNat _ instAddMonoidWithOne $e $lit) := proof pure ⟨lit.natLit!, q(.ofNat $lit), q(($proof).to_isInt)⟩ | .isNegNat _ lit proof => pure ⟨-lit.natLit!, q(.negOfNat $lit), proof⟩ | _ => failure
def
Tactic
[ "Mathlib.Algebra.Field.Defs", "Mathlib.Algebra.GroupWithZero.Invertible", "Mathlib.Data.Sigma.Basic", "Mathlib.Algebra.Ring.Nat", "Mathlib.Data.Int.Cast.Basic", "Qq.MetaM" ]
Mathlib/Tactic/NormNum/Result.lean
Result.toInt
Extract from a `Result` the integer value (as both a term and an expression), and the proof that the original expression is equal to this integer.
Result.toNNRat' {α : Q(Type u)} {e : Q($α)} (_i : Q(DivisionSemiring $α) := by with_reducible assumption) : Result e → Option (Rat × (n : Q(ℕ)) × (d : Q(ℕ)) × Q(IsNNRat $e $n $d)) | .isNat _ lit proof => have proof : Q(@IsNat _ instAddMonoidWithOne' $e $lit) := proof some ⟨lit.natLit!, q($lit), q(nat_lit 1), q(($proof).to_isNNRat)⟩ | .isNNRat _ q n d proof => some ⟨q, n, d, proof⟩ | _ => none
def
Tactic
[ "Mathlib.Algebra.Field.Defs", "Mathlib.Algebra.GroupWithZero.Invertible", "Mathlib.Data.Sigma.Basic", "Mathlib.Algebra.Ring.Nat", "Mathlib.Data.Int.Cast.Basic", "Qq.MetaM" ]
Mathlib/Tactic/NormNum/Result.lean
Result.toNNRat'
Extract from a `Result` the rational value (as both a term and an expression), and the proof that the original expression is equal to this rational number.
Result.toRat' {α : Q(Type u)} {e : Q($α)} (_i : Q(DivisionRing $α) := by with_reducible assumption) : Result e → Option (ℚ × (n : Q(ℤ)) × (d : Q(ℕ)) × Q(IsRat $e $n $d)) | .isBool .. => none | .isNat _ lit proof => have proof : Q(@IsNat _ instAddMonoidWithOne $e $lit) := proof some ⟨lit.natLit!, q(.ofNat $lit), q(nat_lit 1), q(($proof).to_isNNRat.to_isRat)⟩ | .isNegNat _ lit proof => have proof : Q(@IsInt _ DivisionRing.toRing $e (.negOfNat $lit)) := proof some ⟨-lit.natLit!, q(.negOfNat $lit), q(nat_lit 1), q(@IsInt.to_isRat _ DivisionRing.toRing _ _ $proof)⟩ | .isNNRat inst q n d proof => letI : $inst =Q DivisionRing.toDivisionSemiring := ⟨⟩ some ⟨q, q(.ofNat $n), d, q(IsNNRat.to_isRat $proof)⟩ | .isNegNNRat _ q n d proof => some ⟨q, q(.negOfNat $n), d, proof⟩
def
Tactic
[ "Mathlib.Algebra.Field.Defs", "Mathlib.Algebra.GroupWithZero.Invertible", "Mathlib.Data.Sigma.Basic", "Mathlib.Algebra.Ring.Nat", "Mathlib.Data.Int.Cast.Basic", "Qq.MetaM" ]
Mathlib/Tactic/NormNum/Result.lean
Result.toRat'
Extract from a `Result` the rational value (as both a term and an expression), and the proof that the original expression is equal to this rational number.
Result.toRawEq {α : Q(Type u)} {e : Q($α)} : Result e → (e' : Q($α)) × Q($e = $e') | .isBool false p => have e : Q(Prop) := e; have p : Q(¬$e) := p ⟨(q(False) : Expr), (q(eq_false $p) : Expr)⟩ | .isBool true p => have e : Q(Prop) := e; have p : Q($e) := p ⟨(q(True) : Expr), (q(eq_true $p) : Expr)⟩ | .isNat _ lit p => ⟨q(Nat.rawCast $lit), q(IsNat.to_raw_eq $p)⟩ | .isNegNat _ lit p => ⟨q(Int.rawCast (.negOfNat $lit)), q(IsInt.to_raw_eq $p)⟩ | .isNNRat _ _ n d p => ⟨q(NNRat.rawCast $n $d), q(IsNNRat.to_raw_eq $p)⟩ | .isNegNNRat _ _ n d p => ⟨q(Rat.rawCast (.negOfNat $n) $d), q(IsRat.to_raw_eq $p)⟩
def
Tactic
[ "Mathlib.Algebra.Field.Defs", "Mathlib.Algebra.GroupWithZero.Invertible", "Mathlib.Data.Sigma.Basic", "Mathlib.Algebra.Ring.Nat", "Mathlib.Data.Int.Cast.Basic", "Qq.MetaM" ]
Mathlib/Tactic/NormNum/Result.lean
Result.toRawEq
Given a `NormNum.Result e` (which uses `IsNat`, `IsInt`, `IsRat` to express equality to a rational numeral), converts it to an equality `e = Nat.rawCast n`, `e = Int.rawCast n`, or `e = Rat.rawCast n d` to a raw cast expression, so it can be used for rewriting.
Result.toRawIntEq {α : Q(Type u)} {e : Q($α)} : Result e → Option (ℤ × (e' : Q($α)) × Q($e = $e')) | .isNat _ lit p => some ⟨lit.natLit!, q(Nat.rawCast $lit), q(IsNat.to_raw_eq $p)⟩ | .isNegNat _ lit p => some ⟨-lit.natLit!, q(Int.rawCast (.negOfNat $lit)), q(IsInt.to_raw_eq $p)⟩ | .isNNRat _ .. | .isNegNNRat _ .. | .isBool .. => none
def
Tactic
[ "Mathlib.Algebra.Field.Defs", "Mathlib.Algebra.GroupWithZero.Invertible", "Mathlib.Data.Sigma.Basic", "Mathlib.Algebra.Ring.Nat", "Mathlib.Data.Int.Cast.Basic", "Qq.MetaM" ]
Mathlib/Tactic/NormNum/Result.lean
Result.toRawIntEq
`Result.toRawEq` but providing an integer. Given a `NormNum.Result e` for something known to be an integer (which uses `IsNat` or `IsInt` to express equality to an integer numeral), converts it to an equality `e = Nat.rawCast n` or `e = Int.rawCast n` to a raw cast expression, so it can be used for rewriting. Gives `none` if not an integer.
Result.ofRawNat {α : Q(Type u)} (e : Q($α)) : Result e := Id.run do let .app (.app _ (sα : Q(AddMonoidWithOne $α))) (lit : Q(ℕ)) := e | panic! "not a raw nat cast" .isNat sα lit (q(IsNat.of_raw $α $lit) : Expr)
def
Tactic
[ "Mathlib.Algebra.Field.Defs", "Mathlib.Algebra.GroupWithZero.Invertible", "Mathlib.Data.Sigma.Basic", "Mathlib.Algebra.Ring.Nat", "Mathlib.Data.Int.Cast.Basic", "Qq.MetaM" ]
Mathlib/Tactic/NormNum/Result.lean
Result.ofRawNat
Constructs a `Result` out of a raw nat cast. Assumes `e` is a raw nat cast expression.
Result.ofRawInt {α : Q(Type u)} (n : ℤ) (e : Q($α)) : Result e := if 0 ≤ n then Result.ofRawNat e else Id.run do let .app (.app _ (rα : Q(Ring $α))) (.app _ (lit : Q(ℕ))) := e | panic! "not a raw int cast" .isNegNat rα lit (q(IsInt.of_raw $α (.negOfNat $lit)) : Expr)
def
Tactic
[ "Mathlib.Algebra.Field.Defs", "Mathlib.Algebra.GroupWithZero.Invertible", "Mathlib.Data.Sigma.Basic", "Mathlib.Algebra.Ring.Nat", "Mathlib.Data.Int.Cast.Basic", "Qq.MetaM" ]
Mathlib/Tactic/NormNum/Result.lean
Result.ofRawInt
Constructs a `Result` out of a raw int cast. Assumes `e` is a raw int cast expression denoting `n`.
Result.ofRawNNRat {α : Q(Type u)} (q : ℚ) (e : Q($α)) (hyp : Option Expr := none) : Result e := if q.den = 1 then Result.ofRawNat e else Id.run do let .app (.app (.app _ (dα : Q(DivisionSemiring $α))) (n : Q(ℕ))) (d : Q(ℕ)) := e | panic! "not a raw nnrat cast" let hyp : Q(($d : $α) ≠ 0) := hyp.get! .isNNRat dα q n d (q(IsNNRat.of_raw $α $n $d $hyp) : Expr)
def
Tactic
[ "Mathlib.Algebra.Field.Defs", "Mathlib.Algebra.GroupWithZero.Invertible", "Mathlib.Data.Sigma.Basic", "Mathlib.Algebra.Ring.Nat", "Mathlib.Data.Int.Cast.Basic", "Qq.MetaM" ]
Mathlib/Tactic/NormNum/Result.lean
Result.ofRawNNRat
Constructs a `Result` out of a raw rat cast. Assumes `e` is a raw rat cast expression denoting `n`.
Result.ofRawRat {α : Q(Type u)} (q : ℚ) (e : Q($α)) (hyp : Option Expr := none) : Result e := if q.den = 1 then Result.ofRawInt q.num e else if 0 ≤ q then Result.ofRawNNRat q e hyp else Id.run do let .app (.app (.app _ (dα : Q(DivisionRing $α))) (.app _ (n : Q(ℕ)))) (d : Q(ℕ)) := e | panic! "not a raw rat cast" let hyp : Q(($d : $α) ≠ 0) := hyp.get! .isNegNNRat dα q n d (q(IsRat.of_raw $α (.negOfNat $n) $d $hyp) : Expr)
def
Tactic
[ "Mathlib.Algebra.Field.Defs", "Mathlib.Algebra.GroupWithZero.Invertible", "Mathlib.Data.Sigma.Basic", "Mathlib.Algebra.Ring.Nat", "Mathlib.Data.Int.Cast.Basic", "Qq.MetaM" ]
Mathlib/Tactic/NormNum/Result.lean
Result.ofRawRat
Constructs a `Result` out of a raw rat cast. Assumes `e` is a raw rat cast expression denoting `n`.
Result.toSimpResult {α : Q(Type u)} {e : Q($α)} : Result e → MetaM Simp.Result | r@(.isBool ..) => let ⟨expr, proof?⟩ := r.toRawEq; pure { expr, proof? } | .isNat sα lit p => do let ⟨a', pa'⟩ ← mkOfNat α sα lit return { expr := a', proof? := q(IsNat.to_eq $p $pa') } | .isNegNat _rα lit p => do let ⟨a', pa'⟩ ← mkOfNat α q(AddCommMonoidWithOne.toAddMonoidWithOne) lit return { expr := q(-$a'), proof? := q(IsInt.neg_to_eq $p $pa') } | .isNNRat _ _ n d p => do let ⟨n', pn'⟩ ← mkOfNat α q(AddCommMonoidWithOne.toAddMonoidWithOne) n let ⟨d', pd'⟩ ← mkOfNat α q(AddCommMonoidWithOne.toAddMonoidWithOne) d return { expr := q($n' / $d'), proof? := q(IsNNRat.to_eq $p $pn' $pd') } | .isNegNNRat _ _ n d p => do let ⟨n', pn'⟩ ← mkOfNat α q(AddCommMonoidWithOne.toAddMonoidWithOne) n let ⟨d', pd'⟩ ← mkOfNat α q(AddCommMonoidWithOne.toAddMonoidWithOne) d return { expr := q(-($n' / $d')), proof? := q(IsRat.neg_to_eq $p $pn' $pd') }
def
Tactic
[ "Mathlib.Algebra.Field.Defs", "Mathlib.Algebra.GroupWithZero.Invertible", "Mathlib.Data.Sigma.Basic", "Mathlib.Algebra.Ring.Nat", "Mathlib.Data.Int.Cast.Basic", "Qq.MetaM" ]
Mathlib/Tactic/NormNum/Result.lean
Result.toSimpResult
Convert a `Result` to a `Simp.Result`.
BoolResult (p : Q(Prop)) (b : Bool) : Type := Q(Bool.rec (¬ $p) ($p) $b)
abbrev
Tactic
[ "Mathlib.Algebra.Field.Defs", "Mathlib.Algebra.GroupWithZero.Invertible", "Mathlib.Data.Sigma.Basic", "Mathlib.Algebra.Ring.Nat", "Mathlib.Data.Int.Cast.Basic", "Qq.MetaM" ]
Mathlib/Tactic/NormNum/Result.lean
BoolResult
Given `Mathlib.Meta.NormNum.Result.isBool p b`, this is the type of `p`. Note that `BoolResult p b` is definitionally equal to `Expr`, and if you write `match b with ...`, then in the `true` branch `BoolResult p true` is reducibly equal to `Q($p)` and in the `false` branch it is reducibly equal to `Q(¬ $p)`.
Result.ofBoolResult {p : Q(Prop)} {b : Bool} (prf : BoolResult p b) : Result q(Prop) := Result'.isBool b prf
def
Tactic
[ "Mathlib.Algebra.Field.Defs", "Mathlib.Algebra.GroupWithZero.Invertible", "Mathlib.Data.Sigma.Basic", "Mathlib.Algebra.Ring.Nat", "Mathlib.Data.Int.Cast.Basic", "Qq.MetaM" ]
Mathlib/Tactic/NormNum/Result.lean
Result.ofBoolResult
Obtain a `Result` from a `BoolResult`.
Result.eqTrans {α : 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) := a have b : Q(Prop) := b have eq : Q($a = $b) := eq have proof : Q(¬ $b) := proof Result.isFalse (x := a) q($eq ▸ $proof) | .isNat inst lit proof => Result.isNat inst lit q($eq ▸ $proof) | .isNegNat inst lit proof => Result.isNegNat inst lit q($eq ▸ $proof) | .isNNRat inst q n d proof => Result.isNNRat inst q n d q($eq ▸ $proof) | .isNegNNRat inst q n d proof => Result.isNegNNRat inst q n d q($eq ▸ $proof)
def
Tactic
[ "Mathlib.Algebra.Field.Defs", "Mathlib.Algebra.GroupWithZero.Invertible", "Mathlib.Data.Sigma.Basic", "Mathlib.Algebra.Ring.Nat", "Mathlib.Data.Int.Cast.Basic", "Qq.MetaM" ]
Mathlib/Tactic/NormNum/Result.lean
Result.eqTrans
If `a = b` and we can evaluate `b`, then we can evaluate `a`.
AtomicFact | eq (lhs : Nat) (rhs : Nat) (proof : Expr) | ne (lhs : Nat) (rhs : Nat) (proof : Expr) | le (lhs : Nat) (rhs : Nat) (proof : Expr) | nle (lhs : Nat) (rhs : Nat) (proof : Expr) | lt (lhs : Nat) (rhs : Nat) (proof : Expr) | nlt (lhs : Nat) (rhs : Nat) (proof : Expr) | isTop (idx : Nat) | isBot (idx : Nat) | isInf (lhs : Nat) (rhs : Nat) (res : Nat) | isSup (lhs : Nat) (rhs : Nat) (res : Nat) deriving Inhabited, BEq
inductive
Tactic
[ "Mathlib.Order.BoundedOrder.Basic", "Mathlib.Order.Lattice", "Qq" ]
Mathlib/Tactic/Order/CollectFacts.lean
AtomicFact
A structure for storing facts about variables.
CollectFactsState := Std.HashMap Expr <| DiscrTree (Nat × Expr) × Array AtomicFact
abbrev
Tactic
[ "Mathlib.Order.BoundedOrder.Basic", "Mathlib.Order.Lattice", "Qq" ]
Mathlib/Tactic/Order/CollectFacts.lean
CollectFactsState
State for `CollectFactsM`. It contains a map where the key `t` maps to a pair `(atomToIdx, facts)`. `atomToIdx` is a `DiscrTree` containing atomic expressions with their indices, and `facts` stores `AtomicFact`s about them.
CollectFactsM := StateT CollectFactsState MetaM
abbrev
Tactic
[ "Mathlib.Order.BoundedOrder.Basic", "Mathlib.Order.Lattice", "Qq" ]
Mathlib/Tactic/Order/CollectFacts.lean
CollectFactsM
Monad for the fact collection procedure.
addFact (type : Expr) (fact : AtomicFact) : CollectFactsM Unit := modify fun res => res.modify type fun (atomToIdx, facts) => (atomToIdx, facts.push fact)
def
Tactic
[ "Mathlib.Order.BoundedOrder.Basic", "Mathlib.Order.Lattice", "Qq" ]
Mathlib/Tactic/Order/CollectFacts.lean
addFact
Adds `fact` to the state.
partial addAtom {u : Level} (type : Q(Type u)) (x : Q($type)) : CollectFactsM Nat := do modify fun res => res.insertIfNew type (.empty, #[]) let (atomToIdx, facts) := (← get).get! type match ← (← atomToIdx.getUnify x).findM? fun (_, e) => isDefEq x e with | some (idx, _) => return idx | none => let idx := atomToIdx.size let atomToIdx ← atomToIdx.insert x (idx, x) modify fun res => res.insert type (atomToIdx, facts) match x with | ~q((@OrderTop.toTop _ $instLE $instTop).top) => addFact type (.isTop idx) | ~q((@OrderBot.toBot _ $instLE $instBot).bot) => addFact type (.isBot idx) | ~q((@SemilatticeSup.toMax _ $inst).max $a $b) => let aIdx ← addAtom type a let bIdx ← addAtom type b addFact type (.isSup aIdx bIdx idx) | ~q((@SemilatticeInf.toMin _ $inst).min $a $b) => let aIdx ← addAtom type a let bIdx ← addAtom type b addFact type (.isInf aIdx bIdx idx) | _ => pure () return idx set_option linter.unusedVariables false in
def
Tactic
[ "Mathlib.Order.BoundedOrder.Basic", "Mathlib.Order.Lattice", "Qq" ]
Mathlib/Tactic/Order/CollectFacts.lean
addAtom
Updates the state with the atom `x`. If `x` is `⊤` or `⊥`, adds the corresponding fact. If `x` is `y ⊔ z`, adds a fact about it, then recursively calls `addAtom` on `y` and `z`. Similarly for `⊓`.
collectFactsImp : CollectFactsM Unit := do let ctx ← getLCtx for ldecl in ctx do if ldecl.isImplementationDetail then continue processExpr ldecl.toExpr where /-- Extracts facts and atoms from the expression. -/ processExpr (expr : Expr) : CollectFactsM Unit := do let type ← inferType expr if !(← isProp type) then return let ⟨u, type, expr⟩ ← inferTypeQ expr let _ : u =QL 0 := ⟨⟩ match type with | ~q(@Eq ($α : Type _) $x $y) => if (← synthInstance? (q(Preorder $α))).isSome then let xIdx ← addAtom α x let yIdx ← addAtom α y addFact α <| .eq xIdx yIdx expr | ~q(@LE.le $α $inst $x $y) => let xIdx ← addAtom α x let yIdx ← addAtom α y addFact α <| .le xIdx yIdx expr | ~q(@LT.lt $α $inst $x $y) => let xIdx ← addAtom α x let yIdx ← addAtom α y addFact α <| .lt xIdx yIdx expr | ~q(@Ne ($α : Type _) $x $y) => if (← synthInstance? (q(Preorder $α))).isSome then let xIdx ← addAtom α x let yIdx ← addAtom α y addFact α <| .ne xIdx yIdx expr | ~q(Not $p) => match p with | ~q(@LE.le $α $inst $x $y) => let xIdx ← addAtom α x let yIdx ← addAtom α y addFact α <| .nle xIdx yIdx expr | ~q(@LT.lt $α $inst $x $y) => let xIdx ← addAtom α x let yIdx ← addAtom α y addFact α <| .nlt xIdx yIdx expr | _ => return | _ => return
def
Tactic
[ "Mathlib.Order.BoundedOrder.Basic", "Mathlib.Order.Lattice", "Qq" ]
Mathlib/Tactic/Order/CollectFacts.lean
collectFactsImp
Implementation for `collectFacts` in `CollectFactsM` monad.
collectFacts : MetaM <| Std.HashMap Expr <| Std.HashMap Nat Expr × Array AtomicFact := do let res := (← collectFactsImp.run ∅).snd return res.map fun _ (atomToIdx, facts) => let idxToAtom : Std.HashMap Nat Expr := atomToIdx.fold (init := ∅) fun acc _ value => acc.insert value.fst value.snd (idxToAtom, facts)
def
Tactic
[ "Mathlib.Order.BoundedOrder.Basic", "Mathlib.Order.Lattice", "Qq" ]
Mathlib/Tactic/Order/CollectFacts.lean
collectFacts
Collects facts from the local context. For each occurring type `α`, the returned map contains a pair `(idxToAtom, facts)`, where the map `idxToAtom` converts indices to found atomic expressions of type `α`, and `facts` contains all collected `AtomicFact`s about them.
not_lt_of_not_le {α : Type u} [Preorder α] {x y : α} (h : ¬(x ≤ y)) : ¬(x < y) := (h ·.le)
lemma
Tactic
[ "Mathlib.Tactic.Order.CollectFacts" ]
Mathlib/Tactic/Order/Preprocessing.lean
not_lt_of_not_le
null
le_of_not_lt_le {α : Type u} [Preorder α] {x y : α} (h1 : ¬(x < y)) (h2 : x ≤ y) : y ≤ x := not_lt_iff_le_imp_ge.mp h1 h2
lemma
Tactic
[ "Mathlib.Tactic.Order.CollectFacts" ]
Mathlib/Tactic/Order/Preprocessing.lean
le_of_not_lt_le
null
preprocessFactsPreorder (facts : Array AtomicFact) : MetaM <| Array AtomicFact := do let mut res : Array AtomicFact := #[] for fact in facts do match fact with | .lt lhs rhs proof => res := res.push <| .le lhs rhs (← mkAppM ``le_of_lt #[proof]) res := res.push <| .nle rhs lhs (← mkAppM ``not_le_of_gt #[proof]) | .eq lhs rhs proof => res := res.push <| .le lhs rhs (← mkAppM ``le_of_eq #[proof]) res := res.push <| .le rhs lhs (← mkAppM ``ge_of_eq #[proof]) | .ne _ _ _ => continue | _ => res := res.push fact return res
def
Tactic
[ "Mathlib.Tactic.Order.CollectFacts" ]
Mathlib/Tactic/Order/Preprocessing.lean
preprocessFactsPreorder
Preprocesses facts for preorders. Replaces `x < y` with two equivalent facts: `x ≤ y` and `¬ (y ≤ x)`. Replaces `x = y` with `x ≤ y`, `y ≤ x` and removes `x ≠ y`.
preprocessFactsPartial (facts : Array AtomicFact) (idxToAtom : Std.HashMap Nat Expr) : MetaM <| Array AtomicFact := do let mut res : Array AtomicFact := #[] for fact in facts do match fact with | .lt lhs rhs proof => res := res.push <| .ne lhs rhs (← mkAppM ``ne_of_lt #[proof]) res := res.push <| .le lhs rhs (← mkAppM ``le_of_lt #[proof]) | .nle lhs rhs proof => res := res.push <| .ne lhs rhs (← mkAppM ``ne_of_not_le #[proof]) res := res.push <| .nlt lhs rhs (← mkAppM ``not_lt_of_not_le #[proof]) | .eq lhs rhs proof => res := res.push <| .le lhs rhs (← mkAppM ``le_of_eq #[proof]) res := res.push <| .le rhs lhs (← mkAppM ``ge_of_eq #[proof]) | .isSup lhs rhs sup => res := res.push <| .le lhs sup (← mkAppOptM ``le_sup_left #[none, none, idxToAtom.get! lhs, idxToAtom.get! rhs]) res := res.push <| .le rhs sup (← mkAppOptM ``le_sup_right #[none, none, idxToAtom.get! lhs, idxToAtom.get! rhs]) res := res.push fact | .isInf lhs rhs inf => res := res.push <| .le inf lhs (← mkAppOptM ``inf_le_left #[none, none, idxToAtom.get! lhs, idxToAtom.get! rhs]) res := res.push <| .le inf rhs (← mkAppOptM ``inf_le_right #[none, none, idxToAtom.get! lhs, idxToAtom.get! rhs]) res := res.push fact | _ => res := res.push fact return res
def
Tactic
[ "Mathlib.Tactic.Order.CollectFacts" ]
Mathlib/Tactic/Order/Preprocessing.lean
preprocessFactsPartial
Preprocesses facts for partial orders. Replaces `x < y`, `¬ (x ≤ y)`, and `x = y` with equivalent facts involving only `≤`, `≠`, and `≮`. For each fact `x = y ⊔ z` adds `y ≤ x` and `z ≤ x` facts, and similarly for `⊓`.
preprocessFactsLinear (facts : Array AtomicFact) (idxToAtom : Std.HashMap Nat Expr) : MetaM <| Array AtomicFact := do let mut res : Array AtomicFact := #[] for fact in facts do match fact with | .lt lhs rhs proof => res := res.push <| .ne lhs rhs (← mkAppM ``ne_of_lt #[proof]) res := res.push <| .le lhs rhs (← mkAppM ``le_of_lt #[proof]) | .nle lhs rhs proof => res := res.push <| .ne lhs rhs (← mkAppM ``ne_of_not_le #[proof]) res := res.push <| .le rhs lhs (← mkAppM ``le_of_not_ge #[proof]) | .nlt lhs rhs proof => res := res.push <| .le rhs lhs (← mkAppM ``le_of_not_gt #[proof]) | .eq lhs rhs proof => res := res.push <| .le lhs rhs (← mkAppM ``le_of_eq #[proof]) res := res.push <| .le rhs lhs (← mkAppM ``ge_of_eq #[proof]) | .isSup lhs rhs sup => res := res.push <| .le lhs sup (← mkAppOptM ``le_sup_left #[none, none, idxToAtom.get! lhs, idxToAtom.get! rhs]) res := res.push <| .le rhs sup (← mkAppOptM ``le_sup_right #[none, none, idxToAtom.get! lhs, idxToAtom.get! rhs]) res := res.push fact | .isInf lhs rhs inf => res := res.push <| .le inf lhs (← mkAppOptM ``inf_le_left #[none, none, idxToAtom.get! lhs, idxToAtom.get! rhs]) res := res.push <| .le inf rhs (← mkAppOptM ``inf_le_right #[none, none, idxToAtom.get! lhs, idxToAtom.get! rhs]) res := res.push fact | _ => res := res.push fact return res
def
Tactic
[ "Mathlib.Tactic.Order.CollectFacts" ]
Mathlib/Tactic/Order/Preprocessing.lean
preprocessFactsLinear
Preprocesses facts for linear orders. Replaces `x < y`, `¬ (x ≤ y)`, `¬ (x < y)`, and `x = y` with equivalent facts involving only `≤` and `≠`. For each fact `x = y ⊔ z` adds `y ≤ x` and `z ≤ x` facts, and similarly for `⊓`.
private ite_pos [LT α] (ha : 0 < a) (hb : 0 < b) : 0 < ite p a b := by by_cases p <;> simp [*]
lemma
Tactic
[ "Mathlib.Algebra.Order.Group.PosPart", "Mathlib.Algebra.Order.Ring.Basic", "Mathlib.Algebra.Order.Hom.Basic", "Mathlib.Data.Int.CharZero", "Mathlib.Data.Nat.Factorial.Basic", "Mathlib.Data.NNRat.Defs", "Mathlib.Data.PNat.Defs", "Mathlib.Tactic.Positivity.Core", "Qq" ]
Mathlib/Tactic/Positivity/Basic.lean
ite_pos
null
private ite_nonneg [LE α] (ha : 0 ≤ a) (hb : 0 ≤ b) : 0 ≤ ite p a b := by by_cases p <;> simp [*]
lemma
Tactic
[ "Mathlib.Algebra.Order.Group.PosPart", "Mathlib.Algebra.Order.Ring.Basic", "Mathlib.Algebra.Order.Hom.Basic", "Mathlib.Data.Int.CharZero", "Mathlib.Data.Nat.Factorial.Basic", "Mathlib.Data.NNRat.Defs", "Mathlib.Data.PNat.Defs", "Mathlib.Tactic.Positivity.Core", "Qq" ]
Mathlib/Tactic/Positivity/Basic.lean
ite_nonneg
null
private ite_nonneg_of_pos_of_nonneg [Preorder α] (ha : 0 < a) (hb : 0 ≤ b) : 0 ≤ ite p a b := ite_nonneg _ ha.le hb
lemma
Tactic
[ "Mathlib.Algebra.Order.Group.PosPart", "Mathlib.Algebra.Order.Ring.Basic", "Mathlib.Algebra.Order.Hom.Basic", "Mathlib.Data.Int.CharZero", "Mathlib.Data.Nat.Factorial.Basic", "Mathlib.Data.NNRat.Defs", "Mathlib.Data.PNat.Defs", "Mathlib.Tactic.Positivity.Core", "Qq" ]
Mathlib/Tactic/Positivity/Basic.lean
ite_nonneg_of_pos_of_nonneg
null
private ite_nonneg_of_nonneg_of_pos [Preorder α] (ha : 0 ≤ a) (hb : 0 < b) : 0 ≤ ite p a b := ite_nonneg _ ha hb.le
lemma
Tactic
[ "Mathlib.Algebra.Order.Group.PosPart", "Mathlib.Algebra.Order.Ring.Basic", "Mathlib.Algebra.Order.Hom.Basic", "Mathlib.Data.Int.CharZero", "Mathlib.Data.Nat.Factorial.Basic", "Mathlib.Data.NNRat.Defs", "Mathlib.Data.PNat.Defs", "Mathlib.Tactic.Positivity.Core", "Qq" ]
Mathlib/Tactic/Positivity/Basic.lean
ite_nonneg_of_nonneg_of_pos
null
private ite_ne_zero (ha : a ≠ 0) (hb : b ≠ 0) : ite p a b ≠ 0 := by by_cases p <;> simp [*]
lemma
Tactic
[ "Mathlib.Algebra.Order.Group.PosPart", "Mathlib.Algebra.Order.Ring.Basic", "Mathlib.Algebra.Order.Hom.Basic", "Mathlib.Data.Int.CharZero", "Mathlib.Data.Nat.Factorial.Basic", "Mathlib.Data.NNRat.Defs", "Mathlib.Data.PNat.Defs", "Mathlib.Tactic.Positivity.Core", "Qq" ]
Mathlib/Tactic/Positivity/Basic.lean
ite_ne_zero
null
private ite_ne_zero_of_pos_of_ne_zero [Preorder α] (ha : 0 < a) (hb : b ≠ 0) : ite p a b ≠ 0 := ite_ne_zero _ ha.ne' hb
lemma
Tactic
[ "Mathlib.Algebra.Order.Group.PosPart", "Mathlib.Algebra.Order.Ring.Basic", "Mathlib.Algebra.Order.Hom.Basic", "Mathlib.Data.Int.CharZero", "Mathlib.Data.Nat.Factorial.Basic", "Mathlib.Data.NNRat.Defs", "Mathlib.Data.PNat.Defs", "Mathlib.Tactic.Positivity.Core", "Qq" ]
Mathlib/Tactic/Positivity/Basic.lean
ite_ne_zero_of_pos_of_ne_zero
null
private ite_ne_zero_of_ne_zero_of_pos [Preorder α] (ha : a ≠ 0) (hb : 0 < b) : ite p a b ≠ 0 := ite_ne_zero _ ha hb.ne'
lemma
Tactic
[ "Mathlib.Algebra.Order.Group.PosPart", "Mathlib.Algebra.Order.Ring.Basic", "Mathlib.Algebra.Order.Hom.Basic", "Mathlib.Data.Int.CharZero", "Mathlib.Data.Nat.Factorial.Basic", "Mathlib.Data.NNRat.Defs", "Mathlib.Data.PNat.Defs", "Mathlib.Tactic.Positivity.Core", "Qq" ]
Mathlib/Tactic/Positivity/Basic.lean
ite_ne_zero_of_ne_zero_of_pos
null
@[positivity ite _ _ _] evalIte : PositivityExt where eval {u α} zα pα e := do let .app (.app (.app (.app f (p : Q(Prop))) (_ : Q(Decidable $p))) (a : Q($α))) (b : Q($α)) ← withReducible (whnf e) | throwError "not ite" haveI' : $e =Q ite $p $a $b := ⟨⟩ let ra ← core zα pα a; let rb ← core zα pα b guard <|← withDefault <| withNewMCtxDepth <| isDefEq f q(ite (α := $α)) match ra, rb with | .positive pa, .positive pb => pure (.positive q(ite_pos $p $pa $pb)) | .positive pa, .nonnegative pb => let _b ← synthInstanceQ q(Preorder $α) assumeInstancesCommute pure (.nonnegative q(ite_nonneg_of_pos_of_nonneg $p $pa $pb)) | .nonnegative pa, .positive pb => let _b ← synthInstanceQ q(Preorder $α) assumeInstancesCommute pure (.nonnegative q(ite_nonneg_of_nonneg_of_pos $p $pa $pb)) | .nonnegative pa, .nonnegative pb => pure (.nonnegative q(ite_nonneg $p $pa $pb)) | .positive pa, .nonzero pb => let _b ← synthInstanceQ q(Preorder $α) assumeInstancesCommute pure (.nonzero q(ite_ne_zero_of_pos_of_ne_zero $p $pa $pb)) | .nonzero pa, .positive pb => let _b ← synthInstanceQ q(Preorder $α) assumeInstancesCommute pure (.nonzero q(ite_ne_zero_of_ne_zero_of_pos $p $pa $pb)) | .nonzero pa, .nonzero pb => pure (.nonzero q(ite_ne_zero $p $pa $pb)) | _, _ => pure .none
def
Tactic
[ "Mathlib.Algebra.Order.Group.PosPart", "Mathlib.Algebra.Order.Ring.Basic", "Mathlib.Algebra.Order.Hom.Basic", "Mathlib.Data.Int.CharZero", "Mathlib.Data.Nat.Factorial.Basic", "Mathlib.Data.NNRat.Defs", "Mathlib.Data.PNat.Defs", "Mathlib.Tactic.Positivity.Core", "Qq" ]
Mathlib/Tactic/Positivity/Basic.lean
evalIte
The `positivity` extension which identifies expressions of the form `ite p a b`, such that `positivity` successfully recognises both `a` and `b`.
private le_min_of_lt_of_le (ha : a < b) (hb : a ≤ c) : a ≤ min b c := le_min ha.le hb
lemma
Tactic
[ "Mathlib.Algebra.Order.Group.PosPart", "Mathlib.Algebra.Order.Ring.Basic", "Mathlib.Algebra.Order.Hom.Basic", "Mathlib.Data.Int.CharZero", "Mathlib.Data.Nat.Factorial.Basic", "Mathlib.Data.NNRat.Defs", "Mathlib.Data.PNat.Defs", "Mathlib.Tactic.Positivity.Core", "Qq" ]
Mathlib/Tactic/Positivity/Basic.lean
le_min_of_lt_of_le
null
private le_min_of_le_of_lt (ha : a ≤ b) (hb : a < c) : a ≤ min b c := le_min ha hb.le
lemma
Tactic
[ "Mathlib.Algebra.Order.Group.PosPart", "Mathlib.Algebra.Order.Ring.Basic", "Mathlib.Algebra.Order.Hom.Basic", "Mathlib.Data.Int.CharZero", "Mathlib.Data.Nat.Factorial.Basic", "Mathlib.Data.NNRat.Defs", "Mathlib.Data.PNat.Defs", "Mathlib.Tactic.Positivity.Core", "Qq" ]
Mathlib/Tactic/Positivity/Basic.lean
le_min_of_le_of_lt
null
private min_ne (ha : a ≠ c) (hb : b ≠ c) : min a b ≠ c := by rw [min_def]; split_ifs <;> assumption
lemma
Tactic
[ "Mathlib.Algebra.Order.Group.PosPart", "Mathlib.Algebra.Order.Ring.Basic", "Mathlib.Algebra.Order.Hom.Basic", "Mathlib.Data.Int.CharZero", "Mathlib.Data.Nat.Factorial.Basic", "Mathlib.Data.NNRat.Defs", "Mathlib.Data.PNat.Defs", "Mathlib.Tactic.Positivity.Core", "Qq" ]
Mathlib/Tactic/Positivity/Basic.lean
min_ne
null
private min_ne_of_ne_of_lt (ha : a ≠ c) (hb : c < b) : min a b ≠ c := min_ne ha hb.ne'
lemma
Tactic
[ "Mathlib.Algebra.Order.Group.PosPart", "Mathlib.Algebra.Order.Ring.Basic", "Mathlib.Algebra.Order.Hom.Basic", "Mathlib.Data.Int.CharZero", "Mathlib.Data.Nat.Factorial.Basic", "Mathlib.Data.NNRat.Defs", "Mathlib.Data.PNat.Defs", "Mathlib.Tactic.Positivity.Core", "Qq" ]
Mathlib/Tactic/Positivity/Basic.lean
min_ne_of_ne_of_lt
null
private min_ne_of_lt_of_ne (ha : c < a) (hb : b ≠ c) : min a b ≠ c := min_ne ha.ne' hb
lemma
Tactic
[ "Mathlib.Algebra.Order.Group.PosPart", "Mathlib.Algebra.Order.Ring.Basic", "Mathlib.Algebra.Order.Hom.Basic", "Mathlib.Data.Int.CharZero", "Mathlib.Data.Nat.Factorial.Basic", "Mathlib.Data.NNRat.Defs", "Mathlib.Data.PNat.Defs", "Mathlib.Tactic.Positivity.Core", "Qq" ]
Mathlib/Tactic/Positivity/Basic.lean
min_ne_of_lt_of_ne
null
private max_ne (ha : a ≠ c) (hb : b ≠ c) : max a b ≠ c := by rw [max_def]; split_ifs <;> assumption
lemma
Tactic
[ "Mathlib.Algebra.Order.Group.PosPart", "Mathlib.Algebra.Order.Ring.Basic", "Mathlib.Algebra.Order.Hom.Basic", "Mathlib.Data.Int.CharZero", "Mathlib.Data.Nat.Factorial.Basic", "Mathlib.Data.NNRat.Defs", "Mathlib.Data.PNat.Defs", "Mathlib.Tactic.Positivity.Core", "Qq" ]
Mathlib/Tactic/Positivity/Basic.lean
max_ne
null
@[positivity min _ _] evalMin : PositivityExt where eval {u α} zα pα e := do let .app (.app (f : Q($α → $α → $α)) (a : Q($α))) (b : Q($α)) ← withReducible (whnf e) | throwError "not min" let _e_eq : $e =Q $f $a $b := ⟨⟩ let _a ← synthInstanceQ q(LinearOrder $α) assumeInstancesCommute let ⟨_f_eq⟩ ← withDefault <| withNewMCtxDepth <| assertDefEqQ q($f) q(min) match ← core zα pα a, ← core zα pα b with | .positive pa, .positive pb => pure (.positive q(lt_min $pa $pb)) | .positive pa, .nonnegative pb => pure (.nonnegative q(le_min_of_lt_of_le $pa $pb)) | .nonnegative pa, .positive pb => pure (.nonnegative q(le_min_of_le_of_lt $pa $pb)) | .nonnegative pa, .nonnegative pb => pure (.nonnegative q(le_min $pa $pb)) | .positive pa, .nonzero pb => pure (.nonzero q(min_ne_of_lt_of_ne $pa $pb)) | .nonzero pa, .positive pb => pure (.nonzero q(min_ne_of_ne_of_lt $pa $pb)) | .nonzero pa, .nonzero pb => pure (.nonzero q(min_ne $pa $pb)) | _, _ => pure .none
def
Tactic
[ "Mathlib.Algebra.Order.Group.PosPart", "Mathlib.Algebra.Order.Ring.Basic", "Mathlib.Algebra.Order.Hom.Basic", "Mathlib.Data.Int.CharZero", "Mathlib.Data.Nat.Factorial.Basic", "Mathlib.Data.NNRat.Defs", "Mathlib.Data.PNat.Defs", "Mathlib.Tactic.Positivity.Core", "Qq" ]
Mathlib/Tactic/Positivity/Basic.lean
evalMin
The `positivity` extension which identifies expressions of the form `min a b`, such that `positivity` successfully recognises both `a` and `b`.
@[positivity max _ _] evalMax : PositivityExt where eval {u α} zα pα e := do let .app (.app (f : Q($α → $α → $α)) (a : Q($α))) (b : Q($α)) ← withReducible (whnf e) | throwError "not max" let _e_eq : $e =Q $f $a $b := ⟨⟩ let _a ← synthInstanceQ q(LinearOrder $α) assumeInstancesCommute let ⟨_f_eq⟩ ← withDefault <| withNewMCtxDepth <| assertDefEqQ q($f) q(max) let result : Strictness zα pα e ← catchNone do let ra ← core zα pα a match ra with | .positive pa => pure (.positive q(lt_max_of_lt_left $pa)) | .nonnegative pa => pure (.nonnegative q(le_max_of_le_left $pa)) | _ => pure .none orElse result do let rb ← core zα pα b match rb with | .positive pb => pure (.positive q(lt_max_of_lt_right $pb)) | .nonnegative pb => pure (.nonnegative q(le_max_of_le_right $pb)) | .nonzero pb => do match ← core zα pα a with | .nonzero pa => pure (.nonzero q(max_ne $pa $pb)) | _ => pure .none | _ => pure .none
def
Tactic
[ "Mathlib.Algebra.Order.Group.PosPart", "Mathlib.Algebra.Order.Ring.Basic", "Mathlib.Algebra.Order.Hom.Basic", "Mathlib.Data.Int.CharZero", "Mathlib.Data.Nat.Factorial.Basic", "Mathlib.Data.NNRat.Defs", "Mathlib.Data.PNat.Defs", "Mathlib.Tactic.Positivity.Core", "Qq" ]
Mathlib/Tactic/Positivity/Basic.lean
evalMax
Extension for the `max` operator. The `max` of two numbers is nonnegative if at least one is nonnegative, strictly positive if at least one is positive, and nonzero if both are nonzero.
@[positivity _ + _] evalAdd : PositivityExt where eval {u α} zα pα e := do let .app (.app (f : Q($α → $α → $α)) (a : Q($α))) (b : Q($α)) ← withReducible (whnf e) | throwError "not +" let _e_eq : $e =Q $f $a $b := ⟨⟩ let _a ← synthInstanceQ q(AddZeroClass $α) assumeInstancesCommute let ⟨_f_eq⟩ ← withDefault <| withNewMCtxDepth <| assertDefEqQ q($f) q(HAdd.hAdd) let ra ← core zα pα a; let rb ← core zα pα b match ra, rb with | .positive pa, .positive pb => let _a ← synthInstanceQ q(AddLeftStrictMono $α) pure (.positive q(add_pos $pa $pb)) | .positive pa, .nonnegative pb => let _a ← synthInstanceQ q(AddLeftMono $α) pure (.positive q(add_pos_of_pos_of_nonneg $pa $pb)) | .nonnegative pa, .positive pb => let _a ← synthInstanceQ q(AddRightMono $α) pure (.positive q(Right.add_pos_of_nonneg_of_pos $pa $pb)) | .nonnegative pa, .nonnegative pb => let _a ← synthInstanceQ q(AddLeftMono $α) pure (.nonnegative q(add_nonneg $pa $pb)) | _, _ => failure
def
Tactic
[ "Mathlib.Algebra.Order.Group.PosPart", "Mathlib.Algebra.Order.Ring.Basic", "Mathlib.Algebra.Order.Hom.Basic", "Mathlib.Data.Int.CharZero", "Mathlib.Data.Nat.Factorial.Basic", "Mathlib.Data.NNRat.Defs", "Mathlib.Data.PNat.Defs", "Mathlib.Tactic.Positivity.Core", "Qq" ]
Mathlib/Tactic/Positivity/Basic.lean
evalAdd
The `positivity` extension which identifies expressions of the form `a + b`, such that `positivity` successfully recognises both `a` and `b`.
@[positivity _ * _] evalMul : PositivityExt where eval {u α} zα pα e := do let .app (.app (f : Q($α → $α → $α)) (a : Q($α))) (b : Q($α)) ← withReducible (whnf e) | throwError "not *" let _e_eq : $e =Q $f $a $b := ⟨⟩ let _a ← synthInstanceQ q(Mul $α) let ⟨_f_eq⟩ ← withDefault <| withNewMCtxDepth <| assertDefEqQ q($f) q(HMul.hMul) let ra ← core zα pα a; let rb ← core zα pα b let tryProveNonzero (pa? : Option Q($a ≠ 0)) (pb? : Option Q($b ≠ 0)) : MetaM (Strictness zα pα e) := do let pa ← liftOption pa? let pb ← liftOption pb? let _a ← synthInstanceQ q(NoZeroDivisors $α) pure (.nonzero q(mul_ne_zero $pa $pb)) let tryProveNonneg (pa? : Option Q(0 ≤ $a)) (pb? : Option Q(0 ≤ $b)) : MetaM (Strictness zα pα e) := do let pa ← liftOption pa? let pb ← liftOption pb? let _a ← synthInstanceQ q(MulZeroClass $α) let _a ← synthInstanceQ q(PosMulMono $α) assumeInstancesCommute pure (.nonnegative q(mul_nonneg $pa $pb)) let tryProvePositive (pa? : Option Q(0 < $a)) (pb? : Option Q(0 < $b)) : MetaM (Strictness zα pα e) := do let pa ← liftOption pa? let pb ← liftOption pb? let _a ← synthInstanceQ q(MulZeroClass $α) let _a ← synthInstanceQ q(PosMulStrictMono $α) assumeInstancesCommute pure (.positive q(mul_pos $pa $pb)) let mut result := .none result ← orElse result (tryProvePositive ra.toPositive rb.toPositive) result ← orElse result (tryProveNonneg ra.toNonneg rb.toNonneg) result ← orElse result (tryProveNonzero ra.toNonzero rb.toNonzero) return result
def
Tactic
[ "Mathlib.Algebra.Order.Group.PosPart", "Mathlib.Algebra.Order.Ring.Basic", "Mathlib.Algebra.Order.Hom.Basic", "Mathlib.Data.Int.CharZero", "Mathlib.Data.Nat.Factorial.Basic", "Mathlib.Data.NNRat.Defs", "Mathlib.Data.PNat.Defs", "Mathlib.Tactic.Positivity.Core", "Qq" ]
Mathlib/Tactic/Positivity/Basic.lean
evalMul
The `positivity` extension which identifies expressions of the form `a * b`, such that `positivity` successfully recognises both `a` and `b`.
private int_div_self_pos {a : ℤ} (ha : 0 < a) : 0 < a / a := by rw [Int.ediv_self ha.ne']; exact zero_lt_one
lemma
Tactic
[ "Mathlib.Algebra.Order.Group.PosPart", "Mathlib.Algebra.Order.Ring.Basic", "Mathlib.Algebra.Order.Hom.Basic", "Mathlib.Data.Int.CharZero", "Mathlib.Data.Nat.Factorial.Basic", "Mathlib.Data.NNRat.Defs", "Mathlib.Data.PNat.Defs", "Mathlib.Tactic.Positivity.Core", "Qq" ]
Mathlib/Tactic/Positivity/Basic.lean
int_div_self_pos
null
private int_div_nonneg_of_pos_of_nonneg {a b : ℤ} (ha : 0 < a) (hb : 0 ≤ b) : 0 ≤ a / b := Int.ediv_nonneg ha.le hb
lemma
Tactic
[ "Mathlib.Algebra.Order.Group.PosPart", "Mathlib.Algebra.Order.Ring.Basic", "Mathlib.Algebra.Order.Hom.Basic", "Mathlib.Data.Int.CharZero", "Mathlib.Data.Nat.Factorial.Basic", "Mathlib.Data.NNRat.Defs", "Mathlib.Data.PNat.Defs", "Mathlib.Tactic.Positivity.Core", "Qq" ]
Mathlib/Tactic/Positivity/Basic.lean
int_div_nonneg_of_pos_of_nonneg
null