Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Class 16

Avatar for Mohammad Mahmoody Mohammad Mahmoody
October 19, 2017
7.9k

Class 16

Structural Induction

Avatar for Mohammad Mahmoody

Mohammad Mahmoody

October 19, 2017
Tweet

Transcript

  1. Defining List Definition 1. A List is an ordered sequence

    of objects. Definition 2. A List is either: (1) the empty list or (2) and object followed by another list ′. Are these equivalent definitions?
  2. Defining them Using Base and Constructor empty null ⟶ empty

    prepend (, ) ⟶ first prepend (, ) ⟶ rest prepend (, ) ⟶
  3. Length of a List Definition. The length of a list,

    , is: 0 : if is null 1 + length : if = prepend , 10
  4. Concatenation: Descriptive Def Definition. The concatenation of two lists, =

    1 , 2 , … , and = 1 , 2 , … , is 1 , 2 , … , , 1 , 2 , … , . How can we define this constructively? 12
  5. Concatenation Definition. The concatenation of two lists, = 1 ,

    2 , … , and = 1 , 2 , … , is 1 , 2 , … , , 1 , 2 , … , . How can we define this constructively? Also: Any questions about definitions so far, recursive data, etc. 13
  6. Concatenation: Descriptive Def Definition. The concatenation of two lists, =

    1 , 2 , … , and = 1 , 2 , … , is 1 , 2 , … , , 1 , 2 , … , . How can we define this constructively? 14 Suggestion: Define p+q ::= Prepend(p,q) Why does not work: then first(p+q) would be p not 1 Another reason this is not a good idea to define concatenation: We might define Lists of “restricted objects” (e.g. integers) in which case Prepend(e,q) only accepts “e” to be in restricted form (not including lists)
  7. Concatenation: Constructive Def Definition. The concatenation ( + ) of

    two lists, and , is recursively defined as: Base case: if = (empty list) then + = Constructor case: if = prepend(, ) for some list , obj then + = prepend(, + ) 15
  8. Did we define length and concatenation properly? Prove. For any

    two lists, and , length( + ) = length() + length() 16
  9. Structural Induction To prove for all List 1. Prove for

    all base list . 2. Prove ⇒ for all constructable from . 17
  10. Prove. For any two lists, and , length( + )

    = length() + length() Base case: = (empty list) + = Constructor case: = prepend (, ) + = prepend (, + ) 18 Proposition F(p) for any list p : F(p) : ∀ ∈ . length( + ) = length() + length()
  11. Structural Induction (Data Types) Invariant Principle (State Machines) (Regular) Induction

    (Natural Numbers) for all data type objects for all reachable states To prove ∙ for all natural numbers prove a base case 0 0 base object prove an inductive step ⇒ ( + 1) ⇒ for all constructable from ⇒ for all reachable from 19
  12. Charge Next week: Infinite sets and cardinalities.. Problem Set 6

    due tomorrow (make sure to read the updated problem 7) Problem set 7 posted tomorrow night (or Sat morning) – read chapter 7 + notes/slides of this weak