Lean / Reader
Lean reader

StarStatement.lean

116 lines9 declarationsno sorryimports StarProcess StarDyadic

Lean 4 Web has Mathlib, so it can check files that import only Mathlib. This one also imports StarProcess, StarDyadic, which it does not have: you can read it there, but it will not check. Build the project itself to check it.

  1. import StarProcess
  2. import StarDyadic
  3. namespace RotatingStars
  4. private def Invariant (k : ℕ) : Prop :=
  5. (∀ x∈older k, size x ≤ (2:ℚ)^(k-1)) ∧
  6. (∀ j, j ≤ k → size (vertex (origin k) k j)=(2:ℚ)^k)
  7. private theorem vertices_of_origin (k : ℕ) (hk : 2 ≤ k) (h : size (origin k)=(2:ℚ)^k)
  8. (j : ℕ) : size (vertex (origin k) k j)=(2:ℚ)^k := by
  9. apply (size_add_eq ?_).trans h
  10. rw [h]
  11. simpa only [Nat.cast_add,Nat.cast_one,Nat.add_sub_cancel] using
  12. size_fraction_lt (k+1) j (by omega)
  13. private theorem base : Invariant 2 := by
  14. constructor
  15. · intro x hx
  16. rw [show 2=(1:ℕ)+1 by rfl,older_step,initial_older] at hx
  17. rcases Finset.mem_union.mp hx with hx|hx
  18. · simp only [Finset.mem_singleton] at hx
  19. subst x
  20. norm_num
  21. obtain ⟨j,hj,rfl⟩ := Finset.mem_image.mp hx
  22. obtain h := Finset.mem_range.mp hj
  23. interval_cases j
  24. · simpa [vertex,first_stars.1] using size_half.le
  25. · have s := size_int (1:ℤ)
  26. norm_num [vertex,first_stars.1] at *
  27. linarith
  28. · have h := size_int (1:ℤ)
  29. have s : size (1:ℚ) < size (1/4) := by rw [size_quarter]; norm_num at h; linarith
  30. have orig : size (origin 2)=2^2 := by
  31. rw [first_stars.2,show (5:ℚ)/4=1/4+1 by norm_num,size_add_eq s,size_quarter]
  32. norm_num
  33. exact fun j _ => vertices_of_origin 2 (by decide) orig j
  34. private theorem invariant_all (k : ℕ) (hk : 2 ≤ k) : Invariant k := by
  35. induction k, hk using Nat.le_induction with
  36. | base => exact base
  37. | succ k hk ih =>
  38. obtain ⟨low,high⟩ := ih
  39. have pow : (2:ℚ)^(k-1) < 2^k := by
  40. exact pow_lt_pow_right₀ (by norm_num) (by omega)
  41. have last : size (lastAngle k)=(2:ℚ)^k := high k le_rfl
  42. obtain ⟨u,hu,hp⟩ : ∃ u, 0 < u ∧ k=u+1 := ⟨k-1,by omega,by omega⟩
  43. have wit := next_from_older u hu
  44. rw [←hp] at wit
  45. obtain ⟨y,hy,z,hz⟩ := wit
  46. have lt : size (nextAngle k) < size (lastAngle k) := by
  47. rw [hz,last]
  48. exact lt_of_le_of_lt (size_shift (low y hy) z) pow
  49. have orig : size (origin (k+1))=(2:ℚ)^(k+1) := by
  50. rw [origin_step,size_half_sum lt,last,pow_succ]; ring
  51. constructor
  52. · intro x hx
  53. simp only [older_step,Finset.mem_union] at hx
  54. simp only [Nat.add_sub_cancel]
  55. rcases hx with hx|hx
  56. · exact le_trans (low x hx) pow.le
  57. · obtain ⟨j,hj,rfl⟩ := Finset.mem_image.mp hx
  58. exact (high j (by have := Finset.mem_range.mp hj; omega)).le
  59. · exact fun j _ => vertices_of_origin (k+1) (by omega) orig j
  60. private theorem earlier_mem (m k j : ℕ) (hm : m < k) (hj : j ≤ m) :
  61. vertex (origin m) m j ∈ older k := by
  62. induction k, hm using Nat.le_induction with
  63. | base =>
  64. rw [older_step]
  65. exact Finset.mem_union_right _ (Finset.mem_image.mpr ⟨j,Finset.mem_range.mpr (by omega),rfl⟩)
  66. | succ k hk ih =>
  67. rw [older_step]
  68. exact Finset.mem_union_left _ ih
  69. theorem denominator_size (n : ℕ) (hn : 3 ≤ n) (j : ℕ) (hj : j < n) :
  70. size (vertex (origin (n-1)) (n-1) j)=(2:ℚ)^(n-1) :=
  71. (invariant_all _ (by omega)).2 j (by omega)
  72. /-- The point j (zero-based) of the n-th star, in unwrapped turns. -/
  73. def angle (n j : ℕ) : ℚ := vertex (origin (n-1)) (n-1) j
  74. /-- A full turn shifts an angle by one. -/
  75. def samePoint (x y : ℚ) : Prop := ∃ z : ℤ, x=y+z
  76. /-- OEIS A385330. Two labeled vertices of different stars coincide exactly for
  77. the sole vertex of the 1-star and the second vertex of the 2-star. -/
  78. theorem only_overwrite {m n i j : ℕ} (hm : 0 < m) (hmn : m < n) (hi : i < m) (hj : j < n) :
  79. samePoint (angle n j) (angle m i) ↔ m=1 ∧ n=2 ∧ i=0 ∧ j=1 := by
  80. constructor
  81. · rintro ⟨z,h⟩
  82. by_cases hn : 3 ≤ n
  83. · have seen := earlier_mem (m-1) (n-1) i (by omega) (by omega)
  84. have low := size_shift ((invariant_all (n-1) (by omega)).1 _ seen) z
  85. have high := denominator_size n hn j hj
  86. change vertex (origin (n-1)) (n-1) j=vertex (origin (m-1)) (m-1) i+z at h
  87. rw [←h,high] at low
  88. have bad : (2:ℚ)^(n-1-1) < 2^(n-1) := pow_lt_pow_right₀ (by norm_num) (by omega)
  89. exact (not_lt_of_ge low bad).elim
  90. · obtain rfl : m=1 := by omega
  91. obtain rfl : n=2 := by omega
  92. obtain rfl : i=0 := by omega
  93. refine ⟨rfl,rfl,rfl,?_⟩
  94. by_contra! hz
  95. obtain rfl : j=0 := by omega
  96. norm_num [angle,vertex,origin_zero,first_stars.1] at h
  97. have hh : ((2*z:ℤ):ℚ)=1 := by push_cast; linarith
  98. have zz : (2*z:ℤ)=1 := by exact_mod_cast hh
  99. omega
  100. · rintro ⟨rfl,rfl,rfl,rfl⟩
  101. refine ⟨1,?_⟩
  102. norm_num [angle,vertex,origin_zero,first_stars.1]
  103. #print axioms only_overwrite
  104. end RotatingStars