Skip to content

noun: math.hoon transcendental jets (@rd/@rs/@rh/@rq) [ml64]#1045

Open
sigilante wants to merge 3 commits into
neal/lagoon-softblas-64from
neal/math-transcendental-jets
Open

noun: math.hoon transcendental jets (@rd/@rs/@rh/@rq) [ml64]#1045
sigilante wants to merge 3 commits into
neal/lagoon-softblas-64from
neal/math-transcendental-jets

Conversation

@sigilante

Copy link
Copy Markdown
Collaborator

64-bit (ml64) counterpart of #1044. Registers the math.hoon transcendental
library (numerics /lib/math) in the userspace %non chapter so the four IEEE
precision doors run native SoftFloat instead of interpreted Hoon.

Stacked on neal/lagoon-softblas-64; merge after the 64-bit lagoon work.

What

  • 15 transcendentals × 4 doors (exp log sin cos tan atan atan2 asin acos sqt cbt pow pow-n log-2 log-10) for @rd/@rs/@rh/@rq as
    non → math → <door> → arm in the 135 tree.
  • Jet bodies in jets/i/math.c (chub I/O; byte-identical to the 32-bit copy
    bar the two two-arg u3r_mean call sites), q.h/w.h decls, build.zig entry.

Verification

On a fresh hoon-136 fakezod (with 136 scaffolding applied locally): all four
doors fire (exp:rd/rs/rh ~1 µs/call, exp:rq ~1.8 µs, vs ~250 µs
interpreted) and -test %/tests/lib is 247/247 green, bit-exact to the
Hoon door and identical to the 32-bit runtime.

🤖 Generated with Claude Code

@sigilante
sigilante requested a review from a team as a code owner June 26, 2026 04:27
@sigilante
sigilante requested a review from matthew-levan June 26, 2026 04:29
@sigilante

Copy link
Copy Markdown
Collaborator Author

CI failure: near is a reserved identifier/macro on the CI toolchain (it compiles on macOS clang but not Linux gcc — near is a legacy reserved word). That hits the @rh inverse-trig code in math.c and affects both vere PRs.

Register the math.hoon transcendental library (numerics /lib/math) in the
userspace %non chapter, so the four IEEE precision doors run native
SoftFloat instead of interpreted Hoon. 64-bit (vere64) counterpart of the
develop-targeted change; chub-based math.c is byte-identical bar the two
two-arg u3r_mean call sites.

- 15 transcendentals x 4 doors (exp log sin cos tan atan atan2 asin acos
  sqt cbt pow pow-n log-2 log-10) for @rd/@rs/@rh/@rq, as
  non -> math -> <door> -> arm in the 135 tree.
- Jet bodies in jets/i/math.c, u3qi_*/u3wi_* decls in q.h/w.h, build.zig
  source entry.

Bit-exact to the Hoon door; -test %/tests/lib 247/247 green on a fresh
fakezod, jet identical to interpreted Hoon arm-by-arm.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@sigilante
sigilante force-pushed the neal/math-transcendental-jets branch from 9965a23 to 17ef447 Compare June 26, 2026 04:46
@sigilante

Copy link
Copy Markdown
Collaborator Author

Dependency note: this PR is stacked on #1022 (neal/lagoon-softblas-64, the 64-bit lagoon→SoftBLAS migration) — its base branch already contains #1022's commits, so #1022 should merge first, and this PR will retarget to ml/64 once #1022 lands. (Its 32-bit counterpart #1044 is independent of #1021.)

sigilante and others added 2 commits June 26, 2026 09:12
Two accuracy bugs found while writing up this jet work for publication,
both now fixed to match the corrected math.hoon (numerics repo):

- _rh_sin/_rh_cos: the native-f16 quarter-turn reduction broke down past
  |x|~500 (q=round(|x|*2/pi) exceeds f16's 2048 exact-integer ceiling,
  amplifying rounding error by pi/2's leading term) -- catastrophic errors
  up to 10 orders of magnitude past 1 ULP, well within f16's ordinary
  range. Fixed by widening to f32 (f16_to_f32, exact) around the
  already-correct _rs_sin/_rs_cos, narrowing back via f32_to_f16
  (correctly rounded RNE) -- both primitives already linked via SoftFloat.

- _rs_tan: was (div (sin x) (cos x)), the same composed ratio used at
  @rh/@rq (~1.2 ULP). Given a genuine dedicated kernel, mirroring @rd's
  own __kernel_tan structure (Chebyshev-fit Q(z)=(tan(r)/r-1)/z, 7
  coefficients, -cot path via reciprocal for odd reduction quadrants),
  reaching ~0.94 ULP -- beating the ratio outright. The key structural
  detail: the dominant linear term must be added last (w2=x+r), not
  multiplied through the polynomial, matching fdlibm's own convention.

Verified on a freshly booted ship with jets enabled: the full
tests/lib/math-rh.hoon and math-tan.hoon suites (numerics repo) pass,
every case running in tens of microseconds (jetted, not falling back to
interpretation).

Co-Authored-By: Claude Sonnet 5 <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