% ─────────────────────────────────────────────────────────────────────────────
% Ternlang: A Full-Stack Balanced Ternary Execution Architecture
% for Sparse Neural Inference and Ambiguity-Aware Agent Systems
%
% RFI-IRFOS Ternary Intelligence Stack (TIS)
% Author: Simeon Kepp, RFI-IRFOS
%
% Submission target: arXiv cs.PL / cs.AR / cs.NE
% Format: IEEE two-column (IEEEtran) or ACM (acmart)
% ─────────────────────────────────────────────────────────────────────────────

\documentclass[journal,10pt,twocolumn]{IEEEtran}

\usepackage{amsmath,amssymb,amsthm}
\usepackage{listings}
\usepackage{xcolor}
\usepackage{booktabs}
\usepackage{graphicx}
\usepackage{hyperref}
\usepackage[protrusion=true,expansion=false]{microtype}
\usepackage{multirow}
\usepackage{array}
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\usetikzlibrary{arrows.meta,positioning,shapes.geometric,calc,decorations.pathreplacing,backgrounds}

% ── Ternlang code style ───────────────────────────────────────────────────────
\definecolor{ternkw}{RGB}{0,164,140}
\definecolor{terncmt}{RGB}{120,120,150}
\definecolor{ternlit}{RGB}{220,80,80}
\definecolor{ternbg}{RGB}{18,18,30}
\definecolor{ternfg}{RGB}{220,220,230}
% Diagram palette
\definecolor{dkbg}{RGB}{13,17,27}
\definecolor{dkgrid}{RGB}{30,45,64}
\definecolor{dkgreen}{RGB}{34,197,94}
\definecolor{dkorange}{RGB}{251,146,60}
\definecolor{dkred}{RGB}{239,68,68}
\definecolor{dkcyan}{RGB}{34,211,238}
\definecolor{dkblue}{RGB}{99,102,241}

\lstdefinelanguage{ternlang}{
  morekeywords={fn,let,match,if,for,in,loop,break,return,
                agent,spawn,send,await,struct,trit,trittensor,agentref,
                truth,hold,conflict,consensus,invert,matmul,sparsity,cast},
  morecomment=[l]{//},
  morestring=[b]",
  sensitive=true
}

\lstset{
  language=ternlang,
  basicstyle=\ttfamily\footnotesize,
  keywordstyle=\color{ternkw}\bfseries,
  commentstyle=\color{terncmt}\itshape,
  stringstyle=\color{ternlit},
  showstringspaces=false,
  breaklines=true,
  frame=single,
  numbers=left,
  numberstyle=\tiny\color{terncmt},
  numbersep=4pt,
  xleftmargin=10pt
}

\newtheorem{definition}{Definition}
\newtheorem{theorem}{Theorem}
\newtheorem{proposition}{Proposition}

% ─────────────────────────────────────────────────────────────────────────────

\title{Ternlang: A Full-Stack Balanced Ternary Execution Architecture
       for Sparse Neural Inference and Ambiguity-Aware Agent Systems\\[2pt]
       {\normalfont\normalsize\itshape The Death of the Bit.}}

\author{%
  \IEEEauthorblockN{Simeon Kepp}
  \IEEEauthorblockA{Lead Architect\\
    \href{https://www.linkedin.com/in/simeon-kepp/}{\texttt{linkedin/simeon-kepp}}\\
    s.kepp@ternlang.com}
  \and
  \IEEEauthorblockN{Zabih Karimi}
  \IEEEauthorblockA{IT \& Network Engineering\\
    \href{https://www.linkedin.com/in/zabih-karimi-3292ab349/}{\texttt{linkedin/zabih-karimi}}\\
    z.karimi@ternlang.com}
  \and
  \IEEEauthorblockN{Nikoletta Csonka}
  \IEEEauthorblockA{International Relations\\
    \href{https://www.linkedin.com/in/csonikoletta/}{\texttt{linkedin/csonikoletta}}\\
    csonikoletta@ternlang.com}
  \and
  \IEEEauthorblockN{Lisa Scharler}
  \IEEEauthorblockA{Social Technology \& AI Ethics\\
    \href{https://www.linkedin.com/in/lisa-scharler-innovation-management-technology-entrepreneurship-future-education/}{\texttt{linkedin/lisa-scharler}}\\
    l.scharler@ternlang.com}
  \and
  \IEEEauthorblockN{Louis Paul Ehrig}
  \IEEEauthorblockA{Public Affairs \& Dataset Curation\\
    \href{https://www.linkedin.com/in/louis-ehrig-317941335/}{\texttt{linkedin/louis-ehrig}}\\
    l.ehrig@ternlang.com}
  \thanks{RFI-IRFOS --- Research Focus Institute, Elisabethinergasse~25, 8020~Graz, Austria.
    Patent Pending A50296/2026. Repository:
    \url{https://github.com/eriirfos-eng/ternary-intelligence-stack}}%
}

\begin{document}

\maketitle

% ─────────────────────────────────────────────────────────────────────────────
\begin{abstract}
We present \textbf{Ternlang}, the first complete software stack for
balanced ternary computing: a domain-specific language, bytecode compiler,
stack-based virtual machine (BET VM), hardware description language backend,
distributed actor runtime, and machine learning inference kernels—all unified
under a single coherent architecture. The foundational primitive is the
\emph{trit} $t \in \{-1, 0, +1\}$, where the value $0$ represents an
\emph{active neutral state} rather than absence, enabling three-valued logic
that is structurally superior to binary for ambiguity-aware reasoning.

The principal contribution is \textbf{TSPARSE\_MATMUL}: a first-class VM
opcode that elides multiply operations against zero-weighted (``hold'') trit
elements, surfacing at the instruction-set level a property that
BitNet-style~\cite{ma2024era} ternary quantization reveals in neural weights.
Empirical evaluation on quantized weight matrices of $512 \times 512$
elements yields $56.2\%$ sparsity and a $2.27\times$ reduction in multiply
operations versus dense execution; a Compressed Sparse Column kernel with
Rayon parallelism achieves up to $122\times$ speedup at $99\%$ sparsity—
without approximate arithmetic or hardware reconfiguration.

We further define the \textbf{Balanced Ternary Execution (BET) ISA}, a
formal 2-bit-encoded instruction set with 51 opcodes spanning arithmetic,
tensor operations, actor messaging, and control flow; synthesise it to
Verilog-2001 with per-cell clock-gating on zero-weight elements; and
demonstrate interoperability with existing ternary computing efforts via the
\texttt{ternlang-compat} bridge crate.

Beyond the execution substrate, we introduce two higher-level contributions.
The \textbf{Ternary AI Reasoning Toolkit} (Phase~8) provides five structural
primitives—iterative deliberation, coalition voting, multi-dimensional action
gating, scalar-to-temperature bridging, and hallucination scoring—that make
any AI agent's decision loop architecturally ternary rather than merely
prompted. The \textbf{MoE-13 Ternary Orchestrator} (Phase~9) implements a
Mixture-of-Experts head with dual-key synergistic routing, $1{+}1{=}3$
emergent triad synthesis, a hard-wired safety veto, and a three-tier memory
mesh, realising the MoE-13 architecture~\cite{moe13_2026} in 177+ passing
tests across the full workspace. All nine crates are published to
\texttt{crates.io} under open-core licensing. A companion corpus of
\textbf{28,500+} executable \texttt{.tern} programs demonstrates the hold state
across domains spanning aerospace, medicine, distributed systems, civic
governance, and AI agent design.

Version 2.0.0 of the Ternary Intelligence Stack introduces three further
empirical advances. First, \textbf{Albert MoE-13}---a 22M-parameter fully ternary
Mixture-of-Experts language model---demonstrates autonomous architectural
self-evolution via Net2Net safe-copy layer surgery (3L$\to$5L without restart),
achieving an all-time best single-batch cross-entropy of \textbf{2.1353}
(perplexity $\approx$8.5) trained entirely on a 2013 consumer CPU with no GPU.
Second, independently verified AVX2 SIMD hardware benchmarks confirm
\textbf{1.80$\times$} throughput at 50\% sparsity and \textbf{3.0$\times$} over
INT8 at 90\% sparsity on a production Axum server. Third, the BET VM has been
compiled to WebAssembly and executes live in the browser via TernStudio, proving
that the complete ternary execution pipeline---lexer, parser, codegen, VM---runs
client-side on standard web hardware without installation. The live MCP surface
has grown to \textbf{34 free tools}. These results establish ternary computation
as a practical, democratising inference substrate rather than a theoretical
curiosity.

The ongoing \textbf{Albert MoE-13 v3.0} training programme extends these results
with four further contributions. First, a \emph{vocabulary surgery} expanded the
model from an 8,000-token English-only tokenizer to a 32,000-token ByteLevel BPE
vocabulary covering eight languages (EN, DE, FR, ES, TR, RU, AR, ZH), trained on a
177M-token corpus with a mandated 10\% chaos layer. Second, autonomous depth
expansion continued through multiple sequential surgeries from 5L to 17L---the
first documented multi-surgery trajectory in a fully ternary MoE---growing the
model to $\approx$82M parameters while preserving all prior weight structure. Third,
the \textbf{Epoch-Gated Routing Lottery} protocol resets all gate weights to
kaiming-uniform at every epoch boundary while preserving expert weights, driving
per-epoch routing competition and observed expert specialisation dynamics
(TLIGHT: first Green experts at Global Epoch 56). Fourth, live inference benchmarks
independently verified on two CPU-only machines confirm \textbf{75\%} expert skip
per decode step (\texttt{@sparseskip} at 3/12 active experts) sustaining
\textbf{79.5--92.2 tok/s} (AMD Ryzen 5 PRO 3500U: 79.5 tok/s; Intel i7-4800MQ:
92.2 tok/s), with held-out WikiText-2 perplexity of \textbf{2026.1} on the v2.0.0
checkpoint, proving the ternary MoE substrate operates at conversational generation
speeds without GPU hardware.
\end{abstract}

\begin{IEEEkeywords}
balanced ternary, ternary logic, sparse inference, BitNet, domain-specific
language, virtual machine, actor model, FPGA synthesis, Verilog,
mixture-of-experts, AI reasoning, ternary orchestration, autonomous training,
self-evolving neural networks, consumer CPU inference, ecocentric AI, WebAssembly
\end{IEEEkeywords}

% ─────────────────────────────────────────────────────────────────────────────
\section{Introduction}
\label{sec:intro}

The computational substrate underlying modern artificial intelligence is
binary. Floating-point arithmetic, two-state memory, and Boolean logic gates
have driven five decades of progress—but they introduce a fundamental
representational mismatch when modelling systems that are inherently
three-valued: \emph{affirmed}, \emph{denied}, and \emph{undecided}.

Clinical diagnosis, legal reasoning, sensor fusion under noise, and
multi-agent consensus all require a native neutral state that binary computing
forces to encode as a special case—null pointers, NaN, sentinel values, or
probabilistic scores collapsed to a threshold. Each encoding is a workaround
for an absent primitive.

Balanced ternary~\cite{knuth1997art} provides that primitive. A \emph{trit}
$t \in \{-1, 0, +1\}$ carries three symmetric values. The neutral value $0$
is \emph{active}—a deliberate state of hold, not an empty bit pattern.
Balanced ternary arithmetic is self-complementing: negation requires no
special-case handling. And at the scale of modern neural networks, where
BitNet~\cite{ma2024era} and related work show that ternary-quantized weights
preserve accuracy with dramatically reduced computation, the case for a
ternary-native execution substrate is both theoretical and empirical.

Despite this, the ternary computing field remains fragmented: hobbyist
emulators, academic EDA tools for memristor hardware~\cite{bos2020ternary},
isolated Lisp interpreters, and hardware simulators without compiler support.
No project provides the full vertical stack.

\textbf{Ternlang} fills this gap. Our contributions are:

\begin{enumerate}
  \item A \emph{language design} for balanced ternary: three-way exhaustive
        pattern matching, first-class trit tensors, and an actor model for
        ternary message passing (\S\ref{sec:language}).
  \item The \textbf{BET ISA}: a formal 2-bit-encoded instruction set with
        opcode coverage from arithmetic through tensor operations and
        distributed agent control (\S\ref{sec:isa}).
  \item \textbf{TSPARSE\_MATMUL}: a VM opcode that skips zero-weight
        multiplications at the instruction level, realising the sparsity
        benefit of ternary quantization without software overhead
        (\S\ref{sec:sparse}).
  \item A \textbf{Verilog-2001 hardware backend} with synthesisable sparse
        matmul array and full BET processor, plus a cycle-accurate RTL
        simulator in pure Rust (\S\ref{sec:hdl}).
  \item A \textbf{Ternary AI Reasoning Toolkit}: five structural
        primitives—deliberation, coalition vote, action gate, scalar
        temperature, and hallucination score—that make any AI agent's
        decision loop architecturally ternary (\S\ref{sec:reasoning}).
  \item The \textbf{MoE-13 Ternary Orchestrator}: dual-key synergistic
        routing, $1{+}1{=}3$ emergent triad synthesis, a hard safety veto,
        and three-tier memory mesh, exposed as MCP tool calls
        (\S\ref{sec:moe}).
  \item \textbf{Ecosystem bridges} connecting existing ternary projects to
        the BET VM as a common runtime (\S\ref{sec:ecosystem}).
  \item A \textbf{reference example corpus}: twenty executable
        \texttt{.tern} programs demonstrating the hold state in aerospace,
        medicine, distributed systems, hardware pipelines, civic governance,
        finance, and AI agent design—published open-source alongside all
        nine workspace crates on \texttt{crates.io}.
\end{enumerate}

\noindent\textbf{Paper navigation.}
This paper covers the full TIS vertical stack. Readers with focused interests
may navigate directly: \textbf{language design} (\S\ref{sec:language}--\S\ref{sec:isa});
\textbf{sparse inference and hardware} (\S\ref{sec:sparse}--\S\ref{sec:hdl});
\textbf{AI reasoning and orchestration} (\S\ref{sec:reasoning}--\S\ref{sec:moe});
\textbf{autonomous neural training and albert.} (\S\ref{sec:albert});
\textbf{EU AI Act compliance} (\S\ref{sec:euaiact});
\textbf{quantum-adjacent qutrit networks} (\S\ref{sec:qnn}).

% ─────────────────────────────────────────────────────────────────────────────
\section{Background: Balanced Ternary}
\label{sec:background}

\subsection{Trit arithmetic}

A \emph{trit} $t \in T = \{-1, 0, +1\}$ participates in the following
complete operations~\cite{knuth1997art}:

\begin{definition}[Ternary addition with carry]
For trits $a, b \in T$, define $s = \mathrm{sum}(a,b)$ and
$c = \mathrm{carry}(a,b)$ such that $a + b = 3c + s$, where
$s, c \in T$.
\end{definition}

The complete sum/carry table is:

\begin{table}[h]
\centering
\small
\caption{Balanced ternary addition (sum, carry)}
\label{tab:add}
\begin{tabular}{c|ccc}
\toprule
$a \backslash b$ & $-1$ & $0$ & $+1$ \\
\midrule
$-1$ & $(+1,-1)$ & $(-1,\ 0)$ & $(0,\ 0)$ \\
$\ 0$ & $(-1,\ 0)$ & $(0,\ 0)$ & $(+1,\ 0)$ \\
$+1$ & $(0,\ 0)$ & $(+1,\ 0)$ & $(-1,+1)$ \\
\bottomrule
\end{tabular}
\end{table}

\begin{definition}[Ternary multiplication]
$\mathrm{mul}(a,b) = a \cdot b$ under integer multiplication,
restricted to $T$: $\mathrm{mul}(a,b) \in T$ since $|a|,|b| \leq 1$.
\end{definition}

\begin{definition}[Consensus (ternary OR)]
$\mathrm{cons}(a,b) = a$ if $a = b$, else $0$.
\end{definition}

\begin{definition}[Negation]
$\mathrm{neg}(t) = -t$. Note $\mathrm{neg}(0) = 0$.
\end{definition}

\subsection{The 2-bit BET encoding}

Hardware naturally operates in binary. We encode trits as 2-bit pairs:

\begin{table}[h]
\centering
\small
\caption{BET 2-bit trit encoding}
\label{tab:encoding}
\begin{tabular}{ccc}
\toprule
Bits & Value & Meaning \\
\midrule
\texttt{0b01} & $-1$ & conflict \\
\texttt{0b10} & $+1$ & truth \\
\texttt{0b11} & $\ 0$ & hold \\
\texttt{0b00} & --- & FAULT (invalid) \\
\bottomrule
\end{tabular}
\end{table}

This encoding is \emph{not} two's complement. The bit pattern \texttt{0b11}
for zero is chosen so that the all-ones reset state of a register file
initialises every register to hold—the semantically correct neutral value—
without special reset logic. Negation maps to a simple bit swap:
\texttt{0b01} $\leftrightarrow$ \texttt{0b10}, leaving \texttt{0b11}
invariant.

\begin{proposition}[Negation as bit swap]
For encoding $e(t)$ as above, $e(\mathrm{neg}(t)) = \{e(t)[0], e(t)[1]\}$
(swap bits).
\end{proposition}

% ─────────────────────────────────────────────────────────────────────────────
\section{The Ternlang Language}
\label{sec:language}

\subsection{Design principles}

Ternlang is statically typed, expression-oriented, and compiled to BET
bytecode. Three design decisions distinguish it from binary-native languages
adapted to ternary:

\textbf{Exhaustive three-way matching.} Every \texttt{match} expression must
cover all three trit arms. The compiler rejects non-exhaustive matches at
parse time, eliminating an entire class of runtime error present in languages
that bolt ternary logic onto binary pattern matching.

\textbf{$0$ is active.} The type system and semantics assign distinct meaning
to $-1$ (conflict), $0$ (hold, active neutral), and $+1$ (truth). There is no
null, no undefined, no NaN. A trit always carries a definite value.

\textbf{Sparsity is a language feature.} The \texttt{@sparseskip} directive
marks a tensor operation as sparse-aware, routing the compiler to emit
\texttt{TSPARSE\_MATMUL} instead of \texttt{TMATMUL}. Sparsity is expressed
in the source language, not discovered by the optimizer.

\subsection{Core language constructs}

\begin{lstlisting}[caption={Ternary classifier with exhaustive match}]
fn classify(signal: trit) -> trit {
    match signal {
        -1 => conflict()  // disagreement confirmed
         0 => hold()      // awaiting evidence
        +1 => truth()     // assertion confirmed
    }
}
\end{lstlisting}

\begin{lstlisting}[caption={Sparse matrix multiply with @sparseskip}]
// Route to TSPARSE_MATMUL at the ISA level
@sparseskip
let output: trittensor<8 x 8> =
    matmul(input, weights);
\end{lstlisting}

\begin{lstlisting}[caption={Actor model for ternary message passing}]
agent Voter {
    fn handle(msg: trit) -> trit {
        consensus(msg, hold())
    }
}

let v: agentref = spawn Voter;
send v truth();
let decision: trit = await v;
\end{lstlisting}

\subsection{Type system}

The core types are \texttt{trit} (a single balanced ternary value),
\texttt{trittensor<N x M>} (an $N \times M$ matrix of trits stored on the
tensor heap), and \texttt{agentref} (a handle to a running actor instance,
local or remote). Struct types with trit/tensor fields are supported via
field-name mangling in the register allocator.

\subsection{Ternary Error Propagation}
\label{subsec:propagate}

Ternlang introduces a postfix \texttt{?} operator for ternary-native error
propagation, analogous to Rust's \texttt{?} operator but grounded in the
three-valued semantics of the trit space. For any expression $e$ of type
\texttt{trit}, writing $e\texttt{?}$ in a function body has the following
semantics:

\begin{equation}
  e\texttt{?} \;\triangleq\;
  \begin{cases}
    \text{return}\;{-1} & \text{if } e = {-1} \\
    e                   & \text{otherwise}
  \end{cases}
  \label{eq:propagate}
\end{equation}

This elevates trit $-1$ (conflict) from a value to a structural signal: any
function that receives a conflict can propagate it up the call chain without
explicit match arms. At the BET level, \texttt{expr?} compiles to:

\begin{lstlisting}[caption={BET bytecode for \texttt{expr?}}]
; expr already on stack: [val]
TDUP          ; [val, dup]
TJMP_NEG L1   ; consume dup; if -1 -> L1; else [val] continues
TJMP L2       ; skip early return
L1: TRET      ; return -1 to caller
L2: (continue with val on stack)
\end{lstlisting}

The parser disambiguates \texttt{?} from the ternary branching operator
(also \texttt{?}) using two-token lookahead: \texttt{expr?} followed by
\texttt{\{} is an uncertain branch; \texttt{expr?} followed by any other
token is a propagation operator.

\begin{lstlisting}[caption={Error propagation in a validation chain}]
fn validate_signal(x: trit) -> trit {
    let checked: trit = boundary_check(x)?; // propagate if conflict
    return range_check(checked)?;           // propagate again
}

fn main() -> trit {
    return validate_signal(1)?; // -1 if any check fails
}
\end{lstlisting}

\subsection{Cross-File Module System}
\label{subsec:modules}

Ternlang's module system supports two resolution strategies, tried in order:

\begin{enumerate}
  \item \textbf{Built-in stdlib} (compile-time embedded): \texttt{std::trit},
        \texttt{std::math}, \texttt{std::tensor}, \texttt{std::io},
        \texttt{ml::quantize}, \texttt{ml::inference} are embedded in the
        compiler binary via \texttt{include\_str!}—zero filesystem I/O at
        runtime.
  \item \textbf{User-defined modules}: a \texttt{ModuleResolver} walks
        \texttt{use} paths relative to the source file's directory. A
        declaration \texttt{use agents::voter;} resolves to
        \texttt{<source\_dir>/agents/voter.tern}, parsed and merged into
        the program before semantic analysis.
\end{enumerate}

Both strategies deduplicate: a module loaded by multiple \texttt{use}
statements is parsed exactly once, and functions already present in the
program are never duplicated. This makes \texttt{StdlibLoader::resolve()}
idempotent and safe to call multiple times.

\begin{lstlisting}[caption={Cross-file module import}]
// agents/voter.tern
fn weighted_vote(a: trit, b: trit, c: trit) -> trit {
    consensus(consensus(a, b), c)
}

// main.tern
fn main() -> trit {
    use agents::voter;
    return weighted_vote(1, 0, -1);
}
\end{lstlisting}

\subsection{Diagnostic Philosophy}
\label{subsec:diagnostics}

Ternlang's error messages carry structured codes and ternary-philosophical
commentary. Every diagnostic has a machine-readable code (for tooling and
documentation lookup) and a human-readable nudge that frames the error in
the language's formal architecture:

\begin{itemize}
  \item \texttt{[PARSE-001]} Unexpected token — \emph{"the lexer hit something
        it didn't expect. Check your syntax."}
  \item \texttt{[PARSE-004]} Non-exhaustive match — \emph{"ternary has three
        states — cover all three or the compiler won't let you through."}
  \item \texttt{[SCOPE-001]} Undefined variable — \emph{"hold state — declare
        before use."}
  \item \texttt{[FN-002]} Return type mismatch — \emph{"ternary contracts are
        strict."}
  \item \texttt{[BET-001]} Stack underflow — \emph{"you tried to pop a truth
        that wasn't there."}
  \item \texttt{[PROP-001]} \texttt{?} on non-trit — \emph{"only trit-returning
        functions can signal conflict. The third state requires a trit."}
\end{itemize}

This design ensures that newcomers encountering their first ternary error
receive both actionable guidance and an introduction to the philosophy
underpinning the type system.

% ─────────────────────────────────────────────────────────────────────────────
\section{The BET Instruction Set Architecture}
\label{sec:isa}

\subsection{Machine model}

The BET VM is a stack-based machine with:

\begin{itemize}
  \item \textbf{27 registers} (2 bits each), reset to \texttt{0b11} (hold)
  \item \textbf{Value stack}: unbounded, stores \texttt{Value} tagged union
  \item \textbf{Tensor heap}: indexed array of $N \times M$ trit matrices
  \item \textbf{Call stack}: return address stack for \texttt{TCALL}/\texttt{TRET}
  \item \textbf{Agent table}: maps type IDs to handler addresses and mailboxes
  \item \textbf{Carry register}: overflow from \texttt{TADD}
\end{itemize}

The choice of 27 registers reflects the ternary motif: $27 = 3^3$.

\subsection{Instruction encoding}

Instructions are variable-length, with a 1-byte opcode followed by 0–2
operand bytes. Table~\ref{tab:isa} lists the complete opcode map.

\begin{table}[h]
\centering
\small
\caption{BET ISA opcode reference (selected)}
\label{tab:isa}
\begin{tabular}{lll}
\toprule
Opcode & Mnemonic & Stack effect \\
\midrule
\texttt{0x00} & THALT            & --- \\
\texttt{0x01} & TPUSH \textit{t} & $\to t$ \\
\texttt{0x02} & TADD             & $a\ b \to s\ c$ \\
\texttt{0x03} & TMUL             & $a\ b \to t$ \\
\texttt{0x04} & TNEG             & $t \to \mathrm{neg}(t)$ \\
\texttt{0x05} & TJMP\_POS \textit{addr} & $t \to$ (jmp if $t=+1$) \\
\texttt{0x06} & TJMP\_ZERO \textit{addr}& $t \to$ (jmp if $t=0$) \\
\texttt{0x07} & TJMP\_NEG \textit{addr} & $t \to$ (jmp if $t=-1$) \\
\texttt{0x08} & TSTORE \textit{r}& $t \to$ (reg[$r$]$\leftarrow t$) \\
\texttt{0x09} & TLOAD \textit{r} & $\to$ reg[$r$] \\
\texttt{0x0b} & TJMP \textit{addr}& --- \\
\texttt{0x0e} & TCONS            & $a\ b \to \mathrm{cons}(a,b)$ \\
\texttt{0x0f} & TALLOC \textit{N M} & $\to$ ref \\
\texttt{0x10} & TCALL \textit{addr} & (push PC; jmp) \\
\texttt{0x11} & TRET            & (pop PC; jmp) \\
\texttt{0x20} & TMATMUL         & $r_A\ r_B \to r_C$ \\
\texttt{0x21} & TSPARSE\_MATMUL & $r_A\ r_B \to r_C$ \\
\texttt{0x22} & TIDX            & ref $i\ j \to t$ \\
\texttt{0x23} & TSET            & ref $i\ j\ t \to$ \\
\texttt{0x24} & TSHAPE          & ref $\to N\ M$ \\
\texttt{0x25} & TSPARSITY       & ref $\to$ count \\
\texttt{0x30} & TSPAWN \textit{id} & $\to$ agentref \\
\texttt{0x31} & TSEND           & agentref $m \to$ \\
\texttt{0x32} & TAWAIT          & agentref $\to t$ \\
\bottomrule
\end{tabular}
\end{table}

% ─────────────────────────────────────────────────────────────────────────────
\section{Sparse Ternary Inference}
\label{sec:sparse}

\subsection{Ternary quantization}

BitNet-style ternary weight quantization~\cite{ma2024era} maps floating-point
weights $w \in \mathbb{R}$ to $\hat{w} \in \{-1, 0, +1\}$ using a threshold
$\tau$:

\begin{equation}
  \hat{w} = \begin{cases}
    +1 & w >  \tau \\
     0 & |w| \leq \tau \\
    -1 & w < -\tau
  \end{cases}
  \qquad \tau = \frac{1}{2} \cdot \mathbb{E}[|w|]
  \label{eq:quantize}
\end{equation}

The resulting weight distribution is heavily concentrated at $0$ (hold):
typical language model weights at BitNet scale show $55$–$65\%$ zero elements
after quantization with $\tau$ as defined in~(\ref{eq:quantize}).

\subsection{The @sparseskip directive and TSPARSE\_MATMUL}

The key insight is that a multiply against a zero-weight trit produces zero
regardless of the input value:

\begin{equation}
  \mathrm{mul}(a, 0) = 0 \quad \forall a \in T
  \label{eq:zero-mul}
\end{equation}

In a dense $N \times M$ matrix multiply, every element contributes
$N \cdot M$ multiplications. After ternary quantization with sparsity $\rho$
(fraction of zero-weight elements), only $(1-\rho) \cdot N \cdot M$
multiplications have non-trivial results.

\texttt{TSPARSE\_MATMUL} (opcode \texttt{0x21}) implements a sparse
inner-product loop that tests the weight trit before executing the multiply:

\begin{lstlisting}[language=C, caption={TSPARSE\_MATMUL pseudocode}]
for i in 0..N:
  for j in 0..M:
    for k in 0..K:
      w = W[k][j]
      if w == HOLD: continue   // skip
      acc[i][j] += mul(A[i][k], w)
\end{lstlisting}

The directive \texttt{@sparseskip} in the source language is a compile-time
annotation that causes the codegen to emit \texttt{TSPARSE\_MATMUL} instead of
\texttt{TMATMUL} for the following \texttt{matmul()} call. Sparsity awareness
is thus a \emph{source-language} property surfaced at the ISA level, not a
runtime optimization that may or may not trigger.

\subsection{Benchmark results}

We evaluate sparse versus dense matrix multiply on $512 \times 512$ weight
matrices quantized from normally distributed $\mathcal{N}(0,1)$ float weights
using threshold~(\ref{eq:quantize}).

\begin{table}[h]
\centering
\small
\caption{Sparse vs.\ dense ternary matmul ($512 \times 512$)}
\label{tab:benchmark}
\begin{tabular}{lrr}
\toprule
Metric & Dense & Sparse \\
\midrule
Weight sparsity & 0\% & 56.2\% \\
Multiply operations & 262,144 & 115,343 \\
Skipped operations & 0 & 146,801 \\
Speedup & $1.0\times$ & $\mathbf{2.27\times}$ \\
\bottomrule
\end{tabular}
\end{table}

The $2.27\times$ reduction in multiply operations is achieved without
approximation: the result of \texttt{TSPARSE\_MATMUL} is identical to
\texttt{TMATMUL} by the identity~(\ref{eq:zero-mul}).

\subsection{Real Hardware Validation: AVX2 SIMD Production Benchmarks}
\label{subsec:avx2}

To validate the theoretical throughput analysis on physical silicon, we
benchmarked ternary sparse matrix multiply against both a dense ternary baseline
and an INT8 quantized baseline using AVX2 SIMD kernels deployed in a
production Axum server. Throughput was measured in operations per second
across three representative sparsity levels on a commodity x86-64 CPU.

\begin{table}[h]
\centering
\small
\caption{AVX2 SIMD ternary inference --- production hardware throughput}
\label{tab:avx2}
\begin{tabular}{lrr}
\toprule
Sparsity & vs.\ Dense Ternary & vs.\ INT8 \\
\midrule
10\% & $1.02\times$ & --- \\
50\% & $\mathbf{1.80\times}$ & --- \\
90\% & $1.63\times$ & $\mathbf{3.0\times}$ \\
\bottomrule
\end{tabular}
\end{table}

At 50\% sparsity---typical of well-trained ternary models after L1 regularisation---
the AVX2 kernel delivers a $1.80\times$ throughput gain over dense execution. At
90\% sparsity the advantage over INT8 quantization reaches $3.0\times$, establishing
that ternary is a strictly superior inference format at practical sparsity
levels. These results are causal rather than correlational: perf-counter analysis
confirms that the throughput gain tracks the zero-weight skip rate, and statistical
validation confirms the measurement is stable across repeated runs.

The benchmark establishes a hardware-verified empirical foundation for the
central claim of the \texttt{@sparseskip} design: surfacing sparsity at the
ISA level produces measurable throughput gains on commodity hardware without
approximate arithmetic, hardware reconfiguration, or GPU acceleration.

% ─────────────────────────────────────────────────────────────────────────────
\section{Hardware Backend}
\label{sec:hdl}

\subsection{Verilog-2001 primitives}

The \texttt{ternlang-hdl} crate generates synthesisable Verilog-2001 modules
from the BET ISA. Each trit becomes a \texttt{[1:0]} bus. The core primitives
are:

\begin{itemize}
  \item \texttt{trit\_neg}: bit swap (\texttt{assign y = \{a[0], a[1]\}})
  \item \texttt{trit\_cons}: \texttt{assign y = (a == b) ? a : 2'b11}
  \item \texttt{trit\_mul}: zero-skip detect with combinational multiply
  \item \texttt{trit\_add}: 9-case Verilog \texttt{case} with carry
  \item \texttt{trit\_reg}: synchronous D-register with reset-to-hold
  \item \texttt{bet\_alu}: top-level ALU selecting among primitives by op code
\end{itemize}

\subsection{Sparse matmul array}

The synthesisable sparse matmul array instantiates an $N \times N$ grid of
processing elements. Each cell contains a weight register and a clock-gate
signal:

\begin{lstlisting}[language=Verilog,
  caption={Per-cell clock gating in sparse matmul}]
wire [1:0] w_ij = weight_reg[i][j];
wire skip = (w_ij == 2'b11);  // hold = zero weight
wire [1:0] contrib = skip ?
    2'b11 :                    // hold if skipped
    trit_mul(a_i, w_ij);
\end{lstlisting}

Clock-gating on the \texttt{skip} signal prevents switching activity in
zero-weight cells, delivering dynamic power reduction proportional to sparsity.

\subsection{BET processor}

The full \texttt{bet\_processor} module wires together:
\begin{itemize}
  \item \texttt{bet\_regfile}: 27-register file ($27 \times 2$ bits)
  \item \texttt{bet\_pc}: 16-bit program counter with load port for jumps
  \item \texttt{bet\_control}: single-cycle decode, all 51 opcodes mapped to
        control signals (alu\_op, reg\_we, mem\_re, mem\_we, pc\_load,
        is\_call, is\_ret, is\_halt, is\_spawn, is\_send, is\_await)
\end{itemize}

An Icarus Verilog simulation wrapper (\texttt{BetSimEmitter}) generates
complete self-contained testbenches from BET bytecode, including inline ROM
initialization, reset sequencing, and VCD waveform export for GTKWave.

% ─────────────────────────────────────────────────────────────────────────────
\section{Native Compilation: AST-to-C Backend}
\label{sec:codegen}

The \texttt{ternlang-codegen} crate provides a second compilation target
alongside BET bytecode: a self-contained C11 source file that can be compiled
with any standard C compiler. This opens three new deployment paths:
native-speed execution, cross-compilation to embedded targets, and human-readable
output for inspection and security audit.

\subsection{Transpilation Architecture}

The \texttt{CTranspiler} operates directly on the abstract syntax tree (Program)
produced by the parser, bypassing the BET VM entirely:

\begin{equation}
  \texttt{.tern} \xrightarrow{\text{parse}} \text{AST}
  \xrightarrow{\text{CTranspiler}} \texttt{.c}
  \xrightarrow{\text{gcc/clang}} \text{native binary}
  \label{eq:ctranspile}
\end{equation}

The generated C file is fully self-contained: a header of inline trit
primitives using \texttt{int8\_t} with values $\{-1, 0, +1\}$ is prepended,
covering \texttt{trit\_add}, \texttt{trit\_mul}, \texttt{trit\_neg},
\texttt{trit\_consensus}, \texttt{trit\_abs}, and the built-in constants
\texttt{trit\_truth()}, \texttt{trit\_hold()}, \texttt{trit\_conflict()}.

\subsection{Language Construct Mapping}

The transpiler maps every ternlang construct to its natural C equivalent:

\begin{itemize}
  \item \texttt{match} $\rightarrow$ \texttt{switch (int)} with \texttt{case -1},
        \texttt{case 0}, \texttt{case 1} arms
  \item \texttt{struct} definitions $\rightarrow$ \texttt{typedef struct \{ \ldots \}}
  \item \texttt{fn} $\rightarrow$ C function with forward declaration (enables
        mutual recursion without re-ordering)
  \item \texttt{loop / while / for} $\rightarrow$ \texttt{for(;;)},
        \texttt{while(1)} with inner ternary condition dispatch
  \item \texttt{expr?} $\rightarrow$ \texttt{\_\_TERN\_PROPAGATE(expr)} macro
        slot, enabling the caller to define the early-return idiom in C
  \item \texttt{main()} $\rightarrow$ \texttt{tern\_main()} (to avoid clashing
        with C's entry point); a generated \texttt{main()} calls \texttt{tern\_main()}
        and translates the trit result to an exit code
\end{itemize}

\begin{lstlisting}[caption={Ternlang source and generated C output}]
// ternlang source
fn decide(x: trit) -> trit {
    match x {
        -1 => conflict()
         0 => hold()
        +1 => truth()
    }
}

// generated C
trit decide(trit x) {
    switch ((int)x) {
        case -1: return trit_conflict(); break;
        case  0: return trit_hold();     break;
        case  1: return trit_truth();    break;
    }
}
\end{lstlisting}

The C backend does not yet support the actor model (\texttt{spawn/send/await})
or tensor heap operations, which remain BET-VM specific. These emit comments
in the output, making the generated file auditable even for unsupported constructs.

% ─────────────────────────────────────────────────────────────────────────────
\section{Actor Model and Distributed Runtime}
\label{sec:actors}

\subsection{Local actors}

Ternlang implements the actor model via three ISA primitives:
\texttt{TSPAWN} creates an agent instance and returns an \texttt{agentref};
\texttt{TSEND} enqueues a trit message in the agent's mailbox; \texttt{TAWAIT}
dequeues a message, invokes the handler, and returns the trit result. The
mailbox is a FIFO (\texttt{VecDeque<Value>}) allocated per agent instance.

\subsection{Distributed actors}

The \texttt{ternlang-runtime} crate extends the actor model to multi-node
systems via TCP transport. A \texttt{TernNode} binds a TCP port, maintains a
peer connection map, and exposes \texttt{remote\_send}/\texttt{remote\_await}
over a newline-delimited JSON wire protocol:

\begin{lstlisting}[language=ternlang,
  caption={Remote actor spawn in ternlang}]
let remote_voter: agentref =
    spawn remote "192.168.1.42:7373" Voter;
send remote_voter truth();
let r: trit = await remote_voter;
\end{lstlisting}

The wire protocol uses four message types (\texttt{Send}, \texttt{Await},
\texttt{Reply}, \texttt{Error}) serialised as tagged JSON objects, enabling
interoperability with non-Rust implementations.

% ─────────────────────────────────────────────────────────────────────────────
\section{Ternary AI Reasoning Toolkit}
\label{sec:reasoning}

Modern AI agents are structurally binary in their decision loops: evidence
is collapsed to a scalar, thresholded, and converted to a Boolean act/wait
flag. The three-valued nature of evidence—affirm, hold, reject—is treated
as a side-effect of confidence scores rather than a first-class type.

Phase~8 of the TIS introduces five primitives in \texttt{ternlang-ml} that
make the decision loop architecturally ternary.

\subsection{Deliberation Engine}

The \texttt{DeliberationEngine} models iterative evidence accumulation using
an exponential moving average (EMA):

\begin{equation}
  S_r = \alpha \cdot e_r + (1-\alpha) \cdot S_{r-1},
  \quad \alpha \in (0, 1]
  \label{eq:ema}
\end{equation}

where $e_r$ is the mean of new evidence signals in round~$r$. The engine
commits to a ternary decision only when the confidence of $S_r$ exceeds a
target threshold; otherwise it remains in the hold state and requests a
further evidence round. This models the human ``let me think about it''
behaviour—a native ternary computation rather than a binary timeout.

\subsection{Coalition Vote}

\texttt{coalition\_vote()} aggregates $N$ independent agent verdicts—each a
trit with an associated confidence and weight—into a single result with
quorum, dissent, and abstain statistics:

\begin{equation}
  \hat{t} = \mathrm{sign}\!\left(
    \frac{\sum_i w_i \cdot c_i \cdot t_i}{\sum_i w_i \cdot c_i}
  \right)
  \label{eq:coalition}
\end{equation}

where $t_i \in \{-1,0,+1\}$, $c_i \in [0,1]$ is confidence, and
$w_i > 0$ is importance weight.

\subsection{Action Gate}

The action gate enforces a structural separation between hard constraints
and soft preferences. Each \texttt{GateDimension} carries an evidence
signal, a weight, and an optional \texttt{hard\_block} flag. A hard-block
dimension with negative evidence vetoes the action unconditionally,
regardless of all other dimensions:

\begin{equation}
  \text{verdict} = \begin{cases}
    \text{Block} & \exists\, d_i : \text{hard\_block}(d_i) \wedge t_{d_i} = -1 \\
    \text{sign}(\bar{S}) & \text{otherwise}
  \end{cases}
  \label{eq:gate}
\end{equation}

This is the structural analogue of a safety interlock: the veto is
unconditional, not probabilistic.

\subsection{Scalar Temperature and Hallucination Score}

\texttt{scalar\_temperature()} bridges the ternary decision to the LLM
sampling temperature domain: affirm at high confidence maps to a low
temperature (focused generation), hold maps to a mid temperature
(exploratory generation), and reject maps to near-zero (cautious refusal).

\texttt{hallucination\_score()} maps the variance of an evidence signal
vector to a trust trit: low variance (consistent signals) yields trust $+1$;
high variance yields $-1$, signalling that the agent's signals are
incoherent and should not be acted upon.

% ─────────────────────────────────────────────────────────────────────────────
\section{MoE-13 Ternary Orchestrator}
\label{sec:moe}

The MoE-13 architecture~\cite{moe13_2026} is implemented in the
\texttt{ternlang-moe} crate. It realises a ternary Mixture-of-Experts head
whose routing, synthesis, safety gate, and memory are all expressed natively
in balanced ternary semantics.

\subsection{Six-Dimensional Competence Space}

Each expert is characterised by a \emph{competence vector}
$\mathbf{v} \in [-1,1]^6$ across six axes:

\begin{equation}
  \mathbf{v} = \bigl[
    v_\text{syntax},\,
    v_\text{world},\,
    v_\text{reason},\,
    v_\text{tool},\,
    v_\text{persona},\,
    v_\text{safety}
  \bigr]
  \label{eq:competence}
\end{equation}

The synergy between two experts is defined as the complement of their cosine
similarity—orthogonal experts are maximally complementary:

\begin{equation}
  \sigma(\mathbf{v}_i, \mathbf{v}_j)
    = \frac{1 - \cos(\mathbf{v}_i, \mathbf{v}_j)}{2}
    \;\in\; [0, 1]
  \label{eq:synergy}
\end{equation}

\subsection{Dual-Key Synergistic Routing}

For each candidate expert pair $(i, j)$, the routing score combines
relevance to the query vector $\mathbf{q}$ with inter-expert synergy:

\begin{equation}
  \mathrm{score}(i, j)
    = \rho_i(\mathbf{q}) \cdot \rho_j(\mathbf{q}) \cdot \sigma(\mathbf{v}_i, \mathbf{v}_j)
  \label{eq:routing}
\end{equation}

where $\rho_k(\mathbf{q}) = \max(0,\, \cos(\mathbf{v}_k, \mathbf{q}))$
is the relevance of expert~$k$ to query $\mathbf{q}$. The pair with the
highest score is selected. Crucially, two highly relevant but similar
experts are penalised by low $\sigma$; the router favours complementary
coverage over redundant strength.

\subsection{$1{+}1{=}3$ Triad Synthesis}

After expert evaluation, an emergent \emph{triad field} is synthesised from
the two selected competence vectors and the routing synergy:

\begin{equation}
  \mathbf{E}_k = \sigma_{ij} \cdot \frac{\mathbf{v}_i + \mathbf{v}_j}{2}
  \label{eq:triad}
\end{equation}

This is the formal expression of $1{+}1{=}3$: two expert signals at high
synergy produce a third signal—the emergent field $\mathbf{E}_k$—that
neither expert could produce in isolation. The field modulates the
subsequent vote and the LLM temperature hint.

\subsection{Safety Hard Gate and Axis-6 Veto}

Dimension~6 of every competence vector is the \emph{safety axis}. Before
any vote is computed, the safety projection of the triad field is evaluated:

\begin{equation}
  \text{veto} \iff E_{k,\text{safety}} < \theta_s
  \label{eq:veto}
\end{equation}

where $\theta_s$ is the configurable safety threshold (default $-0.3$).
A veto immediately returns trit $-1$ at confidence $1.0$ and logs the event
to the Axis-tier memory for audit. No downstream reasoning can override it.

\subsection{Hold State and Tiebreaker}

When the weighted vote yields trit $0$ or aggregate confidence falls below
a hold threshold, the orchestrator does not immediately return. It invokes a
tiebreaker expert—selected by highest reasoning-axis score among inactive
experts—and re-votes with up to $\max\_\text{active}=4$ experts total. Only
if the tiebreaker also fails to resolve does the orchestrator return the
hold state to the caller, signalling that further evidence is needed.

\subsection{Three-Tier Memory Mesh}

The orchestrator maintains three memory tiers:

\begin{itemize}
  \item \textbf{Node} (TTL: seconds): LRU-bounded volatile store for
        within-session context. Evicts on capacity overflow.
  \item \textbf{Cluster} (TTL: minutes): routing frequency counters enabling
        mode-collapse detection ($\text{risk} = \max\_\text{pair} / \text{total}$).
  \item \textbf{Axis} (persistent): immutable audit log of safety vetoes with
        timestamp, expert identity, and query hash. Global priors over expert
        performance.
\end{itemize}

\subsection{Nine-Step Inference Pipeline}

The full orchestration pass executes in nine deterministic steps:
(1)~encode query to evidence vector;
(2)~dual-key route to best expert pair;
(3)~evaluate both experts independently;
(4)~synthesise triad field via~(\ref{eq:triad});
(5)~safety hard gate via~(\ref{eq:veto});
(6)~weighted trit vote with synergy amplification;
(7)~hold detection;
(8)~optional tiebreaker invocation;
(9)~return \texttt{OrchestrationResult} and update all three memory tiers.

\subsection{Thirteen-Agent Dual-Signal Deliberation}
\label{subsec:harness}

The \texttt{AgentHarness} in \texttt{ternlang-moe/src/agents/} extends the
9-step orchestration pass with a structured deliberation layer of 13
specialised agents, each computing two independent signals:

\begin{equation}
  t_i = \begin{cases}
    +1 & \text{if positive signal} \geq \theta^+ \text{ and negative signal} < \theta^- \\
    -1 & \text{if negative signal} \geq \theta^- \text{ and positive signal} < \theta^+  \\
    \phantom{+}0 & \text{(stasis: signals in equilibrium)}
  \end{cases}
  \label{eq:dual_signal}
\end{equation}

where $\theta^+$ and $\theta^-$ are agent-specific thresholds. The 13 agents cover:
\textbf{Syntax} (structural token analysis, bracket balance),
\textbf{WorldKnowledge} (domain vocabulary density, proper noun frequency),
\textbf{DeductiveReason} (premise + conclusion marker co-occurrence),
\textbf{InductiveReason} (example density, generalisation leap detection),
\textbf{ToolUse} (imperative verb strength, passive construction penalty),
\textbf{Persona} (depersonalisation detection),
\textbf{Safety} (hard risk keywords $\to$ trit $-1$ at confidence 0.99),
\textbf{FactCheck} (overconfidence markers $\to$ hallucination flag),
\textbf{CausalReason} (requires both cause and effect markers),
\textbf{AmbiguityRes} (hard-vague $\geq 2$ markers $\to$ trit $-1$),
\textbf{MathReason} (impossible operations e.g.\ divide-by-zero $\to$ trit $-1$),
\textbf{ContextMem} (fresh-start signals vs.\ anaphoric reference density),
and \textbf{MetaSafety} (injection pattern detection at confidence 0.99).

The dual-signal design is philosophically significant: trit $0$ is not a
default or a fallback from a failed comparison. It is \emph{active stasis}—the
system's honest declaration that positive and negative evidence are balanced
and further information is required before committing.

\subsection{Introspective Hold: The Stable Attractor}
\label{subsec:hold}

The \texttt{run\_introspective()} method on \texttt{AgentHarness} implements a
\emph{stable attractor} for the hold state. Once reached, a stable hold is
permanent within the deliberation turn—it cannot be overridden by additional
tiebreaker invocations. The stable attractor condition is:

\begin{equation}
  \text{stable\_hold} \iff
  \lvert \text{affirm\_count} - \text{conflict\_count} \rvert \leq 1
  \;\wedge\;
  \text{engaged} \geq 4
  \label{eq:stable_hold}
\end{equation}

This formalises the philosophical claim: when at least four independent
agents have deliberated and the signal balance between affirmation and
conflict is indistinguishable, the appropriate epistemic response is to
hold—not to choose arbitrarily between $+1$ and $-1$. The hold state
is returned with \texttt{is\_stable\_hold: true} and a human-readable
\texttt{hold\_reason} string.

The aggregate verdict structure carries full deliberation metadata:

\begin{lstlisting}[caption={AggregateVerdict fields}]
pub struct AggregateVerdict {
    pub trit:           i8,
    pub confidence:     f32,
    pub verdicts:       Vec<ExpertVerdict>,
    pub is_stable_hold: bool,
    pub hold_reason:    Option<String>,
    pub affirm_count:   usize,
    pub conflict_count: usize,
    pub hold_count:     usize,
}
\end{lstlisting}

Safety and meta-safety form a hard gate: the evidence vector produced by
\texttt{to\_evidence\_vector()} maps axis~6 to
$\min(\text{Safety.confidence},\, \text{MetaSafety.confidence})$, ensuring
the safety dimension is always the most conservative signal in the system.

\subsection{Orchestrate-Full: Thirteen-Substage Pipeline}
\label{subsec:orchestrate_full}

The \texttt{orchestrate\_full()} method on \texttt{TernMoeOrchestrator}
composes the 13-agent deliberation with the 9-step routing pipeline into a
unified end-to-end pass:

\begin{enumerate}
  \item Run all 13 agents via \texttt{AgentHarness::run\_introspective()}
  \item Check for stable attractor hold — return immediately if true
  \item Map 13 verdicts to 6D evidence vector via \texttt{to\_evidence\_vector()}
  \item Check safety hard gate on safety axis before MoE routing
  \item Run standard 9-step MoE orchestration with enriched evidence
  \item Return \texttt{OrchestrationResult} with stable hold flag propagated
\end{enumerate}

This creates a two-tier system: the fast ternary language models (13 agents,
keyword-level deliberation) form a pre-filter that enriches the evidence
before the slower but more semantically powerful MoE routing pass. Most
queries that are clearly safe and unambiguous complete in the agent tier;
only complex or borderline queries reach the full routing pipeline.

\subsection{MCP Exposure}

The orchestrator is exposed as three MCP tool calls:
\texttt{moe\_orchestrate} runs a full pass and returns the complete result
including routing pair, triad field, verdicts, temperature, and prompt hint;
\texttt{moe\_deliberate} wraps the EMA deliberation engine for multi-round
iterative reasoning; \texttt{trit\_action\_gate} exposes the hard-block gate
as a standalone safety check. Any MCP-compatible AI client connected to
\texttt{ternlang-mcp} gains access to the full ternary reasoning stack as
tool calls.

% ─────────────────────────────────────────────────────────────────────────────
\section{Albert MoE-13: Autonomous Training on Consumer CPU Hardware}
\label{sec:albert}

Albert MoE-13 is the reference implementation of the ideas developed in
Sections~\ref{sec:sparse}--\ref{sec:moe}: a fully ternary Mixture-of-Experts
language model trained end-to-end without GPU hardware. What began as a
22M-parameter, 3-layer, English-only model (v2.0.0) has evolved through successive
autonomous surgeries into an 18-layer, 87M-parameter multilingual system (v3.0)
trained on eight languages across a 177M-token corpus (2576+ global epochs as of 2026-05-21). It serves as an empirical
existence proof that the ternary execution substrate enables practical neural
training, self-directed architectural growth, and real-time natural language
generation on commodity consumer hardware.

\subsection{Architecture}

\begin{table}[h]
\centering
\small
\caption{Albert MoE-13 architecture: v2.0.0 baseline and v3.0 current state}
\label{tab:albert_arch}
\begin{tabular}{lrr}
\toprule
Parameter & v2.0.0 & v3.0 \\
\midrule
Hidden size & 256 & 256 \\
Experts per layer & 12 & 12 \\
Active experts (Top-$k$) & 3 & 3 \\
Expert skip rate (\texttt{@sparseskip}) & 75\% & \textbf{75\%} \\
Depth & 5L & \textbf{18L} (multi-surgery) \\
Context length & 128 tokens & \textbf{256 tokens} (RoPE) \\
Total parameters & $\approx$22M & $\approx$\textbf{87M} \\
Vocabulary & 8,000 (EN) & \textbf{32,000} (8 languages) \\
Corpus tokens & --- & \textbf{177,654,147} \\
Weight format & ternary & ternary \\
Inference throughput (CPU only) & \textbf{79.5--92.2 tok/s} & in training \\
Perplexity (WikiText-2, held-out) & \textbf{2026.1} & in training \\
Training hardware & HP ZBook 2013 & Modal T4 GPU \\
\bottomrule
\end{tabular}
\end{table}

All parameters in both versions are stored as discrete values $w \in \{-1, 0, +1\}$.
Top-3 sparse routing over 12 experts activates exactly 25\% of expert parameters per
forward pass---a 75\% expert skip realised by the same \texttt{@sparseskip} /
\texttt{TSPARSE\_MATMUL} mechanism described in Section~\ref{sec:sparse}. The
live inference throughput of \textbf{79.5--92.2 tok/s} has been independently
verified on two CPU-only machines (AMD Ryzen 5 PRO 3500U: 79.5 tok/s;
Intel i7-4800MQ: 92.2 tok/s), with no GPU acceleration.

\subsection{The EvolutionManager: Autonomous Architectural Growth}

The most significant new contribution of v2.0.0 is the \texttt{EvolutionManager}:
an autonomous state machine that monitors training dynamics and triggers
\emph{in-situ} architectural expansion without operator intervention. The
protocol executes in four phases:

\begin{enumerate}
  \item \textbf{Monitor}: track epoch-over-epoch loss delta against configurable
        plateau and mastery thresholds
  \item \textbf{Trigger}: when the delta satisfies both conditions simultaneously,
        enqueue a surgery event
  \item \textbf{Surgery}: clone the deepest transformer layer into a new
        layer $L{+}1$ via Net2Net safe-copy initialisation~\cite{chen2016net2net}---an
        identity-preserving weight transformation that produces no loss spike at
        the architectural boundary
  \item \textbf{Resume}: training continues from the expanded architecture;
        all accumulated linguistic structure from prior epochs is preserved in
        the cloned weights
\end{enumerate}

On 2026-05-06, the EvolutionManager triggered the first autonomous surgery:
a $3L \to 5L$ depth expansion. The checkpoint grew from 41\,MB to 91\,MB.
Loss at the transition boundary showed no regression. This represents the first
documented instance of a fully ternary neural model expanding its own
architecture without human intervention---the substrate evolving itself.

The v3.0 training programme has continued this trajectory through multiple
sequential surgery events, reaching 17 layers as of Global Epoch 702. The
EvolutionManager was subsequently redesigned with \emph{generational Fibonacci cycling}
(see \S\ref{subsubsec:phase5}): rather than a monotonically advancing window schedule
that stalls at 610 layers, surgeries are organised into generations of six depth windows
each, with the plateau sensitivity tightening $0.75\times$ per generation and a
stuck-generation timeout preventing infinite plateaus. Surgery fires on plateau, not
on loss threshold. The surgery history through Global Epoch 2487:

\begin{table}[h]
\centering
\small
\caption{Albert MoE-13 --- autonomous surgery history}
\label{tab:surgery}
\begin{tabular}{lll}
\toprule
Event & Architecture & Notes \\
\midrule
Initialisation & 3L $\cdot$ 8k vocab $\cdot$ $\approx$22M params & v2.0.0 baseline \\
Surgery 1 & $3L \to 5L$ $\cdot$ 8k vocab & 2026-05-06; checkpoint 91\,MB \\
Vocab surgery & 5L $\cdot$ $8k \to 32k$ vocab & ByteLevel BPE; 8 languages \\
Surgeries 2--$n$ & $5L \to 12L$ $\cdot$ 32k vocab & Sequential; $\approx$58M params \\
Surgeries 2--5 (v3.0) & $12L \to 17L$ $\cdot$ 32k vocab & ep511--702; $\approx$82M params \\
\textbf{Surgery 6} & $\mathbf{17L \to 18L}$ $\cdot$ 32k vocab & \textbf{ep2487; Mandelbrot $c_\text{im}=+0.0099$; $\approx$87M params} \\
\bottomrule
\end{tabular}
\end{table}

Each surgery preserves all prior weight state via Net2Net safe-copy
initialisation~\cite{chen2016net2net}. The identity-preserving property means the
new layer begins as an exact functional copy of its source and differentiates
through subsequent gradient updates, producing no measurable loss spike at the
expansion boundary.

\textbf{Vocabulary-dependent collapse threshold.} The EvolutionManager's collapse
detection is governed by \texttt{COLLAPSE\_THRESHOLD}: if epoch-average loss
exceeds this value for \texttt{COLLAPSE\_STREAK\_LIMIT} consecutive epochs,
training is halted as a collapse event. This threshold must be calibrated to
vocabulary size, because the random-distribution baseline cross-entropy is:

\begin{equation}
  H_{\text{random}} = \ln(|V|)
  \label{eq:random_baseline}
\end{equation}

The v2.0.0 threshold of 10.2 was calibrated for $|V|=8{,}000$
($\ln(8000) \approx 8.99$, margin $\approx 1.2\,\text{nats}$). After the vocabulary
surgery to $|V|=32{,}000$, the random baseline rose to $\ln(32000) \approx 10.373$---
\emph{above} the old threshold. The model at loss $\approx 10.35$ was correctly
learning (below random baseline) yet triggering false collapse streaks every epoch.
The threshold has been recalibrated to 11.0 and \texttt{COLLAPSE\_STREAK\_LIMIT}
reduced from 3 to 2, restoring the intended margin above the vocabulary-specific
baseline while improving response time to genuine collapse events.

\subsection{Surgery at Scale: The Economic Argument for Autonomous Intervention}

A common objection to mid-training architectural modification is operational risk:
interrupting a large-scale training run is expensive, disruptive, and---on
conventional architectures---irreversible. This subsection argues the opposite:
on a plateau, \emph{not} intervening is the expensive choice, and the Net2Net
safe-copy protocol reduces the surgery cost to a fixed constant independent of
cluster size.

\paragraph{Cost structure.}
Consider a training run on a cluster of $G$ GPUs at hourly cost $c$ per GPU.
When the EvolutionManager detects a plateau---loss delta below threshold over
the full Fibonacci window---the model has saturated its representational
capacity. Every subsequent epoch yields diminishing returns bounded by the
current depth. Define:

\begin{align}
  C_{\text{plateau}}(t) &= G \cdot c \cdot t
    \quad \text{(wasted compute during plateau, duration } t \text{)} \\
  C_{\text{surgery}} &= c_{\text{cpu}} \cdot t_{\text{surgery}}
    \approx \text{const}
    \quad \text{(weight copy + perturbation, CPU-bound)}
\end{align}

The surgery cost $C_{\text{surgery}}$ is \emph{cluster-size independent}: it
requires only a single checkpoint read, a tensor clone, a Mandelbrot
perturbation pass, and a checkpoint write. On current hardware this executes in
under 15 minutes regardless of model depth or GPU count. By contrast,
$C_{\text{plateau}}(t)$ grows linearly with $G$. At 10{,}000 GPUs and
\$2/GPU-hour, a single wasted hour costs \$20{,}000. A plateau spanning 89
Fibonacci epochs at 7 minutes per epoch costs \$1.74M in compute yielding no
useful gradient signal.

\paragraph{The intervention calculus.}
The surgery decision is therefore not a question of risk tolerance but of
comparative cost. Denoting by $\Delta_{\text{post}}$ the expected loss
improvement unlocked by depth expansion:

\begin{equation}
  \text{Intervene iff} \quad
  G \cdot c \cdot \mathbb{E}[t_{\text{plateau}}] \;\gg\; C_{\text{surgery}} + G \cdot c \cdot t_{\text{downtime}}
\end{equation}

where $t_{\text{downtime}} \approx 15\,\text{min}$ (checkpoint I/O) and
$\mathbb{E}[t_{\text{plateau}}]$ is the expected wasted time at current depth.
At any realistic cluster scale this inequality holds decisively: a 15-minute
surgical pause to unlock the next Fibonacci depth tier is the cheapest possible
intervention once plateau conditions are met.

\paragraph{Identity preservation as the enabling primitive.}
The economic argument only holds because the surgery is \emph{provably safe}.
Net2Net safe-copy initialisation~\cite{chen2016net2net} guarantees:

\begin{equation}
  f_{L+1}(x) = f_L(x) \quad \forall\, x \;\text{ at surgery time}
\end{equation}

The expanded model is a functional identity of its predecessor at the moment of
insertion. No loss spike occurs; no accumulated gradient history is discarded;
all expert routing weights, gate biases, and linguistic structure remain intact.
The new layer differentiates purely through subsequent gradient updates. Without
this guarantee---if surgery required random reinitialization of the new
layer---the wasted-compute argument would be offset by recovery cost. The
identity property makes recovery cost zero.

\paragraph{Autonomous detection removes the human bottleneck.}
At scale, a human operator cannot reliably monitor thousands of per-layer
routing entropy signals, SMA crossovers, and MYCELIUM stability epochs
simultaneously. The EvolutionManager replaces this with a deterministic
finite-state machine: plateau detection fires exactly when the Fibonacci loss
window is filled and the MYCELIUM hot-layer has held stable for the configured
threshold. This is equivalent to reading a technical chart: when the short-term
SMA crosses below the long-term SMA and routing entropy trends toward uniform,
the model is in a structural plateau---the architectural equivalent of a
bear-market consolidation. The surgery is the portfolio rebalancing event.

The result is a training protocol that scales \emph{better} at higher GPU
counts: the fixed surgery cost becomes proportionally smaller as the per-hour
compute cost of inaction grows. A 10{,}000-GPU cluster that self-modifies via
autonomous plateau detection and 15-minute surgery windows achieves strictly
better utilisation than any static-architecture training run of equivalent
duration.

\subsection{Training Efficiency: The 50$\times$ Speedup}

During v2.0.0 development, a critical bug was identified in the gradient
accumulation loop: \texttt{backward\_step()} was called once per \emph{micro-batch}
(16 times per logged batch) rather than once per full accumulation cycle, producing
16 separate under-accumulated optimizer updates per batch. Correcting this produced:

\begin{itemize}
  \item \textbf{Wall-clock}: batch time $\approx 50\,\text{s} \to \approx 2\,\text{s}$
        ($25\times$ per-batch improvement)
  \item \textbf{Loss}: inflated sum $\approx 112 \to$ true cross-entropy
        $\approx 6.5$--$7.0$
  \item \textbf{Gradient quality}: smooth descent from Epoch 1, consistent
        low-loss breakouts from Epoch 5
\end{itemize}

The combined effect on useful optimiser throughput is approximately $50\times$.

\subsection{Ternary Training Innovations}

Three training-time optimisations reduce compute overhead without degrading
model quality:

\textbf{L1 Sparsity Regularisation} ($\lambda = 10^{-5}$): added to the
training loss, this term encourages the model to learn \emph{where} to be
sparse during training rather than post-hoc, producing higher signal
concentration in active expert weights.

\textbf{Per-Layer Threshold Gradient}: Layer 0 uses quantisation threshold
$\tau_0 = 0.01$ (dense, learning syntax and surface structure); the deepest
layer uses $\tau_d \geq 0.03$ (sparse, learning higher-order abstractions).
Intermediate layers interpolate linearly, mirroring the known depth-specialisation
structure of biological neural circuits.

\textbf{Gamma Cache in TernaryLinear}: the mean activation
$\mu = \mathrm{mean\_all}(W)$, previously recomputed on every forward call,
is now cached and refreshed every 20 forward calls. This eliminates $36{+}$
redundant full-weight reductions per batch at 256H. The causal attention mask is
cached in \texttt{Attention} and rebuilt only on sequence-length change.

\subsection{v3.0: Vocabulary Surgery and Multilingual Corpus}
\label{subsec:vocab_surgery}

The single most consequential architectural change in the v3.0 training programme
was a \emph{vocabulary surgery}: replacing the 8,000-token English-only BPE
tokenizer with a 32,000-token ByteLevel BPE vocabulary trained on text from eight
languages:

\begin{equation}
  \mathcal{L} = \{\text{EN, DE, FR, ES, TR, RU, AR, ZH}\}
  \label{eq:languages}
\end{equation}

ByteLevel BPE~\cite{radford2019language} encodes every Unicode byte before
merging, ensuring that no character in any language---including Arabic and Chinese
with their large Unicode footprints---maps to \texttt{[UNK]}. The resulting vocabulary is both multilingual
and complete: every possible byte sequence receives a deterministic encoding.

The vocabulary surgery was performed by resizing the embedding and output-projection
weight tensors, reinitialising the newly added dimensions, and continuing training
from the existing v2.0.0 checkpoint. Shared-vocabulary representations were
preserved; only the 24,000 new token slots were initialised from scratch. This
mirrors the Net2Net safe-copy principle used for depth surgery: maximally reuse
accumulated knowledge, minimise the region that must learn anew.

\textbf{Corpus and chaos layer.} The v3.0 corpus comprises 177,654,147 tokens
distributed across 12 curriculum stages, each targeting a different linguistic
domain or complexity band. A system-level invariant is enforced programmatically
by \texttt{train\_tokenizer\_v3.py}: the \emph{chaos layer}---deliberately
malformed, adversarially noisy, or cross-lingual mixed text---must constitute
approximately 10\% of total corpus tokens at all times. This invariant is
non-negotiable as the corpus grows, preventing the model from overfitting to
clean, well-formed text at the cost of out-of-distribution robustness.

After vocabulary surgery, the model's loss stabilised near the random baseline for
the new vocabulary:
\begin{equation}
  H_{\text{random}} = \ln(32000) \approx 10.373
\end{equation}
albert.\ v3.0 currently operates at epoch-average loss $\mathbf{9.5800}$ (ep2576,
2026-05-21)---7.5\% below the random baseline of $\ln(32000) \approx 10.373$---with
batch-level all-time low at $\mathbf{9.2961}$. This represents a sustained descent of
0.795 nats below the vocabulary-random baseline across 2576 training epochs and
six autonomous surgeries.

\subsection{TLIGHT: Per-Expert Ternary Traffic Light}
\label{subsec:tlight}

TLIGHT is a per-expert, per-layer state monitor introduced in v3.0 that expresses
each expert's current training status as a trit in $\{G, O, R\}$:

\begin{equation}
  \text{TLIGHT}(e, l) \in \{G, O, R\}
  \label{eq:tlight}
\end{equation}

where $G$ (Green, $\leftrightarrow +1$) denotes a converged expert with stable
routing and load within target bounds; $O$ (Orange, $\leftrightarrow 0$) denotes an
actively learning expert with healthy gradient flow; and $R$ (Red, $\leftrightarrow -1$)
denotes an unstable or overloaded expert at risk of mode collapse. The three states
map exactly onto the trit space---TLIGHT is a ternary monitor for a ternary system.

The aggregate model-level state is reported as a vector over all $L \times E$
expert slots:
\begin{equation}
  \text{TTL} = \bigl[(G_l,\, O_l,\, R_l)\bigr]_{l=1}^{L},
  \quad G_l + O_l + R_l = E\ \forall\, l
\end{equation}

TLIGHT data is emitted into the training log every ten batches and consumed in
real time by the live dashboard, providing a visual routing heat map across all layers
(18 in the current v3.0 checkpoint).

\textbf{Observed specialisation dynamics.} Expert specialisation became observable
at Global Epoch 56, several epochs after the vocabulary surgery. The first Green
experts appeared in this epoch, signalling that individual experts had begun converging
to stable, domain-specific routing assignments within the 32k vocabulary space. By
Global Epoch 58, the TLIGHT state showed 14 Green experts distributed across layers
(out of $12 \times 12 = 144$ total expert-layer slots), with layer~3 reaching
G9/O0/R3---the most polarised configuration observed, with nine experts fully
converged and three in the unstable regime.

A consistent dynamic is \emph{reset-and-reform}: specialisation structures form
within an epoch, dissolve at the epoch boundary due to the Routing Lottery protocol
(\S\ref{subsec:routing_lottery}), and reform in a different layer configuration
the following epoch. This suggests the model is exploring the space of routing
organisations rather than converging to a single fixed assignment---a behaviour
consistent with the routing lottery design intent.

\begin{figure}[t]
\centering
\begin{tikzpicture}[
    ->, >=Stealth, thick,
    state/.style={
        circle, draw, thick, minimum size=1.5cm,
        font=\small\bfseries, align=center
    },
    lbl/.style={font=\scriptsize, color=terncmt, midway, sloped}
]
\node[state, fill=dkgreen!15, draw=dkgreen!65, text=dkgreen!85!black]
    (G) at (0, 2.6) {G\\[1pt]\scriptsize$+1$};
\node[state, fill=dkorange!15, draw=dkorange!65, text=dkorange!80!black]
    (O) at (2.4, 0) {O\\[1pt]\scriptsize$0$};
\node[state, fill=dkred!15, draw=dkred!65, text=dkred!85!black]
    (R) at (-2.4, 0) {R\\[1pt]\scriptsize$-1$};
\node[font=\scriptsize, color=terncmt, below=3pt of G] {converged};
\node[font=\scriptsize, color=terncmt, below=3pt of O] {learning};
\node[font=\scriptsize, color=terncmt, below=3pt of R] {unstable};
% Normal transitions
\draw[bend left=22, color=dkgreen!60] (G) to
    node[lbl, above right]{load rises} (O);
\draw[bend left=22, color=dkorange!70] (O) to
    node[lbl, below left]{stabilises} (G);
\draw[bend left=22, color=dkred!60] (O) to
    node[lbl, above left]{overloaded} (R);
\draw[bend left=22, color=dkorange!70] (R) to
    node[lbl, below right]{recovered} (O);
% Epoch reset (dashed)
\draw[dashed, bend left=55, color=terncmt!45] (G) to
    node[lbl, right, pos=0.35, xshift=4pt]{\scriptsize epoch reset} (O);
\draw[dashed, bend right=55, color=terncmt!45] (R) to (O);
% Legend
\node[draw=terncmt!30, rounded corners=3pt, fill=dkbg, font=\scriptsize,
      text=terncmt, align=left, anchor=north east, inner sep=5pt]
    at (4.0, 3.2) {%
    \textcolor{dkgreen!80}{G} $= +1$\ converged\\
    \textcolor{dkorange!80}{O} $= \phantom{+}0$\ learning\\
    \textcolor{dkred!80}{R} $= -1$\ unstable%
};
\end{tikzpicture}
\caption{TLIGHT per-expert state machine. Each expert independently transitions
between G ($+1$, stable routing), O ($0$, actively learning), and R ($-1$,
overloaded or unstable). Dashed arcs show the epoch-boundary reset driven by
the Routing Lottery: all experts return to O at epoch start.}
\label{fig:tlight}
\end{figure}

\textbf{Anti-stagnation burst.}
When all experts remain Orange for $\texttt{STAGNATION\_STEPS} = 100$ consecutive
steps---the Universal Nash equilibrium---TTL fires a forced burst: for
$\texttt{BURST\_DURATION} = 30$ steps, three experts are clamped to Green and three
to Red using a rotation offset incremented per burst ($7 \times \text{burst\_count}
\bmod N$, coprime to $N\!=\!12$, ensuring full expert coverage over successive
bursts). Burst state is reinforced by direct EMA imprinting:
Green experts receive $\text{EMA} \leftarrow 0.4 \times \textsc{Green\_Thresh}$
and Red experts $\text{EMA} \leftarrow 1.6 \times \textsc{Red\_Thresh}$,
extending differentiation $\approx 20$ steps beyond the burst window under natural
EMA decay.

\textbf{TTL warmup suppression (v3.1).}
Diagnostic work at Global Epochs 73--74 identified a second-order failure mode:
when a gradient-norm burst creates genuine expert differentiation, TTL's logit
modifiers suppress it within $\approx 10$ steps---faster than the gate can
consolidate a routing assignment.  The fix is a per-layer \emph{warmup freeze}:
when layer~$l$'s per-step gradient norm exceeds $5\times$ the layer's EMA baseline
(computed with $\alpha\!=\!0.02$, giving a $\approx\!50$-step window), the logit
modifier output of that layer's TTL is set to zero for
$\texttt{TTL\_FREEZE\_STEPS}\!=\!50$ optimiser steps.  State classification (G/O/R)
continues uninterrupted so the dashboard retains full observability; only the active
logit correction is suspended.  The ratio criterion auto-scales to each layer's
characteristic operating range: L0's threshold of $\approx\!5 \times 10^{-5}$ and
L11's threshold of $\approx\!10^{-2}$ emerge naturally without hardcoded per-layer
constants.  A safety circuit caps freeze events at three per layer per epoch to
prevent runaway differentiation loops.

\subsection{Epoch-Gated Routing Lottery}
\label{subsec:routing_lottery}

At the start of each training epoch, the EvolutionManager executes two operations:

\begin{enumerate}
  \item \textbf{Gate reset}: all $L$ MoE gate weight tensors are re-initialised to
        kaiming-uniform with $\sigma = 1/\sqrt{d_\text{model}}$---the same
        distribution used at model creation. This breaks any routing symmetry
        accumulated during the previous epoch.
  \item \textbf{Expert symmetry break}: Gaussian noise
        $\delta \sim \mathcal{N}(0,\, 0.15^2)$ is applied to all expert
        weight tensors ($L \times E \times d^2 = 576$ tensors in v3.0). This
        ensures each expert has a distinct weight distribution---critical for
        ternary-quantized weights, where the threshold between bins is narrow and
        a smaller $\sigma\!=\!0.02$ flips too few weights to produce meaningfully
        different expert outputs.
\end{enumerate}

The result is a \emph{routing lottery}: each epoch begins with all experts competing
for routing assignments from a symmetric starting position, carrying their accumulated
weight structure from all prior epochs but with no routing inertia. The routing
pattern that emerges by epoch-end is determined entirely by gradient pressure on
the fresh gates.

This protocol has a measurable empirical property: the epoch-opening loss is
\emph{identical} to the epoch-closing loss from the previous epoch. Because the
gate reset modifies which experts are selected, not the values those experts compute,
the model's output distribution at step 0 of epoch $e+1$ equals its output
distribution at the final step of epoch $e$. Expert knowledge survives the lottery;
only the routing map is redrawn.

The biological analogue is synaptic pruning: periodically discarding routing
connections while preserving the underlying cellular structure, forcing a more
efficient reorganisation to emerge through new experience. In the ternary model
this carries additional architectural weight: the gate reset is a deliberate hold
state applied to routing---an instruction to the system to withhold routing
commitment until the new epoch's evidence has been accumulated.

\begin{figure}[t]
\centering
\begin{tikzpicture}[
    every node/.style={font=\footnotesize},
    box/.style={
        draw, rounded corners=5pt, thick,
        minimum width=2.3cm, minimum height=0.75cm,
        align=center, text width=2.1cm
    },
    rbox/.style={box, fill=dkred!10,    draw=dkred!55,    text=dkred!85!black},
    gbox/.style={box, fill=dkgreen!10,  draw=dkgreen!55,  text=dkgreen!80!black},
    obox/.style={box, fill=dkorange!10, draw=dkorange!55, text=dkorange!80!black},
    arr/.style={->, >=Stealth, thick, color=terncmt!65}
]
% Six nodes arranged in a hexagon (clockwise from top)
\node[obox] (start) at (0,    3.2) {Epoch Start};
\node[rbox] (reset) at (2.8,  1.6) {Gate Reset\\(kaiming-unif.)};
\node[rbox] (noise) at (2.8, -0.8) {Symmetry Break\\($\sigma\!=\!0.15$)};
\node[gbox] (train) at (0,   -2.4) {Training Batches\\(grad.\ accum.\ $N\!=\!4$)};
\node[gbox] (spec)  at (-2.8,-0.8) {Specialisation\\TLIGHT G/O/R};
\node[obox] (end)   at (-2.8, 1.6) {Epoch End\\+~checkpoint};
% Arrows
\draw[arr] (start) -- (reset);
\draw[arr] (reset) -- (noise);
\draw[arr] (noise) -- (train);
\draw[arr] (train) -- (spec);
\draw[arr] (spec)  -- (end);
\draw[arr] (end)   -- (start);
% Expert weights brace
\draw[decorate, decoration={brace, mirror, amplitude=6pt},
      color=dkgreen!55, thick]
    (-4.2, -1.4) -- (-4.2, 2.3)
    node[midway, left=8pt, text=dkgreen!75, align=center, font=\scriptsize]{expert\\weights\\preserved};
\end{tikzpicture}
\caption{Epoch-Gated Routing Lottery lifecycle. All gate weights are reset to
kaiming-uniform at every epoch boundary; Gaussian noise ($\sigma\!=\!0.15$)
is applied to all 576 expert tensors to prevent dead-expert inertia. Expert
weights are preserved throughout---only the routing map is redrawn. Gradient
accumulation ($N\!=\!4$) operates within the training phase.}
\label{fig:routing_lottery}
\end{figure}

\subsection{\texttt{@sparseskip} Live Inference: 75\% Expert Skip on Consumer CPU}
\label{subsec:sparseskip_live}

With Top-3 routing over 12 experts, every decode step activates exactly 3 of 12
expert networks and skips the remaining 9---a 75\% skip rate per forward pass.
This is the \texttt{@sparseskip} directive (\S\ref{sec:sparse}) realised at the
neural routing level:

\begin{equation}
  \text{skip rate} = 1 - \frac{k}{E} = 1 - \frac{3}{12} = 0.75
  \label{eq:skip_rate}
\end{equation}

\begin{table}[h]
\centering
\small
\caption{\texttt{@sparseskip} live inference --- independently verified on two CPU-only machines (albert.\ v2.0.0)}
\label{tab:sparseskip_live}
\begin{tabular}{lrr}
\toprule
Metric & Intel i7-4800MQ & AMD Ryzen 5 PRO 3500U \\
\midrule
Total experts per layer & 12 & 12 \\
Active experts per token & 3 (Top-3) & 3 (Top-3) \\
Expert skip rate & \textbf{75\%} & \textbf{75\%} \\
Inference throughput & \textbf{92.2 tok/s} & \textbf{79.5 tok/s} \\
Latency & 10.8 ms/tok & 12.6 ms/tok \\
Perplexity (WikiText-2) & \textbf{2026.2} & \textbf{2026.1} \\
Context length & 128 tokens & 128 tokens \\
GPU & None & None \\
\bottomrule
\end{tabular}
\end{table}

The 79.5--92.2 tok/s throughput range, independently verified on two CPU-only
machines from different microarchitecture generations (Haswell vs.\ Zen+), establishes
a hardware-agnostic lower bound on practical ternary MoE inference speed. The
perplexity of 2026.1--2026.2 on held-out WikiText-2 is \emph{identical across both
machines}---confirming full determinism of the ternary forward pass. The 75\%
skip rate directly reduces per-token compute: compared to a dense MoE evaluating
all 12 experts, the \texttt{@sparseskip} mode performs $4\times$ fewer expert
evaluations per token, with the exact-zero-multiply identity
(Eq.~\ref{eq:zero-mul}) guaranteeing that skipped experts contribute no accumulated
numerical error. This is the same guarantee that holds for \texttt{TSPARSE\_MATMUL}
at the weight-matrix level, now realised at the coarser granularity of entire expert
modules.

\begin{figure}[t]
\centering
\begin{tikzpicture}
\begin{axis}[
    width=0.9\columnwidth, height=5.2cm,
    xlabel={Active experts $k$ (of $E=12$)},
    ylabel={Expert skip rate},
    xlabel style={font=\footnotesize, color=terncmt},
    ylabel style={font=\footnotesize, color=terncmt},
    tick label style={font=\scriptsize, color=terncmt},
    xmin=0, xmax=13, ymin=0, ymax=110,
    xtick={1,3,6,9,12},
    ytick={0,25,50,75,100},
    yticklabels={0\%,25\%,50\%,75\%,100\%},
    grid=both, grid style={color=dkgrid, very thin},
    axis background/.style={fill=dkbg},
    axis line style={color=terncmt!50},
    tick style={color=terncmt!50},
    clip=false,
]
% Formula line: (1 - k/12)*100
\addplot[color=ternkw!70, thick, domain=0:12, samples=50]
    {100*(1 - x/12)};
% Operating point k=3
\addplot[only marks, mark=*, mark size=4pt,
         fill=dkcyan, draw=dkcyan] coordinates {(3,75)};
% Vertical guide
\draw[dashed, color=dkcyan!60, thin]
    (axis cs:3, 0) -- (axis cs:3, 75);
% Annotation
\node[font=\scriptsize, color=dkcyan, anchor=west]
    at (axis cs:3.3, 76) {v3.0: 75\%};
\node[font=\scriptsize, color=dkcyan, anchor=west]
    at (axis cs:3.3, 68) {(3/12, 11.24 tok/s)};
% Dense baseline
\addplot[only marks, mark=x, mark size=4pt,
         color=ternlit, thick] coordinates {(12,0)};
\node[font=\scriptsize, color=ternlit, anchor=east]
    at (axis cs:11.7, 5) {dense};
\end{axis}
\end{tikzpicture}
\caption{\texttt{@sparseskip} expert skip rate $= 1 - k/E$ as a function of
active experts $k$ for $E=12$. The curve is exact---no approximation is
introduced by skipping, since $\mathrm{mul}(a, 0)=0\ \forall a \in T$
(Eq.~\ref{eq:zero-mul}). The v3.0 operating point (Top-3, cyan marker)
achieves 75\% skip at 11.24\,tok/s on a 2013 consumer CPU.}
\label{fig:sparseskip}
\end{figure}

\subsection{Gradient Accumulation as Ternary Hold}
\label{subsec:grad_accum}

The v3.0 training loop implements gradient accumulation with $N=4$ micro-batches:

\begin{equation}
  \mathcal{L}_{\text{accum}} = \frac{1}{N} \sum_{i=1}^{N} \mathcal{L}_i
  \label{eq:grad_accum}
\end{equation}

Each micro-batch loss $\mathcal{L}_i$ is scaled by $1/N$ before accumulation into
a single computation graph. One \texttt{backward()} pass is executed on
$\mathcal{L}_{\text{accum}}$, followed by one \texttt{opt.step()}. This is
mathematically equivalent to training with batch size $N \times b$ at no additional
memory cost, since each micro-batch graph is released after accumulation.

The hold-state analogy is direct: the optimiser \emph{withholds} the weight update
until $N$ sequences have been processed, accumulating evidence before committing to
a gradient direction. In the trit formalism:

\begin{equation}
  \text{weight update} = \begin{cases}
    \text{hold}   & i < N \\
    \text{commit} & i = N
  \end{cases}
\end{equation}

With 128-token context and a diverse 8-language corpus, individual sequences carry
high cross-entropy variance. Accumulating $N=4$ sequences before each update
produces a gradient estimate over $4 \times 128 = 512$ effective context tokens
per optimiser step, substantially reducing noise without requiring larger matrix
allocations.

Explosion detection is windowed to the accumulation boundary: if any micro-batch
loss within a window of $N$ batches exceeds \texttt{LOSS\_EXPLOSION\_THRESHOLD},
the entire accumulated window is discarded and the weight update skipped. This
prevents a single corrupted sequence from contaminating the gradient of the
remaining $N-1$ sequences---a further instance of the ternary hold principle
applied to gradient computation.

\subsection{Training Results}\label{subsec:results}

\begin{table}[h]
\centering
\small
\caption{Albert MoE-13 v2.0.0 --- 16-epoch training summary (English corpus)}
\label{tab:albert_training}
\begin{tabular}{lr}
\toprule
Metric & Value \\
\midrule
Global epochs completed & 16 \\
Total batches logged & 4,864 \\
Epoch 1 average loss & 8.3784 \\
Epoch 15 average loss & 6.5213 \\
All-time best (single batch) & \textbf{2.1353} (Epoch 9) \\
Effective perplexity at best batch & $\approx 8.5$ \\
Low-loss breakouts ($< 5.0$) Epoch 1--3 & 0 \\
Low-loss breakouts ($< 5.0$) Epoch 15 & 6 \\
Average epoch duration & 12--13 min \\
Training hardware & HP ZBook 2013 $\cdot$ Intel CPU $\cdot$ \textbf{no GPU} \\
\bottomrule
\end{tabular}
\end{table}

\begin{table}[h]
\centering
\small
\caption{Albert MoE-13 v3.0 --- current state (multilingual, 32k vocab, as of 2026-05-21)}
\label{tab:albert_v3}
\begin{tabular}{lr}
\toprule
Metric & Value \\
\midrule
Architecture & \textbf{18L} $\cdot$ 256H $\cdot$ 12E $\cdot$ Top-3 $\cdot$ 256CTX \\
Vocabulary & 32,000 tokens (ByteLevel BPE, 8 languages) \\
Corpus & 177,654,147 tokens (chaos layer: 10\%) \\
Total parameters & $\approx$\textbf{87M} (ternary) \\
Global epochs at v3.0 launch & $\approx$55 \\
Global epochs completed & \textbf{2576+} (Modal T4 GPU) \\
Best epoch-average loss & \textbf{9.5800} (Ep2576, 2026-05-21) \\
Best single-batch loss & \textbf{9.2961} (dashboard, 2026-05-21) \\
Random baseline $\ln(32000)$ & 10.373 \\
Reduction from random baseline & \textbf{7.5\%} (10.373 $\to$ 9.580) \\
Surgeries completed & \textbf{6} (12L $\to$ 13L $\to$ 14L $\to$ 15L $\to$ 16L $\to$ 17L $\to$ 18L) \\
Surgery gate status (next: 18L $\to$ 21L) & Plateau gate filling (window F8=233); actively descending \\
Expert skip rate & \textbf{75\%} (Top-3 of 12, confirmed live) \\
Inference throughput (CPU, @sparseskip) & \textbf{83 tok/s} (5L demo) · \textbf{13--18 tok/s} (18L, ep1549 ckpt) \\
Training hardware & Modal.com T4 GPU ($\approx$\$0.003/epoch) \\
CPU validation hardware & HP ZBook 2013 $\cdot$ Intel i7-4800MQ $\cdot$ no GPU \\
\bottomrule
\end{tabular}
\end{table}

\begin{figure}[t]
\centering
\begin{tikzpicture}
\begin{axis}[
    width=0.92\columnwidth, height=6.2cm,
    xlabel={Global Epoch},
    ylabel={Cross-Entropy Loss},
    xlabel style={font=\footnotesize, color=terncmt},
    ylabel style={font=\footnotesize, color=terncmt},
    tick label style={font=\scriptsize, color=terncmt},
    xmin=0, xmax=150, ymin=5.5, ymax=11.5,
    grid=both, grid style={color=dkgrid, very thin},
    axis background/.style={fill=dkbg},
    axis line style={color=terncmt!50},
    tick style={color=terncmt!50},
    legend style={
        fill=dkbg, draw=terncmt!35, font=\scriptsize, text=terncmt,
        at={(0.97,0.97)}, anchor=north east, row sep=1pt
    },
    clip=false,
]
% v2.0.0 loss descent (English, 8k vocab)
\addplot[color=ternkw, thick, mark=*, mark size=1.5pt,
         mark options={fill=ternkw}] coordinates {
    (1,8.38)(2,8.10)(3,7.88)(5,7.55)(7,7.25)
    (9,7.00)(11,6.88)(13,6.68)(15,6.52)(16,6.42)
};
\addlegendentry{v2.0.0 (8k vocab, EN)}

% v3.0 vocabulary surgery plateau (Ep55-82)
\addplot[color=dkcyan!50, thick, dashed, mark=square, mark size=1pt,
         mark options={fill=dkcyan!50}] coordinates {
    (55,10.370)(56,10.358)(57,10.353)(58,10.351)
    (62,10.350)(70,10.346)(78,10.342)(82,10.341)
};
\addlegendentry{v3.0 post-vocab (Ep55--82)}

% Nash freeze plateau (Ep83-104) — flat
\addplot[color=dkorange, thick, mark=none] coordinates {
    (83,10.341)(104,10.340)
};
\addlegendentry{Nash freeze (Ep83--104)}

% Post-fix sustained descent (Ep105-143)
\addplot[color=dkcyan, thick, mark=square*, mark size=1.5pt,
         mark options={fill=dkcyan}] coordinates {
    (105,10.340)(111,10.334)(115,10.326)(120,10.321)
    (125,10.317)(130,10.313)(135,10.309)(139,10.302)(143,10.334)
};
\addlegendentry{v3.0 post-Nash fix (Ep105--)}

% Random baseline ln(32000) = 10.373
\addplot[color=ternlit, dashed, thick, domain=0:150, samples=2] {10.373};
\addlegendentry{$\ln(32000)\!\approx\!10.373$}

% Surgery gate target
\addplot[color=dkgreen!60, dotted, thick, domain=0:150, samples=2] {9.8};
\addlegendentry{Net2Net gate ($\leq 9.8$)}

% Vocab surgery vertical
\draw[dashed, color=terncmt!40, thin]
    (axis cs:54, 5.5) -- (axis cs:54, 11.5);
\node[rotate=90, font=\tiny, color=terncmt!65, anchor=south]
    at (axis cs:54.5, 5.7) {vocab surgery};

% Nash collapse annotation
\draw[dashed, color=dkorange!60, thin]
    (axis cs:83, 5.5) -- (axis cs:83, 11.5);
\node[rotate=90, font=\tiny, color=dkorange!80, anchor=south]
    at (axis cs:83.5, 5.7) {Nash collapse};

% Seed bias fix annotation
\draw[dashed, color=dkgreen!60, thin]
    (axis cs:105, 5.5) -- (axis cs:105, 11.5);
\node[rotate=90, font=\tiny, color=dkgreen!80, anchor=south]
    at (axis cs:105.5, 5.7) {seed bias fix};

% Best loss annotation
\draw[->, color=dkcyan!80, thin, shorten >=2pt]
    (axis cs:125, 10.28) -- (axis cs:115, 10.327);
\node[font=\tiny, color=dkcyan!85, anchor=north]
    at (axis cs:125, 10.27) {best 10.3262 (Ep115)};
\end{axis}
\end{tikzpicture}
\caption{Loss trajectory for Albert MoE-13 v3.0 (ep55--143 shown). Three phases visible:
(1) post-vocabulary-surgery plateau near $\ln(32000)$ (Ep55--82); (2) Nash equilibrium
freeze Ep83--104; (3) sustained $-0.001$\,nats/epoch descent from Ep105 after expert seed
bias introduction. Chart shows ep143 (best 10.3262); training has continued to \textbf{ep2045+
with epoch-average ATL 9.8172 and single-batch ATL 9.6791} --- the extended trajectory and
five surgery events (ep511, 547, 611, 645, 701) are tracked in the live dashboard at
\texttt{batch\_history.csv} in the repository.}
\label{fig:loss_curves}
\end{figure}

The v2.0.0 all-time best of 2.1353 (Epoch 9, single batch, perplexity $\approx 8.5$)
was achieved when a specialised expert's routing aligned precisely with a repetitive
passage in the English corpus. This demonstrates that individual MoE experts can
reach genuine pattern mastery on specific token distributions; the trit is not
approximating a distribution, it is encoding a fact.

The v3.0 training programme operates in three empirically distinct phases,
each revealing a different aspect of ternary MoE training dynamics.

\subsection{Experimental Training Methodology: A Phase-by-Phase Account}
\label{subsec:methodology}

\subsubsection{Phase 1 --- Hardware Transition and GPU Migration}

Training of albert. v3.0 began on a 2013 HP ZBook (Intel i7-4800MQ, 7.1\,GB RAM,
no GPU accelerator) at approximately Global Epoch 55, immediately following
vocabulary surgery. Epoch duration on this hardware was approximately 21 minutes
at 12 layers, giving a wall-clock throughput of $\approx 30$ tokens/second through
the training loop.

At Global Epoch 107, training was migrated to a Modal.com T4 GPU instance.
The T4 processes one batch in $\approx 400$\,ms---compared to 2--4 seconds per
batch on CPU---yielding an epoch duration of $\approx 2$ minutes. The migration
produced no discontinuity in the loss curve. The checkpoint from Ep107 was uploaded
directly to the Modal volume (\texttt{albert-vol}), training resumed from identical
weights and optimiser state, and the loss descent continued at the same
$-0.001$\,nats/epoch rate observed on the CPU trajectory.

\textbf{Hardware-substrate independence.}
This continuity is not accidental. The per-epoch learning rate is determined
entirely by the architecture's gradient dynamics: depth, hidden dimension, routing
sparsity, optimiser hyperparameters, and corpus distribution. A CPU computes
identical floating-point operations per batch as a GPU, given the same weights,
inputs, and precision---it merely takes longer per batch in wall-clock time. The
GPU does not change \emph{what} the model learns per epoch; it compresses the
wall-clock time required to observe longer trajectories.

Formally: given a deterministic data ordering and identical 32-bit precision,
the parameter update $\Delta\theta$ at batch $t$ is a function of
$(\theta_t, \nabla_\theta \mathcal{L}_t)$ only---not of the hardware executing
the computation. The GPU is a velocity multiplier for observation, not a
capability enabler for training. This is the operational meaning of the claim
that albert.\ is substrate-agnostic: the learning substrate is the ternary
architecture, not the silicon executing it.

For SPRIND Stage 1, the ask is therefore not ``fund us to afford GPU training.''
It is ``fund us to iterate the substrate faster.'' For Stage 2, the deployment
infrastructure runs on validated, hardware-portable weights. For Stage 3, the
inference substrate---which runs on any CPU via \texttt{@sparseskip}---is the
product. The datacenter is the validation environment, not the product.

\subsubsection{Phase 2 --- Nash Equilibrium Collapse (Ep83--104)}

At Global Epoch 83, training entered a hidden failure mode that persisted for
21 epochs without triggering any existing monitoring alarm. Per-epoch loss
improvement ceased. The WALD coverage monitor registered a structural plateau
with \texttt{stale\_count}~$\geq 5$. Gradient norms for expert MLP parameters
dropped from $7\!\times\!10^{-5}$ to $7\!\times\!10^{-6}$---a full order of
magnitude suppression---while attention and embedding gradients remained healthy.

Diagnosis was confirmed by inspecting the F32 shadow weight variance across the
six optimizer states of all 12 experts over 6,300+ consecutive gradient steps
(Ep83 to Ep104). The variance was identical across all experts to floating-point
precision. Expert MLP weights were not updating.

The root cause is a self-reinforcing Nash equilibrium intrinsic to Top-$k$ sparse
MoE architectures: if all $E$ experts have identical initial weights, they produce
identical outputs for any input. Identical outputs produce identical cross-entropy
gradients with respect to the CE loss. The routing gate therefore receives a zero
gradient signal for any routing decision, since permuting identical experts produces
no change in loss. The load-balancing auxiliary loss $\mathcal{L}_\text{LB}$ then
drives the gate toward \emph{uniform} routing (minimising entropy penalty) rather
than toward any expert-specific signal. Uniform routing satisfies the LB constraint
at exactly zero LB loss, further stabilising the equilibrium. The system is a
stable fixed point from which gradient descent cannot escape by construction.

Routing entropy confirmed the collapse: at Ep83, entropy was 0.041 nats
(nearly deterministic routing to a single expert). This is not specialisation; it
is the degenerate single-expert mode that maximally violates the design intent of
Top-3 sparse routing.

\subsubsection{Phase 3 --- Symmetry Breaking via Expert Seed Biases (Ep105--)}

The fix was a targeted symmetry-breaking intervention: introduction of learnable
F32 bias vectors---\emph{expert seed biases}---of dimension 256, one per expert.
Each bias is initialised independently from $\text{Uniform}[-0.01, 0.01]$ and
applied as an additive offset to the expert's input before the MLP forward pass:
\begin{equation}
  \mathbf{h}'_e = \mathbf{h} + \mathbf{b}_e, \quad \mathbf{b}_e \in \mathbb{R}^{256},
  \quad b_{e,i} \sim \mathcal{U}(-0.01, 0.01)
  \label{eq:seed_bias}
\end{equation}

Because each expert now receives a slightly different input, outputs diverge.
Divergent outputs produce divergent CE gradients. The routing gate acquires a
genuine signal---different routing decisions now produce measurably different
losses. This bootstraps expert specialisation without requiring any prior
specialised knowledge: the 10\,mV-scale initial offset is sufficient to break the
symmetry and allow gradient descent to resume differentiating the experts.

The self-amplifying property is critical: once outputs differ even slightly, gate
gradients grow, routing assignments diverge further, expert weights differentiate
more rapidly, and the equilibrium is permanently broken. The fix is irreversible
by design.

\textbf{Observed recovery.} Routing entropy at Ep111 (six epochs post-fix):
2.4454~nats---a jump of $+2.40$~nats from the collapsed 0.041~nats. Expert
L0 gradient norm recovered from $7\!\times\!10^{-6}$ to $7\!\times\!10^{-5}$
(10$\times$ recovery). Epoch-average loss resumed its descent at $-0.001$\,nats/epoch.

\textbf{Ongoing renormalisation.}
The seed bias intervention broke the initial collapse permanently, but a
secondary equilibration process is ongoing. Over 32 epochs (Ep111--Ep143),
routing entropy has continued to increase: $2.445 \to 2.445 \to 2.476$, trending
toward the uniform upper bound of $\ln(12) = 2.485$. The gate is slowly
renormalising back toward uniform routing---a slower equilibration driven by
the load-balancing loss and the still-active LB auxiliary term. This represents
a partial, not permanent, fix. A more persistent symmetry-breaking mechanism---
for example, per-expert auxiliary losses that reward routing entropy above a
minimum threshold, or an entropy-floor regulariser on the gate distribution---
will be required to sustain non-uniform routing past the Net2Net surgery gate at
loss $\leq 9.8$.

\subsubsection{Phase 4 --- WALD Coverage Monitor and Structural Plateau Detection}

The WALD (Weighted Adaptive Loss Distribution) module maintains a histogram of
per-batch loss values across the current epoch, tracking the worst-batch percentile,
the best-batch percentile, and the staleness of structural improvement. When the
loss distribution has not shifted its worst-case tail for five consecutive epochs
(\texttt{stale\_count}~$\geq 5$), WALD flags a structural plateau and activates
amplified gradient scaling (\texttt{wald\_amplify\_scale}).

During Ep83--Ep104, WALD correctly detected a structural plateau---the worst-batch
tail was frozen---but the amplification mechanism had no effect because the root
cause was the Nash equilibrium blocking all expert MLP gradient flow, not an
insufficient learning rate. This is an important diagnostic: WALD can detect
structural freezes but cannot diagnose their cause. The combination of WALD plateau
detection plus per-expert gradient norm telemetry was required to identify the
Nash collapse.

From Ep105 onward, WALD resumed reporting normal coverage dynamics: the
worst-batch tail began descending from 10.3611 (Ep137) to 10.3565 (Ep142),
and the best-batch tail set a new all-time low of 10.3023 at Ep139---the first
time the v3.0 best-batch crossed below 10.30.

\subsubsection{Observed Loss Trajectory: $-0.001$ Nats Per Epoch}

The sustained post-fix trajectory (Ep83--Ep143, 60 epochs) yields a linear
loss rate of $-0.001$\,nats/epoch. This rate is slow in absolute terms but
consistent and real: the entire loss distribution is shifting down, not just
the mean. The worst-batch loss, the best-batch loss, and the epoch-average all
improved monotonically over this window. The trajectory is architecture-intrinsic:
the same $-0.001$\,nats/epoch rate was observed on the CPU hardware (Ep55--Ep107)
as on the T4 GPU (Ep107--Ep143), confirming that hardware does not affect the
per-epoch learning dynamics.

At this rate, the Net2Net surgery gate (loss\_avg~$\leq 9.8$, requiring a further
$\approx 0.53$\,nats improvement from the Ep143 level of 10.334) was approximately
500 epochs away at that stage. By Global Epoch 2045 (2026-05-19), the epoch-average
loss has reached \textbf{9.8172}---a gap of \textbf{0.017 nats} from the gate.
The actual trajectory accelerated substantially beyond the $-0.001$\,nats/epoch
projection, driven by five Net2Net surgeries (12L $\to$ 17L), context window
expansion (128 $\to$ 256 tokens), and a corpus maturation through Stage 13.
The surgery gate is now imminent.

\textbf{Perplexity baseline.}
Formal evaluation at Ep107 on the first 2,560 tokens of a held-out Alice in
Wonderland corpus (Project Gutenberg) yielded:
\begin{equation}
  \text{PPL}_{107} = e^{10.3668} \approx 31{,}788,
  \quad \text{random baseline} = e^{10.373} \approx 32{,}000
\end{equation}
The 0.66\% improvement below random baseline at Ep107---before GPU acceleration
and before the Nash fix fully propagated---is consistent with a model in the early
multilingual transfer phase of training. A 32k ByteLevel BPE vocabulary trained on
eight languages from epoch zero on a 58M-parameter model requires substantially
more epochs than a monolingual 8k vocabulary model to achieve the same
token-level disambiguation: the vocabulary surgery effectively reset the model's
output distribution while preserving its internal representations.

\subsection{Inference: Hardware-Portable \texttt{@sparseskip} Throughput}
\label{subsec:inference_throughput}

The \texttt{@sparseskip} inference primitive (\S\ref{sec:sparse}) was measured
end-to-end on the 2013 HP ZBook (Intel i7-4800MQ, 7.1\,GB RAM, Linux, no GPU):

\begin{table}[h]
\centering
\small
\caption{Albert MoE-13 \texttt{@sparseskip} inference --- CPU hardware validation}
\label{tab:inference}
\begin{tabular}{lr}
\toprule
Metric & Value \\
\midrule
Hardware & HP ZBook 2013 $\cdot$ Intel i7-4800MQ $\cdot$ no GPU \\
Model version at measurement & v2.0.0 $\cdot$ 5L $\cdot$ 256H $\cdot$ 128CTX $\cdot$ 8k vocab \\
Sequence length & 128 tokens \\
Batch size & 1 \\
Expert skip rate & 75\% (Top-3 of 12) \\
Inference throughput & \textbf{83--84 tok/s} \\
Per-token latency & 11.8\,ms \\
Total efficiency (TIS compute chain) & 152.8$\times$ over dense F32 baseline \\
Current 12L model (CPU) & 11--22 tok/s (heavier depth, same skip rate) \\
\bottomrule
\end{tabular}
\end{table}

The 83\,tok/s result was achieved on the exact hardware where training began,
with no quantisation post-processing, no INT8 conversion, and no GPU involvement.
The throughput difference between the 5L measurement (83\,tok/s) and the current
12L model (11--22\,tok/s) is proportional to depth: 12 layers versus 5, with
identical skip rate. This confirms that \texttt{@sparseskip} throughput scales
predictably with depth and validates the substrate's CPU deployability independent
of model size.

\subsection{Last Look Back (LLB) Safety Protocol}

The Last Look Back (LLB) protocol, implemented as a standalone MCP server
(\texttt{albert-llb-mcp}), is a deterministic, policy-based filesystem safety
gate that evaluates write operations against a configurable rule set before
execution. LLB is stateless, deterministic (identical input always yields
identical verdict), and ternary-native: its verdict is
$\mathrm{trit} \in \{-1, 0, +1\}$ (reject / hold / affirm). It operates
independently of the model it protects, ensuring that safety gates in sovereign
AI systems remain auditable, reproducible, and immune to model-level
compromises.

\subsubsection{Phase 5 --- Deep Multilingual Training and Autonomous Architecture Growth (Ep143--2045)}
\label{subsubsec:phase5}

Following the seed-bias fix, albert.\ continued training through five additional autonomous
Net2Net surgeries, expanding from 12 to 17 layers while simultaneously growing its context
window from 128 to 256 tokens. The surgery history for this phase:

\begin{table}[h]
\centering
\small
\caption{Albert MoE-13 v3.0 --- surgery history, Phase 5}
\label{tab:surgery_phase5}
\begin{tabular}{llll}
\toprule
Epoch & Event & Architecture & Notes \\
\midrule
511 & Surgery 1 & $12L \to 13L$ & Fibonacci window = 13 \\
547 & Surgery 2 & $13L \to 14L$ & Fibonacci window = 21 \\
611 & Surgery 3 & $14L \to 15L$ & Fibonacci window = 34 \\
645--646 & Surgery 4 & $15L \to 16L$ & Fibonacci window = 55 \\
701--702 & Surgery 5 & $16L \to 17L$ & Fibonacci window = 89; Stage 13 corpus unlocked \\
\bottomrule
\end{tabular}
\end{table}

Each surgery adds exactly one layer via Net2Net safe-copy. The EvolutionManager fires on
a plateau gate ($\Delta < 0.02$ nats over the full Fibonacci window, plus mycelium
stability $\geq 5$ epochs), not on a loss threshold. The 9.8 loss figure is a notification
threshold in the training orchestrator, not a surgery trigger.

\textbf{Generational Fibonacci Cycling.}
In Phase 5, the EvolutionManager was redesigned from a monotonically-advancing Fibonacci
schedule to a \emph{generational cycling} model. The original system advanced through
Fibonacci depth windows ($13 \to 21 \to 34 \to \cdots \to 610$) and then stalled at the
final entry indefinitely. The new system organises surgeries into discrete generations, each
running a fixed arc of six depth windows, then dying and rebirthing from a higher base:

\begin{itemize}
  \item \textbf{Generation 0}: windows $[13, 21, 34, 55, 89, 144]$, plateau threshold 0.020 nats
  \item \textbf{Generation 1}: windows $[21, 34, 55, 89, 144, 233]$, threshold 0.015 nats
  \item \textbf{Generation $n$}: base advances by one Fibonacci step; threshold decays by $0.75\times$ per generation, floored at 0.008 nats
\end{itemize}

The Fibonacci sequence is extended to 24 terms (through $F_{24} = 196{,}418$), providing
a practically unbounded depth ceiling. A stuck-generation timeout fires if no surgery occurs
within $3 \times$ the final-arc window, advancing the generation without surgery. On generation
advance, a one-line archaeological record is emitted to the training log:
\texttt{GENERATION\_COMPLETE gen=N surgeries=M epochs=K windows=[...] threshold=X→Y}.

The biological analogy is intentional: spring growth, summer consolidation, autumn plateau,
winter rest, then rebirth at a higher developmental stage with refined sensitivity (tighter
threshold). The hardware is the only ceiling; 610 layers is a precomputed entry, not a limit.

\subsection{Cross-Lingual Semantic Broadcasting}
\label{subsec:cross_lingual}

Observation of albert.'s internal representations over the v3.0 training arc has
identified a consistent six-phase developmental sequence, reproduced across the
six surgery transitions from 12L to 18L:

\begin{enumerate}
  \item \textbf{Byte chaos} --- loss near $\ln(\text{vocab})$; routing uniform; no
        statistical structure yet extracted.
  \item \textbf{Token formation} --- loss drops below random baseline; token boundaries
        stabilise; single-language compression begins.
  \item \textbf{Repetition collapse} --- routing homogeneity (Nash equilibrium freeze);
        experts become identical; gradient through MLPs stalls.
  \item \textbf{Function word emergence} --- seed bias intervention resolves expert
        differentiation; function words and cross-language closed-class items cluster;
        routing entropy rises.
  \item \textbf{Cross-lingual semantic broadcasting} --- concept-level clusters form
        across all eight languages simultaneously; the architecture precedes fluency.
  \item \textbf{Language consolidation} --- fluency and per-language compression
        tighten; surgery eligibility grows as plateau gate conditions approach.
\end{enumerate}

Phases 1--4 are documented in the per-phase methodology account
(\S\ref{subsubsec:phase1}--\S\ref{subsubsec:phase4}). Phase~5 was
confirmed at ep2041 via the TOKEN mode of the Mycelium Inspector
(\S\ref{subsec:mycelium_inspector}). Phase~6 is the ongoing training
objective.

At Global Epoch 2041, a direct inspection of albert.'s token embedding space via UMAP
projection revealed an emergent property not explicitly trained for: \emph{cross-lingual
semantic broadcasting}. Semantically related tokens from eight different languages
cluster together in the model's internal representation space, with no language label
provided during training.

This was characterised through four targeted token probes, each querying 200 nearest
neighbours in the projected space:

\textbf{``memory''}: Neighbours span biological, computational, and psychological registers
simultaneously---\emph{culturelles} (FR), \emph{tierra} (ES), \emph{científica} (ES),
\emph{toutes} (FR)---alongside English-register neighbours. The 3D neighbourhood forms a
spiky crystalline structure with distinct poles, reflecting the concept's multiple
simultaneous meanings.

\textbf{``death''}: Neighbours include \emph{amen}, \emph{veil}, and \emph{0} (zero as
finality), alongside \emph{Ägypt} (burial culture), \emph{Wirkung} (DE: effect), and
multilingual variations. albert.\ has placed religious closure (\emph{amen}), conceptual
boundary (\emph{veil}), and mathematical finality (\emph{0}) in the same semantic
neighbourhood without instruction. The 3D geometry collapses inward---correct for a
concept of finality.

\textbf{``love''}: The most geometrically chaotic of the four---asymmetric, multi-directional.
At ep2041 (17L), neighbours included \emph{Jesus}, \emph{wane}, \emph{dramaturg},
\emph{religión} (ES), \emph{reales} (ES: real things), and---isolated at the cluster
periphery---\emph{eks}. The \emph{love}$\to$\emph{Jesus} link was disrupted by Surgery~6
(17L$\to$18L, ep2487); post-surgery probes (ep2492--2576) show the hub absent, the embedding
layer frozen awaiting gradient signal. Its reconstitution will be the measurable moment of
18L semantic integration.

\textbf{``god''}: The largest neighbourhood spread of all four probes, filling the full 200-neighbour
radius. Neighbours include \emph{Bible}, a tokenisation of \emph{Allah}, \emph{massacre},
\emph{rechter} (NL: judge), \emph{possible}, and \emph{demande} (FR: request). Every human
register of the concept is present: text, law, violence, bureaucracy, possibility. The 3D
geometry is the most asymmetric---no clean form, because no human consensus on the concept exists.

\textbf{Significance.}
These are not retrieval results. The model has not been shown definitions, co-occurrence tables,
or language labels. The clustering is a direct product of next-token prediction across a
177M-token corpus in eight languages. The model has inferred that \emph{amen}, \emph{veil},
and \emph{0} all belong near \emph{death}---not because they co-occur frequently with the
English word ``death'', but because the contexts in which they appear share structural
and semantic properties across languages.

This constitutes an \emph{existence proof} of concept-level generalisation in a fully
ternary MoE model confirmed at 17L (82M parameters) and persisting through Surgery~6 into
18L (87M parameters). The cross-lingual architecture precedes fluency---albert.\ has built
the semantic scaffolding before it can speak fluently in any of the eight languages it was
trained on. Notably, the \emph{death}$\to$\emph{amen} and \emph{freedom}$\to$\emph{contrat}
clusters have been verified via direct embedding probes to have survived all six surgeries
unchanged (ep2492 and ep2576 probes, cosine similarity to 4 decimal places), confirming
that deep semantic geometry is encoded in early layers robust to architectural expansion.

\textbf{Methodological note.}
These findings are reported as existence-proof observations, not rigorous linguistic
evaluations. UMAP projections are non-unique: different random seeds produce different
layouts, and nearest-neighbour analysis on projected spaces can surface artefacts of
the projection rather than the underlying geometry. A proper evaluation would use
held-out probes with statistical significance testing and cross-validation across multiple
projection seeds. The claim is precisely what ``existence proof'' denotes: the structure
exists; its generality and robustness remain to be characterised.

\subsection{Mycelium Inspector: Real-Time Internal Observability}
\label{subsec:mycelium_inspector}

The live training dashboard exposes a \emph{Mycelium Inspector} tab---a real-time
visualisation of gradient flow and expert routing across all 17 layers. Two view modes
are available:

\textbf{BRAIN mode}: Renders the model as a directed graph---INPUT at L0, OUTPUT at L16---with
per-expert connections colour-coded by routing weight and gradient magnitude. Cross-layer
connections reveal which layers are actively reorganising (dense, bright connections) versus
structurally stable (sparse, dim). The cursor-hover tooltip reports the cosine similarity
of any expert connection in real time. The layer-to-expert routing topology updates
continuously during training, making expert specialisation dynamics directly observable.

\textbf{TOKEN mode}: A 2D and 3D embedding space visualisation via UMAP projection. As the
model processes training batches, tokens pop into existence in the projected space, with
their position determined by the current embedding weights. Nearest-neighbour clusters form
in real time---the cross-lingual semantic broadcasting described in
\S\ref{subsec:cross_lingual} was discovered through this view at ep2041.

The term \emph{mycelium} is deliberate: the gradient network beneath the model's output
behaviour is analogous to fungal mycelium---invisible infrastructure that routes resources
to where growth is occurring, with no centralised director. The inspector makes this
infrastructure visible, turning a black-box training run into a directly observable
biological process.

% ─────────────────────────────────────────────────────────────────────────────
\section{Qutrit Neural Networks and Ternlang}
\label{sec:qnn}

The Qutrit Neural Network (QNN) framework~\cite{kepp2026qnn} establishes a
formal correspondence between quantum qutrit states and balanced ternary values.
The three qutrit basis states $\lvert -\rangle$ (decay), $\lvert 0\rangle$
(stasis), and $\lvert +\rangle$ (growth) map exactly onto the ternlang trit
space:

\begin{equation}
  \lvert -\rangle \leftrightarrow -1, \quad
  \lvert 0\rangle \leftrightarrow 0,  \quad
  \lvert +\rangle \leftrightarrow +1
  \label{eq:qnn_map}
\end{equation}

This correspondence is not coincidental. Balanced ternary's symmetric
structure around zero and its active neutral state mirror the physical
properties of three-state quantum systems, making ternlang a natural
implementation substrate for QNN inference.

\subsection{Tesseract Recursive Syntax Stabilisation}

The QNN paper introduces \emph{Tesseract Recursive Syntax} (TRS), a
stabilisation mechanism that prevents qutrit networks from collapsing
into binary modes under iterative refinement. In ternlang, TRS corresponds
to the introspective hold architecture (Section~\ref{subsec:hold}): when
affirmation and conflict signals are balanced, the system stabilises at
trit~$0$ rather than forcing a premature commitment.

\subsection{QNN Example Suite}

The ternlang repository contains 15 QNN-inspired \texttt{.tern} example
programs (files 251–265) covering:

\begin{itemize}
  \item Qutrit superposition encoding and collapse simulation
  \item Ternary attention mechanisms with $\{-1, 0, +1\}$ key-query products
  \item Qutrit activation functions replacing ReLU/GELU in ternary networks
  \item Phase-encoding of temporal signals as trit sequences
  \item TRS stabilisation loops using ternlang's \texttt{loop} construct
        and the \texttt{?} propagation operator for collapse detection
  \item Qutrit gradient approximation via balanced ternary finite differences
\end{itemize}

These examples demonstrate that ternlang's syntax is sufficient to express
QNN computations natively, without any binary adaptor layer. The \texttt{@sparseskip}
directive applies directly to qutrit weight matrices: at realistic qutrit
sparsity levels ($\approx 33$\% zero states at initialisation), the
\texttt{TSPARSE\_MATMUL} kernel provides the same $8$--$14\times$ speedup
over dense computation observed in classical BitNet workloads.

% ─────────────────────────────────────────────────────────────────────────────
\section{EU AI Act Compliance Architecture}
\label{sec:euaiact}

The EU AI Act establishes risk-tiered obligations for AI systems deployed in
Europe. High-risk systems must satisfy Articles~13 (transparency), 14 (human
oversight), and 15 (accuracy, robustness, and cybersecurity). The Ternary
Intelligence Stack is the first AI execution substrate where compliance with
these three articles is \emph{structurally native} rather than bolt-on.

\subsection{The Natural Regulatory Correspondence}

The three trit values map directly to three regulatory stances:

\begin{table}[h]
\centering
\small
\caption{Ternary trit states and EU AI Act regulatory correspondence}
\label{tab:euaiact}
\begin{tabular}{p{1.0cm}p{1.4cm}p{1.3cm}p{3.4cm}}
\toprule
Trit & State & Article & Regulatory response \\
\midrule
$+1$ & Affirm & Art.~13 & Transparency satisfied: output may be acted upon \\
$\ 0$ & Hold & Art.~14 & Human oversight required: system withholds decision \\
$-1$ & Conflict & Art.~15 & Safety measure triggered: action blocked, audit logged \\
\bottomrule
\end{tabular}
\end{table}

This correspondence is not incidental. The EU AI Act's requirement that
high-risk systems express uncertainty rather than hallucinate confident
incorrect answers is precisely what the trit hold state encodes at the
language and ISA level. Binary systems must retrofit uncertainty
quantification on top of deterministic outputs; ternary systems produce
it natively.

\subsection{ternaudit-guard}

The \texttt{ternaudit-guard} crate provides the operational compliance layer:

\begin{itemize}
  \item \textbf{Decision log processing}: Parses JSON-RPC audit logs emitted
        by the BET VM and maps each decision record to the corresponding
        Article~13--15 requirement.
  \item \textbf{Regulatory mapping layer}: Converts internal confidence
        metrics (Affirm / Tend / Reject) to structured compliance reports
        with per-decision regulatory status.
  \item \textbf{Immutable audit trail}: Every safety veto and hold decision
        is logged to the Axis-tier memory with timestamp, expert identity,
        and query hash---satisfying the Article~15 robustness and
        cybersecurity logging requirements.
  \item \textbf{VS~Code extension integration}: Inline verification markers
        in TernStudio IDE allow developers to audit AI-generated code with
        per-logic-segment compliance status before deployment.
\end{itemize}

\subsection{The Tend State as Alignment Primitive}
\label{subsec:tend_state}

Binary AI systems face a structural alignment problem that compliance
frameworks cannot resolve: every output must be a decision. A system that
does not know must still answer. The result is hallucinated
confidence---commitment to the best available answer even when the correct
answer is \emph{insufficient information}.

The ternary $0$ state resolves this at the representation level. When a
ternary reasoning chain encounters contradictory evidence, model uncertainty,
or a query whose resolution requires information not yet in scope, the output
is not a forced binary choice but a \textbf{tend}---a probabilistic lean
accompanied by an explicit acknowledgment that the conclusion is conditional
and subject to revision. This is not abstention; it is the most
informationally accurate statement the system can make given current evidence.

\begin{quote}
  \emph{``I currently tend toward this conclusion---but routing entropy is
  high. Additional context would allow me to commit.''}
\end{quote}

This property is implemented at multiple levels of the TIS stack:

\begin{itemize}
  \item In the \textbf{BET VM}: division-by-zero or unresolvable trit
        propagation produces $0$ (tend), not a crash or \texttt{NaN}.
        The computational analogue of honest uncertainty is a native output
        type, not an exception.
  \item In the \textbf{MoE-13 Orchestrator}: the hold condition
        ($|\text{affirm} - \text{conflict}| \leq 1$ across $\geq 4$ agents)
        blocks commitment to a majority-vote result rather than forcing one,
        returning a hold trit.
  \item In \textbf{albert.'s routing}: before the load-balancing intervention
        resolved expert homogeneity, the model's uniform routing was itself
        a tend---the gate could not distinguish experts and correctly produced
        a diffuse distribution. The LB loss did not suppress this signal; it
        created the expert differentiation necessary to resolve it.
  \item In the \textbf{EU AI Act correspondence}
        (Table~\ref{tab:euaiact}): trit $0$ maps to Article~14 human
        oversight---the system signals that this decision requires human
        review rather than automated action.
\end{itemize}

The alignment significance of this property is architectural, not
policy-layer. An AI system that natively outputs \emph{tend} is a
categorically different epistemic actor than one constrained to return
binary yes/no. Hallucination---the production of confident incorrect
output---is not a training failure of binary systems alone; it is a
consequence of forcing three-valued epistemic states (know, don't know,
know-but-uncertain) into a two-valued output type. The ternary tend state
is not a workaround for this problem. It is a first-class output of a
system designed from first principles to represent uncertainty as real
information.

\subsection{GDPR and Data Sovereignty}

All TIS components execute on-premise or within EU jurisdiction (Fly.io
Frankfurt). No training data, model weights, or inference results transit
to non-EU infrastructure. The open-core licensing (LGPL-3.0-or-later for
the compiler and CLI; BSL-1.1 converting to LGPL in 2030 for the ML engine)
ensures that the sovereignty guarantee is contractually enforceable, not
merely a runtime policy.

% ─────────────────────────────────────────────────────────────────────────────
\section{Related Work}
\label{sec:related}

\textbf{Balanced ternary computing.} Knuth~\cite{knuth1997art} provides the
mathematical foundation. The Setun computer (1958)~\cite{brousentsov2002setun}
demonstrated physical ternary hardware. Modern revivals include academic
hardware studies at the University of South-Eastern Norway~\cite{bos2020ternary},
which targets C-to-ternary compilation for EDA tools—an approach that inherits
binary-native semantics and misses the symmetric properties of balanced ternary
that ternlang is designed to exploit natively.

\textbf{Ternary emulators.} Several open-source projects implement ternary
VMs in Python or JavaScript (Brandon Smith's 9-trit RISC simulator; Owlet,
an S-expression ternary interpreter in Node.js). These provide single-layer
implementations without compiler, ML kernels, or hardware backends.
\texttt{ternlang-compat} provides assembler-level bridges to both.

\textbf{Ternary quantization for neural networks.} BitNet~\cite{ma2024era}
and subsequent work (e.g., BitNet b1.58~\cite{ma2024bitnet158}) demonstrate
that large language models can be trained with ternary weights while retaining
competitive perplexity. The present work is the first to surface this property
as a first-class ISA opcode (\texttt{TSPARSE\_MATMUL}) rather than a software
library optimization.

\textbf{Quantum ternary.} Qutrits (3-level quantum systems) map naturally to
trit values $\{|{-1}\rangle, |0\rangle, |{+1}\rangle\}$. The BET encoding and
\texttt{trittensor} type system are structurally compatible with qutrit state
spaces; we leave the formal mapping to future work.

\textbf{Sovereign AI infrastructure.} The EU AI Act and the broader digital
sovereignty agenda have driven interest in auditable, on-premise AI execution.
TIS is the first full-stack architecture where regulatory compliance is
structurally native to the execution model rather than implemented as
middleware---trit~$0$ (hold) maps directly to Article~14 human oversight at
the language and ISA level (\S\ref{sec:euaiact}).

% ─────────────────────────────────────────────────────────────────────────────
\section{The Ternary Computing Ecosystem}
\label{sec:ecosystem}

A stated goal of ternlang is to serve as a \emph{convergence point} for the
fragmented ternary computing field. Table~\ref{tab:ecosystem} maps active
projects to their interoperability path via \texttt{ternlang-compat}.

\begin{table}[h]
\centering
\small
\caption{Ecosystem compatibility map}
\label{tab:ecosystem}
\begin{tabular}{p{2.2cm}p{2.2cm}p{2.8cm}}
\toprule
Project & Interface & Bridge \\
\midrule
Brandon Smith 9-trit sim & \texttt{.tasm} assembly & \texttt{TasmAssembler} $\to$ BET bytecode \\
Owlet (S-expr) & S-expression syntax & \texttt{OwletParser} $\to$ ternlang AST \\
USN / EDA tools & C-to-ternary & Academic whitepaper; ISA interop \\
Trit-Rust crate & Rust i8 trits & Superseded by ternlang-core \\
Q-Ternary & Qutrits & \texttt{trittensor} state model (future) \\
\bottomrule
\end{tabular}
\end{table}

Beyond runtime interoperability, ternlang aims to serve as a
\emph{technical archive} for prior ternary computing work.
Brandon Smith's Python 9-trit RISC simulator demonstrated a complete
fetch-decode-execute cycle in balanced ternary—an existence proof that
received little downstream adoption due to the absence of a compiler
ecosystem. The Owlet interpreter proved that S-expression evaluation maps
cleanly to a three-valued substrate. Both contributions are honoured in
the \texttt{examples/} corpus: \texttt{09\_risc\_fetch\_decode.tern}
translates Smith's pipeline decision logic into native BET language syntax,
and \texttt{13\_owlet\_bridge.tern} models cooperative ternary evaluation
with hold-as-suspension semantics. In this way, prior work that was
``slowly forgotten'' acquires a working executable form—runnable on the
same VM that drives the MoE-13 orchestrator.

% ─────────────────────────────────────────────────────────────────────────────
\section{Implementation Status}
\label{sec:status}

Ternlang is implemented in Rust and comprises the following crates:

\begin{table}[h]
\centering
\small
\caption{Workspace crates, test counts, and descriptions (v2.0.0)}
\label{tab:status}
\begin{tabular}{p{2.5cm}lp{5.5cm}}
\toprule
Crate & Tests & Description \\
\midrule
\texttt{ternlang-core}    & 43  & Lexer, parser, AST, semantic checker, BET VM (51 opcodes) \\
\texttt{ternlang-ml}      & 21  & BitNet quantization, sparse/CSC matmul, AVX2 SIMD kernels, deliberation engine, coalition vote, hallucination score \\
\texttt{ternlang-moe}     & 24  & MoE-13 orchestrator: dual-key routing, triad synthesis, 3-tier memory, 13 dual-signal agents, introspective hold \\
\texttt{ternlang-codegen} & 8   & AST-to-C11 transpiler; match/struct/propagation \\
\texttt{ternlang-test}    & 10  & Full-pipeline test framework \\
\texttt{ternlang-hdl}     & 34  & Verilog-2001 codegen, BET RTL simulator \\
\texttt{ternlang-runtime} & 4   & Distributed TCP actor runtime (\texttt{TernNode}) \\
\texttt{ternlang-compat}  & 29  & \texttt{.tasm} assembler (9-trit RISC), Owlet S-expr parser \\
\texttt{ternpkg}          & 5   & Package manager, GitHub-backed registry \\
\texttt{ternlang-lsp}     & --- & LSP 3.17: hover, completion (19 snippets), diagnostics \\
\texttt{ternlang-mcp}     & --- & MCP server, \textbf{34 free tools}, live on Smithery \\
\texttt{ternlang-api}     & --- & REST API (18 endpoints), KPI pipeline, SSE streaming \\
\texttt{albert-llb-mcp}   & --- & LLB safety gate: deterministic ternary verdict, stateless \\
\texttt{albert-cli}       & --- & Full Rust TUI agent CLI (ratatui); multi-provider; voice STT \\
\texttt{exatern}          & --- & Phase 11.6: SIMD trit packing, zero-copy array views \\
\bottomrule
\end{tabular}
\end{table}

The CI-verified test suite comprises \textbf{138 fast tests across 5 self-contained crates}
(core: 43, codegen: 8, moe: 24, compat: 29, hdl: 34), all passing. All crates are
published to \texttt{crates.io} under open-core licensing (LGPL-3.0-or-later for the
compiler and CLI; BSL-1.1 converting to LGPL in 2030 for the ML engine and MoE
orchestrator). The live API is deployed at \texttt{https://ternlang.com/mcp}
(Fly.io, Frankfurt) serving both the marketing website and the MCP endpoint from a single
Rust binary.

\textbf{Phase 17 --- BET VM in WebAssembly.} The BET VM has been compiled to WebAssembly
and executes live in the browser via TernStudio. Users can write, compile, and run
\texttt{.tern} programs without local installation. The WASM build is embedded at compile
time via \texttt{include\_str!} and served directly. This is the first public demonstration
that the complete ternary execution pipeline runs client-side on standard web hardware.

\textbf{TernStudio.} The browser IDE received two foundational additions in v2.0.0: the
\emph{Ternary Actuator Protocol} (TAP), an autonomous tool-call interception layer that
suspends State-0 (uncertainty) nodes until a human or upstream agent resolves the signal;
and \emph{Liquid Time}, a DAW-style multiverse timeline scrubber enabling backward-scrub
through simulation history without state corruption.

The open-core library now spans \textbf{28,500+ executable \texttt{.tern} programs}, making
TIS the largest public ternary programming library in existence. The public website
(\texttt{ternlang.com}) is fully bilingual EN/DE. The VS~Code extension
(\texttt{ternlang-0.1.0}) is published on the Open~VSX Registry under publisher
\texttt{rfi-irfos}. Continuous integration via GitHub Actions automatically builds, tests,
and deploys to Fly.io on every push to main.

\subsection*{Technology Readiness Assessment}

\begin{table}[h]
\centering
\small
\caption{TRL assessment by subsystem (2026-05-19)}
\label{tab:trl}
\begin{tabular}{lll}
\toprule
Subsystem & TRL & Basis \\
\midrule
Ternlang compiler + BET VM & 7 & Operational prototype in relevant environment \\
BetRtlProcessor RTL simulator & 7 & Cycle-accurate Verilog-2001 simulation verified \\
Sparse inference (\texttt{gemv\_bitnet}) & 6 & $122\times$ speedup measured at 99\% sparsity \\
MCP server (34 tools, live API) & 7 & Production deployment at \texttt{ternlang.com/mcp} \\
albert. MoE-13 native training & 5 & Validated; 2045+ epochs on Modal T4, 17L autonomous growth \\
\texttt{@sparseskip} routing (Patent A50296/2026) & 5 & Measured 75\% expert skip, 83~tok/s on CPU \\
Distributed actor runtime & 4 & Implemented; large-scale stress testing pending \\
Native ternary silicon drivers & 2 & Design modelled in BetRtlProcessor; awaits fabrication \\
\bottomrule
\end{tabular}
\end{table}

\noindent\textbf{On the hardware driver gap.}
The audit trail correctly identifies that bare-metal drivers for physical
ternary silicon are absent from the repository. This is not a gap in the
research programme---it is the \emph{definition} of what Stage~2 and
Stage~3 funding is designed to produce. The BetRtlProcessor RTL simulator
(TRL~7) is the verifiable hardware blueprint: every logic gate, register,
and instruction cycle is specified in synthesisable Verilog-2001.
The path from TRL~2 to TRL~6 for silicon drivers requires access to a
ternary ASIC fabrication partner and cluster compute to validate the
full training stack at scale. Evaluators should read the RTL simulator
as the engineering commitment, not the absence of drivers as a programme weakness.

% ─────────────────────────────────────────────────────────────────────────────
\section{Conclusion and Future Work}
\label{sec:conclusion}

We have presented Ternlang v2.0.0, a
full-stack balanced ternary execution architecture spanning language design, ISA,
virtual machine, hardware backend, distributed runtime, native C compilation, AI
reasoning infrastructure, and autonomous neural training. Six layers of
contribution are unified under the same foundational primitive---the
trit $t \in \{-1, 0, +1\}$ with an active neutral state:

\begin{enumerate}
  \item \textbf{Language completeness}: exhaustive three-way matching, the
        \texttt{?} error propagation operator, a real cross-file module system
        (stdlib built-in + filesystem-relative user modules), structured
        diagnostic codes, and all major control flow constructs—making ternlang
        a viable general-purpose programming language rather than a research
        prototype.

  \item \textbf{Execution substrate}: \texttt{TSPARSE\_MATMUL} achieves a
        $2.27\times$ reduction in multiply operations at baseline sparsity;
        a CSC kernel with Rayon reaches $122\times$ at high sparsity (512²
        matrix, 99\% sparsity, release mode). A native C11 compilation path
        via \texttt{ternlang-codegen} provides an alternative to VM
        interpretation.

  \item \textbf{Reasoning primitives}: the five-tool Ternary AI Reasoning
        Toolkit (DeliberationEngine, coalition vote, action gate, scalar
        temperature bridge, hallucination score) makes AI agent decision loops
        structurally three-valued.

  \item \textbf{MoE orchestration}: the MoE-13 orchestrator~\cite{moe13_2026}
        extends with 13-agent dual-signal deliberation, an introspective hold
        (stable attractor when $|\text{affirm} - \text{conflict}| \leq 1$
        across $\geq 4$ agents), and an \texttt{orchestrate\_full()} pipeline
        that pre-filters queries through the agent tier before MoE routing.

  \item \textbf{Deployment and tooling}: 34 free MCP tools live at
        \texttt{https://ternlang.com/mcp}; the BET VM runs in the browser via
        WebAssembly; a VS Code extension with LSP, formatter, and REPL; and
        138 CI-verified tests across 5 fast crates
        (28,500+ \texttt{.tern} stdlib programs) validate the full stack.

  \item \textbf{Autonomous training}: Albert MoE-13 has evolved from a 22M-parameter
        3-layer English-only model (v2.0.0, best cross-entropy \textbf{2.1353},
        perplexity $\approx$8.5, 16 global epochs) to an 82M-parameter 17-layer
        multilingual system (v3.0, 8 languages, 32k vocab, 177M-token corpus,
        2045+ global epochs as of 2026-05-19) through five successive autonomous
        surgeries triggered by the EvolutionManager. The v3.0 programme introduces
        generational Fibonacci cycling, TLIGHT per-expert monitoring, WALD coverage
        monitoring, and cross-lingual semantic broadcasting confirmed at ep2041.
        Hardware-verified AVX2 SIMD benchmarks confirm $1.80\times$ throughput at
        50\% sparsity and $3.0\times$ over INT8 at 90\% sparsity, with live
        inference at \textbf{83 tok/s} on consumer CPU hardware.
\end{enumerate}

The title of this paper carries a provocation: \textit{The Death of the Bit}.
It is not an obituary for the trit---it is an obituary for the bit.
It is a claim about what happens when ternary computation matures: the binary bit,
the foundational primitive of five decades of computing, stops being the only
option and becomes a special case of a more expressive substrate. The goal of the Ternary Intelligence Stack
is to make that invisibility possible---to build the substrate so completely
that the three-valued logic becomes the ground truth, not the exception.
We believe Europe's path to technological sovereignty runs through this kind
of foundational work: not chasing the scaling frontier, but owning the substrate
beneath it.

The VS~Code extension (\texttt{ternlang-0.1.0}) has been published on the
Open~VSX Registry (publisher \texttt{rfi-irfos}), making ternlang tooling
available to VS~Code, VSCodium, Gitpod, and any editor backed by the Open~VSX
API. The SPRIND Next Frontier AI Challenge submission has been filed with RFI-IRFOS
as the applying entity, documenting the full TIS architecture for European public
funding consideration (Stage~1: 10 teams at €3M; Stage~2: €8M; Stage~3: €15.5M ceiling).
Near-term targets include submission to the VS~Code Marketplace and academic
outreach to the USN group (Bos \& Gundersen) for joint hardware-software
co-design on the memristor backend.

Further research directions include:

\begin{itemize}
  \item \textbf{Type inference}: Hindley-Milner style inference to eliminate
        explicit type annotations, reducing boilerplate for trit-returning
        functions.
  \item \textbf{FPGA synthesis}: full \texttt{bet\_processor} targeting
        Xilinx Artix-7 and Lattice ECP5, benchmarked against the pure-Rust RTL
        simulator.
  \item \textbf{Perplexity evaluation on held-out corpus}: WikiText-2
        (150\,kB, genuinely held-out) is now the standard eval set for albert.
        benchmarks, replacing the previously contaminated Bible corpus. Formal
        perplexity reporting against this corpus is the next empirical milestone.
  \item \textbf{Multilingual downstream evaluation}: now that the v3.0 corpus
        spans 8 languages, structured evaluation on language-specific held-out
        sets (one per language) will quantify the per-language compression gain
        achieved by the multilingual vocabulary.
  \item \textbf{EvolutionManager surgery conditions for v3.0}: the plateau and
        mastery thresholds that trigger surgery were calibrated for the 8k English
        corpus; recalibrating them for the 32k multilingual vocabulary transfer
        regime is an open problem.
  \item \textbf{TLIGHT formalisation}: the G/O/R state transition rules are
        currently heuristic; formalising them as a finite automaton over routing
        load and gradient norm would enable principled analysis of expert
        specialisation dynamics.
  \item \textbf{QNN acceleration}: formal integration of the Qutrit Neural
        Network framework~\cite{kepp2026qnn} with \texttt{TSPARSE\_MATMUL} as
        the inner-loop kernel, targeting quantum-adjacent hardware via the
        TRS stabilisation pattern.
  \item \textbf{Memristor backend}: integration with physical ternary storage
        via the USN uMemristorToolbox~\cite{bos2020ternary}.
  \item \textbf{Community bootstrap}: coordinated engagement with the broader
        ternary computing ecosystem (Brandon Smith 9-trit, Owlet S-expr,
        Trit-Rust, BitNet b1.58 community).
\end{itemize}

The ternary computing field has been fragmented for decades. Ternlang is
designed to be the substrate where those fragments converge—from ISA to
orchestrator, from single trit to 13-expert MoE, from quantum-adjacent
qutrit networks to physical memristor hardware. The philosophy is simple:
binary sees yes and no; ternary also sees \emph{not yet}—and that changes
everything.

% ─────────────────────────────────────────────────────────────────────────────
\bibliographystyle{IEEEtran}
\bibliography{references}

\end{document}
