The engines live in homology/ (Homology.scala, PackedRipserCohomology.scala, Cohomology.scala, FastCubicalHomology.scala, FastAlphaHomology.scala, PackedCubicalCohomology.scala): five algorithms in several concrete classes. Engines 3 and 4 are one algorithm in two representations, and the two fast engines share one algorithm (a dual-graph union-find by Alexander duality) on two cell types. They share the Chain reduction primitives from Architecture but are not variants of one engine: a fix or bug in one says nothing about the others. Read this page before choosing which to build on.
PackedCubicalCohomologyEngine is engine 4's algorithm (clearing, apparent pairs, a packed involution) on a cubical grid's own cell indices, with no Cube or Chain inside the reduction. It must equal engine 5 on any CubicalGridStream, bar for bar and term for term. Engine.Cohomology and engine 6's middle degrees run it on a grid. A reduced column is stored as its cells' keys and coefficients (the cycle of a reported bar is that column), an apparent pair's column is not stored at all, and the tables indexed by cell are dense Int arrays.
CellularHomologyEngine, CellularPersistenceInChunksEngine and CellularCohomologyEngine also implement the PersistenceEngine[CellT, C] trait (def barcode(stream): List[PersistenceBar[Double, Chain[CellT, C]]]) through the PersistenceEngine.naive/.chunks/.cohomology factories: an adapter for callers, such as the MATLAB and CLI facade, that want a finished barcode. Each engine's incremental API (advanceTo/diagramAt/barcodeAt) stays available on the concrete class. The Ripser engines take a FiniteMetricSpace[Int] rather than a stream and do not implement it.
1. CellularHomologyEngine / SimplicialHomologyEngine — reference-grade, generic
CellularHomologyEngine[CellT: OrderedCell, CoefficientT: Field, FiltrationT: Ordering] is the naive single-pivot-table boundary-reduction algorithm: process cells in filtration order, reduce each cell's boundary against pivots recorded so far via Chain.reduceBy, and the cell either opens a class (reduced boundary is zero) or closes one. No clearing, no chunking, no cohomology/twist optimization. Generic over any CellT: OrderedCell — this is what makes it the engine Cube and FiniteSimplicialSet slot into with no new engine code (CubicalHomologyEngine, SimplicialHomologyEngine are one-line specializations of it). It's the oracle every other engine here gets cross-validated against.
It's also the only engine with genuine incremental querying: HomologyState.advanceOne()/advanceTo(f)/ advanceAll(), and diagramAt(f)/barcodeAt(f) can be called mid-stream to get the diagram as of filtration value f. barcodeAt annotates every bar with a real representative cycle, tracked via a parallel V-column alongside the ordinary reduction.
persistentHomology(stream, maxDimension) caps the cursor at a homological degree. Cells above dimension maxDimension + 1 are neither sorted nor reduced. A cell of dimension maxDimension + 1 can only close a class of degree maxDimension, so it is reduced only while such a class is open, and it leaves nothing but the pairing it makes (no V-column, no class of degree maxDimension + 1). The bars of degrees 0 .. maxDimension and their representatives are those of the cursor on the whole complex. The one-argument form reads a stream that has no homologyDegreeLimit whole, and a stream cut off at degree k (VietorisRips(points, maxDimension = k)) up to k, which is also what a larger explicit maxDimension comes to: the cells above k close nothing, so their unpaired ones are not homology. Persistence uses the capped cursor, and so does PersistenceEngine.naive.
2. CellularPersistenceInChunksEngine / PersistenceInChunksEngine — chunked, generic
CellularPersistenceInChunksEngine[CellT: OrderedCell, CoefficientT: Field](maxDim: Int = 5) implements the parallelizable "clear-and-compress" algorithm: local reduction per chunk, active-entry marking, then global column compression/reduction. PersistenceInChunksEngine[VertexT, CoefficientT] is a one-line Simplex-specialized subclass, mirroring SimplicialHomologyEngine's relationship to engine 1 — the class has no Simplex-specific behavior anywhere in its body, so any OrderedCell slots in directly. CubicalPersistenceInChunksEngine[CoefficientT] is the same one-line subclass for Cubes.
Dimensions 0 and 1 go through a dedicated union-find fast path (unionFindDim01) instead of the general Chain-based reduction, which gives the same result on a fixed total order and is much faster when a large point cloud's dimension-0/1 structure dominates the complex. barcodeAt(f) returns a real representative for every bar, at every dimension, including essential classes — reconstructed incrementally from this class's own already-computed boundaries/cleared/paired/killer state (vcolOf, memoized) rather than by delegating to a second engine run. advanceAll() runs the whole pipeline in one shot; there is no incremental querying the way engine 1 has.
Like every engine that reads a stream, it reports no degree above the stream's homologyDegreeLimit, whatever maxDim says: the default maxDim = 5 on VietorisRips(points, maxDimension = 2) gives degrees 0..2.
What the union-find takes. unionFindDim01 sorts each edge by its boundary over the engine's field (edgeShape):
- zero (no entries, a loop's
(v, c), (v, -c), or coefficients that vanish in the field): the edge closes a cycle by itself and is its own representative; c·(v - u)withu ≠ vandca unit: the edge joins two components;- anything else (one vertex with a nonzero coefficient, three vertices, coefficients that are not negatives of each other): union-find stops and clears what it recorded, and the general reduction runs from dimension 0.
Simplices, cubes and simplicial sets only produce the first two shapes. An algebraic chain complex, such as a Morse complex over F_p, may produce the third.
Degree-1 representatives are built on request. A cycle-closing edge's representative is the edge minus the spanning-forest paths to its ends. It is built when barcodeAt first asks for it, then memoized; diagramAt never builds one. Keep the edge pass free of chains: a path chain per cycle-closing edge would cost more than the union-find itself on a Vietoris-Rips complex.
Top cells. At maxDim = 1, once the union-find has taken degrees 0 and 1, the triangles are reduced in filtration order against the number of degree-1 classes still open (the positive edges born at or before the triangle, minus the triangles that have already closed one). A triangle that enters while none is open cannot close a class, so its boundary reduces to zero and the engine does not reduce it. From maxDim = 2 every top cell is reduced. Cells are compared by rank: the stream's cells are sorted once by filtrationOrdering, which is cheaper than asking the stream's ordering at every comparison. A stream in which some cell has no filtration value keeps its own ordering.
3. RipserCohomologyEngine — test/reference oracle for engine 4
Persistent cohomology via Ulrich Bauer's Ripser algorithm (arXiv:1908.02518), specialized to Simplex[Int] Vietoris-Rips/clique complexes via SimplexIndexing's combinatorial number system — a deliberate narrowing from the generic CellT: OrderedCell engines above. One-shot only (persistentCohomology(), no incremental querying).
Production code does not call this class. PackedRipserCohomologyEngine (engine 4) is the same algorithm on a packed representation, and is what engine="ripser" uses. Both share SimplexIndexing, so a bug there passes both; engine 1 is the independent oracle for the algorithm. This class catches what is specific to engine 4's packed representation (its DiameterIndex carrier's index-only equals/hashCode, its index-keyed lookup maps), and its Simplex[Int]-keyed chains are easier to debug by hand. It is maintained; do not add production call sites.
Structural points worth knowing:
- Clearing is required for correctness, not merely an optimization: a simplex already used as a pivot in the previous dimension must be excluded from the next dimension's essential-index count.
- Apparent pairs are partially implemented: mutual apparent pairs can bypass reduction, but the implementation still constructs the full coboundary.
4. PackedRipserCohomologyEngine — the production Ripser engine
Same algorithm as engine 3, method for method, keyed on a packed diameter/combinatorial-index pair (DiameterIndex) instead of a materialized Simplex[Int]. This is what matlab.TDA4j's engine="ripser" calls, and the fastest, most memory-efficient engine in the library — a deliberate representation choice on top of an already-validated algorithm, not a new algorithm. Kept in its own file, separate from the three generic-OrderedCell algorithms in Homology.scala, since it's specific to Vietoris-Rips/SimplexIndexing rather than a general engine.
DiameterIndex overrides equals/hashCode to consider only the combinatorial index (both words), not the diameter — so "same simplex" is true by construction regardless of which floating-point path computed its diameter, so two carriers for the same simplex never compare unequal on floating-point noise.
Index width. The index of a simplex is one Long while C(n + d + 2, d + 2) fits in 63 bits for maxDimension = d (16,000 points to degree 3, 122,000 to degree 2). Beyond that the engine numbers the simplices with two words (WideSimplexIndexing, up to 126 bits; its cursors find the same cofacets and facets in the same order). The choice is made once, in the constructor (wideIndices forces either, usesWideIndices reports it), and a run that fits in one Long runs the one-word code. The second word exists only where it is used: a cell past 63 bits is a WideDiameterIndex (a plain DiameterIndex has high = 0 and no field for it), and the working column, the levels, the pairing and a stored column keep high-word arrays only in a two-word run. The maps keyed by index (pivots, the cleared set) are keyed by a dense number of the two-word index (WideKeys). Decode a returned cell with engine.vertices(cell, size), which reads either width.
Reduction internals. The column being reduced is Ripser's working column: a binary heap of (diameter, index, coefficient) entries in primitive arrays, to which adding a column only pushes entries; equal cells are combined when they reach the top. Coboundaries and boundaries are pushed straight from the SimplexIndexing cursors, never built as Chains. Under a threshold that keeps few of the pairs, a simplex's cofacets are found by intersecting its vertices' lists of neighbours within the threshold (built once, with each distance stored) rather than by trying every vertex; the lists give the same cofacets in the same order. Per-simplex bookkeeping is kept in primitive arrays (each degree's simplices, the pairing, the cleared indices), and a PersistenceBar is built only for a bar that is returned; in the involution, an apparent pair that is not reported is not reduced at all, and its boundary column is rebuilt from its death simplex when another column needs it rather than stored. A stored reduced column keeps its pivot first and the remaining terms uncombined. The test for an apparent or emergent pair decodes a column once: the vertices of its oldest cofacet of the same diameter are the column's with one added, those of that cofacet's facets the cofacet's with one removed, and its youngest facet of the same diameter comes from its longest edges (a facet keeps the diameter unless the removed vertex is an endpoint of every longest edge). An emergent pair (Bauer's Definition 3.11) is a column whose oldest cofacet of the same diameter is the pivot of no earlier column (no stored column, no emergent pair, and not the apparent partner of that cofacet's youngest facet): its coboundary is reduced as it stands, so the engine pairs it at once without putting its cofacets on the working column, and keeps only the simplex, from which the column is rebuilt in the rare case that a later column needs it. useEmergentPairs = false turns the shortcut off; no output changes. Cocycles (the V-columns) are recorded as a reduction log per column and expanded only for the bars that are reported, so persistentCohomology() builds none for zero-length bars and persistentHomology() builds none at all. Cycles come from the engine's own specialization of Involution.cycles on the same heap, which returns exactly what the generic involution returns. The heap relies on a simplex having one diameter: a metric that is not symmetric by construction (anything but EuclideanMetricSpace and ExplicitMetricSpace, which reads its lower triangle) is read as d(max(i, j), min(i, j)), the same triangle.
Degree 0 by union-find. Engine 4 does not reduce the vertices' coboundaries. It generates the edges within the threshold and sorts them once (for this pass and for degree 1), then goes through them oldest first with a union-find: an edge that joins two components kills the one whose oldest vertex is younger, and the pair is that vertex with that edge. These are the pairs the reduction finds, since each column pivots on its oldest edge. A bar's cocycle is the indicator function of the component that dies, as it stands just before its edge (the final component for a vertex that never dies), and the death edges are the cleared columns of degree 1. useUnionFind = false reduces the columns instead, with the same output. Engine 3 always reduces them: it is the oracle.
Counters. Engines 3 and 4 report what their last run did:
apparentPairCount, the simplices paired as apparent pairs with no reduction of their coboundary (in engine 4, of degrees 1 and up: degree 0 is paired by union-find);emergentPairCount(engine 4 only), the simplices of degrees 1 and up paired as emergent pairs;substitutionCount, how often another column needed an apparent pair's column as a pivot and had it rebuilt;totalSimplexCount, the simplices the run assembled over all dimensions.
They explain a speed difference between two inputs of the same size: a high apparent-pair rate means little reduction work. They are diagnostics, not part of any result.
Equal edge lengths (edgeTies). Ripser orders simplices by diameter and then by combinatorial index, so on a lattice or any input with many equal distances, which of two equal edges is the later one decides how many pairs are apparent. ParallelPackedCohomology.EdgeTies names five orders of the edges of one length (Lexicographic, ReverseLexicographic, Colexicographic, ReverseColexicographic, Shuffled), and a simplex is then filed under its last longest edge in that order (the "block" of the parallel engine). Every order gives the same bars; they differ in which pairs are apparent and in which zero-length pairs form.
-
ParallelRipseralways has an edge order, since it ranks the edges within the threshold once (length, then the order chosen);Lexicographicis its default, andPersistence'sedgeTiespicks another. -
PackedRipserCohomologyEnginehas none unless asked.Persistence(..., engine = Ripser, edgeTies = ...)and the facades'edgeTiesrun it on anEdgeRankedMetricSpace: the metric space whose distance is the rank of the edge. The engine's tests for "the same diameter" then see edge blocks, and its bars are read back in lengths withlengthOf. Two ranks of one length give a zero-length bar, which is left out unlessincludeZeroLength. -
Inside a block the engines order simplices by combinatorial index, and
BlockOrdersays which way (Persistence.BlockOrder,blockOrder,--block-order).LargerIndexFirstis the default and Ripser's own convention: the simplex of larger index is older, so a column's apparent cofacet adds the largest vertex that qualifies and its youngest facet drops the largest vertex outside the block's edge.SmallerIndexFirstis the mirror image (the smallest vertices, the smaller index older, and the larger root of a merge dies in degree 0). OnlyParallelRipserhas it: the rules for an apparent pair (apparentCofacetandapparentFacetinParallelPackedCohomology) read the key's index part as the index or as its complement. The sequential engine is alwaysLargerIndexFirst, andPersistencerefuses the other withEngine.Ripser. -
These combinations do the work of Bauer's builds.
ParallelBlockOrderSpecpins the columns left to reduce against ripser.cpp (COUNT_WORK) and ripser-forest (-DCOUNT_WORK,--ties) builds of ripser-dev at 857c9d0 on lattices, and checks every apparent pair against the definition by brute force:edgeTiesblockOrderthe same work as ReverseColexicographicLargerIndexFirstripser.cpp built with EDGE_LEXICOGRAPHICColexicographicSmallerIndexFirstripser-forest --ties increasing, its defaultReverseColexicographicSmallerIndexFirstripser-forest --ties decreasingLexicographicSmallerIndexFirstripser-forest --ties lexicographicShuffledSmallerIndexFirstthe hybrid's --ties random(a hash of the index, from its source; ripser-forest'srandomhashes something else)Bauer's hybrid (
hybrid/pruned.cpp) names the last four as its own--ties(ORDER_CONVENTIONS.md); its engine was read, not run, so its columns are matched through ripser-forest. With the labels reversed the orderLexicographicwithSmallerIndexFirstisReverseColexicographicwithLargerIndexFirst: the same pairing, the same columns (ParallelBlockOrderSpec). -
Counts are not comparable across tools without care: ripser.cpp's
COUNT_WORKcounts a simplex in an apparent pair as apparent whether it is the column or the row,ParallelRipser'sapparentcounts columns only, and itsclearedcounts every pivot of the degree below. The sequential engine'sapparentPairCountequals the sum ofParallelRipser'sapparentover degrees 1 and up in the same order. -
ParallelPackedCohomologyDrivertakesties=<name>andorder=<name>and prints each degree's columns, apparent pairs, cleared pivots, columns left to reduce and additions;EdgeRankMetricDriverruns the sequential engine on lengths or on ranks of an order. The benchmark harness counts the same quantities for the forks of ripser.cpp and RedZeD and for every combination above (bench/count_work.py,PaperBenchmarkDriver work=true;bench/README.md, "Counting the work").
5. CellularCohomologyEngine — generic cohomology, for every cell type
Persistent cohomology, generic over CellT: OrderedCell: the cohomology counterpart to engine 1. It serves every cell type: Cube, FiniteSimplicialSet generators, and the Simplex[Int] complexes that are not Vietoris-Rips (Cech, Alpha, the general witness complex). Engines 3 and 4 cannot: their speed optimizations (insertionDiameter, apparent pairs) are proven only for the max-pairwise-distance functional, not for Cech's circumradius, Alpha's own filtration, or the general witness complex's per-dimension threshold. The lazy witness complex is the exception: it is a max-pairwise-distance flag complex under its own WitnessMetricSpace, so engines 3 and 4 work for it (see "Witness complexes" in architecture.md).
The key idea: the coboundary matrix persistent cohomology reduces is the transpose of the ordinary boundary matrix, same coefficients. Every stream this class targets already gets fully materialized before persistence runs (unlike Vietoris-Rips at the scale engines 3/4 target), so this class builds the coboundary relation directly by inverting each materialized cell's own boundary[CoefficientT] call, one dimension band at a time (built, used, and discarded before moving to the next dimension, bounding peak memory to the largest single band) — no SimplexIndexing-style combinatorial machinery, and no per-cell-type coboundary formula.
No maxDim parameter and no apparent pairs. Callers truncate the input stream when needed, and the coboundary relation is already materialized, so apparent-pair optimizations have nothing to save. A stream built for degrees 0..k says so in its homologyDegreeLimit; the engine then reports no bar above k, cocycles and cycles alike, because the cells of degree k + 1 that close no class are not the complex's homology and would each cost a bar and a representative (PackedCubicalCohomologyEngine does the same on a truncated grid).
Representatives: Every bar carries a V-column. Essential bars yield genuine cocycles over the full complex; finite bars carry representatives valid over their persistence interval.
Degree 0 by union-find. When every edge's boundary is c·(v - u) between two cells of the stream, or has no entries (a loop, listed as nothing or as (v, c), (v, -c)), degree 0 is paired by a union-find over the edges instead of by reducing the vertices' coboundaries: the elder rule, with the indicator of the dying component as the cocycle, as in engine 4. A stream with another kind of edge (a Morse complex or a hand-built chain complex may have one), or an edge with a face outside the stream, reduces degree 0 like every other degree. CellularCohomologyEngine(useUnionFind = false) always reduces; PackedCubicalCohomologyEngine takes the same option.
Simplices on flat arrays. When the cells are simplices with Int vertices and the cell instance is the library's own (simplexIsOrderedCell, which every complex the library builds uses), the engine works on arrays instead of Simplex objects: each dimension's vertex tuples in the engine's order, a table from a tuple to its cell number (the vertices side by side in one Long when they fit, else a hash of them), and each coboundary block as compressed columns of signs, found and laid out on all threads. Degrees above the stream's homologyDegreeLimit are not reduced. A column whose first row is free is paired without building anything. A column that needs an addition is reduced by Chain.reduceBy as before, with the columns it adds built on demand, so the bars and representatives are exactly those of reducing the cells. Cycles take the same route: a death cell whose youngest face is its birth cell needs no reduction, and only the representatives returned are turned back into Simplex objects. CellularCohomologyEngine(packSimplices = false) reduces the cells themselves, and reducesPacked(stream) says which a stream gets. Other vertex types, a vertex order other than Int's and a cell instance of your own fall back to the cells.
Experiments: edge blocks on threads. Two JVM-only objects try reducing Vietoris-Rips cohomology in parallel, with each degree cut into units of whole edge blocks (a simplex's block is its first longest edge): BlockParallelReduction on explicit coboundary matrices, ParallelPackedCohomology on implicit ones, as engine 4 computes them (its key is one Long where the block and the index fit, else the block beside the index; the index itself is still one Long). Both give exactly the pairs of a sequential reduction. BlockParallelReduction builds its matrices in full, returns bars only and Persistence does not call it. ParallelPackedCohomology pairs degree 0 by union-find over the edges in order (a MergeForest keeps the merge history, so a bar's cocycle is read off it when asked for), and reduces the other degrees. With cocycles = true it keeps a Log per reduced column (the columns added to it and their factors; an apparent pair has none), from which cocycle(degree, p, column) builds a bar's cocycle, and with keepPairs the pairing. Persistence.Engine.ParallelRipser runs it: Persistence.Input.parallelRipser calls the seam ParallelRipser.run (shared code: 8 units per thread of Parallel.threads, run by Parallel.tasks, which pulls them from a counter on the JVM and runs them in order on Scala.js; Auto only asks with several threads, which JavaScript never has) and gets a ParallelRipserRun, the engine's keys and logs without its types, which is all the shared Persistence code sees. Each bar's chain is a LazyChain: a cocycle is built from the logs when read, a cycle comes out of one pass of Involution.cycles over the keys (ParallelRipserCycles, with the shortcut of CellularCohomologyEngine: a death simplex whose youngest face is its birth needs no reduction; the death simplices that do need one are found by a parallel scan of faces over every death, which is most of the pass, and their reductions then run in order, one death dimension to a thread). Keys of one dimension ascend with age, which is the order Involution is given, reversed. Cycles need one-word keys; two-word keys give cocycles only. computeAllRepresentatives forces the chains before returning (cocycles on all threads). Engine.Auto chooses the engine when Parallel.threads > 1, the input is a Vietoris-Rips metric space, there is no includeZeroLength, and ParallelRipser.supports (a prime up to 46,000, indices that fit 63 bits). Edge ranks are a dense n x n table up to DenseRankLimit (4,096) points and sorted neighbour lists above it, so memory follows the edges within the threshold. The edge list comes from the space's neighbourListsWithin: a Euclidean cloud above the distance cache (MaxCachedPoints, 8,192 points) answers with one vantage-point-tree query per point on all threads, and the lists, and the longest edge the verb reads off them, are those of the pass over all pairs bit for bit; where a query would measure more than a quarter of the points (a threshold that keeps most pairs), or for any other space, the n-squared pass builds them. Persistence's threads option runs the call in Parallel.withThreads(n) (a fork-join pool of that size on the JVM, none in JavaScript), and the lazy chains keep the count they were made under (Parallel.limit, Parallel.limited). The MATLAB facade and the CLI do the same through threads, and send an unset engine for the Vietoris-Rips complex over Z/p (no includeZeroLength, no edgeCollapse) to this engine when Parallel.threads > 1 (parallelVR); engine=ripser stays PackedRipserCohomologyEngine. The benchmark harness runs the engine directly as engine=parallel (tda4j-parallel-1t/-mt, bars only, with threads and wide; it tabulates the distances, so it takes up to 60,000 points) and through Persistence as engine=parallelverb (tda4j-parallelverb-1t/-mt, with representatives).
6. FastCubicalHomologyEngine — dual-graph union-find
FastCubicalHomologyEngine is specialized to CubicalGridStream.
It computes H_0 by primal union-find and H_{d-1} by applying Alexander duality to a dual graph and running union-find in reverse filtration order. For ambient dimension d >= 3, intermediate dimensions 1 <= k <= d-2 go to cohomology on the grid without its top cells (PackedCubicalCohomologyEngine, cycles by the involution).
The engine is valid for ambient dimension >= 2 and avoids general Chain reduction in the two shortcut dimensions, H_0 and H_{d-1}.
persistentHomology(grid, includeZeroLength, maxDimension) stops at degree maxDimension: the dual graph is walked only when the top degree d - 1 is asked for, and the middle degrees are reduced on the grid cut to dimension maxDimension + 1, the same shape as FastAlphaHomologyEngine.
A masked (NaN) pixel is not in the complex. In the dual graph it is present from the start, like the outside of the grid, and a masked region that dies gives an essential bar.
Representatives are reconstructed from the active dual components so the result remains compatible with the rest of the persistence API. A bar's cycle is the boundary of the region that dies, summed from its top cells, so a bar costs the size of its region. Of two components born at the same value either may die and the bars are the same; the smaller one does, so that a tiling, with an equal maximum in every tile, does not make the large region die over and over. A large region can still die when it is the younger of two by value, and is then walked whole.
Its pieces are public:
SignedUnionFind[C](size)is a union-find whose elements carry an orientation in the fieldC.union(young, old, flip)hangs one root under another and multiplies the young component's orientations byflip;findcomposes orientations along the path;members(root)lists a frozen region with its orientations relative to the root, which is how a representative is read off.UnitSignedUnionFind(size)is the same with orientations±1kept in bytes, exact whenever every flip is±1as in the cubical dual, and it counts each component's elements (sizeOf(root)).DoubledGridwalks the doubled grid (coordinate2ais the pointa,2a + 1the interval[a, a + 1]) one prefix at a time, so a caller can run a tight loop along the last axis.GridCellOrderis the orderPackedCubicalCohomologyEngineputs on the cubes of one grid: the rank of a cell's value, then its doubled-grid index.LimitedCubicalGridStream(stream, maxDim)is a grid stream cut off above a cell dimension, with the same values and order; the engine uses it for the degrees betweenH_0andH_{d-1}.
7. FastAlphaHomologyEngine — dual union-find for alpha complexes
FastAlphaHomologyEngine applies the same dual-graph union-find strategy as FastCubicalHomologyEngine to a Delaunay triangulation (BowyerWatsonDelaunay or HelixDelaunay).
It requires a full triangulation and is not compatible with the DQP alpha backends. As with the cubical engine, H_0 and H_{d-1} use union-find and intermediate dimensions go to CellularCohomologyEngine (cycles by the involution). maxDimension caps the degrees: the cohomology engine then sees the stream only up to dimension maxDimension + 1, and the dual graph is walked only when the cap reaches d - 1. persistentHomologyTopDegree is that dual pass alone.
The dual construction assumes each facet has at most two cofaces. BowyerWatsonDelaunay's exact predicates guarantee this. HelixDelaunay can violate it in rare degenerate configurations, so the engine validates the triangulation and throws FastAlphaTriangulationException rather than returning an invalid result.
See Alpha complex for backend limitations and triangulation repair.
Harmonic chains: HarmonicChainBarcode and HarmonicRepresentatives
These are not engines in the sense above: they do not reduce the boundary matrix to find a barcode, they follow the harmonic chains ker ∂_p ∩ ker ∂_{p+1}ᵀ along a simplex-wise filtration, over a field with an inner product (the reals or Coefficients.Rationals; a finite field is refused, since the dot product is not positive definite there). Both live in homology/ and read any StratifiedCellStream with an OrderedCell, and the facades expose them for Vietoris-Rips.
HarmonicChainBarcode is Algorithm 1 of Hou, Parsa and Wang. One Run inserts the cells in the order value, then dimension, then the stream's order within a dimension (insertionOrder; ofOrder takes any order). A positive cell creates a harmonic cycle: the unique cycle with coefficient 1 on the birth cell that is orthogonal to the older cycles, which is the paper's φ. Orthogonalization chooses how it is found. GramSchmidt (the default) takes the cycle that the standard reduction records for the cell (the V column) and makes it orthogonal to an orthogonal basis of all cycles of the degree kept so far (no square roots, so it is exact over the rationals). LaplacianSolve keeps no basis: with ∂ the boundary of the cells of the degree that entered before the cell, the chain is z = e_σ + ∂ᵀy where (∂∂ᵀ) y = -∂ e_σ, solved by conjugate gradient (exact over the rationals, where it finishes in as many steps as the rank), and the memory is the boundaries and an index of the cofaces. Over the rationals the two give the same chains, term for term. Over the reals every decision of the algorithm is a comparison with the field's tolerance, so on a large complex with many nearly tied values a cycle that is almost orthogonal to a boundary can be judged differently, and the two can pair a few bars differently, and Coefficients.Rationals gives the exact pairing. The solve therefore stops only when its residual is zero to far below the tolerance, and says what to use instead if it cannot get there. A negative cell ends the oldest alive chain that is not orthogonal to its boundary, and subtracts a multiple of it from the others that are not. The invariants that the specs test, against oracles that share no code with the algorithm: the number of bars alive at each value is the Betti number there; the births and deaths are those of the ordinary barcode; every chain is a cycle orthogonal to all boundaries at every value of its bar (Definition 11 of the paper); the barcode equals the one read off the zigzag of the harmonic spaces by counting dim ∩ V_k over each interval.
HarmonicRepresentatives replaces the representatives of an ordinary diagram by the harmonic cycles at the births (Basu and Cox). It reuses the Run's snapshots of the harmonic chains at the values involved, and for each group of bars with one pair of endpoints solves P^{s,t} = M^{s,t} ∩ (N^{s,t})^⊥ in coordinates of the chains at the birth value; the specs check it against the definition of P written out in chain coordinates over the rationals. It depends on the filtration's values and not on how equal values are ordered. With representatives = Representatives.Cocycles it gives the harmonic cocycle of each bar instead: cochains and chains share one coordinate system (the cells are orthonormal), so the harmonic cochains are the harmonic chains, but the maps of the persistence module of cohomology go from a later value to an earlier one and are the orthogonal projections of the harmonic spaces, so the bar [s, t) is born, in cohomology, at the last value before t, and the same construction runs with the values reversed.
What does not carry over from the engines above: clearing and apparent pairs give each cell's sign but not the pairing the harmonic rule chooses, and a reduction of the complex (discrete Morse theory, edge collapse) changes the inner product, so it changes the harmonic barcode. The cost is cubic in the number of cells in the worst case; the memory is the orthogonal cycle basis of a degree with GramSchmidt and the boundaries of the degree with LaplacianSolve.
Querying a run: the cursor
Engine 1's HomologyState is a cursor over the stream:
advanceOne(),advanceTo(f)andadvanceAll()move it;advanceFor(budget)runs it for a time-boxed slice;processedCellsandtotalCellsreport progress.
It exists so that a long run can be inspected while it runs, and keeps its output if it dies.
Queries do not depend on where the cursor is. diagramAt(f), barcodeAt(f) and diagramWithGeneratorsAt(f) give the diagram truncated at f:
- bars born at or before
f, with their deaths capped atf; - a class alive at
fis reported as dying atf, or as essential when no cell enters afterf.
A query past the cursor advances it as far as it needs. A query below the cursor gives what a fresh cursor would. snapshotAt(f) copies the answer into an immutable PersistenceDiagram.
Engine 2 answers diagramAt(f) and barcodeAt(f) with the same contract, but it runs the whole reduction on its first query and has no cursor.
Cycles and cocycles from one pairing: Involution
Every engine but the fast ones and the Ripser oracle (engine 3, cocycles only) gives both kinds of representative. It computes one kind natively and derives the other from its own pairing (homology/Involution.scala, after Čufar and Virk, arXiv:2105.03629).
Cycles from a cohomology pairing (Involution.cycles). Only the boundary columns of death cells are reduced, youngest cell first:
- a finite bar
(σ, τ)getsR_τ, the reduced boundary ofτ, a cycle whose youngest cell isσ; - an essential bar gets the cycle the reduction of
∂σto zero produces.
Engines 4, 5 and the packed cubical class expose this as persistentHomology. Engines 4 and 5 also return the bars with their birth and death cells through pairedCohomology.
Cocycles from a homology pairing (Involution.cocycles, cocycleBars). Only the coboundary columns of birth cells are reduced, built from the stream by coboundariesOf; the representative is the V-column V_σ. Engines 1 and 2 expose a pairing for this.
The pairing must come from the same total order the involution reduces under, and every pivot is checked against the paired cell. A mismatch throws; it is a bug in the pairing or the order, so never fall back. Zero-length pairs must be present: their columns are pivots for the others.
The engines give different, equally valid representatives. Never compare representatives cell for cell across engines; check that each one is a cycle (or cocycle) present at the bar's birth. The fast engines have no derived kind: their union-finds break ties by value rather than by the stream's order. Image cocycles go through Engine.Cohomology.
Circular coordinates from a diagram
CircularCoordinates(diagram, input, ...) turns a degree-1 bar of any PersistenceDiagram[Simplex[Int]] into a map to the circle. A finite bar's cocycle V_σ has σ as its oldest cell and a coboundary that starts at the death cell, so restricted to the complex K_r at a scale r inside the bar it is a cocycle, and it is non-zero there. The diagram records which kind it carries (PersistenceDiagram.representatives); a diagram of cocycles supplies the class directly, and a diagram of cycles has it recovered by the cohomology of K_r over the diagram's field, matched to the bar by its birth. Both lift to integers (checked exactly on every triangle) and are smoothed to the harmonic representative.
A bar's class is only defined up to adding the classes of shorter bars nested inside it. When such bars are alive at r, the engines' representatives, and so their coordinates, differ; every one is a valid circle map. To compare two routes, choose r where only the loops asked for are alive.
Streams × engines: what works with what
Not every engine supports every complex construction. ripser relies on Vietoris-Rips-specific assumptions about the filtration and representation, while fast-cubical and fast-alpha operate only on their corresponding concrete constructions. The generic engines (naive, chunks, and cohomology) support a broader set of streams, subject to the exceptions listed below.
Complex (complex=) |
Default engine | ripser |
naive |
chunks |
cohomology |
fast-cubical |
fast-alpha |
|---|---|---|---|---|---|---|---|
vr |
ripser |
yes | yes | yes | yes | no | no |
cech |
cohomology |
no — not a max-pairwise-distance functional (radius, not diameter) | yes | yes | yes | no | no |
witness, witnessVariant=lazy |
ripser |
yes — a flag complex under its own reified WitnessMetricSpace |
yes | yes | yes | no | no |
witness, witnessVariant=general |
cohomology |
no — not a flag complex (dimension-specific threshold) | yes | no | yes | no | no |
dtm-rips |
cohomology |
no — vertices aren't born at 0, and the weighted-Rips functional isn't insertionDiameter-compatible |
yes | yes | yes | no | no |
dtm-alpha |
cohomology |
no — no notion of a Vietoris-Rips complex at all | yes | no — shares AlphaComplexDQP's known stall/OOM risk (see alpha-complex.md) |
yes | no | no — always uses AlphaComplexDQP, never a triangulation |
alpha |
cohomology |
no — no notion of a Vietoris-Rips complex at all | yes | no — known stall/OOM risk | yes | no | yes — only a triangulating alphaBackend (default, bowyer-watson, helix), any ambient dimension >= 2 |
sheehy-rips |
cohomology |
no — a simplex's value is not the maximum ambient pairwise distance among its vertices (some pairs sparsified away, others excluded outright) | yes | yes | yes | no | no |
cubical (computeFromCubicalImage/computeFromImage, no complex key) |
fast-cubical (2-D and up) |
no — PackedRipserCohomologyEngine is specialized to Simplex[Int] |
yes | yes | yes | yes — any ambient dimension >= 2 |
no |
Dowker relation (computeFromRelation, no complex key) |
cohomology |
no — not a flag complex (edges seen by different witnesses need not have one witness for the whole simplex) | yes | no — same conservative refusal witness/general has (use naive/cohomology) |
yes | no | no |
| simplicial sets | (no matlab/cli entry point at all — construct SimplicialSetStream/FilteredSimplicialSetStream and drive any generic engine directly) |
Unsupported combinations fall into a few categories:
- Non-flag filtrations — Cech, general witness, Dowker, and Sheehy cannot use VR-specific packed Ripser assumptions.
- Non-VR constructions — alpha complexes do not have the metric-space / clique representation the Ripser engines require.
- Weighted flag filtrations — DTM-Rips is combinatorially a flag complex, but its filtration is incompatible with Ripser's diameter-specific optimizations.
- Representation-specific engines —
fast-cubicalandfast-alphaoperate only on their corresponding concrete constructions.
engine="cohomology" (CellularCohomologyEngine, engine 5 above) is the one column with no "no" cells because it is generic over CellT: OrderedCell and assumes nothing about the construction; the price is that it lacks engines 3 and 4's Vietoris-Rips-specific optimizations.
Representatives through the facades. matlab.TDA4j takes the option representativeType, cycles (the default) or cocycles, and the CLI takes --representative-type with the same values. fast-cubical and fast-alpha give cycles only and refuse cocycles with a message that names cohomology. Every other engine gives both kinds, the second through Involution.
PersistenceResult.cycleVertices(i) and cycleCoefficients(i) return bar i's representative of either kind:
- a simplex as its sorted vertices;
- a cube as its doubled coordinates;
- a coefficient of
Z/pas an integer representative.
The CLI prints representatives with --representatives (text output only).
Choosing an engine
Most callers should not choose: Persistence(...) with Engine.Auto picks packed Ripser for Vietoris-Rips on points, fast cubical for images (when cycles are asked for) and cohomology for everything else. See The public API. The table is for building on an engine directly.
| Need | Engine |
|---|---|
Exploration, intermediate-filtration queries, representative cycles, any OrderedCell type |
CellularHomologyEngine |
| Large complex, chunked/parallelizable, representatives for every bar including essential ones | CellularPersistenceInChunksEngine |
| Fast, memory-efficient cohomology on a Vietoris-Rips/clique complex over integer vertex labels | PackedRipserCohomologyEngine (what engine="ripser" uses) |
A Simplex[Int]-keyed reference implementation for hand-debugging engine 4 |
RipserCohomologyEngine (test oracle, not a production choice) |
Cohomology (real cocycle representatives) on Cube/FiniteSimplicialSet/Cech/Alpha/general witness complex, or any OrderedCell type engines 3/4 can't serve |
CellularCohomologyEngine (what engine="cohomology" uses) |
Fastest option for a cubical grid of any ambient dimension >= 2 (no Chain reduction at all for H_0/H_{d-1}; a cohomology hybrid for any residual middle dimensions at d >= 3) |
FastCubicalHomologyEngine (what engine="fast-cubical" uses) |
Fastest option for an alpha complex via a triangulation (BowyerWatsonDelaunay up to 4-D, HelixDelaunay any ambient dimension >= 2; same hybrid shape as FastCubicalHomologyEngine; on Helix noticeably more likely to throw FastAlphaTriangulationException at higher ambient dimension/point count) |
FastAlphaHomologyEngine (what engine="fast-alpha" uses) |