predicate_to_sat_e(negation(b(truth,pred,Info)), _, _, _, WDAcc, Acc, Env, EnvOut, NWDAcc, Falsity, VarAccOut) :-
!,
EnvOut = Env,
VarAccOut = Acc,
NWDAcc = WDAcc,
Falsity = b(falsity,pred,Info).
predicate_to_sat_e(negation(b(falsity,pred,Info)), _, _, _, WDAcc, Acc, Env, EnvOut, NWDAcc, Truth, VarAccOut) :-
!,
EnvOut = Env,
VarAccOut = Acc,
NWDAcc = WDAcc,
Truth = b(truth,pred,Info).
predicate_to_sat_e(truth, pred, Info, _, WDAcc, Acc, Env, EnvOut, NWDAcc, Truth, VarAccOut) :-
!,
EnvOut = Env,
VarAccOut = Acc,
NWDAcc = WDAcc,
Truth = b(truth,pred,Info).
predicate_to_sat_e(falsity, pred, Info, _, WDAcc, Acc, Env, EnvOut, NWDAcc, Falsity, VarAccOut) :-
!,
EnvOut = Env,
VarAccOut = Acc,
NWDAcc = WDAcc,
Falsity = b(falsity,pred,Info).
predicate_to_sat_e(negation(b(negation(Pred),pred,_)), _, _, ReuseType, WDAcc, VarAcc, Env, NewEnv, WDPOs, BoolFormula, NVarAcc) :-
!,
predicate_to_sat(ReuseType, WDAcc, VarAcc, Env, Pred, NewEnv, WDPOs, BoolFormula, NVarAcc).
predicate_to_sat_e(negation(Pred), _, _, ReuseType, WDAcc, VarAcc, Env, NewEnv, WDPOs, BoolFormula, NVarAcc) :-
reuse_or_introduce_bool_var(ReuseType, WDAcc, VarAcc, Env, Pred, boolean_false, TNewEnv, TWDPOs, TBoolFormula, TNVarAcc),
!,
NewEnv = TNewEnv,
WDPOs = TWDPOs,
BoolFormula = TBoolFormula,
NVarAcc = TNVarAcc.
predicate_to_sat_e(negation(Pred), _, _, ReuseType, WDAcc, VarAcc, Env, NewEnv, WDPOs, BoolFormula, NVarAcc) :-
Pred = b(disjunct(A,B),pred,_),
!,
predicate_to_sat(ReuseType, WDAcc, VarAcc, Env, b(negation(A),pred,[]), NewEnv1, WDAcc1, ABoolFormula, NVarAcc1),
predicate_to_sat(ReuseType, WDAcc1, NVarAcc1, NewEnv1, b(negation(B),pred,[]), NewEnv, WDPOs, BBoolFormula, NVarAcc),
% conjunct_predicate/ ensures that truth and falsity are simplified (1)
conjunct_predicates([ABoolFormula,BBoolFormula], BoolFormula).
predicate_to_sat_e(negation(Pred), _, _, ReuseType, WDAcc, VarAcc, Env, NewEnv, WDPOs, BoolFormula, NVarAcc) :-
Pred = b(conjunct(A,B),pred,_),
!,
predicate_to_sat(ReuseType, WDAcc, VarAcc, Env, b(negation(A),pred,[]), NewEnv1, WDAcc1, ABoolFormula, NVarAcc1),
predicate_to_sat(ReuseType, WDAcc1, NVarAcc1, NewEnv1, b(negation(B),pred,[]), NewEnv, WDPOs, BBoolFormula, NVarAcc),
% see above comment (1) for conjunct_predicates/2
disjunct_predicates([ABoolFormula,BBoolFormula], BoolFormula).
predicate_to_sat_e(negation(Pred), _, _, ReuseType, WDAcc, VarAcc, Env, NewEnv, WDPOs, BoolFormula, NVarAcc) :-
Pred = b(implication(A,B),pred,_),
!,
predicate_to_sat(ReuseType, WDAcc, VarAcc, Env, A, NewEnv1, WDAcc1, ABoolFormula, NVarAcc1),
predicate_to_sat(ReuseType, WDAcc1, NVarAcc1, NewEnv1, b(negation(B),pred,[]), NewEnv, WDPOs, BBoolFormula, NVarAcc),
% see (1)
conjunct_predicates([ABoolFormula,BBoolFormula], BoolFormula).
predicate_to_sat_e(negation(Pred), _, _, ReuseType, WDAcc, VarAcc, Env, NewEnv, WDPOs, BoolFormula, NVarAcc) :-
Pred = b(equivalence(A,B),pred,_),
!,
predicate_to_sat(ReuseType, WDAcc, VarAcc, Env, b(negation(b(implication(A,B),pred,[])),pred,[]), NewEnv1, WDAcc1, ABoolFormula, NVarAcc1),
predicate_to_sat(ReuseType, WDAcc1, NVarAcc1, NewEnv1, b(negation(b(implication(B,A),pred,[])),pred,[]), NewEnv, WDPOs, BBoolFormula, NVarAcc),
% see (1)
disjunct_predicates([ABoolFormula,BBoolFormula], BoolFormula).
predicate_to_sat_e(conjunct(A,B), _, _, ReuseType, WDAcc, VarAcc, Env, NewEnv, WDPOs, BoolFormula, NVarAcc) :-
conjunction_to_list(b(conjunct(A,B),pred,[]), PList),
!,
map_predicate_to_sat(ReuseType, WDAcc, VarAcc, Env, PList, NewEnv, WDPOs, SatList, NVarAcc),
conjunct_predicates(SatList, BoolFormula).
predicate_to_sat_e(disjunct(A,B), _, _, ReuseType, WDAcc, VarAcc, Env, NewEnv, WDPOs, BoolFormula, NVarAcc) :-
disjunction_to_list(b(disjunct(A,B),pred,[]), PList),
!,
map_predicate_to_sat(ReuseType, WDAcc, VarAcc, Env, PList, NewEnv, WDPOs, SatList, NVarAcc),
disjunct_predicates(SatList, BoolFormula).
predicate_to_sat_e(Expr, _, _, _, WDAcc, VarAcc, Env, NewEnv, WDPOs, BoolFormula, VarAccOut) :-
( Expr == value(pred_true)
; Expr == value(pred_false)
),
!,
WDPOs = WDAcc,
VarAccOut = VarAcc,
safe_create_texpr(Expr, pred, [], BoolFormula),
NewEnv = Env.
predicate_to_sat_e(implication(Lhs,Rhs), pred, Info, ReuseType, WDAcc, VarAcc, Env, NewEnv, WDPOs, BoolFormula, NVarAcc) :-
!,
map_predicate_to_sat(ReuseType, WDAcc, VarAcc, Env, [Lhs,Rhs], NewEnv, WDPOs, NSatArgs, NVarAcc),
NSatArgs = [NSatLhs,NSatRhs],
safe_create_texpr(implication(NSatLhs,NSatRhs), pred, [smt_formula(b(implication(Lhs,Rhs),pred,Info))], BoolFormula).
predicate_to_sat_e(equivalence(Lhs,Rhs), pred, Info, ReuseType, WDAcc, VarAcc, Env, NewEnv, WDPOs, BoolFormula, NVarAcc) :-
!,
map_predicate_to_sat(ReuseType, WDAcc, VarAcc, Env, [Lhs,Rhs], NewEnv, WDPOs, NSatArgs, NVarAcc),
NSatArgs = [NSatLhs,NSatRhs],
safe_create_texpr(equivalence(NSatLhs,NSatRhs), pred, [smt_formula(b(equivalence(Lhs,Rhs),pred,Info))], BoolFormula).
predicate_to_sat_e(Expr, Type, Info, ReuseType, WDAcc, VarAcc, Env, NewEnv, WDPOs, BoolFormula, NVarAcc) :-
functor(Expr, _, Arity),
( Arity == 2
; Arity == 3
),
!,
reuse_or_introduce_bool_var(ReuseType, WDAcc, VarAcc, Env, b(Expr,Type,Info), boolean_true, NewEnv, WDPOs, BoolFormula, NVarAcc).
predicate_to_sat_e(Expr, Type, Info, ReuseType, WDAcc, VarAcc, Env, NewEnv, WDPOs, BoolFormula, NVarAcc) :-
% formula is a singleton pred which is not splitted such as a subset
reuse_or_introduce_bool_var(ReuseType, WDAcc, VarAcc, Env, b(Expr,Type,Info), boolean_true, NewEnv, WDPOs, BoolFormula, NVarAcc).