0% found this document useful (0 votes)
6 views22 pages

Ch1_2 CS3032

The document provides an overview of Prolog, a logic programming language primarily used in artificial intelligence and computational linguistics. It covers the history, features, applications, and fundamental concepts of Prolog, including data objects, facts, rules, and queries. Additionally, it highlights Prolog's unique declarative nature and its differences from procedural programming languages.

Uploaded by

BT VITHU
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views22 pages

Ch1_2 CS3032

The document provides an overview of Prolog, a logic programming language primarily used in artificial intelligence and computational linguistics. It covers the history, features, applications, and fundamental concepts of Prolog, including data objects, facts, rules, and queries. Additionally, it highlights Prolog's unique declarative nature and its differences from procedural programming languages.

Uploaded by

BT VITHU
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 22

Logic Programming

CS 3032

3rd YEAR 1st SEMESTER


June, 2021
- CHAPTER 01 (Part II) -

2
An Overview of SWI- PROLOG

3
Overview of Prolog
▪ It is a logic programming language, associated with artificial intelligence &
computational linguistics.
▪ Although there are other Logic Programming languages, by far the most widely
used is Prolog.
▪ The name stands for Programming in Logic.
▪ It benefits for rule based logical quarries.
▪ Features:
o Think differently not procedurally, in declaratively manner. **
o Good for rapid prototyping
o Useful in many AI apps
o Not efficient as, C

4
History of Prolog

1972
• First Prolog interpreter introduced by Alain
Colmerauer and Philippe Roussel

1977
• David H. D Warren implemented DEC 10 compiler

1980
• Definite clause grammars implemented by Pereire
and Warren

5
History of Prolog

1980/1990
• Prolog specifically grown in Japan and Europe

2005
• NASA used Prolog to program natural language
interface.

2011
• Parts of IBM’s Watson QA supercomputer were
coded in Prolog.

6
Applications of Prolog
▪ Processing a natural language text, to answer questions about its meaning,
translate it to another language.
▪ Advisory systems for legal applications
▪ Maintaining databases for the Human Genome project
▪ Automatic story generation
▪ Analyzing and measuring social networks
▪ Supporting the development of complex software systems
▪ Automatically generating legally correct licenses and other documents in multiple
languages

7
Prolog is much different from other programming
languages
- Declarative
- Recursion
- Relations
- Unification

8
Fundamental idea behind a Prolog program:
- Describe the situation of interest
- Ask a question
- Logically deduce new facts about the situation you described
- produce deductions back as answers

9
Basic Operators in Prolog

Symbol / Keyword Terminology

?- This is the system prompt. The prompt indicates that the Prolog
system is ready for the user to enter a sequence of one or
more goals, which must be terminated by a full stop.

write(…..). Display the content in side the brackets on the user’s screen.

nl Stands for ‘start a new line’

?-halt. Causes the Prolog system to terminate


?-statistics. Causes system statistics (of value mainly to more experienced
users)

10
Logic Operators in Prolog

Logic Prolog
Implication B→ A A :- B

Conjunction A˄B A ,B

Disjunction A˅B A ;B

11
Data objects in Prolog
1. Numbers
▪ Prolog allows the use of integers. They are written as any sequence of
numeral from 0 to 9, optionally by a + or – sign.
Example: 212
-55
+100
017

▪ Prolog allows the use of numbers with decimal points. They are written in
the same way as integers, but contain a single decimal point, anywhere except
an optional + or – sign.
Example: -12.36
40.1
+448.
12
Data objects in Prolog (contd.)
2. Atoms
▪ Atoms are constants that do not have numerical values. There are three
ways in which atoms can be written.
i. Any sequence of one or more letters (upper or lower case), numerals
and underscores, beginning with lowercase letter.
Example mary / temperatue_value / d3_ABCD
(but not Year / temperature-value / 456abcd )

ii. Any sequence of characters enclosed in single quotes, including spaces


and upper case letters.
Example ‘temp value’ ‘temp-value’ ‘456abcd’

iii. Any sequence of one or more special characters from a list that
includes the following
Example >= > +++
13
Data objects in Prolog (contd.)

3. Variables
▪ A variable is a name used to stand for a term that is to be determined. It
can be denoted by any sequence of one or more letters (upper or lower
case), numerals and underscores, beginning with an upper case letter or
underscore.

Example X Male Student_1 _abcd


( but not 123_c Part-1 male )

▪ When a single underscore is used, it is known as the anonymous variable


and reserved for a special purpose.

14
Data objects in Prolog (contd.)

4. Compound Terms
▪ These are fundamental elements of Prolog programs. A compound term is a
structured data type which begins with an atom, known as functor as well. It
is followed by a sequence of one or more arguments that are enclosed in
brackets and separated by commas.

Example reads(john, book)


happy(X)
cat(Y)
>(3,2)
person(‘Kevin Hendry’ , 23, Engineer, Canada)

15
Data objects in Prolog (contd.)

5. Lists
▪ Lists are written as an unlimited number of elements enclosed in square
brackets and separated by commas

Example [23,34,56,78] [orange, apple, grapes]

▪ An element of a list may be a term of any kind, including a compound term


or another list.

Example [23,34,56,[1,2,3]] [[orange, 23, grapes],[aa, dd]]

▪ A list without elements is known as empty list, [ ].

16
Facts, Rules and Queries

17
Facts
A fact is a predicate expression that makes a declarative statement about the
problem domain. Whenever a variable occurs in a Prolog expression, it is assumed
to be universally quantified.

1. The sky is blue blue(sky).

2. Sam is a male male(sam).

3. Mary likes Riya likes(mary, riya).

18
Rules
Rules are the conditional statements about objects and their relationships.

1. If there is a smoke there is a fire fire :- smoke.

2. Mary likes Riya if Mary likes Yasi


likes(mary, riya) : - likes(mary, yasi).

3. X hates Y if X does not like Y


hates(X,Y) : - not(likes(X,Y)).

19
Facts & Rules in Prolog

likes(mary, riya). Dot – necessary to end


statements
Predicate name Arguments / Objects

likes(X,Y) : - likes(X, Z).

Head Body Variables


20
Queries in Prolog
Dot – necessary to
?-likes(mary, riya). end statements
true. Answer from prolog
interpreter
Prolog query prompt

?-likes(X,Y).
X=mary ,
Y=riya ; To get next solution
X=Jasun ,
Y=Dino . 21
Example 01: Change the following sentences into facts / rules

▪ Scooby is a dog.

▪ Millie is a cat.

▪ Every dog is an animal.

22

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy