Lecture 5 Logical Reasoning

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 59

LOGICAL

REASONING
Zagazig university
Faculty of computers and
informatics
Department of Computer Science
Logic
 Logic is the study of reasoning and the validity of
arguments.
 It is concerned with the truth of statements
(propositions) and the nature of truth.
 Propositional logic: is the study of propositions.
Proposition
• A statement or proposition is a statement that is either
true or false, but not both.
Example
 7*1=7. true
 7*5=23 False
 What is your name? It is not a proposition
 3 – x = 5 Not proposition. May true or false
 x is a dog. It is not a proposition
 May god bless you! It is not a proposition
 Take two aspirins. Not proposition. command
2.1. Propositions and Logical Operation
 Paradox
It is a seemingly true statement or group of statements
that lead to a contradiction or a situation which seems to
defy logic or intuition Paradox is not a statement.
EXAMPLES:
 Less is more
 Earn money by spending it
 The louder you are, the less they hear
 Impossible is not a word in my vocabulary
 “Whatever you do in life will be insignificant, but it is very
important that you do it” (Ghandi)
4
2.1. Propositions and Logical Operation
 Propositional variables
In logic, the letters p, q, r … denote propositional variables,
which are replaced by statements:
p: 1+2 = 5
q: It is raining.

 Compound statements
Propositional variables can be combined by logical
connectives to obtain compound statements.
p and q : 1+2 =5 and it is raining.
5
Logical connectives
• Compound propositions are formed by combining more
than one proposition using logical connectives.
• Example: Ahmed is a boy and Lobna is a girl.
• Types of logical connectives
1. Negation (~) read as NOT
2. Conjunction (⋀) read as AND
3. Disjunction (∨) read as OR
4. Conditional() read as implies
5. Biconditional (↔). If and only if
The most basic connectives are the first three connectives
as we can write any compound proposition using them.
1. Negation
• Negation of the statement is another statement that has
an opposite meaning for the statement.
• If P is a statement, then negation of P is written as ~P (not
P).
P: Yesterday is Monday.
~P: Yesterday is not Monday.
• The truth table for the negation of a proposition is:
p ~p if p is true, then ~p is false. if
T F p is false, then ~p is true.
F T
Examples
 Example:
Give the negation of the following statements
(a) p: 2+3 >1
(b) q: It is snowing.

Solution:
(a) ~p: 2+3 is not greater than 1, namely, 2+3 <=1
(b) ~q: It is not the case that it is snowing. More simply, ~q:
It is not snowing.

8
2. Conjunction (⋀)
Truth table of p ⋀ q
• Let p and q are propositions.
• The proposition p ⋀ q is called
conjunction and read as p and q.
• The p⋀q is true if both p and q are true.
• Example:
p: It is snowing. Simple proposition
q: Iam cold. Simple proposition
p ⋀ q: It is snowing and Iam cold.
Compound proposition
3. Disjunction (∨)
• The proposition p∨q is called disjuction and is read as p
or q.
• p∨q is true if either p or q is true.
• p∨q is false if both p and q are false.
• Example:
p: 2 is a number. true
q:√2 is rational. false
p ∨q: 2 is a number or √2 is rational.
true ∨ false = true
4. Conditional ()
• The proposition pq is called
conditional and is read as if p then q.
• In this implication pq, p is called
hypothesis or premise and q is called
conclusion or consequence.
• Example:
• p: Iam hungry.
• q: I will eat.
• pq: Iam hungry then I will eat.
• Note that: pq is true if both p and q
are false, otherwise it is equal to q.
4. Conditional ()
• The proposition pq is called
conditional and is read as if p then q.
• In this implication pq, p is called
hypothesis or premise and q is called
conclusion or consequence.
• Example:
• p: Iam hungry.
• q: I will eat.
• pq: Iam hungry then I will eat.
Note that: pq is true if both p and q are false, otherwise it
is equal to q.
5. Biconditional (↔)
• The statement p↔q is called bicondional and
read as “p if and only if q” or “p iff q”.
• p↔q: p is necessary and a sufficient condition for
q.
• p↔q is true if both p and q are equal.
• Note that: p↔q =(pq) ⋀ (qp)
Question
• Make a truth table for the statement: (p^q) ∨(~p).
p q p⋀q ~p (p⋀q) ∨(~p)
T T T F T
T F F F F
F T F T T
F F F T T
Question
• Is the following equivalence a true statement?
3 > 2 if and only if 0 < 3 - 2.
Answer:
Let p: 3 > 2. true
q: 0 < 3 – 2. true
Both p and q are true, then p ↔q is true.
Tautology
• Tautology is a statement that is true for all
values.
p q pq ~q ~p ~q~p (pq) ↔ (~q~p)
T T T F F T T
T F F T F F T
F T T F T T T
F F T T T T T
Tautology
Contradiction
• The statement that is false for all possible values is
called contradiction.
p ~p p⋀~p
T F F
F T F
Contradiction
Contingency
• The statement is a combination of true and
false values.
p q p⋀q ~p (p⋀q) ∨(~p)
T T T F T
T F F F F
F T F T T Contingency
F F F T T
Questions. T/F
• Verify that:

1. p∨ ~(p ⋀ q) is a tautology.
2. (p ⋀ q) ⋀ ~(p∨q) is a contradiction.
3. (pq) ⋀(p∨q) is a contingency.
Conditional statment

symbol Statement
Implication or pq If p, then q
conditional
Converse qp If q, then p
Inverse ~p~q If not p, then not q
Contrapositive ~q~p If not q, then not p
Notes T/F
• Each of the following is a tautology:
• p ⋀ qp
• p ⋀ qq
• p(p ∨ 𝑞)
• q(p ∨ 𝑞)
• ~p(pq)
• ~(pq)q
• (p ⋀(pq))q
• (~p ⋀(p ∨ 𝑞))q
Questions . T/F
• Prove that (p ∨ 𝒒) ⋀ ~p ≡~p ⋀ 𝒒.
(p ∨ 𝑞) ⋀ ~p ≡~p ⋀ (p ∨ 𝑞) ≡ (~p ⋀ p) ∨ (~p ⋀ q)
≡ F ∨ (~p ⋀ q) ≡ (~p ⋀ q)

• Prove that: ~q~p ≡ pq


~q~p ≡~(~q) ∨(~p)≡q ∨(~p) ≡~p ∨ q ≡ pq
Questions
Questions
Precedence rules for logical
connectives
Connective Precedence
() first
~ second
⋀ third
∨ fourth
 fifth
↔ sixth
Questions
Determine precedence rules for the following:

• ~p ∨q. (~p) ∨q
• p ∨~q ⋀ r. p ∨((~q) ⋀ r)
• ~q~p. (~q)(~p)
Predicate
• A predicate is a sentence that contains one or more
variables and becomes a statement or a proposition (to be
true or false) when specific values are substituted for the
variables.
• The domain of a predicate variable consists of all values
that may be substituted in place of the variable.
• If p(x) is a predicate and x has domain D, the truth set of
p(x) is the set of all elements of D that make p(x) true. The
truth set is denoted {x ∈ D : p(x)} and is read “the set of all
x in D such that p(x).”
Logical quantifiers
• Consider the following sentence:
“The integer x is prime and x >17”
This sentence isn’t a statement or proposition until the variable
x is given a value to determine if this statement is true or false.
• Such a sentence is called a propositional function and
denoted by p(x), q(x), r(x), … .
• Consider the sentence in logical form:
“If x is prime, then x is not a multiple of 4”

p(x)  q(x)
Logical quantifiers
• Existential quantifier: The statement is true if at least one value of
x is true.
 “There is x such that p(x)” ∃𝒙(𝒑(𝒙))
 It is read as: There is= There exists= for some= There is some

• Universal quantifier: The stament is true for every value of x.
 “for all x, p(x)”. ∀𝒙 𝒑(𝒙)
 It is read as: for all= for each=for every= given any ∀
• Examples:
• “There exists an x such that x is prime and x+10 is prime”
True as when x=19 then x+10=29 and 29 is prime
Logical quantifiers
• Consider the following statement about a real number x.
Determine the truth value for each of them:
• ∃𝒙(𝒙𝟐 = 𝟐).
True. since there is a value for x= 2 satisfy the statement.
• ∃𝒙(𝒙𝟐 < 𝟎).
False. Since every real number x has the property that x2≥0.
• ∀𝒙(𝒙 + 𝟏 > 𝒙).
True. x=1 and x+1=2, x=-1 and x+1=0, x=0 and x+1=1
• ∀𝒙( 𝑥2 = 𝒙).
False. See what happens if x is a negative number. 4=∓2
For each statement give formula that
represents it:
• For every positive integer n there exists a prime p such that p>n.
+
∀n∈ 𝒛 (∃𝒑, 𝒑 𝒊𝒔 𝒑𝒓𝒊𝒎𝒆 ⋀ 𝒑 > 𝒏)
• There exists two primes p and q whose sum is also prime.
∃𝒑 ∃𝒒, 𝒑 𝒊𝒔 𝒑𝒓𝒊𝒎𝒆⋀𝒒 𝒊𝒔 𝒑𝒓𝒊𝒎𝒆⋀(𝒑 + 𝒒) 𝒊𝒔 𝒑𝒓𝒊𝒎𝒆.
• For all rational numbers x and y, the sum x+y is also rational.
∀𝒙 ∈ 𝑸∀𝒚 ∈ 𝑸 (𝒙 + 𝒚 ∈ 𝑸)
• Every even integer n≥ 4 is the sum of two primes p and q.
∀𝒏 ∈ 𝒛(𝒏 𝒊𝒔 𝒆𝒗𝒆𝒏 ⋀𝒏 ≥ 𝟒 ), ∃𝒑 ∈ 𝑷∃𝒒 ∈ 𝑷 (𝒏 = 𝒑 + 𝒒).
P:symbol for prime.
Logical quantifiers
• All human beings are mortal
∀h ∈ H ⋀ h is mortal.
• The square of any real number is positive.
∀x ∈ R, x2 >0.
• Some cats are black
∃c∈C, c is black.
• There is some real number such that x2=2.
∃𝒙(𝒙∈𝑹 ⋀ 𝒙𝟐 = 𝟐).
• For every real number x2+1>0.
∀𝒙(𝒙∈𝑹 ⋀ 𝒙𝟐 + 𝟏 > 𝟎).
• There is some real number x such that x3-3x+1=0.
∃𝒙(𝒙∈𝑹 ⋀ x3−3x+1=0).
Negation of statements with multiple quantifiers
• ∀𝑥 ∈ 𝐴, ∀𝑦 ∈ 𝐵, 𝑃(𝑥, 𝑦)
~(∀𝑥 ∈ 𝐴, ∀𝑦 ∈ 𝐵, 𝑃(𝑥, 𝑦)) ≡ ∃𝑥 ∈ 𝐴, ∃𝑦 ∈ 𝐵, ~ 𝑃(𝑥, 𝑦)
• ∀𝑥 ∈ 𝐴, ∃𝑦 ∈ 𝐵, 𝑃(𝑥, 𝑦)
~(∀𝑥 ∈ 𝐴, ∃𝑦 ∈ 𝐵, 𝑃(𝑥, 𝑦)) ≡ ∃𝑥 ∈ 𝐴, ∀𝑦 ∈ 𝐵, ~ 𝑃(𝑥, 𝑦)
• ∃𝑥 ∈ 𝐴, ∀𝑦 ∈ 𝐵, 𝑃(𝑥, 𝑦)
~(∃𝑥 ∈ 𝐴, ∀𝑦 ∈ 𝐵, 𝑃(𝑥, 𝑦)) ≡ ∀𝑥 ∈ 𝐴, ∃𝑦 ∈ 𝐵, ~ 𝑃(𝑥, 𝑦)
• ∃𝑥 ∈ 𝐴, ∃𝑦 ∈ 𝐵, 𝑃(𝑥, 𝑦)
~(∃𝑥 ∈ 𝐴, ∃𝑦 ∈ 𝐵, 𝑃(𝑥, 𝑦)) ≡ ∀𝑥 ∈ 𝐴, ∀𝑦 ∈ 𝐵, ~ 𝑃(𝑥, 𝑦)
Find the negation of the following
formula:
• ∀𝒙∈Z+(𝐱 𝐢𝐬 𝐩𝐫𝐢𝐦𝐞 → 𝒙𝟐 + 𝟏 𝒊𝒔 𝒆𝒗𝒆𝒏).
Let p(x): x is prime , q(x): 𝒙𝟐 + 𝟏 𝒊𝒔 𝒆𝒗𝒆𝒏
p(x)q(x) = ~ p(x) ∨q(x).
Negation: ~(~ p(x) ∨q(x))= p(x) ⋀~q(x)
• 𝑨𝒏𝒔𝒘𝒆𝒓:
∃x∈Z+(x is prime and 𝒙𝟐 + 𝟏 𝒊𝒔 𝒏𝒐𝒕 𝒆𝒗𝒆𝒏). Or odd
Methods of proof
• Direct proof
• Indirect proof
Proof by contradiction
Proof by contrapositive
• Proof by induction
Proof by induction

• If p1, p2, p3, …, pn is a sequence of propositions.


 Basis: pn for n=1is true
 Hypothesis: Assume pn for n=k is true.
 Induction: If pn for n=k is true, then pn+1 for n=K+1 is true

• Then pn is true for all n by induction


Example 1
𝒏(𝒏+𝟏)
• Prove that: 1+2+3+….+n = . n≥ 𝟏
𝟐
Step 1: for n=1. min value Step 3:
L.H.S=1. Show that pn is true for n=k+1
𝑘+1(𝑘+1+1)
R.H.S=
1(1+1)
=1. 1+2+3+…+k+(k+1)=
2 2
∴ L.H.S=R.H.S
𝑘(𝑘+1)
∴ pn is true for n=1 L.H.S = + (k+1)= ½ k2 + 3/2k+1
2
𝑘+1(𝑘+1+1)
Step 2: R.H.S= = ½ k2 + 3/2k+1
2
Assume pn is true for n=k ∴ L.H.S=R.H.S
𝑘(𝑘+1)
1+2+3+….+k= .
2
Example 2
𝟑𝒏+𝟏 −𝟏
• Prove that: 1+3+9+27+….+3n = . n≥ 𝟎
𝟐
3 𝑛+1 −1
let: pn: 1+3+9+27+….+3n= .
2
Step 1: for n=0. min value
L.H.S=1.
𝟑𝟎+𝟏 −𝟏
R.H.S= =1.
𝟐
∴ L.H.S=R.H.S
∴ pn is true for n=0
Step 2:
Assume pn is true for n=k
3 𝑘+1 −1
1+3+9+27+….+3k= .
2
Example 2 (cont.)
Step 3:
Show that pn is true for n=k+1
3𝑘+1+1 −1
1+3+9+27+….+3k+ 3k+1 =
2

3𝑘+1 −1 k+1 3 𝑘+1 1


k+1= 1 1
L.H.S = +3 = - +3 ∗3 -
k+1 + 3k+1=
2 2 2 2 2
1 1 3 1 1 1 3 𝑘+2 −1
3k+1( +1)- = ∗ 3k+1- = *3* 3k+1 - =
2 2 2 2 2 2 2

3𝑘+1+1 −1 3𝑘+2 −1
R.H.S= =
2 2
∴ L.H.S=R.H.S
Example 3
 1.1!+2.2!+….+n.n!=(n+1)!-1. n≥ 1
Step1: for n=1
LHs=1.1!=1
RHS=(n+1)!-1 =(1+1)!-1=2-1=1
Pn is true for n=1
Step2: Assume pn is true for n=k
1.1!+2.2!+….+k.k!=(k+1)!-1.
Example 3 (cont.)
Step3: prove that pn is true for n=k+1
1.1!+2.2!+….+k.k!+(k+1).(K+1)!=(k+1+1)!-1.

LHS = (k+1)!-1 +(K+1).(k+1)!=(k+1)!.(1+k+1)-1=


(k+1)!.(k+2)-1=(k+2)!-1
RHS = (k+1+1)!-1=(k+2)!-1
Questions
1+3+5+⋯+(2k−1)=k2

20+21+22+23+⋯+2n=2n+1−1 for all non-negative


integers.

You might also like