equation_slicing2([],Predicates,_Identifiers,Used,Used,[],Predicates,[]).
equation_slicing2([Sel|Srest],Predicates,Identifiers,UsedOld,UsedNew,NEE,SP,Eq) :-
( memberchk(Sel,UsedOld) -> % identifier was already processed
equation_slicing2(Srest,Predicates,Identifiers,UsedOld,UsedNew,NEE,SP,Eq)
; nonmember(Sel,Identifiers) -> % an id that is not relevant for us (e.g. an enumerated set element)
equation_slicing2(Srest,Predicates,Identifiers,UsedOld,UsedNew,NEE,SP,Eq)
; contains_equation(Sel,Predicates,Expression,Equation,RestPredicates) -> % we found an equation!
Eq = [Equation|Erest], % store it
find_identifier_uses(Expression,UsedOld,NewIds), % extract all used identifiers in the equation
append(NewIds,Srest,NewSelected), % and continue with all found identifiers recursively
equation_slicing2(NewSelected,RestPredicates,Identifiers,[Sel|UsedOld],UsedNew,NEE,SP,Erest)
; % we encountered an identifier that seems to be relevant but is not defined by an equation
NEE = [Sel|Nrest], % we just store it for later use
equation_slicing2(Srest,Predicates,Identifiers,[Sel|UsedOld],UsedNew,Nrest,SP,Eq)).