MathematicalFunctions[Evalf]

 numerically evaluate a formula depending on a parameter n, or two of them n and m, adding from n = 0, also from m = 0 if there are two parameters, until the result converges for the current value of Digits

Parameters

 formula_procedure - procedure depending on one or two parameters - say $n$ or $n$ and $m$ - such that when they assume non-negative values the formula can be numerically evaluated N - (optional) range of non-negative integers, or just a non-negative integer, indicating the summation range or the upper limit of a sum that starts at $0$, for one or the two parameters $n$ and $m$. The default is infinity.

Description

 • The Add command is used to numerically add a formula, that is passed as a procedure that depends on a single non-negative integer parameter, say $n$, a summation index, or two of them, say $n$ and $m$. The summation over these parameters starts at 0 and is performed until the result converges (up to Digits). If the formula does not converge, the sum is interrupted when the number of terms added reaches $10000\mathrm{Digits}$, in which case a WARNING message explaining the situation is displayed on the screen.
 • When a second argument $N$ is passed, if it is a non-negative integer, the summation, that starts at $n=0$, or $n=0$ and $m=0$ in the case of two parameters, is performed until the result converges (up to Digits) or $n=N$. This second argument can also be passed as a range, say ${n}_{0}..{n}_{f}$, in which case the summation will start at ${n}_{0}$ until the result converges or ${n}_{f}$ terms were added.
 • The case of two parameters $n$ and $m$ is handled by rewriting the double sum from 0 to $\mathrm{\infty }$ as a single sum in only one parameter $k$ from 0 to $\mathrm{\infty }$ according to

${\sum }_{n=0}^{\mathrm{\infty }}\phantom{\rule[-0.0ex]{0.4em}{0.0ex}}{\sum }_{m=0}^{\mathrm{\infty }}f\left(m,n\right)={\sum }_{k=0}^{\mathrm{\infty }}\left(\left({\sum }_{m=0}^{k}f\left(k,m\right)\right)+\left({\sum }_{n=0}^{k-1}f\left(n,k\right)\right)\right)$

 • Add uses option hfloat, which means that, depending on the mathematical contents of the formula_procedure passed, the numerical evaluation will be performed using hardware floating-point values. Depending on the operations performed, this can significantly speed up the execution of the procedure.
 • Add is mainly useful to numerically evaluate mathematical expressions or functions that can be represented as an infinite sum. In these cases, with Add you can do:
 – a fast implementation of a numerical evaluation procedure for the expression (see the Examples section);
 – fast experimentation with different formulas, for instance comparing their performance for numerically evaluating the expression.

Examples

 Initialization: Load the package and set the display of special functions in output to typeset mathematical notation (textbook notation):
 > $\mathrm{with}\left(\mathrm{MathematicalFunctions}:-\mathrm{Evalf}\right);\mathrm{Typesetting}:-\mathrm{EnableTypesetRule}\left(\mathrm{Typesetting}:-\mathrm{SpecialFunctionRules}\right):$
 $\left\{{\mathrm{Add}}{,}{\mathrm{Evalb}}{,}{\mathrm{Zoom}}{,}{\mathrm{QuadrantNumbers}}{,}{\mathrm{Singularities}}{,}{\mathrm{GenerateRecurrence}}{,}{\mathrm{PairwiseSummation}}\right\}$ (1)

Basically all mathematical functions can be represented by a infinite sum. You can query about this sum form of a mathematical function using the FunctionAdvisor. As an example, consider the infinite sum representation for the spherical harmonic SphericalY function

 >
 * Partial match of "sum" against topic "sum_form".
 $\left[{{Y}}_{{\mathrm{\lambda }}}^{{\mathrm{\mu }}}{}\left({\mathrm{\theta }}{,}{\mathrm{\phi }}\right){=}\frac{{\left({-1}\right)}^{{\mathrm{\mu }}}{}\sqrt{\frac{{2}{}{\mathrm{\lambda }}{+}{1}}{{\mathrm{\pi }}}}{}\sqrt{\left({\mathrm{\lambda }}{-}{\mathrm{\mu }}\right){!}}{}{{ⅇ}}^{{I}{}{\mathrm{\phi }}{}{\mathrm{\mu }}}{}{\left({\mathrm{cos}}{}\left({\mathrm{\theta }}\right){+}{1}\right)}^{\frac{{\mathrm{\mu }}}{{2}}}{}\left({\sum }_{{\mathrm{_k1}}{=}{0}}^{{\mathrm{\infty }}}{}\frac{{\left({-}{\mathrm{\lambda }}\right)}_{{\mathrm{_k1}}}{}{\left({\mathrm{\lambda }}{+}{1}\right)}_{{\mathrm{_k1}}}{}{\left(\frac{{1}}{{2}}{-}\frac{{\mathrm{cos}}{}\left({\mathrm{\theta }}\right)}{{2}}\right)}^{{\mathrm{_k1}}}}{{\mathrm{_k1}}{!}{}{\left({1}{-}{\mathrm{\mu }}\right)}_{{\mathrm{_k1}}}}\right)}{{2}{}\sqrt{\left({\mathrm{\lambda }}{+}{\mathrm{\mu }}\right){!}}{}{\left({\mathrm{cos}}{}\left({\mathrm{\theta }}\right){-}{1}\right)}^{\frac{{\mathrm{\mu }}}{{2}}}{}{\mathrm{\Gamma }}{}\left({1}{-}{\mathrm{\mu }}\right)}{,}{¬}\left({\mathrm{\lambda }}{+}{\mathrm{\mu }}\right){::}{'}{\mathrm{negint}}{'}{\wedge }{¬}\left({\mathrm{\lambda }}{-}{\mathrm{\mu }}\right){::}{'}{\mathrm{negint}}{'}{\wedge }{¬}\left({1}{-}{\mathrm{\mu }}\right){::}{'}{\mathrm{nonposint}}{'}\right]$ (2)

How could we use this formula to numerically evaluate the function, for example for $\left[\mathrm{\lambda }=\frac{1}{2},\mathrm{\mu }=\frac{3}{2}+I,\mathrm{\phi }=\frac{\mathrm{\pi }}{7},\mathrm{\theta }=\frac{1}{3}+\frac{I}{5}\right]$? First put all the operands within the summation

 > $\mathrm{combine}\left(\mathrm{op}\left(1,\right)\right)$
 ${{Y}}_{{\mathrm{\lambda }}}^{{\mathrm{\mu }}}{}\left({\mathrm{\theta }}{,}{\mathrm{\phi }}\right){=}{\sum }_{{\mathrm{_k1}}{=}{0}}^{{\mathrm{\infty }}}{}\frac{\sqrt{\left({\mathrm{\lambda }}{-}{\mathrm{\mu }}\right){!}}{}{\left({\mathrm{cos}}{}\left({\mathrm{\theta }}\right){+}{1}\right)}^{\frac{{\mathrm{\mu }}}{{2}}}{}{\left({\mathrm{cos}}{}\left({\mathrm{\theta }}\right){-}{1}\right)}^{{-}\frac{{\mathrm{\mu }}}{{2}}}{}\sqrt{\frac{{2}{}{\mathrm{\lambda }}{+}{1}}{{\mathrm{\pi }}}}{}{{ⅇ}}^{{I}{}{\mathrm{\phi }}{}{\mathrm{\mu }}}{}{\left({-1}\right)}^{{\mathrm{\mu }}}{}{\left({-}{\mathrm{\lambda }}\right)}_{{\mathrm{_k1}}}{}{\left({\mathrm{\lambda }}{+}{1}\right)}_{{\mathrm{_k1}}}{}{\left(\frac{{1}}{{2}}{-}\frac{{\mathrm{cos}}{}\left({\mathrm{\theta }}\right)}{{2}}\right)}^{{\mathrm{_k1}}}}{{2}{}\sqrt{\left({\mathrm{\lambda }}{+}{\mathrm{\mu }}\right){!}}{}{\mathrm{\Gamma }}{}\left({1}{-}{\mathrm{\mu }}\right){}{\mathrm{_k1}}{!}{}{\left({1}{-}{\mathrm{\mu }}\right)}_{{\mathrm{_k1}}}}$ (3)

Take now the summand and substitute in it the values for the function's parameters indicated

 > $\mathrm{summand}≔\mathrm{op}\left(1,\mathrm{rhs}\left(\right)\right)$
 ${\mathrm{summand}}{≔}\frac{\sqrt{\left({\mathrm{\lambda }}{-}{\mathrm{\mu }}\right){!}}{}{\left({\mathrm{cos}}{}\left({\mathrm{\theta }}\right){+}{1}\right)}^{\frac{{\mathrm{\mu }}}{{2}}}{}{\left({\mathrm{cos}}{}\left({\mathrm{\theta }}\right){-}{1}\right)}^{{-}\frac{{\mathrm{\mu }}}{{2}}}{}\sqrt{\frac{{2}{}{\mathrm{\lambda }}{+}{1}}{{\mathrm{\pi }}}}{}{{ⅇ}}^{{I}{}{\mathrm{\phi }}{}{\mathrm{\mu }}}{}{\left({-1}\right)}^{{\mathrm{\mu }}}{}{\left({-}{\mathrm{\lambda }}\right)}_{{\mathrm{_k1}}}{}{\left({\mathrm{\lambda }}{+}{1}\right)}_{{\mathrm{_k1}}}{}{\left(\frac{{1}}{{2}}{-}\frac{{\mathrm{cos}}{}\left({\mathrm{\theta }}\right)}{{2}}\right)}^{{\mathrm{_k1}}}}{{2}{}\sqrt{\left({\mathrm{\lambda }}{+}{\mathrm{\mu }}\right){!}}{}{\mathrm{\Gamma }}{}\left({1}{-}{\mathrm{\mu }}\right){}{\mathrm{_k1}}{!}{}{\left({1}{-}{\mathrm{\mu }}\right)}_{{\mathrm{_k1}}}}$ (4)
 >
 $\frac{\sqrt{\left({-1}{-}{I}\right){!}}{}{\left({\mathrm{cos}}{}\left(\frac{{1}}{{3}}{+}\frac{{I}}{{5}}\right){+}{1}\right)}^{\frac{{3}}{{4}}{+}\frac{{I}}{{2}}}{}{\left({\mathrm{cos}}{}\left(\frac{{1}}{{3}}{+}\frac{{I}}{{5}}\right){-}{1}\right)}^{{-}\frac{{3}}{{4}}{-}\frac{{I}}{{2}}}{}\sqrt{{2}}{}\sqrt{\frac{{1}}{{\mathrm{\pi }}}}{}{{ⅇ}}^{\left({-}\frac{{1}}{{7}}{+}\frac{{3}{}{I}}{{14}}\right){}{\mathrm{\pi }}}{}{\left({-1}\right)}^{\frac{{3}}{{2}}{+}{I}}{}{\left({-}\frac{{1}}{{2}}\right)}_{{\mathrm{_k1}}}{}{\left(\frac{{3}}{{2}}\right)}_{{\mathrm{_k1}}}{}{\left(\frac{{1}}{{2}}{-}\frac{{\mathrm{cos}}{}\left(\frac{{1}}{{3}}{+}\frac{{I}}{{5}}\right)}{{2}}\right)}^{{\mathrm{_k1}}}}{{2}{}\sqrt{\left({2}{+}{I}\right){!}}{}{\mathrm{\Gamma }}{}\left({-}\frac{{1}}{{2}}{-}{I}\right){}{\mathrm{_k1}}{!}{}{\left({-}\frac{{1}}{{2}}{-}{I}\right)}_{{\mathrm{_k1}}}}$ (5)

Construct a formula_procedure with this summand as a function of the summation index $\mathrm{_k1}$

 > $\mathrm{formula_procedure}≔\mathrm{unapply}\left(,\mathrm{_k1}\right)$
 ${\mathrm{formula_procedure}}{≔}{\mathrm{_k1}}{↦}\frac{\sqrt{\left({-1}{-}{I}\right){!}}{}{\left({\mathrm{cos}}{}\left(\frac{{1}}{{3}}{+}\frac{{I}}{{5}}\right){+}{1}\right)}^{\frac{{3}}{{4}}{+}\frac{{I}}{{2}}}{}{\left({\mathrm{cos}}{}\left(\frac{{1}}{{3}}{+}\frac{{I}}{{5}}\right){-}{1}\right)}^{{-}\frac{{3}}{{4}}{-}\frac{{I}}{{2}}}{}\sqrt{{2}}{}\sqrt{\frac{{1}}{{\mathrm{\pi }}}}{}{{ⅇ}}^{\left({-}\frac{{1}}{{7}}{+}\frac{{3}{}{I}}{{14}}\right){}{\mathrm{\pi }}}{}{\left({-1}\right)}^{\frac{{3}}{{2}}{+}{I}}{}{\left({-}\frac{{1}}{{2}}\right)}_{{\mathrm{_k1}}}{}{\left(\frac{{3}}{{2}}\right)}_{{\mathrm{_k1}}}{}{\left(\frac{{1}}{{2}}{-}\frac{{\mathrm{cos}}{}\left(\frac{{1}}{{3}}{+}\frac{{I}}{{5}}\right)}{{2}}\right)}^{{\mathrm{_k1}}}}{{2}{}\sqrt{\left({2}{+}{I}\right){!}}{}{\mathrm{\Gamma }}{}\left({-}\frac{{1}}{{2}}{-}{I}\right){}{\mathrm{_k1}}{!}{}{\left({-}\frac{{1}}{{2}}{-}{I}\right)}_{{\mathrm{_k1}}}}$ (6)

You can now numerically evaluate $'\mathrm{SphericalY}'\left(\frac{1}{2},\frac{3}{2}+I,\frac{1}{3}+\frac{I}{5},\frac{\mathrm{\pi }}{7}\right)$

 > $\mathrm{Add}\left(\mathrm{formula_procedure}\right)$
 ${0.05489806051}{-}{0.01484631132}{}{I}$ (7)

To transform this formula into a procedure for the numerical evaluation of SphericalY for arbitrary arguments, construct with the summand a generic formula, depending on all the parameters, and as a function of the summation index, then use the extension mechanism of evalf, so define evalf/Y as shown below, where Y will represent the spherical harmonics function

 > $\mathrm{general_formula}≔\mathrm{unapply}\left(\mathrm{summand},\mathrm{_k1}\right)$
 ${\mathrm{general_formula}}{≔}{\mathrm{_k1}}{↦}\frac{\sqrt{\left({\mathrm{\lambda }}{-}{\mathrm{\mu }}\right){!}}{}{\left({\mathrm{cos}}{}\left({\mathrm{\theta }}\right){+}{1}\right)}^{\frac{{\mathrm{\mu }}}{{2}}}{}{\left({\mathrm{cos}}{}\left({\mathrm{\theta }}\right){-}{1}\right)}^{{-}\frac{{\mathrm{\mu }}}{{2}}}{}\sqrt{\frac{{2}{}{\mathrm{\lambda }}{+}{1}}{{\mathrm{\pi }}}}{}{{ⅇ}}^{{I}{}{\mathrm{\phi }}{}{\mathrm{\mu }}}{}{\left({-1}\right)}^{{\mathrm{\mu }}}{}{\left({-}{\mathrm{\lambda }}\right)}_{{\mathrm{_k1}}}{}{\left({\mathrm{\lambda }}{+}{1}\right)}_{{\mathrm{_k1}}}{}{\left(\frac{{1}}{{2}}{-}\frac{{\mathrm{cos}}{}\left({\mathrm{\theta }}\right)}{{2}}\right)}^{{\mathrm{_k1}}}}{{2}{}\sqrt{\left({\mathrm{\lambda }}{+}{\mathrm{\mu }}\right){!}}{}{\mathrm{\Gamma }}{}\left({1}{-}{\mathrm{\mu }}\right){}{\mathrm{_k1}}{!}{}{\left({1}{-}{\mathrm{\mu }}\right)}_{{\mathrm{_k1}}}}$ (8)
 >
 ${\mathrm{evalf/Y}}{≔}\left({\mathrm{\lambda }}{,}{\mathrm{\mu }}{,}{\mathrm{\theta }}{,}{\mathrm{\phi }}\right){↦}{\mathrm{Add}}{}\left({\mathrm{subs}}{}\left('\left[{:-}{\mathrm{\lambda }}{=}{\mathrm{\lambda }}{,}{:-}{\mathrm{\mu }}{=}{\mathrm{\mu }}{,}{:-}{\mathrm{\theta }}{=}{\mathrm{\theta }}{,}{:-}{\mathrm{\phi }}{=}{\mathrm{\phi }}\right]'{,}{\mathrm{eval}}{}\left({\mathrm{general_formula}}\right)\right)\right)$ (9)

Note the use of :-, necessary for the replacement to happen within general_formula. Alternatively, you could also write evalf/Y with the contents of general_formula explicitly present and in that way avoid entirely the need of the substitution of parameters by their actual values. Now, if you have not assigned a procedure to Y, it just echoes the function on the screen (i.e. the function returns unevaluated)

 >
 ${Y}{}\left(\frac{{1}}{{2}}{,}\frac{{3}}{{2}}{+}{I}{,}\frac{{1}}{{3}}{+}\frac{{I}}{{5}}{,}\frac{{\mathrm{\pi }}}{{7}}\right)$ (10)

But because of having assigned evalf/Y, however, you can numerically evaluate this function using evalf

 > $\mathrm{evalf}\left(\right)$
 ${0.05489806051}{-}{0.01484631132}{}{I}$ (11)

A plot of the real part of Y for $\mathrm{\theta }$ from 0 to $\mathrm{\pi }$

 >

Compare with the same plot constructed using the standard Maple SphericalY function

 >

As an example using an optional argument to specify the upper limit of the summation, consider the sum forms for the exponential-integral Ei function

 >
 * Partial match of "sum" against topic "sum_form".
 $\left[{{\mathrm{Ei}}}_{{a}}{}\left({z}\right){=}\left({\sum }_{{\mathrm{_k1}}{=}{0}}^{{\mathrm{\infty }}}{}\frac{{\left({-}{z}\right)}^{{\mathrm{_k1}}}}{{\mathrm{\Gamma }}{}\left({\mathrm{_k1}}{+}{1}\right){}\left({-}{1}{+}{a}{-}{\mathrm{_k1}}\right)}\right){+}{{z}}^{{a}{-}{1}}{}{\mathrm{\Gamma }}{}\left({1}{-}{a}\right){,}{a}{::}\left({¬}{'}{\mathrm{posint}}{'}\right)\right]{,}\left[{{\mathrm{Ei}}}_{{a}}{}\left({z}\right){=}\left({\sum }_{{\mathrm{_k1}}{=}{0}}^{{\mathrm{\infty }}}{}\frac{{\left({-1}\right)}^{{a}{+}{2}{}{\mathrm{_k1}}}{}\left({-}{\mathrm{\Psi }}{}\left({\mathrm{_k1}}{+}{1}\right){+}{\mathrm{ln}}{}\left({z}\right)\right){}{{z}}^{{a}{-}{1}{+}{\mathrm{_k1}}}}{{\mathrm{\Gamma }}{}\left({\mathrm{_k1}}{+}{1}\right){}{\mathrm{\Gamma }}{}\left({a}\right){}{{ⅇ}}^{{z}}}\right){+}\left({\sum }_{{\mathrm{_k1}}{=}{0}}^{{-}{2}{+}{a}}{}\frac{{\left({-1}\right)}^{{\mathrm{_k1}}}{}{\mathrm{\Gamma }}{}\left({-}{1}{+}{a}{-}{\mathrm{_k1}}\right){}{{z}}^{{\mathrm{_k1}}}}{{\mathrm{\Gamma }}{}\left({a}\right){}{{ⅇ}}^{{z}}}\right){,}{a}{::}{'}{\mathrm{posint}}{'}{\wedge }{z}{\ne }{0}\right]{,}\left[{{\mathrm{Ei}}}_{{a}}{}\left({z}\right){=}{\sum }_{{\mathrm{_k1}}{=}{0}}^{{-}{a}}{}\frac{\left({-}{a}\right){!}{}{{z}}^{{a}{-}{1}{+}{\mathrm{_k1}}}}{{{ⅇ}}^{{z}}{}{\mathrm{_k1}}{!}}{,}{a}{::}{'}{\mathrm{negint}}{'}{\wedge }{z}{\ne }{0}\right]$ (12)

Get the summand of the last sum in one go

 > $\mathrm{summand}≔\mathrm{op}\left(1,\mathrm{rhs}\left(\left(\left[-1\right]\right)\left[1\right]\right)\right)$
 ${\mathrm{summand}}{≔}\frac{\left({-}{a}\right){!}{}{{z}}^{{a}{-}{1}{+}{\mathrm{_k1}}}}{{{ⅇ}}^{{z}}{}{\mathrm{_k1}}{!}}$ (13)

Construct now a general formula-procedure as a function of the summation index, then a numerical evaluation procedure as done above for the function Y representing the spherical harmonics; call EI this function representing the exponential-integral

 > $\mathrm{general_formula}≔\mathrm{unapply}\left(\mathrm{summand},\mathrm{_k1}\right)$
 ${\mathrm{general_formula}}{≔}{\mathrm{_k1}}{↦}\frac{\left({-}{a}\right){!}{}{{z}}^{{a}{-}{1}{+}{\mathrm{_k1}}}}{{{ⅇ}}^{{z}}{}{\mathrm{_k1}}{!}}$ (14)
 > $\mathrm{evalf/EI}≔\left(a,z\right)→\mathrm{Add}\left(\mathrm{subs}\left('\left[:-a=a,:-z=z\right]',\mathrm{eval}\left(\mathrm{general_formula}\right)\right)\right)$
 ${\mathrm{evalf/EI}}{≔}\left({a}{,}{z}\right){↦}{\mathrm{Add}}{}\left({\mathrm{subs}}{}\left('\left[{:-}{a}{=}{a}{,}{:-}{z}{=}{z}\right]'{,}{\mathrm{eval}}{}\left({\mathrm{general_formula}}\right)\right)\right)$ (15)

Note that the sum form we are using requires $a$ to be a negative integer and also that the upper summation limit is equal to $-a$. In the evalf/EI procedure above, however, we have not specified either of these things. So, the numerical evaluation will be performed adding terms until the result converges. To see how many, turn on the infolevel for Add

 >
 ${{\mathrm{infolevel}}}_{{\mathrm{Add}}}{≔}{5}$ (16)

Enter now the EI function with some parameters and evaluate it numerically using evalf

 > $\mathrm{EI}\left(-4,\frac{21}{50}-\frac{3I}{10}\right)$
 ${\mathrm{EI}}{}\left({-4}{,}\frac{{21}}{{50}}{-}\frac{{3}{}{I}}{{10}}\right)$ (17)
 > $\mathrm{evalf}\left(\right)$
 ${-654.6695416}{+}{26.42712945}{}{I}$ (18)

We see that not just 5 but 14 terms were added and at that point the result already converged. Check the value using the Maple standard Ei function

 >
 ${{\mathrm{Ei}}}_{{-4}}{}\left(\frac{{21}}{{50}}{-}\frac{{3}{}{I}}{{10}}\right)$ (19)
 > $\mathrm{evalf}\left(\right)$
 ${-654.8063012}{+}{26.39258365}{}{I}$ (20)

The two results obtained are close to each other but the level of accuracy is poor. The formula, in fact, for $a=-4$ is valid if we add only 5 terms. Redefine now evalf/Ei taking into account both that it expects $a$ to be a negative integer and also that the upper summation limit is equal to $-a$

 > $\mathrm{evalf/EI}≔\left(a::\mathrm{negint},z\right)→\mathrm{Add}\left(\mathrm{subs}\left('\left[:-a=a,:-z=z\right]',\mathrm{eval}\left(\mathrm{general_formula}\right)\right),-a\right)$
 ${\mathrm{evalf/EI}}{≔}\left({a}{::}{'}{\mathrm{negint}}{'}{,}{z}\right){↦}{\mathrm{Add}}{}\left({\mathrm{subs}}{}\left('\left[{:-}{a}{=}{a}{,}{:-}{z}{=}{z}\right]'{,}{\mathrm{eval}}{}\left({\mathrm{general_formula}}\right)\right){,}{-}{a}\right)$ (21)

Clear the remember table of evalf and compute the value of Ei(-4, 21/50 - 3*I/10) again, checking the number of terms used: for $a=-4$ we expect 5 terms added

 > $\mathrm{forget}\left(\mathrm{evalf}\right)$
 > $\mathrm{evalf}\left(\right)$
 ${-654.8063012}{+}{26.39258366}{}{I}$ (22)

So now only 5 terms got added, as expected, and the accuracy of the result is much better. Also, if we pass a value of $a$ that is not a negative integer, for instance $a=1$, the numerical evaluation is halted with an error message

 > $\mathrm{evalf}\left(\mathrm{EI}\left(1,\frac{21}{50}-\frac{3I}{10}\right)\right)$

As an example of a double sum, consider the AppellF2 function

 >
 $\left[{{F}}_{{2}}{}\left({a}{,}{\mathrm{b1}}{,}{\mathrm{b2}}{,}{\mathrm{c1}}{,}{\mathrm{c2}}{,}{\mathrm{z1}}{,}{\mathrm{z2}}\right){=}{\sum }_{{\mathrm{_k1}}{=}{0}}^{{\mathrm{\infty }}}{}\phantom{\rule[-0.0ex]{0.4em}{0.0ex}}{\sum }_{{\mathrm{_k2}}{=}{0}}^{{\mathrm{\infty }}}{}\frac{{\left({a}\right)}_{{\mathrm{_k1}}{+}{\mathrm{_k2}}}{}{\left({\mathrm{b1}}\right)}_{{\mathrm{_k1}}}{}{\left({\mathrm{b2}}\right)}_{{\mathrm{_k2}}}{}{{\mathrm{z1}}}^{{\mathrm{_k1}}}{}{{\mathrm{z2}}}^{{\mathrm{_k2}}}}{{\left({\mathrm{c1}}\right)}_{{\mathrm{_k1}}}{}{\left({\mathrm{c2}}\right)}_{{\mathrm{_k2}}}{}{\mathrm{_k1}}{!}{}{\mathrm{_k2}}{!}}{,}\left|{\mathrm{z1}}\right|{+}\left|{\mathrm{z2}}\right|{<}{1}\right]$ (23)

Following the same steps outlined before, get the summand and construct a formula-procedure this time depending on 2 parameters $m$ and $n$

 > $\mathrm{summand}≔\mathrm{op}\left(\left[1,1\right],\mathrm{rhs}\left({}_{}\left[1\right]\right)\right)$
 ${\mathrm{summand}}{≔}\frac{{\left({a}\right)}_{{\mathrm{_k1}}{+}{\mathrm{_k2}}}{}{\left({\mathrm{b1}}\right)}_{{\mathrm{_k1}}}{}{\left({\mathrm{b2}}\right)}_{{\mathrm{_k2}}}{}{{\mathrm{z1}}}^{{\mathrm{_k1}}}{}{{\mathrm{z2}}}^{{\mathrm{_k2}}}}{{\left({\mathrm{c1}}\right)}_{{\mathrm{_k1}}}{}{\left({\mathrm{c2}}\right)}_{{\mathrm{_k2}}}{}{\mathrm{_k1}}{!}{}{\mathrm{_k2}}{!}}$ (24)
 > $\mathrm{general_formula}≔\mathrm{unapply}\left(\mathrm{summand},\mathrm{_k1},\mathrm{_k2}\right)$
 ${\mathrm{general_formula}}{≔}\left({\mathrm{_k1}}{,}{\mathrm{_k2}}\right){↦}\frac{{\left({a}\right)}_{{\mathrm{_k1}}{+}{\mathrm{_k2}}}{}{\left({\mathrm{b1}}\right)}_{{\mathrm{_k1}}}{}{\left({\mathrm{b2}}\right)}_{{\mathrm{_k2}}}{}{{\mathrm{z1}}}^{{\mathrm{_k1}}}{}{{\mathrm{z2}}}^{{\mathrm{_k2}}}}{{\left({\mathrm{c1}}\right)}_{{\mathrm{_k1}}}{}{\left({\mathrm{c2}}\right)}_{{\mathrm{_k2}}}{}{\mathrm{_k1}}{!}{}{\mathrm{_k2}}{!}}$ (25)

from where a routine for the numerical evaluation of AppellF2, when the condition $\left|\mathrm{z1}\right|+\left|\mathrm{z2}\right|<1$ shown in the definition is satisfied, is

 > $\mathrm{evalf/AF2}≔\left(a,\mathrm{b1},\mathrm{b2},\mathrm{c1},\mathrm{c2},\mathrm{z1},\mathrm{z2}\right)→\mathrm{Add}\left(\mathrm{subs}\left('\left[:-a=a,:-\mathrm{b1}=\mathrm{b1},:-\mathrm{b2}=\mathrm{b2},:-\mathrm{c1}=\mathrm{c1},:-\mathrm{c2}=\mathrm{c2},:-\mathrm{z1}=\mathrm{z1},:-\mathrm{z2}=\mathrm{z2}\right]',\mathrm{eval}\left(\mathrm{general_formula}\right)\right)\right)$
 ${\mathrm{evalf/AF2}}{≔}\left({a}{,}{\mathrm{b1}}{,}{\mathrm{b2}}{,}{\mathrm{c1}}{,}{\mathrm{c2}}{,}{\mathrm{z1}}{,}{\mathrm{z2}}\right){↦}{\mathrm{Add}}{}\left({\mathrm{subs}}{}\left('\left[{:-}{a}{=}{a}{,}{:-}{\mathrm{b1}}{=}{\mathrm{b1}}{,}{:-}{\mathrm{b2}}{=}{\mathrm{b2}}{,}{:-}{\mathrm{c1}}{=}{\mathrm{c1}}{,}{:-}{\mathrm{c2}}{=}{\mathrm{c2}}{,}{:-}{\mathrm{z1}}{=}{\mathrm{z1}}{,}{:-}{\mathrm{z2}}{=}{\mathrm{z2}}\right]'{,}{\mathrm{eval}}{}\left({\mathrm{general_formula}}\right)\right)\right)$ (26)

where we are calling $\mathrm{AF2}$ this representation of AppellF2. Consider now for instance some numerical complex values of the parameters $a,\mathrm{b1},\mathrm{b2},\mathrm{c1},\mathrm{c2},\mathrm{z1},\mathrm{z2}$ and numerically evaluate this $\mathrm{AF2}$ representation at those values

 > $\mathrm{AF2}\left(\frac{1}{2},\frac{2}{7},-\frac{1}{4},2,\frac{3}{2}+I,\frac{1}{4}I,\frac{1}{4}\right)$
 ${\mathrm{AF2}}{}\left(\frac{{1}}{{2}}{,}\frac{{2}}{{7}}{,}{-}\frac{{1}}{{4}}{,}{2}{,}\frac{{3}}{{2}}{+}{I}{,}\frac{{I}}{{4}}{,}\frac{{1}}{{4}}\right)$ (27)
 > $\mathrm{evalf}\left(\right)$
 ${0.9831522491}{+}{0.02726587338}{}{I}$ (28)

Compare with the numerical value obtained using the standard Maple AppellF2 function

 > $\mathrm{subs}\left(\mathrm{AF2}=\mathrm{AppellF2},\right)$
 ${{F}}_{{2}}{}\left(\frac{{1}}{{2}}{,}\frac{{2}}{{7}}{,}{-}\frac{{1}}{{4}}{,}{2}{,}\frac{{3}}{{2}}{+}{I}{,}\frac{{I}}{{4}}{,}\frac{{1}}{{4}}\right)$ (29)
 > $\mathrm{evalf}\left(\right)$
 ${0.9831522491}{+}{0.02726587338}{}{I}$ (30)

Compatibility

 • The MathematicalFunctions[Evalf][Add] command was introduced in Maple 2017.