Exact Lean source
Nonadditivity.HaarPathRuns
Download original .lean · View on GitHub · Jump to source
Catalog entries: Corrected marked-position and middle-run accounting
Direct imports
Nonadditivity.HaarPathProfilesMathlib.Data.Finset.CarddependencyMathlib.Algebra.BigOperators.Group.Finset.BasicdependencyMathlib.Algebra.BigOperators.Group.Finset.Pidependency
Imported by project modules
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
37 project constants, including generated, internal and private declarations.
37 declarations
Nonadditivity.HaarPathRuns.blockCountNonadditivity.HaarPathRuns.card_endpointPositions_leNonadditivity.HaarPathRuns.card_endpointPositions_le._proof_1_1internal/detail/privateNonadditivity.HaarPathRuns.card_firstPositions_leNonadditivity.HaarPathRuns.card_lastPositions_leNonadditivity.HaarPathRuns.corrected_exponent_leNonadditivity.HaarPathRuns.corrected_exponent_le._proof_1_1internal/detail/privateNonadditivity.HaarPathRuns.count_endpointFlagsNonadditivity.HaarPathRuns.count_true_eq_sumNonadditivity.HaarPathRuns.endpointFlagsNonadditivity.HaarPathRuns.endpointFlags.eq_1internal/detail/privateNonadditivity.HaarPathRuns.endpointPositionsNonadditivity.HaarPathRuns.endpointPositions.congr_simpNonadditivity.HaarPathRuns.firstPositionsNonadditivity.HaarPathRuns.first_endpointNonadditivity.HaarPathRuns.head_endpointFlagsNonadditivity.HaarPathRuns.head_endpointFlags._simp_1_2internal/detail/privateNonadditivity.HaarPathRuns.lastPositionsNonadditivity.HaarPathRuns.last_endpointNonadditivity.HaarPathRuns.middleRunsNonadditivity.HaarPathRuns.middleRuns._sunfoldinternal/detail/privateNonadditivity.HaarPathRuns.middleRuns._unsafe_recinternal/detail/privateNonadditivity.HaarPathRuns.middleRuns.eq_1internal/detail/privateNonadditivity.HaarPathRuns.middleRuns.eq_2internal/detail/privateNonadditivity.HaarPathRuns.middleRuns.eq_3internal/detail/privateNonadditivity.HaarPathRuns.middleRuns.eq_defNonadditivity.HaarPathRuns.middleRuns.match_1internal/detail/privateNonadditivity.HaarPathRuns.middleRuns_add_head_leNonadditivity.HaarPathRuns.middleRuns_add_head_le._proof_1_5internal/detail/privateNonadditivity.HaarPathRuns.middleRuns_add_head_le._proof_1_6internal/detail/privateNonadditivity.HaarPathRuns.middleRuns_add_one_leNonadditivity.HaarPathRuns.occurrence_exponent_leNonadditivity.HaarPathRuns.two_edge_run_counterexample_private.Nonadditivity.HaarPathRuns.0.Nonadditivity.HaarPathRuns.middleRuns.match_1.eq_1internal/detail/private_private.Nonadditivity.HaarPathRuns.0.Nonadditivity.HaarPathRuns.middleRuns.match_1.eq_2internal/detail/private_private.Nonadditivity.HaarPathRuns.0.Nonadditivity.HaarPathRuns.middleRuns.match_1.eq_3internal/detail/private_private.Nonadditivity.HaarPathRuns.0.Nonadditivity.HaarPathRuns.middleRuns.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.HaarPathProfiles7import Mathlib.Data.Finset.Card8import Mathlib.Algebra.BigOperators.Group.Finset.Basic9import Mathlib.Algebra.BigOperators.Group.Finset.Pi1011/-! # First/last markers and the corrected BC coefficient exponent1213The number of middle blocks need not be at most the number of distinct14edges. The valid bound is at most the number of marked positions minus one.15Only marked factors incur a moment-order factor, so this weaker block bound16still gives the required coefficient exponent.17-/18noncomputable section19namespace Nonadditivity.HaarPathRuns20open scoped BigOperators2122/-- Number of maximal false runs that end before the end of the list.23When the last flag is true, these are exactly all middle blocks. -/24def middleRuns : List Bool → ℕ25| [] => 026| [_] => 027| a::b::l => (if a=false ∧ b=true then 1 else 0) + middleRuns (b::l)2829/-- Each middle block can be charged to its following marker; the initial30marker is never charged. This is the sharp general combinatorial bound. -/31theorem middleRuns_add_head_le (l : List Bool) :32middleRuns l + (if l.head?=some true then 1 else 0) ≤ l.count true := by33induction l with34| nil => simp [middleRuns]35| cons a l ih =>36cases l with37| nil => cases a <;> simp [middleRuns]38| cons b l => cases a <;> cases b <;> simp [middleRuns] at * <;> omega3940theorem middleRuns_add_one_le {l : List Bool} (hhead : l.head?=some true) :41middleRuns l + 1 ≤ l.count true := by42simpa only [hhead,if_pos rfl] using middleRuns_add_head_le l4344/-- Marked first/last visits are singleton blocks; the unmarked intervals are45middle blocks. -/46def blockCount (l : List Bool) : ℕ := l.count true + middleRuns l4748/-- The combined exponent from compositions and marked coefficient factors.49This replaces the unnecessarily strong and false bound `r ≤ 3*e`. -/50theorem corrected_exponent_le {l : List Bool} {e : ℕ}51(hhead : l.head?=some true) (hmarks : l.count true ≤ 2*e) :52blockCount l - 1 + l.count true ≤ 6*e-2 := by53have hr := middleRuns_add_one_le hhead54dsimp [blockCount]55omega5657variable {E : Type*} [DecidableEq E] {n : ℕ}5859/-- The first occurrence of each label. -/60def firstPositions (f : Fin n → E) : Finset (Fin n) :=61Finset.univ.filter fun i => ∀ j : Fin n, j < i → f j ≠ f i6263/-- The last occurrence of each label. -/64def lastPositions (f : Fin n → E) : Finset (Fin n) :=65Finset.univ.filter fun i => ∀ j : Fin n, i < j → f j ≠ f i6667def endpointPositions (f : Fin n → E) : Finset (Fin n) :=68firstPositions f ∪ lastPositions f6970theorem card_firstPositions_le (f : Fin n → E) :71(firstPositions f).card ≤ (Finset.univ.image f).card := by72apply Finset.card_le_card_of_injOn f73· intro i hi74exact Finset.mem_image.mpr ⟨i,Finset.mem_univ _,rfl⟩75· intro i hi j hj he76by_contra hij77rcases lt_or_gt_of_ne hij with hlt | hgt78· exact (Finset.mem_filter.mp hj).2 i hlt he79· exact (Finset.mem_filter.mp hi).2 j hgt he.symm8081theorem card_lastPositions_le (f : Fin n → E) :82(lastPositions f).card ≤ (Finset.univ.image f).card := by83apply Finset.card_le_card_of_injOn f84· intro i hi85exact Finset.mem_image.mpr ⟨i,Finset.mem_univ _,rfl⟩86· intro i hi j hj he87by_contra hij88rcases lt_or_gt_of_ne hij with hlt | hgt89· exact (Finset.mem_filter.mp hi).2 j hlt he.symm90· exact (Finset.mem_filter.mp hj).2 i hgt he9192/-- At most two distinguished visits per distinct edge, with singleton93occurrences counted only once. -/94theorem card_endpointPositions_le (f : Fin n → E) :95(endpointPositions f).card ≤ 2*(Finset.univ.image f).card := by96have h := Finset.card_union_le (firstPositions f) (lastPositions f)97have hf := card_firstPositions_le f98have hl := card_lastPositions_le f99dsimp [endpointPositions]100omega101102theorem first_endpoint (f : Fin (n+1) → E) : (0 : Fin (n+1)) ∈ endpointPositions f := by103apply Finset.mem_union_left104apply Finset.mem_filter.mpr105refine ⟨Finset.mem_univ _,?_⟩106intro j hj107exact (Fin.not_lt_zero _ hj).elim108109theorem last_endpoint (f : Fin (n+1) → E) : Fin.last n ∈ endpointPositions f := by110apply Finset.mem_union_right111apply Finset.mem_filter.mpr112refine ⟨Finset.mem_univ _,?_⟩113intro j hj114exact (not_lt_of_ge (Fin.le_last j) hj).elim115116/-- The literal marker flags of a finite edge-occurrence sequence. -/117def endpointFlags (f : Fin n → E) : List Bool :=118List.ofFn fun i => decide (i ∈ endpointPositions f)119120lemma count_true_eq_sum (l : List Bool) :121l.count true = (l.map (fun b => if b then 1 else 0)).sum := by122induction l with123| nil => rfl124| cons a l ih => cases a <;> simp [ih,Nat.add_comm]125126/-- The Boolean marker count is exactly the cardinality of first/last positions. -/127theorem count_endpointFlags (f : Fin n → E) :128(endpointFlags f).count true = (endpointPositions f).card := by129rw [count_true_eq_sum]130simp [endpointFlags,List.map_ofFn,List.sum_ofFn,Function.comp_def]131132theorem head_endpointFlags (f : Fin (n+1) → E) :133(endpointFlags f).head?=some true := by134simp [endpointFlags,List.ofFn_succ,first_endpoint]135136/-- The repaired BC exponent for the actual first/last markers of any137nonempty occurrence sequence. -/138theorem occurrence_exponent_le (f : Fin (n+1) → E) :139blockCount (endpointFlags f) - 1 + (endpointFlags f).count true ≤1406*(Finset.univ.image f).card-2 := by141apply corrected_exponent_le (head_endpointFlags f)142rw [count_endpointFlags]143exact card_endpointPositions_le f144145/-- The eight-position balanced-word example has four markers and three146middle blocks. Thus the generic bound `r ≤ 3*e` fails already for two edges. -/147theorem two_edge_run_counterexample :148blockCount [true,false,false,true,false,true,false,true]=7 ∧1493*2 < blockCount [true,false,false,true,false,true,false,true] := by150decide151152end Nonadditivity.HaarPathRuns