0% found this document useful (0 votes)
794 views23 pages

Theory of Automata: Recursive Definition of Languages

Here are the steps to show that p → ((p → p) → q) is a WFF: 1) p is a WFF (by Rule 1 as it is a single letter) 2) (p → p) is a WFF (by Rule 3 as p and p are WFFs) 3) ((p → p) → q) is a WFF (by Rule 3 as (p → p) and q are WFFs) 4) p → ((p → p) → q) is a WFF (by Rule 3 as p and ((p → p) → q) are WFFs) The following are not WFFs: op

Uploaded by

Saqlain Umer
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
794 views23 pages

Theory of Automata: Recursive Definition of Languages

Here are the steps to show that p → ((p → p) → q) is a WFF: 1) p is a WFF (by Rule 1 as it is a single letter) 2) (p → p) is a WFF (by Rule 3 as p and p are WFFs) 3) ((p → p) → q) is a WFF (by Rule 3 as (p → p) and q are WFFs) 4) p → ((p → p) → q) is a WFF (by Rule 3 as p and ((p → p) → q) are WFFs) The following are not WFFs: op

Uploaded by

Saqlain Umer
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 23

Theory of Automata

Chapter 3
Recursive definition of languages
Recursive definition of languages
The following three steps are used in recursive definition

1. Some basic words are specified in the language. (base


case)
2. Rules for constructing more words are defined in the
language. (Recursive case)
3. No strings except those constructed in above, are allowed
to be in the language.
Example 1: Recursive definition of language INTEGER

Step 1: 1 is in INTEGER.
Step 2: If x is in INTEGER then x+1 and x-1 are also in
INTEGER.
Step 3: No strings except those constructed in above, are
allowed to be in INTEGER.
Example 2: Recursive definition of language EVEN

Step 1: 2 is in EVEN.
Step 2: If x is in EVEN then x+2 and x-2 are also in EVEN.
Step 3: No strings except those constructed in above, are
allowed to be in EVEN.
Prove: 12 is in EVEN

◼ Use rules of the recursive definition:


▪ Rule 1: 2  EVEN
▪ Rule 2: x=2, 2+2 = 4  EVEN
▪ Rule 2: x=4, 4+2 = 6  EVEN
▪ Rule 2: x=6, 6+2 = 8  EVEN
▪ Rule 2: x=8, 8+2 = 10  EVEN
▪ Rule 2: x=10, 10+2 = 12  EVEN
Example 3:
Recursive definition of language factorial
Step 1: As 0!=1, so 1 is in factorial.
Step 2: n!=n*(n-1)! is in factorial.
Step 3: No strings except those constructed in above, are
allowed to be in factorial.
Example 4:
Recursive definition of the language PALINDROME,
defined over Σ = {a,b}
Step 1: λ, a and b are in PALINDROME
Step 2: if x is palindrome, then s(x)Rev(s) and xx will
also be palindrome, where s belongs to Σ*
Step 3: No strings except those constructed in above, are
allowed to be in palindrome
Example 5a:
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}
Example 5b:
◼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
Example 6:
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
Example 7:
Defining the language L, of strings containing aa or bb ,
defined over Σ={a, b}
Step 1: aa and bb are in L
Step 2: s(aa)s’ and s(bb)s’ are also in L, where s & s’
belongs to Σ*
Step 3: No strings except those constructed in above, are
allowed to be in L
Example 8

◼ Kleene closure S* of a language S


▪ Rule 1: L is in S*. All words in S are in S*.
▪ Rule 2: If x and y are in S*, their
concatenation xy is also in S*.
Example 9: set POLYNOMIAL

Recursive definition of the set POLYNOMIAL

1. All numbers are in POLYNOMIAL.


2. The variable x is in POLYNOMIAL.
3. If p and q are in POLYNOMIAL, p+q, p – q, (p), and pq are
also in POLYNOMIAL.
▪ The only elements in POLYNOMIAL are the ones that are
constructed by following rules 1, 2, and 3.
◼ Prove that: 5x3-8x+7 is in POLYNOMIAL
◼ Rule 1: 5  POLYNOMIAL
◼ Rule 2: x  POLYNOMIAL
◼ Rule 3: 5x  POLYNOMIAL
◼ Rule 3: 5xx = 5x2  POLYNOMIAL
◼ Rule 3: 5x2x = 5x3  POLYNOMIAL
◼ Rule 1: 8  POLYNOMIAL
◼ Rule 3: 8x  POLYNOMIAL
◼ Rule 3: 5x3 – 8x  POLYNOMIAL
◼ Rule 1: 7  POLYNOMIAL
◼ Rule 3: 5x3 – 8x + 7  POLYNOMIAL
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, +, -, *, /, (,
)}
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.
AE (Arithmetic Expressions) defined over S =
{0,1,2,3,4,5,6,7,8,9,+, –,*,/,(,)}

◼ 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)
◼ 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.
◼ 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.
◼ 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.
Theorem 3 & 4
◼ No arithmetic expression can begin or end with
the symbol /.
◼ Proof?

◼ No arithmetic expression can contain the


substring //.
◼ Proof?
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).
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?
op→
o→p
o p) → p(

You might also like