0% found this document useful (0 votes)
68 views

Prolog Tutorial 1

This document provides an introduction to PROLOG, including its basics, compilers, syntax, execution flow, examples, and writing style. It describes PROLOG as a descriptive language that uses facts to define a knowledge database and rules. It gives examples of queries and rules involving terms about animal sizes. It also demonstrates printing output, checking term types, matching terms, and implementing logical reasoning about mortality.

Uploaded by

faxijo
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
68 views

Prolog Tutorial 1

This document provides an introduction to PROLOG, including its basics, compilers, syntax, execution flow, examples, and writing style. It describes PROLOG as a descriptive language that uses facts to define a knowledge database and rules. It gives examples of queries and rules involving terms about animal sizes. It also demonstrates printing output, checking term types, matching terms, and implementing logical reasoning about mortality.

Uploaded by

faxijo
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 17

CS-304N

Computational Intelligence

Basics of
PROLOG

Suchitra Agrawal
Research Scholar

Introduction Descriptive Language
• Describe using facts
• Knowledge Database consists of facts
• Define rules
• SWISH: SWI-Prolog for Sharing
Prolog Compiler
• GNU Prolog Compiler
Syntax

Terms Clauses
Atoms Facts
Numbers Rules
Variables Programs
Compound Terms Queries
Execution • Create Knowledge Base/Facts

Flow in • Generate Rules


• Submit Queries

Prolog
Examples

1.
Facts:
bigger(elephant, horse).
bigger(horse, donkey).
bigger(donkey, dog).
bigger(donkey, monkey).
Query:
a. ?- bigger(donkey, dog). Answer: Yes
b. ?- bigger(monkey, elephant). Answer: No
c. ?- bigger(elephant, monkey). Answer: No Why?
Examples

2.
Rules for previous data:
is_bigger(X, Y) :- bigger(X, Y).
is_bigger(X, Y) :- bigger(X, Z), is_bigger(Z, Y).

Query:
?- bigger(elephant, monkey). Answer: Yes
Examples

3.
Query:
?- is_bigger(X, donkey).
Examples

Answer: X = horse

How to get more answers?

Press ; till answer received is No


Examples

4.
Query:
?- is_bigger(donkey, X), is_bigger(X, monkey).

Answer:
No
Example:
Query:
?- write(‘Hello World’), n1.
Print Output
Output:
Hello World
Yes
Query:
?- X = elephant, write(X), n1.

Print Output Output:


elephant
X = elephant
Yes
Example:
1. ?- atom(elephant).
Yes
Check the type 2. ?- atom(Elephant).
of Prolog Term No
3. ?- X = f(mouse), compound(X).
X = f(mouse)
Yes
Example:
Query:
?- is_bigger(X, dog) = is_bigger(elephant, dog).
Answer:
X=elephant
Yes

Matching Query:
?- f(a, g(X, Y)) = f(X, Y), Z = g(W, h(X)).
Answer:
X=a
Y = h(a)
Z = g(a, h(a))
W=a
Yes
All men are mortal. Socrates is a man.
-> Hence, Socrates is mortal.

Implement in Prolog:
Goal
Execution mortal(X) :- man(X).
man(socrates).

?- mortal(socrates).
Yes
• Comment: /* Comment. */ Or
% Comment
• Spaces after every comma
Writing Style • Separate clauses by one or more blank
lines
• One predicate per line with indentation
THANK YOU

QUERIES??

You might also like