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

Commit 313fe11

Browse files
kappelmannmergify[bot]
authored andcommitted
feat(algebra/floor): Split floor from archimedean file. (#1372)
* feat(algebra/floor): Split floor from archimedean file. * feat({algebra,rat}/floor): move lemmas/defs from rat.floor to algebra.floor
1 parent 37b6746 commit 313fe11

File tree

4 files changed

+277
-289
lines changed

4 files changed

+277
-289
lines changed

src/algebra/archimedean.lean

Lines changed: 4 additions & 188 deletions
Original file line numberDiff line numberDiff line change
@@ -5,197 +5,13 @@ Authors: Mario Carneiro
55
66
Archimedean groups and fields.
77
-/
8-
import algebra.group_power algebra.field_power
9-
import data.rat tactic.linarith tactic.abel
8+
import algebra.group_power algebra.field_power algebra.floor
9+
import data.rat tactic.linarith
1010

1111
variables {α : Type*}
1212

1313
open_locale add_monoid
1414

15-
class floor_ring (α) [linear_ordered_ring α] :=
16-
(floor : α → ℤ)
17-
(le_floor : ∀ (z : ℤ) (x : α), z ≤ floor x ↔ (z : α) ≤ x)
18-
19-
instance : floor_ring ℤ :=
20-
{ floor := id, le_floor := λ _ _, by rw int.cast_id; refl }
21-
22-
instance : floor_ring ℚ :=
23-
{ floor := rat.floor, le_floor := @rat.le_floor }
24-
25-
section
26-
variables [linear_ordered_ring α] [floor_ring α]
27-
28-
def floor : α → ℤ := floor_ring.floor
29-
30-
notation `⌊` x `⌋` := floor x
31-
32-
theorem le_floor : ∀ {z : ℤ} {x : α}, z ≤ ⌊x⌋ ↔ (z : α) ≤ x :=
33-
floor_ring.le_floor
34-
35-
theorem floor_lt {x : α} {z : ℤ} : ⌊x⌋ < z ↔ x < z :=
36-
lt_iff_lt_of_le_iff_le le_floor
37-
38-
theorem floor_le (x : α) : (⌊x⌋ : α) ≤ x :=
39-
le_floor.1 (le_refl _)
40-
41-
theorem floor_nonneg {x : α} : 0 ≤ ⌊x⌋ ↔ 0 ≤ x :=
42-
by rw [le_floor]; refl
43-
44-
theorem lt_succ_floor (x : α) : x < ⌊x⌋.succ :=
45-
floor_lt.1 $ int.lt_succ_self _
46-
47-
theorem lt_floor_add_one (x : α) : x < ⌊x⌋ + 1 :=
48-
by simpa only [int.succ, int.cast_add, int.cast_one] using lt_succ_floor x
49-
50-
theorem sub_one_lt_floor (x : α) : x - 1 < ⌊x⌋ :=
51-
sub_lt_iff_lt_add.2 (lt_floor_add_one x)
52-
53-
@[simp] theorem floor_coe (z : ℤ) : ⌊(z:α)⌋ = z :=
54-
eq_of_forall_le_iff $ λ a, by rw [le_floor, int.cast_le]
55-
56-
@[simp] theorem floor_zero : ⌊(0:α)⌋ = 0 := floor_coe 0
57-
58-
@[simp] theorem floor_one : ⌊(1:α)⌋ = 1 :=
59-
by rw [← int.cast_one, floor_coe]
60-
61-
theorem floor_mono {a b : α} (h : a ≤ b) : ⌊a⌋ ≤ ⌊b⌋ :=
62-
le_floor.2 (le_trans (floor_le _) h)
63-
64-
@[simp] theorem floor_add_int (x : α) (z : ℤ) : ⌊x + z⌋ = ⌊x⌋ + z :=
65-
eq_of_forall_le_iff $ λ a, by rw [le_floor,
66-
← sub_le_iff_le_add, ← sub_le_iff_le_add, le_floor, int.cast_sub]
67-
68-
theorem floor_sub_int (x : α) (z : ℤ) : ⌊x - z⌋ = ⌊x⌋ - z :=
69-
eq.trans (by rw [int.cast_neg]; refl) (floor_add_int _ _)
70-
71-
lemma abs_sub_lt_one_of_floor_eq_floor {α : Type*} [decidable_linear_ordered_comm_ring α] [floor_ring α]
72-
{x y : α} (h : ⌊x⌋ = ⌊y⌋) : abs (x - y) < 1 :=
73-
begin
74-
have : x < ⌊x⌋ + 1 := lt_floor_add_one x,
75-
have : y < ⌊y⌋ + 1 := lt_floor_add_one y,
76-
have : (⌊x⌋ : α) = ⌊y⌋ := int.cast_inj.2 h,
77-
have : (⌊x⌋: α) ≤ x := floor_le x,
78-
have : (⌊y⌋ : α) ≤ y := floor_le y,
79-
exact abs_sub_lt_iff.2by linarith, by linarith⟩
80-
end
81-
82-
lemma floor_eq_iff {r : α} {z : ℤ} :
83-
⌊r⌋ = z ↔ ↑z ≤ r ∧ r < (z + 1) :=
84-
by rw [←le_floor, ←int.cast_one, ←int.cast_add, ←floor_lt,
85-
int.lt_add_one_iff, le_antisymm_iff, and.comm]
86-
87-
/-- The fractional part fract r of r is just r - ⌊r⌋ -/
88-
def fract (r : α) : α := r - ⌊r⌋
89-
90-
-- Mathematical notation is usually {r}. Let's not even go there.
91-
92-
@[simp] lemma floor_add_fract (r : α) : (⌊r⌋ : α) + fract r = r := by unfold fract; simp
93-
94-
@[simp] lemma fract_add_floor (r : α) : fract r + ⌊r⌋ = r := sub_add_cancel _ _
95-
96-
theorem fract_nonneg (r : α) : 0 ≤ fract r :=
97-
sub_nonneg.2 $ floor_le _
98-
99-
theorem fract_lt_one (r : α) : fract r < 1 :=
100-
sub_lt.1 $ sub_one_lt_floor _
101-
102-
@[simp] lemma fract_zero : fract (0 : α) = 0 := by unfold fract; simp
103-
104-
@[simp] lemma fract_coe (z : ℤ) : fract (z : α) = 0 :=
105-
by unfold fract; rw floor_coe; exact sub_self _
106-
107-
@[simp] lemma fract_floor (r : α) : fract (⌊r⌋ : α) = 0 := fract_coe _
108-
109-
@[simp] lemma floor_fract (r : α) : ⌊fract r⌋ = 0 :=
110-
by rw floor_eq_iff; exact ⟨fract_nonneg _,
111-
by rw [int.cast_zero, zero_add]; exact fract_lt_one r⟩
112-
113-
theorem fract_eq_iff {r s : α} : fract r = s ↔ 0 ≤ s ∧ s < 1 ∧ ∃ z : ℤ, r - s = z :=
114-
⟨λ h, by rw ←h; exact ⟨fract_nonneg _, fract_lt_one _,
115-
⟨⌊r⌋, sub_sub_cancel _ _⟩⟩, begin
116-
intro h,
117-
show r - ⌊r⌋ = s, apply eq.symm,
118-
rw [eq_sub_iff_add_eq, add_comm, ←eq_sub_iff_add_eq],
119-
rcases h with ⟨hge, hlt, ⟨z, hz⟩⟩,
120-
rw [hz, int.cast_inj, floor_eq_iff, ←hz],
121-
clear hz, split; linarith {discharger := `[simp]}
122-
end
123-
124-
theorem fract_eq_fract {r s : α} : fract r = fract s ↔ ∃ z : ℤ, r - s = z :=
125-
⟨λ h, ⟨⌊r⌋ - ⌊s⌋, begin
126-
unfold fract at h, rw [int.cast_sub, sub_eq_sub_iff_sub_eq_sub.1 h],
127-
end⟩,
128-
λ h, begin
129-
rcases h with ⟨z, hz⟩,
130-
rw fract_eq_iff,
131-
split, exact fract_nonneg _,
132-
split, exact fract_lt_one _,
133-
use z + ⌊s⌋,
134-
rw [eq_add_of_sub_eq hz, int.cast_add],
135-
unfold fract, simp
136-
end
137-
138-
@[simp] lemma fract_fract (r : α) : fract (fract r) = fract r :=
139-
by rw fract_eq_fract; exact ⟨-⌊r⌋, by unfold fract;simp⟩
140-
141-
theorem fract_add (r s : α) : ∃ z : ℤ, fract (r + s) - fract r - fract s = z :=
142-
⟨⌊r⌋ + ⌊s⌋ - ⌊r + s⌋, by unfold fract; simp⟩
143-
144-
theorem fract_mul_nat (r : α) (b : ℕ) : ∃ z : ℤ, fract r * b - fract (r * b) = z :=
145-
begin
146-
induction b with c hc,
147-
use 0, simp,
148-
rcases hc with ⟨z, hz⟩,
149-
rw [nat.succ_eq_add_one, nat.cast_add, mul_add, mul_add, nat.cast_one, mul_one, mul_one],
150-
rcases fract_add (r * c) r with ⟨y, hy⟩,
151-
use z - y,
152-
rw [int.cast_sub, ←hz, ←hy],
153-
abel
154-
end
155-
156-
/-- `ceil x` is the smallest integer `z` such that `x ≤ z` -/
157-
def ceil (x : α) : ℤ := -⌊-x⌋
158-
159-
notation `⌈` x `⌉` := ceil x
160-
161-
theorem ceil_le {z : ℤ} {x : α} : ⌈x⌉ ≤ z ↔ x ≤ z :=
162-
by rw [ceil, neg_le, le_floor, int.cast_neg, neg_le_neg_iff]
163-
164-
theorem lt_ceil {x : α} {z : ℤ} : z < ⌈x⌉ ↔ (z:α) < x :=
165-
lt_iff_lt_of_le_iff_le ceil_le
166-
167-
theorem le_ceil (x : α) : x ≤ ⌈x⌉ :=
168-
ceil_le.1 (le_refl _)
169-
170-
@[simp] theorem ceil_coe (z : ℤ) : ⌈(z:α)⌉ = z :=
171-
by rw [ceil, ← int.cast_neg, floor_coe, neg_neg]
172-
173-
theorem ceil_mono {a b : α} (h : a ≤ b) : ⌈a⌉ ≤ ⌈b⌉ :=
174-
ceil_le.2 (le_trans h (le_ceil _))
175-
176-
@[simp] theorem ceil_add_int (x : α) (z : ℤ) : ⌈x + z⌉ = ⌈x⌉ + z :=
177-
by rw [ceil, neg_add', floor_sub_int, neg_sub, sub_eq_neg_add]; refl
178-
179-
theorem ceil_sub_int (x : α) (z : ℤ) : ⌈x - z⌉ = ⌈x⌉ - z :=
180-
eq.trans (by rw [int.cast_neg]; refl) (ceil_add_int _ _)
181-
182-
theorem ceil_lt_add_one (x : α) : (⌈x⌉ : α) < x + 1 :=
183-
by rw [← lt_ceil, ← int.cast_one, ceil_add_int]; apply lt_add_one
184-
185-
lemma ceil_pos {a : α} : 0 < ⌈a⌉ ↔ 0 < a :=
186-
⟨ λ h, have ⌊-a⌋ < 0, from neg_of_neg_pos h,
187-
pos_of_neg_neg $ lt_of_not_ge $ (not_iff_not_of_iff floor_nonneg).1 $ not_le_of_gt this,
188-
λ h, have -a < 0, from neg_neg_of_pos h,
189-
neg_pos_of_neg $ lt_of_not_ge $ (not_iff_not_of_iff floor_nonneg).2 $ not_le_of_gt this
190-
191-
@[simp] theorem ceil_zero : ⌈(0 : α)⌉ = 0 := by simp [ceil]
192-
193-
lemma ceil_nonneg [decidable_rel ((<) : α → α → Prop)] {q : α} (hq : q ≥ 0) : ⌈q⌉ ≥ 0 :=
194-
if h : q > 0 then le_of_lt $ ceil_pos.2 h
195-
else by rw [le_antisymm (le_of_not_lt h) hq, ceil_zero]; trivial
196-
197-
end
198-
19915
class archimedean (α) [ordered_comm_monoid α] : Prop :=
20016
(arch : ∀ (x : α) {y}, 0 < y → ∃ n : ℕ, x ≤ n • y)
20117

@@ -324,8 +140,8 @@ theorem archimedean_iff_rat_lt :
324140
⟨@exists_rat_gt α _,
325141
λ H, archimedean_iff_nat_lt.2 $ λ x,
326142
let ⟨q, h⟩ := H x in
327-
rat.nat_ceil q, lt_of_lt_of_le h $
328-
by simpa only [rat.cast_coe_nat] using (@rat.cast_le α _ _ _).2 (rat.le_nat_ceil _)⟩⟩
143+
⟨nat_ceil q, lt_of_lt_of_le h $
144+
by simpa only [rat.cast_coe_nat] using (@rat.cast_le α _ _ _).2 (le_nat_ceil _)⟩⟩
329145

330146
theorem archimedean_iff_rat_le :
331147
archimedean α ↔ ∀ x : α, ∃ q : ℚ, x ≤ q :=

0 commit comments

Comments
 (0)