03 Recursive Definitions
03 Recursive Definitions
Recursive Definitions
Example
Standard Definition:
EVEN is the set of all positive whole numbers divisible by 2
Alternative Definition:
EVEN is the set of all 2n where n = 1 2 3 4 . . .
Recursive Definition:
1 2 is in EVEN
2 if x is in EVEN, then so is x + 2.
3 The only elements in EVEN are those produced by (1) and (2)
1 / 17
Fun with EVEN
Question
Why would we ever want to use the recursive definition for EVEN?
Example
Prove 14 is in set EVEN
2 / 17
Fun with EVEN
3 / 17
Fun with EVEN
4 / 17
INTEGERS
Example
1 1 is in INTEGERS
2 If x is in INTEGERS, then so is x + 1.
Note: we will omit rule 3 from now on
If we wanted the set INTEGERS to include positive and negative
integers, we need to change our definition:
Example
1 1 is in INTEGERS
2 If x and y are both in INTEGERS, then so are x + y and x − y.
5 / 17
POSITIVE
Example
1 x is in POSITIVE
2 If x and y are both in POSITIVE, then so are x + y and xy.
Problem: there no base for x
Problem
Show 3x 2 + 7x − 9 is in POLYNOMIAL
7 / 17
POLYNOMIAL
Problem
Show 3x 2 + 7x − 9 is in POLYNOMIAL
Proof.
By Rule 1: 3 is in POLYNOMIAL.
By Rule 2: x is in POLYNOMIAL.
By Rule 3: (3)(x) is in POLYNOMIAL; call it 3x.
By Rule 3: (3x)(x) is in POLYNOMIAL; call it 3x 2 .
By Rule 1: 7 is in POLYNOMIAL; call it 3x 2 .
By Rule 3: (7)(x) is in POLYNOMIAL; call it 7x.
By Rule 3: 3x 2 + 7x is in POLYNOMIAL.
By Rule 1: −9 is in POLYNOMIAL.
By Rule 3: 3x 2 + 7x − 9 is in POLYNOMIAL.
8 / 17
Advantages and Disadvantages of POLYNOMIAL
Advantages
• sums and products of polynomials are obviously polynomials
• if we have a proof for differentiable, we can show all
polynomials are differentiable
• AND we don’t need to give the best algorithm for it
Disadvantages
• Tedious building blocks
•
Example (x + )
1 x is in L1
2 If w is any word in L1 , then xw is also in L1
Example (x ∗ )
1 λ is in L2
2 If w is any word in L2 , then xw is also in L1
Example (x odd )
1 λ is in L3
2 If w is any word in L3 , then xxw is also in L3
10 / 17
Examples
Example (INTEGER)
1 1 2 3 4 5 6 7 8 9 are in INTEGERS
2 If w is any word in INTEGERS, then
w0 w1 w2 w3 w4 w5 w6 w7 w8 w9 are also in INTEGERS
11 / 17
Arithmetic Expressions
Invalid Strings?
(3 + 5) + 6) 2(/8 + 9) (3 + (4−)8) 2) − (4
Problem
What makes a valid string?
Solution
Recursive Definition...
12 / 17
Recursive Definition for Arithmetic Expressions
There may be strings which we may not know the meaning of, but
definitely argue that strings are a part of AE.
For example: 8/4/2 could mean 8/(4/2) or (8/4)/2 depending on
order of operations
13 / 17
Examples with Arithmetic Expressions
Theorem
An arithmetic expression cannot contain the character $
Proof.
$ is not part of any number, so it cannot be induced (by Rule 1)
If a string, x, doesn’t contain $, then neither can (x) or −x (by Rule 2)
If neither x nor y contains $, then neither do any induced (by Rule 3)
The character $ can never be inserted into AE
14 / 17
Examples with Arithmetic Expressions
Theorem
No AE can begin or end with symbol /
Proof.
No number begins or ends with / so it cannot occur (by Rule 1).
Any AE formed by Rule 2 must begin and end with parentheses or
begin with a minus sign.
If x does not already begin with / and y does not end with /, then
any AE formed by any clause in Rule 3 will not begin or end with a /.
These rules prohibit an expression beginning or ending with /.
15 / 17
Examples with Arithmetic Expressions
Theorem
No AE can contain the substring //
Σ = {¬ → ( ) a b c d . . .}
1 Any single Latin letter is a WFF.
2 If p is a WFF, the so are (p) and ¬p.
3 If p and q are WFFs, then so is p → q
• p→
• →p
• (p →
• p)
• p) → p(
• p → ((p → p) → q)
• ¬p → p
17 / 17