You are on page 1of 11

Logic in Computer Science

Prof. Tathagata Ray


Associate Professor, BITS Pilani, Hyderabad Campus
rayt@hyderabad.bits-pilani.ac.in
BITS Pilani
Hyderabad Campus
Mathematical Induction

• Suppose we have a property 𝑀 which we want to prove


true for every natural number. We use Mathematical
Induction

• Definition: Given the below two facts about 𝑀, every natural


number 𝑛 has property 𝑀(𝑛).
• Base Case: The natural number 1 has property 𝑀 i.e. we have a proof of 𝑀 1 .

• Inductive Step: If 𝑛 is a natural number which we assume to have property 𝑀(𝑛),


then we can show that 𝑛 + 1 has property 𝑀 𝑛 + 1 i.e. we have a proof of 𝑀 𝑛 →
M n+1 .

BITS Pilani, Hyderabad Campus


Why it works!

• Proved it for 𝑛 = 1, i.e. 𝑀(1) is true.


• We show 𝑀 1 → 𝑀 2 .
• So by → 𝑒, together we have 𝑀(2) true.
• Then we show M 2 and 𝑀 2 → 𝑀 3 .
• So by → 𝑒, together we have 𝑀(3) true.
• In this manner we prove 𝑀(𝑛 + 1) using 𝑀(𝑛) and
𝑀 𝑛 →𝑀 𝑛+1 .

BITS Pilani, Hyderabad Campus


Another kind of Induction

• The induction hypothesis for proving 𝑀 𝑛 + 1 is not just


𝑀 𝑛 but the conjunction 𝑀 1 ∧ 𝑀 2 ∧ 𝑀 3 ∧... ∧
𝑀 𝑛 .

• Called course-of-values induction.

BITS Pilani, Hyderabad Campus


Example
Theorem: If n is divisible by 3, then fib(n) is even, otherwise fib(n) is odd.
Proof:
We shall employ course-of-values induction; there is thus no base step
but "only" the inductive step for which we have to do a case analysis.
In all cases, we can assume that the result hold for all m < n.
n = 1 or n = 2, These are not divisible by 3, and accordingly fib(n) = 1
which is odd.
n is divisible by 3; Then neither n-1 nor n-2 is divisible by 3. Our induction
hypothesis thus tells us that fib(n-1) and fib(n-2) are both odd. As fib(n) =
fib(n-1) + fib(n-2), this implies that fib(n) is even, as desired.
n > 3 but n is not divisible by 3; Then exactly one of n-1 and n-2 is
divisible by 3. Our induction hypothesis then tells us that exactly one of
fib(n-1) and fib(n-2) is even. As fib(n) = fib(n-1) + fib(n-2), this implies that
fib(n) is odd, as desired.
Note that the last two steps couldn't have been carried out using the
original principle of induction, where we in order to establish M(n) can
assume only M(n-1) but not M(n-2).

Source: http://people.cs.ksu.edu/~tamtoft/CIS301/Fall02/induction.html
BITS Pilani, Hyderabad Campus
Definition

• Given a well-formed formula 𝜙, we define its height to be


1 plus the length of the longest path of its parse tree.

• Example:

Height = 4+1=5

BITS Pilani, Hyderabad Campus


Theorem
Theorem: For every well-formed propositional logic formula, the number of
left brackets is equal to the number of right brackets.
Proof: Apply the course-of-values induction :
𝑀 𝑛 means: all well-formed proposition logic formulas of height 𝑛 have
the same number of left and right brackets.
Take a well formed formulas 𝜙 of height 𝑛. Then if 𝑛 = 1, then 𝜙 has to
be an atom and we are done (zero brackets).
if 𝑛 > 1, then the root of the parse tree of 𝜙 must be a connective ¬,∧,∨
, →. Let’s assume that the root of the parse tree contains →.
𝜙 is of type 𝜙1 → 𝜙2 , for two well-formed formulas 𝜙1 and 𝜙2 of strictly
smaller height than 𝑛. Using inductive hypothesis, we therefore
conclude 𝜙1 𝑎𝑛𝑑 𝜙2 have same number of left and right brackets. But in
𝜙1 → 𝜙2 we add only 1 left bracket and 1 right bracket. Thus the
number of left brackets is same as right bracket.

BITS Pilani, Hyderabad Campus


Soundness of Propositional
Logic
• We know the meaning of 𝜙1 , 𝜙2 , … , 𝜙𝑛 ⊢ 𝜓 being valid.

• Do we have any evidence that the proof rules are all


correct and that valid sequents “preserve truth”
computed by our truth-table semantics.

• Thankfully yes!
• Some proof of natural deduction established
𝜙1 , 𝜙2 , … , 𝜙𝑛 ⊢ 𝜓 is valid. We need to show: for all
valuations in which all propositions 𝜙1 , 𝜙2 , … , 𝜙𝑛 evaluate
to True, 𝜓 evaluates to True as well.

BITS Pilani, Hyderabad Campus


Definition

Definition: If , for all valuations in which all 𝜙1 , 𝜙2 , … , 𝜙𝑛


evaluates 𝑇, 𝜓 evaluates to 𝑇 as well, we say that
𝜙1 , 𝜙2 , … , 𝜙𝑛 ⊨𝜓

holds and call ⊨ semantic entailment relation.

BITS Pilani, Hyderabad Campus


Exercise

• Does 𝑝 ∧ 𝑞⊨𝑝 hold?

• Does 𝑝 ∨ 𝑞⊨𝑝 hold?

• Does ¬𝑞, 𝑝 ∨ 𝑞⊨𝑝 hold?

• Does 𝑝⊨𝑞 ∨ ¬𝑞 hold?

BITS Pilani, Hyderabad Campus


Soundness

• Theorem (Soundness) Let 𝜙1 , 𝜙2 , … , 𝜙𝑛 and 𝜓 be


propositional logic formulas. If 𝜙1 , 𝜙2 , … , 𝜙𝑛 ⊢ 𝜓 is valid,
then 𝜙1 , 𝜙2 , … , 𝜙𝑛 ⊨𝜓 holds.

BITS Pilani, Hyderabad Campus

You might also like