Overview
Computational topology. Depends on riptide_numerics_spatial (Delaunay for alpha complexes, KD-tree for mapper).
| Area | API |
|---|---|
| Complexes | SimplicialComplex (closure, skeleta, faces/cofacets, link, star, cone, suspension), CellComplex (CW: RP^n, lens spaces, surfaces), CubicalComplex (images, voxels, periodic tori) — all ChainComplex |
| Homology | homology / cohomology over Z with torsion (SparseIntMatrix.invariantFactors: sparse unit-pivot elimination then dense Smith normal form), bettiNumbers(prime:) over Q or \frac{Z}{p}, eulerCharacteristic, SmithNormalForm.of with U, V |
| Persistence | FilteredComplex (any filtration, lowerStar), reduction over \frac{Z}{p} with clearing; VietorisRips (Ripser-style cohomology), AlphaComplex (2-D/3-D, squared radii), CubicalComplex.topValues / vertexValues; PersistenceDiagram, bottleneckDistance, wassersteinDistance |
| Mapper | mapper(points, dim, lens, intervals, overlap, epsilon:) → nodes and nerve |
| \pi_{1} | fundamentalGroup(complex) → GroupPresentation (Tietze-simplified), abelianization |
| Morse | DiscreteGradient.lowerStar, Morse numbers and inequalities, MorseSmaleComplex (arcs saddle → min/max), plCriticalPoints |
| Manifolds | TriangulatedSurface (orientability, boundary circles, classification, connected sum, orientation double cover), Triangulated3Manifold (vertex links, orientability), Triangulations (tetrahedron, octahedron, 7-vertex torus, 6-vertex RP², Möbius band, grids, Klein bottle, genus g, S^{3}, T^{n}), cyclicCover |
Rational-first: RationalVietorisRips and RationalAlphaComplex take rational points (Vec<Rational> from riptide_rational_geometry) and compute every filtration value exactly — blue quadrances for Rips, squared circumradii for alpha — so births, deaths and ties are exact rationals (RationalPersistenceDiagram, bettiAt decided exactly). Persistence depends only on the order of the values, so the reduction runs on their ranks; distances and radii are derived float views (toDistanceDiagram). The alpha complex's Delaunay triangulation comes from the float Delaunay and is checked with exact in-circle / in-sphere predicates (isExactlyDelaunay, O(n \cdot T)).
Functions and constants
Functions
SimplicialComplex cyclicCover(SimplicialComplex k, int n, int Function(int a, int b) voltage)The n-sheeted cyclic cover of k defined by a 1-cocycle with values in Z/n: voltage (a, b) for a < b is the sheet shift along the edge a \to b (b → a shifts by its negative), and it must add to 0 \bmod n around every triangle. Upstairs, vertex (v, i) is numbered v \cdot n + i and each simplex [v_{0} \cdots v_{k}] lifts to n copies, sheet i sending v_{j} to sheet i + \operatorname{voltage}(v_{0}, v_{j}). The cover is connected when the voltages generate \frac{Z}{n} on loops.
import 'package:riptide_topology/riptide_topology.ray';
import 'package:riptide_rational_geometry/riptide_rational_geometry.ray' show qv, Vec;
import 'package:riptide_precision/riptide_precision.ray' show Rational;
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f4(num x) => x.isInfinite ? '∞' : x.toStringAsFixed(4);
void main() {
// The 3-fold cyclic cover of a triangle (a circle) by the voltage 1 on one edge: a 9-cycle.
final tri = SimplicialComplex([[0, 1], [1, 2], [0, 2]]);
final c = cyclicCover(tri, 3, (a, b) => a == 0 && b == 1 ? 1 : 0);
print('vertices ${c.cellCount(0)}, edges ${c.cellCount(1)}, betti ${c.bettiNumbers()}');
}vertices 9, edges 9, betti [1, 1]
Map<String, Object?> barcodeScene(PersistenceDiagram diagram, {String id = 'topology.barcode', String title = 'Persistence barcode', String axisLabel = 'scale', int maxBarsPerDimension = 12})A scene that draws diagram's barcode, one dimension per step (H_{0}, H_{1}, H_{2} in the palette's v1, v2, v3), with a labelled filtration axis. Essential bars run to the right edge and end in \infty. At most maxBarsPerDimension of the longest bars are drawn per dimension.
import 'package:riptide_topology/riptide_topology.ray';
import 'package:riptide_rational_geometry/riptide_rational_geometry.ray' show qv, Vec;
import 'package:riptide_precision/riptide_precision.ray' show Rational;
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f4(num x) => x.isInfinite ? '∞' : x.toStringAsFixed(4);
void main() {
final d = VietorisRips.points(Float64List.fromList([0, 0, 1, 0, 0, 1, 1, 1]), 2).persistence();
print(barcodeScene(d).keys.toList());
}[id, title, view, objects, steps]
GroupPresentation fundamentalGroup(SimplicialComplex k, {int? base, bool simplify = true})\pi_{1}(K, base) of the component of base (default: the smallest vertex): generators are the edges outside a breadth-first spanning tree, relators are the triangles (the edge-path group), then Tietze-simplified unless simplify is false.
import 'package:riptide_topology/riptide_topology.ray';
import 'package:riptide_rational_geometry/riptide_rational_geometry.ray' show qv, Vec;
import 'package:riptide_precision/riptide_precision.ray' show Rational;
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f4(num x) => x.isInfinite ? '∞' : x.toStringAsFixed(4);
void main() {
final g = fundamentalGroup(Triangulations.torus7().complex);
print('π₁(torus) = $g, abelianised ${g.abelianization()}');
final rp2 = fundamentalGroup(Triangulations.projectivePlane6().complex);
print('π₁(RP²) = $rp2');
}π₁(torus) = ⟨a, b | aba⁻¹b⁻¹⟩, abelianised Z^2 π₁(RP²) = ⟨a | a⁻¹a⁻¹⟩
MapperGraph mapper(Float64List points, int dim, List<double> lens, {int intervals = 10, double overlap = 0.3, required double epsilon, int maxDim = 2})Mapper of points (dim coordinates each) through lens (one value per point): intervals equal intervals overlapping by the fraction overlap of their length, each preimage clustered by single linkage at distance epsilon (connected components of the epsilon-neighbourhood graph, found with a KD-tree). maxDim bounds the nerve's dimension.
import 'package:riptide_topology/riptide_topology.ray';
import 'package:riptide_rational_geometry/riptide_rational_geometry.ray' show qv, Vec;
import 'package:riptide_precision/riptide_precision.ray' show Rational;
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f4(num x) => x.isInfinite ? '∞' : x.toStringAsFixed(4);
void main() {
// 32 points on the unit circle, coloured by x.
final pts = Float64List.fromList([for (var i = 0; i < 32; i++) ...[math.cos(i * math.pi / 16), math.sin(i * math.pi / 16)]]);
final m = mapper(pts, 2, [for (var i = 0; i < 32; i++) pts[2 * i]], intervals: 4, overlap: 0.4, epsilon: 0.3);
print('${m.nodes.length} nodes; betti of the nerve ${m.nerve.bettiNumbers()}');
}6 nodes; betti of the nerve [1, 1]
int modInverse(int a, int p)a^{-1} mod p for prime p.
import 'package:riptide_topology/riptide_topology.ray';
import 'package:riptide_rational_geometry/riptide_rational_geometry.ray' show qv, Vec;
import 'package:riptide_precision/riptide_precision.ray' show Rational;
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f4(num x) => x.isInfinite ? '∞' : x.toStringAsFixed(4);
void main() {
print('3⁻¹ mod 7 = ${modInverse(3, 7)}');
}3⁻¹ mod 7 = 5
List<PlCriticalPoint> plCriticalPoints(TriangulatedSurface surface, double Function(int vertex) f)The PL critical points of f on a closed surface; their indices add up to \chi.
import 'package:riptide_topology/riptide_topology.ray';
import 'package:riptide_rational_geometry/riptide_rational_geometry.ray' show qv, Vec;
import 'package:riptide_precision/riptide_precision.ray' show Rational;
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f4(num x) => x.isInfinite ? '∞' : x.toStringAsFixed(4);
void main() {
final s = Triangulations.torus7();
final cps = plCriticalPoints(s, (v) => v.toDouble());
print([for (final c in cps) '${c.vertex}:${c.kind}'].join(' '));
print('Σ index = ${cps.fold<int>(0, (a, c) => a + c.index)} = χ = 0');
}0:min 2:saddle 4:saddle 6:max Σ index = 0 = χ = 0
double bottleneckDistance(List<(double, double)> a, List<(double, double)> b)The bottleneck distance between two diagrams given as (birth, death) points (death may be infinite), with the L\infty ground metric and every point free to go to the diagonal.
import 'package:riptide_topology/riptide_topology.ray';
import 'package:riptide_rational_geometry/riptide_rational_geometry.ray' show qv, Vec;
import 'package:riptide_precision/riptide_precision.ray' show Rational;
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f4(num x) => x.isInfinite ? '∞' : x.toStringAsFixed(4);
void main() {
print(f4(bottleneckDistance([(0.0, 1.0), (0.2, 0.5)], [(0.0, 1.1)])));
}0.1500
double wassersteinDistance(List<(double, double)> a, List<(double, double)> b, {double q = 1})The q-Wasserstein distance (L\infty ground metric) between two diagrams: the optimal assignment of points to points or to the diagonal, by the Hungarian algorithm.
import 'package:riptide_topology/riptide_topology.ray';
import 'package:riptide_rational_geometry/riptide_rational_geometry.ray' show qv, Vec;
import 'package:riptide_precision/riptide_precision.ray' show Rational;
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f4(num x) => x.isInfinite ? '∞' : x.toStringAsFixed(4);
void main() {
print(f4(wassersteinDistance([(0.0, 1.0), (0.2, 0.5)], [(0.0, 1.1)])));
}0.2500
double hungarian(List<List<double>> cost)The minimum total cost of a perfect assignment in a square cost matrix (Kuhn–Munkres with potentials, O(n^{3})).
import 'package:riptide_topology/riptide_topology.ray';
import 'package:riptide_rational_geometry/riptide_rational_geometry.ray' show qv, Vec;
import 'package:riptide_precision/riptide_precision.ray' show Rational;
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f4(num x) => x.isInfinite ? '∞' : x.toStringAsFixed(4);
void main() {
print(hungarian([[4, 1, 3], [2, 0, 5], [3, 2, 2]]));
}5.0
Constants and variables
const int rationalPrime = 2147483647A prime above 2^{30} whose products fit in 64 bits: rank mod it equals the rank over Q unless it divides a torsion coefficient (which would need a coefficient this large).
Typedefs
typedef Cell = ({int dim, int index})A cell of a simplicial complex: its dimension and index within that dimension.
Classes
AlphaComplex
final class AlphaComplex
An alpha complex in 2-D or 3-D.
import 'package:riptide_topology/riptide_topology.ray';
import 'package:riptide_rational_geometry/riptide_rational_geometry.ray' show qv, Vec;
import 'package:riptide_precision/riptide_precision.ray' show Rational;
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f4(num x) => x.isInfinite ? '∞' : x.toStringAsFixed(4);
void main() {
// Eight points on a circle of radius 1 (rounded to 4 decimals for display).
final pts = Float64List.fromList([for (var i = 0; i < 8; i++) ...[math.cos(i * math.pi / 4), math.sin(i * math.pi / 4)]]);
final a = AlphaComplex(pts, 2);
final d = a.persistence();
print('H1 intervals: ${[for (final p in d.inDimension(1)) '[${f4(p.birth)}, ${f4(p.death)})']}');
}H1 intervals: [[0.1464, 1.0000)]
Constructors
factory AlphaComplex(Float64List points, int dim)import 'package:riptide_topology/riptide_topology.ray';
import 'package:riptide_rational_geometry/riptide_rational_geometry.ray' show qv, Vec;
import 'package:riptide_precision/riptide_precision.ray' show Rational;
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f4(num x) => x.isInfinite ? '∞' : x.toStringAsFixed(4);
void main() {
// Eight points on a circle of radius 1 (rounded to 4 decimals for display).
final pts = Float64List.fromList([for (var i = 0; i < 8; i++) ...[math.cos(i * math.pi / 4), math.sin(i * math.pi / 4)]]);
print('${AlphaComplex(pts, 2).complex.cellCount(2)} Delaunay triangles');
}6 Delaunay triangles
Properties
final Float64List pointsfinal int dimfinal List<Float64List> valuesThe filtration value (squared radius) of each simplex, by dimension and index.
FilteredComplex get filtrationMethods
SimplicialComplex at(double alpha2)The subcomplex at squared radius ≤ alpha2.
import 'package:riptide_topology/riptide_topology.ray';
import 'package:riptide_rational_geometry/riptide_rational_geometry.ray' show qv, Vec;
import 'package:riptide_precision/riptide_precision.ray' show Rational;
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f4(num x) => x.isInfinite ? '∞' : x.toStringAsFixed(4);
void main() {
// Eight points on a circle of radius 1 (rounded to 4 decimals for display).
final pts = Float64List.fromList([for (var i = 0; i < 8; i++) ...[math.cos(i * math.pi / 4), math.sin(i * math.pi / 4)]]);
final a = AlphaComplex(pts, 2);
for (final r2 in [0.1, 0.2, 1.0]) print('α² = $r2: betti ${a.at(r2).bettiNumbers()}');
}α² = 0.1: betti [8] α² = 0.2: betti [1, 1] α² = 1.0: betti [1, 1, 0]
PersistenceDiagram persistence({int prime = 2})import 'package:riptide_topology/riptide_topology.ray';
import 'package:riptide_rational_geometry/riptide_rational_geometry.ray' show qv, Vec;
import 'package:riptide_precision/riptide_precision.ray' show Rational;
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f4(num x) => x.isInfinite ? '∞' : x.toStringAsFixed(4);
void main() {
// Eight points on a circle of radius 1 (rounded to 4 decimals for display).
final pts = Float64List.fromList([for (var i = 0; i < 8; i++) ...[math.cos(i * math.pi / 4), math.sin(i * math.pi / 4)]]);
print(AlphaComplex(pts, 2).persistence().inDimension(1).length);
}1
ChainComplex
abstract interface class ChainComplex
A finite chain complex of free abelian groups: C_{k} has cellCount (k) generators and \partial_{k}: C_{k} \to C_{k - 1} is boundary (k) (a cellCount(k−1) × cellCount(k) matrix; \partial_{0} = 0).
import 'package:riptide_topology/riptide_topology.ray';
import 'package:riptide_rational_geometry/riptide_rational_geometry.ray' show qv, Vec;
import 'package:riptide_precision/riptide_precision.ray' show Rational;
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f4(num x) => x.isInfinite ? '∞' : x.toStringAsFixed(4);
void main() {
// Any finite chain complex: here the torus as a CW complex.
final ChainComplex t = CellComplex.orientableSurface(1);
print('cells ${[for (var k = 0; k <= 2; k++) t.cellCount(k)]}, H = ${t.homology()}');
}cells [1, 2, 1], H = [Z, Z^2, Z]
Properties
Methods
int cellCount(int k)import 'package:riptide_topology/riptide_topology.ray';
import 'package:riptide_rational_geometry/riptide_rational_geometry.ray' show qv, Vec;
import 'package:riptide_precision/riptide_precision.ray' show Rational;
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f4(num x) => x.isInfinite ? '∞' : x.toStringAsFixed(4);
void main() {
print(SimplicialComplex.sphere(2).cellCount(1));
}6
SparseIntMatrix boundary(int k)import 'package:riptide_topology/riptide_topology.ray';
import 'package:riptide_rational_geometry/riptide_rational_geometry.ray' show qv, Vec;
import 'package:riptide_precision/riptide_precision.ray' show Rational;
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f4(num x) => x.isInfinite ? '∞' : x.toStringAsFixed(4);
void main() {
print(SimplicialComplex.simplex(2).boundary(2).toDense());
}[[1], [-1], [1]]
HomologyGroup
final class HomologyGroup
A finitely generated abelian group Z^rank ⊕ \frac{Z}{t_{1}} \oplus \cdots \oplus \frac{Z}{t_{m}}.
import 'package:riptide_topology/riptide_topology.ray';
import 'package:riptide_rational_geometry/riptide_rational_geometry.ray' show qv, Vec;
import 'package:riptide_precision/riptide_precision.ray' show Rational;
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f4(num x) => x.isInfinite ? '∞' : x.toStringAsFixed(4);
void main() {
print('Z² ⊕ Z/2 = ${HomologyGroup(2, [2])}');
}Z² ⊕ Z/2 = Z^2 ⊕ Z/2
Constructors
const HomologyGroup(this.rank, [this.torsion = const []])import 'package:riptide_topology/riptide_topology.ray';
import 'package:riptide_rational_geometry/riptide_rational_geometry.ray' show qv, Vec;
import 'package:riptide_precision/riptide_precision.ray' show Rational;
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f4(num x) => x.isInfinite ? '∞' : x.toStringAsFixed(4);
void main() {
print('${HomologyGroup(1)}, ${HomologyGroup(0, [2, 4])}');
}Z, Z/2 ⊕ Z/4
Properties
final int rankbool get isTrivialint get hashCodeMethods
String toString()Operators
bool operator ==(Object other)import 'package:riptide_topology/riptide_topology.ray';
import 'package:riptide_rational_geometry/riptide_rational_geometry.ray' show qv, Vec;
import 'package:riptide_precision/riptide_precision.ray' show Rational;
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f4(num x) => x.isInfinite ? '∞' : x.toStringAsFixed(4);
void main() {
print(CellComplex.realProjectiveSpace(2).homology()[1] == HomologyGroup(0, [2]));
}true
Homology
extension Homology on ChainComplex
Homology and cohomology of any ChainComplex.
import 'package:riptide_topology/riptide_topology.ray';
import 'package:riptide_rational_geometry/riptide_rational_geometry.ray' show qv, Vec;
import 'package:riptide_precision/riptide_precision.ray' show Rational;
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f4(num x) => x.isInfinite ? '∞' : x.toStringAsFixed(4);
void main() {
for (final n in [2, 3, 4]) print('RP^$n: ${CellComplex.realProjectiveSpace(n).homology()}');
}RP^2: [Z, Z/2, 0] RP^3: [Z, Z/2, 0, Z] RP^4: [Z, Z/2, 0, Z/2, 0]
Properties
int get eulerCharacteristic\chi = \sum (-1)^{k} · #k-cells (= \sum (-1)^{k} b_{k} over any field).
bool get isChainComplexWhether \partial_{k - 1} \circ \partial_{k} = 0 for every k (a sanity check on hand-built complexes).
Methods
List<HomologyGroup> homology()H_{k}(C; Z) for k = 0 \cdots dimension, with torsion from the Smith normal form of each \partial.
import 'package:riptide_topology/riptide_topology.ray';
import 'package:riptide_rational_geometry/riptide_rational_geometry.ray' show qv, Vec;
import 'package:riptide_precision/riptide_precision.ray' show Rational;
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f4(num x) => x.isInfinite ? '∞' : x.toStringAsFixed(4);
void main() {
print('Klein bottle: ${CellComplex.nonOrientableSurface(2).homology()}');
}Klein bottle: [Z, Z ⊕ Z/2, 0]
List<HomologyGroup> cohomology()H^{k}(C; Z) = \ker \delta^{k} / im \delta^{k - 1}, \delta^{k} = \partial_{k + 1}^{T}, computed from the coboundary matrices themselves (it agrees with the universal coefficient theorem: free part of H_{k}, torsion of H_{k - 1}).
import 'package:riptide_topology/riptide_topology.ray';
import 'package:riptide_rational_geometry/riptide_rational_geometry.ray' show qv, Vec;
import 'package:riptide_precision/riptide_precision.ray' show Rational;
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f4(num x) => x.isInfinite ? '∞' : x.toStringAsFixed(4);
void main() {
print('RP²: H* = ${CellComplex.realProjectiveSpace(2).cohomology()} (the torsion moves up a degree)');
}RP²: H* = [Z, 0, Z/2] (the torsion moves up a degree)
List<int> bettiNumbers({int? prime})Betti numbers over Q (null) or over the field Z/prime.
import 'package:riptide_topology/riptide_topology.ray';
import 'package:riptide_rational_geometry/riptide_rational_geometry.ray' show qv, Vec;
import 'package:riptide_precision/riptide_precision.ray' show Rational;
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f4(num x) => x.isInfinite ? '∞' : x.toStringAsFixed(4);
void main() {
final k = CellComplex.realProjectiveSpace(2);
print('over Q ${k.bettiNumbers()}, over Z/2 ${k.bettiNumbers(prime: 2)}');
}over Q [1, 0, 0], over Z/2 [1, 1, 1]
CellComplex
final class CellComplex implements ChainComplex
A chain complex given directly by its boundary matrices: CW complexes (RP^n, lens spaces), quotients, or any complex built by hand. boundaries [k - 1] is \partial_{k} for k \ge 1.
import 'package:riptide_topology/riptide_topology.ray';
import 'package:riptide_rational_geometry/riptide_rational_geometry.ray' show qv, Vec;
import 'package:riptide_precision/riptide_precision.ray' show Rational;
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f4(num x) => x.isInfinite ? '∞' : x.toStringAsFixed(4);
void main() {
print('genus 2: ${CellComplex.orientableSurface(2).homology()}, χ ${CellComplex.orientableSurface(2).eulerCharacteristic}');
}genus 2: [Z, Z^4, Z], χ -2
Constructors
CellComplex(this.cellCounts, this.boundaries)import 'package:riptide_topology/riptide_topology.ray';
import 'package:riptide_rational_geometry/riptide_rational_geometry.ray' show qv, Vec;
import 'package:riptide_precision/riptide_precision.ray' show Rational;
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f4(num x) => x.isInfinite ? '∞' : x.toStringAsFixed(4);
void main() {
// A circle: one vertex, one edge with zero boundary.
final c = CellComplex([1, 1], [SparseIntMatrix(1, 1)]);
print(c.homology());
}[Z, Z]
factory CellComplex.realProjectiveSpace(int n)The minimal CW structure of RP^n: one cell per dimension, \partial_{k} = 1 + (-1)^{k} (0 or 2).
import 'package:riptide_topology/riptide_topology.ray';
import 'package:riptide_rational_geometry/riptide_rational_geometry.ray' show qv, Vec;
import 'package:riptide_precision/riptide_precision.ray' show Rational;
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f4(num x) => x.isInfinite ? '∞' : x.toStringAsFixed(4);
void main() {
print(CellComplex.realProjectiveSpace(5).homology());
}[Z, Z/2, 0, Z/2, 0, Z]
factory CellComplex.lensSpace(int p)The lens space L(p, q) (one cell per dimension 0 … 3): \partial_{1} = 0, \partial_{2} = p, \partial_{3} = 0. H = Z, \frac{Z}{p}, 0, Z.
import 'package:riptide_topology/riptide_topology.ray';
import 'package:riptide_rational_geometry/riptide_rational_geometry.ray' show qv, Vec;
import 'package:riptide_precision/riptide_precision.ray' show Rational;
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f4(num x) => x.isInfinite ? '∞' : x.toStringAsFixed(4);
void main() {
print('L(5,1): ${CellComplex.lensSpace(5).homology()}');
}L(5,1): [Z, Z/5, 0, Z]
factory CellComplex.orientableSurface(int g)The closed orientable surface of genus g: one 0-cell, 2g 1-cells, one 2-cell with \partial = \sum (a_{i} + b_{i} - a_{i} - b_{i}) = 0.
import 'package:riptide_topology/riptide_topology.ray';
import 'package:riptide_rational_geometry/riptide_rational_geometry.ray' show qv, Vec;
import 'package:riptide_precision/riptide_precision.ray' show Rational;
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f4(num x) => x.isInfinite ? '∞' : x.toStringAsFixed(4);
void main() {
print(CellComplex.orientableSurface(3).bettiNumbers());
}[1, 6, 1]
factory CellComplex.nonOrientableSurface(int k)The connected sum of k projective planes: one 0-cell, k 1-cells, one 2-cell with \partial = 2(a_{1} + \cdots + a_{k}).
import 'package:riptide_topology/riptide_topology.ray';
import 'package:riptide_rational_geometry/riptide_rational_geometry.ray' show qv, Vec;
import 'package:riptide_precision/riptide_precision.ray' show Rational;
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f4(num x) => x.isInfinite ? '∞' : x.toStringAsFixed(4);
void main() {
print(CellComplex.nonOrientableSurface(3).homology());
}[Z, Z^2 ⊕ Z/2, 0]
Properties
final List<int> cellCountsfinal List<SparseIntMatrix> boundariesint get dimensionMethods
int cellCount(int k)import 'package:riptide_topology/riptide_topology.ray';
import 'package:riptide_rational_geometry/riptide_rational_geometry.ray' show qv, Vec;
import 'package:riptide_precision/riptide_precision.ray' show Rational;
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f4(num x) => x.isInfinite ? '∞' : x.toStringAsFixed(4);
void main() {
print([for (var k = 0; k < 3; k++) CellComplex.orientableSurface(2).cellCount(k)]);
}[1, 4, 1]
SparseIntMatrix boundary(int k)import 'package:riptide_topology/riptide_topology.ray';
import 'package:riptide_rational_geometry/riptide_rational_geometry.ray' show qv, Vec;
import 'package:riptide_precision/riptide_precision.ray' show Rational;
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f4(num x) => x.isInfinite ? '∞' : x.toStringAsFixed(4);
void main() {
print(CellComplex.realProjectiveSpace(2).boundary(2).toDense());
}[[2]]
CubicalComplex
final class CubicalComplex implements ChainComplex
The cubical complex of a grid of shape top-dimensional cubes (pixels, voxels), in Khalimsky coordinates: each cell is a point of the (2n + 1)-per-axis grid (2n when periodic) and its dimension is its count of odd coordinates. With periodic every axis wraps, and the complex is the torus T^{d}.
The filtration follows GUDHI's conventions: CubicalComplex.topValues puts values on the top cubes and a face enters with the lowest cube around it; CubicalComplex.vertexValues puts them on the vertices and a cube enters with its highest vertex.
import 'package:riptide_topology/riptide_topology.ray';
import 'package:riptide_rational_geometry/riptide_rational_geometry.ray' show qv, Vec;
import 'package:riptide_precision/riptide_precision.ray' show Rational;
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f4(num x) => x.isInfinite ? '∞' : x.toStringAsFixed(4);
void main() {
// A 4×4 image with a ring of high values: one H1 class.
final img = [0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0].map((v) => v.toDouble()).toList();
final c = CubicalComplex.topValues([4, 4], img);
print(c.persistence().pairs.map((p) => 'H${p.dimension}[${f4(p.birth)}, ${f4(p.death)})').join(' '));
}H0[0.0000, ∞) H1[0.0000, 1.0000)
Constructors
factory CubicalComplex(List<int> shape, {bool periodic = false})The plain complex (no values): use it for homology.
import 'package:riptide_topology/riptide_topology.ray';
import 'package:riptide_rational_geometry/riptide_rational_geometry.ray' show qv, Vec;
import 'package:riptide_precision/riptide_precision.ray' show Rational;
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f4(num x) => x.isInfinite ? '∞' : x.toStringAsFixed(4);
void main() {
print('3×3 grid of squares: χ = ${CubicalComplex([3, 3]).eulerCharacteristic}; periodic: betti ${CubicalComplex([3, 3], periodic: true).bettiNumbers()}');
}3×3 grid of squares: χ = 1; periodic: betti [1, 2, 1]
factory CubicalComplex.topValues(List<int> shape, List<double> values, {bool periodic = false})Values on the top-dimensional cubes, row-major over shape (last axis fastest).
import 'package:riptide_topology/riptide_topology.ray';
import 'package:riptide_rational_geometry/riptide_rational_geometry.ray' show qv, Vec;
import 'package:riptide_precision/riptide_precision.ray' show Rational;
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f4(num x) => x.isInfinite ? '∞' : x.toStringAsFixed(4);
void main() {
final c = CubicalComplex.topValues([3, 3], [1, 1, 1, 1, 0, 1, 1, 1, 1].map((v) => v.toDouble()).toList());
print(c.persistence().inDimension(1).map((p) => '[${f4(p.birth)}, ${f4(p.death)})').toList());
}[]
factory CubicalComplex.vertexValues(List<int> shape, List<double> values, {bool periodic = false})Values on the vertices, row-major over the vertex grid (shape + 1 per axis, or shape when periodic).
import 'package:riptide_topology/riptide_topology.ray';
import 'package:riptide_rational_geometry/riptide_rational_geometry.ray' show qv, Vec;
import 'package:riptide_precision/riptide_precision.ray' show Rational;
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f4(num x) => x.isInfinite ? '∞' : x.toStringAsFixed(4);
void main() {
final c = CubicalComplex.vertexValues([3, 3], [0, 1, 0, 1, 2, 1, 0, 1, 0].map((v) => v.toDouble()).toList());
print(c.persistence().inDimension(0).length);
}2
Properties
final List<int> shapefinal bool periodicint get dimensionMethods
int cellCount(int k)import 'package:riptide_topology/riptide_topology.ray';
import 'package:riptide_rational_geometry/riptide_rational_geometry.ray' show qv, Vec;
import 'package:riptide_precision/riptide_precision.ray' show Rational;
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f4(num x) => x.isInfinite ? '∞' : x.toStringAsFixed(4);
void main() {
print([for (var k = 0; k <= 2; k++) CubicalComplex([2, 2]).cellCount(k)]);
}[9, 12, 4]
SparseIntMatrix boundary(int k)import 'package:riptide_topology/riptide_topology.ray';
import 'package:riptide_rational_geometry/riptide_rational_geometry.ray' show qv, Vec;
import 'package:riptide_precision/riptide_precision.ray' show Rational;
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f4(num x) => x.isInfinite ? '∞' : x.toStringAsFixed(4);
void main() {
print(CubicalComplex([1, 1]).boundary(2).toDense());
}[[-1], [1], [-1], [1]]
PersistenceDiagram persistence({int prime = 2})import 'package:riptide_topology/riptide_topology.ray';
import 'package:riptide_rational_geometry/riptide_rational_geometry.ray' show qv, Vec;
import 'package:riptide_precision/riptide_precision.ray' show Rational;
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f4(num x) => x.isInfinite ? '∞' : x.toStringAsFixed(4);
void main() {
print(CubicalComplex.topValues([2, 2], [0, 1, 2, 3]).persistence().pairs.length);
}1
GroupPresentation
final class GroupPresentation
A finite group presentation \langle g_{1} \cdots g_{n} \mid r_{1} \cdots r_{m}\rangle. A relator is a word: letter i + 1 is g_{i}, -(i + 1) its inverse.
import 'package:riptide_topology/riptide_topology.ray';
import 'package:riptide_rational_geometry/riptide_rational_geometry.ray' show qv, Vec;
import 'package:riptide_precision/riptide_precision.ray' show Rational;
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f4(num x) => x.isInfinite ? '∞' : x.toStringAsFixed(4);
void main() {
final g = GroupPresentation(2, [[1, 2, -1, -2]]);
print('⟨a, b | aba⁻¹b⁻¹⟩: abelianisation ${g.abelianization()}');
}⟨a, b | aba⁻¹b⁻¹⟩: abelianisation Z^2
Constructors
GroupPresentation(this.generatorCount, List<List<int>> relators)import 'package:riptide_topology/riptide_topology.ray';
import 'package:riptide_rational_geometry/riptide_rational_geometry.ray' show qv, Vec;
import 'package:riptide_precision/riptide_precision.ray' show Rational;
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f4(num x) => x.isInfinite ? '∞' : x.toStringAsFixed(4);
void main() {
print(GroupPresentation(1, [[1, 1, 1]]).abelianization());
}Z/3
Properties
final int generatorCountfinal List<List<int>> relatorsbool get isTriviallyTrivialbool get isFreeMethods
HomologyGroup abelianization()The abelianization \frac{G}{[G, G]} (= H_{1} for a fundamental group), from the Smith normal form of the exponent-sum matrix.
import 'package:riptide_topology/riptide_topology.ray';
import 'package:riptide_rational_geometry/riptide_rational_geometry.ray' show qv, Vec;
import 'package:riptide_precision/riptide_precision.ray' show Rational;
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f4(num x) => x.isInfinite ? '∞' : x.toStringAsFixed(4);
void main() {
// The trefoil group ⟨x, y | x² = y³⟩ abelianises to Z.
print(GroupPresentation(2, [[1, 1, -2, -2, -2]]).abelianization());
}Z
GroupPresentation simplify()Applies Tietze transformations until none applies: free and cyclic reduction, dropping empty and repeated relators, and eliminating a generator that occurs exactly once in some relator (g = the rest of that relator, substituted everywhere).
import 'package:riptide_topology/riptide_topology.ray';
import 'package:riptide_rational_geometry/riptide_rational_geometry.ray' show qv, Vec;
import 'package:riptide_precision/riptide_precision.ray' show Rational;
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f4(num x) => x.isInfinite ? '∞' : x.toStringAsFixed(4);
void main() {
print(GroupPresentation(3, [[1, -1], [3], [2, 2]]).simplify());
}⟨a, b | bb⟩
String toString()MapperNode
final class MapperNode
One mapper node: the points of one cluster of one interval's preimage.
import 'package:riptide_topology/riptide_topology.ray';
import 'package:riptide_rational_geometry/riptide_rational_geometry.ray' show qv, Vec;
import 'package:riptide_precision/riptide_precision.ray' show Rational;
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f4(num x) => x.isInfinite ? '∞' : x.toStringAsFixed(4);
void main() {
final n = MapperNode(2, [4, 5, 6]);
print('interval ${n.interval}, members ${n.members}');
}interval 2, members [4, 5, 6]
Constructors
const MapperNode(this.interval, this.members)import 'package:riptide_topology/riptide_topology.ray';
import 'package:riptide_rational_geometry/riptide_rational_geometry.ray' show qv, Vec;
import 'package:riptide_precision/riptide_precision.ray' show Rational;
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f4(num x) => x.isInfinite ? '∞' : x.toStringAsFixed(4);
void main() {
print(MapperNode(0, [1]).members);
}[1]
Properties
final int intervalfinal List<int> membersMapperGraph
final class MapperGraph
The mapper graph and its nerve.
import 'package:riptide_topology/riptide_topology.ray';
import 'package:riptide_rational_geometry/riptide_rational_geometry.ray' show qv, Vec;
import 'package:riptide_precision/riptide_precision.ray' show Rational;
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f4(num x) => x.isInfinite ? '∞' : x.toStringAsFixed(4);
void main() {
// Eight points on a circle of radius 1 (rounded to 4 decimals for display).
final pts = Float64List.fromList([for (var i = 0; i < 8; i++) ...[math.cos(i * math.pi / 4), math.sin(i * math.pi / 4)]]);
final m = mapper(pts, 2, [for (var i = 0; i < 8; i++) pts[2 * i + 1]], intervals: 3, epsilon: 0.9);
print('${m.nodes.length} nodes, ${m.nerve.cellCount(1)} edges');
}4 nodes, 0 edges
Constructors
MapperGraph(this.nodes, this.nerve)import 'package:riptide_topology/riptide_topology.ray';
import 'package:riptide_rational_geometry/riptide_rational_geometry.ray' show qv, Vec;
import 'package:riptide_precision/riptide_precision.ray' show Rational;
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f4(num x) => x.isInfinite ? '∞' : x.toStringAsFixed(4);
void main() {
final g = MapperGraph([MapperNode(0, [0, 1]), MapperNode(1, [1, 2])], SimplicialComplex([[0, 1]]));
print(g.nerve.cellCount(1));
}1
Properties
final List<MapperNode> nodesfinal SimplicialComplex nerveThe nerve: node i is vertex i; an edge (triangle) when two (three) clusters share a point.
List<List<int>> get edgesSparseIntMatrix
final class SparseIntMatrix
A sparse integer matrix stored by columns (row → value, zeros never stored). Boundary matrices are this shape: rows = (k - 1)-cells, cols = k-cells.
import 'package:riptide_topology/riptide_topology.ray';
import 'package:riptide_rational_geometry/riptide_rational_geometry.ray' show qv, Vec;
import 'package:riptide_precision/riptide_precision.ray' show Rational;
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f4(num x) => x.isInfinite ? '∞' : x.toStringAsFixed(4);
void main() {
final m = SparseIntMatrix.fromDense([[2, 0], [0, 4]]);
print('invariant factors ${m.invariantFactors()}, rank mod 2 ${m.rankModP(2)}');
}invariant factors [2, 4], rank mod 2 0
Constructors
SparseIntMatrix(this.rows, this.cols)import 'package:riptide_topology/riptide_topology.ray';
import 'package:riptide_rational_geometry/riptide_rational_geometry.ray' show qv, Vec;
import 'package:riptide_precision/riptide_precision.ray' show Rational;
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f4(num x) => x.isInfinite ? '∞' : x.toStringAsFixed(4);
void main() {
final m = SparseIntMatrix(2, 3)..set(0, 1, 5);
print(m.toDense());
}[[0, 5, 0], [0, 0, 0]]
SparseIntMatrix.fromColumns(this.rows, this.columns)import 'package:riptide_topology/riptide_topology.ray';
import 'package:riptide_rational_geometry/riptide_rational_geometry.ray' show qv, Vec;
import 'package:riptide_precision/riptide_precision.ray' show Rational;
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f4(num x) => x.isInfinite ? '∞' : x.toStringAsFixed(4);
void main() {
print(SparseIntMatrix.fromColumns(2, [{0: 1}, {1: -1}]).toDense());
}[[1, 0], [0, -1]]
factory SparseIntMatrix.fromDense(List<List<int>> a)import 'package:riptide_topology/riptide_topology.ray';
import 'package:riptide_rational_geometry/riptide_rational_geometry.ray' show qv, Vec;
import 'package:riptide_precision/riptide_precision.ray' show Rational;
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f4(num x) => x.isInfinite ? '∞' : x.toStringAsFixed(4);
void main() {
print(SparseIntMatrix.fromDense([[1, 2], [3, 4]]).transpose().toDense());
}[[1, 3], [2, 4]]
Properties
final int rowsfinal int colsfinal List<Map<int, int>> columnsint get nonZerosbool get isZeroMethods
void set(int row, int col, int value)import 'package:riptide_topology/riptide_topology.ray';
import 'package:riptide_rational_geometry/riptide_rational_geometry.ray' show qv, Vec;
import 'package:riptide_precision/riptide_precision.ray' show Rational;
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f4(num x) => x.isInfinite ? '∞' : x.toStringAsFixed(4);
void main() {
final m = SparseIntMatrix(2, 2)..set(1, 0, 7);
print(m.toDense());
}[[0, 0], [7, 0]]
List<List<int>> toDense()import 'package:riptide_topology/riptide_topology.ray';
import 'package:riptide_rational_geometry/riptide_rational_geometry.ray' show qv, Vec;
import 'package:riptide_precision/riptide_precision.ray' show Rational;
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f4(num x) => x.isInfinite ? '∞' : x.toStringAsFixed(4);
void main() {
print(SimplicialComplex.simplex(2).boundary(1).toDense());
}[[-1, -1, 0], [1, 0, -1], [0, 1, 1]]
SparseIntMatrix transpose()import 'package:riptide_topology/riptide_topology.ray';
import 'package:riptide_rational_geometry/riptide_rational_geometry.ray' show qv, Vec;
import 'package:riptide_precision/riptide_precision.ray' show Rational;
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f4(num x) => x.isInfinite ? '∞' : x.toStringAsFixed(4);
void main() {
print(SparseIntMatrix.fromDense([[1, 2, 3]]).transpose().toDense());
}[[1], [2], [3]]
SparseIntMatrix multiply(SparseIntMatrix b)The product this · b.
import 'package:riptide_topology/riptide_topology.ray';
import 'package:riptide_rational_geometry/riptide_rational_geometry.ray' show qv, Vec;
import 'package:riptide_precision/riptide_precision.ray' show Rational;
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f4(num x) => x.isInfinite ? '∞' : x.toStringAsFixed(4);
void main() {
// ∂₁∂₂ = 0 on a triangle.
final k = SimplicialComplex.simplex(2);
print(k.boundary(1).multiply(k.boundary(2)).toDense());
}[[0], [0], [0]]
int rankModP(int p)The rank over the field Z/p (p prime). With a large prime this is the rank over Q.
import 'package:riptide_topology/riptide_topology.ray';
import 'package:riptide_rational_geometry/riptide_rational_geometry.ray' show qv, Vec;
import 'package:riptide_precision/riptide_precision.ray' show Rational;
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f4(num x) => x.isInfinite ? '∞' : x.toStringAsFixed(4);
void main() {
final m = SparseIntMatrix.fromDense([[2, 0], [0, 2]]);
print('rank over Q ${m.rankModP(rationalPrime)}, over Z/2 ${m.rankModP(2)}');
}rank over Q 2, over Z/2 0
List<int> invariantFactors()The nonzero invariant factors d_{1} \mid d_{2} \mid \cdots of the Smith normal form over Z (all positive; their count is the rank). Unit pivots are eliminated sparsely first (boundary matrices are mostly \pm1), then the small remainder is reduced densely.
import 'package:riptide_topology/riptide_topology.ray';
import 'package:riptide_rational_geometry/riptide_rational_geometry.ray' show qv, Vec;
import 'package:riptide_precision/riptide_precision.ray' show Rational;
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f4(num x) => x.isInfinite ? '∞' : x.toStringAsFixed(4);
void main() {
print(SparseIntMatrix.fromDense([[2, 4], [6, 8]]).invariantFactors());
}[2, 4]
Operators
int operator [](({int row, int col}) at)import 'package:riptide_topology/riptide_topology.ray';
import 'package:riptide_rational_geometry/riptide_rational_geometry.ray' show qv, Vec;
import 'package:riptide_precision/riptide_precision.ray' show Rational;
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f4(num x) => x.isInfinite ? '∞' : x.toStringAsFixed(4);
void main() {
print(SparseIntMatrix.fromDense([[1, 2], [3, 4]])[(row: 1, col: 0)]);
}3
SmithNormalForm
final class SmithNormalForm
Smith normal form D = U \cdot A \cdot V over Z with unimodular U and V (dense; for small matrices and for explicit bases).
import 'package:riptide_topology/riptide_topology.ray';
import 'package:riptide_rational_geometry/riptide_rational_geometry.ray' show qv, Vec;
import 'package:riptide_precision/riptide_precision.ray' show Rational;
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f4(num x) => x.isInfinite ? '∞' : x.toStringAsFixed(4);
void main() {
final s = SmithNormalForm.of([[2, 4, 4], [-6, 6, 12], [10, -4, -16]]);
print('diagonal ${s.diagonal}');
}diagonal [2, 6, 12]
Constructors
factory SmithNormalForm.of(List<List<int>> a)import 'package:riptide_topology/riptide_topology.ray';
import 'package:riptide_rational_geometry/riptide_rational_geometry.ray' show qv, Vec;
import 'package:riptide_precision/riptide_precision.ray' show Rational;
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f4(num x) => x.isInfinite ? '∞' : x.toStringAsFixed(4);
void main() {
print(SmithNormalForm.of([[1, 2], [3, 4]]).diagonal);
}[1, 2]
Properties
int get rankDiscreteGradient
final class DiscreteGradient
A discrete gradient vector field: pairs (\sigma, \tau) of a cell and a cofacet, the rest critical.
import 'package:riptide_topology/riptide_topology.ray';
import 'package:riptide_rational_geometry/riptide_rational_geometry.ray' show qv, Vec;
import 'package:riptide_precision/riptide_precision.ray' show Rational;
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f4(num x) => x.isInfinite ? '∞' : x.toStringAsFixed(4);
void main() {
final s = Triangulations.octahedron().complex;
final g = DiscreteGradient.lowerStar(s, (v) => v.toDouble());
print('Morse numbers ${g.morseNumbers}, betti ${s.bettiNumbers()}');
}Morse numbers [2, 2, 2], betti [1, 0, 1]
Constructors
factory DiscreteGradient.lowerStar(SimplicialComplex complex, double Function(int vertex) f)Builds the gradient of f (a value per vertex id; ties broken by vertex id) on complex by processing each vertex's lower star: homotopy expansions in the order of the cells' sorted vertex values, critical cells only where no expansion is possible.
import 'package:riptide_topology/riptide_topology.ray';
import 'package:riptide_rational_geometry/riptide_rational_geometry.ray' show qv, Vec;
import 'package:riptide_precision/riptide_precision.ray' show Rational;
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f4(num x) => x.isInfinite ? '∞' : x.toStringAsFixed(4);
void main() {
final g = DiscreteGradient.lowerStar(Triangulations.torus7().complex, (v) => (v * 3 % 7).toDouble());
print('critical cells per dimension ${g.morseNumbers}');
}critical cells per dimension [1, 2, 1]
Properties
final SimplicialComplex complexList<(Cell, Cell)> get pairsThe gradient pairs (\sigma, \tau) with \sigma a facet of \tau.
List<int> get morseNumbersThe number of critical cells in each dimension (the Morse numbers c_{k}).
Methods
bool isCritical(Cell c)import 'package:riptide_topology/riptide_topology.ray';
import 'package:riptide_rational_geometry/riptide_rational_geometry.ray' show qv, Vec;
import 'package:riptide_precision/riptide_precision.ray' show Rational;
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f4(num x) => x.isInfinite ? '∞' : x.toStringAsFixed(4);
void main() {
final g = DiscreteGradient.lowerStar(SimplicialComplex.simplex(2), (v) => v.toDouble());
print(g.isCritical((dim: 0, index: 0)));
}true
Cell? partnerOf(Cell c)The cell paired with c (a facet or a cofacet), or null when c is critical.
import 'package:riptide_topology/riptide_topology.ray';
import 'package:riptide_rational_geometry/riptide_rational_geometry.ray' show qv, Vec;
import 'package:riptide_precision/riptide_precision.ray' show Rational;
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f4(num x) => x.isInfinite ? '∞' : x.toStringAsFixed(4);
void main() {
final g = DiscreteGradient.lowerStar(SimplicialComplex.simplex(2), (v) => v.toDouble());
print(g.partnerOf((dim: 0, index: 1)));
}(dim: 1, index: 0)
bool satisfiesMorseInequalities(List<int> betti)Whether the weak (c_{k} \ge b_{k}) and strong (alternating partial sums) Morse inequalities hold for betti, and \sum (-1)^{k} c_{k} = \chi.
import 'package:riptide_topology/riptide_topology.ray';
import 'package:riptide_rational_geometry/riptide_rational_geometry.ray' show qv, Vec;
import 'package:riptide_precision/riptide_precision.ray' show Rational;
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f4(num x) => x.isInfinite ? '∞' : x.toStringAsFixed(4);
void main() {
final s = Triangulations.torus7().complex;
final g = DiscreteGradient.lowerStar(s, (v) => v.toDouble());
print(g.satisfiesMorseInequalities(s.bettiNumbers()));
}true
MorseSmaleArc
final class MorseSmaleArc
One arc of a Morse–Smale complex: a V-path from a saddle (critical edge) to a minimum (critical vertex) or a maximum (critical triangle), through cells.
import 'package:riptide_topology/riptide_topology.ray';
import 'package:riptide_rational_geometry/riptide_rational_geometry.ray' show qv, Vec;
import 'package:riptide_precision/riptide_precision.ray' show Rational;
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f4(num x) => x.isInfinite ? '∞' : x.toStringAsFixed(4);
void main() {
final ms = MorseSmaleComplex(DiscreteGradient.lowerStar(Triangulations.octahedron().complex, (v) => v.toDouble()));
for (final a in ms.arcs) print('saddle ${a.saddle} → ${a.extremum}');
}saddle 4 → (dim: 0, index: 1) saddle 4 → (dim: 0, index: 0) saddle 4 → (dim: 2, index: 6) saddle 4 → (dim: 2, index: 7) saddle 5 → (dim: 0, index: 1) saddle 5 → (dim: 0, index: 0) saddle 5 → (dim: 2, index: 6) saddle 5 → (dim: 2, index: 7)
Constructors
const MorseSmaleArc(this.saddle, this.extremum, this.cells)import 'package:riptide_topology/riptide_topology.ray';
import 'package:riptide_rational_geometry/riptide_rational_geometry.ray' show qv, Vec;
import 'package:riptide_precision/riptide_precision.ray' show Rational;
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f4(num x) => x.isInfinite ? '∞' : x.toStringAsFixed(4);
void main() {
print(MorseSmaleArc(0, (dim: 0, index: 1), []).extremum);
}(dim: 0, index: 1)
Properties
final int saddlefinal Cell extremumbool get toMinimumMorseSmaleComplex
final class MorseSmaleComplex
The Morse–Smale complex of a discrete gradient on a triangulated surface: critical cells as nodes, the descending arcs saddle → minimum (vertex V-paths) and ascending arcs saddle → maximum (dual V-paths).
import 'package:riptide_topology/riptide_topology.ray';
import 'package:riptide_rational_geometry/riptide_rational_geometry.ray' show qv, Vec;
import 'package:riptide_precision/riptide_precision.ray' show Rational;
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f4(num x) => x.isInfinite ? '∞' : x.toStringAsFixed(4);
void main() {
final ms = MorseSmaleComplex(DiscreteGradient.lowerStar(Triangulations.torus7().complex, (v) => v.toDouble()));
print('${ms.arcs.length} arcs, ${ms.cellCount2} two-cells');
}8 arcs, 4 two-cells
Constructors
MorseSmaleComplex(this.gradient)import 'package:riptide_topology/riptide_topology.ray';
import 'package:riptide_rational_geometry/riptide_rational_geometry.ray' show qv, Vec;
import 'package:riptide_precision/riptide_precision.ray' show Rational;
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f4(num x) => x.isInfinite ? '∞' : x.toStringAsFixed(4);
void main() {
print(MorseSmaleComplex(DiscreteGradient.lowerStar(Triangulations.tetrahedron().complex, (v) => v.toDouble())).arcs.length);
}0
Properties
final DiscreteGradient gradientfinal List<MorseSmaleArc> arcsList<int> get minimaList<int> get saddlesList<int> get maximaint get cellCount2The 2-cells (quadrilaterals for a generic gradient on a closed surface): arcs − nodes + \chi.
PlCriticalPoint
final class PlCriticalPoint
A piecewise-linear critical point of a vertex function on a closed triangulated surface (Banchoff 1967): around the vertex's link, count the sign changes of f(w) - f(v). 0 changes: a minimum (all higher) or a maximum (all lower); 2m changes with m \ge 2: a saddle of multiplicity m - 1 (index -(m - 1)).
import 'package:riptide_topology/riptide_topology.ray';
import 'package:riptide_rational_geometry/riptide_rational_geometry.ray' show qv, Vec;
import 'package:riptide_precision/riptide_precision.ray' show Rational;
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f4(num x) => x.isInfinite ? '∞' : x.toStringAsFixed(4);
void main() {
for (final c in plCriticalPoints(Triangulations.octahedron(), (v) => v.toDouble())) print('${c.vertex} ${c.kind} index ${c.index}');
}0 min index 1 1 min index 1 2 saddle index -1 3 saddle index -1 4 max index 1 5 max index 1
Constructors
const PlCriticalPoint(this.vertex, this.kind, this.multiplicity)import 'package:riptide_topology/riptide_topology.ray';
import 'package:riptide_rational_geometry/riptide_rational_geometry.ray' show qv, Vec;
import 'package:riptide_precision/riptide_precision.ray' show Rational;
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f4(num x) => x.isInfinite ? '∞' : x.toStringAsFixed(4);
void main() {
print(PlCriticalPoint(3, 'saddle', 2).index);
}-2
Properties
final int vertexfinal int multiplicityPersistencePair
final class PersistencePair
One interval [birth, death) of a k-dimensional class; death is infinite for an essential class.
import 'package:riptide_topology/riptide_topology.ray';
import 'package:riptide_rational_geometry/riptide_rational_geometry.ray' show qv, Vec;
import 'package:riptide_precision/riptide_precision.ray' show Rational;
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f4(num x) => x.isInfinite ? '∞' : x.toStringAsFixed(4);
void main() {
final p = PersistencePair(1, 0.5, 1.25);
print('H${p.dimension} born ${p.birth}, dies ${p.death}, persistence ${p.persistence}');
}H1 born 0.5, dies 1.25, persistence 0.75
Constructors
const PersistencePair(this.dimension, this.birth, this.death)import 'package:riptide_topology/riptide_topology.ray';
import 'package:riptide_rational_geometry/riptide_rational_geometry.ray' show qv, Vec;
import 'package:riptide_precision/riptide_precision.ray' show Rational;
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f4(num x) => x.isInfinite ? '∞' : x.toStringAsFixed(4);
void main() {
print(PersistencePair(0, 0, double.infinity).isEssential);
}true
Properties
final int dimensionfinal double birthfinal double deathdouble get persistencebool get isEssentialMethods
String toString()PersistenceDiagram
final class PersistenceDiagram
A persistence diagram: the multiset of intervals in every dimension.
import 'package:riptide_topology/riptide_topology.ray';
import 'package:riptide_rational_geometry/riptide_rational_geometry.ray' show qv, Vec;
import 'package:riptide_precision/riptide_precision.ray' show Rational;
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f4(num x) => x.isInfinite ? '∞' : x.toStringAsFixed(4);
void main() {
final d = PersistenceDiagram([PersistencePair(0, 0, double.infinity), PersistencePair(1, 0.3, 0.9), PersistencePair(1, 0.4, 0.42)]);
print('betti at 0.5: ${d.bettiAt(0.5)}; significant: ${d.significant(0.1).pairs.length} pairs');
}betti at 0.5: [1, 1]; significant: 2 pairs
Constructors
PersistenceDiagram(List<PersistencePair> pairs)import 'package:riptide_topology/riptide_topology.ray';
import 'package:riptide_rational_geometry/riptide_rational_geometry.ray' show qv, Vec;
import 'package:riptide_precision/riptide_precision.ray' show Rational;
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f4(num x) => x.isInfinite ? '∞' : x.toStringAsFixed(4);
void main() {
print(PersistenceDiagram([PersistencePair(0, 0, 1)]).pairs.length);
}1
Properties
int get maxDimensionMethods
List<PersistencePair> inDimension(int d)import 'package:riptide_topology/riptide_topology.ray';
import 'package:riptide_rational_geometry/riptide_rational_geometry.ray' show qv, Vec;
import 'package:riptide_precision/riptide_precision.ray' show Rational;
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f4(num x) => x.isInfinite ? '∞' : x.toStringAsFixed(4);
void main() {
final d = VietorisRips.points(Float64List.fromList([0, 0, 1, 0, 0, 1, 1, 1]), 2).persistence();
print('H0 ${d.inDimension(0).length}, H1 ${d.inDimension(1).length}');
}H0 4, H1 1
List<int> bettiAt(double t)The Betti numbers of the filtration at t: intervals with birth \le t < death.
import 'package:riptide_topology/riptide_topology.ray';
import 'package:riptide_rational_geometry/riptide_rational_geometry.ray' show qv, Vec;
import 'package:riptide_precision/riptide_precision.ray' show Rational;
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f4(num x) => x.isInfinite ? '∞' : x.toStringAsFixed(4);
void main() {
final d = VietorisRips.points(Float64List.fromList([0, 0, 1, 0, 0, 1, 1, 1]), 2).persistence();
for (final t in [0.5, 1.2, 1.5]) print('t = $t: ${d.bettiAt(t)}');
}t = 0.5: [4, 0] t = 1.2: [1, 1] t = 1.5: [1, 0]
PersistenceDiagram significant(double minPersistence)Intervals longer than minPersistence only (noise removal).
import 'package:riptide_topology/riptide_topology.ray';
import 'package:riptide_rational_geometry/riptide_rational_geometry.ray' show qv, Vec;
import 'package:riptide_precision/riptide_precision.ray' show Rational;
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f4(num x) => x.isInfinite ? '∞' : x.toStringAsFixed(4);
void main() {
final d = PersistenceDiagram([PersistencePair(1, 0, 0.01), PersistencePair(1, 0, 1)]);
print(d.significant(0.1).pairs.length);
}1
double bottleneckTo(PersistenceDiagram other, int dim)The bottleneck distance to other in dimension dim (L\infty ground metric, diagonal allowed).
import 'package:riptide_topology/riptide_topology.ray';
import 'package:riptide_rational_geometry/riptide_rational_geometry.ray' show qv, Vec;
import 'package:riptide_precision/riptide_precision.ray' show Rational;
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f4(num x) => x.isInfinite ? '∞' : x.toStringAsFixed(4);
void main() {
final a = PersistenceDiagram([PersistencePair(1, 0, 1)]), b = PersistenceDiagram([PersistencePair(1, 0.1, 1.2)]);
print(f4(a.bottleneckTo(b, 1)));
}0.2000
double wassersteinTo(PersistenceDiagram other, int dim, {double q = 1})The q-Wasserstein distance to other in dimension dim (L\infty ground metric).
import 'package:riptide_topology/riptide_topology.ray';
import 'package:riptide_rational_geometry/riptide_rational_geometry.ray' show qv, Vec;
import 'package:riptide_precision/riptide_precision.ray' show Rational;
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f4(num x) => x.isInfinite ? '∞' : x.toStringAsFixed(4);
void main() {
final a = PersistenceDiagram([PersistencePair(1, 0, 1)]), b = PersistenceDiagram([PersistencePair(1, 0.1, 1.2)]);
print(f4(a.wassersteinTo(b, 1, q: 2)));
}0.2000
String toString()FilteredComplex
final class FilteredComplex
A filtration of a cell complex: cells in an order where every face comes before its cofaces, each with a value that never decreases along the order. Build one with FilteredComplex.new (any order; it sorts by value, then dimension) or from a simplicial complex.
import 'package:riptide_topology/riptide_topology.ray';
import 'package:riptide_rational_geometry/riptide_rational_geometry.ray' show qv, Vec;
import 'package:riptide_precision/riptide_precision.ray' show Rational;
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f4(num x) => x.isInfinite ? '∞' : x.toStringAsFixed(4);
void main() {
final k = SimplicialComplex([[0, 1], [1, 2], [0, 2]]);
final f = FilteredComplex.lowerStar(k, (v) => [0.0, 1.0, 2.0][v]);
print(f.persistence().pairs.map((p) => 'H${p.dimension}[${p.birth}, ${p.death})').join(' '));
}H0[0.0, Infinity) H1[2.0, Infinity)
Constructors
factory FilteredComplex(List<int> dims, List<double> values, List<Map<int, int>> boundaries)dims i, values i and boundaries i (face index → coefficient, indices into these same lists) describe cell i. Cells are re-sorted by (value, dimension, i).
import 'package:riptide_topology/riptide_topology.ray';
import 'package:riptide_rational_geometry/riptide_rational_geometry.ray' show qv, Vec;
import 'package:riptide_precision/riptide_precision.ray' show Rational;
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f4(num x) => x.isInfinite ? '∞' : x.toStringAsFixed(4);
void main() {
// Two vertices at 0, an edge at 1: two components merge at 1.
final f = FilteredComplex([0, 0, 1], [0, 0, 1], [{}, {}, {0: 1, 1: -1}]);
print(f.persistence().pairs.map((p) => '[${p.birth}, ${p.death})').toList());
}[[0.0, Infinity), [0.0, 1.0)]
factory FilteredComplex.simplicial(SimplicialComplex k, double Function(int dim, int index) value)A simplicial complex filtered by value (dimension, index within dimension). Use FilteredComplex.lowerStar for a function on vertices.
import 'package:riptide_topology/riptide_topology.ray';
import 'package:riptide_rational_geometry/riptide_rational_geometry.ray' show qv, Vec;
import 'package:riptide_precision/riptide_precision.ray' show Rational;
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f4(num x) => x.isInfinite ? '∞' : x.toStringAsFixed(4);
void main() {
final k = SimplicialComplex.sphere(1);
final f = FilteredComplex.simplicial(k, (d, i) => d.toDouble());
print(f.persistence().pairs.length);
}4
factory FilteredComplex.lowerStar(SimplicialComplex k, double Function(int vertex) f)The lower-star filtration of a function on vertices (a simplex enters with its highest vertex).
import 'package:riptide_topology/riptide_topology.ray';
import 'package:riptide_rational_geometry/riptide_rational_geometry.ray' show qv, Vec;
import 'package:riptide_precision/riptide_precision.ray' show Rational;
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f4(num x) => x.isInfinite ? '∞' : x.toStringAsFixed(4);
void main() {
final f = FilteredComplex.lowerStar(SimplicialComplex([[0, 1], [1, 2]]), (v) => [1.0, 0.0, 2.0][v]);
print(f.persistence().pairs.map((p) => '[${p.birth}, ${p.death})').toList());
}[[0.0, Infinity)]
Properties
final List<int> dimsfinal List<double> valuesfinal List<Map<int, int>> boundariesint get lengthMethods
PersistenceDiagram persistence({int prime = 2, bool includeZeroLength = false})The persistence diagram over Z/prime, by column reduction with clearing (twist): dimensions are reduced from the top down and a column that is already a pivot is zeroed without reducing it. Intervals of length 0 are left out unless includeZeroLength.
import 'package:riptide_topology/riptide_topology.ray';
import 'package:riptide_rational_geometry/riptide_rational_geometry.ray' show qv, Vec;
import 'package:riptide_precision/riptide_precision.ray' show Rational;
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f4(num x) => x.isInfinite ? '∞' : x.toStringAsFixed(4);
void main() {
print(FilteredComplex.lowerStar(SimplicialComplex.sphere(2), (v) => v.toDouble()).persistence().pairs.map((p) => 'H${p.dimension}').toList());
}[H0, H2]
final class RationalPersistencePair
One interval [birth, death) with exact quadrance (Rips) or squared-radius (alpha) values; death is null for an essential class.
import 'package:riptide_topology/riptide_topology.ray';
import 'package:riptide_rational_geometry/riptide_rational_geometry.ray' show qv, Vec;
import 'package:riptide_precision/riptide_precision.ray' show Rational;
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f4(num x) => x.isInfinite ? '∞' : x.toStringAsFixed(4);
void main() {
final p = RationalPersistencePair(1, Rational.fromInt(1, 2), Rational.fromInt(2));
print('${p.dimension}: [${p.birth}, ${p.death})');
}1: [1/2, 2)
Constructors
const RationalPersistencePair(this.dimension, this.birth, this.death)import 'package:riptide_topology/riptide_topology.ray';
import 'package:riptide_rational_geometry/riptide_rational_geometry.ray' show qv, Vec;
import 'package:riptide_precision/riptide_precision.ray' show Rational;
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f4(num x) => x.isInfinite ? '∞' : x.toStringAsFixed(4);
void main() {
print(RationalPersistencePair(0, Rational.zero, null).death);
}null
Properties
final int dimensionfinal Rational birthfinal Rational? deathbool get isEssentialMethods
String toString()final class RationalPersistenceDiagram
A persistence diagram whose values are exact squared lengths.
import 'package:riptide_topology/riptide_topology.ray';
import 'package:riptide_rational_geometry/riptide_rational_geometry.ray' show qv, Vec;
import 'package:riptide_precision/riptide_precision.ray' show Rational;
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f4(num x) => x.isInfinite ? '∞' : x.toStringAsFixed(4);
void main() {
final d = RationalVietorisRips([qv([0, 0]), qv([1, 0]), qv([0, 1]), qv([1, 1])]).persistence();
print(d.pairs.map((p) => 'H${p.dimension}[${p.birth}, ${p.death})').join(' '));
}H0[0, null) H0[0, 1) H0[0, 1) H0[0, 1) H1[1, 2)
Constructors
RationalPersistenceDiagram(List<RationalPersistencePair> pairs)import 'package:riptide_topology/riptide_topology.ray';
import 'package:riptide_rational_geometry/riptide_rational_geometry.ray' show qv, Vec;
import 'package:riptide_precision/riptide_precision.ray' show Rational;
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f4(num x) => x.isInfinite ? '∞' : x.toStringAsFixed(4);
void main() {
print(RationalPersistenceDiagram([RationalPersistencePair(0, Rational.zero, null)]).pairs.length);
}1
Properties
final List<RationalPersistencePair> pairsMethods
List<RationalPersistencePair> inDimension(int d)import 'package:riptide_topology/riptide_topology.ray';
import 'package:riptide_rational_geometry/riptide_rational_geometry.ray' show qv, Vec;
import 'package:riptide_precision/riptide_precision.ray' show Rational;
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f4(num x) => x.isInfinite ? '∞' : x.toStringAsFixed(4);
void main() {
final d = RationalVietorisRips([qv([0, 0]), qv([1, 0]), qv([0, 1]), qv([1, 1])]).persistence();
print(d.inDimension(1).map((p) => '[${p.birth}, ${p.death})').toList());
}[[1, 2)]
List<int> bettiAt(Rational q)Betti numbers at the squared scale q: intervals with birth \le q < death, decided exactly.
import 'package:riptide_topology/riptide_topology.ray';
import 'package:riptide_rational_geometry/riptide_rational_geometry.ray' show qv, Vec;
import 'package:riptide_precision/riptide_precision.ray' show Rational;
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f4(num x) => x.isInfinite ? '∞' : x.toStringAsFixed(4);
void main() {
final d = RationalVietorisRips([qv([0, 0]), qv([1, 0]), qv([0, 1]), qv([1, 1])]).persistence();
for (final q in [Rational.one, Rational.fromInt(3, 2), Rational.fromInt(2)]) print('Q = $q: ${d.bettiAt(q)}');
}Q = 1: [1, 1] Q = 3/2: [1, 1] Q = 2: [1, 0]
PersistenceDiagram toDistanceDiagram()The float view with lengths (√ of each value, via FloatBoundary.distance: relative error \le 2^{-52}): a Rips diagram in distances, an alpha diagram in radii.
import 'package:riptide_topology/riptide_topology.ray';
import 'package:riptide_rational_geometry/riptide_rational_geometry.ray' show qv, Vec;
import 'package:riptide_precision/riptide_precision.ray' show Rational;
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f4(num x) => x.isInfinite ? '∞' : x.toStringAsFixed(4);
void main() {
final d = RationalVietorisRips([qv([0, 0]), qv([1, 0]), qv([0, 1]), qv([1, 1])]).persistence().toDistanceDiagram();
print(d.inDimension(1).map((p) => '[${f4(p.birth)}, ${f4(p.death)})').toList());
}[[1.0000, 1.4142)]
PersistenceDiagram toSquaredDiagram()The float view of the squared values themselves (correctly rounded), e.g. to compare with AlphaComplex.
import 'package:riptide_topology/riptide_topology.ray';
import 'package:riptide_rational_geometry/riptide_rational_geometry.ray' show qv, Vec;
import 'package:riptide_precision/riptide_precision.ray' show Rational;
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f4(num x) => x.isInfinite ? '∞' : x.toStringAsFixed(4);
void main() {
final d = RationalVietorisRips([qv([0, 0]), qv([1, 0]), qv([0, 1]), qv([1, 1])]).persistence().toSquaredDiagram();
print(d.inDimension(1).map((p) => '[${f4(p.birth)}, ${f4(p.death)})').toList());
}[[1.0000, 2.0000)]
String toString()RationalVietorisRips
final class RationalVietorisRips
Vietoris–Rips persistence of rational points with the blue quadrance: exact quadrances, exact ties.
import 'package:riptide_topology/riptide_topology.ray';
import 'package:riptide_rational_geometry/riptide_rational_geometry.ray' show qv, Vec;
import 'package:riptide_precision/riptide_precision.ray' show Rational;
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f4(num x) => x.isInfinite ? '∞' : x.toStringAsFixed(4);
void main() {
// The unit square: the loop is born at quadrance 1 and dies at the diagonal quadrance 2, exactly.
final r = RationalVietorisRips([qv([0, 0]), qv([1, 0]), qv([1, 1]), qv([0, 1])]);
print('distinct quadrances ${r.distinct}; H1 ${r.persistence().inDimension(1).map((p) => '[${p.birth}, ${p.death})').toList()}');
}distinct quadrances [0, 1, 2]; H1 [[1, 2)]
Constructors
RationalVietorisRips(List<Vec<Rational>> points)import 'package:riptide_topology/riptide_topology.ray';
import 'package:riptide_rational_geometry/riptide_rational_geometry.ray' show qv, Vec;
import 'package:riptide_precision/riptide_precision.ray' show Rational;
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f4(num x) => x.isInfinite ? '∞' : x.toStringAsFixed(4);
void main() {
print(RationalVietorisRips([qv([0, 0]), qv([3, 4])]).quadrances);
}[0, 25, 25, 0]
Properties
final List<Vec<Rational>> pointslate final List<Rational> quadrancesThe full n \times n quadrance matrix (row-major).
late final List<Rational> distinctThe distinct quadrances in increasing order (the rank filtration's values).
int get nMethods
RationalPersistenceDiagram persistence({int maxDim = 1, int prime = 2, Rational? thresholdQuadrance})The barcodes in dimensions 0 … maxDim over Z/prime, using edges of quadrance ≤ thresholdQuadrance (default: the enclosing radius, which gives the same diagram as no threshold apart from H₀'s infinite class).
import 'package:riptide_topology/riptide_topology.ray';
import 'package:riptide_rational_geometry/riptide_rational_geometry.ray' show qv, Vec;
import 'package:riptide_precision/riptide_precision.ray' show Rational;
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f4(num x) => x.isInfinite ? '∞' : x.toStringAsFixed(4);
void main() {
final r = RationalVietorisRips([qv([0, 0]), qv([2, 0]), qv([1, '7/4'])]);
print(r.persistence().pairs.map((p) => 'H${p.dimension}[${p.birth}, ${p.death})').join(' '));
}H0[0, null) H0[0, 65/16) H0[0, 4)
RationalAlphaComplex
final class RationalAlphaComplex
An alpha complex of rational points in 2-D or 3-D with exact squared-radius filtration values. The Delaunay combinatorics come from riptide_numerics_spatial on the doubles; isExactlyDelaunay checks them against the exact predicates over \mathbb{Q}.
import 'package:riptide_topology/riptide_topology.ray';
import 'package:riptide_rational_geometry/riptide_rational_geometry.ray' show qv, Vec;
import 'package:riptide_precision/riptide_precision.ray' show Rational;
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f4(num x) => x.isInfinite ? '∞' : x.toStringAsFixed(4);
void main() {
final a = RationalAlphaComplex([qv([0, 0]), qv([4, 0]), qv([0, 3]), qv([4, 3])]);
print('exactly Delaunay: ${a.isExactlyDelaunay}; H1 ${a.persistence().inDimension(1).map((p) => '[${p.birth}, ${p.death})').toList()}');
}exactly Delaunay: true; H1 [[4, 25/4)]
Constructors
factory RationalAlphaComplex(List<Vec<Rational>> points)import 'package:riptide_topology/riptide_topology.ray';
import 'package:riptide_rational_geometry/riptide_rational_geometry.ray' show qv, Vec;
import 'package:riptide_precision/riptide_precision.ray' show Rational;
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f4(num x) => x.isInfinite ? '∞' : x.toStringAsFixed(4);
void main() {
print(RationalAlphaComplex([qv([0, 0]), qv([2, 0]), qv([1, 2])]).values);
}[[0, 0, 0], [1, 5/4, 5/4], [25/16]]
Properties
final List<Vec<Rational>> pointsfinal int dimfinal List<List<Rational>> valuesThe exact filtration value (squared radius) of each simplex, by dimension and index.
bool get isExactlyDelaunayWhether every Delaunay triangle (tetrahedron) has no input point strictly inside its circumcircle (circumsphere), decided with the exact in-circle / in-sphere predicates over \mathbb{Q}. Brute force: O(n \cdot T) predicate calls for n points and T top simplices.
Methods
SimplicialComplex at(Rational alpha2)The subcomplex at squared radius ≤ alpha2, decided exactly.
import 'package:riptide_topology/riptide_topology.ray';
import 'package:riptide_rational_geometry/riptide_rational_geometry.ray' show qv, Vec;
import 'package:riptide_precision/riptide_precision.ray' show Rational;
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f4(num x) => x.isInfinite ? '∞' : x.toStringAsFixed(4);
void main() {
final a = RationalAlphaComplex([qv([0, 0]), qv([2, 0]), qv([1, 2])]);
print(a.at(Rational.fromInt(25, 16)).bettiNumbers());
}[1, 0, 0]
RationalPersistenceDiagram persistence({int prime = 2})import 'package:riptide_topology/riptide_topology.ray';
import 'package:riptide_rational_geometry/riptide_rational_geometry.ray' show qv, Vec;
import 'package:riptide_precision/riptide_precision.ray' show Rational;
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f4(num x) => x.isInfinite ? '∞' : x.toStringAsFixed(4);
void main() {
print(RationalAlphaComplex([qv([0, 0]), qv([2, 0]), qv([1, 2])]).persistence().pairs.map((p) => '[${p.birth}, ${p.death})').toList());
}[[0, null), [0, 5/4), [0, 1), [5/4, 25/16)]
VietorisRips
final class VietorisRips
Vietoris–Rips persistence of a finite metric space.
import 'package:riptide_topology/riptide_topology.ray';
import 'package:riptide_rational_geometry/riptide_rational_geometry.ray' show qv, Vec;
import 'package:riptide_precision/riptide_precision.ray' show Rational;
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f4(num x) => x.isInfinite ? '∞' : x.toStringAsFixed(4);
void main() {
// Eight points on a circle of radius 1 (rounded to 4 decimals for display).
final pts = Float64List.fromList([for (var i = 0; i < 8; i++) ...[math.cos(i * math.pi / 4), math.sin(i * math.pi / 4)]]);
final d = VietorisRips.points(pts, 2).persistence();
print(d.inDimension(1).map((p) => '[${f4(p.birth)}, ${f4(p.death)})').toList());
}[[0.7654, 1.8478)]
Constructors
factory VietorisRips.points(Float64List points, int dim)import 'package:riptide_topology/riptide_topology.ray';
import 'package:riptide_rational_geometry/riptide_rational_geometry.ray' show qv, Vec;
import 'package:riptide_precision/riptide_precision.ray' show Rational;
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f4(num x) => x.isInfinite ? '∞' : x.toStringAsFixed(4);
void main() {
print(VietorisRips.points(Float64List.fromList([0, 0, 3, 4]), 2).distances);
}[0.0, 5.0, 5.0, 0.0]
VietorisRips.distances(this.distances, this.n)import 'package:riptide_topology/riptide_topology.ray';
import 'package:riptide_rational_geometry/riptide_rational_geometry.ray' show qv, Vec;
import 'package:riptide_precision/riptide_precision.ray' show Rational;
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f4(num x) => x.isInfinite ? '∞' : x.toStringAsFixed(4);
void main() {
final r = VietorisRips.distances(Float64List.fromList([0, 1, 2, 1, 0, 1, 2, 1, 0]), 3);
print('enclosing radius ${r.enclosingRadius}');
}enclosing radius 1.0
Properties
final Float64List distancesfinal int ndouble get enclosingRadiusThe enclosing radius \min_{i} \max_{j} d(i, j): at this scale the complex is a cone on the centre point, so every class above dimension 0 has died and larger simplices change nothing (Ripser's default threshold).
Methods
PersistenceDiagram persistence({int maxDim = 1, double threshold = double.infinity, int prime = 2})The barcodes in dimensions 0 … maxDim over Z/prime, using simplices of diameter ≤ threshold. With no threshold the enclosing radius is used, which gives the same diagram (only H₀'s infinite class needs more).
import 'package:riptide_topology/riptide_topology.ray';
import 'package:riptide_rational_geometry/riptide_rational_geometry.ray' show qv, Vec;
import 'package:riptide_precision/riptide_precision.ray' show Rational;
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f4(num x) => x.isInfinite ? '∞' : x.toStringAsFixed(4);
void main() {
final r = VietorisRips.points(Float64List.fromList([0, 0, 1, 0, 0, 1, 1, 1]), 2);
print(r.persistence(maxDim: 1, threshold: 1.2).pairs.map((p) => 'H${p.dimension}[${f4(p.birth)}, ${f4(p.death)})').join(' '));
}H0[0.0000, ∞) H0[0.0000, 1.0000) H0[0.0000, 1.0000) H0[0.0000, 1.0000) H1[1.0000, ∞)
SimplicialComplex
final class SimplicialComplex implements ChainComplex
A finite abstract simplicial complex: every face of a simplex is in it. Simplices are sorted vertex lists; within each dimension they are numbered in lexicographic order, and the chain complex uses that numbering with the standard orientation \partial[v_{0}\cdots v_{k}] = \sum (-1)^{i} [v_{0}\cdots\hat{v}_{i}\cdots v_{k}].
import 'package:riptide_topology/riptide_topology.ray';
import 'package:riptide_rational_geometry/riptide_rational_geometry.ray' show qv, Vec;
import 'package:riptide_precision/riptide_precision.ray' show Rational;
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f4(num x) => x.isInfinite ? '∞' : x.toStringAsFixed(4);
void main() {
final k = SimplicialComplex([[0, 1, 2], [2, 3], [3, 4], [4, 2]]);
print('betti ${k.bettiNumbers()}, χ ${k.eulerCharacteristic}');
}betti [1, 1, 0], χ 0
Constructors
factory SimplicialComplex(Iterable<List<int>> simplices)The closure of simplices (any vertex order; duplicates allowed).
import 'package:riptide_topology/riptide_topology.ray';
import 'package:riptide_rational_geometry/riptide_rational_geometry.ray' show qv, Vec;
import 'package:riptide_precision/riptide_precision.ray' show Rational;
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f4(num x) => x.isInfinite ? '∞' : x.toStringAsFixed(4);
void main() {
final k = SimplicialComplex([[2, 0, 1]]);
print('closure: ${k.allSimplices.toList()}');
}closure: [[0], [1], [2], [0, 1], [0, 2], [1, 2], [0, 1, 2]]
factory SimplicialComplex.sphere(int n)The boundary of the (n + 1)-simplex on vertices 0 \cdots n + 1: a triangulated n-sphere.
import 'package:riptide_topology/riptide_topology.ray';
import 'package:riptide_rational_geometry/riptide_rational_geometry.ray' show qv, Vec;
import 'package:riptide_precision/riptide_precision.ray' show Rational;
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f4(num x) => x.isInfinite ? '∞' : x.toStringAsFixed(4);
void main() {
for (final n in [1, 2, 3]) print('S$n: betti ${SimplicialComplex.sphere(n).bettiNumbers()}');
}S1: betti [1, 1] S2: betti [1, 0, 1] S3: betti [1, 0, 0, 1]
factory SimplicialComplex.simplex(int n)The full n-simplex (contractible).
import 'package:riptide_topology/riptide_topology.ray';
import 'package:riptide_rational_geometry/riptide_rational_geometry.ray' show qv, Vec;
import 'package:riptide_precision/riptide_precision.ray' show Rational;
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f4(num x) => x.isInfinite ? '∞' : x.toStringAsFixed(4);
void main() {
print(SimplicialComplex.simplex(3).bettiNumbers());
}[1, 0, 0, 0]
Static
static List<List<int>> facets(List<int> simplex)The codimension-1 faces of simplex (vertex i removed, i = 0 \cdots k).
import 'package:riptide_topology/riptide_topology.ray';
import 'package:riptide_rational_geometry/riptide_rational_geometry.ray' show qv, Vec;
import 'package:riptide_precision/riptide_precision.ray' show Rational;
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f4(num x) => x.isInfinite ? '∞' : x.toStringAsFixed(4);
void main() {
print(SimplicialComplex.facets([0, 1, 2]));
}[[1, 2], [0, 2], [0, 1]]
Properties
int get dimensionList<int> get verticesList<List<int>> get facetsOfComplexThe maximal simplices (faces of nothing else).
bool get isConnectedMethods
int cellCount(int k)import 'package:riptide_topology/riptide_topology.ray';
import 'package:riptide_rational_geometry/riptide_rational_geometry.ray' show qv, Vec;
import 'package:riptide_precision/riptide_precision.ray' show Rational;
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f4(num x) => x.isInfinite ? '∞' : x.toStringAsFixed(4);
void main() {
print([for (var k = 0; k <= 2; k++) SimplicialComplex.sphere(2).cellCount(k)]);
}[4, 6, 4]
List<List<int>> simplices(int k)The k-simplices in lexicographic order.
import 'package:riptide_topology/riptide_topology.ray';
import 'package:riptide_rational_geometry/riptide_rational_geometry.ray' show qv, Vec;
import 'package:riptide_precision/riptide_precision.ray' show Rational;
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f4(num x) => x.isInfinite ? '∞' : x.toStringAsFixed(4);
void main() {
print(SimplicialComplex.sphere(2).simplices(1));
}[[0, 1], [0, 2], [0, 3], [1, 2], [1, 3], [2, 3]]
int indexOf(List<int> simplex)The index of simplex among the simplices of its dimension, or -1.
import 'package:riptide_topology/riptide_topology.ray';
import 'package:riptide_rational_geometry/riptide_rational_geometry.ray' show qv, Vec;
import 'package:riptide_precision/riptide_precision.ray' show Rational;
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f4(num x) => x.isInfinite ? '∞' : x.toStringAsFixed(4);
void main() {
print(SimplicialComplex.sphere(2).indexOf([1, 2]));
}3
bool contains(List<int> simplex)import 'package:riptide_topology/riptide_topology.ray';
import 'package:riptide_rational_geometry/riptide_rational_geometry.ray' show qv, Vec;
import 'package:riptide_precision/riptide_precision.ray' show Rational;
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f4(num x) => x.isInfinite ? '∞' : x.toStringAsFixed(4);
void main() {
print(SimplicialComplex.sphere(2).contains([0, 1, 2, 3]));
}false
List<List<int>> cofacets(List<int> simplex)The simplices of dimension k + 1 that have simplex as a face.
import 'package:riptide_topology/riptide_topology.ray';
import 'package:riptide_rational_geometry/riptide_rational_geometry.ray' show qv, Vec;
import 'package:riptide_precision/riptide_precision.ray' show Rational;
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f4(num x) => x.isInfinite ? '∞' : x.toStringAsFixed(4);
void main() {
print(SimplicialComplex.sphere(2).cofacets([0, 1]));
}[[0, 1, 2], [0, 1, 3]]
SimplicialComplex skeleton(int k)The k-skeleton: simplices of dimension \le k.
import 'package:riptide_topology/riptide_topology.ray';
import 'package:riptide_rational_geometry/riptide_rational_geometry.ray' show qv, Vec;
import 'package:riptide_precision/riptide_precision.ray' show Rational;
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f4(num x) => x.isInfinite ? '∞' : x.toStringAsFixed(4);
void main() {
print('1-skeleton of the tetrahedron: betti ${SimplicialComplex.simplex(3).skeleton(1).bettiNumbers()}');
}1-skeleton of the tetrahedron: betti [1, 3]
SimplicialComplex link(List<int> simplex)The link of simplex: faces \tau disjoint from it with \tau \cup \sigma in the complex.
import 'package:riptide_topology/riptide_topology.ray';
import 'package:riptide_rational_geometry/riptide_rational_geometry.ray' show qv, Vec;
import 'package:riptide_precision/riptide_precision.ray' show Rational;
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f4(num x) => x.isInfinite ? '∞' : x.toStringAsFixed(4);
void main() {
print(Triangulations.octahedron().complex.link([0]).bettiNumbers());
}[1, 1]
SimplicialComplex star(List<int> simplex)The closed star of simplex: every simplex containing it, with its faces.
import 'package:riptide_topology/riptide_topology.ray';
import 'package:riptide_rational_geometry/riptide_rational_geometry.ray' show qv, Vec;
import 'package:riptide_precision/riptide_precision.ray' show Rational;
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f4(num x) => x.isInfinite ? '∞' : x.toStringAsFixed(4);
void main() {
print(Triangulations.octahedron().complex.star([0]).cellCount(2));
}4
SparseIntMatrix boundary(int k)import 'package:riptide_topology/riptide_topology.ray';
import 'package:riptide_rational_geometry/riptide_rational_geometry.ray' show qv, Vec;
import 'package:riptide_precision/riptide_precision.ray' show Rational;
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f4(num x) => x.isInfinite ? '∞' : x.toStringAsFixed(4);
void main() {
print(SimplicialComplex.simplex(2).boundary(2).toDense());
}[[1], [-1], [1]]
SimplicialComplex cone(int apex)The join with a cone point apex (a vertex not in the complex): contractible.
import 'package:riptide_topology/riptide_topology.ray';
import 'package:riptide_rational_geometry/riptide_rational_geometry.ray' show qv, Vec;
import 'package:riptide_precision/riptide_precision.ray' show Rational;
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f4(num x) => x.isInfinite ? '∞' : x.toStringAsFixed(4);
void main() {
print(SimplicialComplex.sphere(1).cone(9).bettiNumbers());
}[1, 0, 0]
SimplicialComplex suspension(int north, int south)The suspension (two cone points): \Sigma K has \tilde{H}_{k + 1}(\Sigma K) = \tilde{H}_{k}(K).
import 'package:riptide_topology/riptide_topology.ray';
import 'package:riptide_rational_geometry/riptide_rational_geometry.ray' show qv, Vec;
import 'package:riptide_precision/riptide_precision.ray' show Rational;
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f4(num x) => x.isInfinite ? '∞' : x.toStringAsFixed(4);
void main() {
print('ΣS¹ = S²: ${SimplicialComplex.sphere(1).suspension(8, 9).bettiNumbers()}');
}ΣS¹ = S²: [1, 0, 1]
String toString()SurfaceClass
final class SurfaceClass
Where a connected compact surface sits in the classification: the sphere with genus handles (orientable) or with genus cross-caps (non-orientable), minus boundaryComponents open disks.
import 'package:riptide_topology/riptide_topology.ray';
import 'package:riptide_rational_geometry/riptide_rational_geometry.ray' show qv, Vec;
import 'package:riptide_precision/riptide_precision.ray' show Rational;
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f4(num x) => x.isInfinite ? '∞' : x.toStringAsFixed(4);
void main() {
print(Triangulations.mobiusBand().classification.name);
}Möbius band
Constructors
const SurfaceClass({required this.orientable, required this.genus, required this.boundaryComponents})import 'package:riptide_topology/riptide_topology.ray';
import 'package:riptide_rational_geometry/riptide_rational_geometry.ray' show qv, Vec;
import 'package:riptide_precision/riptide_precision.ray' show Rational;
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f4(num x) => x.isInfinite ? '∞' : x.toStringAsFixed(4);
void main() {
print(const SurfaceClass(orientable: true, genus: 2, boundaryComponents: 0).name);
}T²#T²
Properties
final bool orientablefinal int boundaryComponentsint get eulerCharacteristicint get hashCodeMethods
String toString()Operators
bool operator ==(Object other)import 'package:riptide_topology/riptide_topology.ray';
import 'package:riptide_rational_geometry/riptide_rational_geometry.ray' show qv, Vec;
import 'package:riptide_precision/riptide_precision.ray' show Rational;
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f4(num x) => x.isInfinite ? '∞' : x.toStringAsFixed(4);
void main() {
print(Triangulations.torus7().classification == const SurfaceClass(orientable: true, genus: 1, boundaryComponents: 0));
}true
TriangulatedSurface
final class TriangulatedSurface
A triangulated compact surface (2-manifold, possibly with boundary): every edge lies in one or two triangles and every vertex link is one path or one cycle. Triangles keep the vertex order given.
import 'package:riptide_topology/riptide_topology.ray';
import 'package:riptide_rational_geometry/riptide_rational_geometry.ray' show qv, Vec;
import 'package:riptide_precision/riptide_precision.ray' show Rational;
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f4(num x) => x.isInfinite ? '∞' : x.toStringAsFixed(4);
void main() {
for (final s in [Triangulations.tetrahedron(), Triangulations.torus7(), Triangulations.projectivePlane6(), Triangulations.mobiusBand()]) print(s.classification.name);
}sphere torus real projective plane Möbius band
Constructors
TriangulatedSurface(List<List<int>> triangles)import 'package:riptide_topology/riptide_topology.ray';
import 'package:riptide_rational_geometry/riptide_rational_geometry.ray' show qv, Vec;
import 'package:riptide_precision/riptide_precision.ray' show Rational;
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f4(num x) => x.isInfinite ? '∞' : x.toStringAsFixed(4);
void main() {
print(TriangulatedSurface([[0, 1, 2], [0, 2, 3]]).classification.name);
}disk
factory TriangulatedSurface.fromComplex(SimplicialComplex k)Any simplicial 2-complex that is a surface.
import 'package:riptide_topology/riptide_topology.ray';
import 'package:riptide_rational_geometry/riptide_rational_geometry.ray' show qv, Vec;
import 'package:riptide_precision/riptide_precision.ray' show Rational;
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f4(num x) => x.isInfinite ? '∞' : x.toStringAsFixed(4);
void main() {
print(TriangulatedSurface.fromComplex(SimplicialComplex.sphere(2)).classification.name);
}sphere
Properties
final List<List<int>> trianglesfinal SimplicialComplex complexint get vertexCountint get eulerCharacteristicbool get isConnectedbool get isClosedList<List<int>> get boundaryComponentsThe boundary circles, as cyclic vertex lists.
late final List<List<int>>? orientationA coherent orientation of the triangles (each listed so that a shared edge is traversed in opposite directions by its two triangles), or null when the surface is non-orientable.
bool get isOrientableSurfaceClass get classificationThe classification of a connected surface: orientability, genus (handles or cross-caps) from \chi and the number of boundary circles.
Methods
TriangulatedSurface orientationDoubleCover()The orientation double cover: two copies of each triangle (one per orientation) glued so the result is oriented. Connected exactly when this surface is non-orientable (RP² \to S^{2}, Klein bottle \to T^{2}).
import 'package:riptide_topology/riptide_topology.ray';
import 'package:riptide_rational_geometry/riptide_rational_geometry.ray' show qv, Vec;
import 'package:riptide_precision/riptide_precision.ray' show Rational;
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f4(num x) => x.isInfinite ? '∞' : x.toStringAsFixed(4);
void main() {
print('double cover of RP²: ${Triangulations.projectivePlane6().orientationDoubleCover().classification.name}');
}double cover of RP²: sphere
TriangulatedSurface connectedSum(TriangulatedSurface other)The connected sum: a triangle is removed from each and the two holes are glued (the second surface's vertices are renumbered after this one's; its glued triangle is reversed so orientations agree).
import 'package:riptide_topology/riptide_topology.ray';
import 'package:riptide_rational_geometry/riptide_rational_geometry.ray' show qv, Vec;
import 'package:riptide_precision/riptide_precision.ray' show Rational;
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f4(num x) => x.isInfinite ? '∞' : x.toStringAsFixed(4);
void main() {
print(Triangulations.torus7().connectedSum(Triangulations.torus7()).classification.name);
}T²#T²
List<HomologyGroup> homology()Homology over Z (H_{1} of RP² is \frac{Z}{2}).
import 'package:riptide_topology/riptide_topology.ray';
import 'package:riptide_rational_geometry/riptide_rational_geometry.ray' show qv, Vec;
import 'package:riptide_precision/riptide_precision.ray' show Rational;
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f4(num x) => x.isInfinite ? '∞' : x.toStringAsFixed(4);
void main() {
print(Triangulations.projectivePlane6().homology());
}[Z, Z/2, 0]
final class Triangulated3Manifold
A triangulated closed 3-manifold: every triangle lies in exactly two tetrahedra and every vertex link is a triangulated 2-sphere. isManifold is false for a closed pseudomanifold whose links are other surfaces.
import 'package:riptide_topology/riptide_topology.ray';
import 'package:riptide_rational_geometry/riptide_rational_geometry.ray' show qv, Vec;
import 'package:riptide_precision/riptide_precision.ray' show Rational;
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f4(num x) => x.isInfinite ? '∞' : x.toStringAsFixed(4);
void main() {
final s = Triangulations.sphere3();
print('orientable ${s.isOrientable}, H ${s.homology()}');
}orientable true, H [Z, 0, 0, Z]
Constructors
Triangulated3Manifold(List<List<int>> tetrahedra)import 'package:riptide_topology/riptide_topology.ray';
import 'package:riptide_rational_geometry/riptide_rational_geometry.ray' show qv, Vec;
import 'package:riptide_precision/riptide_precision.ray' show Rational;
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f4(num x) => x.isInfinite ? '∞' : x.toStringAsFixed(4);
void main() {
print(Triangulated3Manifold(SimplicialComplex.sphere(3).simplices(3)).vertexLinks.values.first.name);
}sphere
Properties
final List<List<int>> tetrahedrafinal SimplicialComplex complexMap<int, SurfaceClass> get vertexLinksEach vertex link, classified (a 2-sphere at every vertex for a manifold).
bool get isManifoldint get eulerCharacteristicbool get isOrientableWhether the tetrahedra can be oriented coherently (each shared triangle induced with opposite orientations).
Methods
List<HomologyGroup> homology()import 'package:riptide_topology/riptide_topology.ray';
import 'package:riptide_rational_geometry/riptide_rational_geometry.ray' show qv, Vec;
import 'package:riptide_precision/riptide_precision.ray' show Rational;
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f4(num x) => x.isInfinite ? '∞' : x.toStringAsFixed(4);
void main() {
print(Triangulations.sphere3().homology());
}[Z, 0, 0, Z]
Triangulations
abstract final class Triangulations
Standard triangulations for tests and demos.
import 'package:riptide_topology/riptide_topology.ray';
import 'package:riptide_rational_geometry/riptide_rational_geometry.ray' show qv, Vec;
import 'package:riptide_precision/riptide_precision.ray' show Rational;
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f4(num x) => x.isInfinite ? '∞' : x.toStringAsFixed(4);
void main() {
print(Triangulations.orientable(2).classification.name);
}T²#T²
Static
static TriangulatedSurface tetrahedron()The boundary of the tetrahedron: S^{2} with 4 vertices.
import 'package:riptide_topology/riptide_topology.ray';
import 'package:riptide_rational_geometry/riptide_rational_geometry.ray' show qv, Vec;
import 'package:riptide_precision/riptide_precision.ray' show Rational;
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f4(num x) => x.isInfinite ? '∞' : x.toStringAsFixed(4);
void main() {
print(Triangulations.tetrahedron().classification.name);
}sphere
static TriangulatedSurface octahedron()The octahedron: S^{2} with 6 vertices (\pm x = \frac{0}{1}, \pm y = \frac{2}{3}, \pm z = \frac{4}{5}).
import 'package:riptide_topology/riptide_topology.ray';
import 'package:riptide_rational_geometry/riptide_rational_geometry.ray' show qv, Vec;
import 'package:riptide_precision/riptide_precision.ray' show Rational;
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f4(num x) => x.isInfinite ? '∞' : x.toStringAsFixed(4);
void main() {
print(Triangulations.octahedron().homology());
}[Z, 0, Z]
static TriangulatedSurface torus7()Möbius' 7-vertex torus (Császár): triangles \{i, i + 1, i + 3\} and \{i, i + 3, i + 2\} \bmod 7; its 1-skeleton is K_{7}.
import 'package:riptide_topology/riptide_topology.ray';
import 'package:riptide_rational_geometry/riptide_rational_geometry.ray' show qv, Vec;
import 'package:riptide_precision/riptide_precision.ray' show Rational;
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f4(num x) => x.isInfinite ? '∞' : x.toStringAsFixed(4);
void main() {
final t = Triangulations.torus7();
print('${t.complex.cellCount(0)} vertices, ${t.homology()}');
}7 vertices, [Z, Z^2, Z]
static TriangulatedSurface projectivePlane6()The 6-vertex real projective plane (the hemi-icosahedron; its 1-skeleton is K_{6}).
import 'package:riptide_topology/riptide_topology.ray';
import 'package:riptide_rational_geometry/riptide_rational_geometry.ray' show qv, Vec;
import 'package:riptide_precision/riptide_precision.ray' show Rational;
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f4(num x) => x.isInfinite ? '∞' : x.toStringAsFixed(4);
void main() {
print(Triangulations.projectivePlane6().homology());
}[Z, Z/2, 0]
static TriangulatedSurface mobiusBand()The 5-vertex Möbius band: triangles \{i, i + 1, i + 2\} \bmod 5; the boundary is the 5-cycle of edges \{i, i + 2\}.
import 'package:riptide_topology/riptide_topology.ray';
import 'package:riptide_rational_geometry/riptide_rational_geometry.ray' show qv, Vec;
import 'package:riptide_precision/riptide_precision.ray' show Rational;
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f4(num x) => x.isInfinite ? '∞' : x.toStringAsFixed(4);
void main() {
print(Triangulations.mobiusBand().boundaryEdges);
}[[0, 2], [1, 3], [2, 4], [0, 3], [1, 4]]
static TriangulatedSurface grid(int m, int n, {bool twist = false, bool periodicJ = true})An m \times n grid of squares (two triangles each) with its sides glued: twist glues the left and right sides with a flip (a Klein bottle), periodicJ false leaves the top and bottom open (an annulus, or a Möbius band with twist). m, n \ge 3 keep it simplicial.
import 'package:riptide_topology/riptide_topology.ray';
import 'package:riptide_rational_geometry/riptide_rational_geometry.ray' show qv, Vec;
import 'package:riptide_precision/riptide_precision.ray' show Rational;
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f4(num x) => x.isInfinite ? '∞' : x.toStringAsFixed(4);
void main() {
print(Triangulations.grid(3, 3, twist: true).classification.name);
}Klein bottle
static TriangulatedSurface torusGrid(int m, int n)import 'package:riptide_topology/riptide_topology.ray';
import 'package:riptide_rational_geometry/riptide_rational_geometry.ray' show qv, Vec;
import 'package:riptide_precision/riptide_precision.ray' show Rational;
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f4(num x) => x.isInfinite ? '∞' : x.toStringAsFixed(4);
void main() {
print(Triangulations.torusGrid(3, 4).homology());
}[Z, Z^2, Z]
static TriangulatedSurface kleinBottleGrid(int m, int n)import 'package:riptide_topology/riptide_topology.ray';
import 'package:riptide_rational_geometry/riptide_rational_geometry.ray' show qv, Vec;
import 'package:riptide_precision/riptide_precision.ray' show Rational;
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f4(num x) => x.isInfinite ? '∞' : x.toStringAsFixed(4);
void main() {
print(Triangulations.kleinBottleGrid(3, 4).homology());
}[Z, Z ⊕ Z/2, 0]
static TriangulatedSurface orientable(int g)The closed orientable surface of genus g (connected sums of 7-vertex tori; the sphere for 0).
import 'package:riptide_topology/riptide_topology.ray';
import 'package:riptide_rational_geometry/riptide_rational_geometry.ray' show qv, Vec;
import 'package:riptide_precision/riptide_precision.ray' show Rational;
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f4(num x) => x.isInfinite ? '∞' : x.toStringAsFixed(4);
void main() {
print(Triangulations.orientable(3).homology());
}[Z, Z^6, Z]
static TriangulatedSurface nonOrientable(int k)The connected sum of k ≥ 1 projective planes.
import 'package:riptide_topology/riptide_topology.ray';
import 'package:riptide_rational_geometry/riptide_rational_geometry.ray' show qv, Vec;
import 'package:riptide_precision/riptide_precision.ray' show Rational;
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f4(num x) => x.isInfinite ? '∞' : x.toStringAsFixed(4);
void main() {
print(Triangulations.nonOrientable(2).classification.name);
}Klein bottle
static Triangulated3Manifold sphere3()S^{3} as the boundary of the 4-simplex (5 vertices, 5 tetrahedra).
import 'package:riptide_topology/riptide_topology.ray';
import 'package:riptide_rational_geometry/riptide_rational_geometry.ray' show qv, Vec;
import 'package:riptide_precision/riptide_precision.ray' show Rational;
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f4(num x) => x.isInfinite ? '∞' : x.toStringAsFixed(4);
void main() {
print(Triangulations.sphere3().vertexLinks.values.map((s) => s.name).toSet());
}{sphere}static SimplicialComplex torus(int n, int m)The n-torus T^{n} as an m^{n} grid of cubes, each cut into n! simplices along the Freudenthal–Kuhn triangulation (m \ge 3 keeps it simplicial). As a SimplicialComplex; for n = 3 wrap it in Triangulated3Manifold.
import 'package:riptide_topology/riptide_topology.ray';
import 'package:riptide_rational_geometry/riptide_rational_geometry.ray' show qv, Vec;
import 'package:riptide_precision/riptide_precision.ray' show Rational;
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f4(num x) => x.isInfinite ? '∞' : x.toStringAsFixed(4);
void main() {
print('T³: betti ${Triangulations.torus(3, 3).bettiNumbers()}');
}T³: betti [1, 3, 3, 1]