roseking's picture
Add lean source and binary files (part 91)
caec230 verified
Raw History Blame Contribute Delete
6.91 kB
16
theorem time_in_stage {ν K D t : ℝ} (hν : 0 < ν) (hK : 0 ≤ K) (hD : 1 ≤ D) (ht : 1 ≤ t) :
    ∃ n, t ∈ Icc (startTime ν K D n) (startTime ν K D (n + 1)) := by
proof · 13 lines
  have hex : ∃ n, t < startTime ν K D (n + 1) := by
    obtain ⟨n, hn⟩ := exists_nat_gt t
    refine ⟨n, ?_⟩
    have hs := startTime_ge hν hK hD (n + 1)
    simp only [Nat.cast_add, Nat.cast_one] at hs
    linarith
  let n := Nat.find hex
  refine ⟨n, ?_, (Nat.find_spec hex).le⟩
  cases hn : n with
  | zero => simpa only [hn, startTime] using ht
  | succ k =>
    have hk : ¬t < startTime ν K D (k + 1) := Nat.find_min hex (by omega : k < Nat.find hex)
    simpa only [hn] using not_lt.mp hk
46
def point (n : ℕ) : Coord 2 :=
body · 3 lines
  let c := orbit hb table c₀ n
  ![spacing ν (K₀ N b m) (D b) n * address (capacity b m n) c.state c.leftStack c.rightStack,
    sign terminal c.state * spacing ν (K₀ N b m) (D b) n]
51
def runPath (n : ℕ) : ℝ → Coord 2 :=
body · 8 lines
  let c := orbit hb table c₀ n
  let d := orbit hb table c₀ (n + 1)
  CenterPaths.signedCenter (startTime ν (K₀ N b m) (D b) n)
    (duration ν (K₀ N b m) (D b) n)
    (spacing ν (K₀ N b m) (D b) n) (spacing ν (K₀ N b m) (D b) (n + 1))
    (sign terminal c.state) (sign terminal d.state)
    (address (capacity b m n) c.state c.leftStack c.rightStack)
    (address (capacity b m (n + 1)) d.state d.leftStack d.rightStack)
61
@[fun_prop] theorem contDiff_runPath (n : ℕ) : ContDiff ℝ ∞ (runPath hb table terminal ν m c₀ n) :=
proof · 1 line
  CenterPaths.contDiff_signedCenter _ _ _ _ _ _ _ _
64
theorem runPath_start (n : ℕ) :
    runPath hb table terminal ν m c₀ n (startTime ν (K₀ N b m) (D b) n) =
      point hb table terminal ν m c₀ n := CenterPaths.signed_start _ _ _ _ _ _ _ _
68
theorem runPath_end (hν : 0 < ν) (n : ℕ) :
    runPath hb table terminal ν m c₀ n (startTime ν (K₀ N b m) (D b) (n + 1)) =
      point hb table terminal ν m c₀ (n + 1) :=
proof · 2 lines
  CenterPaths.signed_end
    (lt_of_lt_of_le zero_lt_one (duration_ge_one hν (K₀_nonneg N b m) (D_ge_one hb) n)) _ _ _ _ _ _ _
74
theorem runPath_joins (hν : 0 < ν) (n : ℕ) :
    runPath hb table terminal ν m c₀ n (startTime ν (K₀ N b m) (D b) (n + 1)) =
      runPath hb table terminal ν m c₀ (n + 1) (startTime ν (K₀ N b m) (D b) (n + 1)) := by
proof · 1 line
  rw [runPath_end hb table terminal ν m c₀ hν, runPath_start]
95
def runBox (n : ℕ) : Box N (capacity b m n) :=
body · 3 lines
  let c := orbit hb table c₀ n
  ⟨c.state, ⟨c.leftStack, (orbit_fits hb table hm c₀ hc₀ n).1⟩,
    ⟨c.rightStack, (orbit_fits hb table hm c₀ hc₀ n).2⟩⟩
100
@[simp] theorem runBox_config (n : ℕ) :
    config (runBox hb table m c₀ hm hc₀ n) = orbit hb table c₀ n := by
proof · 2 lines
  cases h : orbit hb table c₀ n
  simp only [config, runBox, h]
105
def runActive (n : ℕ) (h : (lookup hb table (orbit hb table c₀ n)).isSome) :
    Active hb table (capacity b m n) := ⟨runBox hb table m c₀ hm hc₀ n, h⟩
108
theorem target_runActive (n : ℕ) (h : (lookup hb table (orbit hb table c₀ n)).isSome) :
    target hb table (runActive hb table m c₀ hm hc₀ n h) = orbit hb table c₀ (n + 1) := by
proof · 4 lines
  rw [target, show (runActive hb table m c₀ hm hc₀ n h).val = runBox hb table m c₀ hm hc₀ n from rfl,
    runBox_config, orbit_succ]
  apply (next_eq_of_lookup hb table _).symm
  exact (Option.some_get h).symm
115
theorem runPath_eq_installed (hterm : NoOutgoing table terminal) (n : ℕ)
    (h : (lookup hb table (orbit hb table c₀ n)).isSome) :
    runPath hb table terminal ν m c₀ n =
      path hb table terminal ν m n (runActive hb table m c₀ hm hc₀ n h) := by
proof · 8 lines
  have hs : sign terminal (orbit hb table c₀ n).state = -1 :=
    ite_eq_right (lookup_source_nonterminal hb table hterm h)
  dsimp only [runPath]
  rw [hs, CenterPaths.signed_source_negative]
  unfold path
  rw [target_runActive hb table m c₀ hm hc₀ n h]
  congr 1
  simp only [targetAddress, target_runActive hb table m c₀ hm hc₀ n h, capacity_succ]
130
theorem runPath_plateau (hν : 0 < ν) (hdir : IncomingDirection table) (hin : IncomingRule table)
    (hterm : NoOutgoing table terminal) (n : ℕ)
    (h : (lookup hb table (orbit hb table c₀ n)).isSome) {t : ℝ}
    (ht : t ∈ Icc (startTime ν (K₀ N b m) (D b) n) (startTime ν (K₀ N b m) (D b) (n + 1)))
    (X : Coord 2) (hX : ∀ i, |X i - runPath hb table terminal ν m c₀ n t i| ≤
      radius ν (K₀ N b m) (D b) n) :
    field hb table terminal ν m t X = deriv (runPath hb table terminal ν m c₀ n) t := by
proof · 3 lines
  rw [runPath_eq_installed hb table terminal ν m c₀ hm hc₀ hterm n h] at hX ⊢
  exact field_plateau hb table terminal ν m hν hm hdir hin n
    (runActive hb table m c₀ hm hc₀ n h) ht X hX
141
theorem runPath_negative (hν : 0 < ν) (hterm : NoOutgoing table terminal) (n : ℕ)
    (h : (lookup hb table (orbit hb table c₀ n)).isSome)
    (hn : (orbit hb table c₀ (n + 1)).state ≠ terminal) (t : ℝ) :
    runPath hb table terminal ν m c₀ n t 1 ≤ -spacing ν (K₀ N b m) (D b) n := by
proof · 3 lines
  rw [runPath_eq_installed hb table terminal ν m c₀ hm hc₀ hterm n h]
  apply path_negative hb table terminal ν m hν
  rwa [target_runActive]