Logic
Logic
logic
Introduction:
It is the science dealing with the method of reasoning the
mathematical models.
needs some rules associated with logic so that we can apply those
rules for mathematical reasoning.
It is defined as the representation language of knowledge.
It has practical applications to the design of computing machines, to
artificial intelligence, to computer programming, and to other areas
of computer science.
On the basis of its representation capability it is of two types:
a) propositional logic
b) predicate logic
Propositional Logic:
A proposition is a declarative sentence (that is, a sentence that
declares a fact) that is either true or false, but not both.
The truth value of a proposition is true, denoted by T, if it is a true
proposition, and the truth value of a proposition is false, denoted by
F, if it is a false proposition.
All the following declarative sentences are propositions.
1. Washington, D.C., is the capital of the United States of America.
2. Toronto is the capital of Canada.
3. 1 + 1 = 2.
4. 2 + 2 = 3.
Propositions 1 and 3 are true, whereas 2 and 4 are false.
Propositional logic is of two types
a) Simple propositional logic
b) Compound propositional logic
a) Simple: It express atomic propositions about the world.
Atomic sentence are either propositional symbols P, Q,
R, S…. Or logical constant ( true, false)
b) Compound: It can be formed by combining atomic
formulas with the following connectives not( ¬ ),
and(∧), or(∨), implication(->) and bi-conditional(<->).
Logical Operators/Connectives
Example1:
How can this English sentence be translated into a logical expression?
“You can access the Internet from campus only if you are a computer
science major or you are not a freshman.”
Solution: we will use propositional variables to represent each
sentence part and determine the appropriate logical connectives
between them.
let a, c, and f represent “You can access the Internet from campus,”
“You are a computer science major,” and “You are a freshman,”
respectively. Noting that “only if” is one way a conditional
statement can be expressed, this sentence can be represented as:
a → (c ∨ ¬ f ).
Translating English Sentences
Example2:
How can this English sentence be translated into a logical
expression?
“You cannot ride the roller coaster if you are under 4 feet tall
unless you are older than 16 years old.”
Solution:
Let q, r, and s represent “You can ride the roller coaster,” “You
are under 4 feet tall ,” and “You are older than 16 years old,”
respectively.
Then the sentence can be translated to
(r ∧ ¬ s)→ ¬ q.
Example3:
Express the specification “ the automated reply cannot be
sent when the file system is full” using logical connectives.
Soln:
Let p denote “ the automated reply can be sent”
q denote “ the file system is full”
Then, ¬ p represent “ the automated reply cannot be sent”
Now,
the conditional statement will be
q-> ¬ p
Tautology, Contradiction and Contingency:
A compound proposition that is always true, no matter what the
truth values of the atomic propositions that contain in it, is called
a tautology. For e.g. p ∨ ¬ p is always true.
A compound proposition that is always false is called
contradiction. For e.g. p ∧ ¬ p is always false
A compound proposition that is neither a tautology nor a
contradiction is called a contingency.
Logical Equivalences
Logical Equivalences:
If two propositions are semantically identical then we say
those two propositions are “equivalent”.
The compound propositions p and q are
logically equivalent, denoted by p <-> q or p
≡ q,
If proposition p<-> q is a tautology.
The truth table of each statement have the
same truth values.
Logical Equivalences
a) Truth table:
Logical Equivalences
b) Symbolic Derivation:
Show that ¬ (p → q) and p ∧ ¬ q are logically equivalent.
solution:
¬ (p → q) ≡ ¬ ( ¬ p ∨ q) by implication law
≡ ¬ ( ¬ p)∧ ¬ q by the second De Morgan
law
≡ p ∧ ¬ q by the double negation law
Show that ¬ (p ∨ ( ¬ p ∧ q)) and ¬ p ∧ ¬ q are logically equivalent by
developing a series of logical equivalences.
¬ (p ∨ ( ¬ p ∧ q)) ≡ ¬ p ∧ ¬ ( ¬ p ∧ q) by the second De Morgan law
≡ ¬ p ∧ [ ¬ ( ¬ p)∨ ¬ q] by the first De Morgan law
≡ ¬ p ∧ (p ∨ ¬ q) by the double negation law
≡ ( ¬ p ∧ p) ∨ ( ¬ p ∧ ¬ q) by the second distributive
law
≡ F ∨ ( ¬ p ∧ ¬ q) because ¬ p ∧ p ≡ F
≡ ( ¬ p ∧ ¬ q) ∨ F by the commutative law for
disjunction
≡ ¬p∧¬q by the identity law for F
Show that (p ∧ q) → (p ∨ q) is a tautology.
Solution:
To show that this statement is a tautology, we will use logical
equivalences to demonstrate that it is logically equivalent to T.
(p ∧ q) → (p ∨ q) ≡ ¬ (p ∧ q) ∨ (p ∨ q) by implication law
≡ ( ¬ p ∨ ¬ q) ∨ (p ∨ q) by the first De Morgan law
≡ ( ¬ p ∨ p) ∨ ( ¬ q ∨ q) by the associative and
commutative laws for
disjunction
≡ T ∨ T by trivial tautology and the commutative law
for disjunction
≡T by the domination law
Predicate logic.
1) Universal Quantifier:
It state that the statements within its scope are true for every value of the
specific variable.
It is denoted by the symbol ∀.
The process of converting predicate into proposition using universal
quantifier is called universal quantification.
The universal quantification of P(x) is the statement
“P(x) for all values of x in the domain.”
The notation ∀x P(x) denotes the universal quantification of P(x). Here ∀
is called the universal quantifier. We read ∀x P(x) as “for all x P(x)” or
“for every x P(x).”
An element for which P(x) is false is called a counterexample of ∀x P(x).
Quantifiers
Example:
Let P(x) be the statement “x + 1 > x.” What is the truth
value of the quantification ∀x P(x), where the domain
consists of all real numbers?
Solution:
Because P(x) is true for all real numbers x, the
quantification ∀x P(x) is true.
Quantifiers
Example:
Let Q(x) be the statement “x <= 2.” What is the truth value
of the quantification ∀x Q(x), where the domain consists
of all real numbers?
Solution:
Q(x) is not true for every real number x, because, for
instance, Q(3) is false. That is, x = 3 is a counterexample
for the statement ∀x Q(x). Thus ∀x Q(x) is false.
Quantifiers
2) Existential Quantifier:
It state that the statements within its scope are true for
some value of the specific variable .
It is denoted by ∃.
The existential quantification of P(x), denoted by ∃x P(x),
is a proposition “P(x) is true for some values of x in the
universe of discourse”.
The other forms of representation include “there exists x
such that P(x) is true” or “ P(x) is true for at least one x”.
Quantifiers
Example:
Let P(x) denote the statement “x > 3.” What is the truth
value of the quantification ∃x P(x), where the domain
consists of all real numbers?
Solution:
Because “x > 3” is sometimes true—for instance, when x =
4 the existential quantification of P(x), which is ∃x P(x),
is true.
Quantifiers
Example:
Let Q(x) denote the statement “x = x + 1.”What is the truth
value of the quantification ∃x Q(x), where the domain
consists of all real numbers?
Solution:
Because Q(x) is false for every real number x, the existential
quantification of Q(x), which is ∃x Q(x), is false.
Quantifiers
Precedence of Quantifiers:
The quantifiers ∀ and ∃ have higher precedence than all logical operators
from propositional calculus. For example, ∀x P(x) ∨ Q(x) is the
disjunction of ∀x P(x) and Q(x).
In other words , it means (∀x P(x)) ∨ Q(x) rather than ∀x(P(x) ∨ Q(x)).
Binding Variables:
When a quantifier is used on the variable , we say that this occurrence of
the variable is bound.
An occurrence of a variable that is not bound by a quantifier is said to be
free.
Eg: In the statement ∃x(x + y = 1), the variable x is bound by the existential
quantification ∃x, but the variable y is free because it is not bound by a
quantifier and no value is assigned to this variable. This illustrates that in
the statement ∃x(x + y = 1), x is bound, but y is free.
Quantifiers
Example 1
Translate “not every integer is even” where the universe
of discourse is set of integers.
Solution:
Let E(x) denotes x is even.
¬∀ x E(x)
Translating the Sentences into Logical Expression
Express the statements “Some student in this class has visited Mexico”
and “Every student in this class has visited either Canada or Mexico”
using predicates and quantifiers.
Solution:
The statement “Some student in this class has visited Mexico” means that
“There is a student in this class with the property that the student has
visited Mexico.”
We can introduce a variable x, so that our statement becomes
“There is a student x in this class having the property that x has visited
Mexico.”
We introduce M(x), which is the statement “x has visited Mexico.” If the
domain for x consists of the students in this class, we can translate this
first statement as ∃x M(x).
Translating the Sentences into Logical Expression
Rules of Reasoning:
To draw conclusion from the given premise we must be able to
apply some well defined steps that helps reaching the conclusion.
These steps of reaching the conclusion are provided by rule of
inference.
Rule 1: modus ponens( law of detachment):
p→q
∴q
p
when both p → q and p are true, we know that q must also be true.
i.e (p ∧ (p → q)) → q is tautology.
Example:
Suppose that the conditional statement “If it snows today,
then we will go skiing” and its hypothesis, “It is snowing
today,” are true.
Then, by modus ponens, it follows that the conclusion of
the conditional statement, “We will go skiing,” is true.
Example:
State which rule of inference is the basis of the following
argument: “It is below freezing now . Therefore, it is
either below freezing or raining now.”
Solution: Let p be the proposition “It is below freezing
now” and q the proposition “It is raining now.” Then this
argument is of the form
∴p∨q
p
∴p
p∧q
Solution:
Let p be the proposition “It is sunny this afternoon,” q the
proposition “It is colder than yesterday,” r the proposition “We
will go swimming,” s the proposition “We will take a canoe
trip,” and t the proposition “We will be home by sunset.”
Then the premises become
¬ p ∧ q, r → p, ¬ r → s, and s → t . The conclusion is simply t.
We need to give a valid argument with premises ¬ p ∧ q, r →
p, ¬ r → s, and s → t and conclusion t .
We construct an argument to show that our premises lead to the
desired conclusion as follows.
Using Rules of Inference to Build Arguments
Step Reason
1. ¬ p ∧ q Premise/ Hypothesis
2. ¬ p Simplification using (1)
3. r → p Premise / Hypothesis
4. ¬ r Modus tollens using (2) and (3)
5. ¬ r → s Premise
6. s Modus ponens using (4) and (5)
7. s → t Premise
8. t Modus ponens using (6) and (7)
Using Rules of Inference to Build Arguments
Example:
Show that the premises “If you send me an e-mail message, then I will finish
writing the program,” “If you do not send me an e-mail message, then I will
go to sleep early,” and “If I go to sleep early, then I will wake up feeling
refreshed” lead to the conclusion “If I do not finish writing the program, then I
will wake up feeling refreshed.”
Solution:
Let p be the proposition “You send me an e-mail message,” q
the proposition “I will finish writing the program,” r the
proposition “I will go to sleep early,” and s the proposition “I
will wake up feeling refreshed.” Then the premises are p →
q , ¬ p → r, and r → s. The desired conclusion is ¬ q → s. We
need to give a valid argument with premises p → q, ¬ p → r,
and r → s and conclusion ¬ q → s.
Using Rules of Inference to Build Arguments
This argument form shows that the premises lead to the desired
conclusion.
Step Reason
1. p → q Premise
2. ¬ q → ¬ p Contra-positive of (1)
3. ¬ p → r Premise
4. ¬ q → r Hypothetical syllogism using (2) and (3)
5. r → s Premise
6. ¬ q → s Hypothetical syllogism using (4) and (5)
Rules of Inference for Quantified Statements
1) Direct Proofs:
In a direct proof, we assume that p is true
and use axioms, definitions, and previously
proven theorems, together with rules of
inference, to show that q must also be true.
It is quite straightforward, with a sequence
of steps leading from the hypothesis to the
conclusion.
Direct Proofs:
Give a direct proof of the theorem “If n is an odd integer, then n2 is odd.”
Solution:
To begin a direct proof of this theorem, we assume that the hypothesis of this
conditional statement is true, namely, we assume that n is odd.
By the definition of an odd integer, it follows that
n = 2k + 1, where k is some integer.
We want to show that n2 is also odd.
We can square both sides of the equation n = 2k + 1 to obtain a new equation that
expresses n2.
n2 = (2k + 1)2
= 4k2+ 4k + 1
= 2(2k2 + 2k) + 1.
By the definition of an odd integer, we can conclude that n2 is an odd integer (it is
one more than twice an integer).
Consequently, we have proved that if n is an odd integer, then n2 is an odd integer.
Eg: Give a direct proof that if m and n are both perfect squares, then nm
is also a perfect square.
Solution:
To produce a direct proof of this theorem, we assume that the hypothesis of
this conditional statement is true, namely, we assume that m and n are both
perfect squares.
By the definition of a perfect square, it follows that there are integers s and t
such that m = s2 and n = t2.
The goal of the proof is to show that mn must also be a perfect square when
m and n are; looking ahead we see how we can show this by substituting s2
for m and t2 for n into mn.
mn = s2t2.
= s2t2
= (ss)(t t)
= (st)(st) = (st)2
By the definition of perfect square, it follows that mn is also a perfect
square, because it is the square of st, which is an integer.
We have proved that if m and n are both perfect squares, then mn is also a
perfect square.
2.Indirect proofs
Proofs of theorems of this type that are not direct proofs, that is,
it do not start with the premises and end with the conclusion.
It is also known as proof by contraposition.
Proofs by contraposition make use of the fact that the conditional
statement p → q is equivalent to its contra-positive, ¬ q → ¬ p.
This means that the conditional statement p → q can be proved
by showing that its contra-positive, ¬ q → ¬ p, is true.
In a proof by contraposition of p → q, we take ¬ q as a premise,
and using axioms, definitions, and previously proven theorems,
together with rules of inference, we show that ¬ p must follow.
Example: Prove that if n is an integer and 3n + 2 is odd, then n is
odd.
solution:
The first step in a proof by contraposition is to assume that the
conclusion of the conditional statement
“If 3n + 2 is odd, then n is odd” is false; namely, assume that n is
even. Then, by the definition of an even integer, n = 2k for some
integer k. Substituting 2k for n, we find that
3n + 2 = 3(2k) + 2 = 6k + 2 = 2(3k + 1).
This tells us that 3n + 2 is even (because it is a multiple of 2), and
therefore not odd.
This is the negation of the premise of the theorem.
Because the negation of the conclusion of the conditional statement
implies that the hypothesis is false, the original conditional statement
is true.
Our proof by contraposition succeeded;
We have proved the theorem “If 3n + 2 is odd, then n is odd.”
Indirect method
Solution:
Prove by contraposition. We take as our hypothesis the statement that
n is not odd. This means that n is even.
This implies that there exists an integer k such that n = 2k.
To prove the theorem,
we need to show that this hypothesis implies the conclusion that n2 is
not odd, i.e , that n2 is even.
Can we use the equation n = 2k to achieve this?
By squaring both sides of this equation, we obtain
n2= 4k2= 2(2 k2),
which implies that n2 is also even because n2 = 2t , where t = 2 k2.
We have proved that if n is an integer and n2 is odd, then n is odd.
Our attempt to find a proof by contraposition succeeded.
3.Proofs by Contradiction
a2 is odd
So by contradiction, we can prove that
If a is an even number, then a2 is an even number.
4.Proof by Cases
case 2: n is even
since n is even n will be equal to 2x
Now,
substitute the value of n to the conclusion
n2 +3n + 4 = (2x)2 + 3(2x) +4
=2(2x2 +3x +2)
Which is also even.
So in both cases the conclusion is even i.e. true