The gfun package
Gfun is a Maple package that provides tools for discovering and manipulating generating
functions and holonomic sequences in one variable. It is intended chiefly for
work with sequences, power series, linear recurrences with polynomial
coefficients, and linear differential equations with polynomial coefficients.
The package follows a simple principle: a recurrence or a differential
equation, together with enough initial conditions, is an exact and effective
representation of its solution. Such representations can be converted,
combined, and used to compute coefficients without first looking for a closed
form. Conversely, when only the first terms of a sequence or series are known,
gfun can search for a plausible recurrence, differential equation, algebraic
equation, rational function, or hypergeometric description.
The name reflects the package’s original motivation in enumerative combinatorics, but the algorithms apply more generally to univariate D-finite (holonomic) functions and P-recursive sequences.
Latest version
For ordinary use, download the archive from:
gfun 5.0 (August 2026).
and unpack it in a convenient location. If that location is gfun_path, add it
to Maple’s library search path before loading the package:
libname := "/absolute/path/to/gfun", libname:
with(gfun):
Be careful: the new path should appear before that of Maple’s library, otherwise the version of gfun shipped with Maple will be used. (See the help page of libname for more information). It is convenient to add that line to your .mapleinit file (creating it if it does not exist) so that Maple will find the correct version of gfun in your future sessions.
You can then check that the installation worked by asking gfun:-version; This command should return the number above. (You may have to restart Maple for your changes to be taken into account.)
The public source repository is hosted on Inria GitLab. If you only want to use the package, then it’s better to download it with the link above.
Main facilities
- Guessing from data. The
listto*andseriesto*commands search for recurrences, differential equations, algebraic equations, rational functions, and hypergeometric forms.guessgf,guessode,guessrelation,hermite_pade, andapproximantbasisprovide more general entry points. - Exact conversions. Commands such as
algeqtodiffeq,diffeqtorec, andrectodiffeqmove between algebraic equations, differential equations, and recurrences. - Closure operations. The package computes equations for sums, products, Cauchy products, Hadamard products, algebraic substitutions, and Borel or inverse Borel transforms.
- Coefficient extraction.
diffeqtolist,diffeqtoseries,rectolist,rectoseries, andrectoproccompute terms or turn a recurrence into an efficient Maple procedure. - Structural questions.
minimizediffeqcomputes a minimal-order differential equation for a specified solution, whileistranscendentalcan certify transcendence in cases covered by its algorithm. - Subpackages.
NumGfunsupports numerical and analytic computation with D-finite functions, andContFracprovides tools for continued fractions.
Ordinary generating functions (ogf) are the default in most guessing
commands. Exponential and other generating-function types are also supported;
see gftypes.
Recent changes
Changes in 5.0
That version is a major revision of the package with the help of ChatGPT. There are many many changes, documented in the corresponding help page on the updates.
Minimization of linear differential equations
Given a linear differential equation with polynomial coefficients and initial conditions specifying a unique power series solution, the function minimizediffeq (available in versions of gfun ≥ 3.96) computes a linear differential equation of minimal order that has this power series as a solution. When the input equation is returned, it has thus been certified to be minimal. See the references at the bottom of this page.
A Maple worksheet of examples is available in mw and pdf.
Several properties of a function can be deduced from the minimal differential equation it satisfies.
istranscendental
The function istranscendental takes as input a solution of a linear differential equation specified by an equation and initial conditions and returns a proof that the solution is transcendental, giving a property of the minimal differential equation that allows to detect transcendence. See the references at the bottom of this page.
A Maple worksheet of examples is available in mw and pdf. (An extra file of data is needed to execute the worksheet.)
algvalues
The function algvalues computes the algebraic values taken by an E-function at algebraic points. It is not part of gfun but can be downloaded here. A worksheet includes the examples given in the article mentioned above can be downloaded in mw and pdf.
Help pages
The package installs its documentation in Maple’s help system. The main entry points are
?gfun
?gfun[listtorec]
?gfun[diffeqtorec]
?gfun[algeqtodiffeq]
?gfun[rectoproc]
The help pages are also available as html pages. Here are the pages corresponding to the three help pages above: gfun, listtorec, diffeqtorec, algeqtodiffeq, rectoproc.
Most commands may be called either after with(gfun) or in the long form
gfun[command](...). Setting infolevel[gfun] to a value from 1 to 5 displays
progressively more information about a computation.
Examples
Guessing a recurrence
The first Catalan numbers suffice to recover their familiar first-order recurrence:
with(gfun):
terms := [seq(binomial(2*n,n)/(n+1), n=0..11)]:
rec := listtorec(terms, u(n));
Maple returns
{(-4*n-2)*u(n) + (n+2)*u(n+1), u(0)=1}
Thus the proposed recurrence is
(n+2) u(n+1) = 2(2n+1) u(n), u(0) = 1.
As always with guessing from finite data, this is a conjecture suggested by
the supplied terms, not a proof. In a research computation, one should retain
terms for validation and then prove the resulting equation independently.
Search bounds and validation are controlled by the options described in
?gfun[Parameters].
Passing from a differential equation to coefficients
For the solution of
(1-z)y'(z)-y(z)=0, y(0)=1, one may derive a recurrence and then generate
coefficients from it:
deq := {(1-z)*diff(y(z),z)-y(z)=0, y(0)=1}:
rec := diffeqtorec(deq, y(z), u(n));
# {-u(n)+u(n+1), u(0)=1}
rectolist(rec, u(n), 7);
# [1, 1, 1, 1, 1, 1, 1, 1]
Here the equation is used as an exact data structure: no guessing is involved.
Starting from an algebraic generating function
The Catalan generating function is the branch at the origin defined by
y=1+z*y^2. It can be converted to a differential equation and expanded:
deq := algeqtodiffeq(y=1+z*y^2, y(z)):
diffeqtoseries(deq, y(z), 7);
which gives
1 + z + 2*z^2 + 5*z^3 + 14*z^4 + 42*z^5
+ 132*z^6 + 429*z^7 + O(z^8)
References
The primary reference to use when citing gfun is the following one:
B. Salvy and P. Zimmermann, “Gfun: a Maple package for the manipulation of generating and holonomic functions in one variable,” ACM Transactions on Mathematical Software, vol. 20, no. 2, pp. 163–177, 1994.
The minimization algorithm is described in
A. Bostan, T. Rivoal, and B. Salvy, “Minimization of differential equations and algebraic values of E-functions,” Mathematics of Computation, vol. 93, no. 347, pp. 1427–1472, 2024.
The transcendence test is described in
A. Bostan, B. Salvy, and M. F. Singer, “On deciding transcendence of power series,” arXiv, 2025.
If you are using the NumGfun subpackage, then the proper reference is:
M. Mezzarobba, “NumGfun: a Package for Numerical and Analytic Computation with D-finite Functions,” in Proceedings of the 2010 International Symposium on Symbolic and Algebraic Computation (ISSAC 2010), 2010, pp. 139–145.
Articles citing gfun
There are many of them. I used to maintain a list, but it is much easier to point directly to the corresponding page on Google Scholar.