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 ⌀ |
|---|---|---|---|---|---|---|
isFibAux_two_mul_done {n a b n' a' : ℕ} (H : IsFibAux n a b)
(hn : 2 * n = n') (h : a * (2 * b - a) = a') : fib n' = a' :=
(isFibAux_two_mul H hn h rfl).1 | theorem | Tactic | [
"Mathlib.Data.Nat.Fib.Basic",
"Mathlib.Tactic.NormNum"
] | Mathlib/Tactic/NormNum/NatFib.lean | isFibAux_two_mul_done | null |
isFibAux_two_mul_add_one_done {n a b n' a' : ℕ} (H : IsFibAux n a b)
(hn : 2 * n + 1 = n') (h : a * a + b * b = a') : fib n' = a' :=
(isFibAux_two_mul_add_one H hn h rfl).1 | theorem | Tactic | [
"Mathlib.Data.Nat.Fib.Basic",
"Mathlib.Tactic.NormNum"
] | Mathlib/Tactic/NormNum/NatFib.lean | isFibAux_two_mul_add_one_done | null |
proveNatFib (en' : Q(ℕ)) : (em : Q(ℕ)) × Q(Nat.fib $en' = $em) :=
match en'.natLit! with
| 0 => have : $en' =Q nat_lit 0 := ⟨⟩; ⟨q(nat_lit 0), q(Nat.fib_zero)⟩
| 1 => have : $en' =Q nat_lit 1 := ⟨⟩; ⟨q(nat_lit 1), q(Nat.fib_one)⟩
| 2 => have : $en' =Q nat_lit 2 := ⟨⟩; ⟨q(nat_lit 1), q(Nat.fib_two)⟩
| n' =>
... | def | Tactic | [
"Mathlib.Data.Nat.Fib.Basic",
"Mathlib.Tactic.NormNum"
] | Mathlib/Tactic/NormNum/NatFib.lean | proveNatFib | Given the natural number literal `ex`, returns `Nat.fib ex` as a natural number literal
and an equality proof. Panics if `ex` isn't a natural number literal. |
isNat_fib : {x nx z : ℕ} → IsNat x nx → Nat.fib nx = z → IsNat (Nat.fib x) z
| _, _, _, ⟨rfl⟩, rfl => ⟨rfl⟩ | theorem | Tactic | [
"Mathlib.Data.Nat.Fib.Basic",
"Mathlib.Tactic.NormNum"
] | Mathlib/Tactic/NormNum/NatFib.lean | isNat_fib | null |
@[norm_num Nat.fib _]
evalNatFib : NormNumExt where eval {_ _} e := do
let .app _ (x : Q(ℕ)) ← Meta.whnfR e | failure
let sℕ : Q(AddMonoidWithOne ℕ) := q(instAddMonoidWithOneNat)
let ⟨ex, p⟩ ← deriveNat x sℕ
let ⟨ey, pf⟩ := proveNatFib ex
let pf' : Q(IsNat (Nat.fib $x) $ey) := q(isNat_fib $p $pf)
return .is... | def | Tactic | [
"Mathlib.Data.Nat.Fib.Basic",
"Mathlib.Tactic.NormNum"
] | Mathlib/Tactic/NormNum/NatFib.lean | evalNatFib | Evaluates the `Nat.fib` function. |
private nat_log_zero (n : Nat) : Nat.log 0 n = 0 := Nat.log_zero_left n | lemma | Tactic | [
"Mathlib.Data.Nat.Log",
"Mathlib.Tactic.NormNum"
] | Mathlib/Tactic/NormNum/NatLog.lean | nat_log_zero | null |
private nat_log_one (n : Nat) : Nat.log 1 n = 0 := Nat.log_one_left n | lemma | Tactic | [
"Mathlib.Data.Nat.Log",
"Mathlib.Tactic.NormNum"
] | Mathlib/Tactic/NormNum/NatLog.lean | nat_log_one | null |
private nat_log_helper0 (b n : Nat) (hl : Nat.blt n b = true) :
Nat.log b n = 0 := by
rw [Nat.blt_eq] at hl
simp [hl] | lemma | Tactic | [
"Mathlib.Data.Nat.Log",
"Mathlib.Tactic.NormNum"
] | Mathlib/Tactic/NormNum/NatLog.lean | nat_log_helper0 | null |
private nat_log_helper (b n k : Nat)
(hl : Nat.ble (b ^ k) n = true) (hh : Nat.blt n (b ^ (k + 1)) = true) :
Nat.log b n = k :=
Nat.log_eq_of_pow_le_of_lt_pow (Nat.le_of_ble_eq_true hl) (Nat.le_of_ble_eq_true hh) | lemma | Tactic | [
"Mathlib.Data.Nat.Log",
"Mathlib.Tactic.NormNum"
] | Mathlib/Tactic/NormNum/NatLog.lean | nat_log_helper | null |
private isNat_log : {b nb n nn k : ℕ} → IsNat b nb → IsNat n nn →
Nat.log nb nn = k → IsNat (Nat.log b n) k
| _, _, _, _, _, ⟨rfl⟩, ⟨rfl⟩, rfl => ⟨rfl⟩ | theorem | Tactic | [
"Mathlib.Data.Nat.Log",
"Mathlib.Tactic.NormNum"
] | Mathlib/Tactic/NormNum/NatLog.lean | isNat_log | null |
proveNatLog (eb en : Q(ℕ)) : (ek : Q(ℕ)) × Q(Nat.log $eb $en = $ek) :=
match eb.natLit!, en.natLit! with
| 0, _ => have : $eb =Q nat_lit 0 := ⟨⟩; ⟨q(nat_lit 0), q(nat_log_zero $en)⟩
| 1, _ => have : $eb =Q nat_lit 1 := ⟨⟩; ⟨q(nat_lit 0), q(nat_log_one $en)⟩
| b, n =>
if n < b then
have hh : Q(Nat.blt ... | def | Tactic | [
"Mathlib.Data.Nat.Log",
"Mathlib.Tactic.NormNum"
] | Mathlib/Tactic/NormNum/NatLog.lean | proveNatLog | Given the natural number literals `eb` and `en`, returns `Nat.log eb en`
as a natural number literal and an equality proof.
Panics if `ex` or `en` aren't natural number literals. |
@[norm_num Nat.log _ _]
evalNatLog : NormNumExt where eval {u α} e := do
let mkApp2 _ (b : Q(ℕ)) (n : Q(ℕ)) ← Meta.whnfR e | failure
let sℕ : Q(AddMonoidWithOne ℕ) := q(instAddMonoidWithOneNat)
let ⟨eb, pb⟩ ← deriveNat b sℕ
let ⟨en, pn⟩ ← deriveNat n sℕ
let ⟨ek, pf⟩ := proveNatLog eb en
let pf' : Q(IsNat (N... | def | Tactic | [
"Mathlib.Data.Nat.Log",
"Mathlib.Tactic.NormNum"
] | Mathlib/Tactic/NormNum/NatLog.lean | evalNatLog | Evaluates the `Nat.log` function. |
private nat_clog_zero_left (b n : Nat) (hb : Nat.ble b 1 = true) :
Nat.clog b n = 0 := Nat.clog_of_left_le_one (Nat.le_of_ble_eq_true hb) n | lemma | Tactic | [
"Mathlib.Data.Nat.Log",
"Mathlib.Tactic.NormNum"
] | Mathlib/Tactic/NormNum/NatLog.lean | nat_clog_zero_left | null |
private nat_clog_zero_right (b n : Nat) (hn : Nat.ble n 1 = true) :
Nat.clog b n = 0 := Nat.clog_of_right_le_one (Nat.le_of_ble_eq_true hn) b | lemma | Tactic | [
"Mathlib.Data.Nat.Log",
"Mathlib.Tactic.NormNum"
] | Mathlib/Tactic/NormNum/NatLog.lean | nat_clog_zero_right | null |
nat_clog_helper {b m n : ℕ} (hb : Nat.blt 1 b = true)
(h₁ : Nat.blt (b ^ m) n = true) (h₂ : Nat.ble n (b ^ (m + 1)) = true) :
Nat.clog b n = m + 1 := by
rw [Nat.blt_eq] at hb
rw [Nat.blt_eq, Nat.pow_lt_iff_lt_clog hb] at h₁
rw [Nat.ble_eq, Nat.le_pow_iff_clog_le hb] at h₂
cutsat | theorem | Tactic | [
"Mathlib.Data.Nat.Log",
"Mathlib.Tactic.NormNum"
] | Mathlib/Tactic/NormNum/NatLog.lean | nat_clog_helper | null |
private isNat_clog : {b nb n nn k : ℕ} → IsNat b nb → IsNat n nn →
Nat.clog nb nn = k → IsNat (Nat.clog b n) k
| _, _, _, _, _, ⟨rfl⟩, ⟨rfl⟩, rfl => ⟨rfl⟩ | theorem | Tactic | [
"Mathlib.Data.Nat.Log",
"Mathlib.Tactic.NormNum"
] | Mathlib/Tactic/NormNum/NatLog.lean | isNat_clog | null |
proveNatClog (eb en : Q(ℕ)) : (ek : Q(ℕ)) × Q(Nat.clog $eb $en = $ek) :=
let b := eb.natLit!
let n := en.natLit!
if _ : b ≤ 1 then
have h : Q(Nat.ble $eb 1 = true) := reflBoolTrue
⟨q(nat_lit 0), q(nat_clog_zero_left $eb $en $h)⟩
else if _ : n ≤ 1 then
have h : Q(Nat.ble $en 1 = true) := reflBoolTrue... | def | Tactic | [
"Mathlib.Data.Nat.Log",
"Mathlib.Tactic.NormNum"
] | Mathlib/Tactic/NormNum/NatLog.lean | proveNatClog | Given the natural number literals `eb` and `en`, returns `Nat.clog eb en`
as a natural number literal and an equality proof.
Panics if `ex` or `en` aren't natural number literals. |
@[norm_num Nat.clog _ _]
evalNatClog : NormNumExt where eval {u α} e := do
let mkApp2 _ (b : Q(ℕ)) (n : Q(ℕ)) ← Meta.whnfR e | failure
let sℕ : Q(AddMonoidWithOne ℕ) := q(instAddMonoidWithOneNat)
let ⟨eb, pb⟩ ← deriveNat b sℕ
let ⟨en, pn⟩ ← deriveNat n sℕ
let ⟨ek, pf⟩ := proveNatClog eb en
let pf' : Q(IsNat... | def | Tactic | [
"Mathlib.Data.Nat.Log",
"Mathlib.Tactic.NormNum"
] | Mathlib/Tactic/NormNum/NatLog.lean | evalNatClog | Evaluates the `Nat.clog` function. |
nat_sqrt_helper {x y r : ℕ} (hr : y * y + r = x) (hle : Nat.ble r (2 * y)) :
Nat.sqrt x = y := by
rw [← hr, ← pow_two]
rw [two_mul] at hle
exact Nat.sqrt_add_eq' _ (Nat.le_of_ble_eq_true hle) | lemma | Tactic | [
"Mathlib.Tactic.NormNum"
] | Mathlib/Tactic/NormNum/NatSqrt.lean | nat_sqrt_helper | null |
isNat_sqrt : {x nx z : ℕ} → IsNat x nx → Nat.sqrt nx = z → IsNat (Nat.sqrt x) z
| _, _, _, ⟨rfl⟩, rfl => ⟨rfl⟩ | theorem | Tactic | [
"Mathlib.Tactic.NormNum"
] | Mathlib/Tactic/NormNum/NatSqrt.lean | isNat_sqrt | null |
proveNatSqrt (ex : Q(ℕ)) : (ey : Q(ℕ)) × Q(Nat.sqrt $ex = $ey) :=
match ex.natLit! with
| 0 => have : $ex =Q nat_lit 0 := ⟨⟩; ⟨q(nat_lit 0), q(Nat.sqrt_zero)⟩
| 1 => have : $ex =Q nat_lit 1 := ⟨⟩; ⟨q(nat_lit 1), q(Nat.sqrt_one)⟩
| x =>
let y := Nat.sqrt x
have ey : Q(ℕ) := mkRawNatLit y
have er : Q(... | def | Tactic | [
"Mathlib.Tactic.NormNum"
] | Mathlib/Tactic/NormNum/NatSqrt.lean | proveNatSqrt | Given the natural number literal `ex`, returns its square root as a natural number literal
and an equality proof. Panics if `ex` isn't a natural number literal. |
@[norm_num Nat.sqrt _]
evalNatSqrt : NormNumExt where eval {_ _} e := do
let .app _ (x : Q(ℕ)) ← Meta.whnfR e | failure
let sℕ : Q(AddMonoidWithOne ℕ) := q(instAddMonoidWithOneNat)
let ⟨ex, p⟩ ← deriveNat x sℕ
let ⟨ey, pf⟩ := proveNatSqrt ex
let pf' : Q(IsNat (Nat.sqrt $x) $ey) := q(isNat_sqrt $p $pf)
retur... | def | Tactic | [
"Mathlib.Tactic.NormNum"
] | Mathlib/Tactic/NormNum/NatSqrt.lean | evalNatSqrt | Evaluates the `Nat.sqrt` function. |
isNNRat_ofScientific_of_true [DivisionRing α] :
{m e : ℕ} → {n : ℕ} → {d : ℕ} →
IsNNRat (mkRat m (10 ^ e) : α) n d → IsNNRat (OfScientific.ofScientific m true e : α) n d
| _, _, _, _, ⟨_, eq⟩ => ⟨‹_›, by
rwa [← Rat.cast_ofScientific, ← Rat.ofScientific_eq_ofScientific, Rat.ofScientific_true_def]⟩ | theorem | Tactic | [
"Mathlib.Tactic.NormNum.Basic",
"Mathlib.Data.Rat.Cast.Lemmas"
] | Mathlib/Tactic/NormNum/OfScientific.lean | isNNRat_ofScientific_of_true | null |
isNat_ofScientific_of_false [DivisionRing α] : {m e nm ne n : ℕ} →
IsNat m nm → IsNat e ne → n = Nat.mul nm ((10 : ℕ) ^ ne) →
IsNat (OfScientific.ofScientific m false e : α) n
| _, _, _, _, _, ⟨rfl⟩, ⟨rfl⟩, h => ⟨by
rw [← Rat.cast_ofScientific, ← Rat.ofScientific_eq_ofScientific]
simp only [Nat.cast_i... | theorem | Tactic | [
"Mathlib.Tactic.NormNum.Basic",
"Mathlib.Data.Rat.Cast.Lemmas"
] | Mathlib/Tactic/NormNum/OfScientific.lean | isNat_ofScientific_of_false | null |
@[norm_num OfScientific.ofScientific _ _ _] evalOfScientific :
NormNumExt where eval {u α} e := do
let .app (.app (.app f (m : Q(ℕ))) (b : Q(Bool))) (exp : Q(ℕ)) ← whnfR e | failure
let dα ← inferDivisionRing α
guard <|← withNewMCtxDepth <| isDefEq f q(OfScientific.ofScientific (α := $α))
assumeInstancesCom... | def | Tactic | [
"Mathlib.Tactic.NormNum.Basic",
"Mathlib.Data.Rat.Cast.Lemmas"
] | Mathlib/Tactic/NormNum/OfScientific.lean | evalOfScientific | The `norm_num` extension which identifies expressions in scientific notation, normalizing them
to rat casts if the scientific notation is inherited from the one for rationals. |
@[norm_num (_ : Ordinal) * (_ : Ordinal)]
evalOrdinalMul : NormNumExt where
eval {u α} e := do
let some u' := u.dec | throwError "level is not succ"
haveI' : u =QL u' + 1 := ⟨⟩
match α, e with
| ~q(Ordinal.{u'}), ~q(($a : Ordinal) * ($b : Ordinal)) =>
let i : Q(AddMonoidWithOne Ordinal.{u'}) := ... | def | Tactic | [
"Mathlib.SetTheory.Ordinal.Exponential",
"Mathlib.Tactic.NormNum.Basic"
] | Mathlib/Tactic/NormNum/Ordinal.lean | evalOrdinalMul | info: 12 * 5 -/
#guard_msgs in
#norm_num (12 : Ordinal.{0}) * (5 : Ordinal.{0})
lemma isNat_ordinalMul.{u} : ∀ {a b : Ordinal.{u}} {an bn rn : ℕ},
IsNat a an → IsNat b bn → an * bn = rn → IsNat (a * b) rn
| _, _, _, _, _, ⟨rfl⟩, ⟨rfl⟩, rfl => ⟨Eq.symm <| natCast_mul ..⟩
/-- The `norm_num` extension for multipli... |
@[norm_num (_ : Ordinal) ≤ (_ : Ordinal)]
evalOrdinalLE : NormNumExt where
eval {u α} e := do
let ⟨_⟩ ← assertLevelDefEqQ u ql(0)
match α, e with
| ~q(Prop), ~q(($a : Ordinal) ≤ ($b : Ordinal)) =>
let i : Q(AddMonoidWithOne Ordinal.{u_1}) := q(inferInstance)
let ⟨an, pa⟩ ← deriveNat a i
... | def | Tactic | [
"Mathlib.SetTheory.Ordinal.Exponential",
"Mathlib.Tactic.NormNum.Basic"
] | Mathlib/Tactic/NormNum/Ordinal.lean | evalOrdinalLE | info: 5 ≤ 12 -/
#guard_msgs in
#norm_num (5 : Ordinal.{0}) ≤ 12
/-- info: 5 < 12 -/
#guard_msgs in
#norm_num (5 : Ordinal.{0}) < 12
lemma isNat_ordinalLE_true.{u} : ∀ {a b : Ordinal.{u}} {an bn : ℕ},
IsNat a an → IsNat b bn → decide (an ≤ bn) = true → a ≤ b
| _, _, _, _, ⟨rfl⟩, ⟨rfl⟩, h => Nat.cast_le.mpr <| of... |
@[norm_num (_ : Ordinal) < (_ : Ordinal)]
evalOrdinalLT : NormNumExt where
eval {u α} e := do
let ⟨_⟩ ← assertLevelDefEqQ u ql(0)
match α, e with
| ~q(Prop), ~q(($a : Ordinal) < ($b : Ordinal)) =>
let i : Q(AddMonoidWithOne Ordinal.{u_1}) := q(inferInstance)
let ⟨an, pa⟩ ← deriveNat a i
... | def | Tactic | [
"Mathlib.SetTheory.Ordinal.Exponential",
"Mathlib.Tactic.NormNum.Basic"
] | Mathlib/Tactic/NormNum/Ordinal.lean | evalOrdinalLT | The `norm_num` extension for strict inequality on ordinals. |
@[norm_num (_ : Ordinal) - (_ : Ordinal)]
evalOrdinalSub : NormNumExt where
eval {u α} e := do
let some u' := u.dec | throwError "level is not succ"
haveI' : u =QL u' + 1 := ⟨⟩
match α, e with
| ~q(Ordinal.{u'}), ~q(($a : Ordinal) - ($b : Ordinal)) =>
let i : Q(AddMonoidWithOne Ordinal.{u'}) := ... | def | Tactic | [
"Mathlib.SetTheory.Ordinal.Exponential",
"Mathlib.Tactic.NormNum.Basic"
] | Mathlib/Tactic/NormNum/Ordinal.lean | evalOrdinalSub | info: 12 - 5 -/
#guard_msgs in
#norm_num (12 : Ordinal.{0}) - 5
lemma isNat_ordinalSub.{u} : ∀ {a b : Ordinal.{u}} {an bn rn : ℕ},
IsNat a an → IsNat b bn → an - bn = rn → IsNat (a - b) rn
| _, _, _, _, _, ⟨rfl⟩, ⟨rfl⟩, rfl => ⟨Eq.symm <| natCast_sub ..⟩
/-- The `norm_num` extension for subtraction on ordinals. |
@[norm_num (_ : Ordinal) / (_ : Ordinal)]
evalOrdinalDiv : NormNumExt where
eval {u α} e := do
let some u' := u.dec | throwError "level is not succ"
haveI' : u =QL u' + 1 := ⟨⟩
match α, e with
| ~q(Ordinal.{u'}), ~q(($a : Ordinal) / ($b : Ordinal)) =>
let i : Q(AddMonoidWithOne Ordinal.{u'}) := ... | def | Tactic | [
"Mathlib.SetTheory.Ordinal.Exponential",
"Mathlib.Tactic.NormNum.Basic"
] | Mathlib/Tactic/NormNum/Ordinal.lean | evalOrdinalDiv | info: 12 / 5 -/
#guard_msgs in
#norm_num (12 : Ordinal.{0}) / 5
lemma isNat_ordinalDiv.{u} : ∀ {a b : Ordinal.{u}} {an bn rn : ℕ},
IsNat a an → IsNat b bn → an / bn = rn → IsNat (a / b) rn
| _, _, _, _, _, ⟨rfl⟩, ⟨rfl⟩, rfl => ⟨Eq.symm <| natCast_div ..⟩
/-- The `norm_num` extension for division on ordinals. |
@[norm_num (_ : Ordinal) % (_ : Ordinal)]
evalOrdinalMod : NormNumExt where
eval {u α} e := do
let some u' := u.dec | throwError "level is not succ"
haveI' : u =QL u' + 1 := ⟨⟩
match α, e with
| ~q(Ordinal.{u'}), ~q(($a : Ordinal) % ($b : Ordinal)) =>
let i : Q(AddMonoidWithOne Ordinal.{u'}) := ... | def | Tactic | [
"Mathlib.SetTheory.Ordinal.Exponential",
"Mathlib.Tactic.NormNum.Basic"
] | Mathlib/Tactic/NormNum/Ordinal.lean | evalOrdinalMod | info: 12 % 5 -/
#guard_msgs in
#norm_num (12 : Ordinal.{0}) % 5
lemma isNat_ordinalMod.{u} : ∀ {a b : Ordinal.{u}} {an bn rn : ℕ},
IsNat a an → IsNat b bn → an % bn = rn → IsNat (a % b) rn
| _, _, _, _, _, ⟨rfl⟩, ⟨rfl⟩, rfl => ⟨Eq.symm <| natCast_mod ..⟩
/-- The `norm_num` extension for modulo on ordinals. |
isNat_ordinalOPow.{u} : ∀ {a b : Ordinal.{u}} {an bn rn : ℕ},
IsNat a an → IsNat b bn → an ^ bn = rn → IsNat (a ^ b) rn
| _, _, _, _, _, ⟨rfl⟩, ⟨rfl⟩, rfl => ⟨Eq.symm <| natCast_opow ..⟩ | lemma | Tactic | [
"Mathlib.SetTheory.Ordinal.Exponential",
"Mathlib.Tactic.NormNum.Basic"
] | Mathlib/Tactic/NormNum/Ordinal.lean | isNat_ordinalOPow. | null |
@[norm_num (_ : Ordinal) ^ (_ : Ordinal)]
evalOrdinalOPow : NormNumExt where
eval {u α} e := do
let some u' := u.dec | throwError "level is not succ"
haveI' : u =QL u' + 1 := ⟨⟩
match α, e with
| ~q(Ordinal.{u'}), ~q(($a : Ordinal) ^ ($b : Ordinal)) =>
let i : Q(AddMonoidWithOne Ordinal.{u'}) :=... | def | Tactic | [
"Mathlib.SetTheory.Ordinal.Exponential",
"Mathlib.Tactic.NormNum.Basic"
] | Mathlib/Tactic/NormNum/Ordinal.lean | evalOrdinalOPow | The `norm_num` extension for homogeneous power on ordinals. |
@[norm_num (_ : Ordinal) ^ (_ : ℕ)]
evalOrdinalNPow : NormNumExt where
eval {u α} e := do
let some u' := u.dec | throwError "level is not succ"
haveI' : u =QL u' + 1 := ⟨⟩
match α, e with
| ~q(Ordinal.{u'}), ~q(($a : Ordinal) ^ ($b : ℕ)) =>
let i : Q(AddMonoidWithOne Ordinal.{u'}) := q(inferInst... | def | Tactic | [
"Mathlib.SetTheory.Ordinal.Exponential",
"Mathlib.Tactic.NormNum.Basic"
] | Mathlib/Tactic/NormNum/Ordinal.lean | evalOrdinalNPow | info: 12 ^ 2 -/
#guard_msgs in
#norm_num (12 : Ordinal.{0}) ^ (2 : ℕ)
lemma isNat_ordinalNPow.{u} : ∀ {a : Ordinal.{u}} {b an bn rn : ℕ},
IsNat a an → IsNat b bn → an ^ bn = rn → IsNat (a ^ b) rn
| _, _, _, _, _, ⟨rfl⟩, ⟨rfl⟩, rfl => ⟨Eq.symm <| natCast_opow .. |>.trans <| opow_natCast ..⟩
/-- The `norm_num` ex... |
@[norm_num Even _]
evalEven : NormNumExt where eval {u αP} e := do
match u, αP, e with
| 0, ~q(Prop), ~q(@Even ℕ _ $a) =>
assertInstancesCommute
let ⟨b, r⟩ ← deriveBoolOfIff q($a % 2 = 0) q(Even $a) q((@Nat.even_iff $a).symm)
return .ofBoolResult r
| 0, ~q(Prop), ~q(@Even ℤ _ $a) =>
assertInstance... | def | Tactic | [
"Mathlib.Algebra.Ring.Int.Parity",
"Mathlib.Tactic.NormNum.Core"
] | Mathlib/Tactic/NormNum/Parity.lean | evalEven | `norm_num` extension for `Even`.
Works for `ℕ` and `ℤ`. |
@[norm_num Odd _]
evalOdd : NormNumExt where eval {u αP} e := do
match u, αP, e with
| 0, ~q(Prop), ~q(@Odd ℕ $inst $a) =>
assertInstancesCommute
let ⟨b, r⟩ ← deriveBoolOfIff q($a % 2 = 1) q(Odd $a) q((@Nat.odd_iff $a).symm)
return .ofBoolResult r
| 0, ~q(Prop), ~q(@Odd ℤ $inst $a) =>
assertInstan... | def | Tactic | [
"Mathlib.Algebra.Ring.Int.Parity",
"Mathlib.Tactic.NormNum.Core"
] | Mathlib/Tactic/NormNum/Parity.lean | evalOdd | `norm_num` extension for `Odd`.
Works for `ℕ` and `ℤ`. |
natPow_zero : Nat.pow a (nat_lit 0) = nat_lit 1 := rfl | theorem | Tactic | [
"Mathlib.Data.Int.Cast.Lemmas",
"Mathlib.Tactic.NormNum.Basic"
] | Mathlib/Tactic/NormNum/Pow.lean | natPow_zero | null |
natPow_one : Nat.pow a (nat_lit 1) = a := Nat.pow_one _ | theorem | Tactic | [
"Mathlib.Data.Int.Cast.Lemmas",
"Mathlib.Tactic.NormNum.Basic"
] | Mathlib/Tactic/NormNum/Pow.lean | natPow_one | null |
zero_natPow : Nat.pow (nat_lit 0) (Nat.succ b) = nat_lit 0 := rfl | theorem | Tactic | [
"Mathlib.Data.Int.Cast.Lemmas",
"Mathlib.Tactic.NormNum.Basic"
] | Mathlib/Tactic/NormNum/Pow.lean | zero_natPow | null |
one_natPow : Nat.pow (nat_lit 1) b = nat_lit 1 := Nat.one_pow _ | theorem | Tactic | [
"Mathlib.Data.Int.Cast.Lemmas",
"Mathlib.Tactic.NormNum.Basic"
] | Mathlib/Tactic/NormNum/Pow.lean | one_natPow | null |
IsNatPowT (p : Prop) (a b c : Nat) : Prop where
/-- Unfolds the assertion. -/
run' : p → Nat.pow a b = c | structure | Tactic | [
"Mathlib.Data.Int.Cast.Lemmas",
"Mathlib.Tactic.NormNum.Basic"
] | Mathlib/Tactic/NormNum/Pow.lean | IsNatPowT | This is an opaque wrapper around `Nat.pow` to prevent lean from unfolding the definition of
`Nat.pow` on numerals. The arbitrary precondition `p` is actually a formula of the form
`Nat.pow a' b' = c'` but we usually don't care to unfold this proposition so we just carry a
reference to it. |
IsNatPowT.run
(p : IsNatPowT (Nat.pow a (nat_lit 1) = a) a b c) : Nat.pow a b = c := p.run' (Nat.pow_one _) | theorem | Tactic | [
"Mathlib.Data.Int.Cast.Lemmas",
"Mathlib.Tactic.NormNum.Basic"
] | Mathlib/Tactic/NormNum/Pow.lean | IsNatPowT.run | null |
IsNatPowT.trans {p : Prop} {b' c' : ℕ} (h1 : IsNatPowT p a b c)
(h2 : IsNatPowT (Nat.pow a b = c) a b' c') : IsNatPowT p a b' c' :=
⟨h2.run' ∘ h1.run'⟩ | theorem | Tactic | [
"Mathlib.Data.Int.Cast.Lemmas",
"Mathlib.Tactic.NormNum.Basic"
] | Mathlib/Tactic/NormNum/Pow.lean | IsNatPowT.trans | This is the key to making the proof proceed as a balanced tree of applications instead of
a linear sequence. It is just modus ponens after unwrapping the definitions. |
IsNatPowT.bit0 : IsNatPowT (Nat.pow a b = c) a (nat_lit 2 * b) (Nat.mul c c) :=
⟨fun h1 => by simp [two_mul, pow_add, ← h1]⟩ | theorem | Tactic | [
"Mathlib.Data.Int.Cast.Lemmas",
"Mathlib.Tactic.NormNum.Basic"
] | Mathlib/Tactic/NormNum/Pow.lean | IsNatPowT.bit0 | null |
IsNatPowT.bit1 :
IsNatPowT (Nat.pow a b = c) a (nat_lit 2 * b + nat_lit 1) (Nat.mul c (Nat.mul c a)) :=
⟨fun h1 => by simp [two_mul, pow_add, mul_assoc, ← h1]⟩ | theorem | Tactic | [
"Mathlib.Data.Int.Cast.Lemmas",
"Mathlib.Tactic.NormNum.Basic"
] | Mathlib/Tactic/NormNum/Pow.lean | IsNatPowT.bit1 | null |
partial evalNatPow (a b : Q(ℕ)) : (c : Q(ℕ)) × Q(Nat.pow $a $b = $c) :=
if b.natLit! = 0 then
haveI : $b =Q 0 := ⟨⟩
⟨q(nat_lit 1), q(natPow_zero)⟩
else if a.natLit! = 0 then
haveI : $a =Q 0 := ⟨⟩
have b' : Q(ℕ) := mkRawNatLit (b.natLit! - 1)
haveI : $b =Q Nat.succ $b' := ⟨⟩
⟨q(nat_lit 0), q(... | def | Tactic | [
"Mathlib.Data.Int.Cast.Lemmas",
"Mathlib.Tactic.NormNum.Basic"
] | Mathlib/Tactic/NormNum/Pow.lean | evalNatPow | Proves `Nat.pow a b = c` where `a` and `b` are raw nat literals. This could be done by just
`rfl` but the kernel does not have a special case implementation for `Nat.pow` so this would
proceed by unary recursion on `b`, which is too slow and also leads to deep recursion.
We instead do the proof by binary recursion, bu... |
intPow_ofNat (h1 : Nat.pow a b = c) :
Int.pow (Int.ofNat a) b = Int.ofNat c := by simp [← h1] | theorem | Tactic | [
"Mathlib.Data.Int.Cast.Lemmas",
"Mathlib.Tactic.NormNum.Basic"
] | Mathlib/Tactic/NormNum/Pow.lean | intPow_ofNat | null |
intPow_negOfNat_bit0 {b' c' : ℕ} (h1 : Nat.pow a b' = c')
(hb : nat_lit 2 * b' = b) (hc : c' * c' = c) :
Int.pow (Int.negOfNat a) b = Int.ofNat c := by
rw [← hb, Int.negOfNat_eq, Int.pow_eq, pow_mul, neg_pow_two, ← pow_mul, two_mul, pow_add, ← hc,
← h1]
simp | theorem | Tactic | [
"Mathlib.Data.Int.Cast.Lemmas",
"Mathlib.Tactic.NormNum.Basic"
] | Mathlib/Tactic/NormNum/Pow.lean | intPow_negOfNat_bit0 | null |
intPow_negOfNat_bit1 {b' c' : ℕ} (h1 : Nat.pow a b' = c')
(hb : nat_lit 2 * b' + nat_lit 1 = b) (hc : c' * (c' * a) = c) :
Int.pow (Int.negOfNat a) b = Int.negOfNat c := by
rw [← hb, Int.negOfNat_eq, Int.negOfNat_eq, Int.pow_eq, pow_succ, pow_mul, neg_pow_two, ← pow_mul,
two_mul, pow_add, ← hc, ← h1]
si... | theorem | Tactic | [
"Mathlib.Data.Int.Cast.Lemmas",
"Mathlib.Tactic.NormNum.Basic"
] | Mathlib/Tactic/NormNum/Pow.lean | intPow_negOfNat_bit1 | null |
partial evalIntPow (za : ℤ) (a : Q(ℤ)) (b : Q(ℕ)) : ℤ × (c : Q(ℤ)) × Q(Int.pow $a $b = $c) :=
have a' : Q(ℕ) := a.appArg!
if 0 ≤ za then
haveI : $a =Q .ofNat $a' := ⟨⟩
let ⟨c, p⟩ := evalNatPow a' b
⟨c.natLit!, q(.ofNat $c), q(intPow_ofNat $p)⟩
else
haveI : $a =Q .negOfNat $a' := ⟨⟩
let b' := b... | def | Tactic | [
"Mathlib.Data.Int.Cast.Lemmas",
"Mathlib.Tactic.NormNum.Basic"
] | Mathlib/Tactic/NormNum/Pow.lean | evalIntPow | Evaluates `Int.pow a b = c` where `a` and `b` are raw integer literals. |
isNat_pow {α} [Semiring α] : ∀ {f : α → ℕ → α} {a : α} {b a' b' c : ℕ},
f = HPow.hPow → IsNat a a' → IsNat b b' → Nat.pow a' b' = c → IsNat (f a b) c
| _, _, _, _, _, _, rfl, ⟨rfl⟩, ⟨rfl⟩, rfl => ⟨by simp⟩ | theorem | Tactic | [
"Mathlib.Data.Int.Cast.Lemmas",
"Mathlib.Tactic.NormNum.Basic"
] | Mathlib/Tactic/NormNum/Pow.lean | isNat_pow | null |
isInt_pow {α} [Ring α] : ∀ {f : α → ℕ → α} {a : α} {b : ℕ} {a' : ℤ} {b' : ℕ} {c : ℤ},
f = HPow.hPow → IsInt a a' → IsNat b b' → Int.pow a' b' = c → IsInt (f a b) c
| _, _, _, _, _, _, rfl, ⟨rfl⟩, ⟨rfl⟩, rfl => ⟨by simp⟩ | theorem | Tactic | [
"Mathlib.Data.Int.Cast.Lemmas",
"Mathlib.Tactic.NormNum.Basic"
] | Mathlib/Tactic/NormNum/Pow.lean | isInt_pow | null |
isRat_pow {α} [Ring α] {f : α → ℕ → α} {a : α} {an cn : ℤ} {ad b b' cd : ℕ} :
f = HPow.hPow → IsRat a an ad → IsNat b b' →
Int.pow an b' = cn → Nat.pow ad b' = cd →
IsRat (f a b) cn cd := by
rintro rfl ⟨_, rfl⟩ ⟨rfl⟩ (rfl : an ^ b = _) (rfl : ad ^ b = _)
have := invertiblePow (ad:α) b
rw [← Nat.cast_p... | theorem | Tactic | [
"Mathlib.Data.Int.Cast.Lemmas",
"Mathlib.Tactic.NormNum.Basic"
] | Mathlib/Tactic/NormNum/Pow.lean | isRat_pow | null |
isNNRat_pow {α} [Semiring α] {f : α → ℕ → α} {a : α} {an cn : ℕ} {ad b b' cd : ℕ} :
f = HPow.hPow → IsNNRat a an ad → IsNat b b' →
Nat.pow an b' = cn → Nat.pow ad b' = cd →
IsNNRat (f a b) cn cd := by
rintro rfl ⟨_, rfl⟩ ⟨rfl⟩ (rfl : an ^ b = _) (rfl : ad ^ b = _)
have := invertiblePow (ad:α) b
rw [← ... | theorem | Tactic | [
"Mathlib.Data.Int.Cast.Lemmas",
"Mathlib.Tactic.NormNum.Basic"
] | Mathlib/Tactic/NormNum/Pow.lean | isNNRat_pow | null |
evalPow.core {u : Level} {α : Q(Type u)} (e : Q(«$α»)) (f : Q(«$α» → ℕ → «$α»)) (a : Q(«$α»))
(b nb : Q(ℕ)) (pb : Q(IsNat «$b» «$nb»)) (sα : Q(Semiring «$α»)) (ra : Result a) :
Option (Result e) := do
haveI' : $e =Q $a ^ $b := ⟨⟩
haveI' : $f =Q HPow.hPow := ⟨⟩
match ra with
| .isBool .. => failure
| .... | def | Tactic | [
"Mathlib.Data.Int.Cast.Lemmas",
"Mathlib.Tactic.NormNum.Basic"
] | Mathlib/Tactic/NormNum/Pow.lean | evalPow.core | Main part of `evalPow`. |
@[norm_num _ ^ (_ : ℕ)]
evalPow : NormNumExt where eval {u α} e := do
let .app (.app (f : Q($α → ℕ → $α)) (a : Q($α))) (b : Q(ℕ)) ← whnfR e | failure
let ⟨nb, pb⟩ ← deriveNat b q(instAddMonoidWithOneNat)
let sα ← inferSemiring α
let ra ← derive a
guard <|← withDefault <| withNewMCtxDepth <| isDefEq f q(HPow.h... | def | Tactic | [
"Mathlib.Data.Int.Cast.Lemmas",
"Mathlib.Tactic.NormNum.Basic"
] | Mathlib/Tactic/NormNum/Pow.lean | evalPow | The `norm_num` extension which identifies expressions of the form `a ^ b`,
such that `norm_num` successfully recognises both `a` and `b`, with `b : ℕ`. |
isNat_zpow_pos {α : Type*} [DivisionSemiring α] {a : α} {b : ℤ} {nb ne : ℕ}
(pb : IsNat b nb) (pe' : IsNat (a ^ nb) ne) :
IsNat (a ^ b) ne := by
rwa [pb.out, zpow_natCast] | theorem | Tactic | [
"Mathlib.Data.Int.Cast.Lemmas",
"Mathlib.Tactic.NormNum.Basic"
] | Mathlib/Tactic/NormNum/Pow.lean | isNat_zpow_pos | null |
isNat_zpow_neg {α : Type*} [DivisionSemiring α] {a : α} {b : ℤ} {nb ne : ℕ}
(pb : IsInt b (Int.negOfNat nb)) (pe' : IsNat (a ^ nb)⁻¹ ne) :
IsNat (a ^ b) ne := by
rwa [pb.out, Int.cast_negOfNat, zpow_neg, zpow_natCast] | theorem | Tactic | [
"Mathlib.Data.Int.Cast.Lemmas",
"Mathlib.Tactic.NormNum.Basic"
] | Mathlib/Tactic/NormNum/Pow.lean | isNat_zpow_neg | null |
isInt_zpow_pos {α : Type*} [DivisionRing α] {a : α} {b : ℤ} {nb ne : ℕ}
(pb : IsNat b nb) (pe' : IsInt (a ^ nb) (Int.negOfNat ne)) :
IsInt (a ^ b) (Int.negOfNat ne) := by
rwa [pb.out, zpow_natCast] | theorem | Tactic | [
"Mathlib.Data.Int.Cast.Lemmas",
"Mathlib.Tactic.NormNum.Basic"
] | Mathlib/Tactic/NormNum/Pow.lean | isInt_zpow_pos | null |
isInt_zpow_neg {α : Type*} [DivisionRing α] {a : α} {b : ℤ} {nb ne : ℕ}
(pb : IsInt b (Int.negOfNat nb)) (pe' : IsInt (a ^ nb)⁻¹ (Int.negOfNat ne)) :
IsInt (a ^ b) (Int.negOfNat ne) := by
rwa [pb.out, Int.cast_negOfNat, zpow_neg, zpow_natCast] | theorem | Tactic | [
"Mathlib.Data.Int.Cast.Lemmas",
"Mathlib.Tactic.NormNum.Basic"
] | Mathlib/Tactic/NormNum/Pow.lean | isInt_zpow_neg | null |
isNNRat_zpow_pos {α : Type*} [DivisionSemiring α] {a : α} {b : ℤ} {nb : ℕ}
{num : ℕ} {den : ℕ}
(pb : IsNat b nb) (pe' : IsNNRat (a ^ nb) num den) :
IsNNRat (a^b) num den := by
rwa [pb.out, zpow_natCast] | theorem | Tactic | [
"Mathlib.Data.Int.Cast.Lemmas",
"Mathlib.Tactic.NormNum.Basic"
] | Mathlib/Tactic/NormNum/Pow.lean | isNNRat_zpow_pos | null |
isNNRat_zpow_neg {α : Type*} [DivisionSemiring α] {a : α} {b : ℤ} {nb : ℕ}
{num : ℕ} {den : ℕ}
(pb : IsInt b (Int.negOfNat nb)) (pe' : IsNNRat ((a ^ nb)⁻¹) num den) :
IsNNRat (a^b) num den := by
rwa [pb.out, Int.cast_negOfNat, zpow_neg, zpow_natCast] | theorem | Tactic | [
"Mathlib.Data.Int.Cast.Lemmas",
"Mathlib.Tactic.NormNum.Basic"
] | Mathlib/Tactic/NormNum/Pow.lean | isNNRat_zpow_neg | null |
isRat_zpow_pos {α : Type*} [DivisionRing α] {a : α} {b : ℤ} {nb : ℕ}
{num : ℤ} {den : ℕ}
(pb : IsNat b nb) (pe' : IsRat (a ^ nb) num den) :
IsRat (a ^ b) num den := by
rwa [pb.out, zpow_natCast] | theorem | Tactic | [
"Mathlib.Data.Int.Cast.Lemmas",
"Mathlib.Tactic.NormNum.Basic"
] | Mathlib/Tactic/NormNum/Pow.lean | isRat_zpow_pos | null |
isRat_zpow_neg {α : Type*} [DivisionRing α] {a : α} {b : ℤ} {nb : ℕ}
{num : ℤ} {den : ℕ}
(pb : IsInt b (Int.negOfNat nb)) (pe' : IsRat ((a ^ nb)⁻¹) num den) :
IsRat (a ^ b) num den := by
rwa [pb.out, Int.cast_negOfNat, zpow_neg, zpow_natCast] | theorem | Tactic | [
"Mathlib.Data.Int.Cast.Lemmas",
"Mathlib.Tactic.NormNum.Basic"
] | Mathlib/Tactic/NormNum/Pow.lean | isRat_zpow_neg | null |
@[norm_num _ ^ (_ : ℤ)]
evalZPow : NormNumExt where eval {u α} e := do
let .app (.app (f : Q($α → ℤ → $α)) (a : Q($α))) (b : Q(ℤ)) ← whnfR e | failure
let _c ← synthInstanceQ q(DivisionSemiring $α)
let rb ← derive (α := q(ℤ)) b
match rb with
| .isBool .. | .isNNRat _ .. | .isNegNNRat _ .. => failure
| .isNa... | def | Tactic | [
"Mathlib.Data.Int.Cast.Lemmas",
"Mathlib.Tactic.NormNum.Basic"
] | Mathlib/Tactic/NormNum/Pow.lean | evalZPow | The `norm_num` extension which identifies expressions of the form `a ^ b`,
such that `norm_num` successfully recognises both `a` and `b`, with `b : ℤ`. |
IsNatPowModT (p : Prop) (a b m c : Nat) : Prop where
run' : p → Nat.mod (Nat.pow a b) m = c | structure | Tactic | [
"Mathlib.Tactic.NormNum.Pow"
] | Mathlib/Tactic/NormNum/PowMod.lean | IsNatPowModT | Represents and proves equalities of the form `a^b % m = c` for natural numbers. |
IsNatPowModT.run
(p : IsNatPowModT (Nat.mod (Nat.pow a (nat_lit 1)) m = Nat.mod a m) a b m c) :
Nat.mod (Nat.pow a b) m = c := p.run' (congr_arg (fun x => x % m) (Nat.pow_one a)) | theorem | Tactic | [
"Mathlib.Tactic.NormNum.Pow"
] | Mathlib/Tactic/NormNum/PowMod.lean | IsNatPowModT.run | null |
IsNatPowModT.trans (h1 : IsNatPowModT p a b m c)
(h2 : IsNatPowModT (Nat.mod (Nat.pow a b) m = c) a b' m c') : IsNatPowModT p a b' m c' :=
⟨h2.run' ∘ h1.run'⟩ | theorem | Tactic | [
"Mathlib.Tactic.NormNum.Pow"
] | Mathlib/Tactic/NormNum/PowMod.lean | IsNatPowModT.trans | null |
IsNatPowModT.bit0 :
IsNatPowModT (Nat.mod (Nat.pow a b) m = c) a (nat_lit 2 * b) m (Nat.mod (Nat.mul c c) m) :=
⟨fun h1 => by simp only [two_mul, Nat.pow_eq, pow_add, ← h1, Nat.mul_eq]; exact Nat.mul_mod ..⟩ | theorem | Tactic | [
"Mathlib.Tactic.NormNum.Pow"
] | Mathlib/Tactic/NormNum/PowMod.lean | IsNatPowModT.bit0 | null |
natPow_zero_natMod_zero : Nat.mod (Nat.pow a (nat_lit 0)) (nat_lit 0) = nat_lit 1 := by
simp [Nat.mod, Nat.modCore] | theorem | Tactic | [
"Mathlib.Tactic.NormNum.Pow"
] | Mathlib/Tactic/NormNum/PowMod.lean | natPow_zero_natMod_zero | null |
natPow_zero_natMod_one : Nat.mod (Nat.pow a (nat_lit 0)) (nat_lit 1) = nat_lit 0 := by
simp [Nat.mod, Nat.modCore_eq] | theorem | Tactic | [
"Mathlib.Tactic.NormNum.Pow"
] | Mathlib/Tactic/NormNum/PowMod.lean | natPow_zero_natMod_one | null |
natPow_zero_natMod_succ_succ :
Nat.mod (Nat.pow a (nat_lit 0)) (Nat.succ (Nat.succ m)) = nat_lit 1 := by
rfl | theorem | Tactic | [
"Mathlib.Tactic.NormNum.Pow"
] | Mathlib/Tactic/NormNum/PowMod.lean | natPow_zero_natMod_succ_succ | null |
natPow_one_natMod : Nat.mod (Nat.pow a (nat_lit 1)) m = Nat.mod a m := by rw [natPow_one] | theorem | Tactic | [
"Mathlib.Tactic.NormNum.Pow"
] | Mathlib/Tactic/NormNum/PowMod.lean | natPow_one_natMod | null |
IsNatPowModT.bit1 :
IsNatPowModT (Nat.mod (Nat.pow a b) m = c) a (nat_lit 2 * b + 1) m
(Nat.mod (Nat.mul c (Nat.mod (Nat.mul c a) m)) m) :=
⟨by
rintro rfl
change a ^ (2 * b + 1) % m = (a ^ b % m) * ((a ^ b % m * a) % m) % m
rw [pow_add, two_mul, pow_add, pow_one, Nat.mul_mod (a ^ b % m) a, Nat.m... | theorem | Tactic | [
"Mathlib.Tactic.NormNum.Pow"
] | Mathlib/Tactic/NormNum/PowMod.lean | IsNatPowModT.bit1 | null |
partial evalNatPowMod (a b m : Q(ℕ)) : (c : Q(ℕ)) × Q(Nat.mod (Nat.pow $a $b) $m = $c) :=
if b.natLit! = 0 then
haveI : $b =Q 0 := ⟨⟩
if m.natLit! = 0 then -- a ^ 0 % 0 = 1
haveI : $m =Q 0 := ⟨⟩
⟨q(nat_lit 1), q(natPow_zero_natMod_zero)⟩
else
have m' : Q(ℕ) := mkRawNatLit (m.natLit! - 1)... | def | Tactic | [
"Mathlib.Tactic.NormNum.Pow"
] | Mathlib/Tactic/NormNum/PowMod.lean | evalNatPowMod | Evaluates and proves `a^b % m` for natural numbers using fast modular exponentiation. |
not_prime_mul_of_ble (a b n : ℕ) (h : a * b = n) (h₁ : a.ble 1 = false)
(h₂ : b.ble 1 = false) : ¬ n.Prime :=
not_prime_of_mul_eq h (ble_eq_false.mp h₁).ne' (ble_eq_false.mp h₂).ne' | theorem | Tactic | [
"Mathlib.Tactic.NormNum.Basic",
"Mathlib.Data.Nat.Prime.Basic"
] | Mathlib/Tactic/NormNum/Prime.lean | not_prime_mul_of_ble | null |
deriveNotPrime (n d : ℕ) (en : Q(ℕ)) : Q(¬ Nat.Prime $en) := Id.run <| do
let d' : ℕ := n / d
let prf : Q($d * $d' = $en) := (q(Eq.refl $en) : Expr)
let r : Q(Nat.ble $d 1 = false) := (q(Eq.refl false) : Expr)
let r' : Q(Nat.ble $d' 1 = false) := (q(Eq.refl false) : Expr)
return q(not_prime_mul_of_ble _ _ _ $... | def | Tactic | [
"Mathlib.Tactic.NormNum.Basic",
"Mathlib.Data.Nat.Prime.Basic"
] | Mathlib/Tactic/NormNum/Prime.lean | deriveNotPrime | Produce a proof that `n` is not prime from a factor `1 < d < n`. `en` should be the expression
that is the natural number literal `n`. |
MinFacHelper (n k : ℕ) : Prop :=
2 < k ∧ k % 2 = 1 ∧ k ≤ minFac n | def | Tactic | [
"Mathlib.Tactic.NormNum.Basic",
"Mathlib.Data.Nat.Prime.Basic"
] | Mathlib/Tactic/NormNum/Prime.lean | MinFacHelper | A predicate representing partial progress in a proof of `minFac`. |
MinFacHelper.one_lt {n k : ℕ} (h : MinFacHelper n k) : 1 < n := by
have : 2 < minFac n := h.1.trans_le h.2.2
obtain rfl | h := n.eq_zero_or_pos
· contradiction
rcases (succ_le_of_lt h).eq_or_lt with rfl | h
· simp_all
exact h | theorem | Tactic | [
"Mathlib.Tactic.NormNum.Basic",
"Mathlib.Data.Nat.Prime.Basic"
] | Mathlib/Tactic/NormNum/Prime.lean | MinFacHelper.one_lt | null |
minFacHelper_0 (n : ℕ)
(h1 : Nat.ble (nat_lit 2) n = true) (h2 : nat_lit 1 = n % (nat_lit 2)) :
MinFacHelper n (nat_lit 3) := by
refine ⟨by simp, by simp, ?_⟩
refine (le_minFac'.mpr fun p hp hpn ↦ ?_).resolve_left (Nat.ne_of_gt (Nat.le_of_ble_eq_true h1))
rcases hp.eq_or_lt with rfl | h
· simp [(Nat.dvd... | theorem | Tactic | [
"Mathlib.Tactic.NormNum.Basic",
"Mathlib.Data.Nat.Prime.Basic"
] | Mathlib/Tactic/NormNum/Prime.lean | minFacHelper_0 | null |
minFacHelper_1 {n k k' : ℕ} (e : k + 2 = k') (h : MinFacHelper n k)
(np : minFac n ≠ k) : MinFacHelper n k' := by
rw [← e]
refine ⟨Nat.lt_add_right _ h.1, ?_, ?_⟩
· rw [add_mod, mod_self, add_zero, mod_mod]
exact h.2.1
rcases h.2.2.eq_or_lt with rfl | h2
· exact (np rfl).elim
rcases (succ_le_of_lt h... | theorem | Tactic | [
"Mathlib.Tactic.NormNum.Basic",
"Mathlib.Data.Nat.Prime.Basic"
] | Mathlib/Tactic/NormNum/Prime.lean | minFacHelper_1 | null |
minFacHelper_2 {n k k' : ℕ} (e : k + 2 = k') (nk : ¬ Nat.Prime k)
(h : MinFacHelper n k) : MinFacHelper n k' := by
refine minFacHelper_1 e h fun h2 ↦ ?_
rw [← h2] at nk
exact nk <| minFac_prime h.one_lt.ne' | theorem | Tactic | [
"Mathlib.Tactic.NormNum.Basic",
"Mathlib.Data.Nat.Prime.Basic"
] | Mathlib/Tactic/NormNum/Prime.lean | minFacHelper_2 | null |
minFacHelper_3 {n k k' : ℕ} (e : k + 2 = k') (nk : (n % k).beq 0 = false)
(h : MinFacHelper n k) : MinFacHelper n k' := by
refine minFacHelper_1 e h fun h2 ↦ ?_
have nk := Nat.ne_of_beq_eq_false nk
rw [← Nat.dvd_iff_mod_eq_zero, ← h2] at nk
exact nk <| minFac_dvd n | theorem | Tactic | [
"Mathlib.Tactic.NormNum.Basic",
"Mathlib.Data.Nat.Prime.Basic"
] | Mathlib/Tactic/NormNum/Prime.lean | minFacHelper_3 | null |
isNat_minFac_1 : {a : ℕ} → IsNat a (nat_lit 1) → IsNat a.minFac 1
| _, ⟨rfl⟩ => ⟨minFac_one⟩ | theorem | Tactic | [
"Mathlib.Tactic.NormNum.Basic",
"Mathlib.Data.Nat.Prime.Basic"
] | Mathlib/Tactic/NormNum/Prime.lean | isNat_minFac_1 | null |
isNat_minFac_2 : {a a' : ℕ} → IsNat a a' → a' % 2 = 0 → IsNat a.minFac 2
| a, _, ⟨rfl⟩, h => ⟨by rw [cast_ofNat, minFac_eq_two_iff, Nat.dvd_iff_mod_eq_zero, h]⟩ | theorem | Tactic | [
"Mathlib.Tactic.NormNum.Basic",
"Mathlib.Data.Nat.Prime.Basic"
] | Mathlib/Tactic/NormNum/Prime.lean | isNat_minFac_2 | null |
isNat_minFac_3 : {n n' : ℕ} → (k : ℕ) →
IsNat n n' → MinFacHelper n' k → nat_lit 0 = n' % k → IsNat (minFac n) k
| n, _, k, ⟨rfl⟩, h1, h2 => by
rw [eq_comm, ← Nat.dvd_iff_mod_eq_zero] at h2
exact ⟨le_antisymm (minFac_le_of_dvd h1.1.le h2) h1.2.2⟩ | theorem | Tactic | [
"Mathlib.Tactic.NormNum.Basic",
"Mathlib.Data.Nat.Prime.Basic"
] | Mathlib/Tactic/NormNum/Prime.lean | isNat_minFac_3 | null |
isNat_minFac_4 : {n n' k : ℕ} →
IsNat n n' → MinFacHelper n' k → (k * k).ble n' = false → IsNat (minFac n) n'
| n, _, k, ⟨rfl⟩, h1, h2 => by
refine ⟨(Nat.prime_def_minFac.mp ?_).2⟩
rw [Nat.prime_def_le_sqrt]
refine ⟨h1.one_lt, fun m hm hmn h2mn ↦ ?_⟩
exact lt_irrefl m <| calc
m ≤ sqrt n :=... | theorem | Tactic | [
"Mathlib.Tactic.NormNum.Basic",
"Mathlib.Data.Nat.Prime.Basic"
] | Mathlib/Tactic/NormNum/Prime.lean | isNat_minFac_4 | null |
@[norm_num Nat.minFac _] partial evalMinFac : NormNumExt where eval {_ _} e := do
let .app (.const ``Nat.minFac _) (n : Q(ℕ)) ← whnfR e | failure
let sℕ : Q(AddMonoidWithOne ℕ) := q(instAddMonoidWithOneNat)
let ⟨nn, pn⟩ ← deriveNat n sℕ
let n' := nn.natLit!
let rec aux (ek : Q(ℕ)) (prf : Q(MinFacHelper $nn $e... | def | Tactic | [
"Mathlib.Tactic.NormNum.Basic",
"Mathlib.Data.Nat.Prime.Basic"
] | Mathlib/Tactic/NormNum/Prime.lean | evalMinFac | The `norm_num` extension which identifies expressions of the form `minFac n`. |
isNat_prime_0 : {n : ℕ} → IsNat n (nat_lit 0) → ¬ n.Prime
| _, ⟨rfl⟩ => not_prime_zero | theorem | Tactic | [
"Mathlib.Tactic.NormNum.Basic",
"Mathlib.Data.Nat.Prime.Basic"
] | Mathlib/Tactic/NormNum/Prime.lean | isNat_prime_0 | null |
isNat_prime_1 : {n : ℕ} → IsNat n (nat_lit 1) → ¬ n.Prime
| _, ⟨rfl⟩ => not_prime_one | theorem | Tactic | [
"Mathlib.Tactic.NormNum.Basic",
"Mathlib.Data.Nat.Prime.Basic"
] | Mathlib/Tactic/NormNum/Prime.lean | isNat_prime_1 | null |
isNat_prime_2 : {n n' : ℕ} →
IsNat n n' → Nat.ble 2 n' = true → IsNat (minFac n') n' → n.Prime
| _, _, ⟨rfl⟩, h1, ⟨h2⟩ => prime_def_minFac.mpr ⟨ble_eq.mp h1, h2⟩ | theorem | Tactic | [
"Mathlib.Tactic.NormNum.Basic",
"Mathlib.Data.Nat.Prime.Basic"
] | Mathlib/Tactic/NormNum/Prime.lean | isNat_prime_2 | null |
isNat_not_prime {n n' : ℕ} (h : IsNat n n') : ¬n'.Prime → ¬n.Prime := isNat.natElim h | theorem | Tactic | [
"Mathlib.Tactic.NormNum.Basic",
"Mathlib.Data.Nat.Prime.Basic"
] | Mathlib/Tactic/NormNum/Prime.lean | isNat_not_prime | null |
@[norm_num Nat.Prime _] evalNatPrime : NormNumExt where eval {_ _} e := do
let .app (.const `Nat.Prime _) (n : Q(ℕ)) ← whnfR e | failure
let ⟨nn, pn⟩ ← deriveNat n _
let n' := nn.natLit!
let rec core : MetaM (Result q(Nat.Prime $n)) := do
match n' with
| 0 => haveI' : $nn =Q 0 := ⟨⟩; return .isFalse q(i... | def | Tactic | [
"Mathlib.Tactic.NormNum.Basic",
"Mathlib.Data.Nat.Prime.Basic"
] | Mathlib/Tactic/NormNum/Prime.lean | evalNatPrime | The `norm_num` extension which identifies expressions of the form `Nat.Prime n`. |
isNat_realSqrt {x : ℝ} {nx ny : ℕ} (h : IsNat x nx) (hy : ny * ny = nx) :
IsNat √x ny := ⟨by simp [h.out, ← hy]⟩ | lemma | Tactic | [
"Mathlib.Data.Real.Sqrt"
] | Mathlib/Tactic/NormNum/RealSqrt.lean | isNat_realSqrt | null |
isNat_nnrealSqrt {x : ℝ≥0} {nx ny : ℕ} (h : IsNat x nx) (hy : ny * ny = nx) :
IsNat (NNReal.sqrt x) ny := ⟨by simp [h.out, ← hy]⟩ | lemma | Tactic | [
"Mathlib.Data.Real.Sqrt"
] | Mathlib/Tactic/NormNum/RealSqrt.lean | isNat_nnrealSqrt | null |
isNNRat_nnrealSqrt_of_isNNRat {x : ℝ≥0} {n sn : ℕ} {d sd : ℕ} (hn : sn * sn = n)
(hd : sd * sd = d) (h : IsNNRat x n d) :
IsNNRat (NNReal.sqrt x) sn sd := by
obtain ⟨_, rfl⟩ := h
refine ⟨?_, ?out⟩
· apply invertibleOfNonzero
rw [← mul_self_ne_zero, ← Nat.cast_mul, hd]
exact Invertible.ne_zero _
... | lemma | Tactic | [
"Mathlib.Data.Real.Sqrt"
] | Mathlib/Tactic/NormNum/RealSqrt.lean | isNNRat_nnrealSqrt_of_isNNRat | null |
isNat_realSqrt_neg {x : ℝ} {nx : ℕ} (h : IsInt x (Int.negOfNat nx)) :
IsNat √x (nat_lit 0) := ⟨by simp [Real.sqrt_eq_zero', h.out]⟩ | lemma | Tactic | [
"Mathlib.Data.Real.Sqrt"
] | Mathlib/Tactic/NormNum/RealSqrt.lean | isNat_realSqrt_neg | null |
isNat_realSqrt_of_isRat_negOfNat {x : ℝ} {num : ℕ} {denom : ℕ}
(h : IsRat x (.negOfNat num) denom) : IsNat √x (nat_lit 0) := by
refine ⟨?_⟩
obtain ⟨inv, rfl⟩ := h
have h₁ : 0 ≤ (num : ℚ) * ⅟(denom : ℝ) :=
mul_nonneg (Nat.cast_nonneg' _) (invOf_nonneg.2 <| Nat.cast_nonneg' _)
simpa [Nat.cast_zero, Real.s... | lemma | Tactic | [
"Mathlib.Data.Real.Sqrt"
] | Mathlib/Tactic/NormNum/RealSqrt.lean | isNat_realSqrt_of_isRat_negOfNat | null |
isNNRat_realSqrt_of_isNNRat {x : ℝ} {n sn : ℕ} {d sd : ℕ} (hn : sn * sn = n)
(hd : sd * sd = d) (h : IsNNRat x n d) :
IsNNRat √x sn sd := by
obtain ⟨_, rfl⟩ := h
refine ⟨?_, ?out⟩
· apply invertibleOfNonzero
rw [← mul_self_ne_zero, ← Nat.cast_mul, hd]
exact Invertible.ne_zero _
· simp [← hn, ← h... | lemma | Tactic | [
"Mathlib.Data.Real.Sqrt"
] | Mathlib/Tactic/NormNum/RealSqrt.lean | isNNRat_realSqrt_of_isNNRat | null |
@[norm_num √_]
evalRealSqrt : NormNumExt where eval {u α} e := do
match u, α, e with
| 0, ~q(ℝ), ~q(√$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(ℕ) := mkRawNatLi... | def | Tactic | [
"Mathlib.Data.Real.Sqrt"
] | Mathlib/Tactic/NormNum/RealSqrt.lean | evalRealSqrt | `norm_num` extension that evaluates the function `Real.sqrt`. |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.