Skip to content

math: jet-anchor @rd exp + vere jet mirror#63

Open
sigilante wants to merge 4 commits into
mainfrom
sigilante/transcendental-jets
Open

math: jet-anchor @rd exp + vere jet mirror#63
sigilante wants to merge 4 commits into
mainfrom
sigilante/transcendental-jets

Conversation

@sigilante

Copy link
Copy Markdown
Collaborator

First slice of the transcendental jetting effort: wire the first jetted
math.hoon arm (@rd exp) and establish the structure + cross-repo mirror the
rest will follow.

The Hoon transcendentals themselves already merged; this PR adds only the
jet-anchoring structure and the vere-side mirror. (math.hoon's large diff
is almost entirely the ++ math re-indent — review with whitespace hidden; the
substantive change is ~18 lines.)

What changed

  • libmath/desk/lib/math.hoon — wrap the width doors in a %math engine
    door under the shared %non chapter, mirroring /lib/lagoon's
    %non/%lagoon jet structure. =< math keeps the /+ math + rd:math /
    ~(exp rd:math [%n rtol]) API unchanged. ~/ hints on the rd door and exp
    arm.
  • libmath/vere/ (new) — hand-maintained mirror of the runtime jet code
    (jets/i/math.c, the tree.c registration snippet, README). The jets live in
    urbit/vere pkg/noun; a matching PR there will follow.
  • libmath/tools/rd_exp_check.c (new) — SoftFloat-f64 reference that proves
    the jet is bit-exact to the Hoon (not merely faithful).

The gotcha (documented in the README)

A ~/-hinted engine core must be a door (^| =+ [rnd] ~/ %math |%), not a
bare |%: a sample-less ~/-core anchors its parent to the dashboard root,
so %math and everything under it miss the hot dashboard — the core registers
but no C jet ever attaches. Found by tracing _cj_hot_mean in the runtime
(math par=0 MISSmath par=non FOUND once it's a door).

Verified

exp:rd:math .~10x4005.bf0a.8b14.576a (bit-exact), 34 µs jetted vs
~970 µs interpreted; the rest of math.hoon (other fns/widths, the rounding-mode
door idiom) unchanged.

Follow-on

The remaining 14 fns × 4 widths follow this exact mold (one u3wi_ body + tree.c
entry + bit-exact harness each), plus the matching urbit/vere runtime PR.

🤖 Generated with Claude Code

sigilante and others added 4 commits June 11, 2026 10:28
Wrap math.hoon's width doors in a %math engine DOOR under the shared
%non chapter (=< math preserves the /+ math + rd:math API), mirroring
/lib/lagoon's %non/%lagoon jet structure, with ~/ hints on the rd door
and exp arm. The engine MUST be a door (^| =+ [rnd] ~/ %math |%): a
sample-less ~/-core anchors its parent to the dashboard root, so the
jet never attaches (found by tracing _cj_hot_mean in the runtime).

Mirror the vere-side C jet into libmath/vere/ (jets/i/math.c +
tree-registration.snippet.c + README) for hand-maintained cross-repo
sync -- the runtime jets live in urbit/vere (PR to follow). Add
libmath/tools/rd_exp_check.c, the SoftFloat-f64 reference proving the
jet is bit-exact to the Hoon.

@rd exp verified jetted (34us vs ~970us interpreted), bit-exact
0x4005.bf0a.8b14.576a.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Add @rd log as the second jetted transcendental, and refactor the vere
master (libmath/vere/jets/i/math.c) so the SoftFloat algorithm cores
(_rd_exp, _rd_log) are shared between the runtime jet and a standalone
bit-exact harness (libmath/vere/test/, via -DMATH_JET_HARNESS) -- the C
the test runs is byte-for-byte the C the jet runs, so they can't drift.

log transcribes math.hoon ++rd ++log (2^e*m reduction + degree-9 atanh
Horner); ~/ %log hint added. Verified bit-exact to the Hoon incl the
subnormal and sqrt(2)-boundary branches, and jetted on-ship
(log:rd:math .~2 = 0x3fe6.2e42.fefa.39ef).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…-ship)

Finish the @rd jet port begun with exp/log: add faithful softfloat cores +
u3 wrappers for sin/cos/tan/atan/atan2/asin/acos/sqt/cbt/pow/pow-n/log-2/log-10,
each transcribing its Hoon arm's exact reduction/coefficients/Horner order so
jet output is bit-identical to the pure-Hoon reference, not merely faithful.

- math.hoon: ~/ hints on all 15 @rd arms under the %math door anchor.
- jets/i/math.c: 15 algorithm cores shared with the harness via
  -DMATH_JET_HARNESS, plus u3 ABI wrappers. Fix the 2-arg wrappers
  (atan2/pow/pow-n) to use brace-enclosed u3r_mean pairs {axis,&ptr} —
  the flat form failed -Werror=missing-braces and never compiled.
- test/rd_check.c: add emit2() + atan2/pow/pow-n vectors.
- test/verify_clean.sh: one-query-at-a-time on-ship diff, NO C-c.
  (SIGINT mid-event corrupts the loom; the old verify.sh's C-c spam
  was crashing the serf and masquerading as a jet bug.)

Verified bit-exact on a fresh fakeship: 234/234 vectors, 0 DIFF
(198 single-arg via verify_clean.sh, 36 two-arg via gen/m2.hoon in one
event). sin x 200k under %bout = 431ms (~2.1us/call) confirms jetting.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Mirror /lib/lagoon's layout: maintain both runtimes' vendored jet files under
libmath/, in noun/jets/ form. The two math.c copies differ by exactly two lines
-- the two-arg u3r_mean form (brace-pair {axis,&p} on 64-bit vere-ml64 vs flat
varargs on 32-bit vere), because that macro's API diverged between the runtimes.
Everything else (15 algorithm cores, 12 single-arg wrappers, helpers) is
byte-identical: marshalling is chub-based and word-size-agnostic.

- libmath/vere/   noun/jets/{i/math.c,135/tree.c,q.h,w.h} -- 32-bit
- libmath/vere64/ noun/jets/{i/math.c,135/tree.c,q.h,w.h} -- 64-bit (+ test/)

Both built and verified bit-exact: full -test suite (math-exp/log/sqrt/ainv/
atan/tan/trig/derived) passes ok=%.y on a jetted 32-bit AND 64-bit fakeship,
plus the standalone harness's 234 single+two-arg vectors. Vendor 135 only (the
stock test ships' hoon-version; apply to 136/137 only if a target needs them).

Drop the now-redundant tree-registration.snippet.c (the full vendored tree.c
plus the rewritten README supersede it). README documents the 2-line divergence,
per-word-size apply steps, the door-anchor gotcha, -test verification, and the
SIGINT-corrupts-the-loom warning.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant