mirror of
https://github.com/c-cube/sidekick.git
synced 2025-12-06 11:15:43 -05:00
add tseitin-free example to the readme
This commit is contained in:
parent
8e7efcfd3b
commit
f82e475a42
1 changed files with 35 additions and 5 deletions
40
README.md
40
README.md
|
|
@ -53,11 +53,41 @@ as shown in the following code :
|
|||
```ocaml
|
||||
(* Module initialization *)
|
||||
module Sat = Msat.Sat.Make()
|
||||
module F = Msat.Tseitin.Make(Msat.Sat.Expr)
|
||||
module E = Msat.Sat.Expr (* expressions *)
|
||||
|
||||
(* We create here two distinct atoms *)
|
||||
let a = Msat.Sat.Expr.fresh () (* A 'new_atom' is always distinct from any other atom *)
|
||||
let b = Msat.Sat.Expr.make 1 (* Atoms can be created from integers *)
|
||||
let a = E.fresh () (* A 'new_atom' is always distinct from any other atom *)
|
||||
let b = E.make 1 (* Atoms can be created from integers *)
|
||||
|
||||
(* We can try and check the satisfiability of some clauses --
|
||||
here, the clause [a or b].
|
||||
Sat.assume adds a list of clauses to the solver. *)
|
||||
let() = Sat.assume [[a; b]]
|
||||
let res = Sat.solve () (* Should return (Sat.Sat _) *)
|
||||
|
||||
(* The Sat solver has an incremental mutable state, so we still have
|
||||
the clause [a or b] in our assumptions.
|
||||
We add [not a] and [not b] to the state. *)
|
||||
let () = Sat.assume [[E.neg a]; [E.neg b]]
|
||||
let res = Sat.solve () (* Should return (Sat.Unsat _) *)
|
||||
```
|
||||
|
||||
|
||||
#### Formulas API
|
||||
|
||||
Writing clauses by hand can be tedious and error-prone.
|
||||
The functor `Msat.Tseitin.Make` proposes a formula AST (parametrized by
|
||||
atoms) and a function to convert these formulas into clauses:
|
||||
|
||||
```ocaml
|
||||
(* Module initialization *)
|
||||
module Sat = Msat.Sat.Make()
|
||||
module E = Msat.Sat.Expr (* expressions *)
|
||||
module F = Msat.Tseitin.Make(E)
|
||||
|
||||
(* We create here two distinct atoms *)
|
||||
let a = E.fresh () (* A 'new_atom' is always distinct from any other atom *)
|
||||
let b = E.make 1 (* Atoms can be created from integers *)
|
||||
|
||||
(* Let's create some formulas *)
|
||||
let p = F.make_atom a
|
||||
|
|
@ -66,12 +96,12 @@ let r = F.make_and [p; q]
|
|||
let s = F.make_or [F.make_not p; F.make_not q]
|
||||
|
||||
(* We can try and check the satisfiability of the given formulas *)
|
||||
Sat.assume (F.make_cnf r)
|
||||
let () = Sat.assume (F.make_cnf r)
|
||||
let _ = Sat.solve () (* Should return (Sat.Sat _) *)
|
||||
|
||||
(* The Sat solver has an incremental mutable state, so we still have
|
||||
* the formula 'r' in our assumptions *)
|
||||
Sat.assume (F.make_cnf s)
|
||||
let () = Sat.assume (F.make_cnf s)
|
||||
let _ = Sat.solve () (* Should return (Sat.Unsat _) *)
|
||||
```
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue