Skip to main content

Crate elinvar_engine

Crate elinvar_engine 

Source
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).

use elinvar_engine::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_logic as logic;

Modules§

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 run or check with its scope.
DiffReport
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.
HoldsCore
Which named rules were used to establish a holds or vacuous verdict (REQUIREMENTS.md section 8). Dropping every rule in unused leaves the check unsatisfiable; dropping any rule in used can break it.
InstanceIter
An iterator over every instance (or trace) of a Command up to symmetry breaking (N16). Call InstanceIter::hit_budget after 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): first and next.
Outcome
The answer to run or check.
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).
StepGuard
One guard condition inside a step predicate (N11, N14).
StepLabel
What happened at one step of a trace (LOGIC.md 13.5): an action and its arguments, or nothing.
StepReport
One step of a trace: out of state step, to the next state or, for the last, back to the loop target.
StepSpec
Structured decomposition of one step arm in a transition fact (N11, N14, W14).
TestCase
One generated test case from Model::generate_tests (N11).
TraceReport
A trace as the result gives it.

Enums§

DiagramFormat
Output format for render_instance, render_trace, and render_report.
DiffVerdict
How new differs from old up to the searched scope.
Next
What the next solve gave.
TestKind
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 generate writes it to docs/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 assertion under rules within bounds; when there is none, tells holds from vacuous (LOGIC.md 12.1 and 13.4).
check_with_solver
Like check, using a solver built by make_solver (R9, DESIGN.md section 7.4). Every returned instance or trace is still refereed by elinvar-logic.
codes
Every error code, the logic’s then the engine’s.
count
The number of instances, or traces, of formula within bounds, by the solver, up to limit. None if 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 bounds under which formula is true, as elinvar_logic::count gives it (LOGIC.md section 8), with at most cap free tuples.
count_with_solver
Like count, using a solver built by make_solver (R9, DESIGN.md section 7.4).
diff_functions
Compares the tuples returned by a function expression old_expr in old against new_expr in new over cases allowed by both models (W10).
diff_models
Compares two models sharing the same signatures and fields, up to scope and options, returning a DiffReport with shrunk witnesses for any cases allowed by one model and forbidden by the other.
diff_models_with_bitwidth
Like diff_models, using bitwidth for bounded Int atoms 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 rules that suffices to rule out any counterexample to assertion within bounds (REQUIREMENTS.md section 8).
render_instance
Renders a single static Instance as Graphviz DOT, Mermaid, or SQL.
render_instance_sql_with_values
Renders a single static Instance as executable SQL using sample_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 optional sample_values ("table.col" -> sample strings) for uninterpreted text columns (B16).
render_states
Renders a sequence of trace states sharing fixed relations (one state if state is Some, or every state as a subgraph if state is None).
render_states_sql_with_values
Renders a sequence of trace states sharing fixed relations as executable SQL using sample_values ("table.col" -> sample strings) for uninterpreted text columns (B16).
render_trace
Renders a TraceReport (one state if state is Some, or every state as a subgraph with step labels if state is None).
run
Looks for an instance of formula within bounds; with changing relations, a trace of at most options.steps states.
run_with_solver
Like run, using a solver built by make_solver (R9, DESIGN.md section 7.4). Every returned instance or trace is still refereed by elinvar-logic.
story
LOGIC.md 14.2: the text of a result, made from its data.
story_brief
A brief version of story that 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.