Skip to main content

elinvar_engine/
lib.rs

1//! Elinvar: find the holes in a design before you build it.
2//!
3//! A relational model finder: given bounds on relations and a formula,
4//! `run` finds an instance and `check` finds a counterexample, through a
5//! boolean circuit and a SAT solver. Every instance is refereed by the
6//! evaluator of `elinvar-logic` before it is returned (AGENTS.md law 13).
7//!
8//! ```
9//! use elinvar_engine::prelude::*;
10//!
11//! let mut m = Model::new();
12//! let person = m.set("Person");
13//! let knows = m.field("knows", &person, &person);
14//!
15//! // Nobody knows themselves: broken by a self-loop.
16//! let no_self = knows.intersection(&Expr::iden()).no();
17//! let report = m.check(&no_self).named("NoSelf").scope(3).report();
18//! assert_eq!(report.verdict, Some(Verdict::Counterexample));
19//!
20//! // Add the missing rule and check again.
21//! m.fact(no_self.clone());
22//! let report = m.check(&no_self).named("NoSelf").scope(3).report();
23//! assert_eq!(report.verdict, Some(Verdict::Holds));
24//! ```
25
26#[cfg(feature = "bitslice")]
27mod bitslice;
28mod circuit;
29mod coi;
30mod diff;
31mod model;
32pub mod prelude;
33mod render;
34mod report;
35pub mod sat;
36mod skolem;
37mod solve;
38mod symmetry;
39mod tests_gen;
40mod translate;
41
42#[cfg(feature = "bitslice")]
43pub use bitslice::count_bitsliced;
44pub use diff::{DiffReport, DiffVerdict, diff_functions, diff_models, diff_models_with_bitwidth};
45pub use elinvar_logic as logic;
46pub use model::{
47    Action, Command, InstanceIter, MODEL_CODES, Model, Ordering, Step, StepGuard, StepSpec,
48};
49pub use render::{
50    DiagramFormat, render_instance, render_instance_sql_with_values, render_model, render_report,
51    render_report_sql_with_values, render_states, render_states_sql_with_values, render_trace,
52};
53pub use report::{
54    Change, RESULT_SCHEMA, RESULT_VERSION, Report, SHRINK_CONFLICTS, Sizes, StepReport,
55    TraceReport, story, story_brief,
56};
57pub use tests_gen::{TestCase, TestKind};
58
59/// The explanation of an error code, from the logic's codes or the
60/// engine's (AGENTS.md law 21).
61pub fn explain(code: &str) -> Option<&'static logic::Code> {
62    logic::explain(code).or_else(|| MODEL_CODES.iter().find(|c| c.code == code))
63}
64
65/// Every error code, the logic's then the engine's.
66pub fn codes() -> impl Iterator<Item = &'static logic::Code> {
67    logic::CODES.iter().chain(MODEL_CODES)
68}
69pub use solve::{
70    Finder, HoldsCore, Next, Options, Outcome, Stats, StepLabel, Verdict, check, check_with_solver,
71    count, count_with_solver, explain_core, run, run_with_solver, tuples_named,
72};
73pub use symmetry::partition as symmetry_partition;