Professional Documents
Culture Documents
Foundations of
Computer Science
(AFCS)
Prof.Dr. F.L.
Tiplea
Definitions by
recursion Ferucio Laurentiu Tiplea
Course readings
Spring 2013
Prof.Dr. F.L. Tiplea (UAIC) Algebraic Foundations of Computer Science (AFCS) Spring 2013 1 / 25
Outline
Algebraic
Foundations of
Computer Science
(AFCS)
Closures
Structural
induction
2 Structural induction
Definitions by
induction
Definitions by
recursion 3 Definitions by induction
Course readings
4 Definitions by recursion
5 Course readings
Prof.Dr. F.L. Tiplea (UAIC) Algebraic Foundations of Computer Science (AFCS) Spring 2013 2 / 25
Closures example
Algebraic
Foundations of
Computer Science
(AFCS)
Example 1
Prof.Dr. F.L.
Tiplea Let A be a set of atomic propositions. The set PF (A) of
Closures propositional formulas over A is the least set which fulfills the
Structural following properties:
induction
Definitions by
a PF (A), for any a A (that is, A PF (A));
induction
if and are propositional formulas over A, then
Definitions by
recursion
Closures
Given an n-ary constructor r and a set A, denote by r (A) the set:
Structural
induction r (A) = {a|(a1 , . . . , an A)(((a1 , . . . , an ), a) r )}
Definitions by
induction
Definitions by
recursion
Prof.Dr. F.L. Tiplea (UAIC) Algebraic Foundations of Computer Science (AFCS) Spring 2013 4 / 25
Existence of Closures
Algebraic
Foundations of
Computer Science
(AFCS)
Theorem 3 (Existence of closures)
Prof.Dr. F.L.
Tiplea
Given a set A and a set R of constructors, the closure of A under
R exists and it is unique. Moreover, if R[A] denotes the closure of
Closures
A under R, then [
Structural
induction R[A] = Bm ,
Definitions by m0
induction
Definitions by where
recursion
Course readings B0 = A;
S
Bm+1 = Bm r R r (Bm ), for any m 0;
Structural
induction Recall that natural numbers are defined as follows:
Definitions by
induction
0 = ;
Definitions by 1 = S(0) = {0} = {};
recursion
Prof.Dr. F.L. Tiplea (UAIC) Algebraic Foundations of Computer Science (AFCS) Spring 2013 6 / 25
Closures of a binary relation
Algebraic
Foundations of
Computer Science
(AFCS)
Definition 5
Prof.Dr. F.L.
Tiplea
The reflexive closure of a binary relation A A is the least
reflexive binary relation r () which includes .
Closures
Structural
induction
Definitions by
Fact: r () can be computed as follows:
induction
Definitions by r () = A
recursion
Course readings
Definition 6
The symmetric closure of a binary relation A A is the least
symmetric binary relation s() which includes .
s() = 1
Prof.Dr. F.L. Tiplea (UAIC) Algebraic Foundations of Computer Science (AFCS) Spring 2013 7 / 25
Closures of a binary relation
Algebraic
Foundations of
Computer Science
(AFCS)
Definition 7
Prof.Dr. F.L.
Tiplea
The transitive closure of a binary relation A A is the least
transitive binary relation t() which includes .
Closures
Structural
induction
Definitions by
[
recursion t() = + = m ,
Course readings m1
where
1 = and
m+1 = m , for all m 1.
Prof.Dr. F.L. Tiplea (UAIC) Algebraic Foundations of Computer Science (AFCS) Spring 2013 8 / 25
Closures of a binary relation
Algebraic
Foundations of
Computer Science
(AFCS)
Definition 8
Prof.Dr. F.L.
Tiplea
The reflexive and transitive closure of a binary relation A A
is the least reflexive and transitive binary relation which
Closures
includes .
Structural
induction
Definitions by
induction
Fact: can be computed as follows:
Definitions by
recursion [
Course readings = t(r ()) = r (t()) = m ,
m0
where
0 = A and
m+1 = m , for all m 0.
Prof.Dr. F.L. Tiplea (UAIC) Algebraic Foundations of Computer Science (AFCS) Spring 2013 9 / 25
Closures of a binary relation
Algebraic
Foundations of
Computer Science
(AFCS)
Definition 9
Prof.Dr. F.L.
Tiplea
The closure under equivalence of a binary relation A A is
the least equivalence relation equiv () which includes .
Closures
Structural
induction
Definitions by
recursion equiv () = t(s(r ())) = t(r (s())) = r (t(s())).
Course readings
Remark 1
In general, s(t()) 6= t(s()).
Prof.Dr. F.L. Tiplea (UAIC) Algebraic Foundations of Computer Science (AFCS) Spring 2013 10 / 25
Structural induction
Algebraic
Foundations of
Computer Science
(AFCS)
Theorem 10 (Structural induction)
Prof.Dr. F.L.
Tiplea
Let B = R[A] be the closure of A under R and let P be a property
such that:
Closures
Structural
P(a), for any a A;
induction
Definitions by
(P(a1 ) P(an ) P(a)), for any r R and
induction a1 , . . . , an , a B with ((a1 , . . . , an ), a) r .
Definitions by
recursion Then, P is satisfied by any a B.
Course readings
Remark 2
Prof.Dr. F.L. Tiplea (UAIC) Algebraic Foundations of Computer Science (AFCS) Spring 2013 11 / 25
Structural induction example
Algebraic
Foundations of
Computer Science
(AFCS)
Example 11
Prof.Dr. F.L.
Tiplea
Let A be a set of atomic propositions. The set PF (A) of
propositional formulas as defined in Example 1 is the closure of A
Closures
under some set of constructors (prove it!).
Structural
induction
Definitions by
induction
Let P() be the following property:
Definitions by
recursion P() : has as many left brackets as right brackets.
Course readings
Prof.Dr. F.L. Tiplea (UAIC) Algebraic Foundations of Computer Science (AFCS) Spring 2013 12 / 25
Definitions by induction
Algebraic
Foundations of
Computer Science
(AFCS)
Definition 12
Prof.Dr. F.L.
Tiplea
A set B is inductively defined by A and R if B = R[A].
Closures
Structural
induction If B = R[A], then B is obtained as follows:
Definitions by
induction
B0 = A;
Definitions by Bm+1 = Bm R(Bm ), for all m 0;
recursion S
Course readings B = m0 Bm .
If the chain
B0 , B1 , B2 , . . . , Bm , Bm+1 = Bm , Bm+2 = Bm , . . .
Prof.Dr. F.L. Tiplea (UAIC) Algebraic Foundations of Computer Science (AFCS) Spring 2013 13 / 25
Definitions by induction
Algebraic
Foundations of
Computer Science
A definition by induction corresponds to the following while-loop
(AFCS)
(that might be non-terminating):
Prof.Dr. F.L.
Tiplea
Prof.Dr. F.L. Tiplea (UAIC) Algebraic Foundations of Computer Science (AFCS) Spring 2013 14 / 25
Definitions by recursion
Algebraic
Foundations of
Computer Science
Assume that B is inductively defined by A and R. It would be a
(AFCS)
good idea to define functions f on B in a recursive way as follows:
Prof.Dr. F.L.
Tiplea
Closures
define f for any a A;
Structural
induction
if ((a1 , . . . , an ), a) r and the function has already been
Definitions by defined for a1 , . . . , an , then define the function for a as a
induction
combinations of the values f (a1 ), . . . , f (an ) in the form
Definitions by
recursion
Prof.Dr. F.L. Tiplea (UAIC) Algebraic Foundations of Computer Science (AFCS) Spring 2013 15 / 25
Definitions by recursion
Algebraic
Foundations of
Computer Science
The definition above has a main drawback: it could not work for
(AFCS)
some sets B. Just think that the element a above might be defined
Prof.Dr. F.L.
Tiplea in at least two different ways,
Closures
((a1 , . . . , an ), a) r
Structural
induction
Definitions by and
((a1 , . . . , am
), a) r .
induction
Definitions by
recursion
Course readings
In such a case, you must be assured that
The easiest way to have this property fulfilled is to ask for each
element a B to have exactly one inductive construction of it from
A and R. If B has this property then it is called a free inductively
defined set.
Prof.Dr. F.L. Tiplea (UAIC) Algebraic Foundations of Computer Science (AFCS) Spring 2013 16 / 25
Definitions by recursion
Algebraic
Foundations of
Computer Science
However, for inductively defined sets we can prove the following
(AFCS)
result:
Prof.Dr. F.L.
Tiplea
Closures Lemma 13
Structural
induction
Let B = R[A], C a set, g : A C, and h a function which
Definitions by
induction associates a partial function h(r ) : C n C to each r R, where n
Definitions by is the arity of r . Then, there exists a unique relation f B C
recursion
Course readings
such that:
(1) (a, g(a)) f , for any a A;
(2) if (a1 , b1 ), . . . , (an , bn ) f , ((a1 , . . . , an ), a) r and
h(r )(b1 , . . . , bn ), then (a, h(r )(b1 , . . . , bn )) f ;
(3) f is the least relation from B to C which satisfies (1) and (2).
Prof.Dr. F.L. Tiplea (UAIC) Algebraic Foundations of Computer Science (AFCS) Spring 2013 17 / 25
Definitions by recursion
Algebraic
Foundations of
Computer Science
(AFCS)
Definition 14
Prof.Dr. F.L.
Tiplea
A set B is called free inductively defined by A and R if, for any
a B,
Closures
Structural
either a A,
induction
Definitions by
or there exists a unique r R and a unique n-tuple
induction (a1 , . . . , an ) such that ((a1 , . . . , an ), a) r , where n is the arity
Definitions by
recursion
of r (for n = 0 we understand that a r ).
Course readings
Prof.Dr. F.L. Tiplea (UAIC) Algebraic Foundations of Computer Science (AFCS) Spring 2013 18 / 25
Definitions by recursion
Algebraic
Foundations of
Computer Science
A slight extension of the recursion theorem is the following:
(AFCS)
Prof.Dr. F.L.
Tiplea
Theorem 16
Closures
Structural
Let B = R[A], C a set, g : A C, and h a function which
induction associates a partial function h(r ) : B n C n C to each r R,
Definitions by
induction
where n is the arity of r . If B is free inductively defined by A and
Definitions by R, then there exists a unique function f : B C such that:
recursion
Course readings
(1) f (a) = g(a), for any a A;
(2) f (a) = h(r )(a1 , . . . , an , f (a1 ), . . . , f (an )), for any a, a1 , . . . , an
with ((a1 , . . . , an ), a) r and
h(r )(a1 , . . . , an , f (a1 ), . . . , f (anr )), where n is the arity of r .
Prof.Dr. F.L. Tiplea (UAIC) Algebraic Foundations of Computer Science (AFCS) Spring 2013 19 / 25
Definitions by recursion example
Algebraic
Foundations of
Computer Science
(AFCS)
Example 17
Prof.Dr. F.L.
Tiplea
Let PF (A) be the set of propositional formulas over A. It is easy to
see that this set is free inductively defined.
Closures
Define a function f : PF (A) N in a recursive way as follows:
Structural
induction
Prof.Dr. F.L. Tiplea (UAIC) Algebraic Foundations of Computer Science (AFCS) Spring 2013 20 / 25
Definitions by recursion more examples
Algebraic
Foundations of
Computer Science
Pick up your favorite programming language and:
(AFCS)
Prof.Dr. F.L.
Tiplea show that its set of arithmetic and logic expressions is
inductively defined;
Closures
Structural
induction define recursively the length of an arithmetic expression;
Definitions by
induction define inductively the set of variables of an arithmetic
Definitions by
recursion
expression;
Course readings
define recursively the height of an arithmetic expression.
Prof.Dr. F.L. Tiplea (UAIC) Algebraic Foundations of Computer Science (AFCS) Spring 2013 21 / 25
Definitions by recursion
Algebraic
Foundations of
Computer Science
An important particular case of the recursion theorem:
(AFCS)
Prof.Dr. F.L.
Tiplea Theorem 18 (Recursion theorem for N)
Closures Let A be a set, a A, and h : N A A be a function. Then,
Structural there exists a unique function f : N A such that:
induction
Definitions by
(2) f (n + 1) = h(n, f (n)), for any n.
recursion
Course readings
This result can be strengthen to:
Definitions by
induction Multiplication:
Definitions by x 0=0
recursion
x (n + 1) = (x n) + x;
Course readings
Exponentiation:
x0 = 1
x n+1 = (x n ) x.
Prof.Dr. F.L. Tiplea (UAIC) Algebraic Foundations of Computer Science (AFCS) Spring 2013 23 / 25
Definitions by recursion
Algebraic
Foundations of
Computer Science
In some cases the value of a function f at a natural number n may
(AFCS)
depend on the values of f at 0, . . . , n 1 (Fibonaccis sequence is
Prof.Dr. F.L.
Tiplea such an example).
Closures
The recursion in such cases is called hereditary.
Structural
induction
Theorem 20 (Hereditary recursion theorem)
Definitions by S
induction
Let A be a set, S = nN An , and h : N S A be a function.
Definitions by
recursion Then, there exists a unique function f : N A such that
Course readings
f (n) = h(n, f |n ),
Prof.Dr. F.L. Tiplea (UAIC) Algebraic Foundations of Computer Science (AFCS) Spring 2013 24 / 25
Course readings
Algebraic
Foundations of
Computer Science
1 F.L. Tiplea: Fundamentele Algebrice ale Informaticii, Ed.
(AFCS)
Polirom, Iasi, 2006, pag. 7079.
Prof.Dr. F.L.
Tiplea
Closures
2 F.L. Tiplea: Introducere n Teoria Multimilor, Ed. Univesitatii
Structural
induction Al.I.Cuza, Iasi, 1998, pag. 8390.
Definitions by
induction
Definitions by
recursion
Course readings
Prof.Dr. F.L. Tiplea (UAIC) Algebraic Foundations of Computer Science (AFCS) Spring 2013 25 / 25