Recursive Coalgebras from Comonads

Total Page:16

File Type:pdf, Size:1020Kb

Recursive Coalgebras from Comonads ' $ Recursive coalgebras from comonads Venanzio Capretta (U. of Ottawa) Tarmo Uustalu (Inst. of Cybernetics, Tallinn) Varmo Vene (U. of Tartu) Braga, 23 Jan. 2006 & 1 % ' $ Motivation ² It is handy to de¯ne functions using (general) recursion, but when is this justi¯ed, i.e, in which situations can we be sure that the equation we want to rely on has a unique solution? ² Approches: inductive, coinductive types, structured recursion, corecursion schemes, guarded-by-destructors recursion, guarded-by-constructors corecursion; general totality/termination/productivity analysis methodologies. ² Structured recursion/corecursion for initial algebras/¯nal coalgebras: Lenisa (et al.), Uustalu-Vene-Pardo, Bartels. & 2 % ' $ ² This talk: Osius' recursive coalgebras (in opposition to initial algebras, i.e., inductive types) { as a framework to deal with guarded-by-destructors recursion generically, { generalizing Uustalu-Vene-Pardo and Bartels. ² Everything dualizes: Could just as well do completely iterative algebras (in opposition to ¯nal coalgebras) to deal with guarded-by-constructors corecursion. & 3 % ' $ Outline ² Recursive coalgebras: motivation, de¯nition, examples ² Basic properties ² Two variations: strongly recursive coalgebras, parametrically recursive coalgebras. ² Recursive coalgebras from comonads ² Recursive coalgebras from (cofree comonads of) functors & 4 % ' $ Recursive coalgebras: motivation ² Think of quicksort: Let Z be a set linearly ordered by ·. One usually de¯nes quicksort recursively. qsort: ListZ ! ListZ qsort [] = [] qsort (x : l) = qsort(l·x) ++ (x : qsort(l>x)) ² Why does this recursive (a priori dubious) \de¯nition" actually qualify as a de¯nition, i.e., how do we know the underlying equation has a unique solution? ² Notice the equation has the form qsort = ©(qsort) where © : Set(ListZ; ListZ) ! Set(ListZ; ListZ). This is quite unstructured. & 5 % ' $ ² With a minimal rearrangement of the equation, we see it has a clear overt structure. We can rewrite it as qsort = qmerge ± BTqsort ± qsplit where BTZ X = 1 + Z £ X £ X, i.e. qsplit 1 + Z £ ListZ £ ListZ o ListZ id+id£qsort£qsort qsort ² qmerge ² 1 + Z £ ListZ £ ListZ / ListZ & 6 % ' $ ² Preparation of argument values for recursive calls: qsplit: ListZ ! 1 + Z £ ListZ £ ListZ qsplit [] = inl(¤) qsplit (x : l) = inr(hx; l·x; l>xi) ² Calculating the main call return value from the recursive calls return values. qmerge: 1 + Z £ ListZ £ ListZ ! ListZ qmerge inl(¤) = [] qmerge inr(hx; l1; l2i) = l1 ++ (x : l2) ² So why the does equation make sense as a de¯nition? Because qsplit sends a list to a container of strictly shorter lists. That the result type was ListZ and that the assembling function was qmerge did not play any role, we replace them with something else and the equation is still a de¯nition. & 7 % ' $ Recursive coalgebras: definition ² Def. Let F : C ! C be a functor. A coalgebra-to-algebra morphism from an F -coalgebra (A; ®) to an F -algebra (C; ') is a morphism f : A ! C such that ® F A o A F f f ² ' ² F C / C ² An F -coalgebra (A; ®) is recursive (or algebra-initial) i® for every F -algebra (C; ') there exists a unique coalgebra-to-algebra morphism from (A; ®) to (C; '), denoted ¯xF;®('). ² [An F -algebra (C; ') is completely iterative (or coalgebra-¯nal) i® for every F -coalgebra (A; ®) there exists a unique coalgebra-to-algebra morphism from (A; ®) to (C; '), denoted co¯xF;'®.] & 8 % ' $ ² Cf. \hylomorphisms" from functional programming: Let F : C ! C be a functor with an initial algebra whose inverse is its ¯nal coalgebra (always the case if C is algebraically compact). Then for any F -coalgebra (A; ®) and F -algebra (C; '), there is a canonical (but not at all unique in general) coalgebra-to-algebra morphism: ® F A o A F CoitF ( ® ) CoitF ( ® ) ² inF ² * ² F (¹F ) m ¹F ¡1 inF F ItF ( ' ) ItF ( ' ) ² ' ² F C / C & 9 % ' $ Examples ² Consider any functor F : C ! C with an initial algebra, (¹F; inF ). ¡1 ² The F -coalgebra (¹F; inF ) is recursive (iteration). ¡1 in F (¹F ) o F ¹F F f 9!f ² 8' ² F C / C ¡1 ² But also: The F (Id £ K¹F )-algebra (¹F; F h id¹F ; id¹F i ± inF ) (primitive recursion) ¡1 F h id¹F ;id¹F i in F (¹F £ ¹F ) o F (¹F ) o F ¹F F (f£id¹F ) 9!f ² 8' ² F (C £ ¹F ) / C & 10 % ' $ ¡1 ¡1 ² But also: The F (Id £ F )-coalgebra (¹F; F h id¹F ; inF i ± inF ) (iteration back one or two steps). ¡1 ¡1 F h id¹F ;in i in F (¹F £ F (¹F )) o F F (¹F ) o F ¹F F (f£F f) 9!f ² 8' ² F (C £ F C) / C ² Etc. & 11 % ' $ Examples ctd. ² The set ListZ is the initial algebra of the functor LZ = K1 + KZ £ Id : Set ! Set. ² The following are recursive coalgebras: ² ListZ together with the analysis of every non-empty list into its head and tail is a LZ -recursive coalgebra. ² So is every su±x-closed subset of ListZ. ² ListZ together with the analysis of every non-empty list into its smallest element and the rest is also a recursive LZ -coalgebra. ² ListZ together with the analysis of every non-empty, non-singleton list into two halves is a recursive coalgebra of the functor BTZ = K1 + KZ + Id £ Id. Etc. & 12 % ' $ Examples ctd. ² A functor may well have recursive coalgebras without having an initial algebra: ² Let P : Set ! Set be the covariant powerset function. ² A P-coalgebra (A; ®) is a binary relation (A; Á): ®(a) = fx 2 A j x Á ag x Á a i® x 2 ®(a) ² A P-coalgebra-to-algebra morphism from (A; ®) to (C; ') is a function f : A ! C such that f = ' ± Pf ± ® i.e., such that, for any a 2 A, f(a) = '(ff(x) j x Á ag) Such a morphism exists uniquely for any (C; ') i® Á is wellfounded. So: (A; ®) is recursive i® (A; Á) is wellfounded. ² But P has no initial algebra! & 13 % ' $ Recursive coalgebras: basic properties ² Let F : C ! C be a functor. If F has an initial algebra, we agree to denote it (¹F; inF ). ¡1 ² Prop. If F has an initial algebra, then (¹F; inF ) is a ¯nal recursive F -coalgebra. inF * o ® F (¹F ) m ¹F F A A ¡1 in F g F g F f f ² ² ² inF ² ' / * F C C F (¹F ) m ¹F ¡1 inF & 14 % ' $ ² Prop. If (A; ®) is a recursive F -coalgebra, then (F A; F ®) is also a recursive F -coalgebra. ² Prop. (a) If (A; ®) is a recursive F -coalgebra and ® is iso, then (A; ®¡1) is an initial F -algebra. (b) If (A; ®) is a ¯nal recursive F -coalgebra, then ® is iso (both as a morphism and as a coalgebra morphism) (and hence (A; ®¡1) is an initial F -algebra). ¡1 ® ) o ® (a) F A k A (b) F A o A ® F f f F ® ® ² ' ² ² F ® ² F C / C F 2A o F A F h h ² ® ² F A o A & 15 % ' $ ² Prop. Let C be cartesian and F : C ! C a functor. If (A; ®) is a recursive F -coalgebra, then (A; F h idA; ® i ± ®) is a recursive F (Id £ F )-coalgebra. ² Construction of the recursive morphism: F h id;® i ® F (A £ F A) o F A o A Si SS mmm SSSF (id£®) F h id;id i mmm SSS mm SSS mmm SS mv mm F (g£F g) F (A £ A) F g g F (g£g) F (f£F f) ² ² f F id à F id;id ² ² F ((C £ F C) ( £ )/ F ((C £ F C) ho i à / £F (C £ F C)) £(C £ F C)) F (C £ F C) C £ F C F (fst£F fst) F (fst£snd) fst " ² ² ' ² { F (C £ F C) F (C £ F C) F (C £ F C) / C & 16 % ' $ \Transposition properties" : ² Prop. (folklore) Let F; G : C ! C be functors and ¿ : F ! G a natural transformation. If an F -coalgebra (A; ®) is recursive, then the G-coalgebra (A; ¿A ± ®) is recursive. ² Prop. (Eppendahl) Let F : C ! D and G : D ! C be functors. If (A; ®) is a recursive GF -coalgebra, then (F A; F ®) is a recursive F G-coalgebra. ² Cor. Let F : C ! C, G : D ! D be functors, L : C ! D a functor with a right : adjoint, and ¿ : LF ! GL a natural transformation. If (A; ®) is a recursive F -coalgebra, then (LA; ¿A ± L®) is a recursive G-coalgebra. & 17 % ' $ Variation 1: Strongly recursive coalgebras ² Def. Let C be cartesian and F : C ! C a functor with a strength . An F -coalgebra (A; ') is strongly recursive (or recursive with parameters) i®, for any object ¡ of C and F -algebra (C; '), there is a unique morphism f : ¡ £ A ! C satisfying ¡;A id¡£® F (¡ £ A) o ¡ £ F A o ¡ £ A F f f ² ' ² F C / C i.e., i®, for any object ¡, the F -coalgebra (¡ £ A; ¡;A ± (id¡ £ ®)) is recursive. ² [Cf. iteration with parameters.] ² A strongly recursive F -coalgebra (A; ®) is also a recursive F -coalgebra. ² For the converse to hold, it is su±cient that C is cartesian closed. & 18 % ' $ Variation 2: parametrically recursive coalgebras ² Def. Let C be cartesian and F : C ! C a functor. An F -coalgebra (A; ®) is parametrically recursive i®, for any (KA £ F )-algebra (C; '), there is a unique morphism f : A ! C satisfying h idA;® i A £ F A o A idA£F f f ² ' ² A £ F C / C i.e., i® the (KA £ F )-coalgebra (A; h idA; ® i) is recursive. ² [Cf. primitive recursion.] ² A parametrically recursive F -coalgebra (A; ®) is necessarily recursive, but the converse does not hold in general. ² Adamek-Milius-Velebil completely iterative algebras are dual to this version of the concept of recursive coalgebras. & 19 % ' $ Comonads, comonad algebras, distributive laws ² Def.
Recommended publications
  • NICOLAS WU Department of Computer Science, University of Bristol (E-Mail: [email protected], [email protected])
    Hinze, R., & Wu, N. (2016). Unifying Structured Recursion Schemes. Journal of Functional Programming, 26, [e1]. https://doi.org/10.1017/S0956796815000258 Peer reviewed version Link to published version (if available): 10.1017/S0956796815000258 Link to publication record in Explore Bristol Research PDF-document University of Bristol - Explore Bristol Research General rights This document is made available in accordance with publisher policies. Please cite only the published version using the reference above. Full terms of use are available: http://www.bristol.ac.uk/red/research-policy/pure/user-guides/ebr-terms/ ZU064-05-FPR URS 15 September 2015 9:20 Under consideration for publication in J. Functional Programming 1 Unifying Structured Recursion Schemes An Extended Study RALF HINZE Department of Computer Science, University of Oxford NICOLAS WU Department of Computer Science, University of Bristol (e-mail: [email protected], [email protected]) Abstract Folds and unfolds have been understood as fundamental building blocks for total programming, and have been extended to form an entire zoo of specialised structured recursion schemes. A great number of these schemes were unified by the introduction of adjoint folds, but more exotic beasts such as recursion schemes from comonads proved to be elusive. In this paper, we show how the two canonical derivations of adjunctions from (co)monads yield recursion schemes of significant computational importance: monadic catamorphisms come from the Kleisli construction, and more astonishingly, the elusive recursion schemes from comonads come from the Eilenberg-Moore construction. Thus we demonstrate that adjoint folds are more unifying than previously believed. 1 Introduction Functional programmers have long realised that the full expressive power of recursion is untamable, and so intensive research has been carried out into the identification of an entire zoo of structured recursion schemes that are well-behaved and more amenable to program comprehension and analysis (Meijer et al., 1991).
    [Show full text]
  • Practical Coinduction
    Math. Struct. in Comp. Science: page 1 of 21. c Cambridge University Press 2016 doi:10.1017/S0960129515000493 Practical coinduction DEXTER KOZEN† and ALEXANDRA SILVA‡ †Computer Science, Cornell University, Ithaca, New York 14853-7501, U.S.A. Email: [email protected] ‡Intelligent Systems, Radboud University Nijmegen, Postbus 9010, 6500 GL Nijmegen, the Netherlands Email: [email protected] Received 6 March 2013; revised 17 October 2014 Induction is a well-established proof principle that is taught in most undergraduate programs in mathematics and computer science. In computer science, it is used primarily to reason about inductively defined datatypes such as finite lists, finite trees and the natural numbers. Coinduction is the dual principle that can be used to reason about coinductive datatypes such as infinite streams or trees, but it is not as widespread or as well understood. In this paper, we illustrate through several examples the use of coinduction in informal mathematical arguments. Our aim is to promote the principle as a useful tool for the working mathematician and to bring it to a level of familiarity on par with induction. We show that coinduction is not only about bisimilarity and equality of behaviors, but also applicable to a variety of functions and relations defined on coinductive datatypes. 1. Introduction Perhaps the single most important general proof principle in computer science, and argu- ably in all of mathematics, is induction. There is a valid induction principle corresponding to any well-founded relation, but in computer science, it is most often seen in the form known as structural induction, in which the domain of discourse is an inductively-defined datatype such as finite lists, finite trees, or the natural numbers.
    [Show full text]
  • The Method of Coalgebra: Exercises in Coinduction
    The Method of Coalgebra: exercises in coinduction Jan Rutten CWI & RU [email protected] Draft d.d. 8 July 2018 (comments are welcome) 2 Draft d.d. 8 July 2018 Contents 1 Introduction 7 1.1 The method of coalgebra . .7 1.2 History, roughly and briefly . .7 1.3 Exercises in coinduction . .8 1.4 Enhanced coinduction: algebra and coalgebra combined . .8 1.5 Universal coalgebra . .8 1.6 How to read this book . .8 1.7 Acknowledgements . .9 2 Categories { where coalgebra comes from 11 2.1 The basic definitions . 11 2.2 Category theory in slogans . 12 2.3 Discussion . 16 3 Algebras and coalgebras 19 3.1 Algebras . 19 3.2 Coalgebras . 21 3.3 Discussion . 23 4 Induction and coinduction 25 4.1 Inductive and coinductive definitions . 25 4.2 Proofs by induction and coinduction . 28 4.3 Discussion . 32 5 The method of coalgebra 33 5.1 Basic types of coalgebras . 34 5.2 Coalgebras, systems, automata ::: ....................... 34 6 Dynamical systems 37 6.1 Homomorphisms of dynamical systems . 38 6.2 On the behaviour of dynamical systems . 41 6.3 Discussion . 44 3 4 Draft d.d. 8 July 2018 7 Stream systems 45 7.1 Homomorphisms and bisimulations of stream systems . 46 7.2 The final system of streams . 52 7.3 Defining streams by coinduction . 54 7.4 Coinduction: the bisimulation proof method . 59 7.5 Moessner's Theorem . 66 7.6 The heart of the matter: circularity . 72 7.7 Discussion . 76 8 Deterministic automata 77 8.1 Basic definitions . 78 8.2 Homomorphisms and bisimulations of automata .
    [Show full text]
  • Friends with Benefits: Implementing Corecursion in Foundational
    Friends with Benefits Implementing Corecursion in Foundational Proof Assistants Jasmin Christian Blanchette1;2, Aymeric Bouzy3, Andreas Lochbihler4, Andrei Popescu5;6, and Dmitriy Traytel4 1 Vrije Universiteit Amsterdam, the Netherlands 2 Inria Nancy – Grand Est, Nancy, France 3 Laboratoire d’informatique, École polytechnique, Palaiseau, France 4 Institute of Information Security, Department of Computer Science, ETH Zürich, Switzerland 5 Department of Computer Science, Middlesex University London, UK 6 Institute of Mathematics Simion Stoilow of the Romanian Academy, Bucharest, Romania Abstract. We introduce AmiCo, a tool that extends a proof assistant, Isabelle/ HOL, with flexible function definitions well beyond primitive corecursion. All definitions are certified by the assistant’s inference kernel to guard against in- consistencies. A central notion is that of friends: functions that preserve the pro- ductivity of their arguments and that are allowed in corecursive call contexts. As new friends are registered, corecursion benefits by becoming more expressive. We describe this process and its implementation, from the user’s specification to the synthesis of a higher-order definition to the registration of a friend. We show some substantial case studies where our approach makes a difference. 1 Introduction Codatatypes and corecursion are emerging as a major methodology for programming with infinite objects. Unlike in traditional lazy functional programming, codatatypes support total (co)programming [1, 8, 30, 68], where the defined functions have a simple set-theoretic semantics and productivity is guaranteed. The proof assistants Agda [19], Coq [12], and Matita [7] have been supporting this methodology for years. By contrast, proof assistants based on higher-order logic (HOL), such as HOL4 [64], HOL Light [32], and Isabelle/HOL [56], have traditionally provided only datatypes.
    [Show full text]
  • Some New Approaches in Functional Programming Using Algebras and Coalgebras
    Available online at www.sciencedirect.com Electronic Notes in Theoretical Computer Science 279 (3) (2011) 41–62 www.elsevier.com/locate/entcs Some New Approaches in Functional Programming Using Algebras and Coalgebras Viliam Slodiˇc´ak1,2 Pavol Macko3 Department of Computers and Informatics Technical University of Koˇsice Koˇsice, Slovak Republic Abstract In our paper we deal with the expressing of recursion and corecursion in functional programming. We discuss about the morphisms which express the recursion or corecursion, respectively. Here we consider especially the catamorphisms, anamorphisms and their composition called the hylomorphisms. The main essence of this work is to describe a new method of programming the function for calculating the factorial by using hylomorphism. We show that using of hylomorphism is an alternative method for the computation of factorial to recursive methods programmed classically. Our new method we describe in action semantics which is a new formal method for the program description. Keywords: Recursion, duality, hylomorphism, algebra, recursive coalgebras, action semantics. 1 Introduction Recursion is a very useful tool in modern programming languages, in particular when we deal with inductive data structures such as lists, trees, etc. [9]. The theory of recursive functions was developed by Kurt G¨odeland Stephen Kleene in the 1930s. Now the recursion has the great importance in mathematics and in computer science. The recursion method presents very interesting solution of many computational algorithms. It is an inherent part of functional programming. On the other hand, the dual method called corecursion brings the new opportunities in programming. In section 2 we formulate basic notions from the category the- ory, the mathematical tool which importance for theoretical informatics growth in last decade.
    [Show full text]
  • Corecursive Algebras: a Study of General Structured Corecursion (Extended Abstract)
    Corecursive Algebras: A Study of General Structured Corecursion (Extended Abstract) Venanzio Capretta1, Tarmo Uustalu2, and Varmo Vene3 1 Institute for Computer and Information Science, Radboud University Nijmegen 2 Institute of Cybernetics, Tallinn University of Technology 3 Department of Computer Science, University of Tartu Abstract. We study general structured corecursion, dualizing the work of Osius, Taylor, and others on general structured recursion. We call an algebra of a functor corecursive if it supports general structured corecur- sion: there is a unique map to it from any coalgebra of the same functor. The concept of antifounded algebra is a statement of the bisimulation principle. We show that it is independent from corecursiveness: Neither condition implies the other. Finally, we call an algebra focusing if its codomain can be reconstructed by iterating structural refinement. This is the strongest condition and implies all the others. 1 Introduction A line of research started by Osius and Taylor studies the categorical foundations of general structured recursion. A recursive coalgebra (RCA) is a coalgebra of a functor F with a unique coalgebra-to-algebra morphism to any F -algebra. In other words, it is an algebra guaranteeing unique solvability of any structured recursive diagram. The notion was introduced by Osius [Osi74] (it was also of interest to Eppendahl [Epp99]; we studied construction of recursive coalgebras from coalgebras known to be recursive with the help of distributive laws of functors over comonads [CUV06]). Taylor introduced the notion of wellfounded coalgebra (WFCA) and proved that, in a Set-like category, it is equivalent to RCA [Tay96a,Tay96b],[Tay99, Ch.
    [Show full text]
  • Corecursion in Session-Typed Processes
    Corecursion in Session-Typed Processes Bernardo Toninho∗y, Lu´ıs Caires∗ and Frank Pfenningy ∗CITI and FCT - Universidade Nova de Lisboa yCarnegie Mellon University Abstract—Session types are widely accepted as a useful expres- has sparked a renewed interest in session types and their foun- sive discipline for structuring communications in concurrent and dations [5], and in the idea of exploiting logically motivated distributed systems. In order to express infinitely unbounded approaches for providing powerful reasoning techniques about sessions, as required to model the behaviour of realistic dis- tributed systems, session typed languages often introduce general concurrent and distributed systems. This line of work has recursion operators at both the program and the type level. addressed concepts such as value-dependent types [6], proof- Unfortunately, general recursion, in particular when combined carrying code [7] behavioural polymorphism [8], and higher- with name passing and mobility, may easily introduce undesirable order computation [9], approaching a general type theory for divergence, e.g., infinite unobservable reduction sequences. session-based concurrency, with strong guarantees by virtue In this paper we address, by means of typing, the challenge of ensuring non-divergence in a session-typed π-calculus with of typing such as deadlock freedom and session fidelity. general (co)recursion, while still allowing interesting infinite Although in the untyped case infinite behavior is potentially behaviours to be definable, as necessary to model realistic open encodable using replication in the π-calculus, to express process networks and distributed systems. Our approach builds infinitely unbounded session exchanges, as required to model on a Curry-Howard correspondence between our type system the behaviour of realistic distributed systems, session typed and a standard system of linear logic extended with co-inductive types, for which our non-divergence property implies consistency.
    [Show full text]
  • Corecursion and Non-Divergence in Session Types
    Corecursion and Non-Divergence in Session Types Bernardo Toninho1;2, Luis Caires1, and Frank Pfenning2 1 Universidade Nova de Lisboa, Portugal 2 Carnegie Mellon University, USA Abstract. Session types are widely accepted as an expressive discipline for structuring communications in concurrent and distributed systems. In order to express infinitely un- bounded sessions, session typed languages often include general recursion which may introduce undesirable divergence, e.g., infinite unobservable reduction sequences. In this paper we address, by means of typing, the challenge of ensuring non-divergence in a session-typed π-calculus with general (co)recursion, while still allowing interesting infinite behaviors to be definable. Our approach builds on a Curry-Howard correspon- dence between our type system and linear logic extended with co-inductive types, for which our non-divergence property implies consistency. We prove type safety for our framework, implying protocol compliance and global progress of well-typed processes. We also establish, using a logical relation argument, that well-typed processes are com- positionally non-divergent, that is, that no well-typed composition of processes, includ- ing those dynamically assembled via name passing, can result in divergent behavior. 1 Introduction We live in an age of concurrent and distributed software, meant to run not only as local applications but as cooperating parts of larger, distributed and mobile services, meant to run indefinitely with multiple independent clients, which are hard to build and ensure correct. Process models combined with techniques for precisely characterizing and analyzing system behavior have been used to verify properties such as deadlock freedom, protocol compliance, and availability in distributed and service based systems.
    [Show full text]
  • Cognitive Architecture and Second-Order
    Cognitive architecture and second-order systematicity: categorical compositionality and a (co)recursion model of systematic learning Steven Phillips ([email protected]) Mathematical Neuroinformatics Group, National Institute of Advanced Industrial Science and Technology (AIST), Tsukuba, Ibaraki 305-8568 JAPAN William H. Wilson ([email protected]) School of Computer Science and Engineering, The University of New South Wales, Sydney, New South Wales, 2052 AUSTRALIA Abstract each other. An example that is pertinent to the classical ex- planation is the learning (or memorization) of arbitrary asso- Systematicity commonly means that having certain cognitive capacities entails having certain other cognitive capacities. ciations. For instance, if one has the capacity to learn (mem- Learning is a cognitive capacity central to cognitive science, orize) that the first day of the Japanese financial year is April but systematic learning of cognitive capacities—second-order 1st, then one also has the capacity to learn (memorize) that systematicity—has received little investigation. We proposed associative learning as an instance of second-order systematic- the atomic number of carbon is 6. This example is a legiti- ity that poses a paradox for classical theory, because this form mate instance of systematicity (at the second level) given that of systematicity involves the kinds of associative constructions systematicity has been characterized as equivalence classes that were explicitly rejected by the classical explanation. In fact, both first and second-order forms of systematicity can of cognitive capacities (McLaughlin, 2009). be derived from the formal, category-theoretic concept of uni- Elsewhere (Phillips & Wilson, submitted), we argue that versal morphisms to address this problem.
    [Show full text]
  • Tree (Data Structure)
    Tree (Data Structure) http://en.wikipedia.org/wiki/Tree_(data_structure)#Digraphs Contents 1 Definition o 1.1 Data type vs. data structure o 1.2 Recursive o 1.3 Type theory o 1.4 Mathematical 2 Terminology 3 Drawing graphs 4 Representations 5 Generalizations o 5.1 Digraphs 6 Traversal methods 7 Common operations 8 Common uses 9 See also o 9.1 Other trees 10 Notes 11 References 12 External links A simple unordered tree; in the following diagram, the node labeled 7 has two children, labeled 2 and 6, and one parent, labeled 2. The root node, at the top, has no parent. In computer science, a tree is a widely used abstract data type (ADT) or data structure implementing this ADT that simulates a hierarchical tree structure, with a root value and subtrees of children, represented as a set of linked nodes. A tree data structure can be defined recursively (locally) as a collection of nodes (starting at a root node), where each node is a data structure consisting of a value, together with a list of references to nodes (the "children"), with the constraints that no reference is duplicated, and none points to the root. Alternatively, a tree can be defined abstractly as a whole (globally) as an ordered tree, with a value assigned to each node. Definition Data type vs. data structure There is a distinction between a tree as an ADT (an abstract type) and a "linked tree" as a data structure, analogous to the distinction between a list (an abstract data type) and a linked list (a data structure).
    [Show full text]
  • Corecursion and Coinduction: How They Relate to Recursion and Induction
    Corecursion and coinduction: what they are and how they relate to recursion and induction Mike Gordon 1 Contents Preface 3 Summary 4 Data, codata, constructors and destructors ............... 4 Recursion and corecursion ......................... 5 Fixed points, induction, coinduction and bisimulation ......... 7 Overview of the rest of this article .................... 9 Natural numbers, Peano’s axioms and Peano structures 10 Algebras and coalgebras 11 Numbers and conumbers .......................... 12 Example of corecursion for numbers ................... 14 Lists and colists ............................... 15 Example of corecursion for lists ...................... 17 Coinduction and bisimulation 19 Bisimulation coinduction for conumbers ................. 20 Example of bisimulation coinduction for numbers ..... 20 Justification of bisimulation coinduction for numbers ... 21 Bisimulation coinduction for lists ..................... 22 Examples of bisimulation coinduction for lists ....... 22 Justification of bisimulation coinduction for lists ..... 27 F-algebras and F-coalgebras 28 Set theory notation ............................. 29 Numbers and lists ............................. 29 Morphisms ................................. 30 Initial and terminal algebras ........................ 32 Least and greatest fixed points 32 Fixed points, numbers and conumbers .................. 33 Summary of fixed point proof rules for numbers and conumbers .... 34 Fixed points, lists and colists ....................... 34 Summary of fixed point proof rules
    [Show full text]
  • Sorting with Bialgebras and Distributive Laws
    Sorting with Bialgebras and Distributive Laws Ralf Hinze Daniel W. H. James Thomas Harper Nicolas Wu José Pedro Magalhães Department of Computer Science, University of Oxford {ralf.hinze;daniel.james;tom.harper;nicolas.wu;jose.pedro.magalhaes}@cs.ox.ac.uk Abstract This is an entirely routine and naïve definition, which makes use Sorting algorithms are an intrinsic part of functional programming of the span function from the list utilities section of the Haskell folklore as they exemplify algorithm design using folds and un- Report. When the input list ys is ordered, insert y ys adds y to the folds. This has given rise to an informal notion of duality among list ys and maintains the invariant that the ensuing list is ordered. sorting algorithms: insertion sorts are dual to selection sorts. Using Thus, we are able to fold an unordered list into an ordered one when bialgebras and distributive laws, we formalise this notion within a we start with an empty list as the initial value of the fold. categorical setting. We use types as a guiding force in exposing the Perhaps less well known is that an alternative sorting algorithm, recursive structure of bubble, insertion, selection, quick, tree, and selection sort, can be written in terms of an unfold. An unfold can heap sorts. Moreover, we show how to distill the computational be thought of as the dual of a fold: a fold consumes a list, whereas essence of these algorithms down to one-step operations that are unfold produces a list, as is evident in the type of unfoldr: expressed as natural transformations.
    [Show full text]