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

Differential geometry

Index-notation tensors, metrics and curvature by exact second-order differentiation, differential forms with wedge, d and Hodge star, discrete exterior calculus on meshes, and Lorentz and spinor transformations.

import 'package:riptide_geometry/riptide_geometry.ray';
13 classes174 functions and methods145 of 253 documented150 runnable examples

Overview

PieceWhat it doesChecked against
Jetvalue + gradient + Hessian through arithmetic (order-2 forward AD)hand derivatives
Tensorindex notation (up/down slots), raise/lower/contract, einsum via riptide_numerics_cpu\delta, round trips
MetricField, GeometryAta metric written once → Christoffel, Riemann, Ricci, R, Einstein, Weyl, Kretschmann, Killing residualsS^{2}, H^{2}, S^{3}, Schwarzschild (\frac{48M^{2}}{r^{6}}), FLRW Friedmann
Form, FormFieldexterior algebra, wedge, interior product, Hodge star (any signature), exact d, integration, Gauss linking integral⋆⋆ = \pm1, Stokes, 4\pi, Hopf link
TriangleMeshDEC: d0, d1, ⋆0, ⋆1 (cotan), ⋆2, Laplacians, Hodge decomposition, harmonic 1-forms (tree–cotree), angle defectsGauss–Bonnet, \ell = 1 eigenvalue, b_{1}(T^{2}) = 2
Lorentz, SL2Cboosts, rotations, SL(2,ℂ) double cover, Thomas–Wigner rotation, celestial Möbius maps\eta preserved, \tan(\frac{\theta}{2}) = \tanh(\frac{a}{2})\tanh(\frac{b}{2})
RationalTriangleMesh, QuadranceSpreadMeshrational-first: exact quadrances, spreads, quadreas; exact cotan weights and Laplacian for planar rational meshes; rotationMatrixOf for exact rotationsfloat ⋆1 to 1e-13; octahedron spreads \frac{3}{4}
UnitQuaternionSU(2) → SO(3), loop lifting (\pi_{1}(SO(3)) = \mathbb{Z}/2), explicit belt-trick homotopy, the 720^{\circ} explainer scenelifts of 360^{\circ}/720^{\circ} loops

The symbolic path (metrics as CAS expressions) plugs in when the computer-algebra package lands: a CAS expression compiles to a MetricFunction over Jets, so every quantity above stays exact-derivative numeric and the CAS adds closed forms.

Functions and constants

Functions

popCountfunction
int popCount(int x)

The number of set bits.

Example
import 'package:riptide_geometry/riptide_geometry.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  print('${popCount(0x2D)} bits set in 0b101101');
}
Output
4 bits set in 0b101101
wedgeSignfunction
int wedgeSign(int a, int b)

The sign of e^{A} \wedge e^{B} for disjoint blades A, B (bit i = dx^{i}): (-1)^(pairs i in A, j in B with i > j).

Example
import 'package:riptide_geometry/riptide_geometry.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  // dx1 ∧ dx0 = −dx0 ∧ dx1: blade 2 then blade 1.
  print('${wedgeSign(2, 1)}, ${wedgeSign(1, 2)}');
}
Output
-1, 1
(Float64List, Float64List) gaussLegendre(int n)

Gauss–Legendre nodes and weights on [-1, 1] (Newton on Legendre polynomials; exact for degree 2·n - 1).

Example
import 'package:riptide_geometry/riptide_geometry.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  final (x, w) = gaussLegendre(3);
  print('nodes ${fl(x)}, weights ${fl(w)}');
  print('∫₋₁¹ x⁴ = 2/5: ${f6([for (var i = 0; i < 3; i++) w[i] * math.pow(x[i], 4)].reduce((a, b) => a + b))}');
}
Output
nodes [-0.774597, 0.000000, 0.774597], weights [0.555556, 0.888889, 0.555556]
∫₋₁¹ x⁴ = 2/5: 0.400000
double gaussLinkingIntegral(List<double> Function(double t) a, List<double> Function(double t) b, {int samples = 400})

The Gauss linking integral of two closed curves a, b: [0, 2\pi] \to \mathbb{R}^{3}, Lk = (\frac{1}{4\pi}) \oint\oint (a - b) \cdot (a' \times b') / |a - b|^{3} — an integer, the linking number (sign by orientation).

Example
import 'package:riptide_geometry/riptide_geometry.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  // A Hopf link: two unit circles threaded once through each other.
  final lk = gaussLinkingIntegral((t) => [math.cos(t), math.sin(t), 0], (t) => [1 + math.cos(t), 0, math.sin(t)]);
  print('linking number ≈ ${lk.toStringAsFixed(4)}');
}
Output
linking number ≈ -0.9999
Float64List rotationMatrix(List<double> axis, double angle)

The 3 \times 3 rotation matrix by angle about the unit axis (Rodrigues): the radians form of rotationMatrixTurn.

Example
import 'package:riptide_geometry/riptide_geometry.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  print(fl(rotationMatrix([0, 0, 1], math.pi / 2)));
}
Output
[0.000000, -1.000000, 0.000000, 1.000000, 0.000000, 0.000000, 0.000000, 0.000000, 1.000000]
Float64List rotationMatrixCayley(List<double> axis, double t)

The 3 \times 3 rotation matrix with Cayley parameter t = \tan(\frac{\theta}{2}) about axis: rational in t (Euler–Rodrigues), so a rational t on a rational unit axis gives an exactly rational matrix.

Example
import 'package:riptide_geometry/riptide_geometry.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  // t = tan(θ/2) = 1 is a quarter turn; the entries are rational in t.
  print(fl(rotationMatrixCayley([0, 0, 1], 1)));
}
Output
[0.000000, -1.000000, 0.000000, 1.000000, 0.000000, 0.000000, 0.000000, 0.000000, 1.000000]
Float64List rotationMatrixTurn(List<double> axis, Turn turn)

The 3 \times 3 rotation matrix about axis by the turn (c, s) = (\cos \theta, \sin \theta) (Rodrigues, no trigonometry).

List<double> nullVectorOfSpinor((Complex, Complex) xi)

The null 4-vector k^{\mu} = \tfrac{1}{2} \operatorname{tr}(\sigma_{\mu} \xi \xi^{\dagger}) of a spinor \xi (Penrose: every null direction is a spinor up to phase).

Example
import 'package:riptide_geometry/riptide_geometry.ray';
import 'package:riptide_numerics_cpu/riptide_numerics_cpu.ray' show Complex;
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  print(fl(nullVectorOfSpinor((Complex.one, Complex.zero))));
}
Output
[0.500000, 0.000000, 0.000000, 0.500000]
double wignerCayleyPerpendicular(double a, double b)

The Cayley parameter \tan(\frac{\theta}{2}) of the Thomas–Wigner rotation produced by composing a boost of rapidity a with a perpendicular boost of rapidity b: \tanh(\frac{a}{2}) \cdot \tanh(\frac{b}{2}) (closed form, for checking Lorentz.decompose).

Example
import 'package:riptide_geometry/riptide_geometry.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  print(f6(wignerCayleyPerpendicular(1, 1)));
}
Output
0.213552
double wignerAnglePerpendicular(double a, double b)

The Thomas–Wigner rotation angle of wignerCayleyPerpendicular, in radians.

Example
import 'package:riptide_geometry/riptide_geometry.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  // Thomas–Wigner rotation from two perpendicular boosts of rapidity 1.
  print('${f6(wignerAnglePerpendicular(1, 1))} rad');
}
Output
0.420784 rad
invertfunction
Float64List invert(Float64List a, int n)

The inverse of a small dense matrix (Gauss–Jordan with partial pivoting).

Example
import 'package:riptide_geometry/riptide_geometry.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  print(fl(invert(Float64List.fromList([4, 7, 2, 6]), 2)));
}
Output
[0.600000, -0.700000, -0.200000, 0.400000]
double determinantOf(Float64List a, int n)

The determinant of a small dense matrix (LU with partial pivoting).

Example
import 'package:riptide_geometry/riptide_geometry.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  print(f6(determinantOf(Float64List.fromList([2, 0, 1, 1, 3, 2, 1, 1, 1]), 3)));
}
Output
0.000000
Float64List rotationMatrixOf(RtQuaternion<Rational> q)

The rotation matrix (row-major 3 \times 3, float) of an exact rational quaternion: every entry is the correctly rounded value of the exact rational entry (error \le \tfrac{1}{2} ulp each; the exact matrix is orthogonal).

Example
import 'package:riptide_geometry/riptide_geometry.ray';
import 'package:riptide_rational_geometry/riptide_rational_geometry.ray' show qv, Q, RtQuaternion;
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  print(fl(rotationMatrixOf(RtQuaternion.ints(Q, 1, 1, 0, 0))));
}
Output
[1.000000, 0.000000, 0.000000, 0.000000, 0.000000, -1.000000, 0.000000, 1.000000, 0.000000]
UnitQuaternion unitQuaternionOf(RtQuaternion<Rational> q)

The float unit quaternion \frac{q}{|q|} of an exact rational quaternion, for the SU(2) loop and spinor machinery (the only irrational step, \sqrt{|q|}^{2}, happens here at the boundary; relative error \le 2^{-52} per component).

Example
import 'package:riptide_geometry/riptide_geometry.ray';
import 'package:riptide_rational_geometry/riptide_rational_geometry.ray' show qv, Q, RtQuaternion;
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  final u = unitQuaternionOf(RtQuaternion.ints(Q, 1, 1, 0, 0));
  print('${f6(u.w)}, ${f6(u.x)}');
}
Output
0.707107, 0.707107
double rotationDistance(Float64List a, Float64List b)

The distance between rotation matrices (max entry).

Example
import 'package:riptide_geometry/riptide_geometry.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  print(f6(rotationDistance(rotationMatrix([0, 0, 1], 0.1), rotationMatrix([0, 0, 1], 0.2))));
}
Output
0.098836
quaternionOffunction
UnitQuaternion quaternionOf(Float64List r, {UnitQuaternion near = UnitQuaternion.identity})

A rotation matrix back to one of its two quaternions (Shepperd's method), the one nearest near.

Example
import 'package:riptide_geometry/riptide_geometry.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  final q = quaternionOf(rotationMatrix([1, 0, 0], 1.0));
  print('${f6(q.w)}, ${f6(q.x)} (cos ½, sin ½)');
}
Output
0.877583, 0.479426 (cos ½, sin ½)
liftLoopfunction
List<UnitQuaternion> liftLoop(List<Float64List> loop)

Lifts a loop of rotations (sampled finely, first == last) to SU(2) by continuity, starting at +1. The lift ends at +1 when the loop is contractible in SO(3) and at -1 when it is not: \pi_{1}(SO(3)) = \mathbb{Z}/2.

Example
import 'package:riptide_geometry/riptide_geometry.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  final lift = liftLoop(rotationLoop([0, 0, 1], 1, samples: 36));
  print('360° loop lifts from ${f6(lift.first.w)} to ${f6(lift.last.w)}: it does not close in SU(2)');
}
Output
360° loop lifts from 1.000000 to -1.000000: it does not close in SU(2)
bool isContractible(List<Float64List> loop)

Whether a sampled loop in SO(3) is contractible (its continuous lift closes up).

Example
import 'package:riptide_geometry/riptide_geometry.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  print('360°: ${isContractible(rotationLoop([0, 0, 1], 1))}, 720°: ${isContractible(rotationLoop([0, 0, 1], 2))}');
}
Output
360°: false, 720°: true
rotationLoopfunction
List<Float64List> rotationLoop(List<double> axis, double turns, {int samples = 720})

The loop "rotate by turns × 360° about axis", sampled at samples + 1 points.

Example
import 'package:riptide_geometry/riptide_geometry.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  print('${rotationLoop([0, 1, 0], 1, samples: 8).length} samples');
}
Output
9 samples
beltTrickfunction
UnitQuaternion beltTrick(double s, double t)

Dirac's belt trick as an explicit null-homotopy of the 720^{\circ} rotation about z. In S^{3} the 720^{\circ} loop is the great circle q(t) = \cos(\frac{t}{2}) + \sin(\frac{t}{2})k (t \in [0, 4\pi]); tilting it towards j, q_{s}(t) = \cos(\frac{s\pi}{2}) \cdot q(t) + \sin(\frac{s\pi}{2}) \cdot j, shrinks it through small circles to the constant j (s = 1). Every q_{s} is a closed loop, so its image in SO(3) is a family of closed rotation loops from "720° about z" to "no motion" (a constant 180^{\circ} flip about y, then untwisted by any path back to the identity). No such family exists for 360^{\circ}: its lift runs from +1 to -1, and the endpoints of a lift cannot move continuously.

Example
import 'package:riptide_geometry/riptide_geometry.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  // s = 0 is the 720° loop, s = 1 the constant loop.
  print('${f6(beltTrick(0, 0.25).w)}, ${f6(beltTrick(1, 0.25).w)}');
}
Output
0.992198, 0.000000
(double, double) spinHalfOverlap(double angle)

A spin-\tfrac{1}{2} state picks up -1 under a 360^{\circ} rotation and returns after 720^{\circ}: the amplitude \langle\psi|R(\theta)|\psi\rangle for spin up along the rotation axis is e^{-i\theta/2}. Returns (Re, Im).

Example
import 'package:riptide_geometry/riptide_geometry.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  for (final a in [0.0, 2 * math.pi, 4 * math.pi]) print('${f6(spinHalfOverlap(a).$1)}');
}
Output
1.000000
-1.000000
1.000000
Map<String, Object?> spinorRotationScene({int samples = 96})

An explainer scene: the spinor's overlap \cos(\frac{\theta}{2}) and the rotation's trace-based overlap \frac{1 + 2\cos \theta}{3} as the angle goes to 720^{\circ}.

Example
import 'package:riptide_geometry/riptide_geometry.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  final s = spinorRotationScene(samples: 8);
  print(s.keys.toList());
}
Output
[id, title, view, objects, steps]

Constants and variables

minkowskivariable
final Float64List minkowski

The Minkowski metric \eta = \operatorname{diag}(-1, 1, 1, 1) (signature {-}{+}{+}{+}, c = 1), the convention of riptide_relativity.

paulivariable
final List<SL2C> pauli

The Pauli matrices \sigma0 = I, \sigma1, \sigma2, \sigma3, as 2 \times 2 complex matrices.

Typedefs

typedef FormFieldFunction = Map<int, Jet> Function(List<Jet> x)

A differential form field: blade → coefficient function, written with Jets so d is exact.

typedef MetricFunction = void Function(List<Jet> x, List<Jet> g)

Writes the metric components g_{ab}(x) (n \cdot n, row-major, symmetric) in terms of Jets of the coordinates.

typedef VectorFieldFunction = void Function(List<Jet> x, List<Jet> xi)

Writes a vector field's components \xi^{a}(x).

Classes

final class TriangleMesh

A consistently oriented triangle mesh (a discrete surface): vertex positions (x, y, z per vertex) and faces (three vertex indices each, counter-clockwise seen from outside).

Example
import 'package:riptide_geometry/riptide_geometry.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  final m = TriangleMesh.icosphere(1);
  print('${m.positions.length ~/ 3} vertices, ${m.faces.length ~/ 3} faces');
  print('Gauss–Bonnet: Σ defects / 2π = ${f6(m.angleDefects().reduce((a, b) => a + b) / (2 * math.pi))}');
}
Output
42 vertices, 80 faces
Gauss–Bonnet: Σ defects / 2π = 2.000000

Constructors

TriangleMeshconstructor
TriangleMesh(this.positions, this.faces)
Example
import 'package:riptide_geometry/riptide_geometry.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  final m = TriangleMesh(Float64List.fromList([0, 0, 0, 1, 0, 0, 0, 1, 0]), Int32List.fromList([0, 1, 2]));
  print('area ${f6(m.faceAreas[0])}, edges ${m.edges.length ~/ 2}');
}
Output
area 0.500000, edges 3
factory TriangleMesh.icosphere(int subdivisions)

A UV sphere-free unit icosphere (subdivisions loop subdivisions of the icosahedron, projected to the sphere).

Example
import 'package:riptide_geometry/riptide_geometry.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  for (final k in [0, 1, 2]) print('subdivision $k: ${TriangleMesh.icosphere(k).faces.length ~/ 3} faces');
}
Output
subdivision 0: 20 faces
subdivision 1: 80 faces
subdivision 2: 320 faces
factory TriangleMesh.torus(double major, double minor, int nu, int nv)

A torus of radii major > minor: nu vertices around the main circle and nv (even) rings, alternate rings offset by half a step so the triangles are acute (an intrinsic Delaunay mesh: every cotan weight ⋆1 is positive; the plain quad split puts cocircular trapezoids, ⋆1 = 0, on every diagonal). Genus 1.

Example
import 'package:riptide_geometry/riptide_geometry.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  final t = TriangleMesh.torus(2, 1, 12, 8);
  print('harmonic 1-forms: ${t.harmonicBasis().length} (2g for genus 1)');
}
Output
harmonic 1-forms: 2 (2g for genus 1)
factory TriangleMesh.grid(int nx, int ny)

A flat nx × ny grid on [0, 1]^{2} (z = 0), with a boundary.

Example
import 'package:riptide_geometry/riptide_geometry.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  final g = TriangleMesh.grid(3, 3);
  print('${g.positions.length ~/ 3} vertices, ${g.faces.length ~/ 3} faces');
}
Output
16 vertices, 18 faces

Properties

final Float64List positions
facesfield
final Int32List faces
edgesfield
late final Int32List edges

Edges as (tail, head) pairs, oriented from the lower vertex index to the higher.

int get vertexCount
faceCountgetter
int get faceCount
edgeCountgetter
int get edgeCount
int get eulerCharacteristic

V - E + F.

d0field
late final CsrMatrix d0

The coboundary d0: 0-forms (vertex values) → 1-forms (edge values), (d_{0} f)(a \to b) = f(b) - f(a). E \times V.

d1field
late final CsrMatrix d1

The coboundary d1: 1-forms → 2-forms (face circulation). F \times E. d_{1} \cdot d_{0} = 0.

late final Float64List faceAreas

Face areas.

star0field
late final Float64List star0

⋆0: the barycentric dual cell area of each vertex (a third of each incident face).

star1field
late final Float64List star1

⋆1: the cotangent weights \tfrac{1}{2}(\cot \alpha + \cot \beta), the ratio of dual to primal edge length (circumcentric duality).

star2field
late final Float64List star2

⋆2 = 1 / face area.

late final CsrMatrix laplacian0

The cotan Laplacian (stiffness) L_{0} = d_{0}^{T} \star 1 d0, symmetric positive semidefinite, kernel = constants per component. The pointwise Laplace–Beltrami is ⋆0^{-1} L0 (sign: positive, -\Delta).

late final CsrMatrix curlCurl1

d_{1}^{T} \star 2 d1 (E \times E): the curl-curl part of the 1-form Hodge Laplacian (weak form).

Methods

edgemethod
(int, int) edge(int a, int b)

The index of edge \{a, b\} and +1 when a \to b matches its orientation (-1 otherwise).

Example
import 'package:riptide_geometry/riptide_geometry.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  final m = TriangleMesh(Float64List.fromList([0, 0, 0, 1, 0, 0, 0, 1, 0]), Int32List.fromList([0, 1, 2]));
  print('${m.edge(0, 1)}, ${m.edge(1, 0)}');
}
Output
(0, 1), (0, -1)
vertexmethod
List<double> vertex(int v)
Example
import 'package:riptide_geometry/riptide_geometry.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  print(fl(TriangleMesh.icosphere(0).vertex(0)));
}
Output
[-0.525731, 0.850651, 0.000000]
Float64List hodgeLaplacian1(Float64List omega)

The Hodge Laplacian on primal 1-forms, \Delta1 \omega = d_{0} \star 0^{-1} d_{0}^{T} \star 1 \omega + \star 1^{-1} d_{1}^{T} \star 2 d1 \omega (\delta d + d\delta).

Example
import 'package:riptide_geometry/riptide_geometry.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  final m = TriangleMesh.icosphere(1);
  final f = Float64List.fromList([for (var i = 0; i < m.positions.length ~/ 3; i++) m.positions[3 * i + 2]]);
  final w = Float64List(m.edges.length ~/ 2);
  m.d0.apply(f, w);
  print('|Δ₁ dz| max ${f6(m.hodgeLaplacian1(w).map((v) => v.abs()).reduce(math.max))}');
}
Output
|Δ₁ dz| max 1.196340
Float64List codifferential1(Float64List omega)

The codifferential of a 1-form, \delta\omega = \star 0^{-1} d_{0}^{T} \star 1 \omega (a 0-form; zero for co-closed forms).

Example
import 'package:riptide_geometry/riptide_geometry.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  final m = TriangleMesh.icosphere(1);
  final f = Float64List.fromList([for (var i = 0; i < m.positions.length ~/ 3; i++) m.positions[3 * i]]);
  final w = Float64List(m.edges.length ~/ 2);
  m.d0.apply(f, w);
  print('δ(dx) has ${m.codifferential1(w).length} vertex values');
}
Output
δ(dx) has 42 vertex values
Float64List angleDefects()

The discrete Gaussian curvature: the angle defect 2\pi − Σ angles at each vertex (interior vertices). Gauss–Bonnet: Σ defects = 2\pi \chi on a closed surface.

Example
import 'package:riptide_geometry/riptide_geometry.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  final d = TriangleMesh.icosphere(0).angleDefects();
  print('icosahedron: each defect ${f6(d[0])} = π/3, total ${f6(d.reduce((a, b) => a + b))} = 4π');
}
Output
icosahedron: each defect 1.047198 = π/3, total 12.566371 = 4π
HodgeDecomposition hodgeDecomposition(Float64List omega, {double rtol = 1e-12})

Splits a 1-form into exact, co-exact and harmonic parts, \omega = d\alpha + \delta\beta + h (discrete Hodge decomposition; the two Poisson problems are solved with conjugate gradients from riptide_numerics_sparse).

Example
import 'package:riptide_geometry/riptide_geometry.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  final t = TriangleMesh.torus(2, 1, 12, 8);
  final h = t.harmonicBasis().first;
  final d = t.hodgeDecomposition(h);
  print('harmonic part keeps ${f6(d.harmonic.map((v) => v.abs()).reduce(math.max))}, exact part ${f6(d.exact.map((v) => v.abs()).reduce(math.max))}');
}
Output
harmonic part keeps 0.083333, exact part 0.000000
List<Float64List> harmonicBasis()

A basis of harmonic 1-forms (dimension 2g on a closed orientable surface of genus g; the first de Rham cohomology), from a tree–cotree decomposition (Eppstein 2003): each edge in neither the primal spanning tree nor the dual cotree gives a closed, non-exact 1-form, whose harmonic part is kept.

Example
import 'package:riptide_geometry/riptide_geometry.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  print('sphere: ${TriangleMesh.icosphere(1).harmonicBasis().length}, torus: ${TriangleMesh.torus(2, 1, 12, 8).harmonicBasis().length}');
}
Output
sphere: 0, torus: 2
final class HodgeDecomposition

\omega = exact + coexact + harmonic, with exact = d0·potential.

Example
import 'package:riptide_geometry/riptide_geometry.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  final t = TriangleMesh.torus(2, 1, 10, 6);
  final d = t.hodgeDecomposition(t.harmonicBasis()[0]);
  print('parts of lengths ${d.exact.length}, ${d.coexact.length}, ${d.harmonic.length}');
}
Output
parts of lengths 180, 180, 180

Constructors

HodgeDecomposition(this.exact, this.coexact, this.harmonic, this.potential)
Example
import 'package:riptide_geometry/riptide_geometry.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  final z = Float64List(3);
  final d = HodgeDecomposition(z, z, z, Float64List(2));
  print(d.potential.length);
}
Output
2

Properties

exactfield
final Float64List exact
coexactfield
final Float64List coexact
final Float64List harmonic
final Float64List potential
class

Form

final class Form

An element of the exterior algebra \Lambda(\mathbb{R}^{n})* at a point: a sum of k-forms of any degrees, one coefficient per blade (bitmask: bit i is dx^{i}, so 0b101 is dx^{0} \wedge dx^{2}). n \le 16.

Example
import 'package:riptide_geometry/riptide_geometry.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  // 2-forms in R³: dx0∧dx1 + dx1∧dx2, wedged with dx2.
  final a = Form.basis(3, [0, 1]) + Form.basis(3, [1, 2]);
  print('a ∧ dx2 volume coefficient: ${a.wedge(Form.basis(3, [2]))[7]}');
}
Output
a ∧ dx2 volume coefficient: 1.0

Constructors

Formconstructor
Form(this.dim)
Example
import 'package:riptide_geometry/riptide_geometry.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  final w = Form(3)..[3] = 2;
  print('${w.coefficients}');
}
Output
[0.0, 0.0, 0.0, 2.0, 0.0, 0.0, 0.0, 0.0]
Form.basisfactory
factory Form.basis(int dim, List<int> indices, [double c = 1])

The basis k-form dx^{i_{1}} \wedge \cdots \wedge dx^{ik} (indices in any order; the sign of the sort is applied).

Example
import 'package:riptide_geometry/riptide_geometry.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  print('dx1∧dx0 = ${Form.basis(2, [1, 0])[3]} · dx0∧dx1');
}
Output
dx1∧dx0 = -1.0 · dx0∧dx1
factory Form.oneForm(List<double> a)

A 1-form \sum a_{i} dx^{i}.

Example
import 'package:riptide_geometry/riptide_geometry.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  final a = Form.oneForm([1, 2, 3]);
  print('a(1, 1, 1) = ${a.evaluate([[1, 1, 1]])}');
}
Output
a(1, 1, 1) = 6.0
factory Form.volume(int dim)

The volume form dx^{0} \wedge \cdots \wedge dx^{n - 1}.

Example
import 'package:riptide_geometry/riptide_geometry.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  print('vol(e0, e1, e2) = ${Form.volume(3).evaluate([[1, 0, 0], [0, 1, 0], [0, 0, 1]])}');
}
Output
vol(e0, e1, e2) = 1.0

Properties

dimfield
final int dim
final Float64List coefficients
maxAbsgetter
double get maxAbs

Methods

scalemethod
Form scale(double s)
Example
import 'package:riptide_geometry/riptide_geometry.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  print(Form.volume(2).scale(3)[3]);
}
Output
3.0
wedgemethod
Form wedge(Form o)

\alpha \wedge \beta.

Example
import 'package:riptide_geometry/riptide_geometry.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  final dx = Form.basis(2, [0]), dy = Form.basis(2, [1]);
  print('dx∧dy = ${dx.wedge(dy)[3]}, dy∧dx = ${dy.wedge(dx)[3]}, dx∧dx = ${dx.wedge(dx)[3]}');
}
Output
dx∧dy = 1.0, dy∧dx = -1.0, dx∧dx = 0.0
grademethod
Form grade(int k)

The degree-k part.

Example
import 'package:riptide_geometry/riptide_geometry.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  final m = Form.oneForm([1, 2]) + Form.volume(2);
  print('grade 1: ${m.grade(1).coefficients}, grade 2: ${m.grade(2).coefficients}');
}
Output
grade 1: [0.0, 1.0, 2.0, 0.0], grade 2: [0.0, 0.0, 0.0, 1.0]
interiormethod
Form interior(List<double> v)

The interior product \iota_{v} \alpha (contraction of the first slot with the vector v).

Example
import 'package:riptide_geometry/riptide_geometry.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  print(Form.volume(3).interior([0, 0, 1]).coefficients);
}
Output
[0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0]
evaluatemethod
double evaluate(List<List<double>> vectors)

Evaluates a k-form on k vectors: \alpha(v1, …, vk) = \sum_{I} \alpha_{I} \det(v_{j}^{i}) over blades I.

Example
import 'package:riptide_geometry/riptide_geometry.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  print('(dx0∧dx1)((1,2,0), (3,4,0)) = ${Form.basis(3, [0, 1]).evaluate([[1, 2, 0], [3, 4, 0]])}');
}
Output
(dx0∧dx1)((1,2,0), (3,4,0)) = -2.0
hodgemethod
Form hodge(Float64List g)

The Hodge star with respect to the metric g (n \cdot n, any signature), orientation dx^{0} \wedge \cdots \wedge dx^{n - 1}: ⋆(dx^{I}) = \sqrt{|\det g|} \sum_{L} \det(g^{-1}[I, \complement L]) \operatorname{sign}(\complement L, L) dx^{L}. Satisfies \alpha \wedge \star \beta = \langle\alpha, \beta\rangle vol and ⋆⋆ = (-1)^{k(n - k)} \operatorname{sign}(\det g) on k-forms.

Example
import 'package:riptide_geometry/riptide_geometry.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  final g = Float64List.fromList([1, 0, 0, 0, 1, 0, 0, 0, 1]);
  print('⋆dx0 = ${Form.basis(3, [0]).hodge(g).coefficients}');
}
Output
⋆dx0 = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0]
double innerProduct(Form o, Float64List g)

The pointwise inner product \langle\alpha, \beta\rangle induced by g (from \alpha \wedge \star \beta = \langle\alpha, \beta\rangle vol).

Example
import 'package:riptide_geometry/riptide_geometry.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  final g = Float64List.fromList([1, 0, 0, 1]);
  print(Form.oneForm([3, 4]).innerProduct(Form.oneForm([3, 4]), g));
}
Output
25.0
toStringmethod
String toString()

Operators

operator []operator
double operator [](int blade)
Example
import 'package:riptide_geometry/riptide_geometry.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  print(Form.oneForm([5, 6])[2]);
}
Output
6.0
operator []=operator
void operator []=(int blade, double v)
Example
import 'package:riptide_geometry/riptide_geometry.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  final w = Form(2);
  w[3] = 7;
  print(w.coefficients);
}
Output
[0.0, 0.0, 0.0, 7.0]
operator +operator
Form operator +(Form o)
Example
import 'package:riptide_geometry/riptide_geometry.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  print((Form.oneForm([1, 0]) + Form.oneForm([0, 1])).coefficients);
}
Output
[0.0, 1.0, 1.0, 0.0]
operator -operator
Form operator -(Form o)
Example
import 'package:riptide_geometry/riptide_geometry.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  print((Form.oneForm([1, 2]) - Form.oneForm([1, 2])).coefficients);
}
Output
[0.0, 0.0, 0.0, 0.0]
final class FormField

A differential form on an open set of \mathbb{R}^{n}.

Example
import 'package:riptide_geometry/riptide_geometry.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  // ω = x dy − y dx; dω = 2 dx∧dy.
  final w = FormField.oneForm(2, (x) => [-x[1], x[0]]);
  print('dω at (1, 2): ${w.d.at([1, 2])[3]}');
}
Output
dω at (1, 2): 2.0

Constructors

FormFieldconstructor
FormField(this.dim, this.coefficients)
Example
import 'package:riptide_geometry/riptide_geometry.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  final f = FormField(2, (x) => {3: x[0] * x[1]});
  print(f.at([2, 3])[3]);
}
Output
6.0
factory FormField.oneForm(int dim, List<Jet> Function(List<Jet> x) a)

A 1-form from component functions a_{i}(x).

Example
import 'package:riptide_geometry/riptide_geometry.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  final w = FormField.oneForm(3, (x) => [x[1], x[2], x[0]]);
  print('dω = ${w.d.at([0.5, 1, 2]).coefficients}');
}
Output
dω = [0.0, 0.0, 0.0, -1.0, 0.0, 1.0, -1.0, 0.0]
factory FormField.function(int dim, Jet Function(List<Jet> x) f)

Df for a function f (a 0-form).

Example
import 'package:riptide_geometry/riptide_geometry.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  final df = FormField.function(2, (x) => x[0].square() * x[1]).d;
  print('d(x²y) at (1, 2) = ${df.at([1, 2]).coefficients}');
}
Output
d(x²y) at (1, 2) = [0.0, 4.0, 1.0, 0.0]

Properties

dimfield
final int dim
final FormFieldFunction coefficients
dgetter
FormField get d

d\omega = \sum_{I} \sum_{j} \partial_{j} \omega_{I} dx^{j} \wedge dx^{I}, exact (the result's coefficients carry first derivatives, so d(d\omega) = 0 to rounding).

Methods

atmethod
Form at(List<double> x)

The form's value at x.

Example
import 'package:riptide_geometry/riptide_geometry.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  print(FormField.oneForm(2, (x) => [x[0], x[1]]).at([3, 4]).coefficients);
}
Output
[0.0, 3.0, 4.0, 0.0]
double pullbackDensity(List<Jet> Function(List<Jet> u) phi, List<double> u)

The pullback \varphi \cdot \omega evaluated on the coordinate vectors of a parametrisation phi: \mathbb{R}^{k} \to \mathbb{R}^{n} at u (\omega(\varphi(u))(\frac{\partial\varphi}{\partial u^{1}}, \ldots, \frac{\partial\varphi}{\partial u^{k}})).

Example
import 'package:riptide_geometry/riptide_geometry.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  final w = FormField.oneForm(2, (x) => [-x[1], x[0]]);
  print(f6(w.pullbackDensity((u) => [u[0].cos(), u[0].sin()], [0.3])));
}
Output
1.000000
integratemethod
double integrate(List<Jet> Function(List<Jet> u) phi, List<double> lo, List<double> hi, {int order = 24})

\int \omega over the k-cube [lo, hi] parametrised by phi (tensor Gauss–Legendre with order points per axis).

Example
import 'package:riptide_geometry/riptide_geometry.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  // ∮ x dy − y dx around the unit circle = 2π (twice the area).
  final w = FormField.oneForm(2, (x) => [-x[1], x[0]]);
  print(f6(w.integrate((u) => [u[0].cos(), u[0].sin()], [0], [2 * math.pi])));
}
Output
6.283185
class

Jet

final class Jet

A second-order jet in n variables: the value, gradient and Hessian of a function at a point, carried exactly through arithmetic (forward-mode automatic differentiation truncated at order 2).

Curvature needs the metric and its first and second derivatives; writing a metric once in terms of Jets gives all three with no finite differences and no symbolic algebra. The Hessian is stored full (n \cdot n) and kept symmetric.

final x = Jet.variables([1.0, 2.0]);   // x0 = 1, x1 = 2, seeded
final f = x[0] * x[1].sin();          // f.value, f.grad[k], f.hess[k * n + l]
Example
import 'package:riptide_geometry/riptide_geometry.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  // f = x² sin y with exact first and second derivatives at (1, 0).
  final v = Jet.variables([1, 0]);
  final f = v[0].square() * v[1].sin();
  print('f ${f.value}, ∂y ${f.d(1)}, ∂x∂y ${f.dd(0, 1)}');
}
Output
f 0.0, ∂y 1.0, ∂x∂y 2.0

Constructors

factory Jet.constant(double c, int n)

A constant in n variables.

Example
import 'package:riptide_geometry/riptide_geometry.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  print(Jet.constant(3, 2).grad);
}
Output
[0.0, 0.0]
factory Jet.variable(double value, int index, int n)

The coordinate function x_index at value.

Example
import 'package:riptide_geometry/riptide_geometry.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  final x = Jet.variable(2, 0, 1);
  final c = x * x * x;
  print('x³ at 2: ${c.value}, ${c.d(0)}, ${c.dd(0, 0)}');
}
Output
x³ at 2: 8.0, 12.0, 12.0

Static

variablesstaticmethod
static List<Jet> variables(List<double> point)

One variable per entry of point, seeded.

Example
import 'package:riptide_geometry/riptide_geometry.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  final v = Jet.variables([1, 2, 3]);
  print((v[0] * v[1] * v[2]).grad);
}
Output
[6.0, 3.0, 2.0]

Properties

valuefield
final double value
gradfield
final Float64List grad
hessfield
final Float64List hess
ngetter
int get n

Methods

constantmethod
Jet constant(double c)
Example
import 'package:riptide_geometry/riptide_geometry.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  final x = Jet.variable(1, 0, 1);
  print((x + x.constant(5)).value);
}
Output
6.0
scalemethod
Jet scale(double s)
Example
import 'package:riptide_geometry/riptide_geometry.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  print(Jet.variable(1, 0, 1).scale(4).grad);
}
Output
[4.0]
applymethod
Jet apply(double f0, double f1, double f2)

Applies a scalar function with derivatives f, f', f'' at value (the chain rule to order 2).

Example
import 'package:riptide_geometry/riptide_geometry.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  final x = Jet.variable(0.5, 0, 1);
  final f = x.apply(math.exp(0.5), math.exp(0.5), math.exp(0.5));
  print('${f6(f.d(0))}');
}
Output
1.648721
Jet reciprocal()
Example
import 'package:riptide_geometry/riptide_geometry.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  final x = Jet.variable(2, 0, 1);
  print('1/x: ${x.reciprocal().d(0)}, ${x.reciprocal().dd(0, 0)}');
}
Output
1/x: -0.25, 0.25
sqrtmethod
Jet sqrt()
Example
import 'package:riptide_geometry/riptide_geometry.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  print(Jet.variable(4, 0, 1).sqrt().d(0));
}
Output
0.25
powmethod
Jet pow(double p)
Example
import 'package:riptide_geometry/riptide_geometry.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  print(Jet.variable(2, 0, 1).pow(3).d(0));
}
Output
12.0
squaremethod
Jet square()
Example
import 'package:riptide_geometry/riptide_geometry.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  print(Jet.variable(3, 0, 1).square().dd(0, 0));
}
Output
2.0
sinmethod
Jet sin()
Example
import 'package:riptide_geometry/riptide_geometry.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  print(f6(Jet.variable(0, 0, 1).sin().d(0)));
}
Output
1.000000
cosmethod
Jet cos()
Example
import 'package:riptide_geometry/riptide_geometry.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  print(f6(Jet.variable(0, 0, 1).cos().dd(0, 0)));
}
Output
-1.000000
expmethod
Jet exp()
Example
import 'package:riptide_geometry/riptide_geometry.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  print(f6(Jet.variable(1, 0, 1).exp().d(0)));
}
Output
2.718282
logmethod
Jet log()
Example
import 'package:riptide_geometry/riptide_geometry.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  print(Jet.variable(2, 0, 1).log().d(0));
}
Output
0.5
sinhmethod
Jet sinh()
Example
import 'package:riptide_geometry/riptide_geometry.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  print(f6(Jet.variable(0, 0, 1).sinh().d(0)));
}
Output
1.000000
coshmethod
Jet cosh()
Example
import 'package:riptide_geometry/riptide_geometry.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  print(f6(Jet.variable(0, 0, 1).cosh().dd(0, 0)));
}
Output
1.000000
atanmethod
Jet atan()
Example
import 'package:riptide_geometry/riptide_geometry.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  print(Jet.variable(1, 0, 1).atan().d(0));
}
Output
0.5
dmethod
double d(int i)

∂f/∂x_i.

Example
import 'package:riptide_geometry/riptide_geometry.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  final v = Jet.variables([1, 2]);
  print((v[0] * v[1].square()).d(1));
}
Output
4.0
ddmethod
double dd(int i, int j)

∂²f/∂x_i∂x_j.

Example
import 'package:riptide_geometry/riptide_geometry.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  final v = Jet.variables([1, 2]);
  print((v[0] * v[1].square()).dd(0, 1));
}
Output
4.0
toStringmethod
String toString()

Operators

operator +operator
Jet operator +(Object o)
Example
import 'package:riptide_geometry/riptide_geometry.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  final v = Jet.variables([1, 2]);
  print((v[0] + v[1]).grad);
}
Output
[1.0, 1.0]
operator -operator
Jet operator -(Object o)
Example
import 'package:riptide_geometry/riptide_geometry.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  final v = Jet.variables([1, 2]);
  print((v[0] - v[1]).grad);
}
Output
[1.0, -1.0]
operator -operator
Jet operator -()
Example
import 'package:riptide_geometry/riptide_geometry.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  print((-Jet.variable(1, 0, 1)).grad);
}
Output
[-1.0]
operator *operator
Jet operator *(Object o)
Example
import 'package:riptide_geometry/riptide_geometry.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  final v = Jet.variables([2, 3]);
  print((v[0] * v[1]).hess);
}
Output
[0.0, 1.0, 1.0, 0.0]
operator /operator
Jet operator /(Object o)
Example
import 'package:riptide_geometry/riptide_geometry.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  final v = Jet.variables([2, 4]);
  print((v[0] / v[1]).grad);
}
Output
[0.25, -0.125]
class

Lorentz

final class Lorentz

A Lorentz transformation \Lambda^{\mu}_{\nu} (4 \times 4, row-major, coordinates (t, x, y, z)).

Example
import 'package:riptide_geometry/riptide_geometry.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  // Two collinear boosts add rapidities; perpendicular ones leave a rotation.
  final b = Lorentz.boost([0.6, 0, 0]) * Lorentz.boost([0, 0.6, 0]);
  final (boost, rot) = b.decompose();
  print('Wigner rotation angle ${f6(rot.rotationAngle)} rad');
}
Output
Wigner rotation angle 0.221314 rad

Constructors

Lorentzconstructor
Lorentz(this.m)
Example
import 'package:riptide_geometry/riptide_geometry.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  print(Lorentz(minkowski).at(0, 0));
}
Output
-1.0
factory Lorentz.identity()
Example
import 'package:riptide_geometry/riptide_geometry.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  print(fl(Lorentz.identity().apply([1, 2, 3, 4])));
}
Output
[1.000000, 2.000000, 3.000000, 4.000000]
factory Lorentz.boost(List<double> v)

A pure boost with velocity v (|v| < 1).

Example
import 'package:riptide_geometry/riptide_geometry.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  // v = 3/5: γ = 5/4.
  final b = Lorentz.boost([0.6, 0, 0]);
  print('γ = ${f6(b.at(0, 0))}, (1,0,0,0) ↦ ${fl(b.apply([1, 0, 0, 0]))}');
}
Output
γ = 1.250000, (1,0,0,0) ↦ [1.250000, -0.750000, 0.000000, 0.000000]
factory Lorentz.boostRapidity(List<double> n, double eta)

A boost of rapidity eta along the unit vector n.

Example
import 'package:riptide_geometry/riptide_geometry.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  print(f6(Lorentz.boostRapidity([1, 0, 0], math.log(2)).at(0, 0)));
}
Output
1.250000
factory Lorentz.rotation(List<double> axis, double angle)

A rotation by angle about the unit axis (right-handed, active): the radians form of Lorentz.rotationTurn.

Example
import 'package:riptide_geometry/riptide_geometry.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  print(fl(Lorentz.rotation([0, 0, 1], math.pi / 2).apply([0, 1, 0, 0])));
}
Output
[0.000000, 0.000000, 1.000000, 0.000000]
factory Lorentz.rotationCayley(List<double> axis, double t)

The rotation with Cayley parameter t = \tan(\frac{\theta}{2}) about axis (rational in t; no trigonometry).

Example
import 'package:riptide_geometry/riptide_geometry.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  print(fl(Lorentz.rotationCayley([0, 0, 1], 1).apply([0, 1, 0, 0])));
}
Output
[0.000000, 0.000000, 1.000000, 0.000000]
factory Lorentz.rotationTurn(List<double> axis, Turn turn)

The rotation about axis by the planar turn turn (its unit vector (\cos \theta, \sin \theta)).

Properties

mfield
final Float64List m
inversegetter
Lorentz get inverse

\Lambda^{-1} = \eta \Lambda^{T} \eta.

double get metricDefect

Max |\Lambda^{T} \eta \Lambda - \eta|: zero for a Lorentz transformation.

double get rotationSpread

The spread of a pure rotation, \frac{Q(R_{32} - R_{23}, R_{13} - R_{31}, R_{21} - R_{12})}{4}, from its antisymmetric part. Accurate near 0, where 1 - (\frac{\operatorname{tr} - 1}{2})^{2} and acos cancel.

Turn get rotationTurn

The rotation's angle as a turn (\cos \theta, \sin \theta), \theta in [0, \pi]: \cos \theta = \frac{\operatorname{tr} - 1}{2} and \sin \theta = \tfrac{1}{2}|R - R^{T}|.

double get rotationAngle

The rotation angle of a pure rotation in [0, \pi]: the radians form of rotationTurn.

Methods

atmethod
double at(int mu, int nu)
Example
import 'package:riptide_geometry/riptide_geometry.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  print(f6(Lorentz.boost([0.8, 0, 0]).at(0, 1)));
}
Output
-1.333333
applymethod
List<double> apply(List<double> x)
Example
import 'package:riptide_geometry/riptide_geometry.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  print(fl(Lorentz.boost([0.5, 0, 0]).apply([1, 1, 0, 0])) + ' (a light ray stays a light ray)');
}
Output
[0.577350, 0.577350, 0.000000, 0.000000] (a light ray stays a light ray)
decomposemethod
(Lorentz boost, Lorentz rotation) decompose()

Polar decomposition \Lambda = B \cdot R into a boost B and a rotation R (both proper orthochronous).

Example
import 'package:riptide_geometry/riptide_geometry.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  final (b, r) = (Lorentz.boost([0.3, 0, 0]) * Lorentz.rotation([0, 0, 1], 0.4)).decompose();
  print('rotation angle ${f6(r.rotationAngle)}');
}
Output
rotation angle 0.400000
double maxDifference(Lorentz o)
Example
import 'package:riptide_geometry/riptide_geometry.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  print(f6(Lorentz.boost([0.6, 0, 0]).maxDifference(Lorentz.boostRapidity([1, 0, 0], math.log(2)))));
}
Output
0.000000

Operators

operator []operator
double operator [](int i)
Example
import 'package:riptide_geometry/riptide_geometry.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  print(Lorentz.identity()[5]);
}
Output
1.0
operator *operator
Lorentz operator *(Lorentz o)
Example
import 'package:riptide_geometry/riptide_geometry.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  final l = Lorentz.boost([0.5, 0, 0]) * Lorentz.boost([0.5, 0, 0]);
  // Two boosts of speed 1/2 compose to one of speed 0.8 = (1/2 + 1/2)/(1 + 1/4), not 1.
  print('combined speed ${f6((l.at(0, 1) / l.at(0, 0)).abs())}');
}
Output
combined speed 0.800000
class

SL2C

final class SL2C

A 2 \times 2 complex matrix \begin{bmatrix}a & b \\ c & d\end{bmatrix}; with \det = 1 an element of SL(2, ℂ), the double cover of the proper orthochronous Lorentz group, acting on left-handed Weyl spinors. A 4-vector x is the Hermitian matrix X = x^{0} I + x^{i} \sigma_{i} (\det X = -\eta(x, x)) and transforms as X \to A X A^{\dagger}.

Example
import 'package:riptide_geometry/riptide_geometry.ray';
import 'package:riptide_numerics_cpu/riptide_numerics_cpu.ray' show Complex;
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  final a = SL2C.rotation([0, 0, 1], 2 * math.pi);
  print('2π spinor rotation ≈ −I: ${f6(a.maxDifference(SL2C.identity * SL2C(const Complex(-1, 0), Complex.zero, Complex.zero, const Complex(-1, 0))))}');
}
Output
2π spinor rotation ≈ −I: 0.000000

Constructors

SL2Cconstructor
const SL2C(this.a, this.b, this.c, this.d)
Example
import 'package:riptide_geometry/riptide_geometry.ray';
import 'package:riptide_numerics_cpu/riptide_numerics_cpu.ray' show Complex;
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  print(SL2C(Complex.one, Complex.one, Complex.zero, Complex.one).toLorentz().at(0, 0));
}
Output
1.5
factory SL2C.rotation(List<double> axis, double angle)

The spinor rotation \exp(-i \frac{\theta}{2} n \cdot \sigma): a 2\pi rotation gives -I. The radians form of SL2C.rotationHalfTurn with the half-angle turn (\cos \frac{\theta}{2}, \sin \frac{\theta}{2}), which is what keeps the sign: \theta and \theta + 2\pi are different spinors.

Example
import 'package:riptide_geometry/riptide_geometry.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  print(f6(SL2C.rotation([0, 0, 1], math.pi).toLorentz().at(1, 1)));
}
Output
-1.000000
factory SL2C.rotationCayley(List<double> axis, double t)

The spinor rotation with Cayley parameter t = \tan(\frac{\theta}{2}) about axis: \frac{I - i t n \cdot \sigma}{\sqrt{1 + t^{2}}}, the unit quaternion of the Gibbs vector t \cdot n (one square root, no trigonometry). Covers \theta in (-\pi, \pi) (\cos \frac{\theta}{2} > 0).

Example
import 'package:riptide_geometry/riptide_geometry.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  print(f6(SL2C.rotationCayley([0, 0, 1], 1).toLorentz().at(1, 2)));
}
Output
-1.000000
factory SL2C.rotationHalfTurn(List<double> axis, Turn half)

\cos(\frac{\theta}{2}) I - i \sin(\frac{\theta}{2}) n \cdot \sigma from the half-angle turn half = (\cos \frac{\theta}{2}, \sin \frac{\theta}{2}).

SL2C.boostfactory
factory SL2C.boost(List<double> n, double eta)

The spinor boost \exp(-\frac{\eta}{2} n \cdot \sigma) of rapidity eta along unit n, matching Lorentz.boostRapidity (Hermitian).

Example
import 'package:riptide_geometry/riptide_geometry.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  print(f6(SL2C.boost([1, 0, 0], 1).toLorentz().maxDifference(Lorentz.boostRapidity([1, 0, 0], 1))));
}
Output
0.000000

Static

identityconstant
static const SL2C identity = SL2C(Complex.one, Complex.zero, Complex.zero, Complex.one)

Properties

afield
final Complex a
bfield
final Complex b
cfield
final Complex c
dfield
final Complex d
adjointgetter
SL2C get adjoint
Complex get determinant
tracegetter
Complex get trace
inversegetter
SL2C get inverse

Methods

applymethod
(Complex, Complex) apply((Complex, Complex) xi)

Acts on a 2-spinor (\xi^{1}, \xi^{2}).

Example
import 'package:riptide_geometry/riptide_geometry.ray';
import 'package:riptide_numerics_cpu/riptide_numerics_cpu.ray' show Complex;
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  print(SL2C.identity.apply((Complex.one, Complex.zero)));
}
Output
((1.0+0.0j), (0.0+0.0j))
toLorentzmethod
Lorentz toLorentz()

The Lorentz transformation it covers: \Lambda^{\mu}_{\nu} = \tfrac{1}{2} \operatorname{tr}(\sigma_{\mu} A \sigma_{\nu} A^{\dagger}). A and -A give the same \Lambda.

Example
import 'package:riptide_geometry/riptide_geometry.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  print(fl(SL2C.boost([0, 0, 1], 0.5).toLorentz().apply([1, 0, 0, 0])));
}
Output
[1.127626, 0.000000, 0.000000, -0.521095]
mobiusmethod
Complex mobius(Complex zeta)

The Möbius map \zeta \to \frac{a\zeta + b}{c\zeta + d} it induces on the celestial sphere (directions of light rays, \zeta by stereographic projection): how a boosted observer sees the sky (aberration).

Example
import 'package:riptide_geometry/riptide_geometry.ray';
import 'package:riptide_numerics_cpu/riptide_numerics_cpu.ray' show Complex;
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  print(SL2C(Complex.zero, Complex.one, Complex.one, Complex.zero).mobius(const Complex(2, 0)));
}
Output
(0.5+0.0j)
double maxDifference(SL2C o)
Example
import 'package:riptide_geometry/riptide_geometry.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  print(f6(SL2C.rotation([0, 0, 1], 4 * math.pi).maxDifference(SL2C.identity)));
}
Output
0.000000
toStringmethod
String toString()

Operators

operator *operator
SL2C operator *(SL2C o)
Example
import 'package:riptide_geometry/riptide_geometry.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  print(f6((SL2C.rotation([0, 0, 1], 0.3) * SL2C.rotation([0, 0, 1], 0.4)).maxDifference(SL2C.rotation([0, 0, 1], 0.7))));
}
Output
0.000000
operator -operator
SL2C operator -()
class MetricField

A (pseudo-)Riemannian metric on a coordinate chart, written once as a MetricFunction; everything else — Christoffel symbols, Riemann, Ricci, scalar curvature, the Einstein tensor, Killing residuals — follows by exact second-order automatic differentiation (Jet).

Subclasses may override christoffel with closed forms where speed matters (geodesic integration, ray tracing); the tests check every override against the automatic one.

Example
import 'package:riptide_geometry/riptide_geometry.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  // The round sphere of radius 2: scalar curvature 2/r² = 1/2 everywhere.
  final s = MetricField.diagonal(2, (x) {
    final c = (x[0].square() + x[1].square() + 1).square().reciprocal() * 16;
    return [c, c];
  });
  print('R = ${f6(s.at([0.3, -0.7]).scalarCurvature)}');
}
Output
R = 0.500000

Constructors

MetricFieldconstructor
MetricField(this.dim, this.components, {this.name = 'metric', this.coordinates})
Example
import 'package:riptide_geometry/riptide_geometry.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  final m = MetricField(2, (x, g) {
    g[0] = x[0].constant(1);
    g[1] = x[0].constant(0);
    g[2] = x[0].constant(0);
    g[3] = x[0].square();
  });
  print('polar plane: R = ${f6(m.at([2, 0.5]).scalarCurvature)} (flat)');
}
Output
polar plane: R = 0.000000 (flat)
factory MetricField.diagonal(int dim, List<Jet> Function(List<Jet> x) diagonal, {String name = 'metric', List<String>? coordinates})

A diagonal metric g = \operatorname{diag}(f(x)); unset components are zero in every MetricFunction too.

Example
import 'package:riptide_geometry/riptide_geometry.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  final h = MetricField.diagonal(2, (x) => [x[1].square().reciprocal(), x[1].square().reciprocal()]);
  print('upper half-plane: R = ${f6(h.at([0, 1]).scalarCurvature)}');
}
Output
upper half-plane: R = -2.000000
factory MetricField.constant(int dim, List<double> components, {String name = 'metric'})

A constant metric (e.g. Minkowski \operatorname{diag}(-1, 1, 1, 1)).

Example
import 'package:riptide_geometry/riptide_geometry.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  final m = MetricField.constant(4, [-1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]);
  print('Minkowski: R = ${f6(m.at([0, 0, 0, 0]).scalarCurvature)}');
}
Output
Minkowski: R = 0.000000

Properties

dimfield
final int dim
final MetricFunction components
namefield
final String name
final List<String>? coordinates

Coordinate names, e.g. ['t', 'r', '\theta', '\varphi'].

Methods

metricAtmethod
Float64List metricAt(List<double> x)

g_{ab} at x (n \cdot n row-major).

Example
import 'package:riptide_geometry/riptide_geometry.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  final h = MetricField.diagonal(2, (x) => [x[1].square().reciprocal(), x[1].square().reciprocal()]);
  print(fl(h.metricAt([0, 2])));
}
Output
[0.250000, 0.000000, 0.000000, 0.250000]
atmethod
GeometryAt at(List<double> x)

The full local geometry at x: metric, inverse, derivatives and all curvature.

Example
import 'package:riptide_geometry/riptide_geometry.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  final h = MetricField.diagonal(2, (x) => [x[1].square().reciprocal(), x[1].square().reciprocal()]);
  final g = h.at([0, 1]);
  print('Ricci ${fl(g.ricci.data)}');
}
Output
Ricci [-1.000000, 0.000000, 0.000000, -1.000000]
void christoffel(List<double> x, Float64List out)

\Gamma^{a}_{bc} at x into out (n \cdot n \cdot n, index a \cdot n^{2} + b \cdot n + c).

Example
import 'package:riptide_geometry/riptide_geometry.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  final h = MetricField.diagonal(2, (x) => [x[1].square().reciprocal(), x[1].square().reciprocal()]);
  final out = Float64List(8);
  h.christoffel([0, 1], out);
  print(fl(out));
}
Output
[0.000000, -1.000000, -1.000000, 0.000000, 1.000000, 0.000000, 0.000000, -1.000000]
void geodesicAcceleration(List<double> x, List<double> v, Float64List acc, [Float64List? scratch])

The geodesic equation's acceleration -\Gamma^{a}_{bc} v^{b} v^{c} into acc.

Example
import 'package:riptide_geometry/riptide_geometry.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  final h = MetricField.diagonal(2, (x) => [x[1].square().reciprocal(), x[1].square().reciprocal()]);
  final acc = Float64List(2);
  h.geodesicAcceleration([0, 1], [1, 0], acc);
  print('a = ${fl(acc)} (the path curves down: it is the top of a semicircle centred on the x-axis)');
}
Output
a = [-0.000000, -1.000000] (the path curves down: it is the top of a semicircle centred on the x-axis)
innermethod
double inner(List<double> x, List<double> u, List<double> v)

g_{ab} u^{a} v^{b} at x.

Example
import 'package:riptide_geometry/riptide_geometry.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  final h = MetricField.diagonal(2, (x) => [x[1].square().reciprocal(), x[1].square().reciprocal()]);
  print(f6(h.inner([0, 2], [1, 0], [1, 0])));
}
Output
0.250000
Tensor lieDerivativeOfMetric(VectorFieldFunction xi, List<double> x)

The Lie derivative of the metric along xi at x, (L_{\xi} g)_{ab} = \xi^{c} \partial_{c} g_{ab} + g_{cb} \partial_{a} \xi^{c} + g_{ac} \partial_{b} \xi^{c}. Zero exactly when \xi is a Killing vector (an isometry: a conserved quantity along geodesics).

Example
import 'package:riptide_geometry/riptide_geometry.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  final m = MetricField.constant(2, [1, 0, 0, 1]);
  final t = m.lieDerivativeOfMetric((x, xi) { xi[0] = -x[1]; xi[1] = x[0]; }, [1, 2]);
  print('rotation field: max |L_ξ g| = ${f6(t.maxAbs)} (a Killing vector)');
}
Output
rotation field: max |L_ξ g| = 0.000000 (a Killing vector)
double killingResidual(VectorFieldFunction xi, Iterable<List<double>> points)

The largest component of L_{\xi} g over points: ~0 for a Killing vector.

Example
import 'package:riptide_geometry/riptide_geometry.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  final m = MetricField.constant(2, [1, 0, 0, 1]);
  print('${f6(m.killingResidual((x, xi) { xi[0] = x[0]; xi[1] = x[1]; }, [[1, 2], [0.5, -1]]))} (dilation is not Killing)');
}
Output
2.000000 (dilation is not Killing)
final class GeometryAt

A metric and its curvature at one point. Every quantity is computed on first use and cached.

Example
import 'package:riptide_geometry/riptide_geometry.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  final s = MetricField.diagonal(2, (x) {
    final c = (x[0].square() + x[1].square() + 1).square().reciprocal() * 4;
    return [c, c];
  });
  final g = s.at([0, 0]);
  print('R ${f6(g.scalarCurvature)}, Kretschmann ${f6(g.kretschmann)}');
}
Output
R 2.000000, Kretschmann 4.000000

Properties

fieldfield
final MetricField field
xfield
final Float64List x
nfield
final int n
metricfield
late final Float64List metric

g_{ab}, g^{ab}.

inversefield
late final Float64List inverse

g_{ab}, g^{ab}.

dgfield
late final Float64List dg

\partial_{c} g_{ab} at index (c \cdot n + a) \cdot n + b; \partial_{c} \partial_{d} g_{ab} at ((c \cdot n + d) \cdot n + a) \cdot n + b.

d2gfield
late final Float64List d2g

\partial_{c} g_{ab} at index (c \cdot n + a) \cdot n + b; \partial_{c} \partial_{d} g_{ab} at ((c \cdot n + d) \cdot n + a) \cdot n + b.

double get determinant
late final Float64List christoffelFirst

\Gamma_{\mathrm{abc}} = \tfrac{1}{2}(\partial_{b} g_{ac} + \partial_{c} g_{ab} - \partial_{a} g_{bc}) (first kind).

late final Float64List christoffel

\Gamma^{a}_{bc} (second kind).

late final Float64List christoffelDerivative

\partial_{d} \Gamma^{a}_{bc} at index ((d \cdot n + a) \cdot n + b) \cdot n + c.

riemannfield
late final Tensor riemann

R^{a}_{\mathrm{bcd}} = \partial_{c} \Gamma^{a}_{db} - \partial_{d} \Gamma^{a}_{cb} + \Gamma^{a}_{ce} \Gamma^{e}_{db} - \Gamma^{a}_{de} \Gamma^{e}_{cb} (MTW's convention: the 2-sphere of radius r has R = \frac{2}{r^{2}}).

late final Tensor riemannDown

R_{\mathrm{abcd}} (all indices down).

riccifield
late final Tensor ricci

R_{bd} = R^{a}_{\mathrm{bad}}.

late final double scalarCurvature

R = g^{bd} R_{bd}.

late final Tensor einstein

G_{ab} = R_{ab} - \tfrac{1}{2} R g_{ab}.

late final double kretschmann

R_{\mathrm{abcd}} R^{\mathrm{abcd}} (Schwarzschild: 48 M^{2} / r^{6}).

weylfield
late final Tensor weyl

The Weyl tensor C_{\mathrm{abcd}} (n \ge 3): the trace-free part of the Riemann tensor (zero for conformally flat metrics).

Tensor get metricTensor
Tensor get inverseTensor
Tensor get christoffelArray

\Gamma^{a}_{bc} as a tensor-shaped array (it is not a tensor, but the layout is the same).

final class RationalTriangleMesh

A triangle mesh with exact rational vertex positions (3-D) and consistently oriented faces.

Example
import 'package:riptide_geometry/riptide_geometry.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  final m = RationalTriangleMesh.grid(2, 2);
  print('corner spreads of face 0: ${[for (var k = 0; k < 3; k++) m.cornerSpread(0, k)]}');
}
Output
corner spreads of face 0: [1/2, 1, 1/2]

Constructors

RationalTriangleMesh(List<Vec<Rational>> positions, this.faces)
Example
import 'package:riptide_geometry/riptide_geometry.ray';
import 'package:riptide_rational_geometry/riptide_rational_geometry.ray' show qv, Q, RtQuaternion;
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  final m = RationalTriangleMesh([qv([0, 0, 0]), qv([3, 0, 0]), qv([0, 4, 0])], Int32List.fromList([0, 1, 2]));
  print('quadrea ${m.faceQuadrea(0)} (= 16 · 6²)');
}
Output
quadrea 576 (= 16 · 6²)
factory RationalTriangleMesh.grid(int nx, int ny)

A rational nx × ny grid on [0, 1]^{2} (z = 0): the exact twin of TriangleMesh.grid.

Example
import 'package:riptide_geometry/riptide_geometry.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  print('${RationalTriangleMesh.grid(3, 2).positions.length} exact vertices');
}
Output
12 exact vertices

Properties

final List<Vec<Rational>> positions
facesfield
final Int32List faces
faceCountgetter
int get faceCount
floatfield
late final TriangleMesh float

The float view (positions correctly rounded; each coordinate within \tfrac{1}{2} ulp), with its DEC operators. Its edge numbering is the one edgeQuadrances and exactCotanWeights use.

late final List<Rational> edgeQuadrances

The exact quadrance of every edge, in float's edge order.

Methods

TriangleMesh toTriangleMesh()
Example
import 'package:riptide_geometry/riptide_geometry.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  print(RationalTriangleMesh.grid(2, 2).toTriangleMesh().faces.length ~/ 3);
}
Output
8
Rational cornerSpread(int f, int k)

The spread at corner k of face f (classically \sin^{2} of the corner angle).

Example
import 'package:riptide_geometry/riptide_geometry.ray';
import 'package:riptide_rational_geometry/riptide_rational_geometry.ray' show qv, Q, RtQuaternion;
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  final m = RationalTriangleMesh([qv([0, 0, 0]), qv([2, 0, 0]), qv([1, 1, 0])], Int32List.fromList([0, 1, 2]));
  print([for (var k = 0; k < 3; k++) m.cornerSpread(0, k)]);
}
Output
[1/2, 1/2, 1]
Rational faceQuadrea(int f)

The quadrea \mathcal{A} = 16 \cdot \mathrm{area}^{2} of face f (= 4|u \times v|^{2}; Archimedes' function of its side quadrances).

Example
import 'package:riptide_geometry/riptide_geometry.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  print(RationalTriangleMesh.grid(1, 1).faceQuadrea(0));
}
Output
4
Rational? cornerCotangent(int f, int k)

Cot of corner k of face f: \frac{2(u \cdot v)}{\sqrt{\mathcal{A}}}; null when \mathcal{A} is not a rational square.

Example
import 'package:riptide_geometry/riptide_geometry.ray';
import 'package:riptide_rational_geometry/riptide_rational_geometry.ray' show qv, Q, RtQuaternion;
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  final m = RationalTriangleMesh([qv([0, 0, 0]), qv([2, 0, 0]), qv([1, 1, 0])], Int32List.fromList([0, 1, 2]));
  print([for (var k = 0; k < 3; k++) m.cornerCotangent(0, k)]);
}
Output
[1, 1, 0]
List<Rational>? exactCotanWeights()

The DEC ⋆1 weights \tfrac{1}{2}(\cot \alpha + \cot \beta), exactly, in float's edge order; null when some face's quadrea is not a rational square (then the weights are irrational and only the float TriangleMesh.star1 exists).

Example
import 'package:riptide_geometry/riptide_geometry.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  print(RationalTriangleMesh.grid(1, 1).exactCotanWeights());
}
Output
[1/2, 1/2, 0, 1/2, 1/2]
Mat<Rational>? exactLaplacian0()

The cotan Laplacian L_{0} = d_{0}^{T} \star 1 d0 as an exact rational matrix (planar meshes); null when exactCotanWeights is.

Example
import 'package:riptide_geometry/riptide_geometry.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  print(RationalTriangleMesh.grid(1, 1).exactLaplacian0());
}
Output
1 -1/2 -1/2 0
-1/2 1 0 -1/2
-1/2 0 1 -1/2
0 -1/2 -1/2 1
extension QuadranceSpreadMesh on TriangleMesh

Quadrances and spreads on a float mesh: the rational-first API in floats, with lengths and angles derived.

Properties

Float64List get edgeQuadrances

Squared edge lengths.

Float64List get edgeLengths

Edge lengths, derived: \sqrt{Q}.

Methods

double cornerSpread(int f, int k)

The spread at corner k of face f: |u \times v|^{2} / (|u|^{2}|v|^{2}).

final class UnitQuaternion

A unit quaternion w + \xi + yj + zk: a point of SU(2) ≅ S³, the universal (double) cover of SO(3).

Example
import 'package:riptide_geometry/riptide_geometry.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  final q = UnitQuaternion.rotation([0, 0, 1], math.pi / 2);
  print('${f6(q.w)}, ${f6(q.z)}; rotation matrix ${fl(q.toRotationMatrix())}');
}
Output
0.707107, 0.707107; rotation matrix [0.000000, -1.000000, 0.000000, 1.000000, 0.000000, 0.000000, 0.000000, 0.000000, 1.000000]

Constructors

UnitQuaternionconstructor
const UnitQuaternion(this.w, this.x, this.y, this.z)
Example
import 'package:riptide_geometry/riptide_geometry.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  print(const UnitQuaternion(0, 1, 0, 0).toRotationMatrix());
}
Output
[1.0, 0.0, 0.0, 0.0, -1.0, 0.0, 0.0, 0.0, -1.0]
factory UnitQuaternion.rotation(List<double> axis, double angle)

The rotation by angle about unit axis: \cos(\frac{\theta}{2}) + \sin(\frac{\theta}{2})(n \cdot (i, j, k)). Matches the spinor rotation \exp(-\frac{i\theta}{2} n \cdot \sigma) under i \leftrightarrow -i\sigma_{1}, j \leftrightarrow -i\sigma_{2}, k \leftrightarrow -i\sigma_{3}.

Example
import 'package:riptide_geometry/riptide_geometry.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  print(f6(UnitQuaternion.rotation([1, 0, 0], math.pi).x));
}
Output
1.000000

Static

identityconstant
static const identity = UnitQuaternion(1, 0, 0, 0)

Properties

wfield
final double w
xfield
final double x
yfield
final double y
zfield
final double z

Methods

dotmethod
double dot(UnitQuaternion o)
Example
import 'package:riptide_geometry/riptide_geometry.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  print(f6(UnitQuaternion.identity.dot(UnitQuaternion.rotation([0, 0, 1], 1))));
}
Output
0.877583
distancemethod
double distance(UnitQuaternion o)
Example
import 'package:riptide_geometry/riptide_geometry.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  print(f6(UnitQuaternion.identity.distance(UnitQuaternion.rotation([0, 0, 1], 2 * math.pi))));
}
Output
2.000000
Float64List toRotationMatrix()

The covering map SU(2) → SO(3): q and -q give the same rotation matrix (row-major 3 \times 3).

Example
import 'package:riptide_geometry/riptide_geometry.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  print(fl(UnitQuaternion.rotation([0, 0, 1], 2 * math.pi).toRotationMatrix()) + ' (q and −q give the same matrix)');
}
Output
[1.000000, 0.000000, 0.000000, -0.000000, 1.000000, 0.000000, 0.000000, 0.000000, 1.000000] (q and −q give the same matrix)
toStringmethod
String toString()

Operators

operator *operator
UnitQuaternion operator *(UnitQuaternion o)
Example
import 'package:riptide_geometry/riptide_geometry.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  final q = UnitQuaternion.rotation([0, 0, 1], 0.5) * UnitQuaternion.rotation([0, 0, 1], 0.5);
  print(f6(q.distance(UnitQuaternion.rotation([0, 0, 1], 1))));
}
Output
0.000000
operator -operator
UnitQuaternion operator -()
Example
import 'package:riptide_geometry/riptide_geometry.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  print(f6((-UnitQuaternion.identity).w));
}
Output
-1.000000
class

Tensor

final class Tensor

A tensor at a point of an n-dimensional manifold in index notation: rank slots, each contravariant (up, u) or covariant (down, d), components in a coordinate basis stored row-major (slot 0 slowest).

Tensor.zeros(4, 'udd') is T^{a}_{bc}. Contractions go through riptide_numerics_cpu' einsum, so any index expression NumPy accepts works: Tensor.einsum('ab,bc->ac', [g, h], 'dd').

Example
import 'package:riptide_geometry/riptide_geometry.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  final g = Tensor.generate(2, 'dd', (i) => i[0] == i[1] ? 1.0 : 0.0);
  final v = Tensor(2, 'u', Float64List.fromList([3, 4]));
  print('v lowered: ${v.lower(0, g).data}, trace of v⊗v·g: ${f6(v.outer(v.lower(0, g)).contract(0, 1).data[0])}');
}
Output
v lowered: [3.0, 4.0], trace of v⊗v·g: 25.000000

Constructors

Tensorconstructor
Tensor(this.dim, this.variance, this.data)
Example
import 'package:riptide_geometry/riptide_geometry.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  print(Tensor(2, 'ud', Float64List.fromList([1, 2, 3, 4])).contract(0, 1).data);
}
Output
[5.0]
factory Tensor.zeros(int dim, String variance)
Example
import 'package:riptide_geometry/riptide_geometry.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  print(Tensor.zeros(3, 'dd').data.length);
}
Output
9
factory Tensor.generate(int dim, String variance, double Function(List<int> idx) f)

Builds components from f(indices).

Example
import 'package:riptide_geometry/riptide_geometry.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  print(Tensor.generate(2, 'uu', (i) => (i[0] + 2 * i[1]).toDouble()).data);
}
Output
[0.0, 2.0, 1.0, 3.0]
factory Tensor.einsum(String subscripts, List<Tensor> operands, String variance)

Contracts tensors by an einsum expression; the result's slots get variance.

Example
import 'package:riptide_geometry/riptide_geometry.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  final a = Tensor(2, 'ud', Float64List.fromList([1, 2, 3, 4]));
  print(Tensor.einsum('ij,jk->ik', [a, a], 'ud').data);
}
Output
[7.0, 10.0, 15.0, 22.0]

Properties

dimfield
final int dim
final String variance

One letter per slot: u (contravariant) or d (covariant).

datafield
final Float64List data
rankgetter
int get rank
maxAbsgetter
double get maxAbs

The largest absolute component.

scalargetter
double get scalar

The scalar of a \operatorname{rank} - 0 tensor.

Methods

toNDArraymethod
np.NDArray toNDArray()
Example
import 'package:riptide_geometry/riptide_geometry.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  print(Tensor(2, 'ud', Float64List.fromList([1, 2, 3, 4])).toNDArray().shape);
}
Output
[2, 2]
lowermethod
Tensor lower(int slot, Tensor g)

Lowers slot slot with the metric g (a dd tensor).

Example
import 'package:riptide_geometry/riptide_geometry.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  final eta = Tensor.generate(2, 'dd', (i) => i[0] != i[1] ? 0.0 : (i[0] == 0 ? -1.0 : 1.0));
  print(Tensor(2, 'u', Float64List.fromList([2, 3])).lower(0, eta).data);
}
Output
[-2.0, 3.0]
raisemethod
Tensor raise(int slot, Tensor gInv)

Raises slot slot with the inverse metric gInv (a uu tensor).

Example
import 'package:riptide_geometry/riptide_geometry.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  final inv = Tensor.generate(2, 'uu', (i) => i[0] == i[1] ? 0.5 : 0.0);
  print(Tensor(2, 'd', Float64List.fromList([2, 4])).raise(0, inv).data);
}
Output
[1.0, 2.0]
contractmethod
Tensor contract(int a, int b)

Contracts an up slot with a down slot (a trace).

Example
import 'package:riptide_geometry/riptide_geometry.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  print(Tensor(3, 'ud', Float64List.fromList([1, 0, 0, 0, 2, 0, 0, 0, 3])).contract(0, 1).data);
}
Output
[6.0]
outermethod
Tensor outer(Tensor o)

The tensor product.

Example
import 'package:riptide_geometry/riptide_geometry.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  print(Tensor(2, 'u', Float64List.fromList([1, 2])).outer(Tensor(2, 'd', Float64List.fromList([3, 4]))).data);
}
Output
[3.0, 4.0, 6.0, 8.0]
scalemethod
Tensor scale(double s)
Example
import 'package:riptide_geometry/riptide_geometry.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  print(Tensor(2, 'u', Float64List.fromList([1, 2])).scale(3).data);
}
Output
[3.0, 6.0]
toStringmethod
String toString()

Operators

operator []operator
double operator [](List<int> idx)
Example
import 'package:riptide_geometry/riptide_geometry.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  print(Tensor.generate(2, 'uu', (i) => (10 * i[0] + i[1]).toDouble())[[1, 0]]);
}
Output
10.0
operator []=operator
void operator []=(List<int> idx, double v)
Example
import 'package:riptide_geometry/riptide_geometry.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  final t = Tensor.zeros(2, 'dd');
  t[[0, 1]] = 5;
  print(t.data);
}
Output
[0.0, 5.0, 0.0, 0.0]
operator +operator
Tensor operator +(Tensor o)
Example
import 'package:riptide_geometry/riptide_geometry.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  print((Tensor(2, 'u', Float64List.fromList([1, 2])) + Tensor(2, 'u', Float64List.fromList([3, 4]))).data);
}
Output
[4.0, 6.0]
operator -operator
Tensor operator -(Tensor o)
Example
import 'package:riptide_geometry/riptide_geometry.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  print((Tensor(2, 'u', Float64List.fromList([1, 2])) - Tensor(2, 'u', Float64List.fromList([1, 2]))).data);
}
Output
[0.0, 0.0]