A 4-ary Lyndon word is a string made from the characters 0, 1, 2, 3. It must be aperiodic (not equal to any of its non-trivial rotations) and be lexicographically least among its rotations.
Here we consider the set L(n;t,s) of length n lyndon words a1a2···an over the alphabet {0,1,2,3} that have trace t and subtrace s. The trace of a 4-ary lyndon word is the sum of its digits mod 4, i.e. t = a1+a2+ ··· +an mod 4. The subtrace is the sum of the products of all n(n-1)/2 pairs of digits taken mod 4, i.e. s = SUM( aiaj : 1 < i < j < n ).
| (trace,subtrace) | ||||||||||||
| n | (0,0) | (0,1) | (0,2) | (0,3) | (1,0) (3,0) | (1,1) (3,1) | (1,2) (3,2) | (1,3) (3,3) | (2,0) | (2,1) | (2,2) | (2,3) |
| 1 | 1 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 1 | 0 | 0 | 0 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 2 | 0 | 0 | 0 | 1 | 1 | 0 | 1 | 0 | 1 | 0 | 0 | 0 |
| 3 | 1 | 2 | 0 | 2 | 2 | 0 | 2 | 1 | 1 | 2 | 0 | 2 |
| 4 | 1 | 6 | 1 | 6 | 4 | 4 | 4 | 4 | 4 | 4 | 0 | 6 |
| 5 | 11 | 16 | 8 | 16 | 8 | 16 | 11 | 16 | 11 | 16 | 8 | 16 |
| 6 | 44 | 45 | 36 | 40 | 32 | 53 | 32 | 53 | 45 | 36 | 40 | 44 |
| 7 | 169 | 128 | 160 | 128 | 128 | 169 | 128 | 160 | 169 | 128 | 160 | 128 |
| 8 | 588 | 448 | 548 | 448 | 512 | 512 | 512 | 512 | 576 | 440 | 576 | 440 |
| 9 | 1948 | 1706 | 1920 | 1706 | 1948 | 1706 | 1920 | 1706 | 1948 | 1706 | 1920 | 1706 |
| 10 | 6560 | 6528 | 6496 | 6579 | 6963 | 6144 | 6963 | 6144 | 6579 | 6560 | 6528 | 6496 |
| 11 | 23133 | 24576 | 23040 | 24576 | 24576 | 23040 | 24576 | 23133 | 23133 | 24576 | 23040 | 24576 |
| 12 | 84565 | 90110 | 84565 | 90110 | 87380 | 87380 | 87380 | 87380 | 84820 | 90046 | 84480 | 90004 |
| 13 | 317755 | 327680 | 317440 | 327680 | 317440 | 327680 | 317755 | 327680 | 317755 | 327680 | 317440 | 327680 |
| 14 | 1198336 | 1198665 | 1197824 | 1198080 | 1179648 | 1217097 | 1179648 | 1217097 | 1198665 | 1197824 | 1198080 | 1198336 |
L(n;t,s) = 1/n sum_{k=0,1,2,3} sum_{d|n,d=2k+1(8)} mobius(d) S(n/d,(-1)kt,(-1)ks-kt2),
where S(n;t,s) is the number of 4-ary words with trace t and subtrace s. Tables of the S(n;t,s) numbers may be found on the page http://theory.cs.uvic.ca/inf/trs/str/Zq/str_tr_subtr_Z4.html
In the case where t is odd, this formula may be simplified to
L( n ; t, s ) = 1/n sum_{ d | n, d=1,3(4) } mobius(d) S( n/d, dt, ds-(d-1)/2 ).
