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

Quick start

This page takes you from zero to finding and fixing your first design bug in a few minutes.

1. Install Elinvar

Elinvar is a single Rust binary with no Java, Python, or C runtime required.

cargo install elinvar
elinvar --version

(Or from a local checkout: cargo install --path crates/elinvar. A tagged release also has binary archives on the releases page.)

Check that it runs cleanly. You can get help for any command with elinvar --help or elinvar <verb> --help.

2. Check your first design

Suppose you are designing a company reporting tree:

  • Each employee has at most one manager.
  • Rule: nobody can be their own manager.
  • Promise: following managers upward from anyone always reaches someone at the top (someone with no manager).

Save this as hierarchy.als (or pipe it directly into elinvar with -):

sig Employee {
  manager: lone Employee
}

fact NoSelfManager {
  no e: Employee | e = e.manager
}

assert EveryoneHasATop {
  all e: Employee | some top: Employee | top in e.*manager and no top.manager
}

check EveryoneHasATop for 3

Run it:

elinvar check hierarchy.als

Output (exit code 1):

check EveryoneHasATop: COUNTEREXAMPLE with Employee: 2
  Employee = {Employee0, Employee1}
  manager = {Employee0 -> Employee1, Employee1 -> Employee0}
  witness e = Employee1
  searched every case up to Employee: 3.

Elinvar found the bug right away and shrank it to the smallest possible case: two employees managing each other in a cycle. Neither is their own manager, yet neither reaches the top.

You can also pipe a model straight from stdin without saving a file:

elinvar check - <<'EOF'
sig Employee { manager: lone Employee }
fact NoSelfManager { no e: Employee | e = e.manager }
assert EveryoneHasATop {
  all e: Employee | some top: Employee | top in e.*manager and no top.manager
}
check EveryoneHasATop for 3
EOF

3. Visualize the counterexample

Pipe the JSON output into elinvar render to get a Mermaid diagram (or Graphviz --dot):

elinvar check hierarchy.als --json | elinvar render - --mermaid
flowchart LR
  n_Employee0["Employee0 (Employee)"]
  n_Employee1["Employee1 (Employee, $e)"]
  n_Employee0 -->|"manager"| n_Employee1
  n_Employee1 -->|"manager"| n_Employee0

4. Fix the design and verify

Replace NoSelfManager with a rule that forbids all cycles (e in e.^manager), and ask Elinvar to explain which rules did the work using --explain:

sig Employee {
  manager: lone Employee
}

fact Acyclic {
  no e: Employee | e in e.^manager
}

fact Redundant {
  no e: Employee | e = e.manager
}

assert EveryoneHasATop {
  all e: Employee | some top: Employee | top in e.*manager and no top.manager
}

check EveryoneHasATop for 4
elinvar check hierarchy.als --explain

Output (exit code 0):

check EveryoneHasATop: holds
  searched every case up to Employee: 4; a larger case might still break it.
  used rules: field manager, fact Acyclic
  unused rules: fact Redundant

Not only does the promise now hold up to 4 employees, --explain also spots that Redundant was unnecessary once Acyclic was in place.

5. Understand the four verdicts

Every elinvar check ends with one of four verdicts:

VerdictExit codeWhat it means
holds0No counterexample exists up to the scope searched. Strong evidence, not an unbounded proof: raise --scope if you want to search larger cases.
counterexample1A real case breaks your promise. Every counterexample is double-checked by an independent evaluator and shrunk to the fewest steps, atoms, and links.
vacuous2Your rules contradict each other and allow no valid case at all. Nothing can break the promise only because nothing is allowed. Run with --explain to see which rules conflict.
unknown2The solver ran out of its conflict budget before finishing. Raise --budget or reduce --scope.

A fifth exit code, 3, means the model or command has an error (syntax, unknown name, type/arity mismatch). Every error includes a code, file and line, and a suggested fix; run elinvar explain CODE for details.

Next steps