Professional Documents
Culture Documents
, 2009.
Abstract—In this paper by means of computer experiment we study advantages and disadvantages of the heu-
ristical method of “parallel integrator”. For this purpose we describe and use implementation of the method in
Mathematica. In some cases we compare this implementation with the original one in Maple.
DOI: 10.1134/S0361768809020029
63
64 KRAGLER
Luis A. Medina and Alexander Pavlyk [12] devel- Below we present the code of pmint in Mathematica
oped the concept of pmint for Mathematica. Because in the form of separate procedures. In doing so, where
powerful Maple functions (e.g. convert) used do not it is possible we compare the Mathematica code with
the code of corresponding procedures of pmint in
have a direct correspondence in Mathematica the task Maple.
rewriting pmint into Mathematica code is not straight- (1) Procedures: pmint, pmIntegrate, tryIntegral,
forward. The author of the present paper updated pmint getSpecial, myFactors, enumerateMonoms, splitFactor,
and made their intensive testing by different examples deflation
running for the version 6.0.2 of Mathematica. The main procedure pmint in Mathematica:
Clear[pmint];
pmint[ f–, x–, opt: OptionsPattern[{Extension 0}]] :=
Module[{ff, si, li, lin, lout, q, d, l, lv, ld, ls, fint, lc, t, terms, list},
ff = Together[TrigToTan[f]];
list = ToIndetsAndDerivation[ff, x, t];
If [list == $Failed, Return[INT[f]]];
{ff, terms, lv, ld} = list;
q = denD[ld];
ld = q ∗ ld;
ls = DeleteCases[Map[getSpecial[#,Thread[terms Rest[lv]]]&, terms], Null];
ToTerms[pmIntegrate[ff, lv, ld, q, ls, OptionValue[Extension]],
terms, Rest[lv]] /. {tan Tan}]
For comparison we give the procedure pmint in Maple:
pmint := proc( f, x)
local ff, si, li, lin, lout, ld, q, d, l, vars, dx, ls, fint, lc;
ff := eval(convert( f, tan));] # convert trigs to tan
si := select(proc(d) diff(d, x) <> 0 end, indets( ff ));
si := select(proc(d) diff(d, x) <> 0 end, indets(map(diff, si, x)))
union si;
li := [op(si)]; # list of terms in integrand and its derivative
lin := [seq(d = ‘tools/genglobal‘(x), d = lin)]; # substitution terms –> indets
lout := [seq(rhs(d) = lhs(d), d = lin)]; # substitution indets –> terms
ld := subs(lin, map(dif f, li, x)); # derivatives of all the terms
q := lcm(seq(denom(d), d = ld)); # denominator of the total derivation
l := [seq(normal(q ∗ d),d = ld)]; # q ∗ derivatives of all the terms
vars := map(lhs, lout);
dx := totalDerivation(vars, l); # vector field dx = q ∗ d/dx
ls := [seq(getSpecial(d, lin), d = li)]; # list of known Darboux for dx
fint := subs(lout, pmIntegrate(subs(lin, ff ), dx, q, vars, ls));
lc := select(proc(d) convert(d, string)[1] =" –"; end, indets(fint, name));
subs({seq(d = 0, d = lc minus si)}, fint);
end;
pmIntegrate in Mathematica:
Clear[pmIntegrate];
pmIntegrate[ f–, lv–List, ld–List, q–, ls–: {}, ext–: 0] :=
Module[{splq, s, df, spl, cden, dg, x, monomials, cand, lunk, sol, i, AA},
DRPrint[“Visit pmIntegrate.”];
splq = splitFactor[q, lv, ld];
s = First[splq];
Scan[If [Last[#], s = s ∗ First[#]]&, ls];
x = First[lv];
df = Denominator[f];
spl = splitFactor[df, lv, ld];
cden = s ∗ First[spl] ∗ deflation[Last[spl], lv, ld];
dg = 1 + totalDeg[s, lv] +
Max[totalDeg[Numerator[f], lv], totalDeg[Denominator[f], lv]];
monomials = enumerateMonoms[lv, dg];
DRPrint[“There are”, Length[lv],
“new variables in the integrand and the guess bound for deg is”, dg,
“therefore the number of monomials is”, Length[monomials], “.”];
Derivative in Mathematica:
Derivative[1][tan] = Function[1 + tan[#]ˆ2];
Derivative[1][exp] = exp;
exp[a– + b–] := exp[a] exp[b];
exp[Log[x–]] := x;
This function provides an extension of the first derivatives of tan and exp with additional rules for the expo-
nential function.
(3) Other auxillary functions are: totalDerivation, PolyContentPP, PolyCoeffs, mainVar, myVariables, Ratio-
nalFunctionQ, td, totalDeg, SubSet.
totalDerivation in Mathematica:
totalDerivation[lvList, ldList] :=
Function[u, ld . Table[D[u, k], {k, lv}], Listable]
totalDerivation in Maple:
totalDerivation := proc(lv, ld)
proc( f ) local fp, i;
fp := 0; for i to nops(ld) do fp := fp + ld[i] ∗ diff (f, lv[i]); od;
fp;
end;
end;
PolyContentPP in Mathematica:
PolyContentPP[A–, t–] :=
With[{q = FactorTermsList[A, t]},
{Times @@ Most[q], Last[q]} ]
PolyCoeffs in Mathematica:
PolyCoeffs[p–,vars–] :=
Block[{t},
Union @ Flatten[Coef ficientArrays[p, vars]/.
t–SparseArray :> ArrayRules[t][[All, 2]]] ]
mainVar in Mathematica:
mainVar[p–, lv–List] :=
Catch[Scan[If[Exponent[p, #1] > 0, Throw[#1]]&, Reverse[lv]];
$Failed ]
myVariables in Mathematica:
myVariables[e : (–Plus|–Times)] :=
Union[Flatten[myV ariables /@ Apply [List, e]]];
myVariables[HoldPattern[Power][e–, a–Integer]] := myVariables[e];
myVariables[e– /; NumericQ[e]] := {};
myVariables[HoldPattern [Power][x–, pPlus]] :=
Union[Flatten[myV ariables [xˆApply [List, p]]]];
myVariables[e–] := {e};
SetAttributes[myVariables, {Listable}];
RationalFunctionQ in Mathematica:
RationalFunctionQ[expr : (Plus|–Times), x–] :=
Fold[Function[{pr, el}, pr && RationalFunctionQ[el, x]], True,
List @@ expr];
RationalFunctionQ[HoldPattern[Power][e–, a–Integer], x–] :=
RationalFunctionQ[e, x];
RationalFunctionQ[x_, x–] := True;
RationalFunctionQ[expr : Except[Times]–Plus], x–List] :=
Fold[#1 && (expr === #2 || FreeQ[expr, #2])&, True, x];
Here f is the integrand, x the variable of integration —to adjoin the variables in order to calculate the
and t is a dummy variable whose purpose is to name the integral. This information is needed when changing
new transcendental variables as t1, t2, …. The output of back the result in terms of the original variables.
the procedure ToIndetsAndDerivation is: —The last two elements of the output are of the
form {x, t1, t2, …} and {1, D[t1], D[t2], …}. These ele-
—the integrand f in terms of new variables, ments are needed to obtain totalDerivation.
ToTerms in Mathematica:
ToTerms[F–, terms–List, vars–List] := F /. Thread[vars –> terms]
It is assumed that “derivations” are the list of deriv- given at the time, when denD. In particular, it takes the
atives of transcendental variables ti . This list should be last element of ToIndetsAndDerivation[f, x, t].
denD in Mathematica:
denD[derivations–List] := PolynomialLCM @@ Denominator[Together[derivations]];
Finally, some auxillary definitions are needed for The inverse of the function f(w) = weW is called the
simplification of the expressions etc. Omega function. The Wright Omega function is
(5) Transformations: LambertRule, log2ArctanRule, defined in terms of the Lambert W function with argu-
pureFctConversion ment Ex.
Because Lambert’s W function is implemented in The Omega in Mathematica is defined as:
Mathematica as the function ProductLog, the following Ω[x–] := LambertW[Ex]
substitution rule is used.
In order to recast the logarithmic representation of
LambertRule in Mathematica: the arctan function into the usual representation a
LambertRule = {ProductLog[z–] –> lambertW[z]}; sequence of replacement rules has to be defined.
log2ArctanRule in Mathematica:
log2ArctanRule[result–] :=
((( (result /. {Log[a–] – Log[b–] –> Log[a/b]}) /.
{Log[(–I + z–)/(I + z–)] –> Log[–((1 + I ∗ z)/(1 – I ∗ z))] }) /.
{Log[–c–] –> Log[c] + Log[–1]}) /.
{Log[(1 + I ∗ z–)/(1 – I ∗ z–)] –> 2I ∗ ArcTan[z]}
) // Simplify
Furthermore, the following rule achieves the con- function representation with Function[par, body] and
version between the two forms of Mathematica's pure body[#]&.
pureFctConversion in Mathematica:
pureFctConversion =
Literal[Function[par–, body–]] /; FreeQ[body, #] :>
Unevaluated[Function[body] /. par #];
Finally, DRPrint is used for debugging:
DRPrint[w–––] /; ($DebugRisch === True) := Print[w];
(h) Lambert W function; (a) Elementary functions distinct from the conven-
tional rational functions and from rational expressions
(i) Wright Omega function. of trigonometric functions
As will be shown below some examples involving In the case of elementary functions such as (non-
Airy, Bessel, Lambert W, Wright Omega and Whit- rational) polynomials involving powers of xn or combi-
nations of trigonometric functions pmint reproduces the
taker W functions where pmint gives a result cannot be same results as found with the built-in integrators of
dealt with either by Maple's built-in integrator int Mathematica or Maple. Generally, there arise some
or/and by Mathematica 's built-in procedure Integrate. problems to cast the results in the same form. Thus, as
If available the results of the built-in integrators shown by the subsequent example it needs some addi-
obtained by Maple and/or Mathematica will be com- tional efforts, i.e. a sequence of Mathematica com-
pared with the result of pmint. mands, until the result looks the same.
7 4 2
x – 24x – 4x + 8x – 8
|| pmint ---------------------------------------------------------
8 6 4 2
-, x // Simplify // Apart
x + 6x + 12x + 8x
2 3
4 + 6x + 8x + 3x
⇒ --------------------------------------------
2 2
+ Log [ x ]
x(2 + x )
1
However, the obviously simple integration pmint --------------2, x with result ArcTan[x] only works with extension
1+x
to complex numbers by the additional option of pmint, i.e. Extension Algebraic
1
|| res1 = pmint --------------2 , x, Extension Algebraic // PowerExpand // Together
1+x
⇒ –(1/2) I (Log[–I + x] – Log[I + x])
With a sequence of replacement rules which is the result of Integrate up to an integration con-
log2ArctanRule the logarithmic terms are finally casted stant –I/2Log[–1] = π/2.
into the function ArcTan
(c) Rational expressions in trigonometric functions
|| res1 // log2ArctanRule and powers of the integration variable
⇒ ArcTan[x] + π/2 pmint can handle such integrands.
Alternatively, the Extension (–1)1/3, could have tor first the roots (–1), i.e. {(–1)1/3, (–1)2/3} have to be
been chosen but this choice would require some kind of
1 i 3
preknowledge of the result; therefore the option Exten- casted into ± --- + --------- by means of the substitution rule
sion Algebraic is more general. In order to obtain 2 2
the result in the same form given by the built-in integra- algNumbRule:
|| {z – (1 + 2 Tan[x/2])/ 3 }
the result finally agrees with that of Integrate. The straightforward calculation fails but the calcula-
tion is doable if the integrand is casted into a rational poly-
2 1 + 2Tan [ x/2 ] nomial using the substitution Tan[x/2] z. Because of
⇒ ------- ArcTan ------------------------------------ this substitution the transformed integrand fct(z) has to be
3 3
divided by an additional factor (1 + z2)/2. Hence using
Another intricate example is Apart and ComplexExpand the integrand becomes f1 =
2
1 4 – 4z 2 7 + 2z – z
----------- + --------------------2 + -------------2 and f2 = -----------------------------------------
-.
( Cos [ x ] – Sin [ x ] )Sin [ x ] 1 + z ( 1 + z2 ) 1+z – 1 – z – 3z + z
2 3
|| pmint --------------------------------------------------------------, x
1 + Cot [ x ] + Sin [ x ] Now,
〈 〈 1〉 〉
+ 6(9 + 3I 3 + I 11 + 33 ))) + --------------------------
-
3 ( 〈 〈 1〉 〉 )
1/6
( 〈 〈 1〉 〉 ) 〈 〈 1〉 〉 4 ( 〈 〈 1〉 〉 )
+ --------------------------------
- + ----------------------
6
〈 〈 1〉 〉
( 〈 〈 1〉 〉 ) 〈 〈 1〉 〉
but it is an explicit solution. Yet, interesting is the comparison with Integrate. The straightforward application
of Integrate leads to a result much shorter which, however, is given as an implicit representation in terms of Math-
ematica's RootSum
Numerical approximations of the both results of K and F1 + F2 agree up to integr ation constants.
(d) Transcendental functions of the form Log – Exp
Here is an example where pmint gives a solution
– 2e + 2xe + 3 3Log [ – 1 + x ]
2x 2r 2
|| pmint ------------------------------------------------------------------------------------
-, x
( – 1 + x ) ( e + 3Log [ – 1 + x ] )
2x 3
Exp [ – x ]Erf [ x ]
2
|| pmint ----------------------------------------------------------------------------
-, x
Erf [ x ] – Erf [ x ] – Erf [ x ] + 1
3 2
π
⇒ ------- ⎛ – ------------------------------- + Log [ – 1 + Erf [ x ] ] – Log [ 1 + Erf [ x ] ]⎞
2
8 ⎝ – 1 + Erf [ x ] ⎠
The result of integration is the same for pmint and the integrators built into Maple and Mathematica. However,
2 2
–x –x
for a slightly more complicated case where the numerator e Erf[x] is replaced by e Erf[x ex] neither pmint,
nor the implemented integrators of Maple or Mathematica can deal with this case.
(f) Airy functions
For the subsequent examples which involve AiryAi and AiryAiPrime functions pmint is able to find solutions
while Integrate fails in all cases.
|| pmint[x AiryAiPrime[x] Cos[AiryAi[x]] + Sin[AiryAi[x]], x]
2x Tan [ AiryAi [ x ]/2 ]
⇒ ---------------------------------------------------------2
1 + Tan [ AiryAi [ x ]/2 ]
Here is another integral involving combinations of AiryAi, AiryAiPrime, Log and ArcTan:
AiryAi [ x ] ArcTan [ x ] AiryAi [ x ] Log [ x ]
|| pmint -------------------------------------------------------- + ---------------------------------------------
2
-
x 1+x
|| +AiryAiPrime[x] ArcTan[x] Log[x], x] // Simplify
⇒ AiryAi[x] ArcTan[x] Log[x]
Another integral which pmint can solve but not Integrate is:
Finally
AiryAi [ x ] AiryAi [ x ]
AiryAiPrime [ x ] e ( 1 + 3 AiryAi [ x ] AiryAiPrime [ x ] )
2
e
|| pmint --------------------------------------------------------------- -, x
- – ------------------------------------------------------------------------------------------------------------
x + AiryAi [ x ]
3 3 2
( x + AiryAi [ x ] )
AiryAi [ x ] AiryAi [ x ]
AiryAi [ x ]
3
e x+e
⇒ ------------------------------------------------------------------------------
3 2
( x + AiryAi [ x ] )
In order to obtain this result the CPU time (with BesselJ [ n + 1, x ]
respect to the computer being used) is quite long. || pmint -------------------------------------------, x
BesselJ [ n, x ]
(g) Bessel functions
A straightforward integration for the quotient of The reason why pmint cannot directly cope with this
BesselJ [ n + 1, x ] integrand and hangs up is that every differentiation
Bessel functions ------------------------------------------- fails both for
BesselJ [ n, x ] introduces new orders of BesselJ functions in this spe-
pmint and Integrate. cific case
⎧ n t1 ( n + 1 ) t2 ⎫
⇒ ⎨ – t2 + ----------, t1 – ------------------------ ⎬
⎩ x x ⎭
This result serves as a guidance for the definition of t1' and t2' as “pure” functions
n t1 [ z ]
|| {Derivative[1][t1] = Function z, ----------------- – t2 [ z ] /. pureFctConversion,
z
( n + 1 ) t2 [ z ]
|| Derivative[1][t2] = Function[z, t1[z] – z, t1 [ z ] – ------------------------------- /. pureFctConversion}
z
⎧ n t1 [ #1 ] ( n + 1 ) t2 [ #1 ] ⎫
⇒ ⎨ --------------------- – t2 [ #1 ]$, t1 [ #1 ] – ----------------------------------- $ ⎬
⎩ #1 #1 ⎭
The great advantage of pmint is that one only needs to know the derivative of a function (which needs to be in
the monomial extension of transcendental functions) in order to be able to perform the integration. It is assumed
that the differential is closed on that extension. Therefore, because the derivative of
|| D[nLog[x] – Log[t1[x]], x] // Simplify
t2 [ x ]
⇒ -------------
t1 [ x ]
t2 [ x ]
turns out to be ------------- , pmint can now calculate the integral
t1 [ x ]
t2 [ x ]
|| pmint -------------, x /. {t1[x] BesselJ[n, x], t2[x] BesselJ[n + 1, x]}
t1 [ x ]
The same strategy can also be used for the calcula- (h) Lambert W function
tion of
In Mathematica the Lambert W function is identical
x BesselJ [ n + 1, x ] – n Bessel [ n, x ] with the function ProductLog. Hence, either LambertW
|| pmint -------------------------------------------------------------------------------------------, x or ProductLog can be used. The function w = Product-
x Log[z] is the principal solution for z = w ew. (The k-th
where a direct calculation again fails but with the solution is denoted by ProductLog[k, z]). The solutions
help of the auxillary functions t1 and t2 and their first are ordered according to their imaginary parts. For z >
derivatives the integration gives −1/e ProductLog[z] is real. Moreover, ProductLog[z]
dw w
x t2 [ x ] – t1 [ x ] satisfies the differential equation ------- = -------------------- .
|| pmint -------------------------------------, x dz z ( 1 + w )
x
Both pmint and Integrate can handle the following
⇒ n BesselJ [ n, x ] integral:
|| pmint[Sin[ProductLog[x]], x] // FullSimplify
1
⇒ --- (–x Cos[ProductLog[x]] + (eProductLog[x] + x) Sin[ProductLog[x]])
2
For the next example
2ProductLog [ x ] + ProductLog [ x ]
2
-, x
|| pmint -----------------------------------------------------------------------------------------------------------------
( 1 + ProductLog [ x ] ) ( 1 + x ProductLog [ x ]
2 2
a straightforward integration with pmint does not work. Because pmint has the default
OptionsPattern[{Extension 0}],
this example fails due to the fact that certain polynomials cannot be factorized. However, it suffices to enlarge
the extension to Extension I in order to obtain the solution.
2ProductLog [ x ] + ProductLog [ x ]
2
|| pmint -----------------------------------------------------------------------------------------------------------------
- , x, Extension I] // Simplify
( 1 + ProductLog [ x ] ) ( 1 + x ProductLog [ x ]
2 2
Again, the built-in Mathematica integrator Integrate cannot not find a solution whereas pmint does.
3. Norman, A.C. and Moore, P.M.A., Implementing the 8. Davenport, J.H., On the Parallel Risch Algorithm (III):
New Risch Integration Algorithm, Proc. the 4th Interna- Use of Tangents, SIGSAM Bulletin, 1982, vol. 16, pp. 3–6.
tional Colloquium on Advanced Computing Methods in
Theoretical Physics, 1977, pp. 99–110. 9. Davenport, J.H. and Trager, B.M., On the Parallel Risch
4. Harrington, S.H., A New Symbolic Integration System Algorithm (II), ACM Transactions on Mathematical
in Reduce, The Computer Journal, 1979, vol. 22, Software, 1985, no. 11, pp. 356–362.
pp. 127–131.
10. http://www-sop.inria.fr/cafe/Manuel.Bronstein/pmint/ind-
5. Fitch, J., User-Based Integration Software, Proc.
SYMSAC'81, ACM Press, 1981, pp. 245–248. ex.html.
6. Geddes, K. and Stefanus, L., On the Risch-Norman Inte- 11. Bronstein, M., Symbolic Integration I. Transcendental
gration Method and Its Implementation in Maple, Proc. Functions, Berlin-Heidelberg: Springer-Verlag, 2nd ed.,
ISSAC'89, ACM Press, 1989, pp. 212–217. 2005.
7. Davenport, J.H., On the Parallel Risch Algorithm (I).
Proceedings of EUROCAM'82, LNCS, Springer, 1982, 12. Pavlyk, A., WRI, November 2007, Private communica-
vol. 144, pp. 144–157. tion.