Download data/lean/OAI/Combinatorics/EditApproximation/Geometry/BandEnvelopes.lean from introvoyz045/math: direct link, hf CLI and curl.
- Browser
- Download file 7.82 kB
-
https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Combinatorics/EditApproximation/Geometry/BandEnvelopes.lean
- Command line
-
hf download hf://datasets/introvoyz045/math/data/lean/OAI/Combinatorics/EditApproximation/Geometry/BandEnvelopes.lean
-
curl -L -o BandEnvelopes.lean https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Combinatorics/EditApproximation/Geometry/BandEnvelopes.lean
7.82 kB
| import OAI.Combinatorics.EditApproximation.Geometry.BandGuards | |
| import Mathlib.Data.Int.Log | |
| import OAI.Combinatorics.EditApproximation.Definitions | |
| namespace OAI | |
| /-! | |
| # Actual dyadic child envelopes | |
| The maximum scans the actual finite band. The dyadic ceiling uses the | |
| computable integer upper logarithm of a positive rational, including values | |
| below one. | |
| -/ | |
| namespace EditApproximation | |
| open Finset | |
| theorem rationalMaximum_le (fallback upper : β) (values : List β) | |
| (hfallback : fallback β€ upper) (hvalues : β value β values, value β€ upper) : | |
| rationalMaximum fallback values β€ upper := by | |
| induction values with | |
| | nil => exact hfallback | |
| | cons value rest ih => | |
| exact max_le (hvalues value (by simp)) (ih (fun value hv => hvalues value (by simp [hv]))) | |
| theorem le_rationalMaximum_member (fallback : β) (values : List β) (value : β) | |
| (hvalue : value β values) : value β€ rationalMaximum fallback values := by | |
| induction values with | |
| | nil => simp only [List.not_mem_nil] at hvalue | |
| | cons head rest ih => | |
| rcases List.mem_cons.mp hvalue with rfl | hrest | |
| Β· exact le_max_left _ _ | |
| Β· exact (ih hrest).trans (le_max_right _ _) | |
| theorem rationalDyadicCeiling_bounds (value : β) (hvalue : 0 < value) : | |
| value β€ rationalDyadicCeiling value β§ rationalDyadicCeiling value < 2 * value := by | |
| constructor | |
| Β· exact Int.self_le_zpow_clog (by decide : 1 < 2) value | |
| Β· have h := mul_lt_mul_of_pos_right | |
| (Int.zpow_pred_clog_lt_self (by decide : 1 < 2) hvalue) (by norm_num : (0 : β) < 2) | |
| change (2 : β) ^ (Int.clog 2 value - 1) * 2 < value * 2 at h | |
| have hexponent : Int.clog 2 value - 1 + 1 = Int.clog 2 value := by omega | |
| rw [β zpow_add_oneβ (by norm_num : (2 : β) β 0), hexponent] at h | |
| simpa only [rationalDyadicCeiling, mul_comm] using h | |
| /-- Zero is a harmless duplicated fallback under the initial table lower | |
| invariant. The positive b/M floor ensures that the ceiling input is positive. -/ | |
| theorem bandChildEnvelope_lower {ny M : β} (b : β) | |
| (band : List (Fin M β TargetInterval ny)) | |
| (initial : Fin M β TargetInterval ny β β) (i : Fin M) : | |
| (b : β) / M β€ bandChildEnvelope b band initial i β§ | |
| β action β band, initial i (action i) β€ bandChildEnvelope b band initial i := by | |
| have hceil := Int.self_le_zpow_clog (R := β) (by decide : 1 < 2) | |
| (max ((b : β) / M) (rationalMaximum 0 (band.map fun action => initial i (action i)))) | |
| refine β¨(le_max_left _ _).trans hceil, ?_β© | |
| intro action ha | |
| exact (le_rationalMaximum_member 0 _ _ (List.mem_map.mpr β¨action, ha, rflβ©)).trans | |
| ((le_max_right _ _).trans hceil) | |
| /-- Every finite envelope is bounded using the actual computed-band | |
| endpoint diameter and the initial table's spatial inequality. -/ | |
| theorem bandChildEnvelope_upper {nx ny M : β} (parent : TargetInterval nx) | |
| (r : TargetInterval ny) (b P : β) (hb : 0 < b) (hM : 0 < M) | |
| (tau theta velocity : β) (htau : 0 < tau) (htheta : 0 β€ theta) | |
| (child initial : Fin M β TargetInterval ny β β) | |
| (comparison : Fin M β TargetInterval ny) | |
| (hcomparison : comparison β computedBandActions parent r b P tau theta velocity child) | |
| (L0 : β) (hL0 : 0 β€ L0) | |
| (hinitial : β i, 0 β€ initial i (comparison i)) | |
| (hspatial : β i s t, initial i s β€ initial i t + L0 * targetEndpointDistance s t) | |
| (i : Fin M) : | |
| bandChildEnvelope b (computedBandActions parent r b P tau theta velocity child) initial i β€ | |
| 2 * ((b : β) / M) + 2 * initial i (comparison i) + 8 * L0 * theta * b / M := by | |
| let band := computedBandActions parent r b P tau theta velocity child | |
| let delta : β := 4 * theta * b / M | |
| let upper := initial i (comparison i) + L0 * delta | |
| have hdelta : 0 β€ delta := by dsimp only [delta]; positivity | |
| have hupper : 0 β€ upper := add_nonneg (hinitial i) (mul_nonneg hL0 hdelta) | |
| have hmembers : β value β band.map (fun action => initial i (action i)), value β€ upper := by | |
| intro value hvalue | |
| obtain β¨action, ha, rflβ© := List.mem_map.mp hvalue | |
| have hdistReal := computedBand_child_endpoint_diameter parent r b P tau theta velocity htau htheta | |
| child action comparison ha hcomparison i | |
| have hdist : (targetEndpointDistance (action i) (comparison i) : β) β€ delta := by exact_mod_cast hdistReal | |
| exact (hspatial i (action i) (comparison i)).trans | |
| (add_le_add le_rfl (mul_le_mul_of_nonneg_left hdist hL0)) | |
| have hmaximum := rationalMaximum_le 0 upper _ hupper hmembers | |
| have hfloor : (0 : β) < (b : β) / M := div_pos (by exact_mod_cast hb) (by exact_mod_cast hM) | |
| have hpositive := hfloor.trans_le (le_max_left ((b : β) / M) | |
| (rationalMaximum 0 (band.map fun action => initial i (action i)))) | |
| have hceil := (rationalDyadicCeiling_bounds _ hpositive).2.le | |
| have hmaxUpper : max ((b : β) / M) | |
| (rationalMaximum 0 (band.map fun action => initial i (action i))) β€ (b : β) / M + upper := by | |
| apply max_le | |
| Β· exact le_add_of_nonneg_right hupper | |
| Β· exact hmaximum.trans (le_add_of_nonneg_left hfloor.le) | |
| apply hceil.trans | |
| have hmul := mul_le_mul_of_nonneg_left hmaxUpper (by norm_num : (0 : β) β€ 2) | |
| dsimp only [upper, delta] at hmul | |
| convert hmul using 1 | |
| ring | |
| /-- The actual sum guard follows from the concrete envelopes, the initial | |
| cone bounds at the comparison child states, and their actual edit costs. -/ | |
| theorem bandChildEnvelope_sum_guard {Ξ± : Type*} (source target : List Ξ±) | |
| {M : β} (parent : TargetInterval source.length) (r : TargetInterval target.length) | |
| (b P : β) (hb : 0 < b) (hM : 0 < M) | |
| (tau theta velocity : β) (htau : 0 < tau) (htheta : 0 β€ theta) | |
| (child initial : Fin M β TargetInterval target.length β β) | |
| (comparison : Fin M β TargetInterval target.length) | |
| (hcomparison : comparison β computedBandActions parent r b P tau theta velocity child) | |
| (L0 F : β) (hL0 : 0 β€ L0) (hF : 1 β€ F) (hsmall : L0 * theta β€ 1) | |
| (hinitial : β i, 0 β€ initial i (comparison i)) | |
| (hspatial : β i s t, initial i s β€ initial i t + L0 * targetEndpointDistance s t) | |
| (hinitialUpper : β i, initial i (comparison i) β€ 2 * F * (stateEditCost | |
| (substring source (sourceChild parent i).lo (sourceChild parent i).hi) target (comparison i) : β)) | |
| (hcomparisonCost : (β i : Fin M, (stateEditCost | |
| (substring source (sourceChild parent i).lo (sourceChild parent i).hi) target (comparison i) : β)) β€ 4 * b) : | |
| (β i : Fin M, bandChildEnvelope b | |
| (computedBandActions parent r b P tau theta velocity child) initial i) β€ 64 * F * b := by | |
| have hMr : (0 : β) < M := by exact_mod_cast hM | |
| have hpoint := fun i => bandChildEnvelope_upper parent r b P hb hM tau theta velocity htau htheta | |
| child initial comparison hcomparison L0 hL0 hinitial hspatial i | |
| have hsum := sum_le_sum (fun i (_ : i β (univ : Finset (Fin M))) => hpoint i) | |
| have hequal : (β i : Fin M, (2 * ((b : β) / M) + 2 * initial i (comparison i) + | |
| 8 * L0 * theta * b / M)) = 2 * b + 2 * (β i : Fin M, initial i (comparison i)) + | |
| 8 * L0 * theta * b := by | |
| rw [sum_add_distrib, sum_add_distrib, sum_const, sum_const, | |
| card_univ, Fintype.card_fin, β mul_sum] | |
| simp only [nsmul_eq_mul] | |
| field_simp [hMr.ne'] | |
| rw [hequal] at hsum | |
| have hinitSum := sum_le_sum (fun i (_ : i β (univ : Finset (Fin M))) => hinitialUpper i) | |
| rw [β mul_sum] at hinitSum | |
| have hFpos : 0 β€ 2 * F := by linarith | |
| have hcost := mul_le_mul_of_nonneg_left hcomparisonCost hFpos | |
| have hsmallb := mul_le_mul_of_nonneg_right hsmall (show (0 : β) β€ b by positivity) | |
| have hFb := mul_le_mul_of_nonneg_right hF (show (0 : β) β€ b by positivity) | |
| nlinarith only [hsum, hinitSum, hcost, hsmallb, hFb] | |
| end EditApproximation | |
| end OAI | |