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 simd;
37mod skolem;
38mod solve;
39mod symmetry;
40mod tests_gen;
41mod translate;
42
43#[cfg(feature = "bitslice")]
44pub use bitslice::count_bitsliced;
45pub use diff::{DiffReport, DiffVerdict, diff_functions, diff_models, diff_models_with_bitwidth};
46pub use elinvar_logic as logic;
47pub use model::{
48    Action, Command, InstanceIter, MODEL_CODES, Model, Ordering, Step, StepGuard, StepSpec,
49};
50pub use render::{
51    DiagramFormat, render_instance, render_instance_sql_with_values, render_model, render_report,
52    render_report_sql_with_values, render_states, render_states_sql_with_values, render_trace,
53};
54pub use report::{
55    Change, RESULT_SCHEMA, RESULT_VERSION, Report, SHRINK_CONFLICTS, Sizes, StepReport,
56    TraceReport, story, story_brief,
57};
58pub use tests_gen::{TestCase, TestKind};
59
60/// The explanation of an error code, from the logic's codes or the
61/// engine's (AGENTS.md law 21).
62pub fn explain(code: &str) -> Option<&'static logic::Code> {
63    logic::explain(code).or_else(|| MODEL_CODES.iter().find(|c| c.code == code))
64}
65
66/// Every error code, the logic's then the engine's.
67pub fn codes() -> impl Iterator<Item = &'static logic::Code> {
68    logic::CODES.iter().chain(MODEL_CODES)
69}
70pub use solve::{
71    Finder, HoldsCore, Next, Options, Outcome, Stats, StepLabel, Verdict, check, check_with_solver,
72    count, count_with_solver, explain_core, run, run_with_solver, tuples_named,
73};
74pub use symmetry::partition as symmetry_partition;