Professional Documents
Culture Documents
1. ∅ is an element of R.
2. {λ} is an element of R.
1. ∅
2. {λ}
3. {0}, {1}
2
Further examples:
4. {110}∗ {0, 1}
∗ ∗S
6. {0, 10} {11} {001, λ}
3
A regular language can therefore be described
by an explicit formula. By convention, we may
simplify the formula slightly: We
• replace
S
with +,
4
Example:
1. ∅
2. λ
3. 0, 1
4.(a) 0 + 1
(b) 01, 10
(c) 0∗, 1∗
5
Further examples:
1. 0 + 10
2. 001
3. (1 + λ) 001
4. 110∗ (0 + 1)
6
Regular expressions
1. ∅ is an element of RE.
2. λ is an element of RE.
1. Exponential notation: write (rr) as r2
2. ‘Plus’ notation: write ((r∗) r) as r+
1. Highest: ∗
2. Then: concatenation
3. Lowest: +
8
Convention
Thus
b c = a + b∗ c
∗
a+
However,
(a + b)∗ 6= a + b∗
9
Some examples of simplification:
1∗ (1 + λ) = 1∗
1∗1∗ = 1∗
0∗ + 1∗ = 1∗ + 0∗
∗ ∗ ∗
0 1 = (0 + 1 )∗
(0 + 1)∗01(0 + 1)∗ + 1∗0∗ = (0 + 1)∗
10
Consider
∗
∗
[
(0 + 1) ≈ {0} {1}
represents the language of all strings of 0’s and
1’s.
∗ 01 0 + 1 ∗ ≈
(0 + 1 ) ( )
[ ∗ [ ∗
{0} {1} {0} {1} {0} {1}
represents the language of all strings of 0’s and
1’s having the substring 01.
1∗0∗ ≈ {1}∗{0}∗
represents the language of all strings of 0’s and
1’s where the 1’s precede the 0’s, i.e., that do
not have the substring 01.
11
Example: The language L ⊆ {0, 1}∗ of all
strings of even length:
(00 + 01 + 10 + 11)∗
((0 + 1) (0 + 1))∗
12
Example: The language L ⊆ {0, 1}∗ containing
an odd number of 1’s:
0i10j
(10m10n)
13
If we decide to stop the initial substring imme-
diately after the 1, we can represent L as:
∗ ∗ ∗ ∗ ∗
0 1 0 10 1 0
14
There may be many ways to describe a typical
element of a language, depending on which as-
pect we want to emphasize. There isn’t always
one that is the simplest or most natural.
15
∗ ∗ ∗ ∗
10 10 10
0∗ 10∗10∗ ∗10∗
rectifies that.
16
Let L ⊆ {0, 1}∗ be the set of all strings of
length 6 or less.
λ + 0 + 1 + 00 + 01+
10 + 11 + 000 + . . . + 111110 + 111111
which isn’t very elegant.
(0 + 1 ) ( 0 + 1 ) ( 0 + 1 ) ( 0 + 1 ) ( 0 + 1 ) ( 0 + 1 )
or
(0 + 1 )6
(0 + 1 + λ)6
17
Let
L=
x ∈ {0, 1}∗ |
18
(1 + 01)∗ allows λ, which doesn’t end with 1.
19
Let l (for ‘letter’) denote
a + b + ... + z + A + B + ... + Z
0 + 1 + ... + 9 .
(l + )(l + d + )∗
20
Let
• a denote plus,
• m denote minus,
• p denote a point.
21
A constant in Pascal:
• First a sign,
• then
23
• We won’t wait until we reach the end of a
given string to decide if the string is in the
language or not. At each step we make a
tentative decision on the basis of the string
of input symbols we’ve seen so far.
24
How much must we remember about a prefix
in order to make a decision about it?
Two extremes:
• Nothing, e.g.,
25
Between these extremes, the answer is not al-
ways the same. There are at least two strings
x and y for which the answers are different.
26
Let
27
We haven’t considered λ yet.
1. Neither is in L.
28
In summary, we have only two cases:
29
Let
30
The decision for any x depends only on its last
two symbols.
31
Consider the string 01011: if you remember
only that it doesn’t end with 10, you cannot
distinguish it from 100, now or later.
32
In how many cases do we have to split case N ?
33
Now consider the three strings x, y and z,
where x = 1, y ends in 01, and z ends in 11:
34
Now consider the strings x and y, where x = λ
and y is any string in case A:
• Neither is in L.
35
Let
∗
L = x ∈ {0, 1} | second-last symbol of x is 0
36
Consider case 0a:
• 010 6∈ L, but
• 000 ∈ L
37
Consider case 1a:
• 100 ∈ L, but
• 110 6∈ L
38
Thus we have established that it is necessary to
remember both the last two symbols. There-
fore we already have four different cases.
• λ1 6∈ L, but
• 001 ∈ L
40
Finally, consider 0: It must be distinguished
from
41
Let
42
The decision for any x depends only on its last
two symbols.
43
Consider the strings x and y, where x ends in
01 and y in 00. Both are in case N .
On input 1,
• x1 ∈ L, but
• y1 6∈ L.
44
Do strings ending with 10 also form another
case?
45
Finally, there are the strings λ, 0 and 1.
46
L=
x ∈ {0, 1}∗ |
Steps of abstraction:
47
Therefore
48
L=
x ∈ {0, 1}∗ |
x ends in 1 and
does not contain the substring 00}
49
Case 0: Last symbol of s is 0.
Case λ: s = λ.
50
Therefore
51
Consider
and
52
We can interpret the diagrams in two ways:
53
Interpretation as flowchart:
54
Note the following aspects of such a diagram:
55
Interpretation as abstract machine:
56
The term abstract machine means that it’s a
specification of the capabilities that the ma-
chine must have.
Important are:
57
Crucial is that the set of states is finite: the
number of states puts an absolute limit on the
amount of info the machine needs to, or is able
to, remember.
58
Finite automata
60
Until this FA gets at least two input symbols,
it remembers exactly what it has received.
Therefore there is a separate state for each
of λ, 0 and 1.
61
q δ (q, 0) δ (q, 1)
λ 0 1
0 00 01
1 10 11
00 00 01
01 10 11
10 00 01
11 10 11
62
We have already seen that we can reduce the
number of states.
q δ (q, 0) δ (q, 1)
λ A B
A A B
B 10 B
10 A B
q δ (q, 0) δ (q, 1)
A A B
B 10 B
10 A B
65
Consider
We want
δ ∗ : Q × Σ∗ → Q ,
the state in which the FA ends up, if it begins
in state q and receives the string x of input
symbols.
67
• Basis: input string is λ.
68
Definition
δ ∗ : Q × Σ∗ → Q
as follows:
• ∀q ∈ Q, δ ∗ (q, λ) = q.
• ∀q ∈ Q, y ∈ Σ∗, and a ∈ Σ,
69
Example
= δ δ δ ∗ (q, a) , b , c
∗
= δ δ δ (q, λa) , b , c
∗
= δ δ δ δ (q, λ) , a , b , c
= δ (δ (δ (q, a) , b) , c)
= δ (δ (q1, b) , c)
= δ (q2, c)
= q3
70
Note that as part of the calculation above, we
worked out
= δ (q, a)
71
Definitions
δ ∗ (q0, x) ∈ A .
L (M ) = {x ∈ Σ∗ | x is accepted by M }
72
Note the if and only if in the last statement.
In other words,
75
• State A:
• State B:
77
We notice the following:
We note
79
80
At states p, r and s, we need transitions la-
beled a, a, and b, respectively. We may need
additional states.
81
82
Consider
(11 + 110)∗0
We want the FA that accepts the correspond-
ing language L.
• 1 6∈ L
83
L doesn’t contain
1 10 ∈ L, but 11 10 6∈ L.
λ 00 6∈ L, but 11 00 ∈ L.
00 6∈ L while 1100 ∈ L
Therefore we need another accepting state,
say u, and δ (t, 0) = u.
86
Consider
Therefore δ (u, 0) = p.
Therefore δ (t, 1) = r.
Therefore δ (u, 1) = r.
87
88
We continued to add states as long as it was
necessary. We stopped as soon as we were
able to define the required transitions in a way
that involved only the states we had already.
89
Distinguishing one string from another
depends on
90
Definitions
L/x = {z ∈ Σ∗ | xz ∈ L} .
Two strings x and y in Σ∗ are called distin-
guishable w.r.t. L if L/x 6= L/y.
If
L/x = L/y ,
x and y are indistinguishable w.r.t. L.
xz ∈ L and yz 6∈ L
or
xz 6∈ L and yz ∈ L .
92
Example
Let
∗
L = s ∈ {0, 1} | s ends with 10
Consider z = 0.
93
Another example:
Let
n o
L= 0k 1k | k ≥ 1 .
Let z = 1i.
Then xz = 0i1i ∈ L
and yz = 0j 1i 6∈ L.
94
Consider the language
∗
L = x ∈ {0, 1} | x ends with 01 .
• λ and 01:
λλ 6∈ L, but 01λ ∈ L
• 0 and 01:
0λ 6∈ L, but 01λ ∈ L
• λ and 0:
λ1 6∈ L, but 01 ∈ L
96
Lemma
Proof
Then
δ ∗ (q0, xz ) 6= δ ∗ (q0, yz )
97
However,
∗ ∗ ∗
δ (q0, xz ) = δ δ (q0, x) , z
∗ ∗ ∗
δ (q0, yz ) = δ δ (q0, y ) , z
Thus
δ ∗ (q0, x) 6= δ ∗ (q0, y )
98
Theorem
Proof
|x| ≥ n and
the nth symbol from the right in x is 1}
Naive approach: we create a distinct state for
every possible substring of length n or less, i.e.,
for λ, 0, 1, 00, 01, 11, 10, 000, . . ..
n−i
symbols. Now choose any string z ∈ {0, 1}∗ of
length i − 1.
Then
|xz| = |yz| = n + i − 1 .
To the right of the marker there are now
(n − i) + (i − 1) = n − 1
symbols. Thus the marked position is the nth
from the right.
102
Since the strings xz and yz differ in this po-
sition, one of them must have a 1 in the nth
position from the right, and the other a 0.
103
Recall the theorem: Suppose that L ⊆ Σ∗
and, for some positive integer n, there are n
strings in Σ∗, pairwise distinguishable w.r.t. L.
Then every FA that recognizes L has at least
n states.
104
Often we
105
Example:
Let z = 10i1.
Then xz = 0i10i1 ∈ L, but yz = 0j 10i1 6∈ L.
106
Moreover, sometimes we
Example:
108
Theorem:
Proof:
• |x| = |y|:
Let z = xr .
109
• |x| 6= |y|:
110
The concept of distinguishability gives us
111
Unions, Intersections, Complements
We know
Suppose
x ∈ L1 ∪ L2
if it has enough information at each step to
decide separately whether
x ∈ L1
and whether
x ∈ L2 .
113
It needs to
114
Thus, the set of states is
Q1 × Q2 .
Then the initial state must be
(q1, q2) .
p ∈ A1 or q ∈ A2 .
Suppose that
Q = Q1 × Q2 ,
q0 = (q1, q2) ,
for p ∈ Q1, q ∈ Q2, and a ∈ Σ,
A = {(p, q ) | p ∈ A1 or q ∈ A2} .
Corresponding FAs:
117
L1 ∪ L2 is recognized by
Mu = (Qu, Σ, qu, Au, δu), where
Qu = {A, B, C} × {P, Q, R}
= {(A, P ) , (A, Q) , (A, R)} ∪
{(B, P ) , (B, Q) , (B, R)} ∪
{(C, P ) , (C, Q) , (C, R)}
•
qu = (A, P )
118
•
δu :
q δu (q, 0) δu (q, 1)
(A, P ) (B, Q) (A, P )
(A, Q) (B, Q) (A, R)
(A, R) (B, Q) (A, P )
(B, P ) (C, Q) (A, P )
(B, Q) (C, Q) (A, R)
(B, R) (C, Q) (A, P )
(C, P ) (C, Q) (C, P )
(C, Q) (C, Q) (C, R)
(C, R) (C, Q) (C, P )
119
120
Consider intersection:
p ∈ A1 and q ∈ A2 .
Example (cont.):
121
122
Consider the complement L1 \ L2:
p ∈ A1 and q 6∈ A2 .
Example (cont.):
123
124
Special case: L1 = Σ∗.
Two methods:
• Use
125