==Derivation==
The algorithm computes not just ''G'' but a two-dimensional function
''G''(''N'') = ''g''(''M'', ''N'')
: <math>g(n,m) \text{ for }n=0,1,\cdots,N \text{ and }m=1,\cdots,M</math>.
Once the calculation ends the values we are interested in are found by
:<math> G(n) = g(n,M) \text{ for }n=0,1,\cdots,N</math>.
The definition of ''g'' and a recursive method of calculating it are as follows
\begin{align}
g(mn, nm) & = \sum_{n_1 + \cdot\cdot\cdotcdots + n_m = n} \prod_{i=1}^m f_i(n_iX_i)^{n_i} \\
& = \sum_{j=0}^n \sum_{(n_1 + \cdot\cdot\cdotcdots + n_{m-1}n_m = n-j,) n_m\wedge (n_m= j0)}^n \prod_{i=1}^m f_i( X_i)^{n_i} ) \\+
& = \sum_{j=0}^n f_m( j ) \sum_{n_1 + \cdot\cdot\cdotcdots + n_{m-1}n_m = n-j) \wedge (n_m>0)}^n \prod_{i=1}^{m-1} f_i( n_i X_i)^{n_i} \\
& = \sum_{j=0}^g(n f_m( j ,m-1)+X_m g( mn-1, n-j m)
\end{align}
</math>
Also
: <math>g(m, 0) = 1\,</math> ▼
: <math>g( 1n, n1) = f_1( X_1)^n )\ text{ for }n=0,1,\cdots, N</math> ▼
to avoid affecting the product.
and
▲: <math>g(1, n) = f_1( n )\,</math>
▲: <math>g( m0, 0m) = 1 \text{ for }m=1,2,\ cdots, M</math>
This recursive relationship allows for the calculation of all ''G''(''N'') up to any value of ''N'' in [[Big O notation|order]] O(''MN''<sup>2</sup>) time.
There is a more efficient algorithm for finding ''G''(''N''') for some network. If it is assumed that <math>f_{i>1}( n ) = c_iy_i^n</math>, then the recursive relationship can be simplified as follows:
: <math>
\begin{align}
g(m,n) & = \sum_{j=0}^n f_m( j ) g( m-1, n-j ) \\
& = f_m( 0 ) g( m-1, n ) + \sum_{j=1}^n f_m( j ) g( m-1, n-j ) \\
& = f_m( 0 ) g( m-1, n ) + y_m \sum_{j=1}^{n-1} f_m( j ) g( m-1, n-1-j) \\
& = f_m( 0 ) g( m-1, n ) + y_m g( m, n-1 )
\end{align}
</math>
This simpler recursive relationship allows for the calculation of all ''G''(''N'') up to any value of ''N'' toin be[[Big found inO notation|order]] O(''MN'') time.
==Implementation==
|