Tier 1
Environment
VM Status
Checking…
Endpoint: ternlang-api.fly.dev
Node ID: bet-node-013
Plan & Quota
Tier 1 — Free
Monthly calls
Enter API key to see quota
Need more? Use Upskill ↑ in the top bar
Ternary Playground ⚡ WASM
Work
Quick Actions
Analytics
Session Stats
0
Runs
0
Ok
0
Err
Recent Activity
No runs yet this session
Stdlib Coverage
core/12 modules
math/8 modules
agents/15 modules
safety/5 modules
ml/bitnetv1.58b
Key
No key — anonymous access
Tier 1
Plan Features
Endpoint: https://ternlang.com
GET /health VM health check
POST /api/run Execute .tern code
GET /api/usage Key quota
// Click Try to test an endpoint
Trit Builtins
truth()→ trit(+1)Affirm signal
hold()→ trit(0)Neutral / hold
conflict()→ trit(-1)Reject signal
invert(t)→ tritNegate trit (-1↔+1)
consensus(a,b)→ tritTernary AND merge (max signal)
Math Builtins
abs(x)→ int/floatAbsolute value
min(a, b)→ int/floatMinimum of two values
max(a, b)→ int/floatMaximum of two values
pow(base, exp)→ intInteger exponentiation
len(t)→ intLength of tensor or string
length(t)→ intPrimary dimension of tensor
I/O Builtins
print(v)Print value (no newline)
println(v)Print value + newline
opent(path)→ intOpen file, returns handle
readt(handle)→ stringRead file contents
writet(handle, s)→ tritWrite string to file
Types
trit-1 / 0 / 1Balanced ternary value
inti6464-bit integer
floatf6464-bit floating point
stringUTF-8Text value
booltrue/falseBoolean (coerced to trit)
trit[]dynamicDynamic trit array / buffer
trittensor<N>N×1Fixed-size trit tensor
trittensor<N,M>N×M2D trit tensor
int[N]fixedFixed-size integer array
float[N]fixedFixed-size float array
agentrefrefHandle to a spawned agent
Control Flow
if ? cond { A } tend { B } reject { C }Ternary branch (+1/0/-1)
if cond { A } else { B }Binary branch
while ? cond { body }Ternary loop (runs on +1)
for x in tensor { body }Iterate over tensor elements
match x { 1 => {} 0 => {} _ => {} }Pattern match (int/trit/float)
return val;Return from function
break; / continue;Loop control
val?Early exit on -1 (returns conflict())
Agent Keywords
agent Foo { fn run(...) -> trit { } }Declare agent type
spawn Foo→ agentrefCreate agent instance
send msg to refPush message to mailbox
await ref→ tritRun agent, get result
nodeid→ stringCurrent node address
spawn remote "addr" Foo→ agentrefSpawn on remote node
Directives
@sparseskipSkip zero-signal weights (inference optimization)
VM Error Codes
BET-001StackUnderflowPop on empty stack — add missing return
BET-007TypeMismatchWrong type for op — check trit vs int vs float
BET-008TensorIndexOOBIndex beyond tensor size
BET-010DivByZeroDivision or modulo by zero
BET-013CallStackOverflowDeep recursion or unresolved import
BET-014AgentIdInvalidsend/await on invalid agent ref
BET-015AgentTypeNotRegisteredspawn without agent definition
PARSE-001UnexpectedTokenSyntax error — check grammar
PARSE-002ExpectedTokenMissing token (often ; or })
MOD-004FileNotFoundImport path not found
Literals
1, 0, -1int / tritIntegers; coerce to trit where needed
3.14floatDecimal float
0xFF, 0b1010intHex and binary integer literals
"hello"stringString literal
true / falsebool→intBoolean literals (1 / 0)
hold / tendtritZero-state trit keyword
Known Limitations
VM-STRUCT-001Returning structs from functions not stable — use intermediate vars
COMP-TENSOR-001Tensor size max 65535 elements (16-bit immediate)
MOD-004Named imports require all dependencies imported explicitly
float[] / int[]Array literals/params limited — use individual vars or trit[]
Drag agents from the library or click + to create
Connect agents by dragging from the right port ● to the left port ● of another
100%
Execution Inspector
MULTIVERSE TIMELINE
TIME: 0.00s
Node Properties
Select a node to configure
Drag ● output → ● input to wire

TernWiki

Technical Reference for Balanced Ternary Intelligence

Examples Quickstart Browse Stdlib GitHub
Language Fundamentals

Syntax Guide

Functions
fn add(a: int, b: int) -> int {
  return a + b;
}
Control Flow
match signal {
  affirm => { println("YES"); }
  tend   => { println("HOLD"); }
  reject => { println("NO"); }
}
Agents
agent Sensor {
  handle(s: trit) {
    spawn Consensus(s);
  }
}
Logical Operations

Truth Tables

Input A Input B Consensus
+1 (Affirm) +1 (Affirm) +1
+1 (Affirm) 0 (Tend) 0
+1 (Affirm) -1 (Reject) -1
0 (Tend) 0 (Tend) 0
0 (Tend) -1 (Reject) -1
-1 (Reject) -1 (Reject) -1
Did you know?
The Consensus operator is the ternary equivalent of a logical AND. It resolves to the minimum value of its inputs: consensus(A, B) = min(A, B) where +1 > 0 > -1.
Graph Mechanics & Routing

Node Properties (The Workers)

Nodes are the individual brains of your AI. They evaluate data and make a decision: +1 (True), 0 (Uncertain), or -1 (False). You use this panel to set their rules, ensuring they do not get stuck thinking forever.

Edge Properties (The Smart Pipes)

Edges connect your nodes, but they also filter the traffic. They decide which decisions are allowed to travel to the next worker.

Activation Logic (The Bouncer)

This is how you filter. If you want a strict system, use +1 so only perfect matches pass. If you want a flexible system, use != -1. This allows 0 (Uncertainty) to pass through, letting the AI continue working even if it is not 100 percent sure.

Handling Failures (On Fail)

When a signal fails your logic check, you have choices.

Drop
Silently kills the execution branch to save computer power.
Fallback
Routes the failure to a designated secondary recovery path.
Hold (0)
Converts the failure into a neutral state. This is the magic of ternary computing: a failure does not have to break the machine; it can just mean 'pending'.

The Feedback Loop (Thinking Twice)

Normally, an AI just spits out an answer and stops. Checking this box allows the AI to loop its thoughts backwards and re-evaluate its own work. It is a safety feature that gives the AI permission to think iteratively until it is sure.

● Idle
hello_trit.tern
Ln 1, Col 1
Tier 1 — Open Core
Offline
WASM loading…
🧠 ALBERT CLI F6
Albert CLI — canvas co-pilot mode
Local agent integration coming soon.
This panel will let you prompt Albert directly from the canvas — create nodes, wire flows, and iterate from a single prompt.