package msat

  1. Overview
  2. Docs

Source file Int_lit.ml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66

exception Bad_atom
(** Exception raised if an atom cannot be created *)

type t = int
(** Atoms are represented as integers. [-i] begin the negation of [i].
    Additionally, since we nee dot be able to create fresh atoms, we
    use even integers for user-created atoms, and odd integers for the
    fresh atoms. *)

let max_lit = max_int

(* Counters *)
let max_index = ref 0
let max_fresh = ref (-1)

(** Internal function for creating atoms.
    Updates the internal counters *)
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 to_int i = i

(** *)
let neg a = - a

let norm a =
  abs a, if a < 0 then
    Solver_intf.Negated
  else
    Solver_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 () =
  incr max_fresh;
  _make (2 * !max_fresh + 1)

(*
let iter: (t -> unit) -> unit = fun f ->
  for j = 1 to !max_index do
    f j
  done
*)

let pp 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)
OCaml

Innovation. Community. Security.