< previous page page_33 next page >
Page 33
2.3 Automata that count
Counting is one of the simplest ways of describing languages. For example, we might want to describe a
language by restricting the lengths of the strings that can appear, or by requiring that a particular letter
or pattern appears a certain number of times. We shall also see that there are limits to what automata
can do in the realm of counting. We begin with a simple example.
Example 2.3.1 Construct an automaton to recognise the language
The first step in constructing an automaton is to ensure that you understand what the language is. In
this case, precisely if |
x
|=0, 2, 4,…. The empty string
ε
is accepted since |
ε
|=0, and so the initial
state will also have to be terminal. In this case, we shall only need two states: one state remembers
that we have read an even number of symbols and another that remembers that we have read an odd
number of symbols. We therefore obtain the following automaton.
If, instead, we wanted to construct an automaton that recognised the language of strings over
{a, b}
of
odd
length, then we would simply modify the above machine by making state 0 non-terminal and state
1 terminal.
To generalise the above example, I shall need some terminology. The set of integers, that is the set of
positive and negative whole numbers, is denoted . The word ‘number’ will almost always mean
‘integer’ from now on. If we say that
a divides b,
or that
b
is
divisible by a,
or that
b
is a
multiple
of
a,
if
b
=
aq
for some ; this is written mathematically as
a
|
b
. If and
a
>0 then
we can write
b
=
aq
+
r
where 0≤
r
<
a
. The number
q
is called the
quotient
and
r
is called the
remainder
.
The quotient and remainder are uniquely determined by
a
and
b
meaning that if
b
=
aq′
+
r′
where 0≤
r
′<a
then
q
=
q′
and
r
=
r′
. This result is called the ‘Remainder Theorem’ and is one of the basic properties
of the integers.
Using this terminology, let us look again at odd and even numbers. If we divide a number by 2, then
there are exactly two possible remainders: 0 or 1. A number that has no remainder when divided by 2 is
just an even number and a number that leaves the remainder 1 when divided by 2 is just an odd
number. It is an accident of history that English, and many other languages, happen to have single
words that mean ‘leaves no remainder when divided by 2’ and ‘leaves remainder 1 when divided by 2.’
Now let us look at what happens when we divide a number by 3. This time there are three possible
cases: ‘leaves no remainder when divided by 3,’ ‘leaves
< previous page page_33 next page >