cfahlgren1/math / lean /OAI /Combinatorics /EditApproximation /Refinement /PhysicalRefinementInvariants.lean
cfahlgren1's picture
download
raw
13.4 kB
import OAI.Combinatorics.EditApproximation.Refinement.PhysicalRefinement
namespace OAI
/-! Deterministic Bellman invariants of the complete physical recurrence. -/
namespace EditApproximation
theorem stageWarmup_at_terminal {α : Type*} [DecidableEq α] {M J : ℕ}
(source target : List α) (U : PhysicalEntry M J target.length → ℕ)
(N P F : ℕ) (A : ℚ) (t : ℕ) (node : PhysicalNode M J)
(hterminal : ¬ node.1.val < J ∨ (physicalSourceInterval source.length node).hi -
(physicalSourceInterval source.length node).lo ≤ 1) (q : TargetInterval target.length) :
stageWarmup source target U N P F A t (node, q) =
stageInitial source target U N P F A (node, q) := by
cases t with
| zero => rfl
| succ t =>
change rationalPhysicalBellman source target P (128 * F) _ _ _ (node, q) = _
unfold rationalPhysicalBellman
dsimp only
rcases hterminal with hlast | hleaf
· rw [dite_eq_right hlast]
· split_ifs <;> rfl
theorem physicalRefinement_at_terminal {α : Type*} [DecidableEq α] {M J : ℕ}
(source target : List α) (U : PhysicalEntry M J target.length → ℕ)
(N P F : ℕ) (A : ℚ) (T : ℕ) (delta : ℚ)
(choices : PhysicalSelections M J source.length target.length P
(stageRepresentatives source target U N P F A))
(node : PhysicalNode M J)
(hterminal : ¬ node.1.val < J ∨ (physicalSourceInterval source.length node).hi -
(physicalSourceInterval source.length node).lo ≤ 1) (t : ℕ) (q : TargetInterval target.length) :
physicalRefinement source target U N P F A T delta choices node t q =
stageInitial source target U N P F A (node, q) := by
rw [physicalRefinement]
rcases hterminal with hlast | hleaf
· rw [dite_eq_right hlast]
· split_ifs <;> rfl
theorem physicalRefinement_zero {α : Type*} [DecidableEq α] {M J : ℕ}
(source target : List α) (U : PhysicalEntry M J target.length → ℕ)
(N P F : ℕ) (A : ℚ) (T : ℕ) (delta : ℚ)
(choices : PhysicalSelections M J source.length target.length P
(stageRepresentatives source target U N P F A))
(node : PhysicalNode M J) (q : TargetInterval target.length) :
physicalRefinement source target U N P F A T delta choices node 0 q =
stageWarmup source target U N P F A T (node, q) := by
by_cases hbelow : node.1.val < J
· by_cases hleaf : (physicalSourceInterval source.length node).hi -
(physicalSourceInterval source.length node).lo ≤ 1
· rw [physicalRefinement_at_terminal _ _ _ _ _ _ _ _ _ _ node (Or.inr hleaf),
stageWarmup_at_terminal _ _ _ _ _ _ _ _ node (Or.inr hleaf)]
· rw [physicalRefinement, dite_eq_left hbelow, ite_eq_right hleaf]
· rw [physicalRefinement_at_terminal _ _ _ _ _ _ _ _ _ _ node (Or.inl hbelow),
stageWarmup_at_terminal _ _ _ _ _ _ _ _ node (Or.inl hbelow)]
theorem stageWarmup_postfixed {α : Type*} [DecidableEq α] {M J : ℕ}
(source target : List α) (U : PhysicalEntry M J target.length → ℕ)
(N P F : ℕ) (A : ℚ) (T : ℕ) (state : PhysicalEntry M J target.length) :
rationalPhysicalBellman source target P (128 * F) (stageInitial source target U N P F A)
(stageRepresentatives source target U N P F A)
(stageWarmup source target U N P F A T) state ≤
stageWarmup source target U N P F A T state := by
have h := physicalWarmup_nonincreasing source target P ((128 * F : ℚ) : ℝ)
(fun s => (stageInitial source target U N P F A s : ℝ))
(stageRepresentatives source target U N P F A) T state
apply (Rat.cast_le (K := ℝ)).mp
rw [rationalPhysicalBellman_cast]
simpa only [stageWarmup, rationalPhysicalWarmup_cast, physicalWarmup, warmup] using h
/-- The full recurrence is postfixed for the current-child Bellman operator,
and each next value is at most the previous-child Bellman value. Selected
actions require only their literal wide-list membership certificates. -/
theorem physicalRefinement_bellman_invariants {α : Type*} [DecidableEq α] {M J : ℕ}
(source target : List α) (U : PhysicalEntry M J target.length → ℕ)
(N P F : ℕ) (A : ℚ) (T : ℕ) (delta : ℚ)
(choices : PhysicalSelections M J source.length target.length P
(stageRepresentatives source target U N P F A)) (node : PhysicalNode M J) :
let value := fun t (s : PhysicalEntry M J target.length) =>
physicalRefinement source target U N P F A T delta choices s.1 t s.2
let bellman := rationalPhysicalBellman source target P (128 * F)
(stageInitial source target U N P F A) (stageRepresentatives source target U N P F A)
∀ t q, bellman (value t) (node, q) ≤ value t (node, q) ∧
value (t + 1) (node, q) ≤ bellman (value t) (node, q) := by
dsimp only
by_cases hbelow : node.1.val < J
· by_cases hleaf : (physicalSourceInterval source.length node).hi -
(physicalSourceInterval source.length node).lo ≤ 1
· intro t q
rw [physicalRefinement_at_terminal _ _ _ _ _ _ _ _ _ _ node (Or.inr hleaf),
physicalRefinement_at_terminal _ _ _ _ _ _ _ _ _ _ node (Or.inr hleaf)]
simp only [rationalPhysicalBellman, dite_eq_left hbelow, ite_eq_left hleaf]
exact ⟨le_rfl, le_rfl⟩
· let children : PhysicalChildTables M target.length := fun i =>
physicalRefinement source target U N P F A T delta choices (physicalChild node hbelow i)
have hchildren : ∀ t, (fun is : Fin M × TargetInterval target.length =>
children is.1 (t + 1) is.2) ≤ fun is => children is.1 t is.2 := by
intro t is
have ih := physicalRefinement_bellman_invariants source target U N P F A T delta choices
(physicalChild node hbelow is.1) t is.2
exact ih.2.trans ih.1
have hsandwich (t : ℕ) (q : TargetInterval target.length) :=
rationalWideStep_bellman_sandwich (physicalSourceInterval source.length node)
(stageRepresentatives source target U N P F A node) P
(fun r => stageInitial source target U N P F A (node, r)) (128 * F) delta
(fun is => children is.1 t is.2) (fun is => children is.1 (t + 1) is.2)
(hchildren t) (choices.groups node children (t + 1)) (choices.online node children (t + 1) q)
(choices.groups_mem node children (t + 1)) (choices.online_mem node children (t + 1) q) q
intro t q
constructor
· cases t with
| zero =>
simp_rw [physicalRefinement_zero]
exact stageWarmup_postfixed source target U N P F A T (node, q)
| succ t =>
rw [physicalRefinement_succ _ _ _ _ _ _ _ _ _ _ node hbelow hleaf]
simpa only [rationalPhysicalBellman, dite_eq_left hbelow, ite_eq_right hleaf]
using (hsandwich t q).1
· rw [physicalRefinement_succ _ _ _ _ _ _ _ _ _ _ node hbelow hleaf]
simpa only [rationalPhysicalBellman, dite_eq_left hbelow, ite_eq_right hleaf]
using (hsandwich t q).2
· intro t q
rw [physicalRefinement_at_terminal _ _ _ _ _ _ _ _ _ _ node (Or.inl hbelow),
physicalRefinement_at_terminal _ _ _ _ _ _ _ _ _ _ node (Or.inl hbelow)]
simp only [rationalPhysicalBellman, dite_eq_right hbelow]
exact ⟨le_rfl, le_rfl⟩
termination_by J - node.1.val
decreasing_by
unfold physicalChild
dsimp only
omega
theorem physicalRefinement_nonincreasing {α : Type*} [DecidableEq α] {M J : ℕ}
(source target : List α) (U : PhysicalEntry M J target.length → ℕ)
(N P F : ℕ) (A : ℚ) (T : ℕ) (delta : ℚ)
(choices : PhysicalSelections M J source.length target.length P
(stageRepresentatives source target U N P F A)) (node : PhysicalNode M J)
(t : ℕ) (q : TargetInterval target.length) :
physicalRefinement source target U N P F A T delta choices node (t + 1) q ≤
physicalRefinement source target U N P F A T delta choices node t q := by
have h := physicalRefinement_bellman_invariants source target U N P F A T delta choices node t q
exact h.2.trans h.1
theorem physicalRefinement_le_warmup {α : Type*} [DecidableEq α] {M J : ℕ}
(source target : List α) (U : PhysicalEntry M J target.length → ℕ)
(N P F : ℕ) (A : ℚ) (T : ℕ) (delta : ℚ)
(choices : PhysicalSelections M J source.length target.length P
(stageRepresentatives source target U N P F A)) (node : PhysicalNode M J)
(t : ℕ) (q : TargetInterval target.length) :
physicalRefinement source target U N P F A T delta choices node t q ≤
stageWarmup source target U N P F A T (node, q) := by
induction t with
| zero => exact (physicalRefinement_zero source target U N P F A T delta choices node q).le
| succ t ih =>
exact (physicalRefinement_nonincreasing source target U N P F A T delta choices node t q).trans ih
/-- Lower invariants propagate down the physical tree from the initial table bounds. -/
theorem physicalRefinement_lower {α : Type*} [DecidableEq α] {M J : ℕ}
(source target : List α) (hM : 0 < M) (U : PhysicalEntry M J target.length → ℕ)
(N P F : ℕ) (A : ℚ) (T : ℕ) (delta : ℚ) (a : ℝ) (ha : 1 ≤ a)
(hL : (1 : ℝ) ≤ ((128 * F : ℚ) : ℝ))
(hinit : physicalLower source target a ≤ fun s => (stageInitial source target U N P F A s : ℝ))
(choices : PhysicalSelections M J source.length target.length P
(stageRepresentatives source target U N P F A)) (node : PhysicalNode M J)
(t : ℕ) (q : TargetInterval target.length) :
physicalLower source target a (node, q) ≤
(physicalRefinement source target U N P F A T delta choices node t q : ℝ) := by
by_cases hbelow : node.1.val < J
· by_cases hleaf : (physicalSourceInterval source.length node).hi -
(physicalSourceInterval source.length node).lo ≤ 1
· rw [physicalRefinement_at_terminal _ _ _ _ _ _ _ _ _ _ node (Or.inr hleaf)]
exact hinit (node, q)
· cases t with
| zero =>
rw [physicalRefinement_zero]
simpa only [stageWarmup, rationalPhysicalWarmup_cast] using
physicalWarmup_lower source target hM P a ((128 * F : ℚ) : ℝ) ha hL
(fun s => (stageInitial source target U N P F A s : ℝ))
(stageRepresentatives source target U N P F A) hinit T (node, q)
| succ t =>
have hpost := (physicalRefinement_bellman_invariants source target U N P F A T delta choices
node (t + 1) q).1
have hpostR := (Rat.cast_le (K := ℝ)).mpr hpost
rw [rationalPhysicalBellman_cast] at hpostR
unfold physicalBellman at hpostR
dsimp only at hpostR
rw [dite_eq_left hbelow, ite_eq_right hleaf] at hpostR
apply le_trans ?_ hpostR
apply actualWideBellman_lower source target hM _ _ P _ a _ ha hL
· intro r
exact hinit (node, r)
· intro i r
exact physicalRefinement_lower source target hM U N P F A T delta a ha hL hinit choices
(physicalChild node hbelow i) (t + 1) r
· rw [physicalRefinement_at_terminal _ _ _ _ _ _ _ _ _ _ node (Or.inl hbelow)]
exact hinit (node, q)
termination_by J - node.1.val
decreasing_by
unfold physicalChild
dsimp only
omega
theorem physicalRefinement_stage_bounds {α : Type*} [DecidableEq α] {M J : ℕ}
(source target : List α) (hM : 0 < M) (U : PhysicalEntry M J target.length → ℕ)
(N P F : ℕ) (A : ℚ) (hsize : source.length + target.length ≤ N)
(hP : 66 ≤ P) (hF : 1 ≤ F) (hA : 1 ≤ A)
(hseed : ∀ state, stateEditCost (physicalSource source state.1) target state.2 ≤ U state ∧
(U state : ℚ) ≤ A * stateEditCost (physicalSource source state.1) target state.2)
(T : ℕ) (hT : 0 < T) (delta : ℚ)
(choices : PhysicalSelections M J source.length target.length P
(stageRepresentatives source target U N P F A)) (node : PhysicalNode M J)
(t : ℕ) (q : TargetInterval target.length) :
physicalLower source target (refinementFactor A F : ℝ) (node, q) ≤
(physicalRefinement source target U N P F A T delta choices node t q : ℝ) ∧
physicalRefinement source target U N P F A T delta choices node t q ≤
stageWarmup source target U N P F A T (node, q) ∧
stageWarmup source target U N P F A T (node, q) ≤ stageWarmupMass source target U N P F A T (node, q) ∧
stageWarmupMass source target U N P F A T (node, q) ≤ stageInitial source target U N P F A (node, q) ∧
stageInitial source target U N P F A (node, q) ≤
2 * F * stateEditCost (physicalSource source node) target q := by
have hfactor := refinementFactor_spec A F (by omega)
have hinit := physicalInitialTable_real_lower source target U N P F A (refinementFactor A F)
hsize hP hF hA hfactor.1 hfactor.2 hseed
have haR : (1 : ℝ) ≤ refinementFactor A F := by
simpa only [Rat.cast_one] using (Rat.cast_le (K := ℝ)).mpr hfactor.1
have hLR : (1 : ℝ) ≤ ((128 * F : ℚ) : ℝ) := by
have hFr : (1 : ℚ) ≤ F := by exact_mod_cast hF
simpa only [Rat.cast_one] using
(Rat.cast_le (K := ℝ)).mpr (by linarith : (1 : ℚ) ≤ 128 * F)
have hw := stageWarmup_invariants source target hM U N P F A hsize hP hF hA hseed T hT (node, q)
exact ⟨physicalRefinement_lower source target hM U N P F A T delta _ haR hLR hinit choices node t q,
physicalRefinement_le_warmup source target U N P F A T delta choices node t q,
hw.2.1, hw.2.2.1, hw.2.2.2⟩
end EditApproximation
end OAI

Xet Storage Details

Size:
13.4 kB
·
Xet hash:
fbad73a7fe884dd142f80f56363e54bf10f65d226c62cde02580697b7fbc753f

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.