Exact Lean source
Nonadditivity.NoncommutativeCSSingletons
Download original .lean · View on GitHub · Jump to source
Direct imports
Imported by project modules
2 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
33 project constants, including generated, internal and private declarations.
33 declarations
Nonadditivity.NoncommutativeCS.EndpointSkeleton.closed_mem_singletonLabels_iff_count_eq_oneNonadditivity.NoncommutativeCS.EndpointSkeleton.closed_singletonLabels_toFinsetNonadditivity.NoncommutativeCS.EndpointSkeleton.closed_singletonLabels_toFinset._proof_1_3internal/detail/privateNonadditivity.NoncommutativeCS.EndpointSkeleton.closed_singletonLabels_toFinset._simp_1_1internal/detail/privateNonadditivity.NoncommutativeCS.EndpointSkeleton.closed_singletonLabels_toFinset._simp_1_2internal/detail/privateNonadditivity.NoncommutativeCS.EndpointSkeleton.mem_initial_range_word_or_finalNonadditivity.NoncommutativeCS.EndpointSkeleton.mem_singletonLabels_iff_count_eq_one_not_initialNonadditivity.NoncommutativeCS.EndpointSkeleton.mem_singletonLabels_iff_count_eq_one_not_initial._proof_1_10internal/detail/privateNonadditivity.NoncommutativeCS.EndpointSkeleton.mem_singletonLabels_iff_count_eq_one_not_initial._simp_1_13internal/detail/privateNonadditivity.NoncommutativeCS.EndpointSkeleton.mem_singletonLabels_iff_count_eq_one_not_initial._simp_1_7internal/detail/privateNonadditivity.NoncommutativeCS.EndpointSkeleton.mem_singletonLabels_iff_count_eq_one_not_initial._simp_1_8internal/detail/privateNonadditivity.NoncommutativeCS.EndpointSkeleton.mem_singletonLabels_iff_count_eq_one_not_initial._simp_1_9internal/detail/privateNonadditivity.NoncommutativeCS.EndpointSkeleton.mem_singletonLabels_iff_count_eq_one_not_initial.match_1_11internal/detail/privateNonadditivity.NoncommutativeCS.EndpointSkeleton.mem_word_of_initial_closedNonadditivity.NoncommutativeCS.EndpointSkeleton.mem_word_range_or_profileNonadditivity.NoncommutativeCS.EndpointSkeleton.singletonLabelsNonadditivity.NoncommutativeCS.EndpointSkeleton.singletonLabels._sunfoldinternal/detail/privateNonadditivity.NoncommutativeCS.EndpointSkeleton.singletonLabels._unsafe_recinternal/detail/privateNonadditivity.NoncommutativeCS.EndpointSkeleton.singletonLabels.eq_1internal/detail/privateNonadditivity.NoncommutativeCS.EndpointSkeleton.singletonLabels.eq_2internal/detail/privateNonadditivity.NoncommutativeCS.EndpointSkeleton.singletonLabels.eq_3internal/detail/privateNonadditivity.NoncommutativeCS.EndpointSkeleton.singletonLabels.eq_4internal/detail/privateNonadditivity.NoncommutativeCS.EndpointSkeleton.singletonLabels.eq_5internal/detail/privateNonadditivity.NoncommutativeCS.EndpointSkeleton.singletonLabels.eq_defNonadditivity.NoncommutativeCS.EndpointSkeleton.singletonLabels.match_1internal/detail/privateNonadditivity.NoncommutativeCS.EndpointSkeleton.singletonLabels_nodupNonadditivity.NoncommutativeCS.EndpointSkeleton.singletonLabels_sublist_profileLabels_private.Nonadditivity.NoncommutativeCSSingletons.0.Nonadditivity.NoncommutativeCS.EndpointSkeleton.singletonLabels.match_1.eq_1internal/detail/private_private.Nonadditivity.NoncommutativeCSSingletons.0.Nonadditivity.NoncommutativeCS.EndpointSkeleton.singletonLabels.match_1.eq_2internal/detail/private_private.Nonadditivity.NoncommutativeCSSingletons.0.Nonadditivity.NoncommutativeCS.EndpointSkeleton.singletonLabels.match_1.eq_3internal/detail/private_private.Nonadditivity.NoncommutativeCSSingletons.0.Nonadditivity.NoncommutativeCS.EndpointSkeleton.singletonLabels.match_1.eq_4internal/detail/private_private.Nonadditivity.NoncommutativeCSSingletons.0.Nonadditivity.NoncommutativeCS.EndpointSkeleton.singletonLabels.match_1.eq_5internal/detail/private_private.Nonadditivity.NoncommutativeCSSingletons.0.Nonadditivity.NoncommutativeCS.EndpointSkeleton.singletonLabels.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.NoncommutativeCSEndpointSkeleton78/-! # Singleton labels of closed endpoint skeletons910The endpoint compiler's singleton nodes are exactly the labels occurring11once in the literal visit word. The proof tracks the actual active layout;12it does not assume that the skeleton was built by a particular compiler.13-/14noncomputable section15namespace Nonadditivity.NoncommutativeCS.EndpointSkeleton16variable {I : Type*}1718def singletonLabels {m n : ℕ} {a : Fin m → I} {b : Fin n → I} :19EndpointSkeleton I a b → List I20| .done _ => []21| .first _ P => P.singletonLabels22| .last _ P => P.singletonLabels23| .middle _ P => P.singletonLabels24| .singleton i P => i :: P.singletonLabels2526theorem singletonLabels_sublist_profileLabels {m n : ℕ}27{a : Fin m → I} {b : Fin n → I} (P : EndpointSkeleton I a b) :28P.singletonLabels.Sublist P.profileLabels := by29induction P with30| done => simp [singletonLabels, profileLabels]31| first i P ih => exact ih.cons _32| last p P ih => exact ih33| middle visits P ih => exact ih34| singleton i P ih => exact ih.cons_cons _3536theorem singletonLabels_nodup {m n : ℕ}37{a : Fin m → I} {b : Fin n → I} (P : EndpointSkeleton I a b)38(hP : P.profileLabels.Nodup) : P.singletonLabels.Nodup :=39hP.sublist P.singletonLabels_sublist_profileLabels4041/-- A visit uses an initially active label or a label introduced by the42skeleton itself. -/43theorem mem_word_range_or_profile {m n : ℕ}44{a : Fin m → I} {b : Fin n → I} (P : EndpointSkeleton I a b) (i : I) :45i ∈ P.word → i ∈ Set.range a ∨ i ∈ P.profileLabels := by46induction P with47| done => simp [word]48| @first m n a b j P ih =>49intro hi50rcases List.mem_cons.mp hi with rfl | hi51· exact Or.inr (List.mem_cons_self)52· rcases ih hi with hi | hi53· rcases (show i=j ∨ i ∈ Set.range a by simpa [Fin.range_cons] using hi) with rfl | hi54· exact Or.inr (List.mem_cons_self)55· exact Or.inl hi56· exact Or.inr (List.mem_cons_of_mem _ hi)57| @last m n a b p P ih =>58intro hi59rcases List.mem_cons.mp hi with hi | hi60· exact Or.inl ⟨p,hi.symm⟩61· rcases ih hi with ⟨q,hq⟩ | hi62· exact Or.inl ⟨p.succAbove q,hq⟩63· exact Or.inr hi64| @middle m n a b visits P ih =>65intro hi66rcases List.mem_append.mp hi with hi | hi67· obtain ⟨p,hp,rfl⟩ := List.mem_map.mp hi68exact Or.inl ⟨p,rfl⟩69· exact ih hi70| singleton j P ih =>71intro hi72rcases List.mem_cons.mp hi with rfl | hi73· exact Or.inr List.mem_cons_self74· exact (ih hi).imp_right (List.mem_cons_of_mem _)7576/-- An initially active label is eventually visited or remains in the final77layout. This is the finite register conservation property. -/78theorem mem_initial_range_word_or_final {m n : ℕ}79{a : Fin m → I} {b : Fin n → I} (P : EndpointSkeleton I a b) (i : I) :80i ∈ Set.range a → i ∈ P.word ∨ i ∈ Set.range b := by81induction P with82| done => exact Or.inr83| @first m n a b j P ih =>84intro hi85have hi' : i ∈ Set.range (Fin.cons j a) := by86simpa [Fin.range_cons] using (Or.inr hi : i=j ∨ i ∈ Set.range a)87exact (ih hi').imp_left (List.mem_cons_of_mem _)88| @last m n a b p P ih =>89rintro ⟨q,rfl⟩90by_cases hq : q=p91· subst q92exact Or.inl List.mem_cons_self93· obtain ⟨r,hr⟩ := Fin.exists_succAbove_eq hq94have hi : a q ∈ Set.range (p.removeNth a) := ⟨r,congrArg a hr⟩95exact (ih hi).imp_left (List.mem_cons_of_mem _)96| middle visits P ih =>97intro hi98exact (ih hi).imp_left (List.mem_append_right _)99| singleton j P ih =>100intro hi101exact (ih hi).imp_left (List.mem_cons_of_mem _)102103theorem mem_word_of_initial_closed {m n : ℕ}104{a : Fin m → I} {b : Fin n → I} (P : EndpointSkeleton I a b)105(hend : ∀ q : Fin n, False) (i : I) (hi : i ∈ Set.range a) :106i ∈ P.word := by107rcases P.mem_initial_range_word_or_final i hi with hi | ⟨q,hq⟩108· exact hi109· exact (hend q).elim110111/-- Generic induction invariant: a singleton node accounts exactly for a112single visit of a label which was not active at the start. -/113theorem mem_singletonLabels_iff_count_eq_one_not_initial [DecidableEq I]114{m n : ℕ} {a : Fin m → I} {b : Fin n → I} (P : EndpointSkeleton I a b)115(hend : ∀ q : Fin n, False) (ha : Function.Injective a)116(hP : P.profileLabels.Nodup)117(hdisj : ∀ i ∈ P.profileLabels, i ∉ Set.range a) (i : I) :118i ∈ P.singletonLabels ↔ P.word.count i=1 ∧ i ∉ Set.range a := by119induction P with120| done => simp [singletonLabels, word]121| @first m n a b j P ih =>122obtain ⟨hj,hP⟩ := List.nodup_cons.mp hP123have hja : j ∉ Set.range a := hdisj j List.mem_cons_self124have hd : ∀ k ∈ P.profileLabels, k ∉ Set.range (Fin.cons j a) := by125intro k hk126simp only [Fin.range_cons, Set.mem_insert_iff, not_or]127exact ⟨fun he => hj (he ▸ hk), hdisj k (List.mem_cons_of_mem _ hk)⟩128have hh := ih hend (Fin.cons_injective_of_injective hja ha) hP hd129by_cases hij : i=j130· subst i131have hnot : j ∉ P.singletonLabels := fun h => hj132(P.singletonLabels_sublist_profileLabels.subset h)133have hpos : 0 < P.word.count j := List.count_pos_iff.mpr134(P.mem_word_of_initial_closed hend j ⟨0,by simp⟩)135simp only [singletonLabels, word, hnot, List.count_cons_self, false_iff, not_and]136omega137· simpa [singletonLabels, word, List.count_cons, hij, Ne.symm hij,138Fin.range_cons] using hh139| @last m n a b p P ih =>140have hd : ∀ k ∈ P.profileLabels, k ∉ Set.range (p.removeNth a) := by141intro k hk ⟨q,hq⟩142exact hdisj k hk ⟨p.succAbove q,hq⟩143have hh := ih hend (ha.comp Fin.succAbove_right_injective) hP hd144by_cases hi : i=a p145· subst i146have hnot : a p ∉ P.singletonLabels := fun h =>147hdisj _ (P.singletonLabels_sublist_profileLabels.subset h) ⟨p,rfl⟩148simp [singletonLabels, word, hnot, show a p ∈ Set.range a from ⟨p,rfl⟩]149· simpa [singletonLabels, word, List.count_cons, hi, Ne.symm hi,150mem_range_removeNth ha p, not_and_or] using hh151| @middle m n a b visits P ih =>152have hh := ih hend ha hP hdisj153by_cases hi : i ∈ Set.range a154· have hnot : i ∉ P.singletonLabels := fun h =>155hdisj _ (P.singletonLabels_sublist_profileLabels.subset h) hi156simp [singletonLabels, hnot, hi]157· have hm : i ∉ visits.map a := by158rintro hi'159obtain ⟨p,hp,hp'⟩ := List.mem_map.mp hi'160exact hi ⟨p,hp'⟩161simpa [singletonLabels, word, List.count_append,162List.count_eq_zero.mpr hm, hi] using hh163| @singleton m n a b j P ih =>164obtain ⟨hj,hP⟩ := List.nodup_cons.mp hP165have hd : ∀ k ∈ P.profileLabels, k ∉ Set.range a :=166fun k hk => hdisj k (List.mem_cons_of_mem _ hk)167have hh := ih hend ha hP hd168have hja : j ∉ Set.range a := hdisj j List.mem_cons_self169by_cases hij : i=j170· subst i171have hw : j ∉ P.word := fun h =>172(P.mem_word_range_or_profile j h).elim hja hj173simp [singletonLabels, word, List.count_eq_zero.mpr hw, hja]174· simpa [singletonLabels, word, List.count_cons, hij, Ne.symm hij] using hh175176theorem closed_mem_singletonLabels_iff_count_eq_one [DecidableEq I]177(P : EndpointSkeleton I (Fin.elim0 : Fin 0 → I) (Fin.elim0 : Fin 0 → I))178(hP : P.profileLabels.Nodup) (i : I) :179i ∈ P.singletonLabels ↔ P.word.count i=1 := by180simpa using P.mem_singletonLabels_iff_count_eq_one_not_initial Fin.elim0181(Function.injective_of_subsingleton _) hP (by simp) i182183theorem closed_singletonLabels_toFinset [DecidableEq I]184(P : EndpointSkeleton I (Fin.elim0 : Fin 0 → I) (Fin.elim0 : Fin 0 → I))185(hP : P.profileLabels.Nodup) :186P.singletonLabels.toFinset=P.word.toFinset.filter (fun i => P.word.count i=1) := by187ext i188simp only [List.mem_toFinset, Finset.mem_filter,189P.closed_mem_singletonLabels_iff_count_eq_one hP]190constructor191· intro hi192exact ⟨List.count_pos_iff.mp (by omega),hi⟩193· exact And.right194195end Nonadditivity.NoncommutativeCS.EndpointSkeleton