@ -128,7 +128,8 @@ end
(* * Formulas, denoting sets of structures, built from propositional
(* * Formulas, denoting sets of structures, built from propositional
variables , applications of predicate symbols from various theories , and
variables , applications of predicate symbols from various theories , and
first - order logic connectives . * )
first - order logic connectives . * )
type fml =
module Fml : sig
type fml = private
| Tt
| Tt
| Ff
| Ff
| Eq of trm * trm
| Eq of trm * trm
@ -148,6 +149,46 @@ type fml =
| UNegLit of Predsym . t * trm
| UNegLit of Predsym . t * trm
[ @@ deriving compare , equal , sexp ]
[ @@ deriving compare , equal , sexp ]
val _ Tt : fml
val _ Ff : fml
val _ Eq : trm -> trm -> fml
val _ Dq : trm -> trm -> fml
val _ Eq0 : trm -> fml
val _ Dq0 : trm -> fml
val _ Gt0 : trm -> fml
val _ Ge0 : trm -> fml
val _ Lt0 : trm -> fml
val _ Le0 : trm -> fml
val _ And : fml -> fml -> fml
val _ Or : fml -> fml -> fml
val _ Iff : fml -> fml -> fml
val _ Xor : fml -> fml -> fml
val _ Cond : fml -> fml -> fml -> fml
val _ UPosLit : Predsym . t -> trm -> fml
val _ UNegLit : Predsym . t -> trm -> fml
end = struct
type fml =
| Tt
| Ff
| Eq of trm * trm
| Dq of trm * trm
| Eq0 of trm
| Dq0 of trm
| Gt0 of trm
| Ge0 of trm
| Lt0 of trm
| Le0 of trm
| And of fml * fml
| Or of fml * fml
| Iff of fml * fml
| Xor of fml * fml
| Cond of { cnd : fml ; pos : fml ; neg : fml }
| UPosLit of Predsym . t * trm
| UNegLit of Predsym . t * trm
[ @@ deriving compare , equal , sexp ]
let _ Tt = Tt
let _ Ff = Ff
let _ Eq x y = Eq ( x , y )
let _ Eq x y = Eq ( x , y )
let _ Dq x y = Dq ( x , y )
let _ Dq x y = Dq ( x , y )
let _ Eq0 x = Eq0 x
let _ Eq0 x = Eq0 x
@ -163,6 +204,9 @@ let _Xor p q = Xor (p, q)
let _ Cond cnd pos neg = Cond { cnd ; pos ; neg }
let _ Cond cnd pos neg = Cond { cnd ; pos ; neg }
let _ UPosLit p x = UPosLit ( p , x )
let _ UPosLit p x = UPosLit ( p , x )
let _ UNegLit p x = UNegLit ( p , x )
let _ UNegLit p x = UNegLit ( p , x )
end
open Fml
(*
(*
* Conditional terms
* Conditional terms
@ -686,17 +730,17 @@ let embed_into_fml : exp -> fml = function
0 ) ] = = > [ ( p ? tt : ff ) ] = = > [ p ] . * )
0 ) ] = = > [ ( p ? tt : ff ) ] = = > [ p ] . * )
let dq0 : trm -> fml = function
let dq0 : trm -> fml = function
(* 0 ≠ 0 ==> ff *)
(* 0 ≠ 0 ==> ff *)
| Z _ as z when z = = zero -> Ff
| Z _ as z when z = = zero -> _ Ff
(* 0 ≠ N ==> tt for N≠0 *)
(* 0 ≠ N ==> tt for N≠0 *)
| Z _ -> Tt
| Z _ -> _ Tt
| t -> Dq ( zero , t )
| t -> _ Dq zero t
in
in
let cond : fml -> fml -> fml -> fml =
let cond : fml -> fml -> fml -> fml =
fun cnd pos neg ->
fun cnd pos neg ->
match ( pos , neg ) with
match ( pos , neg ) with
(* ( p ? tt : ff ) ==> p *)
(* ( p ? tt : ff ) ==> p *)
| Tt , Ff -> cnd
| Tt , Ff -> cnd
| _ -> Cond { cnd ; pos ; neg }
| _ -> _ Cond cnd pos neg
in
in
map_cnd cond dq0 c
map_cnd cond dq0 c
@ -704,7 +748,7 @@ let embed_into_fml : exp -> fml = function
let ite : fml -> exp -> exp -> exp =
let ite : fml -> exp -> exp -> exp =
fun cnd thn els ->
fun cnd thn els ->
match ( thn , els ) with
match ( thn , els ) with
| ` Fml pos , ` Fml neg -> ` Fml ( Cond { cnd ; pos ; neg } )
| ` Fml pos , ` Fml neg -> ` Fml ( _ Cond cnd pos neg )
| _ -> (
| _ -> (
let c = ` Ite ( cnd , embed_into_cnd thn , embed_into_cnd els ) in
let c = ` Ite ( cnd , embed_into_cnd thn , embed_into_cnd els ) in
match project_out_fml c with Some f -> ` Fml f | None -> c )
match project_out_fml c with Some f -> ` Fml f | None -> c )
@ -920,8 +964,8 @@ module Formula = struct
(* constants *)
(* constants *)
let tt = Tt
let tt = _ Tt
let ff = Ff
let ff = _ Ff
(* comparisons *)
(* comparisons *)
@ -958,23 +1002,23 @@ module Formula = struct
let cond ~ cnd ~ pos ~ neg = _ Cond cnd pos neg
let cond ~ cnd ~ pos ~ neg = _ Cond cnd pos neg
let rec not_ = function
let rec not_ = function
| Tt -> Ff
| Tt -> _ Ff
| Ff -> Tt
| Ff -> _ Tt
| Eq ( x , y ) -> Dq ( x , y )
| Eq ( x , y ) -> _ Dq x y
| Dq ( x , y ) -> Eq ( x , y )
| Dq ( x , y ) -> _ Eq x y
| Eq0 x -> Dq0 x
| Eq0 x -> _ Dq0 x
| Dq0 x -> Eq0 x
| Dq0 x -> _ Eq0 x
| Gt0 x -> Le0 x
| Gt0 x -> _ Le0 x
| Ge0 x -> Lt0 x
| Ge0 x -> _ Lt0 x
| Lt0 x -> Ge0 x
| Lt0 x -> _ Ge0 x
| Le0 x -> Gt0 x
| Le0 x -> _ Gt0 x
| And ( x , y ) -> Or ( not_ x , not_ y )
| And ( x , y ) -> _ Or ( not_ x ) ( not_ y )
| Or ( x , y ) -> And ( not_ x , not_ y )
| Or ( x , y ) -> _ And ( not_ x ) ( not_ y )
| Iff ( x , y ) -> Xor ( x , y )
| Iff ( x , y ) -> _ Xor x y
| Xor ( x , y ) -> Iff ( x , y )
| Xor ( x , y ) -> _ Iff x y
| Cond { cnd ; pos ; neg } -> Cond { cnd ; pos = not_ pos ; neg = not_ neg }
| Cond { cnd ; pos ; neg } -> _ Cond cnd ( not_ pos ) ( not_ neg )
| UPosLit ( p , x ) -> UNegLit ( p , x )
| UPosLit ( p , x ) -> _ UNegLit p x
| UNegLit ( p , x ) -> UPosLit ( p , x )
| UNegLit ( p , x ) -> _ UPosLit p x
(* * Query *)
(* * Query *)
@ -1124,8 +1168,8 @@ let vs_of_ses : Ses.Var.Set.t -> Var.Set.t =
let uap0 f = ` Trm ( Apply ( f , Tuple [| |] ) )
let uap0 f = ` Trm ( Apply ( f , Tuple [| |] ) )
let uap1 f = ap1t ( fun x -> Apply ( f , Tuple [| x |] ) )
let uap1 f = ap1t ( fun x -> Apply ( f , Tuple [| x |] ) )
let uap2 f = ap2t ( fun x y -> Apply ( f , Tuple [| x ; y |] ) )
let uap2 f = ap2t ( fun x y -> Apply ( f , Tuple [| x ; y |] ) )
let upos2 p = ap2f ( fun x y -> UPosLit ( p , Tuple [| x ; y |] ) )
let upos2 p = ap2f ( fun x y -> _ UPosLit p ( Tuple [| x ; y |] ) )
let uneg2 p = ap2f ( fun x y -> UNegLit ( p , Tuple [| x ; y |] ) )
let uneg2 p = ap2f ( fun x y -> _ UNegLit p ( Tuple [| x ; y |] ) )
let rec uap_tt f a = uap1 f ( of_ses a )
let rec uap_tt f a = uap1 f ( of_ses a )
and uap_ttt f a b = uap2 f ( of_ses a ) ( of_ses b )
and uap_ttt f a b = uap2 f ( of_ses a ) ( of_ses b )