/* hifi(Name, Rms, Tapes, Cds, Turntable, Price) */ hifi(sony, 28, 2,1,1,279). hifi(aiwa, 25, 2,1,1,249). hifi(sanyo,12, 2,3,1,219). hifi(pioneer,40,2,1,0,379). hifi(akai, 12, 2,3,1,379). preferable( Hifi, Price) :- hifi(Name, Rms, Tapes, Cds, Turntable, Price), Rms > 25. preferable( Hifi, Price) :- hifi(Name, Rms, Tapes, Cds, Turntable, Price), Tapes > 1. will_do( Hifi, Price) :- hifi(Name, Rms, Tapes, Cds, Turntable, Price), Tapes > 0. will_do( Hifi, Price) :- hifi(Name, Rms, Tapes, Cds, Turntable, Price), Rms > 10.
Program is constructed from :
Procedures : set of clauses about the same relation,
containing the same predicate in their heads.
Price is a shared variable - restricts range.
Procedures are :
hifi/6
preferable/2
will_do/2
The Program constitutes the formal definition of
the problem, it is not yet the solution. The solution is
what occurs when we ask Prolog a question.
preferable( Hifi, Price), Price < 200.
no
preferable( Hifi, Price), Price < 300.
Hifi=sony, Price=279
{Hifi=akai, Price=279)