t81-foundation

RFC-0049: Canonical Ternary Arithmetic Semantics


Summary

This RFC defines the canonical arithmetic law for balanced-ternary computation in T81. It specifies the normative semantics for addition, subtraction, multiplication, negation, comparison, reduction, carry propagation, overflow signaling, and representation normalization so that scalar, SWAR, SIMD, VM, language, and future accelerator implementations share one mathematical contract.

Motivation

T81 already implements arithmetic across multiple layers, but the architecture still relies on a mix of accepted implementation behavior, local helper conventions, and backend-specific reasoning. That is sufficient for vertical feature delivery, but insufficient for horizontal governance. Backend equivalence, packed-trit stabilization, deterministic lowering, and memory/order guarantees all need a single arithmetic oracle. Without that oracle:

This RFC closes that gap by defining arithmetic semantics before further acceleration and promotion work expands.

Proposal

1. Canonical Domain

The canonical trit domain is balanced ternary:

Any implementation-specific encoding is an internal representation only. Arithmetic is defined over canonical trit values and canonical trit sequences, not over byte patterns.

2. Canonical Representation Rule

For any public or governed arithmetic surface:

3. Primitive Arithmetic Operations

The following operations are normatively defined:

Each primitive must be definable in terms of canonical trit algebra, not host-machine integer overflow behavior.

4. Addition and Carry Semantics

Addition is defined as balanced-ternary digitwise summation with canonical carry propagation.

Rules:

5. Subtraction

Subtraction is defined as canonical addition with canonical negation:

a - b = a + (-b)

No implementation may define subtraction through host underflow behavior or a non-canonical borrow convention that is not reducible to the addition/carry law above.

6. Multiplication

Multiplication is defined over canonical balanced-ternary digits and canonical place values.

Rules:

7. Comparison Semantics

Comparison is value-based, not representation-based.

Rules:

8. Overflow and Range Discipline

This RFC does not force one global overflow policy for every numeric type, but it does require each governed type or opcode family to choose one explicit policy and bind it to the arithmetic law.

Allowed policies:

Forbidden policy:

Each arithmetic surface must document which overflow policy it adopts and must not vary that policy by backend.

9. Reductions and Aggregates

Reductions such as sums, dot-like accumulations, population/sign counts, and arithmetic folds must define:

Any associative regrouping used by a backend must be proven equivalent under the canonical arithmetic law and the scheduling/memory rules of RFC-0045 and RFC-0046.

10. Relation to Types

This RFC applies to:

Type-specific semantics may refine shape, width, overflow, or normalization, but they may not contradict the arithmetic primitives defined here.

11. Relation to Backend Equivalence

RFC-0042 defines when two execution backends are equivalent. RFC-0049 defines what result they must be equivalent to.

Backend equivalence for arithmetic surfaces therefore means:

12. Normative Consequence

No arithmetic implementation may be promoted to Verified / DCP scope unless:

Determinism / Safety Considerations

This RFC reduces nondeterminism by removing backend-local arithmetic interpretation.

Determinism considerations:

Safety considerations:

Compatibility

This RFC is intended to codify and unify intended behavior, not introduce a new arithmetic model.

Compatibility effects:

Implementation Plan

  1. Add a normative arithmetic-semantics section to the relevant core specs.
  2. Map VM arithmetic opcodes and helper APIs to the canonical law.
  3. Audit packed/native/SWAR/SIMD arithmetic helpers against the canonical carry and normalization rules.
  4. Add conformance tests for canonical addition, subtraction, multiplication, comparison, and overflow behavior.
  5. Bind RFC-0042 backend-equivalence tests to RFC-0049 arithmetic expectations.

Open Questions

Acceptance Criteria

Implementation Record (2026-03-21)

All acceptance criteria are satisfied as of this date.

AC1 — Normative spec section: spec/tisc-spec.md §5.2.1 (“Normative Arithmetic Semantics (RFC-0049)”) was added, documenting canonical domain, primitive semantics table, carry propagation rule, overflow policy table per surface, forbidden behaviors, relation to backend equivalence, and conformance test reference.

AC2 — Operations explicitly defined: The §5.2.1 primitive semantics table defines negation, addition, subtraction, multiplication, and comparison in terms of canonical trit algebra. The subtraction identity a − b ≡ a + (−b) is normative; no independent borrow convention is permitted.

AC3 — Overflow behavior explicit: The §5.2.1 overflow policy table explicitly binds each governed surface to one policy: T81BigInt → unbounded; T81Int<N> → exception trap; T81Float<M,E> → special-value saturation; raw trit-vector decode → saturation; integer division → explicit DivisionFault. Silent host UB is a named forbidden behavior.

AC4 — Conformance tests: tests/cpp/test_arithmetic_backend_equivalence.cpp was created and registered as t81_arithmetic_backend_equivalence_test. It verifies for the scalar trit oracle (t81::ternary::add / encode_i64 / decode_i64) and the T81BigInt multi-limb chunk-based packed path:

AC5 — RFC-0042 and RFC-0043 updated: RFC-0042 §1 (Canonical Oracle) now explicitly names RFC-0049 as the arithmetic oracle for arithmetic surfaces. RFC-0043 §3 (Canonical Corpus Classes) now requires RFC-0049-derived corpus cases for arithmetic surfaces and references t81_arithmetic_backend_equivalence_test. Both RFCs updated their Discussion and References fields.