Prolog knowledge base

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 […]

Prolog example – bookies exercise

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

Predicate to return difference between points Write predicate gd(Team, GD) that returns […]

Prolog cheat sheet

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). […]

Prolog odd / even length list function

Prolog reverse list function

 

Prolog function – add member element to list