math / data /lean /OAI /Combinatorics /EditApproximation /Geometry /BandActionGuards.lean
introvoyz045's picture
Migrated from GitHub
4a56cd6 verified
Raw History Blame Contribute Delete
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