Save this PDF as:

Size: px
Start display at page:

## Transcription

1 The Haskell Programmer s Guide to the IO Monad Don t Panic Stefan Klinger University of Twente, the Netherlands EWI, Database Group CTIT Technical Report

2 Stefan Klinger. The Haskell Programmer s Guide to the IO Monad Don t Panic. Order-address: Centre for Telematics and Information Technology University of Twente P. O. Box AL Enschede the Netherlands PDF available at All rights reserved. No part of this Technical Report may be reproduced, stored in a database or retrieval system or published in any form or in any way, electronically, by print, photoprint, microprint or any other means, without prior written permission from the publisher. Stefan Klinger. The Haskell Programmer s Guide to the IO Monad Don t Panic. Technical report, December 2005, no , 33 pp., Centre for Telematics and Information Technology (CTIT), ISSN Version of 2005-Dec-15 15:39:54.

6 Chapter 2 Notation I tried to keep the notation as readable as possible, yet unambiguous. The meaning should be clear immediately, and I hope that predicate logic people excuse some lack of purity. 1. Quite often proofs are interspersed with explanatory text, e.g., talking about integers we might note = a+b operator + is commutative b+a. 2. Function application is always noted in juxtaposition i.e., the operand is just written behind the function to avoid a Lisp-like amount of parenthesis, i.e. fx by definition f(x). 3. Quantifiers have higher precedence than and and or (symbols ^; _ ), but lower than implication and equivalence ();,). A quantifier binds all the free variables in the following ; -separated list of predicates that are neither given in the context of the formula (constants), nor bound by an earlier quantifier. I.e., 8m;n 2 N; m<n 9r2R next line is predicate logic m<r<n 8m8n m 2 N ^n2n ^m<n ) 9r(r 2 R ^m<r<n). 4. Sometimes the exercise sign ( ) occurs, requesting the reader to verify something, or to play with the Haskell code given. 5. A-expression binding the free occurrences ofy in expressioneis written (y 7!e). As a Haskell programmer, you should be familiar with-expressions. 6. Unless stated otherwise, most programming code is Haskell-pseudocode. In contradiction to this, Haskell-code that should be tried out by the user is referred to with a -sign. 6

7 Chapter 3 Categories 3.1 Categories in theory Introductory example Let us start with a quite concrete example of a category: Sets (later called objects) together with all the total functions on them (called morphisms): It is common practice to writef:a!bto denote that a functionf maps from setato set B. This is called the type of the function. Also, we can compose two functionsf andg, if the target set of the former equals the source set of the latter, i.e., iff:a!bandg:b!c for some setsa,b, andc. The composition is commonly denoted bygf. For each seta, there is an identity functionida:a!a. These are the properties of a category. While most things in this guide can be applied to the category of sets, Definition is more precise and general. In particular, category theory is not restricted to sets and total functions, i.e., one can not assume that an object has elements (like sets do), or that an element is mapped to another element Definition A category C =(OC; MC; TC; C;IdC) is a structure consisting of morphisms MC, objects OC, a composition C of morphisms, and type information TC of the morphisms, which obey to the following constraints. Note, that we often omit the subscription with C if the category is clear from the context. 1. We assume the collection of objects O to be a set. Quite often the objects themselves also are sets, however, category theory makes no assumption about that, and provides no means to explore their structure. 2. The collection of morphisms M is also assumed to be a set in this guide. 3. The ternary relation T M O O is called the type information of C. We want every morphism to have a type, so a category requires 8f 2 M 9A;B 2 O (f;a;b) 2 T. We writef:a C! B for(f;a;b) 2 TC. Also, we want the types to be unique, leading to the claim f:a!b^f:a!b 0 0 ) A=A ^B=B 0 0. This gives a notion of having a morphism to map from one object to another. The uniqueness entitles us to give names to the objects involved in a morphism. Forf:A!B we callsrcf :=Athe source, andtgtf :=Bthe target off. 4. The partial function : M M! M, written as a binary infix operator, is called the composition of C. Alternative notations are f;g := gf := g f. 7

9 Chapter 4 Functors 4.1 Functors in theory One can define mappings between categories. If they behave well, i.e., preserve the structural properties of being an object, morphism, identity, the types and composition, they are called functors Definition Let A; B be categories. Then two mappings FO: OA! OB and FM: MA! MB together form a functorf from A to B, writtenf : A! B, iff 8f:A! A B FMf:FOA! B FOB, 1. they preserve type information, i.e., 2. FM maps identities to identities, i.e., 8A2OA FMidA=idFOA, 8f:A A! B; g:b A! C FM(g Af)=FMg BFMf. 3. and application offm distributes under composition of morphisms, i.e., Notation Unless it is required to refer to only one of the mappings, the subscripts M and O are usually omitted. It is clear from the context whether an object or a morphism is mapped by the functor Definition Let A be a category. A functorf : A! A is called endofunctor. It is easy to define a identity on a category, by simply combining the identities on objects and morphisms the same way we just have combined the functors. Also, applying one functor after another where the target category of the first must be the source category of the second looks like composition: Definition Let A; B; C be categories,f : A! B andg:b! C. We define identities IA := idoa]ma and functor compositiongf with 8 A 2 O (GF)A 8f G(FA) 2 M (GF)f :=G(Ff). Due to this definition, we can write GFA and GFf without ambiguity. Multiple application of the same mapping is often noted with a superscript, i.e., we definef 2 :=FF for any functorf. 9

12 CHAPTER 4. FUNCTORS Lemma Maybe and List are both functors. I.e., they are not only members of the class, but also behave as expected in theory. The proof is easy ( ), and when ever you want to add a type to the functor class, you have to perform this kind of proof. So do this as an exercise before reading ahead Proof The proof of Lemma strictly follows the structure of the Haskell types, i.e., we differentiate according to the data constructors used. For the Maybe structure, the data constructors are Just and Nothing. So we prove the second functor property,fida=idfa, by fmap id Nothing == Nothing == id Nothing fmap id (Just y) == Just (id y) == Just y == id (Just y), and the third property,f(g f)=fg Ff, by (fmap g. fmap h) Nothing == fmap g (fmap h Nothing) == fmap g Nothing == Nothing == fmap (g. h) Nothing, (fmap g. fmap h) (Just y) == fmap g (fmap h (Just y)) == fmap g (Just (h y)) == Just (g (h y)) == Just ((g. h) y) == fmap (g. h) (Just y). Note, that List is in contrast to Maybe a recursive structure. This can be observed in the according definition of fmap above, and it urges us to use induction in the proof: The second property,fida=idfa, is shown by fmap id [] == [] == id [] fmap id (x:xs) == (id x):(fmap id xs) == (id x):(id xs) --here we use induction == x:xs == id (x:xs), and the third property,f(g f)=fg Ff can be observed in fmap (g. f) [] == [] == fmap g [] == fmap g (fmap f []) == (fmap g. fmap f) [] fmap (g. f) (x:xs) == ((g. f) x):(fmap (g. f) xs) == ((g. f) x):((fmap g. fmap f) xs) --induction == (g (f x)):(fmap g (fmap f xs)) == fmap g ((f x):(fmap f xs)) == fmap g (fmap f xs) == (fmap g. fmap f) xs. 12

13 O Chapter 5 Natural Transformations 5.1 Natural transformations in theory A natural transformation is intended to transform from one structure to another, without effecting, or being influenced by, the objects in the structure. Imagine two functors F and G imposing two structures between the same categories A and B. Then a natural transformation is a collection of morphisms in the target category B of both functors, always mapping from an objectfa to an objectga. In fact, for each objectain the source category there is one such morphism in the target category: Definition Let A; B be categories,f;g:a!b. Then, a function : OA! MB A 7! A is called a transformation fromf tog, iff 8A2OA A:FA B! GA, 8f:A A! B B BFf=Gf BA. A FA / ac CCCCCCC GA F _ ;{ G A {{{{{{{= f Gf ;B _ C CCCCCCC! F G }{ FB {{{{{{{ B /GB Ff and it is called a natural transformation, denoted:f _!G, iff 5.2 Natural transformations in Haskell The definition says, that a natural transformation transforms from a structuref to a structureg, without altering the behaviour of morphisms on objects. I.e., it does not play a role whether a morphismf is lifted into the one or the other structure, when composed with the transformation. In the drawing on the left, this means that the outer square commutes, i.e., all directed paths with common source and target are equal. First note, that a unary function polymorphic in the same type on source and target side, in fact is a transformation. For example, Haskell s Just is typed Just :: forall a. a -> Maybe a. If we imagine this to be a mapping Just:OH! MH, the application on an objecta 2 OH means binding the type variable a to some Haskell type A. That is, Just maps an objectato a morphism of typea! MaybeA. 13

14 CHAPTER 5. NATURAL TRANSFORMATIONS To spot a transformation here, we still miss a functor on the source side of Just s type. This is overcome by adding the identity functorih, which leads to the transformation Just:IH! Maybe Lemma Just :IH _! Maybe Proof Let f::a->b be an arbitrary Haskell function. Then we have to prove, that Just. I H f == fmap f. Just where the left Just refers tob, and the right one refers toa. In that line, we recognise the definition of the fmap for Maybe (just drop theih). Another example, this time employing two non-trivial functors, are the maybetolist and list- ToMaybe functions. Their definitions read maybetolist :: forall a. Maybe a -> [a] maybetolist Nothing = [] maybetolist (Just x) = [x] listtomaybe :: forall a. [a] -> Maybe a listtomaybe [] = Nothing listtomaybe (x:xs) = Just x. Note, that the loss of information imposed by applying listtomaybe on a list with more than one element does not contradict naturality, i.e., forgetting data is not altering data. We do not go through the proof of their naturality here ( but, of course, you can do this on your own). Instead, we discuss some more interesting examples in the next chapter (see Lemma 6.2.1). 5.3 Composing transformations and functors To describe the Monad structure later on, we need to compose natural transformations with functors and with other natural transformations. This is discussed in the remainder of this chapter. Natural transformations and functors Just as in Definition 4.1.4, we can define a composition between a natural transformation and a functor. Therefore, an object is first lifted by the functor and then mapped to a morphism by the transformation, or it is first mapped to a morphism which is then lifted: Definition Let A; B; C; D be categories,e: A! B,F;G:B!C, andh: C! D. Then, for a natural transformation:f _!G, we define the transformationse andh with (E)A := EA and (H)B := H(B), whereavaries over OA, andb varies over OB. Again, due to the above definition, we can write EA and HB (for A and B objects in the respective category) without ambiguity. The following pictures show the situation: E OA / D OB OB F DDDDDD FFFFFFF" H E " MC MC H / MD Lemma In the situation of Definition 5.3.1, H:HF _!HG E:FE _!GE hold. In (other) words,h ande are both natural transformations. 14

15 Composing transformations and functors Proof of Lemma Part I. Part II :F _!G, ) 8f:A definition of naturality B! B Ff=Gf A ) 8f:A B! B H(B Ff)=H(Gf A) ) 8f:A functor property B! B H(B) H(Ff)=H(Gf) H(A) 8f:A B! B (H)B (HF)f=(HG)f (H)A H:HF _!HG, ) Definition ) definition of naturality :F _!G ) 8f:A definition of naturality B! B B Ff=Gf A ) choosef from category A 8f:A A! B (EB) F(Ef)=G(Ef) (EA) ) 8f:A Definition A! B (E)B (FE)f=(GE)f (E)A ) E:FE definition _!GH of naturality. Composing natural transformations Even natural transformations can be composed with each other. Since, however, transformations map objects to morphisms instead of, e.g., objects to objects they can not be simply applied one after another. Instead, composition is defined component wise, also called vertical composition Definition Let A; B be categories,f;g;h : A! B and:f _!G,:G _!H. Then we define the transformations idf : OA! MB and : OA! MB A 7! idfa A 7! A A. FA A 3 GA HA / A / A A The picture on the left (witha 2 OA) clarifies why this composition is called vertical. All compositions defined before Definition are called horizontal. Why? 15

16 CHAPTER 5. NATURAL TRANSFORMATIONS Lemma In the situation of Definition 5.3.4, idf :F _!F, :F _!H, idg==idf hold Proof of Lemma The naturality ofidf is trivial ( ). For the naturality of consider any morphismf:a A! B. Then, :G _!H :F _!G ) Hf A=B ^ Gf ^ Gf A=B Ff ) applya on the left,b on the right (Hf A) A=(B Gf) A B (Gf A)=B (B Ff) ^ ) Hf (A the two A)=(B middle terms B) are Ff equal ) Hf A=B Definition Ff ) :F _!H 16

17 O O O O Chapter 6 Monads 6.1 Monads in theory Definition Let C be a category, and F : C! C. Consider two natural transformations :IC _!F and:f 2 _!F. The triple(f;;) is called a monad, iff (F)=(F) and (F)=idF =(F). (Mind, that the parenthesis group composition of natural transformations and functors. They do not refer to function application. This is obvious due to the types of the expressions in question.) The transformations and are somewhat contrary: While adds one level of structure (i.e., functor application), removes one. Note, however, that transforms to F, while transforms fromf 2. This is due to the fact that claiming the existence of a transformation from a functorf to the identityic would be too restrictive: Consider the set category S and the list endofunctorl. Any transformationfromltois has to map every objectato a morphisma, which in turn maps the empty list to some element ina, i.e., :L!IS ) 8A2OS A:LA!A ) 8A2OS 9c2A A[]=c, where[] denotes the empty list. This, however, implies 8A2OS A 6= ;. The following drawings are intended to clarify Definition 6.1.1: The first equation of the definition is equivalent to 8A2O A FA=A FA. So what arefa andfa? You can find them at the top of these drawings: F A 3 FA /F A F 2 3 FA A /F A 2 F _ F A 2 A _ /FA FA F _ A A _ Since application of A unnests a nested structure by one level, FA pushes application of this unnesting one level into the nested structure. We need at least two levels of nesting to applya. 17

20 CHAPTER 6. MONADS Letx=y:y 0, wherey 2LA andy 2L 0 2 A. (B L f)x B((L 2 = f)(y:y)) 2 0 B((Lf)y:(L definition of fmap = f)y) 2 0 (Lf)y definition +B((L of concat f)y) 2 0 induction:(b L f)y =(Lf A)y (Lf)y +(Lf)(Ay) (Lf)(y + Ay 0 ) 0 (Lf)(A(y:y definition concat = )) (Lf A)x 0. Part II To prove that is a natural transformation, we have to show that 8f:A!B B f=lf A (B f)x [fx] B(fx) (Lf)[x] = (Lf)( (Lf A)x Ax). holds. The proof reads. Part III Now we show that the monad properties for lists hold. Again, we use induction on the structure of a listx.. Part III.a Proof that(l)=(l). Letx=[] 2F 3 A. (A LA)[] A((LA)[]) A[] = ( A(LA[]) A LA)[]. Letx=y:y 0, wherey 2L A andy 2L A. (A LA)x = A((LA)(y:y )) 0 A(Ay:(LA)y definition of fmap = ) 0 Ay +A((LA)y definition of concat = ) 0 Ay +A(LAy induction = ) 0 definition of concat 20

### Sets and functions. {x R : x > 0}.

Sets and functions 1 Sets The language of sets and functions pervades mathematics, and most of the important operations in mathematics turn out to be functions or to be expressible in terms of functions.

### Domain Theory: An Introduction

Domain Theory: An Introduction Robert Cartwright Rebecca Parsons Rice University This monograph is an unauthorized revision of Lectures On A Mathematical Theory of Computation by Dana Scott [3]. Scott

### Introducing Functions

Functions 1 Introducing Functions A function f from a set A to a set B, written f : A B, is a relation f A B such that every element of A is related to one element of B; in logical notation 1. (a, b 1

### Chapter 1. Logic and Proof

Chapter 1. Logic and Proof 1.1 Remark: A little over 100 years ago, it was found that some mathematical proofs contained paradoxes, and these paradoxes could be used to prove statements that were known

### Cartesian Products and Relations

Cartesian Products and Relations Definition (Cartesian product) If A and B are sets, the Cartesian product of A and B is the set A B = {(a, b) :(a A) and (b B)}. The following points are worth special

### Regular Expressions and Automata using Haskell

Regular Expressions and Automata using Haskell Simon Thompson Computing Laboratory University of Kent at Canterbury January 2000 Contents 1 Introduction 2 2 Regular Expressions 2 3 Matching regular expressions

### CHAPTER 5: MODULAR ARITHMETIC

CHAPTER 5: MODULAR ARITHMETIC LECTURE NOTES FOR MATH 378 (CSUSM, SPRING 2009). WAYNE AITKEN 1. Introduction In this chapter we will consider congruence modulo m, and explore the associated arithmetic called

### 3. Recurrence Recursive Definitions. To construct a recursively defined function:

3. RECURRENCE 10 3. Recurrence 3.1. Recursive Definitions. To construct a recursively defined function: 1. Initial Condition(s) (or basis): Prescribe initial value(s) of the function.. Recursion: Use a

### CHAPTER 7 GENERAL PROOF SYSTEMS

CHAPTER 7 GENERAL PROOF SYSTEMS 1 Introduction Proof systems are built to prove statements. They can be thought as an inference machine with special statements, called provable statements, or sometimes

### 1 if 1 x 0 1 if 0 x 1

Chapter 3 Continuity In this chapter we begin by defining the fundamental notion of continuity for real valued functions of a single real variable. When trying to decide whether a given function is or

### C H A P T E R Regular Expressions regular expression

7 CHAPTER Regular Expressions Most programmers and other power-users of computer systems have used tools that match text patterns. You may have used a Web search engine with a pattern like travel cancun

### Chapter 7: Functional Programming Languages

Chapter 7: Functional Programming Languages Aarne Ranta Slides for the book Implementing Programming Languages. An Introduction to Compilers and Interpreters, College Publications, 2012. Fun: a language

### Metric Spaces. Chapter 1

Chapter 1 Metric Spaces Many of the arguments you have seen in several variable calculus are almost identical to the corresponding arguments in one variable calculus, especially arguments concerning convergence

### INTRODUCTORY SET THEORY

M.Sc. program in mathematics INTRODUCTORY SET THEORY Katalin Károlyi Department of Applied Analysis, Eötvös Loránd University H-1088 Budapest, Múzeum krt. 6-8. CONTENTS 1. SETS Set, equal sets, subset,

### WHAT ARE MATHEMATICAL PROOFS AND WHY THEY ARE IMPORTANT?

WHAT ARE MATHEMATICAL PROOFS AND WHY THEY ARE IMPORTANT? introduction Many students seem to have trouble with the notion of a mathematical proof. People that come to a course like Math 216, who certainly

### + addition - subtraction and unary minus * multiplication / division mod modulo

Chapter 4 Basic types We examine in this chapter the Caml basic types. 4.1 Numbers Caml Light provides two numeric types: integers (type int) and floating-point numbers (type float). Integers are limited

### Sets and Cardinality Notes for C. F. Miller

Sets and Cardinality Notes for 620-111 C. F. Miller Semester 1, 2000 Abstract These lecture notes were compiled in the Department of Mathematics and Statistics in the University of Melbourne for the use

### CHAPTER 3 Numbers and Numeral Systems

CHAPTER 3 Numbers and Numeral Systems Numbers play an important role in almost all areas of mathematics, not least in calculus. Virtually all calculus books contain a thorough description of the natural,

### INCIDENCE-BETWEENNESS GEOMETRY

INCIDENCE-BETWEENNESS GEOMETRY MATH 410, CSUSM. SPRING 2008. PROFESSOR AITKEN This document covers the geometry that can be developed with just the axioms related to incidence and betweenness. The full

### It is time to prove some theorems. There are various strategies for doing

CHAPTER 4 Direct Proof It is time to prove some theorems. There are various strategies for doing this; we now examine the most straightforward approach, a technique called direct proof. As we begin, it

### Chapter 2: Problem Solving Using C++

Chapter 2: Problem Solving Using C++ 1 Objectives In this chapter, you will learn about: Modular programs Programming style Data types Arithmetic operations Variables and declaration statements Common

### (LMCS, p. 317) V.1. First Order Logic. This is the most powerful, most expressive logic that we will examine.

(LMCS, p. 317) V.1 First Order Logic This is the most powerful, most expressive logic that we will examine. Our version of first-order logic will use the following symbols: variables connectives (,,,,

### Fundamentals of Mathematics Lecture 6: Propositional Logic

Fundamentals of Mathematics Lecture 6: Propositional Logic Guan-Shieng Huang National Chi Nan University, Taiwan Spring, 2008 1 / 39 Connectives Propositional Connectives I 1 Negation: (not A) A A T F

### Parametric Domain-theoretic models of Linear Abadi & Plotkin Logic

Parametric Domain-theoretic models of Linear Abadi & Plotkin Logic Lars Birkedal Rasmus Ejlers Møgelberg Rasmus Lerchedahl Petersen IT University Technical Report Series TR-00-7 ISSN 600 600 February 00

### 1. R In this and the next section we are going to study the properties of sequences of real numbers.

+a 1. R In this and the next section we are going to study the properties of sequences of real numbers. Definition 1.1. (Sequence) A sequence is a function with domain N. Example 1.2. A sequence of real

### Definition. Proof. Notation and Terminology

ÌÖ Ò ÓÖÑ Ø ÓÒ Ó Ø ÈÐ Ò A transformation of the Euclidean plane is a rule that assigns to each point in the plane another point in the plane. Transformations are also called mappings, or just maps. Examples

### FIRST YEAR CALCULUS. Chapter 7 CONTINUITY. It is a parabola, and we can draw this parabola without lifting our pencil from the paper.

FIRST YEAR CALCULUS WWLCHENW L c WWWL W L Chen, 1982, 2008. 2006. This chapter originates from material used by the author at Imperial College, University of London, between 1981 and 1990. It It is is

### [Refer Slide Time: 05:10]

Principles of Programming Languages Prof: S. Arun Kumar Department of Computer Science and Engineering Indian Institute of Technology Delhi Lecture no 7 Lecture Title: Syntactic Classes Welcome to lecture

### SYSTEMS OF EQUATIONS AND MATRICES WITH THE TI-89. by Joseph Collison

SYSTEMS OF EQUATIONS AND MATRICES WITH THE TI-89 by Joseph Collison Copyright 2000 by Joseph Collison All rights reserved Reproduction or translation of any part of this work beyond that permitted by Sections

### You know from calculus that functions play a fundamental role in mathematics.

CHPTER 12 Functions You know from calculus that functions play a fundamental role in mathematics. You likely view a function as a kind of formula that describes a relationship between two (or more) quantities.

### CHAPTER 2. Inequalities

CHAPTER 2 Inequalities In this section we add the axioms describe the behavior of inequalities (the order axioms) to the list of axioms begun in Chapter 1. A thorough mastery of this section is essential

### Elementary Number Theory We begin with a bit of elementary number theory, which is concerned

CONSTRUCTION OF THE FINITE FIELDS Z p S. R. DOTY Elementary Number Theory We begin with a bit of elementary number theory, which is concerned solely with questions about the set of integers Z = {0, ±1,

### Mathematics for Computer Science/Software Engineering. Notes for the course MSM1F3 Dr. R. A. Wilson

Mathematics for Computer Science/Software Engineering Notes for the course MSM1F3 Dr. R. A. Wilson October 1996 Chapter 1 Logic Lecture no. 1. We introduce the concept of a proposition, which is a statement

### Moving from CS 61A Scheme to CS 61B Java

Moving from CS 61A Scheme to CS 61B Java Introduction Java is an object-oriented language. This document describes some of the differences between object-oriented programming in Scheme (which we hope you

### 8 Divisibility and prime numbers

8 Divisibility and prime numbers 8.1 Divisibility In this short section we extend the concept of a multiple from the natural numbers to the integers. We also summarize several other terms that express

### Chapter 4, Arithmetic in F [x] Polynomial arithmetic and the division algorithm.

Chapter 4, Arithmetic in F [x] Polynomial arithmetic and the division algorithm. We begin by defining the ring of polynomials with coefficients in a ring R. After some preliminary results, we specialize

### Theory of Computation Lecture Notes

Theory of Computation Lecture Notes Abhijat Vichare August 2005 Contents 1 Introduction 2 What is Computation? 3 The λ Calculus 3.1 Conversions: 3.2 The calculus in use 3.3 Few Important Theorems 3.4 Worked

### (Refer Slide Time: 1:41)

Discrete Mathematical Structures Dr. Kamala Krithivasan Department of Computer Science and Engineering Indian Institute of Technology, Madras Lecture # 10 Sets Today we shall learn about sets. You must

### Elements of Abstract Group Theory

Chapter 2 Elements of Abstract Group Theory Mathematics is a game played according to certain simple rules with meaningless marks on paper. David Hilbert The importance of symmetry in physics, and for

### Discrete Mathematics and Probability Theory Fall 2009 Satish Rao, David Tse Note 2

CS 70 Discrete Mathematics and Probability Theory Fall 2009 Satish Rao, David Tse Note 2 Proofs Intuitively, the concept of proof should already be familiar We all like to assert things, and few of us

### Regular Expressions with Nested Levels of Back Referencing Form a Hierarchy

Regular Expressions with Nested Levels of Back Referencing Form a Hierarchy Kim S. Larsen Odense University Abstract For many years, regular expressions with back referencing have been used in a variety

### Making Sense of a Quadratic Function

About Illustrations: Illustrations of the Standards for Mathematical Practice (SMP) consist of several pieces, including a mathematics task, student dialogue, mathematical overview, teacher reflection

### FIBRATION SEQUENCES AND PULLBACK SQUARES. Contents. 2. Connectivity and fiber sequences. 3

FIRTION SEQUENES ND PULLK SQURES RY MLKIEWIH bstract. We lay out some foundational facts about fibration sequences and pullback squares of topological spaces. We pay careful attention to connectivity ranges

### Real Roots of Univariate Polynomials with Real Coefficients

Real Roots of Univariate Polynomials with Real Coefficients mostly written by Christina Hewitt March 22, 2012 1 Introduction Polynomial equations are used throughout mathematics. When solving polynomials

### An Interesting Way to Combine Numbers

An Interesting Way to Combine Numbers Joshua Zucker and Tom Davis November 28, 2007 Abstract This exercise can be used for middle school students and older. The original problem seems almost impossibly

### Section 3.7. Rolle s Theorem and the Mean Value Theorem. Difference Equations to Differential Equations

Difference Equations to Differential Equations Section.7 Rolle s Theorem and the Mean Value Theorem The two theorems which are at the heart of this section draw connections between the instantaneous rate

### Formal Languages and Automata Theory - Regular Expressions and Finite Automata -

Formal Languages and Automata Theory - Regular Expressions and Finite Automata - Samarjit Chakraborty Computer Engineering and Networks Laboratory Swiss Federal Institute of Technology (ETH) Zürich March

### Chapter 7. Functions and onto. 7.1 Functions

Chapter 7 Functions and onto This chapter covers functions, including function composition and what it means for a function to be onto. In the process, we ll see what happens when two dissimilar quantifiers

### Type Classes with Functional Dependencies

Appears in Proceedings of the 9th European Symposium on Programming, ESOP 2000, Berlin, Germany, March 2000, Springer-Verlag LNCS 1782. Type Classes with Functional Dependencies Mark P. Jones Department

### Chapter 4 Operators & Arithmetic

Chapter 4 Operators & Arithmetic 4-1 Arithmetic in C++ Arithmetic expressions can be made up of constants, variables, operators and parentheses. The arithmetic operators in C++ are as follows + (addition)

### The set consisting of all natural numbers that are in A and are in B is the set f1; 3; 5g;

Chapter 5 Set Theory 5.1 Sets and Operations on Sets Preview Activity 1 (Set Operations) Before beginning this section, it would be a good idea to review sets and set notation, including the roster method

### ML for the Working Programmer

ML for the Working Programmer 2nd edition Lawrence C. Paulson University of Cambridge CAMBRIDGE UNIVERSITY PRESS CONTENTS Preface to the Second Edition Preface xiii xv 1 Standard ML 1 Functional Programming

### THE FUNDAMENTAL THEOREM OF ALGEBRA VIA PROPER MAPS

THE FUNDAMENTAL THEOREM OF ALGEBRA VIA PROPER MAPS KEITH CONRAD 1. Introduction The Fundamental Theorem of Algebra says every nonconstant polynomial with complex coefficients can be factored into linear

### ECS 120 Lesson 17 Church s Thesis, The Universal Turing Machine

ECS 120 Lesson 17 Church s Thesis, The Universal Turing Machine Oliver Kreylos Monday, May 7th, 2001 In the last lecture, we looked at the computation of Turing Machines, and also at some variants of Turing

### CHAPTER II THE LIMIT OF A SEQUENCE OF NUMBERS DEFINITION OF THE NUMBER e.

CHAPTER II THE LIMIT OF A SEQUENCE OF NUMBERS DEFINITION OF THE NUMBER e. This chapter contains the beginnings of the most important, and probably the most subtle, notion in mathematical analysis, i.e.,

### Lecture 12. More algebra: Groups, semigroups, monoids, strings, concatenation.

V. Borschev and B. Partee, November 1, 2001 p. 1 Lecture 12. More algebra: Groups, semigroups, monoids, strings, concatenation. CONTENTS 1. Properties of operations and special elements...1 1.1. Properties

### MAT2400 Analysis I. A brief introduction to proofs, sets, and functions

MAT2400 Analysis I A brief introduction to proofs, sets, and functions In Analysis I there is a lot of manipulations with sets and functions. It is probably also the first course where you have to take

### School of Informatics, University of Edinburgh

CS1Ah Lecture Note 5 Java Expressions Many Java statements can contain expressions, which are program phrases that tell how to compute a data value. Expressions can involve arithmetic calculation and method

### The countdown problem

JFP 12 (6): 609 616, November 2002. c 2002 Cambridge University Press DOI: 10.1017/S0956796801004300 Printed in the United Kingdom 609 F U N C T I O N A L P E A R L The countdown problem GRAHAM HUTTON

### The PCAT Programming Language Reference Manual

The PCAT Programming Language Reference Manual Andrew Tolmach and Jingke Li Dept. of Computer Science Portland State University (revised October 8, 2004) 1 Introduction The PCAT language (Pascal Clone

### Basic Concepts of Point Set Topology Notes for OU course Math 4853 Spring 2011

Basic Concepts of Point Set Topology Notes for OU course Math 4853 Spring 2011 A. Miller 1. Introduction. The definitions of metric space and topological space were developed in the early 1900 s, largely

### The Goldberg Rao Algorithm for the Maximum Flow Problem

The Goldberg Rao Algorithm for the Maximum Flow Problem COS 528 class notes October 18, 2006 Scribe: Dávid Papp Main idea: use of the blocking flow paradigm to achieve essentially O(min{m 2/3, n 1/2 }

### Invertible elements in associates and semigroups. 1

Quasigroups and Related Systems 5 (1998), 53 68 Invertible elements in associates and semigroups. 1 Fedir Sokhatsky Abstract Some invertibility criteria of an element in associates, in particular in n-ary

### Computability Theory

CSC 438F/2404F Notes (S. Cook and T. Pitassi) Fall, 2014 Computability Theory This section is partly inspired by the material in A Course in Mathematical Logic by Bell and Machover, Chap 6, sections 1-10.

### CS 341 Homework 9 Languages That Are and Are Not Regular

CS 341 Homework 9 Languages That Are and Are Not Regular 1. Show that the following are not regular. (a) L = {ww R : w {a, b}*} (b) L = {ww : w {a, b}*} (c) L = {ww' : w {a, b}*}, where w' stands for w

### ORDERS OF ELEMENTS IN A GROUP

ORDERS OF ELEMENTS IN A GROUP KEITH CONRAD 1. Introduction Let G be a group and g G. We say g has finite order if g n = e for some positive integer n. For example, 1 and i have finite order in C, since

### THREE DIMENSIONAL GEOMETRY

Chapter 8 THREE DIMENSIONAL GEOMETRY 8.1 Introduction In this chapter we present a vector algebra approach to three dimensional geometry. The aim is to present standard properties of lines and planes,

### 2. Compressing data to reduce the amount of transmitted data (e.g., to save money).

Presentation Layer The presentation layer is concerned with preserving the meaning of information sent across a network. The presentation layer may represent (encode) the data in various ways (e.g., data

### MODULAR ARITHMETIC. a smallest member. It is equivalent to the Principle of Mathematical Induction.

MODULAR ARITHMETIC 1 Working With Integers The usual arithmetic operations of addition, subtraction and multiplication can be performed on integers, and the result is always another integer Division, on

### Induction and Recursion

Induction and Recursion Jan van Eijck June 3, 2003 Abstract A very important proof method that is not covered by the recipes from Chapter 3 is the method of proof by Mathematical Induction. Roughly speaking,

### Functional Programming. Functional Programming Languages. Chapter 14. Introduction

Functional Programming Languages Chapter 14 Introduction Functional programming paradigm History Features and concepts Examples: Lisp ML 1 2 Functional Programming Functional Programming Languages The

### The Clean programming language. Group 25, Jingui Li, Daren Tuzi

The Clean programming language Group 25, Jingui Li, Daren Tuzi The Clean programming language Overview The Clean programming language first appeared in 1987 and is still being further developed. It was

### I. GROUPS: BASIC DEFINITIONS AND EXAMPLES

I GROUPS: BASIC DEFINITIONS AND EXAMPLES Definition 1: An operation on a set G is a function : G G G Definition 2: A group is a set G which is equipped with an operation and a special element e G, called

### NOTES ON CATEGORIES AND FUNCTORS

NOTES ON CATEGORIES AND FUNCTORS These notes collect basic definitions and facts about categories and functors that have been mentioned in the Homological Algebra course. For further reading about category

### A simple algorithm with no simple verication

A simple algorithm with no simple verication Laszlo Csirmaz Central European University Abstract The correctness of a simple sorting algorithm is resented, which algorithm is \evidently wrong" at the rst

### MA651 Topology. Lecture 6. Separation Axioms.

MA651 Topology. Lecture 6. Separation Axioms. This text is based on the following books: Fundamental concepts of topology by Peter O Neil Elements of Mathematics: General Topology by Nicolas Bourbaki Counterexamples

### MATH PROBLEMS, WITH SOLUTIONS

MATH PROBLEMS, WITH SOLUTIONS OVIDIU MUNTEANU These are free online notes that I wrote to assist students that wish to test their math skills with some problems that go beyond the usual curriculum. These

### Math Review. for the Quantitative Reasoning Measure of the GRE revised General Test

Math Review for the Quantitative Reasoning Measure of the GRE revised General Test www.ets.org Overview This Math Review will familiarize you with the mathematical skills and concepts that are important

### Local periods and binary partial words: An algorithm

Local periods and binary partial words: An algorithm F. Blanchet-Sadri and Ajay Chriscoe Department of Mathematical Sciences University of North Carolina P.O. Box 26170 Greensboro, NC 27402 6170, USA E-mail:

### Problems on Discrete Mathematics 1

Problems on Discrete Mathematics 1 Chung-Chih Li Kishan Mehrotra 3 L A TEX at July 18, 007 1 No part of this book can be reproduced without permission from the authors Illinois State University, Normal,

### Matrix Algebra. Some Basic Matrix Laws. Before reading the text or the following notes glance at the following list of basic matrix algebra laws.

Matrix Algebra A. Doerr Before reading the text or the following notes glance at the following list of basic matrix algebra laws. Some Basic Matrix Laws Assume the orders of the matrices are such that

### MATH REVIEW KIT. Reproduced with permission of the Certified General Accountant Association of Canada.

MATH REVIEW KIT Reproduced with permission of the Certified General Accountant Association of Canada. Copyright 00 by the Certified General Accountant Association of Canada and the UBC Real Estate Division.

### TOPIC 4: DERIVATIVES

TOPIC 4: DERIVATIVES 1. The derivative of a function. Differentiation rules 1.1. The slope of a curve. The slope of a curve at a point P is a measure of the steepness of the curve. If Q is a point on the

### 3. Mathematical Induction

3. MATHEMATICAL INDUCTION 83 3. Mathematical Induction 3.1. First Principle of Mathematical Induction. Let P (n) be a predicate with domain of discourse (over) the natural numbers N = {0, 1,,...}. If (1)

### 3. Equivalence Relations. Discussion

3. EQUIVALENCE RELATIONS 33 3. Equivalence Relations 3.1. Definition of an Equivalence Relations. Definition 3.1.1. A relation R on a set A is an equivalence relation if and only if R is reflexive, symmetric,

### Problem Set. Problem Set #2. Math 5322, Fall December 3, 2001 ANSWERS

Problem Set Problem Set #2 Math 5322, Fall 2001 December 3, 2001 ANSWERS i Problem 1. [Problem 18, page 32] Let A P(X) be an algebra, A σ the collection of countable unions of sets in A, and A σδ the collection

### 1.2 Truth and Sentential Logic

Chapter 1 Mathematical Logic 13 69. Assume that B has m left parentheses and m right parentheses and that C has n left parentheses and n right parentheses. How many left parentheses appear in (B C)? How

### SUBGROUPS OF CYCLIC GROUPS. 1. Introduction In a group G, we denote the (cyclic) group of powers of some g G by

SUBGROUPS OF CYCLIC GROUPS KEITH CONRAD 1. Introduction In a group G, we denote the (cyclic) group of powers of some g G by g = {g k : k Z}. If G = g, then G itself is cyclic, with g as a generator. Examples

### Solutions to TOPICS IN ALGEBRA I.N. HERSTEIN. Part II: Group Theory

Solutions to TOPICS IN ALGEBRA I.N. HERSTEIN Part II: Group Theory No rights reserved. Any part of this work can be reproduced or transmitted in any form or by any means. Version: 1.1 Release: Jan 2013

### On every sheet please give your first name, last name, and matriculation number.

RHEINISCH- WESTFÄLISCHE TECHNISCHE HOCHSCHULE AACHEN LEHR- UND FORSCHUNGSGEBIET INFORMATIK 2 RWTH Aachen D-52056 Aachen GERMANY http://verify.rwth-aachen.de/ LuFG Informatik II Functional Programming Exam,

### CONTENTS 1. Peter Kahn. Spring 2007

CONTENTS 1 MATH 304: CONSTRUCTING THE REAL NUMBERS Peter Kahn Spring 2007 Contents 2 The Integers 1 2.1 The basic construction.......................... 1 2.2 Adding integers..............................

### Exercises with solutions (1)

Exercises with solutions (). Investigate the relationship between independence and correlation. (a) Two random variables X and Y are said to be correlated if and only if their covariance C XY is not equal

### Predicate Logic Review

Predicate Logic Review UC Berkeley, Philosophy 142, Spring 2016 John MacFarlane 1 Grammar A term is an individual constant or a variable. An individual constant is a lowercase letter from the beginning

### = 2 + 1 2 2 = 3 4, Now assume that P (k) is true for some fixed k 2. This means that

Instructions. Answer each of the questions on your own paper, and be sure to show your work so that partial credit can be adequately assessed. Credit will not be given for answers (even correct ones) without

### Introduction to Algebraic Geometry. Bézout s Theorem and Inflection Points

Introduction to Algebraic Geometry Bézout s Theorem and Inflection Points 1. The resultant. Let K be a field. Then the polynomial ring K[x] is a unique factorisation domain (UFD). Another example of a

### Inference Rules and Proof Methods

Inference Rules and Proof Methods Winter 2010 Introduction Rules of Inference and Formal Proofs Proofs in mathematics are valid arguments that establish the truth of mathematical statements. An argument

### A Programming Language for Mechanical Translation Victor H. Yngve, Massachusetts Institute of Technology, Cambridge, Massachusetts

[Mechanical Translation, vol.5, no.1, July 1958; pp. 25-41] A Programming Language for Mechanical Translation Victor H. Yngve, Massachusetts Institute of Technology, Cambridge, Massachusetts A notational

### Automata and Languages

Automata and Languages Computational Models: An idealized mathematical model of a computer. A computational model may be accurate in some ways but not in others. We shall be defining increasingly powerful