Skip to content

v2026.4.7 — Native Trig Sovereignty + Polar Embeddings

v2026.4.7 — Native Trig Sovereignty + Polar Embeddings

Section titled “v2026.4.7 — Native Trig Sovereignty + Polar Embeddings”

Released: April 7, 2026

A session that started with a single graft c "math.h" dependency and ended with 22 native polynomial implementations, a multiplication-free integer fast path, and the first polar embedding type in any systems programming language. Four modules landed. Zero C dependencies added.

1. Native Trigonometric Library — Full Sovereignty (std.math.trig)

Section titled “1. Native Trigonometric Library — Full Sovereignty (std.math.trig)”

Every trigonometric function in Janus’s standard library previously delegated to graft c "math.h". That era is over.

All 22 trig functions – sin, cos, tan, asin, acos, atan, atan2, sincos, hypot, fmod, and remainder across both f64 and f32 – are now implemented as native Janus polynomial approximations. Zero external dependencies. Every function is comptime-eligible (SPEC-043), meaning the compiler can evaluate trig at compile time where inputs are known.

The implementations are grounded in the FDLIBM minimax polynomial library (public domain, Sun Microsystems) – the same mathematical foundation that has underpinned virtually every serious numerical environment for 30 years. Cody-Waite range reduction handles the periodic functions. atan uses an 8-term degree-17 polynomial (FDLIBM aT[0–7]) covering the full argument domain. acos and asin derive from atan with careful edge case handling for the endpoints. hypot avoids overflow through intermediate scaling.

One subtle structural decision worth noting: the private _sqrt_f64 implementation uses Newton-Raphson iteration and lives directly in trig.jan rather than importing from std.math. This is deliberate – it prevents a circular dependency where math.jan would need trig.jan and trig.jan would need math.jan. The acyclic foundation is the load-bearing constraint.

sincos returns a named struct rather than separate outputs – SinCos64 for f64 and SinCos32 for f32 – which allows the compiler to keep both results in registers and avoids the awkward “pass two output pointers” pattern from C.

37 tests ship colocated with the module.

use std.math.trig
let sc = sincos(0.7)
// sc.s ≈ 0.6442, sc.c ≈ 0.7648
// Both computed natively — no C library, comptime-eligible
let angle = atan2(4.0, 3.0) // ≈ 0.9273 radians
let inv = acos(0.5) // ≈ 1.0472 (π/3)

The sovereignty milestone here is not cosmetic. A graft dependency means every platform Janus targets must have a compatible libc math implementation. Native polynomial code means Janus’s trig works identically on embedded targets, bare-metal, WASM, and GPU kernels – anywhere the Janus compiler can emit code, trig follows.


2. Integer Trig Fast Path (std.math.trig_int)

Section titled “2. Integer Trig Fast Path (std.math.trig_int)”

Pure Janus, zero dependencies, zero floating-point operations. Built explicitly for the BitNet × PolarQuant multiplication-free inference pipeline.

BitNet models constrain weights to {-1, 0, +1}. PolarQuant converts KV cache activations from Cartesian coordinates to polar angles, where similarity computation becomes angle subtraction rather than dot products. The bottleneck in that pipeline is not matrix math – it’s the coordinate conversion step. Doing that step in floating point reintroduces the FPU pressure we removed with {-1, 0, +1} weights.

trig_int solves this cleanly:

  • atan2_i8(y, x) -> u8 – Integer atan2 using octant reduction and a polynomial over the first octant. Maximum angular error less than 0.28°. The full circle maps to [0, 255].
  • magnitude_i8(x, y) -> u8 – Integer square root via Newton’s method, exact on Pythagorean triples (3,4,5 → 5; 5,12,13 → 13).
  • sincos_u8(angle) -> SinCosI8 – 65-byte quarter-wave lookup table covering [0°, 90°] with symmetry to reconstruct all four quadrants. No multiplication needed in the lookup path.
  • cartesian_to_polar_i8(cart, angles_out) -> !u8 – Batch 2D pair conversion from a Cartesian slice, writing angle bytes into a caller-provided output buffer.
use std.math.trig_int
// Integer-only polar conversion — no FPU, no floating point
let angle = atan2_i8(80, 60) // u8 angle [0, 255]
let mag = magnitude_i8(3, 4) // 5 (exact for Pythagorean triple)
let sc = sincos_u8(64) // quarter turn: {s: 127, c: 0}

The 65-byte quarter-wave table deserves a note: 65 bytes fits in a single cache line on every modern microarchitecture. The symmetry expansion (sin(x) = sin(180°-x), cos(x) = -cos(180°-x), etc.) adds four comparisons and one subtraction per lookup – far cheaper than any polynomial evaluation.


3. Polar Embeddings — SPEC-070 Phase 0 (std.compute.polar)

Section titled “3. Polar Embeddings — SPEC-070 Phase 0 (std.compute.polar)”

The first polar embedding type in any systems programming language. This is not a curiosity – it is the foundational data structure for the PolarQuant KV cache compression approach and for future angle-domain similarity computation in std.compute.

SPEC-070 Phase 0 ships the hyperspherical coordinate conversion layer: N-dimensional Cartesian vectors converted to radius (signal strength) and an (N-1)-dimensional angle array (direction in semantic space). The insight driving this design is that transformer attention patterns have separable magnitude and direction components. Magnitude encodes relevance; direction encodes semantic content. Storing them separately, quantizing them differently, and computing similarity in angle space rather than dot product space is the architectural bet at the heart of PolarQuant.

The module delivers:

  • PolarEmbedding struct – radius as f64 (the L2 norm of the original vector) + a slice of f64 angles computed via sequential atan2 and acos calls against the native trig library.
  • from_cartesian – N-dimensional conversion using the hyperspherical coordinate recursion. Each angle is computed as atan2(prefix_norm, component) except the final angle, which uses acos.
  • to_cartesian – Lossless reconstruction from polar form. Full round-trip to within floating-point epsilon.
  • 9 tests, including a doctrinal regression test for the atan2/acos asymmetry invariant – the final angle in hyperspherical coordinates requires acos rather than atan2, a subtle distinction that creates a correctness trap if the wrong function is applied. The regression test pins this permanently.
use std.compute.polar
let cart = [_]f64{1.0, 2.0, 3.0, 4.0, 5.0}
let mut angles = [_]f64{0.0, 0.0, 0.0, 0.0}
let emb = from_cartesian(cart, 5, angles)
// emb.radius ≈ 7.416 (L2 norm = signal strength)
// emb.angles = direction in 5D semantic space
// Lossless round-trip
let mut reconstructed = [_]f64{0.0, 0.0, 0.0, 0.0, 0.0}
to_cartesian(&emb, reconstructed)
// reconstructed ≈ [1.0, 2.0, 3.0, 4.0, 5.0]

The Euclidean magnitude computation that from_cartesian needs lived in an inline helper before this release. It now has a proper home as l2_norm in std.math.linalg – a generic vector magnitude utility that any stdlib module can import without pulling in the full polar dependency. Small addition; correct taxonomy.


The new stdlib structure as shipped:

std/math/trig.jan — 557 lines, native polynomial trig, zero graft
std/math/trig_int.jan — 350 lines, integer-only trig, pure Janus
std/math/linalg.jan — l2_norm + type stubs
std/compute/polar.jan — 219 lines, SPEC-070 Phase 0

std.compute is a new top-level stdlib namespace introduced by this release. It will grow to contain the full PolarQuant pipeline, Walsh-Hadamard rotation, and eventually GPU/NPU projection – all natively, without graft.


  • SPEC-070 Phase 1: Quantized angles (u8/u4/u2 precision tiers) + angle-domain similarity scoring. Cosine similarity over Cartesian coordinates becomes angle subtraction over quantized u8 indices. The math is exact; the storage is 8× smaller.
  • PolarQuant pipeline: Walsh-Hadamard rotation + recursive polar conversion for the full KV cache compression path. The integer trig fast path (trig_int) feeds directly into this.
  • Gaussian splatting: Full CPU projection pipeline using native trig. The sovereignty property matters here – Gaussian splatting targets embedded and edge inference hardware where libc is absent or unreliable.

75e8c84 feat(stdlib): register std.compute.polar in sovereign index
50b757b feat(stdlib): add std.compute.polar — SPEC-070 Phase 0
2974182 feat(stdlib): add l2_norm to std.math.linalg
72d7582 feat(stdlib): native Janus trig — full sovereignty, zero graft
ee2d766 refactor(stdlib): migrate trig functions to std.math.trig
5600d74 feat(stdlib): add std.math.trig and std.math.trig_int

“A CPU that never multiplies. An attention cache that stores angles instead of coordinates. A model whose weights are {-1, 0, +1}. Three independent optimizations that compound into something the cloud can’t match on price-per-watt.”