math / data /lean /OAI /Combinatorics /EditApproximation /Geometry /CellGroupSelection.lean
introvoyz045's picture
Migrated from GitHub
4a56cd6 verified
Raw History Blame Contribute Delete
11.4 kB
import OAI.Combinatorics.EditApproximation.Geometry.GroupCells
import OAI.Combinatorics.EditApproximation.Geometry.BandGroupSampling
import OAI.Combinatorics.EditApproximation.Numerics.RationalWideStep
import OAI.Combinatorics.EditApproximation.Definitions
namespace OAI
/-! Literal unskipped groups of whole cells and their selected wide actions. -/
namespace EditApproximation
open Finset
theorem cellUnskippedBands_length_le {Ξ± : Type*} (source target : List Ξ±) {M : β„•}
(parent : TargetInterval source.length) (b P F thetaExponent : β„•) (tau a : β„š)
(parentInitial : TargetInterval target.length β†’ β„š)
(child initial : Fin M β†’ TargetInterval target.length β†’ β„š) (cell : β„• Γ— β„•)
(hb : βˆƒ e : β„•, b = 2 ^ e) (hP : βˆƒ e : β„•, P = 2 ^ e) :
(cellUnskippedBands source target parent b P F thetaExponent tau a parentInitial child initial cell).length ≀
(P + 1) ^ 2 := by
have htheta : 0 ≀ (2 : β„š) ^ (-(thetaExponent : β„€)) ∧
(2 : β„š) ^ (-(thetaExponent : β„€)) ≀ 1 := by
refine ⟨(zpow_pos (by norm_num : (0 : β„š) < 2) _).le, ?_⟩
rw [zpow_neg, zpow_natCast]
exact inv_le_one_of_one_leβ‚€ (one_le_powβ‚€ (by norm_num : (1 : β„š) ≀ 2))
exact (List.length_filterMap_le _ _).trans
(cellRepresentativeStates_length_le a parentInitial _ cell htheta hb hP)
namespace UnskippedBand
theorem canonicalRounded_congr {ny M : β„•} (thetaExponent b : β„•)
(band band' : List (Fin M β†’ TargetInterval ny)) (heq : band = band')
(hnonempty : band β‰  []) (hnonempty' : band' β‰  [])
(initial : Fin M β†’ TargetInterval ny β†’ β„š) :
canonicalRoundedBandAction thetaExponent b band hnonempty initial =
canonicalRoundedBandAction thetaExponent b band' hnonempty' initial := by
cases heq
rfl
theorem rationalAction_wide_mem {Ξ± : Type*} {source target : List Ξ±} {M b P thetaExponent : β„•}
{parent : TargetInterval source.length} {tau F : β„š}
{child initial : Fin M β†’ TargetInterval target.length β†’ β„š}
(member : UnskippedBand source target parent b P thetaExponent tau F child initial)
(representatives : List (β„• Γ— TargetInterval target.length)) (hrep : (b, member.center) ∈ representatives) :
member.rationalAction ∈ rationalActualWideActions parent representatives P := by
apply List.mem_flatMap.mpr
exact ⟨(b, member.center), hrep, List.mem_map.mpr ⟨member.rounded, member.wide_guard, rfl⟩⟩
theorem rounded_cost {Ξ± : Type*} {source target : List Ξ±} {M b P thetaExponent : β„•}
{parent : TargetInterval source.length} {tau F : β„š}
{child initial : Fin M β†’ TargetInterval target.length β†’ β„š}
(member : UnskippedBand source target parent b P thetaExponent tau F child initial)
(htau : 0 < tau) (value : Fin M β†’ TargetInterval target.length β†’ β„š)
(action : Fin M β†’ TargetInterval target.length) (haction : action ∈ member.actions)
(delta L : β„š) (hL : 0 ≀ L)
(hspatial : βˆ€ i s t, value i s ≀ (1 + delta) * value i t + L * targetEndpointDistance s t) :
rationalEndpointActionValue member.center member.rounded value ≀
(1 + delta) * (βˆ‘ i, value i (action i)) +
(6 * L + 2) * (2 : β„š) ^ (-(thetaExponent : β„€)) * βˆ‘ i, member.envelope i := by
have hnonempty := member.nonempty
by_cases hempty : wideActionList M parent member.center b P = []
Β· simp only [representativeBandActions, dite_eq_left hempty] at hnonempty
exact False.elim (hnonempty rfl)
Β· by_cases hZ : 0 < rationalWideActionMinimum parent member.center b P hempty child
Β· have hband : member.actions = computedBandActions parent member.center b P tau
((2 : β„š) ^ (-(thetaExponent : β„€)))
(rationalStateGap (substring source parent.lo parent.hi) target member.center /
rationalWideActionMinimum parent member.center b P hempty child) child := by
simp only [actions, representativeBandActions, dite_eq_right hempty, ite_eq_left hZ]
have hne : computedBandActions parent member.center b P tau
((2 : β„š) ^ (-(thetaExponent : β„€)))
(rationalStateGap (substring source parent.lo parent.hi) target member.center /
rationalWideActionMinimum parent member.center b P hempty child) child β‰  [] := by
rw [← hband]
exact member.nonempty
have ha := haction
rw [hband] at ha
have hcost := canonicalRoundedBandAction_cost parent member.center thetaExponent b P tau _ htau
child initial value hne action ha delta L hL hspatial
have hround := canonicalRounded_congr thetaExponent b _ _ hband member.nonempty hne initial
change member.rounded = _ at hround
rw [hround]
simpa only [envelope, hband] using hcost
Β· simp only [representativeBandActions, dite_eq_right hempty, ite_eq_right hZ] at hnonempty
exact False.elim (hnonempty rfl)
end UnskippedBand
theorem chooseCellGroupAction_wide_mem {Ξ± : Type*} (source target : List Ξ±) {M : β„•}
(parent : TargetInterval source.length) (N b P F thetaExponent Q : β„•) (tau a : β„š)
(parentInitial : TargetInterval target.length β†’ β„š)
(child initial value : Fin M β†’ TargetInterval target.length β†’ β„š) (cell : β„• Γ— β„•)
(draw : βˆ€ scale : Fin (groupDyadicScales M b F).length,
Fin (groupSampleCount M Q b (groupDyadicScaleAt M b F scale)) β†’ Fin M)
(hb : b ∈ dyadicScales N) (action : RationalBellmanAction
(TargetInterval target.length) (Fin M Γ— TargetInterval target.length) M)
(hselected : chooseCellGroupAction source target parent b P F thetaExponent Q tau a
parentInitial child initial value cell draw = some action) :
action ∈ rationalActualWideActions parent (representativeList N P F a parentInitial) P := by
unfold chooseCellGroupAction at hselected
dsimp only at hselected
split_ifs at hselected with hempty
have heq := Option.some.inj hselected
rw [← heq]
apply UnskippedBand.rationalAction_wide_mem
apply cellRepresentativeStates_mem_representatives a parentInitial _ cell _ hb
apply (unskippedBandList_mem_iff _ _).mp
exact (chooseUnskippedGroup_spec Q value _ hempty draw).1
theorem group_rounding_coefficient {F L : β„š} (hF : 1 ≀ F) (hL : 2 ≀ L) :
(6 * L + 2) * (64 * F) + 2 * L ≀ 512 * L * F := by
have hF0 : 0 ≀ F := by linarith only [hF]
have hL0 : 0 ≀ L := by linarith only [hL]
have hlarge := mul_le_mul_of_nonneg_right hL (mul_nonneg (by norm_num : (0 : β„š) ≀ 64) hF0)
have hcell := mul_le_mul_of_nonneg_left hF (mul_nonneg (by norm_num : (0 : β„š) ≀ 2) hL0)
have hprod := mul_nonneg hL0 hF0
nlinarith only [hlarge, hcell, hprod]
/-- Estimated minimization in an actual whole cell gives the group cone
bound simultaneously for every action of the specified member's band. -/
theorem chooseCellGroup_cone_bound {Ξ± : Type*} (source target : List Ξ±) {M : β„•}
(parent : TargetInterval source.length) (b P F thetaExponent Q : β„•) (tau a : β„š)
(parentInitial : TargetInterval target.length β†’ β„š)
(child initial value : Fin M β†’ TargetInterval target.length β†’ β„š) (cell : β„• Γ— β„•)
(hnonempty : cellUnskippedBands source target parent b P F thetaExponent tau a
parentInitial child initial cell β‰  [])
(draw : βˆ€ scale : Fin (groupDyadicScales M b F).length,
Fin (groupSampleCount M Q b (groupDyadicScaleAt M b F scale)) β†’ Fin M)
(specified : UnskippedBand source target parent b P thetaExponent tau F child initial)
(hspecified : specified ∈ cellUnskippedBands source target parent b P F thetaExponent tau a
parentInitial child initial cell)
(delta L gamma : β„š) (hF : 1 ≀ F) (hL : 2 ≀ L) (htau : 0 < tau)
(hspatial : βˆ€ i s t, value i s ≀ (1 + delta) * value i t + L * targetEndpointDistance s t)
(haccurate : βˆ€ member ∈ cellUnskippedBands source target parent b P F thetaExponent tau a
parentInitial child initial cell,
|dyadicUnskippedGroupEstimate Q value member draw -
rationalEndpointActionValue member.center member.rounded value| ≀ gamma * b)
(action : Fin M β†’ TargetInterval target.length) (haction : action ∈ specified.actions)
(q : TargetInterval target.length) :
let selected := chooseUnskippedGroup Q value
(cellUnskippedBands source target parent b P F thetaExponent tau a parentInitial child initial cell)
hnonempty draw
rationalActionValue (fun q r => targetEndpointDistance q r) L (fun is => value is.1 is.2) q
selected.rationalAction ≀
L * targetEndpointDistance q specified.center + (1 + delta) * (βˆ‘ i, value i (action i)) +
(2 * gamma + 512 * L * F * (2 : β„š) ^ (-(thetaExponent : β„€))) * b := by
let members := cellUnskippedBands source target parent b P F thetaExponent tau a
parentInitial child initial cell
let selected := chooseUnskippedGroup Q value members hnonempty draw
have hselected : selected ∈ members := (chooseUnskippedGroup_spec Q value members hnonempty draw).1
have hcost := chooseUnskippedGroup_cost_le Q value members hnonempty draw specified hspecified
(gamma * b) haccurate
change rationalEndpointActionValue selected.center selected.rounded value ≀
rationalEndpointActionValue specified.center specified.rounded value + 2 * (gamma * b) at hcost
have hrounded := specified.rounded_cost htau value action haction delta L (by linarith only [hL]) hspatial
have hcenterCell (member : UnskippedBand source target parent b P thetaExponent tau F child initial)
(hm : member ∈ members) : member.center ∈
cellTargetStates target.length (seedGridSpacing b P) ((2 : β„š) ^ (-(thetaExponent : β„€)) * b) cell := by
have hc := (unskippedBandList_mem_iff _ member).mp hm
exact (List.mem_filter.mp hc).1
have hdiam := cellTargetStates_diameter cell (by unfold seedGridSpacing; omega)
specified.center selected.center (hcenterCell specified hspecified) (hcenterCell selected hselected)
have htriangle : (targetEndpointDistance q selected.center : β„š) ≀
targetEndpointDistance q specified.center + targetEndpointDistance specified.center selected.center := by
have h := targetEndpointDistance_triangle q specified.center selected.center
have h' : (targetEndpointDistance q selected.center : β„š) ≀
targetEndpointDistance specified.center selected.center + targetEndpointDistance q specified.center := by
exact_mod_cast h
simpa only [add_comm] using h'
have hL0 : 0 ≀ L := by linarith only [hL]
have hdist := mul_le_mul_of_nonneg_left (htriangle.trans (add_le_add_right hdiam _)) hL0
have htheta : 0 ≀ (2 : β„š) ^ (-(thetaExponent : β„€)) := (zpow_pos (by norm_num : (0 : β„š) < 2) _).le
have hsum := mul_le_mul_of_nonneg_left specified.sum_guard
(mul_nonneg (by linarith only [hL0] : 0 ≀ 6 * L + 2) htheta)
change (6 * L + 2) * (2 : β„š) ^ (-(thetaExponent : β„€)) * (βˆ‘ i, specified.envelope i) ≀
(6 * L + 2) * (2 : β„š) ^ (-(thetaExponent : β„€)) * (64 * F * b) at hsum
have hcoef := mul_le_mul_of_nonneg_right (group_rounding_coefficient (F := (F : β„š)) (L := L)
(by exact_mod_cast hF) hL)
(mul_nonneg htheta (Nat.cast_nonneg (Ξ± := β„š) b))
dsimp only [rationalActionValue, UnskippedBand.rationalAction]
dsimp only [rationalEndpointActionValue] at hcost hrounded
nlinarith only [hcost, hrounded, hdist, hsum, hcoef]
end EditApproximation
end OAI