mirror of
https://github.com/c-cube/sidekick.git
synced 2025-12-08 20:25:31 -05:00
add simplify to LRA
This commit is contained in:
parent
15cadbaeaa
commit
2810312e2f
4 changed files with 30 additions and 1 deletions
|
|
@ -119,6 +119,7 @@ module Make(C : COEFF)(Var : VAR) = struct
|
||||||
let zero = of_const C.zero
|
let zero = of_const C.zero
|
||||||
|
|
||||||
let is_zero e = C.equal C.zero e.const && Comb.is_empty e.comb
|
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)
|
let map2 f g e e' = make (f e.comb e'.comb) (g e.const e'.const)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -165,6 +165,7 @@ module type S = sig
|
||||||
val const : t -> C.t
|
val const : t -> C.t
|
||||||
|
|
||||||
val is_zero : t -> bool
|
val is_zero : t -> bool
|
||||||
|
val is_const : t -> bool
|
||||||
|
|
||||||
val compare : t -> t -> int
|
val compare : t -> t -> int
|
||||||
(** Standard comparison function on expressions. *)
|
(** Standard comparison function on expressions. *)
|
||||||
|
|
|
||||||
|
|
@ -44,6 +44,8 @@ module type ARG = sig
|
||||||
val view_as_lra : term -> term lra_view
|
val view_as_lra : term -> term lra_view
|
||||||
(** Project the term into the theory 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
|
val mk_lra : S.T.Term.state -> term lra_view -> term
|
||||||
(** Make a term from the given theory view *)
|
(** 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_other t when A.has_ty_real t -> None
|
||||||
| LRA_const _ | LRA_simplex_pred _ | LRA_simplex_var _ | LRA_other _ -> 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)
|
module Q_map = CCMap.Make(Q)
|
||||||
|
|
||||||
(* raise conflict from certificate *)
|
(* raise conflict from certificate *)
|
||||||
|
|
@ -517,7 +543,7 @@ module Make(A : ARG) : S with module A = A = struct
|
||||||
Log.debug 2 "(th-lra.setup)";
|
Log.debug 2 "(th-lra.setup)";
|
||||||
let stat = SI.stats si in
|
let stat = SI.stats si in
|
||||||
let st = create ~stat (SI.tst 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.add_preprocess si (preproc_lra st);
|
||||||
SI.on_final_check si (final_check_ st);
|
SI.on_final_check si (final_check_ st);
|
||||||
SI.on_partial_check si (partial_check_ st);
|
SI.on_partial_check si (partial_check_ st);
|
||||||
|
|
|
||||||
|
|
@ -317,6 +317,7 @@ module Th_lra = Sidekick_arith_lra.Make(struct
|
||||||
|
|
||||||
let mk_eq = Form.eq
|
let mk_eq = Form.eq
|
||||||
let mk_lra = T.lra
|
let mk_lra = T.lra
|
||||||
|
let mk_bool = T.bool
|
||||||
let view_as_lra t = match T.view t with
|
let view_as_lra t = match T.view t with
|
||||||
| T.LRA l -> l
|
| T.LRA l -> l
|
||||||
| T.Eq (a,b) when Ty.equal (T.ty a) Ty.real -> LRA_pred (Eq, a, b)
|
| T.Eq (a,b) when Ty.equal (T.ty a) Ty.real -> LRA_pred (Eq, a, b)
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue