% Risk Analysis for a system described in terms of and/or tree % sample tree: 1 fails if both 2 and 3 happen, 2 happens when either, 4 % or 5 happens. When can the system fail? and(1, 2, 3). or(2,4,5). go:-risk(1,P), write(P), nl, fail. % p operates on a list of events representing the probabillty % of ALL of them occuring. p([1,2,3]) is the probability of 1,2,and 3 % all happening at one time. % risk(N, P) is true when event N has probabillity P risk([],p([])):-!. risk(A,p(PA)):-and(A,B,C),!,risk(C,p(PC)),risk(B,p(PB)),merge(PC,PB,PA). risk(A,p(P)+p(Q)-p(R)):- or(A,B,C),!, risk(B, p(P)), risk(C, p(Q)),join(P,Q,R). risk(A,p([A])). merge(A,A,A):-!. merge([],A,A):-!. merge(A,[],A):-!. merge([X|R],[X|S],[X|T]):-!,merge(R,S,T). merge([X|R],[Y|S],[X|T]):-X