simplify_b_predicate2(truth,Type,Res) :- !,
create_texpr(truth,Type,[],Res).
simplify_b_predicate2(falsity,Type,Res) :- !,
create_texpr(falsity,Type,[],Res).
simplify_b_predicate2(negation(BExpr),_Type,Res) :- !,
simplify_negation(BExpr,Res).
simplify_b_predicate2(conjunct(LHS,RHS),Type,Res) :- !,
simplify_b_predicate(LHS,SimplifiedLHS),
( is_false_constant(SimplifiedLHS) -> % FALSE & f == FALSE
create_texpr(falsity,Type,[],Res)
; is_true_constant(SimplifiedLHS) -> % TRUE & f == f
simplify_b_predicate(RHS,Res)
;
simplify_b_predicate(RHS,SimplifiedRHS),
( is_false_constant(SimplifiedRHS) -> % f & FALSE == FALSE
create_texpr(falsity,Type,[],Res)
; is_true_constant(SimplifiedRHS) -> % f & TRUE == f
Res = SimplifiedLHS
; same_texpr(SimplifiedLHS,SimplifiedRHS) -> % f & f == f (idempotence)
Res = SimplifiedLHS
; is_absorption_rule_conjunct(SimplifiedLHS,SimplifiedRHS,Res) -> % f & (f or g) == f (absorption)
true
; test_transitivity(SimplifiedLHS,SimplifiedRHS,Res) -> % (f => g) & (g => h) == (f => h)
true
;
conjunct_predicates([SimplifiedLHS,SimplifiedRHS],Res)
)
).
simplify_b_predicate2(disjunct(LHS,RHS),Type,Res) :- !,
simplify_b_predicate(LHS,SimplifiedLHS),
( is_true_constant(SimplifiedLHS) -> % TRUE or f == TRUE
create_texpr(truth,Type,[],Res)
; is_false_constant(SimplifiedLHS) -> % FALSE or f == f
simplify_b_predicate(RHS,Res)
;
simplify_b_predicate(RHS,SimplifiedRHS),
( is_true_constant(SimplifiedRHS) -> % f or TRUE == TRUE
create_texpr(truth,Type,[],Res)
; is_false_constant(SimplifiedRHS) -> % f or FALSE == f
Res = SimplifiedLHS
; same_texpr(SimplifiedLHS,SimplifiedRHS) -> % f or f == f (idempotence)
Res = SimplifiedLHS
; is_absorption_rule_disjunct(LHS,RHS,Res) -> % f or (f & g) == f (absorption)
true
;
disjunct_predicates([SimplifiedLHS,SimplifiedRHS],Res)
)
).
simplify_b_predicate2(implication(LHS,RHS),_Type,Res) :- !,
simplify_b_predicate(RHS,SimplifiedRHS),
simplify_implication(LHS,SimplifiedRHS,Res).
simplify_b_predicate2(equivalence(LHS,RHS),Type,Res) :- !,
simplify_b_predicate(LHS,SimplifiedLHS),
simplify_b_predicate(RHS,SimplifiedRHS),
( same_texpr(SimplifiedLHS,SimplifiedRHS) -> % f <=> f == TRUE
create_texpr(truth,Type,[],Res)
; is_negation_of(SimplifiedLHS,SimplifiedRHS) -> % f <=> not(f) == FALSE
create_texpr(falsity,Type,[],Res)
;
create_equivalence(SimplifiedLHS,SimplifiedRHS,Res)
).
simplify_b_predicate2(equal(LHS,RHS),Type,Res) :- !,
print(equal(LHS,RHS)),nl,
simplify_b_predicate(LHS,SimplifiedLHS),
simplify_b_predicate(RHS,SimplifiedRHS),
(same_texpr(SimplifiedLHS,SimplifiedRHS) ->
create_texpr(truth,Type,[],Res)
; different_texpr_values(SimplifiedLHS,SimplifiedRHS) ->
create_texpr(falsity,Type,[],Res)
;
compare('==',SimplifiedLHS,SimplifiedRHS,equal,Type,Res)
%% extract_info(SimplifiedLHS,SimplifiedRHS,Info),
%% create_texpr(equal(SimplifiedLHS,SimplifiedRHS),Type,Info,Res)
).
simplify_b_predicate2(not_equal(LHS,RHS),Type,Res) :- !,
simplify_b_predicate(LHS,SimplifiedLHS),
simplify_b_predicate(RHS,SimplifiedRHS),
(same_texpr(SimplifiedLHS,SimplifiedRHS) ->
create_texpr(falsity,Type,[],Res)
; different_texpr_values(SimplifiedLHS,SimplifiedRHS) ->
create_texpr(truth,Type,[],Res)
;
compare('=\\=',SimplifiedLHS,SimplifiedRHS,not_equal,Type,Res)
%% extract_info(SimplifiedLHS,SimplifiedRHS,Info),
%% create_texpr(not_equal(SimplifiedLHS,SimplifiedRHS),Type,Info,Res)
).
simplify_b_predicate2(greater(LHS,RHS),Type,Res) :- !,
simplify_b_predicate(LHS,SimplifiedLHS),
simplify_b_predicate(RHS,SimplifiedRHS),
compare('>',SimplifiedLHS,SimplifiedRHS,greater,Type,Res).
simplify_b_predicate2(greater_equal(LHS,RHS),Type,Res) :- !,
simplify_b_predicate(LHS,SimplifiedLHS),
simplify_b_predicate(RHS,SimplifiedRHS),
compare('>=',SimplifiedLHS,SimplifiedRHS,greater_equal,Type,Res).
simplify_b_predicate2(less(LHS,RHS),Type,Res) :- !,
simplify_b_predicate(LHS,SimplifiedLHS),
simplify_b_predicate(RHS,SimplifiedRHS),
compare('<',SimplifiedLHS,SimplifiedRHS,less,Type,Res).
simplify_b_predicate2(less_equal(LHS,RHS),Type,Res) :- !,
simplify_b_predicate(LHS,SimplifiedLHS),
simplify_b_predicate(RHS,SimplifiedRHS),
compare('=<',SimplifiedLHS,SimplifiedRHS,less_equal,Type,Res).
simplify_b_predicate2(forall(Ids,LHS,RHS),Type,Res) :- !,
simplify_b_predicate(RHS,SimplifiedRHS),
(is_true_constant(SimplifiedRHS) ->
create_texpr(truth,Type,[],Res)
;
simplify_b_predicate(LHS,SimplifiedLHS),
create_implication(SimplifiedLHS,SimplifiedRHS,ImplicationRes),
create_forall(Ids,ImplicationRes,Res)
).
simplify_b_predicate2(exists(Ids,Pred),Type,Res) :- !,
simplify_b_predicate(Pred,SimplifiedPred),
(is_true_constant(SimplifiedPred) ->
create_texpr(truth,Type,[],Res)
; is_false_constant(SimplifiedPred) ->
create_texpr(falsity,Type,[],Res)
;
create_or_merge_exists(Ids,SimplifiedPred,Res)
).
simplify_b_predicate2(member(Element,Set),Type,Res) :- !,
simplify_membership_predicate(Element,Set,Type,Res).
simplify_b_predicate2(not_member(Element,Set),Type,Res) :- !,
simplify_non_membership_predicate(Element,Set,Type,Res).
simplify_b_predicate2(BExpr,Type,Res) :-
create_texpr(BExpr,Type,[],Res).