Natural Numbers or, "All you ever need is compounds, variants, and recursion".

Slides:



Advertisements
Similar presentations
Joshua Eckroth The Plan 1.Review some functions. 2.Write more functions. 3.Consider the nature of recursion. 4.Look at the.
Advertisements

Lecture 7 Recursive Functions. Initial Functions Zero function ζ(n) = 0. Successor σ(n) = n+1, for n ε N. Projection π i (n 1,…,n k ) = n i. k.
Functional Programming. Pure Functional Programming Computation is largely performed by applying functions to values. The value of an expression depends.
1 Programming Languages and Paradigms Lisp Programming.
CS 116 Tutorial 2 Functional Abstraction. Reminders Assignment 2 is due this Wednesday at Noon.
Verbal Expressions for =
Notes 1.1.
CS3L: Introduction to Symbolic Programming Summer 2008Colleen Lewis Lecture 15: Procedures as Arguments.
Solve an absolute value inequality
Course 2: Inequalities Objectives:
Integers and Introduction to Solving Equations
Solve a compound inequality with and
 Every integer has an opposite integers. A number and its opposite are the same distance from zero.
Arbitrarily Long Data Structures: Lists and Recursion CMSC Introduction to Computer Programming October 4, 2002.
Chapter 6 Solving Linear Inequalities. 6.1 Solving Inequalities by Addition and Subtraction Set builder Notation : –A way to write a solution set Ex:
$100 $200 $300 $400 $500 $200 $300 $400 $500 Graphing Inequalities One Step Inequalities Absolute Value Multi-Step Inequalities Compound Inequalities.
Compound Data. Last Lecture Booleans Only two elements Symbols Not to be confused with variables Strings Notions of equality on values.
COP4020 Programming Languages Functional Programming Prof. Xin Yuan.
4-6 Solving Absolute Value Equations & Inequalities
LISP Data Types Functional Programming Academic Year Alessandro Cimatti
Functions and Relations 2 Page 3 We are going to work on some of the exercises today:
SOLVE ABSOLUTE VALUE INEQUALITIES January 21, 2014 Pages
Absolute Value If ABSOLUTE VALUE represents the distance a number is from zero, means all x values that are 3 units from zero. If given, what are some.
Chapter 2 Inequalities. Lesson 2-1 Graphing and Writing Inequalities INEQUALITY – a statement that two quantities are not equal. SOLUTION OF AN INEQUALITY.
Number Line: Comparing and Ordering Integers LESSON 1.
Cs1321 December 6, 2001 Review. What is computer science? What's an algorithm? Processes and programs Overview of some programming language concepts Functional.
Absolute © 2009 by S - Squared, Inc. All Rights Reserved. Value.
Real Number and the number Line. Number System Real numbers: is number that can be positive or negative and have decimal places after the point. Natural.
Have you ever seen these? NumberDateDescription of TransactionDebit (-)Credit (+)Balance Previous balance ? Deposit10-13 Direct Deposit- paycheck.
Numbers Sets Natural Numbers – Counting numbers. Does not include 0 (example: 1,2,3,4…) Whole Numbers – All Natural numbers and the number zero (example:
Solving an Absolute-Value Inequality Recall that  x  is the distance between x and 0. If  x  8, then any number between  8 and 8 is a solution of.
5-1 Solving Inequalities by Addition & Subtraction N#_____ _____/_____/_____.
Functional Programming Language 1 Scheme Language: part 3.
4-5 Inequalities (pages ) P6  Represent inequalities on a number line or a coordinate plane.
Data Abstraction: Sets
Opener #3 (8/27/10) Solving Equations and Inequalities
CS 550 Programming Languages Jeremy Johnson
1-1 Patterns and Inductive Reasoning
Each term is half the preceding term. So the next two terms are
Sequence, Selection, Iteration The IF Statement
Solving Absolute-Value Inequalities
PPL Lazy Lists.
CS 1321.
Halting Functions for Tree-Like Structures
CS 270 Math Foundations of CS Jeremy Johnson
The Metacircular Evaluator
2-1 Integers Course 2 Warm Up Problem of the Day Lesson Presentation.
Special Graphs of Inequalities.
Lecture 18.
Lecture #8 מבוא מורחב.
The Metacircular Evaluator (Continued)
Warm Up 10/29/18 Write an equation in slope-intercept form which passes through (5, 4) and is parallel to y + 8 = -3(x - 4).
SOLVING ABSOLUTE-VALUE EQUATIONS
Indicator 10 Solving Inequalities.
CS 5010 Program Design Paradigms “Bootcamp” Lesson 6.5
Fundamentals of Algebra
Let's Play "What's the Question"
Compound Inequalities and their Graphs
List and list operations (continue).
DeMorgan's & related Laws
Chapter 10 Section 2.
Objectives: Graph (and write) inequalities on a number line.
6.001 SICP Interpretation Parts of an interpreter
Lecture # , , , , מבוא מורחב.
SOLVING ABSOLUTE-VALUE EQUATIONS
SOLVING ABSOLUTE-VALUE EQUATIONS
2-1 Integers Course 2 Warm Up Problem of the Day Lesson Presentation.
Course 2: Inequalities Objectives:
list data list 만들기 list 사용하기 nil : list link :  * list -> list
1.6 Absolute Value Equations and Inequalities
Presentation transcript:

Natural Numbers or, "All you ever need is compounds, variants, and recursion".

Today's Lecture We've seen types like: [any] -> natural[num] -> num [num] -> [num][X], [X] -> [X] Let's check out this guy: flatten : [[X]] -> [X] And look at "lists without baggage" Close look at "recursion over what?"

Lists of different colors We've seen [any] : the kitchen sink [num] : sequences, n-D points, graph … distance-from-0 = (sqrt (sum (map-square l))) What about [car], [course-info], [posn] Could [[course-info]] be useful?

Flatten ; flatten : [[X]] -> [X] ; Example : (flatten [ [1,2,3], [4], [5,6] ]) ;  [1,2,3,4,5,6] (define (flatten x) (cond [(empty? x) empty] [else (append (first x) (flatten (rest x)))])))

Make your own naturals ; A Natural is ; - 'Zero ; - (make-next nat) where nat is a Natural (define-struct next (nat)) ; Template: ; (define (f m) ; (cond [(symbol? m)...] ; [else (... (f (next-nat m)))]))

Importing them ; natIt : number -> Natural ; purpose : convert numbers into Naturals ; example : 0 -> 'Zero, 1 -> (make-next ‘zero), ; 2 -> (make-next (make-next 1))... (define (natIt n) (cond [(= n 0) 'Zero] [else (make-next (natIt (- n 1)))]))

Exporting them ; numIt : Natural -> number ; purpose : convert a Natural to a number ; example : 0 <- 'Zero, 1 <- (make-next 1), ; 2 <- (make-next (make-next 1))... (define (numIt n) (cond [(symbol? n) 0] [else (+ 1 (numIt (next-nat n)))]))

Addition ; add : Natural, Natural -> Natural (define (add n m) (cond [(symbol? n) m] [else (make-next (add (next-nat n) m))])) Induction on n

Multiplication ; mult : Natural, Natural -> Natural (define (mult n m) (cond [(symbol? n) 'Zero] [else (add m (mult (next-nat n) m))])) Induction on n

Exponentiation ; exp : Natural, Natural -> Natural (define (expo n m) (cond [(symbol? m) (make-next 'Zero)] [else (mult n (expo n (next-nat m)))])) Induction on m

Greater or equal to ; geq : Natural, Natural -> Natural (define (geq n m) ; Induction on m (cond [(symbol? m) true] [else (cond [(symbol? n) false] [else (geq (next-nat n) (next-nat m))])]))

Subtraction ; minus : Natural, Natural -> Natural (define (minus n m) ; Induction on m & n (cond [(symbol? m) n] [(symbol? n) 'Zero] [else (minus (next-nat n) (next-nat m))]))

Division ; divi : Natural, Natural -> Natural (define (divi n m) ; Strong Induction on n (cond [(symbol? (next-nat m)) n] [(not (geq n m)) 'Zero] [else (make-next (divi (minus n m) m))]))