% Prolog code to demonstrate default reasoning.
% Copyright (c) David Poole and Alan Mackworth 2017. This program
% is released under GPL, version 3 or later; see http://www.gnu.org/licenses/gpl.html
:- dynamic on_beach/0, ab_beach_access/0, beach_access/0,
ab_swim_at_beach/0, enclosed_bay/0, big_city/0,
ab_no_swimming_near_city/0, in_BC/0, ab_BC_beaches/0.
away_from_beach :- \+ on_beach.
beach_access :- on_beach, \+ ab_beach_access.
swim_at_beach :- beach_access, \+ ab_swim_at_beach.
ab_swim_at_beach :- enclosed_bay, big_city, \+ ab_no_swimming_near_city.
ab_no_swimming_near_city :- in_BC, \+ ab_BC_beaches.
% some queries to try:
% ?- away_from_beach.
% ?- beach_access.
% ?- assert(on_beach). % this dynamically states a fact is true
% ?- away_from_beach.
% ?- swim_at_beach.
% ?- assert(enclosed_bay).
% ?- swim_at_beach.
% ?- assert(big_city).
% ?- swim_at_beach.
% ?- assert(in_BC).
% ?- swim_at_beach.
% single fact about p
p(a).
% what does \+p(b) return? What does this say about the relationship between a and b?