File size: 17,073 Bytes
4a56cd6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
import OAI.MathematicalPhysics.NavierStokes.VelocityDetection.CutoffRetention
import OAI.MathematicalPhysics.NavierStokes.VelocityDetection.ArrayTrajectories
import OAI.MathematicalPhysics.NavierStokes.VelocityDetection.CutoffCutoffZeroOnUpper

namespace OAI

noncomputable section
namespace VelocityDetection.ExpandingArray
open scoped BigOperators Topology ContDiff
open Set Function Filter
open Set Function Filter MeasureTheory
open scoped Topology BigOperators ContDiff
open scoped Topology ContDiff BigOperators
open Expanding Stacks FiniteAddresses MovingCutoff SmoothProfiles SpatialCalculus
variable {N b : β„•} (hb : 0 < b) (table : Fin N β†’ Fin b β†’ Option (Rule (Fin N) b))
    (terminal : Fin N) (Ξ½ : ℝ) (m : β„•) (cβ‚€ : Configuration (Fin N))

def loss : ℝ := Ξ½ * 3000 * ((initialRadius Ξ½ (Kβ‚€ N b m) (D b))⁻¹ ^ 2 +
  βˆ‘' n : β„•, duration Ξ½ (Kβ‚€ N b m) (D b) n / radius Ξ½ (Kβ‚€ N b m) (D b) n ^ 2)

include hb in

theorem loss_lt (hΞ½ : 0 < Ξ½) : loss (N := N) (b := b) Ξ½ m < (1 / 24 : ℝ) :=
  total_loss_lt hΞ½ (Kβ‚€_nonneg N b m) (D_ge_one hb)

include hb in

theorem loading_loss_le_loss (hΞ½ : 0 < Ξ½) :
    Ξ½ * 3000 / radius Ξ½ (Kβ‚€ N b m) (D b) 0 ^ 2 ≀ loss (N := N) (b := b) Ξ½ m := by
  have heq : Ξ½ * 3000 / radius Ξ½ (Kβ‚€ N b m) (D b) 0 ^ 2 =
      Ξ½ * 3000 * (initialRadius Ξ½ (Kβ‚€ N b m) (D b))⁻¹ ^ 2 := by
    simp only [radius, pow_zero, mul_one, inv_pow, div_eq_mul_inv]
  rw [heq, loss, mul_add]
  have hs : 0 ≀ βˆ‘' n : β„•, duration Ξ½ (Kβ‚€ N b m) (D b) n /
      radius Ξ½ (Kβ‚€ N b m) (D b) n ^ 2 :=
    tsum_nonneg (fun n => (loss_term_bound hΞ½ (Kβ‚€_nonneg N b m) (D_ge_one hb) n).1)
  have : 0 ≀ Ξ½ * 3000 * (βˆ‘' n : β„•, duration Ξ½ (Kβ‚€ N b m) (D b) n /
      radius Ξ½ (Kβ‚€ N b m) (D b) n ^ 2) := by positivity
  linarith

theorem field_slice_component (hΞ½ : 0 < Ξ½) (t : ℝ) (i : Fin 2) :
    ContDiff ℝ 1 (fun X => field hb table terminal Ξ½ m t X i) :=
  ((contDiff_apply ℝ ℝ i).comp
    (SpatialCalculus.contDiff_slice (contDiff_field hb table terminal Ξ½ m hΞ½) t)).of_le (by simp)

end VelocityDetection.ExpandingArray
end

noncomputable section
namespace VelocityDetection.ExpandingArray
open scoped BigOperators Topology ContDiff
open Set Function Filter
open Set Function Filter MeasureTheory
open scoped Topology BigOperators ContDiff
open scoped Topology ContDiff BigOperators
open Expanding Stacks FiniteAddresses MovingCutoff SmoothProfiles SpatialCalculus
variable {N b : β„•} (hb : 0 < b) (table : Fin N β†’ Fin b β†’ Option (Rule (Fin N) b))
    (terminal : Fin N) (Ξ½ : ℝ) (m : β„•) (cβ‚€ : Configuration (Fin N))
variable (hν : 0 < ν) {ρ : ScalarField 2}
    (hρ : ContDiff ℝ 2 (uncurry ρ))
    (heq : βˆ€ t, 0 ≀ t β†’ βˆ€ X,
      deriv (fun s => ρ s X) t + advection (field hb table terminal ν m) ρ t X =
        Ξ½ * laplacian ρ t X + impulse (point hb table terminal Ξ½ m cβ‚€ 0) t X)
    (hρinit : βˆ€ X, ρ 0 X = 0)
    (hρint : βˆ€ t, 0 ≀ t β†’ Integrable (ρ t))
    (hρnonneg : βˆ€ t, 0 ≀ t β†’ βˆ€ X, 0 ≀ ρ t X)
    (hmass : βˆ€ t, 0 ≀ t β†’ (∫ X, ρ t X) = step t)

include hν hρ heq hρinit hρint hρnonneg hmass

theorem retained_loading {t : ℝ} (ht : t ∈ Icc (0 : ℝ) 1) :
    (∫ X, ρ t X) - capture (radius Ξ½ (Kβ‚€ N b m) (D b) 0)
        (fun _ => point hb table terminal Ξ½ m cβ‚€ 0) ρ t ≀
      Ξ½ * 3000 / radius Ξ½ (Kβ‚€ N b m) (D b) 0 ^ 2 := by
  have hR : 0 < radius Ξ½ (Kβ‚€ N b m) (D b) 0 :=
    lt_of_lt_of_le zero_lt_one (radius_ge_one hΞ½ (Kβ‚€_nonneg N b m) (D_ge_one hb) 0)
  have hu (s : ℝ) (hs : s ∈ Ioo (0 : ℝ) t) : 0 ≀ s := hs.1.le
  have h := retention_on_interval (Ξ½ := Ξ½)
    (R := radius Ξ½ (Kβ‚€ N b m) (D b) 0)
    (a := field hb table terminal Ξ½ m) (g := impulse (point hb table terminal Ξ½ m cβ‚€ 0))
    (c := fun _ => point hb table terminal Ξ½ m cβ‚€ 0) (M := step)
    hR hν.le ht.1 hρ contDiff_const Real.smoothTransition.continuous.continuousOn
    (fun s _ => by rw [integral_impulse]; exact (differentiable_step s).hasDerivAt)
    (fun s _ => field_slice_component hb table terminal Ξ½ m hΞ½ s)
    (fun s _ => (contDiff_impulse (point hb table terminal Ξ½ m cβ‚€ 0)).continuous.comp
      (continuous_const.prodMk continuous_id))
    (fun s _ X => divergence_field hb table terminal Ξ½ m hΞ½ s X)
    (fun s hs X => heq s (hu s hs) X)
    (fun s hs X _ => by
      rw [field_at_rest hb table terminal Ξ½ m hΞ½ (hs.2.le.trans ht.2) X]
      symm
      exact deriv_const s _)
    (fun s hs => hρint s (hu s hs)) (fun s hs => hρnonneg s (hu s hs))
    (fun s hs => by rw [hmass s (hu s hs)]; exact Real.smoothTransition.le_one s)
    (fun s _ X hX i => by
      have hsupport := (impulse_support_bound (point hb table terminal Ξ½ m cβ‚€ 0) X s hX).2.2 i
      have hlarge := radius_ge_one hΞ½ (Kβ‚€_nonneg N b m) (D_ge_one hb) 0
      linarith)
  have hz : capture (radius Ξ½ (Kβ‚€ N b m) (D b) 0)
      (fun _ => point hb table terminal Ξ½ m cβ‚€ 0) ρ 0 = 0 := by
    simp only [capture, hρinit, mul_zero, integral_zero]
  rw [hz, show step 0 = 0 from Real.smoothTransition.zero_of_nonpos le_rfl, zero_sub,
    sub_zero, ← hmass t ht.1] at h
  have hm := mul_le_mul_of_nonneg_left ht.2 (by positivity :
    0 ≀ Ξ½ * 3000 / radius Ξ½ (Kβ‚€ N b m) (D b) 0 ^ 2)
  exact h.trans (by simpa using hm)

theorem retained_at_loading_end :
    step (startTime Ξ½ (Kβ‚€ N b m) (D b) 0) -
      capture (radius Ξ½ (Kβ‚€ N b m) (D b) 0) (runPath hb table terminal Ξ½ m cβ‚€ 0) ρ
        (startTime Ξ½ (Kβ‚€ N b m) (D b) 0) ≀
      Ξ½ * 3000 / radius Ξ½ (Kβ‚€ N b m) (D b) 0 ^ 2 := by
  have hc : capture (radius Ξ½ (Kβ‚€ N b m) (D b) 0)
      (runPath hb table terminal Ξ½ m cβ‚€ 0) ρ (startTime Ξ½ (Kβ‚€ N b m) (D b) 0) =
      capture (radius Ξ½ (Kβ‚€ N b m) (D b) 0)
      (fun _ => point hb table terminal Ξ½ m cβ‚€ 0) ρ 1 := by
    unfold capture
    rw [runPath_start]
    rfl
  rw [hc]
  change step 1 - _ ≀ _
  rw [← hmass 1 (by norm_num)]
  exact retained_loading hb table terminal Ξ½ m cβ‚€ hΞ½ hρ heq hρinit hρint hρnonneg hmass ⟨by norm_num, le_rfl⟩

end VelocityDetection.ExpandingArray
end

noncomputable section
namespace VelocityDetection.ExpandingArray
open scoped BigOperators Topology ContDiff
open Set Function Filter
open Set Function Filter MeasureTheory
open scoped Topology BigOperators ContDiff
open scoped Topology ContDiff BigOperators
open Expanding Stacks FiniteAddresses MovingCutoff SmoothProfiles SpatialCalculus
variable {N b : β„•} (hb : 0 < b) (table : Fin N β†’ Fin b β†’ Option (Rule (Fin N) b))
    (terminal : Fin N) (Ξ½ : ℝ) (m : β„•) (cβ‚€ : Configuration (Fin N))
variable (hν : 0 < ν) {ρ : ScalarField 2}
    (hρ : ContDiff ℝ 2 (uncurry ρ))
    (heq : βˆ€ t, 0 ≀ t β†’ βˆ€ X,
      deriv (fun s => ρ s X) t + advection (field hb table terminal ν m) ρ t X =
        Ξ½ * laplacian ρ t X + impulse (point hb table terminal Ξ½ m cβ‚€ 0) t X)
    (hρinit : βˆ€ X, ρ 0 X = 0)
    (hρint : βˆ€ t, 0 ≀ t β†’ Integrable (ρ t))
    (hρnonneg : βˆ€ t, 0 ≀ t β†’ βˆ€ X, 0 ≀ ρ t X)
    (hmass : βˆ€ t, 0 ≀ t β†’ (∫ X, ρ t X) = step t)

include hν hρ heq hρinit hρint hρnonneg hmass
variable (hm : 1 ≀ m)
    (hcβ‚€ : cβ‚€.leftStack < capacity b m 0 ∧ cβ‚€.rightStack < capacity b m 0)
    (hdir : IncomingDirection table) (hin : IncomingRule table) (hterm : NoOutgoing table terminal)

include hm hcβ‚€ hdir hin hterm

theorem retained_stages {n : β„•}
    (hactive : βˆ€ k ≀ n, (lookup hb table (orbit hb table cβ‚€ k)).isSome)
    {t : ℝ} (ht : t ∈ Icc (startTime Ξ½ (Kβ‚€ N b m) (D b) n)
      (startTime Ξ½ (Kβ‚€ N b m) (D b) (n + 1))) :
    (∫ X, ρ t X) - capture (radius Ξ½ (Kβ‚€ N b m) (D b) n)
      (runPath hb table terminal Ξ½ m cβ‚€ n) ρ t ≀ loss (N := N) (b := b) Ξ½ m := by
  have hR (k : β„•) : 0 < radius Ξ½ (Kβ‚€ N b m) (D b) k :=
    lt_of_lt_of_le zero_lt_one (radius_ge_one hΞ½ (Kβ‚€_nonneg N b m) (D_ge_one hb) k)
  have hΟ„ (k : β„•) : startTime Ξ½ (Kβ‚€ N b m) (D b) k ≀ startTime Ξ½ (Kβ‚€ N b m) (D b) (k + 1) :=
    (startTime_strictMono hΞ½ (Kβ‚€_nonneg N b m) (D_ge_one hb)).monotone (Nat.le_succ k)
  have hu (k : β„•) (s : ℝ) (hs : s ∈ Icc (startTime Ξ½ (Kβ‚€ N b m) (D b) k)
      (startTime Ξ½ (Kβ‚€ N b m) (D b) (k + 1))) : 1 ≀ s := by
    linarith [startTime_ge hΞ½ (Kβ‚€_nonneg N b m) (D_ge_one hb) k,
      Nat.cast_nonneg (Ξ± := ℝ) k, hs.1]
  have loss_eq (k : β„•) :
      (Ξ½ * 3000 / radius Ξ½ (Kβ‚€ N b m) (D b) k ^ 2) *
        (startTime Ξ½ (Kβ‚€ N b m) (D b) (k + 1) - startTime Ξ½ (Kβ‚€ N b m) (D b) k) =
      Ξ½ * 3000 * (duration Ξ½ (Kβ‚€ N b m) (D b) k / radius Ξ½ (Kβ‚€ N b m) (D b) k ^ 2) := by
    rw [startTime, add_sub_cancel_left]
    ring
  have hsummable : Summable (fun k => (Ξ½ * 3000 / radius Ξ½ (Kβ‚€ N b m) (D b) k ^ 2) *
      (startTime Ξ½ (Kβ‚€ N b m) (D b) (k + 1) - startTime Ξ½ (Kβ‚€ N b m) (D b) k)) := by
    simp_rw [loss_eq]
    exact (summable_loss hΞ½ (Kβ‚€_nonneg N b m) (D_ge_one hb)).mul_left _
  have h := retention_le_series (Ξ½ := Ξ½)
    (R := radius Ξ½ (Kβ‚€ N b m) (D b)) (Ο„ := startTime Ξ½ (Kβ‚€ N b m) (D b))
    (a := field hb table terminal Ξ½ m) (g := impulse (point hb table terminal Ξ½ m cβ‚€ 0))
    (c := runPath hb table terminal Ξ½ m cβ‚€) (M := step)
    hΞ½.le hR hΟ„ (radius_next_ge hΞ½ (Kβ‚€_nonneg N b m) (D_ge_one hb)) hρ
    (fun k => (contDiff_runPath hb table terminal Ξ½ m cβ‚€ k).of_le (by simp))
    (runPath_joins hb table terminal Ξ½ m cβ‚€ hΞ½)
    (fun _ => Real.smoothTransition.continuous.continuousOn)
    (fun _ s _ => by rw [integral_impulse]; exact (differentiable_step s).hasDerivAt)
    (fun _ s _ => field_slice_component hb table terminal Ξ½ m hΞ½ s)
    (fun _ s _ => (contDiff_impulse (point hb table terminal Ξ½ m cβ‚€ 0)).continuous.comp
      (continuous_const.prodMk continuous_id))
    (fun _ s _ X => divergence_field hb table terminal Ξ½ m hΞ½ s X)
    (fun k s hs X => heq s (by linarith [hu k s ⟨hs.1.le, hs.2.le⟩]) X)
    (fun k hk s hs X hX => runPath_plateau hb table terminal Ξ½ m cβ‚€ hm hcβ‚€ hΞ½ hdir hin hterm
      k (hactive k hk) ⟨hs.1.le, hs.2.le⟩ X hX)
    (fun k s hs => hρint s (by linarith [hu k s hs]))
    (fun k s hs => hρnonneg s (by linarith [hu k s hs]))
    (fun k s hs => by
      rw [hmass s (by linarith [hu k s ⟨hs.1.le, hs.2.le⟩])]
      exact Real.smoothTransition.le_one s)
    (fun k s hs X hX _ => by
      have hz := impulse_zero_of_time_one_le (point hb table terminal Ξ½ m cβ‚€ 0)
        (hu k s ⟨hs.1.le, hs.2.le⟩)
      exact False.elim (hX (congrFun hz X))) hsummable ht
  have hload := retained_at_loading_end hb table terminal Ξ½ m cβ‚€ hΞ½ hρ heq hρinit hρint hρnonneg hmass
  rw [← hmass t (by linarith [hu n t ht])] at h
  simp_rw [loss_eq] at h
  rw [tsum_mul_left] at h
  have hbudget : loss (N := N) (b := b) Ξ½ m = Ξ½ * 3000 / radius Ξ½ (Kβ‚€ N b m) (D b) 0 ^ 2 +
      Ξ½ * 3000 * (βˆ‘' k : β„•, duration Ξ½ (Kβ‚€ N b m) (D b) k / radius Ξ½ (Kβ‚€ N b m) (D b) k ^ 2) := by
    simp only [loss, mul_add, radius, pow_zero, mul_one, inv_pow, div_eq_mul_inv]
  rw [hbudget]
  linarith

end VelocityDetection.ExpandingArray
end

noncomputable section
namespace VelocityDetection.ExpandingArray
open scoped BigOperators Topology ContDiff
open Set Function Filter
open Set Function Filter MeasureTheory
open scoped Topology BigOperators ContDiff
open scoped Topology ContDiff BigOperators
open Expanding Stacks FiniteAddresses MovingCutoff SmoothProfiles SpatialCalculus
variable {N b : β„•} (hb : 0 < b) (table : Fin N β†’ Fin b β†’ Option (Rule (Fin N) b))
    (terminal : Fin N) (Ξ½ : ℝ) (m : β„•) (cβ‚€ : Configuration (Fin N))
variable (hν : 0 < ν) {ρ : ScalarField 2}
    (hρ : ContDiff ℝ 2 (uncurry ρ))
    (heq : βˆ€ t, 0 ≀ t β†’ βˆ€ X,
      deriv (fun s => ρ s X) t + advection (field hb table terminal ν m) ρ t X =
        Ξ½ * laplacian ρ t X + impulse (point hb table terminal Ξ½ m cβ‚€ 0) t X)
    (hρinit : βˆ€ X, ρ 0 X = 0)
    (hρint : βˆ€ t, 0 ≀ t β†’ Integrable (ρ t))
    (hρnonneg : βˆ€ t, 0 ≀ t β†’ βˆ€ X, 0 ≀ ρ t X)
    (hmass : βˆ€ t, 0 ≀ t β†’ (∫ X, ρ t X) = step t)

include hν hρ heq hρinit hρint hρnonneg hmass
variable (hm : 1 ≀ m)
    (hcβ‚€ : cβ‚€.leftStack < capacity b m 0 ∧ cβ‚€.rightStack < capacity b m 0)
    (hdir : IncomingDirection table) (hin : IncomingRule table) (hterm : NoOutgoing table terminal)

include hm hcβ‚€ hdir hin hterm
variable (hcont : Continues hb table terminal cβ‚€)

include hcont

theorem nonterminal_mass_small (hnever : Β¬ Reaches hb table terminal cβ‚€)
    {t : ℝ} (ht : 0 ≀ t) :
    (∫ X in Observation.upperHalfPlane, ρ t X) < (1 / 4 : ℝ) := by
  have hn (k : β„•) : (orbit hb table cβ‚€ k).state β‰  terminal := by
    intro he
    exact hnever ⟨k, he⟩
  have hactive (k : β„•) : (lookup hb table (orbit hb table cβ‚€ k)).isSome := hcont k (hn k)
  have hR (k : β„•) : 0 < radius Ξ½ (Kβ‚€ N b m) (D b) k :=
    lt_of_lt_of_le zero_lt_one (radius_ge_one hΞ½ (Kβ‚€_nonneg N b m) (D_ge_one hb) k)
  by_cases ht₁ : t ≀ 1
  · apply Cutoff.upper_mass_small (hR 0) (hρint t ht) (hρnonneg t ht)
      (c := point hb table terminal Ξ½ m cβ‚€ 0)
      (Ξ΄ := loss (N := N) (b := b) Ξ½ m)
    Β· have hc : point hb table terminal Ξ½ m cβ‚€ 0 1 = -spacing Ξ½ (Kβ‚€ N b m) (D b) 0 := by
        simp only [point, sign, ite_eq_right (hn 0), neg_one_mul, Matrix.cons_val_one, Matrix.cons_val_zero]
      rw [hc, spacing]
      linarith [hR 0]
    Β· exact loss_lt hb Ξ½ m hΞ½
    Β· exact (retained_loading hb table terminal Ξ½ m cβ‚€ hΞ½ hρ heq hρinit hρint hρnonneg hmass
        ⟨ht, htβ‚βŸ©).trans (loading_loss_le_loss hb Ξ½ m hΞ½)
  Β· obtain ⟨n, hstage⟩ := time_in_stage hΞ½ (Kβ‚€_nonneg N b m) (D_ge_one hb) (le_of_not_ge ht₁)
    apply Cutoff.upper_mass_small (hR n) (hρint t ht) (hρnonneg t ht)
      (c := runPath hb table terminal Ξ½ m cβ‚€ n t)
      (Ξ΄ := loss (N := N) (b := b) Ξ½ m)
    Β· have hneg := runPath_negative hb table terminal Ξ½ m cβ‚€ hm hcβ‚€ hΞ½ hterm n
        (hactive n) (hn (n + 1)) t
      rw [spacing] at hneg
      linarith [hR n]
    Β· exact loss_lt hb Ξ½ m hΞ½
    Β· exact retained_stages hb table terminal Ξ½ m cβ‚€ hΞ½ hρ heq hρinit hρint hρnonneg hmass
        hm hcβ‚€ hdir hin hterm (fun k _ => hactive k) hstage

theorem terminal_mass_large (hinit : cβ‚€.state β‰  terminal)
    (hreach : Reaches hb table terminal cβ‚€) :
    βˆƒ t : ℝ, 0 ≀ t ∧ (3 / 4 : ℝ) < ∫ X in Observation.upperHalfPlane, ρ t X := by
  let hex : βˆƒ n, (orbit hb table cβ‚€ n).state = terminal := hreach
  have hzero : Nat.find hex β‰  0 := by
    intro hz
    have h := Nat.find_spec hex
    rw [hz, orbit_zero] at h
    exact hinit h
  obtain ⟨n, hn⟩ := Nat.exists_eq_succ_of_ne_zero hzero
  have hfirst : (orbit hb table cβ‚€ (n + 1)).state = terminal := by
    simpa only [hn] using Nat.find_spec hex
  have hactive (k : β„•) (hk : k ≀ n) : (lookup hb table (orbit hb table cβ‚€ k)).isSome :=
    hcont k (Nat.find_min hex (by omega))
  let t := startTime Ξ½ (Kβ‚€ N b m) (D b) (n + 1)
  have ht₁ : 1 ≀ t := by
    have h := startTime_ge hΞ½ (Kβ‚€_nonneg N b m) (D_ge_one hb) (n + 1)
    dsimp [t]
    linarith [Nat.cast_nonneg (Ξ± := ℝ) (n + 1)]
  have ht : 0 ≀ t := by linarith
  have hR : 0 < radius Ξ½ (Kβ‚€ N b m) (D b) n :=
    lt_of_lt_of_le zero_lt_one (radius_ge_one hΞ½ (Kβ‚€_nonneg N b m) (D_ge_one hb) n)
  refine ⟨t, ht, ?_⟩
  apply Cutoff.upper_mass_large hR (hρint t ht) (hρnonneg t ht)
      (c := runPath hb table terminal Ξ½ m cβ‚€ n t)
      (Ξ΄ := loss (N := N) (b := b) Ξ½ m)
  Β· dsimp [t]
    rw [runPath_end hb table terminal Ξ½ m cβ‚€ hΞ½]
    have hc : point hb table terminal Ξ½ m cβ‚€ (n + 1) 1 =
        spacing Ξ½ (Kβ‚€ N b m) (D b) (n + 1) := by
      simp only [point, sign, hfirst, ite_true, one_mul, Matrix.cons_val_one, Matrix.cons_val_zero]
    rw [hc, spacing]
    linarith [radius_next_ge hΞ½ (Kβ‚€_nonneg N b m) (D_ge_one hb) n]
  Β· exact loss_lt hb Ξ½ m hΞ½
  Β· rw [hmass t ht]
    exact Real.smoothTransition.one_of_one_le ht₁
  Β· apply retained_stages hb table terminal Ξ½ m cβ‚€ hΞ½ hρ heq hρinit hρint hρnonneg hmass
      hm hcβ‚€ hdir hin hterm hactive
    exact ⟨(startTime_strictMono hΞ½ (Kβ‚€_nonneg N b m) (D_ge_one hb)).monotone (Nat.le_succ n), le_rfl⟩

theorem scalar_detection (hinit : cβ‚€.state β‰  terminal) :
    Observation.planeEvent (liftVelocity (field hb table terminal Ξ½ m) ρ) ↔
      Reaches hb table terminal cβ‚€ := by
  rw [Observation.planeEvent_lift]
  constructor
  · rintro ⟨t, ht, hmarg⟩
    by_contra hnever
    have h := nonterminal_mass_small hb table terminal Ξ½ m cβ‚€ hΞ½ hρ heq hρinit hρint hρnonneg hmass
      hm hcβ‚€ hdir hin hterm hcont hnever ht
    linarith
  Β· intro hreach
    obtain ⟨t, ht, hmarg⟩ := terminal_mass_large hb table terminal Ξ½ m cβ‚€ hΞ½ hρ heq hρinit hρint hρnonneg hmass
      hm hcβ‚€ hdir hin hterm hcont hinit hreach
    exact ⟨t, ht, lt_trans (by norm_num) hmarg⟩

end VelocityDetection.ExpandingArray
end

end OAI