-1
$\begingroup$

Let $B_n = \{a^k|$ k is a multiple of n$\}$. Show that for each n ≥ 1, the language Bn is regular.

Proof by construction:

1.36: Let the set $\phi$ be the multiples of n

$$\phi=\{i_0,i_1,...,i_p\} \text{ where $i_p=n$}$$

So the language of $B_n$ is $$B_n=\{a^{i_0},a^{i_1},....,a^{i_p}\}$$

Let's try to construct a NFA for $b_n$

enter image description here

So $B_n$ is regular

1.37) Let Cn = {x| x is a binary number that is a multiple of n}. Show that for each n ≥ 1, the language Cn is regular.

Proof by Construction

Let $\phi$ be the set of binary numbers multiples of n $$\phi=\{i_0,i_1,....,n\}$$

So we can construct the following NFA:

enter image description here

The number of arrows leaving the state $q_0$ equals the cardinality of the set $\phi$. $k_l$ represents the NFA of $i_l$ for $0\leq l \leq n$ Showing that there exists an NFA that accepts a binary number is trivial. Therefore $C_n$ is regular.

I know I kind of took the easy way, but I think it works.

  • 0
    No, it doesn't work. The languages in both families, $B_n$ and $C_n$ are infiinite: there is no final $i_p$. Your approach leads to infinite-state automata, which is not what you're asked. For the $B_n$ the solution is quite easy, so you may want to start from those.2017-02-08
  • 0
    I don't see in $B_n$ or C_n how it would lead to infinite-state automata. I started out with a finite set and construced the NFA from that finite set.2017-02-08
  • 0
    How many nonnegative multiples of three are there?2017-02-08
  • 0
    all I know is that the multiples of a number is a finite set2017-02-08
  • 0
    I see where this is going. You think that we have to construct a NFA for all B_i?2017-02-08
  • 0
    Not at all. You may be thinking of the congruence classes, which is actually the key to solving both problems. However, each congruence class is infinite. It's just very simple: if they were finite, there would be a multiple of three that is the largest of them all. Add three to it. What have you got?2017-02-08
  • 0
    No, I don't think you have to construct an NFA for all $B_n$'s. The problems given to you are standard homework problems and I'm thoroughly familiar with them.2017-02-08
  • 0
    Let us [continue this discussion in chat](http://chat.stackexchange.com/rooms/53219/discussion-between-themathnoob-and-fabio-somenzi).2017-02-08

1 Answers 1

2

Let's focus on the second problem. I'll use $n=3$ as example. Every natural number, when divided by $3$, gives a remainder that is one of $0$, $1$, and $2$. Our goal is to build an automaton whose states are grouped according to the congruence classes.

In the case of $n=3$ there are going to be three classes of two states each, as we shall see.

The automaton for $C_3$ will be in the same state class for all numbers that give the same remainder. For simplicity, we'll assume that we read the numbers from least significant bit to most significant bit, but we could make the opposite assumption as well.

The next important observation is that the value of a bit string $b_0b_1b_2\ldots b_{n-1}$ that represents an unsigned binary number is given by

$$ \sum_{0 \leq i < n} 2^ib_i \enspace. $$

Each element of the summation contributes to the total remainder independently from the others, because (modular) addition is commutative and associative. In particular,

$$ 2^ib_i \bmod 3 = \begin{cases} 0 & \text{ if } b_i = 0 \\ 2^i \bmod 3 & \text{ otherwise. } \end{cases}$$

(The independence of each contribution makes it possible for us to read the number from either end.)

The final observation is that $2^i \bmod 3$ alternates between $1$ and $2$. For example, $2^2 \bmod 3 = 1$, $2^3 \bmod 3 = 2$, $2^4 \bmod 3 = 1$ again, and so on. It is whether $i$ is even or odd that matters.

If the automaton has read $0110$ (six) it will be in the same state as if it had read $1001$ (nine) or $1100$ (three), namely the state for zero remainder after reading an even number of bits. After reading $01111$ (thirty) it will be in another state, which remembers a remainder of $0$ after reading an odd number of bits.

Since our states must remember whether we have read an even number of bits ($i$ even) or an odd number of bits ($i$ odd), so that we can use the right value of $2^i \bmod 3$ when $b_i = 1$, we need six states, namely:

$$ \{(0,e), (0,o), (1,e), (1,o), (2,e), (2,o)\} \enspace. $$

The first component of each state keeps track of the remainder accumulated so far, and the second component (even or odd) tells us the value of $2^i \bmod 3$. If we are in state $(1,o)$ and we read a $1$, then we know that $2^i \bmod 3 = 2$ (even though we lost track of the exact value of $i$, we know it's even) and that the remainder so far is $1$. The next remainder is therefore $(1+2) \bmod 3 = 0$ and the next state is $(0,e)$ accordingly. You can complete the construction. The initial state is $(0,e)$ and the accepting states are $\{(0,e), (0,o)\}$.

This method generalizes to arbitrary $n$ as follows: There are exactly $n$ possible residues, and at most $n$ different values for $2^i \bmod n$. Hence there are at most $n^2$ states in our automaton for $C_n$. (What really matters is that they are finitely many.) For signed integers, say represented in two's complement, things are a bit messier, but the approach is the same.