2. Lecture 02: Theory of Automata
2
Definition: Palindrome
• Let us define a new language called Palindrome over the
alphabet
∑ = { a, b }
PALINDROME = { Λ, and all strings x such that
reverse(x) = x }
• If we want to list the elements in PALINDROME, we find
PALINDROME = { Λ, a, b, aa, bb, aaa, aba, bab, bbb,
aaaa, abba, … }
3. Lecture 02: Theory of Automata
3
• Sometimes two words in PALINDROME when
concatenated will produce a word in PALINDROME
– abba concatenated with abbaabba gives abbaabbaabba (in
PALINDROME)
• But more often, the concatenation is not a word in
PALINDROME
– aa concatenated with aba gives aaaba (NOT in PALINDROME)
Palindrome
4. Lecture 02: Theory of Automata
4
Kleene Closure
• Definition: Given an alphabet ∑, we define a language
in which any string of letters from ∑ is a word, even the
null string Λ. We call this language the closure of the
alphabet ∑, and denote this language by ∑*.
• Examples:
If ∑ = { x } then ∑* = { Λ, x, xx, xxx, … }
If ∑ = { 0, 1 } then ∑* = { Λ, 0, 1, 00, 01, 10, 11,
000, 001, … }
If ∑ = { a, b, c } then ∑* = { Λ, a, b, c, aa, ab, ac,
ba, bb, bc, ca, cb, cc, aaa, … }
5. Lecture 02: Theory of Automata
5
• Note that we listed the words in a language in size order
(i.e., words of shortest length first), and then listed all the
words of the same length alphabetically.
• This ordering is called lexicographic order, which we will
usually follow.
• The star in the closure notation is known as the Kleene
star.
• We can think of the Kleene star as an operation that
makes, out of an alphabet, an infinite language (i.e.,
infinitely many words, each of finite length).
Lexicographic order
6. Lecture 02: Theory of Automata
6
• Let us now generalize the use of the Kleene star oprator
to sets of words, not just sets of alphabet letters.
• Definition: If S is a set of words, then S* is the set of all
finite strings formed by concatenating words from S,
where any word may be used as often as we like, and
where the null string Λ is also included.
Kleene Closure
7. Lecture 02: Theory of Automata
7
• Example: If S = { aa, b } then
S* = { Λ plus any word composed of factors of aa and
b }, or
S* = { Λ plus any strings of a’s and b’s in which the a’s
occur in even clumps }, or
S* = { Λ, b, aa, bb, aab, baa, bbb, aaaa, aabb, baab,
bbaa, bbbb, aaaab, aabaa, aabbb, baaaa, baabb, bbaab,
bbbaa, bbbbb, … }
Note that the string aabaaab is not in S* because it has a
clump of a’s of length 3.
Kleene Closure
8. Lecture 02: Theory of Automata
8
• Example: Let S = { a, ab }. Then
S* = { Λ plus any word composed of factors of a and
ab }, or
S* = { Λ plus all strings of a’s and b’s except those that
start with b and those that contain a double b }, or
S* = { Λ, a, aa, ab, aaa, aab, aba, aaaa, aaab, abaa,
abab, aaaaa, aaaab, aaaba, aabaa, aabab, abaaa,
abaab, ababa, … }
• Note that for each word in S*, every b must have an a
immediately to its left, so the double b, that is bb, is not
possible; neither any string starting with b.
Kleene Closure
9. Lecture 02: Theory of Automata
9
• We must show how it can be written as a concatenation
of words from the base set S.
• In the previous example, to show that abaab is in S*, we
can factor it as follows:
abaab = (ab)(a)(ab)
• These three factors are all in the set S, therefore their
concatenation is in S*.
• Note that the parentheses, ( ), are used for the sole
purpose of demarcating the ends of factors.
How to prove a certain word is in the
closure language S*
10. Lecture 02: Theory of Automata
10
• Observe that if the alphabet has no letters, then its
closure is the language with the null string as its only
word; that is
if ∑ = ø (the empty set), then ∑* = { Λ }
• Also, observe that if the set S has the null string as its
only word, then the closure language S* also has the null
string as its only word; that is
if S = { Λ }, then S* = { Λ }
because ΛΛ = Λ.
• Hence, the Kleene closure always produces an infinite
language unless the underlying set is one of the two
cases above.
How to prove a certain word is in the closure
language S*
11. Lecture 02: Theory of Automata
11
• The Kleene closure of two different sets can end up
being the same language.
• Example: Consider two sets of words
S = { a , b, ab } and T = { a, b, bb }
Then, both S* and T* are languages of all strings of a’s
and b’s since any string of a’s and b’s can be factored
into syllables of (a) or (b), both of which are in S and T.
Kleene Closure of different sets
13. Lecture 02: Theory of Automata
13
Positive Closure
• If we wish to modify the concept of closure to refer only
the concatenation of some (not zero) strings from a set
S, we use the notation + instead of *.
• This “plus operation” is called positive closure.
Example: if ∑ = { x } then ∑+
= { x, xx, xxx, … }
Observe that:
1. If S is a language that does not contain Λ, then S+
is the
language S* without the null word Λ.
2. If S is a language that does contain Λ, then S+
= S*
3. Likewise, if ∑ is an alphabet, then ∑+
is ∑* without the
word Λ.
14. Lecture 02: Theory of Automata
14
• What happens if we apply the closure operator twice?
– We start with a set of words S and form its closure S*
– We then start with the set S* and try to form its closure, which
we denote as (S*)* or S**
• Theorem 1:
For any set S of strings, we have S* = S**
• Before we prove the theorem, recall from Set Theory
that
– A = B if A is a subset of B and B is a subset of A
– A is a subset of B if for all x in A, x is also in B
S**?
16. Lecture 02: Theory of Automata
16
• Let us first prove that S** is a subset of S*:
Every word in S** is made up of factors from S*. Every
factor from S* is made up of factors from S. Hence, every
word from S** is made up of factors from S. Therefore,
every word in S** is also a word in S*. This implies that S**
is a subset of S*.
• Let us now prove that S* is a subset of S**:
In general, it is true that for any set A, we have A is a
subset of A*, because in A* we can choose as a word any
factor from A. So if we consider A to be our set S* then S*
is a subset of S**
• Together, these two inclusions prove that S* = S**.
Proof of Theorem 1:
17. Lecture 02: Theory of Automata
17
Defining Languages Continued…
• 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.
18. Lecture 02: Theory of Automata
18
Example
• Defining language of 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.
19. Lecture 02: Theory of Automata
19
Example
• Defining the 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.
20. Lecture 02: Theory of Automata
20
• Defining the language {an
bn
}, n=1,2,3,… , of
strings defined over Σ={a,b}
Step 1:
ab is in {an
bn
}
Step 2:
if x is in {an
bn
}, then axb is in {an
bn
}
Step 3:
No strings except those constructed in
above, are allowed to be in {an
bn
}
21. Lecture 02: Theory of Automata
21
• 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
22. Lecture 02: Theory of Automata
22
• 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
23. Lecture 02: Theory of Automata
23
• Defining the language L, of strings
containing exactly aa, defined over Σ={a, b}
Step 1:
aa is in L
Step 2:
s(aa)s is also in L, where s belongs to b*
Step 3:
No strings except those constructed in
above, are allowed to be in L
24. Lecture 02: Theory of Automata
Theory Of Automata
24
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, +, -, *, /, (, )}
25. Lecture 02: Theory of Automata
Theory Of Automata
25
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 subsequences // and */ are
also forbidden.
• Are there still more?
• The most suitable way of defining a valid AE is by using
a recursive definition, rather than a long list of
forbidden substrings.
26. Lecture 02: Theory of Automata
Theory Of Automata
26
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)
27. Lecture 02: Theory of Automata
Theory Of Automata
27
• 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.
28. Lecture 02: Theory of Automata
Theory Of Automata
28
• 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.
29. Lecture 02: Theory of Automata
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.
30. Lecture 02: Theory of Automata
Theorem 3 & 4
• No arithmetic expression can begin or end
with the symbol /.
• Proof?
• No arithmetic expression can contain the
substring //.
• Proof?
31. Lecture 02: Theory of Automata
Theory Of Automata
31
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).
32. Lecture 02: Theory of Automata
Theory Of Automata
32
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?
• p →
• → p
• p) → p(
33. Lecture 02: Theory of Automata
• Useful Reading
Third chapter of Daniel I. Cohen book.
33