% -*-Prolog-*- :- expects_dialect(pfc). %% a simple Pfc example - the standard circuit diagnosis problem. %% %% Tim Finin, finin@prc.unisys.com, 9/29/88 % Devices behave as intended unless they are faulty. isa(X,Class), ~faulty(X) ==> behave(X,Class). % a wire equates the values at each end. wire(T1,T2) ==> (value(T1,V) <==> value(T2,V)). % It is a conflict if a terminal has two different values. value(T,V1), value(T,V2)/(\+V1=:=V2) ==> conflict(two_values(T,V1,V2)). % assume an observation is true. observed(P), ~false_observation(P) ==> P. % a conflict triggers a Prolog action to resolve it. conflict(C) ==> {resolveConflict(C)}. % this isn't written yet. resolveConflict(C) :- format("~NHalting with conflict ~w", [C]), pfcHalt. % an adder's behaviour behave(X,adder) ==> (value(in(1,X),I1), value(in(2,X),I2) ==> {O is I1+I2}, value(out(X),O)), (value(in(2,X),I2) <- value(in(1,X),I1), value(out(X),O), {I2 is O-I1}), ( value(in(1,X),I1) <- value(in(2,X),I2), value(out(X),O), {I1 is O-I2}). % a multiplier's behaviour. behave(X,multiplier) ==> (value(in(1,X),I1), value(in(2,X),I2) ==> {O is I1*I2}, value(out(X),O)), (value(in(2,X),I2) <- value(in(1,X),I1), value(out(X),O), {I2 is O/I1}), ( value(in(1,X),I1) <- value(in(2,X),I2), value(out(X),O), {I1 is O/I2}). % meta rules to schedule inferencing. % resolve conflicts asap pfcSelect(conflict(X)) :- pfcQueue(conflict(X)). %% ***** here is a particular test case. ***** % here is a particular circuit - a gizmo. isa(X,gizmo) ==> isa(m1(X),multiplier), isa(m2(X),multiplier), isa(m3(X),multiplier), isa(a1(X),adder), isa(a2(X),adder), wire(out(m1(X)),in(1,a1(X))), wire(out(m2(X)),in(2,a1(X))), wire(out(m2(X)),in(1,a2(X))), wire(out(m3(X)),in(2,a2(X))). %% here is a diagnostic problem for a gizmo. test(X) :- ain(isa(X,gizmo)), ain(value(in(1,m1(X)),3.0)), ain(value(in(2,m1(X)),2.0)), ain(value(in(1,m2(X)),3.0)), ain(value(in(2,m2(X)),2.0)), ain(value(in(1,m3(X)),2.0)), ain(value(in(2,m3(X)),3.0)), ain(observed(value(out(a1(X)),10.0))), ain(observed(value(out(a2(X)),12.0))).