Download data/lean/OAI/Combinatorics/EditApproximation/Geometry/Bellman.lean from introvoyz045/math: direct link, hf CLI and curl.
- Browser
- Download file 12 kB
-
https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Combinatorics/EditApproximation/Geometry/Bellman.lean
- Command line
-
hf download hf://datasets/introvoyz045/math/data/lean/OAI/Combinatorics/EditApproximation/Geometry/Bellman.lean
-
curl -L -o Bellman.lean https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Combinatorics/EditApproximation/Geometry/Bellman.lean
12 kB
| import Mathlib | |
| namespace OAI | |
| /-! | |
| # Finite Bellman propagation and warmup | |
| The action minimum is computed by a finite list with the initial cone as | |
| fallback. Empty action families need no extended-real convention. The | |
| warmup lemmas concern the actual repeated finite Bellman operator. | |
| -/ | |
| namespace EditApproximation | |
| open Finset | |
| def finiteMinimum (fallback : β) : List β β β | |
| | [] => fallback | |
| | value :: rest => min value (finiteMinimum fallback rest) | |
| theorem le_finiteMinimum_iff (lower fallback : β) (values : List β) : | |
| lower β€ finiteMinimum fallback values β lower β€ fallback β§ β v β values, lower β€ v := by | |
| induction values with | |
| | nil => simp [finiteMinimum] | |
| | cons v rest ih => simp only [finiteMinimum, le_min_iff, ih, List.mem_cons, | |
| forall_eq_or_imp]; tauto | |
| theorem finiteMinimum_le_fallback (fallback : β) (values : List β) : | |
| finiteMinimum fallback values β€ fallback := by | |
| induction values with | |
| | nil => rfl | |
| | cons v rest ih => exact (min_le_right _ _).trans ih | |
| theorem finiteMinimum_le_member (fallback : β) (values : List β) | |
| {value : β} (hvalue : value β values) : finiteMinimum fallback values β€ value := by | |
| induction values with | |
| | nil => simp at hvalue | |
| | cons v rest ih => | |
| rcases List.mem_cons.mp hvalue with rfl | hvalue | |
| Β· exact min_le_left _ _ | |
| Β· exact (min_le_right _ _).trans (ih hvalue) | |
| theorem finiteMinimum_map_mono {ΞΉ : Type*} (indices : List ΞΉ) | |
| (fallback fallback' : β) (value value' : ΞΉ β β) | |
| (hfallback : fallback β€ fallback') (hvalue : β i β indices, value i β€ value' i) : | |
| finiteMinimum fallback (indices.map value) β€ | |
| finiteMinimum fallback' (indices.map value') := by | |
| induction indices with | |
| | nil => exact hfallback | |
| | cons i rest ih => | |
| simp only [List.map_cons, finiteMinimum] | |
| exact min_le_min (hvalue i (by simp)) (ih fun j hj => hvalue j (by simp [hj])) | |
| theorem finiteMinimum_map_add {ΞΉ : Type*} (indices : List ΞΉ) | |
| (fallback charge : β) (value : ΞΉ β β) : | |
| finiteMinimum (fallback + charge) (indices.map fun i => value i + charge) = | |
| finiteMinimum fallback (indices.map value) + charge := by | |
| induction indices with | |
| | nil => rfl | |
| | cons i rest ih => simp only [List.map_cons, finiteMinimum, ih, min_add_add_right] | |
| theorem finiteMinimum_map_spatial {ΞΉ : Type*} (indices : List ΞΉ) | |
| (fallback fallback' charge : β) (value value' : ΞΉ β β) | |
| (hfallback : fallback β€ fallback' + charge) | |
| (hvalue : β i β indices, value i β€ value' i + charge) : | |
| finiteMinimum fallback (indices.map value) β€ | |
| finiteMinimum fallback' (indices.map value') + charge := by | |
| rw [β finiteMinimum_map_add] | |
| exact finiteMinimum_map_mono indices _ _ _ _ hfallback hvalue | |
| structure BellmanAction (Parent Child : Type*) (M : β) where | |
| center : Parent | |
| connection : β | |
| childState : Fin M β Child | |
| def bellmanActionValue {Parent Child : Type*} {M : β} | |
| (distance : Parent β Parent β β) (L : β) (child : Child β β) | |
| (query : Parent) (action : BellmanAction Parent Child M) : β := | |
| L * distance query action.center + action.connection + β i, child (action.childState i) | |
| def finiteBellman {Parent Child : Type*} {M : β} | |
| (fallback : Parent β β) (distance : Parent β Parent β β) (L : β) | |
| (actions : List (BellmanAction Parent Child M)) (child : Child β β) (query : Parent) : β := | |
| finiteMinimum (fallback query) (actions.map (bellmanActionValue distance L child query)) | |
| theorem finiteBellman_le_fallback {Parent Child : Type*} {M : β} | |
| (fallback : Parent β β) (distance : Parent β Parent β β) (L : β) | |
| (actions : List (BellmanAction Parent Child M)) (child : Child β β) (query : Parent) : | |
| finiteBellman fallback distance L actions child query β€ fallback query := | |
| finiteMinimum_le_fallback _ _ | |
| theorem finiteBellman_mono {Parent Child : Type*} {M : β} | |
| (fallback : Parent β β) (distance : Parent β Parent β β) (L : β) | |
| (actions : List (BellmanAction Parent Child M)) {child child' : Child β β} | |
| (hchild : child β€ child') : | |
| finiteBellman fallback distance L actions child β€ | |
| finiteBellman fallback distance L actions child' := by | |
| intro query | |
| apply finiteMinimum_map_mono _ _ _ _ _ le_rfl | |
| intro action _ | |
| exact add_le_add le_rfl (sum_le_sum fun i _ => hchild (action.childState i)) | |
| theorem finiteBellman_le_action {Parent Child : Type*} {M : β} | |
| (fallback : Parent β β) (distance : Parent β Parent β β) (L : β) | |
| (actions : List (BellmanAction Parent Child M)) (child : Child β β) | |
| (query : Parent) (action : BellmanAction Parent Child M) (haction : action β actions) : | |
| finiteBellman fallback distance L actions child query β€ | |
| bellmanActionValue distance L child query action := | |
| finiteMinimum_le_member _ _ (List.mem_map.mpr β¨action, haction, rflβ©) | |
| theorem finiteBellman_lower {Parent Child : Type*} {M : β} | |
| (fallback lower : Parent β β) (distance : Parent β Parent β β) (L : β) | |
| (actions : List (BellmanAction Parent Child M)) (child : Child β β) | |
| (hfallback : lower β€ fallback) | |
| (haction : β query, β action β actions, | |
| lower query β€ bellmanActionValue distance L child query action) : | |
| lower β€ finiteBellman fallback distance L actions child := by | |
| intro query | |
| exact (le_finiteMinimum_iff _ _ _).2 | |
| β¨hfallback query, fun v hv => by | |
| obtain β¨action, ha, rflβ© := List.mem_map.mp hv | |
| exact haction query action haβ© | |
| theorem finiteBellman_spatial {Parent Child : Type*} {M : β} | |
| (fallback : Parent β β) (distance : Parent β Parent β β) (L : β) | |
| (actions : List (BellmanAction Parent Child M)) (child : Child β β) | |
| (hL : 0 β€ L) (query query' : Parent) | |
| (hfallback : fallback query β€ fallback query' + L * distance query query') | |
| (htriangle : β center, distance query center β€ distance query' center + distance query query') : | |
| finiteBellman fallback distance L actions child query β€ | |
| finiteBellman fallback distance L actions child query' + L * distance query query' := by | |
| apply finiteMinimum_map_spatial _ _ _ _ _ _ hfallback | |
| intro action _ | |
| have hdist := mul_le_mul_of_nonneg_left (htriangle action.center) hL | |
| dsimp [bellmanActionValue] | |
| linarith | |
| def warmup {State : Type*} (operator : (State β β) β State β β) | |
| (initial : State β β) : β β State β β | |
| | 0 => initial | |
| | t + 1 => operator (warmup operator initial t) | |
| /-- A finite system of node-specific action lists. Child states may | |
| belong to any lower level of the source tree. -/ | |
| def finiteBellmanSystem {State : Type*} {M : β} | |
| (initial : State β β) (distance : State β State β β) (L : β) | |
| (actions : State β List (BellmanAction State State M)) | |
| (child : State β β) (query : State) : β := | |
| finiteBellman initial distance L (actions query) child query | |
| theorem finiteBellmanSystem_monotone {State : Type*} {M : β} | |
| (initial : State β β) (distance : State β State β β) (L : β) | |
| (actions : State β List (BellmanAction State State M)) : | |
| Monotone (finiteBellmanSystem initial distance L actions) := by | |
| intro child child' hchild query | |
| exact finiteBellman_mono initial distance L (actions query) hchild query | |
| theorem finiteBellmanSystem_le_initial {State : Type*} {M : β} | |
| (initial : State β β) (distance : State β State β β) (L : β) | |
| (actions : State β List (BellmanAction State State M)) (child : State β β) : | |
| finiteBellmanSystem initial distance L actions child β€ initial := by | |
| intro query | |
| exact finiteBellman_le_fallback initial distance L (actions query) child query | |
| theorem warmup_nonincreasing {State : Type*} | |
| (operator : (State β β) β State β β) (initial : State β β) | |
| (hmono : Monotone operator) (hfirst : operator initial β€ initial) : | |
| β t, warmup operator initial (t + 1) β€ warmup operator initial t := by | |
| intro t | |
| induction t with | |
| | zero => exact hfirst | |
| | succ t ih => exact hmono ih | |
| theorem warmup_lower {State : Type*} | |
| (operator : (State β β) β State β β) (initial lower : State β β) | |
| (hinit : lower β€ initial) | |
| (hpreserve : β value, lower β€ value β lower β€ operator value) : | |
| β t, lower β€ warmup operator initial t := by | |
| intro t | |
| induction t with | |
| | zero => exact hinit | |
| | succ t ih => exact hpreserve _ ih | |
| theorem finite_bellman_warmup_nonincreasing {State : Type*} {M : β} | |
| (initial : State β β) (distance : State β State β β) (L : β) | |
| (actions : State β List (BellmanAction State State M)) : | |
| β t, warmup (finiteBellmanSystem initial distance L actions) initial (t + 1) β€ | |
| warmup (finiteBellmanSystem initial distance L actions) initial t := | |
| warmup_nonincreasing _ _ (finiteBellmanSystem_monotone initial distance L actions) | |
| (finiteBellmanSystem_le_initial initial distance L actions initial) | |
| noncomputable def warmupAverage {State : Type*} | |
| (operator : (State β β) β State β β) (initial : State β β) | |
| (T : β) (state : State) : β := | |
| (β t β range T, warmup operator initial t state) / T | |
| theorem warmup_average_sandwich {State : Type*} | |
| (operator : (State β β) β State β β) (initial : State β β) | |
| (T : β) (hT : 0 < T) (hmono : Monotone operator) | |
| (hfirst : operator initial β€ initial) (state : State) : | |
| warmup operator initial T state β€ warmupAverage operator initial T state β§ | |
| warmupAverage operator initial T state β€ initial state := by | |
| have hanti : Antitone (fun t => warmup operator initial t state) := | |
| antitone_nat_of_succ_le fun t => warmup_nonincreasing operator initial hmono hfirst t state | |
| have hTr : (0 : β) < T := by exact_mod_cast hT | |
| constructor | |
| Β· apply (le_div_iffβ hTr).2 | |
| have hsum := sum_le_sum (s := range T) fun t ht => hanti (show t β€ T from (mem_range.mp ht).le) | |
| simpa only [sum_const, card_range, nsmul_eq_mul, mul_comm] using hsum | |
| Β· apply (div_le_iffβ hTr).2 | |
| have hsum := sum_le_sum (s := range T) fun t _ => hanti (Nat.zero_le t) | |
| simpa only [sum_const, card_range, nsmul_eq_mul, warmup, mul_comm] using hsum | |
| /-- Averaging the actual one-step action inequality gives the warmup | |
| mass slack, with the exact endpoint correction before its simplification | |
| to the nonnegative initial-cone charge. -/ | |
| theorem warmup_average_action_bound {State ΞΉ : Type*} [Fintype ΞΉ] | |
| (operator : (State β β) β State β β) (initial : State β β) | |
| (T : β) (hT : 0 < T) (parent : State) (child : ΞΉ β State) (charge : β) | |
| (haction : β t < T, warmup operator initial (t + 1) parent β€ | |
| charge + β i, warmup operator initial t (child i)) : | |
| warmupAverage operator initial T parent - | |
| (initial parent - warmup operator initial T parent) / T β€ | |
| charge + β i, warmupAverage operator initial T (child i) := by | |
| have hTr : (0 : β) < T := by exact_mod_cast hT | |
| have htelAll : β K : β, (β t β range K, warmup operator initial t parent) - | |
| (β t β range K, warmup operator initial (t + 1) parent) = | |
| initial parent - warmup operator initial K parent := by | |
| intro K | |
| induction K with | |
| | zero => simp [warmup] | |
| | succ K ih => | |
| rw [sum_range_succ, sum_range_succ] | |
| linarith | |
| have htel := htelAll T | |
| have hsum := sum_le_sum (s := range T) fun t ht => haction t (mem_range.mp ht) | |
| rw [sum_add_distrib, sum_const, card_range, nsmul_eq_mul, sum_comm] at hsum | |
| unfold warmupAverage | |
| rw [β sub_div, β sum_div] | |
| apply (div_le_iffβ hTr).2 | |
| have hright : (charge + (β i, β t β range T, | |
| warmup operator initial t (child i)) / T) * T = | |
| (T : β) * charge + β i, β t β range T, warmup operator initial t (child i) := by | |
| field_simp | |
| rw [hright, β htel] | |
| linarith | |
| end EditApproximation | |
| end OAI | |