add simplify to LRA

This commit is contained in:
Simon Cruanes 2021-02-22 21:10:18 -05:00
parent 15cadbaeaa
commit 2810312e2f
4 changed files with 30 additions and 1 deletions

View file

@ -119,6 +119,7 @@ module Make(C : COEFF)(Var : VAR) = struct
let zero = of_const C.zero
let is_zero e = C.equal C.zero e.const && Comb.is_empty e.comb
let is_const e = Comb.is_empty e.comb
let map2 f g e e' = make (f e.comb e'.comb) (g e.const e'.const)

View file

@ -165,6 +165,7 @@ module type S = sig
val const : t -> C.t
val is_zero : t -> bool
val is_const : t -> bool
val compare : t -> t -> int
(** Standard comparison function on expressions. *)

View file

@ -44,6 +44,8 @@ module type ARG = sig
val view_as_lra : term -> term lra_view
(** Project the term into the theory view *)
val mk_bool : S.T.Term.state -> bool -> term
val mk_lra : S.T.Term.state -> term lra_view -> term
(** Make a term from the given theory view *)
@ -342,6 +344,30 @@ module Make(A : ARG) : S with module A = A = struct
| LRA_other t when A.has_ty_real t -> None
| LRA_const _ | LRA_simplex_pred _ | LRA_simplex_var _ | LRA_other _ -> None
let simplify (self:state) (_recurse:_) (t:T.t) : T.t option =
match A.view_as_lra t with
| LRA_op _ | LRA_mult _ ->
let le = as_linexp_id t in
if LE.is_const le then (
let c = LE.const le in
Some (A.mk_lra self.tst (LRA_const c))
) else None
| LRA_pred (pred, l1, l2) ->
let le = LE.(as_linexp_id l1 - as_linexp_id l2) in
if LE.is_const le then (
let c = LE.const le in
let is_true = match pred with
| Leq -> Q.(c <= zero)
| Geq -> Q.(c >= zero)
| Lt -> Q.(c < zero)
| Gt -> Q.(c > zero)
| Eq -> Q.(c = zero)
| Neq -> Q.(c <> zero)
in
Some (A.mk_bool self.tst is_true)
) else None
| _ -> None
module Q_map = CCMap.Make(Q)
(* raise conflict from certificate *)
@ -517,7 +543,7 @@ module Make(A : ARG) : S with module A = A = struct
Log.debug 2 "(th-lra.setup)";
let stat = SI.stats si in
let st = create ~stat (SI.tst si) in
(* TODO SI.add_simplifier si (simplify st); *)
SI.add_simplifier si (simplify st);
SI.add_preprocess si (preproc_lra st);
SI.on_final_check si (final_check_ st);
SI.on_partial_check si (partial_check_ st);

View file

@ -317,6 +317,7 @@ module Th_lra = Sidekick_arith_lra.Make(struct
let mk_eq = Form.eq
let mk_lra = T.lra
let mk_bool = T.bool
let view_as_lra t = match T.view t with
| T.LRA l -> l
| T.Eq (a,b) when Ty.equal (T.ty a) Ty.real -> LRA_pred (Eq, a, b)