import QLF_RecordForgetting import QLF_ClosureEquivalence import QLF_ColourClosure import QLF_Handedness /-! # Abstraction: lost information leaves an abstraction Part of the [Quantum Logical Framework (QLF)](../README.md). **ZFA** (Zero Free Action) is equal and opposite quantum logical action with zero free energy, the principle of QLF. **The Principle of Emergent Abstraction** (Principles P26). Every deterministic record `D : H → R` that loses a distinction induces a canonical abstraction: the quotient of `H` by "`D` cannot tell them apart". The abstraction is exactly the image of `D`, the properties that survive are exactly the ones invariant under the forgotten distinctions, further loss can only coarsen it, and the information the record drops is exactly the uncertainty about which member of the class occurred. This is **elementary mathematics**, and the module says so: the kernel setoid of a function, its quotient, `Quotient.lift`, and the Shannon chain rule for a deterministic function. Nothing here is a new law. Its use for QLF is that each of these facts can now be cited as a theorem, and that the QLF instances in §6 are *derived* from A01, not assumed: * §1–§2 `abstraction_iff`, `abstractionEquivRange` (`H/∼_D ≃ im D`), `loss_leaves_abstraction`, `nontrivial_class_iff_forgets`, reusing `Forgets` and `forgets_iff_not_injective` from [`QLF_RecordForgetting`](QLF_RecordForgetting.lean) (PR #350) rather than restating them. * §3 `invariant_descends_iff`, `descended_unique`: a property survives the loss exactly when it is invariant under the forgotten distinctions, and then its abstract form is unique. This is the general form of `invariant_iff_class_function` in [`QLF_ClosureEquivalence`](QLF_ClosureEquivalence.lean). * §4 `abstraction_refines`, `coarsen`, `coarsen_surjective`, `coarsen_injective_iff`: successive loss gives a hierarchy; each later abstraction is a surjective image of the earlier one, strictly coarser exactly when the later step forgets something the earlier one kept. * §5 `chain_rule`: for **any** probability vector on a finite set of histories (not only the uniform one of `record_partition`), `H(X) = H(D X) + H(X | D X)`. * §6 QLF instances, each derived: - `closed_iff_vacuum_class`: ZFA closure *is* an abstraction. `full_zeno_prune` is the record, and the closed histories are exactly the class of the empty history. - `closure_forgets_route`: that class is not a singleton (`[+,−]` and `[−,+]` both close), so closure loses information, by A01's own filter. - `ledger_survives_closure`: the net ledger `count_pos − count_neg` descends to the abstraction (from `full_prune_invariant`). Closure conserves the ledger and erases the route (C06) is the abstraction theorem applied to the ZFA filter. - `closureSetoid_is_abstraction`: the closure classes of [`QLF_ClosureEquivalence`](QLF_ClosureEquivalence.lean) are the abstraction of `closureToken`. - `binary_abstraction_forgets_colour`: the binary pos/neg projection is an abstraction of the eight-twist history that forgets colour; colour does not descend to it. - `octoid_balance_iff_zfa`: equal and opposite action on the eight-twist frame (zero net handedness on each of the four axes) is equivalent to the full runtime ZFA test, count balance *and* Pauli closure, because the second is entailed (`count_balanced_pauli_closed`). No axioms beyond Lean's and Mathlib's. -/ namespace QLF.Abstraction open Function QLF.RecordForgetting variable {H R V W : Type*} /-! ## 1. The abstraction a record induces -/ /-- Two histories are indistinguishable to the record `D` when `D` gives them the same value. This is Mathlib's kernel setoid; no physical law is needed to define it. -/ abbrev indistinguishable (D : H → R) : Setoid H := Setoid.ker D /-- The abstraction space `H/∼_D`. -/ abbrev AbstractionSpace (D : H → R) : Type _ := Quotient (indistinguishable D) /-- The abstraction of a history: its class under `D`. -/ def abstract (D : H → R) (h : H) : AbstractionSpace D := Quotient.mk _ h /-- **Two histories have one abstraction exactly when the record identifies them.** -/ theorem abstraction_iff (D : H → R) (x y : H) : abstract D x = abstract D y ↔ D x = D y := ⟨fun h => Quotient.exact h, fun h => Quotient.sound h⟩ /-- Every abstraction is the abstraction of some history. -/ theorem abstract_surjective (D : H → R) : Surjective (abstract D) := Quotient.mk_surjective /-- **The abstraction is the image.** The classes of `∼_D` correspond one to one with the values `D` actually takes: `H/∼_D ≃ im D`. The record does not identify the history, but it identifies its abstraction exactly. -/ noncomputable def abstractionEquivRange (D : H → R) : AbstractionSpace D ≃ Set.range D := Setoid.quotientKerEquivRange D theorem abstractionEquivRange_abstract (D : H → R) (h : H) : (abstractionEquivRange D (abstract D h) : R) = D h := rfl /-! ## 2. Loss leaves an abstraction -/ /-- **Lost information leaves an abstraction.** If `D` forgets the distinction between `x` and `y` (`Forgets`, [`QLF_RecordForgetting`](QLF_RecordForgetting.lean)), the two histories are distinct and share one abstraction. -/ theorem loss_leaves_abstraction (D : H → R) {x y : H} (h : Forgets D x y) : x ≠ y ∧ abstract D x = abstract D y := ⟨h.1, (abstraction_iff D x y).2 h.2⟩ /-- A class with two distinct members exists exactly when `D` forgets something, i.e. exactly when `D` is not injective. -/ theorem nontrivial_class_iff_forgets (D : H → R) : (∃ x y : H, x ≠ y ∧ abstract D x = abstract D y) ↔ ¬ Injective D := by rw [← forgets_iff_not_injective] constructor · rintro ⟨x, y, hne, he⟩ exact ⟨x, y, hne, (abstraction_iff D x y).1 he⟩ · rintro ⟨x, y, hne, he⟩ exact ⟨x, y, hne, (abstraction_iff D x y).2 he⟩ /-- An injective record forgets nothing: its abstraction map is injective, so every class is a single history. -/ theorem abstract_injective_iff (D : H → R) : Injective (abstract D) ↔ Injective D := by constructor · intro h x y hxy exact h ((abstraction_iff D x y).2 hxy) · intro h x y hxy exact h ((abstraction_iff D x y).1 hxy) /-! ## 3. Abstraction preserves exactly the invariant properties -/ /-- **A property survives the loss exactly when it is invariant under the forgotten distinctions.** `O` is a function of the abstraction iff `D x = D y → O x = O y`. -/ theorem invariant_descends_iff (D : H → R) (O : H → V) : (∃ Ō : AbstractionSpace D → V, ∀ h, O h = Ō (abstract D h)) ↔ ∀ x y, D x = D y → O x = O y := by constructor · rintro ⟨Ō, hŌ⟩ x y hxy rw [hŌ x, hŌ y, (abstraction_iff D x y).2 hxy] · intro hO exact ⟨Quotient.lift O hO, fun _ => rfl⟩ /-- The descended property is unique. -/ theorem descended_unique (D : H → R) (O : H → V) (Ō₁ Ō₂ : AbstractionSpace D → V) (h₁ : ∀ h, O h = Ō₁ (abstract D h)) (h₂ : ∀ h, O h = Ō₂ (abstract D h)) : Ō₁ = Ō₂ := by funext a obtain ⟨h, rfl⟩ := abstract_surjective D a rw [← h₁, ← h₂] /-- A property that does not descend separates two histories the record identifies. This is the contrapositive used for the negative instances in §6. -/ theorem not_descends_of_witness (D : H → R) (O : H → V) {x y : H} (hD : D x = D y) (hO : O x ≠ O y) : ¬ ∃ Ō : AbstractionSpace D → V, ∀ h, O h = Ō (abstract D h) := by rw [invariant_descends_iff] exact fun h => hO (h x y hD) /-! ## 4. Successive loss gives a hierarchy of abstractions -/ /-- **Later abstractions are coarser.** Whatever `D₁` identifies, `D₂ ∘ D₁` identifies. -/ theorem abstraction_refines (D₁ : H → R) (D₂ : R → V) : indistinguishable D₁ ≤ indistinguishable (D₂ ∘ D₁) := fun _ _ h => congrArg D₂ h /-- The coarsening map from the finer abstraction to the coarser one. -/ def coarsen (D₁ : H → R) (D₂ : R → V) : AbstractionSpace D₁ → AbstractionSpace (D₂ ∘ D₁) := Quotient.map' id (abstraction_refines D₁ D₂) theorem coarsen_abstract (D₁ : H → R) (D₂ : R → V) (h : H) : coarsen D₁ D₂ (abstract D₁ h) = abstract (D₂ ∘ D₁) h := rfl /-- Every coarser class is the image of a finer one. -/ theorem coarsen_surjective (D₁ : H → R) (D₂ : R → V) : Surjective (coarsen D₁ D₂) := by intro a obtain ⟨h, rfl⟩ := abstract_surjective (D₂ ∘ D₁) a exact ⟨abstract D₁ h, rfl⟩ /-- **The later step loses nothing new exactly when it is injective on what the earlier record kept.** Otherwise the hierarchy is strictly coarser at that step. -/ theorem coarsen_injective_iff (D₁ : H → R) (D₂ : R → V) : Injective (coarsen D₁ D₂) ↔ ∀ x y, D₂ (D₁ x) = D₂ (D₁ y) → D₁ x = D₁ y := by constructor · intro hinj x y hxy have : coarsen D₁ D₂ (abstract D₁ x) = coarsen D₁ D₂ (abstract D₁ y) := by rw [coarsen_abstract, coarsen_abstract] exact (abstraction_iff (D₂ ∘ D₁) x y).2 hxy exact (abstraction_iff D₁ x y).1 (hinj this) · intro h a b hab obtain ⟨x, rfl⟩ := abstract_surjective D₁ a obtain ⟨y, rfl⟩ := abstract_surjective D₁ b rw [coarsen_abstract, coarsen_abstract, abstraction_iff] at hab exact (abstraction_iff D₁ x y).2 (h x y hab) /-! ## 5. The chain rule, for any measure `record_partition` ([`QLF_RecordForgetting`](QLF_RecordForgetting.lean)) proves the split under the uniform measure. Here the measure is an arbitrary probability vector `p`. -/ section ChainRule variable [Fintype H] [Fintype R] [DecidableEq R] /-- Shannon entropy of a probability vector on a finite set, in nats. -/ noncomputable def entropy {α : Type*} [Fintype α] (p : α → ℝ) : ℝ := ∑ a, Real.negMulLog (p a) /-- The distribution of the record: `q b = Σ_{D h = b} p h`. -/ noncomputable def pushforward (D : H → R) (p : H → ℝ) (b : R) : ℝ := ∑ h ∈ Finset.univ.filter (fun h => D h = b), p h /-- The conditional entropy `H(X | D X) = Σ_b q_b · H(X | D X = b)`, with the conditional distribution `p h / q b` on the class `D h = b`. -/ noncomputable def condEntropy (D : H → R) (p : H → ℝ) : ℝ := ∑ b, pushforward D p b * ∑ h ∈ Finset.univ.filter (fun h => D h = b), Real.negMulLog (p h / pushforward D p b) omit [Fintype R] in private lemma le_pushforward (D : H → R) {p : H → ℝ} (hp : ∀ h, 0 ≤ p h) (h : H) : p h ≤ pushforward D p (D h) := by unfold pushforward exact Finset.single_le_sum (f := p) (fun i _ => hp i) (Finset.mem_filter.2 ⟨Finset.mem_univ h, rfl⟩) /-- One term of the conditional sum: `q · η(p/q) = η(p) + p log q`, where `η = negMulLog`. -/ private lemma term_split {p q : ℝ} (hp : 0 ≤ p) (hpq : p ≤ q) : q * Real.negMulLog (p / q) = Real.negMulLog p + p * Real.log q := by rcases eq_or_lt_of_le hp with h0 | hpos · subst h0; simp · have hq : 0 < q := lt_of_lt_of_le hpos hpq unfold Real.negMulLog rw [Real.log_div (ne_of_gt hpos) (ne_of_gt hq)] field_simp ring /-- **The chain rule for a deterministic record.** For any probability vector `p` on a finite set of histories, the information of the history splits into the information of its abstraction and the remaining uncertainty about which member of the class occurred: `H(X) = H(D X) + H(X | D X)`. Non-negativity of `p` is the only hypothesis used; normalization is not needed for the identity. -/ theorem chain_rule (D : H → R) (p : H → ℝ) (hp : ∀ h, 0 ≤ p h) : entropy p = entropy (pushforward D p) + condEntropy D p := by unfold entropy condEntropy -- expand each conditional term have hterm : ∀ b, pushforward D p b * ∑ h ∈ Finset.univ.filter (fun h => D h = b), Real.negMulLog (p h / pushforward D p b) = ∑ h ∈ Finset.univ.filter (fun h => D h = b), (Real.negMulLog (p h) + p h * Real.log (pushforward D p b)) := by intro b rw [Finset.mul_sum] apply Finset.sum_congr rfl intro h hh have hb : D h = b := (Finset.mem_filter.1 hh).2 have hle : p h ≤ pushforward D p b := hb ▸ le_pushforward D hp h exact term_split (hp h) hle simp only [hterm, Finset.sum_add_distrib] -- the `p log q` part sums to `Σ_b q_b log q_b` have hq : ∀ b, ∑ h ∈ Finset.univ.filter (fun h => D h = b), p h * Real.log (pushforward D p b) = - Real.negMulLog (pushforward D p b) := by intro b rw [← Finset.sum_mul] unfold Real.negMulLog pushforward ring simp only [hq, Finset.sum_neg_distrib] -- the `η(p)` part regroups fiberwise into `Σ_h η(p h)` rw [Finset.sum_fiberwise (Finset.univ) D (fun h => Real.negMulLog (p h))] ring /-- Conditional entropy is non-negative for a probability vector, so the abstraction never holds more information than the history: `H(D X) ≤ H(X)`. -/ theorem condEntropy_nonneg (D : H → R) (p : H → ℝ) (hp : ∀ h, 0 ≤ p h) : 0 ≤ condEntropy D p := by unfold condEntropy apply Finset.sum_nonneg intro b _ apply mul_nonneg (Finset.sum_nonneg (fun h _ => hp h)) apply Finset.sum_nonneg intro h hh have hb : D h = b := (Finset.mem_filter.1 hh).2 have hle : p h ≤ pushforward D p b := hb ▸ le_pushforward D hp h apply Real.negMulLog_nonneg (div_nonneg (hp h) (le_trans (hp h) hle)) rcases eq_or_lt_of_le (le_trans (hp h) hle) with h0 | hq · rw [← h0, div_zero]; exact zero_le_one · exact (div_le_one hq).2 hle theorem abstraction_entropy_le (D : H → R) (p : H → ℝ) (hp : ∀ h, 0 ≤ p h) : entropy (pushforward D p) ≤ entropy p := by rw [chain_rule D p hp] linarith [condEntropy_nonneg D p hp] end ChainRule /-! ## 6. QLF instances, derived from A01 -/ section Instances /-- The empty history prunes to itself. -/ theorem prune_nil : full_zeno_prune [] = [] := by rw [full_zeno_prune]; simp [zeno_prune] /-- **ZFA closure is an abstraction.** Take the ZFA filter `full_zeno_prune` as the record. A history achieves ZFA exactly when it has the abstraction of the empty history: the closed histories are one class. -/ theorem closed_iff_vacuum_class (s : TopoString) : achieves_ZFA s ↔ abstract full_zeno_prune s = abstract full_zeno_prune [] := by rw [abstraction_iff, prune_nil] constructor · intro h unfold achieves_ZFA at h cases hp : full_zeno_prune s with | nil => rfl | cons x xs => rw [hp] at h cases x <;> simp [is_gauge] at h · intro h unfold achieves_ZFA rw [h]; rfl private def pn : TopoString := [TopoElement.phase LogicPhase.pos, TopoElement.phase LogicPhase.neg] private def np : TopoString := [TopoElement.phase LogicPhase.neg, TopoElement.phase LogicPhase.pos] private lemma prune_pn : full_zeno_prune pn = [] := by rw [full_zeno_prune]; simp [pn, zeno_prune, prune_nil] private lemma prune_np : full_zeno_prune np = [] := by rw [full_zeno_prune]; simp [np, zeno_prune, prune_nil] /-- **Closure loses information, by A01's own filter.** `[+,−]` and `[−,+]` are distinct, both close, and closure cannot tell them apart: the class of closed histories is not a singleton. -/ theorem closure_forgets_route : Forgets full_zeno_prune pn np := ⟨by decide, by rw [prune_pn, prune_np]⟩ theorem closure_not_injective : ¬ Injective full_zeno_prune := (forgets_iff_not_injective _).1 ⟨pn, np, closure_forgets_route⟩ /-- **The ledger survives closure.** The net count `count_pos − count_neg` descends to the abstraction that the ZFA filter induces (`full_prune_invariant`). With `closure_forgets_route` this is C06, *closure conserves the ledger and erases the route*, read as an abstraction theorem: the ledger is the invariant that the abstraction keeps. -/ theorem ledger_survives_closure : ∃ L : AbstractionSpace full_zeno_prune → Int, ∀ s, count_pos s - count_neg s = L (abstract full_zeno_prune s) := by rw [invariant_descends_iff] intro x y hxy rw [← full_prune_invariant x, ← full_prune_invariant y, hxy] /-- The closure classes of [`QLF_ClosureEquivalence`](QLF_ClosureEquivalence.lean) are the abstraction of the closure token `(ledger, fold)`. -/ theorem closureSetoid_is_abstraction : QLF.ClosureEquivalence.closureSetoid = indistinguishable QLF.ClosureEquivalence.closureToken := Setoid.ext (fun _ _ => Iff.rfl) /-- The binary pos/neg projection of an eight-twist history. -/ def binaryProjection (ts : List QLF.Twist) : TopoString := ts.map QLF.ColourClosure.topoOf /-- **The binary projection is an abstraction that forgets colour.** `>\` and `><` have the same binary projection `[+,−]`, but carry different colour totals, so colour does not descend to the binary abstraction. The eight-twist balance, not the binary one, is what prunes colour (`binary_projection_blind`). -/ theorem binary_abstraction_forgets_colour : ¬ ∃ C : AbstractionSpace binaryProjection → QLF.ColourFlux.V, ∀ ts, QLF.ColourClosure.colourTotal ts = C (abstract binaryProjection ts) := by apply not_descends_of_witness binaryProjection QLF.ColourClosure.colourTotal (x := [QLF.Twist.right, QLF.Twist.backslash]) (y := [QLF.Twist.right, QLF.Twist.left]) · rfl · decide /-- **Equal and opposite action on the eight-twist frame is ZFA.** Zero net handedness on each of the four axes is equivalent to the full runtime test, count balance *and* Pauli closure: the second conjunct is entailed by the first (`count_balanced_pauli_closed`). The converse direction of Pauli closure alone fails (`unbalanced_can_be_imaginary`), so the eight-twist balance is the content. -/ theorem octoid_balance_iff_zfa (ts : List QLF.Twist) : (∀ a : QLF.Axis, QLF.handednessOn a ts = 0) ↔ (QLF.countBalanced ts ∧ ∃ p : QLF.PauliScalar, QLF.twistMatrixFold ts = QLF.pauliScalarToMatrix p) := by rw [← QLF.zfa_iff_handedness_balanced] exact ⟨fun h => ⟨h, QLF.count_balanced_pauli_closed h⟩, fun h => h.1⟩ end Instances end QLF.Abstraction