Documente Academic
Documente Profesional
Documente Cultură
Regular Operations
September 11, 2001
Agenda
Today
Regular languages
Finite languages are regular
Definition of Regular
Language
Recall the definition of a regular language:
DEF: The language accepted by an FA M
is the set of all strings which are accepted
by M and is denoted by L (M).
Would like to understand what types of
languages are regular. Languages of this
type are amenable to super-fast
recognition of their elements
Would be nice to know for example, which
of the following are regular:
3
Language Examples
Unary squares:
{, 1, 14, 19, 116, 125, 136, }
= { 1n | n is a perfect square }
Finite Languages
All the previous examples had the following
property in common: infinite cardinality
NOTE: The strings which made up the
language were finite (as they always will
be in this course); however, the collection
of such strings was infinite.
Before looking at infinite languages, should
definitely look at finite languages.
Languages of Cardinality 1
Q: Is the singleton language
containing one string regular? For
example, is
{ banana }
regular?
Languages of Cardinality 1
A: Yes.
Languages of Cardinality 1
A: Nothing, really. This an example of a
nondeterministic FA. This turns out to be
the most concise way to encapsulate the
language { banana }
Languages of Cardinality 1
A: Yes, just add a fail state q7; I.e., put
a state that sucks in all strings different
from banana for all eternity unless
they happen to be the banana
prefixes {, b, ba, ban, bana, banan}.
Two Strings
Q: How about two strings? For
example
{ banana, nab } ?
11
Two Strings
A: Just add another route:
12
13
14
15
n
a
b
b
a
into
n
Now make word endings
accept states, add a
a
fail sink-state and
add links to the fail state to
finish the construction.
16
Infinite Cardinality
Q: Are all regular languages finite?
17
Infinite Cardinality
A: No! Many infinite languages are regular.
Common Mistake 1: The strings of regular
languages are finite, therefore the regular
languages must be finite.
Common Mistake 2: Regular languages are
by definition accepted by finite
automata, therefore regular languages are
finite.
Q: Give an example of a infinite but regular
language.
18
Infinite Cardinality
Simplest example is
19
Regular Operations
You may have come across the regular
operations when doing advanced searches
utilizing programs such as emacs, egrep,
perl, python, etc. There are three basic
operations we will work with:
1. Union
2. Concatenation
3. Kleene-star
And a fourth definable in terms of the previous:
4. Kleene-plus
20
Regular Operations
Summarizing Table
Operatio Symbo
n
l
Union
Concatenati
on
Kleenestar
Kleene-
UNIX
version
Meaning
match one of
the patterns
implicit in
UNIX
match
patterns in
sequence
Match pattern
0 or more
times
*
+
Match pattern
21
1 or more
String Patterns
A: A good way to define a pattern is
as a set of strings, i.e. a language.
The language for a given pattern is
the set of all strings satisfying the
predicate of the pattern.
EG: vowel-pattern =
{ the set of strings which
contain at least one of: a e i o u }
23
24
=
{aardvarkaardvark, aardvarkbobcat, aardvarkchimpanzee,
bobcataardvark, bobcatbobcat, bobcatchimpanzee,
chimpanzeeaardvark, chimpanzeebobcat,
chimpanzeechimpanzee}
Q1: What is L ?
Q2: What is L ?
28
Algebra of Languages
A1: L = L. In general, is the identity in
29
Regular operations
Kleene-*
UNIX: search for lines consisting purely of
vowels (including the empty line):
egrep -i `^(a|e|i|o|u)*$
Regular operations
Kleene-*
Computability: Suppose we have a
language
B = { ba, na }
Q: What is the language B * ?
31
Regular operations
Kleene-*
A:
B * = { ba, na }*=
{ ,
ba, na,
baba, bana, naba, nana,
bababa, babana, banaba, banana,
Regular operations
Kleene-+
Kleene-+ is just like Kleene-* except that the
pattern is forced to occur at least once.
UNIX: search for lines consisting purely of vowels
(not including the empty line):
egrep -i `^(a|e|i|o|u)+$
33
(N A B )
35
Blackboard Exercises
Express the DFA patterns from the
previous board-exercises using
regular operations in both UNIXstyle and Computability-style.
36