CIS 500 Software Foundations Fall 2004 Reasoning about evaluation More on induction CIS 500, More on induction 1 CIS 500, More on induction 2 Induction principles We ve seen three definitions of sets their associated induction principles: Ordinary natural numbers Boolean terms Arithmetic terms GivenasetdefinedinBNFnotation,itisnottoohardtodescribethe structural induction principle for that set For example: More induction principles However, these are not the only sets that we ve defined inductively so far We defined the semantics of the boolean arithmetic languages using inductively defined relations ie, inductively defined sets of pairs(of terms) These sets also have induction principles What is the structural induction principle for this language? CIS 500, More on induction 3 CIS 500, More on induction 4
Induction on evaluation We can define an induction principle for small-step evaluation Recall the definition(just for booleans, for now): E-IFTRUE E-IFFALSE E-IF Induction on evaluation Induction principle for the evaluation relation: Suppose Ifwecanshow with isapropertyofpairsofterms, thenwemayconcludethat,,, such that, What is the induction principle for this relation? CIS 500, More on induction 5 CIS 500, More on induction 6 Sayingthat Derivations Another way to look at induction on evaluation is in terms of derivations A derivation records the justification for a particular pair of terms that areintheevaluationrelation,intheformofatree We vealreadyseen oneexampleontheboardlasttime Terminology: These trees are called derivation trees(or just derivations) The final statement in a derivation tree is its conclusion Wesaythataderivationisproofofitsconclusion(orawitnessforits conclusion) it records the reasoning steps that justify the conclusion (ie, thepair isintherelation )is equivalenttosaying thereexistsanevaluationderivation whose conclusion is CIS 500, More on induction 7 Observation Lemma: Supposewearegivenaderivation witnessing the pair inthe relation Then exactly one of the following holds: 1 thefinalruleusedin for some 2thefinalruleusedin is E-IFTRUE ;or is E-IFFALSE for some 3thefinalruleusedin ise-if,forsome immediatesubderivationof witnesses ;or ; moreover the CIS 500, More on induction 8
Induction on Derivations We can now write proofs about evaluation by induction on derivation trees Givenanarbitraryderivation with conclusion,weassumethe desiredproperty for its immediate sub-derivations(if any) try to showthat holdsfor itself, using a case analysis(applying the previous lemma) of the final evaluation rule used in constructing the derivation tree Eg Induction on small-step evaluation For example, let us show that small-step evaluation is deterministic Theorem: If then roof: Byinductiononaderivation of (Check: exactly what is here?) 1 Supposethefinalruleusedin is E-IfTrue, with Thenthelast rule of the derivation of cannot be E-IfFalse, because isnot Furthermore, the last rule cannot be E-If either, because this rule requires that, doesnotsteptoanything So thelastrulecanonlybee-iftrue, 2Supposethefinalruleusedin is E-IFFALSE, with Thiscaseissimilartothe previous CIS 500, More on induction 9 CIS 500, More on induction 10 3Supposethefinalruleusedin is E-IF, with,where iswitnessedbyaderivation Thelastruleinthe derivation of canonlybee-if,soitmustbethat By the inductive hypothesis,, fromwhichweconclude What principle to use? We ve proven the same theorem using two different induction principles Q:Whichoneisthebestonetouseinagivencase? A:Theonethatworksinthatcase! For these simple languages, anything you can prove by induction on derivations of,youcanalsoprovebystructuralinductionon Butthatwillnotbethecaseforeverylanguage CIS 500, More on induction 11 CIS 500, More on induction 12
AScepticAsks Well-founded induction Question: Why are any of these induction principles true? Why should I believe a proof that employs one? Answer: These are all instances of a general principle called well-founded induction CIS 500, More on induction 13 CIS 500, More on induction 14 Well-founded induction Well-founded induction Let beawell-foundedrelationonaset letbeaproperty If Forexample,welet def Inthiscase,we can rewrite previous principle as: then If Choosingtheset relation determines the induction principle then Now,bydefinition is either or for some : If then Or, simplifying: If then CIS 500, More on induction 15 CIS 500, More on induction 16
Strong induction Ifwetake to be the strictly less than relation on natural numbers, then the principle we get is strong(or complete ) induction: If then Well-founded relation The induction principle holds only when the relation Definition: A well-founded relation is a binary relation that there are no infinite descending chains Are the successor relations well-founded? is well-founded onaset such CIS 500, More on induction 17 CIS 500, More on induction 18 Now,suppose Theorem: Let property Then roof: The( Validity of well-founded induction isawell-foundedrelationonaset iff )directionistrivial We llshowthe( Letbea ) direction First,observethatanynonemptysubsetQofAhasaminimalelement, evenifqisinfinite oftheset is a contradiction forsome Butthen, in Theremustbeaminimalelement yet which Structural induction Well-founded induction also generalizes structural induction If is the immediate subterm relation, then the principle we get is structural induction for terms For example, in Arith, the term Is the immediate subterm relation well-founded? Yes,sincealltermsofAritharefinite isanimmediatesubtermoftheterm CIS 500, More on induction 19 CIS 500, More on induction 20
Mathematical Digression If you want to understn the full story about induction inductively know defined relations, check out the beginning of Chapter 21 in TAL Termination of evaluation CIS 500, More on induction 21 CIS 500, More on induction 22 Termination of evaluation An Inductive Definition of a Function Theorem: For every there is some normal form such that Wecefinetheofatermwiththefollowingrelation: Howcanweproveit?? Note: thisisyetmoreshorth Howwouldwewritethisdefinitionwith inference rules? CIS 500, More on induction 23 CIS 500, More on induction 24
Theorem: If Induction on Derivations Another Example,then roof: Byinductiononaderivation of 1 Supposethefinalruleusedin is E-IFTRUE, with Thentheresultisimmediate from the definition of 2Supposethefinalruleusedin is E-IFFALSE, with Thentheresultisagain immediate from the definition of 3Supposethefinalruleusedin is E-IF, with,where iswitnessedbyaderivation Bytheinduction Butthen,bythedefinitionof,we hypothesis, have Theorem: For every roof: Termination of evaluation there is some normal form such that First, recall that single-step evaluation strictly reduces the of the term: if,then Now, assume(for a contradiction) that is an infinite-length sequence such that Then is an infinite, strictly decreasing, sequence of natural numbers But such a sequence cannot exist contradiction!, CIS 500, More on induction 25 CIS 500, More on induction 26 Termination roofs Most termination proofs have the same basic form: Theorem: Therelation noinfinitesequences,,,etc suchthat each roof: 1 Choose 2 Show is terminating ie, there are for a well-founded set ie,aset with a partial order such that there are no infinite descending chains in afunction from to 3 Concludethattherearenoinfinitesequences,,,etc such that for each,since,iftherewere,we couldconstructaninfinitedescendingchainin CIS 500, More on induction 27