state
stringlengths
0
159k
srcUpToTactic
stringlengths
387
167k
nextTactic
stringlengths
3
9k
declUpToTactic
stringlengths
22
11.5k
declId
stringlengths
38
95
decl
stringlengths
16
1.89k
file_tag
stringlengths
17
73
R : Type u inst✝ : AddGroupWithOne R ⊢ ↑↑2 = ↑2
/- Copyright (c) 2017 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro, Gabriel Ebner -/ import Mathlib.Init.Data.Nat.Lemmas import Mathlib.Data.Int.Cast.Defs import Mathlib.Algebra.Group.Basic #align_import data.int.cast.basic from "leanprover-community/mathlib"@"70d50ecfd4900dd6d328da39ab7ebd516abe4025" /-! # Cast of integers (additional theorems) This file proves additional properties about the *canonical* homomorphism from the integers into an additive group with a one (`Int.cast`). There is also `Data.Int.Cast.Lemmas`, which includes lemmas stated in terms of algebraic homomorphisms, and results involving the order structure of `ℤ`. By contrast, this file's only import beyond `Data.Int.Cast.Defs` is `Algebra.Group.Basic`. -/ universe u namespace Nat variable {R : Type u} [AddGroupWithOne R] @[simp, norm_cast] theorem cast_sub {m n} (h : m ≤ n) : ((n - m : ℕ) : R) = n - m := eq_sub_of_add_eq <| by rw [← cast_add, Nat.sub_add_cancel h] #align nat.cast_sub Nat.cast_subₓ -- `HasLiftT` appeared in the type signature @[simp, norm_cast] theorem cast_pred : ∀ {n}, 0 < n → ((n - 1 : ℕ) : R) = n - 1 | 0, h => by cases h | n + 1, _ => by rw [cast_succ, add_sub_cancel]; rfl #align nat.cast_pred Nat.cast_pred end Nat open Nat namespace Int variable {R : Type u} [AddGroupWithOne R] @[simp, norm_cast squash] theorem cast_negSucc (n : ℕ) : (-[n+1] : R) = -(n + 1 : ℕ) := AddGroupWithOne.intCast_negSucc n #align int.cast_neg_succ_of_nat Int.cast_negSuccₓ -- expected `n` to be implicit, and `HasLiftT` @[simp, norm_cast] theorem cast_zero : ((0 : ℤ) : R) = 0 := (AddGroupWithOne.intCast_ofNat 0).trans Nat.cast_zero #align int.cast_zero Int.cast_zeroₓ -- type had `HasLiftT` @[simp high, nolint simpNF, norm_cast] -- this lemma competes with `Int.ofNat_eq_cast` to come later theorem cast_ofNat (n : ℕ) : ((n : ℤ) : R) = n := AddGroupWithOne.intCast_ofNat _ #align int.cast_coe_nat Int.cast_ofNatₓ -- expected `n` to be implicit, and `HasLiftT` #align int.cast_of_nat Int.cast_ofNatₓ -- See note [no_index around OfNat.ofNat] @[simp, norm_cast] theorem int_cast_ofNat (n : ℕ) [n.AtLeastTwo] : ((no_index (OfNat.ofNat n) : ℤ) : R) = OfNat.ofNat n := by simpa only [OfNat.ofNat] using AddGroupWithOne.intCast_ofNat (R := R) n @[simp, norm_cast] theorem cast_one : ((1 : ℤ) : R) = 1 := by erw [cast_ofNat, Nat.cast_one] #align int.cast_one Int.cast_oneₓ -- type had `HasLiftT` @[simp, norm_cast] theorem cast_neg : ∀ n, ((-n : ℤ) : R) = -n | (0 : ℕ) => by erw [cast_zero, neg_zero] | (n + 1 : ℕ) => by erw [cast_ofNat, cast_negSucc] | -[n+1] => by erw [cast_ofNat, cast_negSucc, neg_neg] #align int.cast_neg Int.cast_negₓ -- type had `HasLiftT` @[simp, norm_cast] theorem cast_subNatNat (m n) : ((Int.subNatNat m n : ℤ) : R) = m - n := by unfold subNatNat cases e : n - m · simp only [ofNat_eq_coe] simp [e, Nat.le_of_sub_eq_zero e] · rw [cast_negSucc, Nat.add_one, ← e, Nat.cast_sub <| _root_.le_of_lt <| Nat.lt_of_sub_eq_succ e, neg_sub] #align int.cast_sub_nat_nat Int.cast_subNatNatₓ -- type had `HasLiftT` #align int.neg_of_nat_eq Int.negOfNat_eq @[simp] theorem cast_negOfNat (n : ℕ) : ((negOfNat n : ℤ) : R) = -n := by simp [Int.cast_neg, negOfNat_eq] #align int.cast_neg_of_nat Int.cast_negOfNat @[simp, norm_cast] theorem cast_add : ∀ m n, ((m + n : ℤ) : R) = m + n | (m : ℕ), (n : ℕ) => by simp [-Int.natCast_add, ← Int.ofNat_add] | (m : ℕ), -[n+1] => by erw [cast_subNatNat, cast_ofNat, cast_negSucc, sub_eq_add_neg] | -[m+1], (n : ℕ) => by erw [cast_subNatNat, cast_ofNat, cast_negSucc, sub_eq_iff_eq_add, add_assoc, eq_neg_add_iff_add_eq, ← Nat.cast_add, ← Nat.cast_add, Nat.add_comm] | -[m+1], -[n+1] => show (-[m + n + 1+1] : R) = _ by rw [cast_negSucc, cast_negSucc, cast_negSucc, ← neg_add_rev, ← Nat.cast_add, Nat.add_right_comm m n 1, Nat.add_assoc, Nat.add_comm] #align int.cast_add Int.cast_addₓ -- type had `HasLiftT` @[simp, norm_cast] theorem cast_sub (m n) : ((m - n : ℤ) : R) = m - n := by simp [Int.sub_eq_add_neg, sub_eq_add_neg, Int.cast_neg, Int.cast_add] #align int.cast_sub Int.cast_subₓ -- type had `HasLiftT` section deprecated set_option linter.deprecated false @[norm_cast, deprecated] theorem ofNat_bit0 (n : ℕ) : (↑(bit0 n) : ℤ) = bit0 ↑n := rfl #align int.coe_nat_bit0 Int.ofNat_bit0 @[norm_cast, deprecated] theorem ofNat_bit1 (n : ℕ) : (↑(bit1 n) : ℤ) = bit1 ↑n := rfl #align int.coe_nat_bit1 Int.ofNat_bit1 @[norm_cast, deprecated] theorem cast_bit0 (n : ℤ) : ((bit0 n : ℤ) : R) = bit0 (n : R) := Int.cast_add _ _ #align int.cast_bit0 Int.cast_bit0 @[norm_cast, deprecated] theorem cast_bit1 (n : ℤ) : ((bit1 n : ℤ) : R) = bit1 (n : R) := by rw [bit1, Int.cast_add, Int.cast_one, cast_bit0]; rfl #align int.cast_bit1 Int.cast_bit1 end deprecated theorem cast_two : ((2 : ℤ) : R) = 2 := show (((2 : ℕ) : ℤ) : R) = ((2 : ℕ) : R) by
rw [cast_ofNat, Nat.cast_ofNat]
theorem cast_two : ((2 : ℤ) : R) = 2 := show (((2 : ℕ) : ℤ) : R) = ((2 : ℕ) : R) by
Mathlib.Data.Int.Cast.Basic.153_0.3MsWc9B5PAFbTbn
theorem cast_two : ((2 : ℤ) : R) = 2
Mathlib_Data_Int_Cast_Basic
R : Type u inst✝ : AddGroupWithOne R ⊢ ↑↑3 = ↑3
/- Copyright (c) 2017 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro, Gabriel Ebner -/ import Mathlib.Init.Data.Nat.Lemmas import Mathlib.Data.Int.Cast.Defs import Mathlib.Algebra.Group.Basic #align_import data.int.cast.basic from "leanprover-community/mathlib"@"70d50ecfd4900dd6d328da39ab7ebd516abe4025" /-! # Cast of integers (additional theorems) This file proves additional properties about the *canonical* homomorphism from the integers into an additive group with a one (`Int.cast`). There is also `Data.Int.Cast.Lemmas`, which includes lemmas stated in terms of algebraic homomorphisms, and results involving the order structure of `ℤ`. By contrast, this file's only import beyond `Data.Int.Cast.Defs` is `Algebra.Group.Basic`. -/ universe u namespace Nat variable {R : Type u} [AddGroupWithOne R] @[simp, norm_cast] theorem cast_sub {m n} (h : m ≤ n) : ((n - m : ℕ) : R) = n - m := eq_sub_of_add_eq <| by rw [← cast_add, Nat.sub_add_cancel h] #align nat.cast_sub Nat.cast_subₓ -- `HasLiftT` appeared in the type signature @[simp, norm_cast] theorem cast_pred : ∀ {n}, 0 < n → ((n - 1 : ℕ) : R) = n - 1 | 0, h => by cases h | n + 1, _ => by rw [cast_succ, add_sub_cancel]; rfl #align nat.cast_pred Nat.cast_pred end Nat open Nat namespace Int variable {R : Type u} [AddGroupWithOne R] @[simp, norm_cast squash] theorem cast_negSucc (n : ℕ) : (-[n+1] : R) = -(n + 1 : ℕ) := AddGroupWithOne.intCast_negSucc n #align int.cast_neg_succ_of_nat Int.cast_negSuccₓ -- expected `n` to be implicit, and `HasLiftT` @[simp, norm_cast] theorem cast_zero : ((0 : ℤ) : R) = 0 := (AddGroupWithOne.intCast_ofNat 0).trans Nat.cast_zero #align int.cast_zero Int.cast_zeroₓ -- type had `HasLiftT` @[simp high, nolint simpNF, norm_cast] -- this lemma competes with `Int.ofNat_eq_cast` to come later theorem cast_ofNat (n : ℕ) : ((n : ℤ) : R) = n := AddGroupWithOne.intCast_ofNat _ #align int.cast_coe_nat Int.cast_ofNatₓ -- expected `n` to be implicit, and `HasLiftT` #align int.cast_of_nat Int.cast_ofNatₓ -- See note [no_index around OfNat.ofNat] @[simp, norm_cast] theorem int_cast_ofNat (n : ℕ) [n.AtLeastTwo] : ((no_index (OfNat.ofNat n) : ℤ) : R) = OfNat.ofNat n := by simpa only [OfNat.ofNat] using AddGroupWithOne.intCast_ofNat (R := R) n @[simp, norm_cast] theorem cast_one : ((1 : ℤ) : R) = 1 := by erw [cast_ofNat, Nat.cast_one] #align int.cast_one Int.cast_oneₓ -- type had `HasLiftT` @[simp, norm_cast] theorem cast_neg : ∀ n, ((-n : ℤ) : R) = -n | (0 : ℕ) => by erw [cast_zero, neg_zero] | (n + 1 : ℕ) => by erw [cast_ofNat, cast_negSucc] | -[n+1] => by erw [cast_ofNat, cast_negSucc, neg_neg] #align int.cast_neg Int.cast_negₓ -- type had `HasLiftT` @[simp, norm_cast] theorem cast_subNatNat (m n) : ((Int.subNatNat m n : ℤ) : R) = m - n := by unfold subNatNat cases e : n - m · simp only [ofNat_eq_coe] simp [e, Nat.le_of_sub_eq_zero e] · rw [cast_negSucc, Nat.add_one, ← e, Nat.cast_sub <| _root_.le_of_lt <| Nat.lt_of_sub_eq_succ e, neg_sub] #align int.cast_sub_nat_nat Int.cast_subNatNatₓ -- type had `HasLiftT` #align int.neg_of_nat_eq Int.negOfNat_eq @[simp] theorem cast_negOfNat (n : ℕ) : ((negOfNat n : ℤ) : R) = -n := by simp [Int.cast_neg, negOfNat_eq] #align int.cast_neg_of_nat Int.cast_negOfNat @[simp, norm_cast] theorem cast_add : ∀ m n, ((m + n : ℤ) : R) = m + n | (m : ℕ), (n : ℕ) => by simp [-Int.natCast_add, ← Int.ofNat_add] | (m : ℕ), -[n+1] => by erw [cast_subNatNat, cast_ofNat, cast_negSucc, sub_eq_add_neg] | -[m+1], (n : ℕ) => by erw [cast_subNatNat, cast_ofNat, cast_negSucc, sub_eq_iff_eq_add, add_assoc, eq_neg_add_iff_add_eq, ← Nat.cast_add, ← Nat.cast_add, Nat.add_comm] | -[m+1], -[n+1] => show (-[m + n + 1+1] : R) = _ by rw [cast_negSucc, cast_negSucc, cast_negSucc, ← neg_add_rev, ← Nat.cast_add, Nat.add_right_comm m n 1, Nat.add_assoc, Nat.add_comm] #align int.cast_add Int.cast_addₓ -- type had `HasLiftT` @[simp, norm_cast] theorem cast_sub (m n) : ((m - n : ℤ) : R) = m - n := by simp [Int.sub_eq_add_neg, sub_eq_add_neg, Int.cast_neg, Int.cast_add] #align int.cast_sub Int.cast_subₓ -- type had `HasLiftT` section deprecated set_option linter.deprecated false @[norm_cast, deprecated] theorem ofNat_bit0 (n : ℕ) : (↑(bit0 n) : ℤ) = bit0 ↑n := rfl #align int.coe_nat_bit0 Int.ofNat_bit0 @[norm_cast, deprecated] theorem ofNat_bit1 (n : ℕ) : (↑(bit1 n) : ℤ) = bit1 ↑n := rfl #align int.coe_nat_bit1 Int.ofNat_bit1 @[norm_cast, deprecated] theorem cast_bit0 (n : ℤ) : ((bit0 n : ℤ) : R) = bit0 (n : R) := Int.cast_add _ _ #align int.cast_bit0 Int.cast_bit0 @[norm_cast, deprecated] theorem cast_bit1 (n : ℤ) : ((bit1 n : ℤ) : R) = bit1 (n : R) := by rw [bit1, Int.cast_add, Int.cast_one, cast_bit0]; rfl #align int.cast_bit1 Int.cast_bit1 end deprecated theorem cast_two : ((2 : ℤ) : R) = 2 := show (((2 : ℕ) : ℤ) : R) = ((2 : ℕ) : R) by rw [cast_ofNat, Nat.cast_ofNat] #align int.cast_two Int.cast_two theorem cast_three : ((3 : ℤ) : R) = 3 := show (((3 : ℕ) : ℤ) : R) = ((3 : ℕ) : R) by
rw [cast_ofNat, Nat.cast_ofNat]
theorem cast_three : ((3 : ℤ) : R) = 3 := show (((3 : ℕ) : ℤ) : R) = ((3 : ℕ) : R) by
Mathlib.Data.Int.Cast.Basic.157_0.3MsWc9B5PAFbTbn
theorem cast_three : ((3 : ℤ) : R) = 3
Mathlib_Data_Int_Cast_Basic
R : Type u inst✝ : AddGroupWithOne R ⊢ ↑↑4 = ↑4
/- Copyright (c) 2017 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro, Gabriel Ebner -/ import Mathlib.Init.Data.Nat.Lemmas import Mathlib.Data.Int.Cast.Defs import Mathlib.Algebra.Group.Basic #align_import data.int.cast.basic from "leanprover-community/mathlib"@"70d50ecfd4900dd6d328da39ab7ebd516abe4025" /-! # Cast of integers (additional theorems) This file proves additional properties about the *canonical* homomorphism from the integers into an additive group with a one (`Int.cast`). There is also `Data.Int.Cast.Lemmas`, which includes lemmas stated in terms of algebraic homomorphisms, and results involving the order structure of `ℤ`. By contrast, this file's only import beyond `Data.Int.Cast.Defs` is `Algebra.Group.Basic`. -/ universe u namespace Nat variable {R : Type u} [AddGroupWithOne R] @[simp, norm_cast] theorem cast_sub {m n} (h : m ≤ n) : ((n - m : ℕ) : R) = n - m := eq_sub_of_add_eq <| by rw [← cast_add, Nat.sub_add_cancel h] #align nat.cast_sub Nat.cast_subₓ -- `HasLiftT` appeared in the type signature @[simp, norm_cast] theorem cast_pred : ∀ {n}, 0 < n → ((n - 1 : ℕ) : R) = n - 1 | 0, h => by cases h | n + 1, _ => by rw [cast_succ, add_sub_cancel]; rfl #align nat.cast_pred Nat.cast_pred end Nat open Nat namespace Int variable {R : Type u} [AddGroupWithOne R] @[simp, norm_cast squash] theorem cast_negSucc (n : ℕ) : (-[n+1] : R) = -(n + 1 : ℕ) := AddGroupWithOne.intCast_negSucc n #align int.cast_neg_succ_of_nat Int.cast_negSuccₓ -- expected `n` to be implicit, and `HasLiftT` @[simp, norm_cast] theorem cast_zero : ((0 : ℤ) : R) = 0 := (AddGroupWithOne.intCast_ofNat 0).trans Nat.cast_zero #align int.cast_zero Int.cast_zeroₓ -- type had `HasLiftT` @[simp high, nolint simpNF, norm_cast] -- this lemma competes with `Int.ofNat_eq_cast` to come later theorem cast_ofNat (n : ℕ) : ((n : ℤ) : R) = n := AddGroupWithOne.intCast_ofNat _ #align int.cast_coe_nat Int.cast_ofNatₓ -- expected `n` to be implicit, and `HasLiftT` #align int.cast_of_nat Int.cast_ofNatₓ -- See note [no_index around OfNat.ofNat] @[simp, norm_cast] theorem int_cast_ofNat (n : ℕ) [n.AtLeastTwo] : ((no_index (OfNat.ofNat n) : ℤ) : R) = OfNat.ofNat n := by simpa only [OfNat.ofNat] using AddGroupWithOne.intCast_ofNat (R := R) n @[simp, norm_cast] theorem cast_one : ((1 : ℤ) : R) = 1 := by erw [cast_ofNat, Nat.cast_one] #align int.cast_one Int.cast_oneₓ -- type had `HasLiftT` @[simp, norm_cast] theorem cast_neg : ∀ n, ((-n : ℤ) : R) = -n | (0 : ℕ) => by erw [cast_zero, neg_zero] | (n + 1 : ℕ) => by erw [cast_ofNat, cast_negSucc] | -[n+1] => by erw [cast_ofNat, cast_negSucc, neg_neg] #align int.cast_neg Int.cast_negₓ -- type had `HasLiftT` @[simp, norm_cast] theorem cast_subNatNat (m n) : ((Int.subNatNat m n : ℤ) : R) = m - n := by unfold subNatNat cases e : n - m · simp only [ofNat_eq_coe] simp [e, Nat.le_of_sub_eq_zero e] · rw [cast_negSucc, Nat.add_one, ← e, Nat.cast_sub <| _root_.le_of_lt <| Nat.lt_of_sub_eq_succ e, neg_sub] #align int.cast_sub_nat_nat Int.cast_subNatNatₓ -- type had `HasLiftT` #align int.neg_of_nat_eq Int.negOfNat_eq @[simp] theorem cast_negOfNat (n : ℕ) : ((negOfNat n : ℤ) : R) = -n := by simp [Int.cast_neg, negOfNat_eq] #align int.cast_neg_of_nat Int.cast_negOfNat @[simp, norm_cast] theorem cast_add : ∀ m n, ((m + n : ℤ) : R) = m + n | (m : ℕ), (n : ℕ) => by simp [-Int.natCast_add, ← Int.ofNat_add] | (m : ℕ), -[n+1] => by erw [cast_subNatNat, cast_ofNat, cast_negSucc, sub_eq_add_neg] | -[m+1], (n : ℕ) => by erw [cast_subNatNat, cast_ofNat, cast_negSucc, sub_eq_iff_eq_add, add_assoc, eq_neg_add_iff_add_eq, ← Nat.cast_add, ← Nat.cast_add, Nat.add_comm] | -[m+1], -[n+1] => show (-[m + n + 1+1] : R) = _ by rw [cast_negSucc, cast_negSucc, cast_negSucc, ← neg_add_rev, ← Nat.cast_add, Nat.add_right_comm m n 1, Nat.add_assoc, Nat.add_comm] #align int.cast_add Int.cast_addₓ -- type had `HasLiftT` @[simp, norm_cast] theorem cast_sub (m n) : ((m - n : ℤ) : R) = m - n := by simp [Int.sub_eq_add_neg, sub_eq_add_neg, Int.cast_neg, Int.cast_add] #align int.cast_sub Int.cast_subₓ -- type had `HasLiftT` section deprecated set_option linter.deprecated false @[norm_cast, deprecated] theorem ofNat_bit0 (n : ℕ) : (↑(bit0 n) : ℤ) = bit0 ↑n := rfl #align int.coe_nat_bit0 Int.ofNat_bit0 @[norm_cast, deprecated] theorem ofNat_bit1 (n : ℕ) : (↑(bit1 n) : ℤ) = bit1 ↑n := rfl #align int.coe_nat_bit1 Int.ofNat_bit1 @[norm_cast, deprecated] theorem cast_bit0 (n : ℤ) : ((bit0 n : ℤ) : R) = bit0 (n : R) := Int.cast_add _ _ #align int.cast_bit0 Int.cast_bit0 @[norm_cast, deprecated] theorem cast_bit1 (n : ℤ) : ((bit1 n : ℤ) : R) = bit1 (n : R) := by rw [bit1, Int.cast_add, Int.cast_one, cast_bit0]; rfl #align int.cast_bit1 Int.cast_bit1 end deprecated theorem cast_two : ((2 : ℤ) : R) = 2 := show (((2 : ℕ) : ℤ) : R) = ((2 : ℕ) : R) by rw [cast_ofNat, Nat.cast_ofNat] #align int.cast_two Int.cast_two theorem cast_three : ((3 : ℤ) : R) = 3 := show (((3 : ℕ) : ℤ) : R) = ((3 : ℕ) : R) by rw [cast_ofNat, Nat.cast_ofNat] #align int.cast_three Int.cast_three theorem cast_four : ((4 : ℤ) : R) = 4 := show (((4 : ℕ) : ℤ) : R) = ((4 : ℕ) : R) by
rw [cast_ofNat, Nat.cast_ofNat]
theorem cast_four : ((4 : ℤ) : R) = 4 := show (((4 : ℕ) : ℤ) : R) = ((4 : ℕ) : R) by
Mathlib.Data.Int.Cast.Basic.161_0.3MsWc9B5PAFbTbn
theorem cast_four : ((4 : ℤ) : R) = 4
Mathlib_Data_Int_Cast_Basic
a✝ b✝ c : ℚ a b : ℤ h : 0 < b ⊢ Rat.Nonneg (a /. b) ↔ 0 ≤ a
/- Copyright (c) 2019 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro -/ import Mathlib.Algebra.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 ## 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 -/ 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
@[simp] theorem divInt_nonneg (a : ℤ) {b : ℤ} (h : 0 < b) : (a /. b).Nonneg ↔ 0 ≤ a := by
Mathlib.Data.Rat.Order.38_0.NTjR6KCugNscheB
@[simp] theorem divInt_nonneg (a : ℤ) {b : ℤ} (h : 0 < b) : (a /. b).Nonneg ↔ 0 ≤ a
Mathlib_Data_Rat_Order
a✝ b✝ c : ℚ a b : ℤ h : 0 < b x : ℚ ha : a /. b = x ⊢ Rat.Nonneg x ↔ 0 ≤ a
/- Copyright (c) 2019 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro -/ import Mathlib.Algebra.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 ## 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 -/ 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₁
@[simp] theorem divInt_nonneg (a : ℤ) {b : ℤ} (h : 0 < b) : (a /. b).Nonneg ↔ 0 ≤ a := by generalize ha : a /. b = x;
Mathlib.Data.Rat.Order.38_0.NTjR6KCugNscheB
@[simp] theorem divInt_nonneg (a : ℤ) {b : ℤ} (h : 0 < b) : (a /. b).Nonneg ↔ 0 ≤ a
Mathlib_Data_Rat_Order
case mk' a✝ b✝ c : ℚ a b : ℤ h : 0 < b n₁ : ℤ d₁ : ℕ h₁ : d₁ ≠ 0 c₁ : Nat.Coprime (Int.natAbs n₁) d₁ ha : a /. b = mk' n₁ d₁ ⊢ Rat.Nonneg (mk' n₁ d₁) ↔ 0 ≤ a
/- Copyright (c) 2019 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro -/ import Mathlib.Algebra.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 ## 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 -/ 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] 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₁;
Mathlib.Data.Rat.Order.38_0.NTjR6KCugNscheB
@[simp] theorem divInt_nonneg (a : ℤ) {b : ℤ} (h : 0 < b) : (a /. b).Nonneg ↔ 0 ≤ a
Mathlib_Data_Rat_Order
case mk' a✝ b✝ c : ℚ a b : ℤ h : 0 < b n₁ : ℤ d₁ : ℕ h₁ : d₁ ≠ 0 c₁ : Nat.Coprime (Int.natAbs n₁) d₁ ha : a /. b = n₁ /. ↑d₁ ⊢ Rat.Nonneg (mk' n₁ d₁) ↔ 0 ≤ a
/- Copyright (c) 2019 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro -/ import Mathlib.Algebra.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 ## 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 -/ 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]
@[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
Mathlib.Data.Rat.Order.38_0.NTjR6KCugNscheB
@[simp] theorem divInt_nonneg (a : ℤ) {b : ℤ} (h : 0 < b) : (a /. b).Nonneg ↔ 0 ≤ a
Mathlib_Data_Rat_Order
case mk' a✝ b✝ c : ℚ a b : ℤ h : 0 < b n₁ : ℤ d₁ : ℕ h₁ : d₁ ≠ 0 c₁ : Nat.Coprime (Int.natAbs n₁) d₁ ha : a /. b = n₁ /. ↑d₁ ⊢ 0 ≤ n₁ ↔ 0 ≤ a
/- Copyright (c) 2019 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro -/ import Mathlib.Algebra.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 ## 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 -/ 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₁)
@[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]
Mathlib.Data.Rat.Order.38_0.NTjR6KCugNscheB
@[simp] theorem divInt_nonneg (a : ℤ) {b : ℤ} (h : 0 < b) : (a /. b).Nonneg ↔ 0 ≤ a
Mathlib_Data_Rat_Order
case mk' a✝ b✝ c : ℚ a b : ℤ h : 0 < b n₁ : ℤ d₁ : ℕ h₁ : d₁ ≠ 0 c₁ : Nat.Coprime (Int.natAbs n₁) d₁ ha : a /. b = n₁ /. ↑d₁ d0 : ↑0 < ↑d₁ ⊢ 0 ≤ n₁ ↔ 0 ≤ a
/- Copyright (c) 2019 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro -/ import Mathlib.Algebra.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 ## 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 -/ 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
@[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₁)
Mathlib.Data.Rat.Order.38_0.NTjR6KCugNscheB
@[simp] theorem divInt_nonneg (a : ℤ) {b : ℤ} (h : 0 < b) : (a /. b).Nonneg ↔ 0 ≤ a
Mathlib_Data_Rat_Order
case mk' a✝ b✝ c : ℚ a b : ℤ h : 0 < b n₁ : ℤ d₁ : ℕ h₁ : d₁ ≠ 0 c₁ : Nat.Coprime (Int.natAbs n₁) d₁ ha : a /. b = n₁ /. ↑d₁ d0 : ↑0 < ↑d₁ this : a * ↑d₁ = n₁ * b ⊢ 0 ≤ n₁ ↔ 0 ≤ a
/- Copyright (c) 2019 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro -/ import Mathlib.Algebra.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 ## 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 -/ 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
@[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
Mathlib.Data.Rat.Order.38_0.NTjR6KCugNscheB
@[simp] theorem divInt_nonneg (a : ℤ) {b : ℤ} (h : 0 < b) : (a /. b).Nonneg ↔ 0 ≤ a
Mathlib_Data_Rat_Order
case mk'.mp a✝ b✝ c : ℚ a b : ℤ h : 0 < b n₁ : ℤ d₁ : ℕ h₁ : d₁ ≠ 0 c₁ : Nat.Coprime (Int.natAbs n₁) d₁ ha : a /. b = n₁ /. ↑d₁ d0 : ↑0 < ↑d₁ this : a * ↑d₁ = n₁ * b ⊢ 0 ≤ n₁ → 0 ≤ a
/- Copyright (c) 2019 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro -/ import Mathlib.Algebra.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 ## 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 -/ 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₂
@[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 <;>
Mathlib.Data.Rat.Order.38_0.NTjR6KCugNscheB
@[simp] theorem divInt_nonneg (a : ℤ) {b : ℤ} (h : 0 < b) : (a /. b).Nonneg ↔ 0 ≤ a
Mathlib_Data_Rat_Order
case mk'.mpr a✝ b✝ c : ℚ a b : ℤ h : 0 < b n₁ : ℤ d₁ : ℕ h₁ : d₁ ≠ 0 c₁ : Nat.Coprime (Int.natAbs n₁) d₁ ha : a /. b = n₁ /. ↑d₁ d0 : ↑0 < ↑d₁ this : a * ↑d₁ = n₁ * b ⊢ 0 ≤ a → 0 ≤ n₁
/- Copyright (c) 2019 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro -/ import Mathlib.Algebra.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 ## 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 -/ 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₂
@[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 <;>
Mathlib.Data.Rat.Order.38_0.NTjR6KCugNscheB
@[simp] theorem divInt_nonneg (a : ℤ) {b : ℤ} (h : 0 < b) : (a /. b).Nonneg ↔ 0 ≤ a
Mathlib_Data_Rat_Order
case mk'.mp a✝ b✝ c : ℚ a b : ℤ h : 0 < b n₁ : ℤ d₁ : ℕ h₁ : d₁ ≠ 0 c₁ : Nat.Coprime (Int.natAbs n₁) d₁ ha : a /. b = n₁ /. ↑d₁ d0 : ↑0 < ↑d₁ this : a * ↑d₁ = n₁ * b h₂ : 0 ≤ n₁ ⊢ 0 ≤ a
/- Copyright (c) 2019 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro -/ import Mathlib.Algebra.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 ## 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 -/ 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
@[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₂ ·
Mathlib.Data.Rat.Order.38_0.NTjR6KCugNscheB
@[simp] theorem divInt_nonneg (a : ℤ) {b : ℤ} (h : 0 < b) : (a /. b).Nonneg ↔ 0 ≤ a
Mathlib_Data_Rat_Order
a✝ b✝ c : ℚ a b : ℤ h : 0 < b n₁ : ℤ d₁ : ℕ h₁ : d₁ ≠ 0 c₁ : Nat.Coprime (Int.natAbs n₁) d₁ ha : a /. b = n₁ /. ↑d₁ d0 : ↑0 < ↑d₁ this : a * ↑d₁ = n₁ * b h₂ : 0 ≤ n₁ ⊢ 0 ≤ a * ↑d₁
/- Copyright (c) 2019 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro -/ import Mathlib.Algebra.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 ## 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 -/ 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]
@[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
Mathlib.Data.Rat.Order.38_0.NTjR6KCugNscheB
@[simp] theorem divInt_nonneg (a : ℤ) {b : ℤ} (h : 0 < b) : (a /. b).Nonneg ↔ 0 ≤ a
Mathlib_Data_Rat_Order
a✝ b✝ c : ℚ a b : ℤ h : 0 < b n₁ : ℤ d₁ : ℕ h₁ : d₁ ≠ 0 c₁ : Nat.Coprime (Int.natAbs n₁) d₁ ha : a /. b = n₁ /. ↑d₁ d0 : ↑0 < ↑d₁ this : a * ↑d₁ = n₁ * b h₂ : 0 ≤ n₁ ⊢ 0 ≤ n₁ * b
/- Copyright (c) 2019 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro -/ import Mathlib.Algebra.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 ## 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 -/ 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)
@[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]
Mathlib.Data.Rat.Order.38_0.NTjR6KCugNscheB
@[simp] theorem divInt_nonneg (a : ℤ) {b : ℤ} (h : 0 < b) : (a /. b).Nonneg ↔ 0 ≤ a
Mathlib_Data_Rat_Order
case mk'.mpr a✝ b✝ c : ℚ a b : ℤ h : 0 < b n₁ : ℤ d₁ : ℕ h₁ : d₁ ≠ 0 c₁ : Nat.Coprime (Int.natAbs n₁) d₁ ha : a /. b = n₁ /. ↑d₁ d0 : ↑0 < ↑d₁ this : a * ↑d₁ = n₁ * b h₂ : 0 ≤ a ⊢ 0 ≤ n₁
/- Copyright (c) 2019 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro -/ import Mathlib.Algebra.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 ## 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 -/ 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
@[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) ·
Mathlib.Data.Rat.Order.38_0.NTjR6KCugNscheB
@[simp] theorem divInt_nonneg (a : ℤ) {b : ℤ} (h : 0 < b) : (a /. b).Nonneg ↔ 0 ≤ a
Mathlib_Data_Rat_Order
a✝ b✝ c : ℚ a b : ℤ h : 0 < b n₁ : ℤ d₁ : ℕ h₁ : d₁ ≠ 0 c₁ : Nat.Coprime (Int.natAbs n₁) d₁ ha : a /. b = n₁ /. ↑d₁ d0 : ↑0 < ↑d₁ this : a * ↑d₁ = n₁ * b h₂ : 0 ≤ a ⊢ 0 ≤ n₁ * b
/- Copyright (c) 2019 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro -/ import Mathlib.Algebra.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 ## 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 -/ 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]
@[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
Mathlib.Data.Rat.Order.38_0.NTjR6KCugNscheB
@[simp] theorem divInt_nonneg (a : ℤ) {b : ℤ} (h : 0 < b) : (a /. b).Nonneg ↔ 0 ≤ a
Mathlib_Data_Rat_Order
a✝ b✝ c : ℚ a b : ℤ h : 0 < b n₁ : ℤ d₁ : ℕ h₁ : d₁ ≠ 0 c₁ : Nat.Coprime (Int.natAbs n₁) d₁ ha : a /. b = n₁ /. ↑d₁ d0 : ↑0 < ↑d₁ this : a * ↑d₁ = n₁ * b h₂ : 0 ≤ a ⊢ 0 ≤ a * ↑d₁
/- Copyright (c) 2019 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro -/ import Mathlib.Algebra.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 ## 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 -/ 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 _)
@[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]
Mathlib.Data.Rat.Order.38_0.NTjR6KCugNscheB
@[simp] theorem divInt_nonneg (a : ℤ) {b : ℤ} (h : 0 < b) : (a /. b).Nonneg ↔ 0 ≤ a
Mathlib_Data_Rat_Order
a✝ b✝ c a b : ℚ n₁ : ℤ d₁ : ℕ h₁ : d₁ ≠ 0 n₂ : ℤ d₂ : ℕ h₂ : d₂ ≠ 0 ⊢ Rat.Nonneg (n₁ /. ↑d₁) → Rat.Nonneg (n₂ /. ↑d₂) → Rat.Nonneg (n₁ /. ↑d₁ + n₂ /. ↑d₂)
/- Copyright (c) 2019 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro -/ import Mathlib.Algebra.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 ## 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 -/ 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.coe_nat_pos.2 (Nat.pos_of_ne_zero h₁)
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
Mathlib.Data.Rat.Order.53_0.NTjR6KCugNscheB
protected theorem nonneg_add {a b} : Rat.Nonneg a → Rat.Nonneg b → Rat.Nonneg (a + b)
Mathlib_Data_Rat_Order
a✝ b✝ c a b : ℚ n₁ : ℤ d₁ : ℕ h₁ : d₁ ≠ 0 n₂ : ℤ d₂ : ℕ h₂ : d₂ ≠ 0 d₁0 : 0 < ↑d₁ ⊢ Rat.Nonneg (n₁ /. ↑d₁) → Rat.Nonneg (n₂ /. ↑d₂) → Rat.Nonneg (n₁ /. ↑d₁ + n₂ /. ↑d₂)
/- Copyright (c) 2019 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro -/ import Mathlib.Algebra.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 ## 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 -/ 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.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₂)
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₁)
Mathlib.Data.Rat.Order.53_0.NTjR6KCugNscheB
protected theorem nonneg_add {a b} : Rat.Nonneg a → Rat.Nonneg b → Rat.Nonneg (a + b)
Mathlib_Data_Rat_Order
a✝ b✝ c a b : ℚ n₁ : ℤ d₁ : ℕ h₁ : d₁ ≠ 0 n₂ : ℤ d₂ : ℕ h₂ : d₂ ≠ 0 d₁0 : 0 < ↑d₁ d₂0 : 0 < ↑d₂ ⊢ Rat.Nonneg (n₁ /. ↑d₁) → Rat.Nonneg (n₂ /. ↑d₂) → Rat.Nonneg (n₁ /. ↑d₁ + n₂ /. ↑d₂)
/- Copyright (c) 2019 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro -/ import Mathlib.Algebra.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 ## 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 -/ 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.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]
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₂)
Mathlib.Data.Rat.Order.53_0.NTjR6KCugNscheB
protected theorem nonneg_add {a b} : Rat.Nonneg a → Rat.Nonneg b → Rat.Nonneg (a + b)
Mathlib_Data_Rat_Order
a✝ b✝ c a b : ℚ n₁ : ℤ d₁ : ℕ h₁ : d₁ ≠ 0 n₂ : ℤ d₂ : ℕ h₂ : d₂ ≠ 0 d₁0 : 0 < ↑d₁ d₂0 : 0 < ↑d₂ ⊢ 0 ≤ n₁ → 0 ≤ n₂ → 0 ≤ n₁ * ↑d₂ + n₂ * ↑d₁
/- Copyright (c) 2019 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro -/ import Mathlib.Algebra.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 ## 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 -/ 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.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
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]
Mathlib.Data.Rat.Order.53_0.NTjR6KCugNscheB
protected theorem nonneg_add {a b} : Rat.Nonneg a → Rat.Nonneg b → Rat.Nonneg (a + b)
Mathlib_Data_Rat_Order
a✝ b✝ c a b : ℚ n₁ : ℤ d₁ : ℕ h₁ : d₁ ≠ 0 n₂ : ℤ d₂ : ℕ h₂ : d₂ ≠ 0 d₁0 : 0 < ↑d₁ d₂0 : 0 < ↑d₂ n₁0 : 0 ≤ n₁ n₂0 : 0 ≤ n₂ ⊢ 0 ≤ n₁ * ↑d₂ + n₂ * ↑d₁
/- Copyright (c) 2019 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro -/ import Mathlib.Algebra.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 ## 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 -/ 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.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
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
Mathlib.Data.Rat.Order.53_0.NTjR6KCugNscheB
protected theorem nonneg_add {a b} : Rat.Nonneg a → Rat.Nonneg b → Rat.Nonneg (a + b)
Mathlib_Data_Rat_Order
case ha a✝ b✝ c a b : ℚ n₁ : ℤ d₁ : ℕ h₁ : d₁ ≠ 0 n₂ : ℤ d₂ : ℕ h₂ : d₂ ≠ 0 d₁0 : 0 < ↑d₁ d₂0 : 0 < ↑d₂ n₁0 : 0 ≤ n₁ n₂0 : 0 ≤ n₂ ⊢ 0 ≤ n₁ * ↑d₂
/- Copyright (c) 2019 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro -/ import Mathlib.Algebra.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 ## 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 -/ 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.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
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 <;>
Mathlib.Data.Rat.Order.53_0.NTjR6KCugNscheB
protected theorem nonneg_add {a b} : Rat.Nonneg a → Rat.Nonneg b → Rat.Nonneg (a + b)
Mathlib_Data_Rat_Order
case hb a✝ b✝ c a b : ℚ n₁ : ℤ d₁ : ℕ h₁ : d₁ ≠ 0 n₂ : ℤ d₂ : ℕ h₂ : d₂ ≠ 0 d₁0 : 0 < ↑d₁ d₂0 : 0 < ↑d₂ n₁0 : 0 ≤ n₁ n₂0 : 0 ≤ n₂ ⊢ 0 ≤ n₂ * ↑d₁
/- Copyright (c) 2019 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro -/ import Mathlib.Algebra.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 ## 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 -/ 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.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
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 <;>
Mathlib.Data.Rat.Order.53_0.NTjR6KCugNscheB
protected theorem nonneg_add {a b} : Rat.Nonneg a → Rat.Nonneg b → Rat.Nonneg (a + b)
Mathlib_Data_Rat_Order
case ha.ha a✝ b✝ c a b : ℚ n₁ : ℤ d₁ : ℕ h₁ : d₁ ≠ 0 n₂ : ℤ d₂ : ℕ h₂ : d₂ ≠ 0 d₁0 : 0 < ↑d₁ d₂0 : 0 < ↑d₂ n₁0 : 0 ≤ n₁ n₂0 : 0 ≤ n₂ ⊢ 0 ≤ n₁
/- Copyright (c) 2019 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro -/ import Mathlib.Algebra.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 ## 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 -/ 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.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
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 <;> ·
Mathlib.Data.Rat.Order.53_0.NTjR6KCugNscheB
protected theorem nonneg_add {a b} : Rat.Nonneg a → Rat.Nonneg b → Rat.Nonneg (a + b)
Mathlib_Data_Rat_Order
case ha.ha a✝ b✝ c a b : ℚ n₁ : ℤ d₁ : ℕ h₁ : d₁ ≠ 0 n₂ : ℤ d₂ : ℕ h₂ : d₂ ≠ 0 d₁0 : 0 < ↑d₁ d₂0 : 0 < ↑d₂ n₁0 : 0 ≤ n₁ n₂0 : 0 ≤ n₂ ⊢ 0 ≤ n₁
/- Copyright (c) 2019 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro -/ import Mathlib.Algebra.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 ## 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 -/ 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.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
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 |
Mathlib.Data.Rat.Order.53_0.NTjR6KCugNscheB
protected theorem nonneg_add {a b} : Rat.Nonneg a → Rat.Nonneg b → Rat.Nonneg (a + b)
Mathlib_Data_Rat_Order
case ha.hb a✝ b✝ c a b : ℚ n₁ : ℤ d₁ : ℕ h₁ : d₁ ≠ 0 n₂ : ℤ d₂ : ℕ h₂ : d₂ ≠ 0 d₁0 : 0 < ↑d₁ d₂0 : 0 < ↑d₂ n₁0 : 0 ≤ n₁ n₂0 : 0 ≤ n₂ ⊢ 0 ≤ ↑d₂
/- Copyright (c) 2019 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro -/ import Mathlib.Algebra.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 ## 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 -/ 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.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
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 <;> ·
Mathlib.Data.Rat.Order.53_0.NTjR6KCugNscheB
protected theorem nonneg_add {a b} : Rat.Nonneg a → Rat.Nonneg b → Rat.Nonneg (a + b)
Mathlib_Data_Rat_Order
case ha.hb a✝ b✝ c a b : ℚ n₁ : ℤ d₁ : ℕ h₁ : d₁ ≠ 0 n₂ : ℤ d₂ : ℕ h₂ : d₂ ≠ 0 d₁0 : 0 < ↑d₁ d₂0 : 0 < ↑d₂ n₁0 : 0 ≤ n₁ n₂0 : 0 ≤ n₂ ⊢ 0 ≤ ↑d₂
/- Copyright (c) 2019 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro -/ import Mathlib.Algebra.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 ## 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 -/ 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.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
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 |
Mathlib.Data.Rat.Order.53_0.NTjR6KCugNscheB
protected theorem nonneg_add {a b} : Rat.Nonneg a → Rat.Nonneg b → Rat.Nonneg (a + b)
Mathlib_Data_Rat_Order
case ha.hb a✝ b✝ c a b : ℚ n₁ : ℤ d₁ : ℕ h₁ : d₁ ≠ 0 n₂ : ℤ d₂ : ℕ h₂ : d₂ ≠ 0 d₁0 : 0 < ↑d₁ d₂0 : 0 < ↑d₂ n₁0 : 0 ≤ n₁ n₂0 : 0 ≤ n₂ ⊢ 0 ≤ ↑d₂
/- Copyright (c) 2019 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro -/ import Mathlib.Algebra.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 ## 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 -/ 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.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
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|
Mathlib.Data.Rat.Order.53_0.NTjR6KCugNscheB
protected theorem nonneg_add {a b} : Rat.Nonneg a → Rat.Nonneg b → Rat.Nonneg (a + b)
Mathlib_Data_Rat_Order
case hb.ha a✝ b✝ c a b : ℚ n₁ : ℤ d₁ : ℕ h₁ : d₁ ≠ 0 n₂ : ℤ d₂ : ℕ h₂ : d₂ ≠ 0 d₁0 : 0 < ↑d₁ d₂0 : 0 < ↑d₂ n₁0 : 0 ≤ n₁ n₂0 : 0 ≤ n₂ ⊢ 0 ≤ n₂
/- Copyright (c) 2019 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro -/ import Mathlib.Algebra.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 ## 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 -/ 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.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
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 <;> ·
Mathlib.Data.Rat.Order.53_0.NTjR6KCugNscheB
protected theorem nonneg_add {a b} : Rat.Nonneg a → Rat.Nonneg b → Rat.Nonneg (a + b)
Mathlib_Data_Rat_Order
case hb.ha a✝ b✝ c a b : ℚ n₁ : ℤ d₁ : ℕ h₁ : d₁ ≠ 0 n₂ : ℤ d₂ : ℕ h₂ : d₂ ≠ 0 d₁0 : 0 < ↑d₁ d₂0 : 0 < ↑d₂ n₁0 : 0 ≤ n₁ n₂0 : 0 ≤ n₂ ⊢ 0 ≤ n₂
/- Copyright (c) 2019 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro -/ import Mathlib.Algebra.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 ## 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 -/ 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.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
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 |
Mathlib.Data.Rat.Order.53_0.NTjR6KCugNscheB
protected theorem nonneg_add {a b} : Rat.Nonneg a → Rat.Nonneg b → Rat.Nonneg (a + b)
Mathlib_Data_Rat_Order
case hb.hb a✝ b✝ c a b : ℚ n₁ : ℤ d₁ : ℕ h₁ : d₁ ≠ 0 n₂ : ℤ d₂ : ℕ h₂ : d₂ ≠ 0 d₁0 : 0 < ↑d₁ d₂0 : 0 < ↑d₂ n₁0 : 0 ≤ n₁ n₂0 : 0 ≤ n₂ ⊢ 0 ≤ ↑d₁
/- Copyright (c) 2019 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro -/ import Mathlib.Algebra.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 ## 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 -/ 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.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
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 <;> ·
Mathlib.Data.Rat.Order.53_0.NTjR6KCugNscheB
protected theorem nonneg_add {a b} : Rat.Nonneg a → Rat.Nonneg b → Rat.Nonneg (a + b)
Mathlib_Data_Rat_Order
case hb.hb a✝ b✝ c a b : ℚ n₁ : ℤ d₁ : ℕ h₁ : d₁ ≠ 0 n₂ : ℤ d₂ : ℕ h₂ : d₂ ≠ 0 d₁0 : 0 < ↑d₁ d₂0 : 0 < ↑d₂ n₁0 : 0 ≤ n₁ n₂0 : 0 ≤ n₂ ⊢ 0 ≤ ↑d₁
/- Copyright (c) 2019 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro -/ import Mathlib.Algebra.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 ## 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 -/ 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.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
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 |
Mathlib.Data.Rat.Order.53_0.NTjR6KCugNscheB
protected theorem nonneg_add {a b} : Rat.Nonneg a → Rat.Nonneg b → Rat.Nonneg (a + b)
Mathlib_Data_Rat_Order
case hb.hb a✝ b✝ c a b : ℚ n₁ : ℤ d₁ : ℕ h₁ : d₁ ≠ 0 n₂ : ℤ d₂ : ℕ h₂ : d₂ ≠ 0 d₁0 : 0 < ↑d₁ d₂0 : 0 < ↑d₂ n₁0 : 0 ≤ n₁ n₂0 : 0 ≤ n₂ ⊢ 0 ≤ ↑d₁
/- Copyright (c) 2019 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro -/ import Mathlib.Algebra.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 ## 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 -/ 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.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
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|
Mathlib.Data.Rat.Order.53_0.NTjR6KCugNscheB
protected theorem nonneg_add {a b} : Rat.Nonneg a → Rat.Nonneg b → Rat.Nonneg (a + b)
Mathlib_Data_Rat_Order
a✝ b✝ c a b : ℚ n₁ : ℤ d₁ : ℕ h₁ : d₁ ≠ 0 n₂ : ℤ d₂ : ℕ h₂ : d₂ ≠ 0 ⊢ Rat.Nonneg (n₁ /. ↑d₁) → Rat.Nonneg (n₂ /. ↑d₂) → Rat.Nonneg (n₁ /. ↑d₁ * (n₂ /. ↑d₂))
/- Copyright (c) 2019 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro -/ import Mathlib.Algebra.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 ## 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 -/ 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.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₁)
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
Mathlib.Data.Rat.Order.64_0.NTjR6KCugNscheB
protected theorem nonneg_mul {a b} : Rat.Nonneg a → Rat.Nonneg b → Rat.Nonneg (a * b)
Mathlib_Data_Rat_Order
a✝ b✝ c a b : ℚ n₁ : ℤ d₁ : ℕ h₁ : d₁ ≠ 0 n₂ : ℤ d₂ : ℕ h₂ : d₂ ≠ 0 d₁0 : 0 < ↑d₁ ⊢ Rat.Nonneg (n₁ /. ↑d₁) → Rat.Nonneg (n₂ /. ↑d₂) → Rat.Nonneg (n₁ /. ↑d₁ * (n₂ /. ↑d₂))
/- Copyright (c) 2019 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro -/ import Mathlib.Algebra.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 ## 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 -/ 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.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₂)
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₁)
Mathlib.Data.Rat.Order.64_0.NTjR6KCugNscheB
protected theorem nonneg_mul {a b} : Rat.Nonneg a → Rat.Nonneg b → Rat.Nonneg (a * b)
Mathlib_Data_Rat_Order
a✝ b✝ c a b : ℚ n₁ : ℤ d₁ : ℕ h₁ : d₁ ≠ 0 n₂ : ℤ d₂ : ℕ h₂ : d₂ ≠ 0 d₁0 : 0 < ↑d₁ d₂0 : 0 < ↑d₂ ⊢ Rat.Nonneg (n₁ /. ↑d₁) → Rat.Nonneg (n₂ /. ↑d₂) → Rat.Nonneg (n₁ /. ↑d₁ * (n₂ /. ↑d₂))
/- Copyright (c) 2019 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro -/ import Mathlib.Algebra.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 ## 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 -/ 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.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)]
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₂)
Mathlib.Data.Rat.Order.64_0.NTjR6KCugNscheB
protected theorem nonneg_mul {a b} : Rat.Nonneg a → Rat.Nonneg b → Rat.Nonneg (a * b)
Mathlib_Data_Rat_Order
a✝ b✝ c a b : ℚ n₁ : ℤ d₁ : ℕ h₁ : d₁ ≠ 0 n₂ : ℤ d₂ : ℕ h₂ : d₂ ≠ 0 d₁0 : 0 < ↑d₁ d₂0 : 0 < ↑d₂ ⊢ 0 ≤ n₁ → 0 ≤ n₂ → 0 ≤ n₁ * n₂
/- Copyright (c) 2019 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro -/ import Mathlib.Algebra.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 ## 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 -/ 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.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
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)]
Mathlib.Data.Rat.Order.64_0.NTjR6KCugNscheB
protected theorem nonneg_mul {a b} : Rat.Nonneg a → Rat.Nonneg b → Rat.Nonneg (a * b)
Mathlib_Data_Rat_Order
a✝ b c a : ℚ n : ℤ d : ℕ h : d ≠ 0 ⊢ Rat.Nonneg (n /. ↑d) → Rat.Nonneg (-(n /. ↑d)) → n /. ↑d = 0
/- Copyright (c) 2019 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro -/ import Mathlib.Algebra.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 ## 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 -/ 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.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)
protected theorem nonneg_antisymm {a} : Rat.Nonneg a → Rat.Nonneg (-a) → a = 0 := numDenCasesOn' a fun n d h => by
Mathlib.Data.Rat.Order.74_0.NTjR6KCugNscheB
protected theorem nonneg_antisymm {a} : Rat.Nonneg a → Rat.Nonneg (-a) → a = 0
Mathlib_Data_Rat_Order
a✝ b c a : ℚ n : ℤ d : ℕ h : d ≠ 0 d0 : 0 < ↑d ⊢ Rat.Nonneg (n /. ↑d) → Rat.Nonneg (-(n /. ↑d)) → n /. ↑d = 0
/- Copyright (c) 2019 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro -/ import Mathlib.Algebra.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 ## 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 -/ 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.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]
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)
Mathlib.Data.Rat.Order.74_0.NTjR6KCugNscheB
protected theorem nonneg_antisymm {a} : Rat.Nonneg a → Rat.Nonneg (-a) → a = 0
Mathlib_Data_Rat_Order
a✝ b c a : ℚ n : ℤ d : ℕ h : d ≠ 0 d0 : 0 < ↑d ⊢ 0 ≤ n → n ≤ 0 → n = 0
/- Copyright (c) 2019 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro -/ import Mathlib.Algebra.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 ## 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 -/ 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.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₁
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]
Mathlib.Data.Rat.Order.74_0.NTjR6KCugNscheB
protected theorem nonneg_antisymm {a} : Rat.Nonneg a → Rat.Nonneg (-a) → a = 0
Mathlib_Data_Rat_Order
a b c : ℚ ⊢ Rat.Nonneg a ∨ Rat.Nonneg (-a)
/- Copyright (c) 2019 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro -/ import Mathlib.Algebra.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 ## 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 -/ 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.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
protected theorem nonneg_total : Rat.Nonneg a ∨ Rat.Nonneg (-a) := by
Mathlib.Data.Rat.Order.82_0.NTjR6KCugNscheB
protected theorem nonneg_total : Rat.Nonneg a ∨ Rat.Nonneg (-a)
Mathlib_Data_Rat_Order
case mk' b c : ℚ n : ℤ den✝ : ℕ den_nz✝ : den✝ ≠ 0 reduced✝ : Nat.Coprime (Int.natAbs n) den✝ ⊢ Rat.Nonneg (mk' n den✝) ∨ Rat.Nonneg (-mk' n den✝)
/- Copyright (c) 2019 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro -/ import Mathlib.Algebra.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 ## 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 -/ 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.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)
protected theorem nonneg_total : Rat.Nonneg a ∨ Rat.Nonneg (-a) := by cases' a with n;
Mathlib.Data.Rat.Order.82_0.NTjR6KCugNscheB
protected theorem nonneg_total : Rat.Nonneg a ∨ Rat.Nonneg (-a)
Mathlib_Data_Rat_Order
a b c : ℚ ⊢ Decidable (Rat.Nonneg a)
/- Copyright (c) 2019 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro -/ import Mathlib.Algebra.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 ## 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 -/ 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.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
instance decidableNonneg : Decidable (Rat.Nonneg a) := by
Mathlib.Data.Rat.Order.86_0.NTjR6KCugNscheB
instance decidableNonneg : Decidable (Rat.Nonneg a)
Mathlib_Data_Rat_Order
case mk' b c : ℚ num✝ : ℤ den✝ : ℕ den_nz✝ : den✝ ≠ 0 reduced✝ : Nat.Coprime (Int.natAbs num✝) den✝ ⊢ Decidable (Rat.Nonneg (mk' num✝ den✝))
/- Copyright (c) 2019 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro -/ import Mathlib.Algebra.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 ## 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 -/ 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.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
instance decidableNonneg : Decidable (Rat.Nonneg a) := by cases a;
Mathlib.Data.Rat.Order.86_0.NTjR6KCugNscheB
instance decidableNonneg : Decidable (Rat.Nonneg a)
Mathlib_Data_Rat_Order
case mk' b c : ℚ num✝ : ℤ den✝ : ℕ den_nz✝ : den✝ ≠ 0 reduced✝ : Nat.Coprime (Int.natAbs num✝) den✝ ⊢ Decidable (0 ≤ (mk' num✝ den✝).num)
/- Copyright (c) 2019 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro -/ import Mathlib.Algebra.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 ## 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 -/ 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.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
instance decidableNonneg : Decidable (Rat.Nonneg a) := by cases a; unfold Rat.Nonneg;
Mathlib.Data.Rat.Order.86_0.NTjR6KCugNscheB
instance decidableNonneg : Decidable (Rat.Nonneg a)
Mathlib_Data_Rat_Order
a✝ b c : ℚ C : ℚ → Sort u a : ℚ H : (n : ℤ) → (d : ℕ) → (nz : d ≠ 0) → (red : Nat.Coprime (Int.natAbs n) d) → C (mk' n d) n : ℤ d : ℕ h : 0 < d h' : Nat.Coprime (Int.natAbs n) d ⊢ C (n /. ↑d)
/- Copyright (c) 2019 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro -/ import Mathlib.Algebra.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 ## 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 -/ 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.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']
/-- 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
Mathlib.Data.Rat.Order.97_0.NTjR6KCugNscheB
/-- 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
Mathlib_Data_Rat_Order
a✝ b c : ℚ C : ℚ → Sort u a : ℚ H : (n : ℤ) → (d : ℕ) → (nz : d ≠ 0) → (red : Nat.Coprime (Int.natAbs n) d) → C (mk' n d) n : ℤ d : ℕ h : 0 < d h' : Nat.Coprime (Int.natAbs n) d ⊢ C (mk' n d)
/- Copyright (c) 2019 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro -/ import Mathlib.Algebra.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 ## 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 -/ 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.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' _
/-- 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']
Mathlib.Data.Rat.Order.97_0.NTjR6KCugNscheB
/-- 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
Mathlib_Data_Rat_Order
a✝ b✝ c a b : ℚ na : ℤ da : ℕ ha : da ≠ 0 hared : Nat.Coprime (Int.natAbs na) da nb : ℤ db : ℕ hb : db ≠ 0 hbred : Nat.Coprime (Int.natAbs nb) db ⊢ mk' na da ≤ mk' nb db ↔ Rat.Nonneg (mk' nb db - mk' na da)
/- Copyright (c) 2019 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro -/ import Mathlib.Algebra.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 ## 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 -/ 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.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 ↔ _
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
Mathlib.Data.Rat.Order.109_0.NTjR6KCugNscheB
protected theorem le_iff_Nonneg (a b : ℚ) : a ≤ b ↔ Rat.Nonneg (b - a)
Mathlib_Data_Rat_Order
a✝ b✝ c a b : ℚ na : ℤ da : ℕ ha : da ≠ 0 hared : Nat.Coprime (Int.natAbs na) da nb : ℤ db : ℕ hb : db ≠ 0 hbred : Nat.Coprime (Int.natAbs nb) db ⊢ Rat.blt (mk' nb db) (mk' na da) = false ↔ Rat.Nonneg (mk' nb db - mk' na da)
/- Copyright (c) 2019 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro -/ import Mathlib.Algebra.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 ## 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 -/ 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.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
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 ↔ _
Mathlib.Data.Rat.Order.109_0.NTjR6KCugNscheB
protected theorem le_iff_Nonneg (a b : ℚ) : a ≤ b ↔ Rat.Nonneg (b - a)
Mathlib_Data_Rat_Order
a✝ b✝ c a b : ℚ na : ℤ da : ℕ ha : da ≠ 0 hared : Nat.Coprime (Int.natAbs na) da nb : ℤ db : ℕ hb : db ≠ 0 hbred : Nat.Coprime (Int.natAbs nb) db ⊢ (if (decide ((mk' nb db).num < 0) && decide (0 ≤ (mk' na da).num)) = true then true else if (mk' nb db).num = 0 then decide (0 < (mk' na da).num) else if (decide (0 < (mk' nb db).num) && decide ((mk' na da).num ≤ 0)) = true then false else decide ((mk' nb db).num * ↑(mk' na da).den < (mk' na da).num * ↑(mk' nb db).den)) = false ↔ Rat.Nonneg (mk' nb db - mk' na da)
/- Copyright (c) 2019 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro -/ import Mathlib.Algebra.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 ## 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 -/ 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.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 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]
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
Mathlib.Data.Rat.Order.109_0.NTjR6KCugNscheB
protected theorem le_iff_Nonneg (a b : ℚ) : a ≤ b ↔ Rat.Nonneg (b - a)
Mathlib_Data_Rat_Order
a✝ b✝ c a b : ℚ na : ℤ da : ℕ ha : da ≠ 0 hared : Nat.Coprime (Int.natAbs na) da nb : ℤ db : ℕ hb : db ≠ 0 hbred : Nat.Coprime (Int.natAbs nb) db ⊢ (if nb < 0 ∧ 0 ≤ na then False else if nb = 0 then na ≤ 0 else (0 < nb → 0 < na) → na * ↑db ≤ nb * ↑da) ↔ Rat.Nonneg (mk' nb db - mk' na da)
/- Copyright (c) 2019 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro -/ import Mathlib.Algebra.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 ## 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 -/ 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.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 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'
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 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]
Mathlib.Data.Rat.Order.109_0.NTjR6KCugNscheB
protected theorem le_iff_Nonneg (a b : ℚ) : a ≤ b ↔ Rat.Nonneg (b - a)
Mathlib_Data_Rat_Order
case pos a✝ b✝ c a b : ℚ na : ℤ da : ℕ ha : da ≠ 0 hared : Nat.Coprime (Int.natAbs na) da nb : ℤ db : ℕ hb : db ≠ 0 hbred : Nat.Coprime (Int.natAbs nb) db h : nb < 0 ∧ 0 ≤ na ⊢ False ↔ Rat.Nonneg (mk' nb db - mk' na da)
/- Copyright (c) 2019 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro -/ import Mathlib.Algebra.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 ## 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 -/ 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.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 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]
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 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' ·
Mathlib.Data.Rat.Order.109_0.NTjR6KCugNscheB
protected theorem le_iff_Nonneg (a b : ℚ) : a ≤ b ↔ Rat.Nonneg (b - a)
Mathlib_Data_Rat_Order
case pos a✝ b✝ c a b : ℚ na : ℤ da : ℕ ha : da ≠ 0 hared : Nat.Coprime (Int.natAbs na) da nb : ℤ db : ℕ hb : db ≠ 0 hbred : Nat.Coprime (Int.natAbs nb) db h : nb < 0 ∧ 0 ≤ na ⊢ False ↔ Rat.Nonneg (normalize ((mk' nb db).num * ↑(mk' na da).den - (mk' na da).num * ↑(mk' nb db).den) ((mk' nb db).den * (mk' na da).den))
/- Copyright (c) 2019 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro -/ import Mathlib.Algebra.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 ## 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 -/ 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.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 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 only [Rat.Nonneg, false_iff, not_le]
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 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]
Mathlib.Data.Rat.Order.109_0.NTjR6KCugNscheB
protected theorem le_iff_Nonneg (a b : ℚ) : a ≤ b ↔ Rat.Nonneg (b - a)
Mathlib_Data_Rat_Order
case pos a✝ b✝ c a b : ℚ na : ℤ da : ℕ ha : da ≠ 0 hared : Nat.Coprime (Int.natAbs na) da nb : ℤ db : ℕ hb : db ≠ 0 hbred : Nat.Coprime (Int.natAbs nb) db h : nb < 0 ∧ 0 ≤ na ⊢ (normalize (nb * ↑da - na * ↑db) (db * da)).num < 0
/- Copyright (c) 2019 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro -/ import Mathlib.Algebra.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 ## 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 -/ 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.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 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 only [Rat.Nonneg, false_iff, not_le]
simp only [normalize_eq]
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 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 only [Rat.Nonneg, false_iff, not_le]
Mathlib.Data.Rat.Order.109_0.NTjR6KCugNscheB
protected theorem le_iff_Nonneg (a b : ℚ) : a ≤ b ↔ Rat.Nonneg (b - a)
Mathlib_Data_Rat_Order
case pos a✝ b✝ c a b : ℚ na : ℤ da : ℕ ha : da ≠ 0 hared : Nat.Coprime (Int.natAbs na) da nb : ℤ db : ℕ hb : db ≠ 0 hbred : Nat.Coprime (Int.natAbs nb) db h : nb < 0 ∧ 0 ≤ na ⊢ (nb * ↑da - na * ↑db) / ↑(Nat.gcd (Int.natAbs (nb * ↑da - na * ↑db)) (db * da)) < 0
/- Copyright (c) 2019 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro -/ import Mathlib.Algebra.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 ## 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 -/ 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.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 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 only [Rat.Nonneg, false_iff, not_le] simp only [normalize_eq]
apply Int.ediv_neg'
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 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 only [Rat.Nonneg, false_iff, not_le] simp only [normalize_eq]
Mathlib.Data.Rat.Order.109_0.NTjR6KCugNscheB
protected theorem le_iff_Nonneg (a b : ℚ) : a ≤ b ↔ Rat.Nonneg (b - a)
Mathlib_Data_Rat_Order
case pos.Ha a✝ b✝ c a b : ℚ na : ℤ da : ℕ ha : da ≠ 0 hared : Nat.Coprime (Int.natAbs na) da nb : ℤ db : ℕ hb : db ≠ 0 hbred : Nat.Coprime (Int.natAbs nb) db h : nb < 0 ∧ 0 ≤ na ⊢ nb * ↑da - na * ↑db < 0
/- Copyright (c) 2019 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro -/ import Mathlib.Algebra.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 ## 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 -/ 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.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 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 only [Rat.Nonneg, false_iff, not_le] simp only [normalize_eq] apply Int.ediv_neg' ·
rw [sub_neg]
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 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 only [Rat.Nonneg, false_iff, not_le] simp only [normalize_eq] apply Int.ediv_neg' ·
Mathlib.Data.Rat.Order.109_0.NTjR6KCugNscheB
protected theorem le_iff_Nonneg (a b : ℚ) : a ≤ b ↔ Rat.Nonneg (b - a)
Mathlib_Data_Rat_Order
case pos.Ha a✝ b✝ c a b : ℚ na : ℤ da : ℕ ha : da ≠ 0 hared : Nat.Coprime (Int.natAbs na) da nb : ℤ db : ℕ hb : db ≠ 0 hbred : Nat.Coprime (Int.natAbs nb) db h : nb < 0 ∧ 0 ≤ na ⊢ nb * ↑da < na * ↑db
/- Copyright (c) 2019 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro -/ import Mathlib.Algebra.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 ## 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 -/ 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.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 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 only [Rat.Nonneg, false_iff, not_le] simp only [normalize_eq] apply Int.ediv_neg' · rw [sub_neg]
apply lt_of_lt_of_le
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 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 only [Rat.Nonneg, false_iff, not_le] simp only [normalize_eq] apply Int.ediv_neg' · rw [sub_neg]
Mathlib.Data.Rat.Order.109_0.NTjR6KCugNscheB
protected theorem le_iff_Nonneg (a b : ℚ) : a ≤ b ↔ Rat.Nonneg (b - a)
Mathlib_Data_Rat_Order
case pos.Ha.a a✝ b✝ c a b : ℚ na : ℤ da : ℕ ha : da ≠ 0 hared : Nat.Coprime (Int.natAbs na) da nb : ℤ db : ℕ hb : db ≠ 0 hbred : Nat.Coprime (Int.natAbs nb) db h : nb < 0 ∧ 0 ≤ na ⊢ nb * ↑da < ?pos.Ha.b✝
/- Copyright (c) 2019 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro -/ import Mathlib.Algebra.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 ## 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 -/ 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.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 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 only [Rat.Nonneg, false_iff, not_le] simp only [normalize_eq] apply Int.ediv_neg' · rw [sub_neg] apply lt_of_lt_of_le ·
apply mul_neg_of_neg_of_pos h.1
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 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 only [Rat.Nonneg, false_iff, not_le] simp only [normalize_eq] apply Int.ediv_neg' · rw [sub_neg] apply lt_of_lt_of_le ·
Mathlib.Data.Rat.Order.109_0.NTjR6KCugNscheB
protected theorem le_iff_Nonneg (a b : ℚ) : a ≤ b ↔ Rat.Nonneg (b - a)
Mathlib_Data_Rat_Order
case pos.Ha.a a✝ b✝ c a b : ℚ na : ℤ da : ℕ ha : da ≠ 0 hared : Nat.Coprime (Int.natAbs na) da nb : ℤ db : ℕ hb : db ≠ 0 hbred : Nat.Coprime (Int.natAbs nb) db h : nb < 0 ∧ 0 ≤ na ⊢ 0 < ↑da
/- Copyright (c) 2019 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro -/ import Mathlib.Algebra.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 ## 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 -/ 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.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 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 only [Rat.Nonneg, false_iff, not_le] simp only [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]
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 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 only [Rat.Nonneg, false_iff, not_le] simp only [normalize_eq] apply Int.ediv_neg' · rw [sub_neg] apply lt_of_lt_of_le · apply mul_neg_of_neg_of_pos h.1
Mathlib.Data.Rat.Order.109_0.NTjR6KCugNscheB
protected theorem le_iff_Nonneg (a b : ℚ) : a ≤ b ↔ Rat.Nonneg (b - a)
Mathlib_Data_Rat_Order
case pos.Ha.a a✝ b✝ c a b : ℚ na : ℤ da : ℕ ha : da ≠ 0 hared : Nat.Coprime (Int.natAbs na) da nb : ℤ db : ℕ hb : db ≠ 0 hbred : Nat.Coprime (Int.natAbs nb) db h : nb < 0 ∧ 0 ≤ na ⊢ 0 ≤ na * ↑db
/- Copyright (c) 2019 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro -/ import Mathlib.Algebra.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 ## 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 -/ 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.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 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 only [Rat.Nonneg, false_iff, not_le] simp only [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 _)
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 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 only [Rat.Nonneg, false_iff, not_le] simp only [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] ·
Mathlib.Data.Rat.Order.109_0.NTjR6KCugNscheB
protected theorem le_iff_Nonneg (a b : ℚ) : a ≤ b ↔ Rat.Nonneg (b - a)
Mathlib_Data_Rat_Order
case pos.Hb a✝ b✝ c a b : ℚ na : ℤ da : ℕ ha : da ≠ 0 hared : Nat.Coprime (Int.natAbs na) da nb : ℤ db : ℕ hb : db ≠ 0 hbred : Nat.Coprime (Int.natAbs nb) db h : nb < 0 ∧ 0 ≤ na ⊢ 0 < ↑(Nat.gcd (Int.natAbs (nb * ↑da - na * ↑db)) (db * da))
/- Copyright (c) 2019 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro -/ import Mathlib.Algebra.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 ## 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 -/ 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.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 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 only [Rat.Nonneg, false_iff, not_le] simp only [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]
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 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 only [Rat.Nonneg, false_iff, not_le] simp only [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 _) ·
Mathlib.Data.Rat.Order.109_0.NTjR6KCugNscheB
protected theorem le_iff_Nonneg (a b : ℚ) : a ≤ b ↔ Rat.Nonneg (b - a)
Mathlib_Data_Rat_Order
case pos.Hb a✝ b✝ c a b : ℚ na : ℤ da : ℕ ha : da ≠ 0 hared : Nat.Coprime (Int.natAbs na) da nb : ℤ db : ℕ hb : db ≠ 0 hbred : Nat.Coprime (Int.natAbs nb) db h : nb < 0 ∧ 0 ≤ na ⊢ 0 < Nat.gcd (Int.natAbs (nb * ↑da - na * ↑db)) (db * da)
/- Copyright (c) 2019 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro -/ import Mathlib.Algebra.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 ## 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 -/ 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.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 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 only [Rat.Nonneg, false_iff, not_le] simp only [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
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 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 only [Rat.Nonneg, false_iff, not_le] simp only [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]
Mathlib.Data.Rat.Order.109_0.NTjR6KCugNscheB
protected theorem le_iff_Nonneg (a b : ℚ) : a ≤ b ↔ Rat.Nonneg (b - a)
Mathlib_Data_Rat_Order
case pos.Hb.npos a✝ b✝ c a b : ℚ na : ℤ da : ℕ ha : da ≠ 0 hared : Nat.Coprime (Int.natAbs na) da nb : ℤ db : ℕ hb : db ≠ 0 hbred : Nat.Coprime (Int.natAbs nb) db h : nb < 0 ∧ 0 ≤ na ⊢ 0 < db * da
/- Copyright (c) 2019 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro -/ import Mathlib.Algebra.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 ## 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 -/ 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.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 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 only [Rat.Nonneg, false_iff, not_le] simp only [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
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 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 only [Rat.Nonneg, false_iff, not_le] simp only [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
Mathlib.Data.Rat.Order.109_0.NTjR6KCugNscheB
protected theorem le_iff_Nonneg (a b : ℚ) : a ≤ b ↔ Rat.Nonneg (b - a)
Mathlib_Data_Rat_Order
case pos.Hb.npos.ha a✝ b✝ c a b : ℚ na : ℤ da : ℕ ha : da ≠ 0 hared : Nat.Coprime (Int.natAbs na) da nb : ℤ db : ℕ hb : db ≠ 0 hbred : Nat.Coprime (Int.natAbs nb) db h : nb < 0 ∧ 0 ≤ na ⊢ 0 < db
/- Copyright (c) 2019 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro -/ import Mathlib.Algebra.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 ## 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 -/ 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.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 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 only [Rat.Nonneg, false_iff, not_le] simp only [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]
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 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 only [Rat.Nonneg, false_iff, not_le] simp only [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 <;>
Mathlib.Data.Rat.Order.109_0.NTjR6KCugNscheB
protected theorem le_iff_Nonneg (a b : ℚ) : a ≤ b ↔ Rat.Nonneg (b - a)
Mathlib_Data_Rat_Order
case pos.Hb.npos.hb a✝ b✝ c a b : ℚ na : ℤ da : ℕ ha : da ≠ 0 hared : Nat.Coprime (Int.natAbs na) da nb : ℤ db : ℕ hb : db ≠ 0 hbred : Nat.Coprime (Int.natAbs nb) db h : nb < 0 ∧ 0 ≤ na ⊢ 0 < da
/- Copyright (c) 2019 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro -/ import Mathlib.Algebra.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 ## 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 -/ 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.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 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 only [Rat.Nonneg, false_iff, not_le] simp only [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]
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 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 only [Rat.Nonneg, false_iff, not_le] simp only [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 <;>
Mathlib.Data.Rat.Order.109_0.NTjR6KCugNscheB
protected theorem le_iff_Nonneg (a b : ℚ) : a ≤ b ↔ Rat.Nonneg (b - a)
Mathlib_Data_Rat_Order
case pos a✝ b✝ c a b : ℚ na : ℤ da : ℕ ha : da ≠ 0 hared : Nat.Coprime (Int.natAbs na) da nb : ℤ db : ℕ hb : db ≠ 0 hbred : Nat.Coprime (Int.natAbs nb) db h : ¬(nb < 0 ∧ 0 ≤ na) h' : nb = 0 ⊢ na ≤ 0 ↔ Rat.Nonneg (mk' nb db - mk' na da)
/- Copyright (c) 2019 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro -/ import Mathlib.Algebra.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 ## 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 -/ 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.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 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 only [Rat.Nonneg, false_iff, not_le] simp only [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'
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 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 only [Rat.Nonneg, false_iff, not_le] simp only [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] ·
Mathlib.Data.Rat.Order.109_0.NTjR6KCugNscheB
protected theorem le_iff_Nonneg (a b : ℚ) : a ≤ b ↔ Rat.Nonneg (b - a)
Mathlib_Data_Rat_Order
case pos a✝ b✝ c a b : ℚ na : ℤ da : ℕ ha : da ≠ 0 hared : Nat.Coprime (Int.natAbs na) da nb : ℤ db : ℕ hb : db ≠ 0 hbred : Nat.Coprime (Int.natAbs nb) db h : ¬(nb < 0 ∧ 0 ≤ na) h' : nb = 0 ⊢ na ≤ 0 ↔ Rat.Nonneg (mk' nb db - mk' na da)
/- Copyright (c) 2019 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro -/ import Mathlib.Algebra.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 ## 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 -/ 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.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 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 only [Rat.Nonneg, false_iff, not_le] simp only [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]
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 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 only [Rat.Nonneg, false_iff, not_le] simp only [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'
Mathlib.Data.Rat.Order.109_0.NTjR6KCugNscheB
protected theorem le_iff_Nonneg (a b : ℚ) : a ≤ b ↔ Rat.Nonneg (b - a)
Mathlib_Data_Rat_Order
case neg a✝ b✝ c a b : ℚ na : ℤ da : ℕ ha : da ≠ 0 hared : Nat.Coprime (Int.natAbs na) da nb : ℤ db : ℕ hb : db ≠ 0 hbred : Nat.Coprime (Int.natAbs nb) db h : ¬(nb < 0 ∧ 0 ≤ na) h' : ¬nb = 0 ⊢ (0 < nb → 0 < na) → na * ↑db ≤ nb * ↑da ↔ Rat.Nonneg (mk' nb db - mk' na da)
/- Copyright (c) 2019 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro -/ import Mathlib.Algebra.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 ## 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 -/ 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.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 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 only [Rat.Nonneg, false_iff, not_le] simp only [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]
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 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 only [Rat.Nonneg, false_iff, not_le] simp only [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] ·
Mathlib.Data.Rat.Order.109_0.NTjR6KCugNscheB
protected theorem le_iff_Nonneg (a b : ℚ) : a ≤ b ↔ Rat.Nonneg (b - a)
Mathlib_Data_Rat_Order
case neg a✝ b✝ c a b : ℚ na : ℤ da : ℕ ha : da ≠ 0 hared : Nat.Coprime (Int.natAbs na) da nb : ℤ db : ℕ hb : db ≠ 0 hbred : Nat.Coprime (Int.natAbs nb) db h : ¬(nb < 0 ∧ 0 ≤ na) h' : ¬nb = 0 ⊢ (0 < nb → 0 < na) → na * ↑db ≤ nb * ↑da ↔ 0 ≤ (nb * ↑da - na * ↑db) / ↑(Nat.gcd (Int.natAbs (nb * ↑da - na * ↑db)) (db * da))
/- Copyright (c) 2019 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro -/ import Mathlib.Algebra.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 ## 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 -/ 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.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 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 only [Rat.Nonneg, false_iff, not_le] simp only [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 _ => ?_⟩
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 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 only [Rat.Nonneg, false_iff, not_le] simp only [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]
Mathlib.Data.Rat.Order.109_0.NTjR6KCugNscheB
protected theorem le_iff_Nonneg (a b : ℚ) : a ≤ b ↔ Rat.Nonneg (b - a)
Mathlib_Data_Rat_Order
case neg.refine_1 a✝ b✝ c a b : ℚ na : ℤ da : ℕ ha : da ≠ 0 hared : Nat.Coprime (Int.natAbs na) da nb : ℤ db : ℕ hb : db ≠ 0 hbred : Nat.Coprime (Int.natAbs nb) db h : ¬(nb < 0 ∧ 0 ≤ na) h' : ¬nb = 0 H : (0 < nb → 0 < na) → na * ↑db ≤ nb * ↑da ⊢ 0 ≤ (nb * ↑da - na * ↑db) / ↑(Nat.gcd (Int.natAbs (nb * ↑da - na * ↑db)) (db * da))
/- Copyright (c) 2019 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro -/ import Mathlib.Algebra.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 ## 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 -/ 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.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 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 only [Rat.Nonneg, false_iff, not_le] simp only [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 _)
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 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 only [Rat.Nonneg, false_iff, not_le] simp only [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 _ => ?_⟩ ·
Mathlib.Data.Rat.Order.109_0.NTjR6KCugNscheB
protected theorem le_iff_Nonneg (a b : ℚ) : a ≤ b ↔ Rat.Nonneg (b - a)
Mathlib_Data_Rat_Order
case neg.refine_1 a✝ b✝ c a b : ℚ na : ℤ da : ℕ ha : da ≠ 0 hared : Nat.Coprime (Int.natAbs na) da nb : ℤ db : ℕ hb : db ≠ 0 hbred : Nat.Coprime (Int.natAbs nb) db h : ¬(nb < 0 ∧ 0 ≤ na) h' : ¬nb = 0 H : (0 < nb → 0 < na) → na * ↑db ≤ nb * ↑da ⊢ 0 ≤ nb * ↑da - na * ↑db
/- Copyright (c) 2019 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro -/ import Mathlib.Algebra.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 ## 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 -/ 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.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 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 only [Rat.Nonneg, false_iff, not_le] simp only [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]
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 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 only [Rat.Nonneg, false_iff, not_le] simp only [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 _)
Mathlib.Data.Rat.Order.109_0.NTjR6KCugNscheB
protected theorem le_iff_Nonneg (a b : ℚ) : a ≤ b ↔ Rat.Nonneg (b - a)
Mathlib_Data_Rat_Order
case neg.refine_1 a✝ b✝ c a b : ℚ na : ℤ da : ℕ ha : da ≠ 0 hared : Nat.Coprime (Int.natAbs na) da nb : ℤ db : ℕ hb : db ≠ 0 hbred : Nat.Coprime (Int.natAbs nb) db h : ¬(nb < 0 ∧ 0 ≤ na) h' : ¬nb = 0 H : (0 < nb → 0 < na) → na * ↑db ≤ nb * ↑da ⊢ na * ↑db ≤ nb * ↑da
/- Copyright (c) 2019 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro -/ import Mathlib.Algebra.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 ## 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 -/ 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.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 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 only [Rat.Nonneg, false_iff, not_le] simp only [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
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 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 only [Rat.Nonneg, false_iff, not_le] simp only [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]
Mathlib.Data.Rat.Order.109_0.NTjR6KCugNscheB
protected theorem le_iff_Nonneg (a b : ℚ) : a ≤ b ↔ Rat.Nonneg (b - a)
Mathlib_Data_Rat_Order
case neg.refine_1 a✝ b✝ c a b : ℚ na : ℤ da : ℕ ha : da ≠ 0 hared : Nat.Coprime (Int.natAbs na) da nb : ℤ db : ℕ hb : db ≠ 0 hbred : Nat.Coprime (Int.natAbs nb) db h' : ¬nb = 0 H : (0 < nb → 0 < na) → na * ↑db ≤ nb * ↑da h : nb < 0 → na < 0 ⊢ na * ↑db ≤ nb * ↑da
/- Copyright (c) 2019 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro -/ import Mathlib.Algebra.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 ## 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 -/ 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.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 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 only [Rat.Nonneg, false_iff, not_le] simp only [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'
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 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 only [Rat.Nonneg, false_iff, not_le] simp only [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
Mathlib.Data.Rat.Order.109_0.NTjR6KCugNscheB
protected theorem le_iff_Nonneg (a b : ℚ) : a ≤ b ↔ Rat.Nonneg (b - a)
Mathlib_Data_Rat_Order
case neg.refine_1.inl a✝ b✝ c a b : ℚ na : ℤ da : ℕ ha : da ≠ 0 hared : Nat.Coprime (Int.natAbs na) da nb : ℤ db : ℕ hb✝ : db ≠ 0 hbred : Nat.Coprime (Int.natAbs nb) db h' : ¬nb = 0 H : (0 < nb → 0 < na) → na * ↑db ≤ nb * ↑da h : nb < 0 → na < 0 hb : nb < 0 ⊢ na * ↑db ≤ nb * ↑da
/- Copyright (c) 2019 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro -/ import Mathlib.Algebra.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 ## 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 -/ 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.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 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 only [Rat.Nonneg, false_iff, not_le] simp only [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
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 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 only [Rat.Nonneg, false_iff, not_le] simp only [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' ·
Mathlib.Data.Rat.Order.109_0.NTjR6KCugNscheB
protected theorem le_iff_Nonneg (a b : ℚ) : a ≤ b ↔ Rat.Nonneg (b - a)
Mathlib_Data_Rat_Order
case neg.refine_1.inl a✝ b✝ c a b : ℚ na : ℤ da : ℕ ha : da ≠ 0 hared : Nat.Coprime (Int.natAbs na) da nb : ℤ db : ℕ hb✝ : db ≠ 0 hbred : Nat.Coprime (Int.natAbs nb) db h' : ¬nb = 0 H : (0 < nb → 0 < na) → na * ↑db ≤ nb * ↑da h : nb < 0 → na < 0 hb : nb < 0 ⊢ 0 < nb → 0 < na
/- Copyright (c) 2019 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro -/ import Mathlib.Algebra.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 ## 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 -/ 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.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 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 only [Rat.Nonneg, false_iff, not_le] simp only [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'
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 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 only [Rat.Nonneg, false_iff, not_le] simp only [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
Mathlib.Data.Rat.Order.109_0.NTjR6KCugNscheB
protected theorem le_iff_Nonneg (a b : ℚ) : a ≤ b ↔ Rat.Nonneg (b - a)
Mathlib_Data_Rat_Order
case neg.refine_1.inl a✝ b✝ c a b : ℚ na : ℤ da : ℕ ha : da ≠ 0 hared : Nat.Coprime (Int.natAbs na) da nb : ℤ db : ℕ hb✝ : db ≠ 0 hbred : Nat.Coprime (Int.natAbs nb) db h' : ¬nb = 0 H : (0 < nb → 0 < na) → na * ↑db ≤ nb * ↑da h : nb < 0 → na < 0 hb : nb < 0 H' : 0 < nb ⊢ 0 < na
/- Copyright (c) 2019 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro -/ import Mathlib.Algebra.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 ## 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 -/ 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.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 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 only [Rat.Nonneg, false_iff, not_le] simp only [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
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 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 only [Rat.Nonneg, false_iff, not_le] simp only [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'
Mathlib.Data.Rat.Order.109_0.NTjR6KCugNscheB
protected theorem le_iff_Nonneg (a b : ℚ) : a ≤ b ↔ Rat.Nonneg (b - a)
Mathlib_Data_Rat_Order
case neg.refine_1.inr a✝ b✝ c a b : ℚ na : ℤ da : ℕ ha : da ≠ 0 hared : Nat.Coprime (Int.natAbs na) da nb : ℤ db : ℕ hb✝ : db ≠ 0 hbred : Nat.Coprime (Int.natAbs nb) db h' : ¬nb = 0 H : (0 < nb → 0 < na) → na * ↑db ≤ nb * ↑da h : nb < 0 → na < 0 hb : 0 < nb ⊢ na * ↑db ≤ nb * ↑da
/- Copyright (c) 2019 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro -/ import Mathlib.Algebra.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 ## 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 -/ 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.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 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 only [Rat.Nonneg, false_iff, not_le] simp only [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
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 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 only [Rat.Nonneg, false_iff, not_le] simp only [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 ·
Mathlib.Data.Rat.Order.109_0.NTjR6KCugNscheB
protected theorem le_iff_Nonneg (a b : ℚ) : a ≤ b ↔ Rat.Nonneg (b - a)
Mathlib_Data_Rat_Order
case neg.refine_1.inr.inl a✝ b✝ c a b : ℚ na : ℤ da : ℕ ha✝ : da ≠ 0 hared : Nat.Coprime (Int.natAbs na) da nb : ℤ db : ℕ hb✝ : db ≠ 0 hbred : Nat.Coprime (Int.natAbs nb) db h' : ¬nb = 0 H : (0 < nb → 0 < na) → na * ↑db ≤ nb * ↑da h : nb < 0 → na < 0 hb : 0 < nb ha : na ≤ 0 ⊢ na * ↑db ≤ nb * ↑da
/- Copyright (c) 2019 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro -/ import Mathlib.Algebra.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 ## 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 -/ 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.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 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 only [Rat.Nonneg, false_iff, not_le] simp only [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 _)
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 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 only [Rat.Nonneg, false_iff, not_le] simp only [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 ·
Mathlib.Data.Rat.Order.109_0.NTjR6KCugNscheB
protected theorem le_iff_Nonneg (a b : ℚ) : a ≤ b ↔ Rat.Nonneg (b - a)
Mathlib_Data_Rat_Order
case neg.refine_1.inr.inl a✝ b✝ c a b : ℚ na : ℤ da : ℕ ha✝ : da ≠ 0 hared : Nat.Coprime (Int.natAbs na) da nb : ℤ db : ℕ hb✝ : db ≠ 0 hbred : Nat.Coprime (Int.natAbs nb) db h' : ¬nb = 0 H : (0 < nb → 0 < na) → na * ↑db ≤ nb * ↑da h : nb < 0 → na < 0 hb : 0 < nb ha : na ≤ 0 ⊢ 0 ≤ nb * ↑da
/- Copyright (c) 2019 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro -/ import Mathlib.Algebra.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 ## 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 -/ 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.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 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 only [Rat.Nonneg, false_iff, not_le] simp only [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 _)
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 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 only [Rat.Nonneg, false_iff, not_le] simp only [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 _)
Mathlib.Data.Rat.Order.109_0.NTjR6KCugNscheB
protected theorem le_iff_Nonneg (a b : ℚ) : a ≤ b ↔ Rat.Nonneg (b - a)
Mathlib_Data_Rat_Order
case neg.refine_1.inr.inr a✝ b✝ c a b : ℚ na : ℤ da : ℕ ha✝ : da ≠ 0 hared : Nat.Coprime (Int.natAbs na) da nb : ℤ db : ℕ hb✝ : db ≠ 0 hbred : Nat.Coprime (Int.natAbs nb) db h' : ¬nb = 0 H : (0 < nb → 0 < na) → na * ↑db ≤ nb * ↑da h : nb < 0 → na < 0 hb : 0 < nb ha : 0 < na ⊢ na * ↑db ≤ nb * ↑da
/- Copyright (c) 2019 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro -/ import Mathlib.Algebra.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 ## 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 -/ 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.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 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 only [Rat.Nonneg, false_iff, not_le] simp only [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)
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 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 only [Rat.Nonneg, false_iff, not_le] simp only [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 _) ·
Mathlib.Data.Rat.Order.109_0.NTjR6KCugNscheB
protected theorem le_iff_Nonneg (a b : ℚ) : a ≤ b ↔ Rat.Nonneg (b - a)
Mathlib_Data_Rat_Order
case neg.refine_2 a✝ b✝ c a b : ℚ na : ℤ da : ℕ ha : da ≠ 0 hared : Nat.Coprime (Int.natAbs na) da nb : ℤ db : ℕ hb : db ≠ 0 hbred : Nat.Coprime (Int.natAbs nb) db h : ¬(nb < 0 ∧ 0 ≤ na) h' : ¬nb = 0 H : 0 ≤ (nb * ↑da - na * ↑db) / ↑(Nat.gcd (Int.natAbs (nb * ↑da - na * ↑db)) (db * da)) x✝ : 0 < nb → 0 < na ⊢ na * ↑db ≤ nb * ↑da
/- Copyright (c) 2019 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro -/ import Mathlib.Algebra.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 ## 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 -/ 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.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 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 only [Rat.Nonneg, false_iff, not_le] simp only [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]
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 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 only [Rat.Nonneg, false_iff, not_le] simp only [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) ·
Mathlib.Data.Rat.Order.109_0.NTjR6KCugNscheB
protected theorem le_iff_Nonneg (a b : ℚ) : a ≤ b ↔ Rat.Nonneg (b - a)
Mathlib_Data_Rat_Order
case neg.refine_2 a✝ b✝ c a b : ℚ na : ℤ da : ℕ ha : da ≠ 0 hared : Nat.Coprime (Int.natAbs na) da nb : ℤ db : ℕ hb : db ≠ 0 hbred : Nat.Coprime (Int.natAbs nb) db h : ¬(nb < 0 ∧ 0 ≤ na) h' : ¬nb = 0 H : 0 ≤ (nb * ↑da - na * ↑db) / ↑(Nat.gcd (Int.natAbs (nb * ↑da - na * ↑db)) (db * da)) x✝ : 0 < nb → 0 < na ⊢ 0 ≤ nb * ↑da - na * ↑db
/- Copyright (c) 2019 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro -/ import Mathlib.Algebra.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 ## 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 -/ 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.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 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 only [Rat.Nonneg, false_iff, not_le] simp only [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
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 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 only [Rat.Nonneg, false_iff, not_le] simp only [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]
Mathlib.Data.Rat.Order.109_0.NTjR6KCugNscheB
protected theorem le_iff_Nonneg (a b : ℚ) : a ≤ b ↔ Rat.Nonneg (b - a)
Mathlib_Data_Rat_Order
case neg.refine_2 a✝ b✝ c a b : ℚ na : ℤ da : ℕ ha : da ≠ 0 hared : Nat.Coprime (Int.natAbs na) da nb : ℤ db : ℕ hb : db ≠ 0 hbred : Nat.Coprime (Int.natAbs nb) db h : ¬(nb < 0 ∧ 0 ≤ na) h' : ¬nb = 0 x✝ : 0 < nb → 0 < na H : nb * ↑da - na * ↑db < 0 ⊢ (nb * ↑da - na * ↑db) / ↑(Nat.gcd (Int.natAbs (nb * ↑da - na * ↑db)) (db * da)) < 0
/- Copyright (c) 2019 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro -/ import Mathlib.Algebra.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 ## 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 -/ 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.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 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 only [Rat.Nonneg, false_iff, not_le] simp only [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
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 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 only [Rat.Nonneg, false_iff, not_le] simp only [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
Mathlib.Data.Rat.Order.109_0.NTjR6KCugNscheB
protected theorem le_iff_Nonneg (a b : ℚ) : a ≤ b ↔ Rat.Nonneg (b - a)
Mathlib_Data_Rat_Order
case neg.refine_2 a✝ b✝ c a b : ℚ na : ℤ da : ℕ ha : da ≠ 0 hared : Nat.Coprime (Int.natAbs na) da nb : ℤ db : ℕ hb : db ≠ 0 hbred : Nat.Coprime (Int.natAbs nb) db h : ¬(nb < 0 ∧ 0 ≤ na) h' : ¬nb = 0 x✝ : 0 < nb → 0 < na H : nb * ↑da - na * ↑db < 0 ⊢ 0 < ↑(Nat.gcd (Int.natAbs (nb * ↑da - na * ↑db)) (db * da))
/- Copyright (c) 2019 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro -/ import Mathlib.Algebra.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 ## 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 -/ 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.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 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 only [Rat.Nonneg, false_iff, not_le] simp only [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]
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 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 only [Rat.Nonneg, false_iff, not_le] simp only [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
Mathlib.Data.Rat.Order.109_0.NTjR6KCugNscheB
protected theorem le_iff_Nonneg (a b : ℚ) : a ≤ b ↔ Rat.Nonneg (b - a)
Mathlib_Data_Rat_Order
case neg.refine_2 a✝ b✝ c a b : ℚ na : ℤ da : ℕ ha : da ≠ 0 hared : Nat.Coprime (Int.natAbs na) da nb : ℤ db : ℕ hb : db ≠ 0 hbred : Nat.Coprime (Int.natAbs nb) db h : ¬(nb < 0 ∧ 0 ≤ na) h' : ¬nb = 0 x✝ : 0 < nb → 0 < na H : nb * ↑da - na * ↑db < 0 ⊢ 0 < Nat.gcd (Int.natAbs (nb * ↑da - na * ↑db)) (db * da)
/- Copyright (c) 2019 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro -/ import Mathlib.Algebra.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 ## 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 -/ 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.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 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 only [Rat.Nonneg, false_iff, not_le] simp only [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
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 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 only [Rat.Nonneg, false_iff, not_le] simp only [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]
Mathlib.Data.Rat.Order.109_0.NTjR6KCugNscheB
protected theorem le_iff_Nonneg (a b : ℚ) : a ≤ b ↔ Rat.Nonneg (b - a)
Mathlib_Data_Rat_Order
case neg.refine_2.npos a✝ b✝ c a b : ℚ na : ℤ da : ℕ ha : da ≠ 0 hared : Nat.Coprime (Int.natAbs na) da nb : ℤ db : ℕ hb : db ≠ 0 hbred : Nat.Coprime (Int.natAbs nb) db h : ¬(nb < 0 ∧ 0 ≤ na) h' : ¬nb = 0 x✝ : 0 < nb → 0 < na H : nb * ↑da - na * ↑db < 0 ⊢ 0 < db * da
/- Copyright (c) 2019 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro -/ import Mathlib.Algebra.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 ## 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 -/ 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.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 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 only [Rat.Nonneg, false_iff, not_le] simp only [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
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 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 only [Rat.Nonneg, false_iff, not_le] simp only [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
Mathlib.Data.Rat.Order.109_0.NTjR6KCugNscheB
protected theorem le_iff_Nonneg (a b : ℚ) : a ≤ b ↔ Rat.Nonneg (b - a)
Mathlib_Data_Rat_Order
case neg.refine_2.npos.ha a✝ b✝ c a b : ℚ na : ℤ da : ℕ ha : da ≠ 0 hared : Nat.Coprime (Int.natAbs na) da nb : ℤ db : ℕ hb : db ≠ 0 hbred : Nat.Coprime (Int.natAbs nb) db h : ¬(nb < 0 ∧ 0 ≤ na) h' : ¬nb = 0 x✝ : 0 < nb → 0 < na H : nb * ↑da - na * ↑db < 0 ⊢ 0 < db
/- Copyright (c) 2019 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro -/ import Mathlib.Algebra.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 ## 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 -/ 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.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 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 only [Rat.Nonneg, false_iff, not_le] simp only [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_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 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 only [Rat.Nonneg, false_iff, not_le] simp only [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 <;>
Mathlib.Data.Rat.Order.109_0.NTjR6KCugNscheB
protected theorem le_iff_Nonneg (a b : ℚ) : a ≤ b ↔ Rat.Nonneg (b - a)
Mathlib_Data_Rat_Order
case neg.refine_2.npos.hb a✝ b✝ c a b : ℚ na : ℤ da : ℕ ha : da ≠ 0 hared : Nat.Coprime (Int.natAbs na) da nb : ℤ db : ℕ hb : db ≠ 0 hbred : Nat.Coprime (Int.natAbs nb) db h : ¬(nb < 0 ∧ 0 ≤ na) h' : ¬nb = 0 x✝ : 0 < nb → 0 < na H : nb * ↑da - na * ↑db < 0 ⊢ 0 < da
/- Copyright (c) 2019 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro -/ import Mathlib.Algebra.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 ## 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 -/ 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.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 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 only [Rat.Nonneg, false_iff, not_le] simp only [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_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 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 only [Rat.Nonneg, false_iff, not_le] simp only [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 <;>
Mathlib.Data.Rat.Order.109_0.NTjR6KCugNscheB
protected theorem le_iff_Nonneg (a b : ℚ) : a ≤ b ↔ Rat.Nonneg (b - a)
Mathlib_Data_Rat_Order
a✝ b✝ c✝ : ℚ a b c d : ℤ b0 : 0 < b d0 : 0 < d ⊢ a /. b ≤ c /. d ↔ a * d ≤ c * b
/- Copyright (c) 2019 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro -/ import Mathlib.Algebra.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 ## 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 -/ 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.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 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 only [Rat.Nonneg, false_iff, not_le] simp only [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]
protected theorem le_def {a b c d : ℤ} (b0 : 0 < b) (d0 : 0 < d) : a /. b ≤ c /. d ↔ a * d ≤ c * b := by
Mathlib.Data.Rat.Order.151_0.NTjR6KCugNscheB
protected theorem le_def {a b c d : ℤ} (b0 : 0 < b) (d0 : 0 < d) : a /. b ≤ c /. d ↔ a * d ≤ c * b
Mathlib_Data_Rat_Order
a✝ b✝ c✝ : ℚ a b c d : ℤ b0 : 0 < b d0 : 0 < d ⊢ Rat.Nonneg (c /. d - a /. b) ↔ a * d ≤ c * b
/- Copyright (c) 2019 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro -/ import Mathlib.Algebra.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 ## 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 -/ 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.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 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 only [Rat.Nonneg, false_iff, not_le] simp only [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 _ ↔ _
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]
Mathlib.Data.Rat.Order.151_0.NTjR6KCugNscheB
protected theorem le_def {a b c d : ℤ} (b0 : 0 < b) (d0 : 0 < d) : a /. b ≤ c /. d ↔ a * d ≤ c * b
Mathlib_Data_Rat_Order
a✝ b✝ c✝ : ℚ a b c d : ℤ b0 : 0 < b d0 : 0 < d ⊢ Rat.Nonneg (c /. d - a /. b) ↔ a * d ≤ c * b
/- Copyright (c) 2019 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro -/ import Mathlib.Algebra.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 ## 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 -/ 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.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 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 only [Rat.Nonneg, false_iff, not_le] simp only [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]
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 _ ↔ _
Mathlib.Data.Rat.Order.151_0.NTjR6KCugNscheB
protected theorem le_def {a b c d : ℤ} (b0 : 0 < b) (d0 : 0 < d) : a /. b ≤ c /. d ↔ a * d ≤ c * b
Mathlib_Data_Rat_Order
a✝ b✝ c✝ : ℚ a b c d : ℤ b0 : 0 < b d0 : 0 < d ⊢ Rat.Nonneg (c /. d - a /. b) ↔ 0 ≤ c * b - a * d
/- Copyright (c) 2019 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro -/ import Mathlib.Algebra.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 ## 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 -/ 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.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 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 only [Rat.Nonneg, false_iff, not_le] simp only [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]
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]
Mathlib.Data.Rat.Order.151_0.NTjR6KCugNscheB
protected theorem le_def {a b c d : ℤ} (b0 : 0 < b) (d0 : 0 < d) : a /. b ≤ c /. d ↔ a * d ≤ c * b
Mathlib_Data_Rat_Order
a b c : ℚ ⊢ a ≤ a
/- Copyright (c) 2019 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro -/ import Mathlib.Algebra.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 ## 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 -/ 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.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 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 only [Rat.Nonneg, false_iff, not_le] simp only [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]
protected theorem le_refl : a ≤ a := by
Mathlib.Data.Rat.Order.159_0.NTjR6KCugNscheB
protected theorem le_refl : a ≤ a
Mathlib_Data_Rat_Order
a b c : ℚ ⊢ Rat.Nonneg (a - a)
/- Copyright (c) 2019 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro -/ import Mathlib.Algebra.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 ## 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 -/ 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.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 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 only [Rat.Nonneg, false_iff, not_le] simp only [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)
protected theorem le_refl : a ≤ a := by rw [Rat.le_iff_Nonneg]
Mathlib.Data.Rat.Order.159_0.NTjR6KCugNscheB
protected theorem le_refl : a ≤ a
Mathlib_Data_Rat_Order
a b c : ℚ ⊢ Rat.Nonneg (a - a)
/- Copyright (c) 2019 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro -/ import Mathlib.Algebra.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 ## 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 -/ 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.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 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 only [Rat.Nonneg, false_iff, not_le] simp only [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]
protected theorem le_refl : a ≤ a := by rw [Rat.le_iff_Nonneg] show Rat.Nonneg (a - a)
Mathlib.Data.Rat.Order.159_0.NTjR6KCugNscheB
protected theorem le_refl : a ≤ a
Mathlib_Data_Rat_Order
a b c : ℚ ⊢ Rat.Nonneg 0
/- Copyright (c) 2019 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro -/ import Mathlib.Algebra.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 ## 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 -/ 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.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 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 only [Rat.Nonneg, false_iff, not_le] simp only [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 : ℤ)
protected theorem le_refl : a ≤ a := by rw [Rat.le_iff_Nonneg] show Rat.Nonneg (a - a) rw [sub_self]
Mathlib.Data.Rat.Order.159_0.NTjR6KCugNscheB
protected theorem le_refl : a ≤ a
Mathlib_Data_Rat_Order
a b c : ℚ ⊢ a ≤ b ∨ b ≤ a
/- Copyright (c) 2019 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro -/ import Mathlib.Algebra.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 ## 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 -/ 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.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 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 only [Rat.Nonneg, false_iff, not_le] simp only [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)
protected theorem le_total : a ≤ b ∨ b ≤ a := by
Mathlib.Data.Rat.Order.166_0.NTjR6KCugNscheB
protected theorem le_total : a ≤ b ∨ b ≤ a
Mathlib_Data_Rat_Order
a b c : ℚ this : Rat.Nonneg (b - a) ∨ Rat.Nonneg (-(b - a)) ⊢ a ≤ b ∨ b ≤ a
/- Copyright (c) 2019 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro -/ import Mathlib.Algebra.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 ## 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 -/ 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.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 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 only [Rat.Nonneg, false_iff, not_le] simp only [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]
protected theorem le_total : a ≤ b ∨ b ≤ a := by have := Rat.nonneg_total (b - a)
Mathlib.Data.Rat.Order.166_0.NTjR6KCugNscheB
protected theorem le_total : a ≤ b ∨ b ≤ a
Mathlib_Data_Rat_Order