TRIBHUJ
Ternary Radix Implementation — Balanced Harmonic Universal Junction
"Three states: deny, abstain, affirm — the fundamental language of nature."
tribhuj (त्रिभुज) — Sanskrit for "triangle" (three-sided)
Overview
TRIBHUJ provides the mathematical foundation for balanced ternary operations throughout YAKMESH. Unlike binary (0, 1), balanced ternary uses three values: -1, 0, +1.
This enables natural representation of states like "reject/neutral/accept", "disagree/abstain/agree", and "invalid/pending/valid" — concepts that require awkward encoding in binary.
Why Balanced Ternary?
Advantages
- • No sign bit needed: Negative numbers are natural
- • Symmetric around zero: Same range positive/negative
- • Rounding is trivial: Just truncate
- • Efficient multiplication: By ±1 is just sign flip
- • Natural for consensus: -1/0/+1 maps to disagree/abstain/agree
Historical Context
Balanced ternary was used in the Soviet Setun computer (1958) — the only ternary computer to enter mass production. It was more efficient than contemporary binary machines.
YAKMESH revives this elegant number system for post-quantum cryptography, where ternary operations provide algebraic properties essential for lattice-based security.
Core Types
Trit Class
A single balanced ternary digit.
import { Trit } from 'yakmesh/oracle/tribhuj';
// Create trits
const negative = Trit.from(-1); // or Trit.NEG
const zero = Trit.from(0); // or Trit.ZERO
const positive = Trit.from(1); // or Trit.POS
// Arithmetic
negative.add(positive); // → Trit(0)
positive.multiply(negative); // → Trit(-1)
negative.negate(); // → Trit(+1)
// Logic
positive.and(negative); // → Trit(-1) (min)
positive.or(negative); // → Trit(+1) (max)
// Comparison
negative.equals(Trit.NEG); // → true
positive.compareTo(zero); // → 1 (greater)
TritArray Class
Fixed-length array of trits for multi-trit operations.
import { TritArray } from 'yakmesh/oracle/tribhuj';
// Create from values
const arr = TritArray.from([1, 0, -1, 1, -1]);
// Operations
arr.negate(); // Flip all signs
arr.add(otherArr); // Element-wise addition
arr.multiply(otherArr); // Element-wise multiplication
// Polynomial operations (for YPC-27)
arr.polyMultiply(otherArr, 27); // Ring multiplication
// Conversion
arr.toInt8Array(); // → Int8Array([-1, 0, 1, ...])
arr.toBase64(); // → "YWJj..."
TritArray.fromBase64("YWJj...", 27);
// Consensus
TritArray.consensus([arr1, arr2, arr3]); // Majority vote per trit
Ternary Logic Operations
AND (Minimum)
Returns the lesser value. Think: "strongest objection wins"
| AND | -1 | 0 | +1 |
|---|---|---|---|
| -1 | -1 | -1 | -1 |
| 0 | -1 | 0 | 0 |
| +1 | -1 | 0 | +1 |
OR (Maximum)
Returns the greater value. Think: "strongest endorsement wins"
| OR | -1 | 0 | +1 |
|---|---|---|---|
| -1 | -1 | 0 | +1 |
| 0 | 0 | 0 | +1 |
| +1 | +1 | +1 | +1 |
Ternary Averaging (NOT for Validation)
Computes weighted average of ternary values. Not used for cryptographic validation.
Important: YAKMESH validation is deterministic, not democratic.
If nodes compute different results for the same inputs, it signals a bug or attack —
the correct response is RECOMPUTE_AND_VERIFY, not voting.
See SAKSHI for how actual consensus works.
import { weightedAverage } from 'yakmesh/oracle/tribhuj';
// Averaging multiple sensor readings (example: temperature trends)
const readings = [
{ vote: Trit.POS, weight: 1.0 }, // Sensor A: "rising"
{ vote: Trit.ZERO, weight: 0.5 }, // Sensor B: "stable" (lower confidence)
{ vote: Trit.POS, weight: 1.0 }, // Sensor C: "rising"
];
const trend = weightedAverage(readings); // Weighted toward POS
// For cryptographic operations, use SAKSHI instead:
import { checkMathematicalAgreement } from 'yakmesh/security/sakshi';
// Returns AGREED | PENDING | DISAGREED (never votes)
Ternary Arithmetic
Balanced ternary arithmetic follows simple rules:
Addition
| + | -1 | 0 | +1 |
|---|---|---|---|
| -1 | -2* | -1 | 0 |
| 0 | -1 | 0 | +1 |
| +1 | 0 | +1 | +2* |
* Overflow: -2 → (+1, carry -1), +2 → (-1, carry +1)
Multiplication
| × | -1 | 0 | +1 |
|---|---|---|---|
| -1 | +1 | 0 | -1 |
| 0 | 0 | 0 | 0 |
| +1 | -1 | 0 | +1 |
No overflow in single-trit multiplication
Polynomial Ring Operations
YPC-27 checksums operate in the polynomial ring Z[x]/(x²⁷-1) mod 3.
TRIBHUJ provides the primitive operations:
import { TritArray } from 'yakmesh/oracle/tribhuj';
// Create polynomials (coefficients as trits)
const poly1 = TritArray.from([1, 0, -1, 0, 1, ...]); // 27 trits
const poly2 = TritArray.from([0, 1, 1, -1, 0, ...]); // 27 trits
// Ring multiplication: (a * b) mod (x^27 - 1) mod 3
const product = poly1.polyMultiply(poly2, 27);
// This wraps coefficients: x^27 = 1, x^28 = x, etc.
// Result is always a 27-trit polynomial
This ring structure is what makes YPC-27 checksums algebraically mixing — changing one input bit affects all 27 output coefficients.
YAKMESH Integrations
YPC-27 Checksums
27-trit polynomial checksums use TRIBHUJ for all ternary operations.
TATTVA Validation
VALID/INVALID/PENDING mapped to +1/−1/0 trits.
LAMA Consensus
Multi-node validation uses ternary consensus for agreement.
SAKSHI Attestation
Witness fusion uses balanced ternary for agreement detection.
API Reference
oracle/tribhuj.js Exports
| Export | Description |
|---|---|
Trit |
Single balanced ternary digit class |
Trit.NEG, .ZERO, .POS |
Constant trit values |
TritArray |
Fixed-length trit array class |
ternaryConsensus(trits) |
Majority vote for array of trits |
tritAdd(a, b) |
Add two trits with carry |
tritMultiply(a, b) |
Multiply two trits |
tritNegate(t) |
Flip sign of trit |
tritAnd(a, b) |
Ternary AND (min) |
tritOr(a, b) |
Ternary OR (max) |
Implementation: oracle/tribhuj.js · 684 lines · MIT License
Research & Theory
Synergy Sequence Theory (SST)
TRIBHUJ's balanced ternary aligns with Synergy Sequence Theory (Wesley Long), which identifies three "family number groups" in natural mathematics:
SST proposes that the 3-6-9 group acts as a "governing force" in nature, with 3 and 6 oscillating while 9 remains constant (singularity). This mirrors TRIBHUJ's three states: -1 (negative), 0 (neutral/constant), and +1 (positive).
The theory's "Synergy Triangle" (30-60-90°) connects to TRIBHUJ's name — Sanskrit for "triangle". YPC-27's use of 3³ = 27 trits reflects the same ternary harmony.
Ternary-144 Quantum Entropy
PRAHARI extends TRIBHUJ's ternary foundation to a 144-position addressing scheme modeled on the theoretical "Synergy Satellite Tesseract" (SST) constellation of 144 quantum random number generators in orbit.
Family Groups
Family A
Digital roots 1, 2, 4, 5, 7, 8
48 positions
Family B
Digital roots 3, 6
48 positions
Family C
Digital root 9 (singularity)
48 positions
Each position is addressed by a 6-trit value (3⁶ = 729 possible, 144 mapped). Seed selection uses a 24-position Fibonacci digital root cycle to choose the SST family, then round-robin within the family. See the PRAHARI documentation for the full seed algorithm and Entropy Sentinel scoring.
Version History
| Version | Changes |
|---|---|
| v3.0.0 | Ternary-144 addressing via PRAHARI. SST family groups (A/B/C × 48). Fibonacci digital root cycle for seed selection. Entropy Sentinel quality scoring. |
| v2.8.0 | Initial TRIBHUJ module with Trit, TritArray, ternary logic operations |