|
1 |
| -# SymbolicSAT |
| 1 | +# SymbolicSMT.jl |
2 | 2 |
|
3 |
| -**WARNING: This package is experimental! Use it only to find bugs.** |
| 3 | +[](https://github.com/JuliaSymbolics/SymbolicSMT.jl/actions/workflows/ci.yml) |
| 4 | +[](https://codecov.io/gh/JuliaSymbolics/SymbolicSMT.jl) |
4 | 5 |
|
5 |
| -This package extends [SymbolicUtils](https://juliasymbolics.github.io/SymbolicUtils.jl/) expression simplification with a theorem prover. |
| 6 | +**Symbolic SMT solving for Julia** |
6 | 7 |
|
7 |
| -It is a wrapper around [a wrapper](https://github.com/ahumenberger/Z3.jl) to [The Z3 Theorem Prover](https://github.com/Z3Prover/z3/wiki). |
| 8 | +SymbolicSMT.jl provides a high-level interface for symbolic constraint solving and theorem proving. Built on [Z3](https://github.com/Z3Prover/z3) and integrated with [Symbolics.jl](https://github.com/JuliaSymbolics/Symbolics.jl), it enables you to solve complex mathematical problems involving real numbers, integers, and boolean logic. |
8 | 9 |
|
9 |
| -Usage: |
| 10 | +## Installation |
10 | 11 |
|
11 |
| -0. `using SymbolicUtils, SymbolicSAT` |
12 |
| -1. Construct a `Constraints([cs...])` where `cs` are boolean expressions |
13 |
| -2. Pass it as the second argument to `simplify` |
| 12 | +```julia |
| 13 | +using Pkg |
| 14 | +Pkg.add("SymbolicSMT") |
| 15 | +``` |
| 16 | + |
| 17 | +## Quick Start |
14 | 18 |
|
15 | 19 | ```julia
|
16 |
| -julia> using SymbolicUtils, SymbolicSAT |
| 20 | +using Symbolics, SymbolicSMT |
17 | 21 |
|
18 |
| -julia> @syms a::Real b::Real |
19 |
| -(a, b) |
| 22 | +# Create symbolic variables |
| 23 | +@variables x::Real y::Real |
20 | 24 |
|
21 |
| -julia> constraints = Constraints([a^2 + b^2 < 4]) |
22 |
| -Constraints: |
23 |
| - ((a ^ 2) + (b ^ 2)) < 4 |
| 25 | +# Define constraints |
| 26 | +constraints = Constraints([x > 0, y > 0, x^2 + y^2 <= 1]) |
24 | 27 |
|
25 |
| -julia> simplify((a < 2) & (b < 2), Constraints([a^2 + b^2 < 4])) |
26 |
| -true |
| 28 | +# Check satisfiability: Can x be greater than 1? |
| 29 | +issatisfiable(x > 1, constraints) # true |
| 30 | + |
| 31 | +# Check provability: Is x always positive? |
| 32 | +isprovable(x > 0, constraints) # true |
| 33 | + |
| 34 | +# Resolve expressions: Simplify when possible |
| 35 | +resolve(x > 0, constraints) # true (always satisfied) |
| 36 | +resolve(x > 2, constraints) # x > 2 (cannot determine from constraints) |
27 | 37 | ```
|
28 | 38 |
|
29 |
| -Thanks to the author of [Z3.jl](https://github.com/ahumenberger/Z3.jl) for the Julia bindings and answering my questions! |
| 39 | +## Key Features |
| 40 | + |
| 41 | +- **🎯 High-level interface**: Work naturally with symbolic expressions |
| 42 | +- **🔢 Multiple theories**: Real arithmetic, integer constraints, boolean logic |
| 43 | +- **⚡ Powerful backend**: Leverages Microsoft's Z3 SMT solver |
| 44 | +- **🔗 Ecosystem integration**: Seamless with Symbolics.jl and SymbolicUtils.jl |
| 45 | +- **✅ Comprehensive**: Satisfiability, provability, and constraint-based simplification |
| 46 | + |
| 47 | +## Use Cases |
| 48 | + |
| 49 | +- **Optimization**: Verify feasibility and analyze constraint systems |
| 50 | +- **Verification**: Prove mathematical properties and system invariants |
| 51 | +- **Planning**: Resource allocation and scheduling problems |
| 52 | +- **Logic**: Propositional and first-order reasoning |
| 53 | +- **Geometry**: Spatial relationships and geometric constraints |
| 54 | + |
| 55 | +## Example: Geometric Reasoning |
| 56 | + |
| 57 | +```julia |
| 58 | +# Model points on a unit circle |
| 59 | +@variables x₁::Real y₁::Real x₂::Real y₂::Real |
| 60 | + |
| 61 | +circle_constraints = Constraints([ |
| 62 | + x₁^2 + y₁^2 == 1, # Point 1 on unit circle |
| 63 | + x₂^2 + y₂^2 == 1 # Point 2 on unit circle |
| 64 | +]) |
| 65 | + |
| 66 | +# Can two points be more than distance 2 apart? |
| 67 | +issatisfiable((x₁ - x₂)^2 + (y₁ - y₂)^2 > 4, circle_constraints) # true |
| 68 | + |
| 69 | +# Is distance always bounded? |
| 70 | +isprovable((x₁ - x₂)^2 + (y₁ - y₂)^2 <= 4, circle_constraints) # false |
| 71 | +``` |
| 72 | + |
| 73 | +## Documentation |
| 74 | + |
| 75 | +For detailed usage, examples, and API reference, see the documentation: |
| 76 | + |
| 77 | +- **[Stable Documentation](https://JuliaSymbolics.github.io/SymbolicSMT.jl/stable/)** |
| 78 | +- **[Development Documentation](https://JuliaSymbolics.github.io/SymbolicSMT.jl/dev/)** |
| 79 | + |
| 80 | +## Related Packages |
| 81 | + |
| 82 | +SymbolicSMT.jl is part of the [JuliaSymbolics](https://github.com/JuliaSymbolics) ecosystem: |
| 83 | + |
| 84 | +- **[Symbolics.jl](https://github.com/JuliaSymbolics/Symbolics.jl)**: Computer algebra system and symbolic computation |
| 85 | +- **[SymbolicUtils.jl](https://github.com/JuliaSymbolics/SymbolicUtils.jl)**: Expression manipulation and simplification |
| 86 | +- **[ModelingToolkit.jl](https://github.com/SciML/ModelingToolkit.jl)**: Symbolic modeling of mathematical systems |
| 87 | + |
| 88 | +## Acknowledgments |
| 89 | + |
| 90 | +Built with [Z3.jl](https://github.com/ahumenberger/Z3.jl) bindings to Microsoft's [Z3 Theorem Prover](https://github.com/Z3Prover/z3). Special thanks to the Z3.jl authors for providing excellent Julia bindings. |
0 commit comments