Let Svec denote [S0, S1, ..., s]. Layer[N] consists of two functions: layer[N].count(c,Svec) computes the number of S sequence entries covered by the Nth-order S-group (s, c), and layer[N].inc(c,Svec) computes the sum to be added to the R value by the same. The first equation that defines the pattern for incrementing the S-group order seems to be:
layer[N+1].count(c,Svec) = layer[N].inc(c,Svec')
where
Svec' = [S0, S1-1, S2, ..., s]
In seq3_covered >>36 this shows up as
seq3_covered(s, c) = seq2_inc(s - 1, c)
where seq2_inc is called seq3_sum1sc. In seq4_covered >>67 it shows up directly as the first component of seq3_inc (s, c, S1 - 1). It appears this will hold for all higher S-groups. What remains is to derive layer[N+1].inc(c,Svec). I have some ideas that way as well.