SSM-AI – Appendix D — Starter SDK & Golden Vectors (D1–D3)

Copy-paste SDK surface; clamp → rapidity → fuse → tanh — identical semantics everywhere.

D1) Minimal API (reference signatures)
(All math lane-only; classical numbers stay pristine via phi((m,a)) = m.)

# Numerics & clamps
clamp_align(a, eps_a=1e-6) -> a_c               # |a_c| < 1
to_u(a, eps_a=1e-6) -> u                        # u := atanh(clamp_align(a))
from_u(u) -> a                                  # a := tanh(u)

# Order-invariant fuse (streaming, shard-safe)
fuse_init(eps_w=1e-12) -> state(U=0.0, W=0.0)
fuse_add(state, a, w=1.0, eps_a=1e-6) -> None   # U += w*atanh(a_c); W += w
fuse_merge(state, other_state) -> None          # U += other.U; W += other.W
fuse_value(state) -> a_out                      # tanh(U / max(W, eps_w))

# Lens → Align → RSI (two-channel form)
rsi_from_e(e_items, c=1.0, eps_w=1e-12, eps_a=1e-6,
           w_policy="uniform", gamma=1.0) -> RSI
# e_items: iterable of (e_in, e_out, m_or_w)
# weights: if w_policy=="abs_m_gamma" then w := |m_or_w|^gamma else w := 1
# a_in  := tanh(-c*e_in)
# a_out := tanh(+c*e_out)
# U_in  := sum w*atanh(a_in);  V_out := sum w*atanh(a_out);  W_in := sum w
# RSI   := tanh( (V_out - U_in) / max(W_in, eps_w) )

# Calm gate (alignment-only)
gate_apply(RSI, g, mode="mul") -> RSI_env
# "mul"    : RSI_env := g * RSI
# "u_scale": RSI_env := tanh( g * atanh(RSI) )

# Path scoring (push/pop in u-space)
path_init(eps_a=1e-6, eps_w=1e-12) -> path(U=0.0, W=0.0, stack=[])
path_push(path, RSI_used, w=1.0, beta=0.0, b=0.0) -> None
# u_step := atanh(clamp_align(RSI_used, eps_a)) + beta*b
# U += w*u_step; W += w; push( (w*u_step, w) )
path_pop(path) -> None                           # pop last (ΔU, ΔW)
path_value(path) -> RSI_path                     # tanh(U / max(W, eps_w))

# Bands (defaults)
to_band(x) -> {"A++","A+","A0","A-","A--"}
# A++: x >= +0.90 ; A+: +0.60<=x<+0.90 ; A0: -0.60<x<+0.60 ; A-: -0.90<x<=-0.60 ; A--: x<=-0.90

D2) Invariants & policies (normative)
Collapse parity. phi((m,a)) = m in all APIs.
Clamp-first. Never call atanh on raw ±1; always a_c := clamp_align(a, eps_a).
Order/shard invariance. Carry only (U,W); never average directly in a-space.
Lane mul/div (M2). a* := tanh(atanh(a1) ± atanh(a2)) for lane ops; magnitudes follow classical math.
Gate purity. gate_apply acts on alignment only; never mutate m.
Determinism. Same manifest ⇒ same outputs (freeze eps_a, eps_w, weights, bands, gate.mode, c, Unit).
Numeric hygiene. Prefer float64 in SDK internals; dtype-aware eps (eps_a, eps_w) at call sites.

D3) Golden vectors (must match within dtype tolerance)
(Report to ≥ 6 decimals; all angles in radians.)

1) Clamp + round-trip
a_in = 0.9999999, eps_a=1e-6
a_c = 0.999999
u   = atanh(a_c)                 # finite
a_rt= tanh(u)                    # ≈ 0.999999 within tolerance

2) Fuse order invariance
tanh(0.2)=0.197375 ; tanh(0.4)=0.379949
U=0.2+0.4=0.6 ; W=2
a_out=tanh(0.6/2)=tanh(0.3)=0.291313   # same under swap or shard/merge

3) RSI (single item)
e_in=0.2, e_out=0.5, c=1, w=1
RSI = tanh( (0.5 - (-0.2)) ) = tanh(0.7) = 0.604368

4) Gate (two modes), g=0.81, RSI from (3)
"mul"     → RSI_env = 0.81 * 0.604367777 = 0.489538
"u_scale" → RSI_env = tanh(0.81 * atanh(0.604367777)) = tanh(0.567) = 0.513153

5) Path push/pop
Start: U=W=0
Push RSI_used=tanh(0.5869)=0.527662, w=1 → u1=0.586900 → U=0.586900, W=1
Push RSI_used=tanh(0.4)=0.379949        → u2=0.400000 → U=0.986900, W=2
RSI_path=tanh(U/W)=tanh(0.493450)=0.456950
Pop last → U=0.586900, W=1 → RSI_path=tanh(0.586900)=0.527662

6) Weighted roll-up
RSI_a=0.604368 (U=0.700000, w=2)
RSI_b=0.291313 (U=0.300000, w=1)
U=1.700000 ; W=3 ; RSI_win=tanh(1.7/3)=tanh(0.566667)=0.512907 → A0

7) Bands
to_band( 0.910425 ) -> "A++"
to_band( 0.691069 ) -> "A+"
to_band( 0.291313 ) -> "A0"
to_band(-0.875000 ) -> "A-"
to_band( 0.000000 ) -> "A0"

One-line takeaway. This SDK fixes semantics to clamp → atanh → add in u → divide → tanh with (U,W) carried for streams and shards — identical, bounded behavior everywhere, while classical values remain untouched via phi((m,a)) = m.


Navigation
Previous: SSM-AI – Appendix C — Stamp & Ledger Schema (replay, roll-up, CLI)
Next: SSM-AI – Appendix D — Reference Pseudocode, Checklist & Manifest Keys (D4–D6)


Directory of Pages
SSM-AI — Table of Contents