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]
nyteis 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
nit: Stored as a native 8-bit signed integer. Values represent digits exactly.nyte: Unliketryte(which packs trits),nyteis stored directly as a standard 16-bit signed integer. Since $9^5 = 59049$, its valid symmetric range[-29524, 29524]fits perfectly within a 16-bit signed integer ([-32768, 32767]). This makesnytearithmetic substantially faster thantrytearithmetic, as no unpacking/packing is required.
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
nitandnyteuse 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 + 0n1 → ERR)
- 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:
nyteoperations: Very fast. Because it uses direct integer arithmetic under the hood, addition and subtraction are essentially single native instructions followed by a quick range-check. It is faster thantryte.nitatomics: Extremely fast. Roughly equivalent to 2-5 standard binary instructions.
[!TIP] If you need balanced logic but require better performance than
tryte, consider usingnyte. It offers a larger state space ($59049$ vs $729$) with lower emulation overhead.
Related
- Ternary (
trit,tryte) — Base 3 balanced numbers (foundation for Q3) - int.md — Standard binary LBIM integers