Here's a useful exercise.
Let's make this problem simpler by developing rewriting rules for normal play, first.
In normal play, all positions ultimately reduce to nim heaps.
At least this way we can test out how Mathematica simplification logic works in a simpler example.
![[Graphics:../Images/index_gr_24.gif]](../Images/index_gr_24.gif)
![[Graphics:../Images/index_gr_26.gif]](../Images/index_gr_26.gif)
A recursive definition of the Mex function:
![[Graphics:../Images/index_gr_27.gif]](../Images/index_gr_27.gif)
The addition rule for normal play nim heaps is simple:
![[Graphics:../Images/index_gr_28.gif]](../Images/index_gr_28.gif)
![[Graphics:../Images/index_gr_29.gif]](../Images/index_gr_29.gif)
Whenever an expression is of the form NormalGame[n[i],n[j],...] with only n[i] expressions at the top level inside the NormalGame expression, we want it to be replaced by the mex of i, j, etc. )
![[Graphics:../Images/index_gr_30.gif]](../Images/index_gr_30.gif)
![[Graphics:../Images/index_gr_31.gif]](../Images/index_gr_31.gif)
![[Graphics:../Images/index_gr_32.gif]](../Images/index_gr_32.gif)
![[Graphics:../Images/index_gr_34.gif]](../Images/index_gr_34.gif)
![[Graphics:../Images/index_gr_36.gif]](../Images/index_gr_36.gif)
That was pretty successful, at least in that we've codified nim heap addition, the mex rule, and 2x term simplification fix in three rules. Next, we would like to extend this to something that works directly off the octal code definition.
We need to fix several aspects of this when we move to misere play
1) only one call to the inefficient mzMoves function, please.
2) no exponential expansion of definitions without simplification.
2a) we want the top level expansion to just be a syntactic wrapper around summations
3) we want caching to work properly.
![[Graphics:../Images/index_gr_38.gif]](../Images/index_gr_38.gif)
![[Graphics:../Images/index_gr_39.gif]](../Images/index_gr_39.gif)
![[Graphics:../Images/index_gr_40.gif]](../Images/index_gr_40.gif)
Now calculate nim values for normal play Kayles, as a test. First initialize.
![[Graphics:../Images/index_gr_41.gif]](../Images/index_gr_41.gif)
![[Graphics:../Images/index_gr_42.gif]](../Images/index_gr_42.gif)
![[Graphics:../Images/index_gr_44.gif]](../Images/index_gr_44.gif)