Ternary representation of an integer that is a multiple of 3 but not a multiple of 9

Consider the problem of building a Nondeterministic Finite Automaton (NFA) over \{0, 1, 2\} to accept ternary numbers that are a multiple of 3 but not a multiple of 9. Here are the first 19 ternary numbers.

TernaryDecimal
0000
0011
0022
0103
0114
0125
0206
0217
0228
1009
10110
10211
11012
11113
11214
12015
12116
12217
20018

Multiples of 3

From the above table, the ternary numbers that are a multiple of 3 (000, 010, 020, 100, 110, 120, 200) always end with a 0. Notice that, 0 is indeed a multiple of 3.

Multiples of 9

From the above table, the ternary numbers that are a multiple of 9 (000, 100) always end with a 00. Notice that, 0 is indeed a multiple of 9.

Multiples of 3 but not a Multiple of 9

Extrapolating from the previous two observations, the ternary numbers that are a multiple of 3 but not a multiple of 9 are numbers that end with a single 0. Thus, the last two digits can be either 10 or 20. The digits before these two digits do not matter.

Regex

A regular expression to express this would be

    \begin{equation*}(0 \cup 1 \cup 2)^* \, (1 \cup 2) \, 0\end{equation*}

NFA

The above regular expression can expressed as the following NFA

Rendered by QuickLaTeX.com

Leave a Reply

Your email address will not be published. Required fields are marked *