mirror of
https://github.com/c-cube/sidekick.git
synced 2025-12-06 11:15:43 -05:00
feat: add sidekick.lit small library for literals
This commit is contained in:
parent
d40ce304ae
commit
cc1a93fa74
2 changed files with 47 additions and 0 deletions
40
src/lit/Sidekick_lit.ml
Normal file
40
src/lit/Sidekick_lit.ml
Normal file
|
|
@ -0,0 +1,40 @@
|
||||||
|
|
||||||
|
(** Implementation of literals from terms *)
|
||||||
|
|
||||||
|
module Make(T : Sidekick_core.TERM)
|
||||||
|
: Sidekick_core.LIT with module T = T
|
||||||
|
= struct
|
||||||
|
module T = T
|
||||||
|
type term = T.Term.t
|
||||||
|
type t = {
|
||||||
|
lit_term: term;
|
||||||
|
lit_sign : bool
|
||||||
|
}
|
||||||
|
|
||||||
|
let[@inline] neg l = {l with lit_sign=not l.lit_sign}
|
||||||
|
let[@inline] sign t = t.lit_sign
|
||||||
|
let[@inline] abs t = {t with lit_sign=true}
|
||||||
|
let[@inline] term (t:t): term = t.lit_term
|
||||||
|
let[@inline] signed_term t = term t, sign t
|
||||||
|
|
||||||
|
let make ~sign t = {lit_sign=sign; lit_term=t}
|
||||||
|
|
||||||
|
let atom tst ?(sign=true) (t:term) : t =
|
||||||
|
let t, sign' = T.Term.abs tst t in
|
||||||
|
let sign = if not sign' then not sign else sign in
|
||||||
|
make ~sign t
|
||||||
|
|
||||||
|
let equal a b =
|
||||||
|
a.lit_sign = b.lit_sign &&
|
||||||
|
T.Term.equal a.lit_term b.lit_term
|
||||||
|
|
||||||
|
let hash a =
|
||||||
|
let sign = a.lit_sign in
|
||||||
|
CCHash.combine3 2 (CCHash.bool sign) (T.Term.hash a.lit_term)
|
||||||
|
|
||||||
|
let pp out l =
|
||||||
|
if l.lit_sign then T.Term.pp out l.lit_term
|
||||||
|
else Format.fprintf out "(@[@<1>¬@ %a@])" T.Term.pp l.lit_term
|
||||||
|
|
||||||
|
let norm_sign l = if l.lit_sign then l, true else neg l, false
|
||||||
|
end
|
||||||
7
src/lit/dune
Normal file
7
src/lit/dune
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
|
||||||
|
(library
|
||||||
|
(name sidekick_lit)
|
||||||
|
(public_name sidekick.lit)
|
||||||
|
(synopsis "Implementation of literals for Sidekick")
|
||||||
|
(libraries containers sidekick.core sidekick.util)
|
||||||
|
(flags :standard -warn-error -a+8 -open Sidekick_util))
|
||||||
Loading…
Add table
Reference in a new issue