Induction Proofs

37
cs466(Prasad) L6Proof 1 Induction Proofs Equivalent Statements in Proofs

description

Induction Proofs. Equivalent Statements in Proofs. q. p. Language Equivalence Proofs. Soundness : All strings derivable in the grammar G have the “characteristic” property of strings in L. Thou shall not lie. - PowerPoint PPT Presentation

Transcript of Induction Proofs

Page 1: Induction Proofs

cs466(Prasad) L6Proof 1

Induction Proofs

Equivalent Statements in Proofs

Page 2: Induction Proofs

cs466(Prasad) L6Proof 2

p q :tionContraposi

q p :nImplicatio

q thenp if

p ifonly q

p.for necessary is q

q.for sufficient is p

Page 3: Induction Proofs

cs466(Prasad) L6Proof 3

q p hold.not does q and holds p

: thatcase not the isIt

q

p

Page 4: Induction Proofs

cs466(Prasad) L6Proof 4

Language Equivalence Proofs

bbb B

a A

AABAASBSG

| :

.)( Prove

}0|{

}|{)(32

LGL

nbaL

SGLnn

G

Page 5: Induction Proofs

cs466(Prasad) L6Proof 5

• Soundness: All strings derivable in the grammar G have the “characteristic” property of strings in L.

• Thou shall not lie.

• Typically the proof proceeds by associating an invariant with each variable that characterizes the strings it derives.

LGL )(

Page 6: Induction Proofs

cs466(Prasad) L6Proof 6

• Completeness: All strings in L are derivable in G.

• Thou shall speak the whole truth.

• Typically the proof presents an algorithm for generating a string template of L using the rules of the grammar G.

)(GLL

Page 7: Induction Proofs

cs466(Prasad) L6Proof 7

• How do we generate

Derivation Rule Application

)(GLL

bbbBnbbbaa

aAnBaa

AABSBAA

AASBSnSBAAS

nnn

nnn

nn

nnn

of appl. )()(

of .appl 2)(

)(

of appl. )1()(

2

11)1(

?32 nnba

Page 8: Induction Proofs

cs466(Prasad) L6Proof 8

• Let #w(x) = Number of occurrences of x in . Prove that

• Proof : By induction on the length of the derivation of a sentence.– Basis: l = 4

LGL )(

))(*#2)(#3()(: bwawS

aabbbS 4

Page 9: Induction Proofs

cs466(Prasad) L6Proof 9

• Induction Hypothesis:

• Induction Step:

By context-freeness of the grammar:

))(*#2)(#3()(: bwawS n

n

n

AASBS

S

)(:Let 1

aaubbbaaSbbb n 3

4n

1nl

Page 10: Induction Proofs

cs466(Prasad) L6Proof 10

• By induction hypothesis:

(Note that Sudkamp’s text illustrates an alternative approach. Its proof uses a property of sentential forms and shows that the rules in the grammar preserve it.)

uS n )3(

)(# * 2 )(# 3

Hence,

)(# 3 )(#

)(# 2 )(#

)(# * 2 )(# 3

bwaw

bubw

auaw

buau

Page 11: Induction Proofs

cs466(Prasad) L6Proof 11

Example

Two proofs for the same result.

Page 12: Induction Proofs

cs466(Prasad) L6Proof 12

)},|*|{

,*},,{},({

ExEEEEE

xEG

Prove that if (sentence) E

then

)( 1 (*)# )(# x#www

Page 13: Induction Proofs

cs466(Prasad) L6Proof 13

Informal Argument

E E

E

E E

+

*

x

x x

+ x * x x+

*

xx

x

Parse tree

Abstract syntax tree

Strictly Binary Trees: # nodes = (2 * #leaves) – 1# ops + # vars = (2 * #vars) – 1

# ops + 1 = #vars#(+) + #(*) +1 = #(x)

Page 14: Induction Proofs

cs466(Prasad) L6Proof 14

Proof Alternatives

sE

sE

sE

n

n

n

:proof based form Sentential

:proof based Sentence

1

Page 15: Induction Proofs

cs466(Prasad) L6Proof 15

• Proof 1: By induction on the length of the derivation of a sentence.

• Basis: n = 1 s = x

0 + 0 + 1 = 1

• Induction Hypothesis:

)( 1 (*)# )(#

)(:

x #www

E k

1 sEsE nn

nk 1

Page 16: Induction Proofs

cs466(Prasad) L6Proof 16

• Induction step: k=n+1

Possible patterns for w

sE n

22

11

2121

2121

**

sE

sE

sssEEE

sssEEE

n

n

n

n

Page 17: Induction Proofs

cs466(Prasad) L6Proof 17

By induction hypothesis:

)( 1 (*)# )(#

)( 1 (*)# )(#

222

111

x #sss

x #sss

)( )(# )(#

)*( (*)# (*)#

)( 1 )(# )(#

For

21

21

21

21

x #sxsxs

#sss

#sss

sss

Page 18: Induction Proofs

cs466(Prasad) L6Proof 18

)(#

)(# )(

1

(*)# (*)#

1 )(# )(#

21

21

21

xs

xsx #s

ss

ss

)( 1 (*)# )(#

:Verify

x #sss

LHS

RHS

Page 19: Induction Proofs

cs466(Prasad) L6Proof 19

By induction hypothesis:

)( 1 (*)# )(#

)( 1 (*)# )(#

222

111

x #sss

x #sss

)( )(# )(#

)*( 1 (*)# (*)#

)( )(# )(#

*For

21

21

21

21

x #sxsxs

#sss

#sss

sss

Page 20: Induction Proofs

cs466(Prasad) L6Proof 20

)(#

)(# )(

1

1 (*)# (*)#

)(# )(#

21

21

21

xs

xsx #s

ss

ss

)( 1 (*)# )(#

:Verify

x #sss

LHS

RHS

Page 21: Induction Proofs

cs466(Prasad) L6Proof 21

• Proof 2: By induction on the length of the derivation of a sentential form.

• Prove the general result

so that the desired result for sentences follows given that

)(# )( 1 (*)# )(#

)(:)( *

Ewx #www

EV

1 uEuE nn

0 )(# : Ew

Page 22: Induction Proofs

cs466(Prasad) L6Proof 22

• Basis: n = 1

w = +EE 1 + 0 + 1 = 0 + 2

w = *EE 0 + 1 + 1 = 0 + 2

w = x 0 + 0 + 1 = 1 + 0

• Induction Hypothesis:

)(# )( 1 (*)# )(#

)(:)(

Ewx #www

EV k

nk 1

Page 23: Induction Proofs

cs466(Prasad) L6Proof 23

• Induction step: k=n+1

• Changes in the counts due to one-step rewrites:

0(*))(

1)( 1)(

:3 Case

... :2 Case

1)((*)

0)()(

* :1 Case

21

21

Ex

xE

EEE

E

x

EEE

uE n

Page 24: Induction Proofs

cs466(Prasad) L6Proof 24

• In each case, the relationship (to be proved) among the counts of +,*, x and E for a sentential form holds. In other words, each rule application to a sentential form preserves this relationship.

• The desired result is obtained by observing that sentences do not contain any variable (non-terminal).

Page 25: Induction Proofs

GENERAL STRATEGY FOR SENTENCE-BASED PROOF

• Variable of Induction: Length of derivation of sentence.

• Induction Hypothesis: Usually the same as the result to be proved.

• Basis Case: Explicitly verify for sentences derivable in (length =) 1 step.

That is, verify for subset of start symbol (LHS) productions that have only terminals on the RHS.

cs466(Prasad) L6Proof 25

Page 26: Induction Proofs

• Induction Step:

• (n+1) steps is divided into 1 step + n steps to create the sub-problems.

• This ensures that sub-problems created using

can use induction hypothesis about

sentences. • The first step must use E-productions with at least

one non-terminal on the RHS. Thus, there are as many cases as there are E-productions with non-terminals on the RHS.

cs466(Prasad) L6Proof 26

sE

sEn

n

1

sn

Page 27: Induction Proofs

GENERAL STRATEGY FOR SENTENTIAL FORM-BASED PROOF

• Variable of Induction: Length of derivation of sentential form.

• Induction Hypothesis: Usually a generalization of the result to be proved, involving non-terminals. (The result about the sentences is a special case

when number of non-terminals is set to 0.)• Basis Case: Explicitly verify for sentential forms

derivable in (length =) 0 steps and 1 step. That is, verify for start symbol S and

all start symbol (LHS) productions.cs466(Prasad) L6Proof 27

Page 28: Induction Proofs

• Induction Step:

• (n+1) steps is divided into n steps + 1 step to create sub-problems.

• The sub-problems created using

can use induction hypothesis about sentential

forms. • The last step can use all productions applicable to

non-terminals in w. So, we need to show that each rule application preserves the induction hypothesis / invariant, e.g., maintain balance of counts.

cs466(Prasad) L6Proof 28

sE

sEn

n

1

nE

Page 29: Induction Proofs

cs466(Prasad) L6Proof 29

Language of Palindromes

A man, a plan, a canal, Panama! Able was I ere I saw Elba.

Rats live on no evil star. He goddam mad dog, eh?

Madam, I'm Adam. A Santa stops pots at NASA.

A Toyota's a Toyota. Tarzan raised a Desi Arnaz rat.

Aibohphobia (The fear

of palindromes!)

Page 30: Induction Proofs

cs466(Prasad) L6Proof 30

)operation. reversal string theis :()

}|{

}1,0{

R

RP

)},|1|0|11|00{

},1,0{},({

SSSS

SG

.)( Prove PGL

Page 31: Induction Proofs

cs466(Prasad) L6Proof 31

PGL )(:Soundness

RnG

R

R

S

nn

S

S

S

n

G

then If

1 :

:s HypothesiInduction

11 : verify 1

00 : verify 0

: verify

1 :Basis

. in sentencea of

derivation theof length theon Induction

R

Page 32: Induction Proofs

cs466(Prasad) L6Proof 32

QED :Hence

)( then If

: of property Using

:hypothesis induction

and assumption freenesscontextBy

11|00 rules where

then If

Show that

:Step Induction

R

11

1

RR

R

Rn

nn

RnG

xuxxuxu u

uuuSxux

u

SSSx

xSxSS

S

Page 33: Induction Proofs

cs466(Prasad) L6Proof 33

PGL )(:Soundness

| |

2 k : :k

:Hypothesis Induction

, where

)( :verify

)( :verify

)( :verify

)S( :verify

: verify

: verify

2,1 :Basis

. in form sententiala of

derivation theof length theon Induction

R2

R2

R2

R

R

uuuxuuSuS

nn

yx

xySyxxySyxxySyxS

xyxxyxxyxS

xxxxxxS

xxxSxxSxS

xxxS

S

n

G

RRRnG

R

n = 2 is redundant.

Palindromic property + Pattern specified

Page 34: Induction Proofs

cs466(Prasad) L6Proof 34

QED . ofproperty theusing

, palindromea is RHS thecase, each In

, where

: rules

: rules

: rule

) | :(

| |

1k for Show that

:Step Induction

*

1

1

1

R

R

R

R

Rk

RRk

RRRnG

xu

xSx S uxSxu

xS uxu

Suu

uSuS

uuxuuSIgnore

xωSωS

n

Page 35: Induction Proofs

cs466(Prasad) L6Proof 35

PGL )( :ness-Complete

}1,0{ {0,1} 0: where

......

: palindrome length oddfor Template

: Approach Informal

i

0110

xaini

aaxaaaas nn x S

SaaSni ii

0, : for

: Algorithm

{0,1} 0: where

......

: palindrome length evenfor Template

: Approach Informal

i

0110

aini

aaaaaas nn

S

SaaSni ii 0, : for

: Algorithm

Page 36: Induction Proofs

cs466(Prasad) L6Proof 36

PGL )(:ness-Complete

then

0)(k if :k

:s HypothesiInduction

1 ,0 1

0 :Basis

. in sentencea of length theon Induction

*

G

R

S

wlen

SS n

Sn

Pn

Page 37: Induction Proofs

cs466(Prasad) L6Proof 37

1. with0 replacing Similarly,

1. withbegins :2 Case

Hence,

0000

:00 withbegins derivationNew

:hypothesis induction By

1k)( 00

0. withbegins :1 Case

1k )(for Show that

:Step Induction

*

G

n

nG

R

G

R

S

uSS

SS

uS

ulenuuu

S

len