before_after_predicate_no_equalities_aux(assign_single_id(Id,Pred),Predicate,ChangedIDs) :- !,
before_after_predicate_no_equalities_aux(assign([Id],[Pred]),Predicate,ChangedIDs).
before_after_predicate_no_equalities_aux(assign(Ids,Preds),Predicate,ChangedIds) :- !,
maplist(get_changed_id,Ids,ChangedIds),
maplist(ba_predicate_equal,Ids,Preds,Predicates),
conjunct_predicates(Predicates,Predicate).
before_after_predicate_no_equalities_aux(becomes_element_of(Ids,Set),Predicate,Ids) :- !,
maplist(ba_predicate_member(Set),Ids,Predicates),
% THIS IS WRONG: it asserts that each Id is an element of Set, but the tuple Ids is an element!
conjunct_predicates(Predicates,Predicate). % should we generate Set /= {} => Predicate
before_after_predicate_no_equalities_aux(becomes_such(Ids,Pred),Predicate,Ids) :- !,
ba_predicate_becomes_such(Ids,Pred,Predicate).
before_after_predicate_no_equalities_aux(choice(Choices),Predicate,ChangedIDs) :- !,
maplist(before_after_predicate_no_equalities,Choices,BAChoices,Changes),
append(Changes,ChangedIDs),
maplist(add_missing_equalities(ChangedIDs),BAChoices,BAChoicesWithEqualities),
disjunct_predicates(BAChoicesWithEqualities,Predicate).
before_after_predicate_no_equalities_aux(precondition(Pre,Body),Predicate,ChangedIDs) :- !,
before_after_predicate_no_equalities(Body,BABody,ChangedIDs),
create_implication(Pre,BABody,Predicate).
before_after_predicate_no_equalities_aux(witness_then(Pre,Body),Predicate,ChangedIDs) :- !,
before_after_predicate_no_equalities_aux(assertion(Pre,Body),Predicate,ChangedIDs). % TODO: check if ok, or if we should use SELECT
before_after_predicate_no_equalities_aux(assertion(Pre,Body),Predicate,ChangedIDs) :-
!,
before_after_predicate_no_equalities(Body,BABody,ChangedIDs),
create_implication(Pre,BABody,Predicate1),
create_negation(Pre,NotPre),
add_missing_equalities(ChangedIDs,b(truth,pred,[]),NotPrePredicate),
create_implication(NotPre,NotPrePredicate,Predicate2),
conjunct_predicates([Predicate1,Predicate2],Predicate).
before_after_predicate_no_equalities_aux(select_when(Pre,Body),Predicate,ChangedIDs) :- !,
before_after_predicate_no_equalities(Body,BABody,ChangedIDs),
conjunct_predicates([Pre,BABody],Predicate).
before_after_predicate_no_equalities_aux(select(Whens),Predicate,ChangedIDs) :- !,
maplist(before_after_predicate_no_equalities,Whens,WhensPredicates,Changes),
append(Changes,ChangedIDs),
maplist(add_missing_equalities(ChangedIDs),WhensPredicates,WhensPredicatesWithEqualities),
disjunct_predicates(WhensPredicatesWithEqualities,Predicate).
before_after_predicate_no_equalities_aux(select(Whens,Else),Predicate,ChangedIDs) :- !,
maplist(before_after_predicate_no_equalities,Whens,WhensPredicates,Changes),
maplist(add_missing_equalities(ChangedIDs),WhensPredicates,WhensPredicatesWithEqualities),
maplist(get_select_conditions,Whens,SelectConditions),
disjunct_predicates(SelectConditions,ElseTemp),
create_negation(ElseTemp,ElseLHS),
before_after_predicate_no_equalities(Else,ElseRHS,ElseChangedIDs),
append([ElseChangedIDs|Changes],ChangedIDs),
conjunct_predicates([ElseLHS,ElseRHS],ElsePred),
add_missing_equalities(ChangedIDs,ElsePred,ElsePredWithEqualities),
disjunct_predicates([ElsePredWithEqualities|WhensPredicatesWithEqualities],Predicate).
before_after_predicate_no_equalities_aux(sequence(ListOfSteps),Predicate,ChangedIDs) :- !,
ba_predicate_sequence(ListOfSteps,Predicate,ChangedIDs).
before_after_predicate_no_equalities_aux(if(IfList),Predicate,ChangedIDs) :- !,
ba_predicate_if(IfList,Predicate,ChangedIDs).
before_after_predicate_no_equalities_aux(let(P,D,B),Predicate,ChangedIDs) :- !,
before_after_predicate_no_equalities_aux(any(P,D,B),Predicate,ChangedIDs). % TO DO: create let_predicate
before_after_predicate_no_equalities_aux(any(Parameters,PreCond,Body),Predicate,ChangedIDs) :- !,
before_after_predicate_no_equalities(Body,BABody,ChangedIDs),
conjunct_predicates([PreCond,BABody],Inner),
create_or_merge_exists(Parameters,Inner,Predicate).
before_after_predicate_no_equalities_aux(parallel(P),Predicate,ChangedIDs) :- !,
maplist(before_after_predicate_no_equalities,P,Preds,Changes),
append(Changes,ChangedIDs),
conjunct_predicates(Preds,Predicate).
before_after_predicate_no_equalities_aux(skip,Predicate,[]) :- !,
Predicate = b(truth,pred,[]).
before_after_predicate_no_equalities_aux(var(Parameters,Body),Predicate,ChangedIDs) :- !,
before_after_predicate_no_equalities(Body,BABody,ChangedIDs),
create_or_merge_exists(Parameters,BABody,Predicate).
before_after_predicate_no_equalities_aux(rlevent(_Name,_Section,_Stat,_Parameters,Guards,_Thm,Actions,_VWit,_PWit,_Unmod,_AbsEvents),Predicate,ChangedIDs) :- !,
maplist(before_after_predicate_no_equalities,Actions,BAActions,Changes),
append(Changes,ChangedIDs),
conjunct_predicates([Guards|BAActions],Predicate). % should probably be an implication? see precondition.
before_after_predicate_no_equalities_aux(operation_call(OpId,[],[]),Predicate,ChangedIDs) :- !,
get_texpr_id(OpId,op(OpName)),
b_get_machine_operation(OpName,[],[],OpBody),
before_after_predicate_no_equalities(OpBody,Predicate,ChangedIDs).
before_after_predicate_no_equalities_aux(Expr,Predicate,ChangedIDs) :-
add_error_fail(before_after_predicate,'before-after-predicate implementation missing: ',[Expr,Predicate,ChangedIDs]).