1 Operations on formal languages Closure properties of regular

advertisement
Operations on formal languages
Let L1 = {10} and L2 = {011, 11}.
CS 3813: Introduction to Formal Languages
and Automata
L1 ∪ L2 = {10, 011, 11}
Union:
Concatenation: L1 L2 = {10011, 1011}
Regular expressions
Sec 3.1
Kleene Star:
Other operations: intersection, complement, difference
Closure properties of regular languages
• Definition: A regular language is any language that is
accepted by a finite automaton
• The class of regular languages is closed under the
following operations (i.e., performing these operations
on regular languages creates other regular languages)
–
–
–
–
–
–
Union
Concatenation
Kleene star
Intersection
Complement
Difference
Regular expressions
A useful shorthand for describing regular languages.
Compare to arithmetic expressions, such as (x + 3)/2.
An arithmetic expression is constructed using arithmetic
operators, such as addition and division. A regular
expression is constructed using operations on languages,
such as concatenation, union, and Kleene star.
The value of an arithmetic expression is a number.
The value of a regular expression is a (formal) language.
Recursive definition of a regular expression
∅ is a regular expression corresponding to the language ∅
λ is a regular expression corresponding to the language {λ}
For each symbol a ∈ Σ, a is a regular expression
corresponding to the language {a}
For any regular expressions r and s, corresponding to
the regular languages L(r) and L(s), respectively,
each of the following is a regular expression:
r + s corresponding to the language L(r) ∪ L(s)
r ⋅ s (or rs) corresponding to the language L(r)L(s)
r* corresponding to the language (L(r))*
(r) corresponding to the language L(r)
L1* = {e, 10, 1010, 101010, … }
Examples
b = {b, λ, a, aa, aaa, aaaa, aaaaa, … }
a*ba* = {w ∈ Σ* | w has exactly one b}
(a + b)*aa (a + b)* = {w ∈ Σ* : w contains aa}
(a + b)*aa (a + b)* + (a + b)*bb (a + b)* =
{w ∈ Σ* : w contains aa or bb}
*
n
(a + λ)b = {ab : n ≥ 0} ∪ {bn : n ≥ 0}
a*+
As with arithmetic expressions, there is an order of
precedence for operators -- unless you change it using
parentheses. The order is: star closure first, then
concatenation, then union.
1
Hints for writing regular expressions
Assume Σ = {a, b, c}.
Practice
Zero or more a’s:
a*
Let Σ = {a,b,c}. Give a regular expression for the
following languages:
One or more a’s:
aa*
(a) all strings containing exactly one a
Any string at all:
(a + b + c)*
Any nonempty string:
(a + b + c)(a + b + c)*
Any string that does not contain a:
(b + c)*
(b) all strings containing no more than three a’s
Any string containing exactly one a: (b + c)*a(b + c)*
Practice
More practice
What languages correspond to the following
regular expressions?
Give regular expressions for the following languages,
where the alphabet is Σ = {a, b, c}.
a*b
--all strings ending in b
(aaa + bba)
--all strings containing no more than two a’s
(ab)*
-- all strings of even length
More practice
Do these strings match the regular expression?
Give regular expressions for the following languages,
where the alphabet is Σ = {0, 1}.
Regular expression
String
--all strings of one or more 0’s followed by a 1
(01* + 1)
0101
--all strings of two or more symbols followed by three
or more 0’s
(a + λ)b
b
(ab)*a*
λ
(a + b)(ab)
bb
-- all strings that do not end with 01
2
Download