Functional Programming Lecture 13 - induction on lists - PowerPoint PPT Presentation

About This Presentation
Title:

Functional Programming Lecture 13 - induction on lists

Description:

Functional Programming Lecture 13 induction on lists – PowerPoint PPT presentation

Number of Views:19
Avg rating:3.0/5.0
Slides: 13
Provided by: muffyc
Category:

less

Transcript and Presenter's Notes

Title: Functional Programming Lecture 13 - induction on lists


1
Functional ProgrammingLecture 13 - induction
on lists
2
Proof by induction on Nat
  • Nat is an inductively defined set
  • base case 0 Nat,
  • ind. case if n Nat, then n1 Nat.
  • extremal nothing else belongs to Nat.
  • To prove a property of Nat, P(x), we use the
    Principle of Induction
  • base case prove P(0),
  • ind. case Prove P(n1), assuming P(n).

3
Proof by induction on Lists
  • Lists are inductively defined sets
  • base case a,
  • ind. case if xs a, and xa, then
    (xxs) a.
  • extremal nothing else belongs to a.
  • To prove a property of a, P(xs), we use the
    Principle of (Structural) Induction
  • base case prove P(),
  • ind. case Prove P(xxs), assuming P(xs).
  • The format of the proof is extremely important.
    Best illustrated by examples.

4
  • sumlist 0 s.0
  • sumlist (xxs) x sumlist xs s.1
  • double d.0
  • double (xxs) (2x) double xs d.1
  • Theorem For all finite xs.
  • sumlist (double xs) 2 (sumlist xs)
  • Proof By induction on xs.
  • Base Case Prove sumlist (double ) 2
    (sumlist ).
  • l.h.s. sumlist (double ) sumlist by
    d.0
  • 0
    by s.0
  • r.h.s. 2 (sumlist ) 2 0
    by s.0
  • 0
    by arith.
  • Ind Case Assume sumlist (double xs ) 2
    (sumlist xs). Prove sumlist (double xxs ) 2
    (sumlist xxs).
  • l.h.s. sumlist (double xxs )
  • sumlist ((2x) double xs)
    by d.1
  • (2x) sumlist (double xs)
    by s.1

5
Important Points
  • Justify every step.
  • Clearly state assumption.
  • If you do not use the assumption in a step, then
    you are not doing a proof by induction!
  • Work on the l.h.s., or the r.h.s., or both.

6
  • xs xs
    .0
  • xxs ys x(xs ys) .1
  • Theorem For all finite xs. xs xs.
  • ( is a right identity for )
  • Proof By induction on xs.
  • Base Case Prove .
  • l.h.s.
    by .0
  • Ind Case Assume xs xs.
  • Prove xxs xxs.
  • l.h.s. xxs
  • x(xs )
    by .1
  • xxs
    by ass.
  • QED

7
  • xs xs
    .0
  • xxs ys x(xs ys) .1
  • Theorem For all finite xs,yz,zs.
  • xs (ys zs) (xs ys) zs
  • ( is associative)
  • Proof By induction on xs.
  • Base Case Prove (ys zs) ( ys)
    zs
  • l.h.s. (ys zs) ys zs
    by .0
  • ( ys)
    zs by .0
  • Ind Case Assume xs (ys zs) (xs ys)
    zs
  • Prove xxs (ys zs) (xxs ys) zs
  • l.h.s. xxs (ys zs) x(xs (yszs))
    by .1
  • x((xs ys)zs)
    by ass.
  • x(xsys) zs
    by .1
  • (xxs ys) zs
    by .1

8
  • member String -gt Char -gt Bool
  • member y False
    m.0
  • member (xxs) y (xy) member xs y
    m.1
  • False x x
    or.0
  • True x True
    or.1

9
  • Theorem For all finite xs, ys, and elements z.
  • member (xs ys ) z member xs z member ys
    z.
  • Proof By induction on xs.
  • Base Case Prove
  • member ( ys ) z member z member ys
    z.
  • l.h.s. member ( ys ) z member ys z by
    .0
  • r.h.s. member z member ys z
  • False member ys z
    by m.1
  • member ys z
    by or.0
  • Ind Case Assume member (xs ys ) z member xs
    z member ys z. Prove
  • member (xxs ys ) z member (xxs) z
    member ys z.
  • l.h.s. member (xxs ys ) z
  • member (x(xs ys))z
    by .1

10
An Exercise
  • prove that is associative.
  • Question Why dont we need induction?

11
  • rev
    rev.0
  • rev xxs rev xs x rev.
    1
  • Theorem For all finite xs. rev (rev xs) xs
  • Proof By induction on xs.
  • Base Case Prove rev (rev )
  • l.h.s. rev (rev ) rev
    by rev.0

  • by rev.0
  • Ind Case Assume rev (rev xs) xs. Prove
  • rev (rev xxs) xxs.
  • l.h.s. rev (rev xxs) rev (rev xs x)
    by rev.1
  • rev (x) rev
    (rev xs) by ??

12
  • rev
    rev.0
  • rev xxs rev xs x rev.
    1
  • Theorem For all finite xs,ys.
  • rev (xs ys) (rev ys) (rev xs)
  • Proof By induction on xs.
  • Base Case Prove rev ( ys) (rev )
    (rev ys).
  • l.h.s. rev ( ys) rev ys
    by .0
  • rev ys
    by .0
  • (rev ) (rev
    ys) by rev.0
  • Ind Case Assume rev (xs ys) (rev ys) (rev
    xs).
  • Prove rev (xxs ys) (rev ys) (rev xxs).
  • l.h.s. rev (xxs ys) rev (x(xsys))
    by .1
  • rev(xsys) x
    by rev.1
Write a Comment
User Comments (0)
About PowerShow.com