Presentation is loading. Please wait.

Presentation is loading. Please wait.

HOW TO BE MORE PRODUCTIVE Graham Hutton and Mauro Jaskelioff.

Similar presentations


Presentation on theme: "HOW TO BE MORE PRODUCTIVE Graham Hutton and Mauro Jaskelioff."— Presentation transcript:

1 HOW TO BE MORE PRODUCTIVE Graham Hutton and Mauro Jaskelioff

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

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

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

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

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

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

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

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

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

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

12 11 Questions zDoes the converse also hold - every function with a unique fixed point is contractive? zWhat does contractive actually mean? zWhat kind of functions are contractive?

13 12 Key Idea If we view a stream as a time-varying value then a function on streams is contractive iff x 0  x 1  x 2  x 3  x 4... Its output value at any time only depends on input values at strictly earlier times.

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

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

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

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

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

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

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

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

22 21 Summary zGenerating functions are a sound and complete representation of contractive functions; zGives a precise characterisation of the class of functions that are contractive; zProvides a simple but rather general means of producing well-defined streams.

23 22 Ongoing and Further Work zGeneralisation to final co-algebras; zOther kinds of generating functions; zRelationship to other techniques; zImproving efficiency.


Download ppt "HOW TO BE MORE PRODUCTIVE Graham Hutton and Mauro Jaskelioff."

Similar presentations


Ads by Google