data.rat.defs
⟷
Mathlib.Data.Rat.Defs
The following section lists changes to this file in mathlib3 and mathlib4 that occured after the initial port. Most recent changes are shown first. Hovering over a commit will show all commits associated with the same mathlib3 commit.
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(last sync)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
@@ -162,8 +162,7 @@ begin
all_goals { exact int.coe_nat_dvd.2 (nat.gcd_dvd_left _ _) } },
intros a c h,
suffices bd : b / a.gcd b = d / c.gcd d,
- { refine ⟨_, bd⟩,
- apply nat.eq_of_mul_eq_mul_left hb,
+ { refine ⟨mul_left_cancel₀ hb.ne' _, bd⟩,
rw [← nat.mul_div_assoc _ (nat.gcd_dvd_left _ _), mul_comm,
nat.mul_div_assoc _ (nat.gcd_dvd_right _ _), bd,
← nat.mul_div_assoc _ (nat.gcd_dvd_right _ _), h, mul_comm,
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(first ported)
mathlib commit https://github.com/leanprover-community/mathlib/commit/65a1391a0106c9204fe45bc73a039f056558cb83
@@ -257,22 +257,22 @@ theorem divInt_mul_right {a b c : ℤ} (c0 : c ≠ 0) : a * c /. (b * c) = a /.
#align rat.div_mk_div_cancel_left Rat.divInt_mul_right
-/
-#print Rat.num_den /-
+#print Rat.num_divInt_den /-
@[simp]
-theorem num_den : ∀ {a : ℚ}, a.num /. a.den = a
+theorem num_divInt_den : ∀ {a : ℚ}, a.num /. a.den = a
| ⟨n, d, h, (c : _ = 1)⟩ => show mkRat n d = _ by simp [mk_nat, ne_of_gt h, mk_pnat, c]
-#align rat.num_denom Rat.num_den
+#align rat.num_denom Rat.num_divInt_den
-/
-#print Rat.num_den' /-
-theorem num_den' {n d h c} : (⟨n, d, h, c⟩ : ℚ) = n /. d :=
- num_den.symm
-#align rat.num_denom' Rat.num_den'
+#print Rat.mk'_eq_divInt /-
+theorem mk'_eq_divInt {n d h c} : (⟨n, d, h, c⟩ : ℚ) = n /. d :=
+ num_divInt_den.symm
+#align rat.num_denom' Rat.mk'_eq_divInt
-/
#print Rat.intCast_eq_divInt /-
theorem intCast_eq_divInt (z : ℤ) : (z : ℚ) = z /. 1 :=
- num_den'
+ mk'_eq_divInt
#align rat.coe_int_eq_mk Rat.intCast_eq_divInt
-/
@@ -352,9 +352,9 @@ protected def neg (r : ℚ) : ℚ :=
instance : Neg ℚ :=
⟨Rat.neg⟩
-#print Rat.neg_def /-
+#print Rat.neg_divInt /-
@[simp]
-theorem neg_def {a b : ℤ} : -(a /. b) = -a /. b :=
+theorem neg_divInt {a b : ℤ} : -(a /. b) = -a /. b :=
by
by_cases b0 : b = 0; · subst b0; simp; rfl
generalize ha : a /. b = x; cases' x with n₁ d₁ h₁ c₁; rw [num_denom'] at ha
@@ -362,14 +362,14 @@ theorem neg_def {a b : ℤ} : -(a /. b) = -a /. b :=
have d0 := ne_of_gt (Int.ofNat_lt.2 h₁)
apply (mk_eq d0 b0).2; have h₁ := (mk_eq b0 d0).1 ha
simp only [neg_mul, congr_arg Neg.neg h₁]
-#align rat.neg_def Rat.neg_def
+#align rat.neg_def Rat.neg_divInt
-/
-#print Rat.divInt_neg_den /-
+#print Rat.divInt_neg /-
@[simp]
-theorem divInt_neg_den (n d : ℤ) : n /. -d = -n /. d := by
+theorem divInt_neg (n d : ℤ) : n /. -d = -n /. d := by
by_cases hd : d = 0 <;> simp [Rat.divInt_eq_iff, hd]
-#align rat.mk_neg_denom Rat.divInt_neg_den
+#align rat.mk_neg_denom Rat.divInt_neg
-/
#print Rat.mul /-
@@ -382,15 +382,16 @@ protected def mul : ℚ → ℚ → ℚ
instance : Mul ℚ :=
⟨Rat.mul⟩
-#print Rat.mul_def' /-
+#print Rat.divInt_mul_divInt' /-
@[simp]
-theorem mul_def' {a b c d : ℤ} (b0 : b ≠ 0) (d0 : d ≠ 0) : a /. b * (c /. d) = a * c /. (b * d) :=
+theorem divInt_mul_divInt' {a b c d : ℤ} (b0 : b ≠ 0) (d0 : d ≠ 0) :
+ a /. b * (c /. d) = a * c /. (b * d) :=
by
apply lift_binop_eq Rat.mul <;> intros <;> try assumption
· apply mk_pnat_eq
· apply mul_ne_zero d₁0 d₂0
cc
-#align rat.mul_def Rat.mul_def'
+#align rat.mul_def Rat.divInt_mul_divInt'
-/
#print Rat.inv /-
@@ -408,9 +409,9 @@ instance : Inv ℚ :=
instance : Div ℚ :=
⟨fun a b => a * b⁻¹⟩
-#print Rat.inv_def' /-
+#print Rat.inv_divInt /-
@[simp]
-theorem inv_def' {a b : ℤ} : (a /. b)⁻¹ = b /. a :=
+theorem inv_divInt {a b : ℤ} : (a /. b)⁻¹ = b /. a :=
by
by_cases a0 : a = 0; · subst a0; simp; rfl
by_cases b0 : b = 0; · subst b0; simp; rfl
@@ -429,7 +430,7 @@ theorem inv_def' {a b : ℤ} : (a /. b)⁻¹ = b /. a :=
have ha := (mk_eq b0 d0).1 ha
apply (mk_eq n0 a0).2
cc
-#align rat.inv_def Rat.inv_def'
+#align rat.inv_def Rat.inv_divInt
-/
variable (a b c : ℚ)
@@ -467,11 +468,13 @@ protected theorem add_left_neg : -a + a = 0 :=
#align rat.add_left_neg Rat.add_left_neg
-/
-#print Rat.divInt_zero_one /-
+/- warning: rat.mk_zero_one clashes with rat.zero_mk -> Rat.zero_divInt
+Case conversion may be inaccurate. Consider using '#align rat.mk_zero_one Rat.zero_divIntₓ'. -/
+#print Rat.zero_divInt /-
@[simp]
-theorem divInt_zero_one : 0 /. 1 = 0 :=
+theorem zero_divInt : 0 /. 1 = 0 :=
show mkPnat _ _ = _ by rw [mk_pnat]; simp; rfl
-#align rat.mk_zero_one Rat.divInt_zero_one
+#align rat.mk_zero_one Rat.zero_divInt
-/
#print Rat.divInt_one_one /-
@@ -693,7 +696,7 @@ theorem den_zero : Rat.den 0 = 1 :=
#print Rat.zero_of_num_zero /-
theorem zero_of_num_zero {q : ℚ} (hq : q.num = 0) : q = 0 :=
by
- have : q = q.num /. q.den := num_den.symm
+ have : q = q.num /. q.den := num_divInt_den.symm
simpa [hq]
#align rat.zero_of_num_zero Rat.zero_of_num_zero
-/
@@ -704,10 +707,10 @@ theorem zero_iff_num_zero {q : ℚ} : q = 0 ↔ q.num = 0 :=
#align rat.zero_iff_num_zero Rat.zero_iff_num_zero
-/
-#print Rat.num_ne_zero_of_ne_zero /-
-theorem num_ne_zero_of_ne_zero {q : ℚ} (h : q ≠ 0) : q.num ≠ 0 := fun this : q.num = 0 =>
+#print Rat.num_ne_zero /-
+theorem num_ne_zero {q : ℚ} (h : q ≠ 0) : q.num ≠ 0 := fun this : q.num = 0 =>
h <| zero_of_num_zero this
-#align rat.num_ne_zero_of_ne_zero Rat.num_ne_zero_of_ne_zero
+#align rat.num_ne_zero_of_ne_zero Rat.num_ne_zero
-/
#print Rat.num_one /-
@@ -742,19 +745,19 @@ theorem divInt_ne_zero_of_ne_zero {n d : ℤ} (h : n ≠ 0) (hd : d ≠ 0) : n /
#align rat.mk_ne_zero_of_ne_zero Rat.divInt_ne_zero_of_ne_zero
-/
-#print Rat.mul_num_den /-
-theorem mul_num_den (q r : ℚ) : q * r = q.num * r.num /. ↑(q.den * r.den) :=
+#print Rat.mul_def' /-
+theorem mul_def' (q r : ℚ) : q * r = q.num * r.num /. ↑(q.den * r.den) :=
by
have hq' : (↑q.den : ℤ) ≠ 0 := by have := denom_ne_zero q <;> simpa
have hr' : (↑r.den : ℤ) ≠ 0 := by have := denom_ne_zero r <;> simpa
suffices q.num /. ↑q.den * (r.num /. ↑r.den) = q.num * r.num /. ↑(q.den * r.den) by
simpa using this
simp [mul_def hq' hr', -num_denom]
-#align rat.mul_num_denom Rat.mul_num_den
+#align rat.mul_num_denom Rat.mul_def'
-/
-#print Rat.div_num_den /-
-theorem div_num_den (q r : ℚ) : q / r = q.num * r.den /. (q.den * r.num) :=
+#print Rat.div_def' /-
+theorem div_def' (q r : ℚ) : q / r = q.num * r.den /. (q.den * r.num) :=
if hr : r.num = 0 then by
have hr' : r = 0 := zero_of_num_zero hr
simp [*]
@@ -763,8 +766,8 @@ theorem div_num_den (q r : ℚ) : q / r = q.num * r.den /. (q.den * r.num) :=
q / r = q * r⁻¹ := div_eq_mul_inv q r
_ = q.num /. q.den * (r.num /. r.den)⁻¹ := by simp
_ = q.num /. q.den * (r.den /. r.num) := by rw [inv_def]
- _ = q.num * r.den /. (q.den * r.num) := mul_def' (by simpa using denom_ne_zero q) hr
-#align rat.div_num_denom Rat.div_num_den
+ _ = q.num * r.den /. (q.den * r.num) := divInt_mul_divInt' (by simpa using denom_ne_zero q) hr
+#align rat.div_num_denom Rat.div_def'
-/
section Casts
mathlib commit https://github.com/leanprover-community/mathlib/commit/65a1391a0106c9204fe45bc73a039f056558cb83
@@ -270,10 +270,10 @@ theorem num_den' {n d h c} : (⟨n, d, h, c⟩ : ℚ) = n /. d :=
#align rat.num_denom' Rat.num_den'
-/
-#print Rat.coe_int_eq_divInt /-
-theorem coe_int_eq_divInt (z : ℤ) : (z : ℚ) = z /. 1 :=
+#print Rat.intCast_eq_divInt /-
+theorem intCast_eq_divInt (z : ℤ) : (z : ℚ) = z /. 1 :=
num_den'
-#align rat.coe_int_eq_mk Rat.coe_int_eq_divInt
+#align rat.coe_int_eq_mk Rat.intCast_eq_divInt
-/
#print Rat.numDenCasesOn /-
@@ -806,12 +806,12 @@ theorem divInt_div_divInt_cancel_right {x : ℤ} (hx : x ≠ 0) (n d : ℤ) :
#align rat.mk_div_mk_cancel_right Rat.divInt_div_divInt_cancel_right
-/
-#print Rat.coe_int_div_eq_divInt /-
-theorem coe_int_div_eq_divInt {n d : ℤ} : (n : ℚ) / ↑d = n /. d :=
+#print Rat.intCast_div_eq_divInt /-
+theorem intCast_div_eq_divInt {n d : ℤ} : (n : ℚ) / ↑d = n /. d :=
by
repeat' rw [coe_int_eq_mk]
exact mk_div_mk_cancel_left one_ne_zero n d
-#align rat.coe_int_div_eq_mk Rat.coe_int_div_eq_divInt
+#align rat.coe_int_div_eq_mk Rat.intCast_div_eq_divInt
-/
#print Rat.num_div_den /-
@@ -839,9 +839,9 @@ instance canLift : CanLift ℚ ℤ coe fun q => q.den = 1 :=
#align rat.can_lift Rat.canLift
-/
-#print Rat.coe_nat_eq_divInt /-
-theorem coe_nat_eq_divInt (n : ℕ) : ↑n = n /. 1 := by rw [← Int.cast_natCast, coe_int_eq_mk]
-#align rat.coe_nat_eq_mk Rat.coe_nat_eq_divInt
+#print Rat.natCast_eq_divInt /-
+theorem natCast_eq_divInt (n : ℕ) : ↑n = n /. 1 := by rw [← Int.cast_natCast, coe_int_eq_mk]
+#align rat.coe_nat_eq_mk Rat.natCast_eq_divInt
-/
#print Rat.num_natCast /-
mathlib commit https://github.com/leanprover-community/mathlib/commit/65a1391a0106c9204fe45bc73a039f056558cb83
@@ -817,7 +817,7 @@ theorem coe_int_div_eq_divInt {n d : ℤ} : (n : ℚ) / ↑d = n /. d :=
#print Rat.num_div_den /-
@[simp]
theorem num_div_den (r : ℚ) : (r.num / r.den : ℚ) = r := by
- rw [← Int.cast_ofNat, ← mk_eq_div, num_denom]
+ rw [← Int.cast_natCast, ← mk_eq_div, num_denom]
#align rat.num_div_denom Rat.num_div_den
-/
@@ -840,19 +840,19 @@ instance canLift : CanLift ℚ ℤ coe fun q => q.den = 1 :=
-/
#print Rat.coe_nat_eq_divInt /-
-theorem coe_nat_eq_divInt (n : ℕ) : ↑n = n /. 1 := by rw [← Int.cast_ofNat, coe_int_eq_mk]
+theorem coe_nat_eq_divInt (n : ℕ) : ↑n = n /. 1 := by rw [← Int.cast_natCast, coe_int_eq_mk]
#align rat.coe_nat_eq_mk Rat.coe_nat_eq_divInt
-/
#print Rat.num_natCast /-
@[simp, norm_cast]
-theorem num_natCast (n : ℕ) : (n : ℚ).num = n := by rw [← Int.cast_ofNat, coe_int_num]
+theorem num_natCast (n : ℕ) : (n : ℚ).num = n := by rw [← Int.cast_natCast, coe_int_num]
#align rat.coe_nat_num Rat.num_natCast
-/
#print Rat.den_natCast /-
@[simp, norm_cast]
-theorem den_natCast (n : ℕ) : (n : ℚ).den = 1 := by rw [← Int.cast_ofNat, coe_int_denom]
+theorem den_natCast (n : ℕ) : (n : ℚ).den = 1 := by rw [← Int.cast_natCast, coe_int_denom]
#align rat.coe_nat_denom Rat.den_natCast
-/
mathlib commit https://github.com/leanprover-community/mathlib/commit/65a1391a0106c9204fe45bc73a039f056558cb83
@@ -7,8 +7,8 @@ import Data.Rat.Init
import Data.Int.Cast.Defs
import Data.Int.Dvd.Basic
import Algebra.Ring.Regular
-import Data.Nat.Gcd.Basic
-import Data.Pnat.Defs
+import Data.Nat.GCD.Basic
+import Data.PNat.Defs
#align_import data.rat.defs from "leanprover-community/mathlib"@"c3291da49cfa65f0d43b094750541c0731edc932"
@@ -90,7 +90,7 @@ def mkPnat (n : ℤ) : ℕ+ → ℚ
by
cases' Int.natAbs_eq n with e e <;> rw [e]; · rfl
rw [Int.neg_ediv_of_dvd, Int.natAbs_neg]; · rfl
- exact Int.coe_nat_dvd.2 (Nat.gcd_dvd_left _ _)
+ exact Int.natCast_dvd_natCast.2 (Nat.gcd_dvd_left _ _)
rw [this]
exact Nat.coprime_div_gcd_div_gcd (Nat.gcd_pos_of_pos_right _ dpos)⟩
#align rat.mk_pnat Rat.mkPnat
@@ -149,7 +149,7 @@ theorem zero_divInt (n) : 0 /. n = 0 := by cases n <;> simp [mk]
-/
private theorem gcd_abs_dvd_left {a b} : (Nat.gcd (Int.natAbs a) b : ℤ) ∣ a :=
- Int.dvd_natAbs.1 <| Int.coe_nat_dvd.2 <| Nat.gcd_dvd_left (Int.natAbs a) b
+ Int.dvd_natAbs.1 <| Int.natCast_dvd_natCast.2 <| Nat.gcd_dvd_left (Int.natAbs a) b
#print Rat.divInt_eq_zero /-
@[simp]
@@ -208,7 +208,7 @@ theorem divInt_eq_iff :
exact Nat.eq_mul_of_div_eq_left (dv.mul_left _) this.symm
have m0 : (a.nat_abs.gcd b * c.nat_abs.gcd d : ℤ) ≠ 0 :=
by
- refine' Int.coe_nat_ne_zero.2 (ne_of_gt _)
+ refine' Int.natCast_ne_zero.2 (ne_of_gt _)
apply mul_pos <;> apply Nat.gcd_pos_of_pos_right <;> assumption
apply mul_right_cancel₀ m0
simpa [mul_comm, mul_left_comm] using congr (congr_arg (· * ·) ha.symm) (congr_arg coe hb)
@@ -223,7 +223,7 @@ theorem divInt_eq_iff :
conv in c => rw [← Int.sign_mul_natAbs c]
rw [Int.mul_ediv_assoc, Int.mul_ediv_assoc]
exact ⟨congr (congr_arg (· * ·) hs) (congr_arg coe h₁), h₂⟩
- all_goals exact Int.coe_nat_dvd.2 (Nat.gcd_dvd_left _ _)
+ all_goals exact Int.natCast_dvd_natCast.2 (Nat.gcd_dvd_left _ _)
intro a c h
suffices bd : b / a.gcd b = d / c.gcd d
· refine' ⟨mul_left_cancel₀ hb.ne' _, bd⟩
@@ -520,7 +520,7 @@ protected theorem add_mul : (a + b) * c = a * c + b * c :=
numDenCasesOn' b fun n₂ d₂ h₂ =>
numDenCasesOn' c fun n₃ d₃ h₃ => by
simp [h₁, h₂, h₃, mul_ne_zero] <;>
- refine' (div_mk_div_cancel_left (Int.coe_nat_ne_zero.2 h₃)).symm.trans _ <;>
+ refine' (div_mk_div_cancel_left (Int.natCast_ne_zero.2 h₃)).symm.trans _ <;>
simp [mul_add, mul_comm, mul_assoc, mul_left_comm]
#align rat.add_mul Rat.add_mul
-/
mathlib commit https://github.com/leanprover-community/mathlib/commit/65a1391a0106c9204fe45bc73a039f056558cb83
@@ -161,8 +161,8 @@ theorem divInt_eq_zero {a b : ℤ} (b0 : b ≠ 0) : a /. b = 0 ↔ a = 0 :=
rintro a ⟨b, h⟩ e
injection e with e
apply Int.eq_mul_of_ediv_eq_right gcd_abs_dvd_left e
- cases' b with b <;> simp only [mk, mk_nat, Int.ofNat_eq_coe, dite_eq_left_iff] at h
- · simp only [mt (congr_arg Int.ofNat) b0, not_false_iff, forall_true_left] at h
+ cases' b with b <;> simp only [mk, mk_nat, Int.ofNat_eq_coe, dite_eq_left_iff] at h
+ · simp only [mt (congr_arg Int.ofNat) b0, not_false_iff, forall_true_left] at h
exact this h
· apply neg_injective; simp [this h]
#align rat.mk_eq_zero Rat.divInt_eq_zero
@@ -199,12 +199,12 @@ theorem divInt_eq_iff :
have ha := by
have dv := @gcd_abs_dvd_left
have := Int.eq_mul_of_ediv_eq_right dv ha
- rw [← Int.mul_ediv_assoc _ dv] at this
+ rw [← Int.mul_ediv_assoc _ dv] at this
exact Int.eq_mul_of_ediv_eq_left (dv.mul_left _) this.symm
have hb := by
have dv := fun {a b} => Nat.gcd_dvd_right (Int.natAbs a) b
have := Nat.eq_mul_of_div_eq_right dv hb
- rw [← Nat.mul_div_assoc _ dv] at this
+ rw [← Nat.mul_div_assoc _ dv] at this
exact Nat.eq_mul_of_div_eq_left (dv.mul_left _) this.symm
have m0 : (a.nat_abs.gcd b * c.nat_abs.gcd d : ℤ) ≠ 0 :=
by
@@ -218,7 +218,7 @@ theorem divInt_eq_iff :
h₁ h₂
have hs := congr_arg Int.sign h
simp [Int.sign_eq_one_of_pos (Int.ofNat_lt.2 hb),
- Int.sign_eq_one_of_pos (Int.ofNat_lt.2 hd)] at hs
+ Int.sign_eq_one_of_pos (Int.ofNat_lt.2 hd)] at hs
conv in a => rw [← Int.sign_mul_natAbs a]
conv in c => rw [← Int.sign_mul_natAbs c]
rw [Int.mul_ediv_assoc, Int.mul_ediv_assoc]
@@ -317,8 +317,8 @@ theorem lift_binop_eq (f : ℚ → ℚ → ℚ) (f₁ : ℤ → ℤ → ℤ →
f₁ n₁ d₁ n₂ d₂ * f₂ a b c d = f₁ a b c d * f₂ n₁ d₁ n₂ d₂) :
f (a /. b) (c /. d) = f₁ a b c d /. f₂ a b c d :=
by
- generalize ha : a /. b = x; cases' x with n₁ d₁ h₁ c₁; rw [num_denom'] at ha
- generalize hc : c /. d = x; cases' x with n₂ d₂ h₂ c₂; rw [num_denom'] at hc
+ generalize ha : a /. b = x; cases' x with n₁ d₁ h₁ c₁; rw [num_denom'] at ha
+ generalize hc : c /. d = x; cases' x with n₂ d₂ h₂ c₂; rw [num_denom'] at hc
rw [fv]
have d₁0 := ne_of_gt (Int.ofNat_lt.2 h₁)
have d₂0 := ne_of_gt (Int.ofNat_lt.2 h₂)
@@ -357,7 +357,7 @@ instance : Neg ℚ :=
theorem neg_def {a b : ℤ} : -(a /. b) = -a /. b :=
by
by_cases b0 : b = 0; · subst b0; simp; rfl
- generalize ha : a /. b = x; cases' x with n₁ d₁ h₁ c₁; rw [num_denom'] at ha
+ generalize ha : a /. b = x; cases' x with n₁ d₁ h₁ c₁; rw [num_denom'] at ha
show Rat.mk' _ _ _ _ = _; rw [num_denom']
have d0 := ne_of_gt (Int.ofNat_lt.2 h₁)
apply (mk_eq d0 b0).2; have h₁ := (mk_eq b0 d0).1 ha
@@ -414,7 +414,7 @@ theorem inv_def' {a b : ℤ} : (a /. b)⁻¹ = b /. a :=
by
by_cases a0 : a = 0; · subst a0; simp; rfl
by_cases b0 : b = 0; · subst b0; simp; rfl
- generalize ha : a /. b = x; cases' x with n d h c; rw [num_denom'] at ha
+ generalize ha : a /. b = x; cases' x with n d h c; rw [num_denom'] at ha
refine' Eq.trans (_ : Rat.inv ⟨n, d, h, c⟩ = d /. n) _
· cases' n with n <;> [cases' n with n; skip]
· rfl
@@ -423,7 +423,7 @@ theorem inv_def' {a b : ℤ} : (a /. b)⁻¹ = b /. a :=
· unfold Rat.inv; rw [num_denom']; rfl
have n0 : n ≠ 0 := by
rintro rfl
- rw [Rat.zero_divInt, mk_eq_zero b0] at ha
+ rw [Rat.zero_divInt, mk_eq_zero b0] at ha
exact a0 ha
have d0 := ne_of_gt (Int.ofNat_lt.2 h)
have ha := (mk_eq b0 d0).1 ha
mathlib commit https://github.com/leanprover-community/mathlib/commit/65a1391a0106c9204fe45bc73a039f056558cb83
@@ -844,16 +844,16 @@ theorem coe_nat_eq_divInt (n : ℕ) : ↑n = n /. 1 := by rw [← Int.cast_ofNat
#align rat.coe_nat_eq_mk Rat.coe_nat_eq_divInt
-/
-#print Rat.coe_nat_num /-
+#print Rat.num_natCast /-
@[simp, norm_cast]
-theorem coe_nat_num (n : ℕ) : (n : ℚ).num = n := by rw [← Int.cast_ofNat, coe_int_num]
-#align rat.coe_nat_num Rat.coe_nat_num
+theorem num_natCast (n : ℕ) : (n : ℚ).num = n := by rw [← Int.cast_ofNat, coe_int_num]
+#align rat.coe_nat_num Rat.num_natCast
-/
-#print Rat.coe_nat_den /-
+#print Rat.den_natCast /-
@[simp, norm_cast]
-theorem coe_nat_den (n : ℕ) : (n : ℚ).den = 1 := by rw [← Int.cast_ofNat, coe_int_denom]
-#align rat.coe_nat_denom Rat.coe_nat_den
+theorem den_natCast (n : ℕ) : (n : ℚ).den = 1 := by rw [← Int.cast_ofNat, coe_int_denom]
+#align rat.coe_nat_denom Rat.den_natCast
-/
#print Rat.coe_int_inj /-
mathlib commit https://github.com/leanprover-community/mathlib/commit/ce64cd319bb6b3e82f31c2d38e79080d377be451
@@ -3,12 +3,12 @@ Copyright (c) 2019 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Mario Carneiro
-/
-import Mathbin.Data.Rat.Init
-import Mathbin.Data.Int.Cast.Defs
-import Mathbin.Data.Int.Dvd.Basic
-import Mathbin.Algebra.Ring.Regular
-import Mathbin.Data.Nat.Gcd.Basic
-import Mathbin.Data.Pnat.Defs
+import Data.Rat.Init
+import Data.Int.Cast.Defs
+import Data.Int.Dvd.Basic
+import Algebra.Ring.Regular
+import Data.Nat.Gcd.Basic
+import Data.Pnat.Defs
#align_import data.rat.defs from "leanprover-community/mathlib"@"c3291da49cfa65f0d43b094750541c0731edc932"
mathlib commit https://github.com/leanprover-community/mathlib/commit/ce64cd319bb6b3e82f31c2d38e79080d377be451
@@ -281,7 +281,7 @@ theorem coe_int_eq_divInt (z : ℤ) : (z : ℚ) = z /. 1 :=
numbers of the form `n /. d` with `0 < d` and coprime `n`, `d`. -/
@[elab_as_elim]
def numDenCasesOn.{u} {C : ℚ → Sort u} :
- ∀ (a : ℚ) (H : ∀ n d, 0 < d → (Int.natAbs n).coprime d → C (n /. d)), C a
+ ∀ (a : ℚ) (H : ∀ n d, 0 < d → (Int.natAbs n).Coprime d → C (n /. d)), C a
| ⟨n, d, h, c⟩, H => by rw [num_denom'] <;> exact H n d h c
#align rat.num_denom_cases_on Rat.numDenCasesOn
-/
@@ -398,7 +398,7 @@ theorem mul_def' {a b c d : ℤ} (b0 : b ≠ 0) (d0 : d ≠ 0) : a /. b * (c /.
protected def inv : ℚ → ℚ
| ⟨(n + 1 : ℕ), d, h, c⟩ => ⟨d, n + 1, n.succ_pos, c.symm⟩
| ⟨0, d, h, c⟩ => 0
- | ⟨-[n+1], d, h, c⟩ => ⟨-d, n + 1, n.succ_pos, Nat.coprime.symm <| by simp <;> exact c⟩
+ | ⟨-[n+1], d, h, c⟩ => ⟨-d, n + 1, n.succ_pos, Nat.Coprime.symm <| by simp <;> exact c⟩
#align rat.inv Rat.inv
-/
mathlib commit https://github.com/leanprover-community/mathlib/commit/8ea5598db6caeddde6cb734aa179cc2408dbd345
@@ -2,11 +2,6 @@
Copyright (c) 2019 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Mario Carneiro
-
-! This file was ported from Lean 3 source module data.rat.defs
-! leanprover-community/mathlib commit c3291da49cfa65f0d43b094750541c0731edc932
-! Please do not edit these lines, except to modify the commit id
-! if you have ported upstream changes.
-/
import Mathbin.Data.Rat.Init
import Mathbin.Data.Int.Cast.Defs
@@ -15,6 +10,8 @@ import Mathbin.Algebra.Ring.Regular
import Mathbin.Data.Nat.Gcd.Basic
import Mathbin.Data.Pnat.Defs
+#align_import data.rat.defs from "leanprover-community/mathlib"@"c3291da49cfa65f0d43b094750541c0731edc932"
+
/-!
# Basics for the Rational Numbers
mathlib commit https://github.com/leanprover-community/mathlib/commit/9fb8964792b4237dac6200193a0d533f1b3f7423
@@ -112,7 +112,6 @@ def mk : ℤ → ℤ → ℚ
| n, -[d+1] => mkPnat (-n) d.succPNat
#align rat.mk Rat.mk
--- mathport name: rat.mk
scoped infixl:70 " /. " => Rat.mk
theorem mkPnat_eq (n d h) : mkPnat n ⟨d, h⟩ = n /. d := by
@@ -146,13 +145,16 @@ theorem zero_mkRat (n) : mkRat 0 n = 0 := by by_cases n = 0 <;> simp [*, mk_nat]
#align rat.zero_mk_nat Rat.zero_mkRat
-/
+#print Rat.zero_divInt /-
@[simp]
theorem zero_divInt (n) : 0 /. n = 0 := by cases n <;> simp [mk]
#align rat.zero_mk Rat.zero_divInt
+-/
private theorem gcd_abs_dvd_left {a b} : (Nat.gcd (Int.natAbs a) b : ℤ) ∣ a :=
Int.dvd_natAbs.1 <| Int.coe_nat_dvd.2 <| Nat.gcd_dvd_left (Int.natAbs a) b
+#print Rat.divInt_eq_zero /-
@[simp]
theorem divInt_eq_zero {a b : ℤ} (b0 : b ≠ 0) : a /. b = 0 ↔ a = 0 :=
by
@@ -167,11 +169,15 @@ theorem divInt_eq_zero {a b : ℤ} (b0 : b ≠ 0) : a /. b = 0 ↔ a = 0 :=
exact this h
· apply neg_injective; simp [this h]
#align rat.mk_eq_zero Rat.divInt_eq_zero
+-/
+#print Rat.divInt_ne_zero /-
theorem divInt_ne_zero {a b : ℤ} (b0 : b ≠ 0) : a /. b ≠ 0 ↔ a ≠ 0 :=
(divInt_eq_zero b0).Not
#align rat.mk_ne_zero Rat.divInt_ne_zero
+-/
+#print Rat.divInt_eq_iff /-
theorem divInt_eq_iff :
∀ {a b c d : ℤ} (hb : b ≠ 0) (hd : d ≠ 0), a /. b = c /. d ↔ a * d = c * b :=
by
@@ -243,13 +249,16 @@ theorem divInt_eq_iff :
rw [mul_comm, ← Nat.mul_div_assoc _ (Nat.gcd_dvd_left _ _), mul_comm, h,
Nat.mul_div_assoc _ (Nat.gcd_dvd_right _ _), mul_comm]
#align rat.mk_eq Rat.divInt_eq_iff
+-/
+#print Rat.divInt_mul_right /-
@[simp]
theorem divInt_mul_right {a b c : ℤ} (c0 : c ≠ 0) : a * c /. (b * c) = a /. b :=
by
by_cases b0 : b = 0; · subst b0; simp
apply (mk_eq (mul_ne_zero b0 c0) b0).2; simp [mul_comm, mul_assoc]
#align rat.div_mk_div_cancel_left Rat.divInt_mul_right
+-/
#print Rat.num_den /-
@[simp]
@@ -258,9 +267,11 @@ theorem num_den : ∀ {a : ℚ}, a.num /. a.den = a
#align rat.num_denom Rat.num_den
-/
+#print Rat.num_den' /-
theorem num_den' {n d h c} : (⟨n, d, h, c⟩ : ℚ) = n /. d :=
num_den.symm
#align rat.num_denom' Rat.num_den'
+-/
#print Rat.coe_int_eq_divInt /-
theorem coe_int_eq_divInt (z : ℤ) : (z : ℚ) = z /. 1 :=
@@ -297,6 +308,7 @@ protected def add : ℚ → ℚ → ℚ
instance : Add ℚ :=
⟨Rat.add⟩
+#print Rat.lift_binop_eq /-
theorem lift_binop_eq (f : ℚ → ℚ → ℚ) (f₁ : ℤ → ℤ → ℤ → ℤ → ℤ) (f₂ : ℤ → ℤ → ℤ → ℤ → ℤ)
(fv :
∀ {n₁ d₁ h₁ c₁ n₂ d₂ h₂ c₂},
@@ -315,7 +327,9 @@ theorem lift_binop_eq (f : ℚ → ℚ → ℚ) (f₁ : ℤ → ℤ → ℤ →
have d₂0 := ne_of_gt (Int.ofNat_lt.2 h₂)
exact (mk_eq (f0 d₁0 d₂0) (f0 b0 d0)).2 (H ((mk_eq b0 d₁0).1 ha) ((mk_eq d0 d₂0).1 hc))
#align rat.lift_binop_eq Rat.lift_binop_eq
+-/
+#print Rat.add_def'' /-
@[simp]
theorem add_def'' {a b c d : ℤ} (b0 : b ≠ 0) (d0 : d ≠ 0) :
a /. b + c /. d = (a * d + c * b) /. (b * d) :=
@@ -329,6 +343,7 @@ theorem add_def'' {a b c d : ℤ} (b0 : b ≠ 0) (d0 : d ≠ 0) :
_ = a * d₁ * d₂ * d + c * d₂ * (d₁ * b) := by rw [h₁, h₂]
_ = (a * d + c * b) * (d₁ * d₂) := by simp [mul_add, mul_comm, mul_left_comm]
#align rat.add_def Rat.add_def''
+-/
#print Rat.neg /-
/-- Negation of rational numbers. Use `-r` instead. -/
@@ -340,6 +355,7 @@ protected def neg (r : ℚ) : ℚ :=
instance : Neg ℚ :=
⟨Rat.neg⟩
+#print Rat.neg_def /-
@[simp]
theorem neg_def {a b : ℤ} : -(a /. b) = -a /. b :=
by
@@ -350,11 +366,14 @@ theorem neg_def {a b : ℤ} : -(a /. b) = -a /. b :=
apply (mk_eq d0 b0).2; have h₁ := (mk_eq b0 d0).1 ha
simp only [neg_mul, congr_arg Neg.neg h₁]
#align rat.neg_def Rat.neg_def
+-/
+#print Rat.divInt_neg_den /-
@[simp]
theorem divInt_neg_den (n d : ℤ) : n /. -d = -n /. d := by
by_cases hd : d = 0 <;> simp [Rat.divInt_eq_iff, hd]
#align rat.mk_neg_denom Rat.divInt_neg_den
+-/
#print Rat.mul /-
/-- Multiplication of rational numbers. Use `(*)` instead. -/
@@ -366,6 +385,7 @@ protected def mul : ℚ → ℚ → ℚ
instance : Mul ℚ :=
⟨Rat.mul⟩
+#print Rat.mul_def' /-
@[simp]
theorem mul_def' {a b c d : ℤ} (b0 : b ≠ 0) (d0 : d ≠ 0) : a /. b * (c /. d) = a * c /. (b * d) :=
by
@@ -374,6 +394,7 @@ theorem mul_def' {a b c d : ℤ} (b0 : b ≠ 0) (d0 : d ≠ 0) : a /. b * (c /.
· apply mul_ne_zero d₁0 d₂0
cc
#align rat.mul_def Rat.mul_def'
+-/
#print Rat.inv /-
/-- Inverse rational number. Use `r⁻¹` instead. -/
@@ -390,6 +411,7 @@ instance : Inv ℚ :=
instance : Div ℚ :=
⟨fun a b => a * b⁻¹⟩
+#print Rat.inv_def' /-
@[simp]
theorem inv_def' {a b : ℤ} : (a /. b)⁻¹ = b /. a :=
by
@@ -411,6 +433,7 @@ theorem inv_def' {a b : ℤ} : (a /. b)⁻¹ = b /. a :=
apply (mk_eq n0 a0).2
cc
#align rat.inv_def Rat.inv_def'
+-/
variable (a b c : ℚ)
@@ -636,9 +659,11 @@ theorem eq_iff_mul_eq_mul {p q : ℚ} : p = q ↔ p.num * q.den = q.num * p.den
#align rat.eq_iff_mul_eq_mul Rat.eq_iff_mul_eq_mul
-/
+#print Rat.sub_def'' /-
theorem sub_def'' {a b c d : ℤ} (b0 : b ≠ 0) (d0 : d ≠ 0) :
a /. b - c /. d = (a * d - c * b) /. (b * d) := by simp [b0, d0, sub_eq_add_neg]
#align rat.sub_def Rat.sub_def''
+-/
#print Rat.den_neg_eq_den /-
@[simp]
@@ -702,17 +727,23 @@ theorem den_one : (1 : ℚ).den = 1 :=
#align rat.denom_one Rat.den_one
-/
+#print Rat.mk_num_ne_zero_of_ne_zero /-
theorem mk_num_ne_zero_of_ne_zero {q : ℚ} {n d : ℤ} (hq : q ≠ 0) (hqnd : q = n /. d) : n ≠ 0 :=
fun this : n = 0 => hq <| by simpa [this] using hqnd
#align rat.mk_num_ne_zero_of_ne_zero Rat.mk_num_ne_zero_of_ne_zero
+-/
+#print Rat.mk_denom_ne_zero_of_ne_zero /-
theorem mk_denom_ne_zero_of_ne_zero {q : ℚ} {n d : ℤ} (hq : q ≠ 0) (hqnd : q = n /. d) : d ≠ 0 :=
fun this : d = 0 => hq <| by simpa [this] using hqnd
#align rat.mk_denom_ne_zero_of_ne_zero Rat.mk_denom_ne_zero_of_ne_zero
+-/
+#print Rat.divInt_ne_zero_of_ne_zero /-
theorem divInt_ne_zero_of_ne_zero {n d : ℤ} (h : n ≠ 0) (hd : d ≠ 0) : n /. d ≠ 0 :=
(divInt_ne_zero hd).mpr h
#align rat.mk_ne_zero_of_ne_zero Rat.divInt_ne_zero_of_ne_zero
+-/
#print Rat.mul_num_den /-
theorem mul_num_den (q r : ℚ) : q * r = q.num * r.num /. ↑(q.den * r.den) :=
@@ -725,6 +756,7 @@ theorem mul_num_den (q r : ℚ) : q * r = q.num * r.num /. ↑(q.den * r.den) :=
#align rat.mul_num_denom Rat.mul_num_den
-/
+#print Rat.div_num_den /-
theorem div_num_den (q r : ℚ) : q / r = q.num * r.den /. (q.den * r.num) :=
if hr : r.num = 0 then by
have hr' : r = 0 := zero_of_num_zero hr
@@ -736,20 +768,26 @@ theorem div_num_den (q r : ℚ) : q / r = q.num * r.den /. (q.den * r.num) :=
_ = q.num /. q.den * (r.den /. r.num) := by rw [inv_def]
_ = q.num * r.den /. (q.den * r.num) := mul_def' (by simpa using denom_ne_zero q) hr
#align rat.div_num_denom Rat.div_num_den
+-/
section Casts
+#print Rat.add_divInt /-
protected theorem add_divInt (a b c : ℤ) : (a + b) /. c = a /. c + b /. c :=
if h : c = 0 then by simp [h]
else by rw [add_def h h, mk_eq h (mul_ne_zero h h)]; simp [add_mul, mul_assoc]
#align rat.add_mk Rat.add_divInt
+-/
+#print Rat.divInt_eq_div /-
theorem divInt_eq_div (n d : ℤ) : n /. d = (n : ℚ) / d :=
by
by_cases d0 : d = 0; · simp [d0, div_zero]
simp [division_def, coe_int_eq_mk, mul_def one_ne_zero d0]
#align rat.mk_eq_div Rat.divInt_eq_div
+-/
+#print Rat.divInt_mul_divInt_cancel /-
theorem divInt_mul_divInt_cancel {x : ℤ} (hx : x ≠ 0) (n d : ℤ) : n /. x * (x /. d) = n /. d :=
by
by_cases hd : d = 0
@@ -757,25 +795,34 @@ theorem divInt_mul_divInt_cancel {x : ℤ} (hx : x ≠ 0) (n d : ℤ) : n /. x *
simp
rw [mul_def hx hd, mul_comm x, div_mk_div_cancel_left hx]
#align rat.mk_mul_mk_cancel Rat.divInt_mul_divInt_cancel
+-/
+#print Rat.divInt_div_divInt_cancel_left /-
theorem divInt_div_divInt_cancel_left {x : ℤ} (hx : x ≠ 0) (n d : ℤ) : n /. x / (d /. x) = n /. d :=
by rw [div_eq_mul_inv, inv_def, mk_mul_mk_cancel hx]
#align rat.mk_div_mk_cancel_left Rat.divInt_div_divInt_cancel_left
+-/
+#print Rat.divInt_div_divInt_cancel_right /-
theorem divInt_div_divInt_cancel_right {x : ℤ} (hx : x ≠ 0) (n d : ℤ) :
x /. n / (x /. d) = d /. n := by rw [div_eq_mul_inv, inv_def, mul_comm, mk_mul_mk_cancel hx]
#align rat.mk_div_mk_cancel_right Rat.divInt_div_divInt_cancel_right
+-/
+#print Rat.coe_int_div_eq_divInt /-
theorem coe_int_div_eq_divInt {n d : ℤ} : (n : ℚ) / ↑d = n /. d :=
by
repeat' rw [coe_int_eq_mk]
exact mk_div_mk_cancel_left one_ne_zero n d
#align rat.coe_int_div_eq_mk Rat.coe_int_div_eq_divInt
+-/
+#print Rat.num_div_den /-
@[simp]
theorem num_div_den (r : ℚ) : (r.num / r.den : ℚ) = r := by
rw [← Int.cast_ofNat, ← mk_eq_div, num_denom]
#align rat.num_div_denom Rat.num_div_den
+-/
#print Rat.coe_int_num_of_den_eq_one /-
theorem coe_int_num_of_den_eq_one {q : ℚ} (hq : q.den = 1) : ↑q.num = q := by
@@ -795,16 +842,22 @@ instance canLift : CanLift ℚ ℤ coe fun q => q.den = 1 :=
#align rat.can_lift Rat.canLift
-/
+#print Rat.coe_nat_eq_divInt /-
theorem coe_nat_eq_divInt (n : ℕ) : ↑n = n /. 1 := by rw [← Int.cast_ofNat, coe_int_eq_mk]
#align rat.coe_nat_eq_mk Rat.coe_nat_eq_divInt
+-/
+#print Rat.coe_nat_num /-
@[simp, norm_cast]
theorem coe_nat_num (n : ℕ) : (n : ℚ).num = n := by rw [← Int.cast_ofNat, coe_int_num]
#align rat.coe_nat_num Rat.coe_nat_num
+-/
+#print Rat.coe_nat_den /-
@[simp, norm_cast]
theorem coe_nat_den (n : ℕ) : (n : ℚ).den = 1 := by rw [← Int.cast_ofNat, coe_int_denom]
#align rat.coe_nat_denom Rat.coe_nat_den
+-/
#print Rat.coe_int_inj /-
-- Will be subsumed by `int.coe_inj` after we have defined
mathlib commit https://github.com/leanprover-community/mathlib/commit/7e5137f579de09a059a5ce98f364a04e221aabf0
@@ -328,7 +328,6 @@ theorem add_def'' {a b c d : ℤ} (b0 : b ≠ 0) (d0 : d ≠ 0) :
simp [mul_add, mul_comm, mul_left_comm]
_ = a * d₁ * d₂ * d + c * d₂ * (d₁ * b) := by rw [h₁, h₂]
_ = (a * d + c * b) * (d₁ * d₂) := by simp [mul_add, mul_comm, mul_left_comm]
-
#align rat.add_def Rat.add_def''
#print Rat.neg /-
@@ -736,7 +735,6 @@ theorem div_num_den (q r : ℚ) : q / r = q.num * r.den /. (q.den * r.num) :=
_ = q.num /. q.den * (r.num /. r.den)⁻¹ := by simp
_ = q.num /. q.den * (r.den /. r.num) := by rw [inv_def]
_ = q.num * r.den /. (q.den * r.num) := mul_def' (by simpa using denom_ne_zero q) hr
-
#align rat.div_num_denom Rat.div_num_den
section Casts
mathlib commit https://github.com/leanprover-community/mathlib/commit/cca40788df1b8755d5baf17ab2f27dacc2e17acb
@@ -162,8 +162,8 @@ theorem divInt_eq_zero {a b : ℤ} (b0 : b ≠ 0) : a /. b = 0 ↔ a = 0 :=
rintro a ⟨b, h⟩ e
injection e with e
apply Int.eq_mul_of_ediv_eq_right gcd_abs_dvd_left e
- cases' b with b <;> simp only [mk, mk_nat, Int.ofNat_eq_coe, dite_eq_left_iff] at h
- · simp only [mt (congr_arg Int.ofNat) b0, not_false_iff, forall_true_left] at h
+ cases' b with b <;> simp only [mk, mk_nat, Int.ofNat_eq_coe, dite_eq_left_iff] at h
+ · simp only [mt (congr_arg Int.ofNat) b0, not_false_iff, forall_true_left] at h
exact this h
· apply neg_injective; simp [this h]
#align rat.mk_eq_zero Rat.divInt_eq_zero
@@ -177,7 +177,7 @@ theorem divInt_eq_iff :
by
suffices ∀ a b c d hb hd, mkPnat a ⟨b, hb⟩ = mkPnat c ⟨d, hd⟩ ↔ a * d = c * b
by
- intros ; cases' b with b b <;> simp [mk, mk_nat, Nat.succPNat]
+ intros; cases' b with b b <;> simp [mk, mk_nat, Nat.succPNat]
simp [mt (congr_arg Int.ofNat) hb]
all_goals
cases' d with d d <;> simp [mk, mk_nat, Nat.succPNat]
@@ -191,17 +191,17 @@ theorem divInt_eq_iff :
constructor <;> intro h <;> apply neg_injective <;> simpa [left_distrib, eq_comm] using h
· change -a * d.succ = -c * b.succ ↔ a * -d.succ = c * -b.succ
simp [left_distrib, sub_eq_add_neg]; cc
- intros ; simp [mk_pnat]; constructor <;> intro h
+ intros; simp [mk_pnat]; constructor <;> intro h
· cases' h with ha hb
have ha := by
have dv := @gcd_abs_dvd_left
have := Int.eq_mul_of_ediv_eq_right dv ha
- rw [← Int.mul_ediv_assoc _ dv] at this
+ rw [← Int.mul_ediv_assoc _ dv] at this
exact Int.eq_mul_of_ediv_eq_left (dv.mul_left _) this.symm
have hb := by
have dv := fun {a b} => Nat.gcd_dvd_right (Int.natAbs a) b
have := Nat.eq_mul_of_div_eq_right dv hb
- rw [← Nat.mul_div_assoc _ dv] at this
+ rw [← Nat.mul_div_assoc _ dv] at this
exact Nat.eq_mul_of_div_eq_left (dv.mul_left _) this.symm
have m0 : (a.nat_abs.gcd b * c.nat_abs.gcd d : ℤ) ≠ 0 :=
by
@@ -215,7 +215,7 @@ theorem divInt_eq_iff :
h₁ h₂
have hs := congr_arg Int.sign h
simp [Int.sign_eq_one_of_pos (Int.ofNat_lt.2 hb),
- Int.sign_eq_one_of_pos (Int.ofNat_lt.2 hd)] at hs
+ Int.sign_eq_one_of_pos (Int.ofNat_lt.2 hd)] at hs
conv in a => rw [← Int.sign_mul_natAbs a]
conv in c => rw [← Int.sign_mul_natAbs c]
rw [Int.mul_ediv_assoc, Int.mul_ediv_assoc]
@@ -308,8 +308,8 @@ theorem lift_binop_eq (f : ℚ → ℚ → ℚ) (f₁ : ℤ → ℤ → ℤ →
f₁ n₁ d₁ n₂ d₂ * f₂ a b c d = f₁ a b c d * f₂ n₁ d₁ n₂ d₂) :
f (a /. b) (c /. d) = f₁ a b c d /. f₂ a b c d :=
by
- generalize ha : a /. b = x; cases' x with n₁ d₁ h₁ c₁; rw [num_denom'] at ha
- generalize hc : c /. d = x; cases' x with n₂ d₂ h₂ c₂; rw [num_denom'] at hc
+ generalize ha : a /. b = x; cases' x with n₁ d₁ h₁ c₁; rw [num_denom'] at ha
+ generalize hc : c /. d = x; cases' x with n₂ d₂ h₂ c₂; rw [num_denom'] at hc
rw [fv]
have d₁0 := ne_of_gt (Int.ofNat_lt.2 h₁)
have d₂0 := ne_of_gt (Int.ofNat_lt.2 h₂)
@@ -345,7 +345,7 @@ instance : Neg ℚ :=
theorem neg_def {a b : ℤ} : -(a /. b) = -a /. b :=
by
by_cases b0 : b = 0; · subst b0; simp; rfl
- generalize ha : a /. b = x; cases' x with n₁ d₁ h₁ c₁; rw [num_denom'] at ha
+ generalize ha : a /. b = x; cases' x with n₁ d₁ h₁ c₁; rw [num_denom'] at ha
show Rat.mk' _ _ _ _ = _; rw [num_denom']
have d0 := ne_of_gt (Int.ofNat_lt.2 h₁)
apply (mk_eq d0 b0).2; have h₁ := (mk_eq b0 d0).1 ha
@@ -396,16 +396,16 @@ theorem inv_def' {a b : ℤ} : (a /. b)⁻¹ = b /. a :=
by
by_cases a0 : a = 0; · subst a0; simp; rfl
by_cases b0 : b = 0; · subst b0; simp; rfl
- generalize ha : a /. b = x; cases' x with n d h c; rw [num_denom'] at ha
+ generalize ha : a /. b = x; cases' x with n d h c; rw [num_denom'] at ha
refine' Eq.trans (_ : Rat.inv ⟨n, d, h, c⟩ = d /. n) _
- · cases' n with n <;> [cases' n with n;skip]
+ · cases' n with n <;> [cases' n with n; skip]
· rfl
· change Int.ofNat n.succ with (n + 1 : ℕ)
unfold Rat.inv; rw [num_denom']
· unfold Rat.inv; rw [num_denom']; rfl
have n0 : n ≠ 0 := by
rintro rfl
- rw [Rat.zero_divInt, mk_eq_zero b0] at ha
+ rw [Rat.zero_divInt, mk_eq_zero b0] at ha
exact a0 ha
have d0 := ne_of_gt (Int.ofNat_lt.2 h)
have ha := (mk_eq b0 d0).1 ha
mathlib commit https://github.com/leanprover-community/mathlib/commit/cca40788df1b8755d5baf17ab2f27dacc2e17acb
@@ -80,10 +80,8 @@ instance : One ℚ :=
instance : Inhabited ℚ :=
⟨0⟩
-/- warning: rat.mk_pnat clashes with [anonymous] -> [anonymous]
-Case conversion may be inaccurate. Consider using '#align rat.mk_pnat [anonymous]ₓ'. -/
/-- Form the quotient `n / d` where `n:ℤ` and `d:ℕ+` (not necessarily coprime) -/
-def [anonymous] (n : ℤ) : ℕ+ → ℚ
+def mkPnat (n : ℤ) : ℕ+ → ℚ
| ⟨d, dpos⟩ =>
let n' := n.natAbs
let g := n'.gcd d
@@ -98,49 +96,49 @@ def [anonymous] (n : ℤ) : ℕ+ → ℚ
exact Int.coe_nat_dvd.2 (Nat.gcd_dvd_left _ _)
rw [this]
exact Nat.coprime_div_gcd_div_gcd (Nat.gcd_pos_of_pos_right _ dpos)⟩
-#align rat.mk_pnat [anonymous]
+#align rat.mk_pnat Rat.mkPnat
#print mkRat /-
/-- Form the quotient `n / d` where `n:ℤ` and `d:ℕ`. In the case `d = 0`, we
define `n / 0 = 0` by convention. -/
def mkRat (n : ℤ) (d : ℕ) : ℚ :=
- if d0 : d = 0 then 0 else [anonymous] n ⟨d, Nat.pos_of_ne_zero d0⟩
+ if d0 : d = 0 then 0 else mkPnat n ⟨d, Nat.pos_of_ne_zero d0⟩
#align rat.mk_nat mkRat
-/
/-- Form the quotient `n / d` where `n d : ℤ`. -/
def mk : ℤ → ℤ → ℚ
| n, (d : ℕ) => mkRat n d
- | n, -[d+1] => [anonymous] (-n) d.succPNat
+ | n, -[d+1] => mkPnat (-n) d.succPNat
#align rat.mk Rat.mk
-- mathport name: rat.mk
scoped infixl:70 " /. " => Rat.mk
-/- warning: rat.mk_pnat_eq clashes with [anonymous] -> [anonymous]
-Case conversion may be inaccurate. Consider using '#align rat.mk_pnat_eq [anonymous]ₓ'. -/
-theorem [anonymous] (n d h) : [anonymous] n ⟨d, h⟩ = n /. d := by
+theorem mkPnat_eq (n d h) : mkPnat n ⟨d, h⟩ = n /. d := by
change n /. d with dite _ _ _ <;> simp [ne_of_gt h]
-#align rat.mk_pnat_eq [anonymous]
+#align rat.mk_pnat_eq Rat.mkPnat_eq
+#print Rat.mkRat_eq /-
theorem mkRat_eq (n d) : mkRat n d = n /. d :=
rfl
#align rat.mk_nat_eq Rat.mkRat_eq
+-/
+#print Rat.divInt_zero /-
@[simp]
theorem divInt_zero (n) : n /. 0 = 0 :=
rfl
#align rat.mk_zero Rat.divInt_zero
+-/
-/- warning: rat.zero_mk_pnat clashes with [anonymous] -> [anonymous]
-Case conversion may be inaccurate. Consider using '#align rat.zero_mk_pnat [anonymous]ₓ'. -/
@[simp]
-theorem [anonymous] (n) : [anonymous] 0 n = 0 :=
+theorem zero_mkPnat (n) : mkPnat 0 n = 0 :=
by
cases' n with n npos
simp only [mk_pnat, Int.natAbs_zero, Nat.div_self npos, Nat.gcd_zero_left, Int.zero_div]
rfl
-#align rat.zero_mk_pnat [anonymous]
+#align rat.zero_mk_pnat Rat.zero_mkPnat
#print Rat.zero_mkRat /-
@[simp]
@@ -177,7 +175,7 @@ theorem divInt_ne_zero {a b : ℤ} (b0 : b ≠ 0) : a /. b ≠ 0 ↔ a ≠ 0 :=
theorem divInt_eq_iff :
∀ {a b c d : ℤ} (hb : b ≠ 0) (hd : d ≠ 0), a /. b = c /. d ↔ a * d = c * b :=
by
- suffices ∀ a b c d hb hd, [anonymous] a ⟨b, hb⟩ = [anonymous] c ⟨d, hd⟩ ↔ a * d = c * b
+ suffices ∀ a b c d hb hd, mkPnat a ⟨b, hb⟩ = mkPnat c ⟨d, hd⟩ ↔ a * d = c * b
by
intros ; cases' b with b b <;> simp [mk, mk_nat, Nat.succPNat]
simp [mt (congr_arg Int.ofNat) hb]
@@ -253,19 +251,24 @@ theorem divInt_mul_right {a b c : ℤ} (c0 : c ≠ 0) : a * c /. (b * c) = a /.
apply (mk_eq (mul_ne_zero b0 c0) b0).2; simp [mul_comm, mul_assoc]
#align rat.div_mk_div_cancel_left Rat.divInt_mul_right
+#print Rat.num_den /-
@[simp]
theorem num_den : ∀ {a : ℚ}, a.num /. a.den = a
| ⟨n, d, h, (c : _ = 1)⟩ => show mkRat n d = _ by simp [mk_nat, ne_of_gt h, mk_pnat, c]
#align rat.num_denom Rat.num_den
+-/
theorem num_den' {n d h c} : (⟨n, d, h, c⟩ : ℚ) = n /. d :=
num_den.symm
#align rat.num_denom' Rat.num_den'
+#print Rat.coe_int_eq_divInt /-
theorem coe_int_eq_divInt (z : ℤ) : (z : ℚ) = z /. 1 :=
num_den'
#align rat.coe_int_eq_mk Rat.coe_int_eq_divInt
+-/
+#print Rat.numDenCasesOn /-
/-- Define a (dependent) function or prove `∀ r : ℚ, p r` by dealing with rational
numbers of the form `n /. d` with `0 < d` and coprime `n`, `d`. -/
@[elab_as_elim]
@@ -273,18 +276,21 @@ def numDenCasesOn.{u} {C : ℚ → Sort u} :
∀ (a : ℚ) (H : ∀ n d, 0 < d → (Int.natAbs n).coprime d → C (n /. d)), C a
| ⟨n, d, h, c⟩, H => by rw [num_denom'] <;> exact H n d h c
#align rat.num_denom_cases_on Rat.numDenCasesOn
+-/
+#print Rat.numDenCasesOn' /-
/-- Define a (dependent) function or prove `∀ r : ℚ, p r` by dealing with rational
numbers of the form `n /. d` with `d ≠ 0`. -/
@[elab_as_elim]
def numDenCasesOn'.{u} {C : ℚ → Sort u} (a : ℚ) (H : ∀ (n : ℤ) (d : ℕ), d ≠ 0 → C (n /. d)) : C a :=
numDenCasesOn a fun n d h c => H n d h.ne'
#align rat.num_denom_cases_on' Rat.numDenCasesOn'
+-/
#print Rat.add /-
/-- Addition of rational numbers. Use `(+)` instead. -/
protected def add : ℚ → ℚ → ℚ
- | ⟨n₁, d₁, h₁, c₁⟩, ⟨n₂, d₂, h₂, c₂⟩ => [anonymous] (n₁ * d₂ + n₂ * d₁) ⟨d₁ * d₂, mul_pos h₁ h₂⟩
+ | ⟨n₁, d₁, h₁, c₁⟩, ⟨n₂, d₂, h₂, c₂⟩ => mkPnat (n₁ * d₂ + n₂ * d₁) ⟨d₁ * d₂, mul_pos h₁ h₂⟩
#align rat.add Rat.add
-/
@@ -354,7 +360,7 @@ theorem divInt_neg_den (n d : ℤ) : n /. -d = -n /. d := by
#print Rat.mul /-
/-- Multiplication of rational numbers. Use `(*)` instead. -/
protected def mul : ℚ → ℚ → ℚ
- | ⟨n₁, d₁, h₁, c₁⟩, ⟨n₂, d₂, h₂, c₂⟩ => [anonymous] (n₁ * n₂) ⟨d₁ * d₂, mul_pos h₁ h₂⟩
+ | ⟨n₁, d₁, h₁, c₁⟩, ⟨n₂, d₂, h₂, c₂⟩ => mkPnat (n₁ * n₂) ⟨d₁ * d₂, mul_pos h₁ h₂⟩
#align rat.mul Rat.mul
-/
@@ -442,20 +448,26 @@ protected theorem add_left_neg : -a + a = 0 :=
#align rat.add_left_neg Rat.add_left_neg
-/
+#print Rat.divInt_zero_one /-
@[simp]
theorem divInt_zero_one : 0 /. 1 = 0 :=
- show [anonymous] _ _ = _ by rw [mk_pnat]; simp; rfl
+ show mkPnat _ _ = _ by rw [mk_pnat]; simp; rfl
#align rat.mk_zero_one Rat.divInt_zero_one
+-/
+#print Rat.divInt_one_one /-
@[simp]
theorem divInt_one_one : 1 /. 1 = 1 :=
- show [anonymous] _ _ = _ by rw [mk_pnat]; simp; rfl
+ show mkPnat _ _ = _ by rw [mk_pnat]; simp; rfl
#align rat.mk_one_one Rat.divInt_one_one
+-/
+#print Rat.divInt_neg_one_one /-
@[simp]
theorem divInt_neg_one_one : -1 /. 1 = -1 :=
- show [anonymous] _ _ = _ by rw [mk_pnat]; simp; rfl
+ show mkPnat _ _ = _ by rw [mk_pnat]; simp; rfl
#align rat.mk_neg_one_one Rat.divInt_neg_one_one
+-/
#print Rat.mul_one /-
protected theorem mul_one : a * 1 = a :=
@@ -703,6 +715,7 @@ theorem divInt_ne_zero_of_ne_zero {n d : ℤ} (h : n ≠ 0) (hd : d ≠ 0) : n /
(divInt_ne_zero hd).mpr h
#align rat.mk_ne_zero_of_ne_zero Rat.divInt_ne_zero_of_ne_zero
+#print Rat.mul_num_den /-
theorem mul_num_den (q r : ℚ) : q * r = q.num * r.num /. ↑(q.den * r.den) :=
by
have hq' : (↑q.den : ℤ) ≠ 0 := by have := denom_ne_zero q <;> simpa
@@ -711,6 +724,7 @@ theorem mul_num_den (q r : ℚ) : q * r = q.num * r.num /. ↑(q.den * r.den) :=
simpa using this
simp [mul_def hq' hr', -num_denom]
#align rat.mul_num_denom Rat.mul_num_den
+-/
theorem div_num_den (q r : ℚ) : q / r = q.num * r.den /. (q.den * r.num) :=
if hr : r.num = 0 then by
mathlib commit https://github.com/leanprover-community/mathlib/commit/917c3c072e487b3cccdbfeff17e75b40e45f66cb
@@ -81,11 +81,6 @@ instance : Inhabited ℚ :=
⟨0⟩
/- warning: rat.mk_pnat clashes with [anonymous] -> [anonymous]
-warning: rat.mk_pnat -> [anonymous] is a dubious translation:
-lean 3 declaration is
- Int -> PNat -> Rat
-but is expected to have type
- forall {n : Type.{u}} {ᾰ : Type.{v}}, (Nat -> n -> ᾰ) -> Nat -> (List.{u} n) -> (List.{v} ᾰ)
Case conversion may be inaccurate. Consider using '#align rat.mk_pnat [anonymous]ₓ'. -/
/-- Form the quotient `n / d` where `n:ℤ` and `d:ℕ+` (not necessarily coprime) -/
def [anonymous] (n : ℤ) : ℕ+ → ℚ
@@ -123,43 +118,21 @@ def mk : ℤ → ℤ → ℚ
scoped infixl:70 " /. " => Rat.mk
/- warning: rat.mk_pnat_eq clashes with [anonymous] -> [anonymous]
-warning: rat.mk_pnat_eq -> [anonymous] is a dubious translation:
-lean 3 declaration is
- forall (n : Int) (d : Nat) (h : LT.lt.{0} Nat Nat.hasLt (OfNat.ofNat.{0} Nat 0 (OfNat.mk.{0} Nat 0 (Zero.zero.{0} Nat Nat.hasZero))) d), Eq.{1} Rat ([anonymous] n (Subtype.mk.{1} Nat (fun (n : Nat) => LT.lt.{0} Nat Nat.hasLt (OfNat.ofNat.{0} Nat 0 (OfNat.mk.{0} Nat 0 (Zero.zero.{0} Nat Nat.hasZero))) n) d h)) (Rat.mk n ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Nat Int (HasLiftT.mk.{1, 1} Nat Int (CoeTCₓ.coe.{1, 1} Nat Int (coeBase.{1, 1} Nat Int Int.hasCoe))) d))
-but is expected to have type
- forall {n : Type.{u}} {d : Type.{v}}, (Nat -> n -> d) -> Nat -> (List.{u} n) -> (List.{v} d)
Case conversion may be inaccurate. Consider using '#align rat.mk_pnat_eq [anonymous]ₓ'. -/
theorem [anonymous] (n d h) : [anonymous] n ⟨d, h⟩ = n /. d := by
change n /. d with dite _ _ _ <;> simp [ne_of_gt h]
#align rat.mk_pnat_eq [anonymous]
-/- warning: rat.mk_nat_eq -> Rat.mkRat_eq is a dubious translation:
-lean 3 declaration is
- forall (n : Int) (d : Nat), Eq.{1} Rat (mkRat n d) (Rat.mk n ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Nat Int (HasLiftT.mk.{1, 1} Nat Int (CoeTCₓ.coe.{1, 1} Nat Int (coeBase.{1, 1} Nat Int Int.hasCoe))) d))
-but is expected to have type
- forall (n : Int) (d : Nat), Eq.{1} Rat (mkRat n d) (Rat.divInt n (Nat.cast.{0} Int instNatCastInt d))
-Case conversion may be inaccurate. Consider using '#align rat.mk_nat_eq Rat.mkRat_eqₓ'. -/
theorem mkRat_eq (n d) : mkRat n d = n /. d :=
rfl
#align rat.mk_nat_eq Rat.mkRat_eq
-/- warning: rat.mk_zero -> Rat.divInt_zero is a dubious translation:
-lean 3 declaration is
- forall (n : Int), Eq.{1} Rat (Rat.mk n (OfNat.ofNat.{0} Int 0 (OfNat.mk.{0} Int 0 (Zero.zero.{0} Int Int.hasZero)))) (OfNat.ofNat.{0} Rat 0 (OfNat.mk.{0} Rat 0 (Zero.zero.{0} Rat Rat.hasZero)))
-but is expected to have type
- forall (n : Int), Eq.{1} Rat (Rat.divInt n (OfNat.ofNat.{0} Int 0 (instOfNatInt 0))) (OfNat.ofNat.{0} Rat 0 (Rat.instOfNatRat 0))
-Case conversion may be inaccurate. Consider using '#align rat.mk_zero Rat.divInt_zeroₓ'. -/
@[simp]
theorem divInt_zero (n) : n /. 0 = 0 :=
rfl
#align rat.mk_zero Rat.divInt_zero
/- warning: rat.zero_mk_pnat clashes with [anonymous] -> [anonymous]
-warning: rat.zero_mk_pnat -> [anonymous] is a dubious translation:
-lean 3 declaration is
- forall (n : PNat), Eq.{1} Rat ([anonymous] (OfNat.ofNat.{0} Int 0 (OfNat.mk.{0} Int 0 (Zero.zero.{0} Int Int.hasZero))) n) (OfNat.ofNat.{0} Rat 0 (OfNat.mk.{0} Rat 0 (Zero.zero.{0} Rat Rat.hasZero)))
-but is expected to have type
- forall {n : Type.{u}} {β : Type.{v}}, (Nat -> n -> β) -> Nat -> (List.{u} n) -> (List.{v} β)
Case conversion may be inaccurate. Consider using '#align rat.zero_mk_pnat [anonymous]ₓ'. -/
@[simp]
theorem [anonymous] (n) : [anonymous] 0 n = 0 :=
@@ -175,12 +148,6 @@ theorem zero_mkRat (n) : mkRat 0 n = 0 := by by_cases n = 0 <;> simp [*, mk_nat]
#align rat.zero_mk_nat Rat.zero_mkRat
-/
-/- warning: rat.zero_mk -> Rat.zero_divInt is a dubious translation:
-lean 3 declaration is
- forall (n : Int), Eq.{1} Rat (Rat.mk (OfNat.ofNat.{0} Int 0 (OfNat.mk.{0} Int 0 (Zero.zero.{0} Int Int.hasZero))) n) (OfNat.ofNat.{0} Rat 0 (OfNat.mk.{0} Rat 0 (Zero.zero.{0} Rat Rat.hasZero)))
-but is expected to have type
- forall (n : Int), Eq.{1} Rat (Rat.divInt (OfNat.ofNat.{0} Int 0 (instOfNatInt 0)) n) (OfNat.ofNat.{0} Rat 0 (Rat.instOfNatRat 0))
-Case conversion may be inaccurate. Consider using '#align rat.zero_mk Rat.zero_divIntₓ'. -/
@[simp]
theorem zero_divInt (n) : 0 /. n = 0 := by cases n <;> simp [mk]
#align rat.zero_mk Rat.zero_divInt
@@ -188,12 +155,6 @@ theorem zero_divInt (n) : 0 /. n = 0 := by cases n <;> simp [mk]
private theorem gcd_abs_dvd_left {a b} : (Nat.gcd (Int.natAbs a) b : ℤ) ∣ a :=
Int.dvd_natAbs.1 <| Int.coe_nat_dvd.2 <| Nat.gcd_dvd_left (Int.natAbs a) b
-/- warning: rat.mk_eq_zero -> Rat.divInt_eq_zero is a dubious translation:
-lean 3 declaration is
- forall {a : Int} {b : Int}, (Ne.{1} Int b (OfNat.ofNat.{0} Int 0 (OfNat.mk.{0} Int 0 (Zero.zero.{0} Int Int.hasZero)))) -> (Iff (Eq.{1} Rat (Rat.mk a b) (OfNat.ofNat.{0} Rat 0 (OfNat.mk.{0} Rat 0 (Zero.zero.{0} Rat Rat.hasZero)))) (Eq.{1} Int a (OfNat.ofNat.{0} Int 0 (OfNat.mk.{0} Int 0 (Zero.zero.{0} Int Int.hasZero)))))
-but is expected to have type
- forall {a : Int} {b : Int}, (Ne.{1} Int b (OfNat.ofNat.{0} Int 0 (instOfNatInt 0))) -> (Iff (Eq.{1} Rat (Rat.divInt a b) (OfNat.ofNat.{0} Rat 0 (Rat.instOfNatRat 0))) (Eq.{1} Int a (OfNat.ofNat.{0} Int 0 (instOfNatInt 0))))
-Case conversion may be inaccurate. Consider using '#align rat.mk_eq_zero Rat.divInt_eq_zeroₓ'. -/
@[simp]
theorem divInt_eq_zero {a b : ℤ} (b0 : b ≠ 0) : a /. b = 0 ↔ a = 0 :=
by
@@ -209,22 +170,10 @@ theorem divInt_eq_zero {a b : ℤ} (b0 : b ≠ 0) : a /. b = 0 ↔ a = 0 :=
· apply neg_injective; simp [this h]
#align rat.mk_eq_zero Rat.divInt_eq_zero
-/- warning: rat.mk_ne_zero -> Rat.divInt_ne_zero is a dubious translation:
-lean 3 declaration is
- forall {a : Int} {b : Int}, (Ne.{1} Int b (OfNat.ofNat.{0} Int 0 (OfNat.mk.{0} Int 0 (Zero.zero.{0} Int Int.hasZero)))) -> (Iff (Ne.{1} Rat (Rat.mk a b) (OfNat.ofNat.{0} Rat 0 (OfNat.mk.{0} Rat 0 (Zero.zero.{0} Rat Rat.hasZero)))) (Ne.{1} Int a (OfNat.ofNat.{0} Int 0 (OfNat.mk.{0} Int 0 (Zero.zero.{0} Int Int.hasZero)))))
-but is expected to have type
- forall {a : Int} {b : Int}, (Ne.{1} Int b (OfNat.ofNat.{0} Int 0 (instOfNatInt 0))) -> (Iff (Ne.{1} Rat (Rat.divInt a b) (OfNat.ofNat.{0} Rat 0 (Rat.instOfNatRat 0))) (Ne.{1} Int a (OfNat.ofNat.{0} Int 0 (instOfNatInt 0))))
-Case conversion may be inaccurate. Consider using '#align rat.mk_ne_zero Rat.divInt_ne_zeroₓ'. -/
theorem divInt_ne_zero {a b : ℤ} (b0 : b ≠ 0) : a /. b ≠ 0 ↔ a ≠ 0 :=
(divInt_eq_zero b0).Not
#align rat.mk_ne_zero Rat.divInt_ne_zero
-/- warning: rat.mk_eq -> Rat.divInt_eq_iff is a dubious translation:
-lean 3 declaration is
- forall {a : Int} {b : Int} {c : Int} {d : Int}, (Ne.{1} Int b (OfNat.ofNat.{0} Int 0 (OfNat.mk.{0} Int 0 (Zero.zero.{0} Int Int.hasZero)))) -> (Ne.{1} Int d (OfNat.ofNat.{0} Int 0 (OfNat.mk.{0} Int 0 (Zero.zero.{0} Int Int.hasZero)))) -> (Iff (Eq.{1} Rat (Rat.mk a b) (Rat.mk c d)) (Eq.{1} Int (HMul.hMul.{0, 0, 0} Int Int Int (instHMul.{0} Int Int.hasMul) a d) (HMul.hMul.{0, 0, 0} Int Int Int (instHMul.{0} Int Int.hasMul) c b)))
-but is expected to have type
- forall {a : Int} {b : Int} {c : Int} {d : Int}, (Ne.{1} Int a (OfNat.ofNat.{0} Int 0 (instOfNatInt 0))) -> (Ne.{1} Int b (OfNat.ofNat.{0} Int 0 (instOfNatInt 0))) -> (Iff (Eq.{1} Rat (Rat.divInt c a) (Rat.divInt d b)) (Eq.{1} Int (HMul.hMul.{0, 0, 0} Int Int Int (instHMul.{0} Int Int.instMulInt) c b) (HMul.hMul.{0, 0, 0} Int Int Int (instHMul.{0} Int Int.instMulInt) d a)))
-Case conversion may be inaccurate. Consider using '#align rat.mk_eq Rat.divInt_eq_iffₓ'. -/
theorem divInt_eq_iff :
∀ {a b c d : ℤ} (hb : b ≠ 0) (hd : d ≠ 0), a /. b = c /. d ↔ a * d = c * b :=
by
@@ -297,12 +246,6 @@ theorem divInt_eq_iff :
Nat.mul_div_assoc _ (Nat.gcd_dvd_right _ _), mul_comm]
#align rat.mk_eq Rat.divInt_eq_iff
-/- warning: rat.div_mk_div_cancel_left -> Rat.divInt_mul_right is a dubious translation:
-lean 3 declaration is
- forall {a : Int} {b : Int} {c : Int}, (Ne.{1} Int c (OfNat.ofNat.{0} Int 0 (OfNat.mk.{0} Int 0 (Zero.zero.{0} Int Int.hasZero)))) -> (Eq.{1} Rat (Rat.mk (HMul.hMul.{0, 0, 0} Int Int Int (instHMul.{0} Int Int.hasMul) a c) (HMul.hMul.{0, 0, 0} Int Int Int (instHMul.{0} Int Int.hasMul) b c)) (Rat.mk a b))
-but is expected to have type
- forall {a : Int} {b : Int} {c : Int}, (Ne.{1} Int c (OfNat.ofNat.{0} Int 0 (instOfNatInt 0))) -> (Eq.{1} Rat (Rat.divInt (HMul.hMul.{0, 0, 0} Int Int Int (instHMul.{0} Int Int.instMulInt) a c) (HMul.hMul.{0, 0, 0} Int Int Int (instHMul.{0} Int Int.instMulInt) b c)) (Rat.divInt a b))
-Case conversion may be inaccurate. Consider using '#align rat.div_mk_div_cancel_left Rat.divInt_mul_rightₓ'. -/
@[simp]
theorem divInt_mul_right {a b c : ℤ} (c0 : c ≠ 0) : a * c /. (b * c) = a /. b :=
by
@@ -310,43 +253,19 @@ theorem divInt_mul_right {a b c : ℤ} (c0 : c ≠ 0) : a * c /. (b * c) = a /.
apply (mk_eq (mul_ne_zero b0 c0) b0).2; simp [mul_comm, mul_assoc]
#align rat.div_mk_div_cancel_left Rat.divInt_mul_right
-/- warning: rat.num_denom -> Rat.num_den is a dubious translation:
-lean 3 declaration is
- forall {a : Rat}, Eq.{1} Rat (Rat.mk (Rat.num a) ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Nat Int (HasLiftT.mk.{1, 1} Nat Int (CoeTCₓ.coe.{1, 1} Nat Int (coeBase.{1, 1} Nat Int Int.hasCoe))) (Rat.den a))) a
-but is expected to have type
- forall {a : Rat}, Eq.{1} Rat (Rat.divInt (Rat.num a) (Nat.cast.{0} Int instNatCastInt (Rat.den a))) a
-Case conversion may be inaccurate. Consider using '#align rat.num_denom Rat.num_denₓ'. -/
@[simp]
theorem num_den : ∀ {a : ℚ}, a.num /. a.den = a
| ⟨n, d, h, (c : _ = 1)⟩ => show mkRat n d = _ by simp [mk_nat, ne_of_gt h, mk_pnat, c]
#align rat.num_denom Rat.num_den
-/- warning: rat.num_denom' -> Rat.num_den' is a dubious translation:
-lean 3 declaration is
- forall {n : Int} {d : Nat} {h : LT.lt.{0} Nat Nat.hasLt (OfNat.ofNat.{0} Nat 0 (OfNat.mk.{0} Nat 0 (Zero.zero.{0} Nat Nat.hasZero))) d} {c : Nat.coprime (Int.natAbs n) d}, Eq.{1} Rat (Rat.mk' n d h c) (Rat.mk n ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Nat Int (HasLiftT.mk.{1, 1} Nat Int (CoeTCₓ.coe.{1, 1} Nat Int (coeBase.{1, 1} Nat Int Int.hasCoe))) d))
-but is expected to have type
- forall {n : Int} {d : Nat} {h : Ne.{1} Nat d (OfNat.ofNat.{0} Nat 0 (instOfNatNat 0))} {c : Nat.coprime (Int.natAbs n) d}, Eq.{1} Rat (Rat.mk' n d h c) (Rat.divInt n (Nat.cast.{0} Int instNatCastInt d))
-Case conversion may be inaccurate. Consider using '#align rat.num_denom' Rat.num_den'ₓ'. -/
theorem num_den' {n d h c} : (⟨n, d, h, c⟩ : ℚ) = n /. d :=
num_den.symm
#align rat.num_denom' Rat.num_den'
-/- warning: rat.coe_int_eq_mk -> Rat.coe_int_eq_divInt is a dubious translation:
-lean 3 declaration is
- forall (z : Int), Eq.{1} Rat ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Int Rat (HasLiftT.mk.{1, 1} Int Rat (CoeTCₓ.coe.{1, 1} Int Rat (Int.castCoe.{0} Rat Rat.hasIntCast))) z) (Rat.mk z (OfNat.ofNat.{0} Int 1 (OfNat.mk.{0} Int 1 (One.one.{0} Int Int.hasOne))))
-but is expected to have type
- forall (z : Int), Eq.{1} Rat (Int.cast.{0} Rat Rat.instIntCastRat z) (Rat.divInt z (OfNat.ofNat.{0} Int 1 (instOfNatInt 1)))
-Case conversion may be inaccurate. Consider using '#align rat.coe_int_eq_mk Rat.coe_int_eq_divIntₓ'. -/
theorem coe_int_eq_divInt (z : ℤ) : (z : ℚ) = z /. 1 :=
num_den'
#align rat.coe_int_eq_mk Rat.coe_int_eq_divInt
-/- warning: rat.num_denom_cases_on -> Rat.numDenCasesOn is a dubious translation:
-lean 3 declaration is
- forall {C : Rat -> Sort.{u1}} (a : Rat), (forall (n : Int) (d : Nat), (LT.lt.{0} Nat Nat.hasLt (OfNat.ofNat.{0} Nat 0 (OfNat.mk.{0} Nat 0 (Zero.zero.{0} Nat Nat.hasZero))) d) -> (Nat.coprime (Int.natAbs n) d) -> (C (Rat.mk n ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Nat Int (HasLiftT.mk.{1, 1} Nat Int (CoeTCₓ.coe.{1, 1} Nat Int (coeBase.{1, 1} Nat Int Int.hasCoe))) d)))) -> (C a)
-but is expected to have type
- forall {C : Rat -> Sort.{u1}} (a : Rat), (forall (n : [mdata borrowed:1 Int]) (d : Nat), (LT.lt.{0} Nat instLTNat (OfNat.ofNat.{0} Nat 0 (instOfNatNat 0)) d) -> (Nat.coprime (Int.natAbs n) d) -> (C (Rat.divInt n (Nat.cast.{0} Int instNatCastInt d)))) -> (C a)
-Case conversion may be inaccurate. Consider using '#align rat.num_denom_cases_on Rat.numDenCasesOnₓ'. -/
/-- Define a (dependent) function or prove `∀ r : ℚ, p r` by dealing with rational
numbers of the form `n /. d` with `0 < d` and coprime `n`, `d`. -/
@[elab_as_elim]
@@ -355,12 +274,6 @@ def numDenCasesOn.{u} {C : ℚ → Sort u} :
| ⟨n, d, h, c⟩, H => by rw [num_denom'] <;> exact H n d h c
#align rat.num_denom_cases_on Rat.numDenCasesOn
-/- warning: rat.num_denom_cases_on' -> Rat.numDenCasesOn' is a dubious translation:
-lean 3 declaration is
- forall {C : Rat -> Sort.{u1}} (a : Rat), (forall (n : Int) (d : Nat), (Ne.{1} Nat d (OfNat.ofNat.{0} Nat 0 (OfNat.mk.{0} Nat 0 (Zero.zero.{0} Nat Nat.hasZero)))) -> (C (Rat.mk n ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Nat Int (HasLiftT.mk.{1, 1} Nat Int (CoeTCₓ.coe.{1, 1} Nat Int (coeBase.{1, 1} Nat Int Int.hasCoe))) d)))) -> (C a)
-but is expected to have type
- forall {C : Rat -> Sort.{u1}} (a : Rat), (forall (n : Int) (d : Nat), (Ne.{1} Nat d (OfNat.ofNat.{0} Nat 0 (instOfNatNat 0))) -> (C (Rat.divInt n (Nat.cast.{0} Int instNatCastInt d)))) -> (C a)
-Case conversion may be inaccurate. Consider using '#align rat.num_denom_cases_on' Rat.numDenCasesOn'ₓ'. -/
/-- Define a (dependent) function or prove `∀ r : ℚ, p r` by dealing with rational
numbers of the form `n /. d` with `d ≠ 0`. -/
@[elab_as_elim]
@@ -378,12 +291,6 @@ protected def add : ℚ → ℚ → ℚ
instance : Add ℚ :=
⟨Rat.add⟩
-/- warning: rat.lift_binop_eq -> Rat.lift_binop_eq is a dubious translation:
-lean 3 declaration is
- forall (f : Rat -> Rat -> Rat) (f₁ : Int -> Int -> Int -> Int -> Int) (f₂ : Int -> Int -> Int -> Int -> Int), (forall {n₁ : Int} {d₁ : Nat} {h₁ : LT.lt.{0} Nat Nat.hasLt (OfNat.ofNat.{0} Nat 0 (OfNat.mk.{0} Nat 0 (Zero.zero.{0} Nat Nat.hasZero))) d₁} {c₁ : Nat.coprime (Int.natAbs n₁) d₁} {n₂ : Int} {d₂ : Nat} {h₂ : LT.lt.{0} Nat Nat.hasLt (OfNat.ofNat.{0} Nat 0 (OfNat.mk.{0} Nat 0 (Zero.zero.{0} Nat Nat.hasZero))) d₂} {c₂ : Nat.coprime (Int.natAbs n₂) d₂}, Eq.{1} Rat (f (Rat.mk' n₁ d₁ h₁ c₁) (Rat.mk' n₂ d₂ h₂ c₂)) (Rat.mk (f₁ n₁ ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Nat Int (HasLiftT.mk.{1, 1} Nat Int (CoeTCₓ.coe.{1, 1} Nat Int (coeBase.{1, 1} Nat Int Int.hasCoe))) d₁) n₂ ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Nat Int (HasLiftT.mk.{1, 1} Nat Int (CoeTCₓ.coe.{1, 1} Nat Int (coeBase.{1, 1} Nat Int Int.hasCoe))) d₂)) (f₂ n₁ ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Nat Int (HasLiftT.mk.{1, 1} Nat Int (CoeTCₓ.coe.{1, 1} Nat Int (coeBase.{1, 1} Nat Int Int.hasCoe))) d₁) n₂ ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Nat Int (HasLiftT.mk.{1, 1} Nat Int (CoeTCₓ.coe.{1, 1} Nat Int (coeBase.{1, 1} Nat Int Int.hasCoe))) d₂)))) -> (forall {n₁ : Int} {d₁ : Int} {n₂ : Int} {d₂ : Int}, (Ne.{1} Int d₁ (OfNat.ofNat.{0} Int 0 (OfNat.mk.{0} Int 0 (Zero.zero.{0} Int Int.hasZero)))) -> (Ne.{1} Int d₂ (OfNat.ofNat.{0} Int 0 (OfNat.mk.{0} Int 0 (Zero.zero.{0} Int Int.hasZero)))) -> (Ne.{1} Int (f₂ n₁ d₁ n₂ d₂) (OfNat.ofNat.{0} Int 0 (OfNat.mk.{0} Int 0 (Zero.zero.{0} Int Int.hasZero))))) -> (forall (a : Int) (b : Int) (c : Int) (d : Int), (Ne.{1} Int b (OfNat.ofNat.{0} Int 0 (OfNat.mk.{0} Int 0 (Zero.zero.{0} Int Int.hasZero)))) -> (Ne.{1} Int d (OfNat.ofNat.{0} Int 0 (OfNat.mk.{0} Int 0 (Zero.zero.{0} Int Int.hasZero)))) -> (forall {n₁ : Int} {d₁ : Int} {n₂ : Int} {d₂ : Int}, (Eq.{1} Int (HMul.hMul.{0, 0, 0} Int Int Int (instHMul.{0} Int Int.hasMul) a d₁) (HMul.hMul.{0, 0, 0} Int Int Int (instHMul.{0} Int Int.hasMul) n₁ b)) -> (Eq.{1} Int (HMul.hMul.{0, 0, 0} Int Int Int (instHMul.{0} Int Int.hasMul) c d₂) (HMul.hMul.{0, 0, 0} Int Int Int (instHMul.{0} Int Int.hasMul) n₂ d)) -> (Eq.{1} Int (HMul.hMul.{0, 0, 0} Int Int Int (instHMul.{0} Int Int.hasMul) (f₁ n₁ d₁ n₂ d₂) (f₂ a b c d)) (HMul.hMul.{0, 0, 0} Int Int Int (instHMul.{0} Int Int.hasMul) (f₁ a b c d) (f₂ n₁ d₁ n₂ d₂)))) -> (Eq.{1} Rat (f (Rat.mk a b) (Rat.mk c d)) (Rat.mk (f₁ a b c d) (f₂ a b c d))))
-but is expected to have type
- forall (f : Rat -> Rat -> Rat) (f₁ : Int -> Int -> Int -> Int -> Int) (f₂ : Int -> Int -> Int -> Int -> Int), (forall {n₁ : Int} {d₁ : Nat} {h₁ : Ne.{1} Nat d₁ (OfNat.ofNat.{0} Nat 0 (instOfNatNat 0))} {c₁ : Nat.coprime (Int.natAbs n₁) d₁} {n₂ : Int} {d₂ : Nat} {h₂ : Ne.{1} Nat d₂ (OfNat.ofNat.{0} Nat 0 (instOfNatNat 0))} {c₂ : Nat.coprime (Int.natAbs n₂) d₂}, Eq.{1} Rat (f (Rat.mk' n₁ d₁ h₁ c₁) (Rat.mk' n₂ d₂ h₂ c₂)) (Rat.divInt (f₁ n₁ (Nat.cast.{0} Int instNatCastInt d₁) n₂ (Nat.cast.{0} Int instNatCastInt d₂)) (f₂ n₁ (Nat.cast.{0} Int instNatCastInt d₁) n₂ (Nat.cast.{0} Int instNatCastInt d₂)))) -> (forall {n₁ : Int} {d₁ : Int} {n₂ : Int} {d₂ : Int}, (Ne.{1} Int d₁ (OfNat.ofNat.{0} Int 0 (instOfNatInt 0))) -> (Ne.{1} Int d₂ (OfNat.ofNat.{0} Int 0 (instOfNatInt 0))) -> (Ne.{1} Int (f₂ n₁ d₁ n₂ d₂) (OfNat.ofNat.{0} Int 0 (instOfNatInt 0)))) -> (forall (a : Int) (b : Int) (c : Int) (d : Int), (Ne.{1} Int b (OfNat.ofNat.{0} Int 0 (instOfNatInt 0))) -> (Ne.{1} Int d (OfNat.ofNat.{0} Int 0 (instOfNatInt 0))) -> (forall {n₁ : Int} {d₁ : Int} {n₂ : Int} {d₂ : Int}, (Eq.{1} Int (HMul.hMul.{0, 0, 0} Int Int Int (instHMul.{0} Int Int.instMulInt) a d₁) (HMul.hMul.{0, 0, 0} Int Int Int (instHMul.{0} Int Int.instMulInt) n₁ b)) -> (Eq.{1} Int (HMul.hMul.{0, 0, 0} Int Int Int (instHMul.{0} Int Int.instMulInt) c d₂) (HMul.hMul.{0, 0, 0} Int Int Int (instHMul.{0} Int Int.instMulInt) n₂ d)) -> (Eq.{1} Int (HMul.hMul.{0, 0, 0} Int Int Int (instHMul.{0} Int Int.instMulInt) (f₁ n₁ d₁ n₂ d₂) (f₂ a b c d)) (HMul.hMul.{0, 0, 0} Int Int Int (instHMul.{0} Int Int.instMulInt) (f₁ a b c d) (f₂ n₁ d₁ n₂ d₂)))) -> (Eq.{1} Rat (f (Rat.divInt a b) (Rat.divInt c d)) (Rat.divInt (f₁ a b c d) (f₂ a b c d))))
-Case conversion may be inaccurate. Consider using '#align rat.lift_binop_eq Rat.lift_binop_eqₓ'. -/
theorem lift_binop_eq (f : ℚ → ℚ → ℚ) (f₁ : ℤ → ℤ → ℤ → ℤ → ℤ) (f₂ : ℤ → ℤ → ℤ → ℤ → ℤ)
(fv :
∀ {n₁ d₁ h₁ c₁ n₂ d₂ h₂ c₂},
@@ -403,12 +310,6 @@ theorem lift_binop_eq (f : ℚ → ℚ → ℚ) (f₁ : ℤ → ℤ → ℤ →
exact (mk_eq (f0 d₁0 d₂0) (f0 b0 d0)).2 (H ((mk_eq b0 d₁0).1 ha) ((mk_eq d0 d₂0).1 hc))
#align rat.lift_binop_eq Rat.lift_binop_eq
-/- warning: rat.add_def -> Rat.add_def'' is a dubious translation:
-lean 3 declaration is
- forall {a : Int} {b : Int} {c : Int} {d : Int}, (Ne.{1} Int b (OfNat.ofNat.{0} Int 0 (OfNat.mk.{0} Int 0 (Zero.zero.{0} Int Int.hasZero)))) -> (Ne.{1} Int d (OfNat.ofNat.{0} Int 0 (OfNat.mk.{0} Int 0 (Zero.zero.{0} Int Int.hasZero)))) -> (Eq.{1} Rat (HAdd.hAdd.{0, 0, 0} Rat Rat Rat (instHAdd.{0} Rat Rat.hasAdd) (Rat.mk a b) (Rat.mk c d)) (Rat.mk (HAdd.hAdd.{0, 0, 0} Int Int Int (instHAdd.{0} Int Int.hasAdd) (HMul.hMul.{0, 0, 0} Int Int Int (instHMul.{0} Int Int.hasMul) a d) (HMul.hMul.{0, 0, 0} Int Int Int (instHMul.{0} Int Int.hasMul) c b)) (HMul.hMul.{0, 0, 0} Int Int Int (instHMul.{0} Int Int.hasMul) b d)))
-but is expected to have type
- forall {a : Int} {b : Int} {c : Int} {d : Int}, (Ne.{1} Int b (OfNat.ofNat.{0} Int 0 (instOfNatInt 0))) -> (Ne.{1} Int d (OfNat.ofNat.{0} Int 0 (instOfNatInt 0))) -> (Eq.{1} Rat (HAdd.hAdd.{0, 0, 0} Rat Rat Rat (instHAdd.{0} Rat Rat.instAddRat) (Rat.divInt a b) (Rat.divInt c d)) (Rat.divInt (HAdd.hAdd.{0, 0, 0} Int Int Int (instHAdd.{0} Int Int.instAddInt) (HMul.hMul.{0, 0, 0} Int Int Int (instHMul.{0} Int Int.instMulInt) a d) (HMul.hMul.{0, 0, 0} Int Int Int (instHMul.{0} Int Int.instMulInt) c b)) (HMul.hMul.{0, 0, 0} Int Int Int (instHMul.{0} Int Int.instMulInt) b d)))
-Case conversion may be inaccurate. Consider using '#align rat.add_def Rat.add_def''ₓ'. -/
@[simp]
theorem add_def'' {a b c d : ℤ} (b0 : b ≠ 0) (d0 : d ≠ 0) :
a /. b + c /. d = (a * d + c * b) /. (b * d) :=
@@ -434,12 +335,6 @@ protected def neg (r : ℚ) : ℚ :=
instance : Neg ℚ :=
⟨Rat.neg⟩
-/- warning: rat.neg_def -> Rat.neg_def is a dubious translation:
-lean 3 declaration is
- forall {a : Int} {b : Int}, Eq.{1} Rat (Neg.neg.{0} Rat Rat.hasNeg (Rat.mk a b)) (Rat.mk (Neg.neg.{0} Int Int.hasNeg a) b)
-but is expected to have type
- forall {a : Int} {b : Int}, Eq.{1} Rat (Neg.neg.{0} Rat Rat.instNegRat (Rat.divInt a b)) (Rat.divInt (Neg.neg.{0} Int Int.instNegInt a) b)
-Case conversion may be inaccurate. Consider using '#align rat.neg_def Rat.neg_defₓ'. -/
@[simp]
theorem neg_def {a b : ℤ} : -(a /. b) = -a /. b :=
by
@@ -451,12 +346,6 @@ theorem neg_def {a b : ℤ} : -(a /. b) = -a /. b :=
simp only [neg_mul, congr_arg Neg.neg h₁]
#align rat.neg_def Rat.neg_def
-/- warning: rat.mk_neg_denom -> Rat.divInt_neg_den is a dubious translation:
-lean 3 declaration is
- forall (n : Int) (d : Int), Eq.{1} Rat (Rat.mk n (Neg.neg.{0} Int Int.hasNeg d)) (Rat.mk (Neg.neg.{0} Int Int.hasNeg n) d)
-but is expected to have type
- forall (n : Int) (d : Int), Eq.{1} Rat (Rat.divInt n (Neg.neg.{0} Int Int.instNegInt d)) (Rat.divInt (Neg.neg.{0} Int Int.instNegInt n) d)
-Case conversion may be inaccurate. Consider using '#align rat.mk_neg_denom Rat.divInt_neg_denₓ'. -/
@[simp]
theorem divInt_neg_den (n d : ℤ) : n /. -d = -n /. d := by
by_cases hd : d = 0 <;> simp [Rat.divInt_eq_iff, hd]
@@ -472,12 +361,6 @@ protected def mul : ℚ → ℚ → ℚ
instance : Mul ℚ :=
⟨Rat.mul⟩
-/- warning: rat.mul_def -> Rat.mul_def' is a dubious translation:
-lean 3 declaration is
- forall {a : Int} {b : Int} {c : Int} {d : Int}, (Ne.{1} Int b (OfNat.ofNat.{0} Int 0 (OfNat.mk.{0} Int 0 (Zero.zero.{0} Int Int.hasZero)))) -> (Ne.{1} Int d (OfNat.ofNat.{0} Int 0 (OfNat.mk.{0} Int 0 (Zero.zero.{0} Int Int.hasZero)))) -> (Eq.{1} Rat (HMul.hMul.{0, 0, 0} Rat Rat Rat (instHMul.{0} Rat Rat.hasMul) (Rat.mk a b) (Rat.mk c d)) (Rat.mk (HMul.hMul.{0, 0, 0} Int Int Int (instHMul.{0} Int Int.hasMul) a c) (HMul.hMul.{0, 0, 0} Int Int Int (instHMul.{0} Int Int.hasMul) b d)))
-but is expected to have type
- forall {a : Int} {b : Int} {c : Int} {d : Int}, (Ne.{1} Int b (OfNat.ofNat.{0} Int 0 (instOfNatInt 0))) -> (Ne.{1} Int d (OfNat.ofNat.{0} Int 0 (instOfNatInt 0))) -> (Eq.{1} Rat (HMul.hMul.{0, 0, 0} Rat Rat Rat (instHMul.{0} Rat Rat.instMulRat) (Rat.divInt a b) (Rat.divInt c d)) (Rat.divInt (HMul.hMul.{0, 0, 0} Int Int Int (instHMul.{0} Int Int.instMulInt) a c) (HMul.hMul.{0, 0, 0} Int Int Int (instHMul.{0} Int Int.instMulInt) b d)))
-Case conversion may be inaccurate. Consider using '#align rat.mul_def Rat.mul_def'ₓ'. -/
@[simp]
theorem mul_def' {a b c d : ℤ} (b0 : b ≠ 0) (d0 : d ≠ 0) : a /. b * (c /. d) = a * c /. (b * d) :=
by
@@ -502,12 +385,6 @@ instance : Inv ℚ :=
instance : Div ℚ :=
⟨fun a b => a * b⁻¹⟩
-/- warning: rat.inv_def -> Rat.inv_def' is a dubious translation:
-lean 3 declaration is
- forall {a : Int} {b : Int}, Eq.{1} Rat (Inv.inv.{0} Rat Rat.hasInv (Rat.mk a b)) (Rat.mk b a)
-but is expected to have type
- forall {a : Int} {b : Int}, Eq.{1} Rat (Inv.inv.{0} Rat Rat.instInvRat (Rat.divInt a b)) (Rat.divInt b a)
-Case conversion may be inaccurate. Consider using '#align rat.inv_def Rat.inv_def'ₓ'. -/
@[simp]
theorem inv_def' {a b : ℤ} : (a /. b)⁻¹ = b /. a :=
by
@@ -565,34 +442,16 @@ protected theorem add_left_neg : -a + a = 0 :=
#align rat.add_left_neg Rat.add_left_neg
-/
-/- warning: rat.mk_zero_one -> Rat.divInt_zero_one is a dubious translation:
-lean 3 declaration is
- Eq.{1} Rat (Rat.mk (OfNat.ofNat.{0} Int 0 (OfNat.mk.{0} Int 0 (Zero.zero.{0} Int Int.hasZero))) (OfNat.ofNat.{0} Int 1 (OfNat.mk.{0} Int 1 (One.one.{0} Int Int.hasOne)))) (OfNat.ofNat.{0} Rat 0 (OfNat.mk.{0} Rat 0 (Zero.zero.{0} Rat Rat.hasZero)))
-but is expected to have type
- Eq.{1} Rat (Rat.divInt (OfNat.ofNat.{0} Int 0 (instOfNatInt 0)) (OfNat.ofNat.{0} Int 1 (instOfNatInt 1))) (OfNat.ofNat.{0} Rat 0 (Rat.instOfNatRat 0))
-Case conversion may be inaccurate. Consider using '#align rat.mk_zero_one Rat.divInt_zero_oneₓ'. -/
@[simp]
theorem divInt_zero_one : 0 /. 1 = 0 :=
show [anonymous] _ _ = _ by rw [mk_pnat]; simp; rfl
#align rat.mk_zero_one Rat.divInt_zero_one
-/- warning: rat.mk_one_one -> Rat.divInt_one_one is a dubious translation:
-lean 3 declaration is
- Eq.{1} Rat (Rat.mk (OfNat.ofNat.{0} Int 1 (OfNat.mk.{0} Int 1 (One.one.{0} Int Int.hasOne))) (OfNat.ofNat.{0} Int 1 (OfNat.mk.{0} Int 1 (One.one.{0} Int Int.hasOne)))) (OfNat.ofNat.{0} Rat 1 (OfNat.mk.{0} Rat 1 (One.one.{0} Rat Rat.hasOne)))
-but is expected to have type
- Eq.{1} Rat (Rat.divInt (OfNat.ofNat.{0} Int 1 (instOfNatInt 1)) (OfNat.ofNat.{0} Int 1 (instOfNatInt 1))) (OfNat.ofNat.{0} Rat 1 (Rat.instOfNatRat 1))
-Case conversion may be inaccurate. Consider using '#align rat.mk_one_one Rat.divInt_one_oneₓ'. -/
@[simp]
theorem divInt_one_one : 1 /. 1 = 1 :=
show [anonymous] _ _ = _ by rw [mk_pnat]; simp; rfl
#align rat.mk_one_one Rat.divInt_one_one
-/- warning: rat.mk_neg_one_one -> Rat.divInt_neg_one_one is a dubious translation:
-lean 3 declaration is
- Eq.{1} Rat (Rat.mk (Neg.neg.{0} Int Int.hasNeg (OfNat.ofNat.{0} Int 1 (OfNat.mk.{0} Int 1 (One.one.{0} Int Int.hasOne)))) (OfNat.ofNat.{0} Int 1 (OfNat.mk.{0} Int 1 (One.one.{0} Int Int.hasOne)))) (Neg.neg.{0} Rat Rat.hasNeg (OfNat.ofNat.{0} Rat 1 (OfNat.mk.{0} Rat 1 (One.one.{0} Rat Rat.hasOne))))
-but is expected to have type
- Eq.{1} Rat (Rat.divInt (Neg.neg.{0} Int Int.instNegInt (OfNat.ofNat.{0} Int 1 (instOfNatInt 1))) (OfNat.ofNat.{0} Int 1 (instOfNatInt 1))) (Neg.neg.{0} Rat Rat.instNegRat (OfNat.ofNat.{0} Rat 1 (Rat.instOfNatRat 1)))
-Case conversion may be inaccurate. Consider using '#align rat.mk_neg_one_one Rat.divInt_neg_one_oneₓ'. -/
@[simp]
theorem divInt_neg_one_one : -1 /. 1 = -1 :=
show [anonymous] _ _ = _ by rw [mk_pnat]; simp; rfl
@@ -766,12 +625,6 @@ theorem eq_iff_mul_eq_mul {p q : ℚ} : p = q ↔ p.num * q.den = q.num * p.den
#align rat.eq_iff_mul_eq_mul Rat.eq_iff_mul_eq_mul
-/
-/- warning: rat.sub_def -> Rat.sub_def'' is a dubious translation:
-lean 3 declaration is
- forall {a : Int} {b : Int} {c : Int} {d : Int}, (Ne.{1} Int b (OfNat.ofNat.{0} Int 0 (OfNat.mk.{0} Int 0 (Zero.zero.{0} Int Int.hasZero)))) -> (Ne.{1} Int d (OfNat.ofNat.{0} Int 0 (OfNat.mk.{0} Int 0 (Zero.zero.{0} Int Int.hasZero)))) -> (Eq.{1} Rat (HSub.hSub.{0, 0, 0} Rat Rat Rat (instHSub.{0} Rat (SubNegMonoid.toHasSub.{0} Rat (AddGroup.toSubNegMonoid.{0} Rat Rat.addGroup))) (Rat.mk a b) (Rat.mk c d)) (Rat.mk (HSub.hSub.{0, 0, 0} Int Int Int (instHSub.{0} Int Int.hasSub) (HMul.hMul.{0, 0, 0} Int Int Int (instHMul.{0} Int Int.hasMul) a d) (HMul.hMul.{0, 0, 0} Int Int Int (instHMul.{0} Int Int.hasMul) c b)) (HMul.hMul.{0, 0, 0} Int Int Int (instHMul.{0} Int Int.hasMul) b d)))
-but is expected to have type
- forall {a : Int} {b : Int} {c : Int} {d : Int}, (Ne.{1} Int b (OfNat.ofNat.{0} Int 0 (instOfNatInt 0))) -> (Ne.{1} Int d (OfNat.ofNat.{0} Int 0 (instOfNatInt 0))) -> (Eq.{1} Rat (HSub.hSub.{0, 0, 0} Rat Rat Rat (instHSub.{0} Rat Rat.instSubRat) (Rat.divInt a b) (Rat.divInt c d)) (Rat.divInt (HSub.hSub.{0, 0, 0} Int Int Int (instHSub.{0} Int Int.instSubInt) (HMul.hMul.{0, 0, 0} Int Int Int (instHMul.{0} Int Int.instMulInt) a d) (HMul.hMul.{0, 0, 0} Int Int Int (instHMul.{0} Int Int.instMulInt) c b)) (HMul.hMul.{0, 0, 0} Int Int Int (instHMul.{0} Int Int.instMulInt) b d)))
-Case conversion may be inaccurate. Consider using '#align rat.sub_def Rat.sub_def''ₓ'. -/
theorem sub_def'' {a b c d : ℤ} (b0 : b ≠ 0) (d0 : d ≠ 0) :
a /. b - c /. d = (a * d - c * b) /. (b * d) := by simp [b0, d0, sub_eq_add_neg]
#align rat.sub_def Rat.sub_def''
@@ -838,42 +691,18 @@ theorem den_one : (1 : ℚ).den = 1 :=
#align rat.denom_one Rat.den_one
-/
-/- warning: rat.mk_num_ne_zero_of_ne_zero -> Rat.mk_num_ne_zero_of_ne_zero is a dubious translation:
-lean 3 declaration is
- forall {q : Rat} {n : Int} {d : Int}, (Ne.{1} Rat q (OfNat.ofNat.{0} Rat 0 (OfNat.mk.{0} Rat 0 (Zero.zero.{0} Rat Rat.hasZero)))) -> (Eq.{1} Rat q (Rat.mk n d)) -> (Ne.{1} Int n (OfNat.ofNat.{0} Int 0 (OfNat.mk.{0} Int 0 (Zero.zero.{0} Int Int.hasZero))))
-but is expected to have type
- forall {q : Rat} {n : Int} {d : Int}, (Ne.{1} Rat q (OfNat.ofNat.{0} Rat 0 (Rat.instOfNatRat 0))) -> (Eq.{1} Rat q (Rat.divInt n d)) -> (Ne.{1} Int n (OfNat.ofNat.{0} Int 0 (instOfNatInt 0)))
-Case conversion may be inaccurate. Consider using '#align rat.mk_num_ne_zero_of_ne_zero Rat.mk_num_ne_zero_of_ne_zeroₓ'. -/
theorem mk_num_ne_zero_of_ne_zero {q : ℚ} {n d : ℤ} (hq : q ≠ 0) (hqnd : q = n /. d) : n ≠ 0 :=
fun this : n = 0 => hq <| by simpa [this] using hqnd
#align rat.mk_num_ne_zero_of_ne_zero Rat.mk_num_ne_zero_of_ne_zero
-/- warning: rat.mk_denom_ne_zero_of_ne_zero -> Rat.mk_denom_ne_zero_of_ne_zero is a dubious translation:
-lean 3 declaration is
- forall {q : Rat} {n : Int} {d : Int}, (Ne.{1} Rat q (OfNat.ofNat.{0} Rat 0 (OfNat.mk.{0} Rat 0 (Zero.zero.{0} Rat Rat.hasZero)))) -> (Eq.{1} Rat q (Rat.mk n d)) -> (Ne.{1} Int d (OfNat.ofNat.{0} Int 0 (OfNat.mk.{0} Int 0 (Zero.zero.{0} Int Int.hasZero))))
-but is expected to have type
- forall {q : Rat} {n : Int} {d : Int}, (Ne.{1} Rat q (OfNat.ofNat.{0} Rat 0 (Rat.instOfNatRat 0))) -> (Eq.{1} Rat q (Rat.divInt n d)) -> (Ne.{1} Int d (OfNat.ofNat.{0} Int 0 (instOfNatInt 0)))
-Case conversion may be inaccurate. Consider using '#align rat.mk_denom_ne_zero_of_ne_zero Rat.mk_denom_ne_zero_of_ne_zeroₓ'. -/
theorem mk_denom_ne_zero_of_ne_zero {q : ℚ} {n d : ℤ} (hq : q ≠ 0) (hqnd : q = n /. d) : d ≠ 0 :=
fun this : d = 0 => hq <| by simpa [this] using hqnd
#align rat.mk_denom_ne_zero_of_ne_zero Rat.mk_denom_ne_zero_of_ne_zero
-/- warning: rat.mk_ne_zero_of_ne_zero -> Rat.divInt_ne_zero_of_ne_zero is a dubious translation:
-lean 3 declaration is
- forall {n : Int} {d : Int}, (Ne.{1} Int n (OfNat.ofNat.{0} Int 0 (OfNat.mk.{0} Int 0 (Zero.zero.{0} Int Int.hasZero)))) -> (Ne.{1} Int d (OfNat.ofNat.{0} Int 0 (OfNat.mk.{0} Int 0 (Zero.zero.{0} Int Int.hasZero)))) -> (Ne.{1} Rat (Rat.mk n d) (OfNat.ofNat.{0} Rat 0 (OfNat.mk.{0} Rat 0 (Zero.zero.{0} Rat Rat.hasZero))))
-but is expected to have type
- forall {n : Int} {d : Int}, (Ne.{1} Int n (OfNat.ofNat.{0} Int 0 (instOfNatInt 0))) -> (Ne.{1} Int d (OfNat.ofNat.{0} Int 0 (instOfNatInt 0))) -> (Ne.{1} Rat (Rat.divInt n d) (OfNat.ofNat.{0} Rat 0 (Rat.instOfNatRat 0)))
-Case conversion may be inaccurate. Consider using '#align rat.mk_ne_zero_of_ne_zero Rat.divInt_ne_zero_of_ne_zeroₓ'. -/
theorem divInt_ne_zero_of_ne_zero {n d : ℤ} (h : n ≠ 0) (hd : d ≠ 0) : n /. d ≠ 0 :=
(divInt_ne_zero hd).mpr h
#align rat.mk_ne_zero_of_ne_zero Rat.divInt_ne_zero_of_ne_zero
-/- warning: rat.mul_num_denom -> Rat.mul_num_den is a dubious translation:
-lean 3 declaration is
- forall (q : Rat) (r : Rat), Eq.{1} Rat (HMul.hMul.{0, 0, 0} Rat Rat Rat (instHMul.{0} Rat Rat.hasMul) q r) (Rat.mk (HMul.hMul.{0, 0, 0} Int Int Int (instHMul.{0} Int Int.hasMul) (Rat.num q) (Rat.num r)) ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Nat Int (HasLiftT.mk.{1, 1} Nat Int (CoeTCₓ.coe.{1, 1} Nat Int (coeBase.{1, 1} Nat Int Int.hasCoe))) (HMul.hMul.{0, 0, 0} Nat Nat Nat (instHMul.{0} Nat Nat.hasMul) (Rat.den q) (Rat.den r))))
-but is expected to have type
- forall (q : Rat) (r : Rat), Eq.{1} Rat (HMul.hMul.{0, 0, 0} Rat Rat Rat (instHMul.{0} Rat Rat.instMulRat) q r) (Rat.divInt (HMul.hMul.{0, 0, 0} Int Int Int (instHMul.{0} Int Int.instMulInt) (Rat.num q) (Rat.num r)) (Nat.cast.{0} Int instNatCastInt (HMul.hMul.{0, 0, 0} Nat Nat Nat (instHMul.{0} Nat instMulNat) (Rat.den q) (Rat.den r))))
-Case conversion may be inaccurate. Consider using '#align rat.mul_num_denom Rat.mul_num_denₓ'. -/
theorem mul_num_den (q r : ℚ) : q * r = q.num * r.num /. ↑(q.den * r.den) :=
by
have hq' : (↑q.den : ℤ) ≠ 0 := by have := denom_ne_zero q <;> simpa
@@ -883,12 +712,6 @@ theorem mul_num_den (q r : ℚ) : q * r = q.num * r.num /. ↑(q.den * r.den) :=
simp [mul_def hq' hr', -num_denom]
#align rat.mul_num_denom Rat.mul_num_den
-/- warning: rat.div_num_denom -> Rat.div_num_den is a dubious translation:
-lean 3 declaration is
- forall (q : Rat) (r : Rat), Eq.{1} Rat (HDiv.hDiv.{0, 0, 0} Rat Rat Rat (instHDiv.{0} Rat Rat.hasDiv) q r) (Rat.mk (HMul.hMul.{0, 0, 0} Int Int Int (instHMul.{0} Int Int.hasMul) (Rat.num q) ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Nat Int (HasLiftT.mk.{1, 1} Nat Int (CoeTCₓ.coe.{1, 1} Nat Int (coeBase.{1, 1} Nat Int Int.hasCoe))) (Rat.den r))) (HMul.hMul.{0, 0, 0} Int Int Int (instHMul.{0} Int Int.hasMul) ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Nat Int (HasLiftT.mk.{1, 1} Nat Int (CoeTCₓ.coe.{1, 1} Nat Int (coeBase.{1, 1} Nat Int Int.hasCoe))) (Rat.den q)) (Rat.num r)))
-but is expected to have type
- forall (q : Rat) (r : Rat), Eq.{1} Rat (HDiv.hDiv.{0, 0, 0} Rat Rat Rat (instHDiv.{0} Rat Rat.instDivRat) q r) (Rat.divInt (HMul.hMul.{0, 0, 0} Int Int Int (instHMul.{0} Int Int.instMulInt) (Rat.num q) (Nat.cast.{0} Int instNatCastInt (Rat.den r))) (HMul.hMul.{0, 0, 0} Int Int Int (instHMul.{0} Int Int.instMulInt) (Nat.cast.{0} Int instNatCastInt (Rat.den q)) (Rat.num r)))
-Case conversion may be inaccurate. Consider using '#align rat.div_num_denom Rat.div_num_denₓ'. -/
theorem div_num_den (q r : ℚ) : q / r = q.num * r.den /. (q.den * r.num) :=
if hr : r.num = 0 then by
have hr' : r = 0 := zero_of_num_zero hr
@@ -904,35 +727,17 @@ theorem div_num_den (q r : ℚ) : q / r = q.num * r.den /. (q.den * r.num) :=
section Casts
-/- warning: rat.add_mk -> Rat.add_divInt is a dubious translation:
-lean 3 declaration is
- forall (a : Int) (b : Int) (c : Int), Eq.{1} Rat (Rat.mk (HAdd.hAdd.{0, 0, 0} Int Int Int (instHAdd.{0} Int Int.hasAdd) a b) c) (HAdd.hAdd.{0, 0, 0} Rat Rat Rat (instHAdd.{0} Rat Rat.hasAdd) (Rat.mk a c) (Rat.mk b c))
-but is expected to have type
- forall (a : Int) (b : Int) (c : Int), Eq.{1} Rat (Rat.divInt (HAdd.hAdd.{0, 0, 0} Int Int Int (instHAdd.{0} Int Int.instAddInt) a b) c) (HAdd.hAdd.{0, 0, 0} Rat Rat Rat (instHAdd.{0} Rat Rat.instAddRat) (Rat.divInt a c) (Rat.divInt b c))
-Case conversion may be inaccurate. Consider using '#align rat.add_mk Rat.add_divIntₓ'. -/
protected theorem add_divInt (a b c : ℤ) : (a + b) /. c = a /. c + b /. c :=
if h : c = 0 then by simp [h]
else by rw [add_def h h, mk_eq h (mul_ne_zero h h)]; simp [add_mul, mul_assoc]
#align rat.add_mk Rat.add_divInt
-/- warning: rat.mk_eq_div -> Rat.divInt_eq_div is a dubious translation:
-lean 3 declaration is
- forall (n : Int) (d : Int), Eq.{1} Rat (Rat.mk n d) (HDiv.hDiv.{0, 0, 0} Rat Rat Rat (instHDiv.{0} Rat Rat.hasDiv) ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Int Rat (HasLiftT.mk.{1, 1} Int Rat (CoeTCₓ.coe.{1, 1} Int Rat (Int.castCoe.{0} Rat Rat.hasIntCast))) n) ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Int Rat (HasLiftT.mk.{1, 1} Int Rat (CoeTCₓ.coe.{1, 1} Int Rat (Int.castCoe.{0} Rat Rat.hasIntCast))) d))
-but is expected to have type
- forall (n : Int) (d : Int), Eq.{1} Rat (Rat.divInt n d) (HDiv.hDiv.{0, 0, 0} Rat Rat Rat (instHDiv.{0} Rat Rat.instDivRat) (Int.cast.{0} Rat Rat.instIntCastRat n) (Int.cast.{0} Rat Rat.instIntCastRat d))
-Case conversion may be inaccurate. Consider using '#align rat.mk_eq_div Rat.divInt_eq_divₓ'. -/
theorem divInt_eq_div (n d : ℤ) : n /. d = (n : ℚ) / d :=
by
by_cases d0 : d = 0; · simp [d0, div_zero]
simp [division_def, coe_int_eq_mk, mul_def one_ne_zero d0]
#align rat.mk_eq_div Rat.divInt_eq_div
-/- warning: rat.mk_mul_mk_cancel -> Rat.divInt_mul_divInt_cancel is a dubious translation:
-lean 3 declaration is
- forall {x : Int}, (Ne.{1} Int x (OfNat.ofNat.{0} Int 0 (OfNat.mk.{0} Int 0 (Zero.zero.{0} Int Int.hasZero)))) -> (forall (n : Int) (d : Int), Eq.{1} Rat (HMul.hMul.{0, 0, 0} Rat Rat Rat (instHMul.{0} Rat Rat.hasMul) (Rat.mk n x) (Rat.mk x d)) (Rat.mk n d))
-but is expected to have type
- forall {x : Int}, (Ne.{1} Int x (OfNat.ofNat.{0} Int 0 (instOfNatInt 0))) -> (forall (n : Int) (d : Int), Eq.{1} Rat (HMul.hMul.{0, 0, 0} Rat Rat Rat (instHMul.{0} Rat Rat.instMulRat) (Rat.divInt n x) (Rat.divInt x d)) (Rat.divInt n d))
-Case conversion may be inaccurate. Consider using '#align rat.mk_mul_mk_cancel Rat.divInt_mul_divInt_cancelₓ'. -/
theorem divInt_mul_divInt_cancel {x : ℤ} (hx : x ≠ 0) (n d : ℤ) : n /. x * (x /. d) = n /. d :=
by
by_cases hd : d = 0
@@ -941,44 +746,20 @@ theorem divInt_mul_divInt_cancel {x : ℤ} (hx : x ≠ 0) (n d : ℤ) : n /. x *
rw [mul_def hx hd, mul_comm x, div_mk_div_cancel_left hx]
#align rat.mk_mul_mk_cancel Rat.divInt_mul_divInt_cancel
-/- warning: rat.mk_div_mk_cancel_left -> Rat.divInt_div_divInt_cancel_left is a dubious translation:
-lean 3 declaration is
- forall {x : Int}, (Ne.{1} Int x (OfNat.ofNat.{0} Int 0 (OfNat.mk.{0} Int 0 (Zero.zero.{0} Int Int.hasZero)))) -> (forall (n : Int) (d : Int), Eq.{1} Rat (HDiv.hDiv.{0, 0, 0} Rat Rat Rat (instHDiv.{0} Rat Rat.hasDiv) (Rat.mk n x) (Rat.mk d x)) (Rat.mk n d))
-but is expected to have type
- forall {x : Int}, (Ne.{1} Int x (OfNat.ofNat.{0} Int 0 (instOfNatInt 0))) -> (forall (n : Int) (d : Int), Eq.{1} Rat (HDiv.hDiv.{0, 0, 0} Rat Rat Rat (instHDiv.{0} Rat Rat.instDivRat) (Rat.divInt n x) (Rat.divInt d x)) (Rat.divInt n d))
-Case conversion may be inaccurate. Consider using '#align rat.mk_div_mk_cancel_left Rat.divInt_div_divInt_cancel_leftₓ'. -/
theorem divInt_div_divInt_cancel_left {x : ℤ} (hx : x ≠ 0) (n d : ℤ) : n /. x / (d /. x) = n /. d :=
by rw [div_eq_mul_inv, inv_def, mk_mul_mk_cancel hx]
#align rat.mk_div_mk_cancel_left Rat.divInt_div_divInt_cancel_left
-/- warning: rat.mk_div_mk_cancel_right -> Rat.divInt_div_divInt_cancel_right is a dubious translation:
-lean 3 declaration is
- forall {x : Int}, (Ne.{1} Int x (OfNat.ofNat.{0} Int 0 (OfNat.mk.{0} Int 0 (Zero.zero.{0} Int Int.hasZero)))) -> (forall (n : Int) (d : Int), Eq.{1} Rat (HDiv.hDiv.{0, 0, 0} Rat Rat Rat (instHDiv.{0} Rat Rat.hasDiv) (Rat.mk x n) (Rat.mk x d)) (Rat.mk d n))
-but is expected to have type
- forall {x : Int}, (Ne.{1} Int x (OfNat.ofNat.{0} Int 0 (instOfNatInt 0))) -> (forall (n : Int) (d : Int), Eq.{1} Rat (HDiv.hDiv.{0, 0, 0} Rat Rat Rat (instHDiv.{0} Rat Rat.instDivRat) (Rat.divInt x n) (Rat.divInt x d)) (Rat.divInt d n))
-Case conversion may be inaccurate. Consider using '#align rat.mk_div_mk_cancel_right Rat.divInt_div_divInt_cancel_rightₓ'. -/
theorem divInt_div_divInt_cancel_right {x : ℤ} (hx : x ≠ 0) (n d : ℤ) :
x /. n / (x /. d) = d /. n := by rw [div_eq_mul_inv, inv_def, mul_comm, mk_mul_mk_cancel hx]
#align rat.mk_div_mk_cancel_right Rat.divInt_div_divInt_cancel_right
-/- warning: rat.coe_int_div_eq_mk -> Rat.coe_int_div_eq_divInt is a dubious translation:
-lean 3 declaration is
- forall {n : Int} {d : Int}, Eq.{1} Rat (HDiv.hDiv.{0, 0, 0} Rat Rat Rat (instHDiv.{0} Rat Rat.hasDiv) ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Int Rat (HasLiftT.mk.{1, 1} Int Rat (CoeTCₓ.coe.{1, 1} Int Rat (Int.castCoe.{0} Rat Rat.hasIntCast))) n) ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Int Rat (HasLiftT.mk.{1, 1} Int Rat (CoeTCₓ.coe.{1, 1} Int Rat (Int.castCoe.{0} Rat Rat.hasIntCast))) d)) (Rat.mk n d)
-but is expected to have type
- forall {n : Int} {d : Int}, Eq.{1} Rat (HDiv.hDiv.{0, 0, 0} Rat Rat Rat (instHDiv.{0} Rat Rat.instDivRat) (Int.cast.{0} Rat Rat.instIntCastRat n) (Int.cast.{0} Rat Rat.instIntCastRat d)) (Rat.divInt n d)
-Case conversion may be inaccurate. Consider using '#align rat.coe_int_div_eq_mk Rat.coe_int_div_eq_divIntₓ'. -/
theorem coe_int_div_eq_divInt {n d : ℤ} : (n : ℚ) / ↑d = n /. d :=
by
repeat' rw [coe_int_eq_mk]
exact mk_div_mk_cancel_left one_ne_zero n d
#align rat.coe_int_div_eq_mk Rat.coe_int_div_eq_divInt
-/- warning: rat.num_div_denom -> Rat.num_div_den is a dubious translation:
-lean 3 declaration is
- forall (r : Rat), Eq.{1} Rat (HDiv.hDiv.{0, 0, 0} Rat Rat Rat (instHDiv.{0} Rat Rat.hasDiv) ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Int Rat (HasLiftT.mk.{1, 1} Int Rat (CoeTCₓ.coe.{1, 1} Int Rat (Int.castCoe.{0} Rat Rat.hasIntCast))) (Rat.num r)) ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Nat Rat (HasLiftT.mk.{1, 1} Nat Rat (CoeTCₓ.coe.{1, 1} Nat Rat (Nat.castCoe.{0} Rat (AddMonoidWithOne.toNatCast.{0} Rat (AddGroupWithOne.toAddMonoidWithOne.{0} Rat (AddCommGroupWithOne.toAddGroupWithOne.{0} Rat (Ring.toAddCommGroupWithOne.{0} Rat (CommRing.toRing.{0} Rat Rat.commRing)))))))) (Rat.den r))) r
-but is expected to have type
- forall (r : Rat), Eq.{1} Rat (HDiv.hDiv.{0, 0, 0} Rat Rat Rat (instHDiv.{0} Rat Rat.instDivRat) (Int.cast.{0} Rat Rat.instIntCastRat (Rat.num r)) (Nat.cast.{0} Rat (Semiring.toNatCast.{0} Rat Rat.semiring) (Rat.den r))) r
-Case conversion may be inaccurate. Consider using '#align rat.num_div_denom Rat.num_div_denₓ'. -/
@[simp]
theorem num_div_den (r : ℚ) : (r.num / r.den : ℚ) = r := by
rw [← Int.cast_ofNat, ← mk_eq_div, num_denom]
@@ -1002,31 +783,13 @@ instance canLift : CanLift ℚ ℤ coe fun q => q.den = 1 :=
#align rat.can_lift Rat.canLift
-/
-/- warning: rat.coe_nat_eq_mk -> Rat.coe_nat_eq_divInt is a dubious translation:
-lean 3 declaration is
- forall (n : Nat), Eq.{1} Rat ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Nat Rat (HasLiftT.mk.{1, 1} Nat Rat (CoeTCₓ.coe.{1, 1} Nat Rat (Nat.castCoe.{0} Rat (AddMonoidWithOne.toNatCast.{0} Rat (AddGroupWithOne.toAddMonoidWithOne.{0} Rat (AddCommGroupWithOne.toAddGroupWithOne.{0} Rat (Ring.toAddCommGroupWithOne.{0} Rat (CommRing.toRing.{0} Rat Rat.commRing)))))))) n) (Rat.mk ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Nat Int (HasLiftT.mk.{1, 1} Nat Int (CoeTCₓ.coe.{1, 1} Nat Int (coeBase.{1, 1} Nat Int Int.hasCoe))) n) (OfNat.ofNat.{0} Int 1 (OfNat.mk.{0} Int 1 (One.one.{0} Int Int.hasOne))))
-but is expected to have type
- forall (n : Nat), Eq.{1} Rat (Nat.cast.{0} Rat (Semiring.toNatCast.{0} Rat Rat.semiring) n) (Rat.divInt (Nat.cast.{0} Int instNatCastInt n) (OfNat.ofNat.{0} Int 1 (instOfNatInt 1)))
-Case conversion may be inaccurate. Consider using '#align rat.coe_nat_eq_mk Rat.coe_nat_eq_divIntₓ'. -/
theorem coe_nat_eq_divInt (n : ℕ) : ↑n = n /. 1 := by rw [← Int.cast_ofNat, coe_int_eq_mk]
#align rat.coe_nat_eq_mk Rat.coe_nat_eq_divInt
-/- warning: rat.coe_nat_num -> Rat.coe_nat_num is a dubious translation:
-lean 3 declaration is
- forall (n : Nat), Eq.{1} Int (Rat.num ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Nat Rat (HasLiftT.mk.{1, 1} Nat Rat (CoeTCₓ.coe.{1, 1} Nat Rat (Nat.castCoe.{0} Rat (AddMonoidWithOne.toNatCast.{0} Rat (AddGroupWithOne.toAddMonoidWithOne.{0} Rat (AddCommGroupWithOne.toAddGroupWithOne.{0} Rat (Ring.toAddCommGroupWithOne.{0} Rat (CommRing.toRing.{0} Rat Rat.commRing)))))))) n)) ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Nat Int (HasLiftT.mk.{1, 1} Nat Int (CoeTCₓ.coe.{1, 1} Nat Int (coeBase.{1, 1} Nat Int Int.hasCoe))) n)
-but is expected to have type
- forall (n : Nat), Eq.{1} Int (Rat.num (Nat.cast.{0} Rat (Semiring.toNatCast.{0} Rat Rat.semiring) n)) (Nat.cast.{0} Int instNatCastInt n)
-Case conversion may be inaccurate. Consider using '#align rat.coe_nat_num Rat.coe_nat_numₓ'. -/
@[simp, norm_cast]
theorem coe_nat_num (n : ℕ) : (n : ℚ).num = n := by rw [← Int.cast_ofNat, coe_int_num]
#align rat.coe_nat_num Rat.coe_nat_num
-/- warning: rat.coe_nat_denom -> Rat.coe_nat_den is a dubious translation:
-lean 3 declaration is
- forall (n : Nat), Eq.{1} Nat (Rat.den ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Nat Rat (HasLiftT.mk.{1, 1} Nat Rat (CoeTCₓ.coe.{1, 1} Nat Rat (Nat.castCoe.{0} Rat (AddMonoidWithOne.toNatCast.{0} Rat (AddGroupWithOne.toAddMonoidWithOne.{0} Rat (AddCommGroupWithOne.toAddGroupWithOne.{0} Rat (Ring.toAddCommGroupWithOne.{0} Rat (CommRing.toRing.{0} Rat Rat.commRing)))))))) n)) (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne)))
-but is expected to have type
- forall (n : Nat), Eq.{1} Nat (Rat.den (Nat.cast.{0} Rat (Semiring.toNatCast.{0} Rat Rat.semiring) n)) (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1))
-Case conversion may be inaccurate. Consider using '#align rat.coe_nat_denom Rat.coe_nat_denₓ'. -/
@[simp, norm_cast]
theorem coe_nat_den (n : ℕ) : (n : ℚ).den = 1 := by rw [← Int.cast_ofNat, coe_int_denom]
#align rat.coe_nat_denom Rat.coe_nat_den
mathlib commit https://github.com/leanprover-community/mathlib/commit/917c3c072e487b3cccdbfeff17e75b40e45f66cb
@@ -98,10 +98,8 @@ def [anonymous] (n : ℤ) : ℕ+ → ℚ
by
have : Int.natAbs (n / ↑g) = n' / g :=
by
- cases' Int.natAbs_eq n with e e <;> rw [e]
- · rfl
- rw [Int.neg_ediv_of_dvd, Int.natAbs_neg]
- · rfl
+ cases' Int.natAbs_eq n with e e <;> rw [e]; · rfl
+ rw [Int.neg_ediv_of_dvd, Int.natAbs_neg]; · rfl
exact Int.coe_nat_dvd.2 (Nat.gcd_dvd_left _ _)
rw [this]
exact Nat.coprime_div_gcd_div_gcd (Nat.gcd_pos_of_pos_right _ dpos)⟩
@@ -199,10 +197,7 @@ Case conversion may be inaccurate. Consider using '#align rat.mk_eq_zero Rat.div
@[simp]
theorem divInt_eq_zero {a b : ℤ} (b0 : b ≠ 0) : a /. b = 0 ↔ a = 0 :=
by
- refine'
- ⟨fun h => _, by
- rintro rfl
- simp⟩
+ refine' ⟨fun h => _, by rintro rfl; simp⟩
have : ∀ {a b}, mk_pnat a b = 0 → a = 0 :=
by
rintro a ⟨b, h⟩ e
@@ -211,8 +206,7 @@ theorem divInt_eq_zero {a b : ℤ} (b0 : b ≠ 0) : a /. b = 0 ↔ a = 0 :=
cases' b with b <;> simp only [mk, mk_nat, Int.ofNat_eq_coe, dite_eq_left_iff] at h
· simp only [mt (congr_arg Int.ofNat) b0, not_false_iff, forall_true_left] at h
exact this h
- · apply neg_injective
- simp [this h]
+ · apply neg_injective; simp [this h]
#align rat.mk_eq_zero Rat.divInt_eq_zero
/- warning: rat.mk_ne_zero -> Rat.divInt_ne_zero is a dubious translation:
@@ -249,8 +243,7 @@ theorem divInt_eq_iff :
· change -a * ↑d = c * b.succ ↔ a * d = c * -b.succ
constructor <;> intro h <;> apply neg_injective <;> simpa [left_distrib, eq_comm] using h
· change -a * d.succ = -c * b.succ ↔ a * -d.succ = c * -b.succ
- simp [left_distrib, sub_eq_add_neg]
- cc
+ simp [left_distrib, sub_eq_add_neg]; cc
intros ; simp [mk_pnat]; constructor <;> intro h
· cases' h with ha hb
have ha := by
@@ -295,8 +288,7 @@ theorem divInt_eq_iff :
have gd0 := Nat.gcd_pos_of_pos_right c hd
apply Nat.le_of_dvd
apply (Nat.le_div_iff_mul_le gd0).2
- simp
- apply Nat.le_of_dvd hd (Nat.gcd_dvd_right _ _)
+ simp; apply Nat.le_of_dvd hd (Nat.gcd_dvd_right _ _)
apply (Nat.coprime_div_gcd_div_gcd gb0).symm.dvd_of_dvd_mul_left
refine' ⟨c / c.gcd d, _⟩
rw [← Nat.mul_div_assoc _ (Nat.gcd_dvd_left _ _), ← Nat.mul_div_assoc _ (Nat.gcd_dvd_right _ _)]
@@ -314,9 +306,7 @@ Case conversion may be inaccurate. Consider using '#align rat.div_mk_div_cancel_
@[simp]
theorem divInt_mul_right {a b c : ℤ} (c0 : c ≠ 0) : a * c /. (b * c) = a /. b :=
by
- by_cases b0 : b = 0;
- · subst b0
- simp
+ by_cases b0 : b = 0; · subst b0; simp
apply (mk_eq (mul_ne_zero b0 c0) b0).2; simp [mul_comm, mul_assoc]
#align rat.div_mk_div_cancel_left Rat.divInt_mul_right
@@ -453,10 +443,7 @@ Case conversion may be inaccurate. Consider using '#align rat.neg_def Rat.neg_de
@[simp]
theorem neg_def {a b : ℤ} : -(a /. b) = -a /. b :=
by
- by_cases b0 : b = 0;
- · subst b0
- simp
- rfl
+ by_cases b0 : b = 0; · subst b0; simp; rfl
generalize ha : a /. b = x; cases' x with n₁ d₁ h₁ c₁; rw [num_denom'] at ha
show Rat.mk' _ _ _ _ = _; rw [num_denom']
have d0 := ne_of_gt (Int.ofNat_lt.2 h₁)
@@ -524,26 +511,15 @@ Case conversion may be inaccurate. Consider using '#align rat.inv_def Rat.inv_de
@[simp]
theorem inv_def' {a b : ℤ} : (a /. b)⁻¹ = b /. a :=
by
- by_cases a0 : a = 0
- · subst a0
- simp
- rfl
- by_cases b0 : b = 0
- · subst b0
- simp
- rfl
- generalize ha : a /. b = x
- cases' x with n d h c
- rw [num_denom'] at ha
+ by_cases a0 : a = 0; · subst a0; simp; rfl
+ by_cases b0 : b = 0; · subst b0; simp; rfl
+ generalize ha : a /. b = x; cases' x with n d h c; rw [num_denom'] at ha
refine' Eq.trans (_ : Rat.inv ⟨n, d, h, c⟩ = d /. n) _
· cases' n with n <;> [cases' n with n;skip]
· rfl
· change Int.ofNat n.succ with (n + 1 : ℕ)
- unfold Rat.inv
- rw [num_denom']
- · unfold Rat.inv
- rw [num_denom']
- rfl
+ unfold Rat.inv; rw [num_denom']
+ · unfold Rat.inv; rw [num_denom']; rfl
have n0 : n ≠ 0 := by
rintro rfl
rw [Rat.zero_divInt, mk_eq_zero b0] at ha
@@ -597,10 +573,7 @@ but is expected to have type
Case conversion may be inaccurate. Consider using '#align rat.mk_zero_one Rat.divInt_zero_oneₓ'. -/
@[simp]
theorem divInt_zero_one : 0 /. 1 = 0 :=
- show [anonymous] _ _ = _ by
- rw [mk_pnat]
- simp
- rfl
+ show [anonymous] _ _ = _ by rw [mk_pnat]; simp; rfl
#align rat.mk_zero_one Rat.divInt_zero_one
/- warning: rat.mk_one_one -> Rat.divInt_one_one is a dubious translation:
@@ -611,10 +584,7 @@ but is expected to have type
Case conversion may be inaccurate. Consider using '#align rat.mk_one_one Rat.divInt_one_oneₓ'. -/
@[simp]
theorem divInt_one_one : 1 /. 1 = 1 :=
- show [anonymous] _ _ = _ by
- rw [mk_pnat]
- simp
- rfl
+ show [anonymous] _ _ = _ by rw [mk_pnat]; simp; rfl
#align rat.mk_one_one Rat.divInt_one_one
/- warning: rat.mk_neg_one_one -> Rat.divInt_neg_one_one is a dubious translation:
@@ -625,25 +595,18 @@ but is expected to have type
Case conversion may be inaccurate. Consider using '#align rat.mk_neg_one_one Rat.divInt_neg_one_oneₓ'. -/
@[simp]
theorem divInt_neg_one_one : -1 /. 1 = -1 :=
- show [anonymous] _ _ = _ by
- rw [mk_pnat]
- simp
- rfl
+ show [anonymous] _ _ = _ by rw [mk_pnat]; simp; rfl
#align rat.mk_neg_one_one Rat.divInt_neg_one_one
#print Rat.mul_one /-
protected theorem mul_one : a * 1 = a :=
- numDenCasesOn' a fun n d h => by
- rw [← mk_one_one]
- simp [h, -mk_one_one]
+ numDenCasesOn' a fun n d h => by rw [← mk_one_one]; simp [h, -mk_one_one]
#align rat.mul_one Rat.mul_one
-/
#print Rat.one_mul /-
protected theorem one_mul : 1 * a = a :=
- numDenCasesOn' a fun n d h => by
- rw [← mk_one_one]
- simp [h, -mk_one_one]
+ numDenCasesOn' a fun n d h => by rw [← mk_one_one]; simp [h, -mk_one_one]
#align rat.one_mul Rat.one_mul
-/
@@ -679,10 +642,8 @@ protected theorem mul_add : a * (b + c) = a * b + a * c := by
-/
#print Rat.zero_ne_one /-
-protected theorem zero_ne_one : 0 ≠ (1 : ℚ) :=
- by
- rw [ne_comm, ← mk_one_one, mk_ne_zero one_ne_zero]
- exact one_ne_zero
+protected theorem zero_ne_one : 0 ≠ (1 : ℚ) := by
+ rw [ne_comm, ← mk_one_one, mk_ne_zero one_ne_zero]; exact one_ne_zero
#align rat.zero_ne_one Rat.zero_ne_one
-/
@@ -690,12 +651,7 @@ protected theorem zero_ne_one : 0 ≠ (1 : ℚ) :=
protected theorem mul_inv_cancel : a ≠ 0 → a * a⁻¹ = 1 :=
numDenCasesOn' a fun n d h a0 =>
by
- have n0 : n ≠ 0 :=
- mt
- (by
- rintro rfl
- simp)
- a0
+ have n0 : n ≠ 0 := mt (by rintro rfl; simp) a0
simpa [h, n0, mul_comm] using @div_mk_div_cancel_left 1 1 _ n0
#align rat.mul_inv_cancel Rat.mul_inv_cancel
-/
@@ -956,9 +912,7 @@ but is expected to have type
Case conversion may be inaccurate. Consider using '#align rat.add_mk Rat.add_divIntₓ'. -/
protected theorem add_divInt (a b c : ℤ) : (a + b) /. c = a /. c + b /. c :=
if h : c = 0 then by simp [h]
- else by
- rw [add_def h h, mk_eq h (mul_ne_zero h h)]
- simp [add_mul, mul_assoc]
+ else by rw [add_def h h, mk_eq h (mul_ne_zero h h)]; simp [add_mul, mul_assoc]
#align rat.add_mk Rat.add_divInt
/- warning: rat.mk_eq_div -> Rat.divInt_eq_div is a dubious translation:
@@ -1031,11 +985,8 @@ theorem num_div_den (r : ℚ) : (r.num / r.den : ℚ) = r := by
#align rat.num_div_denom Rat.num_div_den
#print Rat.coe_int_num_of_den_eq_one /-
-theorem coe_int_num_of_den_eq_one {q : ℚ} (hq : q.den = 1) : ↑q.num = q :=
- by
- conv_rhs => rw [← @num_denom q, hq]
- rw [coe_int_eq_mk]
- rfl
+theorem coe_int_num_of_den_eq_one {q : ℚ} (hq : q.den = 1) : ↑q.num = q := by
+ conv_rhs => rw [← @num_denom q, hq]; rw [coe_int_eq_mk]; rfl
#align rat.coe_int_num_of_denom_eq_one Rat.coe_int_num_of_den_eq_one
-/
mathlib commit https://github.com/leanprover-community/mathlib/commit/917c3c072e487b3cccdbfeff17e75b40e45f66cb
@@ -189,7 +189,6 @@ theorem zero_divInt (n) : 0 /. n = 0 := by cases n <;> simp [mk]
private theorem gcd_abs_dvd_left {a b} : (Nat.gcd (Int.natAbs a) b : ℤ) ∣ a :=
Int.dvd_natAbs.1 <| Int.coe_nat_dvd.2 <| Nat.gcd_dvd_left (Int.natAbs a) b
-#align rat.gcd_abs_dvd_left rat.gcd_abs_dvd_left
/- warning: rat.mk_eq_zero -> Rat.divInt_eq_zero is a dubious translation:
lean 3 declaration is
mathlib commit https://github.com/leanprover-community/mathlib/commit/8d33f09cd7089ecf074b4791907588245aec5d1b
@@ -537,7 +537,7 @@ theorem inv_def' {a b : ℤ} : (a /. b)⁻¹ = b /. a :=
cases' x with n d h c
rw [num_denom'] at ha
refine' Eq.trans (_ : Rat.inv ⟨n, d, h, c⟩ = d /. n) _
- · cases' n with n <;> [cases' n with n, skip]
+ · cases' n with n <;> [cases' n with n;skip]
· rfl
· change Int.ofNat n.succ with (n + 1 : ℕ)
unfold Rat.inv
mathlib commit https://github.com/leanprover-community/mathlib/commit/08e1d8d4d989df3a6df86f385e9053ec8a372cc1
@@ -1024,7 +1024,7 @@ theorem coe_int_div_eq_divInt {n d : ℤ} : (n : ℚ) / ↑d = n /. d :=
lean 3 declaration is
forall (r : Rat), Eq.{1} Rat (HDiv.hDiv.{0, 0, 0} Rat Rat Rat (instHDiv.{0} Rat Rat.hasDiv) ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Int Rat (HasLiftT.mk.{1, 1} Int Rat (CoeTCₓ.coe.{1, 1} Int Rat (Int.castCoe.{0} Rat Rat.hasIntCast))) (Rat.num r)) ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Nat Rat (HasLiftT.mk.{1, 1} Nat Rat (CoeTCₓ.coe.{1, 1} Nat Rat (Nat.castCoe.{0} Rat (AddMonoidWithOne.toNatCast.{0} Rat (AddGroupWithOne.toAddMonoidWithOne.{0} Rat (AddCommGroupWithOne.toAddGroupWithOne.{0} Rat (Ring.toAddCommGroupWithOne.{0} Rat (CommRing.toRing.{0} Rat Rat.commRing)))))))) (Rat.den r))) r
but is expected to have type
- forall (r : Rat), Eq.{1} Rat (HDiv.hDiv.{0, 0, 0} Rat Rat Rat (instHDiv.{0} Rat Rat.instDivRat) (Int.cast.{0} Rat Rat.instIntCastRat (Rat.num r)) (Nat.cast.{0} Rat (NonAssocRing.toNatCast.{0} Rat (Ring.toNonAssocRing.{0} Rat (CommRing.toRing.{0} Rat Rat.commRing))) (Rat.den r))) r
+ forall (r : Rat), Eq.{1} Rat (HDiv.hDiv.{0, 0, 0} Rat Rat Rat (instHDiv.{0} Rat Rat.instDivRat) (Int.cast.{0} Rat Rat.instIntCastRat (Rat.num r)) (Nat.cast.{0} Rat (Semiring.toNatCast.{0} Rat Rat.semiring) (Rat.den r))) r
Case conversion may be inaccurate. Consider using '#align rat.num_div_denom Rat.num_div_denₓ'. -/
@[simp]
theorem num_div_den (r : ℚ) : (r.num / r.den : ℚ) = r := by
@@ -1056,7 +1056,7 @@ instance canLift : CanLift ℚ ℤ coe fun q => q.den = 1 :=
lean 3 declaration is
forall (n : Nat), Eq.{1} Rat ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Nat Rat (HasLiftT.mk.{1, 1} Nat Rat (CoeTCₓ.coe.{1, 1} Nat Rat (Nat.castCoe.{0} Rat (AddMonoidWithOne.toNatCast.{0} Rat (AddGroupWithOne.toAddMonoidWithOne.{0} Rat (AddCommGroupWithOne.toAddGroupWithOne.{0} Rat (Ring.toAddCommGroupWithOne.{0} Rat (CommRing.toRing.{0} Rat Rat.commRing)))))))) n) (Rat.mk ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Nat Int (HasLiftT.mk.{1, 1} Nat Int (CoeTCₓ.coe.{1, 1} Nat Int (coeBase.{1, 1} Nat Int Int.hasCoe))) n) (OfNat.ofNat.{0} Int 1 (OfNat.mk.{0} Int 1 (One.one.{0} Int Int.hasOne))))
but is expected to have type
- forall (n : Nat), Eq.{1} Rat (Nat.cast.{0} Rat (NonAssocRing.toNatCast.{0} Rat (Ring.toNonAssocRing.{0} Rat (CommRing.toRing.{0} Rat Rat.commRing))) n) (Rat.divInt (Nat.cast.{0} Int instNatCastInt n) (OfNat.ofNat.{0} Int 1 (instOfNatInt 1)))
+ forall (n : Nat), Eq.{1} Rat (Nat.cast.{0} Rat (Semiring.toNatCast.{0} Rat Rat.semiring) n) (Rat.divInt (Nat.cast.{0} Int instNatCastInt n) (OfNat.ofNat.{0} Int 1 (instOfNatInt 1)))
Case conversion may be inaccurate. Consider using '#align rat.coe_nat_eq_mk Rat.coe_nat_eq_divIntₓ'. -/
theorem coe_nat_eq_divInt (n : ℕ) : ↑n = n /. 1 := by rw [← Int.cast_ofNat, coe_int_eq_mk]
#align rat.coe_nat_eq_mk Rat.coe_nat_eq_divInt
@@ -1065,7 +1065,7 @@ theorem coe_nat_eq_divInt (n : ℕ) : ↑n = n /. 1 := by rw [← Int.cast_ofNat
lean 3 declaration is
forall (n : Nat), Eq.{1} Int (Rat.num ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Nat Rat (HasLiftT.mk.{1, 1} Nat Rat (CoeTCₓ.coe.{1, 1} Nat Rat (Nat.castCoe.{0} Rat (AddMonoidWithOne.toNatCast.{0} Rat (AddGroupWithOne.toAddMonoidWithOne.{0} Rat (AddCommGroupWithOne.toAddGroupWithOne.{0} Rat (Ring.toAddCommGroupWithOne.{0} Rat (CommRing.toRing.{0} Rat Rat.commRing)))))))) n)) ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Nat Int (HasLiftT.mk.{1, 1} Nat Int (CoeTCₓ.coe.{1, 1} Nat Int (coeBase.{1, 1} Nat Int Int.hasCoe))) n)
but is expected to have type
- forall (n : Nat), Eq.{1} Int (Rat.num (Nat.cast.{0} Rat (NonAssocRing.toNatCast.{0} Rat (Ring.toNonAssocRing.{0} Rat (CommRing.toRing.{0} Rat Rat.commRing))) n)) (Nat.cast.{0} Int instNatCastInt n)
+ forall (n : Nat), Eq.{1} Int (Rat.num (Nat.cast.{0} Rat (Semiring.toNatCast.{0} Rat Rat.semiring) n)) (Nat.cast.{0} Int instNatCastInt n)
Case conversion may be inaccurate. Consider using '#align rat.coe_nat_num Rat.coe_nat_numₓ'. -/
@[simp, norm_cast]
theorem coe_nat_num (n : ℕ) : (n : ℚ).num = n := by rw [← Int.cast_ofNat, coe_int_num]
@@ -1075,7 +1075,7 @@ theorem coe_nat_num (n : ℕ) : (n : ℚ).num = n := by rw [← Int.cast_ofNat,
lean 3 declaration is
forall (n : Nat), Eq.{1} Nat (Rat.den ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Nat Rat (HasLiftT.mk.{1, 1} Nat Rat (CoeTCₓ.coe.{1, 1} Nat Rat (Nat.castCoe.{0} Rat (AddMonoidWithOne.toNatCast.{0} Rat (AddGroupWithOne.toAddMonoidWithOne.{0} Rat (AddCommGroupWithOne.toAddGroupWithOne.{0} Rat (Ring.toAddCommGroupWithOne.{0} Rat (CommRing.toRing.{0} Rat Rat.commRing)))))))) n)) (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne)))
but is expected to have type
- forall (n : Nat), Eq.{1} Nat (Rat.den (Nat.cast.{0} Rat (NonAssocRing.toNatCast.{0} Rat (Ring.toNonAssocRing.{0} Rat (CommRing.toRing.{0} Rat Rat.commRing))) n)) (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1))
+ forall (n : Nat), Eq.{1} Nat (Rat.den (Nat.cast.{0} Rat (Semiring.toNatCast.{0} Rat Rat.semiring) n)) (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1))
Case conversion may be inaccurate. Consider using '#align rat.coe_nat_denom Rat.coe_nat_denₓ'. -/
@[simp, norm_cast]
theorem coe_nat_den (n : ℕ) : (n : ℚ).den = 1 := by rw [← Int.cast_ofNat, coe_int_denom]
mathlib commit https://github.com/leanprover-community/mathlib/commit/ce86f4e05e9a9b8da5e316b22c76ce76440c56a1
@@ -1022,7 +1022,7 @@ theorem coe_int_div_eq_divInt {n d : ℤ} : (n : ℚ) / ↑d = n /. d :=
/- warning: rat.num_div_denom -> Rat.num_div_den is a dubious translation:
lean 3 declaration is
- forall (r : Rat), Eq.{1} Rat (HDiv.hDiv.{0, 0, 0} Rat Rat Rat (instHDiv.{0} Rat Rat.hasDiv) ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Int Rat (HasLiftT.mk.{1, 1} Int Rat (CoeTCₓ.coe.{1, 1} Int Rat (Int.castCoe.{0} Rat Rat.hasIntCast))) (Rat.num r)) ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Nat Rat (HasLiftT.mk.{1, 1} Nat Rat (CoeTCₓ.coe.{1, 1} Nat Rat (Nat.castCoe.{0} Rat (AddMonoidWithOne.toNatCast.{0} Rat (AddGroupWithOne.toAddMonoidWithOne.{0} Rat (NonAssocRing.toAddGroupWithOne.{0} Rat (Ring.toNonAssocRing.{0} Rat (CommRing.toRing.{0} Rat Rat.commRing)))))))) (Rat.den r))) r
+ forall (r : Rat), Eq.{1} Rat (HDiv.hDiv.{0, 0, 0} Rat Rat Rat (instHDiv.{0} Rat Rat.hasDiv) ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Int Rat (HasLiftT.mk.{1, 1} Int Rat (CoeTCₓ.coe.{1, 1} Int Rat (Int.castCoe.{0} Rat Rat.hasIntCast))) (Rat.num r)) ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Nat Rat (HasLiftT.mk.{1, 1} Nat Rat (CoeTCₓ.coe.{1, 1} Nat Rat (Nat.castCoe.{0} Rat (AddMonoidWithOne.toNatCast.{0} Rat (AddGroupWithOne.toAddMonoidWithOne.{0} Rat (AddCommGroupWithOne.toAddGroupWithOne.{0} Rat (Ring.toAddCommGroupWithOne.{0} Rat (CommRing.toRing.{0} Rat Rat.commRing)))))))) (Rat.den r))) r
but is expected to have type
forall (r : Rat), Eq.{1} Rat (HDiv.hDiv.{0, 0, 0} Rat Rat Rat (instHDiv.{0} Rat Rat.instDivRat) (Int.cast.{0} Rat Rat.instIntCastRat (Rat.num r)) (Nat.cast.{0} Rat (NonAssocRing.toNatCast.{0} Rat (Ring.toNonAssocRing.{0} Rat (CommRing.toRing.{0} Rat Rat.commRing))) (Rat.den r))) r
Case conversion may be inaccurate. Consider using '#align rat.num_div_denom Rat.num_div_denₓ'. -/
@@ -1054,7 +1054,7 @@ instance canLift : CanLift ℚ ℤ coe fun q => q.den = 1 :=
/- warning: rat.coe_nat_eq_mk -> Rat.coe_nat_eq_divInt is a dubious translation:
lean 3 declaration is
- forall (n : Nat), Eq.{1} Rat ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Nat Rat (HasLiftT.mk.{1, 1} Nat Rat (CoeTCₓ.coe.{1, 1} Nat Rat (Nat.castCoe.{0} Rat (AddMonoidWithOne.toNatCast.{0} Rat (AddGroupWithOne.toAddMonoidWithOne.{0} Rat (NonAssocRing.toAddGroupWithOne.{0} Rat (Ring.toNonAssocRing.{0} Rat (CommRing.toRing.{0} Rat Rat.commRing)))))))) n) (Rat.mk ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Nat Int (HasLiftT.mk.{1, 1} Nat Int (CoeTCₓ.coe.{1, 1} Nat Int (coeBase.{1, 1} Nat Int Int.hasCoe))) n) (OfNat.ofNat.{0} Int 1 (OfNat.mk.{0} Int 1 (One.one.{0} Int Int.hasOne))))
+ forall (n : Nat), Eq.{1} Rat ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Nat Rat (HasLiftT.mk.{1, 1} Nat Rat (CoeTCₓ.coe.{1, 1} Nat Rat (Nat.castCoe.{0} Rat (AddMonoidWithOne.toNatCast.{0} Rat (AddGroupWithOne.toAddMonoidWithOne.{0} Rat (AddCommGroupWithOne.toAddGroupWithOne.{0} Rat (Ring.toAddCommGroupWithOne.{0} Rat (CommRing.toRing.{0} Rat Rat.commRing)))))))) n) (Rat.mk ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Nat Int (HasLiftT.mk.{1, 1} Nat Int (CoeTCₓ.coe.{1, 1} Nat Int (coeBase.{1, 1} Nat Int Int.hasCoe))) n) (OfNat.ofNat.{0} Int 1 (OfNat.mk.{0} Int 1 (One.one.{0} Int Int.hasOne))))
but is expected to have type
forall (n : Nat), Eq.{1} Rat (Nat.cast.{0} Rat (NonAssocRing.toNatCast.{0} Rat (Ring.toNonAssocRing.{0} Rat (CommRing.toRing.{0} Rat Rat.commRing))) n) (Rat.divInt (Nat.cast.{0} Int instNatCastInt n) (OfNat.ofNat.{0} Int 1 (instOfNatInt 1)))
Case conversion may be inaccurate. Consider using '#align rat.coe_nat_eq_mk Rat.coe_nat_eq_divIntₓ'. -/
@@ -1063,7 +1063,7 @@ theorem coe_nat_eq_divInt (n : ℕ) : ↑n = n /. 1 := by rw [← Int.cast_ofNat
/- warning: rat.coe_nat_num -> Rat.coe_nat_num is a dubious translation:
lean 3 declaration is
- forall (n : Nat), Eq.{1} Int (Rat.num ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Nat Rat (HasLiftT.mk.{1, 1} Nat Rat (CoeTCₓ.coe.{1, 1} Nat Rat (Nat.castCoe.{0} Rat (AddMonoidWithOne.toNatCast.{0} Rat (AddGroupWithOne.toAddMonoidWithOne.{0} Rat (NonAssocRing.toAddGroupWithOne.{0} Rat (Ring.toNonAssocRing.{0} Rat (CommRing.toRing.{0} Rat Rat.commRing)))))))) n)) ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Nat Int (HasLiftT.mk.{1, 1} Nat Int (CoeTCₓ.coe.{1, 1} Nat Int (coeBase.{1, 1} Nat Int Int.hasCoe))) n)
+ forall (n : Nat), Eq.{1} Int (Rat.num ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Nat Rat (HasLiftT.mk.{1, 1} Nat Rat (CoeTCₓ.coe.{1, 1} Nat Rat (Nat.castCoe.{0} Rat (AddMonoidWithOne.toNatCast.{0} Rat (AddGroupWithOne.toAddMonoidWithOne.{0} Rat (AddCommGroupWithOne.toAddGroupWithOne.{0} Rat (Ring.toAddCommGroupWithOne.{0} Rat (CommRing.toRing.{0} Rat Rat.commRing)))))))) n)) ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Nat Int (HasLiftT.mk.{1, 1} Nat Int (CoeTCₓ.coe.{1, 1} Nat Int (coeBase.{1, 1} Nat Int Int.hasCoe))) n)
but is expected to have type
forall (n : Nat), Eq.{1} Int (Rat.num (Nat.cast.{0} Rat (NonAssocRing.toNatCast.{0} Rat (Ring.toNonAssocRing.{0} Rat (CommRing.toRing.{0} Rat Rat.commRing))) n)) (Nat.cast.{0} Int instNatCastInt n)
Case conversion may be inaccurate. Consider using '#align rat.coe_nat_num Rat.coe_nat_numₓ'. -/
@@ -1073,7 +1073,7 @@ theorem coe_nat_num (n : ℕ) : (n : ℚ).num = n := by rw [← Int.cast_ofNat,
/- warning: rat.coe_nat_denom -> Rat.coe_nat_den is a dubious translation:
lean 3 declaration is
- forall (n : Nat), Eq.{1} Nat (Rat.den ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Nat Rat (HasLiftT.mk.{1, 1} Nat Rat (CoeTCₓ.coe.{1, 1} Nat Rat (Nat.castCoe.{0} Rat (AddMonoidWithOne.toNatCast.{0} Rat (AddGroupWithOne.toAddMonoidWithOne.{0} Rat (NonAssocRing.toAddGroupWithOne.{0} Rat (Ring.toNonAssocRing.{0} Rat (CommRing.toRing.{0} Rat Rat.commRing)))))))) n)) (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne)))
+ forall (n : Nat), Eq.{1} Nat (Rat.den ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Nat Rat (HasLiftT.mk.{1, 1} Nat Rat (CoeTCₓ.coe.{1, 1} Nat Rat (Nat.castCoe.{0} Rat (AddMonoidWithOne.toNatCast.{0} Rat (AddGroupWithOne.toAddMonoidWithOne.{0} Rat (AddCommGroupWithOne.toAddGroupWithOne.{0} Rat (Ring.toAddCommGroupWithOne.{0} Rat (CommRing.toRing.{0} Rat Rat.commRing)))))))) n)) (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne)))
but is expected to have type
forall (n : Nat), Eq.{1} Nat (Rat.den (Nat.cast.{0} Rat (NonAssocRing.toNatCast.{0} Rat (Ring.toNonAssocRing.{0} Rat (CommRing.toRing.{0} Rat Rat.commRing))) n)) (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1))
Case conversion may be inaccurate. Consider using '#align rat.coe_nat_denom Rat.coe_nat_denₓ'. -/
mathlib commit https://github.com/leanprover-community/mathlib/commit/b19481deb571022990f1baa9cbf9172e6757a479
@@ -1020,12 +1020,16 @@ theorem coe_int_div_eq_divInt {n d : ℤ} : (n : ℚ) / ↑d = n /. d :=
exact mk_div_mk_cancel_left one_ne_zero n d
#align rat.coe_int_div_eq_mk Rat.coe_int_div_eq_divInt
-#print Rat.num_div_den /-
+/- warning: rat.num_div_denom -> Rat.num_div_den is a dubious translation:
+lean 3 declaration is
+ forall (r : Rat), Eq.{1} Rat (HDiv.hDiv.{0, 0, 0} Rat Rat Rat (instHDiv.{0} Rat Rat.hasDiv) ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Int Rat (HasLiftT.mk.{1, 1} Int Rat (CoeTCₓ.coe.{1, 1} Int Rat (Int.castCoe.{0} Rat Rat.hasIntCast))) (Rat.num r)) ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Nat Rat (HasLiftT.mk.{1, 1} Nat Rat (CoeTCₓ.coe.{1, 1} Nat Rat (Nat.castCoe.{0} Rat (AddMonoidWithOne.toNatCast.{0} Rat (AddGroupWithOne.toAddMonoidWithOne.{0} Rat (NonAssocRing.toAddGroupWithOne.{0} Rat (Ring.toNonAssocRing.{0} Rat (CommRing.toRing.{0} Rat Rat.commRing)))))))) (Rat.den r))) r
+but is expected to have type
+ forall (r : Rat), Eq.{1} Rat (HDiv.hDiv.{0, 0, 0} Rat Rat Rat (instHDiv.{0} Rat Rat.instDivRat) (Int.cast.{0} Rat Rat.instIntCastRat (Rat.num r)) (Nat.cast.{0} Rat (NonAssocRing.toNatCast.{0} Rat (Ring.toNonAssocRing.{0} Rat (CommRing.toRing.{0} Rat Rat.commRing))) (Rat.den r))) r
+Case conversion may be inaccurate. Consider using '#align rat.num_div_denom Rat.num_div_denₓ'. -/
@[simp]
theorem num_div_den (r : ℚ) : (r.num / r.den : ℚ) = r := by
rw [← Int.cast_ofNat, ← mk_eq_div, num_denom]
#align rat.num_div_denom Rat.num_div_den
--/
#print Rat.coe_int_num_of_den_eq_one /-
theorem coe_int_num_of_den_eq_one {q : ℚ} (hq : q.den = 1) : ↑q.num = q :=
@@ -1057,17 +1061,25 @@ Case conversion may be inaccurate. Consider using '#align rat.coe_nat_eq_mk Rat.
theorem coe_nat_eq_divInt (n : ℕ) : ↑n = n /. 1 := by rw [← Int.cast_ofNat, coe_int_eq_mk]
#align rat.coe_nat_eq_mk Rat.coe_nat_eq_divInt
-#print Rat.coe_nat_num /-
+/- warning: rat.coe_nat_num -> Rat.coe_nat_num is a dubious translation:
+lean 3 declaration is
+ forall (n : Nat), Eq.{1} Int (Rat.num ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Nat Rat (HasLiftT.mk.{1, 1} Nat Rat (CoeTCₓ.coe.{1, 1} Nat Rat (Nat.castCoe.{0} Rat (AddMonoidWithOne.toNatCast.{0} Rat (AddGroupWithOne.toAddMonoidWithOne.{0} Rat (NonAssocRing.toAddGroupWithOne.{0} Rat (Ring.toNonAssocRing.{0} Rat (CommRing.toRing.{0} Rat Rat.commRing)))))))) n)) ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Nat Int (HasLiftT.mk.{1, 1} Nat Int (CoeTCₓ.coe.{1, 1} Nat Int (coeBase.{1, 1} Nat Int Int.hasCoe))) n)
+but is expected to have type
+ forall (n : Nat), Eq.{1} Int (Rat.num (Nat.cast.{0} Rat (NonAssocRing.toNatCast.{0} Rat (Ring.toNonAssocRing.{0} Rat (CommRing.toRing.{0} Rat Rat.commRing))) n)) (Nat.cast.{0} Int instNatCastInt n)
+Case conversion may be inaccurate. Consider using '#align rat.coe_nat_num Rat.coe_nat_numₓ'. -/
@[simp, norm_cast]
theorem coe_nat_num (n : ℕ) : (n : ℚ).num = n := by rw [← Int.cast_ofNat, coe_int_num]
#align rat.coe_nat_num Rat.coe_nat_num
--/
-#print Rat.coe_nat_den /-
+/- warning: rat.coe_nat_denom -> Rat.coe_nat_den is a dubious translation:
+lean 3 declaration is
+ forall (n : Nat), Eq.{1} Nat (Rat.den ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Nat Rat (HasLiftT.mk.{1, 1} Nat Rat (CoeTCₓ.coe.{1, 1} Nat Rat (Nat.castCoe.{0} Rat (AddMonoidWithOne.toNatCast.{0} Rat (AddGroupWithOne.toAddMonoidWithOne.{0} Rat (NonAssocRing.toAddGroupWithOne.{0} Rat (Ring.toNonAssocRing.{0} Rat (CommRing.toRing.{0} Rat Rat.commRing)))))))) n)) (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne)))
+but is expected to have type
+ forall (n : Nat), Eq.{1} Nat (Rat.den (Nat.cast.{0} Rat (NonAssocRing.toNatCast.{0} Rat (Ring.toNonAssocRing.{0} Rat (CommRing.toRing.{0} Rat Rat.commRing))) n)) (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1))
+Case conversion may be inaccurate. Consider using '#align rat.coe_nat_denom Rat.coe_nat_denₓ'. -/
@[simp, norm_cast]
theorem coe_nat_den (n : ℕ) : (n : ℚ).den = 1 := by rw [← Int.cast_ofNat, coe_int_denom]
#align rat.coe_nat_denom Rat.coe_nat_den
--/
#print Rat.coe_int_inj /-
-- Will be subsumed by `int.coe_inj` after we have defined
mathlib commit https://github.com/leanprover-community/mathlib/commit/da3fc4a33ff6bc75f077f691dc94c217b8d41559
@@ -139,7 +139,7 @@ theorem [anonymous] (n d h) : [anonymous] n ⟨d, h⟩ = n /. d := by
lean 3 declaration is
forall (n : Int) (d : Nat), Eq.{1} Rat (mkRat n d) (Rat.mk n ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Nat Int (HasLiftT.mk.{1, 1} Nat Int (CoeTCₓ.coe.{1, 1} Nat Int (coeBase.{1, 1} Nat Int Int.hasCoe))) d))
but is expected to have type
- forall (n : Int) (d : Nat), Eq.{1} Rat (mkRat n d) (Rat.divInt n (Nat.cast.{0} Int Int.instNatCastInt d))
+ forall (n : Int) (d : Nat), Eq.{1} Rat (mkRat n d) (Rat.divInt n (Nat.cast.{0} Int instNatCastInt d))
Case conversion may be inaccurate. Consider using '#align rat.mk_nat_eq Rat.mkRat_eqₓ'. -/
theorem mkRat_eq (n d) : mkRat n d = n /. d :=
rfl
@@ -325,7 +325,7 @@ theorem divInt_mul_right {a b c : ℤ} (c0 : c ≠ 0) : a * c /. (b * c) = a /.
lean 3 declaration is
forall {a : Rat}, Eq.{1} Rat (Rat.mk (Rat.num a) ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Nat Int (HasLiftT.mk.{1, 1} Nat Int (CoeTCₓ.coe.{1, 1} Nat Int (coeBase.{1, 1} Nat Int Int.hasCoe))) (Rat.den a))) a
but is expected to have type
- forall {a : Rat}, Eq.{1} Rat (Rat.divInt (Rat.num a) (Nat.cast.{0} Int Int.instNatCastInt (Rat.den a))) a
+ forall {a : Rat}, Eq.{1} Rat (Rat.divInt (Rat.num a) (Nat.cast.{0} Int instNatCastInt (Rat.den a))) a
Case conversion may be inaccurate. Consider using '#align rat.num_denom Rat.num_denₓ'. -/
@[simp]
theorem num_den : ∀ {a : ℚ}, a.num /. a.den = a
@@ -336,7 +336,7 @@ theorem num_den : ∀ {a : ℚ}, a.num /. a.den = a
lean 3 declaration is
forall {n : Int} {d : Nat} {h : LT.lt.{0} Nat Nat.hasLt (OfNat.ofNat.{0} Nat 0 (OfNat.mk.{0} Nat 0 (Zero.zero.{0} Nat Nat.hasZero))) d} {c : Nat.coprime (Int.natAbs n) d}, Eq.{1} Rat (Rat.mk' n d h c) (Rat.mk n ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Nat Int (HasLiftT.mk.{1, 1} Nat Int (CoeTCₓ.coe.{1, 1} Nat Int (coeBase.{1, 1} Nat Int Int.hasCoe))) d))
but is expected to have type
- forall {n : Int} {d : Nat} {h : Ne.{1} Nat d (OfNat.ofNat.{0} Nat 0 (instOfNatNat 0))} {c : Nat.coprime (Int.natAbs n) d}, Eq.{1} Rat (Rat.mk' n d h c) (Rat.divInt n (Nat.cast.{0} Int Int.instNatCastInt d))
+ forall {n : Int} {d : Nat} {h : Ne.{1} Nat d (OfNat.ofNat.{0} Nat 0 (instOfNatNat 0))} {c : Nat.coprime (Int.natAbs n) d}, Eq.{1} Rat (Rat.mk' n d h c) (Rat.divInt n (Nat.cast.{0} Int instNatCastInt d))
Case conversion may be inaccurate. Consider using '#align rat.num_denom' Rat.num_den'ₓ'. -/
theorem num_den' {n d h c} : (⟨n, d, h, c⟩ : ℚ) = n /. d :=
num_den.symm
@@ -356,7 +356,7 @@ theorem coe_int_eq_divInt (z : ℤ) : (z : ℚ) = z /. 1 :=
lean 3 declaration is
forall {C : Rat -> Sort.{u1}} (a : Rat), (forall (n : Int) (d : Nat), (LT.lt.{0} Nat Nat.hasLt (OfNat.ofNat.{0} Nat 0 (OfNat.mk.{0} Nat 0 (Zero.zero.{0} Nat Nat.hasZero))) d) -> (Nat.coprime (Int.natAbs n) d) -> (C (Rat.mk n ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Nat Int (HasLiftT.mk.{1, 1} Nat Int (CoeTCₓ.coe.{1, 1} Nat Int (coeBase.{1, 1} Nat Int Int.hasCoe))) d)))) -> (C a)
but is expected to have type
- forall {C : Rat -> Sort.{u1}} (a : Rat), (forall (n : [mdata borrowed:1 Int]) (d : Nat), (LT.lt.{0} Nat instLTNat (OfNat.ofNat.{0} Nat 0 (instOfNatNat 0)) d) -> (Nat.coprime (Int.natAbs n) d) -> (C (Rat.divInt n (Nat.cast.{0} Int Int.instNatCastInt d)))) -> (C a)
+ forall {C : Rat -> Sort.{u1}} (a : Rat), (forall (n : [mdata borrowed:1 Int]) (d : Nat), (LT.lt.{0} Nat instLTNat (OfNat.ofNat.{0} Nat 0 (instOfNatNat 0)) d) -> (Nat.coprime (Int.natAbs n) d) -> (C (Rat.divInt n (Nat.cast.{0} Int instNatCastInt d)))) -> (C a)
Case conversion may be inaccurate. Consider using '#align rat.num_denom_cases_on Rat.numDenCasesOnₓ'. -/
/-- Define a (dependent) function or prove `∀ r : ℚ, p r` by dealing with rational
numbers of the form `n /. d` with `0 < d` and coprime `n`, `d`. -/
@@ -370,7 +370,7 @@ def numDenCasesOn.{u} {C : ℚ → Sort u} :
lean 3 declaration is
forall {C : Rat -> Sort.{u1}} (a : Rat), (forall (n : Int) (d : Nat), (Ne.{1} Nat d (OfNat.ofNat.{0} Nat 0 (OfNat.mk.{0} Nat 0 (Zero.zero.{0} Nat Nat.hasZero)))) -> (C (Rat.mk n ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Nat Int (HasLiftT.mk.{1, 1} Nat Int (CoeTCₓ.coe.{1, 1} Nat Int (coeBase.{1, 1} Nat Int Int.hasCoe))) d)))) -> (C a)
but is expected to have type
- forall {C : Rat -> Sort.{u1}} (a : Rat), (forall (n : Int) (d : Nat), (Ne.{1} Nat d (OfNat.ofNat.{0} Nat 0 (instOfNatNat 0))) -> (C (Rat.divInt n (Nat.cast.{0} Int Int.instNatCastInt d)))) -> (C a)
+ forall {C : Rat -> Sort.{u1}} (a : Rat), (forall (n : Int) (d : Nat), (Ne.{1} Nat d (OfNat.ofNat.{0} Nat 0 (instOfNatNat 0))) -> (C (Rat.divInt n (Nat.cast.{0} Int instNatCastInt d)))) -> (C a)
Case conversion may be inaccurate. Consider using '#align rat.num_denom_cases_on' Rat.numDenCasesOn'ₓ'. -/
/-- Define a (dependent) function or prove `∀ r : ℚ, p r` by dealing with rational
numbers of the form `n /. d` with `d ≠ 0`. -/
@@ -393,7 +393,7 @@ instance : Add ℚ :=
lean 3 declaration is
forall (f : Rat -> Rat -> Rat) (f₁ : Int -> Int -> Int -> Int -> Int) (f₂ : Int -> Int -> Int -> Int -> Int), (forall {n₁ : Int} {d₁ : Nat} {h₁ : LT.lt.{0} Nat Nat.hasLt (OfNat.ofNat.{0} Nat 0 (OfNat.mk.{0} Nat 0 (Zero.zero.{0} Nat Nat.hasZero))) d₁} {c₁ : Nat.coprime (Int.natAbs n₁) d₁} {n₂ : Int} {d₂ : Nat} {h₂ : LT.lt.{0} Nat Nat.hasLt (OfNat.ofNat.{0} Nat 0 (OfNat.mk.{0} Nat 0 (Zero.zero.{0} Nat Nat.hasZero))) d₂} {c₂ : Nat.coprime (Int.natAbs n₂) d₂}, Eq.{1} Rat (f (Rat.mk' n₁ d₁ h₁ c₁) (Rat.mk' n₂ d₂ h₂ c₂)) (Rat.mk (f₁ n₁ ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Nat Int (HasLiftT.mk.{1, 1} Nat Int (CoeTCₓ.coe.{1, 1} Nat Int (coeBase.{1, 1} Nat Int Int.hasCoe))) d₁) n₂ ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Nat Int (HasLiftT.mk.{1, 1} Nat Int (CoeTCₓ.coe.{1, 1} Nat Int (coeBase.{1, 1} Nat Int Int.hasCoe))) d₂)) (f₂ n₁ ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Nat Int (HasLiftT.mk.{1, 1} Nat Int (CoeTCₓ.coe.{1, 1} Nat Int (coeBase.{1, 1} Nat Int Int.hasCoe))) d₁) n₂ ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Nat Int (HasLiftT.mk.{1, 1} Nat Int (CoeTCₓ.coe.{1, 1} Nat Int (coeBase.{1, 1} Nat Int Int.hasCoe))) d₂)))) -> (forall {n₁ : Int} {d₁ : Int} {n₂ : Int} {d₂ : Int}, (Ne.{1} Int d₁ (OfNat.ofNat.{0} Int 0 (OfNat.mk.{0} Int 0 (Zero.zero.{0} Int Int.hasZero)))) -> (Ne.{1} Int d₂ (OfNat.ofNat.{0} Int 0 (OfNat.mk.{0} Int 0 (Zero.zero.{0} Int Int.hasZero)))) -> (Ne.{1} Int (f₂ n₁ d₁ n₂ d₂) (OfNat.ofNat.{0} Int 0 (OfNat.mk.{0} Int 0 (Zero.zero.{0} Int Int.hasZero))))) -> (forall (a : Int) (b : Int) (c : Int) (d : Int), (Ne.{1} Int b (OfNat.ofNat.{0} Int 0 (OfNat.mk.{0} Int 0 (Zero.zero.{0} Int Int.hasZero)))) -> (Ne.{1} Int d (OfNat.ofNat.{0} Int 0 (OfNat.mk.{0} Int 0 (Zero.zero.{0} Int Int.hasZero)))) -> (forall {n₁ : Int} {d₁ : Int} {n₂ : Int} {d₂ : Int}, (Eq.{1} Int (HMul.hMul.{0, 0, 0} Int Int Int (instHMul.{0} Int Int.hasMul) a d₁) (HMul.hMul.{0, 0, 0} Int Int Int (instHMul.{0} Int Int.hasMul) n₁ b)) -> (Eq.{1} Int (HMul.hMul.{0, 0, 0} Int Int Int (instHMul.{0} Int Int.hasMul) c d₂) (HMul.hMul.{0, 0, 0} Int Int Int (instHMul.{0} Int Int.hasMul) n₂ d)) -> (Eq.{1} Int (HMul.hMul.{0, 0, 0} Int Int Int (instHMul.{0} Int Int.hasMul) (f₁ n₁ d₁ n₂ d₂) (f₂ a b c d)) (HMul.hMul.{0, 0, 0} Int Int Int (instHMul.{0} Int Int.hasMul) (f₁ a b c d) (f₂ n₁ d₁ n₂ d₂)))) -> (Eq.{1} Rat (f (Rat.mk a b) (Rat.mk c d)) (Rat.mk (f₁ a b c d) (f₂ a b c d))))
but is expected to have type
- forall (f : Rat -> Rat -> Rat) (f₁ : Int -> Int -> Int -> Int -> Int) (f₂ : Int -> Int -> Int -> Int -> Int), (forall {n₁ : Int} {d₁ : Nat} {h₁ : Ne.{1} Nat d₁ (OfNat.ofNat.{0} Nat 0 (instOfNatNat 0))} {c₁ : Nat.coprime (Int.natAbs n₁) d₁} {n₂ : Int} {d₂ : Nat} {h₂ : Ne.{1} Nat d₂ (OfNat.ofNat.{0} Nat 0 (instOfNatNat 0))} {c₂ : Nat.coprime (Int.natAbs n₂) d₂}, Eq.{1} Rat (f (Rat.mk' n₁ d₁ h₁ c₁) (Rat.mk' n₂ d₂ h₂ c₂)) (Rat.divInt (f₁ n₁ (Nat.cast.{0} Int Int.instNatCastInt d₁) n₂ (Nat.cast.{0} Int Int.instNatCastInt d₂)) (f₂ n₁ (Nat.cast.{0} Int Int.instNatCastInt d₁) n₂ (Nat.cast.{0} Int Int.instNatCastInt d₂)))) -> (forall {n₁ : Int} {d₁ : Int} {n₂ : Int} {d₂ : Int}, (Ne.{1} Int d₁ (OfNat.ofNat.{0} Int 0 (instOfNatInt 0))) -> (Ne.{1} Int d₂ (OfNat.ofNat.{0} Int 0 (instOfNatInt 0))) -> (Ne.{1} Int (f₂ n₁ d₁ n₂ d₂) (OfNat.ofNat.{0} Int 0 (instOfNatInt 0)))) -> (forall (a : Int) (b : Int) (c : Int) (d : Int), (Ne.{1} Int b (OfNat.ofNat.{0} Int 0 (instOfNatInt 0))) -> (Ne.{1} Int d (OfNat.ofNat.{0} Int 0 (instOfNatInt 0))) -> (forall {n₁ : Int} {d₁ : Int} {n₂ : Int} {d₂ : Int}, (Eq.{1} Int (HMul.hMul.{0, 0, 0} Int Int Int (instHMul.{0} Int Int.instMulInt) a d₁) (HMul.hMul.{0, 0, 0} Int Int Int (instHMul.{0} Int Int.instMulInt) n₁ b)) -> (Eq.{1} Int (HMul.hMul.{0, 0, 0} Int Int Int (instHMul.{0} Int Int.instMulInt) c d₂) (HMul.hMul.{0, 0, 0} Int Int Int (instHMul.{0} Int Int.instMulInt) n₂ d)) -> (Eq.{1} Int (HMul.hMul.{0, 0, 0} Int Int Int (instHMul.{0} Int Int.instMulInt) (f₁ n₁ d₁ n₂ d₂) (f₂ a b c d)) (HMul.hMul.{0, 0, 0} Int Int Int (instHMul.{0} Int Int.instMulInt) (f₁ a b c d) (f₂ n₁ d₁ n₂ d₂)))) -> (Eq.{1} Rat (f (Rat.divInt a b) (Rat.divInt c d)) (Rat.divInt (f₁ a b c d) (f₂ a b c d))))
+ forall (f : Rat -> Rat -> Rat) (f₁ : Int -> Int -> Int -> Int -> Int) (f₂ : Int -> Int -> Int -> Int -> Int), (forall {n₁ : Int} {d₁ : Nat} {h₁ : Ne.{1} Nat d₁ (OfNat.ofNat.{0} Nat 0 (instOfNatNat 0))} {c₁ : Nat.coprime (Int.natAbs n₁) d₁} {n₂ : Int} {d₂ : Nat} {h₂ : Ne.{1} Nat d₂ (OfNat.ofNat.{0} Nat 0 (instOfNatNat 0))} {c₂ : Nat.coprime (Int.natAbs n₂) d₂}, Eq.{1} Rat (f (Rat.mk' n₁ d₁ h₁ c₁) (Rat.mk' n₂ d₂ h₂ c₂)) (Rat.divInt (f₁ n₁ (Nat.cast.{0} Int instNatCastInt d₁) n₂ (Nat.cast.{0} Int instNatCastInt d₂)) (f₂ n₁ (Nat.cast.{0} Int instNatCastInt d₁) n₂ (Nat.cast.{0} Int instNatCastInt d₂)))) -> (forall {n₁ : Int} {d₁ : Int} {n₂ : Int} {d₂ : Int}, (Ne.{1} Int d₁ (OfNat.ofNat.{0} Int 0 (instOfNatInt 0))) -> (Ne.{1} Int d₂ (OfNat.ofNat.{0} Int 0 (instOfNatInt 0))) -> (Ne.{1} Int (f₂ n₁ d₁ n₂ d₂) (OfNat.ofNat.{0} Int 0 (instOfNatInt 0)))) -> (forall (a : Int) (b : Int) (c : Int) (d : Int), (Ne.{1} Int b (OfNat.ofNat.{0} Int 0 (instOfNatInt 0))) -> (Ne.{1} Int d (OfNat.ofNat.{0} Int 0 (instOfNatInt 0))) -> (forall {n₁ : Int} {d₁ : Int} {n₂ : Int} {d₂ : Int}, (Eq.{1} Int (HMul.hMul.{0, 0, 0} Int Int Int (instHMul.{0} Int Int.instMulInt) a d₁) (HMul.hMul.{0, 0, 0} Int Int Int (instHMul.{0} Int Int.instMulInt) n₁ b)) -> (Eq.{1} Int (HMul.hMul.{0, 0, 0} Int Int Int (instHMul.{0} Int Int.instMulInt) c d₂) (HMul.hMul.{0, 0, 0} Int Int Int (instHMul.{0} Int Int.instMulInt) n₂ d)) -> (Eq.{1} Int (HMul.hMul.{0, 0, 0} Int Int Int (instHMul.{0} Int Int.instMulInt) (f₁ n₁ d₁ n₂ d₂) (f₂ a b c d)) (HMul.hMul.{0, 0, 0} Int Int Int (instHMul.{0} Int Int.instMulInt) (f₁ a b c d) (f₂ n₁ d₁ n₂ d₂)))) -> (Eq.{1} Rat (f (Rat.divInt a b) (Rat.divInt c d)) (Rat.divInt (f₁ a b c d) (f₂ a b c d))))
Case conversion may be inaccurate. Consider using '#align rat.lift_binop_eq Rat.lift_binop_eqₓ'. -/
theorem lift_binop_eq (f : ℚ → ℚ → ℚ) (f₁ : ℤ → ℤ → ℤ → ℤ → ℤ) (f₂ : ℤ → ℤ → ℤ → ℤ → ℤ)
(fv :
@@ -917,7 +917,7 @@ theorem divInt_ne_zero_of_ne_zero {n d : ℤ} (h : n ≠ 0) (hd : d ≠ 0) : n /
lean 3 declaration is
forall (q : Rat) (r : Rat), Eq.{1} Rat (HMul.hMul.{0, 0, 0} Rat Rat Rat (instHMul.{0} Rat Rat.hasMul) q r) (Rat.mk (HMul.hMul.{0, 0, 0} Int Int Int (instHMul.{0} Int Int.hasMul) (Rat.num q) (Rat.num r)) ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Nat Int (HasLiftT.mk.{1, 1} Nat Int (CoeTCₓ.coe.{1, 1} Nat Int (coeBase.{1, 1} Nat Int Int.hasCoe))) (HMul.hMul.{0, 0, 0} Nat Nat Nat (instHMul.{0} Nat Nat.hasMul) (Rat.den q) (Rat.den r))))
but is expected to have type
- forall (q : Rat) (r : Rat), Eq.{1} Rat (HMul.hMul.{0, 0, 0} Rat Rat Rat (instHMul.{0} Rat Rat.instMulRat) q r) (Rat.divInt (HMul.hMul.{0, 0, 0} Int Int Int (instHMul.{0} Int Int.instMulInt) (Rat.num q) (Rat.num r)) (Nat.cast.{0} Int Int.instNatCastInt (HMul.hMul.{0, 0, 0} Nat Nat Nat (instHMul.{0} Nat instMulNat) (Rat.den q) (Rat.den r))))
+ forall (q : Rat) (r : Rat), Eq.{1} Rat (HMul.hMul.{0, 0, 0} Rat Rat Rat (instHMul.{0} Rat Rat.instMulRat) q r) (Rat.divInt (HMul.hMul.{0, 0, 0} Int Int Int (instHMul.{0} Int Int.instMulInt) (Rat.num q) (Rat.num r)) (Nat.cast.{0} Int instNatCastInt (HMul.hMul.{0, 0, 0} Nat Nat Nat (instHMul.{0} Nat instMulNat) (Rat.den q) (Rat.den r))))
Case conversion may be inaccurate. Consider using '#align rat.mul_num_denom Rat.mul_num_denₓ'. -/
theorem mul_num_den (q r : ℚ) : q * r = q.num * r.num /. ↑(q.den * r.den) :=
by
@@ -932,7 +932,7 @@ theorem mul_num_den (q r : ℚ) : q * r = q.num * r.num /. ↑(q.den * r.den) :=
lean 3 declaration is
forall (q : Rat) (r : Rat), Eq.{1} Rat (HDiv.hDiv.{0, 0, 0} Rat Rat Rat (instHDiv.{0} Rat Rat.hasDiv) q r) (Rat.mk (HMul.hMul.{0, 0, 0} Int Int Int (instHMul.{0} Int Int.hasMul) (Rat.num q) ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Nat Int (HasLiftT.mk.{1, 1} Nat Int (CoeTCₓ.coe.{1, 1} Nat Int (coeBase.{1, 1} Nat Int Int.hasCoe))) (Rat.den r))) (HMul.hMul.{0, 0, 0} Int Int Int (instHMul.{0} Int Int.hasMul) ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Nat Int (HasLiftT.mk.{1, 1} Nat Int (CoeTCₓ.coe.{1, 1} Nat Int (coeBase.{1, 1} Nat Int Int.hasCoe))) (Rat.den q)) (Rat.num r)))
but is expected to have type
- forall (q : Rat) (r : Rat), Eq.{1} Rat (HDiv.hDiv.{0, 0, 0} Rat Rat Rat (instHDiv.{0} Rat Rat.instDivRat) q r) (Rat.divInt (HMul.hMul.{0, 0, 0} Int Int Int (instHMul.{0} Int Int.instMulInt) (Rat.num q) (Nat.cast.{0} Int Int.instNatCastInt (Rat.den r))) (HMul.hMul.{0, 0, 0} Int Int Int (instHMul.{0} Int Int.instMulInt) (Nat.cast.{0} Int Int.instNatCastInt (Rat.den q)) (Rat.num r)))
+ forall (q : Rat) (r : Rat), Eq.{1} Rat (HDiv.hDiv.{0, 0, 0} Rat Rat Rat (instHDiv.{0} Rat Rat.instDivRat) q r) (Rat.divInt (HMul.hMul.{0, 0, 0} Int Int Int (instHMul.{0} Int Int.instMulInt) (Rat.num q) (Nat.cast.{0} Int instNatCastInt (Rat.den r))) (HMul.hMul.{0, 0, 0} Int Int Int (instHMul.{0} Int Int.instMulInt) (Nat.cast.{0} Int instNatCastInt (Rat.den q)) (Rat.num r)))
Case conversion may be inaccurate. Consider using '#align rat.div_num_denom Rat.div_num_denₓ'. -/
theorem div_num_den (q r : ℚ) : q / r = q.num * r.den /. (q.den * r.num) :=
if hr : r.num = 0 then by
@@ -1052,7 +1052,7 @@ instance canLift : CanLift ℚ ℤ coe fun q => q.den = 1 :=
lean 3 declaration is
forall (n : Nat), Eq.{1} Rat ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Nat Rat (HasLiftT.mk.{1, 1} Nat Rat (CoeTCₓ.coe.{1, 1} Nat Rat (Nat.castCoe.{0} Rat (AddMonoidWithOne.toNatCast.{0} Rat (AddGroupWithOne.toAddMonoidWithOne.{0} Rat (NonAssocRing.toAddGroupWithOne.{0} Rat (Ring.toNonAssocRing.{0} Rat (CommRing.toRing.{0} Rat Rat.commRing)))))))) n) (Rat.mk ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Nat Int (HasLiftT.mk.{1, 1} Nat Int (CoeTCₓ.coe.{1, 1} Nat Int (coeBase.{1, 1} Nat Int Int.hasCoe))) n) (OfNat.ofNat.{0} Int 1 (OfNat.mk.{0} Int 1 (One.one.{0} Int Int.hasOne))))
but is expected to have type
- forall (n : Nat), Eq.{1} Rat (Nat.cast.{0} Rat (NonAssocRing.toNatCast.{0} Rat (Ring.toNonAssocRing.{0} Rat (CommRing.toRing.{0} Rat Rat.commRing))) n) (Rat.divInt (Nat.cast.{0} Int Int.instNatCastInt n) (OfNat.ofNat.{0} Int 1 (instOfNatInt 1)))
+ forall (n : Nat), Eq.{1} Rat (Nat.cast.{0} Rat (NonAssocRing.toNatCast.{0} Rat (Ring.toNonAssocRing.{0} Rat (CommRing.toRing.{0} Rat Rat.commRing))) n) (Rat.divInt (Nat.cast.{0} Int instNatCastInt n) (OfNat.ofNat.{0} Int 1 (instOfNatInt 1)))
Case conversion may be inaccurate. Consider using '#align rat.coe_nat_eq_mk Rat.coe_nat_eq_divIntₓ'. -/
theorem coe_nat_eq_divInt (n : ℕ) : ↑n = n /. 1 := by rw [← Int.cast_ofNat, coe_int_eq_mk]
#align rat.coe_nat_eq_mk Rat.coe_nat_eq_divInt
mathlib commit https://github.com/leanprover-community/mathlib/commit/3180fab693e2cee3bff62675571264cb8778b212
@@ -754,8 +754,8 @@ instance : CommGroupWithZero ℚ :=
exists_pair_ne := ⟨0, 1, Rat.zero_ne_one⟩
inv_zero := rfl
mul_inv_cancel := Rat.mul_inv_cancel
- mul_zero := mul_zero
- zero_mul := zero_mul }
+ mul_zero := MulZeroClass.mul_zero
+ zero_mul := MulZeroClass.zero_mul }
instance : IsDomain ℚ :=
NoZeroDivisors.to_isDomain _
mathlib commit https://github.com/leanprover-community/mathlib/commit/4c586d291f189eecb9d00581aeb3dd998ac34442
@@ -707,7 +707,7 @@ protected theorem inv_mul_cancel (h : a ≠ 0) : a⁻¹ * a = 1 :=
#align rat.inv_mul_cancel Rat.inv_mul_cancel
-/
-/- ./././Mathport/Syntax/Translate/Tactic/Builtin.lean:72:18: unsupported non-interactive tactic tactic.mk_dec_eq_instance -/
+/- ./././Mathport/Syntax/Translate/Tactic/Builtin.lean:69:18: unsupported non-interactive tactic tactic.mk_dec_eq_instance -/
instance : DecidableEq ℚ := by
run_tac
tactic.mk_dec_eq_instance
mathlib commit https://github.com/leanprover-community/mathlib/commit/bd9851ca476957ea4549eb19b40e7b5ade9428cc
q ^ n
(#12506)
Prove (q ^ n).num = q.num ^ n
and (q ^ n).den = q.den ^ n
by making those defeq. It is somewhat painful. (q ^ n).den = q.den ^ n
is also defeq for NNRat
, but not (q ^ n).num = q.num ^ n
due to the Int.natAbs
in the definition of NNRat.num
.
Co-authored-by: Eric Wieser <wieser.eric@gmail.com>
@@ -4,7 +4,7 @@ Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Mario Carneiro
-/
import Mathlib.Algebra.Ring.Basic
-import Mathlib.Algebra.GroupWithZero.Basic
+import Mathlib.Algebra.GroupWithZero.Units.Basic
import Mathlib.Algebra.Order.Ring.Int
import Mathlib.Data.Int.Cast.Defs
import Mathlib.Data.Rat.Init
@@ -44,6 +44,8 @@ theorem pos (a : ℚ) : 0 < a.den := Nat.pos_of_ne_zero a.den_nz
#align rat.of_int Rat.ofInt
+lemma mk'_num_den (q : ℚ) : mk' q.num q.den q.den_nz q.reduced = q := rfl
+
@[simp]
theorem ofInt_eq_cast (n : ℤ) : ofInt n = Int.cast n :=
rfl
@@ -218,6 +220,12 @@ lemma divInt_mul_divInt' (n₁ d₁ n₂ d₂ : ℤ) : (n₁ /. d₁) * (n₂ /.
attribute [simp] mkRat_mul_mkRat
+lemma mk'_mul_mk' (n₁ n₂ : ℤ) (d₁ d₂ : ℕ) (hd₁ hd₂ hnd₁ hnd₂) (h₁₂ : n₁.natAbs.Coprime d₂)
+ (h₂₁ : n₂.natAbs.Coprime d₁) :
+ mk' n₁ d₁ hd₁ hnd₁ * mk' n₂ d₂ hd₂ hnd₂ = mk' (n₁ * n₂) (d₁ * d₂) (Nat.mul_ne_zero hd₁ hd₂) (by
+ rw [Int.natAbs_mul]; exact (hnd₁.mul h₂₁).mul_right (h₁₂.mul hnd₂)) := by
+ rw [mul_def]; dsimp; rw [mk_eq_normalize]
+
lemma mul_eq_mkRat (q r : ℚ) : q * r = mkRat (q.num * r.num) (q.den * r.den) := by
rw [mul_def, normalize_eq_mkRat]
@@ -227,6 +235,28 @@ alias divInt_eq_divInt := divInt_eq_iff
@[deprecated] alias mul_num_den := mul_eq_mkRat
#align rat.mul_num_denom Rat.mul_eq_mkRat
+instance instPowNat : Pow ℚ ℕ where
+ pow q n := ⟨q.num ^ n, q.den ^ n, by simp [Nat.pow_eq_zero], by
+ rw [Int.natAbs_pow]; exact q.reduced.pow _ _⟩
+
+lemma pow_def (q : ℚ) (n : ℕ) :
+ q ^ n = ⟨q.num ^ n, q.den ^ n,
+ by simp [Nat.pow_eq_zero],
+ by rw [Int.natAbs_pow]; exact q.reduced.pow _ _⟩ := rfl
+
+lemma pow_eq_mkRat (q : ℚ) (n : ℕ) : q ^ n = mkRat (q.num ^ n) (q.den ^ n) := by
+ rw [pow_def, mk_eq_mkRat]
+
+lemma pow_eq_divInt (q : ℚ) (n : ℕ) : q ^ n = q.num ^ n /. q.den ^ n := by
+ rw [pow_def, mk_eq_divInt, Int.natCast_pow]
+
+@[simp] lemma num_pow (q : ℚ) (n : ℕ) : (q ^ n).num = q.num ^ n := rfl
+@[simp] lemma den_pow (q : ℚ) (n : ℕ) : (q ^ n).den = q.den ^ n := rfl
+
+@[simp] lemma mk'_pow (num : ℤ) (den : ℕ) (hd hdn) (n : ℕ) :
+ mk' num den hd hdn ^ n = mk' (num ^ n) (den ^ n)
+ (by simp [Nat.pow_eq_zero, hd]) (by rw [Int.natAbs_pow]; exact hdn.pow _ _) := rfl
+
#align rat.inv Rat.inv
instance : Inv ℚ :=
@@ -350,6 +380,16 @@ instance commRing : CommRing ℚ where
one_mul := Rat.one_mul
mul_comm := Rat.mul_comm
mul_assoc := Rat.mul_assoc
+ npow n q := q ^ n
+ npow_zero := by intros; apply Rat.ext <;> simp
+ npow_succ n q := by
+ dsimp
+ rw [← q.mk'_num_den, mk'_pow, mk'_mul_mk']
+ congr
+ · rw [mk'_pow, Int.natAbs_pow]
+ exact q.reduced.pow_left _
+ · rw [mk'_pow]
+ exact q.reduced.pow_right _
zero_mul := Rat.zero_mul
mul_zero := Rat.mul_zero
left_distrib := Rat.mul_add
@@ -481,6 +521,9 @@ protected theorem add_divInt (a b c : ℤ) : (a + b) /. c = a /. c + b /. c :=
theorem divInt_eq_div (n d : ℤ) : n /. d = (n : ℚ) / d := by simp [div_def']
#align rat.mk_eq_div Rat.divInt_eq_div
+lemma intCast_div_eq_divInt (n d : ℤ) : (n : ℚ) / (d) = n /. d := by rw [divInt_eq_div]
+#align rat.coe_int_div_eq_mk Rat.intCast_div_eq_divInt
+
theorem divInt_mul_divInt_cancel {x : ℤ} (hx : x ≠ 0) (n d : ℤ) : n /. x * (x /. d) = n /. d := by
by_cases hd : d = 0
· rw [hd]
@@ -498,16 +541,17 @@ theorem divInt_div_divInt_cancel_right {x : ℤ} (hx : x ≠ 0) (n d : ℤ) :
rw [div_eq_mul_inv, inv_divInt', mul_comm, divInt_mul_divInt_cancel hx]
#align rat.mk_div_mk_cancel_right Rat.divInt_div_divInt_cancel_right
-theorem intCast_div_eq_divInt {n d : ℤ} : (n : ℚ) / (d) = n /. d := by
- repeat rw [intCast_eq_divInt]
- exact divInt_div_divInt_cancel_left one_ne_zero n d
-#align rat.coe_int_div_eq_mk Rat.intCast_div_eq_divInt
-
-- Porting note: see porting note above about `Int.cast`@[simp]
theorem num_div_den (r : ℚ) : (r.num : ℚ) / (r.den : ℚ) = r := by
rw [← Int.cast_natCast]; erw [← divInt_eq_div, num_divInt_den]
#align rat.num_div_denom Rat.num_div_den
+@[simp] lemma divInt_pow (num : ℕ) (den : ℤ) (n : ℕ) : (num /. den) ^ n = num ^ n /. den ^ n := by
+ simp [divInt_eq_div, div_pow]
+
+@[simp] lemma mkRat_pow (num den : ℕ) (n : ℕ) : mkRat num den ^ n = mkRat (num ^ n) (den ^ n) := by
+ rw [mkRat_eq_divInt, mkRat_eq_divInt, divInt_pow, Int.natCast_pow]
+
theorem coe_int_num_of_den_eq_one {q : ℚ} (hq : q.den = 1) : (q.num : ℚ) = q := by
conv_rhs => rw [← num_divInt_den q, hq]
rw [intCast_eq_divInt]
@@ -499,7 +499,7 @@ theorem divInt_div_divInt_cancel_right {x : ℤ} (hx : x ≠ 0) (n d : ℤ) :
#align rat.mk_div_mk_cancel_right Rat.divInt_div_divInt_cancel_right
theorem intCast_div_eq_divInt {n d : ℤ} : (n : ℚ) / (d) = n /. d := by
- repeat' rw [intCast_eq_divInt]
+ repeat rw [intCast_eq_divInt]
exact divInt_div_divInt_cancel_left one_ne_zero n d
#align rat.coe_int_div_eq_mk Rat.intCast_div_eq_divInt
There are more wrong lemmas in Std, but it's out of my scope
@@ -54,43 +54,45 @@ theorem ofInt_eq_cast (n : ℤ) : ofInt n = Int.cast n :=
@[simp] lemma num_ofNat (n : ℕ) : num (no_index (OfNat.ofNat n)) = OfNat.ofNat n := rfl
@[simp] lemma den_ofNat (n : ℕ) : den (no_index (OfNat.ofNat n)) = 1 := rfl
-@[simp, norm_cast]
-theorem coe_int_num (n : ℤ) : (n : ℚ).num = n :=
- rfl
-#align rat.coe_int_num Rat.coe_int_num
+@[simp, norm_cast] lemma num_natCast (n : ℕ) : num n = n := rfl
+#align rat.coe_nat_num Rat.num_natCast
-@[simp, norm_cast]
-theorem coe_int_den (n : ℤ) : (n : ℚ).den = 1 :=
- rfl
-#align rat.coe_int_denom Rat.coe_int_den
+@[simp, norm_cast] lemma den_natCast (n : ℕ) : den n = 1 := rfl
+#align rat.coe_nat_denom Rat.den_natCast
+
+-- TODO: Replace `intCast_num`/`intCast_den` the names in Std
+@[simp, norm_cast] lemma num_intCast (n : ℤ) : (n : ℚ).num = n := rfl
+#align rat.coe_int_num Rat.num_intCast
+
+@[simp, norm_cast] lemma den_intCast (n : ℤ) : (n : ℚ).den = 1 := rfl
+#align rat.coe_int_denom Rat.den_intCast
+
+-- 2024-04-29
+@[deprecated] alias coe_int_num := num_intCast
+@[deprecated] alias coe_int_den := den_intCast
#noalign rat.mk_pnat
+#noalign rat.mk_pnat_eq
+#noalign rat.zero_mk_pnat
-- Porting note (#11215): TODO Should this be namespaced?
#align rat.mk_nat mkRat
-#noalign rat.mk_pnat_eq
-
-theorem mkRat_eq (n d) : mkRat n d = n /. d :=
- rfl
-#align rat.mk_nat_eq Rat.mkRat_eq
+lemma mkRat_eq_divInt (n d) : mkRat n d = n /. d := rfl
+#align rat.mk_nat_eq Rat.mkRat_eq_divInt
#align rat.mk_zero Rat.divInt_zero
-
-@[simp]
-theorem zero_mk (d) (h : d ≠ 0) (w) : mk' 0 d h w = 0 := by congr
-
-#noalign rat.zero_mk_pnat
-
#align rat.zero_mk_nat Rat.zero_mkRat
#align rat.zero_mk Rat.zero_divInt
+@[simp] lemma mk'_zero (d) (h : d ≠ 0) (w) : mk' 0 d h w = 0 := by congr
+
@[simp]
lemma num_eq_zero {q : ℚ} : q.num = 0 ↔ q = 0 := by
induction q
constructor
· rintro rfl
- exact zero_mk _ _ _
+ exact mk'_zero _ _ _
· exact congr_arg num
lemma num_ne_zero {q : ℚ} : q.num ≠ 0 ↔ q ≠ 0 := num_eq_zero.not
@@ -216,11 +218,14 @@ lemma divInt_mul_divInt' (n₁ d₁ n₂ d₂ : ℤ) : (n₁ /. d₁) * (n₂ /.
attribute [simp] mkRat_mul_mkRat
-lemma mul_def' (q r : ℚ) : q * r = mkRat (q.num * r.num) (q.den * r.den) := by
+lemma mul_eq_mkRat (q r : ℚ) : q * r = mkRat (q.num * r.num) (q.den * r.den) := by
rw [mul_def, normalize_eq_mkRat]
-@[deprecated] alias mul_num_den := mul_def'
-#align rat.mul_num_denom Rat.mul_def'
+-- TODO: Rename `divInt_eq_iff` in Std to `divInt_eq_divInt`
+alias divInt_eq_divInt := divInt_eq_iff
+
+@[deprecated] alias mul_num_den := mul_eq_mkRat
+#align rat.mul_num_denom Rat.mul_eq_mkRat
#align rat.inv Rat.inv
@@ -230,7 +235,8 @@ instance : Inv ℚ :=
@[simp] lemma inv_divInt' (a b : ℤ) : (a /. b)⁻¹ = b /. a := inv_divInt ..
#align rat.inv_def Rat.inv_divInt
-@[simp] lemma inv_mkRat (a : ℤ) (b : ℕ) : (mkRat a b)⁻¹ = b /. a := by rw [mkRat_eq, inv_divInt']
+@[simp] lemma inv_mkRat (a : ℤ) (b : ℕ) : (mkRat a b)⁻¹ = b /. a := by
+ rw [mkRat_eq_divInt, inv_divInt']
lemma inv_def' (q : ℚ) : q⁻¹ = q.den /. q.num := by rw [← inv_divInt', num_divInt_den]
#align rat.inv_def' Rat.inv_def'
@@ -273,7 +279,7 @@ protected lemma add_left_neg : -a + a = 0 := by simp [add_def, normalize_eq_mkRa
#align rat.mk_zero_one Rat.zero_divInt
@[simp] lemma divInt_one (n : ℤ) : n /. 1 = n := by simp [divInt, mkRat, normalize]
-@[simp] lemma mkRat_one (n : ℤ) : mkRat n 1 = n := by simp [mkRat_eq]
+@[simp] lemma mkRat_one (n : ℤ) : mkRat n 1 = n := by simp [mkRat_eq_divInt]
lemma divInt_one_one : 1 /. 1 = 1 := by rw [divInt_one]; rfl
#align rat.mk_one_one Rat.divInt_one_one
@@ -315,7 +321,7 @@ attribute [simp] mkRat_eq_zero
protected theorem mul_inv_cancel : a ≠ 0 → a * a⁻¹ = 1 :=
numDenCasesOn' a fun n d hd hn ↦ by
simp [hd] at hn;
- simp [-divInt_ofNat, mkRat_eq, mul_comm, mul_ne_zero hn (Int.ofNat_ne_zero.2 hd)]
+ simp [-divInt_ofNat, mkRat_eq_divInt, mul_comm, mul_ne_zero hn (Int.ofNat_ne_zero.2 hd)]
#align rat.mul_inv_cancel Rat.mul_inv_cancel
protected theorem inv_mul_cancel (h : a ≠ 0) : a⁻¹ * a = 1 :=
@@ -513,7 +519,7 @@ lemma eq_num_of_isInt {q : ℚ} (h : q.isInt) : q = q.num := by
exact (Rat.coe_int_num_of_den_eq_one h).symm
theorem den_eq_one_iff (r : ℚ) : r.den = 1 ↔ ↑r.num = r :=
- ⟨Rat.coe_int_num_of_den_eq_one, fun h => h ▸ Rat.coe_int_den r.num⟩
+ ⟨Rat.coe_int_num_of_den_eq_one, fun h => h ▸ Rat.den_intCast r.num⟩
#align rat.denom_eq_one_iff Rat.den_eq_one_iff
instance canLift : CanLift ℚ ℤ (↑) fun q => q.den = 1 :=
@@ -529,16 +535,6 @@ theorem natCast_eq_divInt (n : ℕ) : ↑n = n /. 1 := by
@[deprecated] alias coe_int_div_eq_divInt := intCast_div_eq_divInt
@[deprecated] alias coe_nat_eq_divInt := natCast_eq_divInt
-@[simp, norm_cast] lemma num_natCast (n : ℕ) : num n = n := rfl
-#align rat.coe_nat_num Rat.num_natCast
-
-@[simp, norm_cast] lemma den_natCast (n : ℕ) : den n = 1 := rfl
-#align rat.coe_nat_denom Rat.den_natCast
-
--- TODO: Fix the names in Std
-alias num_intCast := intCast_num
-alias den_intCast := intCast_den
-
-- Will be subsumed by `Int.coe_inj` after we have defined
-- `LinearOrderedField ℚ` (which implies characteristic zero).
theorem coe_int_inj (m n : ℤ) : (m : ℚ) = n ↔ m = n :=
@@ -548,6 +544,6 @@ theorem coe_int_inj (m n : ℤ) : (m : ℚ) = n ↔ m = n :=
end Casts
theorem mkRat_eq_div (n : ℤ) (d : ℕ) : mkRat n d = n / d := by
- simp only [mkRat_eq, divInt_eq_div, Int.cast_natCast]
+ simp only [mkRat_eq_divInt, divInt_eq_div, Int.cast_natCast]
end Rat
deprecated
attributeWhy these changes?
@@ -194,13 +194,12 @@ lemma neg_def (q : ℚ) : -q = -q.num /. q.den := by rw [← neg_divInt, num_div
@[simp] lemma divInt_neg (n d : ℤ) : n /. -d = -n /. d := divInt_neg' ..
#align rat.mk_neg_denom Rat.divInt_neg
--- 2024-03-18
-@[deprecated] alias divInt_neg_den := divInt_neg
+@[deprecated] alias divInt_neg_den := divInt_neg -- 2024-03-18
attribute [simp] divInt_sub_divInt
--- 2024-03-18
-@[deprecated divInt_sub_divInt] lemma sub_def'' {a b c d : ℤ} (b0 : b ≠ 0) (d0 : d ≠ 0) :
+@[deprecated divInt_sub_divInt] -- 2024-03-18
+lemma sub_def'' {a b c d : ℤ} (b0 : b ≠ 0) (d0 : d ≠ 0) :
a /. b - c /. d = (a * d - c * b) /. (b * d) := divInt_sub_divInt _ _ b0 d0
#align rat.sub_def Rat.sub_def''
@@ -270,8 +269,7 @@ protected theorem add_assoc : a + b + c = a + (b + c) :=
protected lemma add_left_neg : -a + a = 0 := by simp [add_def, normalize_eq_mkRat]
#align rat.add_left_neg Rat.add_left_neg
--- 2024-03-18
-@[deprecated zero_divInt] lemma divInt_zero_one : 0 /. 1 = 0 := zero_divInt _
+@[deprecated zero_divInt] lemma divInt_zero_one : 0 /. 1 = 0 := zero_divInt _ -- 2024-03-18
#align rat.mk_zero_one Rat.zero_divInt
@[simp] lemma divInt_one (n : ℤ) : n /. 1 = n := by simp [divInt, mkRat, normalize]
@@ -280,8 +278,8 @@ protected lemma add_left_neg : -a + a = 0 := by simp [add_def, normalize_eq_mkRa
lemma divInt_one_one : 1 /. 1 = 1 := by rw [divInt_one]; rfl
#align rat.mk_one_one Rat.divInt_one_one
--- 2024-03-18
-@[deprecated divInt_one] lemma divInt_neg_one_one : -1 /. 1 = -1 := by rw [divInt_one]; rfl
+@[deprecated divInt_one] -- 2024-03-18
+lemma divInt_neg_one_one : -1 /. 1 = -1 := by rw [divInt_one]; rfl
#align rat.mk_neg_one_one Rat.divInt_neg_one_one
#align rat.mul_one Rat.mul_one
Rat
has a long history in (and before) mathlib and as such its development is full of cruft. Now that NNRat
is a thing, there is a need for the theory of Rat
to be mimickable to yield the theory of NNRat
, which is not currently the case.
Broadly, this PR aims at mirroring the Rat
and NNRat
declarations. It achieves this by:
Rat.num
and Rat.den
, and less on the structure representation of Rat
Rat.Nonneg
(which was replaced in Std by a new development of the order on Rat
)Rat
lemmas with dubious names. This creates quite a lot of conflicts with Std lemmas, whose names are themselves dubious. I am priming the relevant new mathlib names and leaving TODOs to fix the Std names.Rat
porting notesReduce the diff of #11203
@@ -3,10 +3,10 @@ Copyright (c) 2019 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Mario Carneiro
-/
+import Mathlib.Algebra.Ring.Basic
import Mathlib.Algebra.GroupWithZero.Basic
import Mathlib.Algebra.Order.Ring.Int
import Mathlib.Data.Int.Cast.Defs
-import Mathlib.Data.Nat.Cast.Basic
import Mathlib.Data.Rat.Init
#align_import data.rat.defs from "leanprover-community/mathlib"@"18a5306c091183ac90884daa9373fa3b178e8607"
@@ -30,6 +30,11 @@ The definition of the field structure on `ℚ` will be done in `Mathlib.Data.Rat
-/
+-- Guard against import creep.
+assert_not_exists Field
+assert_not_exists PNat
+assert_not_exists Nat.dvd_mul
+assert_not_exists IsDomain.toCancelMonoidWithZero
namespace Rat
@@ -89,6 +94,7 @@ lemma num_eq_zero {q : ℚ} : q.num = 0 ↔ q = 0 := by
· exact congr_arg num
lemma num_ne_zero {q : ℚ} : q.num ≠ 0 ↔ q ≠ 0 := num_eq_zero.not
+#align rat.num_ne_zero_of_ne_zero Rat.num_ne_zero
@[simp] lemma den_ne_zero (q : ℚ) : q.den ≠ 0 := q.den_pos.ne'
@@ -108,25 +114,29 @@ theorem divInt_ne_zero {a b : ℤ} (b0 : b ≠ 0) : a /. b ≠ 0 ↔ a ≠ 0 :=
theorem normalize_eq_mk' (n : Int) (d : Nat) (h : d ≠ 0) (c : Nat.gcd (Int.natAbs n) d = 1) :
normalize n d h = mk' n d h c := (mk_eq_normalize ..).symm
--- Porting note: removing as a `@[simp]` lemma as
--- theorem Rat.divInt_ofNat : ∀ (num : ℤ) (den : ℕ), num /. ↑den = mkRat num den
--- applies to the LHS.
--- @[simp]
-theorem num_den : ∀ {a : ℚ}, a.num /. a.den = a := divInt_self _
-#align rat.num_denom Rat.num_den
+-- TODO: Rename `mkRat_num_den` in Std
+@[simp] alias mkRat_num_den' := mkRat_self
+
+-- TODO: Rename `Rat.divInt_self` to `Rat.num_divInt_den` in Std
+lemma num_divInt_den (q : ℚ) : q.num /. q.den = q := divInt_self _
+#align rat.num_denom Rat.num_divInt_den
-theorem num_den' {n d h c} : (⟨n, d, h, c⟩ : ℚ) = n /. d := num_den.symm
-#align rat.num_denom' Rat.num_den'
+lemma mk'_eq_divInt {n d h c} : (⟨n, d, h, c⟩ : ℚ) = n /. d := (num_divInt_den _).symm
+#align rat.num_denom' Rat.mk'_eq_divInt
-theorem intCast_eq_divInt (z : ℤ) : (z : ℚ) = z /. 1 := num_den'
+theorem intCast_eq_divInt (z : ℤ) : (z : ℚ) = z /. 1 := mk'_eq_divInt
#align rat.coe_int_eq_mk Rat.intCast_eq_divInt
+-- TODO: Rename `divInt_self` in Std to `num_divInt_den`
+@[simp] lemma divInt_self' {n : ℤ} (hn : n ≠ 0) : n /. n = 1 := by
+ simpa using divInt_mul_right (n := 1) (d := 1) hn
+
/-- Define a (dependent) function or prove `∀ r : ℚ, p r` by dealing with rational
numbers of the form `n /. d` with `0 < d` and coprime `n`, `d`. -/
@[elab_as_elim]
def numDenCasesOn.{u} {C : ℚ → Sort u} :
∀ (a : ℚ) (_ : ∀ n d, 0 < d → (Int.natAbs n).Coprime d → C (n /. d)), C a
- | ⟨n, d, h, c⟩, H => by rw [num_den']; exact H n d (Nat.pos_of_ne_zero h) c
+ | ⟨n, d, h, c⟩, H => by rw [mk'_eq_divInt]; exact H n d (Nat.pos_of_ne_zero h) c
#align rat.num_denom_cases_on Rat.numDenCasesOn
/-- Define a (dependent) function or prove `∀ r : ℚ, p r` by dealing with rational
@@ -137,6 +147,13 @@ def numDenCasesOn'.{u} {C : ℚ → Sort u} (a : ℚ) (H : ∀ (n : ℤ) (d :
numDenCasesOn a fun n d h _ => H n d h.ne'
#align rat.num_denom_cases_on' Rat.numDenCasesOn'
+/-- Define a (dependent) function or prove `∀ r : ℚ, p r` by dealing with rational
+numbers of the form `mk' n d` with `d ≠ 0`. -/
+@[elab_as_elim]
+def numDenCasesOn''.{u} {C : ℚ → Sort u} (a : ℚ)
+ (H : ∀ (n : ℤ) (d : ℕ) (nz red), C (mk' n d nz red)) : C a :=
+ numDenCasesOn a fun n d h h' ↦ by rw [← mk_eq_divInt _ _ h.ne' h']; exact H n d h.ne' _
+
#align rat.add Rat.add
-- Porting note: there's already an instance for `Add ℚ` is in Std.
@@ -151,126 +168,122 @@ theorem lift_binop_eq (f : ℚ → ℚ → ℚ) (f₁ : ℤ → ℤ → ℤ →
∀ {n₁ d₁ n₂ d₂}, a * d₁ = n₁ * b → c * d₂ = n₂ * d →
f₁ n₁ d₁ n₂ d₂ * f₂ a b c d = f₁ a b c d * f₂ n₁ d₁ n₂ d₂) :
f (a /. b) (c /. d) = f₁ a b c d /. f₂ a b c d := by
- generalize ha : a /. b = x; cases' x with n₁ d₁ h₁ c₁; rw [num_den'] at ha
- generalize hc : c /. d = x; cases' x with n₂ d₂ h₂ c₂; rw [num_den'] at hc
+ generalize ha : a /. b = x; cases' x with n₁ d₁ h₁ c₁; rw [mk'_eq_divInt] at ha
+ generalize hc : c /. d = x; cases' x with n₂ d₂ h₂ c₂; rw [mk'_eq_divInt] at hc
rw [fv]
- have d₁0 := ne_of_gt (Int.ofNat_lt.2 <| Nat.pos_of_ne_zero h₁)
- have d₂0 := ne_of_gt (Int.ofNat_lt.2 <| Nat.pos_of_ne_zero h₂)
+ have d₁0 := Int.ofNat_ne_zero.2 h₁
+ have d₂0 := Int.ofNat_ne_zero.2 h₂
exact (divInt_eq_iff (f0 d₁0 d₂0) (f0 b0 d0)).2
(H ((divInt_eq_iff b0 d₁0).1 ha) ((divInt_eq_iff d0 d₂0).1 hc))
#align rat.lift_binop_eq Rat.lift_binop_eq
-@[simp]
+attribute [simp] divInt_add_divInt
+
+@[deprecated divInt_add_divInt] -- 2024-03-18
theorem add_def'' {a b c d : ℤ} (b0 : b ≠ 0) (d0 : d ≠ 0) :
a /. b + c /. d = (a * d + c * b) /. (b * d) := divInt_add_divInt _ _ b0 d0
#align rat.add_def Rat.add_def''
#align rat.neg Rat.neg
--- Porting note: there's already an instance for `Neg ℚ` is in Std.
+attribute [simp] neg_divInt
+#align rat.neg_def Rat.neg_divInt
--- Porting note: Std has explicit arguments here
-@[simp]
-theorem neg_def {a b : ℤ} : -(a /. b) = -a /. b := neg_divInt a b
-#align rat.neg_def Rat.neg_def
+lemma neg_def (q : ℚ) : -q = -q.num /. q.den := by rw [← neg_divInt, num_divInt_den]
-@[simp]
-theorem divInt_neg_den (n d : ℤ) : n /. -d = -n /. d := divInt_neg' ..
-#align rat.mk_neg_denom Rat.divInt_neg_den
+@[simp] lemma divInt_neg (n d : ℤ) : n /. -d = -n /. d := divInt_neg' ..
+#align rat.mk_neg_denom Rat.divInt_neg
-@[simp]
-theorem sub_def'' {a b c d : ℤ} (b0 : b ≠ 0) (d0 : d ≠ 0) :
+-- 2024-03-18
+@[deprecated] alias divInt_neg_den := divInt_neg
+
+attribute [simp] divInt_sub_divInt
+
+-- 2024-03-18
+@[deprecated divInt_sub_divInt] lemma sub_def'' {a b c d : ℤ} (b0 : b ≠ 0) (d0 : d ≠ 0) :
a /. b - c /. d = (a * d - c * b) /. (b * d) := divInt_sub_divInt _ _ b0 d0
#align rat.sub_def Rat.sub_def''
#align rat.mul Rat.mul
--- Porting note: there's already an instance for `Mul ℚ` in Std.
@[simp]
-theorem mul_def' {a b c d : ℤ} (b0 : b ≠ 0) (d0 : d ≠ 0) : a /. b * (c /. d) = a * c /. (b * d) :=
- divInt_mul_divInt _ _ b0 d0
-#align rat.mul_def Rat.mul_def'
+lemma divInt_mul_divInt' (n₁ d₁ n₂ d₂ : ℤ) : (n₁ /. d₁) * (n₂ /. d₂) = (n₁ * n₂) /. (d₁ * d₂) := by
+ obtain rfl | h₁ := eq_or_ne d₁ 0
+ · simp
+ obtain rfl | h₂ := eq_or_ne d₂ 0
+ · simp
+ exact divInt_mul_divInt _ _ h₁ h₂
+#align rat.mul_def Rat.divInt_mul_divInt'
+
+attribute [simp] mkRat_mul_mkRat
+
+lemma mul_def' (q r : ℚ) : q * r = mkRat (q.num * r.num) (q.den * r.den) := by
+ rw [mul_def, normalize_eq_mkRat]
+
+@[deprecated] alias mul_num_den := mul_def'
+#align rat.mul_num_denom Rat.mul_def'
#align rat.inv Rat.inv
instance : Inv ℚ :=
⟨Rat.inv⟩
--- Porting note: there's already an instance for `Div ℚ` is in Std.
+@[simp] lemma inv_divInt' (a b : ℤ) : (a /. b)⁻¹ = b /. a := inv_divInt ..
+#align rat.inv_def Rat.inv_divInt
-@[simp]
-theorem inv_def' {a b : ℤ} : (a /. b)⁻¹ = b /. a := inv_divInt ..
-#align rat.inv_def Rat.inv_def'
+@[simp] lemma inv_mkRat (a : ℤ) (b : ℕ) : (mkRat a b)⁻¹ = b /. a := by rw [mkRat_eq, inv_divInt']
-variable (a b c : ℚ)
+lemma inv_def' (q : ℚ) : q⁻¹ = q.den /. q.num := by rw [← inv_divInt', num_divInt_den]
+#align rat.inv_def' Rat.inv_def'
+
+@[simp] lemma divInt_div_divInt (n₁ d₁ n₂ d₂) :
+ (n₁ /. d₁) / (n₂ /. d₂) = (n₁ * d₂) /. (d₁ * n₂) := by
+ rw [div_def, inv_divInt, divInt_mul_divInt']
+
+lemma div_def' (q r : ℚ) : q / r = (q.num * r.den) /. (q.den * r.num) := by
+ rw [← divInt_div_divInt, num_divInt_den, num_divInt_den]
--- Porting note (#11215): TODO this is a workaround.
-attribute [-simp] divInt_ofNat
+@[deprecated] alias div_num_den := div_def'
+#align rat.div_num_denom Rat.div_def'
-protected theorem add_zero : a + 0 = a :=
- numDenCasesOn' a fun n d h => by
- rw [← zero_divInt d, add_def'', zero_mul, add_zero, divInt_mul_right] <;> simp [h]
+variable (a b c : ℚ)
+
+protected lemma add_zero : a + 0 = a := by simp [add_def, normalize_eq_mkRat]
#align rat.add_zero Rat.add_zero
-protected theorem zero_add : 0 + a = a :=
- numDenCasesOn' a fun n d h => by
- rw [← zero_divInt d, add_def'', zero_mul, zero_add, divInt_mul_right] <;> simp [h]
+protected lemma zero_add : 0 + a = a := by simp [add_def, normalize_eq_mkRat]
#align rat.zero_add Rat.zero_add
-protected theorem add_comm : a + b = b + a :=
- numDenCasesOn' a fun n₁ d₁ h₁ => numDenCasesOn' b fun n₂ d₂ h₂ => by
- simp [h₁, h₂, add_comm, mul_comm]
+protected lemma add_comm : a + b = b + a := by
+ simp [add_def, Int.add_comm, Int.mul_comm, Nat.mul_comm]
#align rat.add_comm Rat.add_comm
protected theorem add_assoc : a + b + c = a + (b + c) :=
- numDenCasesOn' a fun n₁ d₁ h₁ =>
- numDenCasesOn' b fun n₂ d₂ h₂ =>
- numDenCasesOn' c fun n₃ d₃ h₃ => by
- simp only [ne_eq, Nat.cast_eq_zero, h₁, not_false_eq_true, h₂, add_def'', mul_eq_zero,
- or_self, h₃]
- rw [mul_assoc, add_mul, add_mul, mul_assoc, add_assoc]
- congr 2
- ac_rfl
+ numDenCasesOn' a fun n₁ d₁ h₁ ↦ numDenCasesOn' b fun n₂ d₂ h₂ ↦ numDenCasesOn' c fun n₃ d₃ h₃ ↦ by
+ simp only [ne_eq, Nat.cast_eq_zero, h₁, not_false_eq_true, h₂, divInt_add_divInt, mul_eq_zero,
+ or_self, h₃]
+ rw [mul_assoc, add_mul, add_mul, mul_assoc, add_assoc]
+ congr 2
+ ac_rfl
#align rat.add_assoc Rat.add_assoc
-protected theorem add_left_neg : -a + a = 0 :=
- numDenCasesOn' a fun n d h => by simp [h, mkRat_add_mkRat]
+protected lemma add_left_neg : -a + a = 0 := by simp [add_def, normalize_eq_mkRat]
#align rat.add_left_neg Rat.add_left_neg
-theorem divInt_zero_one : 0 /. 1 = 0 :=
- show divInt _ _ = _ by
- rw [divInt]
- simp
-#align rat.mk_zero_one Rat.divInt_zero_one
+-- 2024-03-18
+@[deprecated zero_divInt] lemma divInt_zero_one : 0 /. 1 = 0 := zero_divInt _
+#align rat.mk_zero_one Rat.zero_divInt
-@[simp]
-theorem divInt_one_one : 1 /. 1 = 1 :=
- show divInt _ _ = _ by
- rw [divInt]
- simp only [inline, mkRat, one_ne_zero, ↓reduceDite, normalize, Int.natAbs_one, Nat.gcd_self,
- maybeNormalize_eq, Nat.cast_one, ne_eq, not_false_eq_true, Int.div_self, zero_lt_one,
- Nat.div_self, mk_den_one]
- rfl
+@[simp] lemma divInt_one (n : ℤ) : n /. 1 = n := by simp [divInt, mkRat, normalize]
+@[simp] lemma mkRat_one (n : ℤ) : mkRat n 1 = n := by simp [mkRat_eq]
+
+lemma divInt_one_one : 1 /. 1 = 1 := by rw [divInt_one]; rfl
#align rat.mk_one_one Rat.divInt_one_one
-@[simp]
-theorem divInt_neg_one_one : -1 /. 1 = -1 :=
- show divInt _ _ = _ by
- rw [divInt]
- simp only [inline, mkRat, one_ne_zero, ↓reduceDite, normalize, Int.reduceNeg, Int.natAbs_neg,
- Int.natAbs_one, Nat.gcd_self, maybeNormalize_eq, Nat.cast_one, Int.div_one, zero_lt_one,
- Nat.div_self, mk_den_one, intCast_neg]
- rfl
+-- 2024-03-18
+@[deprecated divInt_one] lemma divInt_neg_one_one : -1 /. 1 = -1 := by rw [divInt_one]; rfl
#align rat.mk_neg_one_one Rat.divInt_neg_one_one
-theorem divInt_one (n : ℤ) : n /. 1 = n :=
- show divInt _ _ = _ by
- rw [divInt]
- simp [mkRat, normalize]
-
-theorem mkRat_one {n : ℤ} : mkRat n 1 = n := by
- simp [Rat.mkRat_eq, Rat.divInt_one]
-
#align rat.mul_one Rat.mul_one
#align rat.one_mul Rat.one_mul
#align rat.mul_comm Rat.mul_comm
@@ -279,17 +292,15 @@ protected theorem mul_assoc : a * b * c = a * (b * c) :=
numDenCasesOn' a fun n₁ d₁ h₁ =>
numDenCasesOn' b fun n₂ d₂ h₂ =>
numDenCasesOn' c fun n₃ d₃ h₃ => by
- simp [h₁, h₂, h₃, mul_ne_zero, mul_comm, mul_assoc, mul_left_comm]
+ simp [h₁, h₂, h₃, mul_ne_zero, Int.mul_comm, Nat.mul_assoc, Int.mul_left_comm]
#align rat.mul_assoc Rat.mul_assoc
protected theorem add_mul : (a + b) * c = a * c + b * c :=
- numDenCasesOn' a fun n₁ d₁ h₁ =>
- numDenCasesOn' b fun n₂ d₂ h₂ =>
- numDenCasesOn' c fun n₃ d₃ h₃ => by
- simp only [ne_eq, Nat.cast_eq_zero, h₁, not_false_eq_true, h₂, add_def'', mul_eq_zero,
- or_self, h₃, mul_def']
- rw [← divInt_mul_right (Int.natCast_ne_zero.2 h₃), add_mul, add_mul]
- ac_rfl
+ numDenCasesOn' a fun n₁ d₁ h₁ ↦ numDenCasesOn' b fun n₂ d₂ h₂ ↦ numDenCasesOn' c fun n₃ d₃ h₃ ↦ by
+ simp only [ne_eq, Nat.cast_eq_zero, h₁, not_false_eq_true, h₂, divInt_add_divInt, mul_eq_zero,
+ or_self, h₃, divInt_mul_divInt]
+ rw [← divInt_mul_right (Int.natCast_ne_zero.2 h₃), add_mul, add_mul]
+ ac_rfl
#align rat.add_mul Rat.add_mul
protected theorem mul_add : a * (b + c) = a * b + a * c := by
@@ -301,10 +312,12 @@ protected theorem zero_ne_one : 0 ≠ (1 : ℚ) := by
exact one_ne_zero
#align rat.zero_ne_one Rat.zero_ne_one
+attribute [simp] mkRat_eq_zero
+
protected theorem mul_inv_cancel : a ≠ 0 → a * a⁻¹ = 1 :=
- numDenCasesOn' a fun n d h a0 => by
- have n0 : n ≠ 0 := mt (by rintro rfl; simp) a0
- simpa [h, n0, mul_comm] using @divInt_mul_right 1 1 (n * d) (by simp [h, n0])
+ numDenCasesOn' a fun n d hd hn ↦ by
+ simp [hd] at hn;
+ simp [-divInt_ofNat, mkRat_eq, mul_comm, mul_ne_zero hn (Int.ofNat_ne_zero.2 hd)]
#align rat.mul_inv_cancel Rat.mul_inv_cancel
protected theorem inv_mul_cancel (h : a ≠ 0) : a⁻¹ * a = 1 :=
@@ -344,7 +357,7 @@ instance commRing : CommRing ℚ where
natCast n := Int.cast n
natCast_zero := rfl
natCast_succ n := by
- simp only [intCast_eq_divInt, add_def'' one_ne_zero one_ne_zero,
+ simp only [intCast_eq_divInt, divInt_add_divInt _ _ one_ne_zero one_ne_zero,
← divInt_one_one, Nat.cast_add, Nat.cast_one, mul_one]
instance commGroupWithZero : CommGroupWithZero ℚ :=
@@ -397,7 +410,7 @@ instance semigroup : Semigroup ℚ := by infer_instance
theorem eq_iff_mul_eq_mul {p q : ℚ} : p = q ↔ p.num * q.den = q.num * p.den := by
conv =>
lhs
- rw [← @num_den p, ← @num_den q]
+ rw [← num_divInt_den p, ← num_divInt_den q]
apply Rat.divInt_eq_iff <;>
· rw [← Nat.cast_zero, Ne, Int.ofNat_inj]
apply den_nz
@@ -423,19 +436,13 @@ theorem den_zero : Rat.den 0 = 1 :=
rfl
#align rat.denom_zero Rat.den_zero
-theorem zero_of_num_zero {q : ℚ} (hq : q.num = 0) : q = 0 := by
- have : q = q.num /. q.den := num_den.symm
- simpa [hq] using this
+lemma zero_of_num_zero {q : ℚ} (hq : q.num = 0) : q = 0 := by simpa [hq] using q.num_divInt_den.symm
#align rat.zero_of_num_zero Rat.zero_of_num_zero
theorem zero_iff_num_zero {q : ℚ} : q = 0 ↔ q.num = 0 :=
⟨fun _ => by simp [*], zero_of_num_zero⟩
#align rat.zero_iff_num_zero Rat.zero_iff_num_zero
-theorem num_ne_zero_of_ne_zero {q : ℚ} (h : q ≠ 0) : q.num ≠ 0 := fun hq0 : q.num = 0 =>
- h <| zero_of_num_zero hq0
-#align rat.num_ne_zero_of_ne_zero Rat.num_ne_zero_of_ne_zero
-
@[simp]
theorem num_one : (1 : ℚ).num = 1 :=
rfl
@@ -458,54 +465,33 @@ theorem divInt_ne_zero_of_ne_zero {n d : ℤ} (h : n ≠ 0) (hd : d ≠ 0) : n /
(divInt_ne_zero hd).mpr h
#align rat.mk_ne_zero_of_ne_zero Rat.divInt_ne_zero_of_ne_zero
-theorem mul_num_den (q r : ℚ) : q * r = q.num * r.num /. ↑(q.den * r.den) := by
- suffices q.num /. ↑q.den * (r.num /. ↑r.den) = q.num * r.num /. ↑(q.den * r.den) by
- simpa [num_den] using this
- simp [mul_def']
-#align rat.mul_num_denom Rat.mul_num_den
-
-theorem div_num_den (q r : ℚ) : q / r = q.num * r.den /. (q.den * r.num) :=
- if hr : r.num = 0 then by
- have hr' : r = 0 := zero_of_num_zero hr
- simp [*]
- else
- calc
- q / r = q * r⁻¹ := div_eq_mul_inv q r
- _ = q.num /. q.den * (r.num /. r.den)⁻¹ := by simp [num_den]
- _ = q.num /. q.den * (r.den /. r.num) := by rw [inv_def']
- _ = q.num * r.den /. (q.den * r.num) := mul_def' (by simp) hr
-#align rat.div_num_denom Rat.div_num_den
-
section Casts
protected theorem add_divInt (a b c : ℤ) : (a + b) /. c = a /. c + b /. c :=
if h : c = 0 then by simp [h]
else by
- rw [add_def'' h h, divInt_eq_iff h (mul_ne_zero h h)]
+ rw [divInt_add_divInt _ _ h h, divInt_eq_iff h (mul_ne_zero h h)]
simp [add_mul, mul_assoc]
#align rat.add_mk Rat.add_divInt
-theorem divInt_eq_div (n d : ℤ) : n /. d = (n : ℚ) / d := by
- by_cases d0 : d = 0
- · simp [d0, div_zero]
- simp [division_def, intCast_eq_divInt, mul_def' one_ne_zero d0]
+theorem divInt_eq_div (n d : ℤ) : n /. d = (n : ℚ) / d := by simp [div_def']
#align rat.mk_eq_div Rat.divInt_eq_div
theorem divInt_mul_divInt_cancel {x : ℤ} (hx : x ≠ 0) (n d : ℤ) : n /. x * (x /. d) = n /. d := by
by_cases hd : d = 0
· rw [hd]
simp
- rw [mul_def' hx hd, mul_comm x, divInt_mul_right hx]
+ rw [divInt_mul_divInt _ _ hx hd, mul_comm x, divInt_mul_right hx]
#align rat.mk_mul_mk_cancel Rat.divInt_mul_divInt_cancel
theorem divInt_div_divInt_cancel_left {x : ℤ} (hx : x ≠ 0) (n d : ℤ) :
n /. x / (d /. x) = n /. d := by
- rw [div_eq_mul_inv, inv_def', divInt_mul_divInt_cancel hx]
+ rw [div_eq_mul_inv, inv_divInt', divInt_mul_divInt_cancel hx]
#align rat.mk_div_mk_cancel_left Rat.divInt_div_divInt_cancel_left
theorem divInt_div_divInt_cancel_right {x : ℤ} (hx : x ≠ 0) (n d : ℤ) :
x /. n / (x /. d) = d /. n := by
- rw [div_eq_mul_inv, inv_def', mul_comm, divInt_mul_divInt_cancel hx]
+ rw [div_eq_mul_inv, inv_divInt', mul_comm, divInt_mul_divInt_cancel hx]
#align rat.mk_div_mk_cancel_right Rat.divInt_div_divInt_cancel_right
theorem intCast_div_eq_divInt {n d : ℤ} : (n : ℚ) / (d) = n /. d := by
@@ -515,12 +501,11 @@ theorem intCast_div_eq_divInt {n d : ℤ} : (n : ℚ) / (d) = n /. d := by
-- Porting note: see porting note above about `Int.cast`@[simp]
theorem num_div_den (r : ℚ) : (r.num : ℚ) / (r.den : ℚ) = r := by
- rw [← Int.cast_natCast]
- erw [← divInt_eq_div, num_den]
+ rw [← Int.cast_natCast]; erw [← divInt_eq_div, num_divInt_den]
#align rat.num_div_denom Rat.num_div_den
theorem coe_int_num_of_den_eq_one {q : ℚ} (hq : q.den = 1) : (q.num : ℚ) = q := by
- conv_rhs => rw [← @num_den q, hq]
+ conv_rhs => rw [← num_divInt_den q, hq]
rw [intCast_eq_divInt]
rfl
#align rat.coe_int_num_of_denom_eq_one Rat.coe_int_num_of_den_eq_one
@@ -564,21 +549,7 @@ theorem coe_int_inj (m n : ℤ) : (m : ℚ) = n ↔ m = n :=
end Casts
-theorem mkRat_eq_div {n : ℤ} {d : ℕ} : mkRat n d = n / d := by
- simp only [mkRat, zero_mk]
- by_cases h : d = 0
- · simp [h]
- · simp only [h, ↓reduceDite, HDiv.hDiv, Div.div, Rat.div]
- unfold Rat.inv
- have h₁ : 0 < d := Nat.pos_iff_ne_zero.2 h
- have h₂ : ¬ (d : ℤ) < 0 := of_decide_eq_false rfl
- simp [h₁, h₂, ← Rat.normalize_eq_mk', Rat.normalize_eq_mkRat, ← mkRat_one,
- Rat.mkRat_mul_mkRat]
+theorem mkRat_eq_div (n : ℤ) (d : ℕ) : mkRat n d = n / d := by
+ simp only [mkRat_eq, divInt_eq_div, Int.cast_natCast]
end Rat
-
--- Guard against import creep.
-assert_not_exists Field
-assert_not_exists PNat
-assert_not_exists Nat.dvd_mul
-assert_not_exists IsDomain.toCancelMonoidWithZero
CharZero
instance for Int
(#12060)
This adds a shortcut instance CharZero ℤ
in the file Algebra.Ring.Int
(which contains a few other shortcut instances for ℤ
already). The hope is that this will result in a speed-up.
Note: This requires adding import Mathlib.Algebra.CharZero.Defs
.
See here on Zulip.
There is a positive effect (-22.5 s) on type class inference, but no significant change overall. Still, I think it makes sense to have it.
@@ -4,7 +4,6 @@ Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Mario Carneiro
-/
import Mathlib.Algebra.GroupWithZero.Basic
-import Mathlib.Algebra.Order.Ring.CharZero
import Mathlib.Algebra.Order.Ring.Int
import Mathlib.Data.Int.Cast.Defs
import Mathlib.Data.Nat.Cast.Basic
@@ -119,8 +119,8 @@ theorem num_den : ∀ {a : ℚ}, a.num /. a.den = a := divInt_self _
theorem num_den' {n d h c} : (⟨n, d, h, c⟩ : ℚ) = n /. d := num_den.symm
#align rat.num_denom' Rat.num_den'
-theorem coe_int_eq_divInt (z : ℤ) : (z : ℚ) = z /. 1 := num_den'
-#align rat.coe_int_eq_mk Rat.coe_int_eq_divInt
+theorem intCast_eq_divInt (z : ℤ) : (z : ℚ) = z /. 1 := num_den'
+#align rat.coe_int_eq_mk Rat.intCast_eq_divInt
/-- Define a (dependent) function or prove `∀ r : ℚ, p r` by dealing with rational
numbers of the form `n /. d` with `0 < d` and coprime `n`, `d`. -/
@@ -345,7 +345,7 @@ instance commRing : CommRing ℚ where
natCast n := Int.cast n
natCast_zero := rfl
natCast_succ n := by
- simp only [coe_int_eq_divInt, add_def'' one_ne_zero one_ne_zero,
+ simp only [intCast_eq_divInt, add_def'' one_ne_zero one_ne_zero,
← divInt_one_one, Nat.cast_add, Nat.cast_one, mul_one]
instance commGroupWithZero : CommGroupWithZero ℚ :=
@@ -489,7 +489,7 @@ protected theorem add_divInt (a b c : ℤ) : (a + b) /. c = a /. c + b /. c :=
theorem divInt_eq_div (n d : ℤ) : n /. d = (n : ℚ) / d := by
by_cases d0 : d = 0
· simp [d0, div_zero]
- simp [division_def, coe_int_eq_divInt, mul_def' one_ne_zero d0]
+ simp [division_def, intCast_eq_divInt, mul_def' one_ne_zero d0]
#align rat.mk_eq_div Rat.divInt_eq_div
theorem divInt_mul_divInt_cancel {x : ℤ} (hx : x ≠ 0) (n d : ℤ) : n /. x * (x /. d) = n /. d := by
@@ -509,10 +509,10 @@ theorem divInt_div_divInt_cancel_right {x : ℤ} (hx : x ≠ 0) (n d : ℤ) :
rw [div_eq_mul_inv, inv_def', mul_comm, divInt_mul_divInt_cancel hx]
#align rat.mk_div_mk_cancel_right Rat.divInt_div_divInt_cancel_right
-theorem coe_int_div_eq_divInt {n d : ℤ} : (n : ℚ) / (d) = n /. d := by
- repeat' rw [coe_int_eq_divInt]
+theorem intCast_div_eq_divInt {n d : ℤ} : (n : ℚ) / (d) = n /. d := by
+ repeat' rw [intCast_eq_divInt]
exact divInt_div_divInt_cancel_left one_ne_zero n d
-#align rat.coe_int_div_eq_mk Rat.coe_int_div_eq_divInt
+#align rat.coe_int_div_eq_mk Rat.intCast_div_eq_divInt
-- Porting note: see porting note above about `Int.cast`@[simp]
theorem num_div_den (r : ℚ) : (r.num : ℚ) / (r.den : ℚ) = r := by
@@ -522,7 +522,7 @@ theorem num_div_den (r : ℚ) : (r.num : ℚ) / (r.den : ℚ) = r := by
theorem coe_int_num_of_den_eq_one {q : ℚ} (hq : q.den = 1) : (q.num : ℚ) = q := by
conv_rhs => rw [← @num_den q, hq]
- rw [coe_int_eq_divInt]
+ rw [intCast_eq_divInt]
rfl
#align rat.coe_int_num_of_denom_eq_one Rat.coe_int_num_of_den_eq_one
@@ -538,9 +538,14 @@ instance canLift : CanLift ℚ ℤ (↑) fun q => q.den = 1 :=
⟨fun q hq => ⟨q.num, coe_int_num_of_den_eq_one hq⟩⟩
#align rat.can_lift Rat.canLift
-theorem coe_nat_eq_divInt (n : ℕ) : ↑n = n /. 1 := by
- rw [← Int.cast_natCast, coe_int_eq_divInt]
-#align rat.coe_nat_eq_mk Rat.coe_nat_eq_divInt
+theorem natCast_eq_divInt (n : ℕ) : ↑n = n /. 1 := by
+ rw [← Int.cast_natCast, intCast_eq_divInt]
+#align rat.coe_nat_eq_mk Rat.natCast_eq_divInt
+
+-- 2024-04-05
+@[deprecated] alias coe_int_eq_divInt := intCast_eq_divInt
+@[deprecated] alias coe_int_div_eq_divInt := intCast_div_eq_divInt
+@[deprecated] alias coe_nat_eq_divInt := natCast_eq_divInt
@[simp, norm_cast] lemma num_natCast (n : ℕ) : num n = n := rfl
#align rat.coe_nat_num Rat.num_natCast
Data.{Nat,Int}{.Order}.Basic
in group vs ring instances (#11924)
Scatter the content of Data.Nat.Basic
across:
Data.Nat.Defs
for the lemmas having no dependenciesAlgebra.Group.Nat
for the monoid instances and the few miscellaneous lemmas needing them.Algebra.Ring.Nat
for the semiring instance and the few miscellaneous lemmas following it.Similarly, scatter
Data.Int.Basic
across Data.Int.Defs
, Algebra.Group.Int
, Algebra.Ring.Int
Data.Nat.Order.Basic
across Data.Nat.Defs
, Algebra.Order.Group.Nat
, Algebra.Order.Ring.Nat
Data.Int.Order.Basic
across Data.Int.Defs
, Algebra.Order.Group.Int
, Algebra.Order.Ring.Int
Also move a few lemmas from Data.Nat.Order.Lemmas
to Data.Nat.Defs
.
Before
After
@@ -3,11 +3,12 @@ Copyright (c) 2019 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Mario Carneiro
-/
-import Mathlib.Data.Rat.Init
+import Mathlib.Algebra.GroupWithZero.Basic
+import Mathlib.Algebra.Order.Ring.CharZero
+import Mathlib.Algebra.Order.Ring.Int
import Mathlib.Data.Int.Cast.Defs
-import Mathlib.Data.Int.Order.Basic
import Mathlib.Data.Nat.Cast.Basic
-import Mathlib.Algebra.GroupWithZero.Basic
+import Mathlib.Data.Rat.Init
#align_import data.rat.defs from "leanprover-community/mathlib"@"18a5306c091183ac90884daa9373fa3b178e8607"
OfNat
and Nat.cast
lemmas (#11861)
This renames
Int.cast_ofNat
to Int.cast_natCast
Int.int_cast_ofNat
to Int.cast_ofNat
I think the history here is that this lemma was previously about Int.ofNat
, before we globally fixed the simp-normal form to be Nat.cast
.
Since the Int.cast_ofNat
name is repurposed, it can't be deprecated. Int.int_cast_ofNat
is such a wonky name that it was probably never used.
@@ -515,7 +515,7 @@ theorem coe_int_div_eq_divInt {n d : ℤ} : (n : ℚ) / (d) = n /. d := by
-- Porting note: see porting note above about `Int.cast`@[simp]
theorem num_div_den (r : ℚ) : (r.num : ℚ) / (r.den : ℚ) = r := by
- rw [← Int.cast_ofNat]
+ rw [← Int.cast_natCast]
erw [← divInt_eq_div, num_den]
#align rat.num_div_denom Rat.num_div_den
@@ -538,7 +538,7 @@ instance canLift : CanLift ℚ ℤ (↑) fun q => q.den = 1 :=
#align rat.can_lift Rat.canLift
theorem coe_nat_eq_divInt (n : ℕ) : ↑n = n /. 1 := by
- rw [← Int.cast_ofNat, coe_int_eq_divInt]
+ rw [← Int.cast_natCast, coe_int_eq_divInt]
#align rat.coe_nat_eq_mk Rat.coe_nat_eq_divInt
@[simp, norm_cast] lemma num_natCast (n : ℕ) : num n = n := rfl
Rat
internals in the definition of Field
(#11639)
Soon, there will be NNRat
analogs of the Rat
fields in the definition of Field
. NNRat
is less nicely a structure than Rat
, hence there is a need to reduce the dependency of Field
on the internals of Rat
.
This PR achieves this by restating Field.ratCast_mk'
in terms of Rat.num
, Rat.den
. This requires fixing a few downstream instances.
Reduce the diff of #11203.
Co-authored-by: Floris van Doorn <fpvdoorn@gmail.com>
@@ -90,6 +90,8 @@ lemma num_eq_zero {q : ℚ} : q.num = 0 ↔ q = 0 := by
lemma num_ne_zero {q : ℚ} : q.num ≠ 0 ↔ q ≠ 0 := num_eq_zero.not
+@[simp] lemma den_ne_zero (q : ℚ) : q.den ≠ 0 := q.den_pos.ne'
+
@[simp]
theorem divInt_eq_zero {a b : ℤ} (b0 : b ≠ 0) : a /. b = 0 ↔ a = 0 := by
rw [← zero_divInt b, divInt_eq_iff b0 b0, zero_mul, mul_eq_zero, or_iff_left b0]
@@ -313,7 +315,7 @@ protected theorem inv_mul_cancel (h : a ≠ 0) : a⁻¹ * a = 1 :=
/-! At this point in the import hierarchy we have not defined the `Field` typeclass.
Instead we'll instantiate `CommRing` and `CommGroupWithZero` at this point.
-The `Rat.field` instance and any field-specific lemmas can be found in `Mathlib.Data.Rat.Basic`.
+The `Rat.instField` instance and any field-specific lemmas can be found in `Mathlib.Data.Rat.Basic`.
-/
instance commRing : CommRing ℚ where
@@ -457,11 +459,9 @@ theorem divInt_ne_zero_of_ne_zero {n d : ℤ} (h : n ≠ 0) (hd : d ≠ 0) : n /
#align rat.mk_ne_zero_of_ne_zero Rat.divInt_ne_zero_of_ne_zero
theorem mul_num_den (q r : ℚ) : q * r = q.num * r.num /. ↑(q.den * r.den) := by
- have hq' : (↑q.den : ℤ) ≠ 0 := by have := den_nz q; simpa
- have hr' : (↑r.den : ℤ) ≠ 0 := by have := den_nz r; simpa
suffices q.num /. ↑q.den * (r.num /. ↑r.den) = q.num * r.num /. ↑(q.den * r.den) by
simpa [num_den] using this
- simp [mul_def' hq' hr']
+ simp [mul_def']
#align rat.mul_num_denom Rat.mul_num_den
theorem div_num_den (q r : ℚ) : q / r = q.num * r.den /. (q.den * r.num) :=
@@ -473,7 +473,7 @@ theorem div_num_den (q r : ℚ) : q / r = q.num * r.den /. (q.den * r.num) :=
q / r = q * r⁻¹ := div_eq_mul_inv q r
_ = q.num /. q.den * (r.num /. r.den)⁻¹ := by simp [num_den]
_ = q.num /. q.den * (r.den /. r.num) := by rw [inv_def']
- _ = q.num * r.den /. (q.den * r.num) := mul_def' (by simpa using den_nz q) hr
+ _ = q.num * r.den /. (q.den * r.num) := mul_def' (by simp) hr
#align rat.div_num_denom Rat.div_num_den
section Casts
coe_nat
to natCast
(#11637)
Reduce the diff of #11499
All in the Int
namespace:
ofNat_eq_cast
→ ofNat_eq_natCast
cast_eq_cast_iff_Nat
→ natCast_inj
natCast_eq_ofNat
→ ofNat_eq_natCast
coe_nat_sub
→ natCast_sub
coe_nat_nonneg
→ natCast_nonneg
sign_coe_add_one
→ sign_natCast_add_one
nat_succ_eq_int_succ
→ natCast_succ
succ_neg_nat_succ
→ succ_neg_natCast_succ
coe_pred_of_pos
→ natCast_pred_of_pos
coe_nat_div
→ natCast_div
coe_nat_ediv
→ natCast_ediv
sign_coe_nat_of_nonzero
→ sign_natCast_of_ne_zero
toNat_coe_nat
→ toNat_natCast
toNat_coe_nat_add_one
→ toNat_natCast_add_one
coe_nat_dvd
→ natCast_dvd_natCast
coe_nat_dvd_left
→ natCast_dvd
coe_nat_dvd_right
→ dvd_natCast
le_coe_nat_sub
→ le_natCast_sub
succ_coe_nat_pos
→ succ_natCast_pos
coe_nat_modEq_iff
→ natCast_modEq_iff
coe_natAbs
→ natCast_natAbs
coe_nat_eq_zero
→ natCast_eq_zero
coe_nat_ne_zero
→ natCast_ne_zero
coe_nat_ne_zero_iff_pos
→ natCast_ne_zero_iff_pos
abs_coe_nat
→ abs_natCast
coe_nat_nonpos_iff
→ natCast_nonpos_iff
Also rename Nat.coe_nat_dvd
to Nat.cast_dvd_cast
@@ -286,7 +286,7 @@ protected theorem add_mul : (a + b) * c = a * c + b * c :=
numDenCasesOn' c fun n₃ d₃ h₃ => by
simp only [ne_eq, Nat.cast_eq_zero, h₁, not_false_eq_true, h₂, add_def'', mul_eq_zero,
or_self, h₃, mul_def']
- rw [← divInt_mul_right (Int.coe_nat_ne_zero.2 h₃), add_mul, add_mul]
+ rw [← divInt_mul_right (Int.natCast_ne_zero.2 h₃), add_mul, add_mul]
ac_rfl
#align rat.add_mul Rat.add_mul
nsmul
and zsmul
to default automatically (#6262)
This PR removes the default values for nsmul
and zsmul
, forcing the user to populate them manually.
The previous behavior can be obtained by writing nsmul := nsmulRec
and zsmul := zsmulRec
, which is now in the docstring for these fields.
The motivation here is to make it more obvious when module diamonds are being introduced, or at least where they might be hiding; you can now simply search for nsmulRec
in the source code.
Arguably we should do the same thing for intCast
, natCast
, pow
, and zpow
too, but diamonds are less common in those fields, so I'll leave them to a subsequent PR.
Co-authored-by: Matthew Ballard <matt@mrb.email>
@@ -336,6 +336,8 @@ instance commRing : CommRing ℚ where
left_distrib := Rat.mul_add
right_distrib := Rat.add_mul
sub_eq_add_neg := Rat.sub_eq_add_neg
+ nsmul := nsmulRec
+ zsmul := zsmulRec
intCast := fun n => n
natCast n := Int.cast n
natCast_zero := rfl
@@ -245,7 +245,9 @@ theorem divInt_zero_one : 0 /. 1 = 0 :=
theorem divInt_one_one : 1 /. 1 = 1 :=
show divInt _ _ = _ by
rw [divInt]
- simp [mkRat, normalize]
+ simp only [inline, mkRat, one_ne_zero, ↓reduceDite, normalize, Int.natAbs_one, Nat.gcd_self,
+ maybeNormalize_eq, Nat.cast_one, ne_eq, not_false_eq_true, Int.div_self, zero_lt_one,
+ Nat.div_self, mk_den_one]
rfl
#align rat.mk_one_one Rat.divInt_one_one
@@ -253,7 +255,9 @@ theorem divInt_one_one : 1 /. 1 = 1 :=
theorem divInt_neg_one_one : -1 /. 1 = -1 :=
show divInt _ _ = _ by
rw [divInt]
- simp [mkRat, normalize]
+ simp only [inline, mkRat, one_ne_zero, ↓reduceDite, normalize, Int.reduceNeg, Int.natAbs_neg,
+ Int.natAbs_one, Nat.gcd_self, maybeNormalize_eq, Nat.cast_one, Int.div_one, zero_lt_one,
+ Nat.div_self, mk_den_one, intCast_neg]
rfl
#align rat.mk_neg_one_one Rat.divInt_neg_one_one
@@ -557,7 +561,7 @@ theorem mkRat_eq_div {n : ℤ} {d : ℕ} : mkRat n d = n / d := by
simp only [mkRat, zero_mk]
by_cases h : d = 0
· simp [h]
- · simp [h, HDiv.hDiv, Rat.div, Div.div]
+ · simp only [h, ↓reduceDite, HDiv.hDiv, Div.div, Rat.div]
unfold Rat.inv
have h₁ : 0 < d := Nat.pos_iff_ne_zero.2 h
have h₂ : ¬ (d : ℤ) < 0 := of_decide_eq_false rfl
@@ -61,7 +61,7 @@ theorem coe_int_den (n : ℤ) : (n : ℚ).den = 1 :=
#noalign rat.mk_pnat
--- Porting note: TODO Should this be namespaced?
+-- Porting note (#11215): TODO Should this be namespaced?
#align rat.mk_nat mkRat
#noalign rat.mk_pnat_eq
@@ -202,7 +202,7 @@ theorem inv_def' {a b : ℤ} : (a /. b)⁻¹ = b /. a := inv_divInt ..
variable (a b c : ℚ)
--- Porting note: TODO this is a workaround.
+-- Porting note (#11215): TODO this is a workaround.
attribute [-simp] divInt_ofNat
protected theorem add_zero : a + 0 = a :=
@@ -261,7 +261,6 @@ theorem divInt_one (n : ℤ) : n /. 1 = n :=
show divInt _ _ = _ by
rw [divInt]
simp [mkRat, normalize]
- rfl
theorem mkRat_one {n : ℤ} : mkRat n 1 = n := by
simp [Rat.mkRat_eq, Rat.divInt_one]
num
and den
lemmas (#10219)
Add a few basic lemmas about Rat
and NNRat
and fix some lemma names
From LeanAPAP
@@ -44,6 +44,11 @@ theorem ofInt_eq_cast (n : ℤ) : ofInt n = Int.cast n :=
rfl
#align rat.of_int_eq_cast Rat.ofInt_eq_cast
+-- TODO: Replace `Rat.ofNat_num`/`Rat.ofNat_den` in Std
+-- See note [no_index around OfNat.ofNat]
+@[simp] lemma num_ofNat (n : ℕ) : num (no_index (OfNat.ofNat n)) = OfNat.ofNat n := rfl
+@[simp] lemma den_ofNat (n : ℕ) : den (no_index (OfNat.ofNat n)) = 1 := rfl
+
@[simp, norm_cast]
theorem coe_int_num (n : ℤ) : (n : ℚ).num = n :=
rfl
@@ -531,15 +536,15 @@ theorem coe_nat_eq_divInt (n : ℕ) : ↑n = n /. 1 := by
rw [← Int.cast_ofNat, coe_int_eq_divInt]
#align rat.coe_nat_eq_mk Rat.coe_nat_eq_divInt
-@[simp, norm_cast]
-theorem coe_nat_num (n : ℕ) : (n : ℚ).num = n := by
- rw [← Int.cast_ofNat, coe_int_num]
-#align rat.coe_nat_num Rat.coe_nat_num
+@[simp, norm_cast] lemma num_natCast (n : ℕ) : num n = n := rfl
+#align rat.coe_nat_num Rat.num_natCast
-@[simp, norm_cast]
-theorem coe_nat_den (n : ℕ) : (n : ℚ).den = 1 := by
- rw [← Int.cast_ofNat, coe_int_den]
-#align rat.coe_nat_denom Rat.coe_nat_den
+@[simp, norm_cast] lemma den_natCast (n : ℕ) : den n = 1 := rfl
+#align rat.coe_nat_denom Rat.den_natCast
+
+-- TODO: Fix the names in Std
+alias num_intCast := intCast_num
+alias den_intCast := intCast_den
-- Will be subsumed by `Int.coe_inj` after we have defined
-- `LinearOrderedField ℚ` (which implies characteristic zero).
$
with <|
(#9319)
See Zulip thread for the discussion.
@@ -147,8 +147,8 @@ theorem lift_binop_eq (f : ℚ → ℚ → ℚ) (f₁ : ℤ → ℤ → ℤ →
generalize ha : a /. b = x; cases' x with n₁ d₁ h₁ c₁; rw [num_den'] at ha
generalize hc : c /. d = x; cases' x with n₂ d₂ h₂ c₂; rw [num_den'] at hc
rw [fv]
- have d₁0 := ne_of_gt (Int.ofNat_lt.2 $ Nat.pos_of_ne_zero h₁)
- have d₂0 := ne_of_gt (Int.ofNat_lt.2 $ Nat.pos_of_ne_zero h₂)
+ have d₁0 := ne_of_gt (Int.ofNat_lt.2 <| Nat.pos_of_ne_zero h₁)
+ have d₂0 := ne_of_gt (Int.ofNat_lt.2 <| Nat.pos_of_ne_zero h₂)
exact (divInt_eq_iff (f0 d₁0 d₂0) (f0 b0 d0)).2
(H ((divInt_eq_iff b0 d₁0).1 ha) ((divInt_eq_iff d0 d₂0).1 hc))
#align rat.lift_binop_eq Rat.lift_binop_eq
@@ -87,7 +87,7 @@ lemma num_ne_zero {q : ℚ} : q.num ≠ 0 ↔ q ≠ 0 := num_eq_zero.not
@[simp]
theorem divInt_eq_zero {a b : ℤ} (b0 : b ≠ 0) : a /. b = 0 ↔ a = 0 := by
- rw [←zero_divInt b, divInt_eq_iff b0 b0, zero_mul, mul_eq_zero, or_iff_left b0]
+ rw [← zero_divInt b, divInt_eq_iff b0 b0, zero_mul, mul_eq_zero, or_iff_left b0]
#align rat.mk_eq_zero Rat.divInt_eq_zero
theorem divInt_ne_zero {a b : ℤ} (b0 : b ≠ 0) : a /. b ≠ 0 ↔ a ≠ 0 :=
@@ -557,7 +557,7 @@ theorem mkRat_eq_div {n : ℤ} {d : ℕ} : mkRat n d = n / d := by
unfold Rat.inv
have h₁ : 0 < d := Nat.pos_iff_ne_zero.2 h
have h₂ : ¬ (d : ℤ) < 0 := of_decide_eq_false rfl
- simp [h₁, h₂, ←Rat.normalize_eq_mk', Rat.normalize_eq_mkRat, ← mkRat_one,
+ simp [h₁, h₂, ← Rat.normalize_eq_mk', Rat.normalize_eq_mkRat, ← mkRat_one,
Rat.mkRat_mul_mkRat]
end Rat
I've also got a change to make this required, but I'd like to land this first.
@@ -551,7 +551,7 @@ end Casts
theorem mkRat_eq_div {n : ℤ} {d : ℕ} : mkRat n d = n / d := by
simp only [mkRat, zero_mk]
- by_cases d = 0
+ by_cases h : d = 0
· simp [h]
· simp [h, HDiv.hDiv, Rat.div, Div.div]
unfold Rat.inv
This is the supremum of
along with some minor fixes from failures on nightly-testing as Mathlib master
is merged into it.
Note that some PRs for changes that are already compatible with the current toolchain and will be necessary have already been split out: #8380.
I am hopeful that in future we will be able to progressively merge adaptation PRs into a bump/v4.X.0
branch, so we never end up with a "big merge" like this. However one of these adaptation PRs (#8056) predates my new scheme for combined CI, and it wasn't possible to keep that PR viable in the meantime.
In particular this includes adjustments for the Lean PRs
We can get rid of all the
local macro_rules | `($x ^ $y) => `(HPow.hPow $x $y) -- Porting note: See issue [lean4#2220](https://github.com/leanprover/lean4/pull/2220)
macros across Mathlib (and in any projects that want to write natural number powers of reals).
Changes the default behaviour of simp
to (config := {decide := false})
. This makes simp
(and consequentially norm_num
) less powerful, but also more consistent, and less likely to blow up in long failures. This requires a variety of changes: changing some previously by simp
or norm_num
to decide
or rfl
, or adding (config := {decide := true})
.
This changed the behaviour of simp
so that simp [f]
will only unfold "fully applied" occurrences of f
. The old behaviour can be recovered with simp (config := { unfoldPartialApp := true })
. We may in future add a syntax for this, e.g. simp [!f]
; please provide feedback! In the meantime, we have made the following changes:
(config := { unfoldPartialApp := true })
in some places, to recover the old behaviour@[eqns]
to manually adjust the equation lemmas for a particular definition, recovering the old behaviour just for that definition. See #8371, where we do this for Function.comp
and Function.flip
.This change in Lean may require further changes down the line (e.g. adding the !f
syntax, and/or upstreaming the special treatment for Function.comp
and Function.flip
, and/or removing this special treatment). Please keep an open and skeptical mind about these changes!
Co-authored-by: leanprover-community-mathlib4-bot <leanprover-community-mathlib4-bot@users.noreply.github.com> Co-authored-by: Scott Morrison <scott.morrison@gmail.com> Co-authored-by: Eric Wieser <wieser.eric@gmail.com> Co-authored-by: Mauricio Collares <mauricio@collares.org>
@@ -240,14 +240,16 @@ theorem divInt_zero_one : 0 /. 1 = 0 :=
theorem divInt_one_one : 1 /. 1 = 1 :=
show divInt _ _ = _ by
rw [divInt]
- simp
+ simp [mkRat, normalize]
+ rfl
#align rat.mk_one_one Rat.divInt_one_one
@[simp]
theorem divInt_neg_one_one : -1 /. 1 = -1 :=
show divInt _ _ = _ by
rw [divInt]
- simp
+ simp [mkRat, normalize]
+ rfl
#align rat.mk_neg_one_one Rat.divInt_neg_one_one
theorem divInt_one (n : ℤ) : n /. 1 = n :=
Removes nonterminal simps on lines looking like simp [...]
@@ -219,7 +219,8 @@ protected theorem add_assoc : a + b + c = a + (b + c) :=
numDenCasesOn' a fun n₁ d₁ h₁ =>
numDenCasesOn' b fun n₂ d₂ h₂ =>
numDenCasesOn' c fun n₃ d₃ h₃ => by
- simp [h₁, h₂, h₃]
+ simp only [ne_eq, Nat.cast_eq_zero, h₁, not_false_eq_true, h₂, add_def'', mul_eq_zero,
+ or_self, h₃]
rw [mul_assoc, add_mul, add_mul, mul_assoc, add_assoc]
congr 2
ac_rfl
@@ -273,7 +274,8 @@ protected theorem add_mul : (a + b) * c = a * c + b * c :=
numDenCasesOn' a fun n₁ d₁ h₁ =>
numDenCasesOn' b fun n₂ d₂ h₂ =>
numDenCasesOn' c fun n₃ d₃ h₃ => by
- simp [h₁, h₂, h₃, mul_ne_zero]
+ simp only [ne_eq, Nat.cast_eq_zero, h₁, not_false_eq_true, h₂, add_def'', mul_eq_zero,
+ or_self, h₃, mul_def']
rw [← divInt_mul_right (Int.coe_nat_ne_zero.2 h₃), add_mul, add_mul]
ac_rfl
#align rat.add_mul Rat.add_mul
@@ -546,7 +548,7 @@ theorem coe_int_inj (m n : ℤ) : (m : ℚ) = n ↔ m = n :=
end Casts
theorem mkRat_eq_div {n : ℤ} {d : ℕ} : mkRat n d = n / d := by
- simp [mkRat]
+ simp only [mkRat, zero_mk]
by_cases d = 0
· simp [h]
· simp [h, HDiv.hDiv, Rat.div, Div.div]
The n-th Harmonic number is not an integer for n > 1. This proof uses 2-adic valuations.
@@ -511,6 +511,10 @@ theorem coe_int_num_of_den_eq_one {q : ℚ} (hq : q.den = 1) : (q.num : ℚ) = q
rfl
#align rat.coe_int_num_of_denom_eq_one Rat.coe_int_num_of_den_eq_one
+lemma eq_num_of_isInt {q : ℚ} (h : q.isInt) : q = q.num := by
+ rw [Rat.isInt, Nat.beq_eq_true_eq] at h
+ exact (Rat.coe_int_num_of_den_eq_one h).symm
+
theorem den_eq_one_iff (r : ℚ) : r.den = 1 ↔ ↑r.num = r :=
⟨Rat.coe_int_num_of_den_eq_one, fun h => h ▸ Rat.coe_int_den r.num⟩
#align rat.denom_eq_one_iff Rat.den_eq_one_iff
@@ -118,7 +118,7 @@ theorem coe_int_eq_divInt (z : ℤ) : (z : ℚ) = z /. 1 := num_den'
numbers of the form `n /. d` with `0 < d` and coprime `n`, `d`. -/
@[elab_as_elim]
def numDenCasesOn.{u} {C : ℚ → Sort u} :
- ∀ (a : ℚ) (_ : ∀ n d, 0 < d → (Int.natAbs n).coprime d → C (n /. d)), C a
+ ∀ (a : ℚ) (_ : ∀ n d, 0 < d → (Int.natAbs n).Coprime d → C (n /. d)), C a
| ⟨n, d, h, c⟩, H => by rw [num_den']; exact H n d (Nat.pos_of_ne_zero h) c
#align rat.num_denom_cases_on Rat.numDenCasesOn
@@ -118,7 +118,7 @@ theorem coe_int_eq_divInt (z : ℤ) : (z : ℚ) = z /. 1 := num_den'
numbers of the form `n /. d` with `0 < d` and coprime `n`, `d`. -/
@[elab_as_elim]
def numDenCasesOn.{u} {C : ℚ → Sort u} :
- ∀ (a : ℚ) (_ : ∀ n d, 0 < d → (Int.natAbs n).Coprime d → C (n /. d)), C a
+ ∀ (a : ℚ) (_ : ∀ n d, 0 < d → (Int.natAbs n).coprime d → C (n /. d)), C a
| ⟨n, d, h, c⟩, H => by rw [num_den']; exact H n d (Nat.pos_of_ne_zero h) c
#align rat.num_denom_cases_on Rat.numDenCasesOn
Some changes have already been review and delegated in #6910 and #7148.
The diff that needs looking at is https://github.com/leanprover-community/mathlib4/pull/7174/commits/64d6d07ee18163627c8f517eb31455411921c5ac
The std bump PR was insta-merged already!
Co-authored-by: leanprover-community-mathlib4-bot <leanprover-community-mathlib4-bot@users.noreply.github.com> Co-authored-by: Scott Morrison <scott.morrison@gmail.com>
@@ -118,7 +118,7 @@ theorem coe_int_eq_divInt (z : ℤ) : (z : ℚ) = z /. 1 := num_den'
numbers of the form `n /. d` with `0 < d` and coprime `n`, `d`. -/
@[elab_as_elim]
def numDenCasesOn.{u} {C : ℚ → Sort u} :
- ∀ (a : ℚ) (_ : ∀ n d, 0 < d → (Int.natAbs n).coprime d → C (n /. d)), C a
+ ∀ (a : ℚ) (_ : ∀ n d, 0 < d → (Int.natAbs n).Coprime d → C (n /. d)), C a
| ⟨n, d, h, c⟩, H => by rw [num_den']; exact H n d (Nat.pos_of_ne_zero h) c
#align rat.num_denom_cases_on Rat.numDenCasesOn
Co-authored-by: Yaël Dillies <yael.dillies@gmail.com> Co-authored-by: Oliver Nash <github@olivernash.org>
@@ -83,6 +83,8 @@ lemma num_eq_zero {q : ℚ} : q.num = 0 ↔ q = 0 := by
exact zero_mk _ _ _
· exact congr_arg num
+lemma num_ne_zero {q : ℚ} : q.num ≠ 0 ↔ q ≠ 0 := num_eq_zero.not
+
@[simp]
theorem divInt_eq_zero {a b : ℤ} (b0 : b ≠ 0) : a /. b = 0 ↔ a = 0 := by
rw [←zero_divInt b, divInt_eq_iff b0 b0, zero_mul, mul_eq_zero, or_iff_left b0]
@@ -546,8 +546,8 @@ theorem mkRat_eq_div {n : ℤ} {d : ℕ} : mkRat n d = n / d := by
· simp [h, HDiv.hDiv, Rat.div, Div.div]
unfold Rat.inv
have h₁ : 0 < d := Nat.pos_iff_ne_zero.2 h
- have h₂ : ¬ (d : ℤ) < 0 := by simp only [not_lt, Nat.cast_nonneg]
- simp [h, h₁, h₂, ←Rat.normalize_eq_mk', Rat.normalize_eq_mkRat, ← mkRat_one,
+ have h₂ : ¬ (d : ℤ) < 0 := of_decide_eq_false rfl
+ simp [h₁, h₂, ←Rat.normalize_eq_mk', Rat.normalize_eq_mkRat, ← mkRat_one,
Rat.mkRat_mul_mkRat]
end Rat
@@ -5,10 +5,9 @@ Authors: Johannes Hölzl, Mario Carneiro
-/
import Mathlib.Data.Rat.Init
import Mathlib.Data.Int.Cast.Defs
-import Mathlib.Data.Int.Dvd.Basic
-import Mathlib.Algebra.Ring.Regular
-import Mathlib.Data.Nat.GCD.Basic
-import Mathlib.Data.PNat.Defs
+import Mathlib.Data.Int.Order.Basic
+import Mathlib.Data.Nat.Cast.Basic
+import Mathlib.Algebra.GroupWithZero.Basic
#align_import data.rat.defs from "leanprover-community/mathlib"@"18a5306c091183ac90884daa9373fa3b178e8607"
@@ -84,10 +83,6 @@ lemma num_eq_zero {q : ℚ} : q.num = 0 ↔ q = 0 := by
exact zero_mk _ _ _
· exact congr_arg num
-private theorem gcd_abs_dvd_left {a b} : (Nat.gcd (Int.natAbs a) b : ℤ) ∣ a :=
- Int.dvd_natAbs.1 <| Int.coe_nat_dvd.2 <| Nat.gcd_dvd_left (Int.natAbs a) b
--- Porting note: no #align here as the declaration is private.
-
@[simp]
theorem divInt_eq_zero {a b : ℤ} (b0 : b ≠ 0) : a /. b = 0 ↔ a = 0 := by
rw [←zero_divInt b, divInt_eq_iff b0 b0, zero_mul, mul_eq_zero, or_iff_left b0]
@@ -551,7 +546,7 @@ theorem mkRat_eq_div {n : ℤ} {d : ℕ} : mkRat n d = n / d := by
· simp [h, HDiv.hDiv, Rat.div, Div.div]
unfold Rat.inv
have h₁ : 0 < d := Nat.pos_iff_ne_zero.2 h
- have h₂ : ¬ (d : ℤ) < 0 := by simp
+ have h₂ : ¬ (d : ℤ) < 0 := by simp only [not_lt, Nat.cast_nonneg]
simp [h, h₁, h₂, ←Rat.normalize_eq_mk', Rat.normalize_eq_mkRat, ← mkRat_one,
Rat.mkRat_mul_mkRat]
@@ -559,3 +554,6 @@ end Rat
-- Guard against import creep.
assert_not_exists Field
+assert_not_exists PNat
+assert_not_exists Nat.dvd_mul
+assert_not_exists IsDomain.toCancelMonoidWithZero
@@ -76,6 +76,14 @@ theorem zero_mk (d) (h : d ≠ 0) (w) : mk' 0 d h w = 0 := by congr
#align rat.zero_mk_nat Rat.zero_mkRat
#align rat.zero_mk Rat.zero_divInt
+@[simp]
+lemma num_eq_zero {q : ℚ} : q.num = 0 ↔ q = 0 := by
+ induction q
+ constructor
+ · rintro rfl
+ exact zero_mk _ _ _
+ · exact congr_arg num
+
private theorem gcd_abs_dvd_left {a b} : (Nat.gcd (Int.natAbs a) b : ℤ) ∣ a :=
Int.dvd_natAbs.1 <| Int.coe_nat_dvd.2 <| Nat.gcd_dvd_left (Int.natAbs a) b
-- Porting note: no #align here as the declaration is private.
This removes the with
pattern from the Field
and CommSemiGroupWithZero
instances on Rat
.
The resulting term decreases in size by an order of magnitude (at least).
Co-authored-by: Matthew Robert Ballard <100034030+mattrobball@users.noreply.github.com>
@@ -327,13 +327,7 @@ instance commRing : CommRing ℚ where
← divInt_one_one, Nat.cast_add, Nat.cast_one, mul_one]
instance commGroupWithZero : CommGroupWithZero ℚ :=
- { Rat.commRing with
- zero := 0
- one := 1
- mul := (· * ·)
- inv := Inv.inv
- div := (· / ·)
- exists_pair_ne := ⟨0, 1, Rat.zero_ne_one⟩
+ { exists_pair_ne := ⟨0, 1, Rat.zero_ne_one⟩
inv_zero := by
change Rat.inv 0 = 0
rw [Rat.inv_def]
@@ -2,11 +2,6 @@
Copyright (c) 2019 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Mario Carneiro
-
-! This file was ported from Lean 3 source module data.rat.defs
-! leanprover-community/mathlib commit 18a5306c091183ac90884daa9373fa3b178e8607
-! Please do not edit these lines, except to modify the commit id
-! if you have ported upstream changes.
-/
import Mathlib.Data.Rat.Init
import Mathlib.Data.Int.Cast.Defs
@@ -15,6 +10,8 @@ import Mathlib.Algebra.Ring.Regular
import Mathlib.Data.Nat.GCD.Basic
import Mathlib.Data.PNat.Defs
+#align_import data.rat.defs from "leanprover-community/mathlib"@"18a5306c091183ac90884daa9373fa3b178e8607"
+
/-!
# Basics for the Rational Numbers
@@ -272,7 +272,7 @@ protected theorem add_mul : (a + b) * c = a * c + b * c :=
numDenCasesOn' b fun n₂ d₂ h₂ =>
numDenCasesOn' c fun n₃ d₃ h₃ => by
simp [h₁, h₂, h₃, mul_ne_zero]
- rw [← divInt_mul_right (Int.coe_nat_ne_zero.2 h₃), add_mul, add_mul]
+ rw [← divInt_mul_right (Int.coe_nat_ne_zero.2 h₃), add_mul, add_mul]
ac_rfl
#align rat.add_mul Rat.add_mul
Co-authored-by: Komyyy <pol_tta@outlook.jp> Co-authored-by: Scott Morrison <scott.morrison@gmail.com> Co-authored-by: Scott Morrison <scott.morrison@anu.edu.au> Co-authored-by: Ruben Van de Velde <65514131+Ruben-VandeVelde@users.noreply.github.com> Co-authored-by: Mario Carneiro <di.gama@gmail.com>
@@ -238,7 +238,6 @@ theorem divInt_one_one : 1 /. 1 = 1 :=
show divInt _ _ = _ by
rw [divInt]
simp
- rfl
#align rat.mk_one_one Rat.divInt_one_one
@[simp]
@@ -246,7 +245,6 @@ theorem divInt_neg_one_one : -1 /. 1 = -1 :=
show divInt _ _ = _ by
rw [divInt]
simp
- rfl
#align rat.mk_neg_one_one Rat.divInt_neg_one_one
theorem divInt_one (n : ℤ) : n /. 1 = n :=
This is the second half of the changes originally in #5699, removing all occurrences of ;
after a space and implementing a linter rule to enforce it.
In most cases this 2-character substring has a space after it, so the following command was run first:
find . -type f -name "*.lean" -exec sed -i -E 's/ ; /; /g' {} \;
The remaining cases were few enough in number that they were done manually.
@@ -117,7 +117,7 @@ numbers of the form `n /. d` with `0 < d` and coprime `n`, `d`. -/
@[elab_as_elim]
def numDenCasesOn.{u} {C : ℚ → Sort u} :
∀ (a : ℚ) (_ : ∀ n d, 0 < d → (Int.natAbs n).coprime d → C (n /. d)), C a
- | ⟨n, d, h, c⟩, H => by rw [num_den'] ; exact H n d (Nat.pos_of_ne_zero h) c
+ | ⟨n, d, h, c⟩, H => by rw [num_den']; exact H n d (Nat.pos_of_ne_zero h) c
#align rat.num_denom_cases_on Rat.numDenCasesOn
/-- Define a (dependent) function or prove `∀ r : ℚ, p r` by dealing with rational
@@ -560,6 +560,5 @@ theorem mkRat_eq_div {n : ℤ} {d : ℕ} : mkRat n d = n / d := by
end Rat
--- Porting note: `assert_not_exists` is not implemented yet.
-- Guard against import creep.
--- assert_not_exists field
+assert_not_exists Field
This PR fixes two things:
align
statements for definitions and theorems and instances that are separated by two newlines from the relevant declaration (s/\n\n#align/\n#align
). This is often seen in the mathport output after ending calc
blocks.#align
statements. (This was needed for a script I wrote for #3630.)@@ -86,7 +86,6 @@ private theorem gcd_abs_dvd_left {a b} : (Nat.gcd (Int.natAbs a) b : ℤ) ∣ a
@[simp]
theorem divInt_eq_zero {a b : ℤ} (b0 : b ≠ 0) : a /. b = 0 ↔ a = 0 := by
rw [←zero_divInt b, divInt_eq_iff b0 b0, zero_mul, mul_eq_zero, or_iff_left b0]
-
#align rat.mk_eq_zero Rat.divInt_eq_zero
theorem divInt_ne_zero {a b : ℤ} (b0 : b ≠ 0) : a /. b ≠ 0 ↔ a ≠ 0 :=
@@ -157,7 +156,6 @@ theorem add_def'' {a b c d : ℤ} (b0 : b ≠ 0) (d0 : d ≠ 0) :
a /. b + c /. d = (a * d + c * b) /. (b * d) := divInt_add_divInt _ _ b0 d0
#align rat.add_def Rat.add_def''
-
#align rat.neg Rat.neg
-- Porting note: there's already an instance for `Neg ℚ` is in Std.
@@ -468,7 +466,6 @@ theorem div_num_den (q r : ℚ) : q / r = q.num * r.den /. (q.den * r.num) :=
_ = q.num /. q.den * (r.num /. r.den)⁻¹ := by simp [num_den]
_ = q.num /. q.den * (r.den /. r.num) := by rw [inv_def']
_ = q.num * r.den /. (q.den * r.num) := mul_def' (by simpa using den_nz q) hr
-
#align rat.div_num_denom Rat.div_num_den
section Casts
norm_num
(#1707)
We implement #1706.
In addition to a norm_num
extension for OfScientific.ofScientific
, we implement extensions for
Int.ofNat
mkRat
Rat.cast
/RatCast.ratCast
which made implementation more convenient. We also patch up the other two *.cast
evaluators consistently while we're at it.
We create an instance of OfScientific K
for any division ring K
.
See Zulip discussion here for the original discussion, and this Zulip discussion for the more recent one.
@@ -251,6 +251,15 @@ theorem divInt_neg_one_one : -1 /. 1 = -1 :=
rfl
#align rat.mk_neg_one_one Rat.divInt_neg_one_one
+theorem divInt_one (n : ℤ) : n /. 1 = n :=
+ show divInt _ _ = _ by
+ rw [divInt]
+ simp [mkRat, normalize]
+ rfl
+
+theorem mkRat_one {n : ℤ} : mkRat n 1 = n := by
+ simp [Rat.mkRat_eq, Rat.divInt_one]
+
#align rat.mul_one Rat.mul_one
#align rat.one_mul Rat.one_mul
#align rat.mul_comm Rat.mul_comm
@@ -541,6 +550,17 @@ theorem coe_int_inj (m n : ℤ) : (m : ℚ) = n ↔ m = n :=
end Casts
+theorem mkRat_eq_div {n : ℤ} {d : ℕ} : mkRat n d = n / d := by
+ simp [mkRat]
+ by_cases d = 0
+ · simp [h]
+ · simp [h, HDiv.hDiv, Rat.div, Div.div]
+ unfold Rat.inv
+ have h₁ : 0 < d := Nat.pos_iff_ne_zero.2 h
+ have h₂ : ¬ (d : ℤ) < 0 := by simp
+ simp [h, h₁, h₂, ←Rat.normalize_eq_mk', Rat.normalize_eq_mkRat, ← mkRat_one,
+ Rat.mkRat_mul_mkRat]
+
end Rat
-- Porting note: `assert_not_exists` is not implemented yet.
Incorporates the bugfix https://github.com/leanprover/std4/commit/04b3c9831e0c141713a70e68af7e40973ec9a1ff for slow defeq checks between rational number arithmetic expressions.
Co-authored-by: Ruben Van de Velde <65514131+Ruben-VandeVelde@users.noreply.github.com>
@@ -332,7 +332,10 @@ instance commGroupWithZero : CommGroupWithZero ℚ :=
inv := Inv.inv
div := (· / ·)
exists_pair_ne := ⟨0, 1, Rat.zero_ne_one⟩
- inv_zero := rfl
+ inv_zero := by
+ change Rat.inv 0 = 0
+ rw [Rat.inv_def]
+ rfl
mul_inv_cancel := Rat.mul_inv_cancel
mul_zero := mul_zero
zero_mul := zero_mul }
@@ -43,9 +43,6 @@ theorem pos (a : ℚ) : 0 < a.den := Nat.pos_of_ne_zero a.den_nz
#align rat.of_int Rat.ofInt
-instance : IntCast ℚ :=
- ⟨ofInt⟩
-
@[simp]
theorem ofInt_eq_cast (n : ℤ) : ofInt n = Int.cast n :=
rfl
@@ -46,6 +46,7 @@ theorem pos (a : ℚ) : 0 < a.den := Nat.pos_of_ne_zero a.den_nz
instance : IntCast ℚ :=
⟨ofInt⟩
+@[simp]
theorem ofInt_eq_cast (n : ℤ) : ofInt n = Int.cast n :=
rfl
#align rat.of_int_eq_cast Rat.ofInt_eq_cast
@@ -60,15 +61,6 @@ theorem coe_int_den (n : ℤ) : (n : ℚ).den = 1 :=
rfl
#align rat.coe_int_denom Rat.coe_int_den
-instance : Zero ℚ :=
- ⟨(0 : ℤ)⟩
-
-instance : One ℚ :=
- ⟨(1 : ℤ)⟩
-
-instance : Inhabited ℚ :=
- ⟨0⟩
-
#noalign rat.mk_pnat
-- Porting note: TODO Should this be namespaced?
@@ -329,7 +321,7 @@ instance commRing : CommRing ℚ where
right_distrib := Rat.add_mul
sub_eq_add_neg := Rat.sub_eq_add_neg
intCast := fun n => n
- natCast n := ofInt n
+ natCast n := Int.cast n
natCast_zero := rfl
natCast_succ n := by
simp only [coe_int_eq_divInt, add_def'' one_ne_zero one_ne_zero,
@@ -528,17 +520,17 @@ instance canLift : CanLift ℚ ℤ (↑) fun q => q.den = 1 :=
#align rat.can_lift Rat.canLift
theorem coe_nat_eq_divInt (n : ℕ) : ↑n = n /. 1 := by
- rw [← Int.cast_ofNat, ←ofInt_eq_cast, coe_int_eq_divInt]
+ rw [← Int.cast_ofNat, coe_int_eq_divInt]
#align rat.coe_nat_eq_mk Rat.coe_nat_eq_divInt
@[simp, norm_cast]
theorem coe_nat_num (n : ℕ) : (n : ℚ).num = n := by
- rw [← Int.cast_ofNat, ←ofInt_eq_cast, coe_int_num]
+ rw [← Int.cast_ofNat, coe_int_num]
#align rat.coe_nat_num Rat.coe_nat_num
@[simp, norm_cast]
theorem coe_nat_den (n : ℕ) : (n : ℚ).den = 1 := by
- rw [← Int.cast_ofNat, ←ofInt_eq_cast, coe_int_den]
+ rw [← Int.cast_ofNat, coe_int_den]
#align rat.coe_nat_denom Rat.coe_nat_den
-- Will be subsumed by `Int.coe_inj` after we have defined
@@ -523,11 +523,9 @@ theorem den_eq_one_iff (r : ℚ) : r.den = 1 ↔ ↑r.num = r :=
⟨Rat.coe_int_num_of_den_eq_one, fun h => h ▸ Rat.coe_int_den r.num⟩
#align rat.denom_eq_one_iff Rat.den_eq_one_iff
--- Porting note:
--- Waiting on port of the `lift` tactic.
--- instance canLift : CanLift ℚ ℤ coe fun q => q.denom = 1 :=
--- ⟨fun q hq => ⟨q.num, coe_int_num_of_denom_eq_one hq⟩⟩
--- #align rat.can_lift Rat.canLift
+instance canLift : CanLift ℚ ℤ (↑) fun q => q.den = 1 :=
+ ⟨fun q hq => ⟨q.num, coe_int_num_of_den_eq_one hq⟩⟩
+#align rat.can_lift Rat.canLift
theorem coe_nat_eq_divInt (n : ℕ) : ↑n = n /. 1 := by
rw [← Int.cast_ofNat, ←ofInt_eq_cast, coe_int_eq_divInt]
@@ -4,7 +4,7 @@ Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Mario Carneiro
! This file was ported from Lean 3 source module data.rat.defs
-! leanprover-community/mathlib commit fc2ed6f838ce7c9b7c7171e58d78eaf7b438fb0e
+! leanprover-community/mathlib commit 18a5306c091183ac90884daa9373fa3b178e8607
! Please do not edit these lines, except to modify the commit id
! if you have ported upstream changes.
-/
@@ -349,7 +349,7 @@ instance commGroupWithZero : CommGroupWithZero ℚ :=
zero_mul := zero_mul }
instance isDomain : IsDomain ℚ :=
- NoZeroDivisors.toIsDomain _
+ NoZeroDivisors.to_isDomain _
-- Extra instances to short-circuit type class resolution
-- TODO(Mario): this instance slows down Mathlib.Data.Real.Basic
Fix a lot of wrong casing mostly in the docstrings but also sometimes in def/theorem names. E.g. fin 2 --> Fin 2
, add_monoid_hom --> AddMonoidHom
Remove \n
from to_additive
docstrings that were inserted by mathport.
Move files and directories with Gcd
and Smul
to GCD
and SMul
@@ -12,7 +12,7 @@ import Mathlib.Data.Rat.Init
import Mathlib.Data.Int.Cast.Defs
import Mathlib.Data.Int.Dvd.Basic
import Mathlib.Algebra.Ring.Regular
-import Mathlib.Data.Nat.Gcd.Basic
+import Mathlib.Data.Nat.GCD.Basic
import Mathlib.Data.PNat.Defs
/-!
@@ -2,6 +2,11 @@
Copyright (c) 2019 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Mario Carneiro
+
+! This file was ported from Lean 3 source module data.rat.defs
+! leanprover-community/mathlib commit fc2ed6f838ce7c9b7c7171e58d78eaf7b438fb0e
+! Please do not edit these lines, except to modify the commit id
+! if you have ported upstream changes.
-/
import Mathlib.Data.Rat.Init
import Mathlib.Data.Int.Cast.Defs
The unported dependencies are