roseking's picture
Add lean source and binary files (part 91)
caec230 verified
Raw History Blame Contribute Delete
10.7 kB
14
def ramp (r : ℝ) : ℝ := step (2 * r - 1 / 2)
16
@[fun_prop] theorem contDiff_ramp : ContDiff ℝ ∞ ramp := by
proof · 2 lines
  unfold ramp
  fun_prop
20
theorem ramp_nonneg (r : ℝ) : 0 ≤ ramp r := Real.smoothTransition.nonneg _
22
theorem ramp_le_one (r : ℝ) : ramp r ≤ 1 := Real.smoothTransition.le_one _
24
theorem ramp_zero {r : ℝ} (hr : r ≤ 1 / 4) : ramp r = 0 :=
proof · 1 line
  Real.smoothTransition.zero_of_nonpos (by linarith)
27
theorem ramp_one {r : ℝ} (hr : 3 / 4 ≤ r) : ramp r = 1 :=
proof · 1 line
  Real.smoothTransition.one_of_one_le (by linarith)
30
def theta (a T : ℝ) (j : ℕ) (t : ℝ) : ℝ := ramp (3 * (t - a) / T - j)
32
def privateRow (S : ℝ) (k : ℕ) : ℝ := -((k : ℝ) + 2) * S
34
def center (a T S S' σ : ℝ) (k l : ℕ) (t : ℝ) : Coord 2 :=
body · 3 lines
  ![(1 - theta a T 1 t) * S * k + theta a T 1 t * S' * l,
    -(1 - theta a T 0 t) * S +
      (theta a T 0 t - theta a T 2 t) * privateRow S k + theta a T 2 t * σ * S']
39
@[fun_prop] theorem contDiff_theta (a T : ℝ) (j : ℕ) : ContDiff ℝ ∞ (theta a T j) := by
proof · 2 lines
  unfold theta
  fun_prop
43
@[fun_prop] theorem contDiff_center (a T S S' σ : ℝ) (k l : ℕ) :
    ContDiff ℝ ∞ (center a T S S' σ k l) := by
proof · 3 lines
  apply contDiff_pi.mpr
  intro i
  fin_cases i <;> simp [center] <;> fun_prop
49
theorem center_first_slot {a T S S' σ t : ℝ} (k l : ℕ)
    (ht : 3 * (t - a) / T ≤ 1) :
    center a T S S' σ k l t 0 = S * k := by
proof · 2 lines
  have h1 : theta a T 1 t = 0 := ramp_zero (by norm_num only [Nat.cast_ofNat, Nat.cast_zero]; linarith)
  simp [center, h1]
55
theorem center_second_slot {a T S S' σ t : ℝ} (k l : ℕ)
    (ht : 1 ≤ 3 * (t - a) / T) (ht' : 3 * (t - a) / T ≤ 2) :
    center a T S S' σ k l t 1 = privateRow S k := by
proof · 3 lines
  have h0 : theta a T 0 t = 1 := ramp_one (by norm_num only [Nat.cast_ofNat, Nat.cast_zero]; linarith)
  have h2 : theta a T 2 t = 0 := ramp_zero (by norm_num only [Nat.cast_ofNat, Nat.cast_zero]; linarith)
  simp [center, h0, h2]
62
theorem center_third_slot {a T S S' σ t : ℝ} (k l : ℕ)
    (ht : 2 ≤ 3 * (t - a) / T) :
    center a T S S' σ k l t 0 = S' * l := by
proof · 2 lines
  have h1 : theta a T 1 t = 1 := ramp_one (by norm_num only [Nat.cast_ofNat, Nat.cast_zero]; linarith)
  simp [center, h1]
68
theorem nat_gap {k l : ℕ} (hkl : k ≠ l) : (1 : ℝ) ≤ |(k : ℝ) - l| := by
proof · 5 lines
  rcases lt_or_gt_of_ne hkl with h | h
  · have h' : (k : ℝ) + 1 ≤ l := by exact_mod_cast Nat.succ_le_of_lt h
    exact le_abs.mpr (Or.inr (by linarith))
  · have h' : (l : ℝ) + 1 ≤ k := by exact_mod_cast Nat.succ_le_of_lt h
    exact le_abs.mpr (Or.inl (by linarith))
75
theorem scaled_nat_gap {S : ℝ} (hS : 0 ≤ S) {k l : ℕ} (hkl : k ≠ l) :
    S ≤ |S * k - S * l| := by
proof · 2 lines
  rw [← mul_sub, abs_mul, abs_of_nonneg hS]
  simpa using mul_le_mul_of_nonneg_left (nat_gap hkl) hS
80
theorem separated {S S' : ℝ} (hS : 0 ≤ S) (hSS : S ≤ S')
    (a T σ τ t : ℝ) {k l k' l' : ℕ} (hkl : k ≠ l) (hkl' : k' ≠ l') :
    ∃ i : Fin 2, S ≤ |center a T S S' σ k k' t i - center a T S S' τ l l' t i| := by
proof · 16 lines
  by_cases h1 : 3 * (t - a) / T ≤ 1
  · refine ⟨0, ?_⟩
    rw [center_first_slot k k' h1, center_first_slot l l' h1]
    exact scaled_nat_gap hS hkl
  · by_cases h2 : 3 * (t - a) / T ≤ 2
    · refine ⟨1, ?_⟩
      rw [center_second_slot k k' (by linarith) h2,
        center_second_slot l l' (by linarith) h2]
      have hrow : privateRow S k - privateRow S l = -(S * k - S * l) := by
        dsimp [privateRow]
        ring
      rw [hrow, abs_neg]
      exact scaled_nat_gap hS hkl
    · refine ⟨0, ?_⟩
      rw [center_third_slot k k' (by linarith), center_third_slot l l' (by linarith)]
      exact hSS.trans (scaled_nat_gap (hS.trans hSS) hkl')
100
theorem negative_height {S S' : ℝ} (hS : 0 ≤ S) (hSS : S ≤ S')
    (a T t : ℝ) (k l : ℕ) : center a T S S' (-1) k l t 1 ≤ -S := by
proof · 19 lines
  have hrow : privateRow S k ≤ -S := by
    dsimp [privateRow]
    nlinarith [show (0 : ℝ) ≤ k from Nat.cast_nonneg k]
  have hθ (j : ℕ) : 0 ≤ theta a T j t ∧ theta a T j t ≤ 1 :=
    ⟨ramp_nonneg _, ramp_le_one _⟩
  by_cases h1 : 3 * (t - a) / T ≤ 1
  · have h2 : theta a T 2 t = 0 := ramp_zero (by norm_num only [Nat.cast_ofNat, Nat.cast_zero]; linarith)
    simp [center, h2]
    have := mul_le_mul_of_nonneg_left hrow (hθ 0).1
    nlinarith
  · by_cases h2 : 3 * (t - a) / T ≤ 2
    · rw [center_second_slot k l (by linarith) h2]
      exact hrow
    · have h0 : theta a T 0 t = 1 := ramp_one (by norm_num only [Nat.cast_ofNat, Nat.cast_zero]; linarith)
      simp [center, h0]
      have hw : 0 ≤ 1 - theta a T 2 t := by linarith [(hθ 2).2]
      have hp := mul_le_mul_of_nonneg_left hrow hw
      have hq := mul_le_mul_of_nonneg_left hSS (hθ 2).1
      nlinarith
122
theorem center_source_collar {a T S S' σ t : ℝ} (k l : ℕ)
    (ht : 3 * (t - a) / T ≤ 1 / 4) :
    center a T S S' σ k l t = ![S * k, -S] := by
proof · 4 lines
  have h0 : theta a T 0 t = 0 := ramp_zero (by norm_num only [Nat.cast_ofNat, Nat.cast_zero]; linarith)
  have h1 : theta a T 1 t = 0 := ramp_zero (by norm_num only [Nat.cast_ofNat, Nat.cast_zero]; linarith)
  have h2 : theta a T 2 t = 0 := ramp_zero (by norm_num only [Nat.cast_ofNat, Nat.cast_zero]; linarith)
  simp [center, h0, h1, h2]
130
theorem center_target_collar {a T S S' σ t : ℝ} (k l : ℕ)
    (ht : 11 / 4 ≤ 3 * (t - a) / T) :
    center a T S S' σ k l t = ![S' * l, σ * S'] := by
proof · 4 lines
  have h0 : theta a T 0 t = 1 := ramp_one (by norm_num only [Nat.cast_ofNat, Nat.cast_zero]; linarith)
  have h1 : theta a T 1 t = 1 := ramp_one (by norm_num only [Nat.cast_ofNat, Nat.cast_zero]; linarith)
  have h2 : theta a T 2 t = 1 := ramp_one (by norm_num only [Nat.cast_ofNat, Nat.cast_zero]; linarith)
  simp [center, h0, h1, h2]
138
theorem center_start (a T S S' σ : ℝ) (k l : ℕ) :
    center a T S S' σ k l a = ![S * k, -S] :=
proof · 1 line
  center_source_collar k l (by simp)
142
theorem center_end {T : ℝ} (hT : 0 < T) (a S S' σ : ℝ) (k l : ℕ) :
    center a T S S' σ k l (a + T) = ![S' * l, σ * S'] := by
proof · 4 lines
  apply center_target_collar
  have hT0 : T ≠ 0 := ne_of_gt hT
  field_simp
  linarith
149
@[fun_prop] theorem contDiff_velocity (a T S S' σ : ℝ) (k l : ℕ) :
    ContDiff ℝ ∞ (deriv (center a T S S' σ k l)) :=
proof · 1 line
  (contDiff_infty_iff_deriv.mp (contDiff_center a T S S' σ k l)).2
153
theorem velocity_source_collar {a T S S' σ t : ℝ} (k l : ℕ)
    (ht : 3 * (t - a) / T < 1 / 4) : deriv (center a T S S' σ k l) t = 0 := by
proof · 6 lines
  have hev : ∀ᶠ s in 𝓝 t, 3 * (s - a) / T < 1 / 4 :=
    (isOpen_lt (f := fun s : ℝ => 3 * (s - a) / T) (by fun_prop) continuous_const).mem_nhds ht
  have heq : center a T S S' σ k l =ᶠ[𝓝 t] fun _ => ![S * k, -S] :=
    hev.mono (fun s hs => center_source_collar k l hs.le)
  rw [heq.deriv_eq]
  simp
162
theorem velocity_target_collar {a T S S' σ t : ℝ} (k l : ℕ)
    (ht : 11 / 4 < 3 * (t - a) / T) : deriv (center a T S S' σ k l) t = 0 := by
proof · 6 lines
  have hev : ∀ᶠ s in 𝓝 t, 11 / 4 < 3 * (s - a) / T :=
    (isOpen_lt continuous_const (g := fun s : ℝ => 3 * (s - a) / T) (by fun_prop)).mem_nhds ht
  have heq : center a T S S' σ k l =ᶠ[𝓝 t] fun _ => ![S' * l, σ * S'] :=
    hev.mono (fun s hs => center_target_collar k l hs.le)
  rw [heq.deriv_eq]
  simp
171
def gate (R a T S S' σ : ℝ) (k l : ℕ) (t : ℝ) (X : Coord 2) : Coord 2 :=
body · 2 lines
  TranslationGates.field R (center a T S S' σ k l t)
    (deriv (center a T S S' σ k l) t) X
175
@[fun_prop] theorem contDiff_gate (R a T S S' σ : ℝ) (k l : ℕ) :
    ContDiff ℝ ∞ (uncurry (gate R a T S S' σ k l)) :=
proof · 2 lines
  TranslationGates.contDiff_movingField R (contDiff_center a T S S' σ k l)
    (contDiff_velocity a T S S' σ k l)
180
theorem gate_divergence (R a T S S' σ : ℝ) (k l : ℕ) (t : ℝ) (X : Coord 2) :
    divergence (gate R a T S S' σ k l) t X = 0 := by
proof · 3 lines
  simpa only [divergence, spatialD, gate] using
    TranslationGates.divergence_field R (center a T S S' σ k l t)
      (deriv (center a T S S' σ k l) t) X
186
theorem gate_zero_before {T : ℝ} (hT : 0 < T) (R a S S' σ : ℝ) (k l : ℕ)
    {t : ℝ} (ht : t ≤ a) (X : Coord 2) : gate R a T S S' σ k l t X = 0 := by
proof · 4 lines
  unfold gate
  rw [velocity_source_collar k l, TranslationGates.field_zero_velocity]
  have hq : 3 * (t - a) / T ≤ 0 := div_nonpos_of_nonpos_of_nonneg (by linarith) hT.le
  linarith
193
theorem gate_zero_after {T : ℝ} (hT : 0 < T) (R a S S' σ : ℝ) (k l : ℕ)
    {t : ℝ} (ht : a + T ≤ t) (X : Coord 2) : gate R a T S S' σ k l t X = 0 := by
proof · 4 lines
  unfold gate
  rw [velocity_target_collar k l, TranslationGates.field_zero_velocity]
  have hq : 3 ≤ 3 * (t - a) / T := (le_div_iff₀ hT).mpr (by linarith)
  linarith
200
theorem compactSupport_gate {R T : ℝ} (hR : 0 < R) (hT : 0 < T)
    (a S S' σ : ℝ) (k l : ℕ) :
    HasCompactSupport (uncurry (gate R a T S S' σ k l)) := by
proof · 22 lines
  let c := center a T S S' σ k l
  let F : ℝ × Coord 2 → ℝ × Coord 2 := fun q => (q.1, c q.1 + q.2)
  have hc : Continuous c := (contDiff_center a T S S' σ k l).continuous
  have hF : Continuous F := continuous_fst.prodMk ((hc.comp continuous_fst).add continuous_snd)
  apply HasCompactSupport.of_support_subset_isCompact
    ((isCompact_Icc.prod (isCompact_Icc : IsCompact (Icc (fun _ : Fin 2 => -3 * R)
      (fun _ : Fin 2 => 3 * R)))).image hF)
  intro q hq
  have ht : q.1 ∈ Icc a (a + T) := by
    constructor
    · exact (lt_of_not_ge (fun h => hq (gate_zero_before hT R a S S' σ k l h q.2))).le
    · exact (lt_of_not_ge (fun h => hq (gate_zero_after hT R a S S' σ k l h q.2))).le
  have hi (i : Fin 2) : |q.2 i - c q.1 i| < 3 * R := by
    apply lt_of_not_ge
    intro h
    exact hq (TranslationGates.field_zero_outside hR _ _ _ ⟨i, h⟩)
  refine ⟨(q.1, q.2 - c q.1), ⟨ht, ?_⟩, ?_⟩
  · exact ⟨fun i => by dsimp; linarith [(abs_lt.mp (hi i)).1],
      fun i => by dsimp; linarith [(abs_lt.mp (hi i)).2]⟩
  · dsimp [F]
    congr 1
    abel
226
theorem gate_derivatives_bounded {R T : ℝ} (hR : 0 < R) (hT : 0 < T)
    (a S S' σ : ℝ) (k l m : ℕ) :
    ∃ C : ℝ, ∀ q, ‖iteratedFDeriv ℝ m (uncurry (gate R a T S S' σ k l)) q‖ ≤ C := by
proof · 2 lines
  apply ((compactSupport_gate hR hT a S S' σ k l).iteratedFDeriv m).exists_bound_of_continuous
  exact ((contDiff_infty.mp (contDiff_gate R a T S S' σ k l)) m).continuous_iteratedFDeriv le_rfl