Skip to content
This repository was archived by the owner on Jul 24, 2024. It is now read-only.

Commit fa68342

Browse files
kappelmannmergify[bot]
authored andcommitted
feat(data/rat): move lemmas to right file, add nat cast lemmas, remove (#1333)
redundant lemma
1 parent 73cc56c commit fa68342

File tree

4 files changed

+29
-32
lines changed

4 files changed

+29
-32
lines changed

src/data/rat/basic.lean

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,8 @@ theorem num_denom : ∀ a : ℚ, a = a.num /. a.denom
217217

218218
theorem num_denom' (n d h c) : (⟨n, d, h, c⟩ : ℚ) = n /. d := num_denom _
219219

220+
theorem of_int_eq_mk (z : ℤ) : of_int z = z /. 1 := num_denom' _ _ _ _
221+
220222
@[elab_as_eliminator] theorem {u} num_denom_cases_on {C : ℚ → Sort u}
221223
: ∀ (a : ℚ) (H : ∀ n d, d > 0 → (int.nat_abs n).coprime d → C (n /. d)), C a
222224
| ⟨n, d, h, c⟩ H := by rw num_denom'; exact H n d h c

src/data/rat/cast.lean

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@ import data.rat.order
99
1010
## Summary
1111
12-
We define the canonical injection from ℚ into an arbitrary division ring and prove various casting
13-
lemmas showing the well-behavedness of this injection.
12+
1. We define the canonical injection from ℚ into an arbitrary division ring and prove various
13+
casting lemmas showing the well-behavedness of this injection.
14+
2. We prove basic properties about the casts from ℤ and ℕ into ℚ (i.e. `(n : ℚ) = n / 1`) .
1415
1516
## Notations
1617
@@ -37,6 +38,25 @@ protected def cast : ℚ → α
3738

3839
@[priority 0] instance cast_coe : has_coe ℚ α := ⟨rat.cast⟩
3940

41+
theorem coe_int_eq_mk : ∀ (z : ℤ), ↑z = z /. 1
42+
| (n : ℕ) := show (n:ℚ) = n /. 1,
43+
by induction n with n IH n; simp [*, show (1:ℚ) = 1 /. 1, from rfl]
44+
| -[1+ n] := show (-(n + 1) : ℚ) = -[1+ n] /. 1, begin
45+
induction n with n IH, {refl},
46+
show -(n + 1 + 1 : ℚ) = -[1+ n.succ] /. 1,
47+
rw [neg_add, IH],
48+
simpa [show -1 = (-1) /. 1, from rfl]
49+
end
50+
51+
theorem mk_eq_div (n d : ℤ) : n /. d = ((n : ℚ) / d) :=
52+
begin
53+
by_cases d0 : d = 0, {simp [d0, div_zero]},
54+
simp [division_def, coe_int_eq_mk, mul_def one_ne_zero d0]
55+
end
56+
57+
theorem coe_int_eq_of_int (z : ℤ) : ↑z = of_int z :=
58+
(coe_int_eq_mk z).trans (of_int_eq_mk z).symm
59+
4060
@[simp] theorem cast_of_int (n : ℤ) : (of_int n : α) = n :=
4161
show (n / (1:ℕ) : α) = n, by rw [nat.cast_one, div_one]
4262

@@ -49,6 +69,9 @@ by rw coe_int_eq_of_int; refl
4969
@[simp, elim_cast] theorem coe_int_denom (n : ℤ) : (n : ℚ).denom = 1 :=
5070
by rw coe_int_eq_of_int; refl
5171

72+
theorem coe_nat_eq_mk (n : ℕ) : ↑n = n /. 1 :=
73+
by rw [← int.cast_coe_nat, coe_int_eq_mk]
74+
5275
@[simp, elim_cast] theorem coe_nat_num (n : ℕ) : (n : ℚ).num = n :=
5376
by rw [← int.cast_coe_nat, coe_int_num]
5477

src/data/rat/floor.lean

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ Released under Apache 2.0 license as described in the file LICENSE.
44
Authors: Johannes Hölzl, Mario Carneiro
55
-/
66
import data.rat.order
7+
import data.rat.cast
78
/-!
89
# Floor and Ceil Functions for Rational Numbers
910
@@ -38,7 +39,7 @@ theorem le_floor {z : ℤ} : ∀ {r : ℚ}, z ≤ floor r ↔ (z : ℚ) ≤ r
3839
rw [num_denom'],
3940
have h' := int.coe_nat_lt.2 h,
4041
conv { to_rhs,
41-
rw [coe_int_eq_mk, mk_le zero_lt_one h', mul_one] },
42+
rw [coe_int_eq_mk, rat.le_def zero_lt_one h', mul_one] },
4243
exact int.le_div_iff_mul_le h'
4344
end
4445

src/data/rat/order.lean

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -131,13 +131,6 @@ show rat.nonneg a ↔ rat.nonneg (a - 0), by simp
131131
theorem num_nonneg_iff_zero_le : ∀ {a : ℚ}, 0 ≤ a.num ↔ 0 ≤ a
132132
| ⟨n, d, h, c⟩ := @nonneg_iff_zero_le ⟨n, d, h, c⟩
133133

134-
theorem mk_le {a b c d : ℤ} (h₁ : b > 0) (h₂ : d > 0) :
135-
a /. b ≤ c /. d ↔ a * d ≤ c * b :=
136-
by conv in (_ ≤ _) {
137-
simp only [(≤), rat.le],
138-
rw [sub_def (ne_of_gt h₂) (ne_of_gt h₁),
139-
mk_nonneg _ (mul_pos h₂ h₁), ge, sub_nonneg] }
140-
141134
protected theorem add_le_add_left {a b c : ℚ} : c + a ≤ c + b ↔ a ≤ b :=
142135
by unfold has_le.le rat.le; rw add_sub_add_left_eq_sub
143136

@@ -176,28 +169,6 @@ lt_iff_lt_of_le_iff_le $
176169
by simpa [(by cases a; refl : (-a).num = -a.num)]
177170
using @num_nonneg_iff_zero_le (-a)
178171

179-
theorem of_int_eq_mk (z : ℤ) : of_int z = z /. 1 := num_denom' _ _ _ _
180-
181-
theorem coe_int_eq_mk : ∀ z : ℤ, ↑z = z /. 1
182-
| (n : ℕ) := show (n:ℚ) = n /. 1,
183-
by induction n with n IH n; simp [*, show (1:ℚ) = 1 /. 1, from rfl]
184-
| -[1+ n] := show (-(n + 1) : ℚ) = -[1+ n] /. 1, begin
185-
induction n with n IH, {refl},
186-
show -(n + 1 + 1 : ℚ) = -[1+ n.succ] /. 1,
187-
rw [neg_add, IH],
188-
simpa [show -1 = (-1) /. 1, from rfl]
189-
end
190-
191-
theorem coe_int_eq_of_int (z : ℤ) : ↑z = of_int z :=
192-
(coe_int_eq_mk z).trans (of_int_eq_mk z).symm
193-
194-
theorem mk_eq_div (n d : ℤ) : n /. d = (n / d : ℚ) :=
195-
begin
196-
by_cases d0 : d = 0, {simp [d0, div_zero]},
197-
rw [division_def, coe_int_eq_mk, coe_int_eq_mk, inv_def,
198-
mul_def one_ne_zero d0, one_mul, mul_one]
199-
end
200-
201172
theorem abs_def (q : ℚ) : abs q = q.num.nat_abs /. q.denom :=
202173
begin
203174
have hz : (0:ℚ) = 0 /. 1 := rfl,

0 commit comments

Comments
 (0)