RiptideRiptide
Download Riptide SDKInstall Riptorch
Menu
Raya docs · Exact and higher mathematics

Topology

Homology and cohomology over the integers and Z/p, persistent homology (Vietoris–Rips, alpha, cubical), mapper, discrete Morse theory and 3-manifolds.

import 'package:riptide_topology/riptide_topology.ray';
28 classes179 functions and methods140 of 269 documented144 runnable examplesWhat GUDHI and Ripser do

Overview

Computational topology. Depends on riptide_numerics_spatial (Delaunay for alpha complexes, KD-tree for mapper).

AreaAPI
ComplexesSimplicialComplex (closure, skeleta, faces/cofacets, link, star, cone, suspension), CellComplex (CW: RP^n, lens spaces, surfaces), CubicalComplex (images, voxels, periodic tori) — all ChainComplex
Homologyhomology / 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
PersistenceFilteredComplex (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
Mappermapper(points, dim, lens, intervals, overlap, epsilon:) → nodes and nerve
\pi_{1}fundamentalGroup(complex) → GroupPresentation (Tietze-simplified), abelianization
MorseDiscreteGradient.lowerStar, Morse numbers and inequalities, MorseSmaleComplex (arcs saddle → min/max), plCriticalPoints
ManifoldsTriangulatedSurface (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

cyclicCoverfunction
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.

Example
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()}');
}
Output
vertices 9, edges 9, betti [1, 1]
barcodeScenefunction
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.

Example
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());
}
Output
[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.

Example
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');
}
Output
π₁(torus) = ⟨a, b | aba⁻¹b⁻¹⟩, abelianised Z^2
π₁(RP²) = ⟨a | a⁻¹a⁻¹⟩
mapperfunction
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.

Example
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()}');
}
Output
6 nodes; betti of the nerve [1, 1]
modInversefunction
int modInverse(int a, int p)

a^{-1} mod p for prime p.

Example
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)}');
}
Output
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.

Example
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');
}
Output
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.

Example
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)])));
}
Output
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.

Example
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)])));
}
Output
0.2500
hungarianfunction
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})).

Example
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]]));
}
Output
5.0

Constants and variables

const int rationalPrime = 2147483647

A 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

Celltypedef
typedef Cell = ({int dim, int index})

A cell of a simplicial complex: its dimension and index within that dimension.

Classes

final class AlphaComplex

An alpha complex in 2-D or 3-D.

Example
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)})']}');
}
Output
H1 intervals: [[0.1464, 1.0000)]

Constructors

factory AlphaComplex(Float64List points, int dim)

From interleaved points with dim = 2 or 3 coordinates.

Example
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');
}
Output
6 Delaunay triangles

Properties

pointsfield
final Float64List points
dimfield
final int dim
complexfield
final SimplicialComplex complex

The Delaunay complex.

valuesfield
final List<Float64List> values

The filtration value (squared radius) of each simplex, by dimension and index.

FilteredComplex get filtration

Methods

atmethod
SimplicialComplex at(double alpha2)

The subcomplex at squared radius ≤ alpha2.

Example
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()}');
}
Output
α² = 0.1: betti [8]
α² = 0.2: betti [1, 1]
α² = 1.0: betti [1, 1, 0]
PersistenceDiagram persistence({int prime = 2})
Example
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);
}
Output
1
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).

Example
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()}');
}
Output
cells [1, 2, 1], H = [Z, Z^2, Z]

Properties

dimensiongetter
int get dimension

The top dimension with cells (-1 when empty).

Methods

cellCountmethod
int cellCount(int k)
Example
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));
}
Output
6
boundarymethod
SparseIntMatrix boundary(int k)
Example
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());
}
Output
[[1], [-1], [1]]
final class HomologyGroup

A finitely generated abelian group Z^rank ⊕ \frac{Z}{t_{1}} \oplus \cdots \oplus \frac{Z}{t_{m}}.

Example
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])}');
}
Output
Z² ⊕ Z/2 = Z^2 ⊕ Z/2

Constructors

HomologyGroupconstructor
const HomologyGroup(this.rank, [this.torsion = const []])
Example
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])}');
}
Output
Z, Z/2 ⊕ Z/4

Properties

rankfield
final int rank
torsionfield
final List<int> torsion

Torsion coefficients (each > 1, each dividing the next).

isTrivialgetter
bool get isTrivial
hashCodegetter
int get hashCode

Methods

toStringmethod
String toString()

Operators

operator ==operator
bool operator ==(Object other)
Example
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]));
}
Output
true
extension

Homology

extension Homology on ChainComplex

Homology and cohomology of any ChainComplex.

Example
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()}');
}
Output
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 isChainComplex

Whether \partial_{k - 1} \circ \partial_{k} = 0 for every k (a sanity check on hand-built complexes).

Methods

homologymethod
List<HomologyGroup> homology()

H_{k}(C; Z) for k = 0 \cdots dimension, with torsion from the Smith normal form of each \partial.

Example
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()}');
}
Output
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}).

Example
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)');
}
Output
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.

Example
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)}');
}
Output
over Q [1, 0, 0], over Z/2 [1, 1, 1]
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.

Example
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}');
}
Output
genus 2: [Z, Z^4, Z], χ -2

Constructors

CellComplexconstructor
CellComplex(this.cellCounts, this.boundaries)
Example
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());
}
Output
[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).

Example
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());
}
Output
[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.

Example
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()}');
}
Output
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.

Example
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());
}
Output
[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}).

Example
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());
}
Output
[Z, Z^2 ⊕ Z/2, 0]

Properties

final List<int> cellCounts
final List<SparseIntMatrix> boundaries
dimensiongetter
int get dimension

Methods

cellCountmethod
int cellCount(int k)
Example
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)]);
}
Output
[1, 4, 1]
boundarymethod
SparseIntMatrix boundary(int k)
Example
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());
}
Output
[[2]]
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.

Example
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(' '));
}
Output
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.

Example
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()}');
}
Output
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).

Example
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());
}
Output
[]
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).

Example
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);
}
Output
2

Properties

shapefield
final List<int> shape
final bool periodic
dimensiongetter
int get dimension
FilteredComplex get filtration

The sublevel filtration of the values.

Methods

cellCountmethod
int cellCount(int k)
Example
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)]);
}
Output
[9, 12, 4]
boundarymethod
SparseIntMatrix boundary(int k)
Example
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());
}
Output
[[-1], [1], [-1], [1]]
PersistenceDiagram persistence({int prime = 2})
Example
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);
}
Output
1
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.

Example
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()}');
}
Output
⟨a, b | aba⁻¹b⁻¹⟩: abelianisation Z^2

Constructors

GroupPresentation(this.generatorCount, List<List<int>> relators)
Example
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());
}
Output
Z/3

Properties

final int generatorCount
final List<List<int>> relators
int get deficiency

The deficiency #generators − #relators.

bool get isTriviallyTrivial
isFreegetter
bool get isFree

Methods

HomologyGroup abelianization()

The abelianization \frac{G}{[G, G]} (= H_{1} for a fundamental group), from the Smith normal form of the exponent-sum matrix.

Example
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());
}
Output
Z
simplifymethod
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).

Example
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());
}
Output
⟨a, b | bb⟩
toStringmethod
String toString()
final class MapperNode

One mapper node: the points of one cluster of one interval's preimage.

Example
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}');
}
Output
interval 2, members [4, 5, 6]

Constructors

MapperNodeconstructor
const MapperNode(this.interval, this.members)
Example
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);
}
Output
[1]

Properties

final int interval
membersfield
final List<int> members
final class MapperGraph

The mapper graph and its nerve.

Example
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');
}
Output
4 nodes, 0 edges

Constructors

MapperGraphconstructor
MapperGraph(this.nodes, this.nerve)
Example
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));
}
Output
1

Properties

nodesfield
final List<MapperNode> nodes
nervefield
final SimplicialComplex nerve

The nerve: node i is vertex i; an edge (triangle) when two (three) clusters share a point.

edgesgetter
List<List<int>> get edges
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.

Example
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)}');
}
Output
invariant factors [2, 4], rank mod 2 0

Constructors

SparseIntMatrixconstructor
SparseIntMatrix(this.rows, this.cols)
Example
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());
}
Output
[[0, 5, 0], [0, 0, 0]]
SparseIntMatrix.fromColumns(this.rows, this.columns)
Example
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());
}
Output
[[1, 0], [0, -1]]
factory SparseIntMatrix.fromDense(List<List<int>> a)
Example
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());
}
Output
[[1, 3], [2, 4]]

Properties

rowsfield
final int rows
colsfield
final int cols
columnsfield
final List<Map<int, int>> columns
nonZerosgetter
int get nonZeros
isZerogetter
bool get isZero

Methods

setmethod
void set(int row, int col, int value)
Example
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());
}
Output
[[0, 0], [7, 0]]
toDensemethod
List<List<int>> toDense()
Example
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());
}
Output
[[-1, -1, 0], [1, 0, -1], [0, 1, 1]]
transposemethod
SparseIntMatrix transpose()
Example
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());
}
Output
[[1], [2], [3]]
multiplymethod
SparseIntMatrix multiply(SparseIntMatrix b)

The product this · b.

Example
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());
}
Output
[[0], [0], [0]]
rankModPmethod
int rankModP(int p)

The rank over the field Z/p (p prime). With a large prime this is the rank over Q.

Example
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)}');
}
Output
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.

Example
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());
}
Output
[2, 4]

Operators

operator []operator
int operator [](({int row, int col}) at)
Example
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)]);
}
Output
3
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).

Example
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}');
}
Output
diagonal [2, 6, 12]

Constructors

factory SmithNormalForm.of(List<List<int>> a)
Example
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);
}
Output
[1, 2]

Properties

final List<int> diagonal

The nonzero invariant factors, each dividing the next.

dfield
final List<List<int>> d

D, U and V with D = U \cdot A \cdot V.

ufield
final List<List<int>> u

D, U and V with D = U \cdot A \cdot V.

vfield
final List<List<int>> v

D, U and V with D = U \cdot A \cdot V.

rankgetter
int get rank
final class DiscreteGradient

A discrete gradient vector field: pairs (\sigma, \tau) of a cell and a cofacet, the rest critical.

Example
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()}');
}
Output
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.

Example
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}');
}
Output
critical cells per dimension [1, 2, 1]

Properties

complexfield
final SimplicialComplex complex
pairsgetter
List<(Cell, Cell)> get pairs

The gradient pairs (\sigma, \tau) with \sigma a facet of \tau.

List<List<int>> get criticalCells

Critical cells by dimension.

List<int> get morseNumbers

The number of critical cells in each dimension (the Morse numbers c_{k}).

Methods

bool isCritical(Cell c)
Example
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)));
}
Output
true
partnerOfmethod
Cell? partnerOf(Cell c)

The cell paired with c (a facet or a cofacet), or null when c is critical.

Example
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)));
}
Output
(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.

Example
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()));
}
Output
true
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.

Example
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}');
}
Output
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

MorseSmaleArcconstructor
const MorseSmaleArc(this.saddle, this.extremum, this.cells)
Example
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);
}
Output
(dim: 0, index: 1)

Properties

saddlefield
final int saddle
final Cell extremum
cellsfield
final List<Cell> cells

The cells along the path, from the saddle.

toMinimumgetter
bool get toMinimum
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).

Example
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');
}
Output
8 arcs, 4 two-cells

Constructors

MorseSmaleComplex(this.gradient)
Example
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);
}
Output
0

Properties

final DiscreteGradient gradient
arcsfield
final List<MorseSmaleArc> arcs
minimagetter
List<int> get minima
saddlesgetter
List<int> get saddles
maximagetter
List<int> get maxima
int get cellCount2

The 2-cells (quadrilaterals for a generic gradient on a closed surface): arcs − nodes + \chi.

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)).

Example
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}');
}
Output
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

PlCriticalPointconstructor
const PlCriticalPoint(this.vertex, this.kind, this.multiplicity)
Example
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);
}
Output
-2

Properties

vertexfield
final int vertex
kindfield
final String kind

'min', 'max' or 'saddle'.

final int multiplicity
indexgetter
int get index

Its contribution to \chi (the PL Poincaré–Hopf / Banchoff index).

final class PersistencePair

One interval [birth, death) of a k-dimensional class; death is infinite for an essential class.

Example
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}');
}
Output
H1 born 0.5, dies 1.25, persistence 0.75

Constructors

PersistencePairconstructor
const PersistencePair(this.dimension, this.birth, this.death)
Example
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);
}
Output
true

Properties

final int dimension
birthfield
final double birth
deathfield
final double death
double get persistence
bool get isEssential

Methods

toStringmethod
String toString()
final class PersistenceDiagram

A persistence diagram: the multiset of intervals in every dimension.

Example
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');
}
Output
betti at 0.5: [1, 1]; significant: 2 pairs

Constructors

PersistenceDiagram(List<PersistencePair> pairs)
Example
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);
}
Output
1

Properties

pairsfield
final List<PersistencePair> pairs

Sorted by dimension, then longest first.

int get maxDimension

Methods

List<PersistencePair> inDimension(int d)
Example
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}');
}
Output
H0 4, H1 1
bettiAtmethod
List<int> bettiAt(double t)

The Betti numbers of the filtration at t: intervals with birth \le t < death.

Example
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)}');
}
Output
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).

Example
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);
}
Output
1
double bottleneckTo(PersistenceDiagram other, int dim)

The bottleneck distance to other in dimension dim (L\infty ground metric, diagonal allowed).

Example
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)));
}
Output
0.2000
double wassersteinTo(PersistenceDiagram other, int dim, {double q = 1})

The q-Wasserstein distance to other in dimension dim (L\infty ground metric).

Example
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)));
}
Output
0.2000
toStringmethod
String toString()
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.

Example
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(' '));
}
Output
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).

Example
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());
}
Output
[[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.

Example
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);
}
Output
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).

Example
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());
}
Output
[[0.0, Infinity)]

Properties

dimsfield
final List<int> dims
valuesfield
final List<double> values
final List<Map<int, int>> boundaries
lengthgetter
int get length

Methods

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.

Example
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());
}
Output
[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.

Example
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})');
}
Output
1: [1/2, 2)

Constructors

const RationalPersistencePair(this.dimension, this.birth, this.death)
Example
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);
}
Output
null

Properties

final int dimension
birthfield
final Rational birth
deathfield
final Rational? death
bool get isEssential

Methods

toStringmethod
String toString()
final class RationalPersistenceDiagram

A persistence diagram whose values are exact squared lengths.

Example
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(' '));
}
Output
H0[0, null) H0[0, 1) H0[0, 1) H0[0, 1) H1[1, 2)

Constructors

RationalPersistenceDiagram(List<RationalPersistencePair> pairs)
Example
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);
}
Output
1

Properties

pairsfield
final List<RationalPersistencePair> pairs

Methods

List<RationalPersistencePair> inDimension(int d)
Example
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());
}
Output
[[1, 2)]
bettiAtmethod
List<int> bettiAt(Rational q)

Betti numbers at the squared scale q: intervals with birth \le q < death, decided exactly.

Example
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)}');
}
Output
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.

Example
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());
}
Output
[[1.0000, 1.4142)]
PersistenceDiagram toSquaredDiagram()

The float view of the squared values themselves (correctly rounded), e.g. to compare with AlphaComplex.

Example
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());
}
Output
[[1.0000, 2.0000)]
toStringmethod
String toString()
final class RationalVietorisRips

Vietoris–Rips persistence of rational points with the blue quadrance: exact quadrances, exact ties.

Example
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()}');
}
Output
distinct quadrances [0, 1, 2]; H1 [[1, 2)]

Constructors

RationalVietorisRips(List<Vec<Rational>> points)
Example
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);
}
Output
[0, 25, 25, 0]

Properties

pointsfield
final List<Vec<Rational>> points
late final List<Rational> quadrances

The full n \times n quadrance matrix (row-major).

late final List<Rational> distinct

The distinct quadrances in increasing order (the rank filtration's values).

ngetter
int get n

Methods

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).

Example
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(' '));
}
Output
H0[0, null) H0[0, 65/16) H0[0, 4)
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}.

Example
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()}');
}
Output
exactly Delaunay: true; H1 [[4, 25/4)]

Constructors

factory RationalAlphaComplex(List<Vec<Rational>> points)
Example
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);
}
Output
[[0, 0, 0], [1, 5/4, 5/4], [25/16]]

Properties

pointsfield
final List<Vec<Rational>> points
dimfield
final int dim
complexfield
final SimplicialComplex complex

The Delaunay complex.

valuesfield
final List<List<Rational>> values

The exact filtration value (squared radius) of each simplex, by dimension and index.

bool get isExactlyDelaunay

Whether 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

atmethod
SimplicialComplex at(Rational alpha2)

The subcomplex at squared radius ≤ alpha2, decided exactly.

Example
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());
}
Output
[1, 0, 0]
RationalPersistenceDiagram persistence({int prime = 2})
Example
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());
}
Output
[[0, null), [0, 5/4), [0, 1), [5/4, 25/16)]
final class VietorisRips

Vietoris–Rips persistence of a finite metric space.

Example
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());
}
Output
[[0.7654, 1.8478)]

Constructors

factory VietorisRips.points(Float64List points, int dim)

From n points with dim coordinates each, interleaved in points (Euclidean distances).

Example
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);
}
Output
[0.0, 5.0, 5.0, 0.0]
VietorisRips.distances(this.distances, this.n)

From a full symmetric n × n distance matrix (row-major).

Example
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}');
}
Output
enclosing radius 1.0

Properties

final Float64List distances
nfield
final int n
double get enclosingRadius

The 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).

Example
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(' '));
}
Output
H0[0.0000, ∞) H0[0.0000, 1.0000) H0[0.0000, 1.0000) H0[0.0000, 1.0000) H1[1.0000, ∞)
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}].

Example
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}');
}
Output
betti [1, 1, 0], χ 0

Constructors

factory SimplicialComplex(Iterable<List<int>> simplices)

The closure of simplices (any vertex order; duplicates allowed).

Example
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()}');
}
Output
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.

Example
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()}');
}
Output
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).

Example
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());
}
Output
[1, 0, 0, 0]

Static

facetsstaticmethod
static List<List<int>> facets(List<int> simplex)

The codimension-1 faces of simplex (vertex i removed, i = 0 \cdots k).

Example
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]));
}
Output
[[1, 2], [0, 2], [0, 1]]

Properties

dimensiongetter
int get dimension
Iterable<List<int>> get allSimplices

Every simplex, by dimension.

verticesgetter
List<int> get vertices
List<List<int>> get facetsOfComplex

The maximal simplices (faces of nothing else).

List<List<int>> get components

Connected components as vertex lists.

bool get isConnected

Methods

cellCountmethod
int cellCount(int k)
Example
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)]);
}
Output
[4, 6, 4]
simplicesmethod
List<List<int>> simplices(int k)

The k-simplices in lexicographic order.

Example
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));
}
Output
[[0, 1], [0, 2], [0, 3], [1, 2], [1, 3], [2, 3]]
indexOfmethod
int indexOf(List<int> simplex)

The index of simplex among the simplices of its dimension, or -1.

Example
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]));
}
Output
3
containsmethod
bool contains(List<int> simplex)
Example
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]));
}
Output
false
cofacetsmethod
List<List<int>> cofacets(List<int> simplex)

The simplices of dimension k + 1 that have simplex as a face.

Example
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]));
}
Output
[[0, 1, 2], [0, 1, 3]]
skeletonmethod
SimplicialComplex skeleton(int k)

The k-skeleton: simplices of dimension \le k.

Example
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()}');
}
Output
1-skeleton of the tetrahedron: betti [1, 3]
starmethod
SimplicialComplex star(List<int> simplex)

The closed star of simplex: every simplex containing it, with its faces.

Example
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));
}
Output
4
boundarymethod
SparseIntMatrix boundary(int k)
Example
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());
}
Output
[[1], [-1], [1]]
conemethod
SimplicialComplex cone(int apex)

The join with a cone point apex (a vertex not in the complex): contractible.

Example
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());
}
Output
[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).

Example
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()}');
}
Output
ΣS¹ = S²: [1, 0, 1]
toStringmethod
String toString()
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.

Example
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);
}
Output
Möbius band

Constructors

SurfaceClassconstructor
const SurfaceClass({required this.orientable, required this.genus, required this.boundaryComponents})
Example
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);
}
Output
T²#T²

Properties

final bool orientable
genusfield
final int genus

Handles (orientable) or cross-caps (non-orientable).

final int boundaryComponents
int get eulerCharacteristic
symbolgetter
String get symbol

S^{2}, T^{2}, T^{2}#T^{2}, RP², RP²#RP², … with the boundary noted.

namegetter
String get name

The everyday name where there is one.

hashCodegetter
int get hashCode

Methods

toStringmethod
String toString()

Operators

operator ==operator
bool operator ==(Object other)
Example
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));
}
Output
true
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.

Example
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);
}
Output
sphere
torus
real projective plane
Möbius band

Constructors

TriangulatedSurface(List<List<int>> triangles)
Example
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);
}
Output
disk
factory TriangulatedSurface.fromComplex(SimplicialComplex k)

Any simplicial 2-complex that is a surface.

Example
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);
}
Output
sphere

Properties

final List<List<int>> triangles
complexfield
final SimplicialComplex complex
int get vertexCount
int get eulerCharacteristic
bool get isConnected
isClosedgetter
bool get isClosed
List<List<int>> get boundaryEdges

Boundary edges (each in one triangle).

List<List<int>> get boundaryComponents

The boundary circles, as cyclic vertex lists.

late final List<List<int>>? orientation

A 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 isOrientable
SurfaceClass get classification

The 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}).

Example
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}');
}
Output
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).

Example
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);
}
Output
T²#T²
homologymethod
List<HomologyGroup> homology()

Homology over Z (H_{1} of RP² is \frac{Z}{2}).

Example
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());
}
Output
[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.

Example
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()}');
}
Output
orientable true, H [Z, 0, 0, Z]

Constructors

Triangulated3Manifold(List<List<int>> tetrahedra)
Example
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);
}
Output
sphere

Properties

final List<List<int>> tetrahedra
complexfield
final SimplicialComplex complex
bool get isManifold
int get eulerCharacteristic
bool get isOrientable

Whether the tetrahedra can be oriented coherently (each shared triangle induced with opposite orientations).

Methods

homologymethod
List<HomologyGroup> homology()
Example
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());
}
Output
[Z, 0, 0, Z]
abstract final class Triangulations

Standard triangulations for tests and demos.

Example
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);
}
Output
T²#T²

Static

tetrahedronstaticmethod
static TriangulatedSurface tetrahedron()

The boundary of the tetrahedron: S^{2} with 4 vertices.

Example
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);
}
Output
sphere
octahedronstaticmethod
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}).

Example
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());
}
Output
[Z, 0, Z]
torus7staticmethod
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}.

Example
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()}');
}
Output
7 vertices, [Z, Z^2, Z]
projectivePlane6staticmethod
static TriangulatedSurface projectivePlane6()

The 6-vertex real projective plane (the hemi-icosahedron; its 1-skeleton is K_{6}).

Example
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());
}
Output
[Z, Z/2, 0]
mobiusBandstaticmethod
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\}.

Example
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);
}
Output
[[0, 2], [1, 3], [2, 4], [0, 3], [1, 4]]
gridstaticmethod
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.

Example
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);
}
Output
Klein bottle
torusGridstaticmethod
static TriangulatedSurface torusGrid(int m, int n)
Example
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());
}
Output
[Z, Z^2, Z]
kleinBottleGridstaticmethod
static TriangulatedSurface kleinBottleGrid(int m, int n)
Example
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());
}
Output
[Z, Z ⊕ Z/2, 0]
orientablestaticmethod
static TriangulatedSurface orientable(int g)

The closed orientable surface of genus g (connected sums of 7-vertex tori; the sphere for 0).

Example
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());
}
Output
[Z, Z^6, Z]
nonOrientablestaticmethod
static TriangulatedSurface nonOrientable(int k)

The connected sum of k ≥ 1 projective planes.

Example
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);
}
Output
Klein bottle
sphere3staticmethod
static Triangulated3Manifold sphere3()

S^{3} as the boundary of the 4-simplex (5 vertices, 5 tetrahedra).

Example
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());
}
Output
{sphere}
torusstaticmethod
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.

Example
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()}');
}
Output
T³: betti [1, 3, 3, 1]