This preview shows page 1. Sign up to view the full content.
Unformatted text preview: nd (F/G)
are well-formed formulas.
Examples: 42, x, (x+42), (x/y), (3/0), (x*(y+z))
8 Example 4: Lists
We can define the set L of finite lists of integers as follows.
Basis: The empty list () is contained in L
Induction: If i is an integer, and l is a list in L, then (cons i l)
is in L.
[Note: This is the Lisp style of lists, where (cons i l) appends
the data item i at the front of the list l]
Example: (cons 1 (cons 2 (cons 3 () ))) is the list (1 2 3) in Lisp. 9 Example 5: Binary Trees
We can define the set B of binary trees over an
alphabet A as follows:
Induction: If L, R∈B and x∈A, then ⟨L,x,R⟩∈B.
Example: ⟨⟨⟩,1,⟨⟩⟩ // tree with one node (1)
Example: ⟨ ⟨⟨⟩,1,⟨⟩⟩, r, ⟨⟨⟩,2,⟨⟩⟩ ⟩
// tree with root r and two children (1 and 2).
10 Applications of Inductively Defined Sets
In Computer Science, we typically use inductively defined sets
(a.k.a. recursively defined sets) when defining:
- programming languages (via grammars)
- logic (via well-formed logical formulas)
- data structures (binary trees, rooted trees, lists).
We also use them in connection with functional programming
Extremely popular in Computer Science!
11 Recursively Defined Functions 12 Recursively Defined Functions
Suppose we have a function with the set of
nonnegative integers as its domain.
We can specify the function as follows:
Basis step: Specify the value of the function at 0
Inductive step: Give a rule for finding its value at
an integer from its values at smaller integers.
This is called a recursive or inductive definition.
13 Example 1: Factorial Function We can define the factorial function n! as
Base step: 0! = 1
Inductive step: n! = n (n-1)! 14 Example 2: Fibonacci Numbers
The Fibonacci numbers fn are defined as
Base step: f0=0 and f1=1
Inductive step: fn = fn-1 + fn-2 for n >=2 We can use the recursive definition of the Fibonacci
numbers to prove many properties of these numbers. The
recursive structure actually helps to formulate the
15 Recursively Defi...
View Full Document
This note was uploaded on 03/24/2014 for the course CSCE 222 taught by Professor Math during the Fall '11 term at Texas A&M.
- Fall '11