Prolog

1 / 28
next
Slide 1: Slide
Artificial IntelligenceSecondary EducationUniversity

This lesson contains 28 slides, with interactive quizzes and text slides.

Items in this lesson

Slide 1 - Slide

Prolog Introduction
Prolog is a computer programming language.
It has been chosen by many programmers for applications of symbolic computation, including-
  1. Relation databases
  2. Mathematical logic
  3. Abstract problem solving
  4. Understanding natural language

Slide 2 - Slide

Prolog Introduction...Continued
  5. Design Automation
  6. Symbolic Equation Solving
  7. Biochemical Structure analysis
  8. Many areas of ARTIFICIAL INTELLIGENCE
      ...... and many more 

Slide 3 - Slide

Prolog Syntax
Terms: It is the central data structure in Prolog.
Types of Terms:
  • Constants   -  Atoms,  Numbers
  • Variables
  • Compound terms or Structures
  • Ground Term -    A term that doesn’t contain any variables is called a ground term.

Slide 4 - Slide

Compound Term / Structure
It is a single object consisting of a collection of other objects, called Components.
Functor: It names the general kind of structure and corresponds to a data-type in an ordinary programming language.
Components: are enclosed in round brackets and separated by commas.
Components can be any prolog term i.e., atoms, numbers, variables, or other structures.

Slide 5 - Slide

Example:

  • owns(john, book(wuthering_heights, bronte)).
  • owns(john, book(wuthering_heights, author(emily,bronte))). 
  • Is_bigger(horse,X), 
  • f(g(X, _), 7), 
  • ‘My Functor’(dog)

Slide 6 - Slide

Test the Unification

Slide 7 - Slide

pilots(A,london) = pilots(london, paris)

Slide 8 - Open question


points(X,Y,Z)=points(X1,Y1,Z1)

Slide 9 - Open question

p(X,2,2) = p(1,Y,X).

Slide 10 - Open question

p( _, 2, 2) = p( 1, Y, _).

Slide 11 - Open question

Comments in prolog
Single Line Comments: 
  •      Starts with percent (%) sign.
  •      example-   
  •            aunt( X, Z ) :- 
  •                    sister( X, Y ),     % A comment on this suboal.
  •                     parent( Y, Z).

Example - 

Slide 12 - Slide

Comments in prolog
Multi-line comments:
  •  These are enclosed between the two signs /* and */.
  •  Example - 
  •       /* This is a comment.  */

Slide 13 - Slide

Q. Given the following predicates, ask the name of the person, whose position you want to ask, and return the position of the person using a declarative statement.
position("Komal",'Teacher').
position('Joy','director').
position("Raj",manager).
position('Hasan','supervisor').

Slide 14 - Slide

Example using write / read
position("Kowalczyk",'Teacher').
position('Joy','director').
position("Raj",manager).
position('Hasan','supervisor').

find_position:-
        write('Whose position do you wish to know?'),nl,
        read(Input), position(Input, Output),
        write('The position of '), write(Input),
        write(' is '), write(Output), write(' . ').

Slide 15 - Slide

Represent the following statements in the form of clauses 

Slide 16 - Slide

1. John is a thief.
2. John likes anything that likes wine.

Slide 17 - Open question

3. Mary likes wine.
4. Mary likes Chocolates.

Slide 18 - Open question

5. A person may steal something if the person is a thief and the person likes the thing.

Slide 19 - Open question

Given the above mentioned rules and facts, infer the information 'what John can steal...'

Slide 20 - Slide

Q2.   Given the reigns of Mughal Emperors as facts, create a rule that can answer who was on the Indian throne during a particular year.
reigns( babur, 1526, 1530).
reigns( humayun, 1530, 1540).
reigns( humayun, 1555, 1556).
reigns( Akbar, 1556, 1605).
reigns( jahangir, 1605, 1627).
reigns( shahjahan, 1628, 1658).

Slide 21 - Slide

Q3. Given the population and area of a country, find its population density.
pop( india, 548 ).
pop( china, 800 ).
pop( brazil, 108 ).
pop( usa, 203 ).
area( usa, 3 ). 
area( india, 1 ).
area( china, 4 ).
area( brazil, 3 ).

Slide 22 - Slide

Question-4
Write a predicate that takes two numbers as input and gives the result of the following arithmetic operations:
  • Addition                                                      minimum(x,y)
  • Subtraction                                               maximum(x,y)
  • Integer Division                                       squareRoot(X)
  • Multiplication
  • x^y

Slide 23 - Slide

Q. Given the following predicates, ask the name of the person, whose position you want to ask, and return the position of the person using a declarative statement.
position("Komal",'Teacher').
position('Joy','director').
position("Raj",manager).
position('Hasan','supervisor').

Slide 24 - Open question

Slide 25 - Slide

Success Criteria- Now ,I CAN
create facts, rules in prolog clearly, and understand the applications of prolog by implementing it.

A
Strongly Agree
B
Agree
C
Not Sure
D
Need Help

Slide 26 - Quiz


THANK YOU!

Slide 27 - Slide

Slide 28 - Slide