CS 135 (Module 7: Natural Numbers)

0.0(0)
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/15

flashcard set

Earn XP

Description and Tags

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

16 Terms

1
New cards
empty is a
(listof Int)
2
New cards
Is 0 a natural number?
Yes
3
New cards
What do logicians use to define the natural numbers?
Peano axioms
4
New cards
What do the Peano axioms include?
1. 0 is a natural number
2. For every natural number n, S(n) is a natural number
5
New cards
What is S(n) called?
The successor function
6
New cards
What is a successor function?
It is a function that consumes a natural number, and returns the next
7
New cards
What does the successor function produce?
The "next" natural number
8
New cards
What Racket function is used as the successor function?
add1
9
New cards
What is the inverse function of add1?
sub1
10
New cards
A Nat is one of:
- 0
- (add1 Nat)
11
New cards
What happens if (zero? n) is false?
Then n has the value (add1 k) for some k
12
New cards
How do we compute k?
We subtract 1 from n, using the built-in sub1 function
13
New cards
What do it mean to "go along for the ride"?
It is an informal CS135 expression for an argument that is passed unchanged in the recursive application.
14
New cards
What is the function for counting down?
;; requires: n >= base
(define (countdown-to n base)
(cond [(= n base) (cons base empty)]
[else (cons n (countdown-to (sub1 n)
base))]))
15
New cards
What does countdown-to require?
It requires for the relationship n>=b to hold.
16
New cards
What about counting up to b?
;; requires: n