Primitive (Co)Recursion and Course-of-Value (Co)Iteration, Categorically

Size: px
Start display at page:

Download "Primitive (Co)Recursion and Course-of-Value (Co)Iteration, Categorically"

Transcription

1 INORMATICA, 1999 Vol. 10, No. 1, 1 0 Primitive (Co)Recursion and Course-of-Value (Co)Iteration, Categorically Tarmo Uustalu Dept. of Teleinformatics, Royal Inst. of Technology, Electrum 0, SE-1 0 Kista, Sweden tarmo@it.kth.se Varmo Vene Inst. of Computer Science, Univ. of Tartu, J. Liivi, EE-8 Tartu, Estonia varmo@cs.ut.ee Abstract In the mainstream categorical approach to typed (total) functional programming, datatypes are modelled as initial algebras and codatatypes as terminal coalgebras. The basic function definition schemes of iteration and coiteration are modelled by constructions known as catamorphisms and anamorphisms. Primitive recursion has been captured by a construction called paramorphisms. We draw attention to the dual construction of apomorphisms, and show on examples that primitive corecursion is a useful function definition scheme. We also put forward and study two novel constructions, viz., histomorphisms and futumorphisms, that capture the powerful schemes of course-of-value iteration and its dual, respectively, and argue that even these are helpful. Key words: typed (total) functional programming, category theory, program calculation, (co)datatypes, forms of (co)recursion 1. Introduction This paper is about a well-known categorical approach to typed (total) functional programming popular in the program calculation community. In this approach, datatypes and codatatypes are modelled as initial algebras and terminal coalgebras, and iteration and coiteration are modelled by constructions known as catamorphisms and anamorphisms. Primitive recursion, which universally recognized as an important generalization of iteration, is nicely captured by Meertens (199) paramorphisms. With this paper, we aim to draw attention to the dual construction of apomorphisms, described in (Vos, 95) and (Vene and Uustalu, 1998), which models an undeservedly little appreciated scheme that we like to call primitive corecursion. We also put forward and study two novel constructions, viz., histomorphisms and futumorphisms, that capture course-ofvalue iteration and its dual, respectively, and argue that even these schemes are helpful for a declaratively thinking programmer and program reasoner who loves

2 T. Uustalu and V. Vene languages of programming and program reasoning where programs and proof s of properties of programs are easy to write and read. The tradition of categorical functional programming that we follow in this paper started off with the Bird-Meertens formalism (Bird, 1987), which is a theory of the datatype of lists. Malcolm (1990) and okkinga (199), inspired by (Hagino, 1987), generalized the approach for arbitrary datatypes and codatatypes. (Geuvers, 199) contains a thorough category-theoretic analysis of primitive recursion versus iteration and a demonstration that this readily dualizes into an analysis of primitive corecursion versus coiteration. In general, however, it appears that primitive corecursion has largely been overlooked in the theoretical literature, e.g. (okkinga, 199) ignores it. Apart from (Vos, 95) and (Vene and Uustalu, 1998), the sole discussion on primitive corecursion in a programming context that we know about is the laconic report in (Vesely, 1997) on a recent not very clean extension to the categorical functional language Charity in which it is possible to define functions by primitive recursion and primitive corecursion. The most probable reason for this situation is the young age of programming with codatatypes. We are not aware of any work whatsoever on categorical constructions modelling course-of-value (co)iteration. This paper is an intermediate report of an ongoing research project on program construction for typed functional languages in which all programs are guaranteed to terminate (only total functions can be programmed). or a recent defence of the merits of typed total functional programming, see (Turner, 1995). Part of the material of the present paper originates from (Vene and Uustalu, 1998). In another earlier paper, (Uustalu and Vene, 1997), we discussed programming and program construction with (co)datatypes in a different setting of intuitionistic natural deduction. We shall proceed as follows. In section, we present the setting and notation. In section 3, we give a short introduction to the standard categorical approach to (co)datatypes and (co)iteration. In section, we introduce a categorical construction for primitive recursion and prove several laws about it. Afterwards, we dualize this development, introducing a categorical primitive corecursor and stating the laws it obeys, and show the usefulness of primitive corecursion on several examples. In section 5, we introduce a novel construction for course-of-value iteration, prove the crucial laws about it, and hint at programming examples where course-of-value iteration is useful. Again, we also dualize the whole development, arriving at a categorical treatment of the dual of course-of-value iteration. In section, we indicate some possible directions for further work and conclude. Proofs in this paper are carried out in the structured calculational proof style (Grundy, 199).

3 Primitive (Co)Recursion and Course-of-Value (Co)Iteration, Categorically 3. Preliminaries Throughout the paper C is the default category, which we require to be distributive, i.e., it must have finite products (; 1) and co-products (+; 0), and the products must distribute over the coproducts. The typical example of a distributive category is Sets the category of sets and total functions. We make use the following quite standard notation. Given two objects A, B, we write fst : A B! A and snd : A B! B for the left and right projections for the product AB. or g : C! A and h : C! B, h g; h i denotes the unique morphism f : C! A B, such that fst f = g and snd f = h (pairing). The notation g h is a shorthand for h g fst; h snd i. The left and right injections for the coproduct A + B are denoted by inl : A! A + B and inr : B! A + B. or g : A! C and h : B! C, [ g; h ] denotes the unique morphism f : A + B! C, such that f inl = g and f inr = h (case analysis). The notation g + h abbreviates [ inl g; inr h ]. Also,! and denote the unique morphisms f : C! 1 and f 0 : 0! C. The inverse of the canonical map [ inl id C ; inr id C ] : (A C) + (B C)! (A + B) C is denoted by distr : (A + B)C! (AC) + (B C), and the inverse of the canonical map [ id A inl; id A inr ] : (AB)+(AC)! A(B+C) is denoted by distl : A (B + C)! (A B) + (A C). inally, given a predicate p : A! 1 + 1, the guard p? : A! A + A is defined as (snd + snd) distr h p; id A i. 3. (Co)datatypes and (co)iteration Categorically, datatypes (of natural numbers, lists, etc.) are traditionally modelled by initial algebras and codatatypes (of conatural numbers, colists, streams, etc.) by terminal coalgebras. The function definition schemes of iteration and coiteration are modelled by constructions termed catamorphisms and anamorphisms. The theory presented in this section has become a bit of folklore; a good reference source is (okkinga, 199). Initial algebras and catamorphisms Let be a functor from C to C. An algebra with the signature ( -algebra, for short) is a pair (A; '), where A (called the carrier) is an object and ' : A! A (called the structure) is a morphism in C. or any two -algebras (A; ') and (C; ), a morphism f : A! C is said to be a homomorphism (between -algebras) from (A; ') to (C; ) if f ' = f. It is easy to verify that the morphism composition of two homomorphisms is also a homomorphism. Moreover, for any -algebra (A; '), the identity morphism id : A! A is a homomorphism from (A; ') to (A; '). It follows that the -algebras and the homomorphisms between them form a category. The category Alg( ) is the category whose objects are the -algebras and morphisms are the homomorphisms between them. Composition and identities are inherited from C.

4 T. Uustalu and V. Vene A -algebra is said to be an initial -algebra if it is initial (as an object) in the category Alg( ). The initial -algebra may or may not exist. It is guaranteed to exist if is!-cocontinuous (i.e., it preserves the colimits of!-chains). All polynomial functors (i.e., functors built up from products, sums, the identity functor, and constant functors) are!-cocontinuous and, hence, the initial algebras for them exist. Given a functor, the existence of the initial -algebra (; in ) means that, for any -algebra (C; '), there exists a unique -homomorphism of algebras from (; in ) to (C; '). ollowing okkinga (199), we denote this homomorphism by (j ' j), so (j ' j) :! C is characterized by the universal property f in = ' f, f = (j ' j) cata-charn The type information is summarized in the following diagram: in f C ' C Morphisms of the form (j ' j) are called catamorphisms (derived from the Greek preposition meaning downwards ); the construction (j j) is an iterator. EXAMPLE 1. The datatype of natural numbers can be represented as the initial algebra (N; in N ) of the functor N defined by N X = 1 + X and N f = id 1 + f. Write Nat for N. The function zero : 1! Nat equals in N inl, the function succ : Nat : Nat! Nat equals in N inr. Given any two functions c : 1! C and h : C! C, the catamorphism f = (j [ c; h ] j) N : Nat! C is the unique solution of the equation system f f zero = c ^ f succ = h f: Given a function n : 1! Nat, the function add (n) : Nat! Nat (which adds n to its argument), for instance, can be defined as the catamorphism (j [ n; succ ] j) N. EXAMPLE. The datatype of lists over a given set A can be represented as the initial algebra (L A ; in LA ) of the functor L A defined by L A X = 1 + (A X) and L A f = id 1 + (id A f ). Denote L A by List A. The function

5 Primitive (Co)Recursion and Course-of-Value (Co)Iteration, Categorically 5 nil : 1! List A equals in LA inl, the function cons : A List A! List A equals in LA inr. Given any two functions c : 1! C and h : A C! C, the catamorphism f = (j [ c; h ] j) LA : List A! C is the unique solution of the equation system f nil = c ^ f cons = h (id A f ); i.e., foldr (c; h) from functional programming. Given a function h : A! B, the function map(h) : List A! List B (which applies h to every element of the argument), for instance, can be defined as the catamorphism (j [ nil ; cons (h id List A ) ] j) LA : Catamorphisms obey several nice laws, of which the cancellation law, the reflection law (also known as the identity law) and the fusion (or, promotion) law are especially important for program calculation (the cancellation law describing a certain program execution step): (j ' j) in = ' (j ' j) cata-cancel id = (j in j) cata-rel f ' = f ) f (j ' j) = (j j) cata-usion The reflection and fusion laws are proved as follows: id = cata-charn in = functor in id (j in j) f ' = f f (j ' j) = cata-charn (j j) f (j ' j) in = cata-charn f ' (j ' j) = f (j ' j) = functor (f (j ' j) ) The important simple result that in :! is an isomorphism with the inverse (j in j) :! was first recorded by Lambek (198). in (j in j) = id ^ (j in j) in = id LEMMA-1

6 T. Uustalu and V. Vene It is proved by the following two calculations: in (j in j) = cata-usion (j in j) = cata-rel id (j in j) in = cata-charn in (j in j) ) = functor (in (j in j) ) = above id = functor Define id in?1 = (j in j) in-inv-de Lemma 1 gives us the following characterization for in?1 : in in?1 = id ^ in?1 in = id in-inv-charn EXAMPLE 3. Using in?1, the predecessor function pred : Nat! Nat can be defined as [ zero; id Nat ] in?1 N. Terminal coalgebras and anamorphisms We now dualize the material about initial algebras and catamorphisms. Let be a functor from C to C. A coalgebra with the signature ( - coalgebra, for short) is a pair (A; '), where A (called the carrier) is an object and ' : A! A (called the structure) is a morphism in C. or any two - coalgebras (C; ) and (A; '), a morphism f : C! A is said to be a homomorphism (between -coalgebras) from (C; ) to (A; ') if ' f = f. The -coalgebras and the homomorphisms between them form a category. The category CoAlg( ) is the category whose objects are the -coalgebras and morphisms are the homomorphisms between them. Composition and identities are inherited from C. A -coalgebra is said to be a terminal -coalgebra if it is terminal (as an object) in the category CoAlg( ). The terminal -coalgebra may or may not exist. It is guaranteed to exist if is!-continuous (i.e., it preserves the limits of!- chains). All polynomial functors (i.e., functors built up from products, sums, the identity functor, and constant functors) are!-continuous and, hence, the terminal coalgebras for them exist. The existence of the terminal -coalgebra (; out ) means that for any -coalgebra (C; '), there exists a unique -homomorphism of coalgebras from

7 Primitive (Co)Recursion and Course-of-Value (Co)Iteration, Categorically 7 (C; ') to (; out ). This homomorphism is usually denoted by [( ' )], so [( ' )] : C! is characterized by the universal property out f = f ', f = [( ' )] ana-charn The type information is summarized in the following diagram: C ' C f f out Morphisms of the form [( ' )] are called anamorphisms (derived from the Greek preposition meaning upwards ; the name is due to Meijer), and the construction [( )] is a coiterator. Like catamorphisms, anamorphisms enjoy various properties including the following cancellation, reflection and fusion laws: out [( ' )] = [( ' )] ' ana-cancel id = [( out )] ana-rel f = f ' ) [( )] f = [( ' )] ana-usion Also, out :! is an isomorphism with the inverse [( out )] :!. out?1 = [( out )] out-inv-de out?1 out = id ^ out out?1 = id out-inv-charn EXAMPLE. The codatatype of streams over a given set A is nicely represented by the terminal coalgebra (S A ; out SA ) of the functor S A defined by S A X = A X and S A f = id A f. Write Stream A for S A. The functions head : Stream A! A and tail : Stream A! Stream A equal fst out SA and snd out SA, respectively. Given any two functions c : C! A and h : C! C, the anamorphism [( h c; h i )] SA is the unique solution f : C! Stream A of the equation system head f = c ^ tail f = f h: The function nats : Nat! Stream Nat, which returns the stream of all natural numbers starting with the natural number given as the argument, is the

8 8 T. Uustalu and V. Vene unique solution of the equation system head nats = id Nat ^ tail nats = nats succ; and is thus definable as the anamorphism [( h id Nat ; succ i )]. The function zip : Stream A Stream A! Stream AA that zips the argument streams together is characterized as follows: head zip = (fst fst) (out SA out SA ) ^ tail zip = zip (snd snd) (out SA out SA ) This function can, therefore, be defined as [( h fst fst; snd snd i (out SA out SA ) )] SA : EXAMPLE 5. The codatatype of colists over a given set A can be represented as the terminal coalgebra (L A ; out LA ) of the functor L A. Write List 0 A for L A. Given any function g : C! 1+(AC), the anamorphism [( g )] LA is the unique solution f : C! List 0 A of the equation out L A f = (id 1 +(id A f ))g, i.e. the function unfold (g) from functional programming.. Primitive (co-)recursion Paramorphisms EXAMPLE. The factorial function fact : Nat! Nat is most neatly characterized as the unique solution of the equation system fact zero = succ zero ^ fact succ = mult h fact; succ i: This function is not a catamorphism. The problem is that its value for a given argument depends not only on the values for the immediate subparts of the argument, but also on these immediate subparts directly. Meertens (199) showed that any function which can be characterized similarly to the factorial function is definable as the composition of the left projection and a catamorphism. The relevant result is the following:

9 Primitive (Co)Recursion and Course-of-Value (Co)Iteration, Categorically 9 or any two morphisms f :! C and ' : (C )! C, we have fin = ' h f; id i, f = fst(j h '; in snd i j) LEMMA- It is proved by the following calculations: f in = ' h f; id i f fst h f; id i = cata-charn h f; id i in h f in ; in i = functor h f in ; in id i h f in ; in (snd h f; id i) i =, functor h ' h f; id i; in snd h f; id i i h '; in snd i h f; id i fst (j h '; in snd i j) f = fst (j h '; in snd i j) f in = fst (j h '; in snd i j) in = cata-charn fst h '; in snd i (j h '; in snd i j) = pairing, x ' h fst (j h '; in snd i j) ; snd (j h '; in snd i j) i =, cata-usion snd h '; in snd i in snd ' h f; (j in j) i = cata-rel ' h f; id i

10 10 T. Uustalu and V. Vene EXAMPLE 7. or the factorial function, we have that fact in = [ succ zero; mult h fact; succ i ] = [ succ zero; mult (id Nat succ) ] N h fact; id Nat i: and consequently we get the definition of factorial fact = fst (j h [ succ zero; mult (id Nat succ) ]; in N snd i j) N = fst (j h [ succ zero; mult (id Nat succ) ]; [ zero; succ snd ] i j) N To make programming and program reasoning easier, let us introduce a new construction and study its properties. or any morphism ' : (C )! C, define the morphism hj ' ji :! C by hj ' ji = fst (j h '; in snd i j) para-de Morphisms of the form hj ' ji are called paramorphisms ( Greek preposition meaning near to, at the side of, towards ; the name is due to Meertens). The construction hj ji is a primitive recursor. rom Lemma, we get the characterization of paramorphisms by the following universal property: f in = ' h f; id i, f = hj ' ji para-charn The type information is summarized in the following diagram: h f;id i (C ) in ' C f EXAMPLE 8. The paramorphism hj [ succ zero; mult (id Nat succ) ] ji N defines the factorial function. More generally, given any two functions c : 1! C and h : C Nat! C, the paramorphism f = hj [ c; h ] ji N : Nat! C is the unique solution of the

11 Primitive (Co)Recursion and Course-of-Value (Co)Iteration, Categorically 11 equation system f zero = c ^ f succ = h h f; id Nat i: The calculational properties of paramorphisms are similar to those of catamorphisms. In particular, we have the following paramorphic cancellation, reflection and fusion laws: hj ' ji in = ' h hj ' ji ; id i id = hj in fst ji para-cancel para-rel f ' = (f id ) ) f hj ' ji = hj ji para-usion The reflection and fusion laws are proved as follows: id = para-charn in = functor in id in (fst h id ; id i) = functor in fst h id ; id i hj in fst ji f ' = (f id ) f hj ' ji = para-charn hj ji f hj ' ji in = para-charn f ' h hj ' ji ; id i = (f id ) h hj ' ji ; id i = functor ((f id ) h hj ' ji ; id i) h f hj ' ji ; id i

12 1 T. Uustalu and V. Vene By definition, every paramorphism is the composition of the left projection and a catamorphism. In converse, paramorphisms can be viewed as a generalization of catamorphisms, in the sense that every catamorphism is definable as a certain paramorphism: (j ' j) = hj ' fst ji para-cata This law is verified by the following calculation: (j ' j) = para-charn (j ' j) in = cata-charn ' (j ' j) ' (fst h (j ' j) ; id i) = functor ' fst h (j ' j) ; id i hj ' fst ji Actually, every morphism whose source is the carrier of an initial algebra is a paramorphism: f = hj f in snd ji para-any This observation, first recorded in (Meertens, 199), is proved as follows: f = para-charn f in = functor f in id f in (snd h f; id i) = functor f in snd h f; id i hj f in snd ji

13 Primitive (Co)Recursion and Course-of-Value (Co)Iteration, Categorically 13 rom this law, it is a very short step to the following definition of the morphism in?1 as a paramorphism: The proof proceeds as follows: in?1 = hj snd ji para-in-inv in?1 = para-any hj in?1 in snd ji = in-inv-charn hj snd ji Apomorphisms Let us now dualize everything we know about paramorphisms. or any morphism ' : C! (C + ), define the morphism [h ' i] : C! as a composition of a certain anamorphism with the left injection: [h ' i] = [( [ '; inr out ] )] inl apo-de Morphisms of the form [h ' i] are the dual of paramorphisms. Both in (Vos, 95) and (Vene and Uustalu, 1998), these morphisms are called apomorphisms (o Greek preposition meaning apart from, far from, away from ) 1. The construction [h i] is, of course, a primitive corecursor. The characterizing universal property for apomorphisms is following: out f = [ f; id ] ', f = [h ' i] apo-charn The type information is summarized in the following diagram: f C ' out (C + ) [ f;id ] 1 A curious thing is that we wrote (Vene and Uustalu, 1998) unaware of the earlier existence of (Vos, 95), but happened to come up with the exactly the same new name

14 1 T. Uustalu and V. Vene The laws for apomorphisms are just the duals of those for paramorphisms. The cancellation, reflection and fusion laws are these: out [h ' i] = [ [h ' i] ; id ] ' apo-cancel id = [h inl out i] apo-rel f = (f + id ) ' ) [h i] f = [h ' i] apo-usion As paramorphisms generalized catamorphisms, apomorphisms are a generalization of anamorphisms. [( ' )] = [h inl ' i] apo-ana Also, any morphism whose target is the carrier of a terminal coalgebra, is an apomorphism. f = [h inr out f i] apo-any The morphism out?1 has this nice apomorphic definition: out?1 = [h inr i] apo-out-inv EXAMPLE 9. The function maphd (h) : Stream A! Stream A, which modifies any input stream by applying a function h : A! A to its head while leaving the tail unchanged, is definable as the composition of a certain anamorphism with the left injection that constructs the value for a given argument from the value of h for its head and from the elements of its tail. maphd (h) = [( [ h h head ; inr tail i; h head; inr tail i ] )] SA inl = [( [ h h head ; inr tail i; S A inr out SA ] )] SA inl A much more natural definition of this function is given by an apomorphism that constructs the value for a given argument from the value of h for its head and from the whole of its tail. maphd (h) = [h h h head ; inr tail i i] SA EXAMPLE 10. Assume that a given set A is linearly ordered by a predicate () : A A! or any function x : 1! A, the function insert(x) : Stream A! Stream A, that inserts the element x into an input strean

15 Primitive (Co)Recursion and Course-of-Value (Co)Iteration, Categorically 15 immediately before the first element that x is less than or equal to (so that the returned stream will be sorted, if the given stream is), is characterized by the equation h x; ys i if x head ys h head ; tail i insert(x) ys = h head ; insert(x) tail i ys otherwise The function insert(x) is most naturally defined as an apomorphism that constructs the value for a given argument from its certain initial segment elementwise and the remainder as one whole: insert(x) = [h [ h x!; inr i; (id A inl) ] test(x) i] SA where test(x) : Stream A! Stream A + S A Stream A is test(x) = (fst+snd)(()h x!; fst snd i)? h id StreamA ; h head ; tail i i EXAMPLE 11. or any function ` : 1! List 0 A, the function append (`) : List 0 A! List 0 A, which appends the colist ` to an input colist, is naturally definable as an apomorphism which constructs the value for a given argument from the elements of the argument and from the whole of `: append (`) = [h [ [ inl; inr (id A inr) ] out LA `; inr (id A inl) ] out LA i] LA = [h [ L A inr out LA `; inr ] L A inl out LA i] LA 5. Course-of-value (co)iteration Histomorphisms EXAMPLE 1. The famous ibonacci function bo : Nat! Nat is most smoothly characterized as the unique solution of the equation system bo zero = one ^ bo one = one ^ bo succ succ = add h bo succ; bo i; where one = succ zero. This very nice characterization does not give us any definition of bo in terms of catamorphisms. The problem is that the value of bo

16 1 T. Uustalu and V. Vene for a given argument is defined not via the values for the immediate subparts of the argument, but via the values for its subparts of depth. But the characterization of bo together with the function bo 0 : Nat! Nat Nat (which, for any argument n, returns the pair formed of the value of bo for n and either zero or the value of bo for the predecessor of n) by a much trickier equation system, viz., bo = fst bo 0 ^ bo 0 zero = h one; zero i ^ bo 0 succ = h add ; fst i bo 0 ; leads to a definition of bo as the composition of the left projection and a catamorphism: bo = fst (j h [ one; add ]; [ zero; fst ] i j) Nat : To make programming and program reasoning easier, we could introduce a new construction that would capture the natural definition scheme of the ibonacci function and closely similar functions, and start studying its properties. But this would only provide us with a partial solution to the problem manifested by the ibonacci example, as one can imagine functions whose value for a given argument is naturally defined via the values for its subparts of depth three, four, etc. Instead of this, we introduce a construction that captures course-of-value iteration, which is a function definition scheme where the value of a function for a given argument may depend on the values for just any of its subparts. We start with the following result, which, to our knowledge, is novel: Let denote the functor A A X = A X, A h = id A h. Then, for any two morphisms f :! C and ' : ( C )! C, we have f in = ' [( h f; in?1 i )], f = fst out (j out?1 h '; id i j) LEMMA-3

17 Primitive (Co)Recursion and Course-of-Value (Co)Iteration, Categorically 17 Proving it is quite tricky. f in = ' [( h f; in?1 i )] f fst h f; in?1 i fst (id [( h f; in?1 = ana-charn fst out [( h f; in?1 = cata-charn i )] ) h f; in?1 i i )] [( h f; in?1 i )] in = out-inv-charn out?1 out [( h f; in?1 i )] in = ana-charn out?1 (id [( h f; in?1 i )] ) h f; in?1 i in out?1 h f; [( h f; in?1 i )] in?1 i in out?1 h f in ; [( h f; in?1 i )] in?1 in i =, in-inv-charn out?1 h ' [( h f; in?1 i )] ; [( h f; in?1 i )] i out?1 h '; id i [( h f; in?1 i )] fst out (j out?1 h '; id i j)

18 18 T. Uustalu and V. Vene f = fst out (j out?1 h '; id i j) f in = fst out (j out?1 h '; id i j) in = cata-charn fst out out?1 h '; id i (j out?1 h '; id i j) = out-inv-charn fst h '; id i (j out?1 h '; id i j) ' (j out?1 h '; id i j) = ana-charn out (j out?1 h '; id i j) hfst out (j out?1 h '; id i j) ; snd out (j out?1 h '; id i j) i =, in-inv-charn h f; snd out (j out?1 = cata-charn hf; snd out out?1 h '; id i (j out?1 = out-inv-charn h f; snd h '; id i (j out?1 h f; (j out?1 (id (j out?1 ' [( h f; in?1 h '; id i j) in in?1 i h '; id i j) in?1 h '; id i j) in?1 i h '; id i j) in?1 i h '; id i j) ) h f; in?1 i i )] or any morphism ' : ( C )! C, let us now define the morphism fj ' jg :! C by letting fj ' jg = fst out (j out?1 h '; id i j) histo-de Morphisms of the form fj ' jg are called histomorphisms in this paper. The construction fj jg is easily seen to be a course-of-value iterator. By Lemma 3, the characterizing universal property for histomorphisms is the following: f in = ' [( h f; in?1 i )], f = fj ' jg histo-charn

19 Primitive (Co)Recursion and Course-of-Value (Co)Iteration, Categorically 19 The type information is summarized in the following diagram: [( h f;in?1 i )] ( C ) in ' C f EXAMPLE 13. The following is a neat histomorphic definition of the ibonacci function: bo = fj [ one; [ one snd; add (id (fst out N )) ] distl out N ] jg N The cancellation, reflection and fusion laws for histomorphisms are these: fj ' jg in = ' [( h fj ' jg ; in?1 )] histo-cancel id = fj in (fst out ) jg histo-rel f ' = [( (f id) out )] ) f fj ' jg = fj jg histo-usion The reflection law is proved by the following calculation: id = histo-charn in = functor in id = ana-charn = functor in (fst h id; in?1 i) in (fst (id [( h id; in?1 i )] ) h id; in?1 i) in (fst out [( h id; in?1 in (fst out ) [( h id; in?1 fj in (fst out ) jg i )] ) i )]

20 0 T. Uustalu and V. Vene The fusion law is proved as follows: f ' = [( (f id) out )] f fj ' jg = histo-charn fj jg f fj ' jg in = histo-charn f ' [( h fj ' jg; in?1 = i )] [( (f id) out )] [( h fj ' jg ; in?1 = functor ([( (f id) out )] [( h fj ' jg ; in?1 = ana-usion (f id) out [( h fj ' jg ; in?1 = ana-charn (f id) (id [( h fj ' jg ; in?1 h fj ' jg ; in?1 i (f [( h fj ' jg ; in?1 h f fj ' jg ; [( h fj ' jg ; in?1 (id [( h fj ' jg ; in?1 [( h f fj jg ; in?1 i )] i )] ) i )] i )] ) i )] ) h fj ' jg ; in?1 i i )] in?1 i i )] ) h f fj ' jg ; in?1 i i )] Similarly to paramorphisms, histomorphisms can be viewed as a generalization of catamorphisms: (j ' j) = fj ' (fst out ) jg histo-cata

21 Primitive (Co)Recursion and Course-of-Value (Co)Iteration, Categorically 1 This fact is verified by the following calculation: (j ' j) = histo-charn (j ' j) in = cata-charn ' (j ' j) ' (fst h (j ' j) ; in?1 i) ' (fst (id [( h (j ' j) ; in?1 i )] ) h (j ' j) ; in?1 i) = ana-charn i )] ) ' (fst out [( h (j ' j) ; in?1 = functor ' (fst out ) [( h (j ' j) ; in?1 i )] fj ' (fst out ) jg utumorphisms We now introduce a construction dual to histomorphisms. Let + denote the functor A + A X = A + X, + A h = id A + h. Then, given a morphism ' : C! ( + ), we define the morphism [f C ' g] : C! by letting [f ' g] = [( [ '; id ] in?1 + )] in + inl futu-de Our name for morphisms of the form [f ' g] is futumorphisms. The construction [f g] is the dual of a course-of-value iterator (a cocourse-of-argument coiterator). The characterizing universal property for futumorphisms is the following: out f = (j [ f; out?1 ] j) + ', f = [f ' g] futu-charn The type information is summarized in the following diagram: f C ' out ( + C ) (j [ f;out?1 ] j) +

22 T. Uustalu and V. Vene A straightforward dualization of the laws for histomorphisms gives laws for futumorphisms: out [f ' g] = (j [ [f ' g] ; out?1 ] j) + ' futu-cancel id = [f (in + inl) out g] futu-rel f = (j in + (f + id) j) + ' ) [f g] f = [f ' g] futu-usion [( ' )] = [f (in + inl) ' g] futu-ana EXAMPLE 1. The function exch : Stream A! Stream A, which pairwise exchanges the elements of any given argument, is characterized by the equation system head exch = head tail ^ head tail exch = head ^ tail tail exch = exch tail tail : This function is nicely definable as a futumorphism: exch = [f h head tail; in (SA) + inr h head ; in (S A) + inl tail tail i i g] S A :. Conclusion and further work We presented a categorical treatment of the function definition schemes of primitive recursion and course-of-value iteration and their duals. These schemes are generalizations of more basic schemes iteration and coiteration. While the value of an iterative function for a given argument depends solely on the values for its immediate subparts, the value of a primitive recursive function may additionally depend on these immediate subparts directly; the value of a course-of-value iterative function depends on the values for any subparts of the argument. Dually, the argument of a coiterative function for a value may only determine the argument for the immediate subparts of the value, whereas the argument of a primitive corecursive function may alternatively determine these immediate subparts directly; the argument of a cocourse-ofargument coiterative function may determine the arguments for any subparts of the value. Primitive (co)recursion and course-of-value (co)iteration, being more liberal than (co)iteration, make it easier to write programs and to prove properties about programs. Codatatypes and the associating notions such as coinduction and bisimulation are used widely in the analysis of processes specifiable by transition systems or state machines (Jacobs and Rutten, 1997). If processes are understood as functions from states (and, optionally, streams of input tokens) to behaviors, sequential composition of processes becomes a natural example of a function elegantly

23 Primitive (Co)Recursion and Course-of-Value (Co)Iteration, Categorically 3 definable as an apomorphism, whereas any concrete process specified by a finite transition or state machine becomes a natural example of a function elegantly definable as a futumorphism. This leads us to believe that apomorphisms and futumorphisms may turn out viable constructions in the modelling of processes. To check out this conjecture is one possible direction for continuing the work reported here. Acknowledgement The work reported here was partially supported by the Estonian Science oundation grant no. 97. The diagrams were produced using the Xy-pic macro package by Kristoffer H. Rose. Bibliography Bird, R. S. (1987). An introduction to the theory of lists. In M. Broy (Ed.), Logic of Programming and Calculi of Discrete Design (NATO ASI Series, Vol. 3). Springer-Verlag, Berlin. pp. 5. okkinga, M. M. (199). Law and Order in Algorithmics. PhD thesis, University of Twente. iv+11 pp. Geuvers, H. (199). Inductive and coinductive types with iteration and recursion. In B. Nordström, K. Pettersson, and G. Plotkin (Eds.), Informal Proceedings of the Workshop on Types for Proofs and Programs, Båstad, June 199. Dept. of Computer Sciences, Chalmers Univ. of Technology and Göteborg Univ. pp URL ftp://ftp.cs.chalmers.se/pub/cs-reports/baastad.9/. Grundy, J. (199). A browsable format for proof presentation. Mathesis Universalis,. URL Hagino, T. (1987). A Categorical Programming Language. PhD thesis CST-7-87, Univ. of Edinburgh. vii+180 pp. Jacobs, B., and J. Rutten. (1997). A tutorial on (co)algebras and (co)induction. Bulletin of the EATCS,, 59. Lambek, J. (198). A fixpoint theorem for complete categories. Mathematische Zeitschrift, 103, Malcolm, G. (1990). Data structures and program transformation. Science of Computer Programming, 1( 3), Meertens, L. (199). Paramorphisms. ormal Aspects of Computing, (5), 13. Turner, D. A. (1995). Elementary strong functional programming. In P. H. Hartel and R. Plasmeijer (Eds.), Proceedings of the 1st Internat. Symp. on unctional Programming Languages in education, PLE 95, Nijmegen, Dec (Lecture Notes in Computer Science, Vol. 10). Springer- Verlag, Berlin. pp Uustalu, T., and V. Vene. (1997). A cube of proof systems for the intuitionistic predicate -,-logic. In M. Haveraaen and O. Owe (Eds.), Selected Papers of the 8th Nordic Workshop on Programming Theory, NWPT 9, Oslo, Dec. 199, Research Report 8, Dept. of Informatics, Univ. of Oslo. pp. 37. Vene, V., and T. Uustalu. (1998). unctional programming with apomorphisms (corecursion). Proceedings of the Estonian Academy of Sciences: Physics, Mathematics, 7(3), Vesely, P. (1997). Typechecking the Charity term logic. Unpublished notes. 1 pp. URL Vos, T. (1995). Program Construction and Generation Based on Recursive Types. MSc thesis IN/SCR-95-1, Univ. of Utrecht. 35 pp. Received December 1998

24 T. Uustalu and V. Vene T. Uustalu received the MSc degree in system and computer sciences from the Tallinn Technical University in 199 and the PhD degree in computer science from the Royal Institute of Technology, Stockholm, Sweden, in Presently, he is a senior lecturer at the Royal Institute of Technology. His scientific interests include structural proof theory and theorem proving, semantics of programming languages, program verification, transformations, and construction, philosophy of logic and computing. V. Vene obtained the MSc degree in computer science from the University of Tartu, Estonia, in 199. He is a researcher and PhD student in computer science at the University of Tartu. His scientific interests are programming language design and implementation, functional programming, type theory, semantics based program manipulation, category theory.

Primitive (Co)Recursion and Course-of-Value (Co)Iteration, Categorically

Primitive (Co)Recursion and Course-of-Value (Co)Iteration, Categorically INORMATICA, 1999, Vol. 10, No. 1, 5 26 5 1999 Institute of Mathematics and Informatics, Vilnius Primitive (Co)Recursion and Course-of-Value (Co)Iteration, Categorically Tarmo UUSTALU Dept. of Teleinformatics,

More information

When is a function a fold or an unfold?

When is a function a fold or an unfold? When is a function a fold or an unfold? Jeremy Gibbons University of Oxford Graham Hutton University of Nottingham Thorsten Altenkirch University of Nottingham April 29, 2002 Abstract We give a necessary

More information

1. The Method of Coalgebra

1. The Method of Coalgebra 1. The Method of Coalgebra Jan Rutten CWI Amsterdam & Radboud University Nijmegen IMS, Singapore - 15 September 2016 Overview of Lecture one 1. Category theory (where coalgebra comes from) 2. Algebras

More information

Coalgebras and Codata in Agda

Coalgebras and Codata in Agda Coalgebras and Codata in Agda Anton Setzer Swansea University (Wales, UK) (Wessex Seminar, Bath, 3 March 2009) 1. The concept of codata. 2. Codata in Agda. 3. Weakly Final Coalgebras in Dependent Type

More information

The Nottingham eprints service makes this work by researchers of the University of Nottingham available open access under the following conditions.

The Nottingham eprints service makes this work by researchers of the University of Nottingham available open access under the following conditions. Gibbons, Jeremy and Hutton, Graham and Altenkirch, Thorsten (2001) When is a function a fold or an unfold? In: Workshop on Coalgebraic Methods in Computer Science (4th), 6-7 April 2001, Genova, Italy.

More information

Program Fusion with Paramorphisms

Program Fusion with Paramorphisms Facundo Domínguez and Alberto Pardo Instituto de Computación, Universidad de la República Julio Herrera y Reissig 565, 11300 Montevideo, Uruguay {fdomin,pardo}@fing.edu.uy Abstract The design of programs

More information

Generic Accumulations for Program Calculation

Generic Accumulations for Program Calculation Generic Accumulations for Program Calculation Mauro Jaskelioff Facultad de Cs. Exactas, Ingeniería y Agrimensura Universidad Nacional de Rosario Rosario - Argentina mauro@fceia.unr.edu.ar December 2004

More information

Realization of Coinductive Types

Realization of Coinductive Types MFPS 2011 Realization of Coinductive Types Dexter Kozen 1,2 Department of Computer Science Cornell University Ithaca, New York 14853 7501, USA Abstract We give an explicit combinatorial construction of

More information

Notes on Algebra of Programming

Notes on Algebra of Programming Notes on Algebra of Programming Glenn Strong Department of Computer Science Trinity College, Dublin Dublin Ireland Glenn.Strong@cs.tcd.ie December 15, 1999 1 Background In the book Algebra of Programming

More information

Proof Methods for Corecursive Programs. 1. Introduction. Jeremy Gibbons. Graham Hutton

Proof Methods for Corecursive Programs. 1. Introduction. Jeremy Gibbons. Graham Hutton Fundamenta Informaticae XX (2005) 1 14 1 IOS Press Proof Methods for Corecursive Programs Jeremy Gibbons Oxford University Computing Laboratory, UK Graham Hutton School of Computer Science and IT, University

More information

Total (Co)Programming with Guarded Recursion

Total (Co)Programming with Guarded Recursion Total (Co)Programming with Guarded Recursion Andrea Vezzosi Department of Computer Science and Engineering Chalmers University of Technology, Gothenburg, Sweden Types for Proofs and Programs Annual Meeting

More information

Recursive coalgebras from comonads,

Recursive coalgebras from comonads, Information and Computation 204 (2006) 437 468 www.elsevier.com/locate/ic Recursive coalgebras from comonads, Venanzio Capretta a,1, Tarmo Uustalu b,,2, Varmo Vene c,2 a Department of Mathematics and Statistics,

More information

Towards a Flowchart Diagrammatic Language for Monad-based Semantics

Towards a Flowchart Diagrammatic Language for Monad-based Semantics Towards a Flowchart Diagrammatic Language or Monad-based Semantics Julian Jakob Friedrich-Alexander-Universität Erlangen-Nürnberg julian.jakob@au.de 21.06.2016 Introductory Examples 1 2 + 3 3 9 36 4 while

More information

SOME PROPERTIES OF COALGEBRAS AND THEIR RÔLE IN COMPUTER SCIENCE

SOME PROPERTIES OF COALGEBRAS AND THEIR RÔLE IN COMPUTER SCIENCE Journal of Applied Mathematics and Computational Mechanics 2016, 15(4), 145-156 www.amcm.pcz.pl p-issn 2299-9965 DOI: 10.17512/jamcm.2016.4.16 e-issn 2353-0588 SOME PROPERTIES OF COALGEBRAS AND THEIR RÔLE

More information

The Under-Performing Unfold

The Under-Performing Unfold The Under-Performing Unfold A new approach to optimising corecursive programs Jennifer Hackett Graham Hutton University of Nottingham {jph,gmh}@cs.nott.ac.uk Mauro Jaskelioff Universidad Nacional de Rosario,

More information

Transformation of Corecursive Graphs

Transformation of Corecursive Graphs Transformation of Corecursive Graphs Towards M-Adhesive Categories of Corecursive Graphs Julia Padberg 10.2.2017 Padberg Transformation of Corecursive Graphs 10.2.2017 1 Motivation Table of Contents 1

More information

Datatype-Generic Termination Proofs

Datatype-Generic Termination Proofs Datatype-Generic Termination Proofs Roland Backhouse and Henk Doornbos rcb@cs.nott.ac.uk School of Computer Science and Information Technology, University of Nottingham, Nottingham NG8 1BB, England, henk.doornbos@questance.com

More information

Parameterizations and Fixed-Point Operators on Control Categories

Parameterizations and Fixed-Point Operators on Control Categories Parameterizations and Fixed-Point Operators on Control Categories oshihiko Kakutani 1 and Masahito Hasegawa 12 1 Research Institute for Mathematical Sciences, Kyoto University {kakutani,hassei}@kurims.kyoto-u.ac.jp

More information

Modeling and reasoning with I-polynomial data types

Modeling and reasoning with I-polynomial data types Modeling and reasoning with I-polynomial data types Peter Padawitz, TU Dortmund, Germany September 1, 2017 (actual version: http://fldit-www.cs.uni-dortmund.de/ peter/ifip2016.pdf) 1 Road map Some examples

More information

Wolfgang Jeltsch. Seminar talk at the Institute of Cybernetics Tallinn, Estonia

Wolfgang Jeltsch. Seminar talk at the Institute of Cybernetics Tallinn, Estonia in in Brandenburgische Technische Universität Cottbus Cottbus, Germany Seminar talk at the Institute of Cybernetics Tallinn, Estonia February 10, 2011 in in in trueness of a proposition depends on time

More information

An introduction to (co)algebra and (co)induction

An introduction to (co)algebra and (co)induction 1 An introduction to (co)algebra and (co)induction 1.1 Introduction Algebra is a well-established part of mathematics, dealing with sets with operations satisfying certain properties, like groups, rings,

More information

Algebraic Geometry

Algebraic Geometry MIT OpenCourseWare http://ocw.mit.edu 18.726 Algebraic Geometry Spring 2009 For information about citing these materials or our Terms of Use, visit: http://ocw.mit.edu/terms. 18.726: Algebraic Geometry

More information

Conceptual Connections of Circularity and Category Theory

Conceptual Connections of Circularity and Category Theory 1/64 Conceptual Connections of Circularity and Category Theory Larry Moss Indiana University, Bloomington ESSLLI 2012, Opole 2/64 The conceptual comparison chart Filling out the details is my goal for

More information

University of Oxford, Michaelis November 16, Categorical Semantics and Topos Theory Homotopy type theor

University of Oxford, Michaelis November 16, Categorical Semantics and Topos Theory Homotopy type theor Categorical Semantics and Topos Theory Homotopy type theory Seminar University of Oxford, Michaelis 2011 November 16, 2011 References Johnstone, P.T.: Sketches of an Elephant. A Topos-Theory Compendium.

More information

Isomorphism of Finitary Inductive Types

Isomorphism of Finitary Inductive Types Isomorphism of Finitary Inductive Types Christian Sattler joint work (in progress) with Nicolai Kraus University of Nottingham May 2014 Motivating Example Generic data may be represented in a multitude

More information

Productive functions as Term-coalgebra anamorphisms in Coq

Productive functions as Term-coalgebra anamorphisms in Coq Productive functions as Term-coalgebra anamorphisms in Coq Clemens Kupke, Milad Niqui and Jan Rutten April 26, 2010 Abstract We present a method for implementing a class of productive functions in Coq.

More information

Consequence Relations and Natural Deduction

Consequence Relations and Natural Deduction Consequence Relations and Natural Deduction Joshua D. Guttman Worcester Polytechnic Institute September 9, 2010 Contents 1 Consequence Relations 1 2 A Derivation System for Natural Deduction 3 3 Derivations

More information

Distributive laws for the Coinductive Solution of Recursive Equations

Distributive laws for the Coinductive Solution of Recursive Equations Distributive laws for the Coinductive Solution of Recursive Equations Bart Jacobs Institute for Computing and Information Sciences, Radboud University Nijmegen P.O. Box 9010, 6500 GL Nijmegen, The Netherlands

More information

Logic for Computational Effects: work in progress

Logic for Computational Effects: work in progress 1 Logic for Computational Effects: work in progress Gordon Plotkin and John Power School of Informatics University of Edinburgh King s Buildings Mayfield Road Edinburgh EH9 3JZ Scotland gdp@inf.ed.ac.uk,

More information

Reasoning about Codata

Reasoning about Codata 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/ Abstract.

More information

Automated Reasoning Lecture 17: Inductive Proof (in Isabelle)

Automated Reasoning Lecture 17: Inductive Proof (in Isabelle) Automated Reasoning Lecture 17: Inductive Proof (in Isabelle) Jacques Fleuriot jdf@inf.ed.ac.uk Recap Previously: Unification and Rewriting This time: Proof by Induction (in Isabelle) Proof by Mathematical

More information

Proofs and computations

Proofs and computations (j.w.w. Kenji Miyamoto) Mathematisches Institut, LMU, München Leeds University, 7. March 2012 Formalization and extraction One can extract from a (constructive) proof of a formula with computational content

More information

ESSLLI 2010 CHP INTRODUCTION TO CATEGORY THEORY, ALGEBRAS AND COALGEBRA. Stefan Milius

ESSLLI 2010 CHP INTRODUCTION TO CATEGORY THEORY, ALGEBRAS AND COALGEBRA. Stefan Milius ESSLLI 2010 CHP INTRODUCTION TO CATEGORY THEORY, ALGEBRAS AND COALGEBRA Jiří Adámek Stefan Milius This is the course material for our one week course at ESSLLI 2010. The course consists of two parts. The

More information

A categorical model for a quantum circuit description language

A categorical model for a quantum circuit description language A categorical model for a quantum circuit description language Francisco Rios (joint work with Peter Selinger) Department of Mathematics and Statistics Dalhousie University CT July 16th 22th, 2017 What

More information

Topos Theory. Lectures 17-20: The interpretation of logic in categories. Olivia Caramello. Topos Theory. Olivia Caramello.

Topos Theory. Lectures 17-20: The interpretation of logic in categories. Olivia Caramello. Topos Theory. Olivia Caramello. logic s Lectures 17-20: logic in 2 / 40 logic s Interpreting first-order logic in In Logic, first-order s are a wide class of formal s used for talking about structures of any kind (where the restriction

More information

Technical Report No Proofs Accompanying Fast and Loose Reasoning is Morally Correct NILS ANDERS DANIELSSON

Technical Report No Proofs Accompanying Fast and Loose Reasoning is Morally Correct NILS ANDERS DANIELSSON Technical Report No. 07-15 Proofs Accompanying Fast and Loose Reasoning is Morally Correct NILS ANDERS DANIELSSON Department of Computer Science and Engineering Division of Computing Science CHALMERS UNIVERSITY

More information

Higher Order Containers

Higher Order Containers Higher Order Containers Thorsten Altenkirch 1, Paul Levy 2, and Sam Staton 3 1 University of Nottingham 2 University of Birmingham 3 University of Cambridge Abstract. Containers are a semantic way to talk

More information

Transformational programming and forests

Transformational programming and forests Transformational programming and forests AB18 1 A. Bijlsma Eindhoven University of Technology Department of Mathematics and Computing Science P.O. Box 513, 5600 MB Eindhoven, The Netherlands Introduction

More information

Streams and Coalgebra Lecture 2

Streams and Coalgebra Lecture 2 Streams and Coalgebra Lecture 2 Helle Hvid Hansen and Jan Rutten Radboud University Nijmegen & CWI Amsterdam Representing Streams II, Lorentz Center, Leiden, January 2014 Tutorial Overview Lecture 1 (Hansen):

More information

When is a function a fold or an unfold?

When is a function a fold or an unfold? Electronic Notes in Theoretical Computer Science 44 No. 1 (2001) URL: http://www.elsevier.nl/locate/entcs/volume44.html 15 pages When is a function a fold or an unfold? Jeremy Gibbons Oxford University

More information

via Topos Theory Olivia Caramello University of Cambridge The unification of Mathematics via Topos Theory Olivia Caramello

via Topos Theory Olivia Caramello University of Cambridge The unification of Mathematics via Topos Theory Olivia Caramello in University of Cambridge 2 / 23 in in In this lecture, whenever I use the word topos, I really mean Grothendieck topos. Recall that a Grothendieck topos can be seen as: a generalized space a mathematical

More information

sset(x, Y ) n = sset(x [n], Y ).

sset(x, Y ) n = sset(x [n], Y ). 1. Symmetric monoidal categories and enriched categories In practice, categories come in nature with more structure than just sets of morphisms. This extra structure is central to all of category theory,

More information

Coinductive big-step semantics and Hoare logics for nontermination

Coinductive big-step semantics and Hoare logics for nontermination Coinductive big-step semantics and Hoare logics for nontermination Tarmo Uustalu, Inst of Cybernetics, Tallinn joint work with Keiko Nakata COST Rich Models Toolkit meeting, Madrid, 17 18 October 2013

More information

Generic Fibrational Induction

Generic Fibrational Induction Archived version from NCDOCKS Institutional Repository http://libres.uncg.edu/ir/asu/ Generic Fibrational Induction By: Ghani, Neil; Johann, Patricia; and Fumex, Clement Abstract This paper provides an

More information

Functor Pulling. Lambert Meertens

Functor Pulling. Lambert Meertens Functor Pulling Lambert Meertens Department of Algorithmics and Architecture, CWI, Amsterdam, and Department of Computing Science, Utrecht University, The Netherlands www.cwi.nl/ lambert 1 Introduction

More information

Equality of Streams is a Π 0 2-Complete Problem

Equality of Streams is a Π 0 2-Complete Problem Equality of Streams is a Π 0 2-Complete Problem Grigore Roşu Department of Computer Science, University of Illinois at Urbana-Champaign grosu@cs.uiuc.edu Abstract This paper gives a precise characterization

More information

19. Basis and Dimension

19. Basis and Dimension 9. Basis and Dimension In the last Section we established the notion of a linearly independent set of vectors in a vector space V and of a set of vectors that span V. We saw that any set of vectors that

More information

Algebras. Larry Moss Indiana University, Bloomington. TACL 13 Summer School, Vanderbilt University

Algebras. Larry Moss Indiana University, Bloomington. TACL 13 Summer School, Vanderbilt University 1/39 Algebras Larry Moss Indiana University, Bloomington TACL 13 Summer School, Vanderbilt University 2/39 Binary trees Let T be the set which starts out as,,,, 2/39 Let T be the set which starts out as,,,,

More information

Bringing class diagrams to life

Bringing class diagrams to life Bringing class diagrams to life Luis S. Barbosa & Sun Meng DI-CCTC, Minho University, Braga & CWI, Amsterdam UML & FM Workshop 2009 Rio de Janeiro 8 December, 2009 Formal Methods proofs problems structures

More information

GENERAL RECURSION VIA COINDUCTIVE TYPES

GENERAL RECURSION VIA COINDUCTIVE TYPES Logical Methods in Computer Science Vol. 1 (2:1) 2005, pp. 1 28 www.lmcs-online.org Submitted Dec. 22, 2004 Published Jul. 13, 2005 GENERAL RECURSION VIA COINDUCTIVE TYPES VENANZIO CAPRETTA Department

More information

Homological Algebra and Differential Linear Logic

Homological Algebra and Differential Linear Logic Homological Algebra and Differential Linear Logic Richard Blute University of Ottawa Ongoing discussions with Robin Cockett, Geoff Cruttwell, Keith O Neill, Christine Tasson, Trevor Wares February 24,

More information

MATH 101B: ALGEBRA II PART A: HOMOLOGICAL ALGEBRA

MATH 101B: ALGEBRA II PART A: HOMOLOGICAL ALGEBRA MATH 101B: ALGEBRA II PART A: HOMOLOGICAL ALGEBRA These are notes for our first unit on the algebraic side of homological algebra. While this is the last topic (Chap XX) in the book, it makes sense to

More information

1.1.1 Algebraic Operations

1.1.1 Algebraic Operations 1.1.1 Algebraic Operations We need to learn how our basic algebraic operations interact. When confronted with many operations, we follow the order of operations: Parentheses Exponentials Multiplication

More information

Classical Program Logics: Hoare Logic, Weakest Liberal Preconditions

Classical Program Logics: Hoare Logic, Weakest Liberal Preconditions Chapter 1 Classical Program Logics: Hoare Logic, Weakest Liberal Preconditions 1.1 The IMP Language IMP is a programming language with an extensible syntax that was developed in the late 1960s. We will

More information

COMMUTATIVE ALGEBRA LECTURE 1: SOME CATEGORY THEORY

COMMUTATIVE ALGEBRA LECTURE 1: SOME CATEGORY THEORY COMMUTATIVE ALGEBRA LECTURE 1: SOME CATEGORY THEORY VIVEK SHENDE A ring is a set R with two binary operations, an addition + and a multiplication. Always there should be an identity 0 for addition, an

More information

Structural Foundations for Abstract Mathematics

Structural Foundations for Abstract Mathematics May 5, 2013 What no foundation can give us: Certainty What foundations need not give us: Ontological reduction What set theory gives us: Common language in which all mathematics can be encoded:,,,... Dispute

More information

Recursion in Coalgebras

Recursion in Coalgebras Recursion in Coalgebras Mauro Jaskelioff mjj@cs.nott.ac.uk School of Computer Science & IT FoP Away Day 2007 Outline Brief overview of coalgebras. The problem of divergence when considering unguarded recursion.

More information

Duality in Probabilistic Automata

Duality in Probabilistic Automata Duality in Probabilistic Automata Chris Hundt Prakash Panangaden Joelle Pineau Doina Precup Gavin Seal McGill University MFPS May 2006 Genoa p.1/40 Overview We have discovered an - apparently - new kind

More information

Science of Computer Programming

Science of Computer Programming Science of Computer Programming 78 (2013) 2108 2159 Contents lists available at ScienceDirect Science of Computer Programming journal homepage: www.elsevier.com/locate/scico Adjoint folds and unfolds An

More information

Abstracting away from cell complexes

Abstracting away from cell complexes Abstracting away from cell complexes Michael Shulman 1 Peter LeFanu Lumsdaine 2 1 University of San Diego 2 Stockholm University March 12, 2016 Replacing big messy cell complexes with smaller and simpler

More information

Boolean Algebra and Propositional Logic

Boolean Algebra and Propositional Logic Boolean Algebra and Propositional Logic Takahiro Kato June 23, 2015 This article provides yet another characterization of Boolean algebras and, using this characterization, establishes a more direct connection

More information

What are Iteration Theories?

What are Iteration Theories? What are Iteration Theories? Jiří Adámek and Stefan Milius Institute of Theoretical Computer Science Technical University of Braunschweig Germany adamek,milius @iti.cs.tu-bs.de Jiří Velebil Department

More information

The algebraicity of the lambda-calculus

The algebraicity of the lambda-calculus The algebraicity of the lambda-calculus André Hirschowitz 1 and Marco Maggesi 2 1 Université de Nice Sophia Antipolis http://math.unice.fr/~ah 2 Università degli Studi di Firenze http://www.math.unifi.it/~maggesi

More information

Sequents are written as A, where A; B represent formulae and ; represent multisets of formulae. Where represents the multiset A 1 ; : : : ; A n, then!

Sequents are written as A, where A; B represent formulae and ; represent multisets of formulae. Where represents the multiset A 1 ; : : : ; A n, then! What is a Categorical Model of ntuitionistic Linear Logic G.M. Bierman University of Cambridge Computer Laboratory Abstract. This paper re-addresses the old problem of providing a categorical model for

More information

A brief Introduction to Category Theory

A brief Introduction to Category Theory A brief Introduction to Category Theory Dirk Hofmann CIDMA, Department of Mathematics, University of Aveiro, 3810-193 Aveiro, Portugal Office: 11.3.10, dirk@ua.pt, http://sweet.ua.pt/dirk/ October 9, 2017

More information

A note on coinduction and weak bisimilarity for while programs

A note on coinduction and weak bisimilarity for while programs Centrum voor Wiskunde en Informatica A note on coinduction and weak bisimilarity for while programs J.J.M.M. Rutten Software Engineering (SEN) SEN-R9826 October 31, 1998 Report SEN-R9826 ISSN 1386-369X

More information

3.2 Reduction 29. Truth. The constructor just forms the unit element,. Since there is no destructor, there is no reduction rule.

3.2 Reduction 29. Truth. The constructor just forms the unit element,. Since there is no destructor, there is no reduction rule. 32 Reduction 29 32 Reduction In the preceding section, we have introduced the assignment of proof terms to natural deductions If proofs are programs then we need to explain how proofs are to be executed,

More information

Categorical axioms for functional real-number computation

Categorical axioms for functional real-number computation Categorical axioms for functional real-number computation Parts 1 & 2 Martín Escardó University of Birmingham, England Joint work with Alex Simpson, University of Edinburgh, Scotland MAP, Leiden, 28 Nov

More information

Boolean Algebra and Propositional Logic

Boolean Algebra and Propositional Logic Boolean Algebra and Propositional Logic Takahiro Kato September 10, 2015 ABSTRACT. This article provides yet another characterization of Boolean algebras and, using this characterization, establishes a

More information

Bicubical Directed Type Theory

Bicubical Directed Type Theory Bicubical Directed Type Theory Matthew Weaver General Examination May 7th, 2018 Advised by Andrew Appel and Dan Licata Bicubical Directed Type Theory Bicubical directed type theory is a constructive model

More information

Category Theory. Categories. Definition.

Category Theory. Categories. Definition. Category Theory Category theory is a general mathematical theory of structures, systems of structures and relationships between systems of structures. It provides a unifying and economic mathematical modeling

More information

Preliminaries. Chapter 3

Preliminaries. Chapter 3 Chapter 3 Preliminaries In the previous chapter, we studied coinduction for languages and deterministic automata. Deterministic automata are a special case of the theory of coalgebras, which encompasses

More information

Proving Completeness for Nested Sequent Calculi 1

Proving Completeness for Nested Sequent Calculi 1 Proving Completeness for Nested Sequent Calculi 1 Melvin Fitting abstract. Proving the completeness of classical propositional logic by using maximal consistent sets is perhaps the most common method there

More information

p,q H (X), H (Y ) ), where the index p has the same meaning as the

p,q H (X), H (Y ) ), where the index p has the same meaning as the There are two Eilenberg-Moore spectral sequences that we shall consider, one for homology and the other for cohomology. In contrast with the situation for the Serre spectral sequence, for the Eilenberg-Moore

More information

2. Prime and Maximal Ideals

2. Prime and Maximal Ideals 18 Andreas Gathmann 2. Prime and Maximal Ideals There are two special kinds of ideals that are of particular importance, both algebraically and geometrically: the so-called prime and maximal ideals. Let

More information

DRAFT DRAFT. Introduction to Coalgebra. Towards Mathematics of States and Observations. Bart Jacobs. Draft Copy.

DRAFT DRAFT. Introduction to Coalgebra. Towards Mathematics of States and Observations. Bart Jacobs. Draft Copy. Introduction to Coalgebra. Towards Mathematics of States and Observations Bart Jacobs Institute for Computing and Information Sciences, Radboud University Nijmegen, P.O. Box 9010, 6500 GL Nijmegen, The

More information

Between Functions and Relations in Calculating Programs

Between Functions and Relations in Calculating Programs Between Functions and Relations in Calculating Programs Graham Muir Hutton A thesis submitted for the degree of Ph.D. at the Department of Computing Science, University of Glasgow 16th October 1992 Abstract

More information

Lecture Notes on Data Abstraction

Lecture Notes on Data Abstraction Lecture Notes on Data Abstraction 15-814: Types and Programming Languages Frank Pfenning Lecture 14 October 23, 2018 1 Introduction Since we have moved from the pure λ-calculus to functional programming

More information

Beyond First-Order Logic

Beyond First-Order Logic Beyond First-Order Logic Software Formal Verification Maria João Frade Departmento de Informática Universidade do Minho 2008/2009 Maria João Frade (DI-UM) Beyond First-Order Logic MFES 2008/09 1 / 37 FOL

More information

The Lambek-Grishin calculus for unary connectives

The Lambek-Grishin calculus for unary connectives The Lambek-Grishin calculus for unary connectives Anna Chernilovskaya Utrecht Institute of Linguistics OTS, Utrecht University, the Netherlands anna.chernilovskaya@let.uu.nl Introduction In traditional

More information

Multiple Intermediate Structure Deforestation by Shortcut Fusion

Multiple Intermediate Structure Deforestation by Shortcut Fusion Multiple Intermediate Structure Deforestation by Shortcut Fusion Alberto Pardo 1, João P. Fernandes 2,3, and João Saraiva 2 1 Instituto de Computación, Universidad de la República, Uruguay pardo@fing.edu.uy

More information

Copatterns Programming Infinite Objects by Observations

Copatterns Programming Infinite Objects by Observations Copatterns Programming Infinite Objects by Observations Andreas Abel Department of Computer Science Ludwig-Maximilians-University Munich Mathematical Logic Seminar Ludwig-Maximilians-University Munich

More information

Witnessing (Co)datatypes

Witnessing (Co)datatypes Witnessing (Co)datatypes Jasmin Christian Blanchette 1,2, Andrei Popescu 3, and Dmitriy Traytel 4 1 Inria Nancy & LORIA, Villers-lès-Nancy, France 2 Max-Planck-Institut für Informatik, Saarbrücken, Germany

More information

chapter 12 MORE MATRIX ALGEBRA 12.1 Systems of Linear Equations GOALS

chapter 12 MORE MATRIX ALGEBRA 12.1 Systems of Linear Equations GOALS chapter MORE MATRIX ALGEBRA GOALS In Chapter we studied matrix operations and the algebra of sets and logic. We also made note of the strong resemblance of matrix algebra to elementary algebra. The reader

More information

Concrete Stream Calculus

Concrete Stream Calculus Under consideration for publication in J. Functional Programming 1 Concrete Stream Calculus An extended study RALF HINZE Computing Laboratory, University of Oxford, Wolfson Building, Parks Road, Oxford,

More information

Streams and Coalgebra Lecture 1

Streams and Coalgebra Lecture 1 Streams and Coalgebra Lecture 1 Helle Hvid Hansen and Jan Rutten Radboud University Nijmegen & CWI Amsterdam Representing Streams II, Lorentz Center, Leiden, January 2014 Tutorial Overview Lecture 1 (Hansen):

More information

Logical Preliminaries

Logical Preliminaries Logical Preliminaries Johannes C. Flieger Scheme UK March 2003 Abstract Survey of intuitionistic and classical propositional logic; introduction to the computational interpretation of intuitionistic logic

More information

Syntactic Characterisations in Model Theory

Syntactic Characterisations in Model Theory Department of Mathematics Bachelor Thesis (7.5 ECTS) Syntactic Characterisations in Model Theory Author: Dionijs van Tuijl Supervisor: Dr. Jaap van Oosten June 15, 2016 Contents 1 Introduction 2 2 Preliminaries

More information

Type Theory and Constructive Mathematics. Type Theory and Constructive Mathematics Thierry Coquand. University of Gothenburg

Type Theory and Constructive Mathematics. Type Theory and Constructive Mathematics Thierry Coquand. University of Gothenburg Type Theory and Constructive Mathematics Type Theory and Constructive Mathematics Thierry Coquand University of Gothenburg Content An introduction to Voevodsky s Univalent Foundations of Mathematics The

More information

Relational semantics for a fragment of linear logic

Relational semantics for a fragment of linear logic Relational semantics for a fragment of linear logic Dion Coumans March 4, 2011 Abstract Relational semantics, given by Kripke frames, play an essential role in the study of modal and intuitionistic logic.

More information

Theoretical pearl - Church numerals, twice!

Theoretical pearl - Church numerals, twice! See discussions, stats, and author profiles for this publication at: https://www.researchgate.net/publication/231890309 Theoretical pearl - Church numerals, twice! Article in Journal of Functional Programming

More information

Conservation of Information

Conservation of Information Conservation of Information Amr Sabry (in collaboration with Roshan P. James) School of Informatics and Computing Indiana University May 8, 2012 Amr Sabry (in collaboration with Roshan P. James) (IU SOIC)

More information

CHAPTER 3: THE INTEGERS Z

CHAPTER 3: THE INTEGERS Z CHAPTER 3: THE INTEGERS Z MATH 378, CSUSM. SPRING 2009. AITKEN 1. Introduction The natural numbers are designed for measuring the size of finite sets, but what if you want to compare the sizes of two sets?

More information

Lecture Notes on Combinatory Modal Logic

Lecture Notes on Combinatory Modal Logic Lecture Notes on Combinatory Modal Logic 15-816: Modal Logic Frank Pfenning Lecture 9 February 16, 2010 1 Introduction The connection between proofs and program so far has been through a proof term assignment

More information

A Translation from Attribute Grammars to CatamorpMsms

A Translation from Attribute Grammars to CatamorpMsms A Translation from Attribute Grammars to CatamorpMsms Maarten Fokkinga, Johan Jeuring, Lambert Meertens, Erik Meijer November 9, 1990 Let A G be an attribute grammar, with underlying context free grammar

More information

(a) Definition of TMs. First Problem of URMs

(a) Definition of TMs. First Problem of URMs Sec. 4: Turing Machines First Problem of URMs (a) Definition of the Turing Machine. (b) URM computable functions are Turing computable. (c) Undecidability of the Turing Halting Problem That incrementing

More information

Adjunctions! Everywhere!

Adjunctions! Everywhere! Adjunctions! Everywhere! Carnegie Mellon University Thursday 19 th September 2013 Clive Newstead Abstract What do free groups, existential quantifiers and Stone-Čech compactifications all have in common?

More information

Categories of Coalgebraic Games with Selective Sum

Categories of Coalgebraic Games with Selective Sum Fundamenta Informaticae XX (2014) 1 20 1 DOI 10.3233/FI-2012-0000 IOS Press Categories of Coalgebraic Games with Selective Sum Furio Honsell Dipartimento di Matematica e Informatica, Università di Udine,

More information

Code Generation for a Simple First-Order Prover

Code Generation for a Simple First-Order Prover Code Generation for a Simple First-Order Prover Jørgen Villadsen, Anders Schlichtkrull, and Andreas Halkjær From DTU Compute, Technical University of Denmark, 2800 Kongens Lyngby, Denmark Abstract. We

More information

Propositions and Proofs

Propositions and Proofs Chapter 2 Propositions and Proofs The goal of this chapter is to develop the two principal notions of logic, namely propositions and proofs There is no universal agreement about the proper foundations

More information