Reasoning about Codata Ralf Hinze Computing Laboratory, University - - PowerPoint PPT Presentation

reasoning about codata
SMART_READER_LITE
LIVE PREVIEW

Reasoning about Codata Ralf Hinze Computing Laboratory, University - - PowerPoint PPT Presentation

Reasoning about Codata 0.0 Reasoning about Codata Ralf Hinze Computing Laboratory, University of Oxford Wolfson Building, Parks Road, Oxford, OX1 3QD, England ralf.hinze@comlab.ox.ac.uk http://www.comlab.ox.ac.uk/ralf.hinze/ May 2009


slide-1
SLIDE 1

Reasoning about Codata 0.0

Reasoning about Codata

Ralf Hinze

Computing Laboratory, University of Oxford Wolfson Building, Parks Road, Oxford, OX1 3QD, England ralf.hinze@comlab.ox.ac.uk http://www.comlab.ox.ac.uk/ralf.hinze/

May 2009

University of Oxford — Ralf Hinze 1-138

slide-2
SLIDE 2

Reasoning about Codata 1.0

Part 1 Prologue

University of Oxford — Ralf Hinze 2-138

slide-3
SLIDE 3

Reasoning about Codata 1.0

1.0 Outline

  • 1. What?
  • 2. Why?
  • 3. Where?
  • 4. Overview

University of Oxford — Ralf Hinze 3-138

slide-4
SLIDE 4

Reasoning about Codata 1.1

1.1 What is codata?

  • The dual of data, with an emphasis
  • on observation rather than construction,
  • process rather than value, and
  • the indefinite rather than the finite.

University of Oxford — Ralf Hinze 4-138

slide-5
SLIDE 5

Reasoning about Codata 1.2

1.2 For the mathematician . . .

  • More elegant proofs through . . .
  • a holistic or wholemeal approach,
  • avoidance of index variables and subscripts,
  • avoidance of case analysis,
  • a compositional approach.

University of Oxford — Ralf Hinze 5-138

slide-6
SLIDE 6

Reasoning about Codata 1.2

1.2 For the programmer . . .

  • More elegant programs through . . .
  • a holistic or wholemeal approach,
  • avoidance of case analysis,
  • a compositional approach,
  • separation of concerns: production and termination.

See also John Hughes’ “Why Functional Programming Matters”.

University of Oxford — Ralf Hinze 6-138

slide-7
SLIDE 7

Reasoning about Codata 1.3

1.3 References

  • J.J.M.M. Rutten. “Fundamental study — Behavioural differential

equations: a coinductive calculus of streams, automata, and power series.” Theoretical Computer Science, (308):1–53, 2003.

  • J.J.M.M. Rutten. “A coinductive calculus of streams”. Math. Struct.

in Comp. Science, (15):93–147, 2005.

  • Ralf Hinze. “Functional Pearl: Streams and Unique Fixed Points”. In

Peter Thiemann, editor, Proceedings of the 13th ACM Sigplan International Conference on Functional Programming (ICFP’08), September 22–24, 2008, Victoria, BC, Canada, pages 189–200. ACM Press, 2008.

  • Ralf Hinze. “Scans and Convolutions — A Calculational Proof of

Moessner’s Theorem”. In Sven-Bodo Scholz, editor, Post-Proceedings

  • f the 20th International Symposium on the Implementation and

Application of Functional Languages (IFL’08), September 10–12, 2008, Hertfordshire, UK, to appear.

University of Oxford — Ralf Hinze 7-138

slide-8
SLIDE 8

Reasoning about Codata 1.4

1.4 Overview

  • Part 1: Prologue
  • Part 2: Streams
  • Part 3: Recurrences
  • Part 4: Finite Calculus
  • Part 5: Infinite Trees
  • Part 6: Tabulation
  • Part 7: Epilogue

University of Oxford — Ralf Hinze 8-138

slide-9
SLIDE 9

Reasoning about Codata 2.0

Part 2 Streams

University of Oxford — Ralf Hinze 9-138

slide-10
SLIDE 10

Reasoning about Codata 2.0

2.0 Outline

  • 5. Streams
  • 6. Idioms
  • 7. Interleaving
  • 8. Recursion and iteration
  • 9. Laws
  • 10. Proofs

University of Oxford — Ralf Hinze 10-138

slide-11
SLIDE 11

Reasoning about Codata 2.1

2.1 Streams

0, 1, 8, 27, 64, 125, 216, 343, 512, 729, 1000, 1331, . . . 1, 3, 9, 27, 81, 243, 729, 2187, 6561, 19683, 59049, . . . 0, 0, 1, 1, 2, 4, 3, 9, 4, 16, 5, 25, 6, 36, 7, 49, . . . 0, 0, 2, 4, 8, 14, 24, 40, 66, 108, 176, 286, 464, 752, . . . 0, 1, 2, 6, 15, 40, 104, 273, 714, 1870, 4895, 12816, . . .

University of Oxford — Ralf Hinze 11-138

slide-12
SLIDE 12

Reasoning about Codata 2.1

2.1 Datatype of streams

data Stream α = Cons {head :: α, tail :: Stream α} infixr 5 ≺ (≺) :: α → Stream α → Stream α a ≺ s = Cons a s

University of Oxford — Ralf Hinze 12-138

slide-13
SLIDE 13

Reasoning about Codata 2.1

2.1 Fibonacci numbers

fib = 0 ≺ fib + (1 ≺ fib)

University of Oxford — Ralf Hinze 13-138

slide-14
SLIDE 14

Reasoning about Codata 2.1

1 1 2 3 5 8 13 21 34 · · · fib + + + + + + + + + + · · · + 1 1 1 2 3 5 8 13 21 · · · ≺ 1 ≺ fib = = = = = = = = = = = · · · = 1 1 2 3 5 8 13 21 34 55 · · · fib

University of Oxford — Ralf Hinze 14-138

slide-15
SLIDE 15

Reasoning about Codata 2.2

2.2 Idioms or applicative functors

class Idiom φ where pure :: α → φ α (⋄) :: φ (α → β) → (φ α → φ β)

University of Oxford — Ralf Hinze 15-138

slide-16
SLIDE 16

Reasoning about Codata 2.2

2.2 Streams are an idiom

instance Idiom Stream where pure a = s where s = a ≺ s s ⋄ t = (head s) (head t) ≺ (tail s) ⋄ (tail t)

University of Oxford — Ralf Hinze 16-138

slide-17
SLIDE 17

Reasoning about Codata 2.2

2.2 Lifting

repeat :: (Idiom φ) ⇒ α → φ α repeat a = pure a map :: (Idiom φ) ⇒ (α → β) → (φ α → φ β) map f s = pure f ⋄ s zip :: (Idiom φ) ⇒ (α → β → γ) → (φ α → φ β → φ γ) zip g s t = pure g ⋄ s ⋄ t

University of Oxford — Ralf Hinze 17-138

slide-18
SLIDE 18

Reasoning about Codata 2.2

2.2 Arithmetic: a generic Num instance

instance (Idiom φ, Num α) ⇒ Num (φ α) where (+) = zip (+) (−) = zip (−) (∗ ) = zip (∗ ) negate = map negate

  • - unary minus

fromInteger i = repeat (fromInteger i)

University of Oxford — Ralf Hinze 18-138

slide-19
SLIDE 19

Reasoning about Codata 2.2

2.2 Natural numbers

nat = 0 ≺ nat + 1

University of Oxford — Ralf Hinze 19-138

slide-20
SLIDE 20

Reasoning about Codata 2.2

2.2 Natural numbers

nat = 0 ≺ nat + 1 nat = 0 ≺ pure (+) ⋄ nat ⋄ pure 1 nat = 0 ≺ map (1+) nat

University of Oxford — Ralf Hinze 20-138

slide-21
SLIDE 21

Reasoning about Codata 2.2

1 2 3 4 5 6 7 8 9 · · · nat + + + + + + + + + + · · · + 1 1 1 1 1 1 1 1 1 1 · · · ≺ 1 = = = = = = = = = = = · · · = 1 2 3 4 5 6 7 8 9 10 · · · nat

University of Oxford — Ralf Hinze 21-138

slide-22
SLIDE 22

Reasoning about Codata 2.2

2.2 Interactive session

≫ fib 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, . . . ≫ nat ∗ nat 0, 1, 4, 9, 16, 25, 36, 49, 64, 81, . . . ≫ fib′2 − fib ∗ fib′′ 1, −1, 1, −1, 1, −1, 1, −1, 1, −1, . . . ≫ fib′2 − fib ∗ fib′′ (−1)nat True ≫ nat2 0, 1, 4, 9, 16, 25, 36, 49, 64, 81, . . .

University of Oxford — Ralf Hinze 22-138

slide-23
SLIDE 23

Reasoning about Codata 2.3

2.3 Interleaving

infixr 5 () :: Stream α → Stream α → Stream α s t = head s ≺ t tail s

University of Oxford — Ralf Hinze 23-138

slide-24
SLIDE 24

Reasoning about Codata 2.3

2.3 Binary numbers

bin = 0 ≺ 2 ∗ bin + 1 2 ∗ bin + 2

University of Oxford — Ralf Hinze 24-138

slide-25
SLIDE 25

Reasoning about Codata 2.3

nat = bin ?

University of Oxford — Ralf Hinze 25-138

slide-26
SLIDE 26

Reasoning about Codata 2.4

2.4 Recursion and iteration

recurse :: (α → α) → (α → Stream α) recurse f a = s where s = a ≺ map f s iterate :: (α → α) → (α → Stream α) iterate f a = loop a where loop x = x ≺ loop (f x)

University of Oxford — Ralf Hinze 26-138

slide-27
SLIDE 27

Reasoning about Codata 2.5

2.5 Idiom laws

pure id ⋄ u = u (identity) pure (·) ⋄ u ⋄ v ⋄ w = u ⋄ (v ⋄ w) (composition) pure f ⋄ pure x = pure (f x) (homomorphism) u ⋄ pure x = pure (λf → f x) ⋄ u (interchange)

University of Oxford — Ralf Hinze 27-138

slide-28
SLIDE 28

Reasoning about Codata 2.5

2.5 Functor laws

map id = id map (f · g) = map f · map g

University of Oxford — Ralf Hinze 28-138

slide-29
SLIDE 29

Reasoning about Codata 2.5

2.5 Proof: nat + 1 = map (1+) nat

nat + 1 = { definition of + and fromInteger } zip (+) nat (pure 1) = { definition of zip } pure (+) ⋄ nat ⋄ pure 1 = { Exercise 1.4 } pure (+) ⋄ pure 1 ⋄ nat = { homomorphism law } pure (1+) ⋄ nat = { definition of map } map (1+) nat

University of Oxford — Ralf Hinze 29-138

slide-30
SLIDE 30

Reasoning about Codata 2.5

2.5 Lifting Lemma

Since the operations are lifted pointwise to streams, all the point-level identities hold for streams, as well.

University of Oxford — Ralf Hinze 30-138

slide-31
SLIDE 31

Reasoning about Codata 2.5

2.5 Interleaving

pure a pure a = pure a (s1 ⋄ s2) (t1 ⋄ t2) = (s1 t1) ⋄ (s2 t2)

University of Oxford — Ralf Hinze 31-138

slide-32
SLIDE 32

Reasoning about Codata 2.5

2.5 Abide law: geometrical interpretation

s1 ⋄ s2

  • t1

⋄ t2 = s1 s2

  • t1

t2

University of Oxford — Ralf Hinze 32-138

slide-33
SLIDE 33

Reasoning about Codata 2.5

2.5 Recursion and iteration: fusion

map h · recurse f1 = recurse f2 · h ⇑ h · f1 = f2 · h ⇓ map h · iterate f1 = iterate f2 · h

University of Oxford — Ralf Hinze 33-138

slide-34
SLIDE 34

Reasoning about Codata 2.5

2.5 Recursion-iteration lemma

recurse f a = iterate f a

University of Oxford — Ralf Hinze 34-138

slide-35
SLIDE 35

Reasoning about Codata 2.6

2.6 Admissible equations

  • Consider the equations

s1 = tail s1 s2 = head s2 ≺ tail s2

  • Both s1 and s2 loop in Haskell; viewed as stream equations

they are ambiguous.

  • An admissible equation has the form

x x1 . . . xn = h ≺ t .

  • The projection functions head and tail may only be applied

to the arguments of x: head xi or tail xi.

University of Oxford — Ralf Hinze 35-138

slide-36
SLIDE 36

Reasoning about Codata 2.6

2.6 Unique solutions: fix φ = x

  • Let s = φ s be an admissible equation.
  • It has a unique solution, denoted by fix φ.
  • Universal property:

fix φ = x ⇐ ⇒ x = φ x

University of Oxford — Ralf Hinze 36-138

slide-37
SLIDE 37

Reasoning about Codata 2.6

2.6 Example: nat = 2 ∗ nat 2 ∗ nat + 1

2 ∗ nat 2 ∗ nat + 1 = { definition of nat } 2 ∗ (0 ≺ nat + 1) 2 ∗ nat + 1 = { arithmetic } (0 ≺ 2 ∗ nat + 2) 2 ∗ nat + 1 = { definition of } 0 ≺ 2 ∗ nat + 1 2 ∗ nat + 2 = { arithmetic } 0 ≺ (2 ∗ nat 2 ∗ nat + 1) + 1

University of Oxford — Ralf Hinze 37-138

slide-38
SLIDE 38

Reasoning about Codata 2.6

2.6 Unique solutions: fix φ = fix ψ

  • Let s = φ s and t = ψ t be admissible equations.
  • To prove s = t there are at least four possibilities:

φ (ψ s) = ψ s = ⇒ ψ s = s = ⇒ s = t ψ (φ t) = φ t = ⇒ φ t = t = ⇒ s = t

  • Unfortunately, there is no success guarantee.

University of Oxford — Ralf Hinze 38-138

slide-39
SLIDE 39

Reasoning about Codata 2.6

2.6 ⊂-proofs

s = { why? } χ s ⊂ { x = χ x has a unique solution } χ t = { why? } t

University of Oxford — Ralf Hinze 39-138

slide-40
SLIDE 40

Reasoning about Codata 2.6

2.6 Proof: Cassini’s identity

fib′2 − fib ∗ fib′′ = { definition of fib′′ and arithmetic } fib′2 − (fib ∗ fib′ + fib2) = { definition of fib and fib′ } 1 ≺ (fib′′2 − (fib′ ∗ fib′′ + fib′2)) = { fib′′ − fib′ = fib and arithmetic } 1 ≺ (−1) ∗ (fib′2 − fib ∗ fib′′) ⊂ { x = 1 ≺ (−1) ∗ x has a unique solution } 1 ≺ (−1) ∗ (−1)nat = { definition of nat and arithmetic } (−1)nat

University of Oxford — Ralf Hinze 40-138

slide-41
SLIDE 41

Reasoning about Codata 2.6

2.6 Proof: iterate fusion

map h (iterate f1 a) = { definition of iterate and map } h a ≺ map h (iterate f1 (f1 a)) ⊂ { x a = h a ≺ x (f1 a) has a unique solution } h a ≺ iterate f2 (h (f1 a)) = { assumption: h · f1 = f2 · h } h a ≺ iterate f2 (f2 (h a)) = { definition of iterate } iterate f2 (h a)

University of Oxford — Ralf Hinze 41-138

slide-42
SLIDE 42

Reasoning about Codata 2.6

2.6 Proof: recursion-iteration lemma

We show that iterate f a is the unique solution of x = a ≺ map f x. iterate f a = { definition of iterate } a ≺ iterate f (f a) = { iterate fusion law: h = f1 = f2 = f } a ≺ map f (iterate f a) Consequently, nat = iterate (1+) 0.

University of Oxford — Ralf Hinze 42-138

slide-43
SLIDE 43

Reasoning about Codata 2.6

2.6 Summary

  • Stream is a co-inductive datatype.
  • Stream is an idiom.
  • Recursion and iteration.
  • Admissible equations have unique solutions.

University of Oxford — Ralf Hinze 43-138

slide-44
SLIDE 44

Reasoning about Codata 3.0

Part 3 Recurrences

University of Oxford — Ralf Hinze 44-138

slide-45
SLIDE 45

Reasoning about Codata 3.0

3.0 Outline

  • 11. Tabulation
  • 12. Idiom homomorphisms
  • 13. Bit-fiddling

University of Oxford — Ralf Hinze 45-138

slide-46
SLIDE 46

Reasoning about Codata 3.1

3.1 Example: tower of Hanoï

T0 = 0 Tn+1 = 2 ∗ Tn + 1 t = 0 ≺ 2 ∗ t + 1

University of Oxford — Ralf Hinze 46-138

slide-47
SLIDE 47

Reasoning about Codata 3.1

3.1 Recurrences as streams

F0 = k Fn+1 = f (Fn) s = k ≺ map f s

University of Oxford — Ralf Hinze 47-138

slide-48
SLIDE 48

Reasoning about Codata 3.1

3.1 A one-to-one correspondence

Stream α ∼ = Nat → α

University of Oxford — Ralf Hinze 48-138

slide-49
SLIDE 49

Reasoning about Codata 3.1

3.1 Tabulation

data Nat = 0 | Nat + 1 tabulate :: (Nat → α) → Stream α tabulate f = f 0 ≺ tabulate (f · (+1)) lookup :: Stream α → (Nat → α) lookup s 0 = head s lookup s (n + 1) = lookup (tail s) n

  • NB. tabulate and lookup are natural transformations.

University of Oxford — Ralf Hinze 49-138

slide-50
SLIDE 50

Reasoning about Codata 3.1

3.1 Laws: naturality properties

map f · tabulate = tabulate · (f ·) (f ·) · lookup = lookup · map f

  • NB. (f ·) is the mapping function of the functor α →.

map f (tabulate g) = tabulate (f · g) f · lookup t = lookup (map f t)

University of Oxford — Ralf Hinze 50-138

slide-51
SLIDE 51

Reasoning about Codata 3.1

3.1 Laws: isomorphisms

lookup · tabulate = id tabulate · lookup = id

University of Oxford — Ralf Hinze 51-138

slide-52
SLIDE 52

Reasoning about Codata 3.1

3.1 Reminder: initial algebras

fold :: (α → α) → α → (Nat → α) fold s z 0 = z fold s z (n + 1) = s (fold s z n)

University of Oxford — Ralf Hinze 52-138

slide-53
SLIDE 53

Reasoning about Codata 3.1

3.1 Reminder: universal property of fold

h = fold s z ⇐ ⇒ h 0 = z ∧ h · (+1) = s · h

University of Oxford — Ralf Hinze 53-138

slide-54
SLIDE 54

Reasoning about Codata 3.1

3.1 Proof: tabulate (fold s z) = iterate s z

tabulate (fold s z) = { definition of tabulate } fold s z 0 ≺ tabulate (fold s z · (+1)) = { computation rules: fold s z 0 = z and fold s z · (+1) = s · fold s z } z ≺ tabulate (s · fold s z) = { naturality of tabulate } z ≺ map s (tabulate (fold s z))

University of Oxford — Ralf Hinze 54-138

slide-55
SLIDE 55

Reasoning about Codata 3.1

3.1 Proof: tabulate id = nat

tabulate id = { reflection law: fold (+1) 0 = id } tabulate (fold (+1) 0) = { see above } iterate (+1) 0 = { recursion-iteration lemma } nat

University of Oxford — Ralf Hinze 55-138

slide-56
SLIDE 56

Reasoning about Codata 3.2

3.2 Example: Fibonacci numbers

F0 = 0 F1 = 1 Fn+2 = Fn + Fn+1 fib = 0 ≺ 1 ≺ fib + tail fib

University of Oxford — Ralf Hinze 56-138

slide-57
SLIDE 57

Reasoning about Codata 3.2

3.2 Environment idiom: α →

instance Idiom (α →) where pure a = λx → a f ⋄ g = λx → (f x) (g x)

  • NB. pure is the K combinator and ⋄ is the S combinator.

University of Oxford — Ralf Hinze 57-138

slide-58
SLIDE 58

Reasoning about Codata 3.2

3.2 Idiom homomorphism

The natural transformation h :: φ α → ψ α is an idiom homomorphism iff h (pure a) = pure a h (x ⋄ y) = h x ⋄ h y .

University of Oxford — Ralf Hinze 58-138

slide-59
SLIDE 59

Reasoning about Codata 3.2

3.2 Tabulation

The natural transformations tabulate and lookup are idiom homomorphisms between Stream and Nat →. tabulate (pure a) = pure a tabulate (x ⋄ y) = tabulate x ⋄ tabulate y lookup (pure a) = pure a lookup (x ⋄ y) = lookup x ⋄ lookup y

University of Oxford — Ralf Hinze 59-138

slide-60
SLIDE 60

Reasoning about Codata 3.2

3.2 Derivation of fib

tabulate F = { definition of tabulate } F0 ≺ F1 ≺ tabulate (F · (+2)) = { definition of F } 0 ≺ 1 ≺ tabulate (F + F · (+1)) = { tabulate is an idiom homomorphism } 0 ≺ 1 ≺ tabulate F + tabulate (F · (+1)) = { definition of tabulate } 0 ≺ 1 ≺ tabulate F + tail (tabulate F)

University of Oxford — Ralf Hinze 60-138

slide-61
SLIDE 61

Reasoning about Codata 3.3

3.3 Example: Dijkstra’s fusc function

Dijkstra’s fusc sequence (EWD570 and EWD578). S1 = 1 S2∗n = Sn S2∗n+1 = Sn + Sn+1 fusc = 1 ≺ fusc fusc + tail fusc

University of Oxford — Ralf Hinze 61-138

slide-62
SLIDE 62

Reasoning about Codata 3.3

3.3 Recurrences as streams

F0 = k F2∗n+1 = f (Fn) F2∗n+2 = g (Fn) s = k ≺ map f s map g s

University of Oxford — Ralf Hinze 62-138

slide-63
SLIDE 63

Reasoning about Codata 3.3

3.3 Example: most significant bit

msb = 1 ≺ 2 ∗ msb 2 ∗ msb

University of Oxford — Ralf Hinze 63-138

slide-64
SLIDE 64

Reasoning about Codata 3.3

3.3 Example: 1s-counting sequence

  • nes = ones ones + 1
  • nes = 0 ≺ ones′
  • nes′ = 1 ≺ ones′ ones′ + 1

University of Oxford — Ralf Hinze 64-138

slide-65
SLIDE 65

Reasoning about Codata 3.3

3.3 Example: binary carry sequence

1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1

University of Oxford — Ralf Hinze 65-138

slide-66
SLIDE 66

Reasoning about Codata 3.3

1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1

University of Oxford — Ralf Hinze 66-138

slide-67
SLIDE 67

Reasoning about Codata 3.3

carry = 0 carry + 1 carry = 0 ≺ carry + 1 0

University of Oxford — Ralf Hinze 67-138

slide-68
SLIDE 68

Reasoning about Codata 3.3

3.3 Interactive session

≫ msb 1, 2, 2, 4, 4, 4, 4, 8, 8, 8, 8, 8, 8, 8, 8, 16, . . . ≫ ones 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4, . . . ≫ carry 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, 4, . . .

University of Oxford — Ralf Hinze 68-138

slide-69
SLIDE 69

Reasoning about Codata 3.3

3.3 Summary

  • Streams tabulate functions from the naturals.
  • tabulate and lookup are idiom homomorphisms.
  • Using ≺ and we can express many recurrences.

University of Oxford — Ralf Hinze 69-138

slide-70
SLIDE 70

Reasoning about Codata 4.0

Part 4 Finite Calculus

University of Oxford — Ralf Hinze 70-138

slide-71
SLIDE 71

Reasoning about Codata 4.0

4.0 Outline

  • 14. Finite Difference
  • 15. Summation
  • 16. Moessner’s theorem

University of Oxford — Ralf Hinze 71-138

slide-72
SLIDE 72

Reasoning about Codata 4.1

4.1 Finite difference

∆ :: (Num α) ⇒ Stream α → Stream α ∆ s = tail s − s

University of Oxford — Ralf Hinze 72-138

slide-73
SLIDE 73

Reasoning about Codata 4.1

4.1 Interactive session

≫ ∆ 2nat 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, . . . ≫ ∆ carry 1, −1, 2, −2, 1, −1, 3, −3, 1, −1, 2, −2, 1, −1, 4, −4, . . . ≫ ∆ nat3 1, 7, 19, 37, 61, 91, 127, 169, 217, 271, 331, 397, 469, 547, 631, 721, . . . ≫ 3 ∗ nat2 0, 3, 12, 27, 48, 75, 108, 147, 192, 243, 300, 363, 432, 507, 588, 675, . . .

University of Oxford — Ralf Hinze 73-138

slide-74
SLIDE 74

Reasoning about Codata 4.1

4.1 A new power

∆ (natn+1) = (repeat n + 1) ∗ natn

University of Oxford — Ralf Hinze 74-138

slide-75
SLIDE 75

Reasoning about Codata 4.1

4.1 Derivation

∆ (natn+1) = { definition of ∆ } tail (natn+1) − natn+1 = { definition of nat } (nat + 1)n+1 − natn+1 = { requirements: x ∗ (x − 1)n = xn+1 = xn ∗ (x − n) } (nat + 1) ∗ natn − natn ∗ (nat − repeat n) = { arithmetic } (repeat n + 1) ∗ natn

University of Oxford — Ralf Hinze 75-138

slide-76
SLIDE 76

Reasoning about Codata 4.1

4.1 Falling factorial powers

x0 = 1 xn+1 = x ∗ (x − 1)n

University of Oxford — Ralf Hinze 76-138

slide-77
SLIDE 77

Reasoning about Codata 4.1

4.1 Interactive session

≫ ∆ (nat3) 0, 0, 6, 18, 36, 60, 90, 126, 168, 216, 270, 330, 396, 468, 546, 630, . . . ≫ 3 ∗ nat2 0, 0, 6, 18, 36, 60, 90, 126, 168, 216, 270, 330, 396, 468, 546, 630, . . .

University of Oxford — Ralf Hinze 77-138

slide-78
SLIDE 78

Reasoning about Codata 4.1

4.1 Powers and falling factorial powers

x0 = x0 x1 = x1 x2 = x2 + x1 x3 = x3 + 3 ∗ x2 + x1 x4 = x4 + 6 ∗ x3 + 7 ∗ x2 + x1 x0 = x0 x1 = x1 x2 = x2 − x1 x3 = x3 − 3 ∗ x2 + 2 ∗ x1 x4 = x3 − 6 ∗ x2 + 11 ∗ x1 − 6 ∗ x1

University of Oxford — Ralf Hinze 78-138

slide-79
SLIDE 79

Reasoning about Codata 4.1

4.1 Laws

∆ (tail s) = tail (∆ s) ∆ (a ≺ s) = head s − a ≺ ∆ s ∆ (s t) = (t − s) (tail s − t) ∆ c = ∆ (c ∗ s) = c ∗ ∆ s ∆ (s + t) = ∆ s + ∆ t ∆ (s ∗ t) = s ∗ ∆ t + ∆ s ∗ tail t ∆ cnat = (c − 1) ∗ cnat ∆ (natn+1) = (repeat n + 1) ∗ natn

University of Oxford — Ralf Hinze 79-138

slide-80
SLIDE 80

Reasoning about Codata 4.1

4.1 Proof: product rule

∆ (s ∗ t) = { definition of ∆ and ∗ } tail s ∗ tail t − s ∗ t = { arithmetic } s ∗ tail t − s ∗ t + tail s ∗ tail t − s ∗ tail t = { distributivity } s ∗ (tail t − t) + (tail s − s) ∗ tail t = { definition of ∆ } s ∗ ∆ t + ∆ s ∗ tail t

University of Oxford — Ralf Hinze 80-138

slide-81
SLIDE 81

Reasoning about Codata 4.2

4.2 The right-inverse of ∆: Σ

∆ (Σ s) = s ⇐ ⇒ { definition of ∆ } tail (Σ s) − Σ s = s ⇐ ⇒ { arithmetic } tail (Σ s) = Σ s + s

University of Oxford — Ralf Hinze 81-138

slide-82
SLIDE 82

Reasoning about Codata 4.2

4.2 Summation

Σ :: (Num α) ⇒ Stream α → Stream α Σ s = t where t = 0 ≺ t + s

University of Oxford — Ralf Hinze 82-138

slide-83
SLIDE 83

Reasoning about Codata 4.2

t0 t1 t2 t3 t4 t5 t6 t7 t8 t9 · · · t + + + + + + + + + + · · · + s0 s1 s2 s3 s4 s5 s6 s7 s8 s9 · · · ≺ s = = = = = = = = = = = · · · = t0 t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 · · · t

University of Oxford — Ralf Hinze 83-138

slide-84
SLIDE 84

Reasoning about Codata 4.2

4.2 Interactive session

≫ Σ (0 1) 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, . . . ≫ Σ (2 ∗ nat + 1) 0, 1, 4, 9, 16, 25, 36, 49, 64, 81, 100, 121, 144, 169, 196, 225, .. . ≫ Σ carry 0, 0, 1, 1, 3, 3, 4, 4, 7, 7, 8, 8, 10, 10, 11, 11, . . . ≫ Σ (nat ^ 2) 0, 0, 1, 5, 14, 30, 55, 91, 140, 204, 285, 385, 506, 650, 819, 1015, . . . ≫ Σ (nat ∗ 2 ^ nat) 0, 0, 2, 10, 34, 98, 258, 642, 1538, 3586, 8194, 18434, 40962, .. .

University of Oxford — Ralf Hinze 84-138

slide-85
SLIDE 85

Reasoning about Codata 4.2

4.2 Summation by happenstance

t = 0 ≺ t + s ⇐ ⇒ Σ s = t

University of Oxford — Ralf Hinze 85-138

slide-86
SLIDE 86

Reasoning about Codata 4.2

4.2 Proof: Σ fib = fib′ − 1

fib = 0 ≺ fib + (1 ≺ fib) ⇐ ⇒ { summation by happenstance } Σ (1 ≺ fib) = fib ⇐ ⇒ { summation law, see next slide } 0 ≺ 1 + Σ fib = fib = ⇒ { s1 = s2 = ⇒ tail s1 = tail s2 } 1 + Σ fib = fib′ ⇐ ⇒ { arithmetic } Σ fib = fib′ − 1

University of Oxford — Ralf Hinze 86-138

slide-87
SLIDE 87

Reasoning about Codata 4.2

4.2 Laws

Σ (tail s) = tail (Σ s) − repeat (head s) Σ (a ≺ s) = 0 ≺ repeat a + Σ s Σ (s t) = (Σ s + Σ t) (s + Σ s + Σ t) Σ c = c ∗ nat Σ (c ∗ s) = c ∗ Σ s Σ (s + t) = Σ s + Σ t Σ (s ∗ ∆ t) = s ∗ t − Σ (∆ s ∗ tail t) − repeat (head (s ∗ t)) Σ cnat = cnat−1 / (c − 1) Σ (natn) = natn+1 / (repeat n + 1)

University of Oxford — Ralf Hinze 87-138

slide-88
SLIDE 88

Reasoning about Codata 4.2

4.2 Fundamental Theorem

t = ∆ s ⇐ ⇒ Σ t = s − repeat (head s)

University of Oxford — Ralf Hinze 88-138

slide-89
SLIDE 89

Reasoning about Codata 4.2

4.2 Proof: summation by parts

Let c = repeat (head (s ∗ t)), then s ∗ ∆ t + ∆ s ∗ tail t = ∆ (s ∗ t) ⇐ ⇒ { Fundamental Theorem } Σ (s ∗ ∆ t + ∆ s ∗ tail t) = s ∗ t − c ⇐ ⇒ { Σ is linear } Σ (s ∗ ∆ t) + Σ (∆ s ∗ tail t) = s ∗ t − c ⇐ ⇒ { arithmetic } Σ (s ∗ ∆ t) = s ∗ t − Σ (∆ s ∗ tail t) − c .

University of Oxford — Ralf Hinze 89-138

slide-90
SLIDE 90

Reasoning about Codata 4.2

4.2 Derivation: square pyramidal numbers

Σ nat2 = { converting to falling factorial powers } Σ (nat2 + nat1) = { summation laws } 1 3 ∗ nat3 + 1 2 ∗ nat2 = { converting to ordinary powers } 1 3 ∗ (nat3 − 3 ∗ nat2 + 2 ∗ nat) + 1 2 ∗ (nat2 − nat) = { arithmetic } 1 6 ∗ (nat − 1) ∗ nat ∗ (2 ∗ nat − 1)

University of Oxford — Ralf Hinze 90-138

slide-91
SLIDE 91

Reasoning about Codata 4.2

4.2 Derivation: Σ (nat ∗ 2nat)

Σ (nat ∗ 2nat) = { ∆ 2nat = 2nat } Σ (nat ∗ ∆ 2nat) = { summation by parts } nat ∗ 2nat − Σ (∆ nat ∗ tail 2nat) = { ∆ nat = 1, and definition of nat } nat ∗ 2nat − 2 ∗ Σ 2nat = { summation law } nat ∗ 2nat − 2 ∗ (2nat − 1) = { arithmetic } (nat − 2) ∗ 2nat + 2

University of Oxford — Ralf Hinze 91-138

slide-92
SLIDE 92

Reasoning about Codata 4.2

4.2 Running time of the binary increment

Amortised running time of the binary increment: Σ carry / nat. ≫ Σ carry 0, 0, 1, 1, 3, 3, 4, 4, 7, 7, 8, 8, 10, 10, 11, 11, . . . ≫ nat − Σ carry 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4, . . . ≫ nat − Σ carry 0 True

University of Oxford — Ralf Hinze 92-138

slide-93
SLIDE 93

Reasoning about Codata 4.2

4.2 1s-counting sequence, again

  • nes = 0 ≺ ones + 1 − carry

University of Oxford — Ralf Hinze 93-138

slide-94
SLIDE 94

Reasoning about Codata 4.2

4.2 Proof: Σ carry = nat − ones

  • nes = 0 ≺ ones + (1 − carry)

⇐ ⇒ { summation by happenstance } Σ (1 − carry) = ones ⇐ ⇒ { arithmetic } Σ carry = nat − ones

University of Oxford — Ralf Hinze 94-138

slide-95
SLIDE 95

Reasoning about Codata 4.3

4.3 Moessner’s theorem: n = 2

1 2 3 4 5 6 7 8 9 10 11 12 . . . 1 3 5 7 9 11 . . . 1 4 9 16 25 36 . . .

University of Oxford — Ralf Hinze 95-138

slide-96
SLIDE 96

Reasoning about Codata 4.3

4.3 A geometric proof

University of Oxford — Ralf Hinze 96-138

slide-97
SLIDE 97

Reasoning about Codata 4.3

4.3 Moessner’s theorem: n = 3

1 2 3 4 5 6 7 8 9 10 11 12 . . . 1 2 4 5 7 8 10 11 . . . 1 3 7 12 19 27 37 48 . . . 1 7 19 37 . . . 1 8 27 64 . . .

University of Oxford — Ralf Hinze 97-138

slide-98
SLIDE 98

Reasoning about Codata 4.3

4.3 Proof: n = 2

s1

  • s2

s1 + Σ s1 2 ∗ nat1 + 1

  • 2 ∗ nat1 + 2

nat2 + 3 ∗ nat1 + 1 2 ∗ nat + 1

  • 2 ∗ nat + 2

(nat + 1)2

University of Oxford — Ralf Hinze 98-138

slide-99
SLIDE 99

Reasoning about Codata 4.3

4.3 Proof: n = 3

s1 3 s2 3 s3 s1 + Σ (s1 + s2) 2 s1 + s2 + Σ (s1 + s2) s1 + Σ (s1 + s2) + Σ (s1 + Σ (s1 + s2)) 3 ∗ nat1 + 1 3 3 ∗ nat1 + 2 3 3 ∗ nat1 + 3 3 ∗ nat2 + 6 ∗ nat1 2 3 ∗ nat2 + 9 ∗ nat1 + 3 nat3 + 6 ∗ nat2 + 7 ∗ nat1 + 1 3 ∗ nat 1 + 1 3 3 ∗ nat 1 + 2 3 3 ∗ nat 1 + 3 3 ∗ nat2 + 3 ∗ nat 2 3 ∗ nat2 + 6 ∗ nat + 3 (nat + 1)3

University of Oxford — Ralf Hinze 99-138

slide-100
SLIDE 100

Reasoning about Codata 4.3

4.3 Summary

  • Finite calculus serves as an elegant application of stream

calculus.

  • Avoidance of index variables and subscripts.

University of Oxford — Ralf Hinze 100-138

slide-101
SLIDE 101

Reasoning about Codata 5.0

Part 5 Infinite Trees

University of Oxford — Ralf Hinze 101-138

slide-102
SLIDE 102

Reasoning about Codata 5.0

5.0 Outline

  • 17. Infinite trees
  • 18. Idioms
  • 19. Recursion and iteration
  • 20. Tabulation
  • 21. Sequences
  • 22. Laws

University of Oxford — Ralf Hinze 102-138

slide-103
SLIDE 103

Reasoning about Codata 5.1

5.1 Infinite trees

1 3 7 15 23 11 19 27 5 9 17 25 13 21 29 2 4 8 16 24 12 20 28 6 10 18 26 14 22 30

University of Oxford — Ralf Hinze 103-138

slide-104
SLIDE 104

Reasoning about Codata 5.1

5.1 Datatype of infinite trees

data Tree α = Node {root :: α, left :: Tree α, right :: Tree α}

University of Oxford — Ralf Hinze 104-138

slide-105
SLIDE 105

Reasoning about Codata 5.1

5.1 Binary numbers

1 3 7 15 23 11 19 27 5 9 17 25 13 21 29 2 4 8 16 24 12 20 28 6 10 18 26 14 22 30

bin = Node 0 (2 ∗ bin + 1) (2 ∗ bin + 2)

University of Oxford — Ralf Hinze 105-138

slide-106
SLIDE 106

Reasoning about Codata 5.2

5.2 Trees are an idiom

instance Idiom Tree where pure a = t where t = Node a t t t ⋄ u = Node ((root t) (root u)) (left t ⋄ left u) (right t ⋄ right u)

University of Oxford — Ralf Hinze 106-138

slide-107
SLIDE 107

Reasoning about Codata 5.2

5.2 Example: positive numbers

pos = Node 1 (2 ∗ pos + 0) (2 ∗ pos + 1) bin + 1 = pos

University of Oxford — Ralf Hinze 107-138

slide-108
SLIDE 108

Reasoning about Codata 5.2

5.2 Example: Stern-Brocot tree

1/1 1/2 1/3 1/4 1/5 2/7 2/5 3/8 3/7 2/3 3/5 4/7 5/8 3/4 5/7 4/5 2/1 3/2 4/3 5/4 7/5 5/3 8/5 7/4 3/1 5/2 7/3 8/3 4/1 7/2 5/1

stern = Node 1 (1 / (1 / stern + 1)) (stern + 1)

University of Oxford — Ralf Hinze 108-138

slide-109
SLIDE 109

Reasoning about Codata 5.2

5.2 Example: binary sequences

lbits = Node [ ] (map ([0]+ +) lbits) (map ([1]+ +) lbits) rbits = Node [ ] (map (+ +[0]) rbits) (map (+ +[1]) rbits)

University of Oxford — Ralf Hinze 109-138

slide-110
SLIDE 110

Reasoning about Codata 5.3

5.3 Recursion and iteration

recurse :: (α → α) → (α → α) → (α → Tree α) recurse f g a = t where t = Node a (map f t) (map g t) iterate :: (α → α) → (α → α) → (α → Tree α) iterate f g a = loop a where loop x = Node x (loop (f x)) (loop (g x))

University of Oxford — Ralf Hinze 110-138

slide-111
SLIDE 111

Reasoning about Codata 5.3

5.3 Example: bit strings, iteratively

[] [0] [0,0] [0,0,0] [1,0,0] [1,0] [0,1,0] [1,1,0] [1] [0,1] [0,0,1] [1,0,1] [1,1] [0,1,1] [1,1,1]

rbits = iterate ([0]+ +) ([1]+ +) [ ]

University of Oxford — Ralf Hinze 111-138

slide-112
SLIDE 112

Reasoning about Codata 5.3

5.3 Example: bit strings, recursively

[] [0] [0,0] [0,0,0] [0,0,1] [0,1] [0,1,0] [0,1,1] [1] [1,0] [1,0,0] [1,0,1] [1,1] [1,1,0] [1,1,1]

lbits = recurse ([0]+ +) ([1]+ +) [ ]

University of Oxford — Ralf Hinze 112-138

slide-113
SLIDE 113

Reasoning about Codata 5.4

5.4 A one-to-one correspondence

Tree α ∼ = Bin → α

University of Oxford — Ralf Hinze 113-138

slide-114
SLIDE 114

Reasoning about Codata 5.4

5.4 Tabulation

data Bin = Nil | One Bin | Two Bin tabulate :: (Bin → α) → Tree α tabulate f = Node (f Nil) (tabulate (f · One)) (tabulate (f · Two)) lookup :: Tree α → (Bin → α) lookup t Nil = root t lookup t (One b) = lookup (left t) b lookup t (Two b) = lookup (right t) b

University of Oxford — Ralf Hinze 114-138

slide-115
SLIDE 115

Reasoning about Codata 5.4

5.4 Facts

  • tabulate and lookup are natural transformations.
  • They are mutually inverse.
  • tabulate (fold one two nil) = iterate one two nil.
  • tabulate id = bin where

bin = Node Nil (map One bin) (map Two bin) .

University of Oxford — Ralf Hinze 115-138

slide-116
SLIDE 116

Reasoning about Codata 5.5

5.5 Another one-to-one correspondence

Stream α ∼ = Tree α Nat ∼ = Bin

University of Oxford — Ralf Hinze 116-138

slide-117
SLIDE 117

Reasoning about Codata 5.5

5.5 Linearising a tree

stream :: Tree α → Stream α stream t = root t ≺ stream (left t) stream (right t) stream :: Tree α → Stream α stream t = root t ≺ stream (chop t) chop :: Tree α → Tree α chop t = Node (root (left t)) (right t) (chop (left t))

University of Oxford — Ralf Hinze 117-138

slide-118
SLIDE 118

Reasoning about Codata 5.5

5.5 Constructing a tree

tree :: Stream α → Tree α tree s = Node (head s) (tree (even (tail s))) (tree (odd (tail s))) even, odd :: Stream α → Stream α even s = head s ≺ odd (tail s)

  • dd s

= even (tail s)

University of Oxford — Ralf Hinze 118-138

slide-119
SLIDE 119

Reasoning about Codata 5.5

tree (a ≺ l r) = Node a (tree l) (tree r) a ≺ stream l stream r = stream (Node a l r)

University of Oxford — Ralf Hinze 119-138

slide-120
SLIDE 120

Reasoning about Codata 5.5

5.5 Interactive session

≫ stream (iterate (λn → 2 ∗ n + 1) (λn → 2 ∗ n + 2) 0) 0, 1, 2, 3, 5, 4, 6, 7, 11, 9, 13, 8, 12, 10, 14, 15, . . . ≫ stream (recurse (λn → 2 ∗ n + 1) (λn → 2 ∗ n + 2) 0) 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, . . .

University of Oxford — Ralf Hinze 120-138

slide-121
SLIDE 121

Reasoning about Codata 5.6

5.6 Recursion and iteration: fusion

map h · recurse f1 g1 = recurse f2 g2 · h ⇑ h · f1 = f2 · h ∧ h · g1 = g2 · h ⇓ map h · iterate f1 g1 = iterate f2 g2 · h

University of Oxford — Ralf Hinze 121-138

slide-122
SLIDE 122

Reasoning about Codata 5.6

5.6 Monoids

class Monoid α where ǫ :: α (·) :: α → α → α

University of Oxford — Ralf Hinze 122-138

slide-123
SLIDE 123

Reasoning about Codata 5.6

5.6 Recursion-iteration lemma

recurse (a·) (b·) ǫ = iterate (·a) (·b) ǫ

  • NB. One is the bit-reversal permutation tree of the other.

University of Oxford — Ralf Hinze 123-138

slide-124
SLIDE 124

Reasoning about Codata 5.6

5.6 Summary

  • Tree is a co-inductive datatype.
  • Tree is an idiom.
  • Recursion and iteration.
  • Admissible equations have unique solutions!
  • Trees tabulate functions from the binary numbers.
  • tabulate and lookup are idiom homomorphisms!

University of Oxford — Ralf Hinze 124-138

slide-125
SLIDE 125

Reasoning about Codata 6.0

Part 6 Tabulation

University of Oxford — Ralf Hinze 125-138

slide-126
SLIDE 126

Reasoning about Codata 6.1

6.1 Recap: streams

Nat → γ ∼ = Stream γ (µ α . 1 + α) → ∼ = ν τ . Id ˙ × τ

University of Oxford — Ralf Hinze 126-138

slide-127
SLIDE 127

Reasoning about Codata 6.1

6.1 Recap: infinite trees

Bin → γ ∼ = Tree γ (µ α . 1 + α + α) → ∼ = ν τ . Id ˙ × τ ˙ × τ

University of Oxford — Ralf Hinze 127-138

slide-128
SLIDE 128

Reasoning about Codata 6.1

6.1 Laws of exponentials

0 → γ ∼ = 1 1 → γ ∼ = γ (α + β) → γ ∼ = (α → γ) × (β → γ) (α × β) → γ ∼ = α → (β → γ) 0 → ∼ = K 1 1 → ∼ = Id (α + β) → ∼ = (α →) ˙ × (β →) (α × β) → ∼ = (α →) · (β →)

University of Oxford — Ralf Hinze 128-138

slide-129
SLIDE 129

Reasoning about Codata 6.1

6.1 Tabulation

F(α) = αi H(τ) = τi F(α) = H(τ) = K 1 F(α) = 1 H(τ) = Id F(α) = F1(α) + F2(α) H(τ) = H1(τ) ˙ × H2(τ) F(α) = F1(α) × F2(α) H(τ) = H1(τ) · H2(τ) F(α) = µ α . F1(α, α) H(τ) = ν τ . H1(τ, τ)

University of Oxford — Ralf Hinze 129-138

slide-130
SLIDE 130

Reasoning about Codata 6.1

6.1 Tabulation Theorem

F(α1, . . . , αn) → ∼ = T (α1 →, . . . , αn →)

University of Oxford — Ralf Hinze 130-138

slide-131
SLIDE 131

Reasoning about Codata 6.1

6.1 Example: integers

data Int = Neg Nat | Pos Nat Int → ∼ = Stream ˙ × Stream

University of Oxford — Ralf Hinze 131-138

slide-132
SLIDE 132

Reasoning about Codata 6.1

6.1 Example: pairs of naturals

(Nat × Nat) → ∼ = Stream · Stream

University of Oxford — Ralf Hinze 132-138

slide-133
SLIDE 133

Reasoning about Codata 6.1

6.1 Proofs

F1(α) + F2(α) case analysis pairs H1(τ) ˙ × H2(τ) F1(α) × F2(α) pairs nested proofs H1(τ) · H2(τ) µ α . F1(α, α) induction co-induction ν τ . H1(τ, τ)

University of Oxford — Ralf Hinze 133-138

slide-134
SLIDE 134

Reasoning about Codata 6.1

6.1 Applications

  • Memoisation or tabulation of functions.
  • Finite version: tries and generalised tries.
  • Deforested: generic sorting and grouping.

University of Oxford — Ralf Hinze 134-138

slide-135
SLIDE 135

Reasoning about Codata 6.1

6.1 References

  • Richard H. Connelly and F. Lockwood Morris. “A generalization of

the trie data structure”, Math. Struct. in Comp. Science, (5):381–418, 1995.

  • Ralf Hinze. “Memo functions, polytypically!”, in Johan Jeuring, editor,

Proceedings of the 2nd Workshop on Generic Programming, Ponte de Lima, Portugal, pages 17–32, 2000. The proceedings appeared as a technical report of Universiteit Utrecht, UU-CS-2000-19.

  • Thorsten Altenkirch. “Representations of first order function types as

terminal coalgebras”. In Typed Lambda Calculi and Applications (TLCA 2001), LNCS 2044, pages 8–21, 2001.

  • Fritz Henglein. “Generic discrimination: sorting and paritioning

unshared data in linear time”. In Peter Thiemann, editor, Proceedings

  • f the 13th ACM Sigplan International Conference on Functional

Programming (ICFP’08), September 22–24, 2008, Victoria, BC, Canada, pages 91–102. ACM Press, 2008.

University of Oxford — Ralf Hinze 135-138

slide-136
SLIDE 136

Reasoning about Codata 7.0

Part 7 Epilogue

University of Oxford — Ralf Hinze 136-138

slide-137
SLIDE 137

Reasoning about Codata 7.0

7.0 Summary

  • Streams and infinite trees are tabulations.
  • Idioms and idiom homomorphisms.
  • Holistic or wholemeal approach to proving and

programming.

University of Oxford — Ralf Hinze 137-138

slide-138
SLIDE 138

Reasoning about Codata 7.0

7.0 What else?

  • Equality of ADTs or objects.

data Obj F = ∃ σ . Obj ((σ → F σ) × σ)

University of Oxford — Ralf Hinze 138-138