wip: feat(lra): preprocess by renaming lits/terms and storing defs

This commit is contained in:
Simon Cruanes 2020-10-04 21:37:03 -04:00
parent ac6ca7d584
commit fabdb27dfe
2 changed files with 27 additions and 29 deletions

View file

@ -310,6 +310,7 @@ module Th_lra = Sidekick_lra.Make(struct
let mk_lra = T.lra let mk_lra = T.lra
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)
| _ -> LRA_other t | _ -> LRA_other t
module Gensym = struct module Gensym = struct

View file

@ -94,12 +94,16 @@ module Make(A : ARG) : S with module A = A = struct
simps: T.t T.Tbl.t; (* cache *) simps: T.t T.Tbl.t; (* cache *)
simplex: Simplex.t; simplex: Simplex.t;
gensym: A.Gensym.t; gensym: A.Gensym.t;
mutable t_defs: (T.t * LE.t) list; (* term definitions *)
pred_defs: (pred * LE.t * LE.t) T.Tbl.t; (* predicate definitions *)
} }
let create tst : state = let create tst : state =
{ tst; simps=T.Tbl.create 128; { tst; simps=T.Tbl.create 128;
gensym=A.Gensym.create tst; gensym=A.Gensym.create tst;
simplex=Simplex.create(); simplex=Simplex.create();
t_defs=[];
pred_defs=T.Tbl.create 16;
} }
(* FIXME (* FIXME
@ -176,38 +180,26 @@ module Make(A : ARG) : S with module A = A = struct
(* preprocess linear expressions away *) (* preprocess linear expressions away *)
let preproc_lra self si ~mk_lit ~add_clause (t:T.t) : T.t option = let preproc_lra self si ~mk_lit:_ ~add_clause:_ (t:T.t) : T.t option =
Log.debugf 50 (fun k->k "lra.preprocess %a" T.pp t);
let _tst = SI.tst si in let _tst = SI.tst si in
match A.view_as_lra t with match A.view_as_lra t with
| LRA_pred (_pre, _t1, _t2) -> | LRA_pred (pred, t1, t2) ->
None (* TODO: define a bool variable *) (* TODO: map preproc on [l1] and [l2] *)
| LRA_op _ | LRA_const _ -> None let l1 = as_linexp t1 in
(* TODO: remove? let l2 = as_linexp t2 in
let le = as_linexp t in let proxy = fresh_term self ~pre:"_pred_lra_" Ty.bool in
let proxy = fresh_term self ~pre:"lra" (T.ty t) in T.Tbl.add self.pred_defs proxy (pred, l1, l2);
Simplex.add_eq self.simplex (V_t proxy, []); (* TODO add LE *) Log.debugf 5 (fun k->k"lra.preprocess.step %a :into %a" T.pp t T.pp proxy);
Some proxy Some proxy
*) | LRA_op _ | LRA_mult _ ->
let le = as_linexp t in
(* TODO: useless? (* TODO: map preproc on [le] *)
add_clause [ let proxy = fresh_term self ~pre:"_e_lra_" (T.ty t) in
mk_lit self.t_defs <- (proxy, le) :: self.t_defs;
(A.mk_lra tst Log.debugf 5 (fun k->k"lra.preprocess.step %a :into %a" T.pp t T.pp proxy);
(LRA_pred (Eq, le, Simplex.L.Comb.monomial1 (V_t proxy)))) Some proxy
]; | LRA_const _ | LRA_other _ -> None
*)
(*
| B_ite (a,b,c) ->
let t_a = fresh_term self ~pre:"ite" (T.ty b) in
let lit_a = mk_lit a in
add_clause [Lit.neg lit_a; mk_lit (eq self.tst t_a b)];
add_clause [lit_a; mk_lit (eq self.tst t_a c)];
Some t_a
*)
| LRA_mult _ -> None (* TODO *)
| LRA_const _ ->
None (* TODO: turn into linexp *)
| LRA_other _ -> None
(* TODO: remove (* TODO: remove
let cnf (self:state) (_si:SI.t) ~mk_lit ~add_clause (t:T.t) : T.t option = let cnf (self:state) (_si:SI.t) ~mk_lit ~add_clause (t:T.t) : T.t option =
@ -302,11 +294,16 @@ module Make(A : ARG) : S with module A = A = struct
end; end;
() ()
let final_check_ (self:state) si (acts:SI.actions) (_trail:_ Iter.t) : unit =
Log.debug 5 "(th-lra.final-check)";
()
let create_and_setup si = let create_and_setup si =
Log.debug 2 "(th-lra.setup)"; Log.debug 2 "(th-lra.setup)";
let st = create (SI.tst si) in let st = create (SI.tst si) in
(* TODO SI.add_simplifier si (simplify st); *) (* TODO 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.add_preprocess si (cnf st); *) (* SI.add_preprocess si (cnf st); *)
(* TODO: theory combination *) (* TODO: theory combination *)
st st