% Discount Example with GCLP

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

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

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

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

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

% q_c_j
discount_c_1(5,C) :- silver(C).
discount_c_2(10,C) :- gold(C).

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

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

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