UNIT 3 Logic
UNIT 3 Logic
UNIT 3 Logic
INTRODUCTION:
Logical reasoning provides the theoretical base for
many areas of mathematics and consequently
computer science. It has many practical
applications in computer science like design of
computing machines, artificial intelligence, definition
of data structures for programming languages etc.
Propositional Logic :
➢ A proposition is a collection of declarative
statements that has either a truth value "true”
or a truth value "false".
➢ A propositional consists of propositional
variables and connectives. We denote the
propositional variables by capital letters (A,
B, etc). The connectives connect the
propositional variables.
➢ Propositional calculus (or logic) is the study of
the logical relationship between objects called
propositions and forms the basis of all
mathematical reasoning and all automated
reasoning.
➢ A proposition is a statement that is either true
or false, but not both (we usually denote a
proposition by letters;p,q,r,s,...)
➢ The value of a proposition is called its truth
value; denoted by T or 1 if it is true and F or 0
if it is false.
➢ Opinions, interrogative and imperative
sentences are not propositions.
Example (Propositions):
◆ Today is Monday.
◆ The derivative of sinx is cosx.
◆ Every even number has at least two factors.
1. p: it is raining
p represents the proposition “it is raining”
2. q: the streets are wet
q represents the proposition “the streets are wet”
➢ In Propositional Logic, there are two types of
sentences -- simple sentences and compound
sentences. Simple sentences express simple
facts about the world. Compound sentences
express logical relationships between the simpler
sentences of which they are composed.
(¬p)
b)A conjunction is a sequence of sentences
separated by occurrences of the ∧ operator and
enclosed in parentheses, as shown below. The
constituent sentences are called conjuncts. For
example, we can form the conjunction of p and q
as follows.
(p ∧ q)
c) A disjunction is a sequence of sentences
separated by occurrences of the ∨ operator and
enclosed in parentheses. The constituent
sentences are called disjuncts. For example, we
can form the disjunction of p and q as follows.
(p ∨ q)
d) An implication consists of a pair of sentences
separated by the ⇒ operator and enclosed in
parentheses. The sentence to the left of the
operator is called the antecedent, and the
sentence to the right is called the consequent.
The implication of p and q is shown below.
(p ⇒ q)
e) A bi-conditional is a combination of an
implication and a reverse implication. For
example, we can express the bi-conditional of p
and q as shown below.
(p ⇔ q)
Logical Operators: A logical operation
combines propositions using certain rules
Example:
•The operation denoted by “∧” means “and”
•“p ∧ q” means “it is raining and the streets are
wet”
•If both p and q are true then p ∧ q is true
•If either p or q (or both) are false then p ∧ q is
false
•“∧” is called the conjunction
(a) conjunction:“p and q”,p∧q.
(b) disjunction:“p or q”,p∨q.
(c) exclusive or :“exactly one of p or q”,
“p xor q”,p⊕q.
(d) implication:“if p then q”,p→q.
(e) bi-conditional:“p if and only if q”,p↔q.
Truth Tables:
➢ Truth tables are used to exhibit the
relationship between the truth values of a
compound proposition and the truth values
of its component propositions.
➢ Since we need to know the truth value of a
proposition in all possible scenarios, we consider
all the possible combinations of the propositions
which are joined together by Logical Connectives
to form the given compound proposition. This
compilation of all possible scenarios in a tabular
format is called a truth table.
Connectives
In propositional logic generally we use five
connectives which are −
⚫ OR (∨ )
⚫ AND (∧ )
⚫ Negation/ NOT (¬)
⚫ Implication / if-then (→)
⚫ If and only if (⇔).
A B A∧B
True True True
True False False
False True False
False False False
A ¬A
True False
False True
“if x=2,thenx2=4.
The if–then statement is called implication and it
is denoted as p→q. It is false when p is true and
q is false and true otherwise.
if x= - 2 then x2 = 4
which is true even if the first part of this compound
statement is not true, say when x=2.
A B A⇔B
True True True
True False False
False True False
False False True
Example,
“It is raining today if and only if it is Friday
today.” is a proposition which is of the form
. The above proposition is true if it is not
Friday and it is not raining or if it is Friday and
it is raining, and it is false when it is not Friday
or it is not raining.
Example,
The exclusive or of the propositions –
“Today is Friday” and – “It is raining
today”, is “Either today is Friday or it
is raining today, but not both”. This
proposition is true on any day that is a
Friday or a rainy day(not including rainy
Fridays) and is false on any day other
than Friday when it does not rain or rainy
Fridays.
Tautologies
A Tautology is a formula which is always true
for every value of its propositional variables.
Example − Prove [(A→B)∧A]→B is a
tautology
A B A → B (A → B) ∧ A [( A → B ) ∧ A] → B
Contradictions
A Contradiction is a formula which is always
false for every value of its propositional
variables.
Example − Prove (A∨B)∧[(¬A)∧(¬B)] is a
contradiction
The truth table is as follows −
A∨ (¬ A) ∧ (A ∨ B) ∧ [( ¬
A B ¬A ¬B
B ( ¬ B) A) ∧ (¬ B)]
Contingency
A Contingency is a formula which has both
some true and some false values for every
value of its propositional variables.
Example − Prove (A∨B)∧(¬A) is a contingency
The truth table is as follows −
A B A ∨ B ¬ A (A ∨ B) ∧ (¬ A)
True True True False False
True False True False False
False True True True True
False False False True False
As we can see every value of (A∨B)∧(¬A)
has both “True” and “False”, it is a contingency.
Propositional Equivalences
Two statements X and Y are logically
equivalent if any of the following two
conditions hold −
⚫ The truth tables of each statement have the
same truth values.
⚫ The bi-conditional statement X⇔Y is a
tautology.
Example − Prove ¬(A∨B)and[(¬A)∧(¬B)]
are equivalent
Testing by 1st method (Matching truth table)
A∨ ¬ (A ∨ [(¬ A) ∧ (¬
A B ¬A ¬B
B B) B)]
True True True False False False False
True False True False False True False
False True True False True False False
False False False True True True True
Conditional Statement:
p q p→q
True True True
True False False
False True True
False False True
To summarize,
p q p →q q→p (p →q)∧(q→p)
True True True True True
True False False True False
False True True False False
False False True True True
Since, the truth tables are the same, hence
they are logically equivalent. Hence Proved.
Derived Connectors
1. NAND: It means negation after ANDing of
two statements. Assume p and q be two
propositions. Nanding of p and q to be a
proposition which is false when both p and q
are true, otherwise true. It is denoted by p ↑ q.
p q p↑q
True True False
True False True
False True True
False False True
2. NOR or Joint Denial: It means negation
after ORing of two statements. Assume p and
q be two propositions. NORing of p and q to
be a proposition which is true when both p and
q are false, otherwise false. It is denoted by
p ↓ q.
p q p↓q
True True False
True False False
False True False
False False True
3. XOR: Assume p and q be two propositions.
XORing of p and q is true if p is true or q is
true but not both and vice-versa. It is denoted
by p ⨁ q.
p q p⨁q
True True False
True False True
False True True
False False False
Example1: Prove that
X ⨁ Y ≅ (X∧∼Y)∨(∼X∧Y).
Solution: Construct the truth table for both the
propositions.
(X ∧∼Y)
X Y X⨁Y ∼Y ∼X X ∧∼Y ∼X∧Y ∨
(∼X∧Y)
True True False False False False False False
True False True True False True False True
False True True False True False True True
False False False True True False False False
As the truth table for both the proposition is the
same.
X ⨁ Y ≅ (X ∧∼Y)∨(∼X∧Y).
Hence Proved.
Example2: Show that (p ⨁q) ∨(p↓q) is
equivalent to p ↑ q.
Solution: Construct the truth table for both the
propositions.
(p⨁q)
p q p⨁q (p↓q) ∨ p↑q
(p↓q)
True True False False False False
True False True False True True
False True True False True True
False False False True True True
Guidelines to Translation
(i).If the sentence you are translating is a
simple declarative sentence, then you’re done.
Remember, in Propositional Logic, these are
just represented as atomic propositions, e.g.,
p..
(ii). Assuming the sentence you have to
translate is a compound sentence, the first
step is to identify the simple, declarative
sentences in it. (We will ignore embedded
sentences. So for example, the sentence I
know Bob is happy is treated as a simple
declarative sentence, even though it contains
the embedded sentence Bob is happy.)
(iii). Once you’ve identified the simple,
declarative sentences, translate these into
atomic propositions. You can write each one
like this: “p = ...” or “Let p = ...”
(iv).Next you need to identify those words that
string the simple sentences together in English,
e.g., and, but, or, if...then, if and only if, just in
case, it is not the case that, unless,only if,
when, etc.
(v).Once you’ve identify these words, translate
them into the appropriate connectives in
Propositional Logic.
(vi).Lastly, you need to determine the order the
atomic propositions combine in with the
connectives. When you combine the atomic
propositions, remember that the syntactic rules
of PL(propositional logic ) must be satisfied—
so you’re not working in a vacuum. These
rules can help guide you.
(vii).Remember to use (but not abuse) the
parenthesis. They make a difference. Pay
attention to Rule (ii) to figure out where they
go.
Atomic propositions correspond to simple,
declarative sentences. So these are the
easiest to translate. To do this, we need only
equate an atomic proposition to the sentence
we want it to correspond to.
Translating Negation
Translating Conjunction
(A) It is raining and Mary is sick(p ∧ q)
(B) Bob stayed up late last night and John is
a loud-mouth(t ∧ s)
(C) Paris isn’t the capital of France and It
isn’t raining(¬r ∧¬p)
(D) John is a loud-mouth but Mary isn’t sick
(s ∧¬q)
(E) It is not the case that it is raining and
Mary is sick
translation 1: It is not the case that both it is
raining and Mary is sick ¬(p ∧ q)
translation 2: Mary is sick and it is not the case
that it is raining (¬p ∧ q)
Translating Disjunction
Translating Implication
Another example,
Show that .
Considering LHS,
❖ De Morgan’s Law :
In propositional logic and boolean algebra, De
Morgan’s laws are a pair of transformation
rules that are both valid rules of inference.
They are named after Augustus De Morgan, a
19th-century British mathematician. The rules
allow the expression of conjunctions and
disjunctions purely in terms of each other via
negation.
In formal language, the rules are written as –
•
Duality Principle
Two formulas A1 and A2 are said to be dual of each
other if either one can be obtained from the other by
replacing ∧ (AND) by ∨ (OR) and ∨ (OR) by ∧
(AND). Also if the formula contains T (True) or F
(False), then we replace T by F and F by T to obtain
the dual.
Normal Forms
The problem of finding whether a given
statement is tautology or contradiction or
satiable 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
True True True
True False True
False True True
False False 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.
A compound statement is in disjunctive normal
form if it is obtained by operating OR among
variables (negation of variables included)
connected with ANDs. In terms of set
operations, it is a compound statement
obtained by Union among variables connected
with Intersections.
Examples
➢ (A∧B)∨(A∧C)∨(B∧C∧D)
➢ (P∩Q)∪(Q∩R)
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
p q p∧q
True True True
True False False
False True False
False False False
Predicate Logic
Predicate Logic deals with predicates, which
are propositions containing variables.
A predicate is an expression of one or more
variables defined on some specific domain. A
predicate with variables can be made a
proposition by either assigning a value to the
variable or by quantifying the variable.
The following are some examples of
predicates −
• Let E(x, y) denote "x = y"
• Let X(a, b, c) denote "a + b + c = 0"
• Let M(x, y) denote "x is married to y"
Well Formed Formula
Well Formed Formula (wff) is a predicate
holding any of the following −
◆ All propositional constants and propositional
variables are wffs. If x is a variable and Y is
a wff, ∀xY and ∃xY are also wff
Truth value and false values are wffs
Each atomic formula is a wff
All connectives connecting wffs are wffs
Quantifiers
The variable of predicates is quantified by
quantifiers. There are two types of quantifier in
predicate logic − Universal Quantifier and
Existential Quantifier.
Universal Quantifier
Universal quantifier states that the statements
within its scope are true for every value of the
specific variable. It is denoted by the symbol
∀.∀xP(x) is read as for every value of x, P(x) is
true.
Mathematical statements sometimes assert
that a property is true for all the values of a
variable in a particular domain, called the
domain of discourse. Such a statement is
expressed using universal quantification.
The universal quantification of P(x)for a
particular domain is the proposition that
asserts that P(x) is true for all values of x in
this domain. The domain is very important
here since it decides the possible values of x.
The meaning of the universal quantification of
P(x) changes when the domain is changed.
The domain must be specified when a
universal quantification is used, as without it, it
has no meaning.
Example − "Man is mortal" can be
transformed into the propositional form ∀xP(x)
where P(x) is the predicate which denotes x is
mortal and the universe of discourse is all men.
If p(x) is a proposition over the universe U.
Then it is denoted as ∀x,p(x) and read as "For
every x∈U,p(x) is true." The quantifier ∀ is
called the Universal Quantifier.
There are several ways to write a proposition,
with a universal quantifier.
∀x∈A,p(x) or p(x), ∀x ∈A Or ∀x,
p(x) or p(x) is true for all x ∈A.
Existential Quantifier
Existential quantifier states that the statements
within its scope are true for some values of the
specific variable. It is denoted by the symbol
∃.∃xP(x) is read as for some values of x, P(x)
is true.
Some mathematical statements assert that
there is an element with a certain property.
Such statements are expressed by existential
quantification. Existential quantification can be
used to form a proposition that is true if and
only if P(x) is true for at least one value of in
the domain.
Basic Example
Now, before we jump into the inference rules,
let’s look at a basic example to help us
understand the notion of assumptions and
conclusions.
Is this argument valid?
Without using our rules of logic, we can
determine its truth value one of two ways.
1. Surmising the fallacy of each premise,
knowing that the conclusion is valid only
when all the beliefs are valid.
2. Construct a truth table and verify a
tautology.
From the above example, if we know that both
premises “If Marcus is a poet, then he is poor”
and “Marcus is a poet” are both true, then the
conclusion “Marcus is poor” must also be true.
And using a truth table validates our claim as
well.
What are Rules of Inference for?
Mathematical logic is often used for logical
proofs. Proofs are valid arguments that
determine the truth values of mathematical
statements.
An argument is a sequence of statements. The
last statement is the conclusion and all its
preceding statements are called premises (or
hypothesis). The symbol “∴”, (read therefore)
is placed before the conclusion. A valid
argument is one where the conclusion follows
from the truth values of the premises.
Rules of Inference provide the templates or
guidelines for constructing valid arguments
from the statements that we already have.
∴P ∴Q∨S
P→Q (P→Q)∧(R→S) Destructive
¬Q∨¬S Dilemma
P Modus Ponens
∴Q ∴¬P∨¬R
P→Q Modus Tollens
¬Q
∴¬P
◆ Addition
If P is a premise, we can use Addition rule
to derive P∨Q.
P
∴P∨Q
Example
Let P be the proposition, “He studies very hard”
is true
Therefore − "Either he studies very hard Or he
is a very bad student." Here Q is the
proposition “he is a very bad student”.
◆ Conjunction
If P and Q are two premises, we can use
Conjunction rule to derive P∧Q.
P
Q
∴P∧Q
Example
Let P − “He studies very hard”
Let Q − “He is the best boy in the class”
Therefore − "He studies very hard and he is
the best boy in the class"
◆ Simplification
If P∧Q is a premise, we can use Simplification
rule to derive P.
P∧Q
∴P
Example
"He studies very hard and he is the best boy in
the class", P∧Q
Therefore − "He studies very hard"
◆ Modus Ponens
If P and P→Q are two premises, we can use
Modus Ponens to derive Q.
P→Q
P
∴Q
Example
"If you have a password, then you can log on
to facebook", P→Q
"You have a password", P
Therefore − "You can log on to facebook"
◆ Modus Tollens
If P→Q and ¬Q are two premises, we can use
Modus Tollens to derive ¬P.
P→Q
¬Q
∴¬P
Example
"If you have a password, then you can log on
to facebook", P→Q
"You cannot log on to Facebook", ¬Q
Therefore − "You do not have a password "
◆ Disjunctive Syllogism
If ¬P and P∨Q are two premises, we can use
Disjunctive Syllogism to derive Q.
¬P
P∨Q
∴Q
Example
"The ice cream is not vanilla flavored", ¬P
"The ice cream is either vanilla flavored or
chocolate flavored", P∨Q
Therefore − "The ice cream is chocolate
flavored”
◆ Hypothetical Syllogism
If P→Q and Q→R are two premises, we can
use Hypothetical Syllogism to derive P→R
P→Q
Q→R
∴P→R
Example
"If it rains, I shall not go to school”, P→Q
"If I don't go to school, I won't need to do
homework", Q→R
Therefore − "If it rains, I won't need to do
homework"
◆ Constructive Dilemma
If (P→Q)∧(R→S) and P∨R are two premises,
we can use constructive dilemma to derive
Q∨S.
(P→Q)∧(R→S)
P∨R
∴Q∨S
Example
“If it rains, I will take a leave”, (P→Q)
“If it is hot outside, I will go for a shower”,
(R→S)
“Either it will rain or it is hot outside”, P∨R
Therefore − "I will take a leave or I will go for a
shower"
◆ Destructive Dilemma
If (P→Q)∧(R→S) and ¬Q∨¬S are two
premises, we can use destructive dilemma to
derive ¬P∨¬R.
(P→Q)∧(R→S)
¬Q∨¬S
∴¬P∨¬R
Example
“If it rains, I will take a leave”, (P→Q)
“If it is hot outside, I will go for a shower”,
(R→S)
“Either I will not take a leave or I will not go for
a shower”, ¬Q∨¬S
Therefore − "Either it does not rain or it is not
hot outside"
Example — Simplification
Example - Resolution
Logic diagram
Truth Table
0 = FALSE
1 = TRUE
⚫ OR Gate
A circuit which performs an OR operation is
shown in figure. It has n input (n ≥ 2) and one
output.
Logic diagram
Truth Table
⚫ NOT Gate
NOT gate is also known as Inverter. It has
one input A and one output Y.
Logic diagram
Truth Table
⚫ NAND Gate
A NOT-AND operation is known as NAND
operation. It has n input (n ≥ 2) and one output.
Logic diagram
Truth Table
⚫ NOR Gate
A NOT-OR operation is known as NOR
operation. It has n input (n ≥ 2) and one output.
Logic diagram
Truth Table
⚫ XOR Gate
XOR or Ex-OR gate is a special type of gate. It
can be used in the half adder, full adder and
subtractor. The exclusive-OR gate is
abbreviated as EX-OR gate or sometime as
X-OR gate. It has n input (n ≥2) and one
output.
Logic diagram
Truth Table
⚫ XNOR Gate
XNOR gate is a special type of gate. It can be
used in the half adder, full adder and
subtractor. The exclusive-NOR gate is
abbreviated as EX-NOR gate or sometime as
X-NOR gate. It has n input (n ≥ 2) and one
output.
Logic diagram
Truth Table