0% found this document useful (0 votes)
10 views15 pages

Prolog

Uploaded by

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

Prolog

Uploaded by

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

Prolo

g
Facts have some simple rules of syntax:

• Facts should always begin with a lowercase letter and end with a full stop.

• The facts themselves can consist of any letter or number combination, as well as
the underscore _ character.
• However, names containing the characters -,+,*,/, or other mathematical
operators should be avoided.
•Facts syntax:

relation(object1,object2,..).

Eg.fred eats meat.

eats(fred,meat).
variable

• A variable in Prolog is a string of letters, digits, and


underscores (_) beginning either with a capital letter or
with an underscore. Examples:
• Eg. X, Sister, _, _thing, _y47, First_name, Z2
• Propositions will either be true (if stated) or something to prove or
disprove (determine if it is true) – we do not include statements
which are false.

Propositions are represented by a predicate applied to a tuple of


terms. A predicate represents a property of or relation between terms
that can be true or false: Brother(John, Fred)

• An atomic proposition is a statement or assertion that must be true


or false.
• Compound terms (multiple propositions connected through the
logical operators of and, or, not, and implies)
• Knowledge representation:
1. Propositional Logic(PL): It is declarative either true or false.

2.First-order logic (FOL) refers to logic in which the predicate of


a sentence or statement can only refer to a single subject. It is
also known as first-order predicate calculus or first-order
functional calculus.
Eg. ∀x Cat(x) ⇒ Owns(Mary,x) Says that Mary owns all the cats in the
universe. Also true if there are no cats in the universe
Logic • Equivalence means that
both expressions have
identical truth tables
Operators
Name Symbol Example Meaning • Implication is like an if-
negation  a not a (\+) then statement
• if a is true then b is
conjunction  ab a and b(,) true
disjunction  ab a or b(;) • note that this does not
necessarily mean that if
equivalence  ab a is equivalent a is false that b must
to b also be false
• Universal quantifier says
implication  ab a implies b that this is true no matter
 ab b implies a what x is
universal  X.P For all X, P is • Existential quantifier says
true that there is an X that
fulfills the statement
existential X.P There exists a
value of X X.(woman(X)  human(X))
such that P is – if X is a woman, then X is a
true human

X.(mother(mary, X)  male(X))
Logical Not:
likes(ram,apple).

?- \+likes(ram,apple).
false.

?- likes(ram,apple).
true.
Logical and
likes(ram,apple).
likes(ram,mango).

?- likes(ram,mango),likes(ram,apple).
true.
?- likes(ram,mango),likes(ram,banana).
false.
Logical OR

likes(ram,apple).
likes(ram,mango).

?- likes(ram,mango);likes(ram,banana).
true
Claus
•eIt is group of words contain subject and predicate.
• Eg. Charlie runs.
• resolution is inference mechanism. we have two sentences (1)
All women like shopping. (2) Olivia is a woman.
Now we ask query 'Who likes shopping'. So, by resolving above
sentences we can have one new sentence Olivia likes shopping.
Example for applying
rules
eats(dog,vegitable).
eats(dog,meat).
eats(lion,meat).
carnivore(X):-
eats(X,vegitable),ea
ts(X,meat).

?- carnivore(dog).
true.
?- carnivore(lion).
false.
Example
Unification
• The idea is similar to that of unification in logic: we have two terms and
we want to see if they can be made to represent the same structure.
• The expression A=B is true if A and B are terms and unify (look identical)
arity
•?- a =
a. true
•?- a = b.
false
•Identify price of
hat. price(pen,20).
price(pencil,10).
price(hat,30).

•?- price(hat,X).
X = 30.
Other additional example:
max(X,Y,X):-X>Y.

?- max(11,10,Max).
Max = 11.

min(X,Y,X):-X<Y.
?- min(9,10,Min).
Min = 9.

You might also like