I am surprised I understood it.

]]>Regarding the “mathematical theory”, I find it’s easiest to rephrase the problem as a graph problem. For a given M, we have a finite graph (representing all DP states) with weighted directed edges, and a Start/End node. The problem bcomes “what is the highest sum of weights for a path of length N from Start to End”; the challenge is to prove that this will eventually be periodic, since all paths will eventually be dominated by the highest-ratio cycle (the “densest pattern”). Technically, for the proof, you also need the condition that the graph doesn’t end up periodically oscillating between multiple different behaviors (similar to how a Markov Chain usually converges to a stable distribution unless it oscillates), but in this case the edge End -> End exists, which makes that impossible.

To compute results in practice, it’s not too useful to compute a theoretical limit to the period, because that can be very high – I think it’s potentially (max edge weight) * (num of nodes)^2 if you have a 2nd-best-ratio cycle that is only dominated by the highest-ratio cycle after a long time. Instead, my search program can just observe when the cycle starts, because all the states of the DP have values that are just a constant added to all the states of the DP X turns ago. For a problem like this, the cycle (fortunately) occurs much faster than the theoretical limit.

]]>