roseking's picture
Add lean source and binary files (part 90)
37bcf52 verified
Raw History Blame Contribute Delete
8.4 kB
13
lemma BoxLayout.lower_mem {A : BoxLayout ι} (hp : A.Positive) (i : ι) :
    A.center i - A.width i ∈ A.solid i := by
proof · 3 lines
  rw [BoxLayout.mem_solid]
  intro k
  exact ⟨le_rfl, by dsimp; linarith [hp i k]⟩
20
lemma BoxLayout.separated_of_disjoint {A : BoxLayout ι} (hp : A.Positive)
    (hs : Pairwise fun i j => Disjoint (A.solid i) (A.solid j)) : A.Separated 0 := by
proof · 22 lines
  intro i j hij
  by_contra! h
  let x : Space := fun k => max (A.center i k - A.width i k) (A.center j k - A.width j k)
  have hh (k : Fin 3) :
      -(A.width i k + A.width j k) ≤ A.center i k - A.center j k ∧
      A.center i k - A.center j k ≤ A.width i k + A.width j k := by
    have := h k
    simp only [mul_zero, add_zero] at this
    exact abs_le.mp this
  have hi : x ∈ A.solid i := by
    rw [BoxLayout.mem_solid]
    intro k
    refine ⟨le_max_left _ _, max_le ?_ ?_⟩
    · linarith [hp i k]
    · linarith [(hh k).1]
  have hj : x ∈ A.solid j := by
    rw [BoxLayout.mem_solid]
    intro k
    refine ⟨le_max_right _ _, max_le ?_ ?_⟩
    · linarith [(hh k).2]
    · linarith [hp j k]
  exact Set.disjoint_left.mp (hs hij) hi hj
53
def layout (r : ℝ) (digit : S → ℝ) (o : ι → Space) (u : ι → Fin 3 → List S) :
    BoxLayout ι where
body · 2 lines
  center i k := o i k + word r digit (u i k) + r ^ (u i k).length / 2
  width i k := r ^ (u i k).length / 2
58
lemma layout_positive {r : ℝ} (hr : 0 < r) (digit : S → ℝ)
    (o : ι → Space) (u : ι → Fin 3 → List S) : (layout r digit o u).Positive := by
proof · 2 lines
  intro i k
  exact div_pos (pow_pos hr _) (by norm_num)
63
lemma layout_solid [Fintype ι] (r : ℝ) (digit : S → ℝ) (o : ι → Space)
    (u : ι → Fin 3 → List S) (i : ι) :
    (layout r digit o u).solid i = box r digit (o i) (u i) := by
proof · 9 lines
  ext x
  rw [BoxLayout.mem_solid]
  change (∀ k, o i k + word r digit (u i k) + r ^ (u i k).length / 2 -
      r ^ (u i k).length / 2 ≤ x k ∧
      x k ≤ o i k + word r digit (u i k) + r ^ (u i k).length / 2 +
      r ^ (u i k).length / 2) ↔
    ∀ k, word r digit (u i k) ≤ x k - o i k ∧
      x k - o i k ≤ word r digit (u i k) + r ^ (u i k).length
  constructor <;> intro h k <;> have := h k <;> constructor <;> linarith
76
lemma layout_affineMap {r : ℝ} (hr : r ≠ 0) (digit : S → ℝ) (o p : ι → Space)
    (u v : ι → Fin 3 → List S) (i : ι) (x : Space) :
    (layout r digit o u).affineMap (layout r digit p v) i x =
      boxMap r digit (o i) (p i) (u i) (v i) x := by
proof · 4 lines
  ext k
  dsimp [BoxLayout.affineMap, layout, boxMap, replacement]
  field_simp
  ring
85
lemma layout_volume (r : ℝ) (digit : S → ℝ) (o p : ι → Space)
    (u v : ι → Fin 3 → List S) (i : ι)
    (h : ∑ k, (u i k).length = ∑ k, (v i k).length) :
    ∏ k, (layout r digit o u).width i k = ∏ k, (layout r digit p v).width i k := by
proof · 1 line
  simp only [layout, Finset.prod_div_distrib, Finset.prod_pow_eq_pow_sum, h]
99
abbrev ActiveRow (M : Machine Q Γ) := {r : Row Q Γ // r ∈ table M}
101
def sourceLayout (M : Machine Q Γ) : BoxLayout (ActiveRow M) :=
body · 3 lines
  Coding.layout (base Q Γ : ℝ)⁻¹ (fun a : Letter Q Γ => (digit a : ℝ))
    (fun i => Coding.origin (placement M (i.val.instruction M).sourceControl))
    (fun i => (i.val.instruction M).sourcePrefixes)
106
def targetLayout (M : Machine Q Γ) : BoxLayout (ActiveRow M) :=
body · 3 lines
  Coding.layout (base Q Γ : ℝ)⁻¹ (fun a : Letter Q Γ => (digit a : ℝ))
    (fun i => Coding.origin (placement M (i.val.instruction M).targetControl))
    (fun i => (i.val.instruction M).targetPrefixes)
111
def safeRows (M : Machine Q Γ) : Set (ActiveRow M) :=
body · 1 line
  {i | (i.val.instruction M).targetControl ≠ .ready M.halt}
115
lemma sourceLayout_solid (M : Machine Q Γ) (i : ActiveRow M) :
    (sourceLayout M).solid i = (i.val.instruction M).sourceBox
      (base Q Γ : ℝ)⁻¹ (fun a => (digit a : ℝ)) (placement M) :=
proof · 1 line
  Coding.layout_solid _ _ _ _ _
121
lemma targetLayout_solid (M : Machine Q Γ) (i : ActiveRow M) :
    (targetLayout M).solid i = (i.val.instruction M).targetBox
      (base Q Γ : ℝ)⁻¹ (fun a => (digit a : ℝ)) (placement M) :=
proof · 1 line
  Coding.layout_solid _ _ _ _ _
127
lemma sourceLayout_positive (M : Machine Q Γ) : (sourceLayout M).Positive :=
proof · 1 line
  Coding.layout_positive inverse_base_pos _ _ _
131
lemma targetLayout_positive (M : Machine Q Γ) : (targetLayout M).Positive :=
proof · 1 line
  Coding.layout_positive inverse_base_pos _ _ _
134
lemma sourceLayout_separated (M : Machine Q Γ) : (sourceLayout M).Separated 0 := by
proof · 4 lines
  apply BoxLayout.separated_of_disjoint (sourceLayout_positive M)
  intro i j hij
  rw [sourceLayout_solid, sourceLayout_solid]
  exact (compiled_boxes_disjoint M).1 i.property j.property (fun h => hij (Subtype.ext h))
140
lemma targetLayout_separated (M : Machine Q Γ) : (targetLayout M).Separated 0 := by
proof · 4 lines
  apply BoxLayout.separated_of_disjoint (targetLayout_positive M)
  intro i j hij
  rw [targetLayout_solid, targetLayout_solid]
  exact (compiled_boxes_disjoint M).2 i.property j.property (fun h => hij (Subtype.ext h))
147
lemma layouts_equal_volume (M : Machine Q Γ) (i : ActiveRow M) :
    ∏ k, (sourceLayout M).width i k = ∏ k, (targetLayout M).width i k := by
proof · 3 lines
  apply Coding.layout_volume
  simpa [Instruction.sourcePrefixes, Instruction.targetPrefixes, Fin.sum_univ_succ,
    Instruction.Balanced, Nat.add_assoc] using i.val.balanced M
154
lemma sourceLayout_guard (M : Machine Q Γ) : (sourceLayout M).Guarded (safeRows M) := by
proof · 7 lines
  intro i _
  have hh := BoxLayout.lower_mem (sourceLayout_positive M) i
  rw [sourceLayout_solid] at hh
  have hn := source_box_guard M i.val ((mem_table M _).mp i.property) hh
  change 2 < (sourceLayout M).center i 0 - (sourceLayout M).width i 0
  change 4 ≤ (sourceLayout M).center i 0 - (sourceLayout M).width i 0 at hn
  linarith
164
lemma targetLayout_guard (M : Machine Q Γ) : (targetLayout M).Guarded (safeRows M) := by
proof · 7 lines
  intro i hi
  have hh := BoxLayout.lower_mem (targetLayout_positive M) i
  rw [targetLayout_solid] at hh
  have hn := nonhalt_box_guard M _ hi _ hh
  change 2 < (targetLayout M).center i 0 - (targetLayout M).width i 0
  change 4 ≤ (targetLayout M).center i 0 - (targetLayout M).width i 0 at hn
  linarith
174
lemma layouts_affineMap (M : Machine Q Γ) (i : ActiveRow M) (x : Space) :
    (sourceLayout M).affineMap (targetLayout M) i x = (i.val.instruction M).fullMap M x :=
proof · 1 line
  Coding.layout_affineMap inverse_base_pos.ne' _ _ _ _ _ _ _
178
theorem exists_guarded_template (M : Machine Q Γ) :
    ∃ (v : Velocity) (K : Set Space), IsCompact K ∧ JointSmooth v ∧ TimeCollars v ∧
      SpatiallySupported K v ∧ (∀ t x, div v t x = 0) ∧ GuardedTemplate M v := by
proof · 16 lines
  obtain ⟨η, hη, ⟨m⟩⟩ := guarded_solid_box_motion (sourceLayout M) (targetLayout M)
    (safeRows M) (sourceLayout_positive M) (targetLayout_positive M)
    (sourceLayout_separated M) (targetLayout_separated M) (layouts_equal_volume M)
    (sourceLayout_guard M) (targetLayout_guard M)
  obtain ⟨K, hK, hs⟩ := m.velocity_compact_support hη
  refine ⟨m.velocity, K, hK, m.velocity_jointSmooth, m.velocity_collars, hs,
    m.velocity_divergence, ?_⟩
  intro r hr x hx
  let i : ActiveRow M := ⟨r, (mem_table M r).mpr hr⟩
  have hm : x ∈ (sourceLayout M).solid i := by rwa [sourceLayout_solid]
  refine ⟨m.path i x, m.path_start i x, ?_, ?_, ?_⟩
  · rw [m.path_end, layouts_affineMap]
  · intro t _
    exact (m.path_hasDerivAt hη hm t).hasDerivWithinAt
  · intro hsafe t _
    exact m.path_guarded hsafe hm t