diff --git a/CHANGELOG.md b/CHANGELOG.md index c67d98b..80b8edd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,21 @@ cross-version compatibility promise. Changes on `develop` after v0.4.0; the next release version is undecided. +- Identify the diagram of the executed Rips simplex list with the Rips diagram: + for a valid `DistanceTable`, `outputDiagram_ripsInput` states that + `FiniteInput.outputDiagram` of the list, with integer grades read as real + numbers, is `dgm (ZMod 2)` of `Rips.filter` for the table metric in every + degree. `ripsLabelMap` induces an isomorphism from the homology of the Rips + complexes to the sublevel homology of the list, `ripsRunInDegree` returns the + records of one degree and `none` for an invalid table in every degree, and + relabelled tables have equal diagrams. The new module + `TDA.Persistence.SublevelDiagramVertexMap` proves `dgm_eq_of_vertexMaps`, the + invariance of real sublevel diagrams under mutually inverse vertex maps + between complexes on two vertex types. The four-cycle is a kernel-checked + fixture with one class of degree one from `1` to `2`. The cost of the + existing reduction remains unbounded. See + [Diagram and homology of the Rips input](docs/math/finite-ph-computation.md#diagram-and-homology-of-the-rips-input). + - Execute the complete Rips simplex list of an integer distance table in the `FiniteInput` format: `DistanceTable`, its decidable `Valid`, `ripsInput`, `ripsInput?` and `ripsRun`, which return `none` for an invalid table. The diff --git a/TDA/Persistence.lean b/TDA/Persistence.lean index 3450432..b07e1d0 100644 --- a/TDA/Persistence.lean +++ b/TDA/Persistence.lean @@ -439,3 +439,5 @@ import TDA.Persistence.Reduction.FiniteInputHomologyDimensions import TDA.Persistence.Reduction.FiniteInputHomologyDimensionsCorrectness import TDA.Persistence.Reduction.FiniteInputHomologyDimensionsExamples import TDA.Persistence.Reduction.RipsInput +import TDA.Persistence.SublevelDiagramVertexMap +import TDA.Persistence.Reduction.RipsInputDiagram diff --git a/TDA/Persistence/Examples.lean b/TDA/Persistence/Examples.lean index ae5b4e6..076ea0f 100644 --- a/TDA/Persistence/Examples.lean +++ b/TDA/Persistence/Examples.lean @@ -219,3 +219,4 @@ import TDA.Persistence.BoundaryTransportGeometry import TDA.Persistence.BoundaryTransportReverseExamples import TDA.Persistence.BoundaryTransportReverse import TDA.Persistence.Reduction.RipsInputExamples +import TDA.Persistence.Reduction.RipsInputDiagramExamples diff --git a/TDA/Persistence/Reduction/RipsInputDiagram.lean b/TDA/Persistence/Reduction/RipsInputDiagram.lean new file mode 100644 index 0000000..3579e6e --- /dev/null +++ b/TDA/Persistence/Reduction/RipsInputDiagram.lean @@ -0,0 +1,316 @@ +import TDA.Persistence.Reduction.RipsInput +import TDA.Persistence.SublevelDiagramVertexMap +import TDA.Persistence.DiagramMap +import TDA.Persistence.RipsGromovHausdorff +import TDA.Persistence.FiniteFilterStability + +/-! +# The diagram of the executed Rips simplex list + +For a valid `DistanceTable`, the list `ripsInput` of +`TDA.Persistence.Reduction.RipsInput` presents the Rips filtration of the table metric with +the labels `0, …, N - 1` placed in `ℕ` and integer grades. This module compares the executed +list with the Rips filtration of `Rips.filter (D.metric hD)` on `Rips.fullComplex (Fin N)`, +in homology and in the diagrams. + +* `intCastOrderEmbedding`: the inclusion of the integers in the real numbers as an order + embedding, along which `Diagram.map` reads integer grades as real numbers. +* `mem_sublevel_gradeFilter_ripsInput`, `mem_sublevel_rips_filter`: the faces of the executed + list at an integer threshold, and of the Rips filtration at a real threshold, are the + nonempty sets of labels of integer diameter at most the threshold. +* `outputDiagram_ripsInput`: `FiniteInput.outputDiagram` of the executed list, mapped along + `intCastOrderEmbedding`, is `dgm (ZMod 2) (Rips.filter (D.metric hD))` in every degree. +* `ripsLabelMap`: the inclusion of the labels as a vertex map from the Rips complex at an + integer threshold to the sublevel complex of the executed list. It induces an isomorphism + in homology in every degree and over every ring + (`simplicialHomologyMap_ripsLabelMap_isIso`), compatible with raising the threshold + (`simplicialHomologyMap_ripsLabelMap_naturality`). +* `ripsRunInDegree`: the occurrence records of one degree of `ripsRun`; `none` for an invalid + table in every degree, also where a valid table would have no record. + `ripsRunInDegree_correct` reads a returned list as the points of the Rips diagram. +* `valid_of_relabel`, `outputDiagram_ripsInput_of_relabel`: a permutation of the labels of a + valid table gives a valid table with the same diagram of the executed list. + +## Statements + +`outputDiagram_ripsInput` composes `FiniteInput.outputDiagram_eq_dgm`, `dgm_map` and +`dgm_eq_of_vertexMaps`, with `Fin.val` in one direction and, for a nonempty set of labels, a +left inverse `ℕ → Fin N` in the other; a table without labels has no face on either side. +Multiplicities, the deletion of pairs of equal grades, essential classes and unaugmented +degree zero are those of `FiniteInput.outputDiagram_eq_dgm`. The comparison is with the Rips +filtration of the metric built from the table: the caller supplies no metric, isomorphism or +certificate. + +The homology comparison is stated at integer thresholds. All values of both filters are +integers, so the Rips complex at a real threshold is the one at its floor; the diagram +equality covers every pair of real thresholds. + +`ripsRunInDegree p` is `none` exactly when the table is invalid, whatever `p`. +`ripsRunInDegree_correct` compares multisets; the order of the records is that of the +existing reduction and is not part of the comparison. The relabelling statement is an +equality of diagrams, not of lists, and reuses `Rips.dgm_eq_of_isometryEquiv`. + +## Cost + +`ripsRunInDegree` costs `ripsRun` and one comparison of natural numbers for each record; there +are at most `2 ^ N - 1` records. The cost of the existing reduction is not bounded here. The +semantic statements use the noncomputable homology API. + +These are elementary library results, not attributed to a source. See +`docs/math/finite-ph-computation.md`. +-/ + +set_option autoImplicit false + +namespace TDA.Persistence + +/-- The inclusion of the integers in the real numbers, as an order embedding. -/ +def intCastOrderEmbedding : ℤ ↪o ℝ := OrderEmbedding.ofStrictMono (↑) Int.cast_strictMono + +@[simp] theorem intCastOrderEmbedding_apply (a : ℤ) : intCastOrderEmbedding a = (a : ℝ) := rfl + +private theorem Diagram.map_injective {α β : Type*} [LinearOrder α] [LinearOrder β] + (φ : α ↪o β) {d e : Diagram α} (h : d.map φ = e.map φ) : d = e := by + apply Diagram.ext + have hp := congrArg Diagram.points h + rw [Diagram.map_points, Diagram.map_points] at hp + exact Multiset.map_injective + (Function.Injective.prodMap φ.injective (WithTop.map_injective φ.injective)) hp + +end TDA.Persistence + +namespace TDA.Persistence.Reduction + +open TDA.Simplicial TDA.Filtration TDA.Persistence CategoryTheory + +namespace DistanceTable + +variable {N : ℕ} (D : DistanceTable N) + +/-! ## Sublevel complexes -/ + +/-- The faces of the Rips filtration of the table metric at a real threshold. -/ +theorem mem_sublevel_rips_filter (hD : D.Valid) {r : ℝ} {s : Finset (Fin N)} : + s ∈ (Rips.filter (D.metric hD)).sublevel r ↔ s.Nonempty ∧ (D.diameter s : ℝ) ≤ r := by + rw [FilterFunction.mem_sublevel_iff] + constructor + · rintro ⟨hs, hle⟩ + exact ⟨hs, by rw [D.cast_diameter hD]; exact hle⟩ + · rintro ⟨hs, hle⟩ + exact ⟨hs, by rw [Rips.filter_value, ← D.cast_diameter hD]; exact hle⟩ + +private theorem mem_sublevel_map_gradeFilter {r : ℝ} {t : Finset ℕ} : + t ∈ ((FiniteInput.gradeFilter D.ripsInput D.ripsInput_valid).map + intCastOrderEmbedding).sublevel r ↔ + ∃ s : Finset (Fin N), s.Nonempty ∧ (D.diameter s : ℝ) ≤ r ∧ + t = s.map Fin.valEmbedding := by + rw [FilterFunction.mem_sublevel_iff] + constructor + · rintro ⟨ht, hle⟩ + obtain ⟨s, hs, rfl⟩ := D.mem_complex_ripsInput.1 ht + refine ⟨s, hs, ?_, rfl⟩ + rw [← D.gradeFilter_ripsFace_eq_diameter ⟨s, hs⟩] + exact hle + · rintro ⟨s, hs, hle, rfl⟩ + refine ⟨(D.ripsFace ⟨s, hs⟩).2, ?_⟩ + rw [← D.gradeFilter_ripsFace_eq_diameter ⟨s, hs⟩] at hle + exact hle + +/-- The faces of the executed list at an integer threshold: the sets of labels of integer +diameter at most the threshold. -/ +theorem mem_sublevel_gradeFilter_ripsInput {a : ℤ} {t : Finset ℕ} : + t ∈ (FiniteInput.gradeFilter D.ripsInput D.ripsInput_valid).sublevel a ↔ + ∃ s : Finset (Fin N), s.Nonempty ∧ D.diameter s ≤ a ∧ t = s.map Fin.valEmbedding := by + rw [← FilterFunction.map_sublevel_apply _ intCastOrderEmbedding a, mem_sublevel_map_gradeFilter] + simp only [intCastOrderEmbedding_apply, Int.cast_le] + +/-- A left inverse of the inclusion of the labels, for a nonempty set of labels. -/ +private def clamp (hN : 0 < N) (n : ℕ) : Fin N := if h : n < N then ⟨n, h⟩ else ⟨0, hN⟩ + +private theorem clamp_val (hN : 0 < N) (i : Fin N) : clamp hN i.val = i := by + simp [clamp] + +private theorem image_clamp (hN : 0 < N) (s : Finset (Fin N)) : + (s.map Fin.valEmbedding).image (clamp hN) = s := by + ext i + simp only [Finset.mem_image, Finset.mem_map, Fin.valEmbedding_apply] + constructor + · rintro ⟨_, ⟨j, hj, rfl⟩, rfl⟩ + rwa [clamp_val] + · intro hi + exact ⟨i.val, ⟨i, hi, rfl⟩, clamp_val hN i⟩ + +/-! ## The diagram -/ + +/-- The diagram of the executed list, with grades read as real numbers, is the F₂ diagram of +the Rips filtration of the table metric, in every degree. -/ +theorem outputDiagram_ripsInput (hD : D.Valid) (p : ℕ) : + (FiniteInput.outputDiagram D.ripsInput p).map intCastOrderEmbedding = + dgm (ZMod 2) (Rips.filter (D.metric hD)) p := by + let _ := FiniteInput.faceFintype D.ripsInput D.ripsInput_valid + rw [FiniteInput.outputDiagram_eq_dgm D.ripsInput D.ripsInput_valid p, ← dgm_map] + rcases Nat.eq_zero_or_pos N with rfl | hN + · have : IsEmpty (TotalFace (Rips.fullComplex (Fin 0))) := + ⟨fun s => by obtain ⟨i, -⟩ := s.2; exact i.elim0⟩ + have : IsEmpty (TotalFace (FiniteInput.complex D.ripsInput D.ripsInput_valid)) := + ⟨fun t => by obtain ⟨s, -⟩ := D.ripsFace_bijective.2 t; exact isEmptyElim s⟩ + apply Diagram.ext + rw [dgm_empty_faces, dgm_empty_faces] + · refine dgm_eq_of_vertexMaps (ZMod 2) _ _ (clamp hN) Fin.val ?_ ?_ ?_ ?_ p + · intro r t ht + obtain ⟨s, hs, hle, rfl⟩ := D.mem_sublevel_map_gradeFilter.1 ht + rw [image_clamp] + exact (D.mem_sublevel_rips_filter hD).2 ⟨hs, hle⟩ + · intro r s hs + obtain ⟨hne, hle⟩ := (D.mem_sublevel_rips_filter hD).1 hs + exact D.mem_sublevel_map_gradeFilter.2 + ⟨s, hne, hle, (Finset.map_eq_image Fin.valEmbedding s).symm⟩ + · intro t ht v hv + obtain ⟨s, -, rfl⟩ := D.mem_complex_ripsInput.1 ht + obtain ⟨i, -, rfl⟩ := Finset.mem_map.1 hv + exact congrArg Fin.val (clamp_val hN i) + · intro s _ i _ + exact clamp_val hN i + +/-! ## Sublevel homology -/ + +/-- The inclusion of the labels, as a vertex map from the Rips complex of the table metric at +an integer threshold to the sublevel complex of the executed list. -/ +def ripsLabelMap (hD : D.Valid) (a : ℤ) : + VertexMap ((Rips.filter (D.metric hD)).sublevel (a : ℝ)) + ((FiniteInput.gradeFilter D.ripsInput D.ripsInput_valid).sublevel a) where + toFun := Fin.val + map_face s hs := by + obtain ⟨hne, hle⟩ := (D.mem_sublevel_rips_filter hD).1 hs + have hi : s.image Fin.val = s.map Fin.valEmbedding := + (Finset.map_eq_image Fin.valEmbedding s).symm + have h := D.mem_sublevel_gradeFilter_ripsInput.2 ⟨s, hne, Int.cast_le.1 hle, hi⟩ + convert h + +@[simp] theorem ripsLabelMap_apply (hD : D.Valid) (a : ℤ) (i : Fin N) : + D.ripsLabelMap hD a i = i.val := rfl + +private def clampMap (hD : D.Valid) (hN : 0 < N) (a : ℤ) : + VertexMap ((FiniteInput.gradeFilter D.ripsInput D.ripsInput_valid).sublevel a) + ((Rips.filter (D.metric hD)).sublevel (a : ℝ)) where + toFun := clamp hN + map_face t ht := by + obtain ⟨s, hs, hle, rfl⟩ := D.mem_sublevel_gradeFilter_ripsInput.1 ht + have h := (D.mem_sublevel_rips_filter hD).2 ⟨hs, Int.cast_le.2 hle⟩ + rw [← image_clamp hN s] at h + convert h + +/-- The inclusion of the labels induces an isomorphism from the homology of the Rips complex +of the table metric at an integer threshold to the sublevel homology of the executed list, +in every degree and over every ring. -/ +theorem simplicialHomologyMap_ripsLabelMap_isIso (R : Type*) [Ring R] (hD : D.Valid) (a : ℤ) + (n : ℕ) : IsIso (simplicialHomologyMap R (D.ripsLabelMap hD a) n) := by + rcases Nat.eq_zero_or_pos N with rfl | hN + · have hX : Limits.IsZero + (simplicialHomology ((Rips.filter (D.metric hD)).sublevel (a : ℝ)) R n) := by + have hbot : (Rips.filter (D.metric hD)).sublevel (a : ℝ) = ⊥ := + le_antisymm (fun s hs => by + obtain ⟨⟨i, -⟩, -⟩ := (D.mem_sublevel_rips_filter hD).1 hs + exact i.elim0) bot_le + rw [hbot] + exact isZero_simplicialHomology_bot R n + have hY : Limits.IsZero (simplicialHomology + ((FiniteInput.gradeFilter D.ripsInput D.ripsInput_valid).sublevel a) R n) := by + have hbot : (FiniteInput.gradeFilter D.ripsInput D.ripsInput_valid).sublevel a = ⊥ := + le_antisymm (fun t ht => by + obtain ⟨s, ⟨i, -⟩, -⟩ := D.mem_sublevel_gradeFilter_ripsInput.1 ht + exact i.elim0) bot_le + rw [hbot] + exact isZero_simplicialHomology_bot R n + exact ⟨⟨0, hX.eq_of_src _ _, hY.eq_of_src _ _⟩⟩ + · refine ⟨⟨simplicialHomologyMap R (D.clampMap hD hN a) n, ?_, ?_⟩⟩ + · exact simplicialHomologyMap_comp_eq_id R _ _ (fun s _ i _ => clamp_val hN i) n + · refine simplicialHomologyMap_comp_eq_id R _ _ (fun t ht v hv => ?_) n + obtain ⟨s, -, -, rfl⟩ := D.mem_sublevel_gradeFilter_ripsInput.1 ht + obtain ⟨i, -, rfl⟩ := Finset.mem_map.1 hv + exact congrArg Fin.val (clamp_val hN i) + +/-- The isomorphisms of `simplicialHomologyMap_ripsLabelMap_isIso` commute with the maps +induced by raising the threshold. -/ +theorem simplicialHomologyMap_ripsLabelMap_naturality (R : Type*) [Ring R] (hD : D.Valid) + {a b : ℤ} (hab : a ≤ b) (n : ℕ) : + simplicialHomologyIncl R + ((Rips.filter (D.metric hD)).sublevel_mono (Int.cast_le.2 hab)) n ≫ + simplicialHomologyMap R (D.ripsLabelMap hD b) n = + simplicialHomologyMap R (D.ripsLabelMap hD a) n ≫ + simplicialHomologyIncl R + ((FiniteInput.gradeFilter D.ripsInput D.ripsInput_valid).sublevel_mono hab) n := by + rw [← simplicialHomologyMap_inclusion, ← simplicialHomologyMap_inclusion, + ← simplicialHomologyMap_comp, ← simplicialHomologyMap_comp] + rfl + +/-! ## The records of one degree -/ + +/-- The occurrence records of degree `p` in the run of a valid table; `none` for an invalid +table, in every degree. -/ +def ripsRunInDegree (p : ℕ) : Option (List FiniteInput.Occurrence) := + D.ripsRun.map (List.filter fun o => o.degree = p) + +theorem ripsRunInDegree_eq_some_iff {p : ℕ} {out : List FiniteInput.Occurrence} : + D.ripsRunInDegree p = some out ↔ + D.Valid ∧ out = (FiniteInput.occurrences D.ripsInput).filter fun o => o.degree = p := by + unfold ripsRunInDegree ripsRun + by_cases h : D.Valid <;> simp [h, eq_comm] + +theorem ripsRunInDegree_eq_none_iff {p : ℕ} : D.ripsRunInDegree p = none ↔ ¬ D.Valid := by + unfold ripsRunInDegree + rw [Option.map_eq_none_iff, ripsRun_eq_none_iff] + +/-- A returned list of records of degree `p` certifies the table and lists, with +multiplicity, the points of the F₂ diagram of the Rips filtration of the table metric in +degree `p`. -/ +theorem ripsRunInDegree_correct {p : ℕ} {out : List FiniteInput.Occurrence} + (h : D.ripsRunInDegree p = some out) : + ∃ hD : D.Valid, (dgm (ZMod 2) (Rips.filter (D.metric hD)) p).points = + ((out : Multiset FiniteInput.Occurrence).map FiniteInput.Occurrence.point).map + fun q => ((q.1 : ℝ), WithTop.map (Int.cast : ℤ → ℝ) q.2) := by + obtain ⟨hD, rfl⟩ := D.ripsRunInDegree_eq_some_iff.1 h + refine ⟨hD, ?_⟩ + rw [← D.outputDiagram_ripsInput hD p, Diagram.map_points] + rfl + +/-! ## Relabelling -/ + +/-- A table obtained from a valid table by a permutation of the labels is valid. -/ +theorem valid_of_relabel {D E : DistanceTable N} (σ : Equiv.Perm (Fin N)) + (h : ∀ i j, E.dist i j = D.dist (σ i) (σ j)) (hD : D.Valid) : E.Valid := by + refine ⟨fun i j => ?_, fun i j => ?_, fun i => ?_, fun i j hij => ?_, fun i j k => ?_⟩ + · rw [h] + exact hD.1 _ _ + · rw [h, h] + exact hD.2.1 _ _ + · rw [h] + exact hD.2.2.1 _ + · rw [h] + exact hD.2.2.2.1 _ _ (σ.injective.ne hij) + · rw [h, h, h] + exact hD.2.2.2.2 _ _ _ + +/-- Relabelling a valid table does not change the diagram of the executed list, in any +degree. -/ +theorem outputDiagram_ripsInput_of_relabel {D E : DistanceTable N} (σ : Equiv.Perm (Fin N)) + (h : ∀ i j, E.dist i j = D.dist (σ i) (σ j)) (hD : D.Valid) (p : ℕ) : + FiniteInput.outputDiagram E.ripsInput p = FiniteInput.outputDiagram D.ripsInput p := by + have hE := valid_of_relabel σ h hD + apply Diagram.map_injective intCastOrderEmbedding + rw [E.outputDiagram_ripsInput hE p, D.outputDiagram_ripsInput hD p] + let e : @IsometryEquiv (Fin N) (Fin N) + (E.metric hE).toPseudoMetricSpace.toPseudoEMetricSpace + (D.metric hD).toPseudoMetricSpace.toPseudoEMetricSpace := + @IsometryEquiv.mk (Fin N) (Fin N) (E.metric hE).toPseudoMetricSpace.toPseudoEMetricSpace + (D.metric hD).toPseudoMetricSpace.toPseudoEMetricSpace σ + (@Isometry.of_dist_eq (Fin N) (Fin N) (E.metric hE).toPseudoMetricSpace + (D.metric hD).toPseudoMetricSpace σ fun i j => by + change ((D.dist (σ i) (σ j) : ℤ) : ℝ) = ((E.dist i j : ℤ) : ℝ) + rw [h]) + exact @Rips.dgm_eq_of_isometryEquiv (Fin N) (Fin N) _ _ _ _ (E.metric hE) (D.metric hD) + (ZMod 2) _ e p + +end DistanceTable + +end TDA.Persistence.Reduction diff --git a/TDA/Persistence/Reduction/RipsInputDiagramExamples.lean b/TDA/Persistence/Reduction/RipsInputDiagramExamples.lean new file mode 100644 index 0000000..c50658c --- /dev/null +++ b/TDA/Persistence/Reduction/RipsInputDiagramExamples.lean @@ -0,0 +1,315 @@ +import TDA.Persistence.Reduction.RipsInputDiagram +import TDA.Persistence.Reduction.RipsInputExamples +import TDA.Persistence.SublevelDiagramMonotone + +/-! +# Diagrams of executed Rips simplex lists + +The tables are those of `TDA.Persistence.Reduction.RipsInputExamples`. + +* `empty`, `single`, `pair`: the records of each degree and the Rips diagram in degree zero. + A valid table has the empty list of records in a degree without classes. +* `fourCycle`: the kernel-checked reduction of the fifteen faces. One class of degree one is + born at `1` and dies at `2`; three classes of degree zero die at `1` and one is essential; + the pairs of equal grade `2` leave no record. The Rips diagram of the table metric in degree + one is the single point `(1, 2)`, the Rips complex at threshold `1` has one-dimensional + first homology over `ZMod 2` and the complex at threshold `2` has none, and the first + homology of the listed complex at threshold `1` is one-dimensional as well. +* `oneWay`, `merged`, `shortcut`, `loop`, `negative`: `none` in every degree. +* `line`, `relabelled`: equal diagrams of the executed lists in every degree. + +The boundary matrix of the four-cycle is evaluated through `faceIncidence`, which the kernel +reduces, in place of `FiniteInput.boundary`. +-/ + +set_option autoImplicit false + +namespace TDA.Persistence.Reduction.RipsInputDiagramExamples + +open DistanceTable FiniteInput RipsInputExamples TDA.Simplicial TDA.Filtration TDA.Persistence +open CategoryTheory + +/-! ## Small tables -/ + +theorem empty_valid : empty.Valid := by decide +kernel + +theorem empty_ripsRunInDegree (p : ℕ) : empty.ripsRunInDegree p = some [] := by + rw [ripsRunInDegree, empty_ripsRun] + rfl + +/-- The Rips diagram of the empty metric space has no point, in any degree. -/ +theorem empty_dgm (p : ℕ) : + (dgm (ZMod 2) (Rips.filter (empty.metric empty_valid)) p).points = 0 := by + obtain ⟨_, h⟩ := empty.ripsRunInDegree_correct (empty_ripsRunInDegree p) + rw [h] + rfl + +theorem single_valid : single.Valid := by decide +kernel + +theorem single_ripsRunInDegree_zero : + single.ripsRunInDegree 0 = some [⟨0, 0, .essential⟩] := by + rw [ripsRunInDegree, single_ripsRun] + rfl + +/-- One point: one essential class of degree zero, not reduced. -/ +theorem single_dgm_zero : + (dgm (ZMod 2) (Rips.filter (single.metric single_valid)) 0).points = + {((0 : ℝ), (⊤ : WithTop ℝ))} := by + obtain ⟨_, h⟩ := single.ripsRunInDegree_correct single_ripsRunInDegree_zero + rw [h] + simp [Occurrence.point] + +theorem pair_ripsRunInDegree_zero : + pair.ripsRunInDegree 0 = some [⟨0, 0, .finite 3⟩, ⟨0, 0, .essential⟩] := by + rw [ripsRunInDegree, pair_ripsRun] + rfl + +/-- A valid table has the empty list of records in a degree without classes. -/ +theorem pair_ripsRunInDegree_one : pair.ripsRunInDegree 1 = some [] := by + rw [ripsRunInDegree, pair_ripsRun] + rfl + +/-- Two points at distance `3`: one class dies at `3` and one is essential. -/ +theorem pair_dgm_zero : + (dgm (ZMod 2) (Rips.filter (pair.metric pair_valid)) 0).points = + {((0 : ℝ), ((3 : ℝ) : WithTop ℝ)), ((0 : ℝ), (⊤ : WithTop ℝ))} := by + obtain ⟨_, h⟩ := pair.ripsRunInDegree_correct pair_ripsRunInDegree_zero + rw [h] + simp only [Occurrence.point, Multiset.map_coe, List.map_cons, WithTop.coe_ofNat, + List.map_nil, Int.cast_zero, WithTop.map_ofNat, Int.cast_ofNat, WithTop.map_top, + Multiset.insert_eq_cons] + rfl + +/-! ## The four-cycle -/ + +/-- The indicator of the codimension-one faces among the listed faces. -/ +private def faceIncidence (xs : Input) : Matrix (Fin xs.length) (Fin xs.length) (ZMod 2) := + fun i j => + if (xs.get j).1.card = (xs.get i).1.card - 1 + 2 ∧ (xs.get i).1 ⊆ (xs.get j).1 ∧ + (xs.get i).1.Nonempty then 1 else 0 + +/-- Over `ZMod 2` the boundary matrix is the indicator of the codimension-one faces. -/ +private theorem boundary_eq_faceIncidence (xs : Input) : boundary xs = faceIncidence xs := by + funext i j + unfold FiniteInput.boundary faceIncidence + generalize (xs.get i).1 = s + generalize (xs.get j).1 = t + have hone : ∀ a : ℕ, (-1 : ZMod 2) ^ a = 1 := fun a => by + rw [show (-1 : ZMod 2) = 1 from by decide, one_pow] + by_cases hc : t.card = s.card - 1 + 2 + · simp only [hc, ↓reduceDIte, true_and, hone] + by_cases hs : s ⊆ t ∧ s.Nonempty + · simp only [hs, and_self, ↓reduceIte] + obtain ⟨hst, hne⟩ := hs + have hcard : (t \ s).card = 1 := by + rw [Finset.card_sdiff_of_subset hst] + have := hne.card_pos + omega + obtain ⟨v, hv⟩ := Finset.card_eq_one.1 hcard + have hmem : ∀ x, x ∈ t ∧ x ∉ s ↔ x = v := fun x => by + rw [← Finset.mem_sdiff, hv, Finset.mem_singleton] + obtain ⟨a₀, ha₀⟩ : v ∈ Set.range (t.orderEmbOfFin hc) := by + rw [Finset.range_orderEmbOfFin] + exact ((hmem v).2 rfl).1 + have hiff : ∀ a, t.erase (t.orderEmbOfFin hc a) = s ↔ a = a₀ := by + intro a + constructor + · intro he + apply (t.orderEmbOfFin hc).injective + rw [ha₀] + exact (hmem _).1 ⟨Finset.orderEmbOfFin_mem t hc a, fun h => + Finset.notMem_erase _ _ ((Finset.ext_iff.1 he _).2 h)⟩ + · rintro rfl + rw [ha₀] + ext x + rw [Finset.mem_erase] + constructor + · rintro ⟨hx, hxt⟩ + by_contra hxs + exact hx ((hmem x).1 ⟨hxt, hxs⟩) + · intro hxs + exact ⟨fun hx => ((hmem x).2 hx).2 hxs, hst hxs⟩ + simp only [hiff, Finset.sum_ite_eq', Finset.mem_univ, ↓reduceIte] + · simp only [hs, ↓reduceIte] + apply Finset.sum_eq_zero + intro a _ + have hne : t.erase (t.orderEmbOfFin hc a) ≠ s := by + intro he + apply hs + refine ⟨he ▸ Finset.erase_subset _ _, ?_⟩ + rw [← Finset.card_pos, ← he, + Finset.card_erase_of_mem (Finset.orderEmbOfFin_mem t hc a)] + omega + simp only [hne, ↓reduceIte] + · simp only [hc, ↓reduceDIte, false_and, ↓reduceIte] + +/-- The simplex list of `fourCycle`. -/ +def fourCycleInput : Input := + [({0}, 0), ({1}, 0), ({2}, 0), ({3}, 0), + ({0, 1}, 1), ({0, 3}, 1), ({1, 2}, 1), ({2, 3}, 1), + ({0, 2}, 2), ({1, 3}, 2), + ({0, 1, 2}, 2), ({0, 1, 3}, 2), ({0, 2, 3}, 2), ({1, 2, 3}, 2), + ({0, 1, 2, 3}, 2)] + +theorem fourCycle_ripsInput_eq : fourCycle.ripsInput = fourCycleInput := + ((ripsInput?_eq_some_iff _).1 fourCycle_ripsInput).2.symm + +/-- The matrix over `ZMod 2` on the fifteen faces with the given rows of nonzero entries in +each column. -/ +def columnMatrix (cols : List (List ℕ)) : + Matrix (Fin fourCycleInput.length) (Fin fourCycleInput.length) (ZMod 2) := fun r c => + if r.val ∈ cols.getD c.val [] then 1 else 0 + +/-- The boundary matrix: each edge has its two vertices, each triangle its three edges and +the tetrahedron its four triangles. -/ +def fourCycleBoundary : Matrix (Fin fourCycleInput.length) (Fin fourCycleInput.length) (ZMod 2) := + columnMatrix [[], [], [], [], [0, 1], [0, 3], [1, 2], [2, 3], [0, 2], [1, 3], + [4, 6, 8], [4, 5, 9], [5, 7, 8], [6, 7, 9], [10, 11, 12, 13]] + +/-- The reduced matrix: the columns of the fourth edge, of both diagonals and of the last +triangle are zero. -/ +def fourCycleReduced : Matrix (Fin fourCycleInput.length) (Fin fourCycleInput.length) (ZMod 2) := + columnMatrix [[], [], [], [], [0, 1], [0, 3], [1, 2], [], [], [], + [4, 6, 8], [4, 5, 9], [4, 5, 6, 7], [], [10, 11, 12, 13]] + +theorem fourCycle_boundary : boundary fourCycleInput = fourCycleBoundary := by + rw [boundary_eq_faceIncidence] + decide +kernel + +/-- The existing reducer, run by the kernel on the fifteen faces. -/ +theorem fourCycle_reduced : reduced fourCycleInput = fourCycleReduced := by + simp only [reduced, trace] + rw [fourCycle_boundary] + decide +kernel + +theorem fourCycle_pivotPairs : pivotPairs fourCycleInput = + [(⟨1, by decide⟩, ⟨4, by decide⟩), (⟨3, by decide⟩, ⟨5, by decide⟩), + (⟨2, by decide⟩, ⟨6, by decide⟩), (⟨8, by decide⟩, ⟨10, by decide⟩), + (⟨9, by decide⟩, ⟨11, by decide⟩), (⟨7, by decide⟩, ⟨12, by decide⟩), + (⟨13, by decide⟩, ⟨14, by decide⟩)] := by + simp only [pivotPairs] + rw [fourCycle_reduced] + decide +kernel + +theorem fourCycle_essentialIndices : essentialIndices fourCycleInput = [⟨0, by decide⟩] := by + simp only [essentialIndices] + rw [fourCycle_reduced, fourCycle_pivotPairs] + decide +kernel + +/-- The records of the four-cycle: three classes of degree zero die at `1`, one class of +degree one is born at `1` and dies at `2`, and one class of degree zero is essential. The +three pairs of equal grade `2` leave no record. -/ +theorem fourCycle_ripsRun : fourCycle.ripsRun = some + [⟨0, 0, .finite 1⟩, ⟨0, 0, .finite 1⟩, ⟨0, 0, .finite 1⟩, ⟨1, 1, .finite 2⟩, + ⟨0, 0, .essential⟩] := by + rw [ripsRun_eq_some_iff, fourCycle_ripsInput_eq] + refine ⟨fourCycle_valid, ?_⟩ + simp only [occurrences, finiteOccurrences, essentialOccurrences, fourCycle_pivotPairs, + fourCycle_essentialIndices] + decide +kernel + +theorem fourCycle_ripsRunInDegree_zero : fourCycle.ripsRunInDegree 0 = some + [⟨0, 0, .finite 1⟩, ⟨0, 0, .finite 1⟩, ⟨0, 0, .finite 1⟩, ⟨0, 0, .essential⟩] := by + rw [ripsRunInDegree, fourCycle_ripsRun] + rfl + +theorem fourCycle_ripsRunInDegree_one : + fourCycle.ripsRunInDegree 1 = some [⟨1, 1, .finite 2⟩] := by + rw [ripsRunInDegree, fourCycle_ripsRun] + rfl + +theorem fourCycle_ripsRunInDegree_two : fourCycle.ripsRunInDegree 2 = some [] := by + rw [ripsRunInDegree, fourCycle_ripsRun] + rfl + +/-- The Rips diagram of the four-cycle metric in degree one: one class, born at `1` and +dead at `2`. -/ +theorem fourCycle_dgm_one : + (dgm (ZMod 2) (Rips.filter (fourCycle.metric fourCycle_valid)) 1).points = + {((1 : ℝ), ((2 : ℝ) : WithTop ℝ))} := by + obtain ⟨_, h⟩ := fourCycle.ripsRunInDegree_correct fourCycle_ripsRunInDegree_one + rw [h] + simp [Occurrence.point] + +/-- The Rips diagram of the four-cycle metric in degree zero, with multiplicity three and +the essential class. -/ +theorem fourCycle_dgm_zero : + (dgm (ZMod 2) (Rips.filter (fourCycle.metric fourCycle_valid)) 0).points = + Multiset.replicate 3 ((0 : ℝ), ((1 : ℝ) : WithTop ℝ)) + {((0 : ℝ), (⊤ : WithTop ℝ))} := by + obtain ⟨_, h⟩ := fourCycle.ripsRunInDegree_correct fourCycle_ripsRunInDegree_zero + rw [h] + simp only [Occurrence.point, Multiset.map_coe, List.map_cons, WithTop.coe_one, List.map_nil, + Int.cast_zero, WithTop.map_one, Int.cast_one, WithTop.map_top, Multiset.replicate_succ, + Multiset.replicate_zero, Multiset.cons_zero, Multiset.cons_add, Multiset.singleton_add] + rfl + +/-- The Rips diagram of the four-cycle metric has no point in degree two. -/ +theorem fourCycle_dgm_two : + (dgm (ZMod 2) (Rips.filter (fourCycle.metric fourCycle_valid)) 2).points = 0 := by + obtain ⟨_, h⟩ := fourCycle.ripsRunInDegree_correct fourCycle_ripsRunInDegree_two + rw [h] + rfl + +/-- The class is present at `1`: the Rips complex of the four-cycle metric at threshold `1` +has one-dimensional first homology over `ZMod 2`. -/ +theorem fourCycle_finrank_one : + Module.finrank (ZMod 2) (simplicialHomology + ((Rips.filter (fourCycle.metric fourCycle_valid)).sublevel 1) (ZMod 2) 1) = 1 := by + rw [finrank_sublevelHomology_eq_countP, fourCycle_dgm_one, Multiset.countP_eq_card_filter, + Multiset.filter_singleton] + norm_num + +/-- The class is filled at `2`: the Rips complex at threshold `2` has no first homology. -/ +theorem fourCycle_finrank_two : + Module.finrank (ZMod 2) (simplicialHomology + ((Rips.filter (fourCycle.metric fourCycle_valid)).sublevel 2) (ZMod 2) 1) = 0 := by + rw [finrank_sublevelHomology_eq_countP, fourCycle_dgm_one, Multiset.countP_eq_card_filter, + Multiset.filter_singleton] + norm_num + +/-- The first homology of the listed complex at threshold `1` is one-dimensional, by the +isomorphism induced by the inclusion of the labels. -/ +theorem fourCycle_listed_finrank_one : + Module.finrank (ZMod 2) (simplicialHomology + ((gradeFilter fourCycle.ripsInput fourCycle.ripsInput_valid).sublevel 1) (ZMod 2) 1) = + 1 := by + have := fourCycle.simplicialHomologyMap_ripsLabelMap_isIso (ZMod 2) fourCycle_valid 1 1 + rw [← (asIso (simplicialHomologyMap (ZMod 2) + (fourCycle.ripsLabelMap fourCycle_valid 1) 1)).toLinearEquiv.finrank_eq] + have h := fourCycle_finrank_one + rw [show ((1 : ℤ) : ℝ) = 1 from Int.cast_one] + exact h + +/-! ## Invalid tables -/ + +theorem oneWay_ripsRunInDegree (p : ℕ) : oneWay.ripsRunInDegree p = none := + oneWay.ripsRunInDegree_eq_none_iff.2 (by decide +kernel) + +theorem merged_ripsRunInDegree (p : ℕ) : merged.ripsRunInDegree p = none := + merged.ripsRunInDegree_eq_none_iff.2 (by decide +kernel) + +/-- The table violating the triangle inequality is rejected in every degree, also in the +degrees in which three points have no class. -/ +theorem shortcut_ripsRunInDegree (p : ℕ) : shortcut.ripsRunInDegree p = none := + shortcut.ripsRunInDegree_eq_none_iff.2 (by decide +kernel) + +theorem loop_ripsRunInDegree (p : ℕ) : loop.ripsRunInDegree p = none := + loop.ripsRunInDegree_eq_none_iff.2 (by decide +kernel) + +theorem negative_ripsRunInDegree (p : ℕ) : negative.ripsRunInDegree p = none := + negative.ripsRunInDegree_eq_none_iff.2 (by decide +kernel) + +/-- Executed in a degree in which a valid table of three labels has no record. -/ +theorem shortcut_ripsRunInDegree_five : shortcut.ripsRunInDegree 5 = none := by + decide +kernel + +/-! ## Relabelling -/ + +theorem line_valid : line.Valid := by decide +kernel + +/-- The table with two labels exchanged has the same diagram in every degree. -/ +theorem relabelled_outputDiagram (p : ℕ) : + outputDiagram relabelled.ripsInput p = outputDiagram line.ripsInput p := + outputDiagram_ripsInput_of_relabel (Equiv.swap 0 1) relabelled_dist line_valid p + +end TDA.Persistence.Reduction.RipsInputDiagramExamples diff --git a/TDA/Persistence/SublevelDiagramVertexMap.lean b/TDA/Persistence/SublevelDiagramVertexMap.lean new file mode 100644 index 0000000..64c7308 --- /dev/null +++ b/TDA/Persistence/SublevelDiagramVertexMap.lean @@ -0,0 +1,129 @@ +import TDA.Persistence.SublevelDiagram +import TDA.Persistence.RealBarcodeRankUniqueness +import TDA.Simplicial.VertexChainMap + +/-! +# Sublevel diagrams of filtered complexes related by vertex maps + +Two filtered complexes may live over different vertex types, for example a complex on labels +`Fin N` and its copy on the natural numbers. This module compares their homology and their +diagrams through the existing signed maps of `TDA.Simplicial.VertexChainMap`. + +* `simplicialHomologyMap_congr`: vertex maps that agree on the vertices of every face of the + source induce the same map in homology. The ambient functions may differ elsewhere. +* `simplicialHomologyMap_comp_eq_id`: a vertex map followed by one that undoes it on the + vertices of the faces induces the identity in homology. +* `dgm_eq_of_vertexMaps`: real filter functions on complexes over two vertex types have the + same diagram, in every degree and over every field, when functions on the vertices in both + directions preserve every sublevel complex and are mutually inverse on the vertices of the + faces. + +The two functions of `dgm_eq_of_vertexMaps` are total on the ambient vertex types and are +constrained on faces only; neither injectivity nor monotonicity is assumed. The induced maps +of sublevel homology are mutually inverse and commute with the inclusions, so all inclusions +have equal ranks; `rank_sublevelHomologyMap` and +`RealBarcode.multiset_eq_of_rankCounts_eq` recover the points. The statement is for real +grades, the generality of that uniqueness theorem, and for vertex types in the universe of the +field, as `dgm` requires. + +These are elementary library results, not attributed to a source. +-/ + +set_option autoImplicit false + +universe u + +namespace TDA.Simplicial + +open CategoryTheory + +variable {V W : Type u} [LinearOrder V] [LinearOrder W] +variable {K : PreAbstractSimplicialComplex V} {L : PreAbstractSimplicialComplex W} + +private theorem vertexChainMap_congr (R : Type*) [Ring R] (f g : VertexMap K L) + (h : ∀ s ∈ K, ∀ v ∈ s, f v = g v) (n : ℕ) : + vertexChainMap R f n = vertexChainMap R g n := by + apply Finsupp.lhom_ext + intro s a + rw [vertexChainMap_single, vertexChainMap_single] + have he : f ∘ s.1.orderEmbOfFin s.2.2 = g ∘ s.1.orderEmbOfFin s.2.2 := by + funext i + exact h s.1 s.2.1 _ (Finset.orderEmbOfFin_mem _ _ _) + rw [he] + +/-- Vertex maps that agree on the vertices of every face induce the same map in homology. -/ +theorem simplicialHomologyMap_congr (R : Type*) [Ring R] (f g : VertexMap K L) + (h : ∀ s ∈ K, ∀ v ∈ s, f v = g v) (n : ℕ) : + simplicialHomologyMap R f n = simplicialHomologyMap R g n := by + have hc : simplicialChainMap R f = simplicialChainMap R g := by + apply HomologicalComplex.hom_ext + intro i + simp only [simplicialChainMap_f] + rw [vertexChainMap_congr R f g h i] + unfold simplicialHomologyMap + rw [hc] + +/-- A vertex map followed by a vertex map that undoes it on the vertices of the faces induces +the identity in homology. -/ +theorem simplicialHomologyMap_comp_eq_id (R : Type*) [Ring R] (f : VertexMap K L) + (g : VertexMap L K) (h : ∀ s ∈ K, ∀ v ∈ s, g (f v) = v) (n : ℕ) : + simplicialHomologyMap R f n ≫ simplicialHomologyMap R g n = + 𝟙 (simplicialHomology K R n) := by + rw [← simplicialHomologyMap_comp, ← simplicialHomologyMap_id] + exact simplicialHomologyMap_congr R _ _ h n + +end TDA.Simplicial + +namespace TDA.Persistence + +open TDA.Simplicial TDA.Filtration CategoryTheory + +variable {V W : Type u} [LinearOrder V] [LinearOrder W] +variable {K : PreAbstractSimplicialComplex V} {L : PreAbstractSimplicialComplex W} + +private theorem finrank_range_eq_of_iso_square {k : Type*} [Field k] {A B C E : ModuleCat k} + (F : A ⟶ B) (G : C ⟶ E) (e₁ : A ≅ C) (e₂ : B ≅ E) (h : F ≫ e₂.hom = e₁.hom ≫ G) : + Module.finrank k (LinearMap.range F.hom) = Module.finrank k (LinearMap.range G.hom) := by + have hG : G.hom ∘ₗ e₁.hom.hom = e₂.hom.hom ∘ₗ F.hom := by + rw [← ModuleCat.hom_comp, ← ModuleCat.hom_comp, h] + have hs : LinearMap.range e₁.hom.hom = ⊤ := + LinearMap.range_eq_top.2 e₁.toLinearEquiv.surjective + have hi : Function.Injective e₂.hom.hom := e₂.toLinearEquiv.injective + rw [← LinearMap.range_comp_of_range_eq_top G.hom hs, hG, LinearMap.range_comp] + exact (Submodule.equivMapOfInjective e₂.hom.hom hi (LinearMap.range F.hom)).finrank_eq + +/-- Real sublevel diagrams are invariant under vertex maps in both directions that preserve +every sublevel complex and are mutually inverse on the vertices of the faces. -/ +theorem dgm_eq_of_vertexMaps (k : Type u) [Field k] + [Fintype (TotalFace K)] [Fintype (TotalFace L)] + (f : FilterFunction K ℝ) (g : FilterFunction L ℝ) (φ : V → W) (ψ : W → V) + (hφ : ∀ r s, s ∈ f.sublevel r → s.image φ ∈ g.sublevel r) + (hψ : ∀ r t, t ∈ g.sublevel r → t.image ψ ∈ f.sublevel r) + (hψφ : ∀ s ∈ K, ∀ v ∈ s, ψ (φ v) = v) (hφψ : ∀ t ∈ L, ∀ w ∈ t, φ (ψ w) = w) + (n : ℕ) : dgm k f n = dgm k g n := by + let Φ : ∀ r, VertexMap (f.sublevel r) (g.sublevel r) := fun r => + ⟨φ, fun s hs => by convert hφ r s hs⟩ + let Ψ : ∀ r, VertexMap (g.sublevel r) (f.sublevel r) := fun r => + ⟨ψ, fun t ht => by convert hψ r t ht⟩ + let e : ∀ r, + simplicialHomology (f.sublevel r) k n ≅ simplicialHomology (g.sublevel r) k n := + fun r => + ⟨simplicialHomologyMap k (Φ r) n, simplicialHomologyMap k (Ψ r) n, + simplicialHomologyMap_comp_eq_id k (Φ r) (Ψ r) + (fun s hs v hv => hψφ s (f.sublevel_le r hs) v hv) n, + simplicialHomologyMap_comp_eq_id k (Ψ r) (Φ r) + (fun t ht w hw => hφψ t (g.sublevel_le r ht) w hw) n⟩ + apply Diagram.ext + apply RealBarcode.multiset_eq_of_rankCounts_eq _ _ (dgm_isPositive k f n) + (dgm_isPositive k g n) + intro s t hst + rw [← rank_sublevelHomologyMap k f n s t hst, ← rank_sublevelHomologyMap k g n s t hst] + apply finrank_range_eq_of_iso_square _ _ (e s) (e t) + change simplicialHomologyIncl k (f.sublevel_mono hst) n ≫ + simplicialHomologyMap k (Φ t) n = + simplicialHomologyMap k (Φ s) n ≫ simplicialHomologyIncl k (g.sublevel_mono hst) n + rw [← simplicialHomologyMap_inclusion, ← simplicialHomologyMap_inclusion, + ← simplicialHomologyMap_comp, ← simplicialHomologyMap_comp] + rfl + +end TDA.Persistence diff --git a/docs/api.md b/docs/api.md index ad66637..6cb23c0 100644 --- a/docs/api.md +++ b/docs/api.md @@ -1549,9 +1549,9 @@ constructions and the arbitrary-field decomposition remain noncomputable. See [the input contract and correctness route](math/finite-ph-computation.md). `TDA.Persistence.Reduction.DistanceTable N` is an integer distance table on the -labels `Fin N`, and `TDA.Persistence.Reduction.RipsInput` executes the complete Rips -simplex list of such a table in the `FiniteInput` format. `DistanceTable.Valid` -(nonnegative entries, symmetry, zero diagonal, positive distance between distinct +labels `Fin N`, and the module `TDA.Persistence.Reduction.RipsInput` executes the +complete Rips simplex list of such a table in the `FiniteInput` format. +`DistanceTable.Valid` (nonnegative entries, symmetry, zero diagonal, positive distance between distinct labels, every triangle inequality) is decidable; `ripsInput?` and `ripsRun` return `none` for an invalid table, and nothing is repaired. `ripsInput` has one entry `(s.map Fin.valEmbedding, diameter s)` for each nonempty set `s` of labels @@ -1565,10 +1565,44 @@ identifies the listed grade of each face with the value of `Rips.filter`. `ripsR returns the occurrence records of the existing reduction on the list (`ripsRun_eq_bind_run`). The list has `2 ^ N - 1` entries and costs `O(N² 2 ^ N)` label and integer operations; the cost of the existing reduction is separate and -not bounded. The equality of the resulting diagram with the Rips diagram and the -comparison of homology are not provided by this module. See +not bounded. See [Rips input from an integer distance table](math/finite-ph-computation.md#rips-input-from-an-integer-distance-table). +The module `TDA.Persistence.Reduction.RipsInputDiagram` compares the executed +list of a valid table with the Rips filtration of the table metric. +`DistanceTable.outputDiagram_ripsInput` states that `FiniteInput.outputDiagram` +of the list, mapped along `TDA.Persistence.intCastOrderEmbedding : ℤ ↪o ℝ`, is +`dgm (ZMod 2) (Rips.filter (D.metric hD))` in every degree; the caller supplies +no metric, isomorphism or certificate. `mem_sublevel_gradeFilter_ripsInput` and +`mem_sublevel_rips_filter` describe the faces of the two filtrations at a +threshold by the integer diameter. `ripsLabelMap` is the inclusion of the labels +as a vertex map from the Rips complex at an integer threshold to the sublevel +complex of the list; it induces an isomorphism in homology in every degree and +over every ring (`simplicialHomologyMap_ripsLabelMap_isIso`), compatible with +raising the threshold (`simplicialHomologyMap_ripsLabelMap_naturality`). +`ripsRunInDegree p` returns the occurrence records of degree `p`; it is `none` +exactly for an invalid table, whatever the degree +(`ripsRunInDegree_eq_none_iff`), and `ripsRunInDegree_correct` reads a returned +list as the point multiset of the Rips diagram. A permutation of the labels of a +valid table gives a valid table with the same diagram of the executed list +(`valid_of_relabel`, `outputDiagram_ripsInput_of_relabel`). The homology +comparison is stated at integer thresholds, and the relabelling statement is an +equality of diagrams, not of lists. No bound on the cost of the existing +reduction, no representatives for the Rips complex and no statement for invalid +tables beyond rejection are provided. + +The module `TDA.Persistence.SublevelDiagramVertexMap` holds the general +statements behind this comparison. `TDA.Simplicial.simplicialHomologyMap_congr` +states that vertex maps agreeing on the vertices of every face induce the same +map in homology, and `simplicialHomologyMap_comp_eq_id` that a vertex map +followed by one undoing it on those vertices induces the identity. +`TDA.Persistence.dgm_eq_of_vertexMaps` states that real filter functions on +complexes over two vertex types have the same diagram, in every degree and over +every field, when functions on the vertices in both directions preserve every +sublevel complex and are mutually inverse on the vertices of the faces. It is +stated for real grades only. See +[Diagram and homology of the Rips input](math/finite-ph-computation.md#diagram-and-homology-of-the-rips-input). + `FiniteInput.runWithRepresentatives` adds original face-index cycle supports and, for finite occurrences, bounding supports while preserving that exact ordered output. Its correctness API proves actual signed simplicial boundary identities, diff --git a/docs/math/finite-ph-computation.md b/docs/math/finite-ph-computation.md index 7318a4a..43471ec 100644 --- a/docs/math/finite-ph-computation.md +++ b/docs/math/finite-ph-computation.md @@ -204,7 +204,7 @@ list has `2 ^ N - 1` entries (`length_ripsInput`). The tie-break is a property of this implementation; by `outputDiagram_eq_of_same_graded_complex` the interpreted diagram does not depend on it. -`ripsInput_valid` proves the five conditions of `Valid` for the list. It holds +`ripsInput_valid` proves `FiniteInput.Valid` for the list. It holds for every table, valid or not, because the maximum over pairs is monotone in the set; only the metric meaning of the list needs a valid table. `ripsInput?` returns the list for a valid table and `none` otherwise. `ripsRun` returns @@ -224,8 +224,9 @@ value of `Rips.filter` for `metric` at the corresponding face. These are statements about the complex and the filter that `outputDiagram_eq_dgm` uses. This module does not compare diagrams or homology. The equality of -`outputDiagram` of the list with the diagram of `Rips.filter`, and the -positive-degree consumer for the four-cycle, are later units. +`outputDiagram` of the list with the diagram of `Rips.filter`, the comparison of +homology and the positive-degree consumer for the four-cycle are in +[Diagram and homology of the Rips input](#diagram-and-homology-of-the-rips-input). Write `F = 2 ^ N - 1` for the number of faces and `G` for the number of distinct grades; every grade is `0` or a table entry, so @@ -256,6 +257,116 @@ one essential class in degree zero). Tables violating symmetry, separation, the triangle inequality, the zero diagonal or nonnegativity return `none` from `ripsInput?` and from `ripsRun`. +## Diagram and homology of the Rips input + +The list `ripsInput` of a valid table is a filtered complex over the vertex type +`ℕ` with integer grades. The Rips filtration of the table metric is +`Rips.filter (D.metric hD)` on `Rips.fullComplex (Fin N)`, with real grades. +`TDA.Persistence.Reduction.RipsInputDiagram` compares the two; the caller +supplies no metric, isomorphism or certificate. + +The comparison needs a change of vertex type, which +`TDA.Persistence.SublevelDiagramVertexMap` provides in general. A vertex map +induces a signed chain map that reads the map only at the vertices of the faces +of its source, so vertex maps that agree there induce the same map in homology +(`simplicialHomologyMap_congr`), and a vertex map followed by one that undoes it +on those vertices induces the identity (`simplicialHomologyMap_comp_eq_id`). +`dgm_eq_of_vertexMaps` takes real filter functions `f` and `g` on complexes over +two vertex types and functions `φ`, `ψ` on the vertices in the two directions. +If `φ` and `ψ` carry every sublevel complex of one filter into the sublevel +complex of the other at the same threshold, and are mutually inverse on the +vertices of the faces, then `dgm k f n = dgm k g n` in every degree and over +every field. The induced maps of sublevel homology are mutually inverse and +commute with the inclusions, so all inclusion-induced maps have equal ranks; +`rank_sublevelHomologyMap` turns the ranks into interval counts and +`RealBarcode.multiset_eq_of_rankCounts_eq` recovers the points. The functions +are total and constrained on faces only; neither injectivity nor monotonicity is +assumed. The statement is for real grades, the generality of that uniqueness +theorem. The existing Rips- and Čech-specific comparisons, such as +`Rips.dgm_eq_of_isometryEquiv`, relate the complexes of two metric spaces or +point configurations and do not apply to a list on `ℕ`. + +The faces at a threshold are described by the integer diameter. +`mem_sublevel_gradeFilter_ripsInput` states that the faces of the list at an +integer threshold `a` are the sets `s.map Fin.valEmbedding` for nonempty `s` +with `diameter s ≤ a`, for every table. `mem_sublevel_rips_filter` states that +the faces of the Rips filtration at a real threshold `r` are the nonempty `s` +with `(diameter s : ℝ) ≤ r`. All values of both filters are integers, so the +Rips complex at `r` is the one at the floor of `r`. + +`ripsLabelMap hD a` is the vertex map with underlying function `Fin.val` from +the Rips complex at the integer threshold `a` to the sublevel complex of the +list at `a`. It induces an isomorphism in homology in every degree and over +every ring (`simplicialHomologyMap_ripsLabelMap_isIso`), and these isomorphisms +commute with the maps induced by raising the threshold +(`simplicialHomologyMap_ripsLabelMap_naturality`). For a nonempty set of labels +the inverse is induced by a left inverse `ℕ → Fin N` of the inclusion; for no +label both sides are the homology of the empty complex. The comparison of +homology is stated at integer thresholds. + +`outputDiagram_ripsInput` is the diagram equality: for a valid table and every +degree `p`, + +```lean +(FiniteInput.outputDiagram D.ripsInput p).map intCastOrderEmbedding = + dgm (ZMod 2) (Rips.filter (D.metric hD)) p +``` + +`intCastOrderEmbedding : ℤ ↪o ℝ` is the inclusion of the integers, and +`Diagram.map` casts births and finite deaths and keeps the essential death. The +proof composes `outputDiagram_eq_dgm`, `dgm_map` and `dgm_eq_of_vertexMaps`. +Multiplicities, the deletion of pairs of equal grades, essential classes and +unaugmented degree zero are those of `outputDiagram_eq_dgm`. The equality +covers every pair of real thresholds, since the diagram determines the ranks of +all inclusion-induced maps. + +`ripsRunInDegree p` filters `ripsRun` by degree. It is `none` exactly when the +table is invalid, whatever `p` (`ripsRunInDegree_eq_none_iff`), and `some` of +the records of degree `p`, possibly none, for a valid table +(`ripsRunInDegree_eq_some_iff`). `ripsRunInDegree_correct` states that a +returned list certifies the table and that its records, read as points with +real coordinates, are the points of the Rips diagram in degree `p` with +multiplicity. The order of the records is that of the existing reduction and is +not part of the comparison. The consumer costs `ripsRun` and one comparison of +natural numbers for each of the at most `2 ^ N - 1` records. The cost of the +existing reduction is not bounded; it is at least quadratic in the number of +faces, and only measurements are recorded. + +For a permutation `σ` of the labels and tables with +`E.dist i j = D.dist (σ i) (σ j)`, `valid_of_relabel` transfers validity and +`outputDiagram_ripsInput_of_relabel` states that the two executed lists have +the same diagram in every degree. This is an equality of diagrams, not of +lists; it passes through the two Rips diagrams and +`Rips.dgm_eq_of_isometryEquiv`. No relabelling operation on tables is defined. + +`RipsInputDiagramExamples.lean` checks the records of each degree and the Rips +diagram in degree zero for no label, one label (the single point `(0, ⊤)`) and +two labels at distance `3` (the points `(0, 3)` and `(0, ⊤)`; the empty list of +records in degree one). For the four-cycle the kernel runs the existing +reduction on the fifteen faces: `fourCycle_reduced` is the reduced matrix, and +`fourCycle_ripsRun` lists three classes of degree zero from `0` to `1`, one +class of degree one from `1` to `2` and one essential class of degree zero; the +three pairs of equal grade `2` leave no record. The kernel does not evaluate +`FiniteInput.boundary`, so the examples prove privately that over `ZMod 2` it is +the indicator `faceIncidence` of the codimension-one faces, which the kernel +does evaluate. The kernel check of the reduction dominates the build time of the +examples and is meant for small fixtures only. +`fourCycle_dgm_one` states that the Rips diagram of the four-cycle metric in +degree one is the single point `(1, 2)`, `fourCycle_dgm_zero` and +`fourCycle_dgm_two` give the other degrees, and `fourCycle_finrank_one` and +`fourCycle_finrank_two` state that the first homology over `ZMod 2` of the Rips +complex has dimension `1` at threshold `1` and `0` at threshold `2`. +`fourCycle_listed_finrank_one` obtains the same dimension for the listed +complex through the isomorphism of `ripsLabelMap`. The five invalid tables +return `none` in every degree, and the table violating the triangle inequality +is also executed in degree `5`, where a valid table of three labels has no +record. `relabelled_outputDiagram` instantiates the relabelling statement for +the two tables on a line. + +Not provided: a bound on the cost of the reduction, representatives or sublevel +classes of the Rips complex, a statement for invalid tables beyond rejection, +and a transport of diagrams for grades outside the real numbers. + ## Dependency and source scope The computational dependencies are pinned Lean/mathlib finite lists and diff --git a/scripts/print_axioms/Persistence.lean b/scripts/print_axioms/Persistence.lean index fc7443d..bde4819 100644 --- a/scripts/print_axioms/Persistence.lean +++ b/scripts/print_axioms/Persistence.lean @@ -7940,3 +7940,57 @@ set_option linter.auxLemma false #print axioms TDA.Persistence.Reduction.RipsInputExamples.negative #print axioms TDA.Persistence.Reduction.RipsInputExamples.negative_ripsInput #print axioms TDA.Persistence.Reduction.RipsInputExamples.negative_ripsRun +#print axioms TDA.Simplicial.simplicialHomologyMap_congr +#print axioms TDA.Simplicial.simplicialHomologyMap_comp_eq_id +#print axioms TDA.Persistence.dgm_eq_of_vertexMaps +#print axioms TDA.Persistence.intCastOrderEmbedding +#print axioms TDA.Persistence.intCastOrderEmbedding_apply +#print axioms TDA.Persistence.Reduction.DistanceTable.mem_sublevel_rips_filter +#print axioms TDA.Persistence.Reduction.DistanceTable.mem_sublevel_gradeFilter_ripsInput +#print axioms TDA.Persistence.Reduction.DistanceTable.outputDiagram_ripsInput +#print axioms TDA.Persistence.Reduction.DistanceTable.ripsLabelMap +#print axioms TDA.Persistence.Reduction.DistanceTable.ripsLabelMap_apply +#print axioms TDA.Persistence.Reduction.DistanceTable.simplicialHomologyMap_ripsLabelMap_isIso +#print axioms TDA.Persistence.Reduction.DistanceTable.simplicialHomologyMap_ripsLabelMap_naturality +#print axioms TDA.Persistence.Reduction.DistanceTable.ripsRunInDegree +#print axioms TDA.Persistence.Reduction.DistanceTable.ripsRunInDegree_eq_some_iff +#print axioms TDA.Persistence.Reduction.DistanceTable.ripsRunInDegree_eq_none_iff +#print axioms TDA.Persistence.Reduction.DistanceTable.ripsRunInDegree_correct +#print axioms TDA.Persistence.Reduction.DistanceTable.valid_of_relabel +#print axioms TDA.Persistence.Reduction.DistanceTable.outputDiagram_ripsInput_of_relabel +#print axioms TDA.Persistence.Reduction.RipsInputDiagramExamples.empty_valid +#print axioms TDA.Persistence.Reduction.RipsInputDiagramExamples.empty_ripsRunInDegree +#print axioms TDA.Persistence.Reduction.RipsInputDiagramExamples.empty_dgm +#print axioms TDA.Persistence.Reduction.RipsInputDiagramExamples.single_valid +#print axioms TDA.Persistence.Reduction.RipsInputDiagramExamples.single_ripsRunInDegree_zero +#print axioms TDA.Persistence.Reduction.RipsInputDiagramExamples.single_dgm_zero +#print axioms TDA.Persistence.Reduction.RipsInputDiagramExamples.pair_ripsRunInDegree_zero +#print axioms TDA.Persistence.Reduction.RipsInputDiagramExamples.pair_ripsRunInDegree_one +#print axioms TDA.Persistence.Reduction.RipsInputDiagramExamples.pair_dgm_zero +#print axioms TDA.Persistence.Reduction.RipsInputDiagramExamples.fourCycleInput +#print axioms TDA.Persistence.Reduction.RipsInputDiagramExamples.fourCycle_ripsInput_eq +#print axioms TDA.Persistence.Reduction.RipsInputDiagramExamples.columnMatrix +#print axioms TDA.Persistence.Reduction.RipsInputDiagramExamples.fourCycleBoundary +#print axioms TDA.Persistence.Reduction.RipsInputDiagramExamples.fourCycleReduced +#print axioms TDA.Persistence.Reduction.RipsInputDiagramExamples.fourCycle_boundary +#print axioms TDA.Persistence.Reduction.RipsInputDiagramExamples.fourCycle_reduced +#print axioms TDA.Persistence.Reduction.RipsInputDiagramExamples.fourCycle_pivotPairs +#print axioms TDA.Persistence.Reduction.RipsInputDiagramExamples.fourCycle_essentialIndices +#print axioms TDA.Persistence.Reduction.RipsInputDiagramExamples.fourCycle_ripsRun +#print axioms TDA.Persistence.Reduction.RipsInputDiagramExamples.fourCycle_ripsRunInDegree_zero +#print axioms TDA.Persistence.Reduction.RipsInputDiagramExamples.fourCycle_ripsRunInDegree_one +#print axioms TDA.Persistence.Reduction.RipsInputDiagramExamples.fourCycle_ripsRunInDegree_two +#print axioms TDA.Persistence.Reduction.RipsInputDiagramExamples.fourCycle_dgm_one +#print axioms TDA.Persistence.Reduction.RipsInputDiagramExamples.fourCycle_dgm_zero +#print axioms TDA.Persistence.Reduction.RipsInputDiagramExamples.fourCycle_dgm_two +#print axioms TDA.Persistence.Reduction.RipsInputDiagramExamples.fourCycle_finrank_one +#print axioms TDA.Persistence.Reduction.RipsInputDiagramExamples.fourCycle_finrank_two +#print axioms TDA.Persistence.Reduction.RipsInputDiagramExamples.fourCycle_listed_finrank_one +#print axioms TDA.Persistence.Reduction.RipsInputDiagramExamples.oneWay_ripsRunInDegree +#print axioms TDA.Persistence.Reduction.RipsInputDiagramExamples.merged_ripsRunInDegree +#print axioms TDA.Persistence.Reduction.RipsInputDiagramExamples.shortcut_ripsRunInDegree +#print axioms TDA.Persistence.Reduction.RipsInputDiagramExamples.loop_ripsRunInDegree +#print axioms TDA.Persistence.Reduction.RipsInputDiagramExamples.negative_ripsRunInDegree +#print axioms TDA.Persistence.Reduction.RipsInputDiagramExamples.shortcut_ripsRunInDegree_five +#print axioms TDA.Persistence.Reduction.RipsInputDiagramExamples.line_valid +#print axioms TDA.Persistence.Reduction.RipsInputDiagramExamples.relabelled_outputDiagram