% Discount Example with GCLP

% not(discount_s(...)).
not(discount_s(X)) :- discount_s(X),!,fail().
not(discount_s(X)).

% not(discount_r_1(...)).
not(discount_r_1(X)) :- discount_r_1(X),!,fail().
not(discount_r_1(X)).

% not(discount_r_2(...)).
not(discount_r_2(X)) :- discount_r_2(X),!,fail().
not(discount_r_2(X)).

% Facts
silver("Adrian").
gold("Adrian").
overrides("gold","silver").

% Rules
% q :- q_u, not(q_s).
discount(5) :- discount_u(5), not(discount_s(5)).
discount(10) :- discount_u(10), not(discount_s(10)).

% q_c_j
discount_c_1(5) :- silver("Gerald").
discount_c_2(10) :- gold("Gerald").

% q_u :- q_c_j, not(q_r_j)
discount_u(5) :- discount_c_1(5), not(discount_r_1(5)).
discount_u(10) :- discount_c_2(10), not(discount_r_2(10)).

% q_r_j
discount_r_1(5) :- discount_c_1(5), discount_c_2(10), overrides("gold","silver").
discount_r_2(10) :- discount_c_2(10), discount_c_1(5), overrides("silver","gold").

% q_s
discount_s(5) :- discount_u(5), discount_u(10).
discount_s(10) :- discount_u(10), discount_u(5).
					
% Goal
:- solve(discount(X)).