Skip to content

Commit

Permalink
Use the boolean model of satml_frontend in get_value. (#961)
Browse files Browse the repository at this point in the history
* Fix get_value on satml

* Update tests

* Poetry
  • Loading branch information
Stevendeo authored Nov 22, 2023
1 parent ea7b486 commit d2af665
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 40 deletions.
32 changes: 7 additions & 25 deletions src/bin/common/solving_loop.ml
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ let enable_maxsmt b =
(* Dolmen util *)

(** Adds the named terms of the statement [stmt] to the map accumulator [acc] *)
let get_named_of_stmt
let add_if_named
~(acc : DStd.Expr.term Util.MS.t)
(stmt : Typer_Pipe.typechecked D_loop.Typer_Pipe.stmt) =
match stmt.contents with
Expand All @@ -112,7 +112,7 @@ let get_named_of_stmt
end
| _ -> (* Named terms are expected to be definitions with simple
names. *)
assert false
acc

(* We currently use the full state of the solver as model. *)
type model = Model : 'a sat_module * 'a -> model
Expand Down Expand Up @@ -695,10 +695,6 @@ let main () =

(* Fetches the term value in the current model. *)
let evaluate_term get_value name term =
(* There are two ways to evaluate a term:
- if its name is registered in the environment, get its value;
- if not, check if the formula is in the environment.
*)
let simple_form =
Expr.mk_term
(Sy.name name)
Expand All @@ -707,18 +703,7 @@ let main () =
in
match get_value simple_form with
| Some v -> Fmt.to_to_string Expr.print v
| None -> (* Trying with the actual formula. *)
let ae_form =
D_cnf.make_form
name
term
Loc.dummy
~decl_kind:Expr.Dgoal
in
match get_value ae_form with
| None -> "unknown" (* Not in the standard, but useful for recording when
Alt-Ergo fails to guess the value of a term. *)
| Some v -> Fmt.to_to_string Expr.print v
| None -> "unknown"
in

let print_terms_assignments =
Expand Down Expand Up @@ -909,13 +894,10 @@ let main () =
in
let handle_stmts all_context st l =
let rec aux named_map st = function
| [] -> st
| [main_stmt] ->
let st = handle_stmt all_context st main_stmt in
State.set named_terms named_map st
| named_stmt :: tl ->
let st = handle_stmt all_context st named_stmt in
let named_map = get_named_of_stmt ~acc:named_map named_stmt in
| [] -> State.set named_terms named_map st
| stmt :: tl ->
let st = handle_stmt all_context st stmt in
let named_map = add_if_named ~acc:named_map stmt in
aux named_map st tl
in
aux (State.get named_terms st) st l
Expand Down
19 changes: 11 additions & 8 deletions src/lib/reasoners/satml_frontend.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1398,14 +1398,17 @@ module Make (Th : Theory.S) : Sat_solver_sig.S = struct
match E.type_info t with
| Ty.Tbool ->
begin
match ME.find_opt t env.gamma with
| None ->
begin
match ME.find_opt (E.neg t) env.gamma with
| None -> None
| Some _ -> Some E.faux
end
| Some _ -> Some E.vrai
let bmodel = SAT.boolean_model env.satml in
Stdcompat.List.find_map
(fun Atom.{lit; neg = {lit=neglit; _}; _} ->
if E.equal t lit then
Some E.vrai
else if E.equal t neglit then
Some E.faux
else
None
)
bmodel
end
| _ -> None

Expand Down
8 changes: 4 additions & 4 deletions tests/models/bool/bool1.models.expected
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ unknown
(define-fun p () Bool true)
(define-fun q () Bool true)
)
((notp unknown)
(notnq unknown))
((notp false)
(notnq false))


unknown
(
(define-fun p () Bool true)
(define-fun q () Bool true)
)
((notp unknown)
(notnq unknown))
((notp false)
(notnq false))

2 changes: 1 addition & 1 deletion tests/models/bool/bool2.models.expected
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ unknown
(
(define-fun x () Bool false)
)
((notx unknown))
((notx true))

4 changes: 2 additions & 2 deletions tests/models/bool/bool3.models.expected
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ unknown
(define-fun x () Bool true)
(define-fun y () Bool true)
)
((foo unknown)
(bar unknown))
((foo true)
(bar false))

0 comments on commit d2af665

Please sign in to comment.