@@ -5,7 +5,7 @@ Authors: Mario Carneiro
5
5
6
6
Archimedean groups and fields.
7
7
-/
8
- import algebra.group_power data.rat tactic.linarith
8
+ import algebra.group_power data.rat tactic.linarith tactic.abel
9
9
10
10
local infix ` • ` := add_monoid.smul
11
11
78
78
exact abs_sub_lt_iff.2 ⟨by linarith, by linarith⟩
79
79
end
80
80
81
+ lemma floor_eq_iff {r : α} {z : ℤ} :
82
+ ⌊r⌋ = z ↔ ↑z ≤ r ∧ r < (z + 1 ) :=
83
+ by rw [←le_floor, ←int.cast_one, ←int.cast_add, ←floor_lt,
84
+ int.lt_add_one_iff, le_antisymm_iff, and.comm]
85
+
86
+ /-- The fractional part fract r of r is just r - ⌊r⌋ -/
87
+ def fract (r : α) : α := r - ⌊r⌋
88
+
89
+ -- Mathematical notation is usually {r}. Let's not even go there.
90
+
91
+ @[simp] lemma fract_add_floor (r : α) : (⌊r⌋ : α) + fract r = r := by unfold fract; simp
92
+
93
+ @[simp] lemma floor_add_fract (r : α) : fract r + ⌊r⌋ = r := sub_add_cancel _ _
94
+
95
+ theorem fract_nonneg (r : α) : 0 ≤ fract r :=
96
+ sub_nonneg.2 $ floor_le _
97
+
98
+ theorem fract_lt_one (r : α) : fract r < 1 :=
99
+ sub_lt.1 $ sub_one_lt_floor _
100
+
101
+ @[simp] lemma fract_zero : fract (0 : α) = 0 := by unfold fract; simp
102
+
103
+ @[simp] lemma fract_coe (z : ℤ) : fract (z : α) = 0 :=
104
+ by unfold fract; rw floor_coe; exact sub_self _
105
+
106
+ @[simp] lemma fract_floor (r : α) : fract (⌊r⌋ : α) = 0 := fract_coe _
107
+
108
+ @[simp] lemma floor_fract (r : α) : ⌊fract r⌋ = 0 :=
109
+ by rw floor_eq_iff; exact ⟨fract_nonneg _,
110
+ by rw [int.cast_zero, zero_add]; exact fract_lt_one r⟩
111
+
112
+ theorem fract_eq_iff {r s : α} : fract r = s ↔ 0 ≤ s ∧ s < 1 ∧ ∃ z : ℤ, r - s = z :=
113
+ ⟨λ h, by rw ←h; exact ⟨fract_nonneg _, fract_lt_one _,
114
+ ⟨⌊r⌋, sub_sub_cancel _ _⟩⟩, begin
115
+ intro h,
116
+ show r - ⌊r⌋ = s, apply eq.symm,
117
+ rw [eq_sub_iff_add_eq, add_comm, ←eq_sub_iff_add_eq],
118
+ rcases h with ⟨hge, hlt, ⟨z, hz⟩⟩,
119
+ rw [hz, int.cast_inj, floor_eq_iff, ←hz],
120
+ clear hz, split; linarith {discharger := `[simp]}
121
+ end ⟩
122
+
123
+ theorem fract_eq_fract {r s : α} : fract r = fract s ↔ ∃ z : ℤ, r - s = z :=
124
+ ⟨λ h, ⟨⌊r⌋ - ⌊s⌋, begin
125
+ unfold fract at h, rw [int.cast_sub, sub_eq_sub_iff_sub_eq_sub.1 h],
126
+ end ⟩,
127
+ λ h, begin
128
+ rcases h with ⟨z, hz⟩,
129
+ rw fract_eq_iff,
130
+ split, exact fract_nonneg _,
131
+ split, exact fract_lt_one _,
132
+ use z + ⌊s⌋,
133
+ rw [eq_add_of_sub_eq hz, int.cast_add],
134
+ unfold fract, simp
135
+ end ⟩
136
+
137
+ @[simp] lemma fract_fract (r : α) : fract (fract r) = fract r :=
138
+ by rw fract_eq_fract; exact ⟨-⌊r⌋, by unfold fract;simp⟩
139
+
140
+ theorem fract_add (r s : α) : ∃ z : ℤ, fract (r + s) - fract r - fract s = z :=
141
+ ⟨⌊r⌋ + ⌊s⌋ - ⌊r + s⌋, by unfold fract; simp⟩
142
+
143
+ theorem fract_mul_nat (r : α) (b : ℕ) : ∃ z : ℤ, fract r * b - fract (r * b) = z :=
144
+ begin
145
+ induction b with c hc,
146
+ use 0 , simp,
147
+ rcases hc with ⟨z, hz⟩,
148
+ rw [nat.succ_eq_add_one, nat.cast_add, mul_add, mul_add, nat.cast_one, mul_one, mul_one],
149
+ rcases fract_add (r * c) r with ⟨y, hy⟩,
150
+ use z - y,
151
+ rw [int.cast_sub, ←hz, ←hy],
152
+ abel
153
+ end
154
+
81
155
/-- `ceil x` is the smallest integer `z` such that `x ≤ z` -/
82
156
def ceil (x : α) : ℤ := -⌊-x⌋
83
157
0 commit comments