Logicprogramming With Propositional and Predicate
Logicprogramming With Propositional and Predicate
Logic
• Logic is not concerned with what is true. Logic is the study of what follows from
what. What conclusions follow from a set of premises.
• It can be defined as study of principles of correct reasoning.
• The main thing we study in logic are principles governing the validity of arguments
and check that whether certain conclusion follows from some given assumption.
• Consider:
Alice likes everyone who likes logic
Alice likes logic
------------------------------------------------
Alice likes himself.
Example:
Let A be a Proposition: The machine is defective.
Let B be a Proposition: The production is less.
Why we use Propositional Logic?
• Its easier to check formulas.
• We can exploit the Boolean nature for efficient
reasoning.
• Its easier to incrementally add formulas.
• It can be extended infinitely to many variables using
logical quantifiers.
First-order Predicate Logic
• First-order predicate calculus (FOPL) was developed
by logicians to extend the expressiveness of
Propositional Logic.
• It is generalization of propositional logic that permits
reasoning about world entities (objects) as well as
classes and subclasses of objects.
• Prolog is also based on FOPL.
• Predicate logic uses variables and quantifiers which is
not present in propositional logic.
Why First-Order Predicate Logic ?
• Suppose we are having 2 statements , based on which
we have to draw a conclusion.
Facts
elephant(george).
Clauses elephant(mary).
elephant(X) :- grey(X), mammal(X), hasTrunk(X).
Rule
Example
?- elephant(george).
Queries
yes
?- elephant(jane).
Replies
no
Why Rules?
• Rule is an extension of fact with added conditions that
have to be specified for it to be true.
• Rule is much more compact than a list of facts.
• When facts depend on a group of other facts.
•Example: John likes all people who likes sweets.
Way 1: Write down separate facts as below –
likes(james, sweets).
likes(john, james).
likes(john, joe).
likes(john, david).
….. So on
Rules…
Way 2: John likes any object provided it is a person.
In Prolog,
likes(john, X) :- like(X, sweets).
Head Body
If
Example
First-order predicate calculus for the following logical
statements
• A horse is a mammal.
• A human is a mammal.
• Mammals have four legs and no arms, or two legs and
two arms.
• A horse has no arms.
• A human has arms.
• A human has no legs.
• A human has two arms.
• A human has two legs.
Example
To write a rule, X is a sister of Y
• X is a female.
• X has mother M and father F and
• Y has the same mother and father as X does.
sister_of(X, Y) :-
female(X),
parents(X, M, F),
parents(Y, M, F).
Example
• To define a rule “X is a grandfather of Y, if X is a
father of Z and Z is a parent of Y ” using logic
programming convention, then we write
grandfather(X, Y) :- father(X, Z) , parent(Z, Y).
no
Example
?- 2*3+4 = X+Y.
** The term 2*3+4 has principal functor +
X=2*3 and therefore unifies X+Y with X
instantiated to 2*3 and Y instantiated to 4 **
yes
Example
?- [a,b,c] = [X,Y,Z].
** Lists unify just like other terms **
X=a Y=b Z=c
yes
Example
Do the following pairs of items unify (match) ?
eats(fred,tomatoes)
eats(WHOM,WHAT)
Yes WHOM = fred and WHAT = tomatoes.
Example
cd(29,beatles,sgt_pepper).
cd(A,B,help).
f(X,Y)
f(P,P)
Yes X = P and Y = P. A variable (such as X) can be
bound to another variable (such as P). In this case
we can also infer that X = Y
Example
f(X,a)
f(a,X)
Yes X = a
Example
likes(jane,X)
likes(X,jim)
No X can not be bound to both jane and jim
f(foo,L)
f(A,A)
Yes A = foo and A = L. Hence L = foo
A and L are variables