About
easy-smt is a crate for interacting with an SMT solver subprocess. This crate
provides APIs for
- building up expressions and assertions using the SMT-LIB 2 language,
- querying an SMT solver for solutions to those assertions,
- and inspecting the solver's results.
easy-smt works with any solver, as long as the solver has an interactive REPL
mode. You just tell easy-smt how to spawn the subprocess.
Example
use ;
Debugging
Displaying S-Expressions
Want to display an S-Expression that you've built up to make sure it is what you
expect? You can use the easy_smt::Context::display method:
use ContextBuilder;
let ctx = new.build.unwrap;
let my_s_expr = ctx.list;
let string = format!;
assert_eq!;
Logging Solver Interactions
Need to debug exactly what is being sent to and received from the underlying
solver? easy-smt uses the log crate and logs all communication with the
solver at the TRACE log level.
For example, you can use env_logger to see the log messages. Initialize the
logger at the start of main:
And then run your program with the RUST_LOG="easy_smt=trace" environment
variable set to see the TRACE logs:
$ RUST_LOG="easy_smt=trace" cargo run --example sudoku
[2023-01-09T23:41:05Z TRACE easy_smt::solver] -> (set-option :print-success true)
[2023-01-09T23:41:05Z TRACE easy_smt::solver] <- success
[2023-01-09T23:41:05Z TRACE easy_smt::solver] -> (set-option :produce-models true)
[2023-01-09T23:41:05Z TRACE easy_smt::solver] <- success
[2023-01-09T23:41:05Z TRACE easy_smt::solver] -> (set-option :produce-unsat-cores true)
[2023-01-09T23:41:05Z TRACE easy_smt::solver] <- success
[2023-01-09T23:41:05Z TRACE easy_smt::solver] -> (declare-fun cell_0_0 () Int)
[2023-01-09T23:41:05Z TRACE easy_smt::solver] <- success
[2023-01-09T23:41:05Z TRACE easy_smt::solver] -> (assert (and (> cell_0_0 0) (<= cell_0_0 9)))
[2023-01-09T23:41:05Z TRACE easy_smt::solver] <- success
[2023-01-09T23:41:05Z TRACE easy_smt::solver] -> (declare-fun cell_0_1 () Int)
[2023-01-09T23:41:05Z TRACE easy_smt::solver] <- success
[2023-01-09T23:41:05Z TRACE easy_smt::solver] -> (assert (and (> cell_0_1 0) (<= cell_0_1 9)))
[2023-01-09T23:41:05Z TRACE easy_smt::solver] <- success
...
Replaying Solver Interactions
You can save all commands that are being sent to the solver to a file that you can replay without needing to dynamically rebuild your expressions, assertions, and commands.
use ContextBuilder;
Inspiration
Inspired by the simple-smt
haskell package.