Theory of Automata
Recursive Definitions
Dr Aftab A Maroof
Nasreen Akhtar
Faryal Saud
Contents
Recursive Definition
Examples
Arithmetic Expression
Recursive Definition of AE
Theorems
Propositional Calculus
Well Formed Formula
10/6/2019 Theory of Automata 2
Recursive definition of languages
The following three steps are used in recursive
definition
1. Some basic words are specified in the language
2. Rules for constructing more words are defined in
the language
3. No strings except those constructed in above, are
allowed to be in the language
10/6/2019 Theory of Automata 3
Example
Defining language of EVEN
Step 1:
2 is in EVEN.
Step 2:
a. If x is in EVEN then x+2 and x-2 are also in EVEN.
b. If x and y are in EVEN then so are x+y, x-y and x*y.
Step 3:
No strings except those constructed in above, are
allowed to be in EVEN.
10/6/2019 Theory of Automata 4
Defining the language PALINDROME, defined
over Σ = {a,b}
Step 1:
λ, a and b are in PALINDROME
Step 2:
if x is palindrome then axa, bxb, xx are also be
palindrome,
Step 3:
No strings except those constructed in above,
are allowed to be in palindrome
10/6/2019 Theory of Automata 5
Defining the language {anbn }, n=1,2,3,… , of
strings defined over Σ={a,b}
Step 1:
ab is in {anbn}
Step 2:
if x is in {anbn}, then axb is in {anbn}
Step 3:
No strings except those constructed in above,
are allowed to be in {anbn}
10/6/2019 Theory of Automata 6
Defining the language L, of strings ending in a ,
defined over Σ={a,b}
Step 1:
a is in L
Step 2:
if x is in L then s(x) is also in L, where s belongs to
Σ*
Step 3:
No strings except those constructed in above,
are allowed to be in L
10/6/2019 Theory of Automata 7
Defining the language L, of strings beginning
and ending in same letters , defined over Σ={a,
b}
Step 1:
a and b are in L
Step 2:
(a)s(a) and (b)s(b) are also in L, where s belongs to
Σ*
Step 3:
No strings except those constructed in above,
are allowed to be in L
10/6/2019 Theory of Automata 8
Arithmetic Expressions
Suppose we ask ourselves what constitutes a
valid arithmetic expression, or AE for short.
The alphabet for this language is
Σ = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, +, -, *, /, (, )}
10/6/2019 Theory of Automata 9
Arithmetic Expression AE
Obviously, the following expressions are not valid:
(3 + 5) + 6) 2(/8 + 9) (3 + (4-)8)
The first contains unbalanced parentheses; the second
contains the forbidden substring (/; the third contains the
forbidden substring -).
Are there more rules? The substrings // and */ are also
forbidden.
Are there still more?
The most natural way of defining a valid AE is by using a
recursive definition, rather than a long list of forbidden
substrings.
10/6/2019 Theory of Automata 10
Recursive Definition of AE
Rule 1: Any number (positive, negative, or zero) is in AE.
Rule 2: If x is in AE, then so are
(i) (x)
(ii) -x (provided that x does not already start with a minus sign)
Rule 3: If x and y are in AE, then so are
(i) x + y (if the first symbol in y is not + or -)
(ii) x - y (if the first symbol in y is not + or -)
(iii) x * y
(iv) x / y
(v) x ** y (our notation for exponentiation)
10/6/2019 Theory of Automata 11
The above definition is the most natural, because it is the method
we use to recognize valid arithmetic expressions in real life.
For instance, we wish to determine if the following expression is
valid:
(2 + 4) * (7 * (9 - 3)/4)/4 * (2 + 8) - 1
We do not really scan over the string, looking for forbidden
substrings or count the parentheses.
We actually imagine the expression in our mind broken down
into
components:
Is (2 + 4) OK? Yes
Is (9 - 3) OK? Yes
Is 7 * (9 - 3)/4 OK? Yes, and so on.
10/6/2019 Theory of Automata 12
Note that the recursive definition of the set AE gives us the
possibility of writing 8/4/2, which is ambiguous, because it
could mean 8/(4/2) = 4 or (8/4)/2 = 1.
However, the ambiguity of 8=4=2 is a problem of meaning.
There is no doubt that this string is a word in AE, only doubt
about what it means.
By applying Rule 2, we could always put enough parentheses
to avoid such a confusion.
The recursive definition of the set AE is useful for proving
many theorems about arithmetic expressions, as we shall see
in the next few slides.
10/6/2019 Theory of Automata 13
Theorem
An arithmetic expression cannot contain the character $.
Proof
This character is not part of any number, so it cannot be
introduced into an AE by Rule 1.
If the character string x does not contain the character $, then
neither do the string (x) and -x. So, the character $ cannot be
introduced into an AE by Rule 2.
If neither x nor y contains the character $, then neither do any
of the expressions defined in Rule 3.
Therefore, the character $ can never get into an AE.
10/6/2019 Theory of Automata 14
Theorem 3 & 4
No arithmetic expression can begin or end with the
symbol /
Proof?
No arithmetic expression can contain the substring //
Proof?
10/6/2019 Theory of Automata 15
Propositional Calculus
Propositional calculus (or sentential calculus) is a
branch of symbolic logic that we shall be interested
in.
The version we define here uses only negation (¬)
and implication (→), together with the phrase
variables.
The alphabet for this language is
Σ = {¬, →, (, ), a, b, c, d, …}
A valid expression in this language is called WFF
(well-form formula).
10/6/2019 Theory of Automata 16
Propositional Calculus
The rules for forming WFFs are:
Rule 1: Any single Latin letter is a WFF, for instance a, b, c,
...
Rule 2: If p is a WFF, then so are (p) and ¬p.
Rule 3: If p and q are WFFs, then so is p → q.
Can you show that p → ((p → p) → q) is a WFF?
Can you show that the following are NOT WFFs?
o p→
o →p
o p) → p(
10/6/2019 Theory of Automata 17