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

Commit 65a75b0

Browse files
committed
half finished decimal expansions
1 parent f529870 commit 65a75b0

File tree

2 files changed

+73
-0
lines changed

2 files changed

+73
-0
lines changed

src/algebra/archimedean.lean

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ lt_iff_lt_of_le_iff_le le_floor
3737
theorem floor_le (x : α) : (⌊x⌋ : α) ≤ x :=
3838
le_floor.1 (le_refl _)
3939

40+
theorem sub_floor_nonneg (x : α) : 0 ≤ x - ⌊x⌋ :=
41+
sub_nonneg.2 $ floor_le _
42+
4043
theorem floor_nonneg {x : α} : 0 ≤ ⌊x⌋ ↔ 0 ≤ x :=
4144
by rw [le_floor]; refl
4245

@@ -49,6 +52,9 @@ by simpa only [int.succ, int.cast_add, int.cast_one] using lt_succ_floor x
4952
theorem sub_one_lt_floor (x : α) : x - 1 < ⌊x⌋ :=
5053
sub_lt_iff_lt_add.2 (lt_floor_add_one x)
5154

55+
theorem sub_floor_lt_one (x : α) : x - ⌊x⌋ < 1 :=
56+
sub_lt.1 $ sub_one_lt_floor _
57+
5258
@[simp] theorem floor_coe (z : ℤ) : ⌊(z:α)⌋ = z :=
5359
eq_of_forall_le_iff $ λ a, by rw [le_floor, int.cast_le]
5460

@@ -67,6 +73,11 @@ eq_of_forall_le_iff $ λ a, by rw [le_floor,
6773
theorem floor_sub_int (x : α) (z : ℤ) : ⌊x - z⌋ = ⌊x⌋ - z :=
6874
eq.trans (by rw [int.cast_neg]; refl) (floor_add_int _ _)
6975

76+
lemma floor_of_bounds (r : α) (z : ℤ) :
77+
↑z ≤ r ∧ r < (z + 1) ↔ ⌊ r ⌋ = z :=
78+
by rw [←le_floor, ←int.cast_one, ←int.cast_add, ←floor_lt,
79+
int.lt_add_one_iff, le_antisymm_iff, and.comm]
80+
7081
/-- `ceil x` is the smallest integer `z` such that `x ≤ z` -/
7182
def ceil (x : α) : ℤ := -⌊-x⌋
7283

src/algebra/expansion.lean

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/-
2+
Copyright (c) 2019 Kevin Buzzard. All rights reserved.
3+
Released under Apache 2.0 license as described in the file LICENSE.
4+
Authors: Kevin Buzzard
5+
-/
6+
7+
import algebra.archimedean tactic.linarith
8+
9+
/-
10+
11+
This file provides decimal (and more generally base b>=2) expansions of "floor rings",
12+
that is, ordered rings equipped with a floor function to the integers, such as
13+
the rational or real numbers.
14+
15+
If r is an element of such a ring, then expansion.digit b r n is the (n+1)'st digit
16+
after the decimal point in the base b expansion of r, so 0 <= expansion.digit b r n < b.
17+
In other words, if aₙ = expansion.digit b r n then for a real number r, we have
18+
r = (floor r) + 0.a₀a₁a₂... in base b. We have 0 ≤ aₙ < b (digit_lt_base).
19+
20+
-/
21+
22+
namespace expansion
23+
24+
variables {α : Type*} [linear_ordered_ring α] [floor_ring α]
25+
26+
def digit_aux (b : ℕ) (r : α) : ℕ → α
27+
| 0 := (r - ⌊r⌋) * b
28+
| (n + 1) := (digit_aux n - ⌊digit_aux n⌋) * b
29+
30+
lemma digit_aux_nonneg (b : ℕ) (r : α) (n : ℕ) : 0 ≤ digit_aux b r n :=
31+
nat.cases_on n (mul_nonneg (sub_floor_nonneg _) (nat.cast_nonneg _))
32+
(λ _,(mul_nonneg (sub_floor_nonneg _) (nat.cast_nonneg _)))
33+
34+
lemma digit_aux_lt_base {b : ℕ} (hb : 0 < b) (r : α) (n : ℕ) : digit_aux b r n < b :=
35+
nat.cases_on n
36+
((mul_lt_iff_lt_one_left (show (0 : α) < b, by simp [hb])).2 (sub_floor_lt_one _))
37+
(λ n, (mul_lt_iff_lt_one_left (show (0 : α) < b, by simp [hb])).2 (sub_floor_lt_one _))
38+
39+
definition digit (b : ℕ) (r : α) (n : ℕ) := int.to_nat (⌊digit_aux b r n⌋)
40+
41+
lemma digit_lt_base {b : ℕ} (hb : 0 < b) (r : α) (n : ℕ) : digit b r n < b :=
42+
begin
43+
have h : (⌊digit_aux b r n⌋ : α) < b,
44+
exact lt_of_le_of_lt (floor_le _) (digit_aux_lt_base hb r n),
45+
have h2 : ⌊digit_aux b r n⌋ = digit b r n,
46+
exact (int.to_nat_of_nonneg (floor_nonneg.2 $ digit_aux_nonneg b r n)).symm,
47+
have h3 : ((digit b r n : ℤ) : α) < b,
48+
rwa ←h2,
49+
simpa using h3,
50+
end
51+
52+
theorem approx {b : ℕ} (hb : 0 < b) (r : α) (n : ℕ) :
53+
⌊((r - ⌊r⌋) * b ^ n)⌋ = finset.sum (finset.range n) (λ i, digit b r i) :=
54+
begin
55+
induction n with m hm,
56+
{ rw [pow_zero,mul_one,finset.range_zero,finset.sum_empty,←floor_of_bounds],
57+
exact ⟨sub_floor_nonneg _,by convert (sub_floor_lt_one _);simp⟩
58+
},
59+
sorry
60+
end
61+
62+
end expansion

0 commit comments

Comments
 (0)