Presentation is loading. Please wait.

Presentation is loading. Please wait.

PROLOG.

Similar presentations


Presentation on theme: "PROLOG."— Presentation transcript:

1 PROLOG

2 What is PROLOG? Prolog is a Declarative or logical Language.
Prolog takes only facts and rules to arrive at goals. The programmer doesn’t tell it how to solve. For solving logic and decision problems, Prolog is ideal. Typical applications: AI, Database apps, proving theorems, symbolic evaluation (i.e. differentiation).

3 How does Prolog work ? Prolog is based on ‘Horn Clauses’
Horn Clauses are a subset of ‘Predicate Logic’ Predicate logic is a way of simply defining how reasoning gets done in logic terms. Predicate Logic is a syntax for easily reading and writing Logical ideas.

4 Predicate Logic To transform an English sentence to Predicate Logic, we remove unnecessary terms. This leaves only the relationship and the entities involved, known as arguments. Ex: A pie is good = good(pie) The relation is ‘good’, the relation’s argument is ‘pie’. In Prolog, we call the relation’s name (e.g. “good”) the ‘Functor’. A relation may include many arguments after the functor.

5 Components of Prolog Facts and rules are the two important components in prolog.

6 Facts Facts have simple syntax and it always begin with lowercase letter. Eg : smaller(ant,grasshopper). smaller(ant,ladybird). smaller(ladybird,grasshopper). These facts are also known as clauses.

7 After compilation of the facts if we query the prolog system :
?- smaller(ant,ladybird). Yes. ?- smaller(grasshopper,ladybird). No.

8 Rules Any conditional statement about the world are stated rules in prolog. For representing rules :- symbol is used. Syntax of rule : Head :- body pattern Head is true if body is true.

9 fly(x) :- bird(x) bird(dove). ?-fly(A) A = dove

10 Prolog syntax 1. Atoms : are sting of lowercase and uppercase letter, digits, underscore. 2. Numbers : integers, floats 3. Variables : are string of lowercase and uppercase letter, digits, underscore. 4. Compound terms : consists of prolog atoms ‘functor’. Is_bigger(tiger,X)

11 Built-in Predicates ?- X=tiger, write(X),n1. Tiger. X=Tiger. Yes.

12 Matching ?- is_bigger(X,cat) = is_bigger(tiger,cat). X=tiger Yes
?- p(_,2,2) = p(1,Y,_) Y=2

13 List Manipulation List uses collection of terms.
List is denoted by square brackets []. [] means an empty list. The first element of the list is called head and remaining is called tail.

14 ?- [1,2,3,4,5] = [Head | Tail]. Head = 1 Tail = [2,3,4,5] Yes ?- [q,l,j,j,l,b] = [__,X | __] X=l

15 ?- concat_lists([1,2,3],[a,b,c,d],X)
X = [1,2,3,a,b,c,d] Yes

16 Built-in predicates in list
?– length(List,3) List = [A1,A2,A3] Yes ?– member(cat,[horse,donkey,cat,monkey]) ?- analyse_list([]) This is an empty list.

17 ?- analyse_list([dog,cat,horse,cow])
This is the head of your list : dog This is the tail of your list : [cat,horse,cow] Yes ?- remove_duplicates([a,b,a,c,d,d],List). List = [b,a,c,d]

18 ?- reverse_list([lion,elephant,monkey],List)
List = [monkey,elephant,lion] Yes ?- replace([1,2,3,4,3,5],3,x,List). List = [1,2,x,4,x,5]

19 Arithmetic operations in prolog
?- X is , X = 8 X = 8 Yes ?- 8 is 3 + 5

20 Functions in prolog Max Min Sqrt abs

21 relations >= <= =\= (not equal) =:= (equal)

22 structure Stores in form of record.
bookdetails(title,AI,publisher,spd). Query : ?- bookdetails(title,_,publisher,_) AI spd Yes


Download ppt "PROLOG."

Similar presentations


Ads by Google