@@ -25,7 +25,7 @@ assert_not_exists OrderedCommMonoid Field Finset Set.Icc GaloisConnection
2525
2626namespace Rat
2727
28- variable {a b p q : ℚ}
28+ variable {a b c p q : ℚ}
2929
3030@[simp] lemma divInt_nonneg_iff_of_pos_right {a b : ℤ} (hb : 0 < b) : 0 ≤ a /. b ↔ 0 ≤ a := by
3131 rcases hab : a /. b with ⟨n, d, hd, hnd⟩
@@ -126,26 +126,36 @@ protected lemma divInt_le_divInt {a b c d : ℤ} (b0 : 0 < b) (d0 : 0 < d) :
126126protected lemma le_total : a ≤ b ∨ b ≤ a := by
127127 simpa only [← Rat.le_iff_sub_nonneg, neg_sub] using Rat.nonneg_total (b - a)
128128
129+ protected lemma le_refl : a ≤ a := by
130+ rw [Rat.le_iff_sub_nonneg, ← num_nonneg]; simp
131+
132+ protected lemma le_trans (hab : a ≤ b) (hbc : b ≤ c) : a ≤ c := by
133+ rw [Rat.le_iff_sub_nonneg] at hab hbc
134+ have := Rat.add_nonneg hab hbc
135+ simp_rw [sub_eq_add_neg, add_left_comm (b + -a) c (-b), add_comm (b + -a) (-b),
136+ add_left_comm (-b) b (-a), add_comm (-b) (-a), add_neg_cancel_comm_assoc,
137+ ← sub_eq_add_neg] at this
138+ rwa [Rat.le_iff_sub_nonneg]
139+
140+ protected lemma le_antisymm (hab : a ≤ b) (hba : b ≤ a) : a = b := by
141+ rw [Rat.le_iff_sub_nonneg] at hab hba
142+ rw [sub_eq_add_neg] at hba
143+ rw [← neg_sub, sub_eq_add_neg] at hab
144+ have := eq_neg_of_add_eq_zero_left (Rat.nonneg_antisymm hba hab)
145+ rwa [neg_neg] at this
146+
147+ protected lemma lt_iff_le_not_ge (a b : ℚ) : a < b ↔ a ≤ b ∧ ¬b ≤ a := by
148+ rw [← Rat.not_le, and_iff_right_of_imp Rat.le_total.resolve_left]
149+
129150instance linearOrder : LinearOrder ℚ where
130- le_refl a := by rw [Rat.le_iff_sub_nonneg, ← num_nonneg]; simp
131- le_trans a b c hab hbc := by
132- rw [Rat.le_iff_sub_nonneg] at hab hbc
133- have := Rat.add_nonneg hab hbc
134- simp_rw [sub_eq_add_neg, add_left_comm (b + -a) c (-b), add_comm (b + -a) (-b),
135- add_left_comm (-b) b (-a), add_comm (-b) (-a), add_neg_cancel_comm_assoc,
136- ← sub_eq_add_neg] at this
137- rwa [Rat.le_iff_sub_nonneg]
138- le_antisymm a b hab hba := by
139- rw [Rat.le_iff_sub_nonneg] at hab hba
140- rw [sub_eq_add_neg] at hba
141- rw [← neg_sub, sub_eq_add_neg] at hab
142- have := eq_neg_of_add_eq_zero_left (Rat.nonneg_antisymm hba hab)
143- rwa [neg_neg] at this
151+ le_refl _ := Rat.le_refl
152+ le_trans _ _ _ := Rat.le_trans
153+ le_antisymm _ _ := Rat.le_antisymm
144154 le_total _ _ := Rat.le_total
145155 toDecidableEq := inferInstance
146156 toDecidableLE := inferInstance
147157 toDecidableLT := inferInstance
148- lt_iff_le_not_ge _ _ := by rw [← Rat.not_le, and_iff_right_of_imp Rat.le_total.resolve_left]
158+ lt_iff_le_not_ge := Rat.lt_iff_le_not_ge
149159
150160theorem mkRat_nonneg_iff (a : ℤ) {b : ℕ} (hb : b ≠ 0 ) : 0 ≤ mkRat a b ↔ 0 ≤ a :=
151161 divInt_nonneg_iff_of_pos_right (show 0 < (b : ℤ) by simpa using Nat.pos_of_ne_zero hb)
0 commit comments