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

Commit c25122b

Browse files
kbuzzardChrisHughes24
authored andcommitted
feat(algebra/archimedean): add fractional parts of floor_rings (#709)
1 parent d6f84da commit c25122b

File tree

2 files changed

+79
-1
lines changed

2 files changed

+79
-1
lines changed

src/algebra/archimedean.lean

Lines changed: 75 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Authors: Mario Carneiro
55
66
Archimedean groups and fields.
77
-/
8-
import algebra.group_power data.rat tactic.linarith
8+
import algebra.group_power data.rat tactic.linarith tactic.abel
99

1010
local infix ` • ` := add_monoid.smul
1111

@@ -78,6 +78,80 @@ begin
7878
exact abs_sub_lt_iff.2by linarith, by linarith⟩
7979
end
8080

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+
81155
/-- `ceil x` is the smallest integer `z` such that `x ≤ z` -/
82156
def ceil (x : α) : ℤ := -⌊-x⌋
83157

src/algebra/group.lean

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -626,6 +626,10 @@ section add_comm_group
626626
lemma sub_sub_sub_cancel_left (a b c : α) : (c - a) - (c - b) = b - a :=
627627
by rw [← neg_sub b c, sub_neg_eq_add, add_comm, sub_add_sub_cancel]
628628

629+
lemma sub_eq_sub_iff_sub_eq_sub {d : α} :
630+
a - b = c - d ↔ a - c = b - d :=
631+
⟨λ h, by rw eq_add_of_sub_eq h; simp, λ h, by rw eq_add_of_sub_eq h; simp⟩
632+
629633
end add_comm_group
630634

631635
section is_conj

0 commit comments

Comments
 (0)