|
| 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