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SC+SD-1,SD1=:=1.

%Elementary Properties

elem(s(I,D,E,SC,SD),initial) :- I>=1,D=:=0,E=:=0,SC=:=0,SD=:=0.
elem(s(I,D,E,SC,SD),unsafe1) :- I>=0,E>=0,SC>=0,SD>=0, E+SC+SD>=1,D>=1.
elem(s(I,D,E,SC,SD),unsafe2) :- I>=0,D>=0,SC>=0,SD>=0, E>=1, SC+SD>=1.
elem(s(I,D,E,SC,SD),unsafe3) :- I>=0,E>=0,SC>=0,SD>=0, D>=2.
elem(s(I,D,E,SC,SD),unsafe4) :- I>=0,D>=0,SC>=0,SD>=0, E>=2.

%Temporal Properties

safe1 :- prop(not(ef(unsafe1))).
safe2 :- prop(not(ef(unsafe2))).
safe3 :- prop(not(ef(unsafe3))).
safe4 :- prop(not(ef(unsafe4))).
safe :- prop(not(or(ef(unsafe1),or(unsafe2,or(unsafe3,unsafe4))))).