← Back to AILP Home

Nonary — nit and nyte

Overview

Nitpick supports balanced nonary (base 9) as an advanced primitive for multi-level cognitive states, complex quantum logic (Q9), and dense information packing. Where balanced ternary digits (trit) have 3 states, balanced nonary digits have 9 states: {-4, -3, -2, -1, 0, +1, +2, +3, +4}.

There are two nonary types: - nit: A single balanced nonary digit. - nyte: A 5-nit word (nonary byte), offering $9^5 = 59049$ possible states.

[!NOTE] nyte is the fundamental storage type for Wave9 dimensions in Nitpick's UFIE physics kernel.

Specifications

Property nit nyte
Total size 8 bits (C int8_t) 16 bits (C uint16_t)
Valid range [-4, +4] [-29524, +29524]
Valid states 9 $59049$ ($9^5$)
Storage Signed integer Direct unbiased signed integer
ERR Sentinel -128 0x8000 (INT16_MIN)
Logic type Kleene (min/max) Mathematical arithmetic

Internal Representation

Declaration

You can declare nonary variables using the 0n literal syntax. The characters A, B, C, and D represent the negative digits -1, -2, -3, and -4 respectively.

// nit literals: 0n[01234ABCD]+
nit:max_pos = 0n4;  // +4
nit:zero    = 0n0;  // 0
nit:max_neg = 0nD;  // -4

// nyte literals (evaluated positionally base-9)
nyte:val1 = 0n2A;   // 2*9 + (-1)*1 = 17
nyte:val2 = 0n004D; // Leading zeros optional

Arithmetic Operations

Standard arithmetic operations apply symmetrically to nonary values.

// nit arithmetic
nit:a = 0n3;
nit:b = 0nB;       // -2
nit:sum = a + b;   // 0n1 (+1)
nit:prod = a * b;  // 0n2C (-6), wait—overflows a single nit! -> ERR
nit:neg = -a;      // 0nC (-3)

// nyte arithmetic
nyte:x = 0n100;    // 81
nyte:y = 0n010;    // 9
nyte:q = x / y;    // 0n010 (9)
nyte:rem = x % y;  // 0n000 (0)

[!WARNING] Both nit and nyte use symmetric round-to-nearest for division and modulo, unlike standard binary C operators which truncate towards zero.

Nine-State Logic (Kleene Logic)

Like trit, a nit natively implements extended Kleene logic, choosing the minimum (AND) or maximum (OR) state among 9 levels of certainty.

nit:very_true = 0n4;
nit:mild_true = 0n2;
nit:unknown   = 0n0;
nit:very_false= 0nD; // -4

// AND is minimum
nit:and_res = very_true & mild_true;  // 0n2

// OR is maximum
nit:or_res = unknown | very_false;    // 0n0

// NOT is negation (flip)
nit:not_res = ~mild_true;             // 0nB (-2)

Error Handling & The ERR Sentinel

Both nit and nyte utilize sticky ERR sentinels to indicate invalid states.

Triggers for ERR: - Division by zero - Arithmetic overflow (e.g., 0n4 + 0n1ERR) - Operation on an existing ERR value (sticky propagation)

To check for ERR states, use the ok() function:

nyte:result = calculate_wave_state();
if (ok(result) == 0) {
    // result is ERR
    !!! ERR_WAVE_COLLAPSE;
}

Type Conversions

Converting between nonary and binary integers is highly efficient because nyte is already stored as an unbiased signed integer under the hood.

// nyte to int32 (essentially a cast)
int32:val = @cast<int32>(nyte_val);

// int32 to nyte (checks bounds)
nyte:nonary_val = @cast<nyte>(500);

To extract specific nit digits from a nyte:

// Extract the least-significant nit (index 0)
nit:n0 = nyte_val.get_nit(0);

Performance Implications

While all ternary and nonary arithmetic is software-emulated, nyte is significantly more performant than tryte:

[!TIP] If you need balanced logic but require better performance than tryte, consider using nyte. It offers a larger state space ($59049$ vs $729$) with lower emulation overhead.

Related