Quick Review Get paper and pencil out. Not graded just for review.

Slides:



Advertisements
Similar presentations
Substitution & Evaluation Order cos 441 David Walker.
Advertisements

Tree Recursion Traditional Approach. Tree Recursion Consider the Fibonacci Number Sequence: Time: , 1, 1, 2, 3, 5, 8, 13, 21,... /
Type Inference David Walker COS 320. Criticisms of Typed Languages Types overly constrain functions & data polymorphism makes typed constructs useful.
Computing Fundamentals 2 Introduction to CafeOBJ Lecturer: Patrick Browne Lecture Room: K408 Lab Room: A308 Based on work by: Nakamura Masaki, João Pascoal.
Functional Verification III Prepared by Stephen M. Thebaut, Ph.D. University of Florida Software Testing and Verification Lecture Notes 23.
Control-Flow Graphs & Dataflow Analysis CS153: Compilers Greg Morrisett.
Algebra Problems… Solutions Algebra Problems… Solutions © 2007 Herbert I. Gross Set 7 part 2 By Herb I. Gross and Richard A. Medeiros next.
Steps to Solve Word Problems 1.Read the problem carefully. 2.Get rid of clutter 3.Identify key variables (unknowns). 4.Eliminate unneeded variables. 5.Use.
Algebra Problems… Solutions Algebra Problems… Solutions © 2007 Herbert I. Gross Set 22 By Herbert I. Gross and Richard A. Medeiros next.
Induction: One Step At A Time Great Theoretical Ideas In Computer Science Steven RudichCS Spring 2004 Lecture 4Jan 22, 2004Carnegie Mellon University.
Snick  snack CPSC 121: Models of Computation 2011 Winter Term 1 Revisiting Induction Steve Wolfman, based on work by Patrice Belleville and others 1.
Parametric Polymorphism COS 441 Princeton University Fall 2004.
Inductive Definitions COS 510 David Walker. Inductive Definitions Inductive definitions play a central role in the study of programming languages They.
CS70 L23 Hashing (1)Dan Garcia © UCB Dan Garcia ( inst.eecs.berkeley.edu/~cs70/ 1 Handout: notes Computer Science.
Some administrative stuff Class mailing list: –send to with the command “subscribe”
Type Inference David Walker CS 510, Fall Criticisms of Typed Languages Types overly constrain functions & data polymorphism makes typed constructs.
Aggregate Data Structures COS 441 Princeton University Fall 2004.
COS 320 Compilers David Walker. Outline Last Week –Introduction to ML Today: –Lexical Analysis –Reading: Chapter 2 of Appel.
HOT Programming in Java COS 441 Princeton University Fall 2004.
CS 330 Programming Languages 09 / 16 / 2008 Instructor: Michael Eckmann.
Semantics for MinML COS 441 Princeton University Fall 2004.
How to Convert a Context-Free Grammar to Greibach Normal Form
Today’s quiz on 8.2 A Graphing Worksheet 1 will be given at the end of class. You will have 12 minutes to complete this quiz, which will consist of one.
Today’s quiz on 8.2 B Graphing Worksheet 2 will be given at the end of class. You will have 12 minutes to complete this quiz, which will consist of one.
Room Change!!!! Starting Wednesday Room 302. Inductive Definitions COS 441 Princeton University Fall 2004.
Algebra 1 Ch 4.2 – Graphing Linear Equations. Objective Students will graph linear equations using a table. Students will graph linear equations using.
What is a function?.
Keystone Problems… Keystone Problems… next Set 19 © 2007 Herbert I. Gross.
Please open your laptops, log in to the MyMathLab course web site, and open Quiz 5.1. You may use the pink formula sheet on this quiz – please don’t write.
Grade Scale Test 1 Results: Average class score after partial credit: __________ Commonly missed questions: #_________________ If you got less than 70%
Chapter Sequences and Series.
Please open Daily Quiz 34. A scientific calculator may be used on this quiz. You can keep your yellow formula sheets out when you take the quiz. Remember.
CSE 311: Foundations of Computing Fall 2013 Lecture 8: More Proofs.
1 Inference Rules and Proofs (Z); Program Specification and Verification Inference Rules and Proofs (Z); Program Specification and Verification.
March 3, 2015Applied Discrete Mathematics Week 5: Mathematical Reasoning 1Arguments Just like a rule of inference, an argument consists of one or more.
Test Wednesday Review Answers.
Week 12 - Wednesday.  What did we talk about last time?  Asymptotic notation.
CSE-321 Programming Languages Inductive Definitions POSTECH March 14, 2007 박성우.
CSE-321 Programming Languages Inductive Definitions POSTECH March 15, 2006 박성우.
Algebra Problems… Solutions Algebra Problems… Solutions © 2007 Herbert I. Gross Set 10 By Herbert I. Gross and Richard A. Medeiros next.
Week 6 - Monday.  What did we talk about last time?  Exam 1!  Before that:  Recursion.
Lecture 2 Jan Goals: Introduction to recursion Examples of recursive programs Reading: Chapter 1 of the text.
Reading and Writing Mathematical Proofs Spring 2015 Lecture 4: Beyond Basic Induction.
1 Compiler Construction (CS-636) Muhammad Bilal Bashir UIIT, Rawalpindi.
LESSON 7.4 Function Notation To learn function notation To evaluate functions by substitution, by using the graphs drawn by hand, and on the graphing calculator.
Algebra Problems… Solutions Algebra Problems… Solutions © 2007 Herbert I. Gross Set 17 part 2 By Herbert I. Gross and Richard A. Medeiros next.
2.4 Other Types of Equations Objectives: 1. Solve absolute-value equations. 2. Solve radical equations. 3. Solve fractional equations.
Types and Programming Languages
CS412/413 Introduction to Compilers Radu Rugina Lecture 13 : Static Semantics 18 Feb 02.
Exponential and Logarithmic Functions
Inductive Definitions Kangwon National University 임현승 Programming Languages These slides were originally created by Prof. Sungwoo Park at POSTECH.
Reading and Writing Mathematical Proofs Spring 2016 Lecture 2: Basic Proving Techniques II.
Polynomials Graphing and Solving. Standards MM3A1. Students will analyze graphs of polynomial functions of higher degree. a. Graph simple polynomial functions.
6/12/2016 Prepared by Dr.Saad Alabbad1 CS100 : Discrete Structures Proof Techniques(2) Mathematical Induction & Recursion Dr.Saad Alabbad Department of.
CS 461 – Sept. 23 Context-free grammars Derivations Ambiguity Proving correctness.
Quiz 1 A sample quiz 1 is linked to the grading page on the course web site. Everything up to and including this Friday’s lecture except that conditionals.
1 Proving Properties of Recursive List Functions CS 270 Math Foundations of CS Jeremy Johnson.
Quadratic Equations Lesson 4-5 Part 1
UNIT 2 LESSON 9 IMPLICIT DIFFERENTIATION 1. 2 So far, we have been differentiating expressions of the form y = f(x), where y is written explicitly in.
The material in this lecture should be review. If you have not seen it before, you should be able to learn it quickly – and on your own. So we are going.
Introduction to Parsing (adapted from CS 164 at Berkeley)
Goal for this lecture Demonstrate how we can prove that one query language is more expressive than (i.e., “contained in” as described in the book) another.
What is a function?.
Warm Up What are the first 5 terms of a sequence with the following:
Functional Programming
Induction: One Step At A Time
Induction: One Step At A Time
f(x) y x A function is a relation that gives a single
Induction: One Step At A Time
Presentation transcript:

Quick Review Get paper and pencil out. Not graded just for review.

Questions

succ( X ) int X int S zero int Z pred( X ) int X int P Write a derivation tree for pred(succ(zero)) int

succ( X ) int X int S zero int Z pred( X ) int X int P Is the rule below derivable, admissible, or neither? eq(pred(succ( X )), X ) X int R0

succ( X ) int X int S zero int Z pred( X ) int X int P Is the rule below derivable, admissible, or neither? succ( X ) int pred( X ) int R1

succ( X ) int X int S zero int Z pred( X ) int X int P Is the rule below derivable, admissible, or neither? succ(pred( X )) int X int R2

succ( X ) int X int S zero int Z pred( X ) int X int P Is the rule below derivable, admissible, or neither? pred(succ( X )) int pred( X ) int R3

succ( X ) int X int S zero int Z pred( X ) int X int P Is the rule below derivable, admissible, or neither? pred(succ( X )) int succ( X ) int R4

succ( X ) int X int S zero int Z pred( X ) int X int P Prove the following If X nat then X int (just sketch out the structure)

succ( X ) int X int S zero int Z pred( X ) int X int P What is the principle of rule induction look like for the rules above?

Answers

succ( X ) int X int S zero int Z pred( X ) int X int P pred(succ(zero)) int succ(zero) int P zero int SZ Write a derivation tree for

succ( X ) int X int S zero int Z pred( X ) int X int P Is the rule below derivable, admissible, or neither? eq(pred(succ( X )), X ) X int R0

succ( X ) int X int S zero int Z pred( X ) int X int P Is the rule below is neither derivable or admissible. eq(pred(succ( X )), X ) X int R0

succ( X ) int X int S zero int Z pred( X ) int X int P Is the rule below derivable, admissible, or neither? succ( X ) int pred( X ) int R1

succ( X ) int X int S zero int Z pred( X ) int X int P The rule below is admissible. succ( X ) int pred( X ) int R1

succ( X ) int X int S zero int Z pred( X ) int X int P Is the rule below derivable, admissible, or neither? succ(pred( X )) int X int R2

succ( X ) int X int S zero int Z pred( X ) int X int P The rule below is derivable. succ(pred( X )) int X int R2

succ( X ) int X int S zero int Z pred( X ) int X int P Is the rule below derivable, admissible, or neither? pred(succ( X )) int pred( X ) int R3

succ( X ) int X int S zero int Z pred( X ) int X int P The rule below is admissible. pred(succ( X )) int pred( X ) int R3

succ( X ) int X int S zero int Z pred( X ) int X int P Is the rule below derivable, admissible, or neither? pred(succ( X )) int succ( X ) int R4

succ( X ) int X int S zero int Z pred( X ) int X int P The rule below is derivable. pred(succ( X )) int succ( X ) int R4

succ( X ) int X int S zero int Z pred( X ) int X int P Prove the following If X nat then X int (just sketch out the structure, i.e.)

Proof Sketch By induction on X nat IH(x) = If x nat then x int Subgoal1: IH( zero ) Subgoal2: If IH(X’) then IH( succ( X’ ) )

succ( X ) int X int S zero int Z pred( X ) int X int P What is the principle of rule induction look like for the rules above?

Rule Induction Principle If X int, P( zero ), if P(X’) then P( succ( X’ ) ), and if P(Y’) then P( pred( Y’ ) ) then P(X)

Did You Ace The Quiz? If so great! If not go through the notes and the slides from lecture 1 Still stuck talk to me or the TA Did the entire class ace the quiz? –Probably not you are not the only one who is is confused!

Inductively Defined Functions and Standard ML COS 441 Princeton University Fall 2004

Assignment 1 Handout today due back next Wednesday Requires ML programming an a few simple proofs Make sure you’re all set up to use your CS account and program in ML Details and updates available through the course web

Relations Review A relation is set of tuples Odd = {1, 3, 5, … } Line = { (0.0, 0.0), (1.5,1.5), (x, x), …} Circle = { (x, y) | x 2 + y 2 = 1.0 } Odd is a predicate on natural numbers Line, Circle, and Sphere are relations on real numbers Line is a function

Functions and Their Graphs The graph of a function f(x) is the unique relation {(x,y) | f(x) = y } We can uniquely specify a function by defining its graph as a relation Not all relations specify valid functions!

Below are some plotted graphs of the relations Circle and Line For a relation to be a valid graph of a function each unique input has a unique output Some “graphs” of Relations Line Circle

Defining the Function add We want to define a function add(m,n) To do this first specify a relation that defines its graph A(m,n,p) inductively Next show that our for any unique pair of m and n there is a unique p such that A(m,n,p)

Defining the Graph of add A(X, zero,X) X nat A-Z A(X, succ( Y ), succ( Z ) ) A(X,Y,Z)A(X,Y,Z) A-S

Avoiding Clutter A(X, succ( Y ), succ( Z ) ) X nat Y nat Z nat A(X,Y,Z) A-S Alternative definition that is equivalent to our previous one but its more cluttered since we have redundant premises A(X, zero,X) X nat A-Z Why are the all those extra premises not needed?

Defining the Graph of add A(X, zero,X) X nat A-Z A(X, succ( Y ), succ( Z ) ) A(X,Y,Z)A(X,Y,Z) A-S X nat A(X,Y,Z)A(X,Y,Z) A-X-nat The definition above immediately entails the following rules Why? Y nat A(X,Y,Z)A(X,Y,Z) A-Y-nat Z nat A(X,Y,Z)A(X,Y,Z) A-Z-nat

Defining the Graph of add A(X, zero,X) X nat A-Z A(X, succ( Y ), succ( Z ) ) A(X,Y,Z)A(X,Y,Z) A-S X nat A(X,Y,Z)A(X,Y,Z) A-X-nat The definition above immediately entails the following rules They can be shown to be admissible with the principle of rule induction for derivations of A and the rules Z and S Y nat A(X,Y,Z)A(X,Y,Z) A-Y-nat Z nat A(X,Y,Z)A(X,Y,Z) A-Z-nat

Proving A is a Function Graph If A(X,Y,Z), X unique, and Y unique then Z is unique. Proof: By ??

Proving A is a Function Graph If A(X,Y,Z), X unique, and Y unique then Z is unique. Proof: By rule induction for A(X,Y,Z)

Proving A is a Function Graph If A(X,Y,Z), X unique, and Y unique then Z is unique. Proof: By rule induction for A(X,Y,Z) If A(X,Y,Z), If X’ nat then P(X’, zero,X’), and If P(X’,Y’,Z’) then P(X’, succ( Y’ ), succ( Z’ ) ) then P(X,Y,Z).

Proving A is a Function Graph If A(X,Y,Z), case A-Z : If X’ nat then IH(X’, zero,X’), case A-S : If IH(X’,Y’,Z’) then IH(X’, succ( Y’ ), succ( Z’ ) ) then IH(X,Y,Z).

Proving A is a Function Graph If A(X,Y,Z), case A-Z : If X’ nat then IH(X’, zero,X’), case A-S : If IH(X’,Y’,Z’) then IH(X’, succ( Y’ ), succ( Z’ ) ) then IH(X,Y,Z). IH(x,y,z) = ??

Proving A is a Function Graph If A(X,Y,Z), case A-Z : If X’ nat then IH(X’, zero,X’), case A-S : If IH(X’,Y’,Z’) then IH(X’, succ( Y’ ), succ( Z’ ) ) then IH(X,Y,Z). IH(x,y,z) = If A(x,y,z), x unique, and y unique then z is unique.

Proving A is a Function Graph case A-Z : If X’ nat then IH(X’, zero,X’) IH(x,y,z) = If A(x,y,z), x unique, and y unique then z is unique.

Proving A is a Function Graph case A-Z : If X’ nat then if A(X’, zero,X’), X’ unique, and zero unique then X’ is unique.

Proving A is a Function Graph case A-Z : … then if A(X’, zero,X’), X’ unique, and zero unique then X’ is unique. 1. X’ nat by assumption

Proving A is a Function Graph case A-Z : … then X’ is unique. 1. X’ nat by assumption 2. A(X’, zero,X’), X’ unique, and zero unique by assumption

Proving A is a Function Graph case A-Z : 1. X’ nat by assumption 2. A(X’, zero,X’), X’ unique, and zero unique by assumption 3. X’ unique by (2)

Proving A is a Function Graph case A-S : If IH(X’,Y’,Z’) then IH(X’, succ( Y’ ), succ( Z’ ) ) IH(x,y,z) = If A(x,y,z), x unique, and y unique then z is unique.

Proving A is a Function Graph case A-S : … then if A(X’, succ( Y’ ), succ( Z’ ) ), X’ unique, and succ( Y’ ) unique then succ( Z’ ) is unique 1. IH(X’,Y’,Z’) by assumption IH(x,y,z) = If A(x,y,z), x unique, and y unique then z is unique.

Proving A is a Function Graph case A-S : … then succ( Z’ ) is unique 1. IH(X’,Y’,Z’) by assumption 2. A(X’, succ( Y’ ), succ( Z’ ) ), X’ unique, and succ( Y’ ) unique by assumption IH(x,y,z) = If A(x,y,z), x unique, and y unique then z is unique.

Proving A is a Function Graph case A-S : … then succ( Z’ ) is unique 1. IH(X’,Y’,Z’) by assumption 2. A(X’, succ( Y’ ), succ( Z’ ) ), X’ unique, and succ( Y’ ) unique by assumption 3. A(X’,Y’,Z’) by ?? IH(x,y,z) = If A(x,y,z), x unique, and y unique then z is unique.

Proving A is a Function Graph case A-S : … then succ( Z’ ) is unique 1. IH(X’,Y’,Z’) by assumption 2. A(X’, succ( Y’ ), succ( Z’ ) ), X’ unique, and succ( Y’ ) unique by assumption 3. A(X’,Y’,Z’) by (2) and invert-A-S IH(x,y,z) = If A(x,y,z), x unique, and y unique then z is unique.

Proving A is a Function Graph case A-S : … then succ( Z’ ) is unique 1. IH(X’,Y’,Z’) by assumption 2. A(X’, succ( Y’ ), succ( Z’ ) ), X’ unique, and succ( Y’ ) unique by assumption 3. A(X’,Y’,Z’) by (2) and invert-A-S 4. Y’ unique IH(x,y,z) = If A(x,y,z), x unique, and y unique then z is unique.

Proving A is a Function Graph case A-S : … then succ( Z’ ) is unique 1. IH(X’,Y’,Z’) by assumption 2. A(X’, succ( Y’ ), succ( Z’ ) ), X’ unique, and succ( Y’ ) unique by assumption 3. A(X’,Y’,Z’) by (2) and invert-A-S 4. Y’ unique by ?? IH(x,y,z) = If A(x,y,z), x unique, and y unique then z is unique.

Proving A is a Function Graph case A-S : … then succ( Z’ ) is unique 1. IH(X’,Y’,Z’) by assumption 2. A(X’, succ( Y’ ), succ( Z’ ) ), X’ unique, and succ( Y’ ) unique by assumption 3. A(X’,Y’,Z’) by (2) and invert-A-S 4. Y’ unique by ?? 5. Z’ unique by ?? IH(x,y,z) = If A(x,y,z), x unique, and y unique then z is unique.

Proving A is a Function Graph case A-S : … then succ( Z’ ) is unique 1. IH(X’,Y’,Z’) by assumption 2. A(X’, succ( Y’ ), succ( Z’ ) ), X’ unique, and succ( Y’ ) unique by assumption 3. A(X’,Y’,Z’) by (2) and invert-A-S 4. Y’ unique by ?? 5. Z’ unique by IH with (3,2,4) IH(x,y,z) = If A(x,y,z), x unique, and y unique then z is unique.

Proving A is a Function Graph case A-S : 1. IH(X’,Y’,Z’) by assumption 2. A(X’, succ( Y’ ), succ( Z’ ) ), X’ unique, and succ( Y’ ) unique by assumption 3. A(X’,Y’,Z’) by (2) and invert-A-S 4. Y’ unique by ?? 5. Z’ unique by IH with (3,2,4) 6. succ( Z’ ) unique by ?? IH(x,y,z) = If A(x,y,z), x unique, and y unique then z is unique.

Some Missing Pieces A(X,Y,Z)A(X,Y,Z) A(X, succ( Y ), succ( Z ) ) invert-A-S We need to assume the following –zero is unique –If X nat and X unique then succ (X) is unique –If X nat and succ (X) unique then X is unique It is okay to assume “obvious” things just be explicit about what you assume in proofs

A Function as Recursive Equations We often use different notations to defined the graph of a functions add(M, zero )  M add(M, succ( N ) )  succ( add(M,N) ) The equations define a relation implicitly that relation must still be shown to be the graph of a valid function

Example: Fibonacci Function fib( zero )  succ(zero) fib( succ(zero) )  succ(zero) fib( succ(succ( N )) )  add(fib( succ( N ) ), fib(N)) What are the rules for the relation being implicitly defined by the equations above?

Example: Fibonacci Function fib( zero )  succ(zero) fib( succ(zero) )  succ(zero) fib( succ(succ( N )) )  add(fib( succ( N ) ), fib(N)) F( zero, succ(zero) ) F-Z

Example: Fibonacci Function fib( zero )  succ(zero) fib( succ(zero) )  succ(zero) fib( succ(succ( N )) )  add(fib( succ( N ) ), fib(N)) F( zero, succ(zero) ) F-Z F( succ(zero), succ(zero) ) F-S-Z

Example: Fibonacci Function F( succ(zero), succ(zero) ) F-S-Z F( zero, succ(zero) ) F-Z F( succ(succ( N )),Z) F( succ( N ),X) F(N,Y) A(X,Y,Z) F-S-S-N

Example: Fibonacci Function F( succ(zero), succ(zero) ) F-S-Z F( zero, succ(zero) ) F-Z F( succ(succ( N )),Z) F( succ( N ),X) F(N,Y) A(X,Y,Z) F-S-S-N Does the relation F define the graph of a function? Why?

Summary of Definitions succ( X ) nat X nat S zero nat Z A(X, zero,X) X nat A-Z A(X, succ( Y ), succ( Z ) ) A(X,Y,Z)A(X,Y,Z) A-S F( succ(zero), succ(zero) ) F-S-Z F( zero, succ(zero) ) F-Z F( succ(succ( N )),Z) F( succ( N ),X) F(N,Y) A(X,Y,Z) F-S-S-N

Some Derivable Judgments F( succ(succ(zero)), succ(succ(zero)) ) F( succ(succ(succ(zero))), succ(succ(succ(zero))) ) F( succ(succ(succ(succ(zero)))), succ(succ(succ(succ(succ(zero)) ))) ) ….

From Relations to SML Deriving the judgments by hand is tedious! We can use SML as a calculator of sorts to directly express the function we defined as an SML function To do this first we have to separate our functions from our data

Separating Functions From Data The nat predicate defines an abstract syntax tree –More about this next lecture We can express the remaining relations as recursive equations that define a function –We need to verify that the equations do define well defined functions –But we’ve done that already for these two relations in this lecture!

Separating Functions From Data A(X, zero,X) X nat A-Z A(X, succ( Y ), succ( Z ) ) A(X,Y,Z)A(X,Y,Z) A-S F( succ(zero), succ(zero) ) F-S-Z F( zero, succ(zero) ) F-Z F( succ(succ( N )),Z) F( succ( N ),X) F(N,Y) A(X,Y,Z) F-S-S-N succ( X ) nat X nat S zero nat Z

Separating Functions From Data A(X, zero,X) X nat A-Z A(X, succ( Y ), succ( Z ) ) A(X,Y,Z)A(X,Y,Z) A-S F( succ(zero), succ(zero) ) F-S-Z F( zero, succ(zero) ) F-Z F( succ(succ( N )),Z) F( succ( N ),X) F(N,Y) A(X,Y,Z) F-S-S-N nat n ::= zero | succ( n )

Separating Functions From Data F( succ(zero), succ(zero) ) F-S-Z F( zero, succ(zero) ) F-Z F( succ(succ( N )),Z) F( succ( N ),X) F(N,Y) A(X,Y,Z) F-S-S-N nat n ::= zero | succ( n ) add(M, zero )  M add(M, succ( N ) )  succ( add(M,N) )

Separating Functions From Data nat n ::= zero | succ( n ) fib( zero )  succ(zero) fib( succ(zero) )  succ(zero) fib( succ(succ( N )) )  add(fib( succ( N ) ), fib(N)) add(M, zero )  M add(M, succ( N ) )  succ( add(M,N) )

From Relations to SML (cont.) We can convert the abstract syntax tree into and ML datatype declarations The recursive equations we can write down as ML functions –What if our recursive equations didn’t actually define a function but we translated it naviely anyway?

From Relations to SML (cont.) fib( zero )  succ(zero) fib( succ(zero) )  succ(zero) fib( succ(succ( N )) )  add(fib( succ( N ) ), fib(N)) add(M, zero )  M add(M, succ( N ) )  succ( add(M,N) ) nat n ::= zero | succ( n )

From Relations to SML (cont.) fib( zero )  succ(zero) fib( succ(zero) )  succ(zero) fib( succ(succ( N )) )  add(fib( succ( N ) ), fib(N)) add(M, zero )  M add(M, succ( N ) )  succ( add(M,N) ) datatype nat = zero | succ of nat

From Relations to SML (cont.) fib( zero )  succ(zero) fib( succ(zero) )  succ(zero) fib( succ(succ( N )) )  add(fib( succ( N ) ), fib(N)) datatype nat = zero | succ of nat fun add(m,zero) = m | add(m,succ(n)) = succ(add(m,n))

From Relations to SML (cont.) datatype nat = zero | succ of nat fun add(m,zero) = m | add(m,succ(n)) = succ(add(m,n)) fun fib(zero) = succ(zero) | fib(succ(zero)) = succ(zero) | fib(succ(succ(n))) = add(fib(succ(n), fib(n))

Lessons Learned We can define functions by inductively specifying a relation that defines it graph Recursive equations can be used to specify relations that define functions –We must verify that the function is well defined Many recursive equations can be turned directly into SML code –The reason we use SML in this course

Next Lecture Lexical analysis and parsing along with other things you will not learn about in detail from this this course –We’ll talk about them to understand why they are “uninteresting” Abstract Syntax