Exact Lean source
Nonadditivity.HaarSkeletonSegmentation
Download original .lean · View on GitHub · Jump to source
Direct imports
Imported by project modules
3 direct reverse imports
Relationships above come from literal import commands. The declarations below link to types and references extracted from Lean’s environment. Source text is complete and unchanged.
Declarations in this module
24 project constants, including generated, internal and private declarations.
24 declarations
Nonadditivity.HaarSkeletonSegmentation.length_scanWordsNonadditivity.HaarSkeletonSegmentation.pairCoefficientNonadditivity.HaarSkeletonSegmentation.pairCoefficient.eq_1internal/detail/privateNonadditivity.HaarSkeletonSegmentation.raw_blockFactors_segmentedProductNonadditivity.HaarSkeletonSegmentation.reverseFactorsNonadditivity.HaarSkeletonSegmentation.reverseFactors._sunfoldinternal/detail/privateNonadditivity.HaarSkeletonSegmentation.reverseFactors._unsafe_recinternal/detail/privateNonadditivity.HaarSkeletonSegmentation.reverseFactors.eq_1internal/detail/privateNonadditivity.HaarSkeletonSegmentation.reverseFactors.eq_2internal/detail/privateNonadditivity.HaarSkeletonSegmentation.reverseFactors.eq_defNonadditivity.HaarSkeletonSegmentation.reverseFactors.match_1internal/detail/privateNonadditivity.HaarSkeletonSegmentation.reverseFactors_mapIdxNonadditivity.HaarSkeletonSegmentation.reverseFactors_mapIdx._simp_1_4internal/detail/privateNonadditivity.HaarSkeletonSegmentation.reverseFactors_mapIdx._simp_1_5internal/detail/privateNonadditivity.HaarSkeletonSegmentation.reverseFactors_segmentedProductNonadditivity.HaarSkeletonSegmentation.reverseFactors_snocNonadditivity.HaarSkeletonSegmentation.scanWordsNonadditivity.HaarSkeletonSegmentation.scanWords.eq_1internal/detail/private_private.Nonadditivity.HaarSkeletonSegmentation.0.Nonadditivity.HaarSkeletonSegmentation.mapIdx_duration_eq_timesinternal/detail/private_private.Nonadditivity.HaarSkeletonSegmentation.0.Nonadditivity.HaarSkeletonSegmentation.mapIdx_duration_eq_times._proof_1_1internal/detail/private_private.Nonadditivity.HaarSkeletonSegmentation.0.Nonadditivity.HaarSkeletonSegmentation.mapIdx_zipinternal/detail/private_private.Nonadditivity.HaarSkeletonSegmentation.0.Nonadditivity.HaarSkeletonSegmentation.reverseFactors.match_1.eq_1internal/detail/private_private.Nonadditivity.HaarSkeletonSegmentation.0.Nonadditivity.HaarSkeletonSegmentation.reverseFactors.match_1.eq_2internal/detail/private_private.Nonadditivity.HaarSkeletonSegmentation.0.Nonadditivity.HaarSkeletonSegmentation.reverseFactors.match_1.splitterinternal/detail/private
Full module
1/-2Copyright (c) 2026 the Nonadditivity project contributors.3All rights reserved. See COPYRIGHT.md for licensing and attribution.4-/56import Nonadditivity.HaarProfileDecodedCoefficients7import Nonadditivity.HaarProfileCompositionBound8import Nonadditivity.NoncommutativeCSBlocks9import Nonadditivity.HaarNonbacktrackingSegmentation10import Nonadditivity.HaarTimeCompositionReverse1112/-! # The actual register factors are the last-return segmented product1314The skeleton scans occurrences from right to left. Its first block therefore15uses the ordinary polynomial, and each subsequent block uses the killed-return16polynomial. Reversing the scan durations recovers the exact ordered segmented17product, with no commutativity assumption on the operator coefficients.18-/1920noncomputable section21set_option backward.isDefEq.respectTransparency false22namespace Nonadditivity.HaarSkeletonSegmentation23open scoped BigOperators24open HaarOperatorPolynomial HaarProfileBlockCoefficients HaarNonbacktracking25NoncommutativeCS HaarProfileCompositionBound HaarProfileDecodedCoefficients26HaarProfilePatternBound HaarProfileAssignmentBound HaarProfilePadding27HaarProfileCoefficient HaarPathProfiles HaarTimeCompositions2829section Algebra30variable {G R : Type*} [Group G] [Ring R]3132def pairCoefficient (A : MonoidAlgebra R G) (ordinary : Bool) (x : G × ℕ) : R :=33if ordinary then (A ^ x.2) x.1 else killedPolynomial A 1 x.2 x.13435def reverseFactors (A : MonoidAlgebra R G) : Bool → List (G × ℕ) → List R36| _, [] => []37| ordinary, x :: xs => reverseFactors A false xs ++ [pairCoefficient A ordinary x]3839theorem reverseFactors_snoc (A : MonoidAlgebra R G) (ordinary : Bool)40(xs : List (G × ℕ)) (x : G × ℕ) :41reverseFactors A ordinary (xs ++ [x]) =42[pairCoefficient A (ordinary && xs.isEmpty) x] ++ reverseFactors A ordinary xs := by43induction xs generalizing ordinary with44| nil => simp [reverseFactors]45| cons y ys ih => simp [reverseFactors, ih, List.append_assoc]4647theorem reverseFactors_segmentedProduct (A : MonoidAlgebra R G)48(g : G) (gs : List G) (ts : List ℕ) (ht : ts.length = (g :: gs).length) :49(reverseFactors A true (((g :: gs).zip ts).reverse)).prod =50segmentedProduct A g gs ts := by51induction gs generalizing g ts with52| nil =>53cases ts with54| nil => simp at ht55| cons n ns =>56have hn : ns = [] := List.length_eq_zero_iff.mp (by simpa using ht)57subst ns58simp [reverseFactors, pairCoefficient]59| cons h hs ih =>60cases ts with61| nil => simp at ht62| cons n ns =>63have hn : ns.length = (h :: hs).length := by simpa using ht64have hne : ((h :: hs).zip ns).reverse ≠ [] := by65have hl : ((h :: hs).zip ns).reverse.length = (h :: hs).length := by66simp [List.length_zip, hn]67intro he68simp [he] at hl69simp only [List.zip_cons_cons, List.reverse_cons, reverseFactors_snoc]70simp only [List.isEmpty_eq_false_iff.mpr hne, Bool.and_false,71List.singleton_append, List.prod_cons, pairCoefficient, Bool.false_eq_true,72if_false, ih h ns hn, segmentedProduct_cons]7374theorem reverseFactors_mapIdx {X : Type*} (A : MonoidAlgebra R G)75(xs : List X) (word : ℕ → X → G) (duration : ℕ → ℕ) (k : ℕ) :76reverseFactors A (decide (k = 0))77(xs.mapIdx (fun i x => (word (k + i) x, duration (k + i)))) =78(xs.mapIdx (fun i x =>79pairCoefficient A (decide (k + i = 0)) (word (k + i) x, duration (k + i)))).reverse := by80induction xs generalizing k with81| nil => rfl82| cons x xs ih =>83simp only [List.mapIdx_cons, Nat.add_zero, List.reverse_cons, reverseFactors]84have hi := ih (k + 1)85simpa only [Nat.add_assoc, Nat.add_left_comm, Nat.add_comm, Nat.add_eq_zero_iff,86Nat.one_ne_zero, and_false, decide_false] using87congrArg (fun l => l ++ [pairCoefficient A (decide (k = 0)) (word k x, duration k)]) hi8889end Algebra9091variable {I J E : Type*}92variable [NormedAddCommGroup E] [InnerProductSpace ℂ E] [CompleteSpace E]93variable {d : ℕ}9495/-- Decoded whole-block words in the chronological register-scan order. -/96def scanWords {m n : ℕ} {a : Fin m → I} {b : Fin n → I}97(P : EndpointSkeleton I a b)98(decode : ℕ → List I → List J → FreeGroup (Fin d)) (σ : I → J) :99List (FreeGroup (Fin d)) :=100P.blocks.mapIdx (fun k labels => decode k labels (labels.map σ))101102@[simp] theorem length_scanWords {m n : ℕ} {a : Fin m → I} {b : Fin n → I}103(P : EndpointSkeleton I a b)104(decode : ℕ → List I → List J → FreeGroup (Fin d)) (σ : I → J) :105(scanWords P decode σ).length = P.markedFlags.length := by106simp [scanWords]107108private theorem mapIdx_zip {X Y Z : Type*} (xs : List X)109(f : ℕ → X → Y) (g : ℕ → X → Z) :110(xs.mapIdx f).zip (xs.mapIdx g) = xs.mapIdx (fun i x => (f i x, g i x)) := by111induction xs generalizing f g with112| nil => rfl113| cons x xs ih => simp only [List.mapIdx_cons, List.zip_cons_cons, ih]114115private theorem mapIdx_duration_eq_times {m n : ℕ} {a : Fin m → I} {b : Fin n → I}116(P : EndpointSkeleton I a b) (duration : ℕ → ℕ) (k : ℕ) :117P.blocks.mapIdx (fun j _ => duration (k + j)) = P.times duration k := by118induction P generalizing k with119| done => rfl120| first i P ih =>121simp only [EndpointSkeleton.blocks, EndpointSkeleton.times, List.mapIdx_cons, Nat.add_zero]122congr 1123convert ih (k + 1) using 1124congr 1125funext j x126congr 1127omega128| last p P ih =>129simp only [EndpointSkeleton.blocks, EndpointSkeleton.times, List.mapIdx_cons, Nat.add_zero]130congr 1131convert ih (k + 1) using 1132congr 1133funext j x134congr 1135omega136| middle visits P ih =>137simp only [EndpointSkeleton.blocks, EndpointSkeleton.times, List.mapIdx_cons, Nat.add_zero]138congr 1139convert ih (k + 1) using 1140congr 1141funext j x142congr 1143omega144| singleton i P ih =>145simp only [EndpointSkeleton.blocks, EndpointSkeleton.times, List.mapIdx_cons, Nat.add_zero]146congr 1147convert ih (k + 1) using 1148congr 1149funext j x150congr 1151omega152153/-- The literal unpadded register product is exactly the last-return product154on the decoded blocks in their original left-to-right order. -/155theorem raw_blockFactors_segmentedProduct [Fintype J] [DecidableEq J]156{m n : ℕ} {a : Fin m → I} {b : Fin n → I}157(P : EndpointSkeleton I a b) (B : Polynomial (FreeGroup (Fin d)) E)158(duration : ℕ → ℕ)159(decode : ℕ → List I → List J → FreeGroup (Fin d)) (σ : I → J)160(g : FreeGroup (Fin d)) (gs : List (FreeGroup (Fin d)))161(hgs : (scanWords P decode σ).reverse = g :: gs) :162(P.blockFactors (fun k labels choices =>163blockPolynomial B (decide (k = 0)) (duration k) (decode k labels choices)) 0 σ).prod =164segmentedProduct B g gs (P.times duration 0).reverse := by165rw [P.blockFactors_eq_reverse_mapIdx]166simp only [Nat.zero_add]167have hr := reverseFactors_mapIdx B P.blocks168(fun k labels => decode k labels (labels.map σ)) duration 0169simp only [Nat.zero_add, decide_true] at hr170have he : (scanWords P decode σ).zip (P.times duration 0) =171P.blocks.mapIdx (fun k labels => (decode k labels (labels.map σ), duration k)) := by172rw [← mapIdx_duration_eq_times P duration 0]173simpa only [scanWords, Nat.zero_add] using mapIdx_zip P.blocks174(fun k labels => decode k labels (labels.map σ)) (fun k _ => duration k)175have hlen : (P.times duration 0).reverse.length = (g :: gs).length := by176rw [← hgs, List.length_reverse, List.length_reverse, length_scanWords]177simp [times_eq_ofFn]178have hz : ((g :: gs).zip (P.times duration 0).reverse).reverse =179(scanWords P decode σ).zip (P.times duration 0) := by180have heql : (scanWords P decode σ).length = (P.times duration 0).length := by181simp [times_eq_ofFn]182rw [← hgs]183have hz := List.reverse_zipWith (f := Prod.mk) heql184exact congrArg List.reverse hz.symm |>.trans (List.reverse_reverse _)185have h := reverseFactors_segmentedProduct B g gs (P.times duration 0).reverse hlen186rw [hz, he, hr] at h187have hc : ∀ k labels,188pairCoefficient B (decide (k = 0)) (decode k labels (labels.map σ), duration k) =189blockPolynomial B (decide (k = 0)) (duration k) (decode k labels (labels.map σ)) := by190intro k labels191by_cases hk : k = 0 <;> simp [pairCoefficient, blockPolynomial, hk]192simpa only [hc] using h193194end Nonadditivity.HaarSkeletonSegmentation