Lean / Reader
Lean reader

CubeGrid.lean

77 lines6 declarationsno sorryimports CubeLayers CubeCounting

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

  1. import CubeLayers
  2. import CubeCounting
  3. namespace CubeGrid
  4. /-- If all outer corners are covered by unit cubes, they require every grid point. -/
  5. theorem outer_forces_grid (A : Finset (Point 4)) (hA : A ⊆ box 4 3)
  6. (ho : vertices 4 3 (origin 4) ⊆ expansion 4 A) : box 4 4 ⊆ expansion 4 A := by
  7. intro x hx
  8. have hout := ho (outer_contains 4 x)
  9. obtain ⟨a, ha, hav⟩ := Finset.mem_biUnion.mp hout
  10. exact Finset.mem_biUnion.mpr ⟨a,ha,unit_near_outer 4 hx (hA ha) hav⟩
  11. theorem unit_bound (S : Finset (Point 4)) (hS : S.card ≤ 81) : (anchors S 1).card ≤ 16 := by
  12. by_contra! h
  13. obtain ⟨A,hs,hc⟩ := Finset.exists_subset_card_eq (s := anchors S 1) (n := 17) h
  14. have hg : A ⊆ box 4 3 := hs.trans (Finset.filter_subset _ _)
  15. have v := profile_bound 4 (by decide) A hg (by omega)
  16. rw [hc] at v
  17. change 89 ≤ _ at v
  18. have hu := Finset.card_le_card (expansion_inside S A hs)
  19. omega
  20. theorem unit_bound_outer (S : Finset (Point 4)) (hS : S.card ≤ 81)
  21. (h3 : 0 < (anchors S 3).card) : (anchors S 1).card ≤ 15 := by
  22. by_contra! h
  23. obtain ⟨A,hs,hc⟩ := Finset.exists_subset_card_eq (s := anchors S 1) (n := 16) h
  24. have hg : A ⊆ box 4 3 := hs.trans (Finset.filter_subset _ _)
  25. have v := profile_bound 4 (by decide) A hg (by omega)
  26. rw [hc] at v
  27. change 81 ≤ _ at v
  28. have eu : expansion 4 A = S :=
  29. Finset.eq_of_subset_of_card_le (expansion_inside S A hs) (by omega)
  30. obtain ⟨a,ha⟩ := Finset.card_pos.mp h3
  31. obtain ⟨ga,outer⟩ := Finset.mem_filter.mp ha
  32. have one : box 4 (4-3) = {origin 4} := by decide +kernel
  33. rw [one, Finset.mem_singleton] at ga
  34. subst a
  35. rw [← eu] at outer
  36. have huge := Finset.card_le_card (outer_forces_grid A hg outer)
  37. rw [box_card,eu] at huge
  38. omega
  39. /-- At most 17 positive axis-parallel vertex cubes on any at-most-81-point
  40. host in the four-dimensional grid of side four. The enumerated anchor domains
  41. give precisely the positive integral side lengths and placements in the grid. -/
  42. theorem at_most_seventeen (S : Finset (Point 4)) (hS : S.card ≤ 81) : cubeCount S ≤ 17 := by
  43. have a := unit_bound S hS
  44. have b := full_count_le S hS
  45. have c : (anchors S 3).card ≤ 1 := by
  46. have v : (anchors S 3).card ≤ (box 4 (4-3)).card := Finset.card_le_card (Finset.filter_subset _ _)
  47. simpa [box_card] using v
  48. unfold cubeCount
  49. by_cases h13 : 13 ≤ (anchors S 1).card
  50. · have hb := packing_if_thirteen S hS h13
  51. by_cases ho : 0 < (anchors S 3).card
  52. · have := unit_bound_outer S hS ho; omega
  53. · omega
  54. · by_cases hu : 0 < (anchors S 1).card
  55. · have := packing_if_units S hS hu; omega
  56. · omega
  57. set_option maxHeartbeats 0 in
  58. theorem sharp_grid : (box 4 3).card = 81 ∧ cubeCount (box 4 3) = 17 :=
  59. ⟨by rw [box_card]; decide, by decide +kernel⟩
  60. theorem exact_maximum :
  61. (∀ S : Finset (Point 4), S ⊆ box 4 4 → S.card = 81 → cubeCount S ≤ 17) ∧
  62. ∃ S : Finset (Point 4), S ⊆ box 4 4 ∧ S.card = 81 ∧ cubeCount S = 17 := by
  63. exact ⟨fun S _ hc => at_most_seventeen S hc.le,
  64. box 4 3, by decide +kernel, sharp_grid⟩
  65. #print axioms exact_maximum
  66. #print axioms at_most_seventeen
  67. #print axioms profile_bound
  68. end CubeGrid