Expand description
§dreamwell-math — Classical Mathematics for Simulation
Pure mathematical primitives for the Dreamwell engine and research ecosystem. No engine dependencies. No allocation on hot path. Standalone usable.
§Modules
-
Complex: Complex number arithmetic (add, mul, conj, exp_i, norm)
-
Spatial: Distance metrics, Gaussian kernels, AABB extraction
-
Wave: Traveling wave, standing wave, wave packets, dispersion
-
Fibonacci: Golden ratio, phyllotaxis disc, Fibonacci sphere
-
Interpolation: Lerp, exponential decay, smoothstep
-
Random: Deterministic splitmix64 PRNG
-
Linear Algebra: Complex matrix multiply (CGEMM), tiled blocking
-
Eigenvalue: Jacobi rotation solver for Hermitian matrices
-
Matrix Exponential: Scaling-and-squaring with Padé approximant
§Clean Compute Compliance
- Zero heap allocation in caller-provides-output functions
- All functions are
#[inline]where beneficial - No external dependencies
- Deterministic: same inputs always produce same outputs
Modules§
- eigen
- Eigenvalue Decomposition — Jacobi rotation solver for Hermitian matrices.
- linalg
- Linear Algebra — Complex matrix operations for quantum simulation.
- matrix_
exp - Matrix Exponential — Scaling-and-squaring with Padé approximant.
Structs§
- Complex
- Complex number z = re + i·im.
Constants§
- HALF_
NEIGHBORHOOD - Forward half-neighborhood offsets for broadphase pair generation. 14 cells: self + 13 lexicographically forward neighbors. Produces zero-duplicate pairs by construction (Causal Spatial Mask).
Functions§
- adiabatic_
fraction - Adiabatic force distribution: returns the fractional force to apply on the current step within an adiabatic window.
- angular_
frequency - Angular frequency from frequency: ω = 2πf.
- atomic_
f32_ add - Atomic f32 addition via compare-exchange on AtomicU32.
- baumgarte_
correction - Baumgarte positional correction for penetration resolution. correction = max(0, depth - slop) * pct / inv_mass_sum
- clamp01
- Saturating clamp to [0, 1].
- contact_
impulse - Contact impulse magnitude (sequential impulse formula). j = -(1 + e) * v_along_normal / inv_mass_sum
- coulomb_
friction_ clamp - Coulomb friction clamp: limits tangential impulse to mu * |normal impulse|. jt_clamped = clamp(jt, -|j_normal| * mu, |j_normal| * mu)
- dispersion_
linear - Linear dispersion relation: ω = c·k (non-dispersive medium).
- distance_
3d - Euclidean distance between two 3D points.
- distance_
sq_ 3d - Squared Euclidean distance between two 3D points. Avoids sqrt for comparison (cheaper than full distance).
- ease_
in_ out_ cubic - Cubic ease-in-out: smooth acceleration and deceleration. t in [0, 1]. Returns smooth curve from 0 to 1.
- exp_
decay - Exponential decay toward target: current + (target - current) · (1 - e^{-rate·dt}).
- fibonacci_
sphere - Fibonacci sphere: N points uniformly distributed on a unit sphere using the golden ratio spiral.
- fnv1a_
3d - FNV-1a hash of a 3D integer cell coordinate. Used for spatial hash grid broadphase. Deterministic, fast, low collision rate.
- gaussian_
kernel - Gaussian radial basis function: exp(-d²/σ²). Returns 1.0 at center, decays to ~0 at distance 3σ. Used for spatial attention and relevance scoring.
- golden_
angle - The golden angle θ = 2π/φ² ≈ 2.3999632297 radians ≈ 137.508°. Used in phyllotaxis for optimal packing on discs and spheres.
- golden_
ratio - The golden ratio φ = (1 + √5) / 2 ≈ 1.6180339887.
- lerp
- Linear interpolation: a + (b - a) · t.
- lerp3
- 3D linear interpolation.
- phyllotaxis_
disc - Phyllotaxis disc: N points on a flat disc with golden angle spacing. Radius grows as √(index) for uniform area density.
- remap
- Range remapping: maps value from [in_min, in_max] to [out_min, out_max].
- slerp
- Quaternion spherical linear interpolation (slerp). Interpolates between two unit quaternions [x, y, z, w] along the great arc.
- smoothstep
- Smoothstep: Hermite interpolation between edge0 and edge1. Returns 0 below edge0, 1 above edge1, smooth curve between.
- splitmix64
- Splitmix64: deterministic PRNG. Returns (value, next_state).
- splitmix64_
f32 - Splitmix64 -> f32 in [0, 1). Deterministic.
- standing_
wave - Standing wave: y = A·sin(kx)·cos(ωt). Created by superposition of two counter-propagating traveling waves.
- traveling_
wave - Traveling wave: y = A·sin(kx - ωt). k = wave number (2π/λ), ω = angular frequency (2πf). Propagates in +x direction.
- traveling_
wave_ 2d - 2D traveling wave with perpendicular tapering: y = A·sin(k·along - ωt)·cos(k·perp·taper)
- union_
find_ merge - Union-find merge by rank. O(alpha(n)) amortized.
- union_
find_ root - Union-find root with path compression. O(alpha(n)) amortized. Used for island splitting in the Parallel Jacobi solver.
- vec3_
cross - 3D cross product.
- vec3_
dot - 3D dot product.
- vec3_
len - 3D vector length.
- vec3_
normalize - 3D vector normalize (returns zero vector if length < epsilon).
- vec3_
scale - 3D vector scale.
- wave_
number - Wave number from wavelength: k = 2π/λ.
- wave_
packet_ gaussian - Gaussian wave packet: ψ(x,t) = exp(-(x-x0-v_g·t)²/(4σ²)) · exp(i(k0·x - ω0·t)) Returns the real part (amplitude envelope × carrier).