In Prolog there are three basic constructs: facts, rules, and queries. A collection of facts and rules is called a knowledge base (or a database). The main advantage of Prolog is simple questions asking about the information stored in the knowledge base. Prolog knowledge base example – facts
Prolog query example
Prolog answers […]
Bookies wants to take some bets and of course they want to make profit with it. All they have are latest results from friendly matches.Predicate win(Team1, Team2, Result) means that the first team won the match with the Result. Initial knowledge database
win(portugal, saudi_arabia, 3-0).
win(mexico, paraguay, 2-1).f
win(mexico, congo, 2-1).
win(argentina, portugal, 3-2).
win(mexico, gana, 1-0).
win(portugal, croatia, 2-0).
win(netherlands, ivory_coast, 3-1).
win(argentina, hungary, 2-1).
win(netherlands, ecuador, 1-0).
win(portugal, egypt, 2-0).
win(croatia, argentina, 3-2).
win(ivory_coast, slovenia, 3-0).
win(south_corea, mexico, 1-0).
win(netherlands, mexico, 2-1).
Predicate to return difference between points Write predicate gd(Team, GD) that returns […]
We plan a trip to Tokio. We have data about plane flights. For each flight we know duration of flight and distance between airports. Our data is being stored in predicates flight(StartAirport, DestinationAirport, Duration, Distance). On each airport we spent some time waiting (customs etc.) and this waiting time is different for each airport. Data […]
Prolog predefined stuff Useful custom functions = – unification = – true if unification fails == – identity == – identity predicate negation =:= – arithmetic equality predicate == – arithmetic equality negation member(X,List) conc(L1,L2,List) add(X,L,L1) del(X,L,L1) insert(X,L,L1) sublist(S,L) permutation(X,L)oddLength(L) evenLength(L)reverse(List,ReversedList)maxList(List,Max) ordered(List) subsum(Set,Sum,Subset) X<Y X>Y X>=Y X<=Y custom operator :-op(precedense,xfy,name). cut ! true, fail %(P,!,fail;true). […]