Skip to content

spec(port): port specs/port/trinity/src/phi-engine/quantum/qutritizer.t27 (Closes #9781) - #10132

Closed
dmitrii-f-t27 wants to merge 1 commit into
gHashTag:masterfrom
dmitrii-f-t27:zcode-port-9781-qutritizer
Closed

dmitrii-f-t27 wants to merge 1 commit into
gHashTag:masterfrom
dmitrii-f-t27:zcode-port-9781-qutritizer

Conversation

@dmitrii-f-t27

Copy link
Copy Markdown
Contributor

Summary

Port gHashTag/trinity:src/phi-engine/quantum/qutritizer.zig (at ee512359254b) as specs/port/trinity/src/phi-engine/quantum/qutritizer.t27 — Roadmap Stage 5 (goal #4547), target t27c gen-rust. Closes #9781.

The original converts a ternary code into quantum amplitudes: ψ = α|−1⟩ + β|0⟩ + γ|+1⟩.

Per the issue's rule ("Port the decision, not the plumbing"), the one listed function is ported under its name as a pure function with 9 tests (49 runtime asserts, 0 vacuous, 100% function coverage):

  • the uniform superposition (original line 36): α = β = γ = 1/√3 — Newton's method (40 rounds) replaces the math library sqrt, as in the earlier sqrt ports of this series;
  • the sign-bucket threshold (lines 46-54): strictly positive trits are plus, strictly negative are minus, zero is zero — the trit range −13..13 collapses to three classes;
  • the strict-majority bias (lines 66-72): only a trit class strictly more frequent than BOTH others takes the 0.1 boost — a tie boosts nothing;
  • the norm (lines 74-80): the three amplitudes renormalize to unit length; an empty input returns the raw uniform superposition;
  • QutritState carried as a struct with the three amplitudes.

The test windows were measured on the generated code, not estimated: the boosted amplitude lands at 0.638479 and the unboosted at 0.544217 for the uniform 0.5773503 + 0.1 bias shape.

Verification (all run live from the worktree root, zig 0.16.0)

  • t27c parse: OK. t27c spec-status: IMPLEMENTED. t27c typecheck: 0 errors, 0 warnings.
  • t27c coverage: 5/5 tested (100%) — no transports in this port.
  • t27c test-report: 9 tests / 9 pass / 0 FAIL / 0 BLOCKED, 0 vacuous passes — Newton's sqrt at 4/9/3, the uniform amplitude, the bucket threshold at ±13/±1/0, the strict argmax including all three tie shapes, the empty input, the balanced input staying uniform, and all three boost directions at the measured windows.
  • All four generators were run before the push: gen (0 'not yet implemented'), gen-rust, gen-c, gen-verilog.
  • grep -cE '^\s*(pub )?fn (tritsToQutrit)\(': 1. grep -cE '^[[:space:]]*test[[:space:]]+("|[A-Za-z_])': 9 (≥ 1).
  • Boundary: git status --short — exactly this one file. The repo's lefthook pre-commit passed.
  • dupe_scan: all 5 function names unique across the corpus (checked before the commit); the bare scan reports zero error lines — no new duplicate group, none grew.

Dmitrii Fedorov (@dmitrii-f-t27)

….t27 (Closes gHashTag#9781)

Port gHashTag/trinity:src/phi-engine/quantum/qutritizer.zig (at
ee512359254b) as specs/port/trinity/src/phi-engine/quantum/
qutritizer.t27 - Roadmap Stage 5, goal gHashTag#4547, target t27c gen-rust.

The trit-to-qutrit converter's decisions are ported as pure functions
and tested (9 tests, 9 pass, 0 vacuous, 49 runtime asserts, 100%
function coverage): the uniform 1/sqrt(3) superposition the state
starts from (Newton's method replaces the math library sqrt, 40
rounds), the sign-bucket threshold (strictly positive is plus,
strictly negative is minus, zero is zero), the strict-majority bias
(only a trit class strictly more frequent than BOTH others takes the
0.1 boost - a tie boosts nothing), and the norm that brings the three
amplitudes back to unit length; an empty input returns the raw uniform
superposition. The QutritState record is carried as a struct with the
three amplitudes. The amplitude windows in the tests were measured on
the generated code (boosted 0.638479, unboosted 0.544217 for the
uniform 0.5773503 + 0.1 bias shape). All four generators (gen,
gen-rust, gen-c, gen-verilog) emit this spec before the push.

Verified: parse OK, spec-status IMPLEMENTED, typecheck 0 errors,
coverage 5/5, test-report 9/9 pass, 0 BLOCKED, gen 0 'not yet
implemented', boundary exactly this one file, dupe_scan: all 5
function names unique, bare scan reports zero error lines.

Dmitrii Fedorov ([@dmitrii-f-t27](https://github.com/dmitrii-f-t27))
@dmitrii-f-t27

Copy link
Copy Markdown
Contributor Author

@gHashTag Please merge this PR into master via the golden chain — rights on gHashTag/t27 are read-only for me (403), so only you can merge it.

Verification of this head (882e5f8, on current master — no extra merge needed):

  • Required CI trio green: validate, check-linked-issue, parse-ratchet; also Check L1 TRACEABILITY, duplicate-bodies and cli-tri green.
  • The t27b-native-run artifact of this head (commit 882e5f8, run 39072707239) row for specs/port/trinity/src/phi-engine/quantum/qutritizer.t27: reference pass, t27b pass, tests 9, invariants 0, asserts 49, blockers [], detail empty, reference_disagree: [].
  • All four generators were run locally before the push (gen, gen-rust, gen-c, gen-verilog) — this spec emits cleanly everywhere. The test amplitude windows were measured on the generated code, not estimated.
  • The only red checks are proven base-red on master WITHOUT this PR:
    • Corpus ratchet: the failing step is 'Every conflicted type name has a written verdict' — docs/reports/type_conflicts_classified.json disagrees with the tree (UNJUDGED/STALE); the identical error fails on master itself. This spec's one struct (QutritState) is a fresh, unique name — it adds no conflict.
    • t27b-native-ratchet: the registration debt, red on master across this whole port series.

After the merge I will: verify the spec file live on the merge SHA, confirm #9781 auto-closed, and file the 14-step report.

Dmitrii Fedorov (@dmitrii-f-t27)

@gHashTag

Copy link
Copy Markdown
Owner

Landed unchanged (as a merge commit) in #10174, together with ten other green ports, on top of the master fixes #10160/#10172. Closing this as superseded; the linked issue closes when #10174 merges.

@gHashTag gHashTag closed this Oct 18, 2026
dmitrii-f-t27 pushed a commit to dmitrii-f-t27/t27 that referenced this pull request Oct 18, 2026
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.

Port gHashTag/trinity:src/phi-engine/quantum/qutritizer.zig (Zig, 1 function) to specs/port/trinity/src/phi-engine/quantum/qutritizer.t27

2 participants