Integral of GeneratingFunction - Mathematica Stack Exchange most recent 30 from mathematica.stackexchange.com 2019-09-20T17:37:27Z https://mathematica.stackexchange.com/feeds/question/31539 https://creativecommons.org/licenses/by-sa/4.0/rdf https://mathematica.stackexchange.com/q/31539 3 Integral of GeneratingFunction Eckhard https://mathematica.stackexchange.com/users/9146 2013-09-02T17:37:53Z 2015-08-17T13:52:26Z <p>I know that GeneratingFunction can be used to compute the generating function $\sum_{n=0}^\infty a_n x^n$ of a sequence $(a_n)_n$ via</p> <pre><code>GeneratingFunction[a[n],n,x] </code></pre> <p>I also know that polynomial (in $n$) coefficients of the general term $a_n$ of the sequence result in an expression involving derivatives of the generating function, e.g.</p> <pre><code>GeneratingFunction[n a[n],n,x] (* x (GeneratingFunction^(0,0,1))[a[n],n,x] *) </code></pre> <p>This does not seem to happen with rational (in $n$) coefficients, which would lead to indefinite integrals of the generating function. For example I would expect the input</p> <pre><code>GeneratingFunction[a[n]/(n + 1), n, x] </code></pre> <p>to result in </p> <pre><code>(*1/x Integrate[GeneratingFunction[a[n],n,y],{y,0,x}]*) </code></pre> <p>or</p> <pre><code>(*1/x GeneratingFunction^(0,0,-1))[a[n],n,x]*) </code></pre> <p>but this does not seem to be the case.</p> <p><strong>I thus have the following question:</strong> Is it possible to get Mathematica to compute the generating function of a linear combination of lagged values of $a_n$ with rational (in $n$) coefficients in terms of derivatives and integrals of the generating function of the sequence $(a_n)_n$?</p> https://mathematica.stackexchange.com/questions/31539/-/32611#32611 3 Answer by Andrew for Integral of GeneratingFunction Andrew https://mathematica.stackexchange.com/users/208 2013-09-19T01:29:48Z 2013-09-19T01:29:48Z <p>In this answer, I handle coefficients of the form </p> <p>$$\frac{p(n)}{q(n)},$$</p> <p>where $p(n)$ and $q(n)$ are polynomials in the index symbol $n$, $\deg(p(n)) &lt; \deg(q(n))$, and all of the roots of $q(n)$ are negative integers. If $\deg(p(n)) \geq \deg(q(n))$, we may have to differentiate a power series, and as I mentioned in my comment, <em>Mathematica</em> 9 doesn't handle that conveniently. If $q(n)$ has positive integer roots, we have to handle undefined expressions and things are more complicated.</p> <p>First, some setup code</p> <pre><code>(* http://mathematica.stackexchange.com/questions/32531/how-to-unprotect-generatingfunction *) GeneratingFunction; protected = Unprotect[GeneratingFunction]; (* what can usually be used as a variable, according to ref/message/General/ivar *) variablePattern = Except[_String | _?NumberQ | _Plus | _Times | _Sum | _Product | _^_Integer]; arg2 = Sequence[n:variablePattern, x:variablePattern]; </code></pre> <p>Now, we add a downvalue for <code>GeneratingFunction</code> which expands $p(n)/q(n)$ into partial fractions.</p> <pre><code>GeneratingFunction[expr_, arg2, opts:OptionsPattern[]] /; expr =!= Apart[expr, n] := GeneratingFunction[Apart[expr, n], n, x, opts]; </code></pre> <p>I will assume that the coefficients are now in the form</p> <p>$$\frac{c}{(n + k)^j}.$$</p> <p>To go from here, in the next rule we add a downvalue saying </p> <p>$$\sum_{n \geq 0} \frac{1}{n+k} f(n) x^n = x^{-k} \int_0^x t^{k-1} \left( \sum_{n \geq 0} f(n) t^n \right) dt,$$</p> <p>which gets used repeatedly until $j=0$.</p> <pre><code>GeneratingFunction[expr_ * (n_ + k_?Positive)^(j_?Negative), arg2, opts:OptionsPattern[]] := With[ {t = Unique[]}, x^(-k) * Integrate[t^(k-1) * GeneratingFunction[expr * (n + k)^(j + 1), n, t, opts], {t, 0, x}] ]; </code></pre> <p>And we're done.</p> <pre><code>Protect[Evaluate[protected]]; </code></pre>