Download as ps, pdf, or txt
Download as ps, pdf, or txt
You are on page 1of 2

A Simpler Grammar for Fibonacci

Numbers
Markus Holzer1;2 and Peter Rossmanith2
1 Wilhelm-Schickard-Institut fur Informatik, Universitat Tubingen,
Sand 13, D-72076 Tubingen, Germany
2 Fakultat fur Informatik, Technische Universitat Munchen,
Arcisstr. 21, D-80290 Munchen, Germany
Fibonacci numbers can be regarded as a formal language in a very natural
way: The language Fb consists of words encoding each Fibonacci number in
b-ary notation over alphabet f0; 1; : : : ; b 1g. This works for any base b > 1.
The language F1 of unary Fibonacci numbers is de ned as f 0Fn j n  1 g =
f0; 00; 000; 00000; : : :g.
The Chomsky hierarchy of formal languages consists of four levels: Reg-
ular, context-free, context-sensitive, and recursively enumerable languages
(see Hopcroft and Ullman [1] for details).
By Moll and Venkatesan [2] it was shown that Fb is not context-free for
any base b > 1. It is clear that F1 is not context-free, too. If F1 were
context-free, the Fibonacci numbers would be a semi-linear set by Parikh's
Theorem [4], i.e., a nite union of linear sets f nk + ` j n  0 g.
Mootha [3] presented a context-sensitive grammar for F1, demonstrat-
ing that unary Fibonacci numbers are context-sensitive thus placing them
optimally in the Chomsky hierarchy. However, the grammar is compli-
cated and includes 53 symbols and 80 rules. The following simpler gram-
mar G = (N; T; P; S ) with nonterminals N = fS; A; B; Br ; C g, terminals
T = f0g, axiom S , and productions
S ! CS j Br
CA ! BC
CB ! ABC
CBr ! ABr
A!0
B!0
Br ! 0
also generates exactly the unary Fibonacci numbers.
It works as follows: First a sentential form CC : : : CBr is generated using
only the rules S ! CS and S ! Br . Let us call a sentential form C : : : C Br
A Simpler Grammar for Fibonacci Numbers 2

basic, if contains only A's and B 's. #A ( ) denotes the number of A's and
#B ( ) the number of B 's and Br 's in the word .
If and are basic sentential forms, ) , and contains one more C


then , then
#A( ) = #B ( ) and #B ( ) = #A ( ) + #B ( ):
From a basic sentential form C : : : CBr of length n 1 a basic sentential
form of length Fn will be nally derived which itself lead to the word 0Fn .
Note that the length of the derivation itself is exactly Fn+2 + n 3 and that
the number of productions and the cardinality of N and T are Fibonacci
numbers, too.
Observe that b-ary Fibonacci numbers are also context-sensitive. The
context-sensitive languages are a superset of all languages that are recogniz-
able with linear space by a deterministic Turing machine. Since addition of
numbers b-ary notation can be done in linear space, all Fibonacci numbers
can be generated by use of the recurrence that de nes Fibonacci numbers.
Finally we note that if we change the production for nonterminal S to
S ! Cl Br j Br
and add the productions
Cl A ! ClBC j BC
Cl B ! ClABC j ABC
Cl Br ! ClABr j ABr
then the word 0Fn can be derived in exactly Fn+2 1 steps.

References
[1] J. E. Hopcroft and J. D. Ullman. Introduction to Automata Theory,
Languages and Computation. Addison-Wesley, 1979.
[2] R. J. Moll and S. M. Venkatesan. Fibonacci numbers are not context-free.
Fibonacci Quarterly, 29(1):59{61, 1991.
[3] V. K. Mootha. Unary Fibonacci numbers are context-sensitive. Fibonacci
Quarterly, 31(1):41{43, 1993.
[4] R. J. Parikh. On context-free languages. Journal of the ACM, 13(4):570{
581, 1966.
AMS Classi cation Numbers: 68Q50, 68Q45

You might also like