-
Notifications
You must be signed in to change notification settings - Fork 11
/
gostate.tex
2157 lines (1916 loc) · 83.6 KB
/
gostate.tex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
\documentclass{article}
\usepackage{amsmath}
\usepackage{epsf}
\begin{document}
\newtheorem{theorem}{\sc Theorem}
\newtheorem{lemma}{\sc Lemma}
\newtheorem{coro}{\sc Corollary}
\newtheorem{conj}{\sc Conjecture}
\newtheorem{defin}{\sc Definition}
\newenvironment{proof}{\par \sc Proof.\rm}{\hspace*{\fill}$\bullet$\vspace{1ex}}
\newcommand{\BFL}{\mathbf{L}}
\newcommand{\BFl}{\mathbf{l}}
\newcommand{\BFp}{\mathbf{p}}
\newcommand{\BFT}{\mathbf{T}}
%\title{On the State and Game Tree Complexity of Go}
\title{Combinatorics of Go}
\author{John Tromp \and Gunnar Farneb\"{a}ck}
\maketitle
\begin{abstract}
We present several results concerning
the number of positions and games of Go.
We derive recurrences for $L(m,n)$,
the number of legal positions on an $m \times n$ board,
and develop a dynamic programming algorithm which computes
$L(m,n)$ in time $O(m^3 n^2 \lambda^m)$ and space $O(m \lambda^m)$,
for some constant $\lambda < 5.4$.
An implementation of this algorithm lets us list $L(n,n)$ for $n\leq 18$.
For bigger boards, we prove existence of a
{\em base of liberties} $\lim_{m,n \rightarrow \infty} \sqrt[mn]{L(m,n)}$ of
$2.9757341920433572493\ldots$.
Based on a conjecture about vanishing error-terms,
we derive an asymptotic formula for $L(m,n)$,
which is shown to be highly accurate.
We also study the Game Tree complexity of Go,
proving an upper bound on the number of possible games
of $(mn)^{L(m,n)}$ and a lower bound
of $2^{2^{n^2/2\,-O(n)}}$ on $n\times n$ and $2^{2^{n-1}}$
on $1 \times n$ boards, in addition to
exact counts for $mn \leq 4$ and estimates up to $mn=9$.
We end with investigating whether one game can encompass all legal positions.
%, and a study of the maximum number of strings.
\end{abstract}
\section{Introduction}
Originating over 3000 years ago in China,
Go~\cite{gowiki} is perhaps the oldest boardgame in the world,
enjoyed by millions of players worldwide.
Its deceptively simple rules~\cite{gorules}
give rise to amazing strategic depth.
Results about the computational complexity of Go
date back some 25 years. In 1980, Lichtenstein and Sipser~\cite{LS80}
proved Go PSPACE-hard, while 3 years later, Robson~\cite{R83}
showed Go with the basic ko rule to be EXPTIME-complete. More recently,
certain subproblems of the game have been shown PSPACE-complete,
like endgames~\cite{W02} and ladders~\cite{CT00}.
This paper focuses instead on the {\em state complexity} of Go.
We are motivated by the fact that
the number of legal positions is a fundamental property of a game,
the notion of legal position being unambigiously defined for Go
despite many variations in rulesets, and that its computation turns
out to be almost, but not quite, impossible. In particular, we
demonstrate how computing the number of legal 19x19 positions,
a number of 171 digits, will be feasible by 2015.
\section{Previous work}
Results about the state complexity of Go have been mostly confined
to the online newsgroup {\tt rec.games.go} and the {\tt computer-go}
mailing list.
In September 1992, a {\tt rec.games.go} thread ``complexity of go''
raised the question of how many positions are legal.
It was noted that a trivial upper bound is $3^{mn}$,
since every point on the board may be empty, black,
or white. A position is legal if and only if every string of
connected stones of the same color has an empty point adjacent to it.
Achim Flammenkamp was the first to post simulation results, showing
that $L(19,19) \sim 0.012 \times 3^{361} \sim 2.089 \times 10^{170}$.
In August 1994, a thread ``Complexity of Chess and Go'' revisited the problem.
Jack Hahn, Jonathan Cano, and John Tromp all posted programs to compute the
number of legal positions by brute force enumeration.
The largest count published at the time was $L(4,5)=1840058693$.
A week's worth of computation would have found $L(5,5)$ as well,
but enumerating $L(6,6)$ takes over 10000 times longer, severely
limiting this approach.
In a January 2000 thread
``Number of Legal Positions on Almost Rectangular Boards'',
inspired by earlier remarks by John Tromp and Hans Zschintzsch,
Les Fables first explained in detail how to count using dynamic programming.
His remark ``{\it Calculation for 9x9 should be possible on any PC,
and a supercomputer should easily be able to handle 13x13.}''
proves to be spot on.
Much later, on January 23, 2005, Eric Boesch independently discovered
this method on the {\tt computer-go} mailing list. His method is
implemented the next day by Tapani Raiko, but a bug leads him to post a wrong
count for $L(5,5)$. Later that day Jeffrey Rainy,
based on his own implementation, gives the correct values for
$L(5,5)$ and $L(6,6)$ but wrong values for $L(7,7)$ and $L(8,8)$.
Finally, the next day, Gunnar Farneb\"{a}ck posts the first bugfree program,
providing counts up to $L(10,10)$.
In June 1999, a thread ``Math and Go''
discussed the number of games
of Go. Robert Jasiek claimed an upper bound of $n^{3^n}$, which still
needs to be corrected for intermediate passes. John Tromp showed
how to get a double exponential lower bound, which we make more formal
while fixing a slight flaw, in this paper.
In the same month, John Tromp started a thread ``number of 2*2 games'',
noting that the number is 386356909593, as was recently independently
verified.
%In November 2006, a thread "Maximum number of strings" on the
%{\tt computer-go} mailing list reported on research by
%Youhei Yano and Ryuhei Miyashiro who used Linear Programming
%to compute the maximum possible number of strings, which was found to
%be 277 for $19 \times 19$.
\section{Preliminaries}
A position on an $m\times n$ Go board is a
mapping from the set of {\em points}
$\{0,\ldots,m-1\}\times \{0,\ldots,n-1\}$ to the set of colors
$\{\mbox{empty}, \mbox{black}, \mbox{white}\}$.
Points are {\em adjacent} in the usual grid sense---equal
in one coordinate and differing by one in the other.
A point colored black or white is called a {\em stone}.
Adjacent stones of the same color form connected components
called {\em strings}. An empty point adjacent to a string is called a
{\em liberty} of that string.
A game of Go starts with an empty board. The players, black and white,
alternate turns, starting with black.
On his turn, a player can either {\em pass}, or make a move which doesn't
repeat an earlier position.
This is the so-called Positional SuperKo (PSK) rule. Some rulesets,
notably the American Go Association's AGA rules, use the Situational
SuperKo (SSK) rule, which only forbids repeating a position with
the same player to move.
A move consists of coloring an empty point your color, followed by
emptying all opponent strings without liberties (capture), followed by
emptying all your own strings which then have no liberties (suicide).
Finally, two consecutive passes end the game.
Thus, in positions arising in a Go game,
strings always have liberties. Such positions are called {\em legal}.
The number of legal $m \times n$ positions is denoted $L(m,n)$.
\begin{figure}
\begin{center}
\epsfxsize=9cm \epsfbox{ALL2.eps}
\end{center}
\caption{All $3^4$ $2 \times 2$ positions, with illegal ones crossed.}
\label{ALL2}
\end{figure}
Figure~\ref{ALL2} shows all positions on a $2 \times 2$ board.
Obviously, the 16 bottom-right positions with 4 stones are illegal.
Additionally, the other $8$ crossed positions,
with a stone of one color neighboured by two stones of
the opposite color, are illegal. Since all positions with 2 or fewer stones
are legal, we find that $L(2,2) = 3^4-16-8=57$.
\begin{defin}[game graph]
Let $G(m,n)$ be the directed graph whose vertices are the legal $m\times n$
positions, and which has a directed edge $p \rightarrow q$ whenever
a white or black move from position $p$ results in position $q \neq p$.
\end{defin}
Note that we exclude self-loops, corresponding to single-stone suicides,
which are prohibited by the PSK rule.
This will prove useful in Lemma~\ref{movesedges} below.
\begin{figure}
\begin{center}
\epsfxsize=4cm \epsfbox{G21.eps}
\end{center}
\caption{game graph $G(1,2)$.}
\label{G21}
\end{figure}
\begin{figure}
\epsfxsize=12cm \epsfbox{G31.eps}
\caption{game graph $G(1,3)$.}
\label{G31}
\end{figure}
\begin{figure}
\epsfxsize=12cm \epsfbox{G22.eps}
\caption{game graph $G(2,2)$ with nodes/edges grouped
into rotation/mirror symmetry classes.}
\label{G2}
\end{figure}
Figure~\ref{G21} shows $G(1,2)$, consisting of 5 nodes and 12 edges,
Figure~\ref{G31} shows $G(1,3)$, consisting of 15 nodes and 42 edges,
while Figure~\ref{G2} shows $G(2,2)$ factored into rotation/mirror
symmetry classes. Piet Hut observed that
these latter two graphs are the only ones with no 2-loops.
We next establish some basic properties of Go game graphs.
\begin{lemma}
Outgoing edges from a position are in 1-1 correspondence with moves
that are not single-stone suicides.
\label{movesedges}
\end{lemma}
\begin{proof}
Given a position $p$, each move uniquely determines
a resulting position $q$ and hence an edge $p \rightarrow q$.
It remains to show the converse;
that a resulting position $q \neq p$ uniquely determines a move.
If $q$ has one more stone of color $c$, say at position $(x,y)$,
and the same or fewer stones of opposite color, then that was the move.
If $q$ has fewer stones of color $c$ and the same number of stones
of opposite color, then the missing stones must form a string with
1 liberty, and the move was a suicide.
It can be seen that these cases are exhaustive, the former covering
all non-suicide moves, and the latter covering all multiple-stone suicides.
\end{proof}
\begin{coro}
\label{outdeg}
A node with $k$ empty points has outdegree at most $2k$.
\end{coro}
\begin{coro}
Each edge has an implied black or white color.
\end{coro}
Recall that a {\em simple} path is one that has no
repeated vertices.
\begin{lemma}
\label{gamepaths}
Go games are in 1-1 correspondence with simple paths
starting at the empty position in the game graph.
\end{lemma}
\begin{proof}
The previous Lemma shows that any path corresponds to a sequence
of moves, not necessarily alternating in color.
Inserting a single pass before every out-of-turn move,
and 2 passes at the end, produces a properly alternating and ending game.
The starting node ensures that the game starts from an empty board,
while simplicity of the path ensures that each move is legal.
Furthermore, since any game can be stripped of its
passes to produce the corresponding path, this is a bijection.
\end{proof}
The above Lemma applies only to rules with Positional SuperKo.
With Situational SuperKo, the corresponding paths are not necessarily
simple, and a position can be visited twice (once by each player).
%if the first visit is not followed by a pass.
\begin{lemma}
The game graph is strongly connected.
\end{lemma}
\begin{proof}
Obviously we can reach any position from the empty board, so it
suffices to show that we can reach the empty position from any position.
We eliminate strings one by one, without ever creating new strings.
To eliminate a string, its owner repeatedly plays on its liberties
while his opponent passes.
Some opponent strings may get captured in the process, but ultimately,
the string itself will commit suicide.
\end{proof}
Note that this result depends on the possibility of suicide,
and fails to hold for alternative rulesets, such as the Japanese
rules of Go, which forbid suicide. Under such rules, a slightly weaker
property can be shown.
\begin{lemma}
On all boards except $1 \times 1$, $1 \times 2$ and $2 \times 1$,
the game subgraph obtained by removing the empty position and all
suicide edges is strongly connected.
\end{lemma}
\begin{proof}
First note that $G(1,1)$ has no suicide-edges to remove,
while $G(1,2)$ breaks into 2 components when removing the empty position.
Obviously, we can reach any position from a suitable single-stone position,
so it suffices to show that we can reach every single-stone position
from any position.
First, one player, say black, repeatedly plays on a liberty of its strings.
When all such plays result in suicides, the other player, white, can proceed
to capture all black strings.
Next, white can play until she has $mn-1$ stones, which black then captures.
Given that $mn \geq 3$, we can repeat this last phase to lead to a
capture by the desired color on the desired point.
\end{proof}
\section{Counting legal positions}
The simplest way to count $L(m,n)$, the number of legal $m \times n$
positions, is by brute force, just trying
all $3^{mn}$ positions and testing each one for legality.
However, a $5 \times 5$ board already has over 400 billion possible
positions, and $9 \times 9$ has over $10^{38}$.
Instead, we establish a correspondence between legal positions and
paths in the so called {\em border state graph}, whose size is much
more manageable. The problem thus reduces to that of counting paths
of a certain length in a graph, which can be done efficiently
by the method of Dynamic Programming.
First we introduce the notion of partial boards, from which the
border states naturally arise.
\subsection{Partial Boards}
Recall from the preliminaries that we number the points
$(x,y) \in \{0,\ldots,n-1\}\times \{0,\ldots,m-1\}$.
We picture a go board with the point $(0,0)$ in the top-left,
$x$-coordinates increasing to the right, and $y$-coordinates
increasing downward.
For $0 \leq x < n$ and $0 \leq y < m$,
let a partial go board up to column $x$ and row $y$ consist
of all the points to the left of and above $(x,y)$.
It has $x$ full columns and, if $y > 0$, one partial column of $y$ points.
Figure~\ref{border} shows two example partial $7\times n$ positions
up to $(3,3)$.
\begin{figure}
\epsfxsize=10cm \epsfbox{partial.eps}
\caption{Two partial positions up to $(3,3)$ and their common border state.}
\label{border}
\end{figure}
What these positions have in common is that
the set of possible completions into legal full-board positions
is identical. In either case, the remainder of the position has
to provide a liberty to the top white group, to the
black group it surrounds, and to the middle black group.
We say that the positions share the same {\em border state}.
\subsection{Border States}
\begin{defin}[border state]
A {\em border state}, or {\em state} for short, comprises the following
data:
\begin{itemize}
\item the board height $m$,
\item the size $0 \leq y <m $ of the partial column,
\item the color of border points
$(x,0),\ldots,(x,y-1),(x-1,y),\ldots,(x-1,m-1)$
($x$ is only a symbol whose value is immaterial to the state),
\item for each stone on the border, whether it has liberties,
\item connections among libertyless stones.
\end{itemize}
% empty points on the border imply liberties for adjacent stones.
%\item adjacent same-colored stones are connected.
%\item connections form an equivalence relation.
A state with height $m$ and partial column size $y$ is called an
$\binom{m}{y}$-state,
or simply $y$-state if $m$ is clear from context.
A partial position is pseudolegal if
all libertyless stones are on, or connected to, the border.
A state is called {\em constructible} if it is the border state of some
pseudolegal partial position of arbitrary width.
\end{defin}
Information of liberties and connections is assumed to
be consistent within the border.
A partial position up to $(0,y)$ has a border state where
points $(x-1,y),\ldots,(x-1,m-1)$ are off the board.
We accomodate these zero-width positions
by allowing the non-color `edge' for all $(x-1,\cdot)$ points,
and call the result an {\em edge state} instead.
In figures, libertyless stones and their connections are indicated with
lines emanating to the left.
The set of constructible states is difficult to characterize,
and hence to count. We therefore introduce a slightly larger class.
\begin{defin}
Call a $y$-state $s$ {\em valid} if it satisfies all the following:
\begin{itemize}
\item connections don't cross, i.e. if 4 stones are ordered vertically as
$a,b,c,d$, with $a$ and $c$ connected, and $b$ and $d$ connected,
then they must all be connected.
\item if a stone at $(x,y-1)$ either
\begin{itemize}
\item has connections, but (if $y>1$) not to $(x,y-2)$, or
\item has liberties, but (if $y>1$) $(x,y-2)$ is opposite-colored,
\end{itemize}
then points $(x,y-1)$ and $(x-1,y)$ are considered adjacent.
\end{itemize}
\end{defin}
\begin{lemma}
\label{constructibleisvalid}
Every constructible state is valid.
\end{lemma}
\begin{proof}
The non-crossing property can be seen to follow from the planarity
of two-dimensional boards.
If border point $(x,y-1)$ has a connection
necessarily going through non-border point $(x-1,y-1)$,
then the latter's neighbour $(x-1,y)$ is effectively
also the former's neighbour. This virtual adjacency
implies that $(x-1,y)$ must be either opposite colored,
or same colored and connected to $(x,y-1)$.
Similarly, if $(x,y-1)$ has a liberty necessarily obtained through
$(x-1,y-1)$, then $(x,y-1)$ is effectively adjacent to $(x-1,y)$,
preventing the latter from being a same colored-stone without liberties.
\end{proof}
\begin{figure}
\begin{center}
{\epsfxsize=2cm \epsfbox{unrealizable.eps}} \hspace{4cm}
{\epsfxsize=2cm \epsfbox{shape.eps}}
\end{center}
\caption{(a) a valid but unconstructible state (b) non-rectangular boardshape}
\label{validshape}
\end{figure}
The smallest example of a valid but not constructible state occurs at $m=3$
as shown in Figure~\ref{validshape}(a).
%is the single non-constructible valid $\binom{3}{2}$-class.
Any partial board that connects the two white stones
and provides a liberty to the black stone,
will inevitably provide a liberty to the white stones as well.
In other words,
the fixed board height of $3$ doesn't allow the white string to distance
itself from the black one.
If we allowed variable height board shapes
such as the one shown in Figure~\ref{validshape}(b),
then the above valid state would become constructible.
It can be shown that
non-constructability of valid states is due entirely to the `lack
of room' to simultaneously provide liberties and connections.
We can somewhat efficiently compute the number of valid $0$-border states,
each of which corresponds to a balanced path of length $m$
through the finite automaton shown later in Figure~\ref{borderdfa}.
In a {\em balanced} path the
up and down connections of libertyless black and white stones
match up properly like balanced parentheses of two types, e.g. `([]([]))'.
Using Dynamic Programming,
we can compute the number of such paths
ending in a given vertex of the automaton with a given
stack of pending connections. With at most $m/2$ pending
connections, there are at most $2^{m/2}$ such stacks.
Having all counts for paths of length $l$, we can in time
$O(2^{m/2})$ compute all counts for paths of length $l+1$,
thus taking time $O(m2^{m/2})$ overall.
It took only 0.005 sec to determine the number of $\binom{19}{0}$ border states
in this manner.
Computing numbers of $y$-states for $y>0$,
numbers of edge states, and of state classes is only slightly more complicated
and can be done within the same time complexity.
Table~\ref{borderstates} shows for each $m$ the minimum and maximum
number of valid $\binom{m}{y}$-border state classes,
which turn out to be achieved at $y=0$ and $y=m-1$, respectively.
The maximum is always about 45\% larger than the minimum.
\begin{table}
\begin{center}
\begin{tabular}{|r|l|l|}
\hline
$m$ & \#valid $\binom{m}{0}$-classes & \#valid $\binom{m}{m-1}$-classes \\ \hline
1 & 3 & 3 \\
2 & 9 & 13 \\
3 & 32 & 46 \\
4 & 117 & 168 \\
5 & 444 & 642 \\
6 & 1712 & 2482 \\
7 & 6742 & 9808 \\
8 & 26973 & 39324 \\
9 & 109736 & 160286 \\
10 & 452863 & 662265 \\
11 & 1894494 & 2772774 \\
12 & 8020098 & 11742926 \\
13 & 34320647 & 50258461 \\
14 & 148266922 & 217096273 \\
15 & 645949499 & 945567689 \\
16 & 2835158927 & 4148642993 \\
17 & 12526125303 & 18320946269 \\
18 & 55665579032 & 81376671503 \\
19 & 248661924718 & 363324268018 \\
%29 & 954288877719528758 & 1387841561460467776 \\
%39 & 4473796211426669492286473 & 6487684033510851922982593 \\
%49 & 23280658008873608262573408056028 & 33699888311500814844062557229102 \\
%59 & 129235153940653928001315951386080547675 & 186846769643959178001661457280461585567 \\
%63 & 65289749895041712025414950342628423873304 & \\
%64 & 309840492766138133207052185879039243670673 & 447753120258832442706873006322187901422572 \\
\hline
\end{tabular}
\end{center}
\caption{Number of valid border state classes.}
\label{borderstates}
\end{table}
Only a tiny percentage of the listed valid states fails to be constructible
(e.g. only 337 of the 109736 valid $\binom{9}{0}$-classes).
\subsection{The border state graph}
\begin{figure}
\epsfxsize=12cm \epsfbox{expandborder.eps}
\caption{A border state and its 3 successors.}
\label{successors}
\end{figure}
Let's see how
the border state of a partial board up to $(x,y)$ and the color of $(x,y)$
uniquely determine the border state up to $(x,y+1)$,
as exemplified in Figure~\ref{successors}.
If $(x,y)$ is empty, then any libertyless stones at $(x,y-1)$ and $(x-1,y)$
as well as all stones connected to them, become stones with liberties.
Otherwise, suppose $(x,y)$ is black.
If $(x-1,y)$ is a libertyless white stone without connections, then
the new partial board is no longer pseudolegal; a case we must avoid.
If either $(x,y-1)$ or $(x-1,y)$ is empty or
black with liberties then $(x,y)$ has liberties,
which it may provide to the other neighbour
(if that is black without liberties).
Finally, if neither $(x,y-1)$ nor $(x-1,y)$ provides liberties,
then $(x,y)$ is without liberties and connects any black neighbours.
The case for $(x,y)$ being white is identical with all colors reversed.
Similarly, the edge state of a partial board up to $(0,y)$
and the color of $(0,y)$ uniquely determine
the edge state up to $(0,y+1)$ (in case $y<m-1$)
or border state up to $(1,0)$ (in case $y=m-1$).
\begin{defin}[(augmented) border state graph]
Let $B(m)$ be the directed graph whose vertices are the constructible
border states of height $m$,
and which has edges from each $y$-state to its 2 or 3 successor
$((y+1)\bmod m)$ states.
The augmented border state graph $AB(m)$ has additional vertices and
outgoing edges for all edge states.
\end{defin}
\begin{figure}
\begin{center}
\epsfxsize=5cm \epsfbox{B1.eps}
\end{center}
\caption{Augmented border state graph $AB(1)$.}
\label{onebordergraph}
\end{figure}
\begin{figure}
\begin{center}
\epsfxsize=12cm \epsfbox{B2.eps}
\end{center}
\caption{Edges between state classes of $B(2)$.}
\label{twobordergraph}
\end{figure}
Figure~\ref{successors} shows the 3 successors of a border state,
while Figure~\ref{onebordergraph} shows
the augmented border state graph $AB(1)$.
Border state graph $B(2)$ is too large to show in full detail,
so instead of border states we show border state {\em classes}.
%Each edge from a class with stones
%thus represents 2 edges in $B(2)$, one from each of the 2 states in the class
%(necessarily leading to equivalent states).
For further clarity, Figure~\ref{twobordergraph}
shows edges between the 9 $0$-state classes and 13 $1$-state classes
separately for each direction,
with the state classes ordered to minimize edge crossings.
Thick edges represent the case where adding a black stone
and adding a white stone lead to equivalent states in $B(2)$.
\begin{lemma}
\label{connected-border-graph}
The border state graph is strongly connected.
\end{lemma}
\begin{proof}
Every $y$-state reaches the stoneless $y$-state after $m$ empty
successors, and thus reaches the stoneless $0$-state after another
$m-y$ empty successors.
From the latter, we can reach any possible column~0 state $s$,
and hence any constructible state, as follows. Note that $s$ can be reached
in $m$ steps from a $0$-state $s'$ that replaces each stone in $s$ by
a stone with liberties of the opposite color, effectively forming
a virtual edge. Any such state $s'$ can clearly by reached from
the stoneless $0$-state in $m$ steps.
\end{proof}
\begin{lemma}
\label{positionpaths}
There is a 1-1 correspondence between pseudolegal partial positions up
to $(n,y)$ and paths of length $mn+y$ through the augmented border state
graph that start at the all-edge state.
\end{lemma}
\begin{proof}
By induction on $mn+y$. The unique partial position up to $(0,0)$
corresponds to the length $0$ path starting at the all-edge state.
Furthermore, for a path ending at state $s$ corresponding to a
pseudolegal partial position $p$ up to $(n,y)$, the successors of $s$
correspond exactly to the pseudolegal partial positions $p'$ up to
$(n,y+1)$ (or $(n+1,0)$ for $y=m-1$) that extend $p$ by one point.
\end{proof}
\subsection{Recurrences}
\begin{defin}[state counts]
For an $\binom{m}{y}$-state $s$,
denote by $L(m,n,y,s)$ the number of pseudolegal
partial positions up to $(n,y)$ that have border/edge state $s$
(or equivalently, the number of paths of length $mn+y$ in the augmented
border state graph from the all-edge state to $s$).
Call a $y$-state $s$ {\em legal} if $y=0$ and $s$ has no libertyless stones.
\end{defin}
Obviously, we have
\begin{lemma}[color symmetry]
\label{color-symmetry}
Let state $s'$ be derived from state $s$ by reversing the colors
of all stones. Then $L(m,n,y,s) = L(m,n,y,s')$.
\end{lemma}
\begin{defin}[state classes]
We define a {\em state class}, denoted $[s]$, as the equivalence class
of state $s$ under color reversal.
Call a state class {\em legal} when its members are,
and define $L(m,n,y,[s]) = \sum_{s' \in [s]} L(m,n,y,s')$.
\end{defin}
Note that all equivalence classes, except for stoneless states,
consist of exactly 2 states.
These definitions immediately imply
\begin{lemma}
$L(m,n) = \sum_{\mbox{legal }s} L(m,n,0,s)
= \sum_{\mbox{legal }[s]} L(m,n,0,[s])$.
\label{legal-states}
\end{lemma}
Another form of symmetry occurs in $0$-states only:
\begin{lemma}[up-down symmetry]
\label{up-down-symmetry}
Let state $s'$ be derived from $0$-state $s$ by
reversing the order of points from top to bottom.
Then $L(m,n,y,s) = L(m,n,y,s')$ and $L(m,n,y,[s]) = L(m,n,y,[s'])$.
\end{lemma}
\begin{defin}[state count vector]
Denote by $\BFL(m,n,y)$ the state-indexed vector with elements
$L(m,n,y,s)$ for all constructible $y$-states $s$ (edge states for $n=0$,
border states for $n>0$) and by $\BFl_m$ the
characteristic vector of legal states of height $m$.
\end{defin}
Now Lemma~\ref{legal-states} can be expressed as
\[L(m,n) = \BFl_m^T \BFL(m,n,0).\]
The following crucial observation forms the basis for the recurrences
we derive.
Since $L(m,n,y+1,s)$ equals the sum of
$L(m,n,y,s')$ over all predecessor states $s'$ of $s$ in the augmented border
state graph, it follows that
the border state vectors $\BFL(m,n,y), n>0$ are related by linear
transformations $\BFT_{m,y}$, such that
$\BFL(m,n,y+1) = \BFT_{m,y} \BFL(m,n,y)$
(and $\BFL(m,n+1,0) = \BFT_{m,m-1} \BFL(m,n,m-1)$).
Indeed, the $\BFT_{m,y}$
appear as submatrices of the transposed adjacency matrix of
the border state graph.
As a consequence, successive $0$-state vectors are related as
\[ \BFL(m,n+1,0) = \BFT_{m,m-1} \BFT_{m,m-2} \dots
\BFT_{m,1} \BFT_{m,0} \BFL(m,n,0). \]
Thus we are led to define
\begin{defin}[Recurrence matrix]
Let $\BFT_m = \BFT_{m,m-1} \dots \BFT_{m,0}$.
%$\BFv_m(n)=\BFL(m,n,0)$, and $\BFv_m(0)=\BFT_m^{-1} \BFv_m(1)$.
\end{defin}
This leads to a matrix power expression for $L(m,n)$:
\[ L(m,n) = \BFl_m^T \BFT_m^{n-1} \BFL(m,1,0). \]
Furthermore, $L(m,n)$ can be shown to satisfy a recurrence not
involving the border state counts. To simplify the following
derivations, $m$ is understood to be fixed and is dropped from the
notation, so that $L(m,n) = \BFl^T \BFT^{n-1} \BFL(1,0)$.
\begin{theorem}
\label{recurrence}
For fixed $m$, $L(m,n)$ satisfies a linear recurrence
whose order is at most the number of valid $0$-states.
\end{theorem}
\begin{proof}
Let $p(\lambda)$ be the characteristic polynomial of the $r \times r$
matrix $\BFT$,
\[
p(\lambda) = \det (\lambda \mathbf{I} - \BFT) =
\lambda^r + a_{r-1} \lambda^{r-1} + \dots + a_1 \lambda + a_0.
\]
By the Cayley-Hamilton theorem, $p(\BFT) = \mathbf{0}$. It
follows that
\[
\BFT^r = -(a_{r-1}\BFT^{r-1} + \dots + a_1
\BFT + a_0 \mathbf{I})
\]
and by multiplication by $\BFT^{k-1}$ that
\[
\BFT^{r+k-1} = -(a_{r-1}\BFT^{r+k-2} + \dots +
a_1 \BFT^{k} + a_0 \BFT^{k-1})
\]
for all $k \geq 1$. Multiplying by
$\BFl^T$ on the left and $\BFL(1)$ on the right yields
\[
\begin{split}
L(m,k+r) &= \BFl^T \BFT^{r+k-1} \BFL(1,0) \\
&= -(a_{r-1} L(m,k+r-1) + \dots + a_1 L(m,k+1) + a_0 L(m,k))
\end{split}
\]
for all $k \geq 1$, proving the theorem.
\end{proof}
By expressing $\BFT$ in terms of state classes rather than states,
and modifying $\BFl^T$ and $\BFL(1,0)$ accordingly
(as illustrated in section \ref{1xn-boards}),
we obtain a stronger upperbound on the order, namely the number of valid
$0$-state classes as given in Table~\ref{borderstates}.
Finally, that bound may be nearly halved again by exploiting the up-down
symmetry of $0$-states.
The structure of solutions to linear recurrences
is well known~\cite{concretemath}.
Theorem~\ref{recurrence} implies
\begin{coro}
\label{explicit-form}
For fixed $m$, $L(m,n)$ can be written in the form
\[
L(m,n) = \sum_k q_k(n) l_k^n,
\]
where $l_k$ are the distinct eigenvalues of $\BFT$, and $q_k$ are
polynomials of degree at most $\mbox{multiplicity}(l_k)-1$.
\end{coro}
Notice that some of the terms may vanish but not the largest
eigenvalue, which we have additional information about. First a
technical lemma is needed.
\begin{lemma}
\label{jordan-lemma}
If $l_k \ne 0$ is an eigenvalue of $\BFT$ of multiplicity 1 with
corresponding left and right eigenvectors $\mathbf{e}^T$ and
$\mathbf{f}$ then $q_k$ is the constant $\frac{\BFl^T \mathbf{f}
\mathbf{e}^T \BFL(1,0)}{l_k}$.
\end{lemma}
\begin{proof}
Let $\BFT = \mathbf{V} \mathbf{J} \mathbf{V}^{-1}$ be the Jordan
canonical decomposition of $\BFT$. Thus $L(m,n) = \BFl^T \BFT^{n-1}
\BFL(1,0) = \BFl^T \mathbf{V} \mathbf{J}^{n-1} \mathbf{V}^{-1}
\BFL(1,0)$. Since $l_k$ has multiplicity one, it must have a single
corresponding Jordan block of size 1. Due to the structure of $J$
only this block can provide $l_k^n$ terms to $L(m,n)$, more
precisely $\BFl^T e l_k^{n-1} f^T \BFL(1,0)$
\end{proof}
\begin{theorem}
\label{mxn-asymptotics}
There exist $a_m>0$, $0<\lambda_m \leq 3^m$, and $0<\phi_m<1$ such that
\[ L(m,n)=a_m \lambda_m^n (1+r(m,n)) \]
with $r(m,n)=O(\phi_m^n)$.
\end{theorem}
\begin{proof}
By lemma \ref{connected-border-graph} it
follows that $\BFT$ is regular, i.e.\ $\BFT^k$ is (elementwise)
positive for some $k$. Since, by construction, $\BFT$ is also
non-negative, the Perron-Frobenius theorem guarantees the existence of a
real positive eigenvalue $l_1$ with the properties that it has
multiplicity one, is larger in magnitude than all other eigenvalues,
and has left and right eigenvectors $\mathbf{e}^T$ and $\mathbf{f}$
with all elements positive. From Lemma~\ref{jordan-lemma} it follows
that $q_1(n) = \frac{\BFl^T \mathbf{f} \mathbf{e}^T \BFL(1,0)}{l_k}$,
which is guaranteed to be a positive constant since $\BFl^T$ and
$\BFL(1,0)$ are non-negative and not all zero whereas $\mathbf{e}$ and
$\mathbf{f}$ are positive. Now $L(m,n) = q_1 l_1^n (1 + \sum_{k>1}
\frac{q_k(n)}{q_1} \frac{l_k}{l_1}^n)$ and the claimed result follows
(for any $\max_{k>1} \frac{|l_k|}{l_1}<\phi_m<1$). The upper bound on
$\lambda_m$ follows necessarily from the trivial upper bound
$L(m,n) \leq 3^{mn}$.
\end{proof}
The recursion coefficients are most easily obtained by
computing $L(m,n)$ for $n=1,\dots,2s$
by the dynamic programming algorithm in section
\ref{DP-algorithm}. Since we know that the sequence must satisfy
\emph{some} linear recurrence, the problem is reduced to determining the
minimal order and the corresponding coefficients. Moreover, we know
that the minimal order is upper-bounded by the number of valid state
classes $s$ given in Table~\ref{borderstates}.
\begin{lemma}
\label{coefficient-lemma}
Assume that the sequence $x(1), x(2), \dots$ satisfies the linear
recurrence
\[
x(k+r) = c_{r-1} x(k+r-1) + \dots + c_1 x(k+1) + c_0 x(k).
\]
Then the coefficients $c_i$ satisfy the equation system
\[
\begin{pmatrix}
x(1) & x(2) & \dots & x(r) \\
x(2) & x(3) & \dots & x(r+1) \\
\vdots & \vdots & \ddots & \vdots \\
x(r) & x(r+1) & \dots & x(2r-1) \\
\end{pmatrix}
\begin{pmatrix}
c_0 \\ c_1 \\ \vdots \\ c_{r-1}
\end{pmatrix} =
\begin{pmatrix}
x(r+1) \\ x(r+2) \\ \vdots \\ x(2r)
\end{pmatrix}.
\]
Furthermore, $r$ is the minimal order of recurrence iff
the above matrix is non-singular, in which case the coefficients
are uniquely determined.
\end{lemma}
As we do not know the minimal order of recurrence, we form
matrices for increasing $r$. For each non-singular one, we
compute the recurrence coefficients and verify the recurrence for
all $s$ elements $L(m,s+1)$ through $L(m,2s)$.
The smallest verifiable $r$ is the minimal order.
For efficient computations, the Berlekamp-Massey algorithm
\cite{B83} can be used together with modular arithmetic and the
Chinese Remainder Theorem.
\subsubsection{$1 \times n$ Boards}
\label{1xn-boards}
For one-dimensional boards, with $m=1$, Figure~\ref{onebordergraph} shows
the five possible border
states ``empty'', ``black with liberty'', ``white with liberty'',
``black without liberty'', and ``white without liberty''. The first
three are legal, so $\BFl = (1,1,1,0,0)^T$. The state count
transformation is given by the transposed adjacency matrix
\[
\BFT =
\begin{pmatrix}
1 & 1 & 1 & 1 & 1 \\
1 & 1 & 0 & 0 & 0 \\
1 & 0 & 1 & 0 & 0 \\
0 & 0 & 1 & 1 & 0 \\
0 & 1 & 0 & 0 & 1
\end{pmatrix}
\]
and the initial state count with one column gives $\BFL(1,0) = (1,0,0,1,1)^T$.
In this case $\BFT$ is invertible and we can write
$\BFL(0,0) = \BFT^{-1} \BFL(1,0) = (-1,1,1,0,0)^T$ and
\[
L(1,n) = \BFl^T \BFT^{n-1} \BFL(1,0)= \BFl^T \BFT^n \BFL(0,0) =
\]
\[
\begin{pmatrix}
1 & 1 & 1 & 0 & 0
\end{pmatrix}
\begin{pmatrix}
1 & 1 & 1 & 1 & 1 \\
1 & 1 & 0 & 0 & 0 \\
1 & 0 & 1 & 0 & 0 \\
0 & 0 & 1 & 1 & 0 \\
0 & 1 & 0 & 0 & 1
\end{pmatrix}^n
\begin{pmatrix}
-1 \\ 1 \\ 1 \\ 0 \\ 0
\end{pmatrix},
\]
which gives the sequence $1,5,15,41,113,313,867,2401,6649,18413,\dots$
The characteristic polynomial of $\BFT$ is
$p(\lambda)=\det(\lambda \mathbf{I} - \BFT) =
\lambda^5 - 5\lambda^4 + 8\lambda^3 - 6\lambda^2 + 3\lambda - 1$. It
follows that $L(1,n)$ satisfies the recurrence
\[
L(1,k+5) = 5 L(1,k+4) - 8 L(1,k+3) + 6 L(1,k+2) - 3 L(1,k+1) + L(1,k).
\]
This is not a minimal order recurrence, however. Using state classes
instead (empty, stone with liberty, or stone without liberty) yields
\begin{align*}
\BFl &=
\begin{pmatrix}
1 & 1 & 0
\end{pmatrix}^T, \\
\BFT &=
\begin{pmatrix}
1 & 1 & 1 \\
2 & 1 & 0 \\
0 & 1 & 1 \\
\end{pmatrix},\\
\BFL(1,0) &=
\begin{pmatrix}
1 & 0 & 2
\end{pmatrix}^T
\end{align*}
and a characteristic polynomial $p(\lambda) = \lambda^3 - 3 \lambda^2
+ \lambda - 1$, leading to the minimal recurrence
\[
L(1,k+3) = 3 L(1,k+2) - L(1,k+1) + L(1,k).
\]
These coefficients can also be computed directly from $L(1,1), \dots,
L(1,6)$ according to Lemma~\ref{coefficient-lemma} as
\[
\begin{pmatrix}
1 & 5 & 15 \\
5 & 15 & 41 \\
15 & 41 & 113
\end{pmatrix}^{-1}
\begin{pmatrix}
41 \\ 113 \\ 313
\end{pmatrix} =
\begin{pmatrix}
1 \\ -1 \\ 3
\end{pmatrix}.
\]
$L(1,n)$ can be written in the form of Corollary~\ref{explicit-form} as
\[
\begin{split}
L(1,n) &\sim 0.694 \cdot 2.769^n + (0.153 - 0.812 i) \cdot (0.115 + 0.590
i)^n + \\
&+ (0.153 + 0.812 i) \cdot (0.115 - 0.590 i)^n,
\end{split}
\]
where the constants involved are solutions to cubic equations. In
particular the largest eigenvalue can be written in closed form as
\[
\lambda_1 = 1 + \frac{1}{3} \left( (27+3\sqrt{57})^{\frac{1}{3}} +
(27-3\sqrt{57})^{\frac{1}{3}} \right) \sim 2.769292354.
\]
\subsubsection{$2 \times n$ up to $9 \times n$ Boards}
For $2 \times n$ boards, Table~\ref{borderstates} shows 9 state classes,
but up-down symmetry leaves an upper bound on the minimal recurrence order
of only 7, which turns out to be exact:
\[
\begin{split}
L(2,n+7) &= 10 L(2,n+6) - 16 L(2,n+5) + 31 L(2,n+4) -13 L(2,n+3) +
\\
&+ 20 L(2,n+2) + 2 L(2,n+1) - L(2,n).
\end{split}
\]
This sequence starts $1,5,57,489,4125,35117,299681,\ldots$.
For $3 \times n$ the number of constructible state classes is 31, which up-down
symmetry reduces to 21, but the minimal recurrence order is only 19:
\[
\begin{split}
L(3,n+19) &= 33 L(3,n+18) - 233 L(3,n+17) + 1171 L(3,n+16) - \\
&- 3750 L(3,n+15) + 9426 L(3,n+14) - 16646 L(3,n+13) + \\
&+ 22072 L(3,n+12) - 19993 L(3,n+11) + 9083 L(3,n+10) + \\
&+ 1766 L(3,n+9) - 4020 L(3,n+8) + 6018 L(3,n+7) - \\
&- 2490 L(3,n+6) - 5352 L(3,n+5) + 1014 L(3,n+4) - \\
&- 1402 L(3,n+3) + 100 L(3,n+2) + 73 L(3,n+1) - 5 L(3,n).
\end{split}
\]
%The first 19 terms are 1,15,489,12675,321689,8180343,208144601, 5296282323,
%134764135265, 3429075477543, 87252874774409, 2220150677358587,
%56491766630430761, 1437433832683612783, 36575525011037967769,
%930664771769562054147, 23680778803620700205625, 602557764897193682879119,
%15332091188757329557096929.
The recurrences for $m \geq 4$ are too long to show here. Minimal
orders and the $\lambda_m$ values from theorem \ref{mxn-asymptotics}
are listed in Table~\ref{small-board-recurrences} for $1 \leq m \leq 9$.
\begin{table}
\begin{center}
\begin{tabular}{|l|l|l|l|}
\hline
size & order & $a_m$ & $\lambda_m$ \\ \hline
$ 1 \times n$ & 3 & 0.69412340909080771809 & 2.76929235423863141524 \\ \hline
$ 2 \times n$ & 7 & 0.77605920648443217564 & 8.53365251207176310397 \\ \hline
$ 3 \times n$ & 19 & 0.76692462372625158688 & 25.44501470555814081494 \\ \hline
$ 4 \times n$ & 57 & 0.73972591465609392167 & 75.70934113501819973789 \\ \hline
$ 5 \times n$ & 217 & 0.71384057986002504205 & 225.28834590398701930674 \\ \hline