SlideShare une entreprise Scribd logo
1  sur  77
Logic in Computer
Science
CS 19.305
By,
Dr. Mrinal Paliwal
Unit 2
Propositional Logic: Syntax, semantics, propositional logic as a formal
language, natural deduction, normal forms, propositional satisfiability,
propositional resolution and tableaux method.
Propositional logic
 Propositional logic (PL) is the simplest form of logic where all the statements are made
by propositions.
Example:
a) It is Sunday.
b) The Sun rises from West (False proposition)
c) 3+3= 7(False proposition)
d) 5 is a prime number.
 Propositional logic explores simple grammatical connections, like and, or , not, between the
simplest "atomic sentences". Such atomic sentences are for example:
A = "Paris is the capital of France"
B = "mice chase elephants"
 Such atomic components (of possibly more complex sentences) can be either True or false.
(In our understanding of the world, A is true but B is false.)
Why Propositions?
Why use propositional logic?
 Specifying logical formulae is often more natural than filling in tables.
 It is easier to check and debug formulae than tables
 We can exploit the Boolean nature for efficient reasoning
 We need a language for asking queries that may be more complicated than asking for the
value of one variable
 It is easy to incrementally add formulae.
 This is a starting point for more complex logics (e.g., first-order logic).
Propositional logic
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.
 The propositions and connectives are the basic elements of the propositional logic.
 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.
 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.
Syntax of propositional logic
The syntax of propositional logic defines the allowable sentences for the knowledge representation.
There are two types of Propositions:
 Atomic Proposition: Atomic propositions are the simple propositions. It consists of a single
proposition symbol. These are the sentences which must be either true or false.
Example:
a) 2+2 is 4, it is an atomic proposition as it is a true fact.
b) "The Sun is cold" is also a proposition as it is a false fact.
 Compound proposition: Compound propositions are constructed by combining simpler or
atomic propositions, using parenthesis and logical connectives.
Example:
a) "It is raining today, and street is wet."
b) "Ankit is a doctor, and his clinic is in Mumbai."
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 Doctor, 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
P= I am breathing, Q= I am alive, it can be represented as P ⇔ Q.
Logical Connectives
Following is the summarized table for Propositional Logic Connectives:
Logical Connectives
Truth Table:
In propositional logic, we need to know the truth values of propositions in all possible scenarios. We can
combine all the possible combination with logical connectives, and the representation of these combinations
in a tabular format is called Truth table. Following are the truth table for all logical connectives:
Logical Connectives
Significance of P→Q:
p → q may be interpreted as-
• If p then q
• p implies q
• q follows from p
• q if p
• q whenever p
• p only if q
• p is sufficient for q
• q is necessary for p
• q without p is possible and can exist
• p without q is impossible and can not exist
Formulas-
While solving questions, remember-
• You can always replace p → q with ∼p ∨ q.
Logical Connectives
Logical Connectives
Logical Connectives
Significance Of P↔Q:
p ↔ q may be interpreted as-
• (If p then q) and (If q then p)
• p if and only if q
• q if and only if p
• (p if q) and (q if p)
• p is necessary and sufficient for q
• q is necessary and sufficient for p
• p and q are necessary and sufficient for each other
• p and q can not exist without each other
• Either p and q both exist or none of them exist
• p and q are equivalent
• ∼p and ∼q are equivalent
Formulas-
While solving questions, remember-
• Biconditional is equivalent to EX-NOR Gate.
• You can always replace p ↔ q with (p ∧ q) ∨ (∼p ∧ ∼q).
Logical Connectives
Truth table with three propositions:
We can build a proposition composing three propositions P, Q, and R. This truth table is made-up of Tuples as
we have taken three proposition symbols.
Precedence of connectives
Precedence Operators
First Precedence Parenthesis
Second Precedence Negation
Third Precedence Conjunction(AND)
Fourth Precedence Disjunction(OR)
Fifth Precedence Implication
Six Precedence Biconditional
Precedence of connectives:
Just like arithmetic operators, there is a precedence order for propositional connectors or logical operators.
This order should be followed while evaluating a propositional problem. Following is the list of the
precedence order for operators:
Logical Equivalence
Logical equivalence:
 Logical equivalence is one of the features of propositional logic. Two propositions are said to be logically
equivalent if and only if the columns in the truth table are identical to each other.
 Let's take two propositions A and B, so for logical equivalence, we can write it as A⇔B. In below truth
table we can see that column for ¬A∨ B and A→B, are identical hence A is Equivalent to B
Properties of Operators
Properties of Operators:
•Commutativity:
 P∧ Q= Q ∧ P, or
 P ∨ Q = Q ∨ P.
•Associativity:
 (P ∧ Q) ∧ R= P ∧ (Q ∧ R),
 (P ∨ Q) ∨ R= P ∨ (Q ∨ R)
•Identity element:
 P ∧ True = P,
 P ∨ True= True.
•Distributive:
 P∧ (Q ∨ R) = (P ∧ Q) ∨ (P ∧ R).
 P ∨ (Q ∧ R) = (P ∨ Q) ∧ (P ∨ R).
•DE Morgan's Law:
 ¬ (P ∧ Q) = (¬P) ∨ (¬Q)
 ¬ (P ∨ Q) = (¬ P) ∧ (¬Q).
•Double-negation elimination:
 ¬ (¬P) = P.
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.
Propositional logic
Definition (syntax of propositional logic)
An atomic formula has the form Ai where i = 1, 2, 3, .... defined by the following inductive
process:
Formulas are
1. All atomic formulas are formulas.
2. For every formula F, ~F is a formula.
3. For all formulas F and G, also (F V G) and (F ᴧ G) are formulas.
A formula of the form ~F is called negation of F. A formula of the form (F V G) is called
disjunction of F and G, and (F ᴧ G) is the conjunction of F and G. Any formula F which occurs
in another formula G is called a subformula of G.
Propositional logic
Example 2.1
Make a truth table for the statement ¬P∨Q.
Example 2.2
Analyze the statement, “if you get more doubles than any other player you will lose, or that if you
lose you must have bought the most properties,” using truth tables.
Example 2.3
Are the statements, “it will not rain or snow” and “it will not rain and it will not snow” logically
equivalent?
Example 2.4
Are the statements (P∨Q)→R and (P→R)∨(Q→R) logically equivalent?
Propositional logic
Example 2.1
Make a truth table for the statement ¬P∨Q.
P Q ¬P ¬PVQ
T T F T
T F F F
F T T T
F F T T
Note that this statement is not ¬(P∨Q), the negation belongs to P alone. Here is the truth
table:
We added a column for ¬P to make filling out the last column easier. The entries in
the ¬P column were determined by the entries in the PP column. Then to fill in the final
column, look only at the column for Q and the column for ¬P and use the rule for ∨.
Propositional logic
Example 2.2
Analyze the statement, “if you get more doubles than any other player you will lose, or that if
you lose you must have bought the most properties,” using truth tables.
P Q R P→Q Q→R (P→Q)V(Q→R)
T T T T T T
T T F T F T
T F T F T T
T F F F T T
F T T T T T
F T F T F T
F F T T T T
F F F T T T
Represent the statement in symbols as (P→Q)V(Q→R), where P is the statement “you get more
doubles than any other player,” Q is the statement “you will lose,” and R is the statement “you
must have bought the most properties.” Now make a truth table.
Propositional logic
P Q ¬(PVQ) ¬P∧¬Q
T T F F
T F F F
F T F F
F F T T
Example 2.3
Are the statements, “it will not rain or snow” and “it will not rain and it will not snow” logically
equivalent?
We want to know whether ¬(P∨Q) is logically equivalent to ¬P∧¬Q. Make a truth table which
includes both statements:
Since in every row the truth values for the two statements are equal, the two statements are
logically equivalent.
Propositional logic
P Q R (PVQ)→R (P→R)V(Q→R)
T T T T T
T T F F F
T F T T T
T F F F T
F T T T T
F T F F T
F F T T T
F F F T T
Example 2.4
Are the statements (P∨Q)→R and (P→R)∨(Q→R) logically equivalent?
Solution
Note that while we could start rewriting these statements with logically equivalent replacements in the hopes
of transforming one into another, we will never be sure that our failure is due to their lack of logical
equivalence rather than our lack of imagination. So instead, let's make a truth table:
Propositional logic
Part-01:
We have-
•The given sentence is- “If it rains, then I will stay at home.”
•This sentence is of the form- “If p then q”.
So, the symbolic form is p → q where-
p : It rains
q : I will stay at home
Part-02:
We have-
•The given sentence is- “If I will go to Australia, then I will earn more money.”
•This sentence is of the form- “If p then q”.
So, the symbolic form is p → q where-
p : I will go to Australia
q : I will earn more money
Part-03:
We have-
•The given sentence is- “He is poor but honest.”
•We can replace “but” with “and”.
•Then, the sentence is- “He is poor and honest.”
So, the symbolic form is p ∧ q where-
p : He is poor
q : He is honest
Propositional logic
Part-04:
We have-
•The given sentence is- “If a = b and b = c then a = c.”
•This sentence is of the form- “If p then q”.
So, the symbolic form is (p ∧ q) → r where-
p : a = b
q : b = c
r : a = c
Part-05:
We have-
•The given sentence is- “Neither it is hot nor cold today.”
•This sentence is of the form- “Neither p nor q”.
•“Neither p nor q” can be re-written as “Not p and Not q”.
So, the symbolic form is ¬p ∧ ¬q where-
p : It is hot today
q : It is cold today
Part-06:
We have-
•The given sentence is- “He goes to play a match if and only if
it does not rain.”
•This sentence is of the form- “p if and only if q”.
So, the symbolic form is p ↔ q where-
p : He goes to play a match
q : It does not rain
Part-07:
We have-
•The given sentence is- “Birds fly if and only if sky is clear.”
•This sentence is of the form- “p if and only if q”.
So, the symbolic form is p ↔ q where-
p : Birds fly
q : Sky is clear
Propositional logic
Part-08:
We have-
•The given sentence is- “I will go only if he stays.”
•This sentence is of the form- “p only if q”.
So, the symbolic form is p → q where-
p : I will go
q : He stays
Part-09:
We have-
•The given sentence is- “I will go if he stays.”
•This sentence is of the form- “q if p”.
So, the symbolic form is p → q where-
p : He stays
q : I will go
Part-10:
We have-
•The given sentence is- “It is false that he is poor but not honest.”
•We can replace “but” with “and”.
•Then, the sentence is- “It is false that he is poor and not honest.”
So, the symbolic form is ¬(p ∧ ¬q) where-
p : He is poor
q : He is honest
Part-11:
We have-
•The given sentence is- “It is false that he is poor or clever but not
honest.”
•We can replace “but” with “and”.
•Then, the sentence is- “It is false that he is poor or clever and not
honest.”
So, the symbolic form is ¬((p v q) ∧ ¬r) where-
p : He is poor
q : He is clever
r : He is honest
Propositional logic
Part-12:
We have-
•The given sentence is- “It is hot or else it is both
cold and cloudy.”
•It can be re-written as- “It is hot or it is both cold
and cloudy.”
So, the symbolic form is p v (q ∧ r) where-
p : It is hot
q : It is cold
r : It is cloudy
Part-13:
We have-
•The given sentence is- “I will not go to class unless
you come.”
•This sentence is of the form- “p unless q”.
So, the symbolic form is¬ q → p where-
p : I will go to class
q : You come
Part-14:
We have-
•The given sentence is- “We will leave whenever he comes.”
•We can replace “whenever” with “if”.
•Then, the sentence is- “We will leave if he comes.”
•This sentence is of the form- “q if p”.
So, the symbolic form is p → q where-
p : He comes
q : We will leave
Part-15:
We have-
•The given sentence is- “Either today is Sunday or Monday.”
•It can be re-written as- “Today is Sunday or Monday.”
So, the symbolic form is p v q where-
p : Today is Sunday
q : Today is Monday
Propositional logic
Part-16:
We have-
•The given sentence is- “You will qualify GATE only if
you work hard.”
•This sentence is of the form- “p only if q”.
So, the symbolic form is p → q where-
p : You will qualify GATE
q : You work hard
Part-17:
We have-
•The given sentence is- “Presence of cycle in a single
instance RAG is a necessary and sufficient condition
for deadlock.”
•This sentence is of the form- “p is necessary and
sufficient for q”.
So, the symbolic form is p ↔ q where-
p : Presence of cycle in a single instance RAG
q : Presence of deadlock
Part-18:
We have-
•The given sentence is- “Presence of cycle in a multi instance
RAG is a necessary but not sufficient condition for deadlock.”
•This sentence is of the form- “p is necessary but not
sufficient for q”.
So, the symbolic form is (p → q) ∧ ¬(p → q) where-
p : Presence of cycle in a multi instance RAG
q : Presence of deadlock
Part-19:
We have-
•The given sentence is- “I will dance only if you sing.”
•This sentence is of the form- “p only if q”.
So, the symbolic form is p → q where-
p : I will dance
q : You sing
Propositional logic
Part-20:
We have-
•The given sentence is- “Neither the red nor the green is available in size 5.”
•This sentence is of the form- “Neither p nor q”.
•“Neither p nor q” can be written as “Not p and Not q”.
So, the symbolic form is ¬p ^ ¬q where-
p : Red is available in size 5
q : Green is available in size 5
Propositional logic
Write the following English sentences in symbolic form-
1. If it rains, then I will stay at home.
2. If I will go to Australia, then I will earn more money.
3. He is poor but honest.
4. If a = b and b = c then a = c.
5. Neither it is hot nor cold today.
6. He goes to play a match if and only if it does not rain.
7. Birds fly if and only if sky is clear.
8. I will go only if he stays.
9. I will go if he stays.
10. It is false that he is poor but not honest.
11. It is false that he is poor or clever but not honest.
12. It is hot or else it is both cold and cloudy.
13. I will not go to class unless you come.
14. We will leave whenever he comes.
15. Either today is Sunday or Monday.
16. You will qualify GATE only if you work hard.
17. Presence of cycle in a single instance RAG is a necessary and sufficient condition for deadlock.
18. Presence of cycle in a multi instance RAG is a necessary but not sufficient condition for deadlock.
19. I will dance only if you sing.
20. Neither the red nor the green is available in size 5.
Propositional logic
Example 1: The statement ¬P->¬Q is equivalent to
a. P->Q
b. Q->P
c. ¬QvP
d. ¬PvQ
Example 2: Which of the following is not equivalent to P<->Q
a. (¬PvQ)^(Pv¬Q)
b. (¬PvQ)^(Q->P)
c. (¬P^Q)v(P^¬Q)
d. (¬P^¬Q)v(P^Q)
Example 3: Which of the following is not a tautology?
a. ((A->B)^(B->C)->(A->C)
b. (A<->C)->(¬B->(A^C))
c. (A^B^C)->(CvA)
d. A->(B->C)
Hint: P->Q=¬PvQ
Hint: P<->Q=(P->Q)^(Q->P)
Propositional logic
Statement S1 : Ticket is Sufficient To Enter Movie Theater, this statement is logically correct or not.
p
(Ticket)
q
(Entry)
p → q
(Ticket is sufficient for
entry)
F F T
F T T
T F F
T T T
This statement is of the form- “p is sufficient for q” where-
p : You have a ticket
q : You can enter a movie theater
So, the symbolic form is p → q
For p → q to hold, its truth table must hold-
Here,
•Row-2 states it is possible that you do not have a
ticket and you can enter the theater.
•However, it is not possible to enter a movie
theater without ticket.
•Row-3 states it is not possible that you have a
ticket and you do not enter the theater.
•However, there might be a case possible when you
have a ticket but do not enter the theater.
•So, the truth table does not hold.
Thus, the statement- “Ticket is sufficient for entry”
is logically incorrect.
Propositional logic
p
(Entry)
q
(Ticket)
p → q
(Ticket is necessary
for entry)
F F T
F T T
T F F
T T T
Statement S2 : Ticket is Necessary To Enter Movie Theater-
This statement is of the form- “q is necessary for p” where-
p : You can enter a movie theater
q : You have a ticket
So, the symbolic form is p → q
For p → q to hold, its truth table must hold-
Here, All the rows of the truth table make the correct sense. Thus, the statement- “Ticket is necessary for entry” is
logically correct.
Propositional logic
Types of Inference rules:
1. Modus Ponens:
The Modus Ponens rule is one of the most important rules of inference, and it states that if P and P → Q is true,
then we can infer that Q will be true. It can be represented as:
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:
Propositional logic
Types of Inference rules:
2. Modus Tollens:
The Modus Tollens rule state that if P→ Q is true and ¬ Q is true, then ¬ P will also true. It can be represented as:
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:
Propositional logic
Types of Inference rules:
3. Hypothetical Syllogism:
The Hypothetical Syllogism rule state that 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: If you have my home key then you can unlock my home. P→Q
Statement-2: If you can unlock my home then you can take my money. Q→R
Conclusion: If you have my home key then you can take my money. P→R
Proof by truth table:
Propositional logic
Types of Inference rules:
4. Disjunctive Syllogism:
The Disjunctive syllogism rule state that 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:
Propositional logic
5. Addition:
The Addition rule is one the common inference rule, and it states that If P is true, then P∨Q will be true.
Example:
AD
Statement: 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:
Propositional logic
6. Simplification:
The simplification rule state that if P^ Q is true, then Q and P will also be true. It can be represented as:
Proof by Truth-Table:
Propositional logic
7. Resolution:
The Resolution rule state that if P∨Q and ¬ P∧R is true, then Q∨R will also be true. It can be represented as
Proof by Truth-Table:
Propositional logic
Contrapositive: Suppose “if p, then q” is the given conditional statement “if ∼q, then ∼p” is its
contrapositive statement.
Example:
The contrapositive statement for
“If a number n is even, then n2 is
even” is “If n2 is not even, then n
is not even.
Mathematical representation:
Conditional statement: p ⇒ q
Contrapositive statement: ~q ⇒ ~p
p q ~p ~q ~q -> ~p
T T F F T
T F F T F
F T T F T
F F T T T
The truth table for Contrapositive of the conditional statement “If
p, then q” is given below:
Propositional logic
Converse: Suppose “if p, then q” is the given conditional statement “if q, then p” is its converse statement.
Example:
The converse statement for “If a
number n is even, then n2 is even” is “If
a number n2 is even, then n is even.
Mathematical representation:
Conditional statement: p ⇒ q
Converse statement: q ⇒ p
p q q -> p
T T T
T F T
F T F
F F T
Similarly, the truth table for the converse of the
conditional statement “If p, then q” is given as:
Propositional logic
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
Propositional logic
p q p v q
T T T
T F T
F T T
F F F
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
Example: - if p is "4 is a positive integer" and q is "√5 is a rational number", then p ∨ q is true as statement p is
true, although statement q is false.
Propositional logic
Conjunctive Normal Form: If p, q are two statements, then "p and q" is a compound statement, denoted by p ∧ q
and referred as the conjunction of p and q. The conjunction of p and q is true only when both p and q are true,
otherwise, it is false.
Example: if statement p is "6<7" and statement q is "-3>-4" then the conjunction of p and q is true as both p and q
are true statements.
p q p ^q
T T T
T F F
F T F
F F F
Propositional logic
Which of the following Arguments are valid.
i) ((P->Q)^(Q->R)^~R)->~P
Solution: (P->Q)^(Q->R)= P->R
~R
________________
~P
ii) P->S
P->Q
R v P
________________
S v Q
Solution: Modus Ponens
iii) ~P->~R
~S
P->W
R v S
________________
W
iv) S1: (A^B)->C=(A->C)^(B->C)
S2: (AvB)->C=(A->C)v(B->C)
Propositional logic
v) P->R
Q->S
¬R v ¬S
________________
¬P v ¬Q
vi) P->(R->S)
¬R->¬P
P
_____________
S
vii) ¬X->Y
¬Y
_________________
X
Which of the following Arguments are valid.
iv) P v Q
P->R
Q->R
_________________
R
viii) Is (p → q) → [(p → q) → q] a tautology? Why or why not?
Contra Positive
Propositional logic
Prove equivalence By using these laws, we can prove two propositions are logical equivalent.
Example 1: Prove ¬(p ∨ (¬p ∧ q)) ≡ ¬p ∧ ¬q.
¬(p ∨ (¬p ∧ q)) ≡ ¬p ∧ ¬(¬p ∧ q) DeMorgan
≡ ¬p ∧ (p ∨ ¬q) DeMorgan
≡ (¬p ∧ p) ∨ (¬p ∧ ¬q) Distributivity
≡ F∨(¬p ∧ ¬q) Because ¬p ∧ p ≡ F
≡ ¬p ∧ ¬q Because F ∨r ≡ r for any r
Example 2: Prove (p ∧ q) → (p ∨ q) ≡ T.
(p ∧ q) → (p ∨ q) ≡ ¬(p ∧ q) ∨ (p ∨ q) Substitution for →
≡ (¬p ∨ ¬q) ∨ (p ∨ q) DeMorgan
≡ (¬p ∨ p) ∨ (¬q ∨ q) Commutativity and Associativity
≡ T∨T Because ¬p ∨ p ≡ T ≡ T
Propositional logic
Example 3: Prove (p → q) ∧ (p → r) ≡ p → (q ∧ r).
Note that, by “Substitution for →”, we have: RHS = ¬ p ∨ (q ∧ r). So, we start from the LHS and try to get
this proposition:
(p → q) ∧ (p → r) ≡ (¬ p ∨ q) ∧ (¬ p ∨ r) Substitution for →,
≡ ¬p ∨ (q ∧ r) twice Distribution law
≡ p → (q ∧ r) Substitution for →
Example 4: Prove that: [¬ p ∧ (p ∨ q)] → q is a tautology. By using truth table and logic equivalence laws.
Example 5: Prove that: [(p → q) ∧ (q → r)] → [p → r] is a tautology.
• By using truth table.
• By using logic equivalence laws.
Propositional logic
Example 6: Show that [(p ∨ q) ∧ (r ∨ ¬q)] → (p ∨ r)] is a tautology
Example 7: Show that the two statements (p ∧ q) → r and (p → r) ∧ (q → r) are not logically equivalent.
Example 8: Use known logical equivalences to show that
(¬a → b) ∧ (¬b ∨ (¬a ∨ ¬b)) is logically equivalent to ¬(a ↔ b).
Example 9: Use known logical equivalences to show that
¬(p ↔ q) is logically equivalent to (p ∨ q) ∧ (p → ¬q).
Example 10: Use known logical equivalences to show that
¬(p ∨ q) ∨ (¬p ∧ q) ∨ ¬(¬p ∨ ¬q) ⇔ ¬(p ∧ ¬q).
Propositional logic
Example 1: Prove (p → q) ∧ (p → r) ≡ p → (q ∧ r).
Note that, by “Substitution for →”, we have: RHS = ¬ p ∨ (q ∧ r). So, we start from the LHS and try to get this
proposition:
(p → q) ∧ (p → r) ≡ (¬ p ∨ q) ∧ (¬ p ∨ r) Substitution for →,
≡ ¬p ∨ (q ∧ r) twice Distribution law
≡ p → (q ∧ r) Substitution for →
Example 2: Prove that: [¬ p ∧ (p ∨ q)] → q is a tautology. By using truth table and logic equivalence laws.
≡[¬ p ∧ (p ∨ q)] -> q
≡ ¬[¬ p ∧ (p ∨ q)]v q
≡ p v ¬(p v q)v q
≡ p v (¬p ^ ¬q) v q
≡ q v (¬p ^ ¬q) v p
≡(q v ¬p) ^ (q v ¬q) v p
≡ q v ¬p v p
≡ q
Example 2.1) P->R
Q->S
¬R v ¬S
________________
¬P v ¬Q
Propositional logic
Example 3: Prove that: [(p → q) ∧ (q → r)] → [p → r] is a tautology.
• By using truth table.
• By using logic equivalence laws.
≡ ¬ [(p → q) ∧ (q → r)] v [p → r]
≡ ¬ [(¬p v q) ^ (¬q v r)] v [¬p v r]
≡[¬(¬p v q) v ¬(¬q v r)] v [¬p v r]
≡[(p ^ ¬q) v (q^¬r)] v ¬p v r
≡[¬p v (p ^ ¬q)] v [r v (q^¬r)]
≡[(¬p v p) ^ (¬p v ¬q)] v [(r v q) ^ (r v ¬r)]
≡(¬p v ¬q) v (r v q)
≡ ¬p v r
≡ p->r
Propositional logic
Example 4: Show that [(p ∨ q) ∧ (r ∨ ¬q)] → (p ∨ r)] is a tautology
≡ [(p ∨ q) ∧ (r ∨ ¬q)] → (p ∨ r)]
≡ ¬ [(p ∨ q) ∧ (r ∨ ¬q)] v (p ∨ r)
≡[¬(p ∨ q) v ¬(r ∨ ¬q)] v (p ∨ r)
≡[(¬p ^ ¬q) v (¬r ^ q)] v (p ∨ r)
≡[p v (¬p ^ ¬q)] v [r v (¬r ^ ¬q)]
≡[(p v ¬p) ^ (p v q)] v [(r v ¬r) ^ (r v ¬q)]
≡ p v q v r v ¬q
≡True
Propositional logic
Example 5: Show that the two statements ¬p->(q->r) and q->(p v r) are logically equivalent.
≡ ¬p->(q->r)
𠪪p v (q->r)
≡ p v (q->r)
≡ p v (¬q v r)
≡ ¬q v (p v r)
≡ q->(p v r)
Example 6: Show that the two statements p ↔ q & (p ∧ q) ∨ (¬p ∧ ¬q) are logically equivalent.
p ↔ q ≡ (p → q) ∧ (q → p) [iff is two implications]
≡ (¬p ∨ q) ∧ (¬q ∨ p) [Law of Implication]
≡ ((¬p ∨ q) ∧ ¬q) ∨ ((¬p ∨ q) ∧ p) [Distributivity]
≡ (¬p ∧ ¬q) ∨ (q ∧ ¬q) ∨ ((p ∧ ¬p) ∨ (p ∧ q)) [Distributivity]
≡ (¬p ∧ ¬q) ∨ (p ∧ q)) [Negation]
≡ (p ∧ q) ∨ (¬p ∧ ¬q)
Propositional logic
Example 7: Use known logical equivalences to show that
(¬a → b) ∧ (¬b ∨ (¬a ∨ ¬b)) is logically equivalent to ¬(a ↔ b).
Example 8: Use known logical equivalences to show that ¬(p ↔ q) is logically equivalent to (p ∨ q) ∧ (p → ¬q)
≡ (¬a → b) ∧ (¬b ∨ (¬a ∨ ¬b))
≡ (a v b) ^ ( ¬a v ¬b)
≡ ¬(¬a ^ ¬b) ^ ¬(a ^ b)
≡ ¬((¬a ^ ¬b) v (a ^ b))
≡ ¬(a<->b)
≡ ¬(p ↔ q)
≡ ¬[(p ^ q) v (¬p ^ ¬q)]
≡ ¬(p ^ q) ^ ¬(¬p ^ ¬q)
≡ (¬p v ¬q) ^ (p v q)
≡ (p v q) ^ (p->¬q)
Propositional logic
Example 9: We have-
[ (p → q) ∧ (q → r) ] ∧ ( p ∧ ∼r)
Find that the statement is tautology or not?
= [ (∼p ∨ q) ∧ (∼q ∨ r) ] ∧ ( p ∧ ∼r) { ∵ p → q = ∼p ∨ q }
= [ ((∼p ∨ q) ∧ ∼q) ∨ ((∼p ∨ q) ∧ r) ] ∧ ( p ∧ ∼r) { Using Distributive law }
= [ ((∼p ∧ ∼q) ∨ (q ∧ ∼q)) ∨ ((∼p ∧ r) ∨ (q ∧ r)) ] ∧ ( p ∧ ∼r) { Using Distributive law }
= [ ((∼p ∧ ∼q) ∨ F) ∨ ((∼p ∧ r) ∨ (q ∧ r)) ] ∧ ( p ∧ ∼r) { Using Complement law }
= [ (∼p ∧ ∼q) ∨ (∼p ∧ r) ∨ (q ∧ r) ] ∧ ( p ∧ ∼r) { Using Identity law }
= ((∼p ∧ ∼q) ∧ ( p ∧ ∼r)) ∨ ((∼p ∧ r) ∧ ( p ∧ ∼r)) ∨ ((q ∧ r) ∧ ( p ∧ ∼r)) { Using Distributive law }
= (∼p ∧ ∼q ∧ p ∧ ∼r) ∨ (∼p ∧ r ∧ p ∧ ∼r) ∨ (q ∧ r ∧ p ∧ ∼r)
= F ∨ F ∨ F { Using Complement law }
= F
Propositional logic
Example 10: Use known logical equivalences to show that this is true
(p ∧ q) ∨ (¬p ∧ q) ∨ ¬q
(p ∧ q) ∨ (¬p ∧ q) ∨ ¬q
≡ (q ∧ (p ∨ ¬p)) ∨ ¬q [Comm., Assoc., Distrib.]
≡ (q ∧ T) ∨ ¬q [Negation]
≡ q ∨ ¬q [Identity]
≡ T [Negation]
Propositional logic
Arguments
S1: If it is snowing then it is cold
S2: If it is cold, John is wearing a coat It is snowing
__________________________________________________________________________________
C: Therefore, John is wearing a coat
P->Q
Q->R
P
__________________________________________________________________________________
R
Propositional logic
S1: If it is rains then the cricket match will not be
played
S2: The match was played
___________________________________________
_
C: There was no rain
P-> ¬Q
Q
_______
¬P
S1: If it is rains then the cricket match will not be
played
S2: it did not rain
___________________________________________
_
C: The match was played
P-> ¬Q
¬P
_______
Q
Example: Verify that the given statements are correct or not.
(P-> ¬Q) ^ Q-> ¬P
= (¬P v ¬Q) ^ Q -> ¬P
= Q ^ (¬P v ¬Q) -> ¬P
= (Q ^ ¬P) v (Q ^ ¬Q) ->
¬P
= (¬P ^ Q) -> ¬P
= P v ¬Q v ¬P
Propositional logic
Example: It is not raining and it is pleasant, and it is not pleasant only if it is raining and it is cold. (GATE
2017)
p: It is raining
q: It is cold
r: It is pleasant
Find the correct answer:
i) (¬p ^ r) ^ (¬r-> (p ^ q))
ii) (¬p ^ r) ^ ( (p ^ q)->¬r)
iii) (¬p ^ r) v (¬r-> (p ^ q))
iv) (¬p ^ r) v ( (p ^ q)->¬r)
Example: The statement ¬P->¬Q is logically equivalent to
(GATE 2012)
i) P->Q
ii) Q->P
iii) ¬Q v P
iv) ¬P v Q
Answer: i)
Answer: i) & ii)
Propositional logic
Example: The statement P<->Q is logically equivalent to
i) (¬P v Q) ^ (P v ¬Q)
ii) (¬P v Q) ^ (Q->P)
iii) (¬P ^ Q) v (P ^ ¬Q)
iv) (¬P ^ ¬Q) v (P ^ Q)
Example: Which of the following is not a tautology
i) ((a->b) ^ (b->c))->(a->c)
ii) (a<->c)->¬b->(a ^ c)
iii) (a ^ b ^ c)->(c v a)
iv) a->(b->a)
Example: Which of the following are equivalent
1. P v ¬Q
2. ¬(¬P ^ Q)
3. (P ^ Q) v (P ^ ¬Q) v (¬P ^ ¬Q)
4. (P ^ Q) v (P ^ ¬Q) v (¬P ^ Q)
i) 1,2
ii) 1,2,3
iii) 1,2,4
iv) all
Answer: i) , ii) & iv)
Answer: iii)
Answer: i) , iii) & iv)
Horn Clause
An important special case of CNF formulas which often occurs in practical applications are the
Horn formulas (named after the logician Alfred Horn.)
Definition (Horn formula)
A formula F in CNF is a Horn formula if every disjunction in F contains at most one positive literal.
(X1 ^ X2 ^ X3……..Xn)->P
Example:
F - (A v ~B)^(~C v ~A v D)^(~A v ~B)^D^~E
G- (A v ~B)^(C v ~A v D). F is a Horn formula and G is not.
Definite Clause: A formula F in CNF is a Horn formula if every disjunction in F contains one
positive literal.
Example:
A->B=¬A v B
Horn Clause
F - (A v ~B)^(~C v ~A v D)^(~A v ~B)^D^~E
Horn formulas can be (equivalently) rewritten in a more intuitive way, namely as implications.
(We call this the procedural reading of Horn formulas.) In the above example, F can be rewritten
as
F=(B-> A)^(C^A-> D)^(A^B-> 0)^(1->D)^(E->0)
Note: P= T->P
¬Q=Q-> ┴
In logic, a formula is satisfiable if it is true under at least one interpretation.
Example: ¬P1v ¬P2 v ¬P3 v P4
Horn Clause
Exercise 1
(T→ q) ∧ (T → s) ∧ (w →┴) ∧ (p∧q∧s→v) ∧ (v→s) ∧ (T→r) ∧(r→p)
Mark: q, s, r through (T→q),(T→s),(T→r)
(T→ q) ∧ (T → s) ∧ (w →┴) ∧ (p∧q∧s→v) ∧ (v→s) ∧ (T→r) ∧(r→p)
Mark: p through (r→p)
(T→ q) ∧ (T → s) ∧ (w →┴) ∧ (p∧q∧s→v) ∧ (v→s) ∧ (T→r) ∧(r→p)
Mark: v through (p∧q∧s→v)
(T→ q) ∧ (T → s) ∧ (w →┴) ∧ (p∧q∧s→v) ∧ (v→s) ∧ (T→r) ∧(r→p)
– Satisfiable
Horn Clause
Exercise 2
(p∧q∧s→p) ∧ (q∧r→p) ∧ (p∧s→s)
No occurrences of T in f
Nothing is marked
Returning: Satisfiable
Horn Clause
Exercise 3
(p∧q∧s→p) ∧ (q∧r→p) ∧ (p∧s→s)
Remember that a formula f is satisfiable if there is an interpretation that makes the
formula f true.
Let p, q, r, s be false, then
(p∧q∧s→p) is True (false implying anything is True),
(q∧r→p) is True
(p∧s→s) is True
The formula is True
Horn Clause
Exercise 4
(p∧q∧s→┴) ∧ (q∧r→┴) ∧ (s→┴)
No occurrences of T in f
Nothing is marked
Returning: Satisfiable
When p, q, r, s are false, the formula is True
Horn Clause
Exercise 5
{T->P, T->Q, T->R, Q->T, U->V, P^U^S->┴}
=P^Q^R^(¬Q v T)^(¬U v V) ^ (¬P v ¬U v ¬S)
i(P)=1, i(Q)=1, i(R)=1
Returning: Unsatisfiable
Horn Clause
Exercise 5
F = (~A V ~B V ~D) ^ ~E ^ (~C V A) ^ C ^ B ^ (~G V D) ^ G
Resolution
Resolution:
Clause: {c},{d},{b,¬d},{a,¬b,¬c}
Proof: {a}
Questions
Example 1: Show that [(p ∨ q) ∧ (r ∨ ¬q)] → (p ∨ r)] is a tautology
Example 2: Prove that: [¬ p ∧ (p ∨ q)] → q is a tautology. By using truth table and logic equivalence laws.
Example 3: Prove (p ∧ q) → (p ∨ q) ≡ T.
Questions
Note: But means ‘and’
Questions
Questions
Questions
Practice Questions
1. Is (p → q) → [(p → q) → q] a tautology? Why or why not?
2. Use known logical equivalences to show that (¬a → b) ∧ (¬b ∨ (¬a ∨ ¬b)) is logically equivalent to ¬(a ↔ b).
3. Prove ¬(p ∨ (¬p ∧ q)) ≡ ¬p ∧ ¬q.
4. Use known logical equivalences to show that ¬(p ↔ q) is logically equivalent to (p ∨ q) ∧ (p → ¬q).
5. Use known logical equivalences to show that this is true (p ∧ q) ∨ (¬p ∧ q) ∨ ¬q

Contenu connexe

Tendances

Knowledge Representation & Reasoning
Knowledge Representation & ReasoningKnowledge Representation & Reasoning
Knowledge Representation & Reasoning
Sajid Marwat
 
Translating English to Propositional Logic
Translating English to Propositional LogicTranslating English to Propositional Logic
Translating English to Propositional Logic
Janet Stemwedel
 

Tendances (20)

Problem reduction AND OR GRAPH & AO* algorithm.ppt
Problem reduction AND OR GRAPH & AO* algorithm.pptProblem reduction AND OR GRAPH & AO* algorithm.ppt
Problem reduction AND OR GRAPH & AO* algorithm.ppt
 
Uncertainty in AI
Uncertainty in AIUncertainty in AI
Uncertainty in AI
 
Image processing second unit Notes
Image processing second unit NotesImage processing second unit Notes
Image processing second unit Notes
 
Knowledge Representation & Reasoning
Knowledge Representation & ReasoningKnowledge Representation & Reasoning
Knowledge Representation & Reasoning
 
Introduction to theory of computation
Introduction to theory of computationIntroduction to theory of computation
Introduction to theory of computation
 
Predicate Logic
Predicate LogicPredicate Logic
Predicate Logic
 
Predicate calculus
Predicate calculusPredicate calculus
Predicate calculus
 
Inference in First-Order Logic
Inference in First-Order Logic Inference in First-Order Logic
Inference in First-Order Logic
 
Spanning trees
Spanning treesSpanning trees
Spanning trees
 
Knowledge representation and Predicate logic
Knowledge representation and Predicate logicKnowledge representation and Predicate logic
Knowledge representation and Predicate logic
 
AI search techniques
AI search techniquesAI search techniques
AI search techniques
 
Automata theory
Automata theoryAutomata theory
Automata theory
 
Unification and Lifting
Unification and LiftingUnification and Lifting
Unification and Lifting
 
Feature detection - Image Processing
Feature detection - Image ProcessingFeature detection - Image Processing
Feature detection - Image Processing
 
Branch & bound
Branch & boundBranch & bound
Branch & bound
 
FUNCTION DEPENDENCY AND TYPES & EXAMPLE
FUNCTION DEPENDENCY  AND TYPES & EXAMPLEFUNCTION DEPENDENCY  AND TYPES & EXAMPLE
FUNCTION DEPENDENCY AND TYPES & EXAMPLE
 
Context free grammar
Context free grammarContext free grammar
Context free grammar
 
UGC NET Computer Science & Application book.pdf [Sample]
UGC NET Computer Science & Application book.pdf  [Sample]UGC NET Computer Science & Application book.pdf  [Sample]
UGC NET Computer Science & Application book.pdf [Sample]
 
Lecture 4 means end analysis
Lecture 4 means end analysisLecture 4 means end analysis
Lecture 4 means end analysis
 
Translating English to Propositional Logic
Translating English to Propositional LogicTranslating English to Propositional Logic
Translating English to Propositional Logic
 

Similaire à Logic in Computer Science Unit 2 (1).pptx

logicproof-141212042039-conversion-gate01.pdf
logicproof-141212042039-conversion-gate01.pdflogicproof-141212042039-conversion-gate01.pdf
logicproof-141212042039-conversion-gate01.pdf
PradeeshSAI
 
20220818151924_PPT01 - The Logic of Compound and Quantitative Statement.pptx
20220818151924_PPT01 - The Logic of Compound and Quantitative Statement.pptx20220818151924_PPT01 - The Logic of Compound and Quantitative Statement.pptx
20220818151924_PPT01 - The Logic of Compound and Quantitative Statement.pptx
ssuser92109d
 

Similaire à Logic in Computer Science Unit 2 (1).pptx (20)

Artificial Intelligence (AI) | Prepositional logic (PL)and first order predic...
Artificial Intelligence (AI) | Prepositional logic (PL)and first order predic...Artificial Intelligence (AI) | Prepositional logic (PL)and first order predic...
Artificial Intelligence (AI) | Prepositional logic (PL)and first order predic...
 
Chapter 1: The Foundations: Logic and Proofs
Chapter 1: The Foundations: Logic and ProofsChapter 1: The Foundations: Logic and Proofs
Chapter 1: The Foundations: Logic and Proofs
 
Chapter 1
Chapter 1Chapter 1
Chapter 1
 
Chapter 1
Chapter 1Chapter 1
Chapter 1
 
Logic&proof
Logic&proofLogic&proof
Logic&proof
 
Chapter1p1
Chapter1p1Chapter1p1
Chapter1p1
 
Drinkfromme.pptx
Drinkfromme.pptxDrinkfromme.pptx
Drinkfromme.pptx
 
lec3 AI.pptx
lec3  AI.pptxlec3  AI.pptx
lec3 AI.pptx
 
Chapter 01 - p1.pdf
Chapter 01 - p1.pdfChapter 01 - p1.pdf
Chapter 01 - p1.pdf
 
Introduction to mathematical analysis
Introduction to mathematical analysisIntroduction to mathematical analysis
Introduction to mathematical analysis
 
Logic
LogicLogic
Logic
 
Discrete mathematics Chapter1 presentation.ppt
Discrete mathematics Chapter1 presentation.pptDiscrete mathematics Chapter1 presentation.ppt
Discrete mathematics Chapter1 presentation.ppt
 
3 computing truth tables
3   computing truth tables3   computing truth tables
3 computing truth tables
 
Discrete mathematics Ch2 Propositional Logic_Dr.khaled.Bakro د. خالد بكرو
Discrete mathematics Ch2 Propositional Logic_Dr.khaled.Bakro د. خالد بكروDiscrete mathematics Ch2 Propositional Logic_Dr.khaled.Bakro د. خالد بكرو
Discrete mathematics Ch2 Propositional Logic_Dr.khaled.Bakro د. خالد بكرو
 
logicproof-141212042039-conversion-gate01.pdf
logicproof-141212042039-conversion-gate01.pdflogicproof-141212042039-conversion-gate01.pdf
logicproof-141212042039-conversion-gate01.pdf
 
20220818151924_PPT01 - The Logic of Compound and Quantitative Statement.pptx
20220818151924_PPT01 - The Logic of Compound and Quantitative Statement.pptx20220818151924_PPT01 - The Logic of Compound and Quantitative Statement.pptx
20220818151924_PPT01 - The Logic of Compound and Quantitative Statement.pptx
 
Per3 logika&amp;pembuktian
Per3 logika&amp;pembuktianPer3 logika&amp;pembuktian
Per3 logika&amp;pembuktian
 
DM(1).pptx
DM(1).pptxDM(1).pptx
DM(1).pptx
 
L01.ppt
L01.pptL01.ppt
L01.ppt
 
Chapter1p1.pdf
Chapter1p1.pdfChapter1p1.pdf
Chapter1p1.pdf
 

Dernier

Verification of thevenin's theorem for BEEE Lab (1).pptx
Verification of thevenin's theorem for BEEE Lab (1).pptxVerification of thevenin's theorem for BEEE Lab (1).pptx
Verification of thevenin's theorem for BEEE Lab (1).pptx
chumtiyababu
 
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
AldoGarca30
 
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak HamilCara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Kandungan 087776558899
 

Dernier (20)

AIRCANVAS[1].pdf mini project for btech students
AIRCANVAS[1].pdf mini project for btech studentsAIRCANVAS[1].pdf mini project for btech students
AIRCANVAS[1].pdf mini project for btech students
 
Online electricity billing project report..pdf
Online electricity billing project report..pdfOnline electricity billing project report..pdf
Online electricity billing project report..pdf
 
Verification of thevenin's theorem for BEEE Lab (1).pptx
Verification of thevenin's theorem for BEEE Lab (1).pptxVerification of thevenin's theorem for BEEE Lab (1).pptx
Verification of thevenin's theorem for BEEE Lab (1).pptx
 
Thermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VThermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - V
 
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
 
GEAR TRAIN- BASIC CONCEPTS AND WORKING PRINCIPLE
GEAR TRAIN- BASIC CONCEPTS AND WORKING PRINCIPLEGEAR TRAIN- BASIC CONCEPTS AND WORKING PRINCIPLE
GEAR TRAIN- BASIC CONCEPTS AND WORKING PRINCIPLE
 
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptxS1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
 
Double Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torqueDouble Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torque
 
Work-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptxWork-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptx
 
Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...
Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...
Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...
 
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
 
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak HamilCara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
 
Orlando’s Arnold Palmer Hospital Layout Strategy-1.pptx
Orlando’s Arnold Palmer Hospital Layout Strategy-1.pptxOrlando’s Arnold Palmer Hospital Layout Strategy-1.pptx
Orlando’s Arnold Palmer Hospital Layout Strategy-1.pptx
 
Generative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTGenerative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPT
 
COST-EFFETIVE and Energy Efficient BUILDINGS ptx
COST-EFFETIVE  and Energy Efficient BUILDINGS ptxCOST-EFFETIVE  and Energy Efficient BUILDINGS ptx
COST-EFFETIVE and Energy Efficient BUILDINGS ptx
 
data_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfdata_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdf
 
Design For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the startDesign For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the start
 
Computer Networks Basics of Network Devices
Computer Networks  Basics of Network DevicesComputer Networks  Basics of Network Devices
Computer Networks Basics of Network Devices
 
Block diagram reduction techniques in control systems.ppt
Block diagram reduction techniques in control systems.pptBlock diagram reduction techniques in control systems.ppt
Block diagram reduction techniques in control systems.ppt
 
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced LoadsFEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
 

Logic in Computer Science Unit 2 (1).pptx

  • 1. Logic in Computer Science CS 19.305 By, Dr. Mrinal Paliwal
  • 2. Unit 2 Propositional Logic: Syntax, semantics, propositional logic as a formal language, natural deduction, normal forms, propositional satisfiability, propositional resolution and tableaux method.
  • 3. Propositional logic  Propositional logic (PL) is the simplest form of logic where all the statements are made by propositions. Example: a) It is Sunday. b) The Sun rises from West (False proposition) c) 3+3= 7(False proposition) d) 5 is a prime number.  Propositional logic explores simple grammatical connections, like and, or , not, between the simplest "atomic sentences". Such atomic sentences are for example: A = "Paris is the capital of France" B = "mice chase elephants"  Such atomic components (of possibly more complex sentences) can be either True or false. (In our understanding of the world, A is true but B is false.)
  • 4. Why Propositions? Why use propositional logic?  Specifying logical formulae is often more natural than filling in tables.  It is easier to check and debug formulae than tables  We can exploit the Boolean nature for efficient reasoning  We need a language for asking queries that may be more complicated than asking for the value of one variable  It is easy to incrementally add formulae.  This is a starting point for more complex logics (e.g., first-order logic).
  • 5. Propositional logic 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.  The propositions and connectives are the basic elements of the propositional logic.  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.  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.
  • 6. Syntax of propositional logic The syntax of propositional logic defines the allowable sentences for the knowledge representation. There are two types of Propositions:  Atomic Proposition: Atomic propositions are the simple propositions. It consists of a single proposition symbol. These are the sentences which must be either true or false. Example: a) 2+2 is 4, it is an atomic proposition as it is a true fact. b) "The Sun is cold" is also a proposition as it is a false fact.  Compound proposition: Compound propositions are constructed by combining simpler or atomic propositions, using parenthesis and logical connectives. Example: a) "It is raining today, and street is wet." b) "Ankit is a doctor, and his clinic is in Mumbai."
  • 7. 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 Doctor, 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 P= I am breathing, Q= I am alive, it can be represented as P ⇔ Q.
  • 8. Logical Connectives Following is the summarized table for Propositional Logic Connectives:
  • 9. Logical Connectives Truth Table: In propositional logic, we need to know the truth values of propositions in all possible scenarios. We can combine all the possible combination with logical connectives, and the representation of these combinations in a tabular format is called Truth table. Following are the truth table for all logical connectives:
  • 10. Logical Connectives Significance of P→Q: p → q may be interpreted as- • If p then q • p implies q • q follows from p • q if p • q whenever p • p only if q • p is sufficient for q • q is necessary for p • q without p is possible and can exist • p without q is impossible and can not exist Formulas- While solving questions, remember- • You can always replace p → q with ∼p ∨ q.
  • 13. Logical Connectives Significance Of P↔Q: p ↔ q may be interpreted as- • (If p then q) and (If q then p) • p if and only if q • q if and only if p • (p if q) and (q if p) • p is necessary and sufficient for q • q is necessary and sufficient for p • p and q are necessary and sufficient for each other • p and q can not exist without each other • Either p and q both exist or none of them exist • p and q are equivalent • ∼p and ∼q are equivalent Formulas- While solving questions, remember- • Biconditional is equivalent to EX-NOR Gate. • You can always replace p ↔ q with (p ∧ q) ∨ (∼p ∧ ∼q).
  • 14. Logical Connectives Truth table with three propositions: We can build a proposition composing three propositions P, Q, and R. This truth table is made-up of Tuples as we have taken three proposition symbols.
  • 15. Precedence of connectives Precedence Operators First Precedence Parenthesis Second Precedence Negation Third Precedence Conjunction(AND) Fourth Precedence Disjunction(OR) Fifth Precedence Implication Six Precedence Biconditional Precedence of connectives: Just like arithmetic operators, there is a precedence order for propositional connectors or logical operators. This order should be followed while evaluating a propositional problem. Following is the list of the precedence order for operators:
  • 16. Logical Equivalence Logical equivalence:  Logical equivalence is one of the features of propositional logic. Two propositions are said to be logically equivalent if and only if the columns in the truth table are identical to each other.  Let's take two propositions A and B, so for logical equivalence, we can write it as A⇔B. In below truth table we can see that column for ¬A∨ B and A→B, are identical hence A is Equivalent to B
  • 17. Properties of Operators Properties of Operators: •Commutativity:  P∧ Q= Q ∧ P, or  P ∨ Q = Q ∨ P. •Associativity:  (P ∧ Q) ∧ R= P ∧ (Q ∧ R),  (P ∨ Q) ∨ R= P ∨ (Q ∨ R) •Identity element:  P ∧ True = P,  P ∨ True= True. •Distributive:  P∧ (Q ∨ R) = (P ∧ Q) ∨ (P ∧ R).  P ∨ (Q ∧ R) = (P ∨ Q) ∧ (P ∨ R). •DE Morgan's Law:  ¬ (P ∧ Q) = (¬P) ∨ (¬Q)  ¬ (P ∨ Q) = (¬ P) ∧ (¬Q). •Double-negation elimination:  ¬ (¬P) = P.
  • 18. 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.
  • 19. Propositional logic Definition (syntax of propositional logic) An atomic formula has the form Ai where i = 1, 2, 3, .... defined by the following inductive process: Formulas are 1. All atomic formulas are formulas. 2. For every formula F, ~F is a formula. 3. For all formulas F and G, also (F V G) and (F ᴧ G) are formulas. A formula of the form ~F is called negation of F. A formula of the form (F V G) is called disjunction of F and G, and (F ᴧ G) is the conjunction of F and G. Any formula F which occurs in another formula G is called a subformula of G.
  • 20. Propositional logic Example 2.1 Make a truth table for the statement ¬P∨Q. Example 2.2 Analyze the statement, “if you get more doubles than any other player you will lose, or that if you lose you must have bought the most properties,” using truth tables. Example 2.3 Are the statements, “it will not rain or snow” and “it will not rain and it will not snow” logically equivalent? Example 2.4 Are the statements (P∨Q)→R and (P→R)∨(Q→R) logically equivalent?
  • 21. Propositional logic Example 2.1 Make a truth table for the statement ¬P∨Q. P Q ¬P ¬PVQ T T F T T F F F F T T T F F T T Note that this statement is not ¬(P∨Q), the negation belongs to P alone. Here is the truth table: We added a column for ¬P to make filling out the last column easier. The entries in the ¬P column were determined by the entries in the PP column. Then to fill in the final column, look only at the column for Q and the column for ¬P and use the rule for ∨.
  • 22. Propositional logic Example 2.2 Analyze the statement, “if you get more doubles than any other player you will lose, or that if you lose you must have bought the most properties,” using truth tables. P Q R P→Q Q→R (P→Q)V(Q→R) T T T T T T T T F T F T T F T F T T T F F F T T F T T T T T F T F T F T F F T T T T F F F T T T Represent the statement in symbols as (P→Q)V(Q→R), where P is the statement “you get more doubles than any other player,” Q is the statement “you will lose,” and R is the statement “you must have bought the most properties.” Now make a truth table.
  • 23. Propositional logic P Q ¬(PVQ) ¬P∧¬Q T T F F T F F F F T F F F F T T Example 2.3 Are the statements, “it will not rain or snow” and “it will not rain and it will not snow” logically equivalent? We want to know whether ¬(P∨Q) is logically equivalent to ¬P∧¬Q. Make a truth table which includes both statements: Since in every row the truth values for the two statements are equal, the two statements are logically equivalent.
  • 24. Propositional logic P Q R (PVQ)→R (P→R)V(Q→R) T T T T T T T F F F T F T T T T F F F T F T T T T F T F F T F F T T T F F F T T Example 2.4 Are the statements (P∨Q)→R and (P→R)∨(Q→R) logically equivalent? Solution Note that while we could start rewriting these statements with logically equivalent replacements in the hopes of transforming one into another, we will never be sure that our failure is due to their lack of logical equivalence rather than our lack of imagination. So instead, let's make a truth table:
  • 25. Propositional logic Part-01: We have- •The given sentence is- “If it rains, then I will stay at home.” •This sentence is of the form- “If p then q”. So, the symbolic form is p → q where- p : It rains q : I will stay at home Part-02: We have- •The given sentence is- “If I will go to Australia, then I will earn more money.” •This sentence is of the form- “If p then q”. So, the symbolic form is p → q where- p : I will go to Australia q : I will earn more money Part-03: We have- •The given sentence is- “He is poor but honest.” •We can replace “but” with “and”. •Then, the sentence is- “He is poor and honest.” So, the symbolic form is p ∧ q where- p : He is poor q : He is honest
  • 26. Propositional logic Part-04: We have- •The given sentence is- “If a = b and b = c then a = c.” •This sentence is of the form- “If p then q”. So, the symbolic form is (p ∧ q) → r where- p : a = b q : b = c r : a = c Part-05: We have- •The given sentence is- “Neither it is hot nor cold today.” •This sentence is of the form- “Neither p nor q”. •“Neither p nor q” can be re-written as “Not p and Not q”. So, the symbolic form is ¬p ∧ ¬q where- p : It is hot today q : It is cold today Part-06: We have- •The given sentence is- “He goes to play a match if and only if it does not rain.” •This sentence is of the form- “p if and only if q”. So, the symbolic form is p ↔ q where- p : He goes to play a match q : It does not rain Part-07: We have- •The given sentence is- “Birds fly if and only if sky is clear.” •This sentence is of the form- “p if and only if q”. So, the symbolic form is p ↔ q where- p : Birds fly q : Sky is clear
  • 27. Propositional logic Part-08: We have- •The given sentence is- “I will go only if he stays.” •This sentence is of the form- “p only if q”. So, the symbolic form is p → q where- p : I will go q : He stays Part-09: We have- •The given sentence is- “I will go if he stays.” •This sentence is of the form- “q if p”. So, the symbolic form is p → q where- p : He stays q : I will go Part-10: We have- •The given sentence is- “It is false that he is poor but not honest.” •We can replace “but” with “and”. •Then, the sentence is- “It is false that he is poor and not honest.” So, the symbolic form is ¬(p ∧ ¬q) where- p : He is poor q : He is honest Part-11: We have- •The given sentence is- “It is false that he is poor or clever but not honest.” •We can replace “but” with “and”. •Then, the sentence is- “It is false that he is poor or clever and not honest.” So, the symbolic form is ¬((p v q) ∧ ¬r) where- p : He is poor q : He is clever r : He is honest
  • 28. Propositional logic Part-12: We have- •The given sentence is- “It is hot or else it is both cold and cloudy.” •It can be re-written as- “It is hot or it is both cold and cloudy.” So, the symbolic form is p v (q ∧ r) where- p : It is hot q : It is cold r : It is cloudy Part-13: We have- •The given sentence is- “I will not go to class unless you come.” •This sentence is of the form- “p unless q”. So, the symbolic form is¬ q → p where- p : I will go to class q : You come Part-14: We have- •The given sentence is- “We will leave whenever he comes.” •We can replace “whenever” with “if”. •Then, the sentence is- “We will leave if he comes.” •This sentence is of the form- “q if p”. So, the symbolic form is p → q where- p : He comes q : We will leave Part-15: We have- •The given sentence is- “Either today is Sunday or Monday.” •It can be re-written as- “Today is Sunday or Monday.” So, the symbolic form is p v q where- p : Today is Sunday q : Today is Monday
  • 29. Propositional logic Part-16: We have- •The given sentence is- “You will qualify GATE only if you work hard.” •This sentence is of the form- “p only if q”. So, the symbolic form is p → q where- p : You will qualify GATE q : You work hard Part-17: We have- •The given sentence is- “Presence of cycle in a single instance RAG is a necessary and sufficient condition for deadlock.” •This sentence is of the form- “p is necessary and sufficient for q”. So, the symbolic form is p ↔ q where- p : Presence of cycle in a single instance RAG q : Presence of deadlock Part-18: We have- •The given sentence is- “Presence of cycle in a multi instance RAG is a necessary but not sufficient condition for deadlock.” •This sentence is of the form- “p is necessary but not sufficient for q”. So, the symbolic form is (p → q) ∧ ¬(p → q) where- p : Presence of cycle in a multi instance RAG q : Presence of deadlock Part-19: We have- •The given sentence is- “I will dance only if you sing.” •This sentence is of the form- “p only if q”. So, the symbolic form is p → q where- p : I will dance q : You sing
  • 30. Propositional logic Part-20: We have- •The given sentence is- “Neither the red nor the green is available in size 5.” •This sentence is of the form- “Neither p nor q”. •“Neither p nor q” can be written as “Not p and Not q”. So, the symbolic form is ¬p ^ ¬q where- p : Red is available in size 5 q : Green is available in size 5
  • 31. Propositional logic Write the following English sentences in symbolic form- 1. If it rains, then I will stay at home. 2. If I will go to Australia, then I will earn more money. 3. He is poor but honest. 4. If a = b and b = c then a = c. 5. Neither it is hot nor cold today. 6. He goes to play a match if and only if it does not rain. 7. Birds fly if and only if sky is clear. 8. I will go only if he stays. 9. I will go if he stays. 10. It is false that he is poor but not honest. 11. It is false that he is poor or clever but not honest. 12. It is hot or else it is both cold and cloudy. 13. I will not go to class unless you come. 14. We will leave whenever he comes. 15. Either today is Sunday or Monday. 16. You will qualify GATE only if you work hard. 17. Presence of cycle in a single instance RAG is a necessary and sufficient condition for deadlock. 18. Presence of cycle in a multi instance RAG is a necessary but not sufficient condition for deadlock. 19. I will dance only if you sing. 20. Neither the red nor the green is available in size 5.
  • 32. Propositional logic Example 1: The statement ¬P->¬Q is equivalent to a. P->Q b. Q->P c. ¬QvP d. ¬PvQ Example 2: Which of the following is not equivalent to P<->Q a. (¬PvQ)^(Pv¬Q) b. (¬PvQ)^(Q->P) c. (¬P^Q)v(P^¬Q) d. (¬P^¬Q)v(P^Q) Example 3: Which of the following is not a tautology? a. ((A->B)^(B->C)->(A->C) b. (A<->C)->(¬B->(A^C)) c. (A^B^C)->(CvA) d. A->(B->C) Hint: P->Q=¬PvQ Hint: P<->Q=(P->Q)^(Q->P)
  • 33. Propositional logic Statement S1 : Ticket is Sufficient To Enter Movie Theater, this statement is logically correct or not. p (Ticket) q (Entry) p → q (Ticket is sufficient for entry) F F T F T T T F F T T T This statement is of the form- “p is sufficient for q” where- p : You have a ticket q : You can enter a movie theater So, the symbolic form is p → q For p → q to hold, its truth table must hold- Here, •Row-2 states it is possible that you do not have a ticket and you can enter the theater. •However, it is not possible to enter a movie theater without ticket. •Row-3 states it is not possible that you have a ticket and you do not enter the theater. •However, there might be a case possible when you have a ticket but do not enter the theater. •So, the truth table does not hold. Thus, the statement- “Ticket is sufficient for entry” is logically incorrect.
  • 34. Propositional logic p (Entry) q (Ticket) p → q (Ticket is necessary for entry) F F T F T T T F F T T T Statement S2 : Ticket is Necessary To Enter Movie Theater- This statement is of the form- “q is necessary for p” where- p : You can enter a movie theater q : You have a ticket So, the symbolic form is p → q For p → q to hold, its truth table must hold- Here, All the rows of the truth table make the correct sense. Thus, the statement- “Ticket is necessary for entry” is logically correct.
  • 35. Propositional logic Types of Inference rules: 1. Modus Ponens: The Modus Ponens rule is one of the most important rules of inference, and it states that if P and P → Q is true, then we can infer that Q will be true. It can be represented as: 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:
  • 36. Propositional logic Types of Inference rules: 2. Modus Tollens: The Modus Tollens rule state that if P→ Q is true and ¬ Q is true, then ¬ P will also true. It can be represented as: 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:
  • 37. Propositional logic Types of Inference rules: 3. Hypothetical Syllogism: The Hypothetical Syllogism rule state that 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: If you have my home key then you can unlock my home. P→Q Statement-2: If you can unlock my home then you can take my money. Q→R Conclusion: If you have my home key then you can take my money. P→R Proof by truth table:
  • 38. Propositional logic Types of Inference rules: 4. Disjunctive Syllogism: The Disjunctive syllogism rule state that 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:
  • 39. Propositional logic 5. Addition: The Addition rule is one the common inference rule, and it states that If P is true, then P∨Q will be true. Example: AD Statement: 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:
  • 40. Propositional logic 6. Simplification: The simplification rule state that if P^ Q is true, then Q and P will also be true. It can be represented as: Proof by Truth-Table:
  • 41. Propositional logic 7. Resolution: The Resolution rule state that if P∨Q and ¬ P∧R is true, then Q∨R will also be true. It can be represented as Proof by Truth-Table:
  • 42. Propositional logic Contrapositive: Suppose “if p, then q” is the given conditional statement “if ∼q, then ∼p” is its contrapositive statement. Example: The contrapositive statement for “If a number n is even, then n2 is even” is “If n2 is not even, then n is not even. Mathematical representation: Conditional statement: p ⇒ q Contrapositive statement: ~q ⇒ ~p p q ~p ~q ~q -> ~p T T F F T T F F T F F T T F T F F T T T The truth table for Contrapositive of the conditional statement “If p, then q” is given below:
  • 43. Propositional logic Converse: Suppose “if p, then q” is the given conditional statement “if q, then p” is its converse statement. Example: The converse statement for “If a number n is even, then n2 is even” is “If a number n2 is even, then n is even. Mathematical representation: Conditional statement: p ⇒ q Converse statement: q ⇒ p p q q -> p T T T T F T F T F F F T Similarly, the truth table for the converse of the conditional statement “If p, then q” is given as:
  • 44. Propositional logic 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
  • 45. Propositional logic p q p v q T T T T F T F T T F F F 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 Example: - if p is "4 is a positive integer" and q is "√5 is a rational number", then p ∨ q is true as statement p is true, although statement q is false.
  • 46. Propositional logic Conjunctive Normal Form: If p, q are two statements, then "p and q" is a compound statement, denoted by p ∧ q and referred as the conjunction of p and q. The conjunction of p and q is true only when both p and q are true, otherwise, it is false. Example: if statement p is "6<7" and statement q is "-3>-4" then the conjunction of p and q is true as both p and q are true statements. p q p ^q T T T T F F F T F F F F
  • 47. Propositional logic Which of the following Arguments are valid. i) ((P->Q)^(Q->R)^~R)->~P Solution: (P->Q)^(Q->R)= P->R ~R ________________ ~P ii) P->S P->Q R v P ________________ S v Q Solution: Modus Ponens iii) ~P->~R ~S P->W R v S ________________ W iv) S1: (A^B)->C=(A->C)^(B->C) S2: (AvB)->C=(A->C)v(B->C)
  • 48. Propositional logic v) P->R Q->S ¬R v ¬S ________________ ¬P v ¬Q vi) P->(R->S) ¬R->¬P P _____________ S vii) ¬X->Y ¬Y _________________ X Which of the following Arguments are valid. iv) P v Q P->R Q->R _________________ R viii) Is (p → q) → [(p → q) → q] a tautology? Why or why not? Contra Positive
  • 49. Propositional logic Prove equivalence By using these laws, we can prove two propositions are logical equivalent. Example 1: Prove ¬(p ∨ (¬p ∧ q)) ≡ ¬p ∧ ¬q. ¬(p ∨ (¬p ∧ q)) ≡ ¬p ∧ ¬(¬p ∧ q) DeMorgan ≡ ¬p ∧ (p ∨ ¬q) DeMorgan ≡ (¬p ∧ p) ∨ (¬p ∧ ¬q) Distributivity ≡ F∨(¬p ∧ ¬q) Because ¬p ∧ p ≡ F ≡ ¬p ∧ ¬q Because F ∨r ≡ r for any r Example 2: Prove (p ∧ q) → (p ∨ q) ≡ T. (p ∧ q) → (p ∨ q) ≡ ¬(p ∧ q) ∨ (p ∨ q) Substitution for → ≡ (¬p ∨ ¬q) ∨ (p ∨ q) DeMorgan ≡ (¬p ∨ p) ∨ (¬q ∨ q) Commutativity and Associativity ≡ T∨T Because ¬p ∨ p ≡ T ≡ T
  • 50. Propositional logic Example 3: Prove (p → q) ∧ (p → r) ≡ p → (q ∧ r). Note that, by “Substitution for →”, we have: RHS = ¬ p ∨ (q ∧ r). So, we start from the LHS and try to get this proposition: (p → q) ∧ (p → r) ≡ (¬ p ∨ q) ∧ (¬ p ∨ r) Substitution for →, ≡ ¬p ∨ (q ∧ r) twice Distribution law ≡ p → (q ∧ r) Substitution for → Example 4: Prove that: [¬ p ∧ (p ∨ q)] → q is a tautology. By using truth table and logic equivalence laws. Example 5: Prove that: [(p → q) ∧ (q → r)] → [p → r] is a tautology. • By using truth table. • By using logic equivalence laws.
  • 51. Propositional logic Example 6: Show that [(p ∨ q) ∧ (r ∨ ¬q)] → (p ∨ r)] is a tautology Example 7: Show that the two statements (p ∧ q) → r and (p → r) ∧ (q → r) are not logically equivalent. Example 8: Use known logical equivalences to show that (¬a → b) ∧ (¬b ∨ (¬a ∨ ¬b)) is logically equivalent to ¬(a ↔ b). Example 9: Use known logical equivalences to show that ¬(p ↔ q) is logically equivalent to (p ∨ q) ∧ (p → ¬q). Example 10: Use known logical equivalences to show that ¬(p ∨ q) ∨ (¬p ∧ q) ∨ ¬(¬p ∨ ¬q) ⇔ ¬(p ∧ ¬q).
  • 52. Propositional logic Example 1: Prove (p → q) ∧ (p → r) ≡ p → (q ∧ r). Note that, by “Substitution for →”, we have: RHS = ¬ p ∨ (q ∧ r). So, we start from the LHS and try to get this proposition: (p → q) ∧ (p → r) ≡ (¬ p ∨ q) ∧ (¬ p ∨ r) Substitution for →, ≡ ¬p ∨ (q ∧ r) twice Distribution law ≡ p → (q ∧ r) Substitution for → Example 2: Prove that: [¬ p ∧ (p ∨ q)] → q is a tautology. By using truth table and logic equivalence laws. ≡[¬ p ∧ (p ∨ q)] -> q ≡ ¬[¬ p ∧ (p ∨ q)]v q ≡ p v ¬(p v q)v q ≡ p v (¬p ^ ¬q) v q ≡ q v (¬p ^ ¬q) v p ≡(q v ¬p) ^ (q v ¬q) v p ≡ q v ¬p v p ≡ q Example 2.1) P->R Q->S ¬R v ¬S ________________ ¬P v ¬Q
  • 53. Propositional logic Example 3: Prove that: [(p → q) ∧ (q → r)] → [p → r] is a tautology. • By using truth table. • By using logic equivalence laws. ≡ ¬ [(p → q) ∧ (q → r)] v [p → r] ≡ ¬ [(¬p v q) ^ (¬q v r)] v [¬p v r] ≡[¬(¬p v q) v ¬(¬q v r)] v [¬p v r] ≡[(p ^ ¬q) v (q^¬r)] v ¬p v r ≡[¬p v (p ^ ¬q)] v [r v (q^¬r)] ≡[(¬p v p) ^ (¬p v ¬q)] v [(r v q) ^ (r v ¬r)] ≡(¬p v ¬q) v (r v q) ≡ ¬p v r ≡ p->r
  • 54. Propositional logic Example 4: Show that [(p ∨ q) ∧ (r ∨ ¬q)] → (p ∨ r)] is a tautology ≡ [(p ∨ q) ∧ (r ∨ ¬q)] → (p ∨ r)] ≡ ¬ [(p ∨ q) ∧ (r ∨ ¬q)] v (p ∨ r) ≡[¬(p ∨ q) v ¬(r ∨ ¬q)] v (p ∨ r) ≡[(¬p ^ ¬q) v (¬r ^ q)] v (p ∨ r) ≡[p v (¬p ^ ¬q)] v [r v (¬r ^ ¬q)] ≡[(p v ¬p) ^ (p v q)] v [(r v ¬r) ^ (r v ¬q)] ≡ p v q v r v ¬q ≡True
  • 55. Propositional logic Example 5: Show that the two statements ¬p->(q->r) and q->(p v r) are logically equivalent. ≡ ¬p->(q->r) ≡ ¬¬p v (q->r) ≡ p v (q->r) ≡ p v (¬q v r) ≡ ¬q v (p v r) ≡ q->(p v r) Example 6: Show that the two statements p ↔ q & (p ∧ q) ∨ (¬p ∧ ¬q) are logically equivalent. p ↔ q ≡ (p → q) ∧ (q → p) [iff is two implications] ≡ (¬p ∨ q) ∧ (¬q ∨ p) [Law of Implication] ≡ ((¬p ∨ q) ∧ ¬q) ∨ ((¬p ∨ q) ∧ p) [Distributivity] ≡ (¬p ∧ ¬q) ∨ (q ∧ ¬q) ∨ ((p ∧ ¬p) ∨ (p ∧ q)) [Distributivity] ≡ (¬p ∧ ¬q) ∨ (p ∧ q)) [Negation] ≡ (p ∧ q) ∨ (¬p ∧ ¬q)
  • 56. Propositional logic Example 7: Use known logical equivalences to show that (¬a → b) ∧ (¬b ∨ (¬a ∨ ¬b)) is logically equivalent to ¬(a ↔ b). Example 8: Use known logical equivalences to show that ¬(p ↔ q) is logically equivalent to (p ∨ q) ∧ (p → ¬q) ≡ (¬a → b) ∧ (¬b ∨ (¬a ∨ ¬b)) ≡ (a v b) ^ ( ¬a v ¬b) ≡ ¬(¬a ^ ¬b) ^ ¬(a ^ b) ≡ ¬((¬a ^ ¬b) v (a ^ b)) ≡ ¬(a<->b) ≡ ¬(p ↔ q) ≡ ¬[(p ^ q) v (¬p ^ ¬q)] ≡ ¬(p ^ q) ^ ¬(¬p ^ ¬q) ≡ (¬p v ¬q) ^ (p v q) ≡ (p v q) ^ (p->¬q)
  • 57. Propositional logic Example 9: We have- [ (p → q) ∧ (q → r) ] ∧ ( p ∧ ∼r) Find that the statement is tautology or not? = [ (∼p ∨ q) ∧ (∼q ∨ r) ] ∧ ( p ∧ ∼r) { ∵ p → q = ∼p ∨ q } = [ ((∼p ∨ q) ∧ ∼q) ∨ ((∼p ∨ q) ∧ r) ] ∧ ( p ∧ ∼r) { Using Distributive law } = [ ((∼p ∧ ∼q) ∨ (q ∧ ∼q)) ∨ ((∼p ∧ r) ∨ (q ∧ r)) ] ∧ ( p ∧ ∼r) { Using Distributive law } = [ ((∼p ∧ ∼q) ∨ F) ∨ ((∼p ∧ r) ∨ (q ∧ r)) ] ∧ ( p ∧ ∼r) { Using Complement law } = [ (∼p ∧ ∼q) ∨ (∼p ∧ r) ∨ (q ∧ r) ] ∧ ( p ∧ ∼r) { Using Identity law } = ((∼p ∧ ∼q) ∧ ( p ∧ ∼r)) ∨ ((∼p ∧ r) ∧ ( p ∧ ∼r)) ∨ ((q ∧ r) ∧ ( p ∧ ∼r)) { Using Distributive law } = (∼p ∧ ∼q ∧ p ∧ ∼r) ∨ (∼p ∧ r ∧ p ∧ ∼r) ∨ (q ∧ r ∧ p ∧ ∼r) = F ∨ F ∨ F { Using Complement law } = F
  • 58. Propositional logic Example 10: Use known logical equivalences to show that this is true (p ∧ q) ∨ (¬p ∧ q) ∨ ¬q (p ∧ q) ∨ (¬p ∧ q) ∨ ¬q ≡ (q ∧ (p ∨ ¬p)) ∨ ¬q [Comm., Assoc., Distrib.] ≡ (q ∧ T) ∨ ¬q [Negation] ≡ q ∨ ¬q [Identity] ≡ T [Negation]
  • 59. Propositional logic Arguments S1: If it is snowing then it is cold S2: If it is cold, John is wearing a coat It is snowing __________________________________________________________________________________ C: Therefore, John is wearing a coat P->Q Q->R P __________________________________________________________________________________ R
  • 60. Propositional logic S1: If it is rains then the cricket match will not be played S2: The match was played ___________________________________________ _ C: There was no rain P-> ¬Q Q _______ ¬P S1: If it is rains then the cricket match will not be played S2: it did not rain ___________________________________________ _ C: The match was played P-> ¬Q ¬P _______ Q Example: Verify that the given statements are correct or not. (P-> ¬Q) ^ Q-> ¬P = (¬P v ¬Q) ^ Q -> ¬P = Q ^ (¬P v ¬Q) -> ¬P = (Q ^ ¬P) v (Q ^ ¬Q) -> ¬P = (¬P ^ Q) -> ¬P = P v ¬Q v ¬P
  • 61. Propositional logic Example: It is not raining and it is pleasant, and it is not pleasant only if it is raining and it is cold. (GATE 2017) p: It is raining q: It is cold r: It is pleasant Find the correct answer: i) (¬p ^ r) ^ (¬r-> (p ^ q)) ii) (¬p ^ r) ^ ( (p ^ q)->¬r) iii) (¬p ^ r) v (¬r-> (p ^ q)) iv) (¬p ^ r) v ( (p ^ q)->¬r) Example: The statement ¬P->¬Q is logically equivalent to (GATE 2012) i) P->Q ii) Q->P iii) ¬Q v P iv) ¬P v Q Answer: i) Answer: i) & ii)
  • 62. Propositional logic Example: The statement P<->Q is logically equivalent to i) (¬P v Q) ^ (P v ¬Q) ii) (¬P v Q) ^ (Q->P) iii) (¬P ^ Q) v (P ^ ¬Q) iv) (¬P ^ ¬Q) v (P ^ Q) Example: Which of the following is not a tautology i) ((a->b) ^ (b->c))->(a->c) ii) (a<->c)->¬b->(a ^ c) iii) (a ^ b ^ c)->(c v a) iv) a->(b->a) Example: Which of the following are equivalent 1. P v ¬Q 2. ¬(¬P ^ Q) 3. (P ^ Q) v (P ^ ¬Q) v (¬P ^ ¬Q) 4. (P ^ Q) v (P ^ ¬Q) v (¬P ^ Q) i) 1,2 ii) 1,2,3 iii) 1,2,4 iv) all Answer: i) , ii) & iv) Answer: iii) Answer: i) , iii) & iv)
  • 63. Horn Clause An important special case of CNF formulas which often occurs in practical applications are the Horn formulas (named after the logician Alfred Horn.) Definition (Horn formula) A formula F in CNF is a Horn formula if every disjunction in F contains at most one positive literal. (X1 ^ X2 ^ X3……..Xn)->P Example: F - (A v ~B)^(~C v ~A v D)^(~A v ~B)^D^~E G- (A v ~B)^(C v ~A v D). F is a Horn formula and G is not. Definite Clause: A formula F in CNF is a Horn formula if every disjunction in F contains one positive literal. Example: A->B=¬A v B
  • 64. Horn Clause F - (A v ~B)^(~C v ~A v D)^(~A v ~B)^D^~E Horn formulas can be (equivalently) rewritten in a more intuitive way, namely as implications. (We call this the procedural reading of Horn formulas.) In the above example, F can be rewritten as F=(B-> A)^(C^A-> D)^(A^B-> 0)^(1->D)^(E->0) Note: P= T->P ¬Q=Q-> ┴ In logic, a formula is satisfiable if it is true under at least one interpretation. Example: ¬P1v ¬P2 v ¬P3 v P4
  • 65. Horn Clause Exercise 1 (T→ q) ∧ (T → s) ∧ (w →┴) ∧ (p∧q∧s→v) ∧ (v→s) ∧ (T→r) ∧(r→p) Mark: q, s, r through (T→q),(T→s),(T→r) (T→ q) ∧ (T → s) ∧ (w →┴) ∧ (p∧q∧s→v) ∧ (v→s) ∧ (T→r) ∧(r→p) Mark: p through (r→p) (T→ q) ∧ (T → s) ∧ (w →┴) ∧ (p∧q∧s→v) ∧ (v→s) ∧ (T→r) ∧(r→p) Mark: v through (p∧q∧s→v) (T→ q) ∧ (T → s) ∧ (w →┴) ∧ (p∧q∧s→v) ∧ (v→s) ∧ (T→r) ∧(r→p) – Satisfiable
  • 66. Horn Clause Exercise 2 (p∧q∧s→p) ∧ (q∧r→p) ∧ (p∧s→s) No occurrences of T in f Nothing is marked Returning: Satisfiable
  • 67. Horn Clause Exercise 3 (p∧q∧s→p) ∧ (q∧r→p) ∧ (p∧s→s) Remember that a formula f is satisfiable if there is an interpretation that makes the formula f true. Let p, q, r, s be false, then (p∧q∧s→p) is True (false implying anything is True), (q∧r→p) is True (p∧s→s) is True The formula is True
  • 68. Horn Clause Exercise 4 (p∧q∧s→┴) ∧ (q∧r→┴) ∧ (s→┴) No occurrences of T in f Nothing is marked Returning: Satisfiable When p, q, r, s are false, the formula is True
  • 69. Horn Clause Exercise 5 {T->P, T->Q, T->R, Q->T, U->V, P^U^S->┴} =P^Q^R^(¬Q v T)^(¬U v V) ^ (¬P v ¬U v ¬S) i(P)=1, i(Q)=1, i(R)=1 Returning: Unsatisfiable
  • 70. Horn Clause Exercise 5 F = (~A V ~B V ~D) ^ ~E ^ (~C V A) ^ C ^ B ^ (~G V D) ^ G
  • 72. Questions Example 1: Show that [(p ∨ q) ∧ (r ∨ ¬q)] → (p ∨ r)] is a tautology Example 2: Prove that: [¬ p ∧ (p ∨ q)] → q is a tautology. By using truth table and logic equivalence laws. Example 3: Prove (p ∧ q) → (p ∨ q) ≡ T.
  • 77. Practice Questions 1. Is (p → q) → [(p → q) → q] a tautology? Why or why not? 2. Use known logical equivalences to show that (¬a → b) ∧ (¬b ∨ (¬a ∨ ¬b)) is logically equivalent to ¬(a ↔ b). 3. Prove ¬(p ∨ (¬p ∧ q)) ≡ ¬p ∧ ¬q. 4. Use known logical equivalences to show that ¬(p ↔ q) is logically equivalent to (p ∨ q) ∧ (p → ¬q). 5. Use known logical equivalences to show that this is true (p ∧ q) ∨ (¬p ∧ q) ∨ ¬q