define_operators :-
op( 920, xfy, and),
op( 930, xfy, or),
op( 940, xfx, cf),
op( 950, xfx, then),
op( 960, fx, if),
op( 970, xfx, ':').
?- define_operators.
solve( P1 and P2) :-
solve( P1),
solve( P2).
solve( P1 or P2) :-
solve( P1) ;
solve( P2).
solve( not P) :-
not solve( P).
solve( P) :-
Rule: if P0 then P,
solve( P0).
solve( P) :-
Fact : P.
solve( P) :-
askable( P),
told( P, yes).
solve( P) :-
askable( P),
not told( P, _),
ask( P).
ask( P) :-
nl, write( P), write( ' ? '),
read( A), respond( P, A).
respond( P, yes) :-
assert( told( P, yes)), !.
respond( P, no) :-
assert( told( P, no)),
!, fail.
respond( P, _) :-
write(' valid answers are: yes, no'),
ask( P).
init :-
retractall( told( _, _)).
diagnose( D) :-
init,
Fact : diagnosis( D),
solve( D).
askable( S) :-
Fact : symptom( S).
Back to example 10.1
r1 :
if material_verbrennt
then temperatur( zu_hoch).
r2 :
if temperatur( zu_hoch)
or temperatur( zu_niedrig)
then temperatur( falsch).
r3 :
if temperatur( falsch)
and thermostat( richtig_eingestellt)
then thermostat( defekt).
r4 :
if temperatur( falsch)
and not thermostat( richtig_eingestellt)
then thermostat( richtig_einstellen).
r5_1 :
if kein_dampf
then temperatur( zu_niedrig).
r5_2 :
if kein_dampf
then dampfsystem_problem.
r6_1 :
if dampfsystem_problem
then kein_wasser.
r6_2 : if dampfsystem_problem
then duese_verstopft.
r7 :
if buegelwirkung_schlecht
then temperatur( zu_niedrig).
r8 :
if buegeleisen_kalt
and lampe_leuchtet
then warten.
r9 :
if buegeleisen_kalt
and not lampe_leuchtet
then kein_strom.
s1 :
symptom( material_verbrennt).
s2 :
symptom( kein_dampf).
s3 :
symptom( buegelwirkung_schlecht).
s4 :
symptom( buegeleisen_kalt).
s5 :
symptom( lampe_leuchtet).
s6 :
symptom( thermostat( richtig_eingestellt)).
d1 :
diagnosis( thermostat( defekt)).
d2 :
diagnosis( thermostat( richtig_einstellen)).
d3 :
diagnosis( kein_wasser).
d4 :
diagnosis( duese_verstopft).
d5 :
diagnosis( kein_strom).
d6 :
diagnosis( warten).
Back to example 10.2