1 / 23

HOW TO BE MORE PRODUCTIVE

HOW TO BE MORE PRODUCTIVE. Graham Hutton and Mauro Jaskelioff. Streams. A stream is an infinite sequence of values:. 0  1  2  3  4. The type of streams is co-inductively defined:. codata Stream A = A  Stream A. Defining Streams.

acarr
Download Presentation

HOW TO BE MORE PRODUCTIVE

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. HOW TO BE MORE PRODUCTIVE Graham Hutton and Mauro Jaskelioff

  2. Streams A stream is an infinite sequence of values: 0  1  2  3 4 ... The type of streams is co-inductively defined: codata Stream A = A  Stream A

  3. Defining Streams Streams can be defined by recursive equations: ones :: Stream Nat ones = 1  ones nats :: Stream Nat nats = 0  map (+1) nats

  4. This Talk • How do we ensure such equations make sense, i.e. that they produce well-defined streams? loop :: Stream A loop = tail loop • A new approach, based upon a representation theorem for contractive functions.

  5. Fixed Points The starting point for our approach is the use of explicit fixed points. For example: ones = 1  ones can be rewritten as: ones = fix body body xs = 1  xs fix f = f (fix f)

  6. The Problem Given a function on streams f :: Stream A  Stream A when does fix f :: Stream A makes sense, i.e. produce a well-defined stream?

  7. Contractive Functions Adapting an idea from topology, let us say that a function f on streams is contractive iff: xs =n ys f xs =n+1 f ys Equal for the first n elements. Equal for one further element.

  8. Banach’s Theorem Every contractive function f :: Stream A cStream A has a unique fixed point fix f :: Stream A and hence produces a well-defined stream.

  9. This theorem provides a semantic means of ensuring that stream definitions are valid.

  10. Example The function (1 ) is contractive: 1  xs =n+1 1  ys xs =n ys Hence, it has a unique fixed point, and ones = fix (1 ) is a valid definition for a stream.

  11. Example The function tail is not contractive: tail xs =n+1 tail ys xs =n ys Hence, Banach’s theorem does not apply, and loop = fix tail is rejected as an invalid definition.

  12. Questions • Does the converse also hold - every function with a unique fixed point is contractive? • What does contractive actually mean? • What kind of functions are contractive?

  13. Key Idea If we view a stream as a time-varying value x0 x1 x2 x3  x4... then a function on streams is contractive iff Its output value at any time only depends on input values at strictly earlier times.

  14. This result simplifies the process of deciding if a function is contractive.

  15. Examples Each output depends on the input one step earlier in time. (1 ) Each output depends on the input one step later in time. tail

  16. Generating Functions This idea is formalised using generating functions, which map finite lists to single values: [A]  B The next output value. All earlier input values.

  17. Representation Theorem Every contractive function can be represented by a generating function, and vice versa: rep Stream A cStream B [A]  B gen Moreover, rep and gen form an isomorphism.

  18. This theorem provides a practical means of producing streams that are well-defined.

  19. Example g :: [Nat]  Nat g [] = 1 g (x:xs) = x Generator for ones. Guaranteed to be well-defined. ones :: Stream Nat ones = fix (gen g)

  20. Example g :: [Nat]  Nat g [] = 0 g (x:xs) = x+1 Generator for nats. Guaranteed to be well-defined. nats :: Stream Nat nats = fix (gen g)

  21. Example g :: [Nat]  Nat g [] = 0 g [x] = 1 g (x:y:xs) = x+y Generator for fibs. Guaranteed to be well-defined. fibs :: Stream Nat fibs = fix (gen g)

  22. Summary • Generating functions are a sound and complete representation of contractive functions; • Gives a precise characterisation of the class of functions that are contractive; • Provides a simple but rather general means of producing well-defined streams.

  23. Ongoing and Further Work • Generalisation to final co-algebras; • Other kinds of generating functions; • Relationship to other techniques; • Improving efficiency.

More Related