{"id":13749097,"url":"https://github.com/oeb25/smtlib-rs","last_synced_at":"2025-04-11T03:30:50.082Z","repository":{"id":65144880,"uuid":"556689610","full_name":"oeb25/smtlib-rs","owner":"oeb25","description":"A high-level API for interacting with SMT solvers.","archived":false,"fork":false,"pushed_at":"2025-03-19T12:11:49.000Z","size":383,"stargazers_count":28,"open_issues_count":8,"forks_count":12,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-09T15:08:02.197Z","etag":null,"topics":["rust","smt","smtlib"],"latest_commit_sha":null,"homepage":"https://crates.io/crates/smtlib","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/oeb25.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-10-24T10:23:41.000Z","updated_at":"2025-03-26T04:08:32.000Z","dependencies_parsed_at":"2024-05-02T14:11:22.532Z","dependency_job_id":"f16edb76-d8ef-4a5d-8f98-bb8e851977cc","html_url":"https://github.com/oeb25/smtlib-rs","commit_stats":{"total_commits":32,"total_committers":1,"mean_commits":32.0,"dds":0.0,"last_synced_commit":"111b76823f22fdd6d3465ea6d3962f45351b0dd1"},"previous_names":[],"tags_count":16,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oeb25%2Fsmtlib-rs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oeb25%2Fsmtlib-rs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oeb25%2Fsmtlib-rs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oeb25%2Fsmtlib-rs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/oeb25","download_url":"https://codeload.github.com/oeb25/smtlib-rs/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248335355,"owners_count":21086578,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["rust","smt","smtlib"],"created_at":"2024-08-03T07:00:55.233Z","updated_at":"2025-04-11T03:30:50.051Z","avatar_url":"https://github.com/oeb25.png","language":"Rust","funding_links":[],"categories":["Projects"],"sub_categories":["Libraries"],"readme":"# smtlib\n\n[![Crates.io](https://img.shields.io/crates/v/smtlib.svg)](https://crates.io/crates/smtlib)\n[![Docs](https://docs.rs/smtlib/badge.svg)](https://docs.rs/smtlib)\n[![Crates.io license shield](https://img.shields.io/crates/l/smtlib.svg)](https://crates.io/crates/smtlib)\n\n\u003e A high-level API for interacting with SMT solvers\n\n_If you are looking for more control and less ergonomics, take a look at the [low-level crate `smtlib-lowlevel`](https://crates.io/crates/smtlib-lowlevel) for construct SMT-LIB code and talking directly with SMT solvers._\n\n## Background\n\n[Satisfiability modulo theories (SMT)](https://en.wikipedia.org/wiki/Satisfiability_modulo_theories) is the problem of determining whether or not a mathematical formula is satisfiable. SMT solvers (such as [Z3](https://github.com/Z3Prover/z3) and [cvc5](https://cvc5.github.io/)) are programs to automate this process. These are fantastic tools which are very powerful and can solve complex problems efficiently.\n\nTo communicate with the solvers, the [SMT-LIB](https://smtlib.cs.uiowa.edu/index.shtml) specification has been made to standardize the input/output language to all of the solvers.\n\nWriting this format by-hand (or \"programmatically by-hand\") can at times be tedious and error prone. Even more so is interpreting the result produced by the solvers.\n\nThus the goal of `smtlib` (and [`smtlib-lowlevel`](https://crates.io/crates/smtlib-lowlevel)) is to provide ergonomic API's for communicating with the solvers, independent of the concrete solver.\n\n## Usage\n\nThe primary way to use `smtlib` is by constructing a [`smtlib::Solver`](https://docs.rs/smtlib/latest/smtlib/struct.Solver.html). A solver takes as argument a [`smtlib::Backend`](https://docs.rs/smtlib/latest/smtlib/trait.Backend.html). To see which backends are provided with the library check out the [`smtlib::backend`](https://docs.rs/smtlib/latest/smtlib/backend/index.html) module. Some backend is behind a feature flag, so for example to use the [Z3](https://github.com/Z3Prover/z3) statically backend install `smtlib` by running `cargo add smtlib -F z3-static`, but otherwise add it by running:\n\n```bash\ncargo add smtlib\n```\n\nNow you can go ahead and use the library in your project.\n\n```rust\nuse smtlib::{backend::z3_binary::Z3Binary, Int, SatResultWithModel, Solver, Storage, prelude::*};\n\nfn main() -\u003e Result\u003c(), Box\u003cdyn std::error::Error\u003e\u003e {\n    let st = Storage::new();\n\n    // Initialize the solver with the Z3 backend. The \"z3\" string refers the\n    // to location of the already installed `z3` binary. In this case, the\n    // binary is in the path.\n    let mut solver = Solver::new(\u0026st, Z3Binary::new(\"z3\")?)?;\n\n    // Declare two new variables\n    let x = Int::new_const(\u0026st, \"x\");\n    let y = Int::new_const(\u0026st, \"y\");\n\n    // Assert some constraints. This tells the solver that these expressions\n    // must be true, so any solution will satisfy these.\n    solver.assert(x._eq(y + 25))?;\n    solver.assert(x._eq(204))?;\n    // The constraints are thus:\n    // - x == y + 25\n    // - x == 204\n    // Note that we use `a._eq(b)` rather than `a == b`, since we want to\n    // express the mathematical relation of `a` and `b`, while `a == b` checks\n    // that the two **expressions** are structurally the same.\n\n    // Check for validity\n    match solver.check_sat_with_model()? {\n        SatResultWithModel::Sat(model) =\u003e {\n            // Since it is valid, we can extract the possible values of the\n            // variables using a model\n            println!(\"x = {}\", model.eval(x).unwrap());\n            println!(\"y = {}\", model.eval(y).unwrap());\n        }\n        SatResultWithModel::Unsat =\u003e println!(\"No valid solutions found!\"),\n        SatResultWithModel::Unknown =\u003e println!(\"Satisfaction remains unknown...\"),\n    }\n\n    Ok(())\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foeb25%2Fsmtlib-rs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Foeb25%2Fsmtlib-rs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foeb25%2Fsmtlib-rs/lists"}