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

Artificial Intelligence: Introduction To Prolog

Prolog is a logic programming language that is declarative rather than imperative. A Prolog program consists of facts and rules stated in terms of predicates and variables. The Prolog interpreter can answer queries by searching the database of facts and rules to determine if the query logically follows. Prolog is well-suited for artificial intelligence applications like expert systems and natural language processing due to its basis in logical rules.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
51 views

Artificial Intelligence: Introduction To Prolog

Prolog is a logic programming language that is declarative rather than imperative. A Prolog program consists of facts and rules stated in terms of predicates and variables. The Prolog interpreter can answer queries by searching the database of facts and rules to determine if the query logically follows. Prolog is well-suited for artificial intelligence applications like expert systems and natural language processing due to its basis in logical rules.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14

ARTIFICIAL

INTELLIGENCE
Introduction to Prolog
Prolog
◦ PROgramming LOGic

◦ It is most widely used programming language

◦ Main applications:
◦ Artificial Intelligence: expert systems, natural language
processing, …

◦ Mathematics: theorem proving, …


Prolog
◦ Prolog is a declarative language

◦ A program is a collection of axioms from which theorems


can be proven.
◦ Rather than describing how to compute a solution, a program
consists of a database of facts and logical relationships (rules)
◦ Rather than running a program to obtain a solution, the user
asks a question. When asked a question, the run time system
searches through the database of facts and rules to determine
the answer by logical deduction
Prolog Program
◦ Set of specifications in the first-order predicate calculus
describing the objects and relations in a problem domain.

◦ Set of specifications – database

◦ Prolog interpreter responds to questions about this database


◦ Uses pattern directed search
◦ Process queries, searching the database in left to right depth-first
order
◦ It basically checks if the query is a logical sequence of the
database of the specifications
Syntax for Predicate Calculus
Programming
ENGLISH PREDICATE PROLOG
CALCULUS

and  ,

or  ;

implication  :-

not  not
Prolog as Logic
◦ Logic formula:
◦ Logic OR – AB : A;B.

◦ Logic AND – AB : A,B.

◦ Logic NOT - A : not A.

◦ Logic implication: A→B : B:-A.

◦ Each expression terminates with a period ‘.’


Simple Example
◦ Describing George’s, Kate’s and Susie’s likes and dislikes
using following predicates:

◦ likes(george, kate).
◦ likes(george, susie).
◦ likes(george, chocolate).
◦ likes(susie, chocolate).
◦ likes(kate, sushi).
◦ likes(kate, susie).
Queries given about the
database
◦ ?- likes(george, kate).
◦ yes

◦ ?- likes(kate, susie).
◦ yes

◦ ?- likes(george, X).
◦ X = kate
◦ ;
◦ X = susie
◦ ;
◦ X = chocolate
◦ ;
◦ no
Defining Rules
◦ Only one predicate is permitted on the left hand side

◦ This must be a positive literal (negation cannot be applied


to it)

◦ All predicate calculus expressions that contain implication


or equivalence must be reduced to this form – horn clause
logic
◦ Left side of the implication must be a single positive literal
Adding a rule in likes/dislikes
database
◦ In order to check if two people are friends based on their
likes/dislikes

◦ A rule can be constructed as follows:


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

◦ ?- friends(george, susie).

◦ yes
A Simple Rule
◦ English description:
◦ If X is male, F is a father of X, M is a mother of X, F is a father of Y, M is a
mother of Y then X is a brother of Y.

◦ Logic Formula:
◦ male(X)  father(F,X)  mother(M,X)  father(F,Y)  mother(M,Y) →
brother(X,Y)

◦ Prolog:
◦ Brother(X,Y) :- male(X), father(F,X), mother(M,X), father(F,Y),
mother(M,Y).
Another example
◦ Facts
◦ bigger(elephant, horse).
◦ bigger(horse, donkey).
◦ bigger(donkey, dog).
◦ bigger(donkey, monkey).
◦ Queries
◦ ?- bigger(donkey, dog).
◦ Yes

◦ ?- bigger(monkey, elephant).
◦ No
Another example
◦ Facts
◦ bigger(elephant, horse).
◦ bigger(horse, donkey).
◦ bigger(donkey, dog).
◦ bigger(donkey, monkey).
◦ Queries
◦ ?- bigger(elephant, monkey).
◦ No

◦ To incorporate this, we will have to add a new relation – isbigger


Another example

◦ is_bigger(X, Y) :- bigger(X, Y).

◦ is_bigger(X, Y) :- bigger(X, Z), is_bigger(Z, Y).

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