Overview
| Piece | What it does | Checked against |
|---|---|---|
Jet | value + gradient + Hessian through arithmetic (order-2 forward AD) | hand derivatives |
Tensor | index notation (up/down slots), raise/lower/contract, einsum via riptide_numerics_cpu | \delta, round trips |
MetricField, GeometryAt | a metric written once → Christoffel, Riemann, Ricci, R, Einstein, Weyl, Kretschmann, Killing residuals | S^{2}, H^{2}, S^{3}, Schwarzschild (\frac{48M^{2}}{r^{6}}), FLRW Friedmann |
Form, FormField | exterior algebra, wedge, interior product, Hodge star (any signature), exact d, integration, Gauss linking integral | ⋆⋆ = \pm1, Stokes, 4\pi, Hopf link |
TriangleMesh | DEC: d0, d1, ⋆0, ⋆1 (cotan), ⋆2, Laplacians, Hodge decomposition, harmonic 1-forms (tree–cotree), angle defects | Gauss–Bonnet, \ell = 1 eigenvalue, b_{1}(T^{2}) = 2 |
Lorentz, SL2C | boosts, 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, QuadranceSpreadMesh | rational-first: exact quadrances, spreads, quadreas; exact cotan weights and Laplacian for planar rational meshes; rotationMatrixOf for exact rotations | float ⋆1 to 1e-13; octahedron spreads \frac{3}{4} |
UnitQuaternion | SU(2) → SO(3), loop lifting (\pi_{1}(SO(3)) = \mathbb{Z}/2), explicit belt-trick homotopy, the 720^{\circ} explainer scene | lifts 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
int popCount(int x)The number of set bits.
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');
}4 bits set in 0b101101
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).
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)}');
}-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).
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))}');
}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).
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)}');
}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.
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)));
}[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.
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)));
}[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).
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))));
}[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).
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)));
}0.213552
double wignerAnglePerpendicular(double a, double b)The Thomas–Wigner rotation angle of wignerCayleyPerpendicular, in radians.
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');
}0.420784 rad
Float64List invert(Float64List a, int n)The inverse of a small dense matrix (Gauss–Jordan with partial pivoting).
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)));
}[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).
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)));
}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).
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))));
}[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).
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)}');
}0.707107, 0.707107
double rotationDistance(Float64List a, Float64List b)The distance between rotation matrices (max entry).
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))));
}0.098836
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.
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 ½)');
}0.877583, 0.479426 (cos ½, sin ½)
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.
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)');
}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).
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))}');
}360°: false, 720°: true
List<Float64List> rotationLoop(List<double> axis, double turns, {int samples = 720})The loop "rotate by turns × 360° about axis", sampled at samples + 1 points.
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');
}9 samples
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.
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)}');
}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).
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)}');
}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}.
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());
}[id, title, view, objects, steps]
Constants and variables
final Float64List minkowskiThe Minkowski metric \eta = \operatorname{diag}(-1, 1, 1, 1) (signature {-}{+}{+}{+}, c = 1), the convention of riptide_relativity.
final List<SL2C> pauliThe 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
TriangleMesh
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).
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))}');
}42 vertices, 80 faces Gauss–Bonnet: Σ defects / 2π = 2.000000
Constructors
TriangleMesh(this.positions, this.faces)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}');
}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).
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');
}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.
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)');
}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.
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');
}16 vertices, 18 faces
Properties
final Float64List positionsfinal Int32List faceslate final Int32List edgesEdges as (tail, head) pairs, oriented from the lower vertex index to the higher.
int get vertexCountint get faceCountint get edgeCountlate final CsrMatrix d0The coboundary d0: 0-forms (vertex values) → 1-forms (edge values), (d_{0} f)(a \to b) = f(b) - f(a). E \times V.
late final CsrMatrix d1The coboundary d1: 1-forms → 2-forms (face circulation). F \times E. d_{1} \cdot d_{0} = 0.
late final Float64List star0⋆0: the barycentric dual cell area of each vertex (a third of each incident face).
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).
late final CsrMatrix laplacian0The 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 curlCurl1d_{1}^{T} \star 2 d1 (E \times E): the curl-curl part of the 1-form Hodge Laplacian (weak form).
Methods
(int, int) edge(int a, int b)The index of edge \{a, b\} and +1 when a \to b matches its orientation (-1 otherwise).
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)}');
}(0, 1), (0, -1)
List<double> vertex(int v)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)));
}[-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).
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))}');
}|Δ₁ 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).
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');
}δ(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.
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π');
}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).
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))}');
}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.
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}');
}sphere: 0, torus: 2
HodgeDecomposition
final class HodgeDecomposition
\omega = exact + coexact + harmonic, with exact = d0·potential.
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}');
}parts of lengths 180, 180, 180
Constructors
HodgeDecomposition(this.exact, this.coexact, this.harmonic, this.potential)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);
}2
Properties
final Float64List exactfinal Float64List coexactfinal Float64List harmonicfinal Float64List potentialForm
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.
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]}');
}a ∧ dx2 volume coefficient: 1.0
Constructors
Form(this.dim)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}');
}[0.0, 0.0, 0.0, 2.0, 0.0, 0.0, 0.0, 0.0]
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).
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');
}dx1∧dx0 = -1.0 · dx0∧dx1
factory Form.oneForm(List<double> a)A 1-form \sum a_{i} dx^{i}.
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]])}');
}a(1, 1, 1) = 6.0
factory Form.volume(int dim)The volume form dx^{0} \wedge \cdots \wedge dx^{n - 1}.
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]])}');
}vol(e0, e1, e2) = 1.0
Properties
final int dimfinal Float64List coefficientsdouble get maxAbsMethods
Form scale(double s)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]);
}3.0
Form wedge(Form o)\alpha \wedge \beta.
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]}');
}dx∧dy = 1.0, dy∧dx = -1.0, dx∧dx = 0.0
Form grade(int k)The degree-k part.
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}');
}grade 1: [0.0, 1.0, 2.0, 0.0], grade 2: [0.0, 0.0, 0.0, 1.0]
Form interior(List<double> v)The interior product \iota_{v} \alpha (contraction of the first slot with the vector v).
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);
}[0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0]
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.
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]])}');
}(dx0∧dx1)((1,2,0), (3,4,0)) = -2.0
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.
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}');
}⋆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).
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));
}25.0
String toString()Operators
double operator [](int blade)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]);
}6.0
void operator []=(int blade, double v)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);
}[0.0, 0.0, 0.0, 7.0]
Form operator +(Form o)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);
}[0.0, 1.0, 1.0, 0.0]
Form operator -(Form o)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);
}[0.0, 0.0, 0.0, 0.0]
FormField
final class FormField
A differential form on an open set of \mathbb{R}^{n}.
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]}');
}dω at (1, 2): 2.0
Constructors
FormField(this.dim, this.coefficients)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]);
}6.0
factory FormField.oneForm(int dim, List<Jet> Function(List<Jet> x) a)A 1-form from component functions a_{i}(x).
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}');
}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).
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}');
}d(x²y) at (1, 2) = [0.0, 4.0, 1.0, 0.0]
Properties
final int dimfinal FormFieldFunction coefficientsFormField get dd\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
Form at(List<double> x)The form's value at x.
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);
}[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}})).
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])));
}1.000000
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).
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])));
}6.283185
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]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)}');
}f 0.0, ∂y 1.0, ∂x∂y 2.0
Constructors
factory Jet.constant(double c, int n)A constant in n variables.
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);
}[0.0, 0.0]
factory Jet.variable(double value, int index, int n)The coordinate function x_index at value.
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)}');
}x³ at 2: 8.0, 12.0, 12.0
Static
static List<Jet> variables(List<double> point)One variable per entry of point, seeded.
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);
}[6.0, 3.0, 2.0]
Properties
final double valuefinal Float64List gradfinal Float64List hessint get nMethods
Jet constant(double c)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);
}6.0
Jet scale(double s)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);
}[4.0]
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).
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))}');
}1.648721
Jet reciprocal()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)}');
}1/x: -0.25, 0.25
Jet sqrt()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));
}0.25
Jet pow(double p)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));
}12.0
Jet square()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));
}2.0
Jet sin()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)));
}1.000000
Jet cos()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)));
}-1.000000
Jet exp()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)));
}2.718282
Jet log()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));
}0.5
Jet sinh()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)));
}1.000000
Jet cosh()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)));
}1.000000
Jet atan()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));
}0.5
double d(int i)∂f/∂x_i.
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));
}4.0
double dd(int i, int j)∂²f/∂x_i∂x_j.
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));
}4.0
String toString()Operators
Jet operator +(Object o)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);
}[1.0, 1.0]
Jet operator -(Object o)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);
}[1.0, -1.0]
Jet operator -()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);
}[-1.0]
Jet operator *(Object o)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);
}[0.0, 1.0, 1.0, 0.0]
Jet operator /(Object o)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);
}[0.25, -0.125]
Lorentz
final class Lorentz
A Lorentz transformation \Lambda^{\mu}_{\nu} (4 \times 4, row-major, coordinates (t, x, y, z)).
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');
}Wigner rotation angle 0.221314 rad
Constructors
Lorentz(this.m)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));
}-1.0
factory Lorentz.identity()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])));
}[1.000000, 2.000000, 3.000000, 4.000000]
factory Lorentz.boost(List<double> v)A pure boost with velocity v (|v| < 1).
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]))}');
}γ = 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.
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)));
}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.
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])));
}[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).
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])));
}[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
final Float64List mdouble get metricDefectMax |\Lambda^{T} \eta \Lambda - \eta|: zero for a Lorentz transformation.
double get rotationSpreadThe 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 rotationTurnThe 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 rotationAngleThe rotation angle of a pure rotation in [0, \pi]: the radians form of rotationTurn.
Methods
double at(int mu, int nu)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)));
}-1.333333
List<double> apply(List<double> x)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)');
}[0.577350, 0.577350, 0.000000, 0.000000] (a light ray stays a light ray)
(Lorentz boost, Lorentz rotation) decompose()Polar decomposition \Lambda = B \cdot R into a boost B and a rotation R (both proper orthochronous).
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)}');
}rotation angle 0.400000
double maxDifference(Lorentz o)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)))));
}0.000000
Operators
double operator [](int i)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]);
}1.0
Lorentz operator *(Lorentz o)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())}');
}combined speed 0.800000
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}.
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))))}');
}2π spinor rotation ≈ −I: 0.000000
Constructors
const SL2C(this.a, this.b, this.c, this.d)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));
}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.
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)));
}-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).
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)));
}-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}).
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).
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))));
}0.000000
Static
static const SL2C identity = SL2C(Complex.one, Complex.zero, Complex.zero, Complex.one)Properties
final Complex afinal Complex bfinal Complex cfinal Complex dSL2C get adjointComplex get determinantComplex get traceSL2C get inverseMethods
(Complex, Complex) apply((Complex, Complex) xi)Acts on a 2-spinor (\xi^{1}, \xi^{2}).
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)));
}((1.0+0.0j), (0.0+0.0j))
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.
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])));
}[1.127626, 0.000000, 0.000000, -0.521095]
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).
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)));
}(0.5+0.0j)
double maxDifference(SL2C o)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)));
}0.000000
String toString()Operators
SL2C operator *(SL2C o)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))));
}0.000000
SL2C operator -()MetricField
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.
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)}');
}R = 0.500000
Constructors
MetricField(this.dim, this.components, {this.name = 'metric', this.coordinates})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)');
}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.
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)}');
}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)).
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)}');
}Minkowski: R = 0.000000
Properties
final int dimfinal MetricFunction componentsfinal String namefinal List<String>? coordinatesCoordinate names, e.g. ['t', 'r', '\theta', '\varphi'].
Methods
Float64List metricAt(List<double> x)g_{ab} at x (n \cdot n row-major).
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])));
}[0.250000, 0.000000, 0.000000, 0.250000]
GeometryAt at(List<double> x)The full local geometry at x: metric, inverse, derivatives and all curvature.
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)}');
}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).
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));
}[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.
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)');
}a = [-0.000000, -1.000000] (the path curves down: it is the top of a semicircle centred on the x-axis)
double inner(List<double> x, List<double> u, List<double> v)g_{ab} u^{a} v^{b} at x.
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])));
}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).
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)');
}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.
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)');
}2.000000 (dilation is not Killing)
GeometryAt
final class GeometryAt
A metric and its curvature at one point. Every quantity is computed on first use and cached.
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)}');
}R 2.000000, Kretschmann 4.000000
Properties
final MetricField fieldfinal Float64List xfinal int nlate 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.
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 determinantlate 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 christoffelDerivative\partial_{d} \Gamma^{a}_{bc} at index ((d \cdot n + a) \cdot n + b) \cdot n + c.
late final Tensor riemannR^{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 double kretschmannR_{\mathrm{abcd}} R^{\mathrm{abcd}} (Schwarzschild: 48 M^{2} / r^{6}).
late final Tensor weylThe Weyl tensor C_{\mathrm{abcd}} (n \ge 3): the trace-free part of the Riemann tensor (zero for conformally flat metrics).
Tensor get metricTensorTensor get inverseTensorTensor get christoffelArray\Gamma^{a}_{bc} as a tensor-shaped array (it is not a tensor, but the layout is the same).
RationalTriangleMesh
final class RationalTriangleMesh
A triangle mesh with exact rational vertex positions (3-D) and consistently oriented faces.
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)]}');
}corner spreads of face 0: [1/2, 1, 1/2]
Constructors
RationalTriangleMesh(List<Vec<Rational>> positions, this.faces)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²)');
}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.
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');
}12 exact vertices
Properties
final List<Vec<Rational>> positionsfinal Int32List facesint get faceCountlate final TriangleMesh floatThe 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> edgeQuadrancesThe exact quadrance of every edge, in float's edge order.
Methods
TriangleMesh toTriangleMesh()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);
}8
Rational cornerSpread(int f, int k)The spread at corner k of face f (classically \sin^{2} of the corner angle).
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)]);
}[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).
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));
}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.
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)]);
}[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).
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());
}[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.
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());
}1 -1/2 -1/2 0 -1/2 1 0 -1/2 -1/2 0 1 -1/2 0 -1/2 -1/2 1
QuadranceSpreadMesh
extension QuadranceSpreadMesh on TriangleMesh
Quadrances and spreads on a float mesh: the rational-first API in floats, with lengths and angles derived.
Properties
Methods
double cornerSpread(int f, int k)The spread at corner k of face f: |u \times v|^{2} / (|u|^{2}|v|^{2}).
UnitQuaternion
final class UnitQuaternion
A unit quaternion w + \xi + yj + zk: a point of SU(2) ≅ S³, the universal (double) cover of SO(3).
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())}');
}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
const UnitQuaternion(this.w, this.x, this.y, this.z)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());
}[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}.
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));
}1.000000
Static
static const identity = UnitQuaternion(1, 0, 0, 0)Properties
final double wfinal double xfinal double yfinal double zMethods
double dot(UnitQuaternion o)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))));
}0.877583
double distance(UnitQuaternion o)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))));
}2.000000
Float64List toRotationMatrix()The covering map SU(2) → SO(3): q and -q give the same rotation matrix (row-major 3 \times 3).
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)');
}[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)
String toString()Operators
UnitQuaternion operator *(UnitQuaternion o)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))));
}0.000000
UnitQuaternion operator -()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));
}-1.000000
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').
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])}');
}v lowered: [3.0, 4.0], trace of v⊗v·g: 25.000000
Constructors
Tensor(this.dim, this.variance, this.data)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);
}[5.0]
factory Tensor.zeros(int dim, String variance)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);
}9
factory Tensor.generate(int dim, String variance, double Function(List<int> idx) f)Builds components from f(indices).
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);
}[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.
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);
}[7.0, 10.0, 15.0, 22.0]
Properties
final int dimfinal Float64List dataint get rankMethods
np.NDArray toNDArray()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);
}[2, 2]
Tensor lower(int slot, Tensor g)Lowers slot slot with the metric g (a dd tensor).
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);
}[-2.0, 3.0]
Tensor raise(int slot, Tensor gInv)Raises slot slot with the inverse metric gInv (a uu tensor).
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);
}[1.0, 2.0]
Tensor contract(int a, int b)Contracts an up slot with a down slot (a trace).
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);
}[6.0]
Tensor outer(Tensor o)The tensor product.
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);
}[3.0, 4.0, 6.0, 8.0]
Tensor scale(double s)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);
}[3.0, 6.0]
String toString()Operators
double operator [](List<int> idx)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]]);
}10.0
void operator []=(List<int> idx, double v)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);
}[0.0, 5.0, 0.0, 0.0]
Tensor operator +(Tensor o)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);
}[4.0, 6.0]
Tensor operator -(Tensor o)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);
}[0.0, 0.0]