Walnut is free software, written in Java, for
deciding first-order statements phrased in an extension of
Presburger arithmetic, called Buchi arithmetic. It
can be used to prove hundreds of results in combinatorics
on words, number theory, and other areas of discrete
mathematics. It can handle a wide variety of problems. There are some recent additions to Walnut, written by Aseem Baranwal,
Kai Hsiang Yang, and Anatoly Zavyalov.
March 27 2023
Walnut 5.4 is now available! It contains several new commands, including
the ability to do transductions of automatic sequences, and fixes one obscure
bug introduced in Walnut 3: namely, regular expressions with negative elements
could under some rare circumstances be interpreted incorrectly. This version
was modified by Anatoly Zavyalov. This version supersedes all previous versions.
The Walnut book is now available
from Cambridge University Press. Get your copy today!
August 15 2022
Walnut 4 is now available! It contains several
new and useful commands,
in particular for handling negative bases and quantification over Z
instead of N.
It is available for download here. This version incorporates new original work by Kai Hsiang Yang.
September 6 2021
Walnut 3 is now available! It contains several
new and useful commands.
It is available for download
This version represents additional work done by Laindon C. Burnett
to the previous versions of Walnut written by Hamoon Mousavi and updated
by Aseem Raj Baranwal. For this version, you should type
java Main.Prover to get started, insted of the older
When you go to the github site above,
click on the green "Code" button, then choose "Download Zip".
When you get the zip file downloaded, you might (depending exactly one what system you use) just click on it
to extract it. Otherwise you might have to use a zip extractor.
Now you should have a directory called something like Walnut-main.
Go into that directory and there is a command called "build.sh".
Execute that command - on my Unix system you type
to do that.
That should take a few seconds to compile.
Then go to the "bin" directory and type
that gets you into Walnut. To leave, type quit;
Depending on your system, you may need a "Java Development Kit" to install
Walnut. If so, try the command
sudo apt install openjdk-11-jdk
from a terminal window. Once that is done, to compile Walnut,
go to the Walnut directory
sh build-sh (Windows)
It might be that you can get by without the "sh" before the command,
depending on your system.
That should do it! Now you are ready to go to the "bin" directory
Let me know if you have any difficulties.
The old version of Walnut is available at github. For the new version, see above.
After you download it and install it, go to the directory
Walnut/bin and type java Main.prover to get started.
A manual of how to use it is available on the
There is also a text file with some
how to use Walnut.
Here is a video tutorial
on how to use Walnut:
Here is a talk, given on October 18 2022,
about how to use Walnut to prove properties of the
sequences in the OEIS:
If you are using Walnut under the Eclipse environment, here are a few tips.
Download the Walnut software. Start Eclipse up. Use the default
workspace. Open "Project" from the File choices, and choose "Walnut".
Next, go to src/Main in the menu choices, right-click on prover.java
and choose "Run As Java Application". You should now get a window where
you can enter Walnut commands. To see results, go to
the Eclipse file menu, right-click on "Result" and choose "Refresh" and
the results should be there. Thanks to Stepan Holub for this info.
Recently Walnut has been modified by Aseem Baranwal to handle the Pell
number system, and more generally, the Ostrowski number system based
on any quadratic irrational. To use this version of Walnut, visit
https://github.com/aseemrb/walnut. After you download and install it, go to the directory
Ostrowski/bin and type java Main.Prover to get started.
(Note: for the old Walnut, you use lowercase "p" in prover; for the
new version you use uppercase "P" in prover.)
The command "ost name [0 1 2] [3 4]", for example, defines
an Ostrowski number system for the continued fraction [0,1,2,3,4,3,4,3,4,...].
It can then be used by prefacing a query with "?msd_name" or "?lsd_name".
Aseem Baranwal has prepared a brief summary of his additions to
If you find Walnut useful in your research, please be sure to cite
Hamoon Mousavi as the author of the software, and let me know what you
achieved with it.
Walnut has been used in a variety of papers and books. A partial list is here
(will be updated):
X.txt, put in the Word Automata directory of Walnut
Y.txt, put in the Word Automata directory of Walnut
tar file of automata produced, unpack and put in the Automata Library directory of Walnut. These will be produced by
the commands above if you have enough RAM
on your machine and time to devote (about two weeks of computation time on a machine with 400G of RAM). But if you do not have this time you can just
work with the automata produced.
R. Fokkink, G. F. Ortega, and D. Rust,
Corner the empress, Arxiv preprint arXiv:2204.11805 [math.CO], December 8 2022. Available at https://arxiv.org/abs/2204.11805.
Dominik Leon Jilg,
Frobeniuszahl ausgewählter Zahlenfolgen:
Analyse der Frobeniuszahl von synchronisierten Folgen und Folgen mit automatisierter charakteristischer Folge, Bachelor's thesis,
Lehrstuhl für Mathematik IV,
Julius-Maximilians-Universität Würzburg, Germany, August 12 2022.
The Logical Approach To Automatic Sequences: Exploring Combinatorics on Words with Walnut, London Math. Soc. Lecture Note Series,
Press, September 29 2022.
Some Tribonacci conjectures,
arxiv preprint arXiv:2210.03996 [math.CO],
October 8 2022.
Here are the files for the automata you will need
in this paper. Put them in the "Automaton Library" of Walnut.
Jeffrey Shallit, Sonja Linghui Shan, and Kai Hsiang Yang,
Automatic Sequences in Negative Bases and Proofs of Some Conjectures of
Shevelev, arxiv preprint arXiv:2208.06025 [cs.FL], August 11 2022,
available at https://arxiv.org/abs/2208.06025. Appeared in
J. Shallit, S. L. Shan and K. H. Yang,
"Automatic sequences in negative bases and proofs of some
conjectures of Shevelev", RAIRO-Theor. Inf. Appl.57 (2023), 4.
R. Burns, Factorials and Legendre's three-square theorem: II,
arxiv preprint arXiv:2203.16469 [math.NT],
March 30 2022. Available at https://arxiv.org/abs/2203.16469.
J. Shallit, Note on a Fibonacci parity sequence,
arxiv preprint arXiv:2203.10504 [cs.FL], March 20 2022.
Available at https://arxiv.org/abs/2203.10504.
Appeared in J. Shallit,
Cryptography and Communications15 (2023), 309-315.
N. Rampersad, The periodic complexity function of the Thue-Morse word, the Rudin-Shapiro word, and the period-doubling word,
arxiv preprint arXiv:2112.04416, December 8 2021.
Available at https://arxiv.org/abs/2112.04416. Appeared in Australasian J. Combinatorics85 (2023), 150-158.
N. Rampersad, Prefixes of the Fibonacci word that end with a cube,
arxiv preprint arXiv:2111.09253, November 17 2021.
Available at https://arxiv.org/abs/2111.09253. Appeared as
N. Rampersad, Prefixes of the Fibonacci word,
C. R. Math. Acad. Sci. Paris361 (2023) 323-330.
J. Shallit, Intertwining of Complementary Thue-Morse Factors,
arxiv preprint arXiv:2203.02917 [cs.FL], March 6 2022.
Available at https://arxiv.org/abs/2203.02917. Revised, published version in
Australasian J. Combinatorics84 (2022), 419-430.
Sumsets of Wythoff sequences, Fibonacci representation, and beyond,
Periodica Mathematica Hungarica84 (2022), 37--46.
Phakhinkon Napp Phunphayap, Prapanpong Pongsriiam, and
Sumsets associated with Beatty sequences, to appear,
Aseem Raj Baranwal, Jeffrey Shallit,
Repetitions in infinite palindrome-rich words, arxiv preprint, April 22 2019.
In Mercas R., Reidenbach D. (eds.) Combinatorics on Words. WORDS 2019.
Lecture Notes in Computer Science, vol. 11682, Springer, 2019, pp. 93-105.
Tim Ng, Pascal Ochem, Narad Rampersad, Jeffrey Shallit,
results on pseudosquare avoidance, arxiv preprint, April 19 2019.
In Mercas R., Reidenbach D. (eds.) Combinatorics on Words. WORDS 2019.
Lecture Notes in Computer Science, vol. 11682, Springer, 2019, pp. 264-274.
James Currie, Narad Rampersad, Tero Harju, and Pascal Ochem,
Some further results on squarefree arithmetic
progressions in infinite words,
January 18 2019. Appeared in
Theoretical Computer Science799 (2019) 140-148.
James Currie and Narad Rampersad,
On some problems of Harju concerning squarefree
arithmetic progressions in infinite words,
December 5 2018.
Formal inverses of the generalized Thue-Morse sequences
and variations of the Rudin-Shapiro sequence,
October 8 2018. Appeared in
Discrete Mathematics and Theoretical Computer Science
Vol. 22:1, 2020, #15.
Colin Krawchuk and Narad Rampersad,
Cyclic Complexity of Some Infinite Words and Generalizations,
Integers18A (2018), #A12.
Jeffrey Shallit and Ramin Zarifi,
Circular critical exponents for Thue–Morse factors,
RAIRO Info. Theor., published online 17 January 2019.
Pierre Bonardo, Anna E. Frid, Jeffrey Shallit,
"The number of valid factorizations of Fibonacci prefixes",
Theor. Comput. Sci., 2019, to appear.
Available online at https://doi.org/10.1016/j.tcs.2018.12.016.
Jason Bell, Kathryn Hare and Jeffrey Shallit,
When is an automatic set an additive basis?
Proc. Amer. Math. Soc. Ser. B5 (2018), 50-63.
Jason Bell, Thomas Finn Lidbetter, and Jeffrey Shallit,
Additive Number Theory via Approximation by Regular Languages,
arxiv preprint, April 23 2018. Appeared in M. Hoshi and S. Seki, eds.,
DLT 2018, LNCS Vol. 11088, Springer, 2018, pp. 121-132.
Here are text files describing how you can verify the results
yourself using Grail and Walnut.
Daniel Goc, Hamoon Mousavi, Luke Schaeffer, Jeffrey Shallit,
A New Approach to the Paperfolding Sequences,
in Arnold Beckmann, Victor Mitrana, Mariya Soskova, eds.,
11th Conference on Computability in Europe, CiE 2015, Springer, LNICS,
Vol. 9136, 2015, pp. 34-43. Available