Concrete stream calculus: An extended study

This paper shows how to reason about streams concisely and precisely. Streams, infinite sequences of elements, live in a coworld: they are given by a coinductive datatype, operations on streams are implemented by corecursive programs, and proofs are typically concocted using coinduction. This paper offers an alternative to coinduction. Suitably restricted, stream equations possess unique solutions. This property gives rise to a simple and attractive proof technique, essentially bringing equational reasoning to the coworld. We redevelop the theory of recurrences, finite calculus and generating functions using streams and stream operators, building on the cornerstone of unique solutions. The paper contains a smorgasbord of examples: we study recursion elimination, investigate the binary carry sequence, explore Sprague-Grundy numbers and present two proofs of Moessner's Theorem. The calculations benefit from the rich structure of streams. As the type of streams is an applicative functor we can effortlessly lift operations and their properties to streams. In combination with Haskell's facilities for overloading, this greatly contributes to conciseness of notation. The development is indeed constructive: streams and stream operators are implemented in Haskell, usually by one-liners. The resulting calculus or library, if you wish, is elegant and fun to use.

[1]  Alexandra Silva,et al.  A coinductive calculus of binary trees , 2010, Inf. Comput..

[2]  Niklas Röjemo Garbage Collection, and Memory Efficiency, in Lazy Functional Languages , 1995 .

[3]  Ian Stewart The Magical Maze: Seeing The World Through Mathematical Eyes , 1998 .

[4]  M. Douglas McIlroy,et al.  The music of streams , 2001, Inf. Process. Lett..

[5]  Richard S. Bird,et al.  Introduction to functional programming , 1988, Prentice Hall International series in computer science.

[6]  Olivier Danvy,et al.  An Extensional Characterization of Lambda-Lifting and Lambda-Dropping , 1998, Fuji International Symposium on Functional and Logic Programming.

[7]  Tobias Nipkow,et al.  Types for Proofs and Programs: International Workshop TYPES '93, Nijmegen, The Netherlands, May 24 - 28, 1993. Selected Papers , 1994 .

[8]  Falk Bartels,et al.  Generalised coinduction , 2003, Mathematical Structures in Computer Science.

[9]  Donald E. Knuth,et al.  The Art of Computer Programming: Volume 3: Sorting and Searching , 1998 .

[10]  Jan J. M. M. Rutten,et al.  A coinductive calculus of streams , 2005, Mathematical Structures in Computer Science.

[11]  Jerzy Karczmarczuk,et al.  Generating Power of Lazy Semantics , 1997, Theor. Comput. Sci..

[12]  Donald E. Knuth,et al.  The art of computer programming, volume 3: (2nd ed.) sorting and searching , 1998 .

[13]  Graham Hutton,et al.  The worker/wrapper transformation , 2009, Journal of Functional Programming.

[14]  Jan J. M. M. Rutten,et al.  Behavioural differential equations: a coinductive calculus of streams, automata, and power series , 2003, Theor. Comput. Sci..

[15]  Ralf Hinze Scans and Convolutions - A Calculational Proof of Moessner's Theorem , 2008, IFL.

[16]  Richard S. Bird,et al.  An introduction to the theory of lists , 1987 .

[17]  Richard S. Bird,et al.  Introduction to functional programming using haskeu , 1998 .

[18]  M. Douglas McIlroy,et al.  Power series, power serious , 1999, Journal of Functional Programming.

[19]  Conor McBride,et al.  Applicative programming with effects , 2008, J. Funct. Program..

[20]  Thorsten Altenkirch,et al.  Representations of First Order Function Types as Terminal Coalgebras , 2001, TLCA.

[21]  Richard S. Bird,et al.  Nested Datatypes , 1998, MPC.

[22]  Graham Hutton,et al.  Proof Methods for Corecursive Programs , 2005, Fundam. Informaticae.

[23]  Thierry Coquand,et al.  Infinite Objects in Type Theory , 1994, TYPES.

[24]  Ralf Hinze Functional pearl: streams and unique fixed points , 2008, ICFP 2008.

[25]  Maarten M. Fokkinga,et al.  Law and order in algorithmics , 1992 .

[26]  Ralf Hinze Type Fusion , 2010, AMAST.

[27]  Ralf Hinze,et al.  Memo functions‚ polytypically! , 2000 .

[28]  Ralf Hinze,et al.  The Bird Tree , 2009, Journal of Functional Programming.

[29]  Roland Carl Backhouse,et al.  Galois Connections and Fixed Point Calculus , 2000, Algebraic and Coalgebraic Methods in the Mathematics of Program Construction.

[30]  Ralf Hinze,et al.  Perfect trees and bit-reversal permutations , 2000, J. Funct. Program..

[31]  Roland Carl Backhouse,et al.  The associativity of equivalence and the Towers of Hanoi problem , 2001, Inf. Process. Lett..

[32]  Robin Milner,et al.  Communication and concurrency , 1989, PHI Series in computer science.

[33]  Milad Niqui,et al.  Sampling, Splitting and Merging in Coinductive Stream Calculus , 2009, MPC.

[34]  S. Lane Categories for the Working Mathematician , 1971 .