mirror of
https://github.com/c-cube/sidekick.git
synced 2025-12-11 13:38:43 -05:00
feat(core): expose a preprocess function
This commit is contained in:
parent
945ee577c0
commit
17702729d5
3 changed files with 27 additions and 14 deletions
|
|
@ -227,8 +227,8 @@ module Make(A : ARG) : S with module A = A = struct
|
||||||
Log.debugf 50 (fun k->k "lra.preprocess %a" T.pp t);
|
Log.debugf 50 (fun k->k "lra.preprocess %a" T.pp t);
|
||||||
let tst = SI.tst si in
|
let tst = SI.tst si in
|
||||||
|
|
||||||
(* simplify subterm *)
|
(* preprocess subterm *)
|
||||||
let simp_t = SI.simp_t si in
|
let preproc_t = SI.preprocess_term ~add_clause si in
|
||||||
|
|
||||||
(* tell the CC this term exists *)
|
(* tell the CC this term exists *)
|
||||||
let declare_term_to_cc t =
|
let declare_term_to_cc t =
|
||||||
|
|
@ -257,8 +257,8 @@ module Make(A : ARG) : S with module A = A = struct
|
||||||
None
|
None
|
||||||
|
|
||||||
| LRA_pred (pred, t1, t2) ->
|
| LRA_pred (pred, t1, t2) ->
|
||||||
let l1 = as_linexp ~f:simp_t t1 in
|
let l1 = as_linexp ~f:preproc_t t1 in
|
||||||
let l2 = as_linexp ~f:simp_t t2 in
|
let l2 = as_linexp ~f:preproc_t t2 in
|
||||||
let le = LE.(l1 - l2) in
|
let le = LE.(l1 - l2) in
|
||||||
let le_comb, le_const = LE.comb le, LE.const le in
|
let le_comb, le_const = LE.comb le, LE.const le in
|
||||||
let le_const = Q.neg le_const in
|
let le_const = Q.neg le_const in
|
||||||
|
|
@ -306,7 +306,7 @@ module Make(A : ARG) : S with module A = A = struct
|
||||||
end
|
end
|
||||||
|
|
||||||
| LRA_op _ | LRA_mult _ ->
|
| LRA_op _ | LRA_mult _ ->
|
||||||
let le = as_linexp ~f:simp_t t in
|
let le = as_linexp ~f:preproc_t t in
|
||||||
let le_comb, le_const = LE.comb le, LE.const le in
|
let le_comb, le_const = LE.comb le, LE.const le in
|
||||||
|
|
||||||
if Q.(le_const = zero) then (
|
if Q.(le_const = zero) then (
|
||||||
|
|
|
||||||
|
|
@ -437,7 +437,11 @@ module type SOLVER_INTERNAL = sig
|
||||||
not be backtracked. *)
|
not be backtracked. *)
|
||||||
|
|
||||||
val mk_lit : t -> actions -> ?sign:bool -> term -> lit
|
val mk_lit : t -> actions -> ?sign:bool -> term -> lit
|
||||||
(** Create a literal *)
|
(** Create a literal. This automatically preprocesses the term. *)
|
||||||
|
|
||||||
|
val preprocess_term :
|
||||||
|
t -> add_clause:(Lit.t list -> unit) -> term -> term
|
||||||
|
(** Preprocess a term. *)
|
||||||
|
|
||||||
val add_lit : t -> actions -> lit -> unit
|
val add_lit : t -> actions -> lit -> unit
|
||||||
(** Add the given literal to the SAT solver, so it gets assigned
|
(** Add the given literal to the SAT solver, so it gets assigned
|
||||||
|
|
|
||||||
|
|
@ -226,8 +226,9 @@ module Make(A : ARG)
|
||||||
Stat.incr self.count_axiom;
|
Stat.incr self.count_axiom;
|
||||||
acts.Msat.acts_add_clause ~keep lits P.default
|
acts.Msat.acts_add_clause ~keep lits P.default
|
||||||
|
|
||||||
let preprocess_lit_ (self:t) ~add_clause (lit:lit) : lit =
|
let preprocess_term_ (self:t) ~add_clause (t:term) : term =
|
||||||
let mk_lit t = Lit.atom self.tst t in
|
let mk_lit t = Lit.atom self.tst t in (* no further simplification *)
|
||||||
|
|
||||||
(* compute and cache normal form of [t] *)
|
(* compute and cache normal form of [t] *)
|
||||||
let rec aux t =
|
let rec aux t =
|
||||||
match Term.Tbl.find self.preprocess_cache t with
|
match Term.Tbl.find self.preprocess_cache t with
|
||||||
|
|
@ -255,19 +256,27 @@ module Make(A : ARG)
|
||||||
| None -> aux_rec t hooks_tl
|
| None -> aux_rec t hooks_tl
|
||||||
| Some u -> aux u
|
| Some u -> aux u
|
||||||
in
|
in
|
||||||
let t = Lit.term lit |> simp_t self |> aux in
|
t |> simp_t self |> aux
|
||||||
|
|
||||||
|
let preprocess_lit_ (self:t) ~add_clause (lit:lit) : lit =
|
||||||
|
let t = Lit.term lit |> preprocess_term_ self ~add_clause in
|
||||||
let lit' = Lit.atom self.tst ~sign:(Lit.sign lit) t in
|
let lit' = Lit.atom self.tst ~sign:(Lit.sign lit) t in
|
||||||
Log.debugf 10
|
Log.debugf 10
|
||||||
(fun k->k "(@[msat-solver.preprocess.lit@ :lit %a@ :into %a@])" Lit.pp lit Lit.pp lit');
|
(fun k->k "(@[msat-solver.preprocess.lit@ :lit %a@ :into %a@])" Lit.pp lit Lit.pp lit');
|
||||||
lit'
|
lit'
|
||||||
|
|
||||||
let mk_lit self acts ?sign t : Lit.t =
|
(* add a clause using [acts] *)
|
||||||
let add_clause lits =
|
let add_clause_ self acts lits : unit =
|
||||||
Stat.incr self.count_preprocess_clause;
|
Stat.incr self.count_preprocess_clause;
|
||||||
add_sat_clause_ self acts ~keep:true lits
|
add_sat_clause_ self acts ~keep:true lits
|
||||||
in
|
|
||||||
|
let mk_lit self acts ?sign t =
|
||||||
|
let add_clause = add_clause_ self acts in
|
||||||
preprocess_lit_ self ~add_clause @@ Lit.atom self.tst ?sign t
|
preprocess_lit_ self ~add_clause @@ Lit.atom self.tst ?sign t
|
||||||
|
|
||||||
|
let[@inline] preprocess_term self ~add_clause (t:term) : term =
|
||||||
|
preprocess_term_ self ~add_clause t
|
||||||
|
|
||||||
let[@inline] add_clause_temp self acts lits : unit =
|
let[@inline] add_clause_temp self acts lits : unit =
|
||||||
add_sat_clause_ self acts ~keep:false lits
|
add_sat_clause_ self acts ~keep:false lits
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue