Lean / Reader
Lean reader

Erdos311Digits.lean

56 lines3 declarationsno sorryimports Mathlib
  1. import Mathlib
  2. namespace Erdos311Digits
  3. /-- The arithmetic digit used in the constructive fractional-part theorem. Scaling by p^k
  4. leaves a nonzero digit that one denominator p^a*t realizes without changing earlier digits. -/
  5. theorem one_digit {p : ℕ} [Fact p.Prime] (a k c : ℕ) (hc : ¬p ∣ c)
  6. (covers : ∀ t : ℕ, 0 < t → t < p → t ∣ c) (digit : ZMod p) (hd : digit ≠ 0) :
  7. ∃ t : ℕ, 0 < t ∧ t < p ∧ (↑(c/t) : ZMod p) = digit ∧
  8. (p^(a+k)*c)/(p^a*t) = p^k*(c/t) := by
  9. have hcp : (c : ZMod p) ≠ 0 := fun h => hc ((ZMod.natCast_eq_zero_iff ..).mp h)
  10. let x : ZMod p := (c : ZMod p)/digit
  11. have hx : x ≠ 0 := div_ne_zero hcp hd
  12. let t := x.val
  13. have ht : (t : ZMod p) = x := ZMod.natCast_zmod_val x
  14. have htn : 0 < t := by
  15. by_contra! h
  16. have ht0 : t = 0 := by omega
  17. exact hx (by simpa [ht0] using ht.symm)
  18. have hp0 : 0 < p := (Fact.out : Nat.Prime p).pos
  19. have hlt : t < p := x.val_lt
  20. have he : c/t*t = c := Nat.div_mul_cancel (covers t htn hlt)
  21. refine ⟨t, htn, hlt, ?_, ?_⟩
  22. · apply mul_right_cancel₀ (show (t : ZMod p) ≠ 0 by rwa [ht])
  23. calc (↑(c/t) : ZMod p)*t = (c : ZMod p) := by rw [← Nat.cast_mul,he]
  24. _ = digit*t := by rw [ht]; dsimp [x]; field_simp
  25. · apply Nat.div_eq_of_eq_mul_right (Nat.mul_pos (pow_pos hp0 _) htn)
  26. rw [pow_add]
  27. calc p^a*p^k*c = p^a*p^k*(c/t*t) := by rw [he]
  28. _ = _ := by ring
  29. /-- The factor left after removing the full p-power in an lcm contains every positive t<p. -/
  30. theorem small_divisors_in_unit (N p e c : ℕ) (hp : p.Prime) (hpN : p ≤ N)
  31. (hL : (Finset.Icc 1 N).lcm id = p^e*c) : ∀ t : ℕ, 0 < t → t < p → t ∣ c := by
  32. intro t ht htp
  33. have hn : ¬p ∣ t := fun h => (not_le_of_gt htp) (Nat.le_of_dvd ht h)
  34. have hd : t ∣ (Finset.Icc 1 N).lcm id := Finset.dvd_lcm (f := id) (Finset.mem_Icc.mpr ⟨ht,by omega⟩)
  35. rw [hL] at hd
  36. exact ((hp.coprime_iff_not_dvd.mpr hn).pow_left e).symm.dvd_of_dvd_mul_left hd
  37. /-- Fixing one signed base-p digit increases the power dividing the residual. -/
  38. theorem lift_power {p : ℕ} (k : ℕ) (residualValue nextWeight digitValue : ℤ)
  39. (hvalue : residualValue = (p : ℤ)^k * digitValue)
  40. (digitWeight : ℤ) (hweight : nextWeight = (p : ℤ)^k * digitWeight)
  41. (hmatch : (p : ℤ) ∣ digitValue-digitWeight) :
  42. (p : ℤ)^(k+1) ∣ residualValue-nextWeight := by
  43. obtain ⟨d,hd⟩ := hmatch
  44. refine ⟨d,?_⟩
  45. rw [hvalue,hweight,← mul_sub,hd,pow_succ]
  46. ring
  47. #print axioms small_divisors_in_unit
  48. #print axioms lift_power
  49. #print axioms one_digit
  50. end Erdos311Digits