Chapter 1Foundationsnotes.en.pdf:30-31; slides.en.pdf:67-69

Defining Operations on ℕ

Addition, multiplication, exponentiation via recursive equations

Def 2.3.1Addition on NDef 2.3.2Replacement ruleDef 2.3.6MultiplicationDef 2.3.7Exponentiation
Concept

Once we have naturals, we want to do things with them. We define operations
by defining equations that mirror the Peano construction.

Addition \oplus:
- m0=mm \oplus 0 = m
- ms(n)=s(mn)m \oplus s(n) = s(m \oplus n)

Multiplication \odot:
- m0=0m \odot 0 = 0
- ms(n)=(mn)mm \odot s(n) = (m \odot n) \oplus m

Exponentiation mnm^n:
- m0=s(0)m^0 = s(0)
- ms(n)=mnmm^{s(n)} = m^n \odot m

These are recursive definitions: each one reduces nn until it reaches 00.
That gives us a mechanical way to compute — apply the rules as rewrite
rules until no more apply. This is the replacement rule.

For example, to compute 212 \oplus 1:

2s(0)=s(20)=s(2)=32 \oplus s(0) = s(2 \oplus 0) = s(2) = 3

Animation — sml_eval
Example: GCD on unary naturals

The greatest common divisor gcd(a, b) is the largest natural dividing both a and b. On unary naturals, gcd is defined by Euclid's algorithm:

gcd(a,b):={ab=0gcd(b,amodb)otherwise\gcd(a, b) := \begin{cases} a & b = 0 \\ \gcd(b, a \bmod b) & \text{otherwise} \end{cases}

where amodba \bmod b is the remainder when aa is divided by bb.

Step-by-step (working with peano numerals):

For gcd(s(s(s(o))),s(s(o)))\gcd(s(s(s(o))), s(s(o))) (i.e. gcd(3,2)\gcd(3, 2)):
1. b0b \neq 0: compute gcd(b,amodb)=gcd(2,3mod2)\gcd(b, a \bmod b) = \gcd(2, 3 \bmod 2).
2. 3mod2=13 \bmod 2 = 1: compute gcd(1,2mod1)\gcd(1, 2 \bmod 1).
3. 2mod1=02 \bmod 1 = 0: compute gcd(1,0)\gcd(1, 0).
4. b=0b = 0: return a=1a = 1. So gcd(3,2)=1\gcd(3, 2) = 1. ✓

Predecessor. To compute amodba \bmod b we need the predecessor function pp with p(s(n))=n,p(o)=op(s(n)) = n, p(o) = o. Defined recursively:
- p(o)=op(o) = o
- p(s(n))=np(s(n)) = n

The proof of correctness for gcd uses induction on bb. Euclid's algorithm always terminates because the second argument strictly decreases.

Worked example
Step 0 of 1
Practice — score 100% to advance
Multiple choice
Q1
What is the base case of multiplication on naturals?
Q2
Apply the rules: what is ss(0)ss(0)ss(0) \oplus ss(0)?
Q3
What does the replacement rule let us do?
Q4
Why are these definitions called 'recursive'?
Q5
What is m0m^0?
Q6
Compute 1+21 + 2 using the recursive rules. How many reductions?
Q7
Euclid's algorithm for gcd always terminates because:
Fill in the blank
Q1
gcd(3,2)\gcd(3,2) equals ___.
Loading…