data.rat.order
⟷
Mathlib.Data.Rat.Order
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)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(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)
mathlib commit https://github.com/leanprover-community/mathlib/commit/65a1391a0106c9204fe45bc73a039f056558cb83
@@ -37,16 +37,14 @@ variable (a b c : ℚ)
open scoped Rat
-#print Rat.Nonneg /-
/-- A rational number is called nonnegative if its numerator is nonnegative. -/
protected def Nonneg (r : ℚ) : Prop :=
0 ≤ r.num
#align rat.nonneg Rat.Nonneg
--/
-#print Rat.divInt_nonneg /-
+#print Rat.divInt_nonneg_iff_of_pos_right /-
@[simp]
-theorem divInt_nonneg (a : ℤ) {b : ℤ} (h : 0 < b) : (a /. b).NonNeg ↔ 0 ≤ a :=
+theorem divInt_nonneg_iff_of_pos_right (a : ℤ) {b : ℤ} (h : 0 < b) : (a /. b).NonNeg ↔ 0 ≤ a :=
by
generalize ha : a /. b = x; cases' x with n₁ d₁ h₁ c₁; rw [num_denom'] at ha
simp [Rat.Nonneg]
@@ -57,11 +55,11 @@ theorem divInt_nonneg (a : ℤ) {b : ℤ} (h : 0 < b) : (a /. b).NonNeg ↔ 0
rw [this]; exact mul_nonneg h₂ (le_of_lt h)
· apply nonneg_of_mul_nonneg_left _ h
rw [← this]; exact mul_nonneg h₂ (Int.ofNat_zero_le _)
-#align rat.mk_nonneg Rat.divInt_nonneg
+#align rat.mk_nonneg Rat.divInt_nonneg_iff_of_pos_right
-/
-#print Rat.nonneg_add /-
-protected theorem nonneg_add {a b} : Rat.Nonneg a → Rat.Nonneg b → Rat.Nonneg (a + b) :=
+#print Rat.add_nonneg /-
+protected theorem add_nonneg {a b} : Rat.Nonneg a → Rat.Nonneg b → Rat.Nonneg (a + b) :=
numDenCasesOn' a fun n₁ d₁ h₁ =>
numDenCasesOn' b fun n₂ d₂ h₂ =>
by
@@ -74,18 +72,18 @@ protected theorem nonneg_add {a b} : Rat.Nonneg a → Rat.Nonneg b → Rat.Nonne
first
| assumption
| apply Int.ofNat_zero_le
-#align rat.nonneg_add Rat.nonneg_add
+#align rat.nonneg_add Rat.add_nonneg
-/
-#print Rat.nonneg_mul /-
-protected theorem nonneg_mul {a b} : Rat.Nonneg a → Rat.Nonneg b → Rat.Nonneg (a * b) :=
+#print Rat.mul_nonneg /-
+protected theorem mul_nonneg {a b} : Rat.Nonneg a → Rat.Nonneg b → Rat.Nonneg (a * b) :=
numDenCasesOn' a fun n₁ d₁ h₁ =>
numDenCasesOn' b fun n₂ d₂ h₂ =>
by
have d₁0 : 0 < (d₁ : ℤ) := Int.natCast_pos.2 (Nat.pos_of_ne_zero h₁)
have d₂0 : 0 < (d₂ : ℤ) := Int.natCast_pos.2 (Nat.pos_of_ne_zero h₂)
simp (config := { contextual := true }) [d₁0, d₂0, h₁, h₂, mul_pos d₁0 d₂0, mul_nonneg]
-#align rat.nonneg_mul Rat.nonneg_mul
+#align rat.nonneg_mul Rat.mul_nonneg
-/
#print Rat.nonneg_antisymm /-
@@ -104,40 +102,40 @@ protected theorem nonneg_total : Rat.Nonneg a ∨ Rat.Nonneg (-a) := by
#align rat.nonneg_total Rat.nonneg_total
-/
-#print Rat.decidableNonneg /-
-instance decidableNonneg : Decidable (Rat.Nonneg a) := by
+#print Rat.instDecidableLeRatInstLERat /-
+instance instDecidableLeRatInstLERat : Decidable (Rat.Nonneg a) := by
cases a <;> unfold Rat.Nonneg <;> infer_instance
-#align rat.decidable_nonneg Rat.decidableNonneg
+#align rat.decidable_nonneg Rat.instDecidableLeRatInstLERat
-/
-#print Rat.le' /-
/-- Relation `a ≤ b` on `ℚ` defined as `a ≤ b ↔ rat.nonneg (b - a)`. Use `a ≤ b` instead of
`rat.le a b`. -/
-protected def le' (a b : ℚ) :=
+protected def Le (a b : ℚ) :=
Rat.Nonneg (b - a)
-#align rat.le Rat.le'
--/
+#align rat.le Rat.Le
instance : LE ℚ :=
- ⟨Rat.le'⟩
+ ⟨Rat.Le⟩
instance decidableLe : DecidableRel ((· ≤ ·) : ℚ → ℚ → Prop)
| a, b => show Decidable (Rat.Nonneg (b - a)) by infer_instance
#align rat.decidable_le Rat.decidableLe
-#print Rat.le_def /-
-protected theorem le_def {a b c d : ℤ} (b0 : 0 < b) (d0 : 0 < d) :
+#print Rat.divInt_le_divInt /-
+protected theorem divInt_le_divInt {a b c d : ℤ} (b0 : 0 < b) (d0 : 0 < d) :
a /. b ≤ c /. d ↔ a * d ≤ c * b := by
show Rat.Nonneg _ ↔ _
rw [← sub_nonneg]
simp [sub_eq_add_neg, ne_of_gt b0, ne_of_gt d0, mul_pos d0 b0]
-#align rat.le_def Rat.le_def
+#align rat.le_def Rat.divInt_le_divInt
-/
-#print Rat.le_refl /-
+/- warning: rat.le_refl clashes with le_refl -> le_refl
+Case conversion may be inaccurate. Consider using '#align rat.le_refl le_reflₓ'. -/
+#print le_refl /-
protected theorem le_refl : a ≤ a :=
show Rat.Nonneg (a - a) by rw [sub_self] <;> exact le_refl (0 : ℤ)
-#align rat.le_refl Rat.le_refl
+#align rat.le_refl le_refl
-/
#print Rat.le_total /-
@@ -146,30 +144,34 @@ protected theorem le_total : a ≤ b ∨ b ≤ a := by
#align rat.le_total Rat.le_total
-/
-#print Rat.le_antisymm /-
+/- warning: rat.le_antisymm clashes with le_antisymm -> le_antisymm
+Case conversion may be inaccurate. Consider using '#align rat.le_antisymm le_antisymmₓ'. -/
+#print le_antisymm /-
protected theorem le_antisymm {a b : ℚ} (hab : a ≤ b) (hba : b ≤ a) : a = b :=
by
have := eq_neg_of_add_eq_zero_left (Rat.nonneg_antisymm hba <| by rwa [← sub_eq_add_neg, neg_sub])
rwa [neg_neg] at this
-#align rat.le_antisymm Rat.le_antisymm
+#align rat.le_antisymm le_antisymm
-/
-#print Rat.le_trans /-
+/- warning: rat.le_trans clashes with le_trans -> le_trans
+Case conversion may be inaccurate. Consider using '#align rat.le_trans le_transₓ'. -/
+#print le_trans /-
protected theorem le_trans {a b c : ℚ} (hab : a ≤ b) (hbc : b ≤ c) : a ≤ c :=
by
- have : Rat.Nonneg (b - a + (c - b)) := Rat.nonneg_add hab hbc
+ have : Rat.Nonneg (b - a + (c - b)) := Rat.add_nonneg hab hbc
simpa [sub_eq_add_neg, add_comm, add_left_comm]
-#align rat.le_trans Rat.le_trans
+#align rat.le_trans le_trans
-/
instance : LinearOrder ℚ where
- le := Rat.le'
- le_refl := Rat.le_refl
- le_trans := @Rat.le_trans
- le_antisymm := @Rat.le_antisymm
+ le := Rat.Le
+ le_refl := le_refl
+ le_trans := @le_trans
+ le_antisymm := @le_antisymm
le_total := Rat.le_total
DecidableEq := by infer_instance
- decidableLe a b := Rat.decidableNonneg (b - a)
+ decidableLe a b := Rat.instDecidableLeRatInstLERat (b - a)
-- Extra instances to short-circuit type class resolution
instance : LT ℚ := by infer_instance
@@ -190,19 +192,19 @@ instance : PartialOrder ℚ := by infer_instance
instance : Preorder ℚ := by infer_instance
-#print Rat.le_def' /-
-protected theorem le_def' {p q : ℚ} : p ≤ q ↔ p.num * q.den ≤ q.num * p.den :=
+#print Rat.le_def /-
+protected theorem le_def {p q : ℚ} : p ≤ q ↔ p.num * q.den ≤ q.num * p.den :=
by
rw [← @num_denom q, ← @num_denom p]
conv_rhs => simp only [num_denom]
- exact Rat.le_def (by exact_mod_cast p.pos) (by exact_mod_cast q.pos)
-#align rat.le_def' Rat.le_def'
+ exact Rat.divInt_le_divInt (by exact_mod_cast p.pos) (by exact_mod_cast q.pos)
+#align rat.le_def' Rat.le_def
-/
#print Rat.lt_def /-
protected theorem lt_def {p q : ℚ} : p < q ↔ p.num * q.den < q.num * p.den :=
by
- rw [lt_iff_le_and_ne, Rat.le_def']
+ rw [lt_iff_le_and_ne, Rat.le_def]
suffices p ≠ q ↔ p.num * q.denom ≠ q.num * p.denom
by
constructor <;> intro h
@@ -212,11 +214,9 @@ protected theorem lt_def {p q : ℚ} : p < q ↔ p.num * q.den < q.num * p.den :
#align rat.lt_def Rat.lt_def
-/
-#print Rat.nonneg_iff_zero_le /-
theorem nonneg_iff_zero_le {a} : Rat.Nonneg a ↔ 0 ≤ a :=
show Rat.Nonneg a ↔ Rat.Nonneg (a - 0) by simp
#align rat.nonneg_iff_zero_le Rat.nonneg_iff_zero_le
--/
#print Rat.num_nonneg /-
theorem num_nonneg : ∀ {a : ℚ}, 0 ≤ a.num ↔ 0 ≤ a
@@ -226,13 +226,15 @@ theorem num_nonneg : ∀ {a : ℚ}, 0 ≤ a.num ↔ 0 ≤ a
#print Rat.add_le_add_left /-
protected theorem add_le_add_left {a b c : ℚ} : c + a ≤ c + b ↔ a ≤ b := by
- unfold LE.le Rat.le' <;> rw [add_sub_add_left_eq_sub]
+ unfold LE.le Rat.Le <;> rw [add_sub_add_left_eq_sub]
#align rat.add_le_add_left Rat.add_le_add_left
-/
+/- warning: rat.mul_nonneg clashes with rat.nonneg_mul -> Rat.mul_nonneg
+Case conversion may be inaccurate. Consider using '#align rat.mul_nonneg Rat.mul_nonnegₓ'. -/
#print Rat.mul_nonneg /-
protected theorem mul_nonneg {a b : ℚ} (ha : 0 ≤ a) (hb : 0 ≤ b) : 0 ≤ a * b := by
- rw [← nonneg_iff_zero_le] at ha hb ⊢ <;> exact Rat.nonneg_mul ha hb
+ rw [← nonneg_iff_zero_le] at ha hb ⊢ <;> exact Rat.mul_nonneg ha hb
#align rat.mul_nonneg Rat.mul_nonneg
-/
@@ -277,8 +279,8 @@ theorem div_lt_div_iff_mul_lt_mul {a b c d : ℤ} (b_pos : 0 < b) (d_pos : 0 < d
by
simp only [lt_iff_le_not_le]
apply and_congr
- · simp [div_num_denom, Rat.le_def b_pos d_pos]
- · apply not_congr; simp [div_num_denom, Rat.le_def d_pos b_pos]
+ · simp [div_num_denom, Rat.divInt_le_divInt b_pos d_pos]
+ · apply not_congr; simp [div_num_denom, Rat.divInt_le_divInt d_pos b_pos]
#align rat.div_lt_div_iff_mul_lt_mul Rat.div_lt_div_iff_mul_lt_mul
-/
@@ -292,12 +294,12 @@ theorem abs_def (q : ℚ) : |q| = q.num.natAbs /. q.den :=
by
cases' le_total q 0 with hq hq
· rw [abs_of_nonpos hq]
- rw [← @num_denom q, ← mk_zero_one, Rat.le_def (Int.natCast_pos.2 q.pos) zero_lt_one, mul_one,
- MulZeroClass.zero_mul] at hq
+ rw [← @num_denom q, ← mk_zero_one, Rat.divInt_le_divInt (Int.natCast_pos.2 q.pos) zero_lt_one,
+ mul_one, MulZeroClass.zero_mul] at hq
rw [Int.ofNat_natAbs_of_nonpos hq, ← neg_def, num_denom]
· rw [abs_of_nonneg hq]
- rw [← @num_denom q, ← mk_zero_one, Rat.le_def zero_lt_one (Int.natCast_pos.2 q.pos), mul_one,
- MulZeroClass.zero_mul] at hq
+ rw [← @num_denom q, ← mk_zero_one, Rat.divInt_le_divInt zero_lt_one (Int.natCast_pos.2 q.pos),
+ mul_one, MulZeroClass.zero_mul] at hq
rw [Int.natAbs_of_nonneg hq, num_denom]
#align rat.abs_def Rat.abs_def
-/
mathlib commit https://github.com/leanprover-community/mathlib/commit/65a1391a0106c9204fe45bc73a039f056558cb83
@@ -65,8 +65,8 @@ protected theorem nonneg_add {a b} : Rat.Nonneg a → Rat.Nonneg b → Rat.Nonne
numDenCasesOn' a fun n₁ d₁ h₁ =>
numDenCasesOn' b fun n₂ d₂ h₂ =>
by
- have d₁0 : 0 < (d₁ : ℤ) := Int.coe_nat_pos.2 (Nat.pos_of_ne_zero h₁)
- have d₂0 : 0 < (d₂ : ℤ) := Int.coe_nat_pos.2 (Nat.pos_of_ne_zero h₂)
+ have d₁0 : 0 < (d₁ : ℤ) := Int.natCast_pos.2 (Nat.pos_of_ne_zero h₁)
+ have d₂0 : 0 < (d₂ : ℤ) := Int.natCast_pos.2 (Nat.pos_of_ne_zero h₂)
simp [d₁0, d₂0, h₁, h₂, mul_pos d₁0 d₂0]
intro n₁0 n₂0
apply add_nonneg <;> apply mul_nonneg <;>
@@ -82,8 +82,8 @@ protected theorem nonneg_mul {a b} : Rat.Nonneg a → Rat.Nonneg b → Rat.Nonne
numDenCasesOn' a fun n₁ d₁ h₁ =>
numDenCasesOn' b fun n₂ d₂ h₂ =>
by
- have d₁0 : 0 < (d₁ : ℤ) := Int.coe_nat_pos.2 (Nat.pos_of_ne_zero h₁)
- have d₂0 : 0 < (d₂ : ℤ) := Int.coe_nat_pos.2 (Nat.pos_of_ne_zero h₂)
+ have d₁0 : 0 < (d₁ : ℤ) := Int.natCast_pos.2 (Nat.pos_of_ne_zero h₁)
+ have d₂0 : 0 < (d₂ : ℤ) := Int.natCast_pos.2 (Nat.pos_of_ne_zero h₂)
simp (config := { contextual := true }) [d₁0, d₂0, h₁, h₂, mul_pos d₁0 d₂0, mul_nonneg]
#align rat.nonneg_mul Rat.nonneg_mul
-/
@@ -92,7 +92,7 @@ protected theorem nonneg_mul {a b} : Rat.Nonneg a → Rat.Nonneg b → Rat.Nonne
protected theorem nonneg_antisymm {a} : Rat.Nonneg a → Rat.Nonneg (-a) → a = 0 :=
numDenCasesOn' a fun n d h =>
by
- have d0 : 0 < (d : ℤ) := Int.coe_nat_pos.2 (Nat.pos_of_ne_zero h)
+ have d0 : 0 < (d : ℤ) := Int.natCast_pos.2 (Nat.pos_of_ne_zero h)
simp [d0, h]
exact fun h₁ h₂ => le_antisymm h₂ h₁
#align rat.nonneg_antisymm Rat.nonneg_antisymm
@@ -292,11 +292,11 @@ theorem abs_def (q : ℚ) : |q| = q.num.natAbs /. q.den :=
by
cases' le_total q 0 with hq hq
· rw [abs_of_nonpos hq]
- rw [← @num_denom q, ← mk_zero_one, Rat.le_def (Int.coe_nat_pos.2 q.pos) zero_lt_one, mul_one,
+ rw [← @num_denom q, ← mk_zero_one, Rat.le_def (Int.natCast_pos.2 q.pos) zero_lt_one, mul_one,
MulZeroClass.zero_mul] at hq
rw [Int.ofNat_natAbs_of_nonpos hq, ← neg_def, num_denom]
· rw [abs_of_nonneg hq]
- rw [← @num_denom q, ← mk_zero_one, Rat.le_def zero_lt_one (Int.coe_nat_pos.2 q.pos), mul_one,
+ rw [← @num_denom q, ← mk_zero_one, Rat.le_def zero_lt_one (Int.natCast_pos.2 q.pos), mul_one,
MulZeroClass.zero_mul] at hq
rw [Int.natAbs_of_nonneg hq, num_denom]
#align rat.abs_def Rat.abs_def
mathlib commit https://github.com/leanprover-community/mathlib/commit/65a1391a0106c9204fe45bc73a039f056558cb83
@@ -4,7 +4,7 @@ Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Mario Carneiro
-/
import Algebra.Order.Field.Defs
-import Data.Rat.Basic
+import Data.Rat.Field
import Data.Int.Cast.Lemmas
import Tactic.AssertExists
mathlib commit https://github.com/leanprover-community/mathlib/commit/65a1391a0106c9204fe45bc73a039f056558cb83
@@ -48,7 +48,7 @@ protected def Nonneg (r : ℚ) : Prop :=
@[simp]
theorem divInt_nonneg (a : ℤ) {b : ℤ} (h : 0 < b) : (a /. b).NonNeg ↔ 0 ≤ a :=
by
- 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
simp [Rat.Nonneg]
have d0 := Int.ofNat_lt.2 h₁
have := (mk_eq (ne_of_gt h) (ne_of_gt d0)).1 ha
@@ -142,7 +142,7 @@ protected theorem le_refl : a ≤ a :=
#print Rat.le_total /-
protected theorem le_total : a ≤ b ∨ b ≤ a := by
- have := Rat.nonneg_total (b - a) <;> rwa [neg_sub] at this
+ have := Rat.nonneg_total (b - a) <;> rwa [neg_sub] at this
#align rat.le_total Rat.le_total
-/
@@ -150,7 +150,7 @@ protected theorem le_total : a ≤ b ∨ b ≤ a := by
protected theorem le_antisymm {a b : ℚ} (hab : a ≤ b) (hba : b ≤ a) : a = b :=
by
have := eq_neg_of_add_eq_zero_left (Rat.nonneg_antisymm hba <| by rwa [← sub_eq_add_neg, neg_sub])
- rwa [neg_neg] at this
+ rwa [neg_neg] at this
#align rat.le_antisymm Rat.le_antisymm
-/
@@ -293,11 +293,11 @@ theorem abs_def (q : ℚ) : |q| = q.num.natAbs /. q.den :=
cases' le_total q 0 with hq hq
· rw [abs_of_nonpos hq]
rw [← @num_denom q, ← mk_zero_one, Rat.le_def (Int.coe_nat_pos.2 q.pos) zero_lt_one, mul_one,
- MulZeroClass.zero_mul] at hq
+ MulZeroClass.zero_mul] at hq
rw [Int.ofNat_natAbs_of_nonpos hq, ← neg_def, num_denom]
· rw [abs_of_nonneg hq]
rw [← @num_denom q, ← mk_zero_one, Rat.le_def zero_lt_one (Int.coe_nat_pos.2 q.pos), mul_one,
- MulZeroClass.zero_mul] at hq
+ MulZeroClass.zero_mul] at hq
rw [Int.natAbs_of_nonneg hq, num_denom]
#align rat.abs_def Rat.abs_def
-/
mathlib commit https://github.com/leanprover-community/mathlib/commit/65a1391a0106c9204fe45bc73a039f056558cb83
@@ -218,10 +218,10 @@ theorem nonneg_iff_zero_le {a} : Rat.Nonneg a ↔ 0 ≤ a :=
#align rat.nonneg_iff_zero_le Rat.nonneg_iff_zero_le
-/
-#print Rat.num_nonneg_iff_zero_le /-
-theorem num_nonneg_iff_zero_le : ∀ {a : ℚ}, 0 ≤ a.num ↔ 0 ≤ a
+#print Rat.num_nonneg /-
+theorem num_nonneg : ∀ {a : ℚ}, 0 ≤ a.num ↔ 0 ≤ a
| ⟨n, d, h, c⟩ => @nonneg_iff_zero_le ⟨n, d, h, c⟩
-#align rat.num_nonneg_iff_zero_le Rat.num_nonneg_iff_zero_le
+#align rat.num_nonneg_iff_zero_le Rat.num_nonneg
-/
#print Rat.add_le_add_left /-
@@ -264,11 +264,11 @@ instance : OrderedCancelAddCommMonoid ℚ := by infer_instance
instance : OrderedAddCommMonoid ℚ := by infer_instance
-#print Rat.num_pos_iff_pos /-
-theorem num_pos_iff_pos {a : ℚ} : 0 < a.num ↔ 0 < a :=
+#print Rat.num_pos /-
+theorem num_pos {a : ℚ} : 0 < a.num ↔ 0 < a :=
lt_iff_lt_of_le_iff_le <| by
simpa [(by cases a <;> rfl : (-a).num = -a.num)] using @num_nonneg_iff_zero_le (-a)
-#align rat.num_pos_iff_pos Rat.num_pos_iff_pos
+#align rat.num_pos_iff_pos Rat.num_pos
-/
#print Rat.div_lt_div_iff_mul_lt_mul /-
mathlib commit https://github.com/leanprover-community/mathlib/commit/ce64cd319bb6b3e82f31c2d38e79080d377be451
@@ -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 Mathbin.Algebra.Order.Field.Defs
-import Mathbin.Data.Rat.Basic
-import Mathbin.Data.Int.Cast.Lemmas
-import Mathbin.Tactic.AssertExists
+import Algebra.Order.Field.Defs
+import Data.Rat.Basic
+import Data.Int.Cast.Lemmas
+import Tactic.AssertExists
#align_import data.rat.order from "leanprover-community/mathlib"@"c3291da49cfa65f0d43b094750541c0731edc932"
mathlib commit https://github.com/leanprover-community/mathlib/commit/8ea5598db6caeddde6cb734aa179cc2408dbd345
@@ -2,17 +2,14 @@
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.order
-! 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.Algebra.Order.Field.Defs
import Mathbin.Data.Rat.Basic
import Mathbin.Data.Int.Cast.Lemmas
import Mathbin.Tactic.AssertExists
+#align_import data.rat.order from "leanprover-community/mathlib"@"c3291da49cfa65f0d43b094750541c0731edc932"
+
/-!
# Order for Rational Numbers
mathlib commit https://github.com/leanprover-community/mathlib/commit/9fb8964792b4237dac6200193a0d533f1b3f7423
@@ -47,6 +47,7 @@ protected def Nonneg (r : ℚ) : Prop :=
#align rat.nonneg Rat.Nonneg
-/
+#print Rat.divInt_nonneg /-
@[simp]
theorem divInt_nonneg (a : ℤ) {b : ℤ} (h : 0 < b) : (a /. b).NonNeg ↔ 0 ≤ a :=
by
@@ -60,6 +61,7 @@ theorem divInt_nonneg (a : ℤ) {b : ℤ} (h : 0 < b) : (a /. b).NonNeg ↔ 0
· apply nonneg_of_mul_nonneg_left _ h
rw [← this]; exact mul_nonneg h₂ (Int.ofNat_zero_le _)
#align rat.mk_nonneg Rat.divInt_nonneg
+-/
#print Rat.nonneg_add /-
protected theorem nonneg_add {a b} : Rat.Nonneg a → Rat.Nonneg b → Rat.Nonneg (a + b) :=
@@ -126,32 +128,42 @@ instance decidableLe : DecidableRel ((· ≤ ·) : ℚ → ℚ → Prop)
| a, b => show Decidable (Rat.Nonneg (b - a)) by infer_instance
#align rat.decidable_le Rat.decidableLe
+#print Rat.le_def /-
protected theorem le_def {a b c d : ℤ} (b0 : 0 < b) (d0 : 0 < d) :
a /. b ≤ c /. d ↔ a * d ≤ c * b := by
show Rat.Nonneg _ ↔ _
rw [← sub_nonneg]
simp [sub_eq_add_neg, ne_of_gt b0, ne_of_gt d0, mul_pos d0 b0]
#align rat.le_def Rat.le_def
+-/
+#print Rat.le_refl /-
protected theorem le_refl : a ≤ a :=
show Rat.Nonneg (a - a) by rw [sub_self] <;> exact le_refl (0 : ℤ)
#align rat.le_refl Rat.le_refl
+-/
+#print Rat.le_total /-
protected theorem le_total : a ≤ b ∨ b ≤ a := by
have := Rat.nonneg_total (b - a) <;> rwa [neg_sub] at this
#align rat.le_total Rat.le_total
+-/
+#print Rat.le_antisymm /-
protected theorem le_antisymm {a b : ℚ} (hab : a ≤ b) (hba : b ≤ a) : a = b :=
by
have := eq_neg_of_add_eq_zero_left (Rat.nonneg_antisymm hba <| by rwa [← sub_eq_add_neg, neg_sub])
rwa [neg_neg] at this
#align rat.le_antisymm Rat.le_antisymm
+-/
+#print Rat.le_trans /-
protected theorem le_trans {a b c : ℚ} (hab : a ≤ b) (hbc : b ≤ c) : a ≤ c :=
by
have : Rat.Nonneg (b - a + (c - b)) := Rat.nonneg_add hab hbc
simpa [sub_eq_add_neg, add_comm, add_left_comm]
#align rat.le_trans Rat.le_trans
+-/
instance : LinearOrder ℚ where
le := Rat.le'
@@ -181,12 +193,14 @@ instance : PartialOrder ℚ := by infer_instance
instance : Preorder ℚ := by infer_instance
+#print Rat.le_def' /-
protected theorem le_def' {p q : ℚ} : p ≤ q ↔ p.num * q.den ≤ q.num * p.den :=
by
rw [← @num_denom q, ← @num_denom p]
conv_rhs => simp only [num_denom]
exact Rat.le_def (by exact_mod_cast p.pos) (by exact_mod_cast q.pos)
#align rat.le_def' Rat.le_def'
+-/
#print Rat.lt_def /-
protected theorem lt_def {p q : ℚ} : p < q ↔ p.num * q.den < q.num * p.den :=
@@ -201,21 +215,29 @@ protected theorem lt_def {p q : ℚ} : p < q ↔ p.num * q.den < q.num * p.den :
#align rat.lt_def Rat.lt_def
-/
+#print Rat.nonneg_iff_zero_le /-
theorem nonneg_iff_zero_le {a} : Rat.Nonneg a ↔ 0 ≤ a :=
show Rat.Nonneg a ↔ Rat.Nonneg (a - 0) by simp
#align rat.nonneg_iff_zero_le Rat.nonneg_iff_zero_le
+-/
+#print Rat.num_nonneg_iff_zero_le /-
theorem num_nonneg_iff_zero_le : ∀ {a : ℚ}, 0 ≤ a.num ↔ 0 ≤ a
| ⟨n, d, h, c⟩ => @nonneg_iff_zero_le ⟨n, d, h, c⟩
#align rat.num_nonneg_iff_zero_le Rat.num_nonneg_iff_zero_le
+-/
+#print Rat.add_le_add_left /-
protected theorem add_le_add_left {a b c : ℚ} : c + a ≤ c + b ↔ a ≤ b := by
unfold LE.le Rat.le' <;> rw [add_sub_add_left_eq_sub]
#align rat.add_le_add_left Rat.add_le_add_left
+-/
+#print Rat.mul_nonneg /-
protected theorem mul_nonneg {a b : ℚ} (ha : 0 ≤ a) (hb : 0 ≤ b) : 0 ≤ a * b := by
rw [← nonneg_iff_zero_le] at ha hb ⊢ <;> exact Rat.nonneg_mul ha hb
#align rat.mul_nonneg Rat.mul_nonneg
+-/
instance : LinearOrderedField ℚ :=
{ Rat.field, Rat.linearOrder,
@@ -268,6 +290,7 @@ theorem lt_one_iff_num_lt_denom {q : ℚ} : q < 1 ↔ q.num < q.den := by simp [
#align rat.lt_one_iff_num_lt_denom Rat.lt_one_iff_num_lt_denom
-/
+#print Rat.abs_def /-
theorem abs_def (q : ℚ) : |q| = q.num.natAbs /. q.den :=
by
cases' le_total q 0 with hq hq
@@ -280,6 +303,7 @@ theorem abs_def (q : ℚ) : |q| = q.num.natAbs /. q.den :=
MulZeroClass.zero_mul] at hq
rw [Int.natAbs_of_nonneg hq, num_denom]
#align rat.abs_def Rat.abs_def
+-/
end Rat
mathlib commit https://github.com/leanprover-community/mathlib/commit/cca40788df1b8755d5baf17ab2f27dacc2e17acb
@@ -50,7 +50,7 @@ protected def Nonneg (r : ℚ) : Prop :=
@[simp]
theorem divInt_nonneg (a : ℤ) {b : ℤ} (h : 0 < b) : (a /. b).NonNeg ↔ 0 ≤ a :=
by
- 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
simp [Rat.Nonneg]
have d0 := Int.ofNat_lt.2 h₁
have := (mk_eq (ne_of_gt h) (ne_of_gt d0)).1 ha
@@ -70,7 +70,11 @@ protected theorem nonneg_add {a b} : Rat.Nonneg a → Rat.Nonneg b → Rat.Nonne
have d₂0 : 0 < (d₂ : ℤ) := Int.coe_nat_pos.2 (Nat.pos_of_ne_zero h₂)
simp [d₁0, d₂0, h₁, h₂, mul_pos d₁0 d₂0]
intro n₁0 n₂0
- apply add_nonneg <;> apply mul_nonneg <;> · first |assumption|apply Int.ofNat_zero_le
+ apply add_nonneg <;> apply mul_nonneg <;>
+ ·
+ first
+ | assumption
+ | apply Int.ofNat_zero_le
#align rat.nonneg_add Rat.nonneg_add
-/
@@ -134,13 +138,13 @@ protected theorem le_refl : a ≤ a :=
#align rat.le_refl Rat.le_refl
protected theorem le_total : a ≤ b ∨ b ≤ a := by
- have := Rat.nonneg_total (b - a) <;> rwa [neg_sub] at this
+ have := Rat.nonneg_total (b - a) <;> rwa [neg_sub] at this
#align rat.le_total Rat.le_total
protected theorem le_antisymm {a b : ℚ} (hab : a ≤ b) (hba : b ≤ a) : a = b :=
by
have := eq_neg_of_add_eq_zero_left (Rat.nonneg_antisymm hba <| by rwa [← sub_eq_add_neg, neg_sub])
- rwa [neg_neg] at this
+ rwa [neg_neg] at this
#align rat.le_antisymm Rat.le_antisymm
protected theorem le_trans {a b c : ℚ} (hab : a ≤ b) (hbc : b ≤ c) : a ≤ c :=
@@ -210,7 +214,7 @@ protected theorem add_le_add_left {a b c : ℚ} : c + a ≤ c + b ↔ a ≤ b :=
#align rat.add_le_add_left Rat.add_le_add_left
protected theorem mul_nonneg {a b : ℚ} (ha : 0 ≤ a) (hb : 0 ≤ b) : 0 ≤ a * b := by
- rw [← nonneg_iff_zero_le] at ha hb⊢ <;> exact Rat.nonneg_mul ha hb
+ rw [← nonneg_iff_zero_le] at ha hb ⊢ <;> exact Rat.nonneg_mul ha hb
#align rat.mul_nonneg Rat.mul_nonneg
instance : LinearOrderedField ℚ :=
@@ -269,11 +273,11 @@ theorem abs_def (q : ℚ) : |q| = q.num.natAbs /. q.den :=
cases' le_total q 0 with hq hq
· rw [abs_of_nonpos hq]
rw [← @num_denom q, ← mk_zero_one, Rat.le_def (Int.coe_nat_pos.2 q.pos) zero_lt_one, mul_one,
- MulZeroClass.zero_mul] at hq
+ MulZeroClass.zero_mul] at hq
rw [Int.ofNat_natAbs_of_nonpos hq, ← neg_def, num_denom]
· rw [abs_of_nonneg hq]
rw [← @num_denom q, ← mk_zero_one, Rat.le_def zero_lt_one (Int.coe_nat_pos.2 q.pos), mul_one,
- MulZeroClass.zero_mul] at hq
+ MulZeroClass.zero_mul] at hq
rw [Int.natAbs_of_nonneg hq, num_denom]
#align rat.abs_def Rat.abs_def
mathlib commit https://github.com/leanprover-community/mathlib/commit/917c3c072e487b3cccdbfeff17e75b40e45f66cb
@@ -38,7 +38,7 @@ namespace Rat
variable (a b c : ℚ)
-open Rat
+open scoped Rat
#print Rat.Nonneg /-
/-- A rational number is called nonnegative if its numerator is nonnegative. -/
@@ -184,6 +184,7 @@ protected theorem le_def' {p q : ℚ} : p ≤ q ↔ p.num * q.den ≤ q.num * p.
exact Rat.le_def (by exact_mod_cast p.pos) (by exact_mod_cast q.pos)
#align rat.le_def' Rat.le_def'
+#print Rat.lt_def /-
protected theorem lt_def {p q : ℚ} : p < q ↔ p.num * q.den < q.num * p.den :=
by
rw [lt_iff_le_and_ne, Rat.le_def']
@@ -194,6 +195,7 @@ protected theorem lt_def {p q : ℚ} : p < q ↔ p.num * q.den < q.num * p.den :
· have tmp := lt_iff_le_and_ne.elim_left h; exact ⟨tmp.left, this.elim_right tmp.right⟩
exact not_iff_not.elim_right eq_iff_mul_eq_mul
#align rat.lt_def Rat.lt_def
+-/
theorem nonneg_iff_zero_le {a} : Rat.Nonneg a ↔ 0 ≤ a :=
show Rat.Nonneg a ↔ Rat.Nonneg (a - 0) by simp
@@ -239,11 +241,14 @@ instance : OrderedCancelAddCommMonoid ℚ := by infer_instance
instance : OrderedAddCommMonoid ℚ := by infer_instance
+#print Rat.num_pos_iff_pos /-
theorem num_pos_iff_pos {a : ℚ} : 0 < a.num ↔ 0 < a :=
lt_iff_lt_of_le_iff_le <| by
simpa [(by cases a <;> rfl : (-a).num = -a.num)] using @num_nonneg_iff_zero_le (-a)
#align rat.num_pos_iff_pos Rat.num_pos_iff_pos
+-/
+#print Rat.div_lt_div_iff_mul_lt_mul /-
theorem div_lt_div_iff_mul_lt_mul {a b c d : ℤ} (b_pos : 0 < b) (d_pos : 0 < d) :
(a : ℚ) / b < c / d ↔ a * d < c * b :=
by
@@ -252,9 +257,12 @@ theorem div_lt_div_iff_mul_lt_mul {a b c d : ℤ} (b_pos : 0 < b) (d_pos : 0 < d
· simp [div_num_denom, Rat.le_def b_pos d_pos]
· apply not_congr; simp [div_num_denom, Rat.le_def d_pos b_pos]
#align rat.div_lt_div_iff_mul_lt_mul Rat.div_lt_div_iff_mul_lt_mul
+-/
+#print Rat.lt_one_iff_num_lt_denom /-
theorem lt_one_iff_num_lt_denom {q : ℚ} : q < 1 ↔ q.num < q.den := by simp [Rat.lt_def]
#align rat.lt_one_iff_num_lt_denom Rat.lt_one_iff_num_lt_denom
+-/
theorem abs_def (q : ℚ) : |q| = q.num.natAbs /. q.den :=
by
mathlib commit https://github.com/leanprover-community/mathlib/commit/917c3c072e487b3cccdbfeff17e75b40e45f66cb
@@ -47,12 +47,6 @@ protected def Nonneg (r : ℚ) : Prop :=
#align rat.nonneg Rat.Nonneg
-/
-/- warning: rat.mk_nonneg -> Rat.divInt_nonneg is a dubious translation:
-lean 3 declaration is
- forall (a : Int) {b : Int}, (LT.lt.{0} Int Int.hasLt (OfNat.ofNat.{0} Int 0 (OfNat.mk.{0} Int 0 (Zero.zero.{0} Int Int.hasZero))) b) -> (Iff (Rat.Nonneg (Rat.mk a b)) (LE.le.{0} Int Int.hasLe (OfNat.ofNat.{0} Int 0 (OfNat.mk.{0} Int 0 (Zero.zero.{0} Int Int.hasZero))) a))
-but is expected to have type
- forall (a : Int) {b : Int}, (LT.lt.{0} Int Int.instLTInt (OfNat.ofNat.{0} Int 0 (instOfNatInt 0)) b) -> (Iff (Rat.Nonneg (Rat.divInt a b)) (LE.le.{0} Int Int.instLEInt (OfNat.ofNat.{0} Int 0 (instOfNatInt 0)) a))
-Case conversion may be inaccurate. Consider using '#align rat.mk_nonneg Rat.divInt_nonnegₓ'. -/
@[simp]
theorem divInt_nonneg (a : ℤ) {b : ℤ} (h : 0 < b) : (a /. b).NonNeg ↔ 0 ≤ a :=
by
@@ -128,12 +122,6 @@ instance decidableLe : DecidableRel ((· ≤ ·) : ℚ → ℚ → Prop)
| a, b => show Decidable (Rat.Nonneg (b - a)) by infer_instance
#align rat.decidable_le Rat.decidableLe
-/- warning: rat.le_def -> Rat.le_def is a dubious translation:
-lean 3 declaration is
- forall {a : Int} {b : Int} {c : Int} {d : Int}, (LT.lt.{0} Int Int.hasLt (OfNat.ofNat.{0} Int 0 (OfNat.mk.{0} Int 0 (Zero.zero.{0} Int Int.hasZero))) b) -> (LT.lt.{0} Int Int.hasLt (OfNat.ofNat.{0} Int 0 (OfNat.mk.{0} Int 0 (Zero.zero.{0} Int Int.hasZero))) d) -> (Iff (LE.le.{0} Rat Rat.hasLe (Rat.mk a b) (Rat.mk c d)) (LE.le.{0} Int Int.hasLe (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}, (LT.lt.{0} Int Int.instLTInt (OfNat.ofNat.{0} Int 0 (instOfNatInt 0)) b) -> (LT.lt.{0} Int Int.instLTInt (OfNat.ofNat.{0} Int 0 (instOfNatInt 0)) d) -> (Iff (LE.le.{0} Rat Rat.instLERat (Rat.divInt a b) (Rat.divInt c d)) (LE.le.{0} Int Int.instLEInt (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)))
-Case conversion may be inaccurate. Consider using '#align rat.le_def Rat.le_defₓ'. -/
protected theorem le_def {a b c d : ℤ} (b0 : 0 < b) (d0 : 0 < d) :
a /. b ≤ c /. d ↔ a * d ≤ c * b := by
show Rat.Nonneg _ ↔ _
@@ -141,44 +129,20 @@ protected theorem le_def {a b c d : ℤ} (b0 : 0 < b) (d0 : 0 < d) :
simp [sub_eq_add_neg, ne_of_gt b0, ne_of_gt d0, mul_pos d0 b0]
#align rat.le_def Rat.le_def
-/- warning: rat.le_refl -> Rat.le_refl is a dubious translation:
-lean 3 declaration is
- forall (a : Rat), LE.le.{0} Rat Rat.hasLe a a
-but is expected to have type
- forall (a : Rat), LE.le.{0} Rat Rat.instLERat a a
-Case conversion may be inaccurate. Consider using '#align rat.le_refl Rat.le_reflₓ'. -/
protected theorem le_refl : a ≤ a :=
show Rat.Nonneg (a - a) by rw [sub_self] <;> exact le_refl (0 : ℤ)
#align rat.le_refl Rat.le_refl
-/- warning: rat.le_total -> Rat.le_total is a dubious translation:
-lean 3 declaration is
- forall (a : Rat) (b : Rat), Or (LE.le.{0} Rat Rat.hasLe a b) (LE.le.{0} Rat Rat.hasLe b a)
-but is expected to have type
- forall (a : Rat) (b : Rat), Or (LE.le.{0} Rat Rat.instLERat a b) (LE.le.{0} Rat Rat.instLERat b a)
-Case conversion may be inaccurate. Consider using '#align rat.le_total Rat.le_totalₓ'. -/
protected theorem le_total : a ≤ b ∨ b ≤ a := by
have := Rat.nonneg_total (b - a) <;> rwa [neg_sub] at this
#align rat.le_total Rat.le_total
-/- warning: rat.le_antisymm -> Rat.le_antisymm is a dubious translation:
-lean 3 declaration is
- forall {a : Rat} {b : Rat}, (LE.le.{0} Rat Rat.hasLe a b) -> (LE.le.{0} Rat Rat.hasLe b a) -> (Eq.{1} Rat a b)
-but is expected to have type
- forall {a : Rat} {b : Rat}, (LE.le.{0} Rat Rat.instLERat a b) -> (LE.le.{0} Rat Rat.instLERat b a) -> (Eq.{1} Rat a b)
-Case conversion may be inaccurate. Consider using '#align rat.le_antisymm Rat.le_antisymmₓ'. -/
protected theorem le_antisymm {a b : ℚ} (hab : a ≤ b) (hba : b ≤ a) : a = b :=
by
have := eq_neg_of_add_eq_zero_left (Rat.nonneg_antisymm hba <| by rwa [← sub_eq_add_neg, neg_sub])
rwa [neg_neg] at this
#align rat.le_antisymm Rat.le_antisymm
-/- warning: rat.le_trans -> Rat.le_trans is a dubious translation:
-lean 3 declaration is
- forall {a : Rat} {b : Rat} {c : Rat}, (LE.le.{0} Rat Rat.hasLe a b) -> (LE.le.{0} Rat Rat.hasLe b c) -> (LE.le.{0} Rat Rat.hasLe a c)
-but is expected to have type
- forall {a : Rat} {b : Rat} {c : Rat}, (LE.le.{0} Rat Rat.instLERat a b) -> (LE.le.{0} Rat Rat.instLERat b c) -> (LE.le.{0} Rat Rat.instLERat a c)
-Case conversion may be inaccurate. Consider using '#align rat.le_trans Rat.le_transₓ'. -/
protected theorem le_trans {a b c : ℚ} (hab : a ≤ b) (hbc : b ≤ c) : a ≤ c :=
by
have : Rat.Nonneg (b - a + (c - b)) := Rat.nonneg_add hab hbc
@@ -213,12 +177,6 @@ instance : PartialOrder ℚ := by infer_instance
instance : Preorder ℚ := by infer_instance
-/- warning: rat.le_def' -> Rat.le_def' is a dubious translation:
-lean 3 declaration is
- forall {p : Rat} {q : Rat}, Iff (LE.le.{0} Rat Rat.hasLe p q) (LE.le.{0} Int Int.hasLe (HMul.hMul.{0, 0, 0} Int Int Int (instHMul.{0} Int Int.hasMul) (Rat.num p) ((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))) (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 p))))
-but is expected to have type
- forall {p : Rat} {q : Rat}, Iff (LE.le.{0} Rat Rat.instLERat p q) (LE.le.{0} Int Int.instLEInt (HMul.hMul.{0, 0, 0} Int Int Int (instHMul.{0} Int Int.instMulInt) (Rat.num p) (Nat.cast.{0} Int instNatCastInt (Rat.den q))) (HMul.hMul.{0, 0, 0} Int Int Int (instHMul.{0} Int Int.instMulInt) (Rat.num q) (Nat.cast.{0} Int instNatCastInt (Rat.den p))))
-Case conversion may be inaccurate. Consider using '#align rat.le_def' Rat.le_def'ₓ'. -/
protected theorem le_def' {p q : ℚ} : p ≤ q ↔ p.num * q.den ≤ q.num * p.den :=
by
rw [← @num_denom q, ← @num_denom p]
@@ -226,12 +184,6 @@ protected theorem le_def' {p q : ℚ} : p ≤ q ↔ p.num * q.den ≤ q.num * p.
exact Rat.le_def (by exact_mod_cast p.pos) (by exact_mod_cast q.pos)
#align rat.le_def' Rat.le_def'
-/- warning: rat.lt_def -> Rat.lt_def is a dubious translation:
-lean 3 declaration is
- forall {p : Rat} {q : Rat}, Iff (LT.lt.{0} Rat Rat.hasLt p q) (LT.lt.{0} Int Int.hasLt (HMul.hMul.{0, 0, 0} Int Int Int (instHMul.{0} Int Int.hasMul) (Rat.num p) ((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))) (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 p))))
-but is expected to have type
- forall {p : Rat} {q : Rat}, Iff (LT.lt.{0} Rat Rat.instLTRat_1 p q) (LT.lt.{0} Int Int.instLTInt (HMul.hMul.{0, 0, 0} Int Int Int (instHMul.{0} Int Int.instMulInt) (Rat.num p) (Nat.cast.{0} Int instNatCastInt (Rat.den q))) (HMul.hMul.{0, 0, 0} Int Int Int (instHMul.{0} Int Int.instMulInt) (Rat.num q) (Nat.cast.{0} Int instNatCastInt (Rat.den p))))
-Case conversion may be inaccurate. Consider using '#align rat.lt_def Rat.lt_defₓ'. -/
protected theorem lt_def {p q : ℚ} : p < q ↔ p.num * q.den < q.num * p.den :=
by
rw [lt_iff_le_and_ne, Rat.le_def']
@@ -243,42 +195,18 @@ protected theorem lt_def {p q : ℚ} : p < q ↔ p.num * q.den < q.num * p.den :
exact not_iff_not.elim_right eq_iff_mul_eq_mul
#align rat.lt_def Rat.lt_def
-/- warning: rat.nonneg_iff_zero_le -> Rat.nonneg_iff_zero_le is a dubious translation:
-lean 3 declaration is
- forall {a : Rat}, Iff (Rat.Nonneg a) (LE.le.{0} Rat Rat.hasLe (OfNat.ofNat.{0} Rat 0 (OfNat.mk.{0} Rat 0 (Zero.zero.{0} Rat Rat.hasZero))) a)
-but is expected to have type
- forall {a : Rat}, Iff (Rat.Nonneg a) (LE.le.{0} Rat Rat.instLERat (OfNat.ofNat.{0} Rat 0 (Rat.instOfNatRat 0)) a)
-Case conversion may be inaccurate. Consider using '#align rat.nonneg_iff_zero_le Rat.nonneg_iff_zero_leₓ'. -/
theorem nonneg_iff_zero_le {a} : Rat.Nonneg a ↔ 0 ≤ a :=
show Rat.Nonneg a ↔ Rat.Nonneg (a - 0) by simp
#align rat.nonneg_iff_zero_le Rat.nonneg_iff_zero_le
-/- warning: rat.num_nonneg_iff_zero_le -> Rat.num_nonneg_iff_zero_le is a dubious translation:
-lean 3 declaration is
- forall {a : Rat}, Iff (LE.le.{0} Int Int.hasLe (OfNat.ofNat.{0} Int 0 (OfNat.mk.{0} Int 0 (Zero.zero.{0} Int Int.hasZero))) (Rat.num a)) (LE.le.{0} Rat Rat.hasLe (OfNat.ofNat.{0} Rat 0 (OfNat.mk.{0} Rat 0 (Zero.zero.{0} Rat Rat.hasZero))) a)
-but is expected to have type
- forall {a : Rat}, Iff (LE.le.{0} Int Int.instLEInt (OfNat.ofNat.{0} Int 0 (instOfNatInt 0)) (Rat.num a)) (LE.le.{0} Rat Rat.instLERat (OfNat.ofNat.{0} Rat 0 (Rat.instOfNatRat 0)) a)
-Case conversion may be inaccurate. Consider using '#align rat.num_nonneg_iff_zero_le Rat.num_nonneg_iff_zero_leₓ'. -/
theorem num_nonneg_iff_zero_le : ∀ {a : ℚ}, 0 ≤ a.num ↔ 0 ≤ a
| ⟨n, d, h, c⟩ => @nonneg_iff_zero_le ⟨n, d, h, c⟩
#align rat.num_nonneg_iff_zero_le Rat.num_nonneg_iff_zero_le
-/- warning: rat.add_le_add_left -> Rat.add_le_add_left is a dubious translation:
-lean 3 declaration is
- forall {a : Rat} {b : Rat} {c : Rat}, Iff (LE.le.{0} Rat Rat.hasLe (HAdd.hAdd.{0, 0, 0} Rat Rat Rat (instHAdd.{0} Rat Rat.hasAdd) c a) (HAdd.hAdd.{0, 0, 0} Rat Rat Rat (instHAdd.{0} Rat Rat.hasAdd) c b)) (LE.le.{0} Rat Rat.hasLe a b)
-but is expected to have type
- forall {a : Rat} {b : Rat} {c : Rat}, Iff (LE.le.{0} Rat Rat.instLERat (HAdd.hAdd.{0, 0, 0} Rat Rat Rat (instHAdd.{0} Rat Rat.instAddRat) c a) (HAdd.hAdd.{0, 0, 0} Rat Rat Rat (instHAdd.{0} Rat Rat.instAddRat) c b)) (LE.le.{0} Rat Rat.instLERat a b)
-Case conversion may be inaccurate. Consider using '#align rat.add_le_add_left Rat.add_le_add_leftₓ'. -/
protected theorem add_le_add_left {a b c : ℚ} : c + a ≤ c + b ↔ a ≤ b := by
unfold LE.le Rat.le' <;> rw [add_sub_add_left_eq_sub]
#align rat.add_le_add_left Rat.add_le_add_left
-/- warning: rat.mul_nonneg -> Rat.mul_nonneg is a dubious translation:
-lean 3 declaration is
- forall {a : Rat} {b : Rat}, (LE.le.{0} Rat Rat.hasLe (OfNat.ofNat.{0} Rat 0 (OfNat.mk.{0} Rat 0 (Zero.zero.{0} Rat Rat.hasZero))) a) -> (LE.le.{0} Rat Rat.hasLe (OfNat.ofNat.{0} Rat 0 (OfNat.mk.{0} Rat 0 (Zero.zero.{0} Rat Rat.hasZero))) b) -> (LE.le.{0} Rat Rat.hasLe (OfNat.ofNat.{0} Rat 0 (OfNat.mk.{0} Rat 0 (Zero.zero.{0} Rat Rat.hasZero))) (HMul.hMul.{0, 0, 0} Rat Rat Rat (instHMul.{0} Rat Rat.hasMul) a b))
-but is expected to have type
- forall {a : Rat} {b : Rat}, (LE.le.{0} Rat Rat.instLERat (OfNat.ofNat.{0} Rat 0 (Rat.instOfNatRat 0)) a) -> (LE.le.{0} Rat Rat.instLERat (OfNat.ofNat.{0} Rat 0 (Rat.instOfNatRat 0)) b) -> (LE.le.{0} Rat Rat.instLERat (OfNat.ofNat.{0} Rat 0 (Rat.instOfNatRat 0)) (HMul.hMul.{0, 0, 0} Rat Rat Rat (instHMul.{0} Rat Rat.instMulRat) a b))
-Case conversion may be inaccurate. Consider using '#align rat.mul_nonneg Rat.mul_nonnegₓ'. -/
protected theorem mul_nonneg {a b : ℚ} (ha : 0 ≤ a) (hb : 0 ≤ b) : 0 ≤ a * b := by
rw [← nonneg_iff_zero_le] at ha hb⊢ <;> exact Rat.nonneg_mul ha hb
#align rat.mul_nonneg Rat.mul_nonneg
@@ -311,23 +239,11 @@ instance : OrderedCancelAddCommMonoid ℚ := by infer_instance
instance : OrderedAddCommMonoid ℚ := by infer_instance
-/- warning: rat.num_pos_iff_pos -> Rat.num_pos_iff_pos is a dubious translation:
-lean 3 declaration is
- forall {a : Rat}, Iff (LT.lt.{0} Int Int.hasLt (OfNat.ofNat.{0} Int 0 (OfNat.mk.{0} Int 0 (Zero.zero.{0} Int Int.hasZero))) (Rat.num a)) (LT.lt.{0} Rat Rat.hasLt (OfNat.ofNat.{0} Rat 0 (OfNat.mk.{0} Rat 0 (Zero.zero.{0} Rat Rat.hasZero))) a)
-but is expected to have type
- forall {a : Rat}, Iff (LT.lt.{0} Int Int.instLTInt (OfNat.ofNat.{0} Int 0 (instOfNatInt 0)) (Rat.num a)) (LT.lt.{0} Rat Rat.instLTRat_1 (OfNat.ofNat.{0} Rat 0 (Rat.instOfNatRat 0)) a)
-Case conversion may be inaccurate. Consider using '#align rat.num_pos_iff_pos Rat.num_pos_iff_posₓ'. -/
theorem num_pos_iff_pos {a : ℚ} : 0 < a.num ↔ 0 < a :=
lt_iff_lt_of_le_iff_le <| by
simpa [(by cases a <;> rfl : (-a).num = -a.num)] using @num_nonneg_iff_zero_le (-a)
#align rat.num_pos_iff_pos Rat.num_pos_iff_pos
-/- warning: rat.div_lt_div_iff_mul_lt_mul -> Rat.div_lt_div_iff_mul_lt_mul is a dubious translation:
-lean 3 declaration is
- forall {a : Int} {b : Int} {c : Int} {d : Int}, (LT.lt.{0} Int Int.hasLt (OfNat.ofNat.{0} Int 0 (OfNat.mk.{0} Int 0 (Zero.zero.{0} Int Int.hasZero))) b) -> (LT.lt.{0} Int Int.hasLt (OfNat.ofNat.{0} Int 0 (OfNat.mk.{0} Int 0 (Zero.zero.{0} Int Int.hasZero))) d) -> (Iff (LT.lt.{0} Rat Rat.hasLt (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))) a) ((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))) b)) (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))) c) ((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))) (LT.lt.{0} Int Int.hasLt (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}, (LT.lt.{0} Int Int.instLTInt (OfNat.ofNat.{0} Int 0 (instOfNatInt 0)) b) -> (LT.lt.{0} Int Int.instLTInt (OfNat.ofNat.{0} Int 0 (instOfNatInt 0)) d) -> (Iff (LT.lt.{0} Rat Rat.instLTRat_1 (HDiv.hDiv.{0, 0, 0} Rat Rat Rat (instHDiv.{0} Rat Rat.instDivRat) (Int.cast.{0} Rat Rat.instIntCastRat a) (Int.cast.{0} Rat Rat.instIntCastRat b)) (HDiv.hDiv.{0, 0, 0} Rat Rat Rat (instHDiv.{0} Rat Rat.instDivRat) (Int.cast.{0} Rat Rat.instIntCastRat c) (Int.cast.{0} Rat Rat.instIntCastRat d))) (LT.lt.{0} Int Int.instLTInt (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)))
-Case conversion may be inaccurate. Consider using '#align rat.div_lt_div_iff_mul_lt_mul Rat.div_lt_div_iff_mul_lt_mulₓ'. -/
theorem div_lt_div_iff_mul_lt_mul {a b c d : ℤ} (b_pos : 0 < b) (d_pos : 0 < d) :
(a : ℚ) / b < c / d ↔ a * d < c * b :=
by
@@ -337,21 +253,9 @@ theorem div_lt_div_iff_mul_lt_mul {a b c d : ℤ} (b_pos : 0 < b) (d_pos : 0 < d
· apply not_congr; simp [div_num_denom, Rat.le_def d_pos b_pos]
#align rat.div_lt_div_iff_mul_lt_mul Rat.div_lt_div_iff_mul_lt_mul
-/- warning: rat.lt_one_iff_num_lt_denom -> Rat.lt_one_iff_num_lt_denom is a dubious translation:
-lean 3 declaration is
- forall {q : Rat}, Iff (LT.lt.{0} Rat Rat.hasLt q (OfNat.ofNat.{0} Rat 1 (OfNat.mk.{0} Rat 1 (One.one.{0} Rat Rat.hasOne)))) (LT.lt.{0} Int Int.hasLt (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 q)))
-but is expected to have type
- forall {q : Rat}, Iff (LT.lt.{0} Rat Rat.instLTRat_1 q (OfNat.ofNat.{0} Rat 1 (Rat.instOfNatRat 1))) (LT.lt.{0} Int Int.instLTInt (Rat.num q) (Nat.cast.{0} Int instNatCastInt (Rat.den q)))
-Case conversion may be inaccurate. Consider using '#align rat.lt_one_iff_num_lt_denom Rat.lt_one_iff_num_lt_denomₓ'. -/
theorem lt_one_iff_num_lt_denom {q : ℚ} : q < 1 ↔ q.num < q.den := by simp [Rat.lt_def]
#align rat.lt_one_iff_num_lt_denom Rat.lt_one_iff_num_lt_denom
-/- warning: rat.abs_def -> Rat.abs_def is a dubious translation:
-lean 3 declaration is
- forall (q : Rat), Eq.{1} Rat (Abs.abs.{0} Rat (Neg.toHasAbs.{0} Rat Rat.hasNeg Rat.hasSup) q) (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))) (Int.natAbs (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 q)))
-but is expected to have type
- forall (q : Rat), Eq.{1} Rat (Abs.abs.{0} Rat (Neg.toHasAbs.{0} Rat Rat.instNegRat Rat.instSupRat) q) (Rat.divInt (Nat.cast.{0} Int instNatCastInt (Int.natAbs (Rat.num q))) (Nat.cast.{0} Int instNatCastInt (Rat.den q)))
-Case conversion may be inaccurate. Consider using '#align rat.abs_def Rat.abs_defₓ'. -/
theorem abs_def (q : ℚ) : |q| = q.num.natAbs /. q.den :=
by
cases' le_total q 0 with hq hq
mathlib commit https://github.com/leanprover-community/mathlib/commit/917c3c072e487b3cccdbfeff17e75b40e45f66cb
@@ -62,11 +62,9 @@ theorem divInt_nonneg (a : ℤ) {b : ℤ} (h : 0 < b) : (a /. b).NonNeg ↔ 0
have := (mk_eq (ne_of_gt h) (ne_of_gt d0)).1 ha
constructor <;> intro h₂
· apply nonneg_of_mul_nonneg_left _ d0
- rw [this]
- exact mul_nonneg h₂ (le_of_lt h)
+ rw [this]; exact mul_nonneg h₂ (le_of_lt h)
· apply nonneg_of_mul_nonneg_left _ h
- rw [← this]
- exact mul_nonneg h₂ (Int.ofNat_zero_le _)
+ rw [← this]; exact mul_nonneg h₂ (Int.ofNat_zero_le _)
#align rat.mk_nonneg Rat.divInt_nonneg
#print Rat.nonneg_add /-
@@ -241,8 +239,7 @@ protected theorem lt_def {p q : ℚ} : p < q ↔ p.num * q.den < q.num * p.den :
by
constructor <;> intro h
· exact lt_iff_le_and_ne.elim_right ⟨h.left, this.elim_left h.right⟩
- · have tmp := lt_iff_le_and_ne.elim_left h
- exact ⟨tmp.left, this.elim_right tmp.right⟩
+ · have tmp := lt_iff_le_and_ne.elim_left h; exact ⟨tmp.left, this.elim_right tmp.right⟩
exact not_iff_not.elim_right eq_iff_mul_eq_mul
#align rat.lt_def Rat.lt_def
@@ -337,8 +334,7 @@ theorem div_lt_div_iff_mul_lt_mul {a b c d : ℤ} (b_pos : 0 < b) (d_pos : 0 < d
simp only [lt_iff_le_not_le]
apply and_congr
· simp [div_num_denom, Rat.le_def b_pos d_pos]
- · apply not_congr
- simp [div_num_denom, Rat.le_def d_pos b_pos]
+ · apply not_congr; simp [div_num_denom, Rat.le_def d_pos b_pos]
#align rat.div_lt_div_iff_mul_lt_mul Rat.div_lt_div_iff_mul_lt_mul
/- warning: rat.lt_one_iff_num_lt_denom -> Rat.lt_one_iff_num_lt_denom is a dubious translation:
mathlib commit https://github.com/leanprover-community/mathlib/commit/0b9eaaa7686280fad8cce467f5c3c57ee6ce77f8
@@ -228,7 +228,12 @@ protected theorem le_def' {p q : ℚ} : p ≤ q ↔ p.num * q.den ≤ q.num * p.
exact Rat.le_def (by exact_mod_cast p.pos) (by exact_mod_cast q.pos)
#align rat.le_def' Rat.le_def'
-#print Rat.lt_def /-
+/- warning: rat.lt_def -> Rat.lt_def is a dubious translation:
+lean 3 declaration is
+ forall {p : Rat} {q : Rat}, Iff (LT.lt.{0} Rat Rat.hasLt p q) (LT.lt.{0} Int Int.hasLt (HMul.hMul.{0, 0, 0} Int Int Int (instHMul.{0} Int Int.hasMul) (Rat.num p) ((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))) (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 p))))
+but is expected to have type
+ forall {p : Rat} {q : Rat}, Iff (LT.lt.{0} Rat Rat.instLTRat_1 p q) (LT.lt.{0} Int Int.instLTInt (HMul.hMul.{0, 0, 0} Int Int Int (instHMul.{0} Int Int.instMulInt) (Rat.num p) (Nat.cast.{0} Int instNatCastInt (Rat.den q))) (HMul.hMul.{0, 0, 0} Int Int Int (instHMul.{0} Int Int.instMulInt) (Rat.num q) (Nat.cast.{0} Int instNatCastInt (Rat.den p))))
+Case conversion may be inaccurate. Consider using '#align rat.lt_def Rat.lt_defₓ'. -/
protected theorem lt_def {p q : ℚ} : p < q ↔ p.num * q.den < q.num * p.den :=
by
rw [lt_iff_le_and_ne, Rat.le_def']
@@ -240,7 +245,6 @@ protected theorem lt_def {p q : ℚ} : p < q ↔ p.num * q.den < q.num * p.den :
exact ⟨tmp.left, this.elim_right tmp.right⟩
exact not_iff_not.elim_right eq_iff_mul_eq_mul
#align rat.lt_def Rat.lt_def
--/
/- warning: rat.nonneg_iff_zero_le -> Rat.nonneg_iff_zero_le is a dubious translation:
lean 3 declaration is
@@ -310,14 +314,23 @@ instance : OrderedCancelAddCommMonoid ℚ := by infer_instance
instance : OrderedAddCommMonoid ℚ := by infer_instance
-#print Rat.num_pos_iff_pos /-
+/- warning: rat.num_pos_iff_pos -> Rat.num_pos_iff_pos is a dubious translation:
+lean 3 declaration is
+ forall {a : Rat}, Iff (LT.lt.{0} Int Int.hasLt (OfNat.ofNat.{0} Int 0 (OfNat.mk.{0} Int 0 (Zero.zero.{0} Int Int.hasZero))) (Rat.num a)) (LT.lt.{0} Rat Rat.hasLt (OfNat.ofNat.{0} Rat 0 (OfNat.mk.{0} Rat 0 (Zero.zero.{0} Rat Rat.hasZero))) a)
+but is expected to have type
+ forall {a : Rat}, Iff (LT.lt.{0} Int Int.instLTInt (OfNat.ofNat.{0} Int 0 (instOfNatInt 0)) (Rat.num a)) (LT.lt.{0} Rat Rat.instLTRat_1 (OfNat.ofNat.{0} Rat 0 (Rat.instOfNatRat 0)) a)
+Case conversion may be inaccurate. Consider using '#align rat.num_pos_iff_pos Rat.num_pos_iff_posₓ'. -/
theorem num_pos_iff_pos {a : ℚ} : 0 < a.num ↔ 0 < a :=
lt_iff_lt_of_le_iff_le <| by
simpa [(by cases a <;> rfl : (-a).num = -a.num)] using @num_nonneg_iff_zero_le (-a)
#align rat.num_pos_iff_pos Rat.num_pos_iff_pos
--/
-#print Rat.div_lt_div_iff_mul_lt_mul /-
+/- warning: rat.div_lt_div_iff_mul_lt_mul -> Rat.div_lt_div_iff_mul_lt_mul is a dubious translation:
+lean 3 declaration is
+ forall {a : Int} {b : Int} {c : Int} {d : Int}, (LT.lt.{0} Int Int.hasLt (OfNat.ofNat.{0} Int 0 (OfNat.mk.{0} Int 0 (Zero.zero.{0} Int Int.hasZero))) b) -> (LT.lt.{0} Int Int.hasLt (OfNat.ofNat.{0} Int 0 (OfNat.mk.{0} Int 0 (Zero.zero.{0} Int Int.hasZero))) d) -> (Iff (LT.lt.{0} Rat Rat.hasLt (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))) a) ((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))) b)) (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))) c) ((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))) (LT.lt.{0} Int Int.hasLt (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}, (LT.lt.{0} Int Int.instLTInt (OfNat.ofNat.{0} Int 0 (instOfNatInt 0)) b) -> (LT.lt.{0} Int Int.instLTInt (OfNat.ofNat.{0} Int 0 (instOfNatInt 0)) d) -> (Iff (LT.lt.{0} Rat Rat.instLTRat_1 (HDiv.hDiv.{0, 0, 0} Rat Rat Rat (instHDiv.{0} Rat Rat.instDivRat) (Int.cast.{0} Rat Rat.instIntCastRat a) (Int.cast.{0} Rat Rat.instIntCastRat b)) (HDiv.hDiv.{0, 0, 0} Rat Rat Rat (instHDiv.{0} Rat Rat.instDivRat) (Int.cast.{0} Rat Rat.instIntCastRat c) (Int.cast.{0} Rat Rat.instIntCastRat d))) (LT.lt.{0} Int Int.instLTInt (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)))
+Case conversion may be inaccurate. Consider using '#align rat.div_lt_div_iff_mul_lt_mul Rat.div_lt_div_iff_mul_lt_mulₓ'. -/
theorem div_lt_div_iff_mul_lt_mul {a b c d : ℤ} (b_pos : 0 < b) (d_pos : 0 < d) :
(a : ℚ) / b < c / d ↔ a * d < c * b :=
by
@@ -327,12 +340,15 @@ theorem div_lt_div_iff_mul_lt_mul {a b c d : ℤ} (b_pos : 0 < b) (d_pos : 0 < d
· apply not_congr
simp [div_num_denom, Rat.le_def d_pos b_pos]
#align rat.div_lt_div_iff_mul_lt_mul Rat.div_lt_div_iff_mul_lt_mul
--/
-#print Rat.lt_one_iff_num_lt_denom /-
+/- warning: rat.lt_one_iff_num_lt_denom -> Rat.lt_one_iff_num_lt_denom is a dubious translation:
+lean 3 declaration is
+ forall {q : Rat}, Iff (LT.lt.{0} Rat Rat.hasLt q (OfNat.ofNat.{0} Rat 1 (OfNat.mk.{0} Rat 1 (One.one.{0} Rat Rat.hasOne)))) (LT.lt.{0} Int Int.hasLt (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 q)))
+but is expected to have type
+ forall {q : Rat}, Iff (LT.lt.{0} Rat Rat.instLTRat_1 q (OfNat.ofNat.{0} Rat 1 (Rat.instOfNatRat 1))) (LT.lt.{0} Int Int.instLTInt (Rat.num q) (Nat.cast.{0} Int instNatCastInt (Rat.den q)))
+Case conversion may be inaccurate. Consider using '#align rat.lt_one_iff_num_lt_denom Rat.lt_one_iff_num_lt_denomₓ'. -/
theorem lt_one_iff_num_lt_denom {q : ℚ} : q < 1 ↔ q.num < q.den := by simp [Rat.lt_def]
#align rat.lt_one_iff_num_lt_denom Rat.lt_one_iff_num_lt_denom
--/
/- warning: rat.abs_def -> Rat.abs_def is a dubious translation:
lean 3 declaration is
mathlib commit https://github.com/leanprover-community/mathlib/commit/da3fc4a33ff6bc75f077f691dc94c217b8d41559
@@ -219,7 +219,7 @@ instance : Preorder ℚ := by infer_instance
lean 3 declaration is
forall {p : Rat} {q : Rat}, Iff (LE.le.{0} Rat Rat.hasLe p q) (LE.le.{0} Int Int.hasLe (HMul.hMul.{0, 0, 0} Int Int Int (instHMul.{0} Int Int.hasMul) (Rat.num p) ((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))) (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 p))))
but is expected to have type
- forall {p : Rat} {q : Rat}, Iff (LE.le.{0} Rat Rat.instLERat p q) (LE.le.{0} Int Int.instLEInt (HMul.hMul.{0, 0, 0} Int Int Int (instHMul.{0} Int Int.instMulInt) (Rat.num p) (Nat.cast.{0} Int Int.instNatCastInt (Rat.den q))) (HMul.hMul.{0, 0, 0} Int Int Int (instHMul.{0} Int Int.instMulInt) (Rat.num q) (Nat.cast.{0} Int Int.instNatCastInt (Rat.den p))))
+ forall {p : Rat} {q : Rat}, Iff (LE.le.{0} Rat Rat.instLERat p q) (LE.le.{0} Int Int.instLEInt (HMul.hMul.{0, 0, 0} Int Int Int (instHMul.{0} Int Int.instMulInt) (Rat.num p) (Nat.cast.{0} Int instNatCastInt (Rat.den q))) (HMul.hMul.{0, 0, 0} Int Int Int (instHMul.{0} Int Int.instMulInt) (Rat.num q) (Nat.cast.{0} Int instNatCastInt (Rat.den p))))
Case conversion may be inaccurate. Consider using '#align rat.le_def' Rat.le_def'ₓ'. -/
protected theorem le_def' {p q : ℚ} : p ≤ q ↔ p.num * q.den ≤ q.num * p.den :=
by
@@ -338,7 +338,7 @@ theorem lt_one_iff_num_lt_denom {q : ℚ} : q < 1 ↔ q.num < q.den := by simp [
lean 3 declaration is
forall (q : Rat), Eq.{1} Rat (Abs.abs.{0} Rat (Neg.toHasAbs.{0} Rat Rat.hasNeg Rat.hasSup) q) (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))) (Int.natAbs (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 q)))
but is expected to have type
- forall (q : Rat), Eq.{1} Rat (Abs.abs.{0} Rat (Neg.toHasAbs.{0} Rat Rat.instNegRat Rat.instSupRat) q) (Rat.divInt (Nat.cast.{0} Int Int.instNatCastInt (Int.natAbs (Rat.num q))) (Nat.cast.{0} Int Int.instNatCastInt (Rat.den q)))
+ forall (q : Rat), Eq.{1} Rat (Abs.abs.{0} Rat (Neg.toHasAbs.{0} Rat Rat.instNegRat Rat.instSupRat) q) (Rat.divInt (Nat.cast.{0} Int instNatCastInt (Int.natAbs (Rat.num q))) (Nat.cast.{0} Int instNatCastInt (Rat.den q)))
Case conversion may be inaccurate. Consider using '#align rat.abs_def Rat.abs_defₓ'. -/
theorem abs_def (q : ℚ) : |q| = q.num.natAbs /. q.den :=
by
mathlib commit https://github.com/leanprover-community/mathlib/commit/3180fab693e2cee3bff62675571264cb8778b212
@@ -345,11 +345,11 @@ theorem abs_def (q : ℚ) : |q| = q.num.natAbs /. q.den :=
cases' le_total q 0 with hq hq
· rw [abs_of_nonpos hq]
rw [← @num_denom q, ← mk_zero_one, Rat.le_def (Int.coe_nat_pos.2 q.pos) zero_lt_one, mul_one,
- zero_mul] at hq
+ MulZeroClass.zero_mul] at hq
rw [Int.ofNat_natAbs_of_nonpos hq, ← neg_def, num_denom]
· rw [abs_of_nonneg hq]
rw [← @num_denom q, ← mk_zero_one, Rat.le_def zero_lt_one (Int.coe_nat_pos.2 q.pos), mul_one,
- zero_mul] at hq
+ MulZeroClass.zero_mul] at hq
rw [Int.natAbs_of_nonneg hq, num_denom]
#align rat.abs_def Rat.abs_def
mathlib commit https://github.com/leanprover-community/mathlib/commit/9da1b3534b65d9661eb8f42443598a92bbb49211
@@ -207,9 +207,9 @@ instance : SemilatticeInf ℚ := by infer_instance
instance : SemilatticeSup ℚ := by infer_instance
-instance : HasInf ℚ := by infer_instance
+instance : Inf ℚ := by infer_instance
-instance : HasSup ℚ := by infer_instance
+instance : Sup ℚ := by infer_instance
instance : PartialOrder ℚ := by infer_instance
@@ -338,7 +338,7 @@ theorem lt_one_iff_num_lt_denom {q : ℚ} : q < 1 ↔ q.num < q.den := by simp [
lean 3 declaration is
forall (q : Rat), Eq.{1} Rat (Abs.abs.{0} Rat (Neg.toHasAbs.{0} Rat Rat.hasNeg Rat.hasSup) q) (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))) (Int.natAbs (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 q)))
but is expected to have type
- forall (q : Rat), Eq.{1} Rat (Abs.abs.{0} Rat (Neg.toHasAbs.{0} Rat Rat.instNegRat Rat.instHasSupRat) q) (Rat.divInt (Nat.cast.{0} Int Int.instNatCastInt (Int.natAbs (Rat.num q))) (Nat.cast.{0} Int Int.instNatCastInt (Rat.den q)))
+ forall (q : Rat), Eq.{1} Rat (Abs.abs.{0} Rat (Neg.toHasAbs.{0} Rat Rat.instNegRat Rat.instSupRat) q) (Rat.divInt (Nat.cast.{0} Int Int.instNatCastInt (Int.natAbs (Rat.num q))) (Nat.cast.{0} Int Int.instNatCastInt (Rat.den q)))
Case conversion may be inaccurate. Consider using '#align rat.abs_def Rat.abs_defₓ'. -/
theorem abs_def (q : ℚ) : |q| = q.num.natAbs /. q.den :=
by
mathlib commit https://github.com/leanprover-community/mathlib/commit/bd9851ca476957ea4549eb19b40e7b5ade9428cc
OfScientific
instance for NNRat
and NNReal
(#12485)
The existing RatCast.toOfScientific
instance has to be removed since it forms a non-defeq diamond (there is nothing enforcing that nnratCast
and ratCast
are defeq).
The norm_num
extension also needs some fixes, though the old design didn't make much sense anyway, as it synthesize the instances separately, thus losing important defeqs.
@@ -49,6 +49,27 @@ variable {a b c : ℚ}
@[simp] lemma mkRat_nonneg {a : ℤ} (ha : 0 ≤ a) (b : ℕ) : 0 ≤ mkRat a b := by
simpa using divInt_nonneg ha b.cast_nonneg
+theorem ofScientific_nonneg (m : ℕ) (s : Bool) (e : ℕ) :
+ 0 ≤ Rat.ofScientific m s e := by
+ rw [Rat.ofScientific]
+ cases s
+ · rw [if_neg (by decide)]
+ refine num_nonneg.mp ?_
+ rw [num_natCast]
+ exact Nat.cast_nonneg _
+ · rw [if_pos rfl, normalize_eq_mkRat]
+ exact Rat.mkRat_nonneg (Nat.cast_nonneg _) _
+
+instance _root_.NNRatCast.toOfScientific {K} [NNRatCast K] : OfScientific K where
+ ofScientific (m : ℕ) (b : Bool) (d : ℕ) :=
+ NNRat.cast ⟨Rat.ofScientific m b d, ofScientific_nonneg m b d⟩
+
+/-- Casting a scientific literal via `ℚ≥0` is the same as casting directly. -/
+@[simp, norm_cast]
+theorem _root_.NNRat.cast_ofScientific {K} [NNRatCast K] (m : ℕ) (s : Bool) (e : ℕ) :
+ (OfScientific.ofScientific m s e : ℚ≥0) = (OfScientific.ofScientific m s e : K) :=
+ rfl
+
protected lemma add_nonneg : 0 ≤ a → 0 ≤ b → 0 ≤ a + b :=
numDenCasesOn' a fun n₁ d₁ h₁ ↦ numDenCasesOn' b fun n₂ d₂ h₂ ↦ by
have d₁0 : 0 < (d₁ : ℤ) := mod_cast h₁.bot_lt
These are changes from #11997, the latest adaptation PR for nightly-2024-04-07, which can be made directly on master.
Co-authored-by: Scott Morrison <scott.morrison@gmail.com> Co-authored-by: Ruben Van de Velde <65514131+Ruben-VandeVelde@users.noreply.github.com>
@@ -53,7 +53,7 @@ protected lemma add_nonneg : 0 ≤ a → 0 ≤ b → 0 ≤ a + b :=
numDenCasesOn' a fun n₁ d₁ h₁ ↦ numDenCasesOn' b fun n₂ d₂ h₂ ↦ by
have d₁0 : 0 < (d₁ : ℤ) := mod_cast h₁.bot_lt
have d₂0 : 0 < (d₂ : ℤ) := mod_cast h₂.bot_lt
- simp only [d₁0, d₂0, h₁, h₂, mul_pos, divInt_nonneg_iff_of_pos_right, divInt_add_divInt, Ne.def,
+ simp only [d₁0, d₂0, h₁, h₂, mul_pos, divInt_nonneg_iff_of_pos_right, divInt_add_divInt, Ne,
Nat.cast_eq_zero, not_false_iff]
intro n₁0 n₂0
apply add_nonneg <;> apply mul_nonneg <;> · first |assumption|apply Int.ofNat_zero_le
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
@@ -4,8 +4,8 @@ Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Mario Carneiro
-/
import Mathlib.Init.Data.Bool.Lemmas
+import Mathlib.Data.Nat.Cast.Order
import Mathlib.Data.Rat.Defs
-import Mathlib.Data.Int.Cast.Lemmas
#align_import data.rat.order from "leanprover-community/mathlib"@"a59dad53320b73ef180174aae867addd707ef00e"
@@ -26,96 +26,71 @@ rat, rationals, field, ℚ, numerator, denominator, num, denom, order, ordering
namespace Rat
-variable (a b c : ℚ)
-
-open Rat
-
-/-- A rational number is called nonnegative if its numerator is nonnegative. -/
-protected def Nonneg (r : ℚ) : Prop :=
- 0 ≤ r.num
-#align rat.nonneg Rat.Nonneg
-
-@[simp]
-theorem divInt_nonneg (a : ℤ) {b : ℤ} (h : 0 < b) : (a /. b).Nonneg ↔ 0 ≤ a := by
- generalize ha : a /. b = x; cases' x with n₁ d₁ h₁ c₁; rw [num_den'] at ha
- simp only [Rat.Nonneg]
- have d0 := Int.ofNat_lt.2 (Nat.pos_of_ne_zero h₁)
- have := (divInt_eq_iff (ne_of_gt h) (ne_of_gt d0)).1 ha
- constructor <;> intro h₂
- · apply nonneg_of_mul_nonneg_left _ d0
- rw [this]
- exact mul_nonneg h₂ (le_of_lt h)
- · apply nonneg_of_mul_nonneg_left _ h
- rw [← this]
- exact mul_nonneg h₂ (Int.ofNat_zero_le _)
-#align rat.mk_nonneg Rat.divInt_nonneg
-
-protected theorem nonneg_add {a b} : Rat.Nonneg a → Rat.Nonneg b → Rat.Nonneg (a + b) :=
- numDenCasesOn' a fun n₁ d₁ h₁ =>
- numDenCasesOn' b fun n₂ d₂ h₂ => by
- have d₁0 : 0 < (d₁ : ℤ) := Int.natCast_pos.2 (Nat.pos_of_ne_zero h₁)
- have d₂0 : 0 < (d₂ : ℤ) := Int.natCast_pos.2 (Nat.pos_of_ne_zero h₂)
- simp only [d₁0, d₂0, h₁, h₂, mul_pos, divInt_nonneg, add_def'', Ne,
- Nat.cast_eq_zero, not_false_iff]
- intro n₁0 n₂0
- apply add_nonneg <;> apply mul_nonneg <;> · first |assumption|apply Int.ofNat_zero_le
-#align rat.nonneg_add Rat.nonneg_add
-
-protected theorem nonneg_mul {a b} : Rat.Nonneg a → Rat.Nonneg b → Rat.Nonneg (a * b) :=
+variable {a b c : ℚ}
+
+#noalign rat.nonneg
+
+@[simp] lemma num_nonneg : 0 ≤ a.num ↔ 0 ≤ a := by simp [instLERat, Rat.blt, le_iff_lt_or_eq]; tauto
+#align rat.num_nonneg_iff_zero_le Rat.num_nonneg
+
+@[simp] lemma divInt_nonneg_iff_of_pos_right {a b : ℤ} (hb : 0 < b) : 0 ≤ a /. b ↔ 0 ≤ a := by
+ cases' hab : a /. b with n d hd hnd
+ rw [mk'_eq_divInt, divInt_eq_iff hb.ne' (mod_cast hd)] at hab
+ rw [← num_nonneg, ← mul_nonneg_iff_of_pos_right hb, ← hab,
+ mul_nonneg_iff_of_pos_right (mod_cast hd.bot_lt)]
+#align rat.mk_nonneg Rat.divInt_nonneg_iff_of_pos_right
+
+@[simp] lemma divInt_nonneg {a b : ℤ} (ha : 0 ≤ a) (hb : 0 ≤ b) : 0 ≤ a /. b := by
+ obtain rfl | hb := hb.eq_or_lt
+ · simp
+ rfl
+ rwa [divInt_nonneg_iff_of_pos_right hb]
+
+@[simp] lemma mkRat_nonneg {a : ℤ} (ha : 0 ≤ a) (b : ℕ) : 0 ≤ mkRat a b := by
+ simpa using divInt_nonneg ha b.cast_nonneg
+
+protected lemma add_nonneg : 0 ≤ a → 0 ≤ b → 0 ≤ a + b :=
+ numDenCasesOn' a fun n₁ d₁ h₁ ↦ numDenCasesOn' b fun n₂ d₂ h₂ ↦ by
+ have d₁0 : 0 < (d₁ : ℤ) := mod_cast h₁.bot_lt
+ have d₂0 : 0 < (d₂ : ℤ) := mod_cast h₂.bot_lt
+ simp only [d₁0, d₂0, h₁, h₂, mul_pos, divInt_nonneg_iff_of_pos_right, divInt_add_divInt, Ne.def,
+ Nat.cast_eq_zero, not_false_iff]
+ intro n₁0 n₂0
+ apply add_nonneg <;> apply mul_nonneg <;> · first |assumption|apply Int.ofNat_zero_le
+#align rat.nonneg_add Rat.add_nonneg
+
+protected lemma mul_nonneg : 0 ≤ a → 0 ≤ b → 0 ≤ a * b :=
numDenCasesOn' a fun n₁ d₁ h₁ =>
numDenCasesOn' b fun n₂ d₂ h₂ => by
- have d₁0 : 0 < (d₁ : ℤ) := Int.natCast_pos.2 (Nat.pos_of_ne_zero h₁)
- have d₂0 : 0 < (d₂ : ℤ) := Int.natCast_pos.2 (Nat.pos_of_ne_zero h₂)
- rw [mul_def' d₁0.ne.symm d₂0.ne.symm, divInt_nonneg _ d₁0, divInt_nonneg _ d₂0,
- divInt_nonneg _ (mul_pos d₁0 d₂0)]
+ have d₁0 : 0 < (d₁ : ℤ) := mod_cast h₁.bot_lt
+ have d₂0 : 0 < (d₂ : ℤ) := mod_cast h₂.bot_lt
+ simp only [d₁0, d₂0, mul_pos, divInt_nonneg_iff_of_pos_right,
+ divInt_mul_divInt _ _ d₁0.ne' d₂0.ne']
apply mul_nonneg
-#align rat.nonneg_mul Rat.nonneg_mul
-
-protected theorem nonneg_antisymm {a} : Rat.Nonneg a → Rat.Nonneg (-a) → a = 0 :=
- numDenCasesOn' a fun n d h => by
- have d0 : 0 < (d : ℤ) := Int.natCast_pos.2 (Nat.pos_of_ne_zero h)
- rw [divInt_nonneg _ d0, neg_def, divInt_nonneg _ d0, Right.nonneg_neg_iff,
- divInt_eq_zero d0.ne.symm]
- exact fun h₁ h₂ => le_antisymm h₂ h₁
+#align rat.nonneg_mul Rat.mul_nonneg
+#align rat.mul_nonneg Rat.mul_nonneg
+
+protected lemma nonneg_antisymm : 0 ≤ a → 0 ≤ -a → a = 0 := by
+ simp_rw [← num_eq_zero, le_antisymm_iff, ← num_nonneg, num_neg_eq_neg_num, neg_nonneg]; tauto
#align rat.nonneg_antisymm Rat.nonneg_antisymm
-protected theorem nonneg_total : Rat.Nonneg a ∨ Rat.Nonneg (-a) := by
- cases' a with n; exact Or.imp_right neg_nonneg_of_nonpos (le_total 0 n)
+protected theorem nonneg_total (a : ℚ) : 0 ≤ a ∨ 0 ≤ -a := by
+ simp_rw [← num_nonneg, num_neg_eq_neg_num, neg_nonneg]; exact le_total _ _
#align rat.nonneg_total Rat.nonneg_total
-instance decidableNonneg : Decidable (Rat.Nonneg a) := by
- cases a; unfold Rat.Nonneg; infer_instance
-#align rat.decidable_nonneg Rat.decidableNonneg
-
--- Porting note: Now `Std` defines `≤` on `Rat`.
--- This is the old mathlib3 definition.
-/-- Relation `a ≤ b` on `ℚ` defined as `a ≤ b ↔ Rat.Nonneg (b - a)`. Use `a ≤ b` instead of
-`Rat.le a b`. -/
-protected def le' (a b : ℚ) := Rat.Nonneg (b - a)
-#align rat.le Rat.le'
-
-/-- Define a (dependent) function or prove `∀ r : ℚ, p r` by dealing with rational
-numbers of the form `mk' n d` with `d ≠ 0`. -/
--- Porting note (#11215): TODO move
-@[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.decidable_nonneg Rat.instDecidableLeRatInstLERat
-- Porting note (#11215): TODO can this be shortened?
-protected theorem le_iff_Nonneg (a b : ℚ) : a ≤ b ↔ Rat.Nonneg (b - a) :=
+protected theorem le_iff_sub_nonneg (a b : ℚ) : a ≤ b ↔ 0 ≤ b - a :=
numDenCasesOn'' a fun na da ha hared =>
numDenCasesOn'' b fun nb db hb hbred => by
change Rat.blt _ _ = false ↔ _
unfold Rat.blt
simp only [Bool.and_eq_true, decide_eq_true_eq, Bool.ite_eq_false_distrib,
- decide_eq_false_iff_not, not_lt, ite_eq_left_iff, not_and, not_le]
+ decide_eq_false_iff_not, not_lt, ite_eq_left_iff, not_and, not_le, ← num_nonneg]
split_ifs with h h'
· rw [Rat.sub_def]
- simp only [Rat.Nonneg, false_iff, not_le]
+ simp only [false_iff, not_le]
simp only [normalize_eq]
apply Int.ediv_neg'
· rw [sub_neg]
@@ -127,8 +102,8 @@ protected theorem le_iff_Nonneg (a b : ℚ) : a ≤ b ↔ Rat.Nonneg (b - a) :=
apply Nat.gcd_pos_of_pos_right
apply mul_pos <;> rwa [pos_iff_ne_zero]
· simp only [divInt_ofNat, ← zero_iff_num_zero, mkRat_eq_zero hb] at h'
- simp [h', Rat.Nonneg]
- · simp only [Rat.Nonneg, sub_def, normalize_eq]
+ simp [h']
+ · simp only [Rat.sub_def, normalize_eq]
refine ⟨fun H => ?_, fun H _ => ?_⟩
· refine Int.ediv_nonneg ?_ (Nat.cast_nonneg _)
rw [sub_nonneg]
@@ -148,55 +123,39 @@ protected theorem le_iff_Nonneg (a b : ℚ) : a ≤ b ↔ Rat.Nonneg (b - a) :=
apply Nat.gcd_pos_of_pos_right
apply mul_pos <;> rwa [pos_iff_ne_zero]
-protected theorem le_def {a b c d : ℤ} (b0 : 0 < b) (d0 : 0 < d) :
+protected lemma divInt_le_divInt {a b c d : ℤ} (b0 : 0 < b) (d0 : 0 < d) :
a /. b ≤ c /. d ↔ a * d ≤ c * b := by
- rw [Rat.le_iff_Nonneg]
- show Rat.Nonneg _ ↔ _
- rw [← sub_nonneg]
+ rw [Rat.le_iff_sub_nonneg, ← sub_nonneg (α := ℤ)]
simp [sub_eq_add_neg, ne_of_gt b0, ne_of_gt d0, mul_pos d0 b0]
-#align rat.le_def Rat.le_def
-
-protected theorem le_refl : a ≤ a := by
- rw [Rat.le_iff_Nonneg]
- show Rat.Nonneg (a - a)
- rw [sub_self]
- exact le_refl (0 : ℤ)
-#align rat.le_refl Rat.le_refl
-
-protected theorem le_total : a ≤ b ∨ b ≤ a := by
- have := Rat.nonneg_total (b - a)
- rw [Rat.le_iff_Nonneg, Rat.le_iff_Nonneg]
- rwa [neg_sub] at this
-#align rat.le_total Rat.le_total
+#align rat.le_def Rat.divInt_le_divInt
-protected theorem le_antisymm {a b : ℚ} (hab : a ≤ b) (hba : b ≤ a) : a = b := by
- rw [Rat.le_iff_Nonneg] at hab hba
- rw [sub_eq_add_neg] at hba
- rw [← neg_sub, sub_eq_add_neg] at hab
- have := eq_neg_of_add_eq_zero_left (Rat.nonneg_antisymm hba hab)
- rwa [neg_neg] at this
-#align rat.le_antisymm Rat.le_antisymm
-
-protected theorem le_trans {a b c : ℚ} (hab : a ≤ b) (hbc : b ≤ c) : a ≤ c := by
- rw [Rat.le_iff_Nonneg] at hab hbc
- have : Rat.Nonneg (b - a + (c - b)) := Rat.nonneg_add hab hbc
- simp_rw [sub_eq_add_neg, add_left_comm (b + -a) c (-b), add_comm (b + -a) (-b),
- add_left_comm (-b) b (-a), add_comm (-b) (-a), add_neg_cancel_comm_assoc,
- ← sub_eq_add_neg] at this
- rw [Rat.le_iff_Nonneg]
- exact this
-#align rat.le_trans Rat.le_trans
+protected lemma le_total : a ≤ b ∨ b ≤ a := by
+ simpa only [← Rat.le_iff_sub_nonneg, neg_sub] using Rat.nonneg_total (b - a)
+#align rat.le_total Rat.le_total
protected theorem not_le {a b : ℚ} : ¬a ≤ b ↔ b < a := (Bool.not_eq_false _).to_iff
instance linearOrder : LinearOrder ℚ where
- le_refl := Rat.le_refl
- le_trans := @Rat.le_trans
- le_antisymm := @Rat.le_antisymm
- le_total := Rat.le_total
+ le_refl a := by rw [Rat.le_iff_sub_nonneg, ← num_nonneg]; simp
+ le_trans a b c hab hbc := by
+ rw [Rat.le_iff_sub_nonneg] at hab hbc
+ have := Rat.add_nonneg hab hbc
+ simp_rw [sub_eq_add_neg, add_left_comm (b + -a) c (-b), add_comm (b + -a) (-b),
+ add_left_comm (-b) b (-a), add_comm (-b) (-a), add_neg_cancel_comm_assoc,
+ ← sub_eq_add_neg] at this
+ rwa [Rat.le_iff_sub_nonneg]
+ le_antisymm a b hab hba := by
+ rw [Rat.le_iff_sub_nonneg] at hab hba
+ rw [sub_eq_add_neg] at hba
+ rw [← neg_sub, sub_eq_add_neg] at hab
+ have := eq_neg_of_add_eq_zero_left (Rat.nonneg_antisymm hba hab)
+ rwa [neg_neg] at this
+ le_total _ _ := Rat.le_total
decidableLE _ _ := by infer_instance
- lt_iff_le_not_le _ _ := by
- rw [← Rat.not_le, and_iff_right_of_imp (Rat.le_total _ _).resolve_left]
+ lt_iff_le_not_le _ _ := by rw [← Rat.not_le, and_iff_right_of_imp Rat.le_total.resolve_left]
+#align rat.le_refl le_refl
+#align rat.le_antisymm le_antisymm
+#align rat.le_trans le_trans
-- Extra instances to short-circuit type class resolution
instance : LT ℚ := by infer_instance
@@ -217,14 +176,14 @@ instance : PartialOrder ℚ := by infer_instance
instance : Preorder ℚ := by infer_instance
-protected theorem le_def' {p q : ℚ} : p ≤ q ↔ p.num * q.den ≤ q.num * p.den := by
- rw [← @num_den q, ← @num_den p]
- conv_rhs => simp only [num_den]
- exact Rat.le_def (mod_cast p.pos) (mod_cast q.pos)
-#align rat.le_def' Rat.le_def'
+protected lemma le_def {p q : ℚ} : p ≤ q ↔ p.num * q.den ≤ q.num * p.den := by
+ rw [← num_divInt_den q, ← num_divInt_den p]
+ conv_rhs => simp only [num_divInt_den]
+ exact Rat.divInt_le_divInt (mod_cast p.pos) (mod_cast q.pos)
+#align rat.le_def' Rat.le_def
protected theorem lt_def {p q : ℚ} : p < q ↔ p.num * q.den < q.num * p.den := by
- rw [lt_iff_le_and_ne, Rat.le_def']
+ rw [lt_iff_le_and_ne, Rat.le_def]
suffices p ≠ q ↔ p.num * q.den ≠ q.num * p.den by
constructor <;> intro h
· exact lt_iff_le_and_ne.mpr ⟨h.left, this.mp h.right⟩
@@ -233,24 +192,12 @@ protected theorem lt_def {p q : ℚ} : p < q ↔ p.num * q.den < q.num * p.den :
exact not_iff_not.mpr eq_iff_mul_eq_mul
#align rat.lt_def Rat.lt_def
-theorem nonneg_iff_zero_le {a} : Rat.Nonneg a ↔ 0 ≤ a := by
- rw [Rat.le_iff_Nonneg]
- show Rat.Nonneg a ↔ Rat.Nonneg (a - 0)
- simp
-#align rat.nonneg_iff_zero_le Rat.nonneg_iff_zero_le
-
-@[simp] lemma num_nonneg : ∀ {a : ℚ}, 0 ≤ a.num ↔ 0 ≤ a
- | ⟨n, d, h, c⟩ => @nonneg_iff_zero_le ⟨n, d, h, c⟩
-#align rat.num_nonneg_iff_zero_le Rat.num_nonneg
+#noalign rat.nonneg_iff_zero_le
protected theorem add_le_add_left {a b c : ℚ} : c + a ≤ c + b ↔ a ≤ b := by
- rw [Rat.le_iff_Nonneg, add_sub_add_left_eq_sub, Rat.le_iff_Nonneg]
+ rw [Rat.le_iff_sub_nonneg, add_sub_add_left_eq_sub, ← Rat.le_iff_sub_nonneg]
#align rat.add_le_add_left Rat.add_le_add_left
-protected theorem mul_nonneg {a b : ℚ} (ha : 0 ≤ a) (hb : 0 ≤ b) : 0 ≤ a * b := by
- rw [← nonneg_iff_zero_le] at ha hb ⊢; exact Rat.nonneg_mul ha hb
-#align rat.mul_nonneg Rat.mul_nonneg
-
instance instLinearOrderedCommRing : LinearOrderedCommRing ℚ where
__ := Rat.linearOrder
__ := Rat.commRing
@@ -287,9 +234,9 @@ theorem div_lt_div_iff_mul_lt_mul {a b c d : ℤ} (b_pos : 0 < b) (d_pos : 0 < d
(a : ℚ) / b < c / d ↔ a * d < c * b := by
simp only [lt_iff_le_not_le]
apply and_congr
- · simp [div_num_den, Rat.le_def b_pos d_pos]
+ · simp [div_def', Rat.divInt_le_divInt b_pos d_pos]
· apply not_congr
- simp [div_num_den, Rat.le_def d_pos b_pos]
+ simp [div_def', Rat.divInt_le_divInt d_pos b_pos]
#align rat.div_lt_div_iff_mul_lt_mul Rat.div_lt_div_iff_mul_lt_mul
theorem lt_one_iff_num_lt_denom {q : ℚ} : q < 1 ↔ q.num < q.den := by simp [Rat.lt_def]
@@ -298,13 +245,13 @@ theorem lt_one_iff_num_lt_denom {q : ℚ} : q < 1 ↔ q.num < q.den := by simp [
theorem abs_def (q : ℚ) : |q| = q.num.natAbs /. q.den := by
rcases le_total q 0 with hq | hq
· rw [abs_of_nonpos hq]
- rw [← @num_den q, ← divInt_zero_one, Rat.le_def (Int.natCast_pos.2 q.pos) zero_lt_one, mul_one,
- zero_mul] at hq
- rw [Int.ofNat_natAbs_of_nonpos hq, ← neg_def, num_den]
+ rw [← num_divInt_den q, ← zero_divInt, Rat.divInt_le_divInt (mod_cast q.pos) zero_lt_one,
+ mul_one, zero_mul] at hq
+ rw [Int.ofNat_natAbs_of_nonpos hq, ← neg_def]
· rw [abs_of_nonneg hq]
- rw [← @num_den q, ← divInt_zero_one, Rat.le_def zero_lt_one (Int.natCast_pos.2 q.pos), mul_one,
- zero_mul] at hq
- rw [Int.natAbs_of_nonneg hq, num_den]
+ rw [← num_divInt_den q, ← zero_divInt, Rat.divInt_le_divInt zero_lt_one (mod_cast q.pos),
+ mul_one, zero_mul] at hq
+ rw [Int.natAbs_of_nonneg hq, num_divInt_den]
#align rat.abs_def Rat.abs_def
end Rat
@@ -53,8 +53,8 @@ theorem divInt_nonneg (a : ℤ) {b : ℤ} (h : 0 < b) : (a /. b).Nonneg ↔ 0
protected theorem nonneg_add {a b} : Rat.Nonneg a → Rat.Nonneg b → Rat.Nonneg (a + b) :=
numDenCasesOn' a fun n₁ d₁ h₁ =>
numDenCasesOn' b fun n₂ d₂ h₂ => by
- have d₁0 : 0 < (d₁ : ℤ) := Int.coe_nat_pos.2 (Nat.pos_of_ne_zero h₁)
- have d₂0 : 0 < (d₂ : ℤ) := Int.coe_nat_pos.2 (Nat.pos_of_ne_zero h₂)
+ have d₁0 : 0 < (d₁ : ℤ) := Int.natCast_pos.2 (Nat.pos_of_ne_zero h₁)
+ have d₂0 : 0 < (d₂ : ℤ) := Int.natCast_pos.2 (Nat.pos_of_ne_zero h₂)
simp only [d₁0, d₂0, h₁, h₂, mul_pos, divInt_nonneg, add_def'', Ne,
Nat.cast_eq_zero, not_false_iff]
intro n₁0 n₂0
@@ -64,8 +64,8 @@ protected theorem nonneg_add {a b} : Rat.Nonneg a → Rat.Nonneg b → Rat.Nonne
protected theorem nonneg_mul {a b} : Rat.Nonneg a → Rat.Nonneg b → Rat.Nonneg (a * b) :=
numDenCasesOn' a fun n₁ d₁ h₁ =>
numDenCasesOn' b fun n₂ d₂ h₂ => by
- have d₁0 : 0 < (d₁ : ℤ) := Int.coe_nat_pos.2 (Nat.pos_of_ne_zero h₁)
- have d₂0 : 0 < (d₂ : ℤ) := Int.coe_nat_pos.2 (Nat.pos_of_ne_zero h₂)
+ have d₁0 : 0 < (d₁ : ℤ) := Int.natCast_pos.2 (Nat.pos_of_ne_zero h₁)
+ have d₂0 : 0 < (d₂ : ℤ) := Int.natCast_pos.2 (Nat.pos_of_ne_zero h₂)
rw [mul_def' d₁0.ne.symm d₂0.ne.symm, divInt_nonneg _ d₁0, divInt_nonneg _ d₂0,
divInt_nonneg _ (mul_pos d₁0 d₂0)]
apply mul_nonneg
@@ -73,7 +73,7 @@ protected theorem nonneg_mul {a b} : Rat.Nonneg a → Rat.Nonneg b → Rat.Nonne
protected theorem nonneg_antisymm {a} : Rat.Nonneg a → Rat.Nonneg (-a) → a = 0 :=
numDenCasesOn' a fun n d h => by
- have d0 : 0 < (d : ℤ) := Int.coe_nat_pos.2 (Nat.pos_of_ne_zero h)
+ have d0 : 0 < (d : ℤ) := Int.natCast_pos.2 (Nat.pos_of_ne_zero h)
rw [divInt_nonneg _ d0, neg_def, divInt_nonneg _ d0, Right.nonneg_neg_iff,
divInt_eq_zero d0.ne.symm]
exact fun h₁ h₂ => le_antisymm h₂ h₁
@@ -298,11 +298,11 @@ theorem lt_one_iff_num_lt_denom {q : ℚ} : q < 1 ↔ q.num < q.den := by simp [
theorem abs_def (q : ℚ) : |q| = q.num.natAbs /. q.den := by
rcases le_total q 0 with hq | hq
· rw [abs_of_nonpos hq]
- rw [← @num_den q, ← divInt_zero_one, Rat.le_def (Int.coe_nat_pos.2 q.pos) zero_lt_one, mul_one,
+ rw [← @num_den q, ← divInt_zero_one, Rat.le_def (Int.natCast_pos.2 q.pos) zero_lt_one, mul_one,
zero_mul] at hq
rw [Int.ofNat_natAbs_of_nonpos hq, ← neg_def, num_den]
· rw [abs_of_nonneg hq]
- rw [← @num_den q, ← divInt_zero_one, Rat.le_def zero_lt_one (Int.coe_nat_pos.2 q.pos), mul_one,
+ rw [← @num_den q, ← divInt_zero_one, Rat.le_def zero_lt_one (Int.natCast_pos.2 q.pos), mul_one,
zero_mul] at hq
rw [Int.natAbs_of_nonneg hq, num_den]
#align rat.abs_def Rat.abs_def
@@ -55,7 +55,7 @@ protected theorem nonneg_add {a b} : Rat.Nonneg a → Rat.Nonneg b → Rat.Nonne
numDenCasesOn' b fun n₂ d₂ h₂ => by
have d₁0 : 0 < (d₁ : ℤ) := Int.coe_nat_pos.2 (Nat.pos_of_ne_zero h₁)
have d₂0 : 0 < (d₂ : ℤ) := Int.coe_nat_pos.2 (Nat.pos_of_ne_zero h₂)
- simp only [d₁0, d₂0, h₁, h₂, mul_pos, divInt_nonneg, add_def'', Ne.def,
+ simp only [d₁0, d₂0, h₁, h₂, mul_pos, divInt_nonneg, add_def'', Ne,
Nat.cast_eq_zero, not_false_iff]
intro n₁0 n₂0
apply add_nonneg <;> apply mul_nonneg <;> · first |assumption|apply Int.ofNat_zero_le
LinearOrderedCommGroupWithZero
(#11716)
Reconstitute the file Algebra.Order.Monoid.WithZero
from three files:
Algebra.Order.Monoid.WithZero.Defs
Algebra.Order.Monoid.WithZero.Basic
Algebra.Order.WithZero
Avoid importing it in many files. Most uses were just to get le_zero_iff
to work on Nat
.
Before
After
@@ -316,6 +316,3 @@ assert_not_exists Fintype
assert_not_exists Set.Icc
assert_not_exists GaloisConnection
-
--- These are less significant, but should not be relaxed until at least after port to Lean 4.
-assert_not_exists LinearOrderedCommGroupWithZero
@@ -128,7 +128,7 @@ protected theorem le_iff_Nonneg (a b : ℚ) : a ≤ b ↔ Rat.Nonneg (b - a) :=
apply mul_pos <;> rwa [pos_iff_ne_zero]
· simp only [divInt_ofNat, ← zero_iff_num_zero, mkRat_eq_zero hb] at h'
simp [h', Rat.Nonneg]
- · simp [Rat.Nonneg, Rat.sub_def, normalize_eq]
+ · simp only [Rat.Nonneg, sub_def, normalize_eq]
refine ⟨fun H => ?_, fun H _ => ?_⟩
· refine Int.ediv_nonneg ?_ (Nat.cast_nonneg _)
rw [sub_nonneg]
@@ -96,7 +96,7 @@ protected def le' (a b : ℚ) := Rat.Nonneg (b - a)
/-- Define a (dependent) function or prove `∀ r : ℚ, p r` by dealing with rational
numbers of the form `mk' n d` with `d ≠ 0`. -/
--- Porting note: TODO move
+-- Porting note (#11215): TODO move
@[elab_as_elim]
def numDenCasesOn''.{u} {C : ℚ → Sort u} (a : ℚ)
(H : ∀ (n : ℤ) (d : ℕ) (nz red), C (mk' n d nz red)) :
@@ -105,7 +105,7 @@ def numDenCasesOn''.{u} {C : ℚ → Sort u} (a : ℚ)
rw [← mk_eq_divInt _ _ h.ne' h']
exact H n d h.ne' _
--- Porting note: TODO can this be shortened?
+-- Porting note (#11215): TODO can this be shortened?
protected theorem le_iff_Nonneg (a b : ℚ) : a ≤ b ↔ Rat.Nonneg (b - a) :=
numDenCasesOn'' a fun na da ha hared =>
numDenCasesOn'' b fun nb db hb hbred => by
ℕ
, ℤ
and ℚ≥0
are star-ordered rings (#10633)
Also golf the existing instance for ℚ
and rename Rat.num_nonneg_iff_zero_le
to Rat.num_nonneg
, Rat.num_pos_iff_pos
to Rat.num_pos
.
From LeanAPAP
@@ -239,7 +239,7 @@ theorem nonneg_iff_zero_le {a} : Rat.Nonneg a ↔ 0 ≤ a := by
simp
#align rat.nonneg_iff_zero_le Rat.nonneg_iff_zero_le
-theorem num_nonneg : ∀ {a : ℚ}, 0 ≤ a.num ↔ 0 ≤ a
+@[simp] lemma num_nonneg : ∀ {a : ℚ}, 0 ≤ a.num ↔ 0 ≤ a
| ⟨n, d, h, c⟩ => @nonneg_iff_zero_le ⟨n, d, h, c⟩
#align rat.num_nonneg_iff_zero_le Rat.num_nonneg
@@ -275,10 +275,13 @@ instance : OrderedCancelAddCommMonoid ℚ := by infer_instance
instance : OrderedAddCommMonoid ℚ := by infer_instance
-theorem num_pos {a : ℚ} : 0 < a.num ↔ 0 < a :=
- lt_iff_lt_of_le_iff_le <| by
- simpa [(by cases a; rfl : (-a).num = -a.num)] using @num_nonneg (-a)
+@[simp] lemma num_nonpos {a : ℚ} : a.num ≤ 0 ↔ a ≤ 0 := by simpa using @num_nonneg (-a)
+@[simp] lemma num_pos {a : ℚ} : 0 < a.num ↔ 0 < a := lt_iff_lt_of_le_iff_le num_nonpos
#align rat.num_pos_iff_pos Rat.num_pos
+@[simp] lemma num_neg {a : ℚ} : a.num < 0 ↔ a < 0 := lt_iff_lt_of_le_iff_le num_nonneg
+
+@[deprecated] alias num_nonneg_iff_zero_le := num_nonneg -- 2024-02-16
+@[deprecated] alias num_pos_iff_pos := num_pos -- 2024-02-16
theorem div_lt_div_iff_mul_lt_mul {a b c d : ℤ} (b_pos : 0 < b) (d_pos : 0 < d) :
(a : ℚ) / b < c / d ↔ a * d < c * b := by
positivity
extension for Rat.num
, Rat.den
(#10218)
and rename num_nonneg_iff_zero_le
to num_nonneg
, num_pos_iff_pos
to num_pos
From LeanAPAP
@@ -239,9 +239,9 @@ theorem nonneg_iff_zero_le {a} : Rat.Nonneg a ↔ 0 ≤ a := by
simp
#align rat.nonneg_iff_zero_le Rat.nonneg_iff_zero_le
-theorem num_nonneg_iff_zero_le : ∀ {a : ℚ}, 0 ≤ a.num ↔ 0 ≤ a
+theorem num_nonneg : ∀ {a : ℚ}, 0 ≤ a.num ↔ 0 ≤ a
| ⟨n, d, h, c⟩ => @nonneg_iff_zero_le ⟨n, d, h, c⟩
-#align rat.num_nonneg_iff_zero_le Rat.num_nonneg_iff_zero_le
+#align rat.num_nonneg_iff_zero_le Rat.num_nonneg
protected theorem add_le_add_left {a b c : ℚ} : c + a ≤ c + b ↔ a ≤ b := by
rw [Rat.le_iff_Nonneg, add_sub_add_left_eq_sub, Rat.le_iff_Nonneg]
@@ -275,10 +275,10 @@ instance : OrderedCancelAddCommMonoid ℚ := by infer_instance
instance : OrderedAddCommMonoid ℚ := by infer_instance
-theorem num_pos_iff_pos {a : ℚ} : 0 < a.num ↔ 0 < a :=
+theorem num_pos {a : ℚ} : 0 < a.num ↔ 0 < a :=
lt_iff_lt_of_le_iff_le <| by
- simpa [(by cases a; rfl : (-a).num = -a.num)] using @num_nonneg_iff_zero_le (-a)
-#align rat.num_pos_iff_pos Rat.num_pos_iff_pos
+ simpa [(by cases a; rfl : (-a).num = -a.num)] using @num_nonneg (-a)
+#align rat.num_pos_iff_pos Rat.num_pos
theorem div_lt_div_iff_mul_lt_mul {a b c d : ℤ} (b_pos : 0 < b) (d_pos : 0 < d) :
(a : ℚ) / b < c / d ↔ a * d < c * b := by
The goal is to separate the field material on Rat
/NNRat
from everything before to make way for NNRat.cast
. We achieve this by
Data.Rat.NNRat
into
Data.NNRat.Defs
for the foundationl stuff that will be needed in the definition of Field
Data.NNRat.Lemmas
for the field and big operators materialData.Rat.Order
to Data.Rat.Basic
rfl
rather than coeHom.some_now_unavailable_lemma
Data.Rat.NNRat.BigOperators
to Data.NNRat.BigOperators
@@ -4,8 +4,7 @@ Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Mario Carneiro
-/
import Mathlib.Init.Data.Bool.Lemmas
-import Mathlib.Algebra.Order.Field.Defs
-import Mathlib.Data.Rat.Basic
+import Mathlib.Data.Rat.Defs
import Mathlib.Data.Int.Cast.Lemmas
#align_import data.rat.order from "leanprover-community/mathlib"@"a59dad53320b73ef180174aae867addd707ef00e"
@@ -13,15 +12,15 @@ import Mathlib.Data.Int.Cast.Lemmas
/-!
# Order for Rational Numbers
-## Summary
-
-We define the order on `ℚ`, prove that `ℚ` is a discrete, linearly ordered field, and define
-functions such as `abs` and `sqrt` that depend on this order.
+This file constructs the order on `ℚ` and proves that `ℚ` is a discrete, linearly ordered
+commutative ring.
+`ℚ` is in fact a linearly ordered field, but this fact is located in `Data.Rat.Field` instead of
+here because we need the order on `ℚ` to define `ℚ≥0`, which we itself need to define `Field`.
## Tags
-rat, rationals, field, ℚ, numerator, denominator, num, denom, order, ordering, sqrt, abs
+rat, rationals, field, ℚ, numerator, denominator, num, denom, order, ordering
-/
@@ -252,17 +251,14 @@ protected theorem mul_nonneg {a b : ℚ} (ha : 0 ≤ a) (hb : 0 ≤ b) : 0 ≤ a
rw [← nonneg_iff_zero_le] at ha hb ⊢; exact Rat.nonneg_mul ha hb
#align rat.mul_nonneg Rat.mul_nonneg
-instance : LinearOrderedField ℚ :=
- { Rat.field, Rat.linearOrder, Rat.semiring with
- zero_le_one := by decide
- add_le_add_left := fun a b ab c => Rat.add_le_add_left.2 ab
- mul_pos := fun a b ha hb =>
- lt_of_le_of_ne (Rat.mul_nonneg (le_of_lt ha) (le_of_lt hb))
- (mul_ne_zero (ne_of_lt ha).symm (ne_of_lt hb).symm).symm }
+instance instLinearOrderedCommRing : LinearOrderedCommRing ℚ where
+ __ := Rat.linearOrder
+ __ := Rat.commRing
+ zero_le_one := by decide
+ add_le_add_left := fun a b ab c => Rat.add_le_add_left.2 ab
+ mul_pos a b ha hb := (Rat.mul_nonneg ha.le hb.le).lt_of_ne' (mul_ne_zero ha.ne' hb.ne')
-- Extra instances to short-circuit type class resolution
-instance : LinearOrderedCommRing ℚ := by infer_instance
-
instance : LinearOrderedRing ℚ := by infer_instance
instance : OrderedRing ℚ := by infer_instance
@@ -3,6 +3,7 @@ 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.Init.Data.Bool.Lemmas
import Mathlib.Algebra.Order.Field.Defs
import Mathlib.Data.Rat.Basic
import Mathlib.Data.Int.Cast.Lemmas
cases'
(#9171)
I literally went through and regex'd some uses of cases'
, replacing them with rcases
; this is meant to be a low effort PR as I hope that tools can do this in the future.
rcases
is an easier replacement than cases
, though with better tools we could in future do a second pass converting simple rcases
added here (and existing ones) to cases
.
@@ -296,7 +296,7 @@ theorem lt_one_iff_num_lt_denom {q : ℚ} : q < 1 ↔ q.num < q.den := by simp [
#align rat.lt_one_iff_num_lt_denom Rat.lt_one_iff_num_lt_denom
theorem abs_def (q : ℚ) : |q| = q.num.natAbs /. q.den := by
- cases' le_total q 0 with hq hq
+ rcases le_total q 0 with hq | hq
· rw [abs_of_nonpos hq]
rw [← @num_den q, ← divInt_zero_one, Rat.le_def (Int.coe_nat_pos.2 q.pos) zero_lt_one, mul_one,
zero_mul] at hq
@@ -102,7 +102,7 @@ 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']
+ rw [← mk_eq_divInt _ _ h.ne' h']
exact H n d h.ne' _
-- Porting note: TODO can this be shortened?
@@ -126,7 +126,7 @@ protected theorem le_iff_Nonneg (a b : ℚ) : a ≤ b ↔ Rat.Nonneg (b - a) :=
· simp only [Nat.cast_pos]
apply Nat.gcd_pos_of_pos_right
apply mul_pos <;> rwa [pos_iff_ne_zero]
- · simp only [divInt_ofNat, ←zero_iff_num_zero, mkRat_eq_zero hb] at h'
+ · simp only [divInt_ofNat, ← zero_iff_num_zero, mkRat_eq_zero hb] at h'
simp [h', Rat.Nonneg]
· simp [Rat.Nonneg, Rat.sub_def, normalize_eq]
refine ⟨fun H => ?_, fun H _ => ?_⟩
@@ -141,7 +141,7 @@ protected theorem le_iff_Nonneg (a b : ℚ) : a ≤ b ↔ Rat.Nonneg (b - a) :=
· apply le_trans <| mul_nonpos_of_nonpos_of_nonneg ha (Nat.cast_nonneg _)
exact mul_nonneg hb.le (Nat.cast_nonneg _)
· exact H (fun _ => ha)
- · rw [←sub_nonneg]
+ · rw [← sub_nonneg]
contrapose! H
apply Int.ediv_neg' H
simp only [Nat.cast_pos]
@@ -172,7 +172,7 @@ protected theorem le_total : a ≤ b ∨ b ≤ a := by
protected theorem le_antisymm {a b : ℚ} (hab : a ≤ b) (hba : b ≤ a) : a = b := by
rw [Rat.le_iff_Nonneg] at hab hba
rw [sub_eq_add_neg] at hba
- rw [←neg_sub, sub_eq_add_neg] at hab
+ rw [← neg_sub, sub_eq_add_neg] at hab
have := eq_neg_of_add_eq_zero_left (Rat.nonneg_antisymm hba hab)
rwa [neg_neg] at this
#align rat.le_antisymm Rat.le_antisymm
exact_mod_cast
tactic with mod_cast
elaborator where possible (#8404)
We still have the exact_mod_cast
tactic, used in a few places, which somehow (?) works a little bit harder to prevent the expected type influencing the elaboration of the term. I would like to get to the bottom of this, and it will be easier once the only usages of exact_mod_cast
are the ones that don't work using the term elaborator by itself.
Co-authored-by: Scott Morrison <scott.morrison@gmail.com>
@@ -220,7 +220,7 @@ instance : Preorder ℚ := by infer_instance
protected theorem le_def' {p q : ℚ} : p ≤ q ↔ p.num * q.den ≤ q.num * p.den := by
rw [← @num_den q, ← @num_den p]
conv_rhs => simp only [num_den]
- exact Rat.le_def (by exact_mod_cast p.pos) (by exact_mod_cast q.pos)
+ exact Rat.le_def (mod_cast p.pos) (mod_cast q.pos)
#align rat.le_def' Rat.le_def'
protected theorem lt_def {p q : ℚ} : p < q ↔ p.num * q.den < q.num * p.den := by
Removes nonterminal simps on lines looking like simp [...]
@@ -38,7 +38,7 @@ protected def Nonneg (r : ℚ) : Prop :=
@[simp]
theorem divInt_nonneg (a : ℤ) {b : ℤ} (h : 0 < b) : (a /. b).Nonneg ↔ 0 ≤ a := by
generalize ha : a /. b = x; cases' x with n₁ d₁ h₁ c₁; rw [num_den'] at ha
- simp [Rat.Nonneg]
+ simp only [Rat.Nonneg]
have d0 := Int.ofNat_lt.2 (Nat.pos_of_ne_zero h₁)
have := (divInt_eq_iff (ne_of_gt h) (ne_of_gt d0)).1 ha
constructor <;> intro h₂
@@ -111,11 +111,12 @@ protected theorem le_iff_Nonneg (a b : ℚ) : a ≤ b ↔ Rat.Nonneg (b - a) :=
numDenCasesOn'' b fun nb db hb hbred => by
change Rat.blt _ _ = false ↔ _
unfold Rat.blt
- simp [-divInt_ofNat, mkRat_eq]
+ simp only [Bool.and_eq_true, decide_eq_true_eq, Bool.ite_eq_false_distrib,
+ decide_eq_false_iff_not, not_lt, ite_eq_left_iff, not_and, not_le]
split_ifs with h h'
· rw [Rat.sub_def]
- simp [Rat.Nonneg]
- simp [normalize_eq]
+ simp only [Rat.Nonneg, false_iff, not_le]
+ simp only [normalize_eq]
apply Int.ediv_neg'
· rw [sub_neg]
apply lt_of_lt_of_le
@@ -2,16 +2,13 @@
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.order
-! leanprover-community/mathlib commit a59dad53320b73ef180174aae867addd707ef00e
-! Please do not edit these lines, except to modify the commit id
-! if you have ported upstream changes.
-/
import Mathlib.Algebra.Order.Field.Defs
import Mathlib.Data.Rat.Basic
import Mathlib.Data.Int.Cast.Lemmas
+#align_import data.rat.order from "leanprover-community/mathlib"@"a59dad53320b73ef180174aae867addd707ef00e"
+
/-!
# Order for Rational Numbers
at
and goals (#5387)
Changes are of the form
some_tactic at h⊢
-> some_tactic at h ⊢
some_tactic at h
-> some_tactic at h
@@ -250,7 +250,7 @@ protected theorem add_le_add_left {a b c : ℚ} : c + a ≤ c + b ↔ a ≤ b :=
#align rat.add_le_add_left Rat.add_le_add_left
protected theorem mul_nonneg {a b : ℚ} (ha : 0 ≤ a) (hb : 0 ≤ b) : 0 ≤ a * b := by
- rw [← nonneg_iff_zero_le] at ha hb⊢; exact Rat.nonneg_mul ha hb
+ rw [← nonneg_iff_zero_le] at ha hb ⊢; exact Rat.nonneg_mul ha hb
#align rat.mul_nonneg Rat.mul_nonneg
instance : LinearOrderedField ℚ :=
@@ -311,15 +311,13 @@ theorem abs_def (q : ℚ) : |q| = q.num.natAbs /. q.den := by
end Rat
--- Porting note: `assert_not_exists` not yet implemented.
-
-- We make some assertions here about declarations that do not need to be in the import dependencies
-- for this file, but have been in the past.
--- assert_not_exists fintype
+assert_not_exists Fintype
--- assert_not_exists set.Icc
+assert_not_exists Set.Icc
--- assert_not_exists galois_connection
+assert_not_exists GaloisConnection
-- These are less significant, but should not be relaxed until at least after port to Lean 4.
--- assert_not_exists LinearOrderedCommGroupWithZero
+assert_not_exists LinearOrderedCommGroupWithZero
LinearOrder
decidable fields (#4006)
This renames
decidable_eq
to decidableEq
decidable_lt
to decidableLT
decidable_le
to decidableLE
decidableLT_of_decidableLE
to decidableLTOfDecidableLE
decidableEq_of_decidableLE
to decidableEqOfDecidableLE
These fields are data not proofs, so they should be lowerCamelCased
.
@@ -196,7 +196,7 @@ instance linearOrder : LinearOrder ℚ where
le_trans := @Rat.le_trans
le_antisymm := @Rat.le_antisymm
le_total := Rat.le_total
- decidable_le _ _ := by infer_instance
+ decidableLE _ _ := by infer_instance
lt_iff_le_not_le _ _ := by
rw [← Rat.not_le, and_iff_right_of_imp (Rat.le_total _ _).resolve_left]
@@ -211,9 +211,9 @@ instance : SemilatticeInf ℚ := by infer_instance
instance : SemilatticeSup ℚ := by infer_instance
-instance : HasInf ℚ := by infer_instance
+instance : Inf ℚ := by infer_instance
-instance : HasSup ℚ := by infer_instance
+instance : Sup ℚ := by infer_instance
instance : PartialOrder ℚ := by infer_instance
Co-authored-by: Scott Morrison <scott.morrison@gmail.com> Co-authored-by: Patrick Massot <patrickmassot@free.fr> Co-authored-by: Ruben Van de Velde <65514131+Ruben-VandeVelde@users.noreply.github.com> Co-authored-by: ChrisHughes24 <chrishughes24@gmail.com> Co-authored-by: Arien Malec <arien.malec@gmail.com>
@@ -1,39 +1,325 @@
/-
-Copyright (c) 2022 Scott Morrison. All rights reserved.
+Copyright (c) 2019 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
-Authors: Scott Morrison
+Authors: Johannes Hölzl, Mario Carneiro
+
+! This file was ported from Lean 3 source module data.rat.order
+! leanprover-community/mathlib commit a59dad53320b73ef180174aae867addd707ef00e
+! Please do not edit these lines, except to modify the commit id
+! if you have ported upstream changes.
-/
-import Mathlib.Data.Rat.Defs
-import Mathlib.Algebra.Order.Ring.Defs
+import Mathlib.Algebra.Order.Field.Defs
+import Mathlib.Data.Rat.Basic
+import Mathlib.Data.Int.Cast.Lemmas
/-!
-# Stub port for `linarith`.
+# Order for Rational Numbers
+
+## Summary
+
+We define the order on `ℚ`, prove that `ℚ` is a discrete, linearly ordered field, and define
+functions such as `abs` and `sqrt` that depend on this order.
+
+
+## Tags
+
+rat, rationals, field, ℚ, numerator, denominator, num, denom, order, ordering, sqrt, abs
-/
-set_option warningAsError false
-
-instance : Preorder Rat where
- le := (· ≤· )
- le_refl := sorry
- le_trans := sorry
- lt_iff_le_not_le := sorry
-
-instance : PartialOrder Rat where
- le_antisymm := sorry
-
-instance : LinearOrder Rat where
- min := fun a b => if a ≤ b then a else b
- max := fun a b => if a ≤ b then b else a
- le_total := sorry
- decidable_le := inferInstance
-
-instance : LinearOrderedCommRing Rat where
- add_le_add_left := sorry
- zero_le_one := sorry
- le_total := sorry
- decidable_le := inferInstance
- exists_pair_ne := sorry
- mul_comm := sorry
- min_def := sorry
- max_def := sorry
- mul_pos := sorry
+
+namespace Rat
+
+variable (a b c : ℚ)
+
+open Rat
+
+/-- A rational number is called nonnegative if its numerator is nonnegative. -/
+protected def Nonneg (r : ℚ) : Prop :=
+ 0 ≤ r.num
+#align rat.nonneg Rat.Nonneg
+
+@[simp]
+theorem divInt_nonneg (a : ℤ) {b : ℤ} (h : 0 < b) : (a /. b).Nonneg ↔ 0 ≤ a := by
+ generalize ha : a /. b = x; cases' x with n₁ d₁ h₁ c₁; rw [num_den'] at ha
+ simp [Rat.Nonneg]
+ have d0 := Int.ofNat_lt.2 (Nat.pos_of_ne_zero h₁)
+ have := (divInt_eq_iff (ne_of_gt h) (ne_of_gt d0)).1 ha
+ constructor <;> intro h₂
+ · apply nonneg_of_mul_nonneg_left _ d0
+ rw [this]
+ exact mul_nonneg h₂ (le_of_lt h)
+ · apply nonneg_of_mul_nonneg_left _ h
+ rw [← this]
+ exact mul_nonneg h₂ (Int.ofNat_zero_le _)
+#align rat.mk_nonneg Rat.divInt_nonneg
+
+protected theorem nonneg_add {a b} : Rat.Nonneg a → Rat.Nonneg b → Rat.Nonneg (a + b) :=
+ numDenCasesOn' a fun n₁ d₁ h₁ =>
+ numDenCasesOn' b fun n₂ d₂ h₂ => by
+ have d₁0 : 0 < (d₁ : ℤ) := Int.coe_nat_pos.2 (Nat.pos_of_ne_zero h₁)
+ have d₂0 : 0 < (d₂ : ℤ) := Int.coe_nat_pos.2 (Nat.pos_of_ne_zero h₂)
+ simp only [d₁0, d₂0, h₁, h₂, mul_pos, divInt_nonneg, add_def'', Ne.def,
+ Nat.cast_eq_zero, not_false_iff]
+ intro n₁0 n₂0
+ apply add_nonneg <;> apply mul_nonneg <;> · first |assumption|apply Int.ofNat_zero_le
+#align rat.nonneg_add Rat.nonneg_add
+
+protected theorem nonneg_mul {a b} : Rat.Nonneg a → Rat.Nonneg b → Rat.Nonneg (a * b) :=
+ numDenCasesOn' a fun n₁ d₁ h₁ =>
+ numDenCasesOn' b fun n₂ d₂ h₂ => by
+ have d₁0 : 0 < (d₁ : ℤ) := Int.coe_nat_pos.2 (Nat.pos_of_ne_zero h₁)
+ have d₂0 : 0 < (d₂ : ℤ) := Int.coe_nat_pos.2 (Nat.pos_of_ne_zero h₂)
+ rw [mul_def' d₁0.ne.symm d₂0.ne.symm, divInt_nonneg _ d₁0, divInt_nonneg _ d₂0,
+ divInt_nonneg _ (mul_pos d₁0 d₂0)]
+ apply mul_nonneg
+#align rat.nonneg_mul Rat.nonneg_mul
+
+protected theorem nonneg_antisymm {a} : Rat.Nonneg a → Rat.Nonneg (-a) → a = 0 :=
+ numDenCasesOn' a fun n d h => by
+ have d0 : 0 < (d : ℤ) := Int.coe_nat_pos.2 (Nat.pos_of_ne_zero h)
+ rw [divInt_nonneg _ d0, neg_def, divInt_nonneg _ d0, Right.nonneg_neg_iff,
+ divInt_eq_zero d0.ne.symm]
+ exact fun h₁ h₂ => le_antisymm h₂ h₁
+#align rat.nonneg_antisymm Rat.nonneg_antisymm
+
+protected theorem nonneg_total : Rat.Nonneg a ∨ Rat.Nonneg (-a) := by
+ cases' a with n; exact Or.imp_right neg_nonneg_of_nonpos (le_total 0 n)
+#align rat.nonneg_total Rat.nonneg_total
+
+instance decidableNonneg : Decidable (Rat.Nonneg a) := by
+ cases a; unfold Rat.Nonneg; infer_instance
+#align rat.decidable_nonneg Rat.decidableNonneg
+
+-- Porting note: Now `Std` defines `≤` on `Rat`.
+-- This is the old mathlib3 definition.
+/-- Relation `a ≤ b` on `ℚ` defined as `a ≤ b ↔ Rat.Nonneg (b - a)`. Use `a ≤ b` instead of
+`Rat.le a b`. -/
+protected def le' (a b : ℚ) := Rat.Nonneg (b - a)
+#align rat.le Rat.le'
+
+/-- Define a (dependent) function or prove `∀ r : ℚ, p r` by dealing with rational
+numbers of the form `mk' n d` with `d ≠ 0`. -/
+-- Porting note: TODO move
+@[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' _
+
+-- Porting note: TODO can this be shortened?
+protected theorem le_iff_Nonneg (a b : ℚ) : a ≤ b ↔ Rat.Nonneg (b - a) :=
+ numDenCasesOn'' a fun na da ha hared =>
+ numDenCasesOn'' b fun nb db hb hbred => by
+ change Rat.blt _ _ = false ↔ _
+ unfold Rat.blt
+ simp [-divInt_ofNat, mkRat_eq]
+ split_ifs with h h'
+ · rw [Rat.sub_def]
+ simp [Rat.Nonneg]
+ simp [normalize_eq]
+ apply Int.ediv_neg'
+ · rw [sub_neg]
+ apply lt_of_lt_of_le
+ · apply mul_neg_of_neg_of_pos h.1
+ rwa [Nat.cast_pos, pos_iff_ne_zero]
+ · apply mul_nonneg h.2 (Nat.cast_nonneg _)
+ · simp only [Nat.cast_pos]
+ apply Nat.gcd_pos_of_pos_right
+ apply mul_pos <;> rwa [pos_iff_ne_zero]
+ · simp only [divInt_ofNat, ←zero_iff_num_zero, mkRat_eq_zero hb] at h'
+ simp [h', Rat.Nonneg]
+ · simp [Rat.Nonneg, Rat.sub_def, normalize_eq]
+ refine ⟨fun H => ?_, fun H _ => ?_⟩
+ · refine Int.ediv_nonneg ?_ (Nat.cast_nonneg _)
+ rw [sub_nonneg]
+ push_neg at h
+ obtain hb|hb := Ne.lt_or_lt h'
+ · apply H
+ intro H'
+ exact (hb.trans H').false.elim
+ · obtain ha|ha := le_or_lt na 0
+ · apply le_trans <| mul_nonpos_of_nonpos_of_nonneg ha (Nat.cast_nonneg _)
+ exact mul_nonneg hb.le (Nat.cast_nonneg _)
+ · exact H (fun _ => ha)
+ · rw [←sub_nonneg]
+ contrapose! H
+ apply Int.ediv_neg' H
+ simp only [Nat.cast_pos]
+ apply Nat.gcd_pos_of_pos_right
+ apply mul_pos <;> rwa [pos_iff_ne_zero]
+
+protected theorem le_def {a b c d : ℤ} (b0 : 0 < b) (d0 : 0 < d) :
+ a /. b ≤ c /. d ↔ a * d ≤ c * b := by
+ rw [Rat.le_iff_Nonneg]
+ show Rat.Nonneg _ ↔ _
+ rw [← sub_nonneg]
+ simp [sub_eq_add_neg, ne_of_gt b0, ne_of_gt d0, mul_pos d0 b0]
+#align rat.le_def Rat.le_def
+
+protected theorem le_refl : a ≤ a := by
+ rw [Rat.le_iff_Nonneg]
+ show Rat.Nonneg (a - a)
+ rw [sub_self]
+ exact le_refl (0 : ℤ)
+#align rat.le_refl Rat.le_refl
+
+protected theorem le_total : a ≤ b ∨ b ≤ a := by
+ have := Rat.nonneg_total (b - a)
+ rw [Rat.le_iff_Nonneg, Rat.le_iff_Nonneg]
+ rwa [neg_sub] at this
+#align rat.le_total Rat.le_total
+
+protected theorem le_antisymm {a b : ℚ} (hab : a ≤ b) (hba : b ≤ a) : a = b := by
+ rw [Rat.le_iff_Nonneg] at hab hba
+ rw [sub_eq_add_neg] at hba
+ rw [←neg_sub, sub_eq_add_neg] at hab
+ have := eq_neg_of_add_eq_zero_left (Rat.nonneg_antisymm hba hab)
+ rwa [neg_neg] at this
+#align rat.le_antisymm Rat.le_antisymm
+
+protected theorem le_trans {a b c : ℚ} (hab : a ≤ b) (hbc : b ≤ c) : a ≤ c := by
+ rw [Rat.le_iff_Nonneg] at hab hbc
+ have : Rat.Nonneg (b - a + (c - b)) := Rat.nonneg_add hab hbc
+ simp_rw [sub_eq_add_neg, add_left_comm (b + -a) c (-b), add_comm (b + -a) (-b),
+ add_left_comm (-b) b (-a), add_comm (-b) (-a), add_neg_cancel_comm_assoc,
+ ← sub_eq_add_neg] at this
+ rw [Rat.le_iff_Nonneg]
+ exact this
+#align rat.le_trans Rat.le_trans
+
+protected theorem not_le {a b : ℚ} : ¬a ≤ b ↔ b < a := (Bool.not_eq_false _).to_iff
+
+instance linearOrder : LinearOrder ℚ where
+ le_refl := Rat.le_refl
+ le_trans := @Rat.le_trans
+ le_antisymm := @Rat.le_antisymm
+ le_total := Rat.le_total
+ decidable_le _ _ := by infer_instance
+ lt_iff_le_not_le _ _ := by
+ rw [← Rat.not_le, and_iff_right_of_imp (Rat.le_total _ _).resolve_left]
+
+-- Extra instances to short-circuit type class resolution
+instance : LT ℚ := by infer_instance
+
+instance : DistribLattice ℚ := by infer_instance
+
+instance : Lattice ℚ := by infer_instance
+
+instance : SemilatticeInf ℚ := by infer_instance
+
+instance : SemilatticeSup ℚ := by infer_instance
+
+instance : HasInf ℚ := by infer_instance
+
+instance : HasSup ℚ := by infer_instance
+
+instance : PartialOrder ℚ := by infer_instance
+
+instance : Preorder ℚ := by infer_instance
+
+protected theorem le_def' {p q : ℚ} : p ≤ q ↔ p.num * q.den ≤ q.num * p.den := by
+ rw [← @num_den q, ← @num_den p]
+ conv_rhs => simp only [num_den]
+ exact Rat.le_def (by exact_mod_cast p.pos) (by exact_mod_cast q.pos)
+#align rat.le_def' Rat.le_def'
+
+protected theorem lt_def {p q : ℚ} : p < q ↔ p.num * q.den < q.num * p.den := by
+ rw [lt_iff_le_and_ne, Rat.le_def']
+ suffices p ≠ q ↔ p.num * q.den ≠ q.num * p.den by
+ constructor <;> intro h
+ · exact lt_iff_le_and_ne.mpr ⟨h.left, this.mp h.right⟩
+ · have tmp := lt_iff_le_and_ne.mp h
+ exact ⟨tmp.left, this.mpr tmp.right⟩
+ exact not_iff_not.mpr eq_iff_mul_eq_mul
+#align rat.lt_def Rat.lt_def
+
+theorem nonneg_iff_zero_le {a} : Rat.Nonneg a ↔ 0 ≤ a := by
+ rw [Rat.le_iff_Nonneg]
+ show Rat.Nonneg a ↔ Rat.Nonneg (a - 0)
+ simp
+#align rat.nonneg_iff_zero_le Rat.nonneg_iff_zero_le
+
+theorem num_nonneg_iff_zero_le : ∀ {a : ℚ}, 0 ≤ a.num ↔ 0 ≤ a
+ | ⟨n, d, h, c⟩ => @nonneg_iff_zero_le ⟨n, d, h, c⟩
+#align rat.num_nonneg_iff_zero_le Rat.num_nonneg_iff_zero_le
+
+protected theorem add_le_add_left {a b c : ℚ} : c + a ≤ c + b ↔ a ≤ b := by
+ rw [Rat.le_iff_Nonneg, add_sub_add_left_eq_sub, Rat.le_iff_Nonneg]
+#align rat.add_le_add_left Rat.add_le_add_left
+
+protected theorem mul_nonneg {a b : ℚ} (ha : 0 ≤ a) (hb : 0 ≤ b) : 0 ≤ a * b := by
+ rw [← nonneg_iff_zero_le] at ha hb⊢; exact Rat.nonneg_mul ha hb
+#align rat.mul_nonneg Rat.mul_nonneg
+
+instance : LinearOrderedField ℚ :=
+ { Rat.field, Rat.linearOrder, Rat.semiring with
+ zero_le_one := by decide
+ add_le_add_left := fun a b ab c => Rat.add_le_add_left.2 ab
+ mul_pos := fun a b ha hb =>
+ lt_of_le_of_ne (Rat.mul_nonneg (le_of_lt ha) (le_of_lt hb))
+ (mul_ne_zero (ne_of_lt ha).symm (ne_of_lt hb).symm).symm }
+
+-- Extra instances to short-circuit type class resolution
+instance : LinearOrderedCommRing ℚ := by infer_instance
+
+instance : LinearOrderedRing ℚ := by infer_instance
+
+instance : OrderedRing ℚ := by infer_instance
+
+instance : LinearOrderedSemiring ℚ := by infer_instance
+
+instance : OrderedSemiring ℚ := by infer_instance
+
+instance : LinearOrderedAddCommGroup ℚ := by infer_instance
+
+instance : OrderedAddCommGroup ℚ := by infer_instance
+
+instance : OrderedCancelAddCommMonoid ℚ := by infer_instance
+
+instance : OrderedAddCommMonoid ℚ := by infer_instance
+
+theorem num_pos_iff_pos {a : ℚ} : 0 < a.num ↔ 0 < a :=
+ lt_iff_lt_of_le_iff_le <| by
+ simpa [(by cases a; rfl : (-a).num = -a.num)] using @num_nonneg_iff_zero_le (-a)
+#align rat.num_pos_iff_pos Rat.num_pos_iff_pos
+
+theorem div_lt_div_iff_mul_lt_mul {a b c d : ℤ} (b_pos : 0 < b) (d_pos : 0 < d) :
+ (a : ℚ) / b < c / d ↔ a * d < c * b := by
+ simp only [lt_iff_le_not_le]
+ apply and_congr
+ · simp [div_num_den, Rat.le_def b_pos d_pos]
+ · apply not_congr
+ simp [div_num_den, Rat.le_def d_pos b_pos]
+#align rat.div_lt_div_iff_mul_lt_mul Rat.div_lt_div_iff_mul_lt_mul
+
+theorem lt_one_iff_num_lt_denom {q : ℚ} : q < 1 ↔ q.num < q.den := by simp [Rat.lt_def]
+#align rat.lt_one_iff_num_lt_denom Rat.lt_one_iff_num_lt_denom
+
+theorem abs_def (q : ℚ) : |q| = q.num.natAbs /. q.den := by
+ cases' le_total q 0 with hq hq
+ · rw [abs_of_nonpos hq]
+ rw [← @num_den q, ← divInt_zero_one, Rat.le_def (Int.coe_nat_pos.2 q.pos) zero_lt_one, mul_one,
+ zero_mul] at hq
+ rw [Int.ofNat_natAbs_of_nonpos hq, ← neg_def, num_den]
+ · rw [abs_of_nonneg hq]
+ rw [← @num_den q, ← divInt_zero_one, Rat.le_def zero_lt_one (Int.coe_nat_pos.2 q.pos), mul_one,
+ zero_mul] at hq
+ rw [Int.natAbs_of_nonneg hq, num_den]
+#align rat.abs_def Rat.abs_def
+
+end Rat
+
+-- Porting note: `assert_not_exists` not yet implemented.
+
+-- We make some assertions here about declarations that do not need to be in the import dependencies
+-- for this file, but have been in the past.
+-- assert_not_exists fintype
+
+-- assert_not_exists set.Icc
+
+-- assert_not_exists galois_connection
+
+-- These are less significant, but should not be relaxed until at least after port to Lean 4.
+-- assert_not_exists LinearOrderedCommGroupWithZero
The unported dependencies are