math / data /lean /OAI /Combinatorics /EditApproximation /Geometry /ActualRoundedGroupInputs.lean
introvoyz045's picture
Migrated from GitHub
4a56cd6 verified
Raw History Blame Contribute Delete
5.34 kB
import OAI.Combinatorics.EditApproximation.Geometry.RoundedGroupStates
import OAI.Combinatorics.EditApproximation.Definitions
namespace OAI
/-! Every actual unskipped rounded group input belongs to a common
small endpoint list determined by the cell, child and envelope label. -/
namespace EditApproximation
theorem groupRoundSpacing_pos (exponent : β„•) (h : β„š) : 0 < groupRoundSpacing exponent h := by
apply Nat.ceil_pos.mpr
exact lt_of_lt_of_le zero_lt_one (le_max_left _ _)
theorem groupRoundSpacing_envelope_bound (exponent : β„•) (h : β„š) :
h ≀ (2 : β„š) ^ exponent * groupRoundSpacing exponent h := by
have hpow : (0 : β„š) < (2 : β„š) ^ exponent := by positivity
have hceil : (2 : β„š) ^ (-(exponent : β„€)) * h ≀ (groupRoundSpacing exponent h : β„š) :=
(le_max_right _ _).trans (Nat.le_ceil _)
have hmul := mul_le_mul_of_nonneg_left hceil hpow.le
rw [zpow_neg, zpow_natCast] at hmul
simpa only [← mul_assoc, mul_inv_cancelβ‚€ hpow.ne', one_mul] using hmul
theorem bandRoundSpacing_group_spacing {ny M : β„•} (exponent b : β„•)
(band : List (Fin M β†’ TargetInterval ny)) (initial : Fin M β†’ TargetInterval ny β†’ β„š)
(i : Fin M) (h : β„š) (henvelope : bandChildEnvelope b band initial i = h) :
bandRoundSpacing exponent b band initial i = groupRoundSpacing exponent h := by
have heq := bandRoundSpacing_exact exponent b band initial i
rw [henvelope] at heq
have hceil := congrArg (fun r : β„š => ⌈rβŒ‰β‚Š) heq
simpa only [Nat.ceil_natCast, groupRoundSpacing] using hceil
theorem gridStateBox_sound {n g radius lo hi : β„•} (hg : 0 < g) (r : TargetInterval n)
(hr : r ∈ gridStateBox n g radius lo hi) :
Nat.dist lo r.lo ≀ radius ∧ Nat.dist hi r.hi ≀ radius ∧ g ∣ r.lo ∧ g ∣ r.hi := by
obtain ⟨s, hs, hr⟩ := List.mem_flatMap.mp hr
obtain ⟨t, ht, hmake⟩ := List.mem_filterMap.mp hr
have heq : r.lo = s ∧ r.hi = t := by
unfold makeTargetState at hmake
split_ifs at hmake with hvalid
cases hmake
exact ⟨rfl, rfl⟩
rw [← heq.1] at hs
rw [← heq.2] at ht
have hlo := gridPointsBetween_sound hg hs
have hhi := gridPointsBetween_sound hg ht
refine ⟨?_, ?_, hlo.2.2, hhi.2.2⟩ <;> unfold Nat.dist <;> omega
theorem actual_rounded_group_input_mem {Ξ± : Type*} (source target : List Ξ±) {M b P exponent : β„•}
(parent : TargetInterval source.length) (tau a : β„š) (F : β„•)
(parentInitial : TargetInterval target.length β†’ β„š)
(child initial : Fin M β†’ TargetInterval target.length β†’ β„š) (cell : β„• Γ— β„•)
(member : UnskippedBand source target parent b P exponent tau F child initial)
(hb : 1 ≀ b)
(hcenter : member.center ∈ cellRepresentativeStates target.length P F b a parentInitial
((2 : β„š) ^ (-(exponent : β„€))) cell)
(i : Fin M) (h : β„š) (henvelope : member.envelope i = h) :
member.rounded i ∈ groupRoundedStateList source target parent b exponent cell i h := by
have hspacing := bandRoundSpacing_group_spacing exponent b member.actions initial i h henvelope
have hgrid : groupRoundSpacing exponent h ∣ (member.rounded i).lo ∧
groupRoundSpacing exponent h ∣ (member.rounded i).hi := by
simpa only [UnskippedBand.rounded, canonicalRoundedBandAction, roundedBandAction, hspacing] using
roundInterval_on_grid (bandRoundSpacing exponent b member.actions initial i)
(member.actions.head member.nonempty i)
have hwide : member.rounded i ∈ wideChildStateList parent member.center b P i :=
finiteAssignments_sound M (wideChildStateList parent member.center b P) member.rounded member.wide_guard i
have hwideFirst := (gridStateBox_sound (by unfold seedGridSpacing; omega) (member.rounded i) hwide).1
have htheta : 0 ≀ (2 : β„š) ^ (-(exponent : β„€)) ∧ (2 : β„š) ^ (-(exponent : β„€)) ≀ 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))
have hfirst := wide_firstEndpoint_near_cell cell (by unfold seedGridSpacing; omega) htheta hb
member.center (member.rounded i) ((sourceChild parent i).lo - parent.lo)
(List.mem_filter.mp hcenter).1 hwideFirst
have hgap := member.imbalance_guard i
change |rationalStateGap _ _ (member.rounded i)| ≀ 2 * member.envelope i at hgap
rw [henvelope] at hgap
unfold rationalStateGap at hgap
have hgapDistance := lengthGap_guard_distance (member.rounded i)
(substring source (sourceChild parent i).lo (sourceChild parent i).hi).length h hgap
unfold groupRoundedStateList
apply gridGapStates_complete (groupRoundSpacing_pos exponent h) _ _ hgapDistance hgrid
simpa only [mul_assoc] using hfirst
theorem groupRoundedStateList_length {Ξ± : Type*} (source target : List Ξ±) {M : β„•}
(parent : TargetInterval source.length) (b exponent : β„•) (cell : β„• Γ— β„•)
(i : Fin M) (h : β„š) (hh : 0 < h) :
((groupRoundedStateList source target parent b exponent cell i h).length : β„š) ≀
208 * ((2 : β„š) ^ exponent) ^ 2 * (1 + b / h) := by
exact gridGapStates_rounded_count _ _ _ _ b h ((2 : β„š) ^ exponent)
(groupRoundSpacing_pos exponent h) hh (one_le_powβ‚€ (by norm_num : (1 : β„š) ≀ 2))
(groupRoundSpacing_envelope_bound exponent h)
end EditApproximation
end OAI