t27.aiРусский

Five rules for a weight alphabet

You will learn

What values a ternary weight may take, how five measured rules leave one formula, and what a sixth rule removes from it.

The spec golden_sieve.t27 gives a ternary weight five measured rules and a sixth that narrows what they leave. S1: the number of values is a power of three; S2: at most two trits, as a third gave no significant gain. S3: one accumulator lane, so any two weights have a rational ratio: plus and minus phi pass as a common scale, while 1 and phi need two lanes. S4: at most six input bits per neuron, a trade, not a law, says the spec; S5: no DSP48E1 or SRL16E cells, for which openXC7 wrote a wrong bitstream while every tool said OK. The five leave TNF(k, b) with 3 or 9 levels, and S6 removes the 9-level form: on every integer ladder the top weight outweighs the others added, so one input decides. The browser runs all 3 tests and all 8 invariants.

Try it

Run the tests; then change MAX_TRITS to 3 in the source and see which two checks fail. In the spec frame, trits size a float exponent, not a weight: find exp_values of tnf4 and the test that says which offset is not finite.

Open the interactive lesson →

golden_sieve.t27, the ternary sieve, compiled inside the post
golden_sieve.t27, the ternary sieve, compiled inside the post ↗

The Golden Sieve as a t27 spec: five predicates a ternary weight alphabet must pass, compiled by t27c as WebAssembly in your browser. Seven backends; every test runs in the page.

specs/numeric/tnf4.t27

// SPDX-License-Identifier: Apache-2.0
// tnf4.t27 -- TNF4: Ternary Network Float, 4-bit class (bottom rung).
// Balanced-ternary exponent = 2 trits (3^2 = 9 offsets, exponent +-4, ~2.4
// decades), 1-bit mantissa, NO regime decode.
//   layout: [ sign(1) | E = 2 balanced-ternary trits | M = 1 bit ]
//
// Positioning (the 4-bit rung is unique): the format-to-beat here is NOT tekum
// but **BitNet-1.58 ternary WEIGHTS** {-1,0,+1} -- a weight quantizer, not a real
// format. TNF4 is a genuine 4-bit REAL number (magnitude + ~2.4-decade range),
// so it plays the ACTIVATION/value role next to BitNet's weight role, exactly as
// tri_compute_bitnet.t27 attests (ternary weights x GF/TF activations). Against
// the binary 4-bit leader MXFP4 it trades block-scale range for a native ternary
// exponent and no block-decode. phi^2 + 1/phi^2 = 3 | TRINITY

module triformat_tnf4 {
    use base::types;

    const EXP_TRITS: u32 = 2;
    const MANT_BITS: u32 = 1;
    const EXP_OFFSET: u32 = 4;    // (3^2 - 1) / 2
    const OFFSET_MAX: u32 = 8;    // 3^2 - 1 (reserved special row)

    // 2-trit exponent field -> unsigned offset in [0,8].
    fn exp_offset(t0: u32, t1: u32) -> u32 {
        return t0 + (3 * t1);
    }

    fn is_finite(offset: u32) -> bool {
        return offset != OFFSET_MAX;
    }

    fn exp_values() -> u32 {
        return 9;
    }

    // ---- Tests / invariants ----
    test offset_range {
        assert(exp_offset(0, 0) == 0, "min offset (exponent -4)");
        assert(exp_offset(2, 2) == 8, "max offset (reserved special)");
        assert(exp_offset(1, 1) == 4, "center offset = exponent 0 (unity)");
    }
    test finiteness {
        assert(is_finite(4) == true, "unity finite");
        assert(is_finite(8) == false, "offset 8 special");
        assert(exp_values() == 9, "3^2 exponent values (~2.4 decades) in 2 trits");
    }
}

Open the lesson's spec in the player ↗

All lessons