AI-UNIT-3-2
AI-UNIT-3-2
PROPOSITIONAL LOGIC
Syllabus
Propositional logic in Artificial intelligence
Introduction
Propositional logic (PL) is the simplest form of logic
where all the statements are made by propositions. A
proposition is a declarative statement which is
either true or false. It is a technique of knowledge
representation in logical and mathematical form.
Example:
1.a) It is Sunday.
2.b) The Sun rises from West (False proposition)
3.c) 3+3= 7(False proposition)
4.d) 5 is a prime number.
Propositional Logic Facts
Following are some basic facts about propositional logic:
•Propositional logic is also called Boolean logic as it works on 0 and 1.
•In propositional logic, we use symbolic variables to represent the logic, and we can use any symbol
for a representing a proposition, such A, B, C, P, Q, R, etc.
•Propositions can be either true or false, but it cannot be both.
•Propositional logic consists of an object, relations or function, and logical connectives.
•These connectives are also called logical operators.
•The propositions and connectives are the basic elements of the propositional logic.
•Connectives can be said as a logical operator which connects two sentences.
•A proposition formula which is always true is called tautology, and it is also called a valid
sentence.
•A proposition formula which is always false is called Contradiction.
•A Statements which are questions, commands, or opinions are not propositions such as
"Where is Rohini", "How are you", "What is your name", are not propositions.
Ex. [~P^(P Q)]->Q
Ex.P->Q,~Q->~P
Propositional logic in Artificial
intelligence
A proposition is a statement - which in English is a declarative sentence and Logic defines the ways of
putting symbols together to form sentences that represent facts. Every proposition is either true or false.
Propositional logic is also called boolean algebra.
Examples:(a) The sky is blue.,
(c) 12 * 12=144
Propositional logic : It is fundamental to all logic. Propositions are “Sentences”; either true or false but not
both. A sentence is smallest unit in propositional logic If proposition is true, then truth value is "true"; else
“false”.
Example ; Sentence "Grass is green";
Truth value “ true”;
Proposition “yes”
Logical Connectives:
• Logical connectives are used to connect two simpler propositions or representing a sentence logically. We can
create compound propositions with the help of logical connectives. There are mainly five connectives, which are given as
follows:
1. Negation: A sentence such as ¬ P is called negation of P. A literal can be either Positive literal or negative literal.
2. Conjunction: A sentence which has ∧ connective such as, P ∧ Q is called a conjunction.
Example: Rohan is intelligent and hardworking. It can be written as,
P= Rohan is intelligent,
Q= Rohan is hardworking. → P∧ Q.
3. Disjunction: A sentence which has ∨ connective, such as P ∨ Q. is called disjunction, where P and Q are the
propositions.
Example: "Ritika is a doctor or Engineer",
Here P= Ritika is Doctor. Q= Ritika is Engineer, so we can write it as P ∨ Q.
4. Implication: A sentence such as P → Q, is called an implication. Implications are also known as if-then rules. It can be
represented as
If it is raining, then the street is wet.
Let P= It is raining, and Q= Street is wet, so it is represented as P → Q
5. Biconditional: A sentence such as P⇔ Q is a Biconditional sentence, example If I am breathing, then I am alive
Limitations of Propositional logic:
• We cannot represent relations like ALL, some, or none with
propositional logic. Example:
• All the girls are intelligent.
• Some apples are sweet.
• Propositional logic has limited expressive power.
• In propositional logic, we cannot describe statements in terms of their
properties or logical relationships.
Syntax of propositional logic:
Inference rules:
• Inference rules are the templates for generating valid arguments.
• Inference rules are applied to derive proofs in artificial
intelligence, and the proof is a sequence of the conclusion that leads
to the desired goal.
•Implication: It is one of the logical connectives which can
be represented as P → Q. It is a Boolean expression.
•Converse: The converse of implication, which means the
right-hand side proposition goes to the left-hand side and
vice-versa. It can be written as Q → P.
•Contrapositive: The negation of converse is termed as
contrapositive, and it can be represented as ¬ Q → ¬ P.
•Inverse: The negation of implication is called inverse. It
can be represented as ¬ P → ¬ Q.
From the above term some of the compound statements are equivalent to each other, which we can
prove using truth table:
As a result from the above truth table, we can prove that P → Q is equivalent to ¬ Q → ¬ P, and Q→ P is
equivalent to ¬ P → ¬ Q.
Types of Inference rules:
1. Modus Ponens:
One of the most essential laws of inference is the Modus Ponens rule, which asserts that if P and P → Q
are both true, we can infer that Q will be true as well. It's written like this:
Example:
Statement-1: "If I am sleepy then I go to bed" ==> P → Q
Statement-2: ""I am sleepy" ==> P"
Conclusion: "I go to bed." ==> Q.
Hence, we can say that, if P → Q is true and P is true then Q will be true.
Proof by Truth table:
2.Modus Tollens:
According to the Modus Tollens rule if P→ Q is true and ¬ Q is true, then ¬ P will also true. It can be
represented as:
Example:
Statement-1: "If I am sleepy then I go to bed" ==> P→ Q
Statement-2: "I do not go to the bed."==> ~Q
Statement-3: Which infers that "I am not sleepy" => ~P
Proof by Truth table:
3. Hypothetical Syllogism:
According to the Hypothetical Syllogism rule if P→R is true whenever P→Q is true, and Q→R is true. It
can be represented as the following notation:
Example:
Statement-1: Statement-1: If you have my home key then you can unlock my home. P→Q
Statement-2: Statement-2: If you can unlock my home then you can take my money. Q→R
Statement-3: Conclusion: If you have my home key then you can take my money. P→R
4. Disjunctive Syllogism:
According to the Disjunctive syllogism rule if P∨Q is true, and ¬P is true, then Q will be true. It can be
represented as:
Example:
Statement-1:Today is Sunday or Monday. ==>P∨Q
Statement-2:Today is not Sunday. ==> ¬P
Conclusion: Today is Monday. ==> Q
Proof by Truth table:
6. Simplification:
According to the simplification rule if P∧ Q is true,
then Q or P will also be true. It can be represented
as:
5. Addition:
According to the Addition rule which is one of the
common
inference rule, If P is true, then P∨Q will be true.
Proof by Truth table:
Example:
Statement-1: I have a vanilla ice-cream. ==> P
Statement-2: I have Chocolate ice-cream.
Conclusion: I have vanilla or chocolate ice-cream.
==> (P∨Q)
Proof by Truth table:
7. Resolution:
According to the Resolution rule if P∨Q and ¬ P∧R
is true, then Q∨R will also be true. It can be
represented as
not sufficient to represent the complex sentences or natural language statements. The
propositional logic has very limited expressive power. Consider the following sentence, which
Variables x, y, z, a, b,....
Connectives ∧, ∨, ¬, ⇒, ⇔
Equality ==
Quantifier ∀, ∃
• Constants: represent specific objects in the domain being modeled,
such as "0" or "1" in the domain of integers.
• Variables: represent arbitrary objects in the domain being modeled,
such as "x" or "y".
• Predicates: represent relationships between objects in the domain
being modeled, such as "equal to" or "greater than".
• Functions: represent operations that map objects in the domain being
modeled to other objects, such as "addition" or "multiplication".
• Quantifiers: include "for all" (∀) and "there exists" (∃), which allow
for statements about all objects in the domain or some objects in the
domain
USING FIRST ORDER PREDICATE LOGIC
Atomic sentences:
•Atomic sentences are the most basic sentences of first-order logic. These sentences are formed
from a predicate symbol followed by a parenthesis with a sequence of terms.We can represent
atomic sentences as
Predicate (term1, term2, ......, term n).
Example: Ravi and Ajay are brothers: => Brothers(Ravi, Ajay).
Chinky is a cat: => cat (Chinky).
Complex Sentences:
•Complex sentences are made by combining atomic sentences using connectives.
First-order logic statements can be divided into two parts:
•Subject: Subject is the main part of the statement.
•Predicate: A predicate can be defined as a relation, which binds two atoms together in a
statement. Consider the statement: "x is an integer.", it consists of two parts, the first part x is
Quantifiers in First-order logic:
•A quantifier is a language element which generates quantification, and quantification specifies the
quantity of specimen in the universe of discourse.
•These are the symbols that permit to determine or identify the range and scope of the variable
in the logical expression. There are two types of quantifier:
• Universal Quantifier, (for all, everyone, everything)
• Existential quantifier, (for some, at least one).
Universal Quantifier:
Universal quantifier is a symbol of logical representation, which specifies that the statement within
its range is true for everything or every instance of a particular thing.
The Universal quantifier is represented by a symbol ∀, which resembles an inverted A.If x is a
variable, then ∀x is read as:
•For all x
•For each x
•For every x.
Existential Quantifier:
Existential quantifiers are the type of quantifiers,
which express that the statement within its scope is
true for at least one instance of something.
It is denoted by the logical operator ∃, which
resembles as inverted E. When it is used with a
predicate variable then it is called as an existential
quantifier.
Example:
All men drink coffee.
Let a variable x which refers to a men so all x can
be represented
as∀xbelow:
man(x) → drink (x, coffee).
It will be read as: There are all x where x is a man
who
drink coffee.
Existential Quantifier:
Existential quantifiers are the type of quantifiers, which express that the statement within its scope is
true for at least one instance of something.
It is denoted by the logical operator ∃, which resembles as inverted E. When it is used with a predicate
variable then it is called as an existential quantifier.
If x is a variable, then existential quantifier will be ∃x or
∃(x). And it will be read as:
•There exists a 'x.'
•For some 'x.'
•For at least one 'x.’
If x is a variable, then existential quantifier will be ∃x or ∃(x). And it will be read as:
•There exists a 'x.'
•For some 'x.'
•For at least one 'x.'
Example:
Some boys are intelligent.
∃x: boys(x) ∧ intelligent(x)
It will be read as: There are some x where x
is a boy who is intelligent.
Convert Following statements in Predicate logic representations
1. All humans are mortal.
2. Some students love mathematics.
3. Every dog has a tail.
4. Some birds can fly.
5. No fish can fly.
6. If it rains, the ground is wet.
7. Some people are doctors.
8. Every car has an engine.
9. A person who studies hard will pass the exam.
10.There exists a number that is even.
1) ∀x bird(x) →fly(x)
Mathematics)].
Some Examples of FOL using quantifier:
In this question the predicate is "fly(bird)."And since there are all birds who fly so it will be
represented as follows.
In this question, the predicate is "respect(x, y)," where x=man, and y= parent.
Since there is every man so will use ∀, and it will be represented as follows:
In this question, the predicate is "play(x, y)," where x= boys, and y= game. Since there are some
y= subject.
Since there are not all students, so we will use ∀ with negation,
y= subject.
Since there is only one student who failed in Mathematics, so we will use
Literals can be positive literals or negative literals. For the forms of the
OR Qm
This clause can be transformed into the following equivalent logical formula :
1) Horn clause with exactly one positive literal(1 positive literal, at least 1 negative literal) called
definite clause.an implication often called A “rule”. whose antecedent(left side) consists of
a conjunction of positive literals and whose consequent(right side) consists of a single positive
literal.
• Rules: Logical implications or constraints that govern the behavior of entities within the domain.
• Axioms: Fundamental truths or assumptions about the domain that serve as the basis for reasoning.
5. Formalize Inference:
• Define mechanisms for performing inference or reasoning over the knowledge base represented in
FOL. This could involve methods such as deduction, induction, abduction, or probabilistic reasoning.
• Validate the knowledge representation against real-world scenarios or expert knowledge within the
•
It can be represented as: .
•This rule can be used if we want to show that every element has a similar property.
•In this rule, x must not appear as a free variable.
Free and Bound Variables:
The quantifiers interact with variables which appear in a suitable way. There are two types of
Free Variable: A variable is said to be a free variable in a formula if it occurs outside the
Bound Variable: A variable is said to be a bound variable in a formula if it occurs within the
• Syntax:
• Propositional logic deals with propositions, which are statements that are either true or
false.
• It uses propositional variables (p, q, r, etc.) to represent propositions.
• Logical connectives include AND (∧), OR (∨), NOT (¬), IMPLIES (→), and IF AND ONLY IF
(↔).
• Semantics:
• Propositional logic doesn't deal with the internal structure of propositions. It treats
propositions as indivisible units.
• Truth values (true or false) are assigned to propositional variables or combinations of
them using truth tables.
• Expressiveness:
• Propositional logic is limited in expressiveness. It cannot represent the internal structure
of propositions or quantify over objects.
• It's suitable for representing simple relationships and logical operations but lacks the
ability to express more complex relationships involving objects and properties.
2) First order logic
• Syntax:
• First-order logic deals with objects, properties of objects, and relationships between objects.
• It includes variables to represent objects, constants representing specific objects, predicates
representing properties and relations, quantifiers (∀ for universal quantification and ∃ for
existential quantification), and logical connectives.
• Quantifiers allow statements to refer to all objects in the domain (universal quantification)
or to some objects (existential quantification).
• Semantics:
• FOL provides a rich semantics that allows for reasoning about objects, their properties, and
relationships.
• It allows for the interpretation of quantified statements in terms of the domain of discourse
and interpretations of predicates.
• Expressiveness:
• FOL is much more expressive than propositional logic. It can represent complex relationships
and quantified statements about objects and their properties.
• FOL can express statements such as "All humans are mortal," "Some mammals can fly," or
"Every student has a unique ID."
UNIFICATION
Unification is a fundamental process in artificial intelligence (AI) and symbolic reasoning that
involves finding a common solution or "unified" form for expressions containing
variables. It is the process of making different expressions or terms identical by assigning
values to variables in a way that allows them to match or unify. Unification plays a crucial role
in knowledge representation, logic programming, and natural language .
Example
Example
Unification in AI Examples of How Unification Works
in Logic:
Consider a simple example of unification in predicate logic:
Given two expressions:
1. P(x, a, b)
2. P(y, z, b)
We want to find a substitution that unifies these
expressions.
1. Start by matching the predicates. In this case, P is the
same in both expressions.
2. Now, compare the arguments:
x matches with y (x/y substitution).
a matches with z (a/z substitution).
b matches with b (no substitution needed).
The unification substitution for these expressions is:
x/y
a/z
Applying these substitutions to the original expressions, we obtain:
1. P(y, a, b)
2. P(y, z, b)
The expressions are now unified, and both are equivalent.
Step-2:
At the second step, we will infer other facts form goal fact which
satisfies the rules. So as we can see in Rule-1, the goal predicate
Criminal (Robert) is present with substitution {Robert/P}. So we will
add all the conjunctive facts below the first level and will replace p
with Robert.
Here we can see American (Robert) is a fact, so it is proved
Step-3:t At step-3, we will extract
further fact Missile(q) which infer
from Weapon(q), as it satisfies
Rule-(5). Weapon (q) is also true
with the substitution of a constant
T1 at q.
• Step-4:
Step-5:
At step-4, we can infer facts At step-5, we can infer the
Missile(T1) and Owns(A, T1) fact Enemy(A,
form Sells(Robert, T1, r) which America) from Hostile(A) which
satisfies the Rule- 4, with the satisfies Rule- 6. And hence all
substitution of A in place of r. the statements are proved true
So these two statements are using backward chaining.
proved here.
Example of Backward-Chaining
Some Facts:
1.Ravi enjoys a wide variety of foods.
Conversion into FOL:
2.Banana are food. 1) ∀x Food ( x ) -> Likes ( Ravi, x )
3.Pizza is food. 2) Food ( Banana )
3) Food ( Pizza )
4.A food is anything that anyone
4) ∀x ∀y Eats(x, y) ^ ¬ Harmed(y) ->
consumes and isn't harmed by.
Food(x)
5.Sam eats Idli and is still alive. 5) Eats ( Idli, Sam ) -> ¬ Harmed
6.Bill eats everything Sam eats. ( Sam )
Goal: 6) ∀x Eats ( x, Sam ) -> Eats ( x, Bill )
Ravi Like Idli
iv. Backward-Chaining proof
Iteration 1:
• Separation of Facts:
• Food ( Banana )
• Food ( Pizza )
• Eats ( Idli, Sam ) -> ¬ Harmed ( Sam )
Iteration 2:
1.We must regard the statement we must establish to be true, i.e. Likes
( Ravi, Idli ) is now true.
2.We can deduce from the first rule that Food ( Idli ) is true.
3.We can deduce from the fourth rule that Eats ( Idli, Ravi ) -> ¬
Harmed ( Ravi ) is true.
• We demonstrated that the assertion we wished to prove is legitimate
because we ended up with all of the statements being true.
• Hence Proved!
Difference between Forwarding Chaining and Backward Chaining
6. Slow as it has to use all the rules. Fast as it has to use only a few rules.
It operates in forward direction i.e it works It operates in backward direction i.e it works
7.
from initial state to final decision. from goal to reach initial state.
Forward chaining is used for the planning, It is used in automated inference engines,
8. monitoring, control, and interpretation theorem proofs, proof assistants and other
Resolution in FOL
• Resolution is used, if there are various statements are given, and
we need to prove a conclusion of those statements.
• Unification is a key concept in proofs by resolutions.
• Resolution is a single inference rule which can efficiently operate on
the conjunctive normal form or clausal form.
• Clause: Disjunction of literals (an atomic sentence) is called
a clause. It is also known as a unit clause.
• Conjunctive Normal Form: A sentence represented as a
conjunction of clauses is said to be conjunctive normal
form or CNF.
• Steps for Resolution:
1.Conversion of facts into first-order logic.
2.Convert FOL statements into CNF
3.Negate the statement which needs to prove (proof by
contradiction)
Normal Forms
• The problem of finding whether a given statement is tautology
or contradiction or satisfiable in a finite number of steps is
called the Decision Problem. For Decision Problem,
construction of truth table may not be practical always. We
consider an alternate procedure known as the reduction to
normal forms.
• There are two such forms:
1.Disjunctive Normal Form (DNF)
2.Conjunctive Normal Form
• Disjunctive Normal Form (DNF): If p, q are two statements,
then "p or q" is a compound statement, denoted by p ∨ q and
referred as the disjunction of p and q. The disjunction of p and q
is true whenever at least one of the two statements is true, and
it is false only when both p and q are false
p q p∨q
T T T
T F T
F T T
F F F
𝐴⊕𝐵≡(𝐴∨𝐵)∧¬(𝐴∧𝐵)
logical equivalences:
𝐴→𝐵≡¬𝐴∨𝐵
•
𝐴↔𝐵≡(¬𝐴∨𝐵)∧(𝐴∨¬𝐵)
•
𝐴↔𝐵≡(𝐴∧𝐵)∨(¬𝐴∧¬𝐵)
•
•
• We move all the negations inwards to appear only as a part of
the literal. The ¬¬ symbol can only precede a propositional
variable or a predicate symbol. To accomplish this, we use
• ¬¬𝐴≡𝐴
the following logical equivalences:
• De Morgan's law
Some common equivalences that we use for the
disjunction: 𝐴∨(𝐵∧𝐶)≡(𝐴∨𝐵)∧(𝐴∨𝐶)
• Distribution over
conjunction: 𝐴∧(𝐵∨𝐶)≡(𝐴∧𝐵)∨(𝐴∧𝐶)
• Distribution over
• Step-2: Conversion of FOL into CNF
1) ¬((¬𝐴→¬𝐵)∧¬𝐶)
Consider the first formula,
Remove the conditional symbol as per the rules explained in the first
≡¬((¬¬𝐴∨¬𝐵)∧¬𝐶)
step:
≡¬((𝐴∨¬𝐵)∧¬𝐶)
Remove the double negation as mentioned in the second step:
≡¬(𝐴∨¬𝐵)∨¬¬𝐶
Apply the De Morgans law that opens a negation as a whole:
≡¬(𝐴∨¬𝐵)∨𝐶
Remove the double negation similar to the step we did before:
≡(¬𝐴∧¬¬𝐵)∨𝐶
Apply the De Morgans law again:
≡(¬𝐴∧𝐵)∨𝐶
Remove the double negation again:
Apply the distributive property over disjunction, which will lead to two
≡(¬𝐴∨𝐶)∧(𝐵∨𝐶)
clauses:
This is the final conjunction form of the formula. This is in the product of
sums form.
2) (𝐴→𝐵)→(¬𝐶→𝐵)
Let's take another formula:
≡(𝐴∧¬𝐵)∨(¬𝐶∧𝐵)
Remove all the occurrences of the conditional symbols:
≡(𝐴∨(¬𝐶∧𝐵))∧(¬𝐵∨(¬𝐶∧𝐵))
Apply the distributive property over conjunction:
≡(𝐴∨(¬𝐶∧𝐵))∧(¬𝐵∨¬𝐶)∧(¬𝐵∨𝐵)
Apply the same property:
3. Ramji is a man.
4. Ramji is a farmer