If you are computer-savvy, you can install Walnut on your computer by going to this page, or if you just want to try it in a web browser, go to this URL. It takes about 15-30 seconds to load. Once it loads, click the button that says "New ▼" and select "Walnut". You will now see a blue rectangle. You can now type in Walnut commands and click the small black right-pointing triangle ▸ to run them.
Use the syntax eval test followed the predicate in quotes, then a semicolon, to enter Walnut queries for
Remember that A denotes "for all" and E denotes "there exists".
Solution. Do you see why the first returns TRUE and the second FALSE?
def odd "E k n=2*k+1";
Try entering that now.
By the way, if you want to see more of what is happening "behind the scenes", you can always end a command with a colon : instead of a semicolon ; . Or if you want to see even more, use two colons at the end.
Next, define an automaton "even" in the same way, and then try evaluating the following command, which proves the theorem.
eval thm1 "A m,n ($odd(m) & $odd(n)) => $even(m+n)";
Notice that when you use a defined automaton, you precede its name with a dollar-sign. Next, prove that the sum of an odd number and an even number is odd.
Now let's prove one of the very first theorems in combinatorics on words, proved by the Norwegian mathematician Axel Thue in 1912: the Thue-Morse sequence has no overlaps. An overlap is a string of the form axaxa, where a is a single letter and x is an arbitrary string, possibly empty. An example of an overlap in English is the word alfalfa.
Try writing a Walnut predicate hasover that asserts that T has an overlap axaxa of total length 2n + 1 beginning at position i of T. So here the variables i and n are unbound; they have no quantifier associated with them. It should look something like
def hasover "definition goes here";
Try writing a Walnut command starting with "eval" that asserts that T has no overlaps anywhere in it. Here you can use the symbol ~ for logical negation. There is a small pitfall here to avoid...
In Walnut there is no way to directly quantify over all strings. You can only quantify over the natural numbers. So we can't express "if a string x occurs then ..." directly. Instead of working with strings, we work with occurrences of strings. These can be specified, for example, by giving the starting position i and the length n of the string, inside some sequence.
Try writing a Walnut command proving the mirror invariant property for T.
Try defining that one using def and then using it to prove that T has the property of recurrence: namely, every string occurring in T, actually occurs infinitely often.
Here's how Walnut can not only prove theorems, but actually figure out the right statement to prove! Consider the Thue-Morse sequence one more time. It has squares in it, that is, blocks of the form xx where x is nonempty, such as 00 and 010010. It is natural to ask what the length of these blocks can be. Write a Walnut predicate squarelen with n as a free variable (unbound by any quantifier) that says there exists a square of length 2n in the Thue-Morse sequence.
Once you have created the automaton, you can deduce the theorem about what the lengths are by simply examining the strings it accepts, which are those n that are possible, expressed in base 2. What are they?
(You can see the automaton in two different ways, depending on whether you have Walnut installed on your computer, or you're using the web browser version. For the latter, just type
%showme squarelen
and it should appear on your screen. For the former, a bit more work is needed. Use another terminal window, go to the Result directory, and look for the file squarelen.gv, which is a GraphViz encoding of the automaton. Then you can use a command like
dot -Tpdf squarelen.gv > squarelen.pdf
in Linux to create a pdf file you can view.
Whenever we work with an exotic numeration system like Fibonacci, we need to tell Walnut that's what we are doing. To do this we write the query as
"?msd_fib rest of query";
Determine the degree of repetition in this sequence. Does it have squares, of the form xx, or cubes of the form xxx, or fourth powers of the form xxxx, where x is a nonempty block?
Let ϕ = (1+√5)/2 be the golden ratio. It turns out that the functions n → floor (ϕ n) and n → floor (ϕ2 n) are both computable in this way, and the following Walnut code defines them, respectively, as phin and phi2n:
reg shift {0,1} {0,1} "([0,0]|[0,1][1,1]*[1,0])*"; def phin "?msd_fib (s=0 & n=0) | E x $shift(n-1,x) & s=x+1"; def phi2n "?msd_fib (s=0 & n=0) | E x,y $shift(n-1,x) & $shift(x,y) & s=y+2";It would take us too far afield to explain how this works, so please just take it on faith.
Now we can do some additive number theory. Show that every sufficiently large natural number is representable as floor (ϕ m) + floor (ϕ n) for m, n ≥ 1. However this is not possible for floor (ϕ2 m) + floor (ϕ2 n). Also show that every sufficiently large natural number is representable as floor (ϕ2 m) + floor (ϕ2 n) + floor (ϕ2 p) for m, n, p ≥ 1.