Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Elinvar: the logic

Status: current, 2026-11-29. Specifies phases 1 to 5 and bounded integers (R1 to R26 of REQUIREMENTS.md): what a model is made of, what every operator means, finding, time, answers, model text, and integers.

This is the definition the evaluator computes and everything else is judged by (DESIGN.md section 6.5, AGENTS.md law 12). Where it follows Alloy or Kodkod, and where it does not, is in section 10.

Contents: 1 Universe, atoms, tuples · 2 Relations, bounds, instances · 3 Expressions · 4 Formulas · 5 Declarations and variables · 6 Errors · 7 The evaluator · 8 Counting by brute force · 9 Worked examples · 10 Compatibility with Alloy and Kodkod · 11 Not yet specified · 12 Finding · 13 Time · 14 Answers · 15 Model text · 16 Integers

1. Universe, atoms, tuples

A universe is a list of n atoms, n at least 1, each with a name, the names distinct. The position of an atom in the list, from 0, is the atom: two universes with the same names in a different order are different universes.

A tuple of arity k, k at least 1, is a sequence of k atoms of one universe. An arity of 0 is an error (arity.zero), and so is a tuple that names an atom the universe lacks (universe.unknown_atom). Its index is its atoms read as digits in base n, first atom most significant:

index(a1, ..., ak) = a1 * n^(k-1) + a2 * n^(k-2) + ... + ak

Tuples of the same arity are ordered by index. A tuple set has an arity and holds tuples of that arity, in order, each at most once; a tuple of another arity is an error (tuples.arity), and so is one over another universe (tuples.other_universe). Two universes are the same when they have the same names in the same order.

The number of tuples of an arity in use, n^k, is at most 2^64 - 1, so that it and every index fit in 64 unsigned bits. A universe and an arity past that are an error (section 6, universe.capacity). An expression has no universe of its own, so the check is made where an arity meets a universe: when a tuple set is built, and when a formula is evaluated, run, or checked.

2. Relations, bounds, instances

A relation has a name and an arity of 1 or more (arity.zero otherwise). Two relations are the same only if they are the same declaration; the name is for people. A set is a relation of arity 1.

Identity is compared for equality and for nothing else. Whatever it is made of may differ from one run to the next, so it has no order that means anything, and nothing on a result path sorts or iterates by it (AGENTS.md law 16). Order comes from the bounds.

Bounds, over one universe, give each of a list of relations two tuple sets of its arity: a lower bound and an upper bound, with the lower inside the upper. The order of the list is the order in which the relations were given their bounds. That is the declaration order every later section means: the model builder gives bounds in the order the model declares. A relation is in the list once (bounds.duplicate_relation), and the names in one list are distinct (bounds.duplicate_name). An exact bound is one whose lower and upper are equal.

An instance, over the same universe, gives each relation a tuple set of its arity. It is within the bounds when, for every relation, the lower bound is inside its tuple set and its tuple set is inside the upper bound. An instance built by hand is checked as bounds are, under the instance. codes of section 6.

Because names are distinct within one bounds or instance, its serialized form names each relation by its name, in list order. Reading one back takes the list of relations it is for and matches them by name; identity itself is never written.

3. Expressions

An expression has an arity and, given an instance and values for its free variables, denotes a tuple set of that arity. Below, A and B are the tuple sets of a and b, and |a| is the arity of a.

ExpressionWrittenRequiresArityDenotes
relationrthat of rthe instance’s tuple set for r
variablexbound (section 5)1the one atom x is bound to
emptynone1no tuples
everythinguniv1every atom
identityiden2(a, a) for every atom a
uniona + b|a| = |b||a|tuples in A or in B
intersectiona & b|a| = |b||a|tuples in A and in B
differencea - b|a| = |b||a|tuples in A and not in B
joina . b|a| + |b| > 2|a| + |b| - 2(a1, ..., a(i-1), b2, ..., bj) for every (a1, ..., ai) in A and (b1, ..., bj) in B with ai = b1
producta -> b|a| + |b|(a1, ..., ai, b1, ..., bj) for every tuple in A and every tuple in B
transpose~a|a| = 22(y, x) for every (x, y) in A
closure^a|a| = 22the smallest set T with A inside T and T . T inside T
reflexive closure*a|a| = 22^a + iden
overridea ++ b|a| = |b||a|the tuples of A whose first atom is the first atom of no tuple in B, and every tuple of B
domain restrictions <: a|s| = 1|a|the tuples of A whose first atom is in S
range restrictiona :> s|s| = 1|a|the tuples of A whose last atom is in S
comprehension{x1: e1, ..., xm: em | F}section 5m(a1, ..., am) for every binding of the declarations under which F is true
if-then-elseF => a else b|a| = |b||a|A if F is true, otherwise B

Notes.

  • iden and *a range over the whole universe, not over the atoms some relation happens to hold.
  • For sets, override is union: every tuple is its own first atom.
  • Join has no arity-0 result. s . t for two sets is an error, not “is the intersection non-empty”.

4. Formulas

A formula, given an instance and values for its free variables, is true or false.

FormulaWrittenRequiresTrue when
constantstrue, falsealways, never
subseta in b|a| = |b|every tuple of A is in B
equalitya = b|a| = |b|A and B hold the same tuples
somesome aA has at least one tuple
nono aA has no tuple
oneone aA has exactly one tuple
lonelone aA has at most one tuple
notnot FF is false
andF and Gboth are true
orF or Gat least one is true
impliesF implies GF is false or G is true
iffF iff Gboth are true or both are false
allall x1: e1, ..., xm: em | Fsection 5F is true under every binding
somesome x1: e1, ..., xm: em | Fsection 5F is true under at least one binding
nono x1: e1, ..., xm: em | Fsection 5F is true under no binding
oneone x1: e1, ..., xm: em | Fsection 5F is true under exactly one binding
lonelone x1: e1, ..., xm: em | Fsection 5F is true under at most one binding

and and or take any number of formulas. With none, and is true and or is false.

5. Declarations and variables

A variable has a name and stands for one atom. Two variables are the same only if they are the same declaration, as with relations.

A declaration x: e introduces x, where e is an expression of arity 1. A quantifier or a comprehension has a list of one or more declarations (logic.no_declarations for an empty list), and a later declaration’s expression may use an earlier one’s variable.

A binding of x1: e1, ..., xm: em is a tuple (a1, ..., am) of atoms such that a1 is in what e1 denotes, a2 is in what e2 denotes with x1 bound to a1, and so on. The bindings of a list are counted as tuples: in one x: s, y: t | F, “exactly one” means exactly one pair. With no binding at all, all, no, and lone are true, and some and one are false.

A variable is bound inside the body of the quantifier or comprehension that declares it, and in the expressions of later declarations in the same list. Anywhere else it is free. A formula given to the evaluator, to run, or to check has no free variables.

There is no shadowing: a variable is not declared where it is already bound (logic.rebound_variable). That rules out two cases and allows two.

  • Twice in one list is an error: all x: s, x: t | F.
  • Inside the body, or a later declaration, of a quantifier or comprehension that declares it is an error: all x: s | some x: t | F.
  • In two places of which neither is inside the other’s scope is fine, and each is its own binding: (all x: s | F) and (all x: t | G).
  • A declaration’s own expression is outside its variable’s scope, so all x: {x: s | F} | G is fine.

A declaration over sets or relations is written x: m e, with m one of set, some, lone, or one, and x of the arity of e. Its bindings are the tuple sets inside what e denotes with as many tuples as m allows: any number, at least one, at most one, or exactly one. x: e with e of arity 1 and no m is the declaration of one atom above, and with e of greater arity it is x: set e. The evaluator enumerates these bindings as it does any others; when e denotes more than 63 tuples it cannot, and says so (enumerate.too_large). A comprehension declares atoms only (logic.higher_order).

6. Errors

Arity errors are found when the node is built, and carry the place it was built (DESIGN.md section 6.4). The others are found where the table says. Every code is explained by elinvar explain (AGENTS.md law 21).

An ill-formed node has no arity. A node built from an ill-formed part is ill-formed too. It keeps the errors of all its parts and records none of its own, so (s + r) . r reports the one arity.mismatch and nothing for the join, and (s + r) + (r <: r) reports both of its parts’ errors and nothing for the outer +.

The evaluator, run, and check refuse a formula with any error, and return all of them together (section 7). The evaluator takes an expression too, and what this section and the table say of a formula that is evaluated holds for an expression that is evaluated.

CodeWhenMessage carries
universe.emptya universe with no atoms
universe.duplicate_atomtwo atoms with one namethe name
universe.unknown_atoma tuple names an atom the universe lacksthe name
universe.bitwidtha bitwidth outside 1 to 32 (section 16.1)the bitwidth
universe.intan integer atom’s integer outside the bitwidth’s range, two integers for one atom, or two atoms for one integer (section 16.1)the atom, the integer, the range
universe.capacityn^k is more than 2^64 - 1, for a tuple set of arity k when it is built, or for an expression of arity k when its formula is evaluated, run, or checkedn, k
tuples.aritya tuple set is given a tuple of another arityboth arities
tuples.indexa tuple set is given an index of no tuple of its arity, n^k or morethe index, n^k
tuples.other_universea tuple set is given a tuple, or combined with a tuple set, over a different universe
bounds.aritya bound whose arity is not the relation’sboth arities, the relation
bounds.lower_outside_uppera lower bound with a tuple the upper bound lacksthe relation, the first such tuple
bounds.other_universea tuple set over a different universethe relation
bounds.duplicate_relationbounds are given for a relation that has themthe relation
bounds.duplicate_nametwo relations of one bounds have one namethe name
instance.aritya tuple set whose arity is not the relation’sboth arities, the relation
instance.other_universea tuple set over a different universethe relation
instance.duplicate_relationa tuple set is given for a relation that has onethe relation
instance.duplicate_nametwo relations of one instance have one namethe name
arity.zeroa relation or a tuple of arity 0
arity.mismatch+, &, -, ++, in, =, if-then-else with unequal aritiesthe operator, both arities
arity.joina join of two expressions of arity 1
arity.not_binary~, ^, * on an expression of arity other than 2the operator, the arity
arity.not_a_setthe set side of <: or :>, or a declaration’s expression, of arity other than 1the arity
logic.free_variablea formula with a free variable is evaluated, run, or checkedthe variable
logic.no_declarationsa quantifier or a comprehension with an empty list of declarations
logic.rebound_variablea formula is evaluated, run, or checked, and declares a variable where it is already bound (section 5)the variable
logic.higher_ordera declaration over sets or relations in a comprehension, or, when a formula is run or checked, in a quantifier that skolemization cannot remove (section 12.2)the variable
logic.unbound_relationa formula is run or checked and uses a relation the bounds lackthe relation
instance.missing_relationa formula is evaluated and uses a relation the instance lacksthe relation
enumerate.too_largebrute-force enumeration over more free tuples than its capthe count, the cap

7. The evaluator

The evaluator takes an instance and an expression or a formula with no free variables, and returns the tuple set or the truth value that sections 3 to 5 define. It keeps an environment that maps each bound variable to an atom.

Before it computes anything it checks the whole expression or formula: the errors recorded when its nodes were built, free and rebound variables, relations the instance lacks, and capacity. It returns every error it finds, together, and computes only when there is none. So an error is never hidden by a part the computation would not reach, as in false and F or all x: none | F.

It computes each definition as written:

  • Set operators work on sorted tuple sets.
  • Join and product build each result tuple from a pair of tuples.
  • Closure starts from T = A and replaces T by T + T . A until T stops growing.
  • A quantifier or a comprehension enumerates the bindings of its declarations, first declaration outermost, each in tuple order, and evaluates the body under each. one and lone count the bindings under which the body is true.

It does not cache, reorder, or stop early in a way that could change an answer or hide an error. Its cost is whatever the definitions cost.

8. Counting by brute force

Given bounds, the free tuples are the tuples in some relation’s upper bound and not in its lower bound, listed relation by relation in declaration order and by index within a relation: t0, t1, ..., t(m-1). Instance number j, for j from 0 to 2^m - 1, gives every relation its lower bound plus those ti of its own for which bit i of j is set. Enumeration goes through j in increasing order. The caller gives a cap on m (enumerate.too_large). Whatever the cap, m above 63 is enumerate.too_large, so that j and the count fit in 64 bits.

The count of a formula under bounds is the number of those instances under which the evaluator finds it true. elinvar::count_bitsliced computes the same count 4,096 instances at a time, for static first-order formulas, and must agree with this one (DESIGN.md section 10).

These counts are known, and are phase 1’s test that the evaluator and the enumeration are right together. The universe has n atoms, and r is one relation of arity 2 with an empty lower bound and every pair in its upper bound.

r isFormulan = 1234
anythingtrue21651265536
reflexiveiden in r14644096
symmetric~r in r28641024
a functionall x: univ | one x.r1427256
a bijectiona function, and all x: univ | one r.x12624
transitiver.r in r2131713994
an equivalencereflexive, symmetric, and transitive12515
a strict partial orderno iden & r, and transitive1319219
a strict total ordera strict partial order, and all x, y: univ | x = y or x->y in r or y->x in r12624
acyclicno ^r & iden1325543

The first three rows and the two with factorials are 2^(n*n), 2^(n*n - n), 2^(n*(n+1)/2), n^n, and n!. The others are the sequences A006905 (transitive relations), A000110 (Bell numbers), A001035 (partial orders), and A003024 (acyclic digraphs) of the OEIS.

9. Worked examples

Each line is a test (AGENTS.md law 29). The universe is (A, B, C), and the instance is

s = {A, B}        t = {B, C}        r = {(A,B), (B,C)}        q = {(A,C)}

Expressions:

ExpressionDenotes
none{}
univ{A, B, C}
iden{(A,A), (B,B), (C,C)}
s + t{A, B, C}
s & t{B}
s - t{A}
s -> t{(A,B), (A,C), (B,B), (B,C)}
s . r{B, C}
r . t{A, B}
r . r{(A,C)}
r . univ{A, B}
univ . r{B, C}
~r{(B,A), (C,B)}
^r{(A,B), (A,C), (B,C)}
*r{(A,A), (A,B), (A,C), (B,B), (B,C), (C,C)}
r ++ q{(A,C), (B,C)}
s ++ t{A, B, C}
t <: r{(B,C)}
r :> s{(A,B)}
{x: univ | some x.r}{A, B}
{x: s, y: x.r | y in t}{(A,B), (B,C)}
{x: s, y: t | x->y in r}{(A,B), (B,C)}
(some s - t) => s else t{A, B}
(no s) => s else t{B, C}

Formulas:

FormulaValue
r in s -> ttrue
s = tfalse
s + t = univtrue
some s & ttrue
no s - univtrue
one sfalse
one s & ttrue
lone sfalse
lone s - univtrue
all x: s | some x.rtrue
all x: univ | some x.rfalse
all x: none | falsetrue
some x: univ | no x.rtrue
some x: none | truefalse
one x: univ | no x.rtrue
lone x: univ | some x.rfalse
no x: univ | x in x.rtrue
one x: s, y: t | x->y in rfalse
some x: univ, y: x.r | no y.rtrue
r.r in rfalse
^r . ^r in ^rtrue

Errors, with s and r as above:

BuiltCode
s + rarity.mismatch
s . tarity.join
~sarity.not_binary
r <: rarity.not_a_set
all x: r | some xarity.not_a_set
(s + r) . rarity.mismatch, once
(s + r) + (r <: r)arity.mismatch and arity.not_a_set, once each

Checked before evaluation (section 7), with x and y variables:

EvaluatedResult
x in slogic.free_variable
false and x in slogic.free_variable
all x: none | y in slogic.free_variable
all x: s, x: t | x in slogic.rebound_variable
all x: s | some x: t | x in slogic.rebound_variable
(all x: s | x in s) and (all x: t | x in t)true
all x: {x: s | x in t} | x in strue

10. Compatibility with Alloy and Kodkod

Where Elinvar’s logic differs from upstream, or depends on a fact about it (AGENTS.md laws 3 and 5). Files are at the pinned commits (cargo x fetch).

TopicUpstreamElinvar
which engineAlloy 6.2.0 does not solve through the Kodkod repository. It uses the copy of Pardinus in its own tree, a fork of Kodkod (org.alloytools.pardinus.core, reached from A4Solution.java as PardinusSolver)a claim about what Alloy answers is checked in that copy. The Kodkod repository is cited for the design the two share
expression operatorsKodkod has union, intersection, override, product, difference, join, transpose, closure, and reflexive closure (kodkod/ast/operator/ExprOperator.java), and no restriction operators. Alloy builds s <: a as a intersected with s -> univ -> ..., and a :> s as a intersected with ... -> univ -> s, for any arity of a (TranslateAlloyToKodkod.java, visit(ExprBinary), cases DOMAIN and RANGE)the same nine with the same meaning, and domain and range restriction as operators of the core, with the meaning Alloy gives them
overridea tuple of the left operand is kept when the right has none in the same row, a row being the tuples that share a first atom (kodkod/engine/bool/BooleanMatrix.java, override)the same (section 3)
quantifiersKodkod has all and some (kodkod/ast/operator/Quantifier.java). Alloy rewrites the others: no as all of the negated body; one and lone as the multiplicity of a comprehension when every declaration ranges over a set, and otherwise through all over two copies of the declarations (TranslateAlloyToKodkod.java, visit_qt)all five are core, counting bindings as section 5 says, which is what both of Alloy’s forms count. The rewriting still matters to instance counts, through skolemization (CORPUS.md section 4)
multiplicity of an expressionno, lone, one, some (kodkod/ast/operator/Multiplicity.java)the same four
integer atomsAlloy gives every command an integer bitwidth of 4 unless told otherwise, and so 16 integer atoms in the universe, whether or not the model uses integers (ScopeComputer.java: shouldUseInts = true, then bitwidth = 4 and 1 << bitwidth atoms)integers as section 16 has them, with integer atoms only where a model asks for them. univ, iden, and * therefore range over fewer atoms than Alloy’s in a model without integers. A corpus model whose answer depends on that is read with Alloy’s integer atoms (CORPUS.md section 4)
integer arithmeticwraps around at the bitwidth unless the noOverflow option is on, which is off by default (A4Options.noOverflow); Kodkod’s integers are two’s complement circuits (kodkod/engine/bool/TwosComplementInt.java)wraps around always (section 16); there is no option that rules out overflow
empty universeKodkod rejects one (kodkod/instance/Universe.java, both constructors)rejected (universe.empty)
the same variable in two quantifiersKodkod allows one Variable in both non-enclosing and nested quantifiers, with the innermost binding shadowing the outer (kodkod/engine/fol2sat/Environment.java, extend and lookup; kodkod/ast/QuantifiedFormula.java and Decls.java do not forbid reuse)allowed in non-enclosing quantifiers; rebinding where it is already bound is an error (section 5)
instances told apartenumeration rules out the last instance with a clause over every primary variable, and skolem relations have primary variables (ExtendedSolver.java, nextNonTrivialSolution; Skolemizer.java adds each skolem relation to the bounds)the same (DESIGN.md section 7.7), so two instances that differ only in a witness count as two on both sides

11. Not yet specified

Each item is written here, with its tests, before its code (AGENTS.md law 1). The design for each is in DESIGN.md.

Phase 3 is specified in section 13.

Phase 4 is specified in section 14.

Phase 5 is specified in section 15.

Integers are specified in section 16.

12. Finding

Phase 2: how run and check find an instance with a SAT solver (DESIGN.md section 7). Everything here is a function of its input, so the same problem gives the same answer on every machine (AGENTS.md law 16).

12.1 Problems and verdicts

A problem is bounds and a formula with no free variables, checked as section 7 checks it, against the bounds (logic.unbound_relation).

  • run F looks for an instance within the bounds under which F is true. The verdict is found, with the instance, or none.
  • check A under rules R looks for an instance of R and not A. The verdict is counterexample, with the instance; or, when there is none, holds if R alone has an instance and vacuous if it has none, found by a second solve of R alone.
  • A solve that runs out of its budget gives unknown, with the budget that ran out. If the second solve of a check runs out, the verdict is unknown and records that no counterexample exists within the bounds.

12.2 Skolemization

A conjunction or disjunction of one formula is that formula. A quantifier is skolemized when it is an existential reached from the root through and, not, and the left side of a negated implies only, with no universal quantifier above it: a some with an even number of not above it, or an all or a no with an odd number, since no x | F is all x | not F, as Alloy writes it before Kodkod sees it (TranslateAlloyToKodkod.visit_qt at 59ba203). one and lone are never skolemized.

Each declaration x: m e of a skolemized quantifier becomes a fresh relation $x of x‘s arity ($x_2, $x_3, and so on when the name is taken), in declaration order, bounded above by the upper approximation of e and below by nothing. The upper approximation of an expression is what it denotes when every relation holds its upper bound and a skolem relation stands for an earlier declaration, except that a - b is taken as a, a ++ b as a + b, a comprehension as the product of its declarations’ approximations, and F => a else b as a + b. Every operator then only grows with its operands, so no instance within the bounds gives e an atom outside it. The quantifier is replaced by m $x and $x in e and B, where m is the declaration’s multiplicity, one for an atom and nothing for set, and e and the body B have the earlier declarations’ variables replaced by their relations. A declaration over sets or relations that skolemization does not remove is an error (logic.higher_order): the solver grounds quantifiers over atoms only. The skolem relations are added to the bounds after the user’s, and are part of the instance the solver returns. The referee drops them and evaluates the formula as the user wrote it (section 12.7).

12.3 The circuit

A boolean value is the constant true, the constant false, a variable, or a gate. A gate is an and of two or more distinct values, sorted by number, an xor of two distinct positive values, or a maj (at least two of three values), shared when asked for with the same inputs. not is a sign on a value, and or is the not of the and of the nots. Building a gate simplifies: an and with a false input is false, true inputs are dropped, an input together with its not gives false, a repeated input is kept once, an and of one input is that input, and an and of none is true; xor and maj simplify constants, equal inputs, and complementary inputs, and canonicalize signs so that xor(not a, b) = not xor(a, b) and maj(not a, not b, not c) = not maj(a, b, c). An existing gate with the same kind and inputs is returned unchanged.

Variables are numbered from 1, relation by relation in bounds order, and within a relation by tuple index, one for each tuple in the upper bound and not in the lower bound. These are the primary variables. Gates are numbered after them, in the order they are first built.

An expression of arity k becomes a table: for each tuple index, a boolean value, false when absent. A relation’s table is true on its lower bound and its variable on the rest of its upper bound. The operators of section 3 are computed entry by entry from their definitions, with or for “some pair”, and for “both”, and not for “not in”; closure is computed as T = A, then T = T + T . T repeated until T covers paths of length n. A variable bound to atom a is the table true on a alone.

A quantifier is grounded over the atoms its declaration’s table does not make false, in index order, first declaration outermost. Each binding gives a guard, the and of its declarations’ entries, and the body’s value under it. all is the and over bindings of guard implies body; some is the or of guard and body; no is the not of some. lone over values v1, ..., vk, each a binding’s guard and body, is a sequential counter, as Kodkod’s BooleanMatrix.lone is: with p0 false and pi = p(i-1) or vi, it is the and over i of not (vi and p(i-1)). one is lone and pk. A multiplicity of an expression is the same over its table’s entries. a in b is the and over a’s entries of ai implies bi, and a = b is that both ways, entry by entry.

A node met again with the same values of its free variables gives the same value, without being computed again (R8).

12.4 Clauses

The root value is asserted. Each gate the root reaches has the polarities it occurs in: the root occurs positively, an input of and or maj occurs as the gate does (or the other way round when negated), and the inputs of xor occur in both polarities. A gate g = and(x1, ..., xm) that occurs positively gives the clauses (not g or xi) for each i, and negatively (g or not x1 or ... or not xm). A gate g = xor(a, b) gives (not g or a or b) and (not g or not a or not b) positively, and (g or not a or b) and (g or a or not b) negatively. A gate g = maj(a, b, c) gives (not g or a or b), (not g or a or c), and (not g or b or c) positively, and (g or not a or not b), (g or not a or not c), and (g or not b or not c) negatively. Gates are encoded in number order. This is Plaisted and Greenbaum’s encoding, as Kodkod’s Bool2CNFTranslator makes it at 6e80244. It has a model exactly when the root does, with the same primary variables, and only those are read. If the root is a constant, no clause is made: true is satisfied by every assignment of the primary variables, false by none.

12.5 Symmetry breaking

Atoms a and b are interchangeable when neither is an integer atom (section 16.4) and swapping them maps every lower and upper bound to itself. This is an equivalence relation; its classes, each listed in atom order, are the parts of the universe.

For each part and each pair of neighbouring atoms (a, b) in it, the predicate compares two vectors: the primary variables whose tuple the swap moves, and the variables of the tuples they are moved to. The primary variables are taken relation by relation, in order of arity and then bounds declaration order, and within a relation in number order. A pair of entries (y, x) after the pair (x, y) is left out: it can only matter once x and y are equal, as Kodkod’s atSameIndex has it. The predicate asks that the first vector be no greater than the second in lexicographic order, false before true, comparing at most 20 entries. The predicate is on by default and can be turned off. With it on, instances that differ only by a renaming of atoms may be left out; a count of instances is meant with it off.

12.6 The next instance

After an instance, the next is found by adding one clause that rules out its values for all primary variables, skolem relations’ included. The order instances come in is the solver’s, which is deterministic.

12.7 The referee

Every instance the solver returns is checked before it is given out (AGENTS.md law 13): the user’s relations are given their tuple sets from the solver, the bounds must admit that instance, and the evaluator must find the problem’s formula, as the user wrote it, true. A failure is a bug in Elinvar and panics with a message naming the check. When the formula as written cannot be evaluated because a declaration over sets or relations ranges over more than 63 tuples (enumerate.too_large), the referee evaluates the skolemized formula instead: its witnesses are relations of the instance, so it is still checked against what the instance holds, but by a formula the engine wrote.

12.8 The solver

The default solver is Elinvar’s own, conflict-driven with clause learning, decided by the user on 2026-11-28. It is deterministic: variable activity breaks ties by the lower variable number, the first value tried is false, restarts follow the Luby sequence, and nothing is random. A budget is a number of conflicts, a time limit, or both; only running out can depend on the time.

12.9 The model builder

Most models are not written as bounds. The model builder of the elinvar-engine crate (re-exported by elinvar) declares sets and relations, and a command gives each set a scope; the builder turns them into bounds and facts (R11).

  • A top-level set gets its own atoms, named after it and numbered from 0: Person0, Person1. Top-level sets are therefore disjoint. Under scope k its upper bound is its k atoms and its lower bound is empty; with an exact scope, the lower bound is all k. A one set has exactly one atom whatever the scope.
  • A subset of a set has the parent’s atoms as its upper bound, and the fact that it is inside the parent. Subsets declared as extending the same parent are disjoint from each other, and an abstract parent with extensions is their union.
  • A relation over columns of sets has the product of the columns’ upper bounds as its upper bound, and the fact that it is inside the product of the columns. A field, a binary relation from a domain to a range, may have a multiplicity m of one, lone, or some, which adds all x: domain | m x.f.
  • The universe is the atoms of the top-level sets in declaration order. The builder’s univ is the union of the top-level sets, and its iden is iden restricted to it, because the logic’s own univ also holds atoms that a set under a smaller scope leaves out.
  • A command needs a scope for every top-level set that is not one: there is no default in the Rust builder (DESIGN.md section 13, open item 7).
  • A set’s scope makes room for the subsets declared one below it, as Alloy’s ScopeComputer.computeLowerBound does; and an abstract top-level set without a scope of its own, whose extensions are all one, holds exactly those, as derive_abstract_scope does.
  • An ordering on a top-level set makes its scope exact and gives it two relations, first and next, bounded exactly: the set’s atoms in atom order, first the first of them and next each to the one after. This is the order Alloy fixes for util/ordering whatever symmetry breaking says (DESIGN.md section 7.5).
  • An ordering on a set that extends or is in another gives it first and next bounded above by its top-level set’s atoms, first alone and next every pair, and a fact that they are a total order of the set: one first, first in s, next in s -> s, no next.first, each atom of s with at most one before and one after it, s in first.*next, and no ^next & iden. A set that extends another has an exact size in each command, its own scope if it has one and its top-level set’s otherwise, as Alloy 6.2.0 answers for util/ordering[exactly elem] (corpus/language/ordered_subsig.als). A set in another is exact only as Pardinus makes it (SymmetryBreaker.breakTotalOrder at d3e7aea): when its upper bound lies inside one part of the universe (section 12.5’s parts, of the bounds without the orderings’ own relations, which Alloy does not fix in advance), the set is that whole upper bound, and the part is taken, so no later ordering’s set is made exact by it. Otherwise, as beside a one extension of its parent, its size is free. Orderings are taken in the order of the names Alloy gives their relations, alias/Ord.Next (SymmetryBreaker.sort), a library module’s own ordering being module/ord, and a top-level ordered set takes its part too (corpus/language/ordered_subsig_split.als, ordered_shared_a.als, ordered_shared_z.als). An ordering on a subset of a union of sets is one on a set in another, over the atoms of the sets’ top-level sets: over two top-level sets its upper bound lies in two parts and its size is free (ordered_union_subset.als). The order is the solver’s to find, not fixed by atoms, because the set’s atoms are not known before solving. An ordering on a set that changes over time is model.not_a_set.
  • A set that extends another may have a scope too, as in Alloy (ScopeComputer and BoundsComputer at 59ba203). When none of the extensions under an unordered top-level set changes over time and their exact sizes fit in the top-level set, each one or exactly k extension gets disjoint exact atoms from its top-level set, bottom-up, and sibling non-exact extensions exclude those atoms from their upper bounds, as Alloy’s BoundsComputer assigns them. Otherwise its command has the fact that it has at most k atoms, or exactly k, stated as BoundsComputer.size states it: no s or some v1, ..., vk: s | s = v1 + ... + vk, with the vi disjoint for exactly k, lone s and one s for 1, and no s for 0. A scope of at least the atoms of the set’s upper bound adds nothing, as Alloy’s BoundsComputer adds nothing when upper.size() <= n (BoundsComputer.java at 59ba203). The atoms of the extensions with an exact scope must fit in their top-level set, which grows to hold them; and an abstract top-level set without a scope of its own, each of whose extensions has a scope or is one, holds at most their sum; and of an abstract set with a scope, all of whose extensions but one have a scope or are one, the one left has the difference, or 0 (derive_abstract_scope).
  • Int, the set of integer atoms (section 16), is a top-level set that holds, in each command, exactly one atom for each integer of the command’s bitwidth, named by it and from the least: -8 to 7 at the default bitwidth of 4. A bitwidth above 16 in a model with Int is an error (model.bitwidth), since Int would have 2^w atoms; the universe’s own limit is 32 (section 16.1).
CodeWhenMessage carries
model.bitwidtha command asks for a bitwidth above 16 in a model with Intthe bitwidth
model.no_scopea command leaves a top-level set without a scopethe set
model.not_a_seta scope is given for something that is not a top-level set of the model, or an ordering for a set that changes over timethe expression
model.not_changingan action’s effect names something that is not a changing relation of the modelthe action, the expression
model.changing_after_actiona changing relation is declared after an action, whose frame then misses itthe relation
model.diff_mismatchtwo models compared with diff do not declare the same signatures and fields with the same arities and mutabilitythe mismatched relation
model.trivial_holdsa check assertion holds from the bounds alone without using any rule of the modelthe check
model.vacuous_premisean implication promise’s premise is never satisfied in any allowed case within the scopethe check
model.premise_unknownwarning: an implication promise holds, but whether its premise is ever satisfied was not settled within the budget for that question (the command’s conflict budget, at most 50,000)the check and the conflicts spent
model.invalid_stepsa command asks for 0 steps; a trace needs at least 1 statethe command
model.scope_too_largea command asks for more than 4096 non-integer atoms in total, or its relations have more than 2^24 (16,777,216) possible tuples in all, each a solver variablethe requested atom or tuple count, and the relation that passed the limit

13. Time

Phase 3 (DESIGN.md section 8, R19 to R22).

13.1 Changing relations and traces

A relation is fixed or changing; it is declared one or the other (R19).

A trace, over one universe, is an instance of the fixed relations, a list of L states, L at least 1, each an instance of the changing relations, and a loop target j with 0 <= j < L. It stands for the infinite sequence of positions 0, 1, 2, ...: position p shows state p when p < L, and otherwise state j + (p - j) mod (L - j). After the last state comes state j again, for ever (R21).

A trace is within bounds when its fixed instance is, and every state gives each changing relation a tuple set between that relation’s bounds.

13.2 Temporal formulas

A formula holds at a position. Everything of sections 3 to 5 holds at a position as it does in that position’s state, with the fixed relations the same at every position. A formula is true of a trace when it holds at position 0.

WrittenHolds at p when
e' (an expression)denotes, at p, what e denotes at p + 1
after FF holds at p + 1
always FF holds at every q >= p
eventually FF holds at some q >= p
F until GG holds at some q >= p, and F at every r with p <= r < q
F releases Gnot (not F until not G) holds
before Fp > 0 and F holds at p - 1
historically FF holds at every q <= p
once FF holds at some q <= p
F since GG holds at some q <= p, and F at every r with q < r <= p
F triggered Gnot (not F since not G) holds

13.3 Evaluating on a lasso

The past depth of a formula, or of an expression or integer expression evaluated on a trace, is the greatest number of past operators (before, historically, once, since, triggered) nested in one another in it. With past depth d and period P = L - j, whether a formula holds at a position p >= j + d * P depends only on (p - j) mod P. So the evaluator works on the positions 0 to N - 1, N = j + (d + 1) * P, with the next position of N - 1 being N - P. A future operator at p walks forward from p until a position repeats; a past operator walks back to 0. The evaluator checks a trace as it checks an instance (section 7), relations being looked for in the fixed instance and in every state.

CodeWhenMessage carries
trace.no_statesa trace with no states
trace.loopa loop target that is not a statethe target, L
trace.relationsthe states do not all give tuple sets to the same changing relations, or a state gives one to a fixed relationthe relation

13.4 Finding traces

A command with changing relations or temporal operators has a limit S on steps, 10 unless the command says otherwise, as Alloy’s is (ScopeComputer.java, maxtrace). For L from 1 to S:

  • For L = 1, the loop target is fixed to 0.
  • For L > 1, the circuit allocates L loop-target selector variables after the primary variables, constrained so that exactly one is true, and unrolls (past_depth + 1) copies of the L states (pos = d * L + k for copy d in 0..=past_depth and state k in 0..L). Stepping past state L - 1 multiplexes on the selector variables to (min(d + 1, past_depth), j); stepping back at (d, k) with d > 0 chooses (d - 1, L - 1) when j = k and (d, k - 1) otherwise. One solve rules out every loop target of length L when unsatisfiable; when satisfiable, assumptions on the selector variables in order 0 to L - 1 find the earliest loop target, and enumeration continues in the same order.

In both cases the first trace returned is the shortest, and of those the one that loops back earliest. A command with no changing relation solves only L = 1.

In the circuit (section 12.3), a changing relation has one table per state, and its primary variables come block by block, state by state, at its place in bounds order. The value of a formula is computed per position, on the positions of section 13.3, with and for “every” and or for “some” over the positions the definition visits.

Skolemization (section 12.2) stops below a temporal operator and below a prime: a skolem relation is fixed, and stands for a witness at position 0.

The verdicts of section 12.1 hold with “within the bounds” read as “within the bounds and with at most S states”: holds says no counterexample trace exists up to S states, and vacuous that no trace of the rules does.

13.5 Actions and frames

The model builder declares changing relations and actions (R22). A changing set, top-level or a subset, has its atoms as a fixed set does; which of them it holds may change. A changing relation’s facts from its declaration, being inside its parent or its columns and its multiplicity, hold in every state. An action has a name, parameters each ranging over a set, a guard, and effects on changing relations: add(r, e) gives r' = r + e, remove(r, e) gives r' = r - e, and set(r, e) gives r' = e. Effects on one relation combine in the order written. Every changing relation the action does not name stays as it was: r' = r. That is the frame.

That the action happens with arguments a1, ..., ak is the formula guard and effects and frame with the parameters bound to them. A step is one action happening with some arguments, or a step where every changing relation stays the same. The builder adds the fact always (some step) when the model has actions.

Each step of a trace found is labelled with the first action, in declaration order, and the first arguments, in tuple order, that happen at it, or with “nothing changed”. Step k is the one out of state k: to state k + 1, or for the last state, back to the loop target. The evaluator decides it, at position k with the parameters bound to the arguments.

13.6 Worked examples

Each line is a test. The universe is (A), s is a changing set, and the trace has three states looping to state 1: s is {}, {A}, {}, so the positions show {}, {A}, {}, {A}, {}, and so on.

FormulaValue
some sfalse
after some strue
eventually some strue
always some sfalse
always eventually some strue
eventually always some sfalse
no s until some strue
some s releases no sfalse
once some sfalse
after once some strue
after after before some strue
eventually historically no strue
always (some s implies before no s)true
after (no s since some s)true
some s triggered no strue
s' = sfalse
always not (s' = s)true

14. Answers

Phase 4 (DESIGN.md section 9, R23 to R26, R30 to R33): what a command returns, as data and as text.

14.1 The result

A command of the model builder returns a result. Its JSON form is version 1 of the schema in docs/schema/result-v1.json, which cargo x generate writes and cargo x verify checks is current. Its fields:

FieldHolds
elinvarthe schema version, 1
commandrun or check
namethe command’s name
verdictfound, none, counterexample, holds, proved, vacuous, or unknown
scopefor each top-level set, the most atoms searched; and steps, the most states, for a model with changing relations
shrunk_tofor a counterexample, the scope it was shrunk to (section 14.3)
fully_shrunkwhether shrinking finished within its budget
instancethe instance, without changing relations
tracethe trace: fixed, states, loop_to, and steps, one per state: the action and its arguments, and for each changing relation the tuples it gains and loses
broken_atfor a counterexample to always P, to a block holding only always P, or to A implies always P, the first state where P fails
broken_witnessoptional; for a broken `always all x: S
expectoptional; the command’s expect 0 or expect 1 annotation when present
expect_metoptional; whether the verdict met expect (null when unknown)
notefor unknown, which budget ran out and what is known
errorsevery error, each with code, message, fix, and place
warningsoptional; non-fatal warnings about the model or command (such as wrapped integer literals or step predicates leaving changing relations unconstrained), each with code, message, fix, and place
statsprimary variables, gates, and conflicts
coreoptional; present when --explain / report_explained is used on a holds or vacuous check: { used, unused }, the minimal subset of named rules that suffices to rule out counterexamples; or on a run with no instance: the minimal subset that, with the run’s constraint, allows no instance, or, when the rules alone allow none, the minimal subset of them that allows none, with a note saying so
storythe text of section 14.2

A field with nothing to hold is null, or an empty list. Atoms, relations, and tuples are named, never numbered.

The rules in core carry the names the model gives them. Through the library a fact is the name given to fact_named. In model text it is fact F, or fact n for the nth unnamed fact. A signature’s declaration is sig S: its parent, its children being disjoint and, if it is abstract, covering it, and its multiplicity. A field’s type and multiplicity are field f, and the count a scope adds (section 12.9) is scope S. The frame of a model’s actions is actions. A transition fact in used is split into its step guards, each named step: guard.

14.2 Stories

The text of a result is made from the data, never the other way round. Its first line is the command, the verdict, and the size: for example check NoCycle: COUNTEREXAMPLE with Employee: 2 when shrunk to those atoms, or run Show: found in scope Employee: 3 when an unshrunk instance is found in that scope. Then:

  • An instance: each relation the user declared with its tuples, sets as {A, B} and tuples as A -> B, in declaration order; then each witness of a skolemized quantifier as witness p = Person0.
  • A trace: start, with the fixed relations and the changing relations of state 0 that hold tuples; then one line per step, step k + 1 for the step out of state k (DESIGN.md section 9.5 numbers them so), with its action and arguments, the tuples each changing relation gains and loses, and for the last, the state it loops back to. A model without actions, such as one read from text, names no action; a step that changes nothing says nothing changes.
  • broken at state k, as step k + 1 begins when the result has broken_at.
  • For holds, proved, vacuous, and none, the scope searched, and for vacuous, that the rules allow no case in it. proved states that the promise holds for any number of steps within the scope by k-induction.
  • For unknown (or when an inductive check fell back to bounded traces from a possibly unreachable state), the note.
  • For errors, one line per error: place, code, message, and fix.

14.3 Shrinking

A counterexample from the model builder is shrunk before it is returned (R25). Smaller means fewer states, then fewer atoms, then fewer tuples.

  1. States: the search already returns a shortest trace (section 13.4).
  2. Atoms: for each top-level set in declaration order whose scope is not exact and not one, the check is run again with that set’s scope one less, while a counterexample exists, down to 0.
  3. Tuples: at the scope found, without symmetry breaking, and for the number of states and loop target of the counterexample, the solver’s first counterexample becomes the current one. Then each primary variable true in the current counterexample, in number order, is asked to be false, together with every one asked before and kept; when the solver finds a counterexample so, it becomes the current one and the variable stays false.

Each step’s counterexample is refereed. Shrinking has its own budget, of conflicts over all its solves, 1,000,000 by default; when it runs out, the smallest counterexample so far is returned and fully_shrunk is false.

14.4 In tests

assert_holds runs a check and returns if the verdict is holds. Otherwise it panics, and the panic’s message is the story: a counterexample, vacuous, unknown, or the errors (R26).

15. Model text

Phase 5 (DESIGN.md section 9.4, R34): the subset of Alloy 6 that elinvar-als reads into a model of the builder (section 12.9). A construct outside it is an error that names it, never a wrong answer (DESIGN.md section 9.4).

15.1 What is read

ConstructRead as
//, --, /* */ commentsnothing
modulenothing
sig A {}, abstract sig, one sig, lone sig, some siga top-level set; one a one set; lone and some add the fact lone A or some A
sig B extends A, sig B in Aan extension or a subset
sig A, B {}one declaration per name
var siga changing set
enum E { a, b }an abstract set with a one extension per name
a field f: m e or f: e with arrowsa relation of the signature and the columns of e, each the top-level signature its column ranges over; and the fact, for each this of the signature, that this.f is inside e, with m (one by default for a set, lone, some, or set) and the multiplicities of e’s arrows. e may name the signature’s own fields, read as this.g, as in addr: names -> some Target
fields of one name in several signatureseach its own relation; x.f picks the one whose signature is the type of x’s last column, and a use whose type cannot tell is als.unsupported
var fielda changing relation
a defined field, g = ea relation of the signature and the columns of e, with the fact, for each this, that this.g = e (isIn in TranslateAlloyToKodkod.java at 59ba203). As in any field, a field name in e is read on this, so f.@f is this.f.f, and f.f joins this.f with this.f (Alloy’s name resolution 1, CompModule.java at 59ba203). It cannot be var or disj, as in Alloy
sig A { ... } { F }the fact `all this: A
fact, fact name, fact "name"a fact; a string literal here, or as the name of an assertion, is a name
String, and a string literal "abc" in an expressionString is a top-level set, and each literal of the file a set that extends it, named "abc" with its quotes, as Alloy names its atom. Each command makes the set of a literal it reads, in the facts, the fields, or its own formula and the predicates and functions that formula calls, exactly one atom, and the set of any other literal none; String is exactly the literals the command reads, or exactly N String if N is more, as Alloy’s ScopeComputer.compute gives it at 59ba203 (corpus/language/strings.als). A scope on String that is not exact, and a declaration sig String, are als.syntax, as in Alloy. The atoms past the literals are named String2 and on, where Alloy names them "String0" and on
private before open, pred, fun, let, sig, or a fieldnothing: in Alloy it hides the declaration from a module that opens this one (Vis in Alloy.cup at 59ba203), and a model’s own declarations are all visible to it
a number written 12, 0x0F, 0x_0F, or 0b1_01its value, as Alloy.lex at 59ba203 reads it: hex digits come in pairs, _ is passed over after 0x and 0b, and digits followed by a letter or _ (1_000), or a value above 2^31 - 1, is als.syntax
pred, fun, with parametersinlined at each use: p[a, b], a.p[b], and p with no parameters
predicates and functions of one name, pred A.p, pred B.p, fun f[x: A], fun f[x: B], including those of two modules, such as dom of util/relation and of util/ternaryoverloads, as Alloy keeps them (CompModule.addFunc at 59ba203): a call is to the one with as many parameters as arguments; among several, the one where each argument has its parameter’s arity and shares a top-level set with it in every column. A call whose arguments fit none or more than one is als.arguments. A declaration of the model’s own hides a module’s of one name and number of parameters
a macro, let m[a, b] { F }, let m[a, b] = e, let m { F }, or let m = e, at the top of a fileeach call, m[x, y], x.m[y], x.m with one parameter, or m with none, replaced by the body with each parameter bound to its argument, the arguments read where the call is: a variable of the body never captures one of an argument’s, and a variable bound around a call hides a macro of its name. An argument that is a name stands for itself, so a predicate or function passed by name is applied by p[x] in the body, as util/time’s then and while do: it is put in place of its parameter, unless the body binds a name like it, when it is bound to a fresh name as other arguments are. Its parameters have no type, so an argument may be a formula. The macros of util/time are expanded in the file that opens it. A call with the wrong number of arguments is als.arguments, and a macro that calls itself is als.unsupported
assert name { F }, assert "name" { F }an assertion for check
run, check, with a name, a predicate or assertion, or a blocka command
for N, for N but k A, exactly j B, for k A, j Bscopes of top-level sets; a set the command does not name gets N, or 3 when there is no N, as in Alloy
n steps, m..n stepsat most n states
expect 0, expect 1the expected answer, kept for the corpus: 1 is a counterexample or an instance
operatorsthose of sections 3, 4, and 13, written as in Alloy, with ! for not, && and ||, => and <=>, !=, not in and !in, a[b] for b.a, and F => G else H for formulas and expressions
let x = e | F, let x = e { F }F with x replaced by e
F ; GF and after G (Alloy.cup at 59ba203): looser than every other operator, F ; G ; H being F ; (G ; H), and looser even than a quantifier’s or let’s | body, which stops at it: all x: e | F ; G is (all x: e | F) ; G, and G cannot name x. In a block, { F ; G H } is (F ; G) and H. The grammar leaves both to its conflict resolution; Alloy 6.2.0’s answers to corpus/language/sequence.als settle them
disj[e1, e2, ...]no (e1 & e2) and no ((e1 + e2) & e3) and so on, which says no two share a tuple, built as visit(ExprList) in TranslateAlloyToKodkod.java at 59ba203 builds it; fewer than two arguments is als.arguments. disjoint is a name like any other, as in Alloy 6.2.0, though Alloy.lex lists it as a keyword
an arrow with multiplicities, A m->n B, in a field, a declaration, or on the right of inthe product, and what it says of the relation r it types: each tuple of A picks out n tuples of B in r, each tuple of B m of A, and an arrow inside A or B says the same of the part of r each tuple of the other side picks out, as in (Room -> lone Key) -> Time
disj f, g: e among a signature’s fieldsfor each atom of the signature, f and g hold no tuple in common
all disj x, y: e | Fx and y differ
univ, iden, nonethe builder’s univ and iden (section 12.9), and none
open util/ordering[S], open util/ordering[S] as oan ordering on the signature S, top-level or not, or a subset of a union of signatures (section 12.9), with Alloy’s first, last, next, prev, nexts, prevs, lt, gt, lte, gte, larger, smaller, max, and min (util/ordering.als at the pinned commit), called as o/next or, with no declaration of the name, as next. With several orderings open, next alone means the one whose set is the type of what it meets: the last column of the left side of a join, the first column of the other side of any other operator, the parameter’s signature for a call’s argument, and the first column of the argument of min [e] and the like
a subset of a union of signatures, sig C in A + B { ... }, and a subset of ita relation of arity 1 over the sets of A and B, with the fact C in A + B and its multiplicity; its fields range over the same sets. A signature that extends a subset signature is an error (als.syntax), as in Alloy (CompModule.java at 59ba203)
a field over a union of signatures, f: set A + Ba relation whose column ranges over the top-level sets of A and B
a field named in several signaturesthe one the type of what it meets picks out, on either side of a join or a restriction and under ^, *, and ~
open util/relation, open util/graph[S], open util/boolean, open util/ternary, open util/natural, open util/time, open util/sequence[E], open util/seqrel[E], open util/history[Tick], with or without astheir predicates, functions, and signatures, in Elinvar’s own statement of them (crates/elinvar-als/src/modules/), with Alloy’s names and parameters (plus Elinvar’s util/history[Tick] for timestamped append-only histories, which also opens util/ordering[Tick]); called as alias/name or name, a declaration of the model’s own winning over a module’s of one name and number of parameters. The ordering a module opens for itself (util/natural’s of Natural, util/sequence’s and util/seqrel’s of SeqIdx) is the module’s own, as in Alloy: an unqualified first or next in the model means the model’s ordering when it has one. A call of an ordering’s function is one when no declaration of the name takes as many arguments, so first beside util/sequence’s first[s] is the ordering’s
open m [A, B] as a of the model’s own module mthe module’s signatures, fields, facts, predicates, functions, and assertions, each named a/name, with the module’s parameters read as A and B, and a module it opens as b named a/b; its commands are not the model’s. The file is found beside the opening one, as Alloy finds it: the opening file’s own module name says how deep it sits. A name used without its module means the one declaration that ends in /name; a field so named among several is chosen by type
module m [A, B] heading the model itselfA and B are signatures, unless the model declares them
a number, #e, sum x: e | n, int[e], int e, Int[n], and Intthe integers of section 16: Int is the builder’s set of integer atoms, made the first time a model uses an integer. As in Alloy, which casts the same way (TranslateAlloyToKodkod, toInt and toSet at 59ba203), a set where an integer belongs is the sum of its integer atoms, and an integer where a set belongs is its atom
a < b, a > b, a =< b and a <= b, a >= b, each negated by ! or notinteger comparisons (section 16.3)
a = b, a != binteger comparison when both sides are integers, and set equality otherwise, an integer side cast to its atom. + and - are always union and difference, of integers too, as in Alloy (ExprBinary.java at 59ba203: “these are always relational operators now”): #a = #b + 1 compares the set Int[#a] with Int[#b] + Int[1]
for 5 Int, for 5 inta bitwidth of 5 for the command; 4 without one, as in Alloy
the functions and predicates of util/integer, which Alloy opens in every module, so that open util/integer adds nothing: add, plus, sub, minus, mul, div, rem, negate, signum, larger, smaller, eq, gt, lt, gte, lte, zero, pos, neg, nonpos, nonneg, max, min, next, prev, prevs, nexts, and int2elem and elem2int, the element at a place in an order and the place of an element (also qualified as int/... or integer/...), called as f[a, b], a.f[b], or a.ftheir meaning in util/integer.als at 59ba203, unless the model declares the name
a << b, a >> b, a >>> bthe shifts of section 16.2, each side read as an integer; they bind looser than + and - and tighter than the comparisons, left to right, as ShiftExprB in Alloy.cup at 59ba203 has them
sequences: seq T in fields (f: seq T, var f: seq T) and declarations, seq/Int, for N seq (default 4, capped by bitwidth), and the functions and predicates of util/sequniv: isSeq, elems, first, last, rest, butlast, isEmpty, hasDups, inds, lastIdx, afterLastIdx, idxOf, lastIdxOf, indsOf, add, setAt, insert, delete, append, subseq (also qualified as seq/..., and after open util/sequniv or open util/sequniv as a as sequniv/... or a/...)a relation seq/Int -> lone T covering a contiguous prefix of seq/Int from 0, with each helper defined as in util/sequniv.als at 59ba203
a scope on a module’s signature, as 3 msg/Tickthe scope of that signature
open util/graph[A] and open util/graph[B], a library module opened with two lists of argumentstwo modules, as Alloy makes one for each list: each copy’s declarations are named alias/name. Two opens of util/ordering on one set are one ordering
this/AA
@f in a signature factthe field f itself, not this.f
a file without commandsAlloy’s default command, run {} named Default, with the warning als.default_command
(an option, off by default)a set Int of exactly 16 atoms in every command, the integers Alloy puts in every universe (section 10), so that univ, iden, and * range over what they do in Alloy; the comparison with Alloy reads models so

15.2 What is not read

The unbounded 1.. steps and a growing scope on a signature (for 1..3 A, for 1..9:2 A, which Alloy grows from solve to solve, carrying each instance into the next: execute_greedyCommand in TranslateAlloyToKodkod.java at 59ba203), each an error of that command alone, when it runs, while the file’s other commands run, open of a library module other than util/ordering, util/relation, util/graph, util/boolean, util/ternary, util/natural, util/history, util/time, util/sequence, util/seqrel, util/integer, and util/sequniv, or of a model’s own module whose file is not found (model text given without a file, as over MCP, has none), two sequence modules (util/sequence and util/seqrel, or one of them with two arguments, which Alloy keeps apart as two modules with a SeqIdx each), a declaration over sets or relations that skolemization cannot remove (an error of the logic, logic.higher_order), a field whose columns cannot be told apart by signature, an overloaded field or an ordering’s function whose meaning the type does not settle, scopes on signatures declared in another (which Alloy refuses too: ScopeComputer.java at 59ba203), and functions, predicates, and macros that call themselves. Each is als.unsupported, with the construct and the line.

15.3 Errors

CodeWhenMessage carries
als.syntaxtext that is not Alloy, or not this subset’s grammarwhat was expected, what was found
als.unknown_namea name that is no signature, field, predicate, function, parameter, or variable in scopethe name
als.unsupporteda construct of section 15.2the construct
als.sorta formula where an expression belongs, or the other way roundwhat was expected
als.duplicatetwo declarations of one namethe name
als.argumentsa predicate or function called with the wrong number of arguments, or with arguments whose types fit none or more than one of its overloadsboth numbers, or the number of overloads and of those that fit
als.no_commanda command name the file does not havethe name
eval.resultelinvar eval is given a result it cannot read as an instance or trace of the modelwhat is missing
sql.skippedelinvar import --strict found a SQL statement or constraint the importer does not readthe skipped SQL and reason
sql.scriptelinvar accepts is given a SQL DML script containing a statement or expression it cannot readthe line number and unsupported form
sql.databaseelinvar fuzz could not run the external database command given to --against or the database rejected the schemathe command and database error
als.int_wrapwarning: an integer literal written in the model does not fit the command’s Int bitwidth and wrapsthe literal, bitwidth, range, and wrapped value
als.unframed_varwarning: a step predicate primes some var relation(s) while leaving another var relation unconstrainedthe predicate and unconstrained relation names
als.default_commandwarning: the file has no command, so Alloy’s default, run {} named Default, was runthe default command
als.empty_by_typewarning: a join or comparison combines expressions whose column types never overlapthe operator and the disjoint types

Every error’s place is the file, line, and column in the model text. The errors of the logic, such as arity.mismatch, carry the place of the text that built the node.

16. Integers

Integers are bounded and wrap around, as Alloy’s are (REQUIREMENTS.md section 6 no longer leaves them out: decided with the user on 2026-11-28, DESIGN.md section 13).

16.1 Bitwidth and integer atoms

A universe has a bitwidth w, from 1 to 32, and gives some of its atoms an integer each. A universe made from atom names alone has bitwidth 4, as Kodkod’s default is, and no integer atoms. The integers of bitwidth w are those from -2^(w-1) to 2^(w-1) - 1. Each integer atom’s integer is one of them, and no two integer atoms have the same integer. A bitwidth outside 1 to 32 is an error (universe.bitwidth), and so is an integer atom whose integer is out of range, a second atom for one integer, or a second integer for one atom (universe.int).

To wrap a number is to keep the w low bits of its two’s complement and read them back as a signed number: 8 wraps to -8 at bitwidth 4, and -9 to 7. Every integer expression denotes a wrapped number.

16.2 Integer expressions

ExpressionDenotes
k, a numberk wrapped
#ethe number of tuples of e, wrapped: at bitwidth 4, #e of 8 tuples is -8
sum e, e a setthe sum of the integers of e’s integer atoms, wrapped; its other atoms add nothing
a + b, a - b, a * bthe sum, difference, and product, wrapped
a / b, a % b, b not 0the quotient rounded toward zero, and the remainder a - (a / b) * b, which has the sign of a, both wrapped: -7 / 2 is -3 and -7 % 2 is -1, and -8 / -1 is -8 at bitwidth 4
a / 0, a % 0a / 0 is -1 when a is positive, 1 when it is negative, and 0 when it is 0; a % 0 is a. This is what Kodkod’s division circuit gives (TwosComplementInt.nonRestoringDivision at 6e80244), worked out bit by bit at bitwidths 3, 4, and 5 for every pair, which also agree with the row above when b is not 0
a << b, a >> b, a >>> bwith m the number of bits of w - 1 (2 at bitwidth 4, 3 at bitwidth 5, 0 at bitwidth 1) and n the m low bits of b read as an unsigned number: a << b is a * 2^n wrapped; a >> b is a / 2^n rounded down, keeping the sign; a >>> b is the w bits of a read as an unsigned number, divided by 2^n and rounded down, then wrapped. When n is at least w, which happens only when w is not a power of two, a << b and a >>> b are 0, and a >> b is -1 when a is negative and 0 otherwise. At bitwidth 4: 3 << 2 is -4, -8 >> 1 is -4, -8 >>> 1 is 4, 1 << 4 is 1 (n is 0), and 1 << -1 is -8 (n is 3); at bitwidth 5, 1 << 5 is 0 and 1 << 8 is 1. This is what Pardinus’s shifters give (TwosComplementInt.shl and shr at d3e7aea, which Alloy 6.2.0 runs; Kodkod’s at 6e80244 use every bit of b), and Alloy 6.2.0’s answers to corpus/language/shifts.als agree; Alloy’s >> is sha and >>> is shr (ExprBinary.Op and TranslateAlloyToKodkod.visit(ExprBinary) at 59ba203)
-a0 - a, wrapped
F => a else ba where F is true, b where it is false
sum x1: e1, ..., xm: em | n, and sum disj x, y: e | n, which adds n only where the variables differ (ExprQt.desugar at 59ba203)the sum of n over the bindings of the declarations, each of one atom (section 5), wrapped; 0 when there are none

A sum is wrapped once, at the end, which is the same as wrapping each addition. sum e of an expression whose arity is not 1 is ill-formed (arity.not_a_set), and so is a declaration of sum x: ... over sets or relations (logic.higher_order).

16.3 Comparisons and the set of an integer

a = b, a < b, a =< b, a > b, and a >= b compare the values of two integer expressions as signed numbers. Int[n] is an expression of arity 1: the integer atom whose integer is the value of n, or the empty set when no atom has it.

16.4 Integers in the circuit

An integer expression becomes w boolean values, its bits in two’s complement, the least significant first (section 12.3). Every operation keeps only w bits, which wraps. Building them uses the circuit’s xor and maj gates (section 12.3) and ite(c, x, y), which is (c and x) or (not c and y).

  • A number’s bits are constants.
  • a + b adds bit by bit from bit 0 with a carry, first false: bit i is xor(xor(ai, bi), ci) and the next carry maj(ai, bi, ci). a - b is the same with not bi and a first carry of true. -a is 0 - a.
  • a * b starts from 0 and, for each bit i of b from 0, adds the number whose bit j is bi and a(j-i) for j >= i and false below.
  • a / b and a % b divide the magnitudes. With s the sign bit of a, t that of b, |a| is ite(s, -a, a) on w + 1 bits, so that 2^(w-1) fits, and the same for |b|. Long division from the top bit of |a| down gives the magnitudes q and r: the remainder so far, shifted left with the next bit of |a| in, is compared with |b|, and where it is not less, |b| is subtracted and the quotient bit is true. Then a / b is ite(xor(s, t), -q, q) and a % b is ite(s, -r, r), both on their w low bits; and where every bit of b is false, a / b is -1, 1, or 0 by the sign of a, and a % b is a.
  • a << b, a >>> b, and a >> b shift in stages, as Pardinus’s barrel shifter does: starting from a, for each bit i of b from 0 to m - 1 (section 16.2), the value becomes ite(bi, shifted, value), where shifted moves every bit by 2^i: for << bit j takes bit j - 2^i, false below; for >>> bit j takes bit j + 2^i, false above; for >> the same with the sign bit of a above.
  • #e sums the entries of e’s table, in index order, with a balanced binary tree of adders (as Kodkod’s BooleanFactory.sum does), each subtree wide enough for its count up to w bits, zero-extended to w. sum e sums, in a balanced binary tree over integer atoms in index order, ite of each atom’s entry with its integer and 0. sum x: e | n sums, in a balanced binary tree over bindings as quantifiers ground them, ite of each binding’s guard with n under it and 0.
  • F => a else b is ite bit by bit.
  • a = b is the and of not xor(ai, bi) over the bits. a < b is true where the sign bits differ and a’s is true, or where they agree and a is less as an unsigned number, which is decided at the highest bit where they differ. a =< b is a < b or a = b, and > and >= swap the operands.
  • Int[n]’s entry for an integer atom is whether n equals its integer; for every other atom, false.

Integer atoms are told apart by their integers, so no two of them are interchangeable in symmetry breaking (section 12.5), and none of them is interchangeable with an atom that is not an integer. The upper approximation of Int[n] in skolemization is univ, which holds every integer atom: no relation holds just them.