Theory of Automata
Theory of Automata
Theory of Automata
Theory of Automata
Lecture 02: Theory of Automata:08
Arithmetic Expressions
• Suppose we ask ourselves what constitutes a
valid arithmetic expression, or AE for short.
• Σ = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, +, -, *, /, (, )}
Theory Of Automata 2
Lecture 02: Theory of Automata:08
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.
Theory Of Automata 3
Lecture 02: Theory of Automata:08
Recursive Definition of AE
• Rule 1: Any number (positive, negative, or zero) is in
AE.
Theory Of Automata 4
Lecture 02: Theory of Automata:08
Theory Of Automata 5
Lecture 02: Theory of Automata:08
Theory Of Automata 6
Lecture 02: Theory of Automata:08
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.
Theory Of Automata 7
Lecture 02: Theory of Automata:08
Theorem 3 & 4
• No arithmetic expression can begin or end
with the symbol /.
• Proof?
Theory Of Automata 8
Lecture 02: Theory of Automata:08
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).
Theory Of Automata 9
Lecture 02: Theory of Automata:08
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(
Theory Of Automata 10
Lecture 02: Theory of Automata:08
Regular Expressions
• Defining Languages by Another New Method
• Introducing EVEN-EVEN
Theory Of Automata 12
Lecture 02: Theory of Automata:08
Language-Defining Symbols
• We now introduce the use of the Kleene star, applied not
to a set, but directly to the letter x and written as a
superscript: x*.
• This simple expression indicates some sequence of x’s
(may be none at all):
x* =Ʌ or x or x2 or x3…
= xn for some n = 0, 1, 2, 3, …
Theory Of Automata 13
Lecture 02: Theory of Automata:08
Theory Of Automata 14
Lecture 02: Theory of Automata:08
• From now on, for convenience, we will simply say some b’s to mean
some or no b’s. When we want to mean some positive number of
b’s, we will explicitly say so.
Theory Of Automata 15
Lecture 02: Theory of Automata:08
Theory Of Automata 16
Lecture 02: Theory of Automata:08
Theory Of Automata 17
Lecture 02: Theory of Automata:08
Plus Sign
• Let us introduce another use of the plus sign. By
the expression
x+y
where x and y are strings of characters from an
alphabet, we mean either x or y.
Theory Of Automata 18
Lecture 02: Theory of Automata:08
Example
• Consider the language T over the alphabet
Σ = {a; b; c}:
• T = {a; c; ab; cb; abb; cbb; abbb; cbbb; abbbb;
cbbbb; …}
• In other words, all the words in T begin with
either an a or a c and then are followed by some
number of b’s.
• Using the above plus sign notation, we may
write this as
T = language((a+ c)b*)
Theory Of Automata 19
Lecture 02: Theory of Automata:08
Example
• Consider a finite language L that contains all the
strings of a’s and b’s of length three exactly:
L = {aaa, aab, aba, abb, baa, bab, bba, bbb}
• Note that the first letter of each word in L is
either an a or a b; so are the second letter and
third letter of each word in L.
• Thus, we may write
L = language((a+ b)(a + b)(a + b))
• or for short,
L = language((a+ b)3)
Theory Of Automata 20
Lecture 02: Theory of Automata:08
Example
• In general, if we want to refer to the set of all possible
strings of a’s and b’s of any length whatsoever, we could
write
language((a+ b)*)
Theory Of Automata 22
Lecture 02: Theory of Automata:08
Example
• Consider the language defined by the expression
(a + b)*a(a + b)*
Theory Of Automata 23
Lecture 02: Theory of Automata:08
Example contd.
• This language is the set of all words over the
alphabet Σ = {a, b} that have at least one a.
• The only words left out are those that have only
b’s and the word Ʌ.
These left out words are exactly the language
defined by the expression b*.
• If we combine this language, we should provide
a language of all strings over the alphabet Σ =
{a, b}. That is,
(a + b)* = (a + b)*a(a + b)* + b*
Theory Of Automata 24
Lecture 02: Theory of Automata:08
Example
• The language of all words that have at least two a’s can
be defined by the expression:
(a + b)*a(a + b)*a(a + b)*
Example
• The language of all words that have at least one a and at least one b
is somewhat trickier. If we write
(a + b)*a(a + b)*b(a + b)*
then we are requiring that an a must precede a b in the word. Such
words as ba and bbaaaa are not included in this language.
• Since we know that either the a comes before the b or the b comes
before the a, we can define the language by the expression
• Note that the only words that are omitted by the first term
(a + b)*a(a + b)*b(a + b)* are the words of the form some b’s
followed by some a’s. They are defined by the expression bb*aa*
Theory Of Automata 26
Lecture 02: Theory of Automata:08
Example
• We can add these specific exceptions. So, the
language of all words over the alphabet Σ = {a,
b} that contain at least one a and at least one b
is defined by the expression:
(a + b)a(a + b)b(a + b) + bb*aa*
• Thus, we have proved that
(a + b)*a(a + b)*b(a + b)* + (a + b)*b(a + b)*a(a + b)*
= (a + b)*a(a + b)*b(a + b)* + bb*aa*
Theory Of Automata 27
Lecture 02: Theory of Automata:08
Example
• In the above example, the language of all words that
contain both an a and ab is defined by the expression
(a + b)*a(a + b)*b(a + b)* + bb*aa*
Theory Of Automata 28
Lecture 02: Theory of Automata:08
• Thus
Theory Of Automata 29
Lecture 02: Theory of Automata:08
Example
• The following equivalences show that we should not treat
expressions as algebraic polynomials:
– The second term, b*a* describes all the words that do not contain the
substring ab (i.e., all a’s, all b’s, Ʌ, or some b’s followed by some a’s).
Theory Of Automata 30
Lecture 02: Theory of Automata:08
Example
• Let V be the language of all strings of a’s and b’s in
which either the strings are all b’s, or else an a followed
by some b’s. Let V also contain the word Ʌ. Hence,
V = {Ʌ, a, b, ab, bb, abb, bbb, abbb, bbbb, …}
• We can define V by the expression
b* + ab*
where Ʌ is included in b*.
• Alternatively, we could define V by
(Ʌ + a)b*
which means that in front of the string of some b’s, we have
either an a or nothing.
Theory Of Automata 31
Lecture 02: Theory of Automata:08
Example contd.
• Hence,
(Ʌ + a)b* = b* + ab*
Theory Of Automata 32
Lecture 02: Theory of Automata:08
Product Set
• If S and T are sets of strings of letters (whether
they are finite or infinite sets), we define the
product set of strings of letters to be
Theory Of Automata 33
Lecture 02: Theory of Automata:08
Example
• If S = {a, aa, aaa} and T = {bb, bbb} then
(a + aa + aaa)(bb + bbb)
= abb + abbb + aabb + aabbb + aaabb + aaabbb
Theory Of Automata 34
Lecture 02: Theory of Automata:08
Example
• If M = {Ʌ, x, xx} and N = {Ʌ, y, yy, yyy, yyyy, …}
then
• MN ={Ʌ, y, yy, yyy, yyyy,…x, xy, xyy, xyyy,
xyyyy, …xx, xxy, xxyy, xxyyy, xxyyyy, …}
Theory Of Automata 35
Lecture 02: Theory of Automata:08
Definition
• The following rules define the language associated with
any regular expression:
language(r1r2) = L1L2
Theory Of Automata 37
Lecture 02: Theory of Automata:08
Definition contd.
• Rule 2 (cont.):
Theory Of Automata 38
Lecture 02: Theory of Automata:08
Theorem 5
• If L is a finite language (a language with only finitely many
words), then L can be defined by a regular expression. In other
words, all finite languages are regular.
• Proof
Theory Of Automata 40
Lecture 02: Theory of Automata:08
Example
• Consider the expression
Example contd.
• The expression (ab)* covers all of these except
those that begin with b or end with a. Adding
these choices gives us the expression:
(Ʌ + b)(ab)*(Ʌ + a)
Theory Of Automata 43
Lecture 02: Theory of Automata:08
Examples
• Note that
(a + b*)* = (a + b)*
since the internal * adds nothing to the language.
However,
Example
• Consider the regular expression: (a*b*)*.
• Since both the single letter a and the single letter b are
words of the form a*b*, this language contains all strings
of a’s and b’s. That is,
(a*b*) = (a + b)*
Introducing EVEN-EVEN
• Consider the regular expression
E = [aa + bb + (ab + ba)(aa + bb)*(ab + ba)]*
• All strings with an even number of a’s and an even number of b’s
belong to the language defined by E.
Theory Of Automata 46
Lecture 02: Theory of Automata:08
• Algorithm 1: Keep two binary flags, the a-flag and the b-flag.
Every time an a is read, the a-flag is reversed (0 to 1, or 1 to 0); and
every time a b is read, the b-flag is reversed. We start both flags at 0
and check to be sure they are both 0 at the end.
Theory Of Automata 47
Lecture 02: Theory of Automata:08
(aa)(ab)(bb)(ba)(ab)(bb)(bb)(bb)(ab)(ab)(bb)(ba)
(aa) then, by Algorithm 2, the type3-flag is
reversed 6 times and ends at 0.
Theory Of Automata 48