Natural Numbers. We will use natural numbers to illustrate several ideas that will apply to Haskell data types in general.

Similar documents
Programming Languages Third Edition

CIS 194: Homework 8. Due Wednesday, 8 April. Propositional Logic. Implication

CSC Discrete Math I, Spring Sets

MITOCW watch?v=4dj1oguwtem

AXIOMS FOR THE INTEGERS

Lecture 1. 1 Notation

This is already grossly inconvenient in present formalisms. Why do we want to make this convenient? GENERAL GOALS


CHAPTER 8. Copyright Cengage Learning. All rights reserved.

Introduction to dependent types in Coq

9.5 Equivalence Relations

To illustrate what is intended the following are three write ups by students. Diagonalization

Ramsey s Theorem on Graphs

4&5 Binary Operations and Relations. The Integers. (part I)

4 Mathematical Data Types

Material from Recitation 1

Overview. CS389L: Automated Logical Reasoning. Lecture 6: First Order Logic Syntax and Semantics. Constants in First-Order Logic.

Lecture 5. Logic I. Statement Logic

Lecture 7: Primitive Recursion is Turing Computable. Michael Beeson

Lesson 4 Typed Arithmetic Typed Lambda Calculus

MATH20902: Discrete Maths, Solutions to Problem Set 1. These solutions, as well as the corresponding problems, are available at

Formal Methods of Software Design, Eric Hehner, segment 1 page 1 out of 5

Program Calculus Calculational Programming

Order from Chaos. University of Nebraska-Lincoln Discrete Mathematics Seminar

An Introduction to Programming and Proving in Agda (incomplete draft)

Guidelines for Writing Mathematical Proofs

We ve studied the main models and concepts of the theory of computation:

CS103 Spring 2018 Mathematical Vocabulary

Integers and Mathematical Induction

Order from Chaos. Nebraska Wesleyan University Mathematics Circle

Formal Methods of Software Design, Eric Hehner, segment 24 page 1 out of 5

Lecture 6,

Utility Maximization

Module 2 Congruence Arithmetic pages 39 54

Semantics via Syntax. f (4) = if define f (x) =2 x + 55.

Programming with Math and Logic

ELEMENTARY NUMBER THEORY AND METHODS OF PROOF

Exercise 1 ( = 22 points)

These notes are intended exclusively for the personal usage of the students of CS352 at Cal Poly Pomona. Any other usage is prohibited without

Topic 1: What is HoTT and why?

ELEMENTARY NUMBER THEORY AND METHODS OF PROOF

(Refer Slide Time: 4:00)

2.3 Algebraic properties of set operations

1 Introduction CHAPTER ONE: SETS

Math Introduction to Advanced Mathematics

Chapter 18 out of 37 from Discrete Mathematics for Neophytes: Number Theory, Probability, Algorithms, and Other Stuff by J. M. Cargal.

Sets. {1, 2, 3, Calvin}.

CONNECTED SPACES AND HOW TO USE THEM

In this chapter, we define limits of functions and describe some of their properties.

Lecture 4: examples of topological spaces, coarser and finer topologies, bases and closed sets

Inference rule for Induction

Lecture Notes on Program Equivalence

Denotational Semantics. Domain Theory

Lesson 10. Student Outcomes. Lesson Notes

Lecture 10. Finding strongly connected components

Solutions to In-Class Problems Week 4, Fri

THREE LECTURES ON BASIC TOPOLOGY. 1. Basic notions.

MATH10001 Mathematical Workshop. Graphs, Trees and Algorithms Part 2. Trees. From Trees to Prüfer Codes

2. CONNECTIVITY Connectivity

Chapter 3. Set Theory. 3.1 What is a Set?

Point-Set Topology 1. TOPOLOGICAL SPACES AND CONTINUOUS FUNCTIONS

MAT 3271: Selected Solutions to the Assignment 6

.Math 0450 Honors intro to analysis Spring, 2009 Notes #4 corrected (as of Monday evening, 1/12) some changes on page 6, as in .

Built-in Module BOOL. Lecture Note 01a

MATHEMATICS 191, FALL 2004 MATHEMATICAL PROBABILITY Outline #1 (Countability and Uncountability)

Types and Programming Languages. Lecture 8. Recursive type

Figure 4.1: The evolution of a rooted tree.

axiomatic semantics involving logical rules for deriving relations between preconditions and postconditions.

The Encoding Complexity of Network Coding

TOPOLOGY CHECKLIST - SPRING 2010

ELEMENTARY NUMBER THEORY AND METHODS OF PROOF

From Types to Sets in Isabelle/HOL

Structures with lots of symmetry

Lecture 3: Recursion; Structural Induction

This Lecture. We will first introduce some basic set theory before we do counting. Basic Definitions. Operations on Sets.

Recursively Enumerable Languages, Turing Machines, and Decidability

Introduction to Homotopy Type Theory

MC 302 GRAPH THEORY 10/1/13 Solutions to HW #2 50 points + 6 XC points

From natural numbers to the lambda calculus

Introduction to Counting, Some Basic Principles

The Structure of Bull-Free Perfect Graphs

3 Fractional Ramsey Numbers

COMPUTABILITY THEORY AND RECURSIVELY ENUMERABLE SETS

9/19/12. Why Study Discrete Math? What is discrete? Sets (Rosen, Chapter 2) can be described by discrete math TOPICS

Solution Set 8 Date: 1 December, 1992

CS 6110 S14 Lecture 1 Introduction 24 January 2014

Notes for Recitation 8

3.1 Constructions with sets

n λxy.x n y, [inc] [add] [mul] [exp] λn.λxy.x(nxy) λmn.m[inc]0 λmn.m([add]n)0 λmn.n([mul]m)1

(Refer Slide Time: 0:19)

Math 443/543 Graph Theory Notes

Bases of topologies. 1 Motivation

Mathematics for Computer Scientists 2 (G52MC2)

Reasoning About Programs Panagiotis Manolios

CS 320: Concepts of Programming Languages

Logical Verification Course Notes. Femke van Raamsdonk Vrije Universiteit Amsterdam

PACKING DIGRAPHS WITH DIRECTED CLOSED TRAILS

Review of Sets. Review. Philippe B. Laval. Current Semester. Kennesaw State University. Philippe B. Laval (KSU) Sets Current Semester 1 / 16

Expr_annotated.v. Expr_annotated.v. Printed by Zach Tatlock

Functions. How is this definition written in symbolic logic notation?

Transcription:

Natural Numbers We will use natural numbers to illustrate several ideas that will apply to Haskell data types in general. For the moment we will ignore that fact that each type in Haskell includes possible value. as a We note that it is only possible to define the natural numbers up to isomorphism. Natural Numbers F. Warren Burton 1

1 Peano s Axioms Let s consider a definition of Natural Numbers,, based on Peano s axioms. 1. 2.. Natural Numbers F. Warren Burton 2

Oops, we forgot to exclude negative numbers! 1. 2.. 3. Natural Numbers F. Warren Burton 3

We also need one more axiom. 1. 2.. 3. 4. Natural Numbers F. Warren Burton 4

Oh my gosh! I just noticed that the nonnegative real numbers, the rational excluding negative integers, and lots of other sets, all satisfy these axioms. I forgot the induction axiom! 1. 2.. 3. 4. 5. For any predicate in the first order predicate calculus, The induction axiom insures that axioms. is the smallest set that satisfies the above Natural Numbers F. Warren Burton 5

While you were looking at the previous page, I remembered that there are some completeness issues with the axioms for number theory. The axioms on the previous page are satisfied by an infinite number of sets, most of which are a bit weird. We have to allow to be any predicate. 1. 2.. 3. 4. 5. For any predicate, Natural Numbers F. Warren Burton 6

Since we have no way of expressing more than a countable subset of the predicates on, perhaps it is better to restate the final axiom in terms of sets. 1. 2.. 3. 4. 5. Natural Numbers F. Warren Burton 7

Are you really sure we finally have a correct definition for the natural numbers? Are you even sure I finally managed to get my parentheses balanced correctly? Natural Numbers F. Warren Burton 8

2 Natural Numbers defined using Category Theory Let s try another approach. Consider a category, An Object is any triple (for unary system), where such that is a set,, and is a function. An Arrow is any homomorphism between objects. The desired unary system,, is an initial object in this category. (An initial object is an object such that for any object,, there is exactly one arrow from the initial object to. In particular, there is exactly one arrow from the initial object to itself, which in this case is the identity function.) Natural Numbers F. Warren Burton 9

We will define category, object, arrow and initial object later. Initial objects are unique up to isomorphism, when they exist, and in cases like this initial objects always exist. For now, all we need to understand about this definition is that the natural numbers is a unary system such that for another unary system there is exactly one homomorphism from the natural numbers to the other unary system. If and are any two unary systems, then a homomorphism,, is a structure preserving function from to. That is Later we will give a more general definition of homomorphism that will apply to a variety of different structures. Natural Numbers F. Warren Burton 10

To see that is an initial object, it is sufficient to show that for any other object,, in there is a unique homomorphism from to. Clearly, defined by is the unique homomorphism. This is clearly the case because of our intuitive understanding of the natural numbers. We are actually using the requirement that the above holds to define the natural numbers. Natural Numbers F. Warren Burton 11

Quiz: For each of the following unary systems, (i) find the unique homomorphism from to the system, (ii) determine whether there are zero, one or more than one homomorphisms from the unary system to, (iii) find either two or all homomorphisms from the unary system to, and in the case of a unique homomorphism to determine if the homomorphism is an isomorphism. 1. 2. 3. Nonempty strings over 4., where 5. 6. 7. Natural Numbers F. Warren Burton 12

Quiz: 1. Prove that if is a homomorphism from to and is a homomorphism from to then is also a homomorphism. 2. Prove that if for each unary system there is a unique homomorphism from to that unary system, then is isomorphic to. Note: and are isomorphic unary systems if there exist homomorphisms and such that and. Natural Numbers F. Warren Burton 13

3 Haskell Nats With Bird s definition of Nats in Haskell (ignoring the deriving stuff), data Nat = Zero Succ Nat we have an additional constructor,. Everything we have done so far carries over with minimal change. Instead of a unary system we have (Nat, Zero,, Succ). A homomorphism from Nat Zero Nat Succ to is a function Nat such that Zero Nat Nat Succ Natural Numbers F. Warren Burton 14

We will usually refer to without using a subscript, even though each domain (set of values corresponding to a type more or less) has a different. Sometimes we will skip explicitly mentioning, since the impact of adding is straight forward. The second condition on the previous page, is strict., will usually be stated as Natural Numbers F. Warren Burton 15

4 Catamorphisms The homomorphisms from Nat, or more generally homomorphisms from types defined by Haskell data statements, are called catamorphisms. The catamorphisms for a type are exactly the functions that can be defined using the function for the type. Natural Numbers F. Warren Burton 16

The functions for Nat s (given in Bird) is foldn :: (a -> a) -> a -> Nat -> a foldn h c Zero = c foldn h c (Succ n) = h (foldn h c n) Recall that is a homomorphism from Nat Zero Succ to iff is strict Zero Nat Succ in which case foldn The third condition above, Nat Succ, can be written more compactly as Succ. Natural Numbers F. Warren Burton 17

Another way to look at foldn :: (a -> a) -> a -> Nat -> a foldn h c Zero = c foldn h c (Succ n) = h (foldn h c n) is that foldn h c n constructs a new value by replacing the Zero constructor in n with c and each Succ constructor with h. For example foldn h c (Succ (Succ (Succ Zero))) = h (h (h c)) Natural Numbers F. Warren Burton 18

4.1 Fusion Suppose foldn g a is a homomorphism from (Nat,Zero,,Succ) to (,a,,g), foldn h b is a homomorphism from (Nat,Zero,,Succ) to (,b,,h), and f is a homomorphism from (,a,,g) to (,b,,h). Since the composition of two homomorphisms is a homomorphism, and there is exactly one homomorphism from (Nat,Zero,,Succ) to (,b,,h), it must be the case that: f. foldn g a = foldn h b Natural Numbers F. Warren Burton 19

The result on the previous page is the fusion Law for Nat. In the book, the condition that f is a homomorphism is stated as f is strict f a = b f.g = h.f It may help to note that Zero: Nat Succ: Nat -> Nat a: g: -> b: h: -> f: -> Natural Numbers F. Warren Burton 20

4.2 Induction In Bird, the fusion law for Nats was proved using induction. We will reverse this process and show, using the fusion law for Nats, that proof by induction is valid on. Before going into detail, let us consider why we can prove the validity of proof by induction, while mathematicians regard induction as an axiom. Recall that on page 10 we defined the natural numbers to be an initial object of the category of unary systems, which implicitly assumed that an initial object exists. It turns out that this assumption is equivalent to the induction axiom. Natural Numbers F. Warren Burton 21

We will break our proof into a number of small lemmas so that each lemma and its proof can be written on a single page. We will use the following definitions throughout the lemmas and the theorem that follows. f1 n = (n, True) f2 n = (n, p n) g = Succ h (n, q) = (Succ n, q p (Succ n)) a = Zero b1 = f1 a = (Zero, True) b2 = f2 a = (Zero, p Zero) While our work is done using the notation of Haskell, we note that the results will still hold even if p is not a computable predicate. Natural Numbers F. Warren Burton 22

Important: In our consideration of natural numbers, we will restrict our attention to. In particular, we will not allow numbers to be or partial numbers, or infinite. This seems reasonable, since induction is usually expressed in terms of rather than Nat. Furthermore, we will assume that p is a total predicate (i.e. (p n) can never be ). This seems reasonable, since we are not restricting p to be a computable predicate. Natural Numbers F. Warren Burton 23

Lemma 1 foldn Succ Zero = id Proof: The function foldn Succ Zero is a homomorphism from to. The identity function is also a homomorphism from to. Since there can be only one such homomorphism, the result holds. Notice that we avoided using induction, since that would result in a circular argument. Natural Numbers F. Warren Burton 24

Lemma 2 If p n p (Succ n) then Proof: If p (Succ n) = (p n p (Succ n)) p n = True then p (Succ n) True (assumptions: p n = True and p n p (Succ n)) (algebra of logic) True p (Succ n) (asumption: p n = True) p n p (Succ n) Otherwise (p n = False), by a similar argument p (Succ n) = False p (Succ n) = p n p (Succ n) Natural Numbers F. Warren Burton 25

If we allow p n to be then Lemma 2 will no longer hold. However, we can define a predicate, which may not be computable, by True p n True False p n False False p n Now, if then. Natural Numbers F. Warren Burton 26

Lemma 3 f1.g = h.f1 Proof: For any n (f1.g) n (plug and grind) (Succ n, True) (algebra of logic) (Succ n, True p (Succ n)) (plug and grind) (h.f1) n so the result holds by extensionality. Natural Numbers F. Warren Burton 27

Lemma 4 f1 = foldn h (Zero, True) Proof: f1 (Lemma 1) f1. foldn Succ Zero (fusion; Lemma 3) foldn h (f1 Zero) (plug and grind) foldn h (Zero, True) The fusion step uses: f1.foldn Succ Zero = foldn h (f1 Zero) Natural Numbers F. Warren Burton 28

Lemma 5 If p n p (Succ n) then f2.g = h.f2 Proof: For any n (f2.g) n (plug and grind) (Succ n, p (Succ n)) (Lemma 2) (Succ n, p n p (Succ n)) (plug and grind) (h.f2) n so the result holds by extensionality. Natural Numbers F. Warren Burton 29

Lemma 6 If (p Zero) (p n p (Succ n)) then f2 = foldn h (Zero, True) Proof: f2 (Lemma 1) f2. foldn Succ Zero (fusion; Lemma 5) foldn h (f2 Zero) (p Zero is True) foldn h (Zero, True) The fusion step uses: f2.foldn Succ Zero = foldn h (f2 Zero) Natural Numbers F. Warren Burton 30

Theorem 1 (Induction) If (p Zero) (p n p (Succ n)) then n p n = True Proof: On (but not Nat), by Lemma 4 and Lemma 6, so Since f1 = f2 snd.f1 = snd.f2 (snd.fl) n = True (snd.f2) n = p n We have the desired result, that for n p n = True. Natural Numbers F. Warren Burton 31