Expand description
Elinvar: find the holes in a design before you build it.
A relational model finder: given bounds on relations and a formula,
run finds an instance and check finds a counterexample, through a
boolean circuit and a SAT solver. Every instance is refereed by the
evaluator of elinvar-logic before it is returned (AGENTS.md law 13).
This crate is the one to depend on and to install: it re-exports the
engine (elinvar-engine), the Alloy reader as als, and the logic as
logic, and cargo install elinvar builds the elinvar command line
(DESIGN.md section 5.3).
use elinvar::prelude::*;
let mut m = Model::new();
let person = m.set("Person");
let knows = m.field("knows", &person, &person);
// Nobody knows themselves: broken by a self-loop.
let no_self = knows.intersection(&Expr::iden()).no();
let report = m.check(&no_self).named("NoSelf").scope(3).report();
assert_eq!(report.verdict, Some(Verdict::Counterexample));
// Add the missing rule and check again.
m.fact(no_self.clone());
let report = m.check(&no_self).named("NoSelf").scope(3).report();
assert_eq!(report.verdict, Some(Verdict::Holds));Re-exports§
pub use elinvar_als as als;
Modules§
- logic
- The relational logic of Elinvar, and its evaluator.
- prelude
- What a model written in Rust needs, in one import (R23):
use elinvar_engine::prelude::*;. - sat
- The solver trait and Elinvar’s own conflict-driven solver (LOGIC.md section 12.8, DESIGN.md section 7.4).
Structs§
- Action
- A named step with parameters (LOGIC.md 13.5).
- Change
- What a changing relation gains and loses in one step.
- Command
- A
runorcheckwith its scope. - Diff
Report - The result of comparing two models (
diff_models). - Finder
- A search for the instances, or traces, of one problem, one after another. With changing relations, it tries the shapes of LOGIC.md 13.4 in order: by number of states, then by loop target.
- Holds
Core - Which named rules were used to establish a
holdsorvacuousverdict (REQUIREMENTS.md section 8). Dropping every rule inunusedleaves the check unsatisfiable; dropping any rule inusedcan break it. - Instance
Iter - An iterator over every instance (or trace) of a
Commandup to symmetry breaking (N16). CallInstanceIter::hit_budgetafter iteration to check whether enumeration finished completely or stopped at the solver budget. - Model
- A model: sets, relations, actions, and facts.
- Options
- How a search runs.
- Ordering
- An ordering of a set’s atoms (LOGIC.md 12.9):
firstandnext. - Outcome
- The answer to
runorcheck. - Report
- The result of a command (LOGIC.md 14.1).
- Sizes
- Sizes by name, in declaration order, written as a JSON object.
- Stats
- The size of a translation and the work of its solves.
- Step
- What an action does: its guard and its effects (LOGIC.md 13.5).
- Step
Guard - One guard condition inside a step predicate (N11, N14).
- Step
Label - What happened at one step of a trace (LOGIC.md 13.5): an action and its arguments, or nothing.
- Step
Report - One step of a trace: out of state
step, to the next state or, for the last, back to the loop target. - Step
Spec - Structured decomposition of one step arm in a transition fact (N11, N14, W14).
- Test
Case - One generated test case from
Model::generate_tests(N11). - Trace
Report - A trace as the result gives it.
Enums§
- Diagram
Format - Output format for
render_instance,render_trace, andrender_report. - Diff
Verdict - How
newdiffers fromoldup to the searched scope. - Next
- What the next solve gave.
- Test
Kind - Outcome kind of one generated test case (N11, B22).
- Verdict
- What a search concluded (DESIGN.md section 7.6).
Constants§
- MODEL_
CODES - The engine’s own error codes, beside those of the logic.
- RESULT_
SCHEMA - The JSON Schema of the result, version 1 (LOGIC.md 14.1).
cargo x generatewrites it todocs/schema/result-v1.json. - RESULT_
VERSION - The version of the result’s JSON schema (LOGIC.md 14.1).
- SHRINK_
CONFLICTS - The default budget of shrinking, in conflicts over all its solves (LOGIC.md 14.3).
Functions§
- check
- Looks for a counterexample to
assertionunderruleswithinbounds; when there is none, tellsholdsfromvacuous(LOGIC.md 12.1 and 13.4). - check_
with_ solver - Like
check, using a solver built bymake_solver(R9, DESIGN.md section 7.4). Every returned instance or trace is still refereed byelinvar-logic. - codes
- Every error code, the logic’s then the engine’s.
- count
- The number of instances, or traces, of
formulawithinbounds, by the solver, up tolimit.Noneif the budget ran out first. With symmetry breaking off and no changing relations, this is the count brute force gives (R18). - count_
bitsliced - The number of instances within
boundsunder whichformulais true, aselinvar_logic::countgives it (LOGIC.md section 8), with at mostcapfree tuples. - count_
with_ solver - Like
count, using a solver built bymake_solver(R9, DESIGN.md section 7.4). - diff_
functions - Compares the tuples returned by a function expression
old_exprinoldagainstnew_exprinnewover cases allowed by both models (W10). - diff_
models - Compares two models sharing the same signatures and fields, up to
scopeandoptions, returning aDiffReportwith shrunk witnesses for any cases allowed by one model and forbidden by the other. - diff_
models_ with_ bitwidth - Like
diff_models, usingbitwidthfor boundedIntatoms on both sides (used, for example, when comparing two imported SQL schemas whose integer literals need more than 4 bits). - explain
- The explanation of an error code, from the logic’s codes or the engine’s (AGENTS.md law 21).
- explain_
core - Extracts a minimal subset of
rulesthat suffices to rule out any counterexample toassertionwithinbounds(REQUIREMENTS.md section 8). - render_
instance - Renders a single static
Instanceas Graphviz DOT, Mermaid, or SQL. - render_
instance_ sql_ with_ values - Renders a single static
Instanceas executable SQL usingsample_values("table.col"-> sample strings) for uninterpreted text columns (B16). - render_
model - Renders a
Model’s structure (signatures, fields, and registered step predicates with their guards) as Mermaid or Graphviz DOT (W14). - render_
report - Renders a
Report’s instance or trace as Graphviz DOT or Mermaid. - render_
report_ sql_ with_ values - Renders a
Report’s instance or trace as executable SQL using optionalsample_values("table.col"-> sample strings) for uninterpreted text columns (B16). - render_
states - Renders a sequence of trace
statessharingfixedrelations (one state ifstateisSome, or every state as a subgraph ifstateisNone). - render_
states_ sql_ with_ values - Renders a sequence of trace
statessharingfixedrelations as executable SQL usingsample_values("table.col"-> sample strings) for uninterpreted text columns (B16). - render_
trace - Renders a
TraceReport(one state ifstateisSome, or every state as a subgraph with step labels ifstateisNone). - run
- Looks for an instance of
formulawithinbounds; with changing relations, a trace of at mostoptions.stepsstates. - run_
with_ solver - Like
run, using a solver built bymake_solver(R9, DESIGN.md section 7.4). Every returned instance or trace is still refereed byelinvar-logic. - story
- LOGIC.md 14.2: the text of a result, made from its data.
- story_
brief - A brief version of
storythat omits empty relations and library ordering relations (first,next), showing only signatures and fields that hold atoms or tuples. - symmetry_
partition - The parts of the universe: atoms that no bound tells apart, each part in atom order, parts in the order of their first atom.
- tuples_
named - The tuple set of a relation by name in an instance, for tests and renderings.