Download data/lean/OAI/Combinatorics/EditApproximation/Geometry/BandActionGuards.lean from introvoyz045/math: direct link, hf CLI and curl.
- Browser
- Download file 19.2 kB
-
https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Combinatorics/EditApproximation/Geometry/BandActionGuards.lean
- Command line
-
hf download hf://datasets/introvoyz045/math/data/lean/OAI/Combinatorics/EditApproximation/Geometry/BandActionGuards.lean
-
curl -L -o BandActionGuards.lean https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Combinatorics/EditApproximation/Geometry/BandActionGuards.lean
19.2 kB
| import OAI.Combinatorics.EditApproximation.Geometry.BandRounding | |
| import OAI.Combinatorics.EditApproximation.Definitions | |
| namespace OAI | |
| /-! | |
| # Actual rounded band actions pass the finite guards | |
| Each child uses its own envelope-derived integer spacing. The action is | |
| rounded with literal integer division; wide-grid, radius and imbalance | |
| claims are proved for these returned states. | |
| -/ | |
| namespace EditApproximation | |
| open Finset | |
| theorem bandChildEnvelope_pos {ny M : β} (b : β) | |
| (band : List (Fin M β TargetInterval ny)) | |
| (initial : Fin M β TargetInterval ny β β) (i : Fin M) : | |
| 0 < bandChildEnvelope b band initial i := by | |
| unfold bandChildEnvelope rationalDyadicCeiling | |
| positivity | |
| theorem roundedBandAction_endpoint_error {ny M : β} (thetaExponent b : β) | |
| (band : List (Fin M β TargetInterval ny)) | |
| (initial : Fin M β TargetInterval ny β β) (action : Fin M β TargetInterval ny) (i : Fin M) : | |
| (Nat.dist (action i).lo (roundedBandAction thetaExponent b band initial action i).lo : β) β€ | |
| (2 : β) ^ (-(thetaExponent : β€)) * bandChildEnvelope b band initial i β§ | |
| (Nat.dist (action i).hi (roundedBandAction thetaExponent b band initial action i).hi : β) β€ | |
| (2 : β) ^ (-(thetaExponent : β€)) * bandChildEnvelope b band initial i := by | |
| have hscaled : 0 β€ (2 : β) ^ (-(thetaExponent : β€)) * bandChildEnvelope b band initial i := | |
| mul_nonneg (zpow_pos (by norm_num : (0 : β) < 2) _).le (bandChildEnvelope_pos b band initial i).le | |
| exact β¨gridRound_scaled_error _ _ _ (bandRoundSpacing_exact thetaExponent b band initial i) hscaled, | |
| gridRound_scaled_error _ _ _ (bandRoundSpacing_exact thetaExponent b band initial i) hscaledβ© | |
| theorem roundedBandAction_distance {ny M : β} (thetaExponent b : β) | |
| (band : List (Fin M β TargetInterval ny)) | |
| (initial : Fin M β TargetInterval ny β β) (action : Fin M β TargetInterval ny) (i : Fin M) : | |
| (targetEndpointDistance (action i) (roundedBandAction thetaExponent b band initial action i) : β) β€ | |
| 2 * (2 : β) ^ (-(thetaExponent : β€)) * bandChildEnvelope b band initial i := by | |
| have h := roundedBandAction_endpoint_error thetaExponent b band initial action i | |
| unfold targetEndpointDistance | |
| push_cast | |
| convert add_le_add h.1 h.2 using 1 | |
| ring | |
| /-- Actual rounded wide membership and imbalance guard. The sum premise | |
| is supplied by bandChildEnvelope_sum_guard, and the remaining premises | |
| are explicit computed-parameter inequalities. -/ | |
| theorem roundedBandAction_guards {Ξ± : Type*} (source target : List Ξ±) | |
| {M b P : β} (parent : TargetInterval source.length) (r : TargetInterval target.length) | |
| (thetaExponent : β) (tau velocity : β) | |
| (child initial : Fin M β TargetInterval target.length β β) | |
| (action : Fin M β TargetInterval target.length) | |
| (haction : action β computedBandActions parent r b P tau ((2 : β) ^ (-(thetaExponent : β€))) velocity child) | |
| (hM : 0 < M) (hPpos : 0 < P) | |
| (hbPower : β e : β, b = 2 ^ e) (hPPower : β e : β, P = 2 ^ e) | |
| (hscale : (M : β) β€ (2 : β) ^ (-(thetaExponent : β€)) * P) | |
| (F : β) | |
| (hsmall : 64 * F * (2 : β) ^ (-(thetaExponent : β€)) β€ 4) | |
| (htheta : (2 : β) ^ (-(thetaExponent : β€)) β€ 1 / 2) | |
| (hinitialGap : β i s, |rationalStateGap | |
| (substring source (sourceChild parent i).lo (sourceChild parent i).hi) target s| β€ initial i s) | |
| (hsum : (β i : Fin M, bandChildEnvelope b | |
| (computedBandActions parent r b P tau ((2 : β) ^ (-(thetaExponent : β€))) velocity child) initial i) β€ 64 * F * b) : | |
| let band := computedBandActions parent r b P tau ((2 : β) ^ (-(thetaExponent : β€))) velocity child | |
| roundedBandAction thetaExponent b band initial action β wideActionList M parent r b P β§ | |
| β i, |rationalStateGap | |
| (substring source (sourceChild parent i).lo (sourceChild parent i).hi) target | |
| (roundedBandAction thetaExponent b band initial action i)| β€ 2 * bandChildEnvelope b band initial i := by | |
| let theta : β := 2 ^ (-(thetaExponent : β€)) | |
| let band := computedBandActions parent r b P tau theta velocity child | |
| let envelope := fun i : Fin M => bandChildEnvelope b band initial i | |
| let rounded := roundedBandAction thetaExponent b band initial action | |
| have htheta0 : 0 β€ theta := (zpow_pos (by norm_num : (0 : β) < 2) _).le | |
| have henv (i : Fin M) : 0 β€ envelope i := (bandChildEnvelope_pos b band initial i).le | |
| have hsingle (i : Fin M) : envelope i β€ β j, envelope j := | |
| single_le_sum (fun j _ => henv j) (mem_univ i) | |
| have hbudget (i : Fin M) : theta * envelope i β€ 4 * b := by | |
| have h := (mul_le_mul_of_nonneg_left (hsingle i) htheta0).trans | |
| (mul_le_mul_of_nonneg_left hsum htheta0) | |
| have hb := mul_le_mul_of_nonneg_right hsmall (show (0 : β) β€ b by positivity) | |
| nlinarith only [h, hb] | |
| obtain β¨hnonempty, hwide, hv, hpredicateβ© := | |
| computedBandActions_mem parent r b P tau theta velocity child action haction | |
| have herr := roundedBandAction_endpoint_error thetaExponent b band initial action | |
| have hanchor (anchor before after : β) (i : Fin M) | |
| (hbefore : Nat.dist anchor before β€ 6 * b) | |
| (herror : (Nat.dist before after : β) β€ theta * envelope i) : | |
| Nat.dist anchor after β€ 10 * b := by | |
| have htriangle : (Nat.dist anchor after : β) β€ (Nat.dist anchor before : β) + Nat.dist before after := by | |
| exact_mod_cast Nat.dist.triangle_inequality anchor before after | |
| have hbeforeQ : (Nat.dist anchor before : β) β€ 6 * b := by exact_mod_cast hbefore | |
| have hafter : (Nat.dist anchor after : β) β€ 10 * b := by | |
| linarith only [htriangle, hbeforeQ, herror, hbudget i] | |
| exact_mod_cast hafter | |
| constructor | |
| Β· apply wideActionList_complete | |
| Β· intro i | |
| have hgrid := bandRoundSpacing_wide_grid thetaExponent band initial i hM hPpos hbPower hPPower hscale | |
| exact β¨hgrid.trans (dvd_mul_right _ _), hgrid.trans (dvd_mul_right _ _)β© | |
| Β· intro i | |
| exact hanchor _ _ _ i (hpredicate.2.1 i).1 (herr i).1 | |
| Β· intro i | |
| exact hanchor _ _ _ i (hpredicate.2.1 i).2 (herr i).2 | |
| Β· intro i | |
| have hbefore := (hinitialGap i (action i)).trans | |
| ((bandChildEnvelope_lower b band initial i).2 action haction) | |
| have hspatial := stateLengthGap_spatial | |
| (substring source (sourceChild parent i).lo (sourceChild parent i).hi) target (rounded i) (action i) | |
| rw [β rationalStateGap_cast, β rationalStateGap_cast] at hspatial | |
| have hspatialQ : |rationalStateGap | |
| (substring source (sourceChild parent i).lo (sourceChild parent i).hi) target (rounded i)| β€ | |
| |rationalStateGap (substring source (sourceChild parent i).lo (sourceChild parent i).hi) target (action i)| + | |
| (targetEndpointDistance (rounded i) (action i) : β) := by exact_mod_cast hspatial | |
| have hdistance := roundedBandAction_distance thetaExponent b band initial action i | |
| have hsym : targetEndpointDistance (rounded i) (action i) = targetEndpointDistance (action i) (rounded i) := by | |
| unfold targetEndpointDistance | |
| rw [Nat.dist_comm (rounded i).lo, Nat.dist_comm (rounded i).hi] | |
| rw [hsym] at hspatialQ | |
| have hscaled := mul_le_mul_of_nonneg_right htheta (henv i) | |
| nlinarith only [hbefore, hspatialQ, hdistance, hscaled] | |
| /-- Moving the two endpoints of each interval charges at most their total | |
| movement, including the outside connections. -/ | |
| theorem connectionBudget_pair_perturbation {n : β} | |
| (pairs : List (TargetInterval n Γ TargetInterval n)) (beforeStart afterStart finish : β) : | |
| connectionBudget afterStart (pairs.map Prod.snd) finish β€ | |
| connectionBudget beforeStart (pairs.map Prod.fst) finish + Nat.dist afterStart beforeStart + | |
| (pairs.map fun pair => targetEndpointDistance pair.1 pair.2).sum := by | |
| induction pairs generalizing beforeStart afterStart with | |
| | nil => | |
| simp only [List.map_nil, List.sum_nil, connectionBudget, Nat.add_zero] | |
| have h := Nat.dist.triangle_inequality afterStart beforeStart finish | |
| omega | |
| | cons pair rest ih => | |
| rcases pair with β¨before, afterβ© | |
| have htail := ih before.hi after.hi | |
| have hfirst := Nat.dist.triangle_inequality afterStart beforeStart before.lo | |
| have hsecond := Nat.dist.triangle_inequality afterStart before.lo after.lo | |
| rw [Nat.dist_comm after.hi before.hi] at htail | |
| simp only [List.map_cons, List.sum_cons, connectionBudget, targetEndpointDistance] at htail β’ | |
| omega | |
| theorem endpointActionConnection_perturbation {n M : β} (r : TargetInterval n) | |
| (before after : Fin M β TargetInterval n) : | |
| endpointActionConnection r after β€ endpointActionConnection r before + | |
| β i, targetEndpointDistance (before i) (after i) := by | |
| have h := connectionBudget_pair_perturbation | |
| (List.ofFn fun i : Fin M => (before i, after i)) r.lo r.lo r.hi | |
| simpa only [List.map_ofFn, List.sum_ofFn, Function.comp_def, Nat.dist_self, Nat.add_zero, | |
| endpointActionConnection] using h | |
| /-- The returned rounded action pays at most `2 ΞΈ β hα΅’` in actual | |
| connection cost when its unrounded band action has zero connection. -/ | |
| theorem roundedBandAction_connection {n M : β} (r : TargetInterval n) | |
| (thetaExponent b : β) (band : List (Fin M β TargetInterval n)) | |
| (initial : Fin M β TargetInterval n β β) (action : Fin M β TargetInterval n) | |
| (hzero : endpointActionConnection r action = 0) : | |
| (endpointActionConnection r (roundedBandAction thetaExponent b band initial action) : β) β€ | |
| 2 * (2 : β) ^ (-(thetaExponent : β€)) * β i, bandChildEnvelope b band initial i := by | |
| have hnatural := endpointActionConnection_perturbation r action | |
| (roundedBandAction thetaExponent b band initial action) | |
| rw [hzero, Nat.zero_add] at hnatural | |
| have hcast : (endpointActionConnection r | |
| (roundedBandAction thetaExponent b band initial action) : β) β€ | |
| β i, (targetEndpointDistance (action i) | |
| (roundedBandAction thetaExponent b band initial action i) : β) := by | |
| exact_mod_cast hnatural | |
| calc | |
| _ β€ β i, (targetEndpointDistance (action i) | |
| (roundedBandAction thetaExponent b band initial action i) : β) := hcast | |
| _ β€ β i, 2 * (2 : β) ^ (-(thetaExponent : β€)) * bandChildEnvelope b band initial i := | |
| sum_le_sum fun i _ => roundedBandAction_distance thetaExponent b band initial action i | |
| _ = _ := by rw [mul_sum] | |
| theorem canonicalRoundedBandAction_connection {nx ny M : β} (parent : TargetInterval nx) | |
| (r : TargetInterval ny) (thetaExponent b P : β) (tau velocity : β) | |
| (child initial : Fin M β TargetInterval ny β β) | |
| (hnonempty : computedBandActions parent r b P tau | |
| ((2 : β) ^ (-(thetaExponent : β€))) velocity child β []) : | |
| let band := computedBandActions parent r b P tau | |
| ((2 : β) ^ (-(thetaExponent : β€))) velocity child | |
| (endpointActionConnection r | |
| (canonicalRoundedBandAction thetaExponent b band hnonempty initial) : β) β€ | |
| 2 * (2 : β) ^ (-(thetaExponent : β€)) * β i, bandChildEnvelope b band initial i := by | |
| have hmem := List.head_mem hnonempty | |
| obtain β¨_, _, _, hpredicateβ© := computedBandActions_mem parent r b P tau | |
| ((2 : β) ^ (-(thetaExponent : β€))) velocity child _ hmem | |
| exact roundedBandAction_connection r thetaExponent b _ initial _ hpredicate.1 | |
| /-- The initial table's literal spatial bound controls the value of every | |
| returned rounded state. -/ | |
| theorem roundedBandAction_initialValue {ny M : β} (thetaExponent b : β) | |
| (band : List (Fin M β TargetInterval ny)) | |
| (initial : Fin M β TargetInterval ny β β) (action : Fin M β TargetInterval ny) | |
| (L0 : β) (hL0 : 0 β€ L0) | |
| (hspatial : β i s t, initial i s β€ initial i t + L0 * targetEndpointDistance s t) | |
| (i : Fin M) : | |
| initial i (roundedBandAction thetaExponent b band initial action i) β€ initial i (action i) + | |
| 2 * L0 * (2 : β) ^ (-(thetaExponent : β€)) * bandChildEnvelope b band initial i := by | |
| have h := hspatial i (roundedBandAction thetaExponent b band initial action i) (action i) | |
| have hsym : targetEndpointDistance (roundedBandAction thetaExponent b band initial action i) (action i) = | |
| targetEndpointDistance (action i) (roundedBandAction thetaExponent b band initial action i) := by | |
| unfold targetEndpointDistance | |
| rw [Nat.dist_comm (roundedBandAction thetaExponent b band initial action i).lo, | |
| Nat.dist_comm (roundedBandAction thetaExponent b band initial action i).hi] | |
| rw [hsym] at h | |
| have hmove := mul_le_mul_of_nonneg_left | |
| (roundedBandAction_distance thetaExponent b band initial action i) hL0 | |
| nlinarith only [h, hmove] | |
| theorem roundedBandAction_initialValue_le_twice {ny M : β} (thetaExponent b : β) | |
| (band : List (Fin M β TargetInterval ny)) | |
| (initial : Fin M β TargetInterval ny β β) (action : Fin M β TargetInterval ny) | |
| (haction : action β band) (L0 : β) (hL0 : 0 β€ L0) | |
| (hsmall : 2 * L0 * (2 : β) ^ (-(thetaExponent : β€)) β€ 1) | |
| (hspatial : β i s t, initial i s β€ initial i t + L0 * targetEndpointDistance s t) | |
| (i : Fin M) : | |
| initial i (roundedBandAction thetaExponent b band initial action i) β€ | |
| 2 * bandChildEnvelope b band initial i := by | |
| have hbefore := (bandChildEnvelope_lower b band initial i).2 action haction | |
| have hafter := roundedBandAction_initialValue thetaExponent b band initial action L0 hL0 hspatial i | |
| have hmove := mul_le_mul_of_nonneg_right hsmall (bandChildEnvelope_pos b band initial i).le | |
| nlinarith only [hbefore, hafter, hmove] | |
| /-- The canonical rounded action is close to every member of its actual | |
| computed band, with distance measured at both child endpoints. -/ | |
| theorem canonicalRoundedBandAction_distance {nx ny M : β} (parent : TargetInterval nx) | |
| (r : TargetInterval ny) (thetaExponent b P : β) (tau velocity : β) (htau : 0 < tau) | |
| (child initial : Fin M β TargetInterval ny β β) | |
| (hnonempty : computedBandActions parent r b P tau | |
| ((2 : β) ^ (-(thetaExponent : β€))) velocity child β []) | |
| (action : Fin M β TargetInterval ny) | |
| (haction : action β computedBandActions parent r b P tau | |
| ((2 : β) ^ (-(thetaExponent : β€))) velocity child) (i : Fin M) : | |
| let band := computedBandActions parent r b P tau | |
| ((2 : β) ^ (-(thetaExponent : β€))) velocity child | |
| (targetEndpointDistance (action i) | |
| (canonicalRoundedBandAction thetaExponent b band hnonempty initial i) : β) β€ | |
| 6 * (2 : β) ^ (-(thetaExponent : β€)) * bandChildEnvelope b band initial i := by | |
| let theta : β := (2 : β) ^ (-(thetaExponent : β€)) | |
| let band := computedBandActions parent r b P tau theta velocity child | |
| let canonical := band.head hnonempty | |
| let rounded := canonicalRoundedBandAction thetaExponent b band hnonempty initial | |
| have htheta : 0 β€ theta := (zpow_pos (by norm_num : (0 : β) < 2) _).le | |
| have hcanonical : canonical β band := List.head_mem hnonempty | |
| have hdiameter := computedBand_child_endpoint_diameter parent r b P tau theta velocity | |
| htau htheta child action canonical haction hcanonical i | |
| have hdiameterQ : (targetEndpointDistance (action i) (canonical i) : β) β€ 4 * theta * b / M := by | |
| exact_mod_cast hdiameter | |
| have hfloor := (bandChildEnvelope_lower b band initial i).1 | |
| have hscaled := mul_le_mul_of_nonneg_left hfloor (mul_nonneg (by norm_num : (0 : β) β€ 4) htheta) | |
| have hdiameterEnvelope : (targetEndpointDistance (action i) (canonical i) : β) β€ | |
| 4 * theta * bandChildEnvelope b band initial i := by | |
| calc | |
| _ β€ 4 * theta * ((b : β) / M) := by convert hdiameterQ using 1; ring | |
| _ β€ _ := hscaled | |
| have hround := roundedBandAction_distance thetaExponent b band initial canonical i | |
| change (targetEndpointDistance (canonical i) (rounded i) : β) β€ | |
| 2 * theta * bandChildEnvelope b band initial i at hround | |
| have htriangle : (targetEndpointDistance (action i) (rounded i) : β) β€ | |
| targetEndpointDistance (action i) (canonical i) + targetEndpointDistance (canonical i) (rounded i) := by | |
| have hnatural : targetEndpointDistance (action i) (rounded i) β€ | |
| targetEndpointDistance (action i) (canonical i) + targetEndpointDistance (canonical i) (rounded i) := by | |
| unfold targetEndpointDistance | |
| have hlo := Nat.dist.triangle_inequality (action i).lo (canonical i).lo (rounded i).lo | |
| have hhi := Nat.dist.triangle_inequality (action i).hi (canonical i).hi (rounded i).hi | |
| omega | |
| exact_mod_cast hnatural | |
| change (targetEndpointDistance (action i) (rounded i) : β) β€ | |
| 6 * theta * bandChildEnvelope b band initial i | |
| linarith only [htriangle, hdiameterEnvelope, hround] | |
| /-- The actual canonical rounded action satisfies the rounded-action | |
| cost inequality uniformly for every actual band member. -/ | |
| theorem canonicalRoundedBandAction_cost {nx ny M : β} (parent : TargetInterval nx) | |
| (r : TargetInterval ny) (thetaExponent b P : β) (tau velocity : β) (htau : 0 < tau) | |
| (child initial value : Fin M β TargetInterval ny β β) | |
| (hnonempty : computedBandActions parent r b P tau | |
| ((2 : β) ^ (-(thetaExponent : β€))) velocity child β []) | |
| (action : Fin M β TargetInterval ny) | |
| (haction : action β computedBandActions parent r b P tau | |
| ((2 : β) ^ (-(thetaExponent : β€))) velocity child) | |
| (delta L : β) (hL : 0 β€ L) | |
| (hspatial : β i s t, value i s β€ (1 + delta) * value i t + L * targetEndpointDistance s t) : | |
| let band := computedBandActions parent r b P tau | |
| ((2 : β) ^ (-(thetaExponent : β€))) velocity child | |
| rationalEndpointActionValue r (canonicalRoundedBandAction thetaExponent b band hnonempty initial) value β€ | |
| (1 + delta) * (β i, value i (action i)) + | |
| (6 * L + 2) * (2 : β) ^ (-(thetaExponent : β€)) * β i, bandChildEnvelope b band initial i := by | |
| let theta : β := (2 : β) ^ (-(thetaExponent : β€)) | |
| let band := computedBandActions parent r b P tau theta velocity child | |
| let rounded := canonicalRoundedBandAction thetaExponent b band hnonempty initial | |
| have hchild (i : Fin M) : value i (rounded i) β€ (1 + delta) * value i (action i) + | |
| 6 * L * theta * bandChildEnvelope b band initial i := by | |
| have h := hspatial i (rounded i) (action i) | |
| have hsym : targetEndpointDistance (rounded i) (action i) = targetEndpointDistance (action i) (rounded i) := by | |
| unfold targetEndpointDistance | |
| rw [Nat.dist_comm (rounded i).lo, Nat.dist_comm (rounded i).hi] | |
| rw [hsym] at h | |
| have hmove := mul_le_mul_of_nonneg_left | |
| (canonicalRoundedBandAction_distance parent r thetaExponent b P tau velocity htau child initial | |
| hnonempty action haction i) hL | |
| nlinarith only [h, hmove] | |
| have hsum := sum_le_sum fun i (_ : i β (univ : Finset (Fin M))) => hchild i | |
| rw [sum_add_distrib, β mul_sum, β mul_sum] at hsum | |
| have hconnection := canonicalRoundedBandAction_connection parent r thetaExponent b P tau velocity child initial hnonempty | |
| change (endpointActionConnection r rounded : β) + β i, value i (rounded i) β€ _ | |
| nlinarith only [hsum, hconnection] | |
| end EditApproximation | |
| end OAI | |