HeunG - Maple Programming Help

HeunG

The Heun general function

HeunGPrime

The derivative of the Heun general function

 Calling Sequence HeunG(a, q, $\mathrm{\alpha }$, $\mathrm{\beta }$, $\mathrm{\gamma }$, $\mathrm{\delta }$, z) HeunGPrime(a, q, $\mathrm{\alpha }$, $\mathrm{\beta }$, $\mathrm{\gamma }$, $\mathrm{\delta }$, z)

Parameters

 a - algebraic expression q - algebraic expression $\mathrm{\alpha }$ - algebraic expression $\mathrm{\beta }$ - algebraic expression $\mathrm{\gamma }$ - algebraic expression $\mathrm{\delta }$ - algebraic expression z - algebraic expression

Description

 • The HeunG function is the solution of the Heun General equation. Following the first reference (at the end), the equation and the conditions at the origin satisfied by HeunG are
 ${\mathrm{HeunG}}{}\left({a}{,}{q}{,}{\mathrm{α}}{,}{\mathrm{β}}{,}{\mathrm{γ}}{,}{\mathrm{δ}}{,}{z}\right){=}{\mathrm{DESol}}{}\left(\left\{\frac{{{ⅆ}}^{{2}}}{{ⅆ}{{z}}^{{2}}}{}{\mathrm{_Y}}{}\left({z}\right){-}\frac{\left(\left({\mathrm{α}}{+}{\mathrm{β}}{+}{1}\right){}{{z}}^{{2}}{+}\left(\left({-}{\mathrm{δ}}{-}{\mathrm{γ}}\right){}{a}{-}{\mathrm{α}}{+}{\mathrm{δ}}{-}{\mathrm{β}}{-}{1}\right){}{z}{+}{\mathrm{γ}}{}{a}\right){}\left(\frac{{ⅆ}}{{ⅆ}{z}}{}{\mathrm{_Y}}{}\left({z}\right)\right)}{{z}{}\left({z}{-}{1}\right){}\left({-}{z}{+}{a}\right)}{-}\frac{\left({\mathrm{α}}{}{\mathrm{β}}{}{z}{-}{q}\right){}{\mathrm{_Y}}{}\left({z}\right)}{{z}{}\left({z}{-}{1}\right){}\left({-}{z}{+}{a}\right)}\right\}{,}\left\{{\mathrm{_Y}}{}\left({z}\right)\right\}{,}\left\{{\mathrm{_Y}}{}\left({0}\right){=}{1}{,}{\mathrm{D}}{}\left({\mathrm{_Y}}\right){}\left({0}\right){=}\frac{{q}}{{\mathrm{γ}}{}{a}}\right\}\right)$ (1)
 Heun's equation is an extension of the 2F1 hypergeometric equation in that it is a second-order Fuchsian equation with four regular singular points. The 2F1 equation has three regular singularities. The HeunG function, thus, contains as particular cases all the functions of the hypergeometric 2F1 class.
 • Another important case of Heun's equation, for $\left\{q=-\frac{ah}{4},\mathrm{\alpha }=-\frac{\mathrm{\nu }}{2},\mathrm{\beta }=\frac{1}{2}+\frac{\mathrm{\nu }}{2},\mathrm{\delta }=\frac{1}{2},\mathrm{\gamma }=\frac{1}{2}\right\}$, is Lame's equation in algebraic form,
 > diff(y(z),z,z) + 1/2*(1/z + 1/(z-1) + 1/(z-a))*diff(y(z),z) + (a*h-nu*(nu+1)*z)/(4*z*(z-1)*(z-a))*y(z) = 0;
 $\frac{{{ⅆ}}^{{2}}}{{ⅆ}{{z}}^{{2}}}{}{y}{}\left({z}\right){+}\frac{{1}}{{2}}{}\left(\frac{{1}}{{z}}{+}\frac{{1}}{{z}{-}{1}}{+}\frac{{1}}{{z}{-}{a}}\right){}\left(\frac{{ⅆ}}{{ⅆ}{z}}{}{y}{}\left({z}\right)\right){+}\frac{{1}}{{4}}{}\frac{\left({a}{}{h}{-}{\mathrm{ν}}{}\left({1}{+}{\mathrm{ν}}\right){}{z}\right){}{y}{}\left({z}\right)}{{z}{}\left({z}{-}{1}\right){}\left({z}{-}{a}\right)}{=}{0}$ (2)
 where the parameter $\mathrm{\nu }$ is called the order of the equation and many special features arise when $\mathrm{\nu }$ is an integer. Lame's equation arises in the separation of variables in Laplace's equation.
 • The HeunG(a,q,$\mathrm{\alpha }$,$\mathrm{\beta }$,$\mathrm{\gamma }$,$\mathrm{\delta }$,z) function is a local (Frobenius) solution to Heun's equation, computed as a power series expansion around the origin, a regular singular point. The radius of convergence of this series is $\left|{z}_{s}\right|$ where ${z}_{s}$ is the location of the singularity closer to the origin, either a or 1. An analytic continuation of HeunG is obtained through identities, relating the values of the function in different regions, or by expanding the solution around the other singularities (a, 1 or $\mathrm{\infty }$). For example, the value of the function outside a circle of radius 2 is computable from the value of another HeunG function inside that circle using
 > HeunG(a,q,alpha,beta,gamma,delta,z) = (1-z)^(-alpha)*HeunG(a/(a-1),(-q+gamma*alpha*a)/(a-1),alpha,alpha-delta+1,gamma,alpha-beta+1,z/(z-1));
 ${\mathrm{HeunG}}{}\left({a}{,}{q}{,}{\mathrm{α}}{,}{\mathrm{β}}{,}{\mathrm{γ}}{,}{\mathrm{δ}}{,}{z}\right){=}{\left({1}{-}{z}\right)}^{{-}{\mathrm{α}}}{}{\mathrm{HeunG}}{}\left(\frac{{a}}{{a}{-}{1}}{,}\frac{{a}{}{\mathrm{α}}{}{\mathrm{γ}}{-}{q}}{{a}{-}{1}}{,}{\mathrm{α}}{,}{\mathrm{α}}{-}{\mathrm{δ}}{+}{1}{,}{\mathrm{γ}}{,}{\mathrm{α}}{-}{\mathrm{β}}{+}{1}{,}\frac{{z}}{{z}{-}{1}}\right)$ (3)
 • For certain values of the parameters, it can happen that the expansion around the origin is also a Frobenius solution around the next adjacent singularity, so the function is analytic in some domain including both singularities. In the literature, the term Heun function is sometimes reserved for these cases, important in physical applications.
 • A more special situation happens when the parameters entering HeunG are such that the function is, simultaneously, a Frobenius solution around three adjacent singularities and hence analytic in a domain containing all of them. In such a case the solution will also be a Frobenius solution around the fourth singularity and HeunG will be a polynomial. A necessary (not sufficient) condition for this case is that $\mathrm{\alpha }=-n$, with $n$ a positive integer, and $q$ has one of a finite number of characteristic values, in which case the function is a polynomial of degree $n$.

Examples

Heun's equation can be transformed into another version of itself, that is, an equation with four regular singularities three of which are located at $\left\{0,1,\mathrm{\infty }\right\}$, by any of 24 Mobius transformations $z$ -> $f\left(z\right)$ of the independent variable $z$; these forms of $f\left(z\right)$ are

 > $\mathrm{Matrix}\left(\left[\left[z,1-z,\frac{1}{z},\frac{1}{1-z}\right],\left[\frac{z}{z-1},\frac{z-1}{z},\frac{z}{a},\frac{a-z}{a}\right],\left[\frac{a}{z},\frac{a}{a-z},\frac{z}{z-a},\frac{z-a}{z}\right],\left[\frac{z-a}{1-a},\frac{z-1}{a-1},\frac{1-a}{z-a},\frac{a-1}{z-1}\right],\left[\frac{z-a}{z-1},\frac{z-1}{z-a},\frac{z-a}{a\left(z-1\right)},\frac{\left(a-1\right)z}{z-a}\right],\left[\frac{a\left(z-1\right)}{z-a},\frac{a\left(z-1\right)}{\left(a-1\right)z},\frac{z-a}{\left(1-a\right)z},\frac{\left(1-a\right)z}{z-a}\right]\right]\right)$
 $\left[\begin{array}{cccc}{z}& {1}{-}{z}& \frac{{1}}{{z}}& \frac{{1}}{{1}{-}{z}}\\ \frac{{z}}{{z}{-}{1}}& \frac{{z}{-}{1}}{{z}}& \frac{{z}}{{a}}& \frac{{a}{-}{z}}{{a}}\\ \frac{{a}}{{z}}& \frac{{a}}{{a}{-}{z}}& \frac{{z}}{{z}{-}{a}}& \frac{{z}{-}{a}}{{z}}\\ \frac{{z}{-}{a}}{{1}{-}{a}}& \frac{{z}{-}{1}}{{a}{-}{1}}& \frac{{1}{-}{a}}{{z}{-}{a}}& \frac{{a}{-}{1}}{{z}{-}{1}}\\ \frac{{z}{-}{a}}{{z}{-}{1}}& \frac{{z}{-}{1}}{{z}{-}{a}}& \frac{{z}{-}{a}}{{a}{}\left({z}{-}{1}\right)}& \frac{\left({a}{-}{1}\right){}{z}}{{z}{-}{a}}\\ \frac{{a}{}\left({z}{-}{1}\right)}{{z}{-}{a}}& \frac{{a}{}\left({z}{-}{1}\right)}{\left({a}{-}{1}\right){}{z}}& \frac{{z}{-}{a}}{\left({1}{-}{a}\right){}{z}}& \frac{\left({1}{-}{a}\right){}{z}}{{z}{-}{a}}\end{array}\right]$ (4)

Note that the location of the fourth singularity resulting from these transformations, say $\mathrm{\lambda }$, is in general different from $a$. The six possible values of $\mathrm{\lambda }$ are $\left\{a,\frac{1}{a},\frac{1}{1-a},\frac{a}{a-1},1-a\right\}$ and $\frac{a-1}{a}$.

Taking into account that Heun's equation has 4 regular singularities, that at around each one it is possible to construct 2 Frobenius solutions, and that there exist these 24 transformations mapping the equation into one of the same type, the solution to Heun's equation can be written in 192 different manners. This situation is equivalent to the one of the 2F1 hypergeometric equation, where instead of 4 there are 3 regular singularities, instead of 24 transformations there are only 6, and so the solution can be written in 24 different manners.

This group of transformations of order 24 admitted by Heun's equation also leads to a rather large number of identities for the function solution HeunG, among which you have

 > $\mathrm{FunctionAdvisor}\left(\mathrm{identities},\mathrm{HeunG}\right)$
 $\left[{\mathrm{HeunG}}{}\left({a}{,}{q}{,}{\mathrm{α}}{,}{\mathrm{β}}{,}{\mathrm{γ}}{,}{\mathrm{δ}}{,}{z}\right){=}{\left({1}{-}{z}\right)}^{{1}{-}{\mathrm{δ}}}{}{\mathrm{HeunG}}{}\left({a}{,}{q}{-}\left({\mathrm{δ}}{-}{1}\right){}{\mathrm{γ}}{}{a}{,}{\mathrm{β}}{-}{\mathrm{δ}}{+}{1}{,}{\mathrm{α}}{-}{\mathrm{δ}}{+}{1}{,}{\mathrm{γ}}{,}{2}{-}{\mathrm{δ}}{,}{z}\right){,}\left[{\mathrm{HeunG}}{}\left({a}{,}{q}{,}{\mathrm{α}}{,}{\mathrm{β}}{,}{\mathrm{γ}}{,}{\mathrm{δ}}{,}{z}\right){=}{\left({1}{-}\frac{{z}}{{a}}\right)}^{{-}{\mathrm{α}}{-}{\mathrm{β}}{+}{\mathrm{γ}}{+}{\mathrm{δ}}}{}{\mathrm{HeunG}}{}\left({a}{,}{q}{-}{\mathrm{γ}}{}\left({\mathrm{α}}{+}{\mathrm{β}}{-}{\mathrm{γ}}{-}{\mathrm{δ}}\right){,}{-}{\mathrm{β}}{+}{\mathrm{γ}}{+}{\mathrm{δ}}{,}{-}{\mathrm{α}}{+}{\mathrm{γ}}{+}{\mathrm{δ}}{,}{\mathrm{γ}}{,}{\mathrm{δ}}{,}{z}\right){,}{\mathrm{And}}{}\left({a}{\ne }{0}\right)\right]{,}\left[{\mathrm{HeunG}}{}\left({a}{,}{q}{,}{\mathrm{α}}{,}{\mathrm{β}}{,}{\mathrm{γ}}{,}{\mathrm{δ}}{,}{z}\right){=}{\left({1}{-}{z}\right)}^{{1}{-}{\mathrm{δ}}}{}{\left({1}{-}\frac{{z}}{{a}}\right)}^{{-}{\mathrm{α}}{-}{\mathrm{β}}{+}{\mathrm{γ}}{+}{\mathrm{δ}}}{}{\mathrm{HeunG}}{}\left({a}{,}{q}{-}{\mathrm{γ}}{}\left(\left({\mathrm{δ}}{-}{1}\right){}{a}{+}{\mathrm{α}}{+}{\mathrm{β}}{-}{\mathrm{γ}}{-}{\mathrm{δ}}\right){,}{-}{\mathrm{β}}{+}{\mathrm{γ}}{+}{1}{,}{-}{\mathrm{α}}{+}{\mathrm{γ}}{+}{1}{,}{\mathrm{γ}}{,}{2}{-}{\mathrm{δ}}{,}{z}\right){,}{\mathrm{And}}{}\left({a}{\ne }{0}\right)\right]{,}\left[{\mathrm{HeunG}}{}\left({a}{,}{q}{,}{\mathrm{α}}{,}{\mathrm{β}}{,}{\mathrm{γ}}{,}{\mathrm{δ}}{,}{z}\right){=}{\mathrm{HeunG}}{}\left(\frac{{1}}{{a}}{,}\frac{{q}}{{a}}{,}{\mathrm{α}}{,}{\mathrm{β}}{,}{\mathrm{γ}}{,}{\mathrm{α}}{+}{\mathrm{β}}{-}{\mathrm{γ}}{-}{\mathrm{δ}}{+}{1}{,}\frac{{z}}{{a}}\right){,}{\mathrm{And}}{}\left({a}{\ne }{0}\right)\right]{,}\left[{\mathrm{HeunG}}{}\left({a}{,}{q}{,}{\mathrm{α}}{,}{\mathrm{β}}{,}{\mathrm{γ}}{,}{\mathrm{δ}}{,}{z}\right){=}{\left({1}{-}{z}\right)}^{{-}{\mathrm{α}}}{}{\mathrm{HeunG}}{}\left(\frac{{a}}{{a}{-}{1}}{,}\frac{{a}{}{\mathrm{α}}{}{\mathrm{γ}}{-}{q}}{{a}{-}{1}}{,}{\mathrm{α}}{,}{\mathrm{α}}{-}{\mathrm{δ}}{+}{1}{,}{\mathrm{γ}}{,}{\mathrm{α}}{-}{\mathrm{β}}{+}{1}{,}\frac{{z}}{{z}{-}{1}}\right){,}{\mathrm{And}}{}\left({a}{\ne }{1}{,}{z}{\ne }{1}\right)\right]{,}\left[{\mathrm{HeunG}}{}\left({a}{,}{q}{,}{\mathrm{α}}{,}{\mathrm{β}}{,}{\mathrm{γ}}{,}{\mathrm{δ}}{,}{z}\right){=}{\left({1}{-}\frac{{z}}{{a}}\right)}^{{-}{\mathrm{α}}}{}{\mathrm{HeunG}}{}\left({1}{-}{a}{,}{\mathrm{α}}{}{\mathrm{γ}}{-}{q}{,}{\mathrm{α}}{,}{-}{\mathrm{β}}{+}{\mathrm{γ}}{+}{\mathrm{δ}}{,}{\mathrm{γ}}{,}{\mathrm{δ}}{,}\frac{\left({1}{-}{a}\right){}{z}}{{z}{-}{a}}\right){,}{\mathrm{And}}{}\left({a}{\ne }{0}{,}{z}{\ne }{a}\right)\right]{,}\left[{\mathrm{HeunG}}{}\left({a}{,}{q}{,}{\mathrm{α}}{,}{\mathrm{β}}{,}{\mathrm{γ}}{,}{\mathrm{δ}}{,}{z}\right){=}{\left({1}{-}\frac{{z}}{{a}}\right)}^{{-}{\mathrm{α}}}{}{\mathrm{HeunG}}{}\left(\frac{{1}}{{1}{-}{a}}{,}\frac{{-}{\mathrm{α}}{}{\mathrm{γ}}{+}{q}}{{a}{-}{1}}{,}{\mathrm{α}}{,}{-}{\mathrm{β}}{+}{\mathrm{γ}}{+}{\mathrm{δ}}{,}{\mathrm{γ}}{,}{\mathrm{α}}{-}{\mathrm{β}}{+}{1}{,}\frac{{z}}{{z}{-}{a}}\right){,}{\mathrm{And}}{}\left({a}{\ne }{0}{,}{a}{\ne }{1}{,}{z}{\ne }{a}\right)\right]\right]$ (5)

Some hypergeometric special cases of HeunG are

 > $\mathrm{FunctionAdvisor}\left(\mathrm{specialize},\mathrm{HeunG},\mathrm{hypergeom}\right)$
 $\left[{\mathrm{HeunG}}{}\left({a}{,}{q}{,}{\mathrm{α}}{,}{\mathrm{β}}{,}{\mathrm{γ}}{,}{\mathrm{δ}}{,}{z}\right){=}{\mathrm{hypergeom}}{}\left(\left[{\mathrm{α}}{,}{\mathrm{β}}\right]{,}\left[{\mathrm{α}}{-}{\mathrm{δ}}{+}{1}{+}{\mathrm{β}}\right]{,}{z}\right){,}{\mathrm{And}}{}\left({a}{=}{0}{,}{q}{=}{0}\right)\right]{,}\left[{\mathrm{HeunG}}{}\left({a}{,}{q}{,}{\mathrm{α}}{,}{\mathrm{β}}{,}{\mathrm{γ}}{,}{\mathrm{δ}}{,}{z}\right){=}{\mathrm{hypergeom}}{}\left(\left[{\mathrm{α}}{,}{\mathrm{β}}\right]{,}\left[{\mathrm{γ}}\right]{,}{z}\right){,}{\mathrm{And}}{}\left({a}{=}{1}{,}{q}{=}{\mathrm{α}}{}{\mathrm{β}}\right)\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{or}}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathrm{And}}{}\left({q}{=}{a}{}{\mathrm{α}}{}{\mathrm{β}}{,}{\mathrm{δ}}{=}{\mathrm{α}}{+}{\mathrm{β}}{-}{\mathrm{γ}}{+}{1}\right)\right]{,}\left[{\mathrm{HeunG}}{}\left({a}{,}{q}{,}{\mathrm{α}}{,}{\mathrm{β}}{,}{\mathrm{γ}}{,}{\mathrm{δ}}{,}{z}\right){=}\frac{{\mathrm{hypergeom}}{}\left(\left[\frac{{1}}{{2}}{}\sqrt{{\left({\mathrm{α}}{-}{\mathrm{β}}\right)}^{{2}}{-}{2}{}\left({\mathrm{α}}{+}{\mathrm{β}}\right){}{\mathrm{γ}}{+}{{\mathrm{γ}}}^{{2}}{+}{4}{}{q}}{+}\frac{{1}}{{2}}{}{\mathrm{γ}}{+}\frac{{1}}{{2}}{}{\mathrm{α}}{-}\frac{{1}}{{2}}{}{\mathrm{β}}{,}\frac{{1}}{{2}}{}\sqrt{{\left({\mathrm{α}}{-}{\mathrm{β}}\right)}^{{2}}{-}{2}{}\left({\mathrm{α}}{+}{\mathrm{β}}\right){}{\mathrm{γ}}{+}{{\mathrm{γ}}}^{{2}}{+}{4}{}{q}}{+}\frac{{1}}{{2}}{}{\mathrm{γ}}{-}\frac{{1}}{{2}}{}{\mathrm{α}}{+}\frac{{1}}{{2}}{}{\mathrm{β}}\right]{,}\left[{\mathrm{γ}}\right]{,}{z}\right)}{{\left({z}{-}{1}\right)}^{{-}\frac{{1}}{{2}}{}\sqrt{{\left({\mathrm{α}}{-}{\mathrm{β}}\right)}^{{2}}{-}{2}{}\left({\mathrm{α}}{+}{\mathrm{β}}\right){}{\mathrm{γ}}{+}{{\mathrm{γ}}}^{{2}}{+}{4}{}{q}}{-}\frac{{1}}{{2}}{}{\mathrm{γ}}{+}\frac{{1}}{{2}}{}{\mathrm{α}}{+}\frac{{1}}{{2}}{}{\mathrm{β}}}{}{{ⅇ}}^{{-}\frac{{1}}{{2}}{}{I}{}{\mathrm{π}}{}\left({-}\sqrt{{\left({\mathrm{α}}{-}{\mathrm{β}}\right)}^{{2}}{-}{2}{}\left({\mathrm{α}}{+}{\mathrm{β}}\right){}{\mathrm{γ}}{+}{{\mathrm{γ}}}^{{2}}{+}{4}{}{q}}{-}{\mathrm{γ}}{+}{\mathrm{α}}{+}{\mathrm{β}}\right)}}{,}{\mathrm{And}}{}\left({a}{=}{1}{,}{0}{\le }{\mathrm{ℑ}}{}\left({z}\right)\right)\right]{,}\left[{\mathrm{HeunG}}{}\left({a}{,}{q}{,}{\mathrm{α}}{,}{\mathrm{β}}{,}{\mathrm{γ}}{,}{\mathrm{δ}}{,}{z}\right){=}{\mathrm{hypergeom}}{}\left(\left[\frac{{1}}{{2}}{}{\mathrm{β}}{,}\frac{{1}}{{2}}{}{\mathrm{α}}\right]{,}\left[{\mathrm{γ}}\right]{,}{-}{z}{}\left({z}{-}{2}\right)\right){,}{\mathrm{And}}{}\left({a}{=}{2}{,}{q}{=}{\mathrm{α}}{}{\mathrm{β}}{,}{\mathrm{δ}}{=}{\mathrm{α}}{+}{\mathrm{β}}{-}{2}{}{\mathrm{γ}}{+}{1}{,}{-}{1}{<}{\mathrm{ℜ}}{}\left({z}\right){,}{\mathrm{ℜ}}{}\left({z}\right){<}{1}\right)\right]{,}\left[{\mathrm{HeunG}}{}\left({a}{,}{q}{,}{\mathrm{α}}{,}{\mathrm{β}}{,}{\mathrm{γ}}{,}{\mathrm{δ}}{,}{z}\right){=}{\mathrm{hypergeom}}{}\left(\left[\frac{{1}}{{3}}{}{\mathrm{β}}{,}\frac{{1}}{{3}}{}{\mathrm{α}}\right]{,}\left[\frac{{1}}{{2}}\right]{,}\frac{{1}}{{4}}{}{z}{}{\left({z}{-}{3}\right)}^{{2}}\right){,}{\mathrm{And}}{}\left({a}{=}{4}{,}{q}{=}{\mathrm{α}}{}{\mathrm{β}}{,}{\mathrm{γ}}{=}\frac{{1}}{{2}}{,}{\mathrm{δ}}{=}\frac{{2}}{{3}}{}{\mathrm{α}}{+}\frac{{2}}{{3}}{}{\mathrm{β}}{,}{-}{1}{<}{\mathrm{ℜ}}{}\left({z}\right){,}{\mathrm{ℜ}}{}\left({z}\right){<}{1}{,}{-}{\mathrm{π}}{<}{\mathrm{ℑ}}{}\left({z}\right){,}{\mathrm{ℑ}}{}\left({z}\right){<}{\mathrm{π}}\right)\right]$ (6)

When $\mathrm{\alpha }=-n$, with $n$ a positive integer, the $n$th + 1 coefficient in the series expansion is a polynomial in $q$ of order $n+1$. If $q$ is a root of that polynomial, that coefficient is zero and with it all the following ones, so the series truncates and HeunG is a polynomial. For example, for $\mathrm{\alpha }=-1$

 > $\mathrm{HG}≔\mathrm{HeunG}\left(a,q,-1,\mathrm{β},g,\mathrm{δ},z\right)$
 ${\mathrm{HG}}{:=}{\mathrm{HeunG}}{}\left({a}{,}{q}{,}{-}{1}{,}{\mathrm{β}}{,}{g}{,}{\mathrm{δ}}{,}{z}\right)$ (7)
 > $Q≔\mathrm{simplify}\left(\mathrm{series}\left(\mathrm{HG},z,3\right),\mathrm{size}\right)$
 ${Q}{:=}{1}{+}\frac{{q}}{{g}{}{a}}{}{z}{+}\frac{{1}}{{2}}{}\frac{{{q}}^{{2}}{+}\left(\left({g}{+}{\mathrm{δ}}\right){}{a}{-}{\mathrm{δ}}{+}{\mathrm{β}}\right){}{q}{+}{\mathrm{β}}{}{g}{}{a}}{{g}{}{{a}}^{{2}}{}\left({g}{+}{1}\right)}{}{{z}}^{{2}}{+}{\mathrm{O}}\left({{z}}^{{3}}\right)$ (8)

So the coefficient of ${z}^{2}$ is

 > $\mathrm{c2}≔\mathrm{coeff}\left(Q,z,2\right)$
 ${\mathrm{c2}}{:=}\frac{{1}}{{2}}{}\frac{{{q}}^{{2}}{+}\left(\left({g}{+}{\mathrm{δ}}\right){}{a}{-}{\mathrm{δ}}{+}{\mathrm{β}}\right){}{q}{+}{\mathrm{β}}{}{g}{}{a}}{{g}{}{{a}}^{{2}}{}\left({g}{+}{1}\right)}$ (9)

solving for $q$, requesting from solve to return using RootOf we have

 > $\mathrm{_EnvExplicit}≔\mathrm{false}$
 ${\mathrm{_EnvExplicit}}{:=}{\mathrm{false}}$ (10)
 > $q=\mathrm{solve}\left(\mathrm{c2},q\right)$
 ${q}{=}{\mathrm{RootOf}}{}\left({{\mathrm{_Z}}}^{{2}}{+}\left({a}{}{\mathrm{δ}}{+}{a}{}{g}{+}{\mathrm{β}}{-}{\mathrm{δ}}\right){}{\mathrm{_Z}}{+}{\mathrm{β}}{}{g}{}{a}\right)$ (11)

substituting in $\mathrm{HG}$ we have

 > $\mathrm{HG_polynomial}≔\mathrm{subs}\left(,\mathrm{HG}\right)$
 ${\mathrm{HG_polynomial}}{:=}{\mathrm{HeunG}}{}\left({a}{,}{\mathrm{RootOf}}{}\left({{\mathrm{_Z}}}^{{2}}{+}\left({a}{}{\mathrm{δ}}{+}{a}{}{g}{+}{\mathrm{β}}{-}{\mathrm{δ}}\right){}{\mathrm{_Z}}{+}{\mathrm{β}}{}{g}{}{a}\right){,}{-}{1}{,}{\mathrm{β}}{,}{g}{,}{\mathrm{δ}}{,}{z}\right)$ (12)

When the function admits a polynomial form, as is the case of $\mathrm{HG_polynomial}$ by construction, to obtain the actual polynomial of degree $n$ (in this case $n=1$) use

 > $\genfrac{}{}{0}{}{\phantom{\mathrm{HeunG}=\mathrm{HeunG}:-\mathrm{SpecialValues}:-\mathrm{Polynomial}}}{}\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}|\phantom{\rule[-0.0ex]{0.1em}{0.0ex}}\genfrac{}{}{0}{}{\phantom{}}{\mathrm{HeunG}=\mathrm{HeunG}:-\mathrm{SpecialValues}:-\mathrm{Polynomial}}$
 ${1}{+}\frac{{\mathrm{RootOf}}{}\left({{\mathrm{_Z}}}^{{2}}{+}\left({a}{}{\mathrm{δ}}{+}{a}{}{g}{+}{\mathrm{β}}{-}{\mathrm{δ}}\right){}{\mathrm{_Z}}{+}{\mathrm{β}}{}{g}{}{a}\right){}{z}}{{g}{}{a}}$ (13)

References

 Ronveaux, A. ed. Heun's Differential Equations. Oxford University Press, 1995.
 Slavyanov, S.Y., and Lay, W. Special Functions, A Unified Theory Based on Singularities. Oxford Mathematical Monographs, 2000.