Uploaded by sainaslam101

02 Recursive Definition

advertisement
Recursive Definition
Faryal Shamsi
Lecturer Computer Science
Sukkur IBA University
Recursive Definition
• A recursive definition is characteristically a three-step process.
1. First, we specify some basic objects in the set.
2. Second, we give rules for constructing more objects in the set from the
ones we already know.
3. Third, we declare that no objects except those constructed in this way are
allowed in the set.
Example
’EVEN’ is the set of all positive whole numbers divisible by 2
• Rule 1 – 2 is in EVEN.
• Rule 2 – If x is in EVEN then so is y, (where y = x + 2)
• Rule 3 – The only elements in the set EVEN are those that can be
produced from the two rules above.
Proof
14 is in ’EVEN’
• By Rule 1 – 2 is in EVEN
• By Rule 2 – x = 2, y = 2  4 is in EVEN
• By Rule2 – x = 2, y = 4  6 is in EVEN
• By Rule2 – x = 4, y = 4  8 is in EVEN
• By Rule2 – x = 6, y = 8  14 is in EVEN
Example
’POLYNOMIAL’ – Recursive Definition
• Any number is in POLYNOMIAL.
• If p and q are in POLYNOMIAL, then so are p + q and (p) and pq
• POLYNOMIAL contains only those things which can be created by the
three rules above.
Prove that 2x+1 is a polynomial?
1. Any number is in POLYNOMIAL.
2. If p and q are in POLYNOMIAL, then so are p + q and (p) and pq
3. POLYNOMIAL contains only those things which can be created by
the three rules above.
Automata Theory
• Rule 1 The children of Henry VIII are all elements of DESCENDANTS.
• Rule 2 If x is an element of DESCENDANTS, then so are x's children.
• Rule 3 …
Automata Theory & Arithmetic Expressions
• Rule 1 0! = 1
• Rule 2 (n + 1)! = (n + 1)(n!)
Example
Example
Example
Example
Arithmetical Expression – AE
Recursive Definition – AE
• Rule 1 Any number (positive, negative, or zero) is in AE.
• Rule 2 If x is in AE, then so are (x) and -(x).
• Rule 3 If x and y are in AE, then so are
•
•
•
•
•
(i) x + y (if the first symbol in y is not -)
(ii) x - y (if the first symbol in y is not -)
(iii)) x * y
(iv) x / y
(v) x**y (our notation for exponentiation)
• See Page no. 33 of Course Text Book
Download