Skip to content

unum+saloon: finish posit transcendentals; wire %unum into Saloon#58

Merged
sigilante merged 7 commits into
mainfrom
sigilante/unum-transcendentals
Jun 9, 2026
Merged

unum+saloon: finish posit transcendentals; wire %unum into Saloon#58
sigilante merged 7 commits into
mainfrom
sigilante/unum-transcendentals

Conversation

@sigilante

Copy link
Copy Markdown
Collaborator

Completes the %unum transcendental story so Saloon's Tier B works on posits, not just %i754.

/lib/unum — the five missing elementary functions

factorial, cbrt, atan, asin, acos, mirroring /lib/math's algorithms in posit arithmetic with NaR domain guards (negative/out-of-range → NaR per the unum convention). The reference SoftPosit has no transcendentals, so — like /lib/math — these are the naive Taylor/AGM series; #18's Chebyshev rewrite will harden the real and posit layers together.

Saloon — %unum dispatch

+trans-scalar / +fun-scalar gain a %unum branch (posits are bloq 3/4/5/6, and unum's sqrt is +sqt), so exp/sin/cos/tan/log/sqrt/cbrt/factorial/pow/pow-n now accept %unum rays.

Oracle + tests (all green on ~hex)

  • tools/posit_check.py: a posit-arithmetic series replica + check_transcendental — confirms the series is correctly rounded vs mpmath at posit8 (11/11). (asin/acos/small-arg atan sit ~1 ULP off and are excluded from the exact gate, as noted.)
  • tests/lib/unum-fns: new arms + domain guards at posit8, and the full transcendental set at posit8/16/32 (Hoon == replica at all three widths).
  • tests/lib/saloon-unum: ray-level %unum dispatch through Saloon Tier B.
  • %i754 eig and all lagoon suites unaffected.

Complex — penciled in

A TODO in /lib/complex with the closed forms (cexp/clog/csqrt/…) for the next follow-on, which would then wire a %cplx branch into Saloon the same way.

🤖 Generated with Claude Code

sigilante and others added 2 commits June 9, 2026 10:12
/lib/unum gains the five elementary functions it was missing (factorial, cbrt,
atan, asin, acos), mirroring /lib/math's algorithms in posit arithmetic with
NaR domain guards.  (The reference SoftPosit has no transcendentals, so these
follow the same naive Taylor/AGM series as /lib/math; #18's Chebyshev rewrite
will harden both real and posit layers together.)

Saloon's Tier-B dispatch (+trans-scalar / +fun-scalar) gains a %unum branch
(posits are bloq 3/4/5/6; unum's sqrt is +sqt), so exp/sin/cos/tan/log/sqrt/
cbrt/factorial/pow/pow-n now work on %unum rays, not just %i754.

Oracle + tests:
- tools/posit_check.py: a posit-arithmetic series replica + check_transcendental
  that confirms the series is correctly rounded vs mpmath at posit8 (11/11).
- tests/lib/unum-fns: the new arms + domain guards at posit8, and the full
  transcendental set at posit8/16/32 (Hoon == replica at all three widths).
- tests/lib/saloon-unum: ray-level %unum dispatch through Saloon's Tier B.
All green on ~hex; %i754 eig and the lagoon suites unaffected.

Complex transcendentals are penciled in (a TODO in /lib/complex with the closed
forms) as the next follow-on.

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

/lib/complex gains complex elementary functions (cexp, clog, csqrt, csin, ccos,
ctan, cpow) in all four width doors (cs/cd/ch/cq).  Kept self-contained -- like
/lib/unum, /lib/fixed, /lib/twoc -- by giving each door its OWN real exp/sin/
cos/log/atan as naive Taylor/AGM series over the stdlib component float door,
rather than depending on /lib/math (which would couple the kind-primitive to
the special-functions lib and pull it into Lagoon's build).

Saloon's Tier-B dispatch (+trans-scalar / +fun-scalar) gains a %cplx branch
(complex bloqs 5/6/7/8 = ch/cs/cd/cq), so exp/sin/cos/tan/log/sqrt/pow now work
on %cplx rays.  Real-only / ordered functions (factorial, log-10, log-2, cbrt,
pow-n) are undefined on complex and crash.

Tests (validated vs numpy, all green on ~hex):
- tests/lib/complex-fns: the full set at @cs, exp/log/sqrt at @cd, exp at
  @ch/@cq (cd matches complex128 to ~15 digits, cq to ~34).
- tests/lib/saloon-cplx: ray-level %cplx dispatch through Saloon Tier B, plus
  factorial/cbrt crash-on-complex guards.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
sigilante and others added 5 commits June 9, 2026 11:33
Edge-case testing surfaced a bug: the self-contained real +rlog lacked the
x<=0 domain guard the unum +log has, so clog(0+0i) ran the atanh series on
y=-1 and returned garbage (~-5.4) instead of the -inf singularity.  Add a
log(0) -> -inf guard to +rlog in all four doors (|z| is always >= 0, so 0 is
the only singular input).

Add /tests/lib/complex-edge: origin, real/imaginary axes, the csqrt/clog branch
cut (-1, +-i), the csqrt sign branch (sqrt(-i) = 0.707 - 0.707i), the clog(0)
singularity, off-axis (1+1i, 3+4i), and two large-argument cases locked as
documented limitations (the naive series is ~0.2% off far from the origin).
All validated against numpy complex64.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
complex-edge now covers the same edges across all four widths -- @cd/@ch/@cq
get origin, the csqrt/clog branch cut (-1, -i), the clog(0)=-inf singularity,
and the imaginary axis -- plus:

- cpow edges: 2^0=1, 2^2=4, i^2=-1, (-1)^0.5=i, and the 0^2 corner (documented:
  yields NaN, since cpow routes through clog(0)=-inf -> exp(-inf), which the
  naive series can't represent -- locked as a known limitation, not correctness).
- rounding: cexp(1+2i) under %n/%u/%d/%z gives four distinct bit patterns,
  confirming the rounding mode propagates bit-exactly through the complex ops.

39 cases total, all validated against numpy complex64/128.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Adds tests/lib/unum-edge (28 cases), the %unum analogue of complex-edge:
- exact identities (exp0=1, cos0=1, sqt4=2, fact5=120, log1=0, acos1=0, ...)
- sign (exp(-1)=1/e, atan(-1)=-pi/4)
- NaR propagation (exp/sin/sqt/factorial of NaR -> NaR)
- domain -> NaR (sqrt(-1))
- a posit8 cross-width spot (identity + NaR propagation)
- large-argument breakdown / saturation, locked as DOCUMENTED limitations:
  exp(10)~21991 vs 22026; exp(50)/exp(100) saturate near maxpos; sin(10) blows
  up out of [-1,1] (no range reduction); log (atanh) holds up (log(100)~4.605).

No bug found (the unum domain guards from the transcendental PR already hold);
posits round-to-nearest-even so there is no rounding-mode axis to sweep.  The
large-arg cases are the #18 hazard made explicit, not asserted as correct.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
unum: posit transcendental edge-case sweep
complex+saloon: implement complex transcendentals; wire %cplx into Saloon
@sigilante sigilante merged commit ad51e62 into main Jun 9, 2026
@sigilante sigilante deleted the sigilante/unum-transcendentals branch June 9, 2026 17:38
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