Information Technology Reference
In-Depth Information
Figure 11.9.
A knowledge base about car trouble
cars.pl
% The background knowledge
background([
[wipers, not(dead_battery)],
[radio, not(dead_battery), not(broken_speaker)],
[ignition, key_turned, not(dead_battery)],
[car_starts, not(out_of_gas), ignition],
[gauge_shows_gas, not(out_of_gas), not(dead_battery)],
[key_turned]]).
% Things that can go wrong
assumable(dead_battery).
assumable(out_of_gas).
assumable(broken_speaker).
Figure 11.10.
Explanations for car trouble
?- explain([not(car_starts)],[]).
No
?- explain([not(car_starts)],[A]).
A = dead_battery ;
A = out_of_gas
;
No
?- explain([not(car_starts),radio],[A]).
A = out_of_gas
;
No
?- explain([not(car_starts),not(radio),wipers],[A]).
No
?- explain([not(car_starts),not(radio),wipers],[A1,A2]).
A1 = broken_speaker,
A2 = out_of_gas
;
A1 = out_of_gas,
A2 = broken_speaker
;
No
?- explain([not(car_starts),not(radio),wipers],E).
E = [broken_speaker,out_of_gas]
;
E = [out_of_gas,broken_speaker]
;
ERROR: Out of global stack
The fourth query shows that no single-atom suffices to explain all three facts: the
car not starting, the radio not working, the wipers working.
 
Search WWH ::




Custom Search