diff --git a/src/sat/expr_sat.ml b/src/sat/expr_sat.ml new file mode 100644 index 00000000..23c0498d --- /dev/null +++ b/src/sat/expr_sat.ml @@ -0,0 +1,64 @@ +(* +MSAT is free software, using the Apache license, see file LICENSE +Copyright 2016 Guillaume Bury +Copyright 2016 Simon Cruanes +*) + +exception Bad_atom + +type t = int +type proof = unit + +let max_lit = max_int +let max_fresh = ref (-1) +let max_index = ref 0 + +let _make i = + if i <> 0 && (abs i) < max_lit then begin + max_index := max !max_index (abs i); + i + end else + raise Bad_atom + +let dummy = 0 + +let neg a = - a + +let norm a = + abs a, if a < 0 then + Formula_intf.Negated + else + Formula_intf.Same_sign + +let abs = abs + +let sign i = i > 0 + +let apply_sign b i = if b then i else neg i + +let set_sign b i = if b then abs i else neg (abs i) + +let hash (a:int) = a land max_int +let equal (a:int) b = a=b +let compare (a:int) b = Pervasives.compare a b + +let make i = _make (2 * i) + +let fresh, iter = + let create () = + incr max_fresh; + _make (2 * !max_fresh + 1) + in + let iter: (t -> unit) -> unit = fun f -> + for j = 1 to !max_index do + f j + done + in + create, iter + +let print fmt a = + Format.fprintf fmt "%s%s%d" + (if a < 0 then "~" else "") + (if a mod 2 = 0 then "v" else "f") + ((abs a) / 2) + diff --git a/src/sat/expr_sat.mli b/src/sat/expr_sat.mli new file mode 100644 index 00000000..f4b72e48 --- /dev/null +++ b/src/sat/expr_sat.mli @@ -0,0 +1,8 @@ +(* +MSAT is free software, using the Apache license, see file LICENSE +Copyright 2016 Guillaume Bury +Copyright 2016 Simon Cruanes +*) + +include Formula_intf.S + diff --git a/src/sat/sat.ml b/src/sat/sat.ml index 2c91c65f..9e0442f3 100644 --- a/src/sat/sat.ml +++ b/src/sat/sat.ml @@ -5,5 +5,5 @@ Copyright 2014 Simon Cruanes *) module Make(Dummy : sig end) = - Solver.Make(Expr.Atom)(Solver.DummyTheory(Expr.Atom))(struct end) + Solver.Make(Expr_sat)(Solver.DummyTheory(Expr_sat))(struct end) diff --git a/src/sat/sat.mli b/src/sat/sat.mli index 79c9b6b0..dc20113a 100644 --- a/src/sat/sat.mli +++ b/src/sat/sat.mli @@ -4,6 +4,6 @@ Copyright 2014 Guillaume Bury Copyright 2014 Simon Cruanes *) -module Make(Dummy : sig end) : Solver.S with type St.formula = Expr.Atom.t +module Make(Dummy : sig end) : Solver.S with type St.formula = Expr_sat.t