# Can an FSA count?

This may be a silly question. It seem clear that an FSA, since it is finite, can only count the number of symbols in its input string up to a number bounded by the number of its states. But now suppose we equip the FSA with output (e.g. printing) capabilities. It would then be very easy to construct a machine capable of printing one symbol for each symbol that it reads. Would that count as counting? If not, why not?

To put it in terms of FSTs instead: I take it that it is not possible to construct an FST capable of mapping a string of an arbitrary length to a binary representation (i.e. a number in the base-2 numeral system) of its length. But it IS of course trivial to construct an FST capable of mapping a string of arbitrary length to a string of says zeroes (or ones) of the same length. But that could count as counting, could it not, beacuse what the FST is doing is building a representation of the length of its input. A somewhat odd representation, but still a representation, is it not?

• So you are really asking the question "what is counting?" That does not sound like computer science to me. It would be computer science if your question was "for this definition of counting, can an FSA count?". – Sasho Nikolov Apr 9 '13 at 17:19

This question is a bit vague, so here is a vague answer: Translating unary to unary is not exactly counting, since the machine doesn't actually "know" what the size of the input was "in the end".

You realize this, of course, which is why you question the fact that it is indeed counting.

Translating from unary to binary, however, seems like a way-more advanced operation, because it does not only involve counting, it also involves arithmetic.

So perhaps the more precise notion to look at, instead of counting, is comparing. That is, given two numbers (in unary) $1^n$ and $1^m$, determine if $n=m$.

The ability to do this comparison is what gives rise to the famous non-regular language $\{a^nb^n: n\ge 0\}$. And the inability of an NFA to count is what makes this language non-regular.

Interestingly, this language is a CFL. And indeed, the corresponding automata model - PDAs, do have the ability to do a limited comparison.

When you talk about comparing, transducers no longer give you any additional power, so the question is resolved in that sense.

An additional note: completely informally, the ability to compare two numbers can often be used to simulate a 2-counter machine Minsky Machine, which are equivalent to TMs.

No. Finite state automata do not count. They may do things that look like it, but they cannot count. They can even do a little (hard-wired) computations (like determining whether a binary number is divisible by three) but that is not counting.

A little story. You are on a big rectangular square in a famous city. The locals tell you the square is actually square. If you can count you check whether the horizontal and vertical numbers of tiles match by counting tiles along the sides of the square. If you cannot count you can still verify the claim: start at a corner and walk diagonally. If you exactly reach the opposite corner you have a square.

In your example the fsa tests whether a string has an equal number of $a$'s and $b$'s by tallying these numbers to two different output tapes. Another device has to be doing the final comparison, unless you have a trick to handle the letters $a$ and $b$ in pairs and cros off one against the other. Like in the square.

Now a more formal model to compare with. According to the Chomsky–Schützenberger Theorem every context-free language $L$ is an inverse of a finite state transduction $T$ of the Dyck language $D_2$ on two pairs of brackets $L = T^{-1}(D_2)$ (it is not stated like that on wikipedia, but you have to believe me). Now the finite state transducer $T$ can "accept" its context-free language $L$ as follows (for each language its own transducer). On input $T$ transforms the string into the (guessed) series of pops and pushes of the pda for $L$, then test whether the result is pushdown behaviour, i.e., the result is a string in $D_2$. (Technical details omitted, but this is as claimed by the Ch-Sch Theorem: one has $w\in T^{-1}(D_2)$ iff $T(w) \in D_2$)

My point here is that some "computation" is done by the transducer but much power is hidden in the test with $D_2$. Likewise your example, where two letters are sorted on two tapes.

• I can construct a DFA that counts between $0$ to $2^{n!}$ (for fixed $n$) or even in $\mathbb{N}$. That's more than any human or real computer manages. What would you call counting? – Raphael Apr 10 '13 at 8:53
• @Raphael. Sure. And easily larger numbers than that. Stop teaching that context-free languages are more powerful than regular languages: they are the same (at least for strings of length at most $2^{n!}$). Just joking. Referring to real computer languages like that makes anything finite state isn't it? Finite state automata do not count! They just distinguish a finite number of states, although that number may be very large. – Hendrik Jan Apr 10 '13 at 9:39
• But the way FSAs are usually presented, they are only "allowed" to say either "yes" (accepted) or "no" (not accepted). Given this, no one could construct an FSA that counts. If we allow it to report (e.g. print) the (number of the) state it is in when it terminates, then it can count, but only up to a bound given by the number of states. But if DO we allow it to print, then it is trivial to construct a single state FSA that prints (say) 1 each time it reads a symbol from the input string, thus reporting the count in the tally representation. What's wrong with this idea? – Torbjörn Apr 10 '13 at 10:06
• And if we forget about reporting/printing, and think in terms of internal representations instead, an FSA can count the symbols in a string, but not in an arbitrary long one. The single state FSA then of course cannot count at all. – Torbjörn Apr 10 '13 at 10:44
• Hendrik, I think we are "debating" a matter of semantics: for me, "counting" can be "from one to ten" which FA can do. When intersecting Büchi-automata, for instance, we count how many (of $k$, fixed) automata have reached a final state while the others proceed. Therefore, I think the statement "can not count" is too strong. The (only) true statement is "the can not count farther than to a constant". – Raphael Apr 10 '13 at 11:10

@Shaull: Thanks for your answer! I'm new to StackExchange and don't know how to comment on an answer, so I choose to write an answer instead, in the hope that I may be forgiven.

Hmm, it seems to me that a shepard counting his sheep by writing a mark on a slip of paper for each sheep that he sees, or a prisoner counting the days he's been in jail by writing marks on the wall, are counting. Why wouldn't n marks on a slip of paper or on a wall count as a representation of the number n? Isn't that what is called a tally representation? AFAICS it is in no obvious way inferior to (say) a binary representation, except that it uses more space.

I suppose that for you then, "know" means that it has an internal representation of the count in the end. Then, of course, it is obvious that an FSA of FST cannot compute the length of an arbitrary string. But if we don't require knowledge in that sense, but demand only that the FSA or FST should be able to tell the result to an external observer, then it seems to me that presenting the count in a tally format should be ok.

Furthermore, if an FSA is equipped with both incremental input and output, then it should in principle be able to use its external environment as a read/write memory, and thus be as powerful as a Turing machine. Right?

Thanks for bringing up the case of comparing. Now, it appears to be the case that if we lift the requirement of an internal representation, and we only require that the machine is able to present the result to en external observer, then we could easily build an FSM that could produce a kind of graphical presentation of the outcome. Suppose the FSM, upon readins "aaaaaabbbbbb" wrote

000000
000000

then, since the bars are of the same length, the FSM has accepted the string "aaaaaabbbbbb". Two bars of the same length means "yes", different lengths means "no".

I guess I'm bending the rules, but that's what I want since I'm interested in the more or less implicit assumptions that are being made in the field of mathematical linguistics.

• Perhaps your "model" can be seen as a FSA with a finite number (equal to the alphabet size) of write only counters plus a special final state that can compare two (or more) of them and accept or reject according if they are equal or not. Such "$FSA_{WOC}$" is more powerful than a FSA; but it has some troubles recognizing things like $\{a^n | n \mbox{ is prime }\}$ i.e. doing arithmetic. – Vor Apr 9 '13 at 13:53
• I think the difference between the examples you give and FST-output is that the shepherd can read the lines after they are written, whereas an FSM can't. Same goes for comparing. – Shaull Apr 9 '13 at 18:49