The console language

alon

alon is the language this site speaks. It is deliberately small - numbers, strings, lists, records, functions, and a pipeline operator - because it is not trying to be a general purpose language. What it adds instead is a set of first-class values that the rest of QHoTT already deals in: circuits, claims, unitaries, verification reports, type theory developments and registrable artifacts.

Everything below runs in your browser. The interpreter calls the same verifier that Verify uses and the same kernel that Explorer uses; there is no second implementation that could disagree with them.

alonrunning locally in your browser
alon>
Enter runShift+Enter newlineTab complete:help commands

New to the subject matter? Start Here explains what a circuit and a proof are before the syntax matters.


The shape of a program

The pipeline operator |> passes its left-hand value in as the first argument, which is why every builtin that works on a circuit, a report or an artifact takes it in that position. A long pipeline is split across lines by starting each continuation with |>.

A claim decided exactly, start to finish
circuit "ghz" {
  qubits 3
  h 0
  cx 0 1
  cx 1 2
}
  |> verify([is_unitary(), prepares("000", "111")])
  |> artifact("ghz-3")
  |> digest()

A circuit block holds the textual gate format verbatim, so anything that can be pasted into the verifier works here unchanged. A theory block holds type theory declarations and is checked against the prelude by the kernel.

A proof, and the axioms it leans on
let paths = theory "paths" {
  def invRight : (A : Type) -> (x : A) -> (y : A) -> (p : Id A x y)
              -> Id (Id A x x) (trans A x y x p (sym A x y p)) (refl A x)
    := \A x y p. J A x (\b q. Id (Id A x x) (trans A x b x q (sym A x b q)) (refl A x))
                   (refl (Id A x x) (refl A x)) y p
}

paths.ok
paths.axioms

Refutation is a result, not an error. A claim that fails comes back as a report whose verdict is refuted, carrying the first matrix entry that disagrees; a declaration the kernel rejects is reported with the kernel's own reason and the declarations after it are still checked.

Everything is data, including the prelude
prelude()
  |> filter(fn (d) -> len(d.axioms) > 0)
  |> map(fn (d) -> d.name + " depends on " + join(d.axioms))

verify(bell, is_identity()).verdict   # "refuted", with a witness

Run :syntax in the console for the full language reference, or help("verify") for any single builtin.


Values

Beyond the usual scalars and containers, alon has one value type per object the system produces. Each one answers to field access, and fields(v) lists what it responds to.

ValueProduced byFields
circuitcircuit { }, parse_circuit, inverse, seqname, qubits, gates, ops, source
claimis_unitary, equals, prepares, and the restkind, label
unitarymatrixqubits, dim, entries
reportverifyverdict, verified, checks, failures, qubits, gates, depth, tcount
theorytheory { }, check_theory, run_exampleok, checked, failed, names, axioms, declarations
termnfnormal, type, source
artifactartifactlabel, kind, schema, verdict, verified, claims

Builtins

The whole standard library. Every entry is a thin binding to the verifier, the kernel or the registry; none of them reimplements anything, which is the only reason a result in the console can be trusted to mean what the same result means elsewhere on this site.

core

Values, text and lists.

print(value, ...) -> nilWrites each argument to the console on its own line.
type(value) -> stringThe name of a value's type.
str(value) -> stringRenders a value as text, the same way the console would.
show(value) -> stringA compact one-line rendering, useful inside messages.
num(string) -> numberParses text as a number.
json(value) -> stringSerialises a value as indented JSON.
len(list | string | record) -> numberNumber of items, characters or fields.
fields(value) -> listThe field names a value responds to.
range(count) | range(from, to) -> listWhole numbers from `from` up to but not including `to`.
map(list, fn) -> listApplies a function to every item.
filter(list, fn) -> listKeeps the items for which the function is true.
fold(list, start, fn) -> valueLeft fold: `fn(accumulator, item)` across the list.
all(list) -> boolTrue when every item is truthy.
any(list) -> boolTrue when at least one item is truthy.
count(list, value) -> numberHow many items equal the given value.
join(list, separator) -> stringConcatenates the rendered items with a separator.
assert(condition, message?) -> boolRaises an error when the condition is false; returns true otherwise.

quantum

Clifford+T circuits, their exact semantics, and claims about them.

parse_circuit(source, name?) -> circuitBuilds a circuit from the textual gate format, same as a circuit { } block.
gates() -> listEvery gate the verifier understands, with its arity and meaning.
max_qubits() -> numberThe widest circuit the exact verifier will build a unitary for.
matrix(circuit) -> unitaryThe circuit's unitary, computed exactly over Z[omega][1/sqrt(2)].
state(circuit) -> listThe non-zero amplitudes of the state the circuit prepares from |0...0>.
probabilities(circuit) -> listMeasurement probabilities for every basis state, in index order.
inverse(circuit) -> circuitThe circuit reversed, with every gate replaced by its adjoint.
seq(circuit, circuit) -> circuitRuns one circuit after another; both must have the same width.
depth(circuit) -> numberCircuit depth under greedy layering.
tcount(circuit) -> numberNumber of T and T-dagger gates, the usual cost measure for fault tolerance.
source(circuit) -> stringThe circuit back in textual form, ready to paste or store.
is_unitary() -> claimClaims U-dagger U = I exactly.
is_identity() -> claimClaims the circuit is semantically a no-op.
is_self_inverse() -> claimClaims applying the circuit twice is the identity.
cancels_inverse() -> claimClaims the gate-by-gate adjoint undoes the circuit.
is_classical() -> claimClaims the unitary is a permutation matrix, so the circuit is a reversible Boolean function.
equals(circuit) -> claimClaims this circuit denotes the same unitary as another, entry for entry.
equals_up_to_phase(circuit) -> claimAs equals, but allowing an unobservable global phase from the eight units omega^k.
commutes_with(circuit) -> claimClaims the two circuits may be reordered without changing semantics.
prepares("00", "11") -> claimClaims the circuit maps |0...0> to an equal superposition over the listed basis states.
verify(circuit, claims?) -> reportDecides each claim exactly and returns a report. Defaults to is_unitary().
holds(report) -> boolTrue when every claim in the report was discharged.

theory

The Martin-Lof kernel: the prelude, normalisation, and checking new developments.

prelude() -> listEvery name the standard library defines, with its type.
lookup(name) -> recordThe declared type of a prelude name, and the axioms it leans on.
search(text) -> listPrelude names whose name or type mentions the given text.
nf(term) -> termNormalises a closed term against the prelude and reports its type.
type_of(term) -> stringThe inferred type of a closed term, as the kernel prints it.
same(term, term) -> boolTrue when two closed terms have the same normal form.
check_theory(source, label?) -> theoryChecks declarations written as text; the theory { } block is sugar for this.
examples() -> listThe worked developments shipped with the explorer.
example(id) -> recordOne worked development, including its source and the point it makes.
run_example(id) -> theoryChecks a worked development with the kernel and returns the result.
kernel() -> recordWhat the kernel is, and what it deliberately is not.

chain

Reproducible digests, and the Solana registry that anchors them.

artifact(label, report | theory) -> artifactPackages a verification result into the object the registry commits to.
digest(artifact) -> stringSHA-256 of the canonical payload: the 32 bytes the chain stores, as hex.
canonical(artifact) -> stringThe exact JSON string that gets hashed: sorted keys, no loose whitespace.
hash(string) -> stringSHA-256 of arbitrary text, for checking a digest by hand.
registry() -> recordWhere the registry lives, what it gates on, and which cluster is configured.
registration(artifact, uri?) -> recordThe exact register_proof payload and the account the record would occupy.
record_address(artifact) -> stringThe PDA a record derives from its digest, so duplicates are impossible.
explorer("address" | "tx", value) -> stringAn explorer link on the configured cluster.
schemas() -> listThe artifact schema identifiers the digest format is versioned by.

help

Finding your way around.

help(name?) -> stringLists the builtins, or explains one builtin or one group.
builtins() -> listEvery builtin name, as data.

What alon is not