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 ⌀ |
|---|---|---|---|---|---|---|
isNat_lt_true [Semiring α] [PartialOrder α] [IsOrderedRing α] [CharZero α] :
{a b : α} → {a' b' : ℕ} →
IsNat a a' → IsNat b b' → Nat.ble b' a' = false → a < b
| _, _, _, _, ⟨rfl⟩, ⟨rfl⟩, h =>
Nat.cast_lt.2 <| ble_eq_false.1 h | theorem | Tactic | [
"Mathlib.Tactic.NormNum.Eq",
"Mathlib.Algebra.Order.Field.Defs",
"Mathlib.Algebra.Order.Invertible",
"Mathlib.Algebra.Order.Monoid.WithTop",
"Mathlib.Algebra.Order.Ring.Cast"
] | Mathlib/Tactic/NormNum/Ineq.lean | isNat_lt_true | null |
isNat_le_false [Semiring α] [PartialOrder α] [IsOrderedRing α] [CharZero α]
{a b : α} {a' b' : ℕ}
(ha : IsNat a a') (hb : IsNat b b') (h : Nat.ble a' b' = false) : ¬a ≤ b :=
not_le_of_gt (isNat_lt_true hb ha h) | theorem | Tactic | [
"Mathlib.Tactic.NormNum.Eq",
"Mathlib.Algebra.Order.Field.Defs",
"Mathlib.Algebra.Order.Invertible",
"Mathlib.Algebra.Order.Monoid.WithTop",
"Mathlib.Algebra.Order.Ring.Cast"
] | Mathlib/Tactic/NormNum/Ineq.lean | isNat_le_false | null |
isInt_le_true [Ring α] [PartialOrder α] [IsOrderedRing α] : {a b : α} → {a' b' : ℤ} →
IsInt a a' → IsInt b b' → decide (a' ≤ b') → a ≤ b
| _, _, _, _, ⟨rfl⟩, ⟨rfl⟩, h => Int.cast_mono <| of_decide_eq_true h | theorem | Tactic | [
"Mathlib.Tactic.NormNum.Eq",
"Mathlib.Algebra.Order.Field.Defs",
"Mathlib.Algebra.Order.Invertible",
"Mathlib.Algebra.Order.Monoid.WithTop",
"Mathlib.Algebra.Order.Ring.Cast"
] | Mathlib/Tactic/NormNum/Ineq.lean | isInt_le_true | null |
isInt_lt_true [Ring α] [PartialOrder α] [IsOrderedRing α] [Nontrivial α] :
{a b : α} → {a' b' : ℤ} →
IsInt a a' → IsInt b b' → decide (a' < b') → a < b
| _, _, _, _, ⟨rfl⟩, ⟨rfl⟩, h => Int.cast_lt.2 <| of_decide_eq_true h | theorem | Tactic | [
"Mathlib.Tactic.NormNum.Eq",
"Mathlib.Algebra.Order.Field.Defs",
"Mathlib.Algebra.Order.Invertible",
"Mathlib.Algebra.Order.Monoid.WithTop",
"Mathlib.Algebra.Order.Ring.Cast"
] | Mathlib/Tactic/NormNum/Ineq.lean | isInt_lt_true | null |
isInt_le_false [Ring α] [PartialOrder α] [IsOrderedRing α] [Nontrivial α]
{a b : α} {a' b' : ℤ}
(ha : IsInt a a') (hb : IsInt b b') (h : decide (b' < a')) : ¬a ≤ b :=
not_le_of_gt (isInt_lt_true hb ha h) | theorem | Tactic | [
"Mathlib.Tactic.NormNum.Eq",
"Mathlib.Algebra.Order.Field.Defs",
"Mathlib.Algebra.Order.Invertible",
"Mathlib.Algebra.Order.Monoid.WithTop",
"Mathlib.Algebra.Order.Ring.Cast"
] | Mathlib/Tactic/NormNum/Ineq.lean | isInt_le_false | null |
isInt_lt_false [Ring α] [PartialOrder α] [IsOrderedRing α] {a b : α} {a' b' : ℤ}
(ha : IsInt a a') (hb : IsInt b b') (h : decide (b' ≤ a')) : ¬a < b :=
not_lt_of_ge (isInt_le_true hb ha h)
attribute [local instance] monadLiftOptionMetaM in | theorem | Tactic | [
"Mathlib.Tactic.NormNum.Eq",
"Mathlib.Algebra.Order.Field.Defs",
"Mathlib.Algebra.Order.Invertible",
"Mathlib.Algebra.Order.Monoid.WithTop",
"Mathlib.Algebra.Order.Ring.Cast"
] | Mathlib/Tactic/NormNum/Ineq.lean | isInt_lt_false | null |
@[norm_num _ ≤ _] evalLE : NormNumExt where eval {v β} e := do
haveI' : v =QL 0 := ⟨⟩; haveI' : $β =Q Prop := ⟨⟩
let .app (.app f a) b ← whnfR e | failure
let ⟨u, α, a⟩ ← inferTypeQ' a
have b : Q($α) := b
let ra ← derive a; let rb ← derive b
let lα ← synthInstanceQ q(LE $α)
guard <|← withNewMCtxDepth <| isDefEq f q(LE.le (α := $α))
core lα ra rb
where
/-- Identify (as `true` or `false`) expressions of the form `a ≤ b`, where `a` and `b` are numeric
expressions whose evaluations to `NormNum.Result` have already been computed. -/
core {u : Level} {α : Q(Type u)} (lα : Q(LE $α)) {a b : Q($α)}
(ra : NormNum.Result a) (rb : NormNum.Result b) : MetaM (NormNum.Result q($a ≤ $b)) := do
let e := q($a ≤ $b)
let rec intArm : MetaM (Result e) := do
let ⟨_ir, _, _i⟩ ← inferOrderedRing α
haveI' : $e =Q ($a ≤ $b) := ⟨⟩
let ⟨za, na, pa⟩ ← ra.toInt q($_ir)
let ⟨zb, nb, pb⟩ ← rb.toInt q($_ir)
assumeInstancesCommute
if decide (za ≤ zb) then
let r : Q(decide ($na ≤ $nb) = true) := (q(Eq.refl true) : Expr)
return .isTrue q(isInt_le_true $pa $pb $r)
else if let .some _i ← trySynthInstanceQ q(Nontrivial $α) then
let r : Q(decide ($nb < $na) = true) := (q(Eq.refl true) : Expr)
return .isFalse q(isInt_le_false $pa $pb $r)
else
failure
let rec ratArm : MetaM (Result e) := do
let ⟨_if, _, _i⟩ ← inferLinearOrderedField α
haveI' : $e =Q ($a ≤ $b) := ⟨⟩
let ⟨qa, na, da, pa⟩ ← ra.toRat' q(Field.toDivisionRing)
let ⟨qb, nb, db, pb⟩ ← rb.toRat' q(Field.toDivisionRing)
assumeInstancesCommute
if decide (qa ≤ qb) then
let r : Q(decide ($na * $db ≤ $nb * $da) = true) := (q(Eq.refl true) : Expr)
return (.isTrue q(isRat_le_true $pa $pb $r))
else
let _i : Q(Nontrivial $α) := q(IsStrictOrderedRing.toNontrivial)
let r : Q(decide ($nb * $da < $na * $db) = true) := (q(Eq.refl true) : Expr)
return .isFalse q(isRat_le_false $pa $pb $r)
match ra, rb with
| .isBool .., _ | _, .isBool .. => failure
| .isNNRat _ .., _ | _, .isNNRat _ .. => ratArm
| .isNegNNRat _ .., _ | _, .isNegNNRat _ .. => ratArm
| .isNegNat _ .., _ | _, .isNegNat _ .. => intArm
| .isNat ra na pa, .isNat rb nb pb =>
let ⟨_, _, _i⟩ ← inferOrderedSemiring α
haveI' : $ra =Q by clear! $ra $rb; infer_instance := ⟨⟩
haveI' : $rb =Q by clear! $ra $rb; infer_instance := ⟨⟩
... | def | Tactic | [
"Mathlib.Tactic.NormNum.Eq",
"Mathlib.Algebra.Order.Field.Defs",
"Mathlib.Algebra.Order.Invertible",
"Mathlib.Algebra.Order.Monoid.WithTop",
"Mathlib.Algebra.Order.Ring.Cast"
] | Mathlib/Tactic/NormNum/Ineq.lean | evalLE | The `norm_num` extension which identifies expressions of the form `a ≤ b`,
such that `norm_num` successfully recognises both `a` and `b`. |
@[norm_num _ < _] evalLT : NormNumExt where eval {v β} e := do
haveI' : v =QL 0 := ⟨⟩; haveI' : $β =Q Prop := ⟨⟩
let .app (.app f a) b ← whnfR e | failure
let ⟨u, α, a⟩ ← inferTypeQ' a
have b : Q($α) := b
let ra ← derive a; let rb ← derive b
let lα ← synthInstanceQ q(LT $α)
guard <|← withNewMCtxDepth <| isDefEq f q(LT.lt (α := $α))
core lα ra rb
where
/-- Identify (as `true` or `false`) expressions of the form `a < b`, where `a` and `b` are numeric
expressions whose evaluations to `NormNum.Result` have already been computed. -/
core {u : Level} {α : Q(Type u)} (lα : Q(LT $α)) {a b : Q($α)}
(ra : NormNum.Result a) (rb : NormNum.Result b) : MetaM (NormNum.Result q($a < $b)) := do
let e := q($a < $b)
let rec intArm : MetaM (Result e) := do
let ⟨_ir, _, _i⟩ ← inferOrderedRing α
haveI' : $e =Q ($a < $b) := ⟨⟩
let ⟨za, na, pa⟩ ← ra.toInt q($_ir)
let ⟨zb, nb, pb⟩ ← rb.toInt q($_ir)
assumeInstancesCommute
if za < zb then
if let .some _i ← trySynthInstanceQ q(Nontrivial $α) then
let r : Q(decide ($na < $nb) = true) := (q(Eq.refl true) : Expr)
return .isTrue q(isInt_lt_true $pa $pb $r)
else
failure
else
let r : Q(decide ($nb ≤ $na) = true) := (q(Eq.refl true) : Expr)
return .isFalse q(isInt_lt_false $pa $pb $r)
let rec nnratArm : MetaM (Result e) := do
/-
NOTE: after the ordered algebra refactor, this is not true anymore,
so there may be a better typeclass
-/
let ⟨_, _, _⟩ ← inferLinearOrderedSemifield α
assumeInstancesCommute
haveI' : $e =Q ($a < $b) := ⟨⟩
let ⟨qa, na, da, pa⟩ ← ra.toNNRat' q(Semifield.toDivisionSemiring)
let ⟨qb, nb, db, pb⟩ ← rb.toNNRat' q(Semifield.toDivisionSemiring)
if qa < qb then
let r : Q(decide ($na * $db < $nb * $da) = true) := (q(Eq.refl true) : Expr)
return .isTrue q(isNNRat_lt_true $pa $pb $r)
else
let r : Q(decide ($nb * $da ≤ $na * $db) = true) := (q(Eq.refl true) : Expr)
return .isFalse q(isNNRat_lt_false $pa $pb $r)
let rec ratArm : MetaM (Result e) := do
/-
NOTE: after the ordered algebra refactor, this is not true anymore,
so there may be a better typeclass
-/
... | def | Tactic | [
"Mathlib.Tactic.NormNum.Eq",
"Mathlib.Algebra.Order.Field.Defs",
"Mathlib.Algebra.Order.Invertible",
"Mathlib.Algebra.Order.Monoid.WithTop",
"Mathlib.Algebra.Order.Ring.Cast"
] | Mathlib/Tactic/NormNum/Ineq.lean | evalLT | The `norm_num` extension which identifies expressions of the form `a < b`,
such that `norm_num` successfully recognises both `a` and `b`. |
inferCharZeroOfRing {α : Q(Type u)} (_i : Q(Ring $α) := by with_reducible assumption) :
MetaM Q(CharZero $α) :=
return ← synthInstanceQ q(CharZero $α) <|>
throwError "not a characteristic zero ring" | def | Tactic | [
"Mathlib.Tactic.NormNum.Basic",
"Mathlib.Data.Rat.Cast.CharZero",
"Mathlib.Algebra.Field.Basic"
] | Mathlib/Tactic/NormNum/Inv.lean | inferCharZeroOfRing | Helper function to synthesize a typed `CharZero α` expression given `Ring α`. |
inferCharZeroOfRing? {α : Q(Type u)} (_i : Q(Ring $α) := by with_reducible assumption) :
MetaM (Option Q(CharZero $α)) :=
return (← trySynthInstanceQ q(CharZero $α)).toOption | def | Tactic | [
"Mathlib.Tactic.NormNum.Basic",
"Mathlib.Data.Rat.Cast.CharZero",
"Mathlib.Algebra.Field.Basic"
] | Mathlib/Tactic/NormNum/Inv.lean | inferCharZeroOfRing | Helper function to synthesize a typed `CharZero α` expression given `Ring α`, if it exists. |
inferCharZeroOfAddMonoidWithOne {α : Q(Type u)}
(_i : Q(AddMonoidWithOne $α) := by with_reducible assumption) : MetaM Q(CharZero $α) :=
return ← synthInstanceQ q(CharZero $α) <|>
throwError "not a characteristic zero AddMonoidWithOne" | def | Tactic | [
"Mathlib.Tactic.NormNum.Basic",
"Mathlib.Data.Rat.Cast.CharZero",
"Mathlib.Algebra.Field.Basic"
] | Mathlib/Tactic/NormNum/Inv.lean | inferCharZeroOfAddMonoidWithOne | Helper function to synthesize a typed `CharZero α` expression given `AddMonoidWithOne α`. |
inferCharZeroOfAddMonoidWithOne? {α : Q(Type u)}
(_i : Q(AddMonoidWithOne $α) := by with_reducible assumption) :
MetaM (Option Q(CharZero $α)) :=
return (← trySynthInstanceQ q(CharZero $α)).toOption | def | Tactic | [
"Mathlib.Tactic.NormNum.Basic",
"Mathlib.Data.Rat.Cast.CharZero",
"Mathlib.Algebra.Field.Basic"
] | Mathlib/Tactic/NormNum/Inv.lean | inferCharZeroOfAddMonoidWithOne | Helper function to synthesize a typed `CharZero α` expression given `AddMonoidWithOne α`, if it
exists. |
inferCharZeroOfDivisionRing {α : Q(Type u)}
(_i : Q(DivisionRing $α) := by with_reducible assumption) : MetaM Q(CharZero $α) :=
return ← synthInstanceQ q(CharZero $α) <|>
throwError "not a characteristic zero division ring" | def | Tactic | [
"Mathlib.Tactic.NormNum.Basic",
"Mathlib.Data.Rat.Cast.CharZero",
"Mathlib.Algebra.Field.Basic"
] | Mathlib/Tactic/NormNum/Inv.lean | inferCharZeroOfDivisionRing | Helper function to synthesize a typed `CharZero α` expression given `DivisionRing α`. |
inferCharZeroOfDivisionSemiring? {α : Q(Type u)}
(_i : Q(DivisionSemiring $α) := by with_reducible assumption) : MetaM (Option Q(CharZero $α)) :=
return (← trySynthInstanceQ (q(CharZero $α) : Q(Prop))).toOption | def | Tactic | [
"Mathlib.Tactic.NormNum.Basic",
"Mathlib.Data.Rat.Cast.CharZero",
"Mathlib.Algebra.Field.Basic"
] | Mathlib/Tactic/NormNum/Inv.lean | inferCharZeroOfDivisionSemiring | Helper function to synthesize a typed `CharZero α` expression given `Divisionsemiring α`, if it
exists. |
inferCharZeroOfDivisionRing? {α : Q(Type u)}
(_i : Q(DivisionRing $α) := by with_reducible assumption) : MetaM (Option Q(CharZero $α)) :=
return (← trySynthInstanceQ q(CharZero $α)).toOption | def | Tactic | [
"Mathlib.Tactic.NormNum.Basic",
"Mathlib.Data.Rat.Cast.CharZero",
"Mathlib.Algebra.Field.Basic"
] | Mathlib/Tactic/NormNum/Inv.lean | inferCharZeroOfDivisionRing | Helper function to synthesize a typed `CharZero α` expression given `DivisionRing α`, if it
exists. |
isRat_mkRat : {a na n : ℤ} → {b nb d : ℕ} → IsInt a na → IsNat b nb →
IsRat (na / nb : ℚ) n d → IsRat (mkRat a b) n d
| _, _, _, _, _, _, ⟨rfl⟩, ⟨rfl⟩, ⟨_, h⟩ => by rw [Rat.mkRat_eq_div]; exact ⟨_, h⟩
attribute [local instance] monadLiftOptionMetaM in | theorem | Tactic | [
"Mathlib.Tactic.NormNum.Basic",
"Mathlib.Data.Rat.Cast.CharZero",
"Mathlib.Algebra.Field.Basic"
] | Mathlib/Tactic/NormNum/Inv.lean | isRat_mkRat | null |
@[norm_num mkRat _ _]
evalMkRat : NormNumExt where eval {u α} (e : Q(ℚ)) : MetaM (Result e) := do
let .app (.app (.const ``mkRat _) (a : Q(ℤ))) (b : Q(ℕ)) ← whnfR e | failure
haveI' : $e =Q mkRat $a $b := ⟨⟩
let ra ← derive a
let some ⟨_, na, pa⟩ := ra.toInt (q(Int.instRing) : Q(Ring Int)) | failure
let ⟨nb, pb⟩ ← deriveNat q($b) q(AddCommMonoidWithOne.toAddMonoidWithOne)
let rab ← derive q($na / $nb : Rat)
let ⟨q, n, d, p⟩ ← rab.toRat' q(Rat.instDivisionRing)
return .isRat _ q n d q(isRat_mkRat $pa $pb $p) | def | Tactic | [
"Mathlib.Tactic.NormNum.Basic",
"Mathlib.Data.Rat.Cast.CharZero",
"Mathlib.Algebra.Field.Basic"
] | Mathlib/Tactic/NormNum/Inv.lean | evalMkRat | The `norm_num` extension which identifies expressions of the form `mkRat a b`,
such that `norm_num` successfully recognises both `a` and `b`, and returns `a / b`. |
isNat_ratCast {R : Type*} [DivisionRing R] : {q : ℚ} → {n : ℕ} →
IsNat q n → IsNat (q : R) n
| _, _, ⟨rfl⟩ => ⟨by simp⟩ | theorem | Tactic | [
"Mathlib.Tactic.NormNum.Basic",
"Mathlib.Data.Rat.Cast.CharZero",
"Mathlib.Algebra.Field.Basic"
] | Mathlib/Tactic/NormNum/Inv.lean | isNat_ratCast | null |
isInt_ratCast {R : Type*} [DivisionRing R] : {q : ℚ} → {n : ℤ} →
IsInt q n → IsInt (q : R) n
| _, _, ⟨rfl⟩ => ⟨by simp⟩ | theorem | Tactic | [
"Mathlib.Tactic.NormNum.Basic",
"Mathlib.Data.Rat.Cast.CharZero",
"Mathlib.Algebra.Field.Basic"
] | Mathlib/Tactic/NormNum/Inv.lean | isInt_ratCast | null |
isNNRat_ratCast {R : Type*} [DivisionRing R] [CharZero R] : {q : ℚ} → {n : ℕ} → {d : ℕ} →
IsNNRat q n d → IsNNRat (q : R) n d
| _, _, _, ⟨⟨qi,_,_⟩, rfl⟩ => ⟨⟨qi, by norm_cast, by norm_cast⟩, by simp only; norm_cast⟩ | theorem | Tactic | [
"Mathlib.Tactic.NormNum.Basic",
"Mathlib.Data.Rat.Cast.CharZero",
"Mathlib.Algebra.Field.Basic"
] | Mathlib/Tactic/NormNum/Inv.lean | isNNRat_ratCast | null |
isRat_ratCast {R : Type*} [DivisionRing R] [CharZero R] : {q : ℚ} → {n : ℤ} → {d : ℕ} →
IsRat q n d → IsRat (q : R) n d
| _, _, _, ⟨⟨qi,_,_⟩, rfl⟩ => ⟨⟨qi, by norm_cast, by norm_cast⟩, by simp only; norm_cast⟩ | theorem | Tactic | [
"Mathlib.Tactic.NormNum.Basic",
"Mathlib.Data.Rat.Cast.CharZero",
"Mathlib.Algebra.Field.Basic"
] | Mathlib/Tactic/NormNum/Inv.lean | isRat_ratCast | null |
@[norm_num Rat.cast _, RatCast.ratCast _] evalRatCast : NormNumExt where eval {u α} e := do
let dα ← inferDivisionRing α
let .app r (a : Q(ℚ)) ← whnfR e | failure
guard <|← withNewMCtxDepth <| isDefEq r q(Rat.cast (K := $α))
let r ← derive q($a)
haveI' : $e =Q Rat.cast $a := ⟨⟩
match r with
| .isNat _ na pa =>
assumeInstancesCommute
return .isNat _ na q(isNat_ratCast $pa)
| .isNegNat _ na pa =>
assumeInstancesCommute
return .isNegNat _ na q(isInt_ratCast $pa)
| .isNNRat _ qa na da pa =>
assumeInstancesCommute
let i ← inferCharZeroOfDivisionRing dα
return .isNNRat q(inferInstance) qa na da q(isNNRat_ratCast $pa)
| .isNegNNRat _ qa na da pa =>
assumeInstancesCommute
let i ← inferCharZeroOfDivisionRing dα
return .isNegNNRat dα qa na da q(isRat_ratCast $pa)
| _ => failure | def | Tactic | [
"Mathlib.Tactic.NormNum.Basic",
"Mathlib.Data.Rat.Cast.CharZero",
"Mathlib.Algebra.Field.Basic"
] | Mathlib/Tactic/NormNum/Inv.lean | evalRatCast | The `norm_num` extension which identifies an expression `RatCast.ratCast q` where `norm_num`
recognizes `q`, returning the cast of `q`. |
isNNRat_inv_pos {α} [DivisionSemiring α] [CharZero α] {a : α} {n d : ℕ} :
IsNNRat a (Nat.succ n) d → IsNNRat a⁻¹ d (Nat.succ n) := by
rintro ⟨_, rfl⟩
have := invertibleOfNonzero (α := α) (Nat.cast_ne_zero.2 (Nat.succ_ne_zero n))
exact ⟨this, by simp⟩ | theorem | Tactic | [
"Mathlib.Tactic.NormNum.Basic",
"Mathlib.Data.Rat.Cast.CharZero",
"Mathlib.Algebra.Field.Basic"
] | Mathlib/Tactic/NormNum/Inv.lean | isNNRat_inv_pos | null |
isRat_inv_pos {α} [DivisionRing α] [CharZero α] {a : α} {n d : ℕ} :
IsRat a (.ofNat (Nat.succ n)) d → IsRat a⁻¹ (.ofNat d) (Nat.succ n) := by
rintro ⟨_, rfl⟩
have := invertibleOfNonzero (α := α) (Nat.cast_ne_zero.2 (Nat.succ_ne_zero n))
exact ⟨this, by simp⟩ | theorem | Tactic | [
"Mathlib.Tactic.NormNum.Basic",
"Mathlib.Data.Rat.Cast.CharZero",
"Mathlib.Algebra.Field.Basic"
] | Mathlib/Tactic/NormNum/Inv.lean | isRat_inv_pos | null |
isNat_inv_one {α} [DivisionSemiring α] : {a : α} →
IsNat a (nat_lit 1) → IsNat a⁻¹ (nat_lit 1)
| _, ⟨rfl⟩ => ⟨by simp⟩ | theorem | Tactic | [
"Mathlib.Tactic.NormNum.Basic",
"Mathlib.Data.Rat.Cast.CharZero",
"Mathlib.Algebra.Field.Basic"
] | Mathlib/Tactic/NormNum/Inv.lean | isNat_inv_one | null |
isNat_inv_zero {α} [DivisionSemiring α] : {a : α} →
IsNat a (nat_lit 0) → IsNat a⁻¹ (nat_lit 0)
| _, ⟨rfl⟩ => ⟨by simp⟩ | theorem | Tactic | [
"Mathlib.Tactic.NormNum.Basic",
"Mathlib.Data.Rat.Cast.CharZero",
"Mathlib.Algebra.Field.Basic"
] | Mathlib/Tactic/NormNum/Inv.lean | isNat_inv_zero | null |
isInt_inv_neg_one {α} [DivisionRing α] : {a : α} →
IsInt a (.negOfNat (nat_lit 1)) → IsInt a⁻¹ (.negOfNat (nat_lit 1))
| _, ⟨rfl⟩ => ⟨by simp⟩ | theorem | Tactic | [
"Mathlib.Tactic.NormNum.Basic",
"Mathlib.Data.Rat.Cast.CharZero",
"Mathlib.Algebra.Field.Basic"
] | Mathlib/Tactic/NormNum/Inv.lean | isInt_inv_neg_one | null |
isRat_inv_neg {α} [DivisionRing α] [CharZero α] {a : α} {n d : ℕ} :
IsRat a (.negOfNat (Nat.succ n)) d → IsRat a⁻¹ (.negOfNat d) (Nat.succ n) := by
rintro ⟨_, rfl⟩
simp only [Int.negOfNat_eq]
have := invertibleOfNonzero (α := α) (Nat.cast_ne_zero.2 (Nat.succ_ne_zero n))
generalize Nat.succ n = n at *
use this; simp only [Int.ofNat_eq_coe, Int.cast_neg,
Int.cast_natCast, invOf_eq_inv, inv_neg, neg_mul, mul_inv_rev, inv_inv]
open Lean
attribute [local instance] monadLiftOptionMetaM in | theorem | Tactic | [
"Mathlib.Tactic.NormNum.Basic",
"Mathlib.Data.Rat.Cast.CharZero",
"Mathlib.Algebra.Field.Basic"
] | Mathlib/Tactic/NormNum/Inv.lean | isRat_inv_neg | null |
Result.inv {u : Level} {α : Q(Type u)} {a : Q($α)} (ra : Result a)
(dsα : Q(DivisionSemiring $α)) (czα? : Option Q(CharZero $α)) :
MetaM (Result q($a⁻¹)) := do
if let .some ⟨qa, na, da, pa⟩ := ra.toNNRat' dsα then
let qb := qa⁻¹
if qa > 0 then
if let some _i := czα? then
have lit2 : Q(ℕ) := mkRawNatLit (na.natLit! - 1)
haveI : $na =Q ($lit2).succ := ⟨⟩
return .isNNRat' dsα qb q($da) q($na) q(isNNRat_inv_pos $pa)
else
guard (qa = 1)
let .isNat inst n pa := ra | failure
haveI' : $n =Q nat_lit 1 := ⟨⟩
assumeInstancesCommute
return .isNat inst n q(isNat_inv_one $pa)
else
let .isNat inst n pa := ra | failure
haveI' : $n =Q nat_lit 0 := ⟨⟩
assumeInstancesCommute
return .isNat inst n q(isNat_inv_zero $pa)
else
let dα ← inferDivisionRing α
assertInstancesCommute
let ⟨qa, na, da, pa⟩ ← ra.toRat' dα
let qb := qa⁻¹
guard <| qa < 0
if let some _i := czα? then
have lit : Q(ℕ) := na.appArg!
haveI : $na =Q Int.negOfNat $lit := ⟨⟩
have lit2 : Q(ℕ) := mkRawNatLit (lit.natLit! - 1)
haveI : $lit =Q ($lit2).succ := ⟨⟩
return .isRat dα qb q(.negOfNat $da) lit q(isRat_inv_neg $pa)
else
guard (qa = -1)
let .isNegNat inst n pa := ra | failure
haveI' : $n =Q nat_lit 1 := ⟨⟩
assumeInstancesCommute
return .isNegNat inst n q(isInt_inv_neg_one $pa) | def | Tactic | [
"Mathlib.Tactic.NormNum.Basic",
"Mathlib.Data.Rat.Cast.CharZero",
"Mathlib.Algebra.Field.Basic"
] | Mathlib/Tactic/NormNum/Inv.lean | Result.inv | The result of inverting a norm_num result. |
@[norm_num _⁻¹] evalInv : NormNumExt where eval {u α} e := do
let .app f (a : Q($α)) ← whnfR e | failure
let ra ← derive a
let dsα ← inferDivisionSemiring α
guard <| ← withNewMCtxDepth <| isDefEq f q(Inv.inv (α := $α))
haveI' : $e =Q $a⁻¹ := ⟨⟩
assumeInstancesCommute
ra.inv q($dsα) (← inferCharZeroOfDivisionSemiring? dsα) | def | Tactic | [
"Mathlib.Tactic.NormNum.Basic",
"Mathlib.Data.Rat.Cast.CharZero",
"Mathlib.Algebra.Field.Basic"
] | Mathlib/Tactic/NormNum/Inv.lean | evalInv | The `norm_num` extension which identifies expressions of the form `a⁻¹`,
such that `norm_num` successfully recognises `a`. |
private irrational_rpow_rat_of_not_power {q : ℚ} {a b : ℕ}
(h : ∀ p : ℚ, q ^ a ≠ p ^ b) (hb : 0 < b) (hq : 0 ≤ q) :
Irrational (Real.rpow q (a / b : ℚ)) := by
simp only [Irrational, Rat.cast_div, Rat.cast_natCast, Real.rpow_eq_pow, Set.mem_range,
not_exists]
intro x hx
absurd h x
rify
rw [hx, ← Real.rpow_mul_natCast, div_mul_cancel₀] <;> simp
· cutsat
· assumption | theorem | Tactic | [
"Mathlib.Analysis.SpecialFunctions.Pow.Real",
"Mathlib.Data.Real.Irrational",
"Mathlib.Tactic.NormNum.GCD",
"Mathlib.Tactic.Rify"
] | Mathlib/Tactic/NormNum/Irrational.lean | irrational_rpow_rat_of_not_power | null |
private not_power_nat_pow {n p q : ℕ}
(h_coprime : p.Coprime q)
(hq : 0 < q)
(h : ∀ m, n ≠ m ^ q) (m : ℕ) :
n ^ p ≠ m ^ q := by
by_cases hn : n = 0
· specialize h 0
simp [hn, zero_pow hq.ne.symm] at h
contrapose! h
apply_fun Nat.factorization at h
simp only [Nat.factorization_pow] at h
suffices ∃ f : ℕ →₀ ℕ, n.factorization = q • f by
obtain ⟨f, hf⟩ := this
have : f = (f.prod fun x1 x2 => x1 ^ x2).factorization := by
rw [Nat.prod_pow_factorization_eq_self]
intro z hz
apply_fun Finsupp.support at hf
rw [Finsupp.support_smul_eq (by cutsat)] at hf
rw [← hf] at hz
exact Nat.prime_of_mem_primeFactors hz
have hf0 : f 0 = 0 := by
apply_fun (· 0) at hf
simp only [Nat.factorization_zero_right, Finsupp.coe_smul, Pi.smul_apply, smul_eq_mul,
zero_eq_mul] at hf
cases hf
· cutsat
· assumption
rw [this, ← Nat.factorization_pow] at hf
apply Nat.factorization_inj at hf
· use f.prod (· ^ ·)
· exact hn
· simp only [ne_eq, Set.mem_setOf_eq, pow_eq_zero_iff', Finsupp.prod_eq_zero_iff,
Finsupp.mem_support_iff, existsAndEq, true_and, and_self, not_and, Decidable.not_not]
tauto
use n.factorization.mapRange (fun e ↦ e / q) (by simp)
ext z
apply_fun (· z) at h
simp only [Finsupp.coe_smul, Pi.smul_apply, smul_eq_mul, Finsupp.mapRange_apply] at h ⊢
rw [Nat.mul_div_cancel']
apply Nat.Coprime.dvd_of_dvd_mul_left _ ⟨_, h⟩
rwa [Nat.coprime_comm] | theorem | Tactic | [
"Mathlib.Analysis.SpecialFunctions.Pow.Real",
"Mathlib.Data.Real.Irrational",
"Mathlib.Tactic.NormNum.GCD",
"Mathlib.Tactic.Rify"
] | Mathlib/Tactic/NormNum/Irrational.lean | not_power_nat_pow | null |
private not_power_nat_of_bounds {n k d : ℕ}
(h_left : k ^ d < n) (h_right : n < (k + 1) ^ d) {m : ℕ} :
n ≠ m ^ d := by
intro h
rw [h] at h_left h_right
have : k < m := lt_of_pow_lt_pow_left' d h_left
have : m < k + 1 := lt_of_pow_lt_pow_left' d h_right
cutsat | theorem | Tactic | [
"Mathlib.Analysis.SpecialFunctions.Pow.Real",
"Mathlib.Data.Real.Irrational",
"Mathlib.Tactic.NormNum.GCD",
"Mathlib.Tactic.Rify"
] | Mathlib/Tactic/NormNum/Irrational.lean | not_power_nat_of_bounds | null |
private not_power_nat_pow_of_bounds {n k p q : ℕ}
(hq : 0 < q) (h_coprime : p.Coprime q) (h_left : k ^ q < n) (h_right : n < (k + 1) ^ q)
(m : ℕ) :
n ^ p ≠ m ^ q := by
apply not_power_nat_pow h_coprime hq
intro m
apply not_power_nat_of_bounds h_left h_right | theorem | Tactic | [
"Mathlib.Analysis.SpecialFunctions.Pow.Real",
"Mathlib.Data.Real.Irrational",
"Mathlib.Tactic.NormNum.GCD",
"Mathlib.Tactic.Rify"
] | Mathlib/Tactic/NormNum/Irrational.lean | not_power_nat_pow_of_bounds | null |
private eq_of_mul_eq_mul_of_coprime_aux {a b x y : ℕ} (hab : a.Coprime b)
(h : a * x = b * y) : a ∣ y := Nat.Coprime.dvd_of_dvd_mul_left hab (Dvd.intro x h) | lemma | Tactic | [
"Mathlib.Analysis.SpecialFunctions.Pow.Real",
"Mathlib.Data.Real.Irrational",
"Mathlib.Tactic.NormNum.GCD",
"Mathlib.Tactic.Rify"
] | Mathlib/Tactic/NormNum/Irrational.lean | eq_of_mul_eq_mul_of_coprime_aux | null |
private eq_of_mul_eq_mul_of_coprime {a b x y : ℕ} (hab : a.Coprime b) (hxy : x.Coprime y)
(h : a * x = b * y) : a = y := by
apply Nat.dvd_antisymm
· exact eq_of_mul_eq_mul_of_coprime_aux hab h
· exact eq_of_mul_eq_mul_of_coprime_aux (x := b) hxy.symm (by rw [mul_comm, ← h, mul_comm]) | lemma | Tactic | [
"Mathlib.Analysis.SpecialFunctions.Pow.Real",
"Mathlib.Data.Real.Irrational",
"Mathlib.Tactic.NormNum.GCD",
"Mathlib.Tactic.Rify"
] | Mathlib/Tactic/NormNum/Irrational.lean | eq_of_mul_eq_mul_of_coprime | null |
private not_power_rat_of_num_aux {a b d : ℕ}
(h_coprime : a.Coprime b) (ha : ∀ x, a ≠ x ^ d) {q : ℚ} (hq : 0 ≤ q) :
(a / b : ℚ) ≠ q ^ d := by
by_cases hb_zero : b = 0
· subst hb_zero
contrapose! ha
simp only [Nat.coprime_zero_right] at h_coprime
subst h_coprime
use 1
simp
by_contra! h
rw [← Rat.num_div_den q] at h
set x' := q.num
set y := q.den
obtain ⟨x, hx'⟩ := Int.eq_ofNat_of_zero_le (show 0 ≤ x' by rwa [Rat.num_nonneg])
rw [hx'] at h
specialize ha x
simp only [Int.cast_natCast, div_pow] at h
rw [div_eq_div_iff] at h
rotate_left
· simpa
· simp [y]
replace h : a * y ^ d = x ^ d * b := by
qify
assumption
apply ha
conv at h => rhs; rw [mul_comm]
apply eq_of_mul_eq_mul_of_coprime h_coprime _ h
apply Nat.Coprime.pow_left
apply Nat.Coprime.pow_right
apply Nat.Coprime.symm
simpa [hx'] using (show x'.natAbs.Coprime y from Rat.reduced q) | theorem | Tactic | [
"Mathlib.Analysis.SpecialFunctions.Pow.Real",
"Mathlib.Data.Real.Irrational",
"Mathlib.Tactic.NormNum.GCD",
"Mathlib.Tactic.Rify"
] | Mathlib/Tactic/NormNum/Irrational.lean | not_power_rat_of_num_aux | Weaker version of `not_power_rat_of_num` with extra `q ≥ 0` assumption. |
private not_power_rat_of_num {a b d : ℕ}
(h_coprime : a.Coprime b) (ha : ∀ x, a ≠ x ^ d) (q : ℚ) :
(a / b : ℚ) ≠ q ^ d := by
by_cases hq : 0 ≤ q
· apply not_power_rat_of_num_aux h_coprime ha hq
rcases d.even_or_odd with (h_even | h_odd)
· have := not_power_rat_of_num_aux h_coprime (q := -q) ha (by linarith)
rwa [h_even.neg_pow] at this
· contrapose! hq
rw [← h_odd.pow_nonneg_iff, ← hq]
positivity | theorem | Tactic | [
"Mathlib.Analysis.SpecialFunctions.Pow.Real",
"Mathlib.Data.Real.Irrational",
"Mathlib.Tactic.NormNum.GCD",
"Mathlib.Tactic.Rify"
] | Mathlib/Tactic/NormNum/Irrational.lean | not_power_rat_of_num | null |
private irrational_rpow_rat_rat_of_num {x y : ℝ} {x_num x_den y_num y_den k_num : ℕ}
(hx_isNNRat : IsNNRat x x_num x_den)
(hy_isNNRat : IsNNRat y y_num y_den)
(hx_coprime : Nat.Coprime x_num x_den)
(hy_coprime : Nat.Coprime y_num y_den)
(hn1 : k_num ^ y_den < x_num)
(hn2 : x_num < (k_num + 1) ^ y_den) :
Irrational (x ^ y) := by
have hy_den_pos : 0 < y_den := by
by_contra! h
simp only [nonpos_iff_eq_zero] at h
simp only [h, pow_zero, Nat.lt_one_iff] at hn1 hn2
omega
rcases hx_isNNRat with ⟨hx_inv, hx_eq⟩
rcases hy_isNNRat with ⟨hy_inv, hy_eq⟩
rw [hy_eq, hx_eq]
have h1 : (y_num * ⅟(y_den : ℝ) : ℝ) = ((y_num / y_den : ℚ) : ℝ) := by
simp
rfl
have h2 : (x_num * ⅟(x_den : ℝ) : ℝ) = ((x_num / x_den : ℚ) : ℝ) := by
simp
rfl
rw [h1, h2]
refine irrational_rpow_rat_of_not_power ?_ hy_den_pos ?_
· simp only [div_pow, ← Nat.cast_pow]
apply not_power_rat_of_num
· apply Nat.Coprime.pow _ _ hx_coprime
· apply not_power_nat_pow_of_bounds hy_den_pos hy_coprime hn1 hn2
· positivity | theorem | Tactic | [
"Mathlib.Analysis.SpecialFunctions.Pow.Real",
"Mathlib.Data.Real.Irrational",
"Mathlib.Tactic.NormNum.GCD",
"Mathlib.Tactic.Rify"
] | Mathlib/Tactic/NormNum/Irrational.lean | irrational_rpow_rat_rat_of_num | null |
private irrational_rpow_rat_rat_of_den {x y : ℝ} {x_num x_den y_num y_den k_den : ℕ}
(hx_isNNRat : IsNNRat x x_num x_den)
(hy_isNNRat : IsNNRat y y_num y_den)
(hx_coprime : Nat.Coprime x_num x_den)
(hy_coprime : Nat.Coprime y_num y_den)
(hd1 : k_den ^ y_den < x_den)
(hd2 : x_den < (k_den + 1) ^ y_den) :
Irrational (x ^ y) := by
rcases hx_isNNRat with ⟨hx_inv, hx_eq⟩
apply Irrational.of_inv
rw [← Real.inv_rpow (by simp [hx_eq]; positivity)]
apply irrational_rpow_rat_rat_of_num (x_num := x_den) (x_den := x_num) _ hy_isNNRat
(Nat.coprime_comm.mp hx_coprime) hy_coprime hd1 hd2
refine ⟨invertibleOfNonzero (fun _ ↦ ?_), by simp [hx_eq]⟩
simp_all | theorem | Tactic | [
"Mathlib.Analysis.SpecialFunctions.Pow.Real",
"Mathlib.Data.Real.Irrational",
"Mathlib.Tactic.NormNum.GCD",
"Mathlib.Tactic.Rify"
] | Mathlib/Tactic/NormNum/Irrational.lean | irrational_rpow_rat_rat_of_den | null |
private irrational_rpow_nat_rat {x y : ℝ} {x_num y_num y_den k : ℕ}
(hx_isNat : IsNat x x_num)
(hy_isNNRat : IsNNRat y y_num y_den)
(hy_coprime : Nat.Coprime y_num y_den)
(hn1 : k ^ y_den < x_num)
(hn2 : x_num < (k + 1) ^ y_den) :
Irrational (x ^ y) :=
irrational_rpow_rat_rat_of_num hx_isNat.to_isNNRat hy_isNNRat (by simp) hy_coprime hn1 hn2 | theorem | Tactic | [
"Mathlib.Analysis.SpecialFunctions.Pow.Real",
"Mathlib.Data.Real.Irrational",
"Mathlib.Tactic.NormNum.GCD",
"Mathlib.Tactic.Rify"
] | Mathlib/Tactic/NormNum/Irrational.lean | irrational_rpow_nat_rat | null |
private irrational_sqrt_rat_of_num {x : ℝ} {num den num_k : ℕ}
(hx_isNNRat : IsNNRat x num den)
(hx_coprime : Nat.Coprime num den)
(hn1 : num_k ^ 2 < num)
(hn2 : num < (num_k + 1) ^ 2) :
Irrational (Real.sqrt x) := by
rw [Real.sqrt_eq_rpow]
apply irrational_rpow_rat_rat_of_num hx_isNNRat (y_num := 1) (y_den := 2) _ hx_coprime (by simp)
hn1 hn2
exact ⟨Invertible.mk (1/2) (by simp) (by simp), by simp⟩ | theorem | Tactic | [
"Mathlib.Analysis.SpecialFunctions.Pow.Real",
"Mathlib.Data.Real.Irrational",
"Mathlib.Tactic.NormNum.GCD",
"Mathlib.Tactic.Rify"
] | Mathlib/Tactic/NormNum/Irrational.lean | irrational_sqrt_rat_of_num | null |
private irrational_sqrt_rat_of_den {x : ℝ} {num den den_k : ℕ}
(hx_isNNRat : IsNNRat x num den)
(hx_coprime : Nat.Coprime num den)
(hd1 : den_k ^ 2 < den)
(hd2 : den < (den_k + 1) ^ 2) :
Irrational (Real.sqrt x) := by
rw [Real.sqrt_eq_rpow]
apply irrational_rpow_rat_rat_of_den hx_isNNRat (y_num := 1) (y_den := 2) _ hx_coprime (by simp)
hd1 hd2
exact ⟨Invertible.mk (1/2) (by simp) (by simp), by simp⟩ | theorem | Tactic | [
"Mathlib.Analysis.SpecialFunctions.Pow.Real",
"Mathlib.Data.Real.Irrational",
"Mathlib.Tactic.NormNum.GCD",
"Mathlib.Tactic.Rify"
] | Mathlib/Tactic/NormNum/Irrational.lean | irrational_sqrt_rat_of_den | null |
private irrational_sqrt_nat {x : ℝ} {n k : ℕ}
(hx_isNat : IsNat x n)
(hn1 : k ^ 2 < n)
(hn2 : n < (k + 1) ^ 2) :
Irrational (Real.sqrt x) :=
irrational_sqrt_rat_of_num hx_isNat.to_isNNRat (by simp) hn1 hn2 | theorem | Tactic | [
"Mathlib.Analysis.SpecialFunctions.Pow.Real",
"Mathlib.Data.Real.Irrational",
"Mathlib.Tactic.NormNum.GCD",
"Mathlib.Tactic.Rify"
] | Mathlib/Tactic/NormNum/Irrational.lean | irrational_sqrt_nat | null |
NotPowerCertificate (m n : Q(ℕ)) where
/-- Natural `k` such that `k ^ n < m < (k + 1) ^ n`. -/
k : Q(ℕ)
/-- Proof of `k ^ n < m`. -/
pf_left : Q($k ^ $n < $m)
/-- Proof of `m < (k + 1) ^ n`. -/
pf_right : Q($m < ($k + 1) ^ $n) | structure | Tactic | [
"Mathlib.Analysis.SpecialFunctions.Pow.Real",
"Mathlib.Data.Real.Irrational",
"Mathlib.Tactic.NormNum.GCD",
"Mathlib.Tactic.Rify"
] | Mathlib/Tactic/NormNum/Irrational.lean | NotPowerCertificate | To prove that `m` is not `n`-power (and thus `m ^ (1/n)` is irrational), we find `k` such that
`k ^ n < m < (k + 1) ^ n`. |
findNotPowerCertificateCore (m n : ℕ) : Option ℕ := Id.run do
let mut left := 0
let mut right := m + 1
while right - left > 1 do
let middle := (left + right) / 2
if middle ^ n ≤ m then
left := middle
else
right := middle
if left ^ n < m then
return some left
return none | def | Tactic | [
"Mathlib.Analysis.SpecialFunctions.Pow.Real",
"Mathlib.Data.Real.Irrational",
"Mathlib.Tactic.NormNum.GCD",
"Mathlib.Tactic.Rify"
] | Mathlib/Tactic/NormNum/Irrational.lean | findNotPowerCertificateCore | Finds `k` such that `k ^ n < m < (k + 1) ^ n` using bisection method. It assumes `n > 0`. |
findNotPowerCertificate (m n : Q(ℕ)) : MetaM (NotPowerCertificate m n) := do
let .isNat (_ : Q(AddMonoidWithOne ℕ)) m _ := ← derive m | failure
let .isNat (_ : Q(AddMonoidWithOne ℕ)) n _ := ← derive n | failure
let mVal := m.natLit!
let nVal := n.natLit!
let some k := findNotPowerCertificateCore mVal nVal | failure
let .isBool true pf_left ← derive q($k ^ $n < $m) | failure
let .isBool true pf_right ← derive q($m < ($k + 1) ^ $n) | failure
return ⟨q($k), pf_left, pf_right⟩ | def | Tactic | [
"Mathlib.Analysis.SpecialFunctions.Pow.Real",
"Mathlib.Data.Real.Irrational",
"Mathlib.Tactic.NormNum.GCD",
"Mathlib.Tactic.Rify"
] | Mathlib/Tactic/NormNum/Irrational.lean | findNotPowerCertificate | Finds `NotPowerCertificate` showing that `m` is not `n`-power. |
@[norm_num Irrational (_ ^ (_ : ℝ))]
evalIrrationalRpow : NormNumExt where eval {u α} e := do
let 0 := u | failure
let ~q(Prop) := α | failure
let ~q(Irrational (($x : ℝ) ^ ($y : ℝ))) := e | failure
let .isNNRat sℝ _ y_num y_den y_isNNRat ← derive y | failure
let ⟨gy, hy_coprime⟩ := proveNatGCD y_num y_den
if gy.natLit! != 1 then failure
let _ : $gy =Q 1 := ⟨⟩
match ← derive x with
| .isNat sℝ ex x_isNat =>
let cert ← findNotPowerCertificate q($ex) y_den
assumeInstancesCommute
return .isTrue q(irrational_rpow_nat_rat $x_isNat $y_isNNRat $hy_coprime
$cert.pf_left $cert.pf_right)
| .isNNRat sℝ _ x_num x_den x_isNNRat =>
let ⟨gx, hx_coprime⟩ := proveNatGCD x_num x_den
if gx.natLit! != 1 then failure
let _ : $gx =Q 1 := ⟨⟩
let hx_isNNRat' : Q(IsNNRat $x $x_num $x_den) := x_isNNRat
let hy_isNNRat' : Q(IsNNRat $y $y_num $y_den) := y_isNNRat
try
let numCert ← findNotPowerCertificate q($x_num) y_den
assumeInstancesCommute
return Result.isTrue q(irrational_rpow_rat_rat_of_num $hx_isNNRat' $hy_isNNRat'
$hx_coprime $hy_coprime $numCert.pf_left $numCert.pf_right)
catch _ =>
let denCert ← findNotPowerCertificate q($x_den) y_den
assumeInstancesCommute
return Result.isTrue q(irrational_rpow_rat_rat_of_den $hx_isNNRat' $hy_isNNRat'
$hx_coprime $hy_coprime $denCert.pf_left $denCert.pf_right)
| _ => failure | def | Tactic | [
"Mathlib.Analysis.SpecialFunctions.Pow.Real",
"Mathlib.Data.Real.Irrational",
"Mathlib.Tactic.NormNum.GCD",
"Mathlib.Tactic.Rify"
] | Mathlib/Tactic/NormNum/Irrational.lean | evalIrrationalRpow | `norm_num` extension that proves `Irrational x ^ y` for rational `y`. `x` may be
natural or rational. |
@[norm_num Irrational (Real.sqrt _)]
evalIrrationalSqrt : NormNumExt where eval {u α} e := do
let 0 := u | failure
let ~q(Prop) := α | failure
let ~q(Irrational (√$x)) := e | failure
match ← derive x with
| .isNat sℝ ex pf =>
let cert ← findNotPowerCertificate ex q(nat_lit 2)
assumeInstancesCommute
return .isTrue q(irrational_sqrt_nat $pf $cert.pf_left $cert.pf_right)
| .isNNRat sℝ eq en ed pf =>
let ⟨g, pf_coprime⟩ := proveNatGCD en ed
if g.natLit! != 1 then failure
let _ : $g =Q 1 := ⟨⟩
try
let numCert ← findNotPowerCertificate en q(nat_lit 2)
assumeInstancesCommute
return Result.isTrue
q(irrational_sqrt_rat_of_num $pf $pf_coprime $numCert.pf_left $numCert.pf_right)
catch _ =>
let denCert ← findNotPowerCertificate ed q(nat_lit 2)
assumeInstancesCommute
return Result.isTrue
q(irrational_sqrt_rat_of_den $pf $pf_coprime $denCert.pf_left $denCert.pf_right)
| _ => failure | def | Tactic | [
"Mathlib.Analysis.SpecialFunctions.Pow.Real",
"Mathlib.Data.Real.Irrational",
"Mathlib.Tactic.NormNum.GCD",
"Mathlib.Tactic.Rify"
] | Mathlib/Tactic/NormNum/Irrational.lean | evalIrrationalSqrt | `norm_num` extension that proves `Irrational √x` for rational `x`. |
int_not_isCoprime_helper (x y : ℤ) (d : ℕ) (hd : Int.gcd x y = d)
(h : Nat.beq d 1 = false) : ¬ IsCoprime x y := by
rw [Int.isCoprime_iff_gcd_eq_one, hd]
exact Nat.ne_of_beq_eq_false h | theorem | Tactic | [
"Mathlib.RingTheory.Coprime.Lemmas",
"Mathlib.Tactic.NormNum.GCD"
] | Mathlib/Tactic/NormNum/IsCoprime.lean | int_not_isCoprime_helper | null |
isInt_isCoprime : {x y nx ny : ℤ} →
IsInt x nx → IsInt y ny → IsCoprime nx ny → IsCoprime x y
| _, _, _, _, ⟨rfl⟩, ⟨rfl⟩, h => h | theorem | Tactic | [
"Mathlib.RingTheory.Coprime.Lemmas",
"Mathlib.Tactic.NormNum.GCD"
] | Mathlib/Tactic/NormNum/IsCoprime.lean | isInt_isCoprime | null |
isInt_not_isCoprime : {x y nx ny : ℤ} →
IsInt x nx → IsInt y ny → ¬ IsCoprime nx ny → ¬ IsCoprime x y
| _, _, _, _, ⟨rfl⟩, ⟨rfl⟩, h => h | theorem | Tactic | [
"Mathlib.RingTheory.Coprime.Lemmas",
"Mathlib.Tactic.NormNum.GCD"
] | Mathlib/Tactic/NormNum/IsCoprime.lean | isInt_not_isCoprime | null |
proveIntIsCoprime (ex ey : Q(ℤ)) : Q(IsCoprime $ex $ey) ⊕ Q(¬ IsCoprime $ex $ey) :=
let ⟨ed, pf⟩ := proveIntGCD ex ey
if ed.natLit! = 1 then
have pf' : Q(Int.gcd $ex $ey = 1) := pf
Sum.inl q(Int.isCoprime_iff_gcd_eq_one.mpr $pf')
else
have h : Q(Nat.beq $ed 1 = false) := (q(Eq.refl false) : Expr)
Sum.inr q(int_not_isCoprime_helper $ex $ey $ed $pf $h) | def | Tactic | [
"Mathlib.RingTheory.Coprime.Lemmas",
"Mathlib.Tactic.NormNum.GCD"
] | Mathlib/Tactic/NormNum/IsCoprime.lean | proveIntIsCoprime | Evaluates `IsCoprime` for the given integer number literals.
Panics if `ex` or `ey` aren't integer number literals. |
@[norm_num IsCoprime (_ : ℤ) (_ : ℤ)]
evalIntIsCoprime : NormNumExt where eval {_ _} e := do
let .app (.app _ (x : Q(ℤ))) (y : Q(ℤ)) ← Meta.whnfR e | failure
let ⟨ex, p⟩ ← deriveInt x _
let ⟨ey, q⟩ ← deriveInt y _
match proveIntIsCoprime ex ey with
| .inl pf =>
have pf' : Q(IsCoprime $x $y) := q(isInt_isCoprime $p $q $pf)
return .isTrue pf'
| .inr pf =>
have pf' : Q(¬ IsCoprime $x $y) := q(isInt_not_isCoprime $p $q $pf)
return .isFalse pf' | def | Tactic | [
"Mathlib.RingTheory.Coprime.Lemmas",
"Mathlib.Tactic.NormNum.GCD"
] | Mathlib/Tactic/NormNum/IsCoprime.lean | evalIntIsCoprime | Evaluates the `IsCoprime` predicate over `ℤ`. |
jacobiSymNat (a b : ℕ) : ℤ :=
jacobiSym a b
/-! | def | Tactic | [
"Mathlib.NumberTheory.LegendreSymbol.JacobiSymbol"
] | Mathlib/Tactic/NormNum/LegendreSymbol.lean | jacobiSymNat | The Jacobi symbol restricted to natural numbers in both arguments. |
jacobiSymNat.zero_right (a : ℕ) : jacobiSymNat a 0 = 1 := by
rw [jacobiSymNat, jacobiSym.zero_right] | theorem | Tactic | [
"Mathlib.NumberTheory.LegendreSymbol.JacobiSymbol"
] | Mathlib/Tactic/NormNum/LegendreSymbol.lean | jacobiSymNat.zero_right | Base cases: `b = 0`, `b = 1`, `a = 0`, `a = 1`. |
jacobiSymNat.one_right (a : ℕ) : jacobiSymNat a 1 = 1 := by
rw [jacobiSymNat, jacobiSym.one_right] | theorem | Tactic | [
"Mathlib.NumberTheory.LegendreSymbol.JacobiSymbol"
] | Mathlib/Tactic/NormNum/LegendreSymbol.lean | jacobiSymNat.one_right | null |
jacobiSymNat.zero_left (b : ℕ) (hb : Nat.beq (b / 2) 0 = false) : jacobiSymNat 0 b = 0 := by
rw [jacobiSymNat, Nat.cast_zero, jacobiSym.zero_left ?_]
calc
1 < 2 * 1 := by decide
_ ≤ 2 * (b / 2) :=
Nat.mul_le_mul_left _ (Nat.succ_le.mpr (Nat.pos_of_ne_zero (Nat.ne_of_beq_eq_false hb)))
_ ≤ b := Nat.mul_div_le b 2 | theorem | Tactic | [
"Mathlib.NumberTheory.LegendreSymbol.JacobiSymbol"
] | Mathlib/Tactic/NormNum/LegendreSymbol.lean | jacobiSymNat.zero_left | null |
jacobiSymNat.one_left (b : ℕ) : jacobiSymNat 1 b = 1 := by
rw [jacobiSymNat, Nat.cast_one, jacobiSym.one_left] | theorem | Tactic | [
"Mathlib.NumberTheory.LegendreSymbol.JacobiSymbol"
] | Mathlib/Tactic/NormNum/LegendreSymbol.lean | jacobiSymNat.one_left | null |
LegendreSym.to_jacobiSym (p : ℕ) (pp : Fact p.Prime) (a r : ℤ)
(hr : IsInt (jacobiSym a p) r) : IsInt (legendreSym p a) r := by
rwa [@jacobiSym.legendreSym.to_jacobiSym p pp a] | theorem | Tactic | [
"Mathlib.NumberTheory.LegendreSymbol.JacobiSymbol"
] | Mathlib/Tactic/NormNum/LegendreSymbol.lean | LegendreSym.to_jacobiSym | Turn a Legendre symbol into a Jacobi symbol. |
JacobiSym.mod_left (a : ℤ) (b ab' : ℕ) (ab r b' : ℤ) (hb' : (b : ℤ) = b')
(hab : a % b' = ab) (h : (ab' : ℤ) = ab) (hr : jacobiSymNat ab' b = r) : jacobiSym a b = r := by
rw [← hr, jacobiSymNat, jacobiSym.mod_left, hb', hab, ← h] | theorem | Tactic | [
"Mathlib.NumberTheory.LegendreSymbol.JacobiSymbol"
] | Mathlib/Tactic/NormNum/LegendreSymbol.lean | JacobiSym.mod_left | The value depends only on the residue class of `a` mod `b`. |
jacobiSymNat.mod_left (a b ab : ℕ) (r : ℤ) (hab : a % b = ab) (hr : jacobiSymNat ab b = r) :
jacobiSymNat a b = r := by
rw [← hr, jacobiSymNat, jacobiSymNat, _root_.jacobiSym.mod_left a b, ← hab]; rfl | theorem | Tactic | [
"Mathlib.NumberTheory.LegendreSymbol.JacobiSymbol"
] | Mathlib/Tactic/NormNum/LegendreSymbol.lean | jacobiSymNat.mod_left | null |
jacobiSymNat.even_even (a b : ℕ) (hb₀ : Nat.beq (b / 2) 0 = false) (ha : a % 2 = 0)
(hb₁ : b % 2 = 0) : jacobiSymNat a b = 0 := by
refine jacobiSym.eq_zero_iff.mpr
⟨ne_of_gt ((Nat.pos_of_ne_zero (Nat.ne_of_beq_eq_false hb₀)).trans_le (Nat.div_le_self b 2)),
fun hf => ?_⟩
have h : 2 ∣ a.gcd b := Nat.dvd_gcd (Nat.dvd_of_mod_eq_zero ha) (Nat.dvd_of_mod_eq_zero hb₁)
change 2 ∣ (a : ℤ).gcd b at h
rw [hf, ← even_iff_two_dvd] at h
exact Nat.not_even_one h | theorem | Tactic | [
"Mathlib.NumberTheory.LegendreSymbol.JacobiSymbol"
] | Mathlib/Tactic/NormNum/LegendreSymbol.lean | jacobiSymNat.even_even | The symbol vanishes when both entries are even (and `b / 2 ≠ 0`). |
jacobiSymNat.odd_even (a b c : ℕ) (r : ℤ) (ha : a % 2 = 1) (hb : b % 2 = 0) (hc : b / 2 = c)
(hr : jacobiSymNat a c = r) : jacobiSymNat a b = r := by
have ha' : legendreSym 2 a = 1 := by
simp only [legendreSym.mod 2 a, Int.ofNat_mod_ofNat, ha]
decide
rcases eq_or_ne c 0 with (rfl | hc')
· rw [← hr, Nat.eq_zero_of_dvd_of_div_eq_zero (Nat.dvd_of_mod_eq_zero hb) hc]
· haveI : NeZero c := ⟨hc'⟩
rwa [← Nat.mod_add_div b 2, hb, hc, Nat.zero_add, jacobiSymNat, jacobiSym.mul_right,
← jacobiSym.legendreSym.to_jacobiSym, ha', one_mul] | theorem | Tactic | [
"Mathlib.NumberTheory.LegendreSymbol.JacobiSymbol"
] | Mathlib/Tactic/NormNum/LegendreSymbol.lean | jacobiSymNat.odd_even | When `a` is odd and `b` is even, we can replace `b` by `b / 2`. |
jacobiSymNat.double_even (a b c : ℕ) (r : ℤ) (ha : a % 4 = 0) (hb : b % 2 = 1)
(hc : a / 4 = c) (hr : jacobiSymNat c b = r) : jacobiSymNat a b = r := by
simp only [jacobiSymNat, ← hr, ← hc, Int.natCast_ediv, Nat.cast_ofNat]
exact (jacobiSym.div_four_left (mod_cast ha) hb).symm | theorem | Tactic | [
"Mathlib.NumberTheory.LegendreSymbol.JacobiSymbol"
] | Mathlib/Tactic/NormNum/LegendreSymbol.lean | jacobiSymNat.double_even | If `a` is divisible by `4` and `b` is odd, then we can remove the factor `4` from `a`. |
jacobiSymNat.even_odd₁ (a b c : ℕ) (r : ℤ) (ha : a % 2 = 0) (hb : b % 8 = 1)
(hc : a / 2 = c) (hr : jacobiSymNat c b = r) : jacobiSymNat a b = r := by
simp only [jacobiSymNat, ← hr, ← hc, Int.natCast_ediv, Nat.cast_ofNat]
rw [← jacobiSym.even_odd (mod_cast ha), if_neg (by simp [hb])]
rw [← Nat.mod_mod_of_dvd, hb]; simp | theorem | Tactic | [
"Mathlib.NumberTheory.LegendreSymbol.JacobiSymbol"
] | Mathlib/Tactic/NormNum/LegendreSymbol.lean | jacobiSymNat.even_odd₁ | If `a` is even and `b` is odd, then we can remove a factor `2` from `a`,
but we may have to change the sign, depending on `b % 8`.
We give one version for each of the four odd residue classes mod `8`. |
jacobiSymNat.even_odd₇ (a b c : ℕ) (r : ℤ) (ha : a % 2 = 0) (hb : b % 8 = 7)
(hc : a / 2 = c) (hr : jacobiSymNat c b = r) : jacobiSymNat a b = r := by
simp only [jacobiSymNat, ← hr, ← hc, Int.natCast_ediv, Nat.cast_ofNat]
rw [← jacobiSym.even_odd (mod_cast ha), if_neg (by simp [hb])]
rw [← Nat.mod_mod_of_dvd, hb]; simp | theorem | Tactic | [
"Mathlib.NumberTheory.LegendreSymbol.JacobiSymbol"
] | Mathlib/Tactic/NormNum/LegendreSymbol.lean | jacobiSymNat.even_odd₇ | null |
jacobiSymNat.even_odd₃ (a b c : ℕ) (r : ℤ) (ha : a % 2 = 0) (hb : b % 8 = 3)
(hc : a / 2 = c) (hr : jacobiSymNat c b = r) : jacobiSymNat a b = -r := by
simp only [jacobiSymNat, ← hr, ← hc, Int.natCast_ediv, Nat.cast_ofNat]
rw [← jacobiSym.even_odd (mod_cast ha), if_pos (by simp [hb])]
rw [← Nat.mod_mod_of_dvd, hb]; simp | theorem | Tactic | [
"Mathlib.NumberTheory.LegendreSymbol.JacobiSymbol"
] | Mathlib/Tactic/NormNum/LegendreSymbol.lean | jacobiSymNat.even_odd₃ | null |
jacobiSymNat.even_odd₅ (a b c : ℕ) (r : ℤ) (ha : a % 2 = 0) (hb : b % 8 = 5)
(hc : a / 2 = c) (hr : jacobiSymNat c b = r) : jacobiSymNat a b = -r := by
simp only [jacobiSymNat, ← hr, ← hc, Int.natCast_ediv, Nat.cast_ofNat]
rw [← jacobiSym.even_odd (mod_cast ha), if_pos (by simp [hb])]
rw [← Nat.mod_mod_of_dvd, hb]; simp | theorem | Tactic | [
"Mathlib.NumberTheory.LegendreSymbol.JacobiSymbol"
] | Mathlib/Tactic/NormNum/LegendreSymbol.lean | jacobiSymNat.even_odd₅ | null |
jacobiSymNat.qr₁ (a b : ℕ) (r : ℤ) (ha : a % 4 = 1) (hb : b % 2 = 1)
(hr : jacobiSymNat b a = r) : jacobiSymNat a b = r := by
rwa [jacobiSymNat, jacobiSym.quadratic_reciprocity_one_mod_four ha (Nat.odd_iff.mpr hb)] | theorem | Tactic | [
"Mathlib.NumberTheory.LegendreSymbol.JacobiSymbol"
] | Mathlib/Tactic/NormNum/LegendreSymbol.lean | jacobiSymNat.qr₁ | Use quadratic reciprocity to reduce to smaller `b`. |
jacobiSymNat.qr₁_mod (a b ab : ℕ) (r : ℤ) (ha : a % 4 = 1) (hb : b % 2 = 1)
(hab : b % a = ab) (hr : jacobiSymNat ab a = r) : jacobiSymNat a b = r :=
jacobiSymNat.qr₁ _ _ _ ha hb <| jacobiSymNat.mod_left _ _ ab r hab hr | theorem | Tactic | [
"Mathlib.NumberTheory.LegendreSymbol.JacobiSymbol"
] | Mathlib/Tactic/NormNum/LegendreSymbol.lean | jacobiSymNat.qr₁_mod | null |
jacobiSymNat.qr₁' (a b : ℕ) (r : ℤ) (ha : a % 2 = 1) (hb : b % 4 = 1)
(hr : jacobiSymNat b a = r) : jacobiSymNat a b = r := by
rwa [jacobiSymNat, ← jacobiSym.quadratic_reciprocity_one_mod_four hb (Nat.odd_iff.mpr ha)] | theorem | Tactic | [
"Mathlib.NumberTheory.LegendreSymbol.JacobiSymbol"
] | Mathlib/Tactic/NormNum/LegendreSymbol.lean | jacobiSymNat.qr₁' | null |
jacobiSymNat.qr₁'_mod (a b ab : ℕ) (r : ℤ) (ha : a % 2 = 1) (hb : b % 4 = 1)
(hab : b % a = ab) (hr : jacobiSymNat ab a = r) : jacobiSymNat a b = r :=
jacobiSymNat.qr₁' _ _ _ ha hb <| jacobiSymNat.mod_left _ _ ab r hab hr | theorem | Tactic | [
"Mathlib.NumberTheory.LegendreSymbol.JacobiSymbol"
] | Mathlib/Tactic/NormNum/LegendreSymbol.lean | jacobiSymNat.qr₁'_mod | null |
jacobiSymNat.qr₃ (a b : ℕ) (r : ℤ) (ha : a % 4 = 3) (hb : b % 4 = 3)
(hr : jacobiSymNat b a = r) : jacobiSymNat a b = -r := by
rwa [jacobiSymNat, jacobiSym.quadratic_reciprocity_three_mod_four ha hb, neg_inj] | theorem | Tactic | [
"Mathlib.NumberTheory.LegendreSymbol.JacobiSymbol"
] | Mathlib/Tactic/NormNum/LegendreSymbol.lean | jacobiSymNat.qr₃ | null |
jacobiSymNat.qr₃_mod (a b ab : ℕ) (r : ℤ) (ha : a % 4 = 3) (hb : b % 4 = 3)
(hab : b % a = ab) (hr : jacobiSymNat ab a = r) : jacobiSymNat a b = -r :=
jacobiSymNat.qr₃ _ _ _ ha hb <| jacobiSymNat.mod_left _ _ ab r hab hr | theorem | Tactic | [
"Mathlib.NumberTheory.LegendreSymbol.JacobiSymbol"
] | Mathlib/Tactic/NormNum/LegendreSymbol.lean | jacobiSymNat.qr₃_mod | null |
isInt_jacobiSym : {a na : ℤ} → {b nb : ℕ} → {r : ℤ} →
IsInt a na → IsNat b nb → jacobiSym na nb = r → IsInt (jacobiSym a b) r
| _, _, _, _, _, ⟨rfl⟩, ⟨rfl⟩, rfl => ⟨rfl⟩ | theorem | Tactic | [
"Mathlib.NumberTheory.LegendreSymbol.JacobiSymbol"
] | Mathlib/Tactic/NormNum/LegendreSymbol.lean | isInt_jacobiSym | null |
isInt_jacobiSymNat : {a na : ℕ} → {b nb : ℕ} → {r : ℤ} →
IsNat a na → IsNat b nb → jacobiSymNat na nb = r → IsInt (jacobiSymNat a b) r
| _, _, _, _, _, ⟨rfl⟩, ⟨rfl⟩, rfl => ⟨rfl⟩ | theorem | Tactic | [
"Mathlib.NumberTheory.LegendreSymbol.JacobiSymbol"
] | Mathlib/Tactic/NormNum/LegendreSymbol.lean | isInt_jacobiSymNat | null |
partial proveJacobiSymOdd (ea eb : Q(ℕ)) : (er : Q(ℤ)) × Q(jacobiSymNat $ea $eb = $er) :=
match eb.natLit! with
| 1 =>
haveI : $eb =Q 1 := ⟨⟩
⟨mkRawIntLit 1, q(jacobiSymNat.one_right $ea)⟩
| b =>
match ea.natLit! with
| 0 =>
haveI : $ea =Q 0 := ⟨⟩
have hb : Q(Nat.beq ($eb / 2) 0 = false) := (q(Eq.refl false) : Expr)
⟨mkRawIntLit 0, q(jacobiSymNat.zero_left $eb $hb)⟩
| 1 =>
haveI : $ea =Q 1 := ⟨⟩
⟨mkRawIntLit 1, q(jacobiSymNat.one_left $eb)⟩
| a =>
match a % 2 with
| 0 =>
match a % 4 with
| 0 =>
have ha : Q(Nat.mod $ea 4 = 0) := (q(Eq.refl 0) : Expr)
have hb : Q(Nat.mod $eb 2 = 1) := (q(Eq.refl 1) : Expr)
have ec : Q(ℕ) := mkRawNatLit (a / 4)
have hc : Q(Nat.div $ea 4 = $ec) := (q(Eq.refl $ec) : Expr)
have ⟨er, p⟩ := proveJacobiSymOdd ec eb
⟨er, q(jacobiSymNat.double_even $ea $eb $ec $er $ha $hb $hc $p)⟩
| _ =>
have ha : Q(Nat.mod $ea 2 = 0) := (q(Eq.refl 0) : Expr)
have ec : Q(ℕ) := mkRawNatLit (a / 2)
have hc : Q(Nat.div $ea 2 = $ec) := (q(Eq.refl $ec) : Expr)
have ⟨er, p⟩ := proveJacobiSymOdd ec eb
match b % 8 with
| 1 =>
have hb : Q(Nat.mod $eb 8 = 1) := (q(Eq.refl 1) : Expr)
⟨er, q(jacobiSymNat.even_odd₁ $ea $eb $ec $er $ha $hb $hc $p)⟩
| 3 =>
have er' := mkRawIntLit (-er.intLit!)
have hb : Q(Nat.mod $eb 8 = 3) := (q(Eq.refl 3) : Expr)
show (_ : Q(ℤ)) × Q(jacobiSymNat $ea $eb = -$er) from
⟨er', q(jacobiSymNat.even_odd₃ $ea $eb $ec $er $ha $hb $hc $p)⟩
| 5 =>
have er' := mkRawIntLit (-er.intLit!)
haveI : $er' =Q -$er := ⟨⟩
have hb : Q(Nat.mod $eb 8 = 5) := (q(Eq.refl 5) : Expr)
⟨er', q(jacobiSymNat.even_odd₅ $ea $eb $ec $er $ha $hb $hc $p)⟩
| _ =>
have hb : Q(Nat.mod $eb 8 = 7) := (q(Eq.refl 7) : Expr)
⟨er, q(jacobiSymNat.even_odd₇ $ea $eb $ec $er $ha $hb $hc $p)⟩
| _ =>
have eab : Q(ℕ) := mkRawNatLit (b % a)
have hab : Q(Nat.mod $eb $ea = $eab) := (q(Eq.refl $eab) : Expr)
have ⟨er, p⟩ := proveJacobiSymOdd eab ea
... | def | Tactic | [
"Mathlib.NumberTheory.LegendreSymbol.JacobiSymbol"
] | Mathlib/Tactic/NormNum/LegendreSymbol.lean | proveJacobiSymOdd | This evaluates `r := jacobiSymNat a b` recursively using quadratic reciprocity
and produces a proof term for the equality, assuming that `a < b` and `b` is odd. |
partial proveJacobiSymNat (ea eb : Q(ℕ)) : (er : Q(ℤ)) × Q(jacobiSymNat $ea $eb = $er) :=
match eb.natLit! with
| 0 =>
haveI : $eb =Q 0 := ⟨⟩
⟨mkRawIntLit 1, q(jacobiSymNat.zero_right $ea)⟩
| 1 =>
haveI : $eb =Q 1 := ⟨⟩
⟨mkRawIntLit 1, q(jacobiSymNat.one_right $ea)⟩
| b =>
match b % 2 with
| 0 =>
match ea.natLit! with
| 0 =>
have hb : Q(Nat.beq ($eb / 2) 0 = false) := (q(Eq.refl false) : Expr)
show (er : Q(ℤ)) × Q(jacobiSymNat 0 $eb = $er) from
⟨mkRawIntLit 0, q(jacobiSymNat.zero_left $eb $hb)⟩
| 1 =>
show (er : Q(ℤ)) × Q(jacobiSymNat 1 $eb = $er) from
⟨mkRawIntLit 1, q(jacobiSymNat.one_left $eb)⟩
| a =>
match a % 2 with
| 0 =>
have hb₀ : Q(Nat.beq ($eb / 2) 0 = false) := (q(Eq.refl false) : Expr)
have ha : Q(Nat.mod $ea 2 = 0) := (q(Eq.refl 0) : Expr)
have hb₁ : Q(Nat.mod $eb 2 = 0) := (q(Eq.refl 0) : Expr)
⟨mkRawIntLit 0, q(jacobiSymNat.even_even $ea $eb $hb₀ $ha $hb₁)⟩
| _ =>
have ha : Q(Nat.mod $ea 2 = 1) := (q(Eq.refl 1) : Expr)
have hb : Q(Nat.mod $eb 2 = 0) := (q(Eq.refl 0) : Expr)
have ec : Q(ℕ) := mkRawNatLit (b / 2)
have hc : Q(Nat.div $eb 2 = $ec) := (q(Eq.refl $ec) : Expr)
have ⟨er, p⟩ := proveJacobiSymOdd ea ec
⟨er, q(jacobiSymNat.odd_even $ea $eb $ec $er $ha $hb $hc $p)⟩
| _ =>
have a := ea.natLit!
if b ≤ a then
have eab : Q(ℕ) := mkRawNatLit (a % b)
have hab : Q(Nat.mod $ea $eb = $eab) := (q(Eq.refl $eab) : Expr)
have ⟨er, p⟩ := proveJacobiSymOdd eab eb
⟨er, q(jacobiSymNat.mod_left $ea $eb $eab $er $hab $p)⟩
else
proveJacobiSymOdd ea eb | def | Tactic | [
"Mathlib.NumberTheory.LegendreSymbol.JacobiSymbol"
] | Mathlib/Tactic/NormNum/LegendreSymbol.lean | proveJacobiSymNat | This evaluates `r := jacobiSymNat a b` and produces a proof term for the equality
by removing powers of `2` from `b` and then calling `proveJacobiSymOdd`. |
partial proveJacobiSym (ea : Q(ℤ)) (eb : Q(ℕ)) : (er : Q(ℤ)) × Q(jacobiSym $ea $eb = $er) :=
match eb.natLit! with
| 0 =>
haveI : $eb =Q 0 := ⟨⟩
⟨mkRawIntLit 1, q(jacobiSym.zero_right $ea)⟩
| 1 =>
haveI : $eb =Q 1 := ⟨⟩
⟨mkRawIntLit 1, q(jacobiSym.one_right $ea)⟩
| b =>
have eb' := mkRawIntLit b
have hb' : Q(($eb : ℤ) = $eb') := (q(Eq.refl $eb') : Expr)
have ab := ea.intLit! % b
have eab := mkRawIntLit ab
have hab : Q(Int.emod $ea $eb' = $eab) := (q(Eq.refl $eab) : Expr)
have eab' : Q(ℕ) := mkRawNatLit ab.toNat
have hab' : Q(($eab' : ℤ) = $eab) := (q(Eq.refl $eab) : Expr)
have ⟨er, p⟩ := proveJacobiSymNat eab' eb
⟨er, q(JacobiSym.mod_left $ea $eb $eab' $eab $er $eb' $hb' $hab $hab' $p)⟩ | def | Tactic | [
"Mathlib.NumberTheory.LegendreSymbol.JacobiSymbol"
] | Mathlib/Tactic/NormNum/LegendreSymbol.lean | proveJacobiSym | This evaluates `r := jacobiSym a b` and produces a proof term for the equality.
This is done by reducing to `r := jacobiSymNat (a % b) b`. |
@[norm_num jacobiSym _ _]
evalJacobiSym : NormNumExt where eval {u α} e := do
let .app (.app _ (a : Q(ℤ))) (b : Q(ℕ)) ← Meta.whnfR e | failure
let ⟨ea, pa⟩ ← deriveInt a _
let ⟨eb, pb⟩ ← deriveNat b _
haveI' : u =QL 0 := ⟨⟩ haveI' : $α =Q ℤ := ⟨⟩
have ⟨er, pr⟩ := proveJacobiSym ea eb
haveI' : $e =Q jacobiSym $a $b := ⟨⟩
return .isInt _ er er.intLit! q(isInt_jacobiSym $pa $pb $pr) | def | Tactic | [
"Mathlib.NumberTheory.LegendreSymbol.JacobiSymbol"
] | Mathlib/Tactic/NormNum/LegendreSymbol.lean | evalJacobiSym | This is the `norm_num` plug-in that evaluates Jacobi symbols. |
@[norm_num jacobiSymNat _ _]
evalJacobiSymNat : NormNumExt where eval {u α} e := do
let .app (.app _ (a : Q(ℕ))) (b : Q(ℕ)) ← Meta.whnfR e | failure
let ⟨ea, pa⟩ ← deriveNat a _
let ⟨eb, pb⟩ ← deriveNat b _
haveI' : u =QL 0 := ⟨⟩ haveI' : $α =Q ℤ := ⟨⟩
have ⟨er, pr⟩ := proveJacobiSymNat ea eb
haveI' : $e =Q jacobiSymNat $a $b := ⟨⟩
return .isInt _ er er.intLit! q(isInt_jacobiSymNat $pa $pb $pr) | def | Tactic | [
"Mathlib.NumberTheory.LegendreSymbol.JacobiSymbol"
] | Mathlib/Tactic/NormNum/LegendreSymbol.lean | evalJacobiSymNat | This is the `norm_num` plug-in that evaluates Jacobi symbols on natural numbers. |
@[norm_num legendreSym _ _]
evalLegendreSym : NormNumExt where eval {u α} e := do
let .app (.app (.app _ (p : Q(ℕ))) (fp : Q(Fact (Nat.Prime $p)))) (a : Q(ℤ)) ← Meta.whnfR e |
failure
let ⟨ea, pa⟩ ← deriveInt a _
let ⟨ep, pp⟩ ← deriveNat p _
haveI' : u =QL 0 := ⟨⟩ haveI' : $α =Q ℤ := ⟨⟩
have ⟨er, pr⟩ := proveJacobiSym ea ep
haveI' : $e =Q legendreSym $p $a := ⟨⟩
return .isInt _ er er.intLit!
q(LegendreSym.to_jacobiSym $p $fp $a $er (isInt_jacobiSym $pa $pp $pr)) | def | Tactic | [
"Mathlib.NumberTheory.LegendreSymbol.JacobiSymbol"
] | Mathlib/Tactic/NormNum/LegendreSymbol.lean | evalLegendreSym | This is the `norm_num` plug-in that evaluates Legendre symbols. |
evalNatModEq : NormNumExt where eval {u αP} e := do
match u, αP, e with
| 0, ~q(Prop), ~q($a ≡ $b [MOD $n]) =>
let ⟨b, pb⟩ ← deriveBoolOfIff _ e q(Nat.modEq_iff_dvd.symm)
return .ofBoolResult pb
| _, _, _ => failure | def | Tactic | [
"Mathlib.Tactic.NormNum.DivMod",
"Mathlib.Data.Int.ModEq"
] | Mathlib/Tactic/NormNum/ModEq.lean | evalNatModEq | null |
evalIntModEq : NormNumExt where eval {u αP} e := do
match u, αP, e with
| 0, ~q(Prop), ~q($a ≡ $b [ZMOD $n]) =>
let ⟨b, pb⟩ ← deriveBoolOfIff _ e q(Int.modEq_iff_dvd.symm)
return .ofBoolResult pb
| _, _, _ => failure | def | Tactic | [
"Mathlib.Tactic.NormNum.DivMod",
"Mathlib.Data.Int.ModEq"
] | Mathlib/Tactic/NormNum/ModEq.lean | evalIntModEq | null |
asc_factorial_aux (n l m a b : ℕ) (h₁ : n.ascFactorial l = a)
(h₂ : (n + l).ascFactorial m = b) : n.ascFactorial (l + m) = a * b := by
rw [← h₁, ← h₂]
symm
apply ascFactorial_mul_ascFactorial | lemma | Tactic | [
"Mathlib.Data.Nat.Factorial.Basic",
"Mathlib.Tactic.NormNum"
] | Mathlib/Tactic/NormNum/NatFactorial.lean | asc_factorial_aux | null |
partial proveAscFactorial (n l : ℕ) (en el : Q(ℕ)) :
ℕ × (eresult : Q(ℕ)) × Q(($en).ascFactorial $el = $eresult) :=
if l ≤ 50 then
have res : ℕ := n.ascFactorial l
have eres : Q(ℕ) := mkRawNatLit (n.ascFactorial l)
have : ($en).ascFactorial $el =Q $eres := ⟨⟩
⟨res, eres, q(Eq.refl $eres)⟩
else
have m : ℕ := l / 2
have em : Q(ℕ) := mkRawNatLit m
have : $em =Q $el / 2 := ⟨⟩
have r : ℕ := l - m
have er : Q(ℕ) := mkRawNatLit r
have : $er =Q $el - $em := ⟨⟩
have : $el =Q ($em + $er) := ⟨⟩
have nm : ℕ := n + m
have enm : Q(ℕ) := mkRawNatLit nm
have : $enm =Q $en + $em := ⟨⟩
let ⟨a, ea, a_prf⟩ := proveAscFactorial n m en em
let ⟨b, eb, b_prf⟩ := proveAscFactorial (n + m) r enm er
have eab : Q(ℕ) := mkRawNatLit (a * b)
have : $eab =Q $ea * $eb := ⟨⟩
⟨a * b, eab, q(by convert asc_factorial_aux $en $em $er $ea $eb $a_prf $b_prf)⟩ | def | Tactic | [
"Mathlib.Data.Nat.Factorial.Basic",
"Mathlib.Tactic.NormNum"
] | Mathlib/Tactic/NormNum/NatFactorial.lean | proveAscFactorial | Calculate `n.ascFactorial l` and return this value along with a proof of the result. |
isNat_factorial {n x : ℕ} (h₁ : IsNat n x) (a : ℕ) (h₂ : (1).ascFactorial x = a) :
IsNat (n !) a := by
constructor
simp only [h₁.out, cast_id, ← h₂, one_ascFactorial] | lemma | Tactic | [
"Mathlib.Data.Nat.Factorial.Basic",
"Mathlib.Tactic.NormNum"
] | Mathlib/Tactic/NormNum/NatFactorial.lean | isNat_factorial | null |
@[nolint unusedHavesSuffices, norm_num Nat.factorial _]
evalNatFactorial : NormNumExt where eval {u α} e := do
let .app _ (x : Q(ℕ)) ← Meta.whnfR e | failure
have : u =QL 0 := ⟨⟩; have : $α =Q ℕ := ⟨⟩; have : $e =Q Nat.factorial $x := ⟨⟩
let sℕ : Q(AddMonoidWithOne ℕ) := q(instAddMonoidWithOneNat)
let ⟨ex, p⟩ ← deriveNat x sℕ
let ⟨_, val, ascPrf⟩ := proveAscFactorial 1 ex.natLit! q(nat_lit 1) ex
return .isNat sℕ q($val) q(isNat_factorial $p $val $ascPrf) | def | Tactic | [
"Mathlib.Data.Nat.Factorial.Basic",
"Mathlib.Tactic.NormNum"
] | Mathlib/Tactic/NormNum/NatFactorial.lean | evalNatFactorial | Evaluates the `Nat.factorial` function. |
isNat_ascFactorial {n x l y : ℕ} (h₁ : IsNat n x) (h₂ : IsNat l y) (a : ℕ)
(p : x.ascFactorial y = a) : IsNat (n.ascFactorial l) a := by
constructor
simp [h₁.out, h₂.out, ← p] | lemma | Tactic | [
"Mathlib.Data.Nat.Factorial.Basic",
"Mathlib.Tactic.NormNum"
] | Mathlib/Tactic/NormNum/NatFactorial.lean | isNat_ascFactorial | null |
@[nolint unusedHavesSuffices, norm_num Nat.ascFactorial _ _]
evalNatAscFactorial : NormNumExt where eval {u α} e := do
let .app (.app _ (x : Q(ℕ))) (y : Q(ℕ)) ← Meta.whnfR e | failure
have : u =QL 0 := ⟨⟩; have : $α =Q ℕ := ⟨⟩; have : $e =Q Nat.ascFactorial $x $y := ⟨⟩
let sℕ : Q(AddMonoidWithOne ℕ) := q(instAddMonoidWithOneNat)
let ⟨ex₁, p₁⟩ ← deriveNat x sℕ
let ⟨ex₂, p₂⟩ ← deriveNat y sℕ
let ⟨_, val, ascPrf⟩ := proveAscFactorial ex₁.natLit! ex₂.natLit! ex₁ ex₂
return .isNat sℕ q($val) q(isNat_ascFactorial $p₁ $p₂ $val $ascPrf) | def | Tactic | [
"Mathlib.Data.Nat.Factorial.Basic",
"Mathlib.Tactic.NormNum"
] | Mathlib/Tactic/NormNum/NatFactorial.lean | evalNatAscFactorial | Evaluates the Nat.ascFactorial function. |
isNat_descFactorial {n x l y : ℕ} (z : ℕ) (h₁ : IsNat n x) (h₂ : IsNat l y)
(h₃ : x = z + y) (a : ℕ) (p : (z + 1).ascFactorial y = a) : IsNat (n.descFactorial l) a := by
constructor
simpa [h₁.out, h₂.out, ← p, h₃] using Nat.add_descFactorial_eq_ascFactorial _ _ | lemma | Tactic | [
"Mathlib.Data.Nat.Factorial.Basic",
"Mathlib.Tactic.NormNum"
] | Mathlib/Tactic/NormNum/NatFactorial.lean | isNat_descFactorial | null |
isNat_descFactorial_zero {n x l y : ℕ} (z : ℕ) (h₁ : IsNat n x) (h₂ : IsNat l y)
(h₃ : y = z + x + 1) : IsNat (n.descFactorial l) 0 := by
constructor
simp [h₁.out, h₂.out, h₃]
private partial def evalNatDescFactorialNotZero {x' y' : Q(ℕ)} (x y z : Q(ℕ))
(_hx : $x =Q $z + $y)
(px : Q(IsNat $x' $x)) (py : Q(IsNat $y' $y)) :
(n : Q(ℕ)) × Q(IsNat (descFactorial $x' $y') $n) :=
have zp1 :Q(ℕ) := mkRawNatLit (z.natLit! + 1)
have : $zp1 =Q $z + 1 := ⟨⟩
let ⟨_, val, ascPrf⟩ := proveAscFactorial (z.natLit! + 1) y.natLit! zp1 y
⟨val, q(isNat_descFactorial $z $px $py rfl $val $ascPrf)⟩
private partial def evalNatDescFactorialZero {x' y' : Q(ℕ)} (x y z : Q(ℕ))
(_hy : $y =Q $z + $x + 1)
(px : Q(IsNat $x' $x)) (py : Q(IsNat $y' $y)) :
(n : Q(ℕ)) × Q(IsNat (descFactorial $x' $y') $n) :=
⟨q(nat_lit 0), q(isNat_descFactorial_zero $z $px $py rfl)⟩ | lemma | Tactic | [
"Mathlib.Data.Nat.Factorial.Basic",
"Mathlib.Tactic.NormNum"
] | Mathlib/Tactic/NormNum/NatFactorial.lean | isNat_descFactorial_zero | null |
@[nolint unusedHavesSuffices, norm_num Nat.descFactorial _ _]
evalNatDescFactorial : NormNumExt where eval {u α} e := do
let .app (.app _ (x' : Q(ℕ))) (y' : Q(ℕ)) ← Meta.whnfR e | failure
have : u =QL 0 := ⟨⟩
have : $α =Q ℕ := ⟨⟩
have : $e =Q Nat.descFactorial $x' $y' := ⟨⟩
let sℕ : Q(AddMonoidWithOne ℕ) := q(instAddMonoidWithOneNat)
let ⟨x, p₁⟩ ← deriveNat x' sℕ
let ⟨y, p₂⟩ ← deriveNat y' sℕ
if x.natLit! ≥ y.natLit! then
have z : Q(ℕ) := mkRawNatLit (x.natLit! - y.natLit!)
have : $x =Q $z + $y := ⟨⟩
let ⟨val, prf⟩ := evalNatDescFactorialNotZero (x' := x') (y' := y') x y z ‹_› p₁ p₂
return .isNat sℕ val q($prf)
else
have z : Q(ℕ) := mkRawNatLit (y.natLit! - x.natLit! - 1)
have : $y =Q $z + $x + 1 := ⟨⟩
let ⟨val, prf⟩ := evalNatDescFactorialZero (x' := x') (y' := y') x y z ‹_› p₁ p₂
return .isNat sℕ val q($prf) | def | Tactic | [
"Mathlib.Data.Nat.Factorial.Basic",
"Mathlib.Tactic.NormNum"
] | Mathlib/Tactic/NormNum/NatFactorial.lean | evalNatDescFactorial | Evaluates the `Nat.descFactorial` function. |
IsFibAux (n a b : ℕ) :=
fib n = a ∧ fib (n + 1) = b | def | Tactic | [
"Mathlib.Data.Nat.Fib.Basic",
"Mathlib.Tactic.NormNum"
] | Mathlib/Tactic/NormNum/NatFib.lean | IsFibAux | Auxiliary definition for `proveFib` extension. |
isFibAux_zero : IsFibAux 0 0 1 :=
⟨fib_zero, fib_one⟩ | theorem | Tactic | [
"Mathlib.Data.Nat.Fib.Basic",
"Mathlib.Tactic.NormNum"
] | Mathlib/Tactic/NormNum/NatFib.lean | isFibAux_zero | null |
isFibAux_one : IsFibAux 1 1 1 :=
⟨fib_one, fib_two⟩ | theorem | Tactic | [
"Mathlib.Data.Nat.Fib.Basic",
"Mathlib.Tactic.NormNum"
] | Mathlib/Tactic/NormNum/NatFib.lean | isFibAux_one | null |
isFibAux_two_mul {n a b n' a' b' : ℕ} (H : IsFibAux n a b)
(hn : 2 * n = n') (h1 : a * (2 * b - a) = a') (h2 : a * a + b * b = b') :
IsFibAux n' a' b' :=
⟨by rw [← hn, fib_two_mul, H.1, H.2, ← h1],
by rw [← hn, fib_two_mul_add_one, H.1, H.2, pow_two, pow_two, add_comm, h2]⟩ | theorem | Tactic | [
"Mathlib.Data.Nat.Fib.Basic",
"Mathlib.Tactic.NormNum"
] | Mathlib/Tactic/NormNum/NatFib.lean | isFibAux_two_mul | null |
isFibAux_two_mul_add_one {n a b n' a' b' : ℕ} (H : IsFibAux n a b)
(hn : 2 * n + 1 = n') (h1 : a * a + b * b = a') (h2 : b * (2 * a + b) = b') :
IsFibAux n' a' b' :=
⟨by rw [← hn, fib_two_mul_add_one, H.1, H.2, pow_two, pow_two, add_comm, h1],
by rw [← hn, fib_two_mul_add_two, H.1, H.2, h2]⟩ | theorem | Tactic | [
"Mathlib.Data.Nat.Fib.Basic",
"Mathlib.Tactic.NormNum"
] | Mathlib/Tactic/NormNum/NatFib.lean | isFibAux_two_mul_add_one | null |
partial proveNatFibAux (en' : Q(ℕ)) : (ea' eb' : Q(ℕ)) × Q(IsFibAux $en' $ea' $eb') :=
match en'.natLit! with
| 0 =>
have : $en' =Q nat_lit 0 := ⟨⟩;
⟨q(nat_lit 0), q(nat_lit 1), q(isFibAux_zero)⟩
| 1 =>
have : $en' =Q nat_lit 1 := ⟨⟩;
⟨q(nat_lit 1), q(nat_lit 1), q(isFibAux_one)⟩
| n' =>
have en : Q(ℕ) := mkRawNatLit <| n' / 2
let ⟨ea, eb, H⟩ := proveNatFibAux en
let a := ea.natLit!
let b := eb.natLit!
if n' % 2 == 0 then
have hn : Q(2 * $en = $en') := (q(Eq.refl $en') : Expr)
have ea' : Q(ℕ) := mkRawNatLit <| a * (2 * b - a)
have eb' : Q(ℕ) := mkRawNatLit <| a * a + b * b
have h1 : Q($ea * (2 * $eb - $ea) = $ea') := (q(Eq.refl $ea') : Expr)
have h2 : Q($ea * $ea + $eb * $eb = $eb') := (q(Eq.refl $eb') : Expr)
⟨ea', eb', q(isFibAux_two_mul $H $hn $h1 $h2)⟩
else
have hn : Q(2 * $en + 1 = $en') := (q(Eq.refl $en') : Expr)
have ea' : Q(ℕ) := mkRawNatLit <| a * a + b * b
have eb' : Q(ℕ) := mkRawNatLit <| b * (2 * a + b)
have h1 : Q($ea * $ea + $eb * $eb = $ea') := (q(Eq.refl $ea') : Expr)
have h2 : Q($eb * (2 * $ea + $eb) = $eb') := (q(Eq.refl $eb') : Expr)
⟨ea', eb', q(isFibAux_two_mul_add_one $H $hn $h1 $h2)⟩ | def | Tactic | [
"Mathlib.Data.Nat.Fib.Basic",
"Mathlib.Tactic.NormNum"
] | Mathlib/Tactic/NormNum/NatFib.lean | proveNatFibAux | null |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.