Skip to content

Add genus-2 split model (not_char2, arbitrary, char2; both reduced bases) - #1

Merged
salindne merged 5 commits into
mainfrom
g2-split-model
Jun 18, 2026
Merged

Add genus-2 split model (not_char2, arbitrary, char2; both reduced bases)#1
salindne merged 5 commits into
mainfrom
g2-split-model

Conversation

@salindne

Copy link
Copy Markdown
Owner

Summary

Implements explicit divisor arithmetic for the genus-2 split model (curves with two points at infinity, y² + h·y = f, deg f = 6), ported from the Magma reference in salindne/divisorArithmetic. This fills in src/g2/split/, which was previously a // TODO stub.

Divisors use the balanced 4-coordinate Mumford representation with an integer balance weight n, in both the positive (Vpl) and negative (Vn = −Vpl − h) reduced bases.

What's added

  • g2::split::not_char2 — odd characteristic, h = 0
  • g2::split::arbitrary — any characteristic (incl. 2 and 3), general h
  • g2::split::char2 — characteristic 2 over GF(2^k), XOR-based
  • Each provides precompute + add_neg/double_neg + add_pos/double_pos.
  • generic::split generalized to thread h through Add/Double/Adjust_SPLIT_{NEG,POS} (was h = 0-only), so it's a faithful Cantor reference for every characteristic.
  • Split benchmarks; README + docs; scripts/test.sh runs the split suites.

How it's verified

Mirroring the original Magma testers, every explicit formula is cross-checked against the generic Cantor reference (no Magma needed):

  • random valid divisors over growing fields (F7..F8191, GF(2^4..2^8)),
  • whitebox input vectors extracted from the Magma testers (nch2),
  • branch instrumentation asserting full coverage (DBLnn/ADDnn labels).

cargo test --release: 226 passing. Clippy (-D warnings), rustfmt, rustdoc, and cargo bench --no-run all clean.

Notes

  • precompute for arbitrary/char2 takes a caller-supplied root y3 of x² + h3·x − f6 (the points at infinity); tests construct splitting curves with a known y3.
  • For char2, 13 rare double-degenerate ADD branches (which return a trivial neutral constant) aren't reached by randomized testing and are allowlisted in the coverage test — char2 whitebox vectors can't be ported because Magma's GF(2^k) uses a different irreducible than this crate's BinaryExtField. Correctness of those branches follows by direct correspondence to the oracle-verified nch2/arb analogs.

Out of scope: the genus-3 split model (src/g3/ remains a stub).

Commits

  1. nch2 split (both bases)
  2. generalize generic::split oracle for h≠0 + arbitrary-characteristic model
  3. char2 model
  4. benchmarks + docs
  5. rustfmt + clippy/doc CI compliance

salindne added 5 commits June 18, 2026 11:57
Ports the not-characteristic-2 split (two points at infinity) genus 2
divisor arithmetic from the Magma negReduced + posReduced formulas:

- precompute(): curve constants, Vpl/Vn, degree-0 adjust divisor
- negative basis: add_neg, double_neg
- positive basis: add_pos, double_pos

Divisors use the 4-coordinate balanced Mumford representation with an
integer balance weight n (DivisorCoords{u2,u1,u0,v1,v0,n}).

Verification mirrors the original Magma testers, checking against the
generic Cantor reference in src/generic/split.rs (no Magma needed):
- random divisor pairs over F7/F31/F127/F8191 (cf. *_random.mag)
- whitebox vectors auto-extracted from the GF(5)/GF(7) tester blocks
- test-only branch instrumentation proving all 154 formula branches
  (ADD/DBL neg + PADD/PDBL pos) are exercised

cargo test --release: 203 passing (177 prior + 26 split).
- generic/split.rs: rewrite Add/Double/Adjust_SPLIT_{NEG,POS} to faithfully
  match Magma with h threaded throughout (previously h=0-only). Factors the
  shared compose/normalize/reduce. nch2 (h=0) regresses cleanly.
- g2/split/arbitrary.rs: arbitrary-characteristic split model (any field incl.
  char 2 and 3), both reduced bases, ADD + DBL, ported from arb_splitG2_*.mag.
  precompute takes a caller-supplied root y3 of x²+h3x−f6 (the ∞ points).
- arb_tests.rs: cross-checks vs the h-aware oracle over odd fields with h≠0;
  all 18+59 branches per basis exercised.

cargo test --release: 218 passing.
Char-2 split genus 2 divisor arithmetic over GF(2^k), in the normalized form
h = x³ + h1·x + h0, f = f6·x⁶ + f2·x² + f1·x + f0. Both reduced bases, ADD + DBL,
ported from ch2_splitG2_*.mag with XOR-based char-2 arithmetic (no /2).

precompute takes a caller-supplied root y3 of x²+x+f6 (the two ∞ points).

Tested over GF(2^4/2^6/2^8) against the h-aware generic Cantor oracle:
- A0 harness validation (round-trip incl. n, oracle well-formedness)
- explicit add/double cross-checks (neg + pos)
- branch coverage incl. an exhaustive deg-1 doubling sweep; the only branches
  not reached by testing are 13 double-degenerate ADD cases that return a
  trivial neutral constant (allowlisted; char2 whitebox vectors can't be ported
  because Magma's GF(2^k) uses a different irreducible than BinaryExtField).

Fixed 4 transliteration bugs in the u=up special cases (CDBL09, CPDBL09,
CADD13, CADD38) that returned degree 1 instead of the degree-2 u².

cargo test --release: 226 passing.
- benches: representative degree-2 add/double benchmarks for the split model
  (nch2, arbitrary, char2), building valid divisors via the generic oracle then
  timing the explicit formulas.
- README: document the split model + a split performance table.
- scripts/test.sh: run the g2::split suites.
- split mod docs: list all three variants.
Rebased onto current main (which added cargo fmt + clippy cleanup). Apply
rustfmt, satisfy `clippy --all-targets -- -D warnings` (assign-op patterns,
drop a dead s_deg store, module-level allow(too_many_arguments) for the
coordinate-formula modules), and adopt main's generic/mod.rs (re-applying the
h-threading edits). All four CI gates pass: test, fmt, clippy, doc.
@salindne
salindne merged commit e427a43 into main Jun 18, 2026
4 checks passed
@salindne
salindne deleted the g2-split-model branch June 18, 2026 15:53
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