Integration Utility Functions
H* TimeLimit is the time constraint in seconds on some potentially expensive routines. *L
If@Not@NumberQ@TimeLimitDD, TimeLimit=1.0D;
IntHide[u,x]
IntHide@u_,x_SymbolD :=
Block@8ShowSteps=False,StepCounter=Null<, Int@u,xDD
Mapping functions
MapAnd[u,x]
H* MapAnd@f,lD applies f to the elements of list l until False is returned; else returns True *L
MapAnd@f_,lst_D :=
Catch@Scan@Function@If@f@ðD,Null,Throw@FalseDDD,lstD;TrueD
MapAnd@f_,lst_,x_D :=
Catch@Scan@Function@If@f@ð,xD,Null,Throw@FalseDDD,lstD;TrueD
Map2[func,lst1,lst2]
Map2@func_,lst1_,lst2_D :=
Module@8i<,
ReapList@Do@Sow@func@lst1@@iDD,lst2@@iDDDD,8i,Length@lst1D<DDD
ReapList[u]
ReapList@u_D :=
With@8lst=Reap@uD@@2DD<,
If@lst===8<, lst, lst@@1DDDD
SetAttributes@ReapList,HoldFirstD
2 | Integration utility functions.m
Numerical type predicates
FalseQ[u]
FalseQ@u_D := u===False
ZeroQ[u]
H* ZeroQ@u1,u2,...D returns True if u1, u2, ... are all 0; else it returns False. *L
ZeroQ@u_D := Quiet@PossibleZeroQ@uDD
ZeroQ@u__D := Catch@Scan@Function@If@ZeroQ@ðD,Null,Throw@FalseDDD,8u<D;TrueD
NonzeroQ[u]
NonzeroQ@u_D := Not@ZeroQ@uDD
IntegersQ[u]
H* IntegersQ@m,n,...D returns True if m, n, ... are all explicit integers; else it returns False. *L
IntegersQ@u__D := Catch@Scan@Function@If@IntegerQ@ðD,Null,Throw@FalseDDD,8u<D; TrueD;
PositiveIntegerQ[u]
H* PositiveIntegerQ@m,n,...D returns True if m, n, ... are all explicit positive integers; else it returns False. *L
PositiveIntegerQ@u__D := Catch@Scan@Function@If@IntegerQ@ðD && ð>0,Null,Throw@FalseDDD,8u<D; TrueD;
NegativeIntegerQ[u]
H* NegativeIntegerQ@m,n,...D returns True if m, n, ... are all explicit negative integers; else it returns False. *L
NegativeIntegerQ@u__D := Catch@Scan@Function@If@IntegerQ@ðD && ð<0,Null,Throw@FalseDDD,8u<D; TrueD;
FractionQ[u]
H* FractionQ@m,n,...D returns True if m, n, ... are all explicit fractions; else it returns False. *L
FractionQ@u__D := Catch@Scan@Function@If@Head@ðD===Rational,Null,Throw@FalseDDD,8u<D; TrueD
RationalQ[u]
H* RationalQ@m,n,...D returns True if m, n, ... are all explicit integers or fractions; else it returns False. *L
RationalQ@u__D := Catch@Scan@Function@If@IntegerQ@ðD ÈÈ Head@ðD===Rational,Null,Throw@FalseDDD,8u<D; TrueD
ComplexNumberQ[u]
H* ComplexNumberQ@m,n,...D returns True if m, n, ... are all explicit complex numbers; else it returns False. *L
ComplexNumberQ@u__D := Catch@Scan@Function@If@Head@ðD===Complex,Null,Throw@FalseDDD,8u<D; TrueD
Integration utility functions.m | 3
RealNumericQ[u]
H* RealNumericQ@uD returns True if u is a real numeric quantity, else returns False. *L
RealNumericQ@u_D := NumericQ@uD && HZeroQ@Im@uDD ÈÈ ZeroQ@Im@N@uDDDL
PositiveQ[u]
H* PositiveQ@uD returns True if u is a positive numeric quantity, else returns False. *L
PositiveQ@u_D :=
With@8v=Simplify@uD<,
RealNumericQ@vD && Re@N@vDD>0D
NegativeQ[u]
H* NegativeQ@uD returns True if u is a negative numeric quantity, else returns False. *L
NegativeQ@u_D :=
With@8v=Simplify@uD<,
RealNumericQ@vD && Re@N@vDD<0D
PositiveOrZeroQ[u]
H* PositiveOrZeroQ@uD returns True if u is a nonpositive numeric quantity, else returns False. *L
PositiveOrZeroQ@u_D :=
With@8v=Simplify@uD<,
RealNumericQ@vD && Re@N@vDD>=0D
NegativeOrZeroQ[u]
H* NegativeQ@uD returns True if u is a negative numeric quantity, else returns False. *L
NegativeOrZeroQ@u_D :=
With@8v=Simplify@uD<,
RealNumericQ@vD && Re@N@vDD<=0D
FractionOrNegativeQ[u]
H* FractionOrNegativeQ@uD returns True if u is a fraction or negative number; else returns False *L
FractionOrNegativeQ@u__D := Catch@Scan@Function@If@FractionQ@ðD ÈÈ IntegerQ@ðD && ð<0,Null,Throw@FalseDDD,8u<D; TrueD
SqrtNumberQ[u]
H* SqrtNumberQ@uD returns True if u^2 is a rational number; else it returns False. *L
SqrtNumberQ@m_^n_D :=
IntegerQ@nD && SqrtNumberQ@mD ÈÈ IntegerQ@n-12D && RationalQ@mD
SqrtNumberQ@u_*v_D :=
SqrtNumberQ@uD && SqrtNumberQ@vD
SqrtNumberQ@u_D :=
RationalQ@uD ÈÈ u===I
4 | Integration utility functions.m
SqrtNumberSumQ[u]
SqrtNumberSumQ@u_D :=
SumQ@uD && SqrtNumberQ@First@uDD && SqrtNumberQ@Rest@uDD ÈÈ
ProductQ@uD && SqrtNumberQ@First@uDD && SqrtNumberSumQ@Rest@uDD
IndependentQ[u,x]
IndependentQ@u_,x_D :=
FreeQ@u,xD
NotIntegrableQ[u,x]
H* NotIntegrableQ@u,xD returns True if u is definitely not integrable wrt x; else it returns
False if u is, or might be, integrable wrt x. *L
NotIntegrableQ@u_,x_SymbolD :=
MatchQ@u,x^m_*Log@a_+b_.*xD^n_ ; FreeQ@8a,b<,xD && IntegersQ@m,nD && m<0 && n<0D ÈÈ
MatchQ@u,f_@x^m_.*Log@a_.+b_.*xDD ; FreeQ@8a,b<,xD && IntegerQ@mD && HTrigQ@fD ÈÈ HyperbolicQ@fDLD
Expression type predicates
PowerQ[u]
H* If u is a power, SumQ@uD returns True; else it returns False. *L
PowerQ@u_D := Head@uD===Power
ProductQ[u]
H* If u is a product, SumQ@uD returns True; else it returns False. *L
ProductQ@u_D := Head@uD===Times
SumQ[u]
H* If u is a sum, SumQ@uD returns True; else it returns False. *L
SumQ@u_D := Head@uD===Plus
NonsumQ[u]
H* If u is not a sum, NonsumQ@uD returns True; else it returns False. *L
NonsumQ@u_D := Head@uD=!=Plus
IntegerPowerQ[u]
IntegerPowerQ@u_D :=
PowerQ@uD && IntegerQ@u@@2DDD
Integration utility functions.m | 5
PositiveIntegerPowerQ[u]
PositiveIntegerPowerQ@u_D :=
PowerQ@uD && IntegerQ@u@@2DDD && u@@2DD>0
FractionalPowerQ[u]
FractionalPowerQ@u_D :=
PowerQ@uD && FractionQ@u@@2DDD
FractionalPowerFreeQ[u]
FractionalPowerFreeQ@u_D :=
If@AtomQ@uD,
True,
If@FractionalPowerQ@uD && Not@AtomQ@u@@1DDDD,
False,
Catch@Scan@Function@If@FractionalPowerFreeQ@ðD,Null,Throw@FalseDDD,uD;TrueDDD
ComplexFreeQ[u]
ComplexFreeQ@u_D :=
If@AtomQ@uD,
Not@ComplexNumberQ@uDD,
Catch@Scan@Function@If@ComplexFreeQ@ðD,Null,Throw@FalseDDD,uD;TrueDD
ExpQ[u]
ExpQ@u_D := PowerQ@uD && u@@1DD===E
LogQ[u]
H* If u is an expression of the form Log@vD, LogQ@uD returns True; else it returns False. *L
LogQ@u_D := Head@uD===Log
TrigQ[u]
H* TrigQ@uD returns True if u or the head of u is a trig function; else returns False *L
TrigQ@u_D :=
MemberQ@8Sin,Cos,Tan,Cot,Sec,Csc<,If@AtomQ@uD,u,Head@uDDD
6 | Integration utility functions.m
SinQ@u_D := Head@uD===Sin
CosQ@u_D := Head@uD===Cos
TanQ@u_D := Head@uD===Tan
CotQ@u_D := Head@uD===Cot
SecQ@u_D := Head@uD===Sec
CscQ@u_D := Head@uD===Csc
HyperbolicQ[u]
H* HyperbolicQ@uD returns True if u or the head of u is a trig function; else returns False *L
HyperbolicQ@u_D :=
MemberQ@8Sinh,Cosh,Tanh,Coth,Sech,Csch<,If@AtomQ@uD,u,Head@uDDD
SinhQ@u_D := Head@uD===Sinh
CoshQ@u_D := Head@uD===Cosh
TanhQ@u_D := Head@uD===Tanh
CothQ@u_D := Head@uD===Coth
SechQ@u_D := Head@uD===Sech
CschQ@u_D := Head@uD===Csch
InverseTrigQ[u]
H* InverseTrigQ@uD returns True if u or the head of u is an inverse trig function; else returns False *L
InverseTrigQ@u_D :=
MemberQ@8ArcSin,ArcCos,ArcTan,ArcCot,ArcSec,ArcCsc<,If@AtomQ@uD,u,Head@uDDD
InverseHyperbolicQ[u]
H* InverseHyperbolicQ@uD returns True if u or the head of u is an inverse trig function; else returns False *L
InverseHyperbolicQ@u_D :=
MemberQ@8ArcSinh,ArcCosh,ArcTanh,ArcCoth,ArcSech,ArcCsch<,If@AtomQ@uD,u,Head@uDDD
SinCosQ[u]
SinCosQ@f_D :=
MemberQ@8Sin,Cos,Sec,Csc<,fD
Integration utility functions.m | 7
SinhCoshQ[u]
SinhCoshQ@f_D :=
MemberQ@8Sinh,Cosh,Sech,Csch<,fD
CalculusQ[u]
CalculusFunctions=8D,Integrate,Sum,Product,Int,Dif,Subst<;
H* CalculusQ@uD returns True if the head of u is a calculus function; else returns False *L
CalculusQ@u_D :=
MemberQ@CalculusFunctions,Head@uDD
CalculusFreeQ@u_,x_D :=
If@AtomQ@uD,
True,
If@CalculusQ@uD && u@@2DD===x ÈÈ HeldFormQ@uD,
False,
Catch@Scan@Function@If@CalculusFreeQ@ð,xD,Null,Throw@FalseDDD,uD;TrueDDD
HeldFormQ@u_D :=
If@AtomQ@Head@uDD,
MemberQ@8Hold,HoldForm,Defer,Pattern<,Head@uDD,
HeldFormQ@Head@uDDD
H* InverseFunctionQ@uD returns True if u is a call on an inverse function; else returns False. *L
InverseFunctionQ@u_D :=
LogQ@uD ÈÈ InverseTrigQ@uD && Length@uD<=1 ÈÈ InverseHyperbolicQ@uD ÈÈ Head@uD===Mods ÈÈ Head@uD===PolyLog
H* If u is free of trig, hyperbolic and calculus functions involving x,
TrigHyperbolicFreeQ@u,xD returns true; else it returns False. *L
TrigHyperbolicFreeQ@u_,x_SymbolD :=
If@AtomQ@uD,
True,
If@TrigQ@uD ÈÈ HyperbolicQ@uD ÈÈ CalculusQ@uD,
FreeQ@u,xD,
Catch@Scan@Function@If@TrigHyperbolicFreeQ@ð,xD,Null,Throw@FalseDDD,uD;TrueDDD
H* If u is free of inverse, calculus and hypergeometric functions involving x,
InverseFunctionFreeQ@u,xD returns true; else it returns False. *L
InverseFunctionFreeQ@u_,x_SymbolD :=
If@AtomQ@uD,
True,
If@InverseFunctionQ@uD ÈÈ CalculusQ@uD ÈÈ Head@uD===Hypergeometric2F1 ÈÈ Head@uD===AppellF1,
FreeQ@u,xD,
Catch@Scan@Function@If@InverseFunctionFreeQ@ð,xD,Null,Throw@FalseDDD,uD;TrueDDD
8 | Integration utility functions.m
H* ElementaryExpressionQ@uD returns True if u is a sum, product, or power and all the operands
are elementary expressions; or if u is a call on a trig, hyperbolic, or inverse function
and all the arguments are elementary expressions; else it returns False. *L
H* ElementaryFunctionQ@u_D :=
If@AtomQ@uD,
True,
If@SumQ@uD ÈÈ ProductQ@uD ÈÈ PowerQ@uD ÈÈ TrigQ@uD ÈÈ HyperbolicQ@uD ÈÈ InverseFunctionQ@uD,
Catch@Scan@Function@If@ElementaryFunctionQ@ðD,Null,Throw@FalseDDD,uD;TrueD,
FalseDD *L
RealQ[u]
H* Real@uD returns True if u is a real-valued quantity, else returns False. *L
RealQ@u_D :=
MapAnd@RealQ,uD ;
ListQ@uD
RealQ@u_D :=
ZeroQ@Im@N@uDDD ;
NumericQ@uD
RealQ@u_^v_D :=
RealQ@uD && RealQ@vD && HIntegerQ@vD ÈÈ PositiveOrZeroQ@uDL
RealQ@u_*v_D :=
RealQ@uD && RealQ@vD
RealQ@u_+v_D :=
RealQ@uD && RealQ@vD
RealQ@f_@u_DD :=
If@MemberQ@8Sin,Cos,Tan,Cot,Sec,Csc,ArcTan,ArcCot,Erf<,fD,
RealQ@uD,
If@MemberQ@8ArcSin,ArcCos<,fD,
LE@-1,u,1D,
If@f===Log,
PositiveOrZeroQ@uD,
FalseDDD
RealQ@u_D :=
False
Integration utility functions.m | 9
Equality and inequality predicates
EqQ[u,v]
H* If u=v, EqQ@u,vD returns True; else it returns False. *L
EqQ@u_,v_D := ZeroQ@u-vD
Multinomial predicates
PolyQ[u,x]
H* PolyQ@u,x,nD returns True iff u is a polynomial of degree n. *L
PolyQ@u_,x_Symbol,n_IntegerD :=
If@ListQ@uD,
Catch@Scan@Function@If@Not@PolyQ@ð,x,nDD,Throw@FalseDDD,uD; TrueD,
PolynomialQ@u,xD && Exponent@u,xD==n && Coefficient@u,x,nD=!=0D
H*
H*
H*
H*
H*
H*
Mathematica's built-in PolynomialQ, Exponent and Coefficient functions can return erroneous results because they do not *L
cancel the gcd in pseudo-rational functions that are actually polynomial. *L
For some unfully expanded polynomials, the built-in Mathematica function Exponent sometimes returns erronously large degrees.
For example, Exponent@3*H1+aL*x^4 + 3*x^5 + x^6 - Ha+x+x^2L^3, xD incorrectly returns 4 instead of 3. *L
Despite what the online help says, PolynomialQ@u,xD returns an error message if x is not a symbol or *L
a symbol raised to a symbol power. *L
H* If u is a polynomial in x,PolyQ@u,xD returns True; else it returns False. *L
PolyQ@u_,x_SymbolD :=
PolynomialQ@u,xD ÈÈ PolynomialQ@Together@uD,xD
PolyQ@u_,x_Symbol^n_D :=
If@PositiveIntegerQ@nD,
PolyQ@u,xD && HPolynomialQ@u,x^nD ÈÈ PolynomialQ@Together@uD,x^nDL,
If@AtomQ@nD,
PolynomialQ@u,x^nD && FreeQ@CoefficientList@u,x^nD,xD,
FalseDD ;
FreeQ@n,xD
PolyQ@u_,u_D :=
False
10 | Integration utility functions.m
BinomialQ[u,x]
H* If u is equivalent to an expression of the form a+b*x^n where n and b are not 0, *L
H* BinomialQ@u,xD returns True; else it returns False. *L
BinomialQ@u_,x_SymbolD :=
If@ListQ@uD,
Catch@Scan@Function@If@Not@BinomialQ@ð,xDD,Throw@FalseDDD,uD; TrueD,
ListQ@BinomialParts@u,xDDD
H* If u is equivalent to an expression of the form a+b*x^n, BinomialQ@u,x,nD returns True; else it returns False. *L
BinomialQ@u_,x_Symbol,n_D :=
If@ListQ@uD,
Catch@Scan@Function@If@Not@BinomialQ@ð,x,nDD,Throw@FalseDDD,uD; TrueD,
Function@ListQ@ðD && ð@@3DD===nD@BinomialParts@u,xDDD
TrinomialQ[u,x]
H* If u is equivalent to an expression of the form a+b*x^n+c*x^H2*nL where n, b and c are not 0, *L
H* TrinomialQ@u,xD returns True; else it returns False. *L
TrinomialQ@u_,x_SymbolD :=
If@ListQ@uD,
Catch@Scan@Function@If@Not@TrinomialQ@ð,xDD,Throw@FalseDDD,uD; TrueD,
ListQ@TrinomialParts@u,xDD && Not@QuadraticQ@u,xDD && Not@MatchQ@u,w_^2 ; BinomialQ@w,xDDDD
GeneralizedBinomialQ[u,x]
H* If u is equivalent to an expression of the form a*x^q+b*x^n where n, q and b are not 0, *L
H* GeneralizedBinomialQ@u,xD returns True; else it returns False. *L
GeneralizedBinomialQ@u_,x_SymbolD :=
If@ListQ@uD,
Catch@Scan@Function@If@Not@GeneralizedBinomialQ@ð,xDD,Throw@FalseDDD,uD; TrueD,
ListQ@GeneralizedBinomialParts@u,xDDD
GeneralizedTrinomialQ[u,x]
H* If u is equivalent to an expression of the form a*x^q+b*x^n+c*x^H2*n-qL where n, q, b and c are not 0, *L
H* GeneralizedTrinomialQ@u,xD returns True; else it returns False. *L
GeneralizedTrinomialQ@u_,x_SymbolD :=
If@ListQ@uD,
Catch@Scan@Function@If@Not@GeneralizedTrinomialQ@ð,xDD,Throw@FalseDDD,uD; TrueD,
ListQ@GeneralizedTrinomialParts@u,xDDD
Integration utility functions.m | 11
Expression form predicates
PosQ[u]
H* If u is not 0 and has a positive form, PosQ@uD returns True, else it returns False. *L
PosQ@u_D :=
PosAux@TogetherSimplify@uDD
PosAux@u_D :=
If@RationalQ@uD,
u>0,
If@NumberQ@uD,
If@ZeroQ@Re@uDD,
Im@uD>0,
Re@uD>0D,
If@NumericQ@uD,
With@8v=N@uD<,
If@ZeroQ@Re@vDD,
Im@vD>0,
Re@vD>0DD,
If@PowerQ@uD && OddQ@u@@2DDD,
PosAux@u@@1DDD,
If@ProductQ@uD,
If@PosAux@First@uDD,
PosAux@Rest@uDD,
Not@PosAux@Rest@uDDDD,
If@SumQ@uD,
PosAux@First@uDD,
TrueDDDDDD
NegQ[u]
NegQ@u_D :=
Not@PosQ@uDD && NonzeroQ@uD
12 | Integration utility functions.m
NiceSqrtQ[u]
NiceSqrtQ@u_D :=
Not@NegativeQ@uDD && NiceSqrtAuxQ@uD
NiceSqrtAuxQ@u_D :=
If@RationalQ@uD,
u>0,
If@PowerQ@uD,
EvenQ@u@@2DDD,
If@ProductQ@uD,
NiceSqrtAuxQ@First@uDD && NiceSqrtAuxQ@Rest@uDD,
If@SumQ@uD,
Function@NonsumQ@ðD && NiceSqrtAuxQ@ðDD @Simplify@uDD,
FalseDDDD
PerfectSquareQ[u]
H* If u is a rational number whose squareroot is rational or if u is of the form u1^n1 u2^n2 ...
and n1, n2, ... are even, PerfectSquareQ@uD returns True; else it returns False. *L
PerfectSquareQ@u_D :=
If@RationalQ@uD,
u>0 && u!=1 && RationalQ@Sqrt@uDD,
If@PowerQ@uD,
EvenQ@u@@2DDD,
If@ProductQ@uD,
PerfectSquareQ@First@uDD && PerfectSquareQ@Rest@uDD,
If@SumQ@uD,
Function@NonsumQ@ðD && PerfectSquareQ@ðDD @Simplify@uDD,
FalseDDDD
Simpler functions
SimplerQ[u,v]
H* If u is simpler than v, SimplerQ@u,vD returns True, else it returns False.
SimplerQ@u_,v_D :=
If@IntegerQ@uD,
If@IntegerQ@vD,
If@Abs@uD==Abs@vD,
v<0,
Abs@uD<Abs@vDD,
TrueD,
If@IntegerQ@vD,
False,
SimplerQ@u,uD returns False. *L
Integration utility functions.m | 13
False,
If@FractionQ@uD,
If@FractionQ@vD,
If@Denominator@uD==Denominator@vD,
SimplerQ@Numerator@uD,Numerator@vDD,
Denominator@uD<Denominator@vDD,
TrueD,
If@FractionQ@vD,
False,
If@HRe@uD===0 ÈÈ Re@uD===0.0L && HRe@vD===0 ÈÈ Re@vD===0.0L,
SimplerQ@Im@uD,Im@vDD,
If@ComplexNumberQ@uD,
If@ComplexNumberQ@vD,
If@Re@uD==Re@vD,
SimplerQ@Im@uD,Im@vDD,
SimplerQ@Re@uD,Re@vDDD,
FalseD,
If@NumberQ@uD,
If@NumberQ@vD,
OrderedQ@8u,v<D,
TrueD,
If@NumberQ@vD,
False,
If@AtomQ@uD,
If@AtomQ@vD,
OrderedQ@8u,v<D,
TrueD,
If@AtomQ@vD,
False,
If@Head@uD===Head@vD,
If@Length@uD==Length@vD,
Catch@Do@If@u@@iiDD===v@@iiDD,Null,Throw@SimplerQ@u@@iiDD,v@@iiDDDDD,8ii,Length@uD<D; FalseD,
Length@uD<Length@vDD,
If@LeafCount@uD<LeafCount@vD,
True,
If@LeafCount@vD<LeafCount@uD,
False,
Not@OrderedQ@8v,u<DDDDDDDDDDDDDDD
SimplerSqrtQ[u,v]
14 | Integration utility functions.m
H* If Rt@u,2D is simpler than Rt@v,2D, SimplerSqrtQ@u,vD returns True, else it returns False.
SimplerSqrtQ@u_,v_D :=
If@NegativeQ@vD && Not@NegativeQ@uDD,
True,
If@NegativeQ@uD && Not@NegativeQ@vDD,
False,
With@8sqrtu=Rt@u,2D,sqrtv=Rt@v,2D<,
If@IntegerQ@sqrtuD,
If@IntegerQ@sqrtvD,
sqrtu<sqrtv,
TrueD,
If@IntegerQ@sqrtvD,
False,
If@RationalQ@sqrtuD,
If@RationalQ@sqrtvD,
sqrtu<sqrtv,
TrueD,
If@RationalQ@sqrtvD,
False,
If@PosQ@uD,
If@PosQ@vD,
LeafCount@sqrtuD<LeafCount@sqrtvD,
TrueD,
If@PosQ@vD,
False,
If@LeafCount@sqrtuD<LeafCount@sqrtvD,
True,
If@LeafCount@sqrtvD<LeafCount@sqrtuD,
False,
Not@OrderedQ@8v,u<DDDDDDDDDDDDD
SimplerSqrtQ@u,uD returns False. *L
SumSimplerQ[u,v]
H* If u+v is simpler than u, SumSimplerQ@u,vD returns True, else it returns False. *L
H* If for every term w of v there is a term of u equal to n*w where n<-12, u+v will be simpler than u. *L
SumSimplerQ@u_,v_D :=
If@RationalQ@u,vD,
If@v==0,
False,
If@v>0,
u<-1,
u>=-vDD,
SumSimplerAuxQ@Expand@uD,Expand@vDDD
Integration utility functions.m | 15
SumSimplerAuxQ@u_,v_D :=
HRationalQ@First@vDD ÈÈ SumSimplerAuxQ@u,First@vDDL &&
HRationalQ@Rest@vDD ÈÈ SumSimplerAuxQ@u,Rest@vDDL ;
SumQ@vD
SumSimplerAuxQ@u_,v_D :=
SumSimplerAuxQ@First@uD,vD ÈÈ SumSimplerAuxQ@Rest@uD,vD ;
SumQ@uD
SumSimplerAuxQ@u_,v_D :=
v=!=0 &&
NonnumericFactors@uD===NonnumericFactors@vD &&
HNumericFactor@uDNumericFactor@vD<-12 ÈÈ NumericFactor@uDNumericFactor@vD==-12 && NumericFactor@uD<0L
SimplerIntegrandQ[u,v,x]
H* SimplerIntegrandQ@u,v,xD returns True iff u is simpler to integrate wrt x than v. *L
SimplerIntegrandQ@u_,v_,x_SymbolD :=
Module@8lst=CancelCommonFactors@u,vD,u1,v1<,
u1=lst@@1DD;
v1=lst@@2DD;
H*If@Head@u1D===Head@v1D && Length@u1D==Length@v1D==1,
SimplerIntegrandQ@u1@@1DD,v1@@1DD,xD, *L
If@LeafCount@u1D<34*LeafCount@v1D,
True,
If@RationalFunctionQ@u1,xD,
If@RationalFunctionQ@v1,xD,
Apply@Plus,RationalFunctionExponents@u1,xDD<Apply@Plus,RationalFunctionExponents@v1,xDD,
TrueD,
FalseDDD
H* CancelCommonFactors@u,vD returns 8u',v'< are the noncommon factors of u and v respectively. *L
CancelCommonFactors@u_,v_D :=
If@ProductQ@uD,
If@ProductQ@vD,
If@MemberQ@v,First@uDD,
CancelCommonFactors@Rest@uD,DeleteCases@v,First@uD,1,1DD,
Function@8First@uD*ð@@1DD,ð@@2DD<D@CancelCommonFactors@Rest@uD,vDDD,
If@MemberQ@u,vD,
8DeleteCases@u,v,1,1D,1<,
8u,v<DD,
If@ProductQ@vD,
If@MemberQ@v,uD,
81,DeleteCases@v,u,1,1D<,
8u,v<D,
8u,v<DD
16 | Integration utility functions.m
Parts functions
BinomialParts[u,x]
H* u is a binomial. BinomialDegree@u,xD returns the degree of x in u. *L
BinomialDegree@u_,x_SymbolD :=
BinomialParts@u,xD@@3DD
H* If u@xD is equivalent to an expression of the form a+b*x^n where n!=0 and b!=0,
BinomialParts@u,xD returns the list 8a,b,n<; else it returns False. *L
BinomialParts@u_,x_SymbolD :=
If@PolynomialQ@u,xD,
If@Exponent@u,xD>0,
With@8lst=Exponent@u,x,ListD<,
If@Length@lstD==1,
80, Coefficient@u,x,Exponent@u,xDD, Exponent@u,xD<,
If@Length@lstD==2 && lst@@1DD==0,
8Coefficient@u,x,0D, Coefficient@u,x,Exponent@u,xDD, Exponent@u,xD<,
FalseDDD,
FalseD,
If@PowerQ@uD,
If@u@@1DD===x && FreeQ@u@@2DD,xD,
80,1,u@@2DD<,
FalseD,
If@ProductQ@uD,
If@FreeQ@First@uD,xD,
With@8lst2=BinomialParts@Rest@uD,xD<,
If@AtomQ@lst2D,
False,
8First@uD*lst2@@1DD,First@uD*lst2@@2DD,lst2@@3DD<DD,
If@FreeQ@Rest@uD,xD,
With@8lst1=BinomialParts@First@uD,xD<,
If@AtomQ@lst1D,
False,
8Rest@uD*lst1@@1DD,Rest@uD*lst1@@2DD,lst1@@3DD<DD,
With@8lst1=BinomialParts@First@uD,xD<,
If@AtomQ@lst1D,
False,
With@8lst2=BinomialParts@Rest@uD,xD<,
If@AtomQ@lst2D,
False,
With@8a=lst1@@1DD,b=lst1@@2DD,m=lst1@@3DD, c=lst2@@1DD,d=lst2@@2DD,n=lst2@@3DD<,
If@ZeroQ@aD,
If@ZeroQ@cD,
80,b*d,m+n<,
If@ZeroQ@m+nD,
,
Integration utility functions.m | 17
If@ZeroQ@m+nD,
8b*d,b*c,m<,
FalseDD,
If@ZeroQ@cD,
If@ZeroQ@m+nD,
8b*d,a*d,n<,
FalseD,
If@EqQ@m,nD && ZeroQ@a*d+b*cD,
8a*c,b*d,2*m<,
FalseDDDDDDDDDD,
If@SumQ@uD,
If@FreeQ@First@uD,xD,
With@8lst2=BinomialParts@Rest@uD,xD<,
If@AtomQ@lst2D,
False,
8First@uD+lst2@@1DD,lst2@@2DD,lst2@@3DD<DD,
If@FreeQ@Rest@uD,xD,
With@8lst1=BinomialParts@First@uD,xD<,
If@AtomQ@lst1D,
False,
8Rest@uD+lst1@@1DD,lst1@@2DD,lst1@@3DD<DD,
With@8lst1=BinomialParts@First@uD,xD<,
If@AtomQ@lst1D,
False,
With@8lst2=BinomialParts@Rest@uD,xD<,
If@AtomQ@lst2D,
False,
If@EqQ@lst1@@3DD,lst2@@3DDD,
8lst1@@1DD+lst2@@1DD,lst1@@2DD+lst2@@2DD,lst1@@3DD<,
FalseDDDDDDD,
FalseDDDD
TrinomialParts[u,x]
H* If u is equivalent to a trinomial of the form a + b*x^n + c*x^H2*nL where n!=0, b!=0 and c!=0,
TrinomialDegree@u,xD returns n. *L
TrinomialDegree@u_,x_SymbolD :=
TrinomialParts@u,xD@@4DD
H* If u is equivalent to a trinomial of the form a + b*x^n + c*x^H2*nL where n!=0, b!=0 and c!=0,
TrinomialParts@u,xD returns the list 8a,b,c,n<; else it returns False. *L
TrinomialParts@u_,x_SymbolD :=
If@PolynomialQ@u,xD,
With@8lst=CoefficientList@u,xD<,
If@Length@lstD<3 ÈÈ EvenQ@Length@lstDD ÈÈ ZeroQ@lst@@HLength@lstD+1L2DDD,
False,
Catch@
Scan@Function@If@ZeroQ@ðD,Null,Throw@FalseDDD,Drop@Drop@Drop@lst,8HLength@lstD+1L2<D,1D,-1DD;
DDD,
18 | Integration utility functions.m
Scan@Function@If@ZeroQ@ðD,Null,Throw@FalseDDD,Drop@Drop@Drop@lst,8HLength@lstD+1L2<D,1D,-1DD;
8First@lstD,lst@@HLength@lstD+1L2DD,Last@lstD,HLength@lstD-1L2<DDD,
If@PowerQ@uD,
If@EqQ@u@@2DD,2D,
With@8lst=BinomialParts@u@@1DD,xD<,
If@AtomQ@lstD ÈÈ ZeroQ@lst@@1DDD,
False,
8lst@@1DD^2,2*lst@@1DD*lst@@2DD,lst@@2DD^2,lst@@3DD<DD,
FalseD,
If@ProductQ@uD,
If@FreeQ@First@uD,xD,
With@8lst2=TrinomialParts@Rest@uD,xD<,
If@AtomQ@lst2D,
False,
8First@uD*lst2@@1DD,First@uD*lst2@@2DD,First@uD*lst2@@3DD,lst2@@4DD<DD,
If@FreeQ@Rest@uD,xD,
With@8lst1=TrinomialParts@First@uD,xD<,
If@AtomQ@lst1D,
False,
8Rest@uD*lst1@@1DD,Rest@uD*lst1@@2DD,Rest@uD*lst1@@3DD,lst1@@4DD<DD,
With@8lst1=BinomialParts@First@uD,xD<,
If@AtomQ@lst1D,
False,
With@8lst2=BinomialParts@Rest@uD,xD<,
If@AtomQ@lst2D,
False,
With@8a=lst1@@1DD,b=lst1@@2DD,m=lst1@@3DD, c=lst2@@1DD,d=lst2@@2DD,n=lst2@@3DD<,
If@EqQ@m,nD && NonzeroQ@a*d+b*cD,
8a*c,a*d+b*c,b*d,m<,
FalseDDDDDDDD,
If@SumQ@uD,
If@FreeQ@First@uD,xD,
With@8lst2=TrinomialParts@Rest@uD,xD<,
If@AtomQ@lst2D,
False,
8First@uD+lst2@@1DD,lst2@@2DD,lst2@@3DD,lst2@@4DD<DD,
If@FreeQ@Rest@uD,xD,
With@8lst1=TrinomialParts@First@uD,xD<,
If@AtomQ@lst1D,
False,
8Rest@uD+lst1@@1DD,lst1@@2DD,lst1@@3DD,lst1@@4DD<DD,
With@8lst1=TrinomialParts@First@uD,xD<,
If@AtomQ@lst1D,
With@8lst3=BinomialParts@First@uD,xD<,
If@AtomQ@lst3D,
False,
With@8lst2=TrinomialParts@Rest@uD,xD<,
Integration utility functions.m | 19
With@8lst2=TrinomialParts@Rest@uD,xD<,
If@AtomQ@lst2D,
With@8lst4=BinomialParts@Rest@uD,xD<,
If@AtomQ@lst4D,
False,
If@EqQ@lst3@@3DD,2*lst4@@3DDD,
8lst3@@1DD+lst4@@1DD,lst4@@2DD,lst3@@2DD,lst4@@3DD<,
If@EqQ@lst4@@3DD,2*lst3@@3DDD,
8lst3@@1DD+lst4@@1DD,lst3@@2DD,lst4@@2DD,lst3@@3DD<,
FalseDDDD,
If@EqQ@lst3@@3DD,lst2@@4DDD && NonzeroQ@lst3@@2DD+lst2@@2DDD,
8lst3@@1DD+lst2@@1DD,lst3@@2DD+lst2@@2DD,lst2@@3DD,lst2@@4DD<,
If@EqQ@lst3@@3DD,2*lst2@@4DDD && NonzeroQ@lst3@@2DD+lst2@@3DDD,
8lst3@@1DD+lst2@@1DD,lst2@@2DD,lst3@@2DD+lst2@@3DD,lst2@@4DD<,
FalseDDDDDD,
With@8lst2=TrinomialParts@Rest@uD,xD<,
If@AtomQ@lst2D,
With@8lst4=BinomialParts@Rest@uD,xD<,
If@AtomQ@lst4D,
False,
If@EqQ@lst4@@3DD,lst1@@4DDD && NonzeroQ@lst1@@2DD+lst4@@2DDD,
8lst1@@1DD+lst4@@1DD,lst1@@2DD+lst4@@2DD,lst1@@3DD,lst1@@4DD<,
If@EqQ@lst4@@3DD,2*lst1@@4DDD && NonzeroQ@lst1@@3DD+lst4@@2DDD,
8lst1@@1DD+lst4@@1DD,lst1@@2DD,lst1@@3DD+lst4@@2DD,lst1@@4DD<,
FalseDDDD,
If@EqQ@lst1@@4DD,lst2@@4DDD && NonzeroQ@lst1@@2DD+lst2@@2DDD && NonzeroQ@lst1@@3DD+lst2@@3DDD,
8lst1@@1DD+lst2@@1DD,lst1@@2DD+lst2@@2DD,lst1@@3DD+lst2@@3DD,lst1@@4DD<,
FalseDDDDDDD,
FalseDDDD
GeneralizedBinomialParts[u,x]
H* If u is equivalent to a generalized binomial of the form a*x^q + b*x^n where a, b, n, and q not equal 0,
GeneralizedBinomialDegree@u,xD returns n-q. *L
GeneralizedBinomialDegree@u_,x_SymbolD :=
Function@ð@@3DD-ð@@4DDD@GeneralizedBinomialParts@u,xDD
20 | Integration utility functions.m
H* If u is equivalent to a generalized binomial of the form a*x^q + b*x^n where a, b, n, and q not equal 0,
GeneralizedBinomialParts@u,xD returns the list 8a,b,n,q<; else it returns False. *L
GeneralizedBinomialParts@a_.*x_^q_.+b_.*x_^n_.,x_SymbolD :=
8a,b,n,q< ;
FreeQ@8a,b,n,q<,xD && PosQ@n-qD
GeneralizedBinomialParts@a_*u_,x_SymbolD :=
With@8lst=GeneralizedBinomialParts@u,xD<,
8a*lst@@1DD, a*lst@@2DD, lst@@3DD, lst@@4DD< ;
ListQ@lstDD ;
FreeQ@a,xD
GeneralizedBinomialParts@x_^m_.*u_,x_SymbolD :=
With@8lst=GeneralizedBinomialParts@u,xD<,
8lst@@1DD, lst@@2DD, m+lst@@3DD, m+lst@@4DD< ;
ListQ@lstD && NonzeroQ@m+lst@@3DDD && NonzeroQ@m+lst@@4DDDD ;
FreeQ@m,xD
GeneralizedBinomialParts@x_^m_.*u_,x_SymbolD :=
With@8lst=BinomialParts@u,xD<,
8lst@@1DD, lst@@2DD, m+lst@@3DD, m< ;
ListQ@lstD && NonzeroQ@m+lst@@3DDDD ;
FreeQ@m,xD
GeneralizedBinomialParts@u_,x_SymbolD :=
False
GeneralizedTrinomialParts[u,x]
H* If u is equivalent to a generalized trinomial of the form a*x^q + b*x^n + c*x^H2*n-qL where n!=0, q!=0, b!=0 and c!=0,
GeneralizedTrinomialDegree@u,xD returns n-q. *L
GeneralizedTrinomialDegree@u_,x_SymbolD :=
Function@ð@@4DD-ð@@5DDD@GeneralizedTrinomialParts@u,xDD
Integration utility functions.m | 21
H* If u is equivalent to a generalized trinomial of the form a*x^q + b*x^n + c*x^H2*n-qL where n!=0, q!=0, b!=0 and c!=0,
GeneralizedTrinomialParts@u,xD returns the list 8a,b,c,n,q<; else it returns False. *L
GeneralizedTrinomialParts@a_.*x_^q_.+b_.*x_^n_.+c_.*x_^r_.,x_SymbolD :=
8a,b,c,n,q< ;
FreeQ@8a,b,c,n,q<,xD && EqQ@r,2*n-qD
GeneralizedTrinomialParts@a_*u_,x_SymbolD :=
With@8lst=GeneralizedTrinomialParts@u,xD<,
8a*lst@@1DD, a*lst@@2DD, a*lst@@3DD, lst@@4DD, lst@@5DD< ;
ListQ@lstDD ;
FreeQ@a,xD
GeneralizedTrinomialParts@x_^m_.*u_,x_SymbolD :=
With@8lst=GeneralizedTrinomialParts@u,xD<,
8lst@@1DD, lst@@2DD, lst@@3DD, m+lst@@4DD, m+lst@@5DD< ;
ListQ@lstD && NonzeroQ@m+lst@@4DDD && NonzeroQ@m+lst@@5DDDD ;
FreeQ@m,xD
GeneralizedTrinomialParts@x_^m_.*u_,x_SymbolD :=
With@8lst=TrinomialParts@u,xD<,
8lst@@1DD, lst@@2DD, lst@@3DD, m+lst@@4DD, m< ;
ListQ@lstD && NonzeroQ@m+lst@@4DDDD ;
FreeQ@m,xD
GeneralizedTrinomialParts@u_,x_SymbolD :=
False
22 | Integration utility functions.m
Selection functions
IntPart[u]
H* IntPart@uD returns the sum of the integer terms of u. *L
IntPart@n_*u_D :=
n*IntPart@uD ;
IntegerQ@nD
IntPart@u_D :=
If@IntegerQ@uD,
u,
If@FractionQ@uD,
IntegerPart@uD,
If@SumQ@uD,
Map@IntPart,uD,
0DDD
FracPart[u]
H* IntPart@uD returns the sum of the non-integer terms of u. *L
FracPart@n_*u_D :=
n*FracPart@uD ;
IntegerQ@nD
FracPart@u_D :=
If@IntegerQ@uD,
0,
If@FractionQ@uD,
FractionalPart@uD,
If@SumQ@uD,
Map@FracPart,uD,
uDDD
Integration utility functions.m | 23
NumericFactor[u]
H* NumericFactor@uD returns the real numeric factor of u. *L
NumericFactor@u_D :=
If@NumberQ@uD,
If@ZeroQ@Im@uDD,
u,
If@ZeroQ@Re@uDD,
Im@uD,
1DD,
If@PowerQ@uD,
If@RationalQ@u@@1DDD && FractionQ@u@@2DDD,
If@u@@2DD>0,
1Denominator@u@@1DDD,
1Denominator@1u@@1DDDD,
1D,
If@ProductQ@uD,
Map@NumericFactor,uD,
If@SumQ@uD,
If@LeafCount@uD<50,
H* Eliminate this kludge! *L
Function@If@SumQ@ðD, 1, NumericFactor@ðDDD@ContentFactor@uDD,
With@8m=NumericFactor@First@uDD,n=NumericFactor@Rest@uDD<,
If@m<0 && n<0,
-GCD@-m,-nD,
GCD@m,nDDDD,
1DDDD
24 | Integration utility functions.m
H* NonnumericFactors@uD returns the product of the factors of u that are not real numbers. *L
NonnumericFactors@u_D :=
If@NumberQ@uD,
If@ZeroQ@Im@uDD,
1,
If@ZeroQ@Re@uDD,
I,
uDD,
If@PowerQ@uD,
If@RationalQ@u@@1DDD && FractionQ@u@@2DDD,
uNumericFactor@uD,
uD,
If@ProductQ@uD,
Map@NonnumericFactors,uD,
If@SumQ@uD,
If@LeafCount@uD<50,
H* Eliminate this kludge! *L
Function@If@SumQ@ðD, u, NonnumericFactors@ðDDD@ContentFactor@uDD,
With@8n=NumericFactor@uD<,
Map@Function@ðnD,uDDD,
uDDDD
RemoveContent[u,x]
H* RemoveContent@u,xD returns u with the content free of x removed. *L
RemoveContent@u_,x_SymbolD :=
With@8v=NonfreeFactors@u,xD<,
With@8w=Together@vD<,
If@EqQ@FreeFactors@w,xD,1D,
RemoveContentAux@v,xD,
RemoveContentAux@NonfreeFactors@w,xD,xDDDD
RemoveContentAux@a_^m_*u_.+b_*v_.,x_SymbolD :=
If@m>1,
RemoveContentAux@a^Hm-1L*u-v,xD,
RemoveContentAux@u-a^H1-mL*v,xDD ;
IntegersQ@a,bD && a+b==0 && RationalQ@mD
RemoveContentAux@a_^m_.*u_.+a_^n_.*v_.,x_SymbolD :=
RemoveContentAux@u+a^Hn-mL*v,xD ;
FreeQ@a,xD && RationalQ@m,nD && n-m>=0
RemoveContentAux@a_^m_.*u_.+a_^n_.*v_.+a_^p_.*w_.,x_SymbolD :=
RemoveContentAux@u+a^Hn-mL*v+a^Hp-mL*w,xD ;
FreeQ@a,xD && RationalQ@m,n,pD && n-m>=0 && p-m>=0
Integration utility functions.m | 25
RemoveContentAux@u_,x_SymbolD :=
If@SumQ@uD && NegQ@First@uDD,
-u,
uD
FreeFactors[u,x]
H* FreeFactors@u,xD returns the product of the factors of u free of x. *L
FreeFactors@u_,x_D :=
If@ProductQ@uD,
Map@Function@If@FreeQ@ð,xD,ð,1DD,uD,
If@FreeQ@u,xD,
u,
1DD
NonfreeFactors[u,x]
H* NonfreeFactors@u,xD returns the product of the factors of u not free of x. *L
NonfreeFactors@u_,x_D :=
If@ProductQ@uD,
Map@Function@If@FreeQ@ð,xD,1,ðDD,uD,
If@FreeQ@u,xD,
1,
uDD
FreeTerms[u,x]
H* FreeTerms@u,xD returns the sum of the terms of u free of x. *L
FreeTerms@u_,x_D :=
If@SumQ@uD,
Map@Function@If@FreeQ@ð,xD,ð,0DD,uD,
If@FreeQ@u,xD,
u,
0DD
NonfreeTerms[u,x]
H* NonfreeTerms@u,xD returns the sum of the terms of u not free of x. *L
NonfreeTerms@u_,x_D :=
If@SumQ@uD,
Map@Function@If@FreeQ@ð,xD,0,ðDD,uD,
If@FreeQ@u,xD,
0,
uDD
26 | Integration utility functions.m
Polynomial functions
Expon@expr_,form_D :=
Exponent@Together@exprD,formD
Expon@expr_,form_,h_D :=
Exponent@Together@exprD,form,hD
Coeff@expr_,form_D :=
Coefficient@Together@exprD,formD
Coeff@expr_,form_,n_D :=
Block@8coef1=Coefficient@expr,form,nD,coef2=Coefficient@Together@exprD,form,nD<,
If@Simplify@coef1-coef2D===0,
coef1,
coef2DD
LeadTerm[u]
LeadTerm@u_D :=
If@SumQ@uD,
First@uD,
uD
RemainingTerms[u]
RemainingTerms@u_D :=
If@SumQ@uD,
Rest@uD,
0D
LeadFactor[u]
H* LeadFactor@uD returns the leading factor of u. *L
LeadFactor@u_D :=
If@ProductQ@uD,
LeadFactor@First@uDD,
If@ComplexNumberQ@uD && Re@uD===0,
If@Im@uD===1,
u,
LeadFactor@Im@uDDD,
uDD
Integration utility functions.m | 27
RemainingFactors[u]
H* RemainingFactors@uD returns the remaining factors of u. *L
RemainingFactors@u_D :=
If@ProductQ@uD,
RemainingFactors@First@uDD*Rest@uD,
If@ComplexNumberQ@uD && Re@uD===0,
If@Im@uD===1,
1,
I*RemainingFactors@Im@uDDD,
1DD
LeadBase[u]
H* LeadBase@uD returns the base of the leading factor of u. *L
LeadBase@u_D :=
With@8v=LeadFactor@uD<,
If@PowerQ@vD,
v@@1DD,
vDD
LeadDegree[u]
H* LeadDegree@uD returns the degree of the leading factor of u. *L
LeadDegree@u_D :=
With@8v=LeadFactor@uD<,
If@PowerQ@vD,
v@@2DD,
1DD
Multinomial functions
Multinomial Recognizer functions
è LinearQ[u,x] returns True iff u is a polynomial of degree 1
LinearQ@u_,x_SymbolD :=
PolyQ@u,x,1D
è PowerOfLinearQ[u,x] returns True iff u is equivalent to an expression of the form (a+b x)^m.
PowerOfLinearQ@u_^m_.,x_SymbolD :=
FreeQ@m,xD && PolynomialQ@u,xD && If@IntegerQ@mD, MatchQ@FactorSquareFree@uD, w_^n_. ; FreeQ@n,xD && LinearQ@w,xDD, LinearQ@u,
D
28 | Integration utility functions.m
è QuadraticQ[u,x] returns True iff u is a polynomial of degree 2 and not a monomial of the form a x^2.
QuadraticQ@u_,x_SymbolD :=
If@ListQ@uD,
Catch@Scan@Function@If@Not@QuadraticQ@ð,xDD,Throw@FalseDDD,uD; TrueD,
PolyQ@u,x,2D && Not@Coefficient@u,x,0D===0 && Coefficient@u,x,1D===0DD
è LinearPairQ[u,v,x] returns True iff u and v are linear not equal x but u/v is a constant wrt x.
LinearPairQ@u_,v_,x_SymbolD :=
LinearQ@u,xD && LinearQ@v,xD && NonzeroQ@u-xD && ZeroQ@Coefficient@u,x,0D*Coefficient@v,x,1D-Coefficient@u,x,1D*Coefficient@v,x
è If u is of the form a*x^n where n!=0 and a!=0, MonomialQ[u,x] returns True; else False.
MonomialQ@u_,x_SymbolD :=
If@ListQ@uD,
Catch@Scan@Function@If@MonomialQ@ð,xD,Null,Throw@FalseDDD,uD; TrueD,
MatchQ@u, a_.*x^n_. ; FreeQ@8a,n<,xDDD
è f u[x] is a sum and each term is free of x or an expression of the form a*x^n, MonomialSumQ[u,x] returns True; else it returns False.
MonomialSumQ@u_,x_SymbolD :=
SumQ@uD && Catch@
Scan@Function@If@FreeQ@ð,xD ÈÈ MonomialQ@ð,xD, Null, Throw@FalseDDD,uD;
TrueD
è u is sum whose terms are monomials. MinimumExponent[u,x] returns the exponent of the term having the smallest exponent.
MinimumMonomialExponent@u_,x_SymbolD :=
Module@8n=MonomialExponent@First@uD,xD<,
Scan@Function@If@PosQ@n-MonomialExponent@ð,xDD,n=MonomialExponent@ð,xDDD,uD;
nD
è u is a monomial. MonomialExponent[u,x] returns the exponent of x in u.
MonomialExponent@a_.*x_^n_.,x_SymbolD :=
n ;
FreeQ@8a,n<,xD
D
Integration utility functions.m | 29
Multinomial Match functions
è LinearMatchQ[u,x] returns True iff u matches patterns of the form a+b x where a and b are free of x.
LinearMatchQ@u_,x_SymbolD :=
If@ListQ@uD,
Catch@Scan@Function@If@Not@LinearMatchQ@ð,xDD,Throw@FalseDDD,uD; TrueD,
MatchQ@u, a_.+b_.*x ; FreeQ@8a,b<,xDDD
è PowerOfLinearMatchQ[u,x] returns True iff u matches patterns of the form (a+b x)^m where a, b and m are free of x.
PowerOfLinearMatchQ@u_,x_SymbolD :=
If@ListQ@uD,
Catch@Scan@Function@If@Not@PowerOfLinearMatchQ@ð,xDD,Throw@FalseDDD,uD; TrueD,
MatchQ@u, Ha_.+b_.*xL^m_. ; FreeQ@8a,b,m<,xDDD
è QuadraticMatchQ[u,x] returns True iff u matches patterns of the form a+b x+c x^2 or a+c x^2 where a, b and c are free of x.
QuadraticMatchQ@u_,x_SymbolD :=
If@ListQ@uD,
Catch@Scan@Function@If@Not@QuadraticMatchQ@ð,xDD,Throw@FalseDDD,uD; TrueD,
MatchQ@u, a_.+b_.*x+c_.*x^2 ; FreeQ@8a,b,c<,xDD ÈÈ MatchQ@u, a_.+c_.*x^2 ; FreeQ@8a,c<,xDDD
è CubicMatchQ[u,x] returns True iff u matches patterns of the form a+b x+c x^2+d x^3, a+b x+d x^3, a+c x^2+d x^3 or a+d x^3 where a, b, c and d are free of x.
CubicMatchQ@u_,x_SymbolD :=
If@ListQ@uD,
Catch@Scan@Function@If@Not@CubicMatchQ@ð,xDD,Throw@FalseDDD,uD; TrueD,
MatchQ@u, a_.+b_.*x+c_.*x^2+d_.*x^3 ; FreeQ@8a,b,c,d<,xDD ÈÈ
MatchQ@u, a_.+b_.*x+d_.*x^3 ; FreeQ@8a,b,d<,xDD ÈÈ
MatchQ@u, a_.+c_.*x^2+d_.*x^3 ; FreeQ@8a,c,d<,xDD ÈÈ
MatchQ@u, a_.+d_.*x^3 ; FreeQ@8a,d<,xDDD
è BinomialMatchQ[u,x] returns True iff u matches patterns of the form a+b x^n where a, b and n are free of x.
BinomialMatchQ@u_,x_SymbolD :=
If@ListQ@uD,
Catch@Scan@Function@If@Not@BinomialMatchQ@ð,xDD,Throw@FalseDDD,uD; TrueD,
MatchQ@u, a_.+b_.*x^n_. ; FreeQ@8a,b,n<,xDDD
30 | Integration utility functions.m
è GeneralizedBinomialMatchQ[u,x] returns True iff u matches patterns of the form a x^q+b x^n where a, b, n and q are free of x.
GeneralizedBinomialMatchQ@u_,x_SymbolD :=
If@ListQ@uD,
Catch@Scan@Function@If@Not@GeneralizedBinomialMatchQ@ð,xDD,Throw@FalseDDD,uD; TrueD,
MatchQ@u, a_.*x^q_.+b_.*x^n_. ; FreeQ@8a,b,n,q<,xDDD
è TrinomialMatchQ[u,x] returns True iff u matches patterns of the form a+b x+c x^n or a+c x^(2 n) where a, b, c and n are free of x.
TrinomialMatchQ@u_,x_SymbolD :=
If@ListQ@uD,
Catch@Scan@Function@If@Not@TrinomialMatchQ@ð,xDD,Throw@FalseDDD,uD; TrueD,
MatchQ@u, a_.+b_.*x^n_.+c_.*x^j_. ; FreeQ@8a,b,c,n<,xD && ZeroQ@j-2*nDDD
è GeneralizedTrinomialMatchQ[u,x] returns True iff u matches patterns of the form a x^q+b x^n+c x^(2 n-q) where a, b, c, n and q are free of x.
GeneralizedTrinomialMatchQ@u_,x_SymbolD :=
If@ListQ@uD,
Catch@Scan@Function@If@Not@GeneralizedTrinomialMatchQ@ð,xDD,Throw@FalseDDD,uD; TrueD,
MatchQ@u, a_.*x^q_.+b_.*x^n_.+c_.*x^r_. ; FreeQ@8a,b,c,n,q<,xD && ZeroQ@r-H2*n-qLDDD
è QuotientOfLinearsMatchQ[u,x] returns True iff u matches patterns of the form e (a+b x)/(c+d x) where a, b, c and d are free of x.
QuotientOfLinearsMatchQ@u_,x_SymbolD :=
IfAListQ@uD,
Catch@Scan@Function@If@Not@QuotientOfLinearsMatchQ@ð,xDD,Throw@FalseDDD,uD; TrueD,
MatchQAu, e_.*Ha_.+b_.*xLHc_.+d_.*xL ; FreeQ@8a,b,c,d,e<,xDEE
Polynomial Terms functions
H* If u HxL is an expression of the form a*x^n where n is zero or a positive integer,
PolynomialTermQ@u,xD returns True; else it returns False. *L
PolynomialTermQ@u_,x_SymbolD :=
FreeQ@u,xD ÈÈ MatchQ@u,a_.*x^n_. ; FreeQ@a,xD && IntegerQ@nD && n>0D
H* u HxL is a sum. PolynomialTerms@u,xD returns the sum of the polynomial terms of u HxL. *L
PolynomialTerms@u_,x_SymbolD :=
Map@Function@If@PolynomialTermQ@ð,xD,ð,0DD,uD
Integration utility functions.m | 31
H* u HxL is a sum. NonpolynomialTerms@u,xD returns the sum of the nonpolynomial terms of u HxL. *L
NonpolynomialTerms@u_,x_SymbolD :=
Map@Function@If@PolynomialTermQ@ð,xD,0,ðDD,uD
PseudoBinomial Routines
H* If u is equivalent to a polynomial of the form a+b*Hc+d*xL^n where nÎZ and n>2,
PseudoBinomialQ@u,xD returns True; else it returns False. *L
PseudoBinomialQ@u_,x_SymbolD :=
ListQ@PseudoBinomialParts@u,xDD
H* If u is equivalent to a polynomial of the form a+b*He+f*xL^n and v to a polynomial of the form c+d*He+f*xL^n where nÎZ and n>2
PseudoBinomialPairQ@u,v,xD returns True; else it returns False. *L
PseudoBinomialPairQ@u_,v_,x_SymbolD :=
With@8lst1=PseudoBinomialParts@u,xD<,
If@AtomQ@lst1D,
False,
With@8lst2=PseudoBinomialParts@v,xD<,
If@AtomQ@lst2D,
False,
Drop@lst1,2D===Drop@lst2,2DDDDD
H* u is pseudo-binomial in x, NormalizePseudoBinomial@u,xD returns u in the form a+b*Hc+d*xL^n. *L
NormalizePseudoBinomial@u_,x_SymbolD :=
With@8lst=PseudoBinomialParts@u,xD<,
lst@@1DD+lst@@2DD*Hlst@@3DD+lst@@4DD*xL^lst@@5DDD
H* If u is equivalent to a polynomial of the form a+b*Hc+d*xL^n where nÎZ and n>2,
PseudoBinomialParts@u,xD returns the list 8a,b,c,d,n<; else it returns False. *L
PseudoBinomialParts@u_,x_SymbolD :=
If@PolynomialQ@u,xD && Expon@u,xD>2,
Module@8a,c,d,n<,
n=Expon@u,xD;
d=Rt@Coefficient@u,x,nD,nD;
c=Coefficient@u,x,n-1DHn*d^Hn-1LL;
a=Simplify@u-Hc+d*xL^nD;
If@NonzeroQ@aD && FreeQ@a,xD,
8a,1,c,d,n<,
FalseDD,
FalseD
32 | Integration utility functions.m
Perfect Power Test Function
H* If u HxL is equivalent to a polynomial raised to an integer power greater than 1,
PerfectPowerTest@u,xD returns u HxL as an expanded polynomial raised to the power;
else it returns False. *L
PerfectPowerTest@u_,x_SymbolD :=
If@PolynomialQ@u,xD,
Module@8lst=FactorSquareFreeList@uD,gcd=0,v=1<,
If@lst@@1DD===81,1<,
lst=Rest@lstDD;
Scan@Function@gcd=GCD@gcd,ð@@2DDDD,lstD;
If@gcd>1,
Scan@Function@v=v*ð@@1DD^Hð@@2DDgcdLD,lstD;
Expand@vD^gcd,
FalseDD,
FalseD
Square Free Factor Test Function
H* If u HxL can be square free factored, SquareFreeFactorTest@u,xD returns u HxL in
factored form; else it returns False. *L
H* SquareFreeFactorTest@u_,x_SymbolD :=
If@PolynomialQ@u,xD,
With@8v=FactorSquareFree@uD<,
If@PowerQ@vD ÈÈ ProductQ@vD,
v,
FalseDD,
FalseD *L
Rational function functions
RationalFunctionQ
H* If u is a rational function of x, RationalFunctionQ@u,xD returns True; else it returns False. *L
RationalFunctionQ@u_,x_SymbolD :=
If@AtomQ@uD ÈÈ FreeQ@u,xD,
True,
If@IntegerPowerQ@uD,
RationalFunctionQ@u@@1DD,xD,
If@ProductQ@uD ÈÈ SumQ@uD,
Catch@Scan@Function@If@Not@RationalFunctionQ@ð,xDD,Throw@FalseDDD,uD;TrueD,
FalseDDD
Integration utility functions.m | 33
RationalFunctionFactors
H* RationalFunctionFactors@u,xD returns the product of the factors of u that are rational functions of x. *L
RationalFunctionFactors@u_,x_SymbolD :=
If@ProductQ@uD,
Map@Function@If@RationalFunctionQ@ð,xD,ð,1DD,uD,
If@RationalFunctionQ@u,xD,
u,
1DD
NonrationalFunctionFactors
H* NonrationalFunctionFactors@u,xD returns the product of the factors of u that are not rational functions of x. *L
NonrationalFunctionFactors@u_,x_SymbolD :=
If@ProductQ@uD,
Map@Function@If@RationalFunctionQ@ð,xD,1,ðDD,uD,
If@RationalFunctionQ@u,xD,
1,
uDD
RationalFunctionExponents
H* u is a polynomial or rational function of x. *L
H* RationalFunctionExponents@u,xD returns a list of the exponent of the *L
H* numerator of u and the exponent of the denominator of u. *L
RationalFunctionExponents@u_,x_SymbolD :=
If@PolynomialQ@u,xD,
8Exponent@u,xD,0<,
If@IntegerPowerQ@uD,
If@u@@2DD>0,
u@@2DD*RationalFunctionExponents@u@@1DD,xD,
H-u@@2DDL*Reverse@RationalFunctionExponents@u@@1DD,xDDD,
If@ProductQ@uD,
RationalFunctionExponents@First@uD,xD+RationalFunctionExponents@Rest@uD,xD,
If@SumQ@uD,
With@8v=Together@uD<,
If@SumQ@vD,
Module@8lst1,lst2<,
lst1=RationalFunctionExponents@First@uD,xD;
lst2=RationalFunctionExponents@Rest@uD,xD;
8Max@lst1@@1DD+lst2@@2DD,lst2@@1DD+lst1@@2DDD,lst1@@2DD+lst2@@2DD<D,
RationalFunctionExponents@v,xDDD,
80,0<DDDD
34 | Integration utility functions.m
RationalFunctionExpand
H* u is a polynomial or rational function of x. *L
H* RationalFunctionExpand@u,xD returns the expansion of the factors of u that are rational functions times the other factors. *L
RationalFunctionExpand@u_*v_^n_,x_SymbolD :=
With@8w=RationalFunctionExpand@u,xD<,
If@SumQ@wD,
Map@Function@ð*v^nD,wD,
w*v^nDD ;
FractionQ@nD && v=!=x
RationalFunctionExpand@u_,x_SymbolD :=
ModuleA8v,w<,
v=ExpandIntegrand@u,xD;
IfAv=!=u && NotAMatchQAu, x^m_.*Hc_+d_.*xL^p_Ha_+b_.*x^n_L ; FreeQ@8a,b,c,d,p<,xD && IntegersQ@m,nD && m==n-1EE,
v,
v=ExpandIntegrand@RationalFunctionFactors@u,xD,xD;
w=NonrationalFunctionFactors@u,xD;
If@SumQ@vD,
Map@Function@ð*wD,vD,
v*wDEE
PolyGCD
H* u and v are polynomials in x. *L
H* PolyGCD@u,v,xD returns the factors of the gcd of u and v dependent on x. *L
PolyGCD@u_,v_,x_SymbolD :=
NonfreeFactors@PolynomialGCD@u,vD,xD
Integration utility functions.m | 35
Algebraic function functions
AlgebraicFunctionQ
H* AlgebraicFunctionQ@u,xD returns True iff u is an algebraic of x *L
H* If flag is True, exponents can be nonnumeric. *L
AlgebraicFunctionQ@u_,x_Symbol,flag_:FalseD :=
If@AtomQ@uD ÈÈ FreeQ@u,xD,
True,
If@PowerQ@uD && HRationalQ@u@@2DDD ÈÈ flag && FreeQ@u@@2DD,xDL,
AlgebraicFunctionQ@u@@1DD,x,flagD,
If@ProductQ@uD ÈÈ SumQ@uD,
Catch@Scan@Function@If@Not@AlgebraicFunctionQ@ð,x,flagDD,Throw@FalseDDD,uD;TrueD,
If@ListQ@uD,
If@u===8<,
True,
If@AlgebraicFunctionQ@First@uD,x,flagD,
AlgebraicFunctionQ@Rest@uD,x,flagD,
FalseDD,
FalseDDDD
AlgebraicFunctionFactors
H* AlgebraicFunctionFactors@u,xD returns the product of the factors of u that are algebraic functions of x. *L
H* AlgebraicFunctionFactors@u_,x_Symbol,flag_:FalseD :=
If@ProductQ@uD,
Map@Function@If@AlgebraicFunctionQ@ð,x,flagD,ð,1DD,uD,
If@AlgebraicFunctionQ@u,x,flagD,u,1DD *L
NonalgebraicFunctionFactors
H* NonalgebraicFunctionFactors@u,xD returns the product of the factors of u that are not algebraic functions of x. *L
H* NonalgebraicFunctionFactors@u_,x_Symbol,flag_:FalseD :=
If@ProductQ@uD,
Map@Function@If@AlgebraicFunctionQ@ð,x,flagD,1,ðDD,uD,
If@AlgebraicFunctionQ@u,x,flagD,1,uDD *L
Quotient of linears functions
QuotientOfLinearsQ
è QuotientOfLinearsQ[u,x] returns True iff u is equivalent to an expression of the form (a+b x)/(c+d x) where b!=0 and d!=0.
36 | Integration utility functions.m
QuotientOfLinearsQ@u_,x_SymbolD :=
If@ListQ@uD,
Catch@Scan@Function@If@Not@QuotientOfLinearsQ@ð,xDD,Throw@FalseDDD,uD; TrueD,
QuotientOfLinearsP@u,xD && Function@NonzeroQ@ð@@2DDD && NonzeroQ@ð@@4DDDD@QuotientOfLinearsParts@u,xDDD
QuotientOfLinearsP@a_*u_,x_D :=
QuotientOfLinearsP@u,xD ;
FreeQ@a,xD
QuotientOfLinearsP@a_+u_,x_D :=
QuotientOfLinearsP@u,xD ;
FreeQ@a,xD
QuotientOfLinearsPA1u_,x_E :=
QuotientOfLinearsP@u,xD
QuotientOfLinearsP@u_,x_D :=
True ;
LinearQ@u,xD
QuotientOfLinearsPAu_v_,x_E :=
True ;
LinearQ@u,xD && LinearQ@v,xD
QuotientOfLinearsP@u_,x_D :=
u===x ÈÈ FreeQ@u,xD
Integration utility functions.m | 37
QuotientOfLinearsParts
H* If u is equivalent to an expression of the form Ha+b*xLHc+d*xL, QuotientOfLinearsParts@u,xD
returns the list 8a, b, c, d<. *L
QuotientOfLinearsParts@a_*u_,x_D :=
Apply@Function@8a*ð1, a*ð2, ð3, ð4<D, QuotientOfLinearsParts@u,xDD ;
FreeQ@a,xD
QuotientOfLinearsParts@a_+u_,x_D :=
Apply@Function@8ð1+a*ð3, ð2+a*ð4, ð3, ð4<D, QuotientOfLinearsParts@u,xDD ;
FreeQ@a,xD
QuotientOfLinearsPartsA1u_,x_E :=
Apply@Function@8ð3, ð4, ð1, ð2<D, QuotientOfLinearsParts@u,xDD
QuotientOfLinearsParts@u_,x_D :=
8Coefficient@u,x,0D, Coefficient@u,x,1D, 1, 0< ;
LinearQ@u,xD
QuotientOfLinearsPartsAu_v_,x_E :=
8Coefficient@u,x,0D, Coefficient@u,x,1D, Coefficient@v,x,0D, Coefficient@v,x,1D< ;
LinearQ@u,xD && LinearQ@v,xD
QuotientOfLinearsParts@u_,x_D :=
If@u===x,
80, 1, 1, 0<,
If@FreeQ@u,xD,
8u, 0, 1, 0<,
Print@"QuotientOfLinearsParts error!"D;
8u, 0, 1, 0<DD
38 | Integration utility functions.m
SubstForFractionalPowerOfQuotientOfLinears
H* If u has a subexpression of the form HHa+b*xLHc+d*xLL^HmnL where m and n>1 are integers,
SubstForFractionalPowerOfQuotientOfLinears@u,xD returns the list 8v,n,Ha+b*xLHc+d*xL,b*c-a*d< where v is u
with subexpressions of the form HHa+b*xLHc+d*xLL^HmnL replaced by x^m and x replaced
by H-a+c*x^nLHb-d*x^nL, and all times x^Hn-1LHb-d*x^nL^2; else it returns False. *L
SubstForFractionalPowerOfQuotientOfLinears@u_,x_SymbolD :=
Module@8lst=FractionalPowerOfQuotientOfLinears@u,1,False,xD<,
If@AtomQ@lstD ÈÈ AtomQ@lst@@2DDD,
False,
With@8n=lst@@1DD,tmp=lst@@2DD<,
lst=QuotientOfLinearsParts@tmp,xD;
With@8a=lst@@1DD,b=lst@@2DD,c=lst@@3DD,d=lst@@4DD<,
If@ZeroQ@dD,
False,
lst=Simplify@x^Hn-1L*SubstForFractionalPower@u,tmp,n,H-a+c*x^nLHb-d*x^nL,xDHb-d*x^nL^2D;
8NonfreeFactors@lst,xD,n,tmp,FreeFactors@lst,xD*Hb*c-a*dL<DDDDD
H* If the substitution x=v^H1nL will not complicate algebraic subexpressions of u,
SubstForFractionalPowerQ@u,v,xD returns True; else it returns False. *L
SubstForFractionalPowerQ@u_,v_,x_SymbolD :=
If@AtomQ@uD ÈÈ FreeQ@u,xD,
True,
If@FractionalPowerQ@uD,
SubstForFractionalPowerAuxQ@u,v,xD,
Catch@Scan@Function@If@Not@SubstForFractionalPowerQ@ð,v,xDD,Throw@FalseDDD,uD;TrueDDD
SubstForFractionalPowerAuxQ@u_,v_,x_D :=
If@AtomQ@uD,
False,
If@FractionalPowerQ@uD && ZeroQ@u@@1DD-vD,
True,
Catch@Scan@Function@If@SubstForFractionalPowerAuxQ@ð,v,xD,Throw@TrueDDD,uD;FalseDDD
H* If u has a subexpression of the form HHa+b*xLHc+d*xLL^HmnL,
FractionalPowerOfQuotientOfLinears@u,1,False,xD returns 8n,Ha+b*xLHc+d*xL<; else it returns False. *L
FractionalPowerOfQuotientOfLinears@u_,n_,v_,x_D :=
If@AtomQ@uD ÈÈ FreeQ@u,xD,
8n,v<,
If@CalculusQ@uD,
False,
If@FractionalPowerQ@uD && QuotientOfLinearsQ@u@@1DD,xD && Not@LinearQ@u@@1DD,xDD && HFalseQ@vD ÈÈ ZeroQ@u@@1DD-vDL,
8LCM@Denominator@u@@2DDD,nD,u@@1DD<,
Catch@Module@8lst=8n,v<<,
Scan@Function@If@AtomQ@lst=FractionalPowerOfQuotientOfLinears@ð,lst@@1DD,lst@@2DD,xDD,Throw@FalseDDD,uD;
lstDDDDD
Integration utility functions.m | 39
SubstForInverseFunctionOfQuotientOfLinears
H* If u has a subexpression of the form g@Ha+b*xLHc+d*xLD where g is the inverse of function h
and f@x,g@Ha+b*xLHc+d*xLDD equals u, SubstForInverseFunctionOfQuotientOfLinears@u,xD returns
the list 8f@H-a+c*h@xDLHb-d*h@xDL,xD*h'@xDHb-d*h@xDL^2, g@Ha+b*xLHc+d*xLD, b*c-a*d< *L
SubstForInverseFunctionOfQuotientOfLinears@u_,x_SymbolD :=
With@8tmp=InverseFunctionOfQuotientOfLinears@u,xD<,
If@AtomQ@tmpD,
False,
With@8h=InverseFunction@Head@tmpDD,lst=QuotientOfLinearsParts@tmp@@1DD,xD<,
With@8a=lst@@1DD,b=lst@@2DD,c=lst@@3DD,d=lst@@4DD<,
8SubstForInverseFunction@u,tmp,H-a+c*h@xDLHb-d*h@xDL,xD*D@h@xD,xDHb-d*h@xDL^2, tmp, b*c-a*d<DDDD
H* If u has a subexpression of the form g@Ha+b*xLHc+d*xLD where g is an inverse function,
InverseFunctionOfQuotientOfLinears@u,xD returns g@Ha+b*xLHc+d*xLD; else it returns False. *L
InverseFunctionOfQuotientOfLinears@u_,x_SymbolD :=
If@AtomQ@uD ÈÈ CalculusQ@uD ÈÈ FreeQ@u,xD,
False,
If@InverseFunctionQ@uD && QuotientOfLinearsQ@u@@1DD,xD,
u,
Module@8tmp<,
Catch@
Scan@Function@If@Not@AtomQ@tmp=InverseFunctionOfQuotientOfLinears@ð,xDDD,Throw@tmpDDD,uD;
FalseDDDD
Substitution for inverse functions
H* SubstForFractionalPower@u,v,n,w,xD returns u with subexpressions equal to v^HmnL replaced
by x^m and x replaced by w. *L
SubstForFractionalPower@u_,v_,n_,w_,x_SymbolD :=
If@AtomQ@uD,
If@u===x,
w,
uD,
If@FractionalPowerQ@uD && ZeroQ@u@@1DD-vD,
x^Hn*u@@2DDL,
Map@Function@SubstForFractionalPower@ð,v,n,w,xDD,uDDD
40 | Integration utility functions.m
H* SubstForInverseFunction@u,v,w,xD returns u with subexpressions equal to v replaced by x
and x replaced by w. *L
SubstForInverseFunction@u_,v_,x_SymbolD :=
H* Module@8a=Coefficient@v@@1DD,0D,b=Coefficient@v@@1DD,1D<,
SubstForInverseFunction@u,v,-ab+InverseFunction@Head@vDDb,xDD *L
SubstForInverseFunction@u,v,
H-Coefficient@v@@1DD,x,0D+InverseFunction@Head@vDD@xDLCoefficient@v@@1DD,x,1D,xD
SubstForInverseFunction@u_,v_,w_,x_SymbolD :=
If@AtomQ@uD,
If@u===x,
w,
uD,
If@Head@uD===Head@vD && ZeroQ@u@@1DD-v@@1DDD,
x,
Map@Function@SubstForInverseFunction@ð,v,w,xDD,uDDD
Absurd number factors
Definition: A number is absurd if it is a rational number, a positive rational number raised to a fractional power, or a product of absurd numbers.
H* AbsurdNumberQ@uD returns True if u is an absurd number, else it returns False. *L
AbsurdNumberQ@u_D :=
RationalQ@uD
AbsurdNumberQ@u_^v_D :=
RationalQ@uD && u>0 && FractionQ@vD
AbsurdNumberQ@u_*v_D :=
AbsurdNumberQ@uD && AbsurdNumberQ@vD
H* AbsurdNumberFactors@uD returns the product of the factors of u that are absurd numbers. *L
AbsurdNumberFactors@u_D :=
If@AbsurdNumberQ@uD,
u,
If@ProductQ@uD,
Map@AbsurdNumberFactors,uD,
NumericFactor@uDDD
Integration utility functions.m | 41
H* NonabsurdNumberFactors@uD returns the product of the factors of u that are not absurd numbers. *L
NonabsurdNumberFactors@u_D :=
If@AbsurdNumberQ@uD,
1,
If@ProductQ@uD,
Map@NonabsurdNumberFactors,uD,
NonnumericFactors@uDDD
H* m must be an absurd number. FactorAbsurdNumber@mD returns the prime factorization of m *L
H* as list of base-degree pairs where the bases are prime numbers and the degrees are rational. *L
FactorAbsurdNumber@m_D :=
If@RationalQ@mD,
FactorInteger@mD,
If@PowerQ@mD,
Map@Function@8ð@@1DD, ð@@2DD*m@@2DD<D,FactorInteger@m@@1DDDD,
CombineExponents@Sort@Flatten@Map@FactorAbsurdNumber,Apply@List,mDD,1D, Function@ð1@@1DD<ð2@@1DDDDDDD
CombineExponents@lst_D :=
If@Length@lstD<2,
lst,
If@lst@@1,1DD==lst@@2,1DD,
CombineExponents@Prepend@Drop@lst,2D,8lst@@1,1DD,lst@@1,2DD+lst@@2,2DD<DD,
Prepend@CombineExponents@Rest@lstDD,First@lstDDDD
H* m, n, ... must be absurd numbers. AbsurdNumberGCD@m,n,...D returns the gcd of m, n, ... *L
AbsurdNumberGCD@seq__D :=
With@8lst=8seq<<,
If@Length@lstD==1,
First@lstD,
AbsurdNumberGCDList@FactorAbsurdNumber@First@lstDD,FactorAbsurdNumber@Apply@AbsurdNumberGCD,Rest@lstDDDDDD
42 | Integration utility functions.m
H* lst1 and lst2 must be absurd number prime factorization lists. *L
H* AbsurdNumberGCDList@lst1,lst2D returns the gcd of the absurd numbers represented by lst1 and lst2. *L
AbsurdNumberGCDList@lst1_,lst2_D :=
If@lst1===8<,
Apply@Times,Map@Function@ð@@1DD^Min@ð@@2DD,0DD,lst2DD,
If@lst2===8<,
Apply@Times,Map@Function@ð@@1DD^Min@ð@@2DD,0DD,lst1DD,
If@lst1@@1,1DD==lst2@@1,1DD,
If@lst1@@1,2DD<=lst2@@1,2DD,
lst1@@1,1DD^lst1@@1,2DD*AbsurdNumberGCDList@Rest@lst1D,Rest@lst2DD,
lst1@@1,1DD^lst2@@1,2DD*AbsurdNumberGCDList@Rest@lst1D,Rest@lst2DDD,
If@lst1@@1,1DD<lst2@@1,1DD,
If@lst1@@1,2DD<0,
lst1@@1,1DD^lst1@@1,2DD*AbsurdNumberGCDList@Rest@lst1D,lst2D,
AbsurdNumberGCDList@Rest@lst1D,lst2DD,
If@lst2@@1,2DD<0,
lst2@@1,1DD^lst2@@1,2DD*AbsurdNumberGCDList@lst1,Rest@lst2DD,
AbsurdNumberGCDList@lst1,Rest@lst2DDDDDDD
Normalization functions
NormalizeIntegrand
H* NormalizeIntegrand@u,xD returns u in a standard form recognizable by integration rules. *L
NormalizeIntegrand@u_,x_SymbolD :=
With@8v=NormalizeLeadTermSigns@NormalizeIntegrandAux@u,xDD<,
If@v===NormalizeLeadTermSigns@uD,
u,
vDD
NormalizeIntegrandAux
NormalizeIntegrandAux@u_,x_SymbolD :=
If@SumQ@uD,
Map@Function@NormalizeIntegrandAux@ð,xDD,uD,
If@ProductQ@MergeMonomials@u,xDD,
Map@Function@NormalizeIntegrandFactor@ð,xDD,MergeMonomials@u,xDD,
NormalizeIntegrandFactor@MergeMonomials@u,xD,xDDD
Integration utility functions.m | 43
NormalizeIntegrandFactor@u_,x_SymbolD :=
Module@8bas,deg,min<,
If@PowerQ@uD && FreeQ@u@@2DD,xD,
bas=NormalizeIntegrandFactorBase@u@@1DD,xD;
deg=u@@2DD;
If@IntegerQ@degD && SumQ@basD,
If@MapAnd@Function@MonomialQ@ð,xDD,basD,
min=MinimumMonomialExponent@bas,xD;
x^Hmin*degL*Map@Function@Simplify@ðx^minDD,basD^deg,
bas^degD,
bas^degD,
If@PowerQ@uD && FreeQ@u@@1DD,xD,
u@@1DD^NormalizeIntegrandFactorBase@u@@2DD,xD,
bas=NormalizeIntegrandFactorBase@u,xD;
If@SumQ@basD,
If@MapAnd@Function@MonomialQ@ð,xDD,basD,
min=MinimumMonomialExponent@bas,xD;
x^min*Map@Function@ðx^minD,basD,
basD,
basDDDD
NormalizeIntegrandFactorBase@x_^m_.*u_,x_SymbolD :=
NormalizeIntegrandFactorBase@Map@Function@x^m*ðD,uD,xD ;
FreeQ@m,xD && SumQ@uD
NormalizeIntegrandFactorBase@u_,x_SymbolD :=
If@BinomialQ@u,xD,
If@BinomialMatchQ@u,xD,
u,
ExpandToSum@u,xDD,
If@TrinomialQ@u,xD,
If@TrinomialMatchQ@u,xD,
u,
ExpandToSum@u,xDD,
If@ProductQ@uD,
Map@Function@NormalizeIntegrandFactor@ð,xDD,uD,
If@PolynomialQ@u,xD && Exponent@u,xD<=4,
ExpandToSum@u,xD,
If@SumQ@uD,
With@8v=TogetherSimplify@uD<,
If@SumQ@vD ÈÈ MatchQ@v, x^m_.*w_ ; FreeQ@m,xD && SumQ@wDD ÈÈ LeafCount@vD>LeafCount@uD+2,
UnifySum@u,xD,
NormalizeIntegrandFactorBase@v,xDDD,
Map@Function@NormalizeIntegrandFactor@ð,xDD,uDDDDDD
44 | Integration utility functions.m
NormalizeLeadTermSigns
NormalizeTogether@u_D :=
NormalizeLeadTermSigns@Together@uDD
H* NormalizeLeadTermSigns@uD returns an expression equal u but with not more than one sum
factor raised to a integer degree having a lead term with a negative coefficient. *L
NormalizeLeadTermSigns@u_D :=
With@8lst=If@ProductQ@uD, Map@SignOfFactor,uD, SignOfFactor@uDD<,
If@lst@@1DD==1,
lst@@2DD,
AbsorbMinusSign@lst@@2DDDDD
H* AbsorbMinusSign@uD returns an expression equal to -u. If there is a factor of u of the
form v^m where v is a sum and m is an odd power, the minus sign is distributed over v;
otherwise -u is returned. *L
AbsorbMinusSign@u_.*v_PlusD :=
u*H-vL
AbsorbMinusSign@u_.*v_Plus^m_D :=
u*H-vL^m ;
OddQ@mD
AbsorbMinusSign@u_D :=
-u
NormalizeSumFactors
H* NormalizeSumFactors@uD returns an expression equal u but with the numeric coefficient of
the lead term of sum factors made positive where possible. *L
NormalizeSumFactors@u_D :=
If@AtomQ@uD ÈÈ Head@uD===If ÈÈ Head@uD===Int ÈÈ HeldFormQ@uD,
u,
If@ProductQ@uD,
Function@ð@@1DD*ð@@2DDD@SignOfFactor@Map@NormalizeSumFactors,uDDD,
Map@NormalizeSumFactors,uDDD
Integration utility functions.m | 45
H* SignOfFactor@uD returns the list 8n,v< where n*v equals u, n^2 equals 1, and the lead
term of the sum factors of v raised to integer degrees all have positive coefficients. *L
SignOfFactor@u_D :=
If@RationalQ@uD && u<0 ÈÈ SumQ@uD && NumericFactor@First@uDD<0,
8-1, -u<,
If@IntegerPowerQ@uD && SumQ@u@@1DDD && NumericFactor@First@u@@1DDDD<0,
8H-1L^u@@2DD, H-u@@1DDL^u@@2DD<,
If@ProductQ@uD,
Map@SignOfFactor,uD,
81, u<DDD
NormalizePowerOfLinear
H* u can be square-free factored into an expression of the form Ha+b*xL^m. *L
H* NormalizePowerOfLinear@u,xD returns u in the form Ha+b*xL^m. *L
NormalizePowerOfLinear@u_,x_SymbolD :=
With@8v=FactorSquareFree@uD<,
If@PowerQ@vD && LinearQ@v@@1DD,xD && FreeQ@v@@2DD,xD,
ExpandToSum@v@@1DD,xD^v@@2DD,
ExpandToSum@v,xDDD
MergeMonomials
Basis: If mÎZ ß b c-a d==0, then (a+b z)^m==b^m/d^m (c+d z)^m
MergeMonomials@u_.*Ha_.+b_.*x_L^m_.*Hc_.+d_.*x_L^n_.,x_SymbolD :=
u*b^md^m*Hc+d*xL^Hm+nL ;
FreeQ@8a,b,c,d<,xD && IntegerQ@mD && ZeroQ@b*c-a*dD
Basis: If m/nÎZ, then z^m (c z^n)^p==(c z^n)^(m/n+p)/c^(m/n)
MergeMonomials@u_.*Ha_.+b_.*x_L^m_.*Hc_.*Ha_.+b_.*x_L^n_.L^p_,x_SymbolD :=
u*Hc*Ha+b*xL^nL^Hmn+pLc^HmnL ;
FreeQ@8a,b,c,m,n,p<,xD && IntegerQ@mnD
MergeMonomials@u_,x_SymbolD := u
46 | Integration utility functions.m
Simplification functions
SimplifyIntegrand
H* SimplifyIntegrand@u,xD simplifies u and returns the result in a standard form recognizable by integration rules. *L
SimplifyIntegrand@u_,x_SymbolD :=
Module@8v<,
v=NormalizeLeadTermSigns@NormalizeIntegrandAux@Simplify@uD,xDD;
If@LeafCount@vD<45*LeafCount@uD,
v,
If@v=!=NormalizeLeadTermSigns@uD,
v,
uDDD
SimplifyTerm
????
H* SimplifyTerm@u_,x_SymbolD :=
Module@8v=Simplify@uD,w<,
w=Together@vD;
NormalizeIntegrand@If@LeafCount@vD<LeafCount@wD,v,wD,xDD *L
SimplifyTerm@u_,x_SymbolD :=
Module@8v=Simplify@uD,w<,
w=Together@vD;
NormalizeIntegrand@If@LeafCount@vD<LeafCount@wD,w,wD,xDD
TogetherSimplify
TogetherSimplify@u_D :=
TimeConstrained@
Module@8v<,
v=Together@Simplify@Together@uDDD;
TimeConstrained@FixSimplify@vD,TimeLimit3,vDD,
TimeLimit,uD
H* TogetherSimplify could replace SmartSimplify, but results in more complicated *L
H* antiderivatives and would require thousands of changes to test suite. *L
SmartSimplify@u_D :=
TimeConstrained@
Module@8v,w<,
v=Simplify@uD;
w=Factor@vD;
v=If@LeafCount@wD<LeafCount@vD H* -1 *L,w,vD;
v=If@Not@FalseQ@w=FractionalPowerOfSquareQ@vDDD && FractionalPowerSubexpressionQ@u,w,Expand@wDD,SubstForExpn@v,w,Expand@wDD,v
v=FactorNumericGcd@vD;
TimeConstrained@FixSimplify@vD,TimeLimit3,vDD,
TimeLimit,uD
Integration utility functions.m | 47
SubstForExpn@u_,v_,w_D :=
If@u===v,
w,
If@AtomQ@uD,
u,
Map@Function@SubstForExpn@ð,v,wDD,uDDD
Simp
Simp@u_,x_D :=
TimeConstrained@NormalizeSumFactors@SimpHelp@u,xDD,TimeLimit,uD
SimpHelp@E^Hu_.*Hv_.*Log@a_D+w_LL,x_D :=
a^Hu*vL*SimpHelp@E^Hu*wL,xD
SimpHelp@u_,x_D :=
If@AtomQ@uD,
u,
If@Head@uD===If ÈÈ Head@uD===Int ÈÈ HeldFormQ@uD,
u,
If@FreeQ@u,xD,
With@8v=SmartSimplify@uD<,
If@LeafCount@vD<=LeafCount@uD,
v,
uDD,
If@ProductQ@uD,
Module@8v=FreeFactors@u,xD,w=NonfreeFactors@u,xD<,
v=NumericFactor@vD*SmartSimplify@NonnumericFactors@vD*x^2Dx^2;
w=If@ProductQ@wD, Map@Function@SimpHelp@ð,xDD,wD, SimpHelp@w,xDD;
w=FactorNumericGcd@wD;
v=MergeFactors@v,wD;
If@ProductQ@vD,
Map@Function@SimpFixFactor@ð,xDD,vD,
vDD,
If@SumQ@uD,
If@PolynomialQ@u,xD && Exponent@u,xD<=0,
SimpHelp@Coefficient@u,x,0D,xD,
If@PolynomialQ@u,xD && Exponent@u,xD==1 && Coefficient@u,x,0D===0,
SimpHelp@Coefficient@u,x,1D,xD*x,
Module@8v=0,w=0<,
Scan@Function@If@FreeQ@ð,xD,v=ð+v,w=ð+wDD,uD;
v=SmartSimplify@vD;
w=If@SumQ@wD, Map@Function@SimpHelp@ð,xDD,wD, SimpHelp@w,xDD;
v+wDDD,
Map@Function@SimpHelp@ð,xDD,uDDDDDD
48 | Integration utility functions.m
FractionalPowerOfSquareQ
H* If a subexpression of u is of the form HHv+wL^2L^n where n is a fraction, *L
H* FractionalPowerOfSquareQ@uD returns Hv+wL^2; else it returns False. *L
FractionalPowerOfSquareQ@u_D :=
If@AtomQ@uD,
False,
If@FractionalPowerQ@uD && MatchQ@u@@1DD, a_.*Hb_+c_L^2 ; NonsumQ@aDD,
u@@1DD,
Module@8tmp<,
Catch@
Scan@Function@If@Not@FalseQ@tmp=FractionalPowerOfSquareQ@ðDDD,Throw@tmpDDD,uD;
FalseDDDD
H* If a subexpression of u is of the form w^n where n is a fraction but not equal to v, *L
H* FractionalPowerSubexpressionQ@u,v,wD returns True; else it returns False. *L
FractionalPowerSubexpressionQ@u_,v_,w_D :=
If@AtomQ@uD,
False,
If@FractionalPowerQ@uD && PositiveQ@u@@1DDwD,
Not@u@@1DD===vD && LeafCount@wD<3*LeafCount@vD,
Catch@Scan@Function@If@FractionalPowerSubexpressionQ@ð,v,wD,Throw@TrueDDD,uD; FalseDDD
FixSimplify
Clear@FixSimplifyD
è Basis: If nÎZ, then u I (v I+w)^n==(-1)^((n+1)/2) u (v-I w)^n
FixSimplify@u_.*Complex@0,a_D*Hv_.*Complex@0,b_D+w_L^n_.D :=
H-1L^HHn+1L2L*a*u*FixSimplify@Hb*v-Complex@0,1D*wL^nD ;
OddQ@nD
è Basis: If u>0 ß v>0, let g=GCD[m,n], then u^m v^n==((u^(m/g) v^(n/g)))^g
FixSimplify@w_.*u_^m_.*v_^n_D :=
With@8z=Simplify@u^HmGCD@m,nDL*v^HnGCD@m,nDLD<,
FixSimplify@w*z^GCD@m,nDD;
AbsurdNumberQ@zD ÈÈ SqrtNumberSumQ@zDD ;
RationalQ@mD && FractionQ@nD && SqrtNumberSumQ@uD && SqrtNumberSumQ@vD && PositiveQ@uD && PositiveQ@vD
FixSimplify@w_.*u_^m_.*v_^n_D :=
With@8z=Simplify@u^HmGCD@m,-nDL*v^HnGCD@m,-nDLD<,
FixSimplify@w*z^GCD@m,-nDD;
AbsurdNumberQ@zD ÈÈ SqrtNumberSumQ@zDD ;
RationalQ@mD && FractionQ@nD && SqrtNumberSumQ@uD && SqrtNumberSumQ@1vD && PositiveQ@uD && PositiveQ@vD
è Basis: If mÎZ ß u<0 ß v>0, then u^m v^n==-(((-u))^(m/n) v)^n
Integration utility functions.m | 49
FixSimplify@w_.*u_^m_.*v_^n_D :=
With@8z=Simplify@H-uL^HmGCD@m,nDL*v^HnGCD@m,nDLD<,
FixSimplify@-w*z^GCD@m,nDD;
AbsurdNumberQ@zD ÈÈ SqrtNumberSumQ@zDD ;
IntegerQ@mD && FractionQ@nD && SqrtNumberSumQ@uD && SqrtNumberSumQ@vD && NegativeQ@uD && PositiveQ@vD
FixSimplify@w_.*u_^m_.*v_^n_D :=
With@8z=Simplify@H-uL^HmGCD@m,-nDL*v^HnGCD@m,-nDLD<,
FixSimplify@-w*z^GCD@m,-nDD;
AbsurdNumberQ@zD ÈÈ SqrtNumberSumQ@zDD ;
IntegerQ@mD && FractionQ@nD && SqrtNumberSumQ@uD && SqrtNumberSumQ@1vD && NegativeQ@uD && PositiveQ@vD
è Basis: If pÎZ Þ a>0, then a^m (u+v)^p==(a^(m/p) u+a^(m/p) v)^p
FixSimplify@w_.*a_^m_*Hu_+b_^n_*v_.L^p_.D :=
With@8c=Simplify@a^HmpL*b^nD<,
FixSimplify@w*Ha^HmpL*u+c*vL^pD ;
RationalQ@cDD ;
RationalQ@a,b,m,nD && a>0 && b>0 && PositiveIntegerQ@pD
è Basis: If pÎZ, then a^m (a^n u+(-a)^p v)==a^(m+n) (u+(-1)^p a^(p-n) v)
FixSimplify@w_.*a_^m_.*Ha_^n_*u_.+b_^p_.*v_.LD :=
FixSimplify@w*a^Hm+nL*Hu+H-1L^p*a^Hp-nL*vLD ;
RationalQ@mD && FractionQ@nD && IntegerQ@pD && p-n>0 && a+b===0
è Basis: If mÎZ ß b c-a d==0, then (a+b)^m==(b/d)^m (c+d)^m
FixSimplify@w_.*Ha_+b_L^m_.*Hc_+d_L^n_D :=
With@8q=Simplify@bdD<,
FixSimplify@w*q^m*Hc+dL^Hm+nLD ;
FreeQ@q,PlusDD ;
IntegerQ@mD && Not@IntegerQ@nDD && ZeroQ@b*c-a*dD
è Basis: If tÎZ, then (a^m u+a^n v+...)^t==a^(m t) (u+a^(n-m) v+...)^t
FixSimplify@w_.*Ha_^m_.*u_.+a_^n_.*v_.L^t_.D :=
FixSimplify@a^Hm*tL*w*Hu+a^Hn-mL*vL^tD ;
Not@RationalQ@aDD && IntegerQ@tD && RationalQ@m,nD && 0<m<=n
FixSimplify@w_.*Ha_^m_.*u_.+a_^n_.*v_.+a_^p_.*z_.L^t_.D :=
FixSimplify@a^Hm*tL*w*Hu+a^Hn-mL*v+a^Hp-mL*zL^tD ;
Not@RationalQ@aDD && IntegerQ@tD && RationalQ@m,n,pD && 0<m<=n<=p
FixSimplify@w_.*Ha_^m_.*u_.+a_^n_.*v_.+a_^p_.*z_.+a_^q_.*y_.L^t_.D :=
FixSimplify@a^Hm*tL*w*Hu+a^Hn-mL*v+a^Hp-mL*z+a^Hq-mL*yL^tD ;
Not@RationalQ@aDD && IntegerQ@tD && RationalQ@m,n,pD && 0<m<=n<=p<=q
50 | Integration utility functions.m
è Basis: a Sqrt[v]+b Sqrt[v]+...==(a+b+...)Sqrt[v]
FixSimplify@w_.*Hu_.+a_.*Sqrt@v_PlusD+b_.*Sqrt@v_D+c_.*Sqrt@v_D+d_.*Sqrt@v_DLD :=
FixSimplify@w*Hu+FixSimplify@a+b+c+dD*Sqrt@vDLD
FixSimplify@w_.*Hu_.+a_.*Sqrt@v_PlusD+b_.*Sqrt@v_D+c_.*Sqrt@v_DLD :=
FixSimplify@w*Hu+FixSimplify@a+b+cD*Sqrt@vDLD
FixSimplify@w_.*Hu_.+a_.*Sqrt@v_PlusD+b_.*Sqrt@v_DLD :=
FixSimplify@w*Hu+FixSimplify@a+bD*Sqrt@vDLD
è Basis: If a>0, then a^(m/4) Sqrt[b(c+d Sqrt[a])]==Sqrt[b(c a^(m/2)+d a^((m+1)/2))]
FixSimplify@u_.*a_^m_*Sqrt@b_.*Hc_+d_.*Sqrt@a_DLDD :=
Sqrt@Together@b*Hc*a^H2*mL+d*a^H2*m+12LLDD*FixSimplify@uD ;
RationalQ@a,b,c,d,mD && a>0 && Denominator@mD==4
FixSimplifyAu_.*a_^m_Sqrt@b_.*Hc_+d_.*Sqrt@a_DLDE :=
FixSimplify@uDSqrt@Together@b*Hca^H2*mL+da^H2*m-12LLDD ;
RationalQ@a,b,c,d,mD && a>0 && Denominator@mD==4
è Basis: If w^-n==v, then v^m w^n==v^(m-1)
FixSimplify@u_.*v_^m_*w_^n_D :=
-FixSimplify@u*v^Hm-1LD ;
RationalQ@mD && Not@RationalQ@wDD && FractionQ@nD && n<0 && ZeroQ@v+w^H-nLD
è Basis: If nÎZ, then v^m (-v)^n==(-1)^n v^(m+n)
FixSimplify@u_.*v_^m_*w_^n_.D :=
H-1L^HnL*FixSimplify@u*v^Hm+nLD ;
RationalQ@mD && Not@RationalQ@wDD && IntegerQ@nD && ZeroQ@v+wD
è Basis: If n/pÎZ, then (-v^p)^m v^n==(-1)^(n/p) (-v^p)^(m+n/p)
FixSimplify@u_.*H-v_^p_.L^m_*w_^n_.D :=
H-1L^HnpL*FixSimplify@u*H-v^pL^Hm+npLD ;
RationalQ@mD && Not@RationalQ@wDD && IntegerQ@npD && ZeroQ@v-wD
è Basis: If (n|n/p)ÎZ, then (-v^p)^m (-v)^n==(-1)^(n+n/p) (-v^p)^(m+n/p)
FixSimplify@u_.*H-v_^p_.L^m_*w_^n_.D :=
H-1L^Hn+npL*FixSimplify@u*H-v^pL^Hm+npLD ;
RationalQ@mD && Not@RationalQ@wDD && IntegersQ@n,npD && ZeroQ@v+wD
Integration utility functions.m | 51
FixSimplify@u_.*Ha-bL^m_.*Ha+bL^m_.D :=
u*Ha^2-b^2L^m ;
IntegerQ@mD
FixSimplify@u_.*Hc*d^2-e*Hb*d-a*eLL^m_.D :=
u*Hc*d^2-b*d*e+a*e^2L^m ;
RationalQ@mD
FixSimplify@u_.*Hc*d^2+e*H-b*d+a*eLL^m_.D :=
u*Hc*d^2-b*d*e+a*e^2L^m ;
RationalQ@mD
FixSimplify@u_D := u
SimpFixFactor
H* SimpFixFactor@Ha_.*c_ + b_.*c_L^p_.,x_D :=
c^p*SimpFixFactor@Ha+bL^p,xD ;
FreeQ@c,xD && IntegerQ@pD && c^p=!=-1 *L
SimpFixFactor@Ha_.*Complex@0,c_D + b_.*Complex@0,d_DL^p_.,x_D :=
I^p*SimpFixFactor@Ha*c+b*dL^p,xD ;
IntegerQ@pD
SimpFixFactor@Ha_.*Complex@0,d_D + b_.*Complex@0,e_D+ c_.*Complex@0,f_DL^p_.,x_D :=
I^p*SimpFixFactor@Ha*d+b*e+c*fL^p,xD ;
IntegerQ@pD
SimpFixFactor@Ha_.*c_^r_ + b_.*x_^n_.L^p_.,x_D :=
c^Hr*pL*SimpFixFactor@Ha+bc^r*x^nL^p,xD ;
FreeQ@8a,b,c<,xD && IntegersQ@n,pD && AtomQ@cD && RationalQ@rD && r<0
SimpFixFactor@Ha_. + b_.*c_^r_*x_^n_.L^p_.,x_D :=
c^Hr*pL*SimpFixFactor@Hac^r+b*x^nL^p,xD ;
FreeQ@8a,b,c<,xD && IntegersQ@n,pD && AtomQ@cD && RationalQ@rD && r<0
SimpFixFactor@Ha_.*c_^s_. + b_.*c_^r_.*x_^n_.L^p_.,x_D :=
c^Hs*pL*SimpFixFactor@Ha+b*c^Hr-sL*x^nL^p,xD ;
FreeQ@8a,b,c<,xD && IntegersQ@n,pD && RationalQ@s,rD && 0<s<=r && c^Hs*pL=!=-1
SimpFixFactor@Ha_.*c_^s_. + b_.*c_^r_.*x_^n_.L^p_.,x_D :=
c^Hr*pL*SimpFixFactor@Ha*c^Hs-rL+b*x^nL^p,xD ;
FreeQ@8a,b,c<,xD && IntegersQ@n,pD && RationalQ@s,rD && 0<r<s && c^Hr*pL=!=-1
SimpFixFactor@u_,x_D := u
52 | Integration utility functions.m
FactorNumericGcd
H* FactorNumericGcd@uD returns u with the gcd of the numeric coefficients of terms of sums factored out. *L
FactorNumericGcd@u_D :=
If@PowerQ@uD && RationalQ@u@@2DDD,
FactorNumericGcd@u@@1DDD^u@@2DD,
If@ProductQ@uD,
Map@FactorNumericGcd,uD,
If@SumQ@uD,
With@8g=Apply@GCD,Map@NumericFactor,Apply@List,uDDD<,
g*Map@Function@ðgD,uDD,
uDDD
MergeFactors
H* MergeFactors@u,vD returns the product of u and v, but with the mergeable factors of u merged into v. *L
MergeFactors@u_,v_D :=
If@ProductQ@uD,
MergeFactors@Rest@uD,MergeFactors@First@uD,vDD,
If@PowerQ@uD,
If@MergeableFactorQ@u@@1DD,u@@2DD,vD,
MergeFactor@u@@1DD,u@@2DD,vD,
If@RationalQ@u@@2DDD && u@@2DD<-1 && MergeableFactorQ@u@@1DD,-1,vD,
MergeFactors@u@@1DD^Hu@@2DD+1L,MergeFactor@u@@1DD,-1,vDD,
u*vDD,
If@MergeableFactorQ@u,1,vD,
MergeFactor@u,1,vD,
u*vDDD
H* If MergeableFactorQ@bas,deg,vD, MergeFactor@bas,deg,vD return the product of bas^deg and v,
but with bas^deg merged into the factor of v whose base equals bas. *L
MergeFactor@bas_,deg_,v_D :=
If@bas===v,
bas^Hdeg+1L,
If@PowerQ@vD,
If@bas===v@@1DD,
bas^Hdeg+v@@2DDL,
MergeFactor@bas,degv@@2DD,v@@1DDD^v@@2DDD,
If@ProductQ@vD,
If@MergeableFactorQ@bas,deg,First@vDD,
MergeFactor@bas,deg,First@vDD*Rest@vD,
First@vD*MergeFactor@bas,deg,Rest@vDDD,
MergeFactor@bas,deg,First@vDD + MergeFactor@bas,deg,Rest@vDDDDD
Integration utility functions.m | 53
H* MergeableFactorQ@bas,deg,vD returns True iff bas equals the base of a factor of v or bas is a factor of every term of v. *L
MergeableFactorQ@bas_,deg_,v_D :=
If@bas===v,
RationalQ@deg+1D && Hdeg+1>=0 ÈÈ RationalQ@degD && deg>0L,
If@PowerQ@vD,
If@bas===v@@1DD,
RationalQ@deg+v@@2DDD && Hdeg+v@@2DD>=0 ÈÈ RationalQ@degD && deg>0L,
SumQ@v@@1DDD && IntegerQ@v@@2DDD && HNot@IntegerQ@degDD ÈÈ IntegerQ@degv@@2DDDL && MergeableFactorQ@bas,degv@@2DD,v@@1DDDD,
If@ProductQ@vD,
MergeableFactorQ@bas,deg,First@vDD ÈÈ MergeableFactorQ@bas,deg,Rest@vDD,
SumQ@vD && MergeableFactorQ@bas,deg,First@vDD && MergeableFactorQ@bas,deg,Rest@vDDDDD
TrigSimplify
H* TrigSimplifyQ@uD returns True if TrigSimplify@uD actually simplifies u; else False. *L
TrigSimplifyQ@u_D :=
ActivateTrig@uD=!=TrigSimplify@uD
H* TrigSimplify@uD returns a bottom-up trig simplification of u. *L
TrigSimplify@u_D :=
ActivateTrig@TrigSimplifyRecur@uDD
TrigSimplifyRecur@u_D :=
If@AtomQ@uD,
u,
If@Head@uD===If,
u,
TrigSimplifyAux@Map@TrigSimplifyRecur,uDDDD
Clear@TrigSimplifyAuxD
H* Basis: a*z^m+b*z^n == z^m*Ha+b*z^Hn-mLL *L
TrigSimplifyAux@u_.*Ha_.*v_^m_.+b_.*v_^n_.L^p_D :=
u*v^Hm*pL*TrigSimplifyAux@a+b*v^Hn-mLD^p ;
InertTrigQ@vD && IntegerQ@pD && RationalQ@m,nD && m<n
Basis: Sin[z]^2+Cos[z]^2==1
Basis: Sec[z]^2-Tan[z]^2==1
Basis: Csc[z]^2-Cot[z]^2==1
TrigSimplifyAux@a_.*cos@u_D^2+b_.*sin@u_D^2+v_.D := a+v ; a===b
TrigSimplifyAux@a_.*sec@u_D^2+b_.*tan@u_D^2+v_.D := a+v ; a===-b
TrigSimplifyAux@a_.*csc@u_D^2+b_.*cot@u_D^2+v_.D := a+v ; a===-b
54 | Integration utility functions.m
Basis: a Cos[z]^2==a-a Sin[z]^2
TrigSimplifyAux@Ha_.*cos@u_D^2+b_.*sin@u_D^2+v_.L^n_D :=
HHb-aL*Sin@uD^2+a+vL^n
H* Basis: 1-Sin@zD^2 == Cos@zD^2 *L
TrigSimplifyAux@u_+v_.*sin@z_D^2+w_.D := u*Cos@zD^2+w ; u===-v
H* Basis: 1-Cos@zD^2 == Sin@zD^2 *L
TrigSimplifyAux@u_+v_.*cos@z_D^2+w_.D := u*Sin@zD^2+w ; u===-v
H* Basis: 1+Tan@zD^2 == Sec@zD^2 *L
TrigSimplifyAux@u_+v_.*tan@z_D^2+w_.D := u*Sec@zD^2+w ; u===v
H* Basis: 1+Cot@zD^2 == Csc@zD^2 *L
TrigSimplifyAux@u_+v_.*cot@z_D^2+w_.D := u*Csc@zD^2+w ; u===v
H* Basis: -1+Sec@zD^2 == Tan@zD^2 *L
TrigSimplifyAux@u_+v_.*sec@z_D^2+w_.D := v*Tan@zD^2+w ; u===-v
H* Basis: -1+Csc@zD^2 == Cot@zD^2 *L
TrigSimplifyAux@u_+v_.*csc@z_D^2+w_.D := v*Cot@zD^2+w ; u===-v
H* Basis: If a^2-b^2==0, Sin@zD^2Ha+b*Cos@zDL == 1a-Cos@zDb *L
TrigSimplifyAuxAu_.*sin@v_D^2Ha_+b_.*cos@v_DLE := u*H1a - Cos@vDbL ; ZeroQ@a^2-b^2D
H* Basis: If a^2-b^2==0, Cos@zD^2Ha+b*Sin@zDL == 1a-Sin@zDb *L
TrigSimplifyAuxAu_.*cos@v_D^2Ha_+b_.*sin@v_DLE := u*H1a - Sin@vDbL ; ZeroQ@a^2-b^2D
H* Basis: If n is an integer, Tan@zD^nHa+b*Tan@zD^nL == 1Hb+a*Cot@zD^nL *L
TrigSimplifyAuxAu_.*tan@v_D^n_.Ha_+b_.*tan@v_D^n_.LE := uHb+a*Cot@vD^nL ; PositiveIntegerQ@nD && NonsumQ@aD
H* Basis: If n is an integer, Cot@zD^nHa+b*Cot@zD^nL == 1Hb+a*Tan@zD^nL *L
TrigSimplifyAuxAu_.*cot@v_D^n_.Ha_+b_.*cot@v_D^n_.LE := uHb+a*Tan@vD^nL ; PositiveIntegerQ@nD && NonsumQ@aD
H* Basis: If n is an integer, Sec@zD^nHa+b*Sec@zD^nL == 1Hb+a*Cos@zD^nL *L
TrigSimplifyAuxAu_.*sec@v_D^n_.Ha_+b_.*sec@v_D^n_.LE := uHb+a*Cos@vD^nL ; PositiveIntegerQ@nD && NonsumQ@aD
H* Basis: If n is an integer, Csc@zD^nHa+b*Csc@zD^nL == 1Hb+a*Sin@zD^nL *L
TrigSimplifyAuxAu_.*csc@v_D^n_.Ha_+b_.*csc@v_D^n_.LE := uHb+a*Sin@vD^nL ; PositiveIntegerQ@nD && NonsumQ@aD
Integration utility functions.m | 55
H* Basis: If n is an integer, Tan@zD^nHa+b*Sec@zD^nL == Sin@zD^nHb+a*Cos@zD^nL *L
TrigSimplifyAuxAu_.*tan@v_D^n_.Ha_+b_.*sec@v_D^n_.LE := u*Sin@vD^nHb+a*Cos@vD^nL ; PositiveIntegerQ@nD && NonsumQ@aD
H* Basis: If n is an integer, Cot@zD^nHa+b*Csc@zD^nL == Cos@zD^nHb+a*Sin@zD^nL *L
TrigSimplifyAuxAu_.*cot@v_D^n_.Ha_+b_.*csc@v_D^n_.LE := u*Cos@vD^nHb+a*Sin@vD^nL ; PositiveIntegerQ@nD && NonsumQ@aD
Basis: a Sec[z]+b Tan[z]==Sec[z](a+b Sin[z])
TrigSimplifyAux@u_.*Ha_.*sec@v_D^n_.+b_.*tan@v_D^n_.L^p_.D :=
u*Sec@vD^Hn*pL*Ha+b*Sin@vD^nL^p ;
IntegersQ@n,pD
TrigSimplifyAux@u_.*Ha_.*csc@v_D^n_.+b_.*cot@v_D^n_.L^p_.D :=
u*Csc@vD^Hn*pL*Ha+b*Cos@vD^nL^p ;
IntegersQ@n,pD
Basis: a Tan[z]+b Sin[z]==Tan[z](a+b Cos[z])
TrigSimplifyAux@u_.*Ha_.*tan@v_D^n_.+b_.*sin@v_D^n_.L^p_.D :=
u*Tan@vD^Hn*pL*Ha+b*Cos@vD^nL^p ;
IntegersQ@n,pD
TrigSimplifyAux@u_.*Ha_.*cot@v_D^n_.+b_.*cos@v_D^n_.L^p_.D :=
u*Cot@vD^Hn*pL*Ha+b*Sin@vD^nL^p ;
IntegersQ@n,pD
56 | Integration utility functions.m
Basis: a+b Tan[z]+c Sec[z]==(c+b Sin[z]+a Cos[z])/Cos[z]
Basis: a+b Tan[z]+c Sec[z]==Sec[z] (c+b Sin[z]+a Cos[z])
Basis: a+b Cot[z]+c Csc[z]==(c+b Cos[z]+a Sin[z])/Sin[z]
Basis: a+b Cot[z]+c Csc[z]==Csc[z] (c+b Cos[z]+a Sin[z])
TrigSimplifyAux@u_.*cos@v_D^m_.*Ha_.+b_.*tan@v_D^n_.+c_.*sec@v_D^n_.L^p_.D :=
u*Cos@vD^Hm-n*pL*Hc+b*Sin@vD^n+a*Cos@vD^nL^p ;
IntegersQ@m,n,pD
TrigSimplifyAux@u_.*sec@v_D^m_.*Ha_.+b_.*tan@v_D^n_.+c_.*sec@v_D^n_.L^p_.D :=
u*Sec@vD^Hm+n*pL*Hc+b*Sin@vD^n+a*Cos@vD^nL^p ;
IntegersQ@m,n,pD
TrigSimplifyAux@u_.*sin@v_D^m_.*Ha_.+b_.*cot@v_D^n_.+c_.*csc@v_D^n_.L^p_.D :=
u*Sin@vD^Hm-n*pL*Hc+b*Cos@vD^n+a*Sin@vD^nL^p ;
IntegersQ@m,n,pD
TrigSimplifyAux@u_.*csc@v_D^m_.*Ha_.+b_.*cot@v_D^n_.+c_.*csc@v_D^n_.L^p_.D :=
u*Csc@vD^Hm+n*pL*Hc+b*Cos@vD^n+a*Sin@vD^nL^p ;
IntegersQ@m,n,pD
Basis: If nÎZ, then a Csc[z]^m+b Sin[z]^n==(a+b Sin[z]^(m+n))/Sin[z]^m
Basis: If nÎZ, then a Sec[z]^m+b Cos[z]^n==(a+b Cos[z]^(m+n))/Cos[z]^m
TrigSimplifyAux@u_.*Ha_.*csc@v_D^m_.+b_.*sin@v_D^n_.L^p_.D :=
If@ZeroQ@m+n-2D && ZeroQ@a+bD,
u*Ha*Cos@vD^2Sin@vD^mL^p,
u*HHa+b*Sin@vD^Hm+nLLSin@vD^mL^pD ;
IntegersQ@m,nD
TrigSimplifyAux@u_.*Ha_.*sec@v_D^m_.+b_.*cos@v_D^n_.L^p_.D :=
If@ZeroQ@m+n-2D && ZeroQ@a+bD,
u*Ha*Sin@vD^2Cos@vD^mL^p,
u*HHa+b*Cos@vD^Hm+nLLCos@vD^mL^pD ;
IntegersQ@m,nD
H* H* Basis: Csc@zD+Cot@zD == Cot@z2D *L
TrigSimplifyAux@Ha_.*csc@v_D+b_.*cot@v_DL^n_D := a^n*Cot@v2D^n ; EvenQ@nD && ZeroQ@a-bD
H* Basis: Csc@zD-Cot@zD == Tan@z2D *L
TrigSimplifyAux@Ha_.*csc@v_D+b_.*cot@v_DL^n_D := a^n*Tan@v2D^n ; EvenQ@nD && ZeroQ@a+bD *L
Integration utility functions.m | 57
H* H* Basis: Sin@zD*Ha+b*Cot@zDL == a*Sin@zD + b*Cos@zD *L
H* TrigSimplifyAux@u_*sin@v_D^m_.*Ha_.+b_.*cot@v_D^2L^p_.D :=
u*Hb*Cos@vD^2+a*Sin@vD^2L^p ;
IntegersQ@m,pD && m==2*p *L
H* Basis: a+b*Cot@zD == Hb*Cos@zD+a*Sin@zDLSin@zD *L
TrigSimplifyAux@u_.*sin@v_D^m_.*Ha_.+b_.*cot@v_D^n_.L^p_.D :=
u*Sin@vD^Hm-n*pL*Hb*Cos@vD^n+a*Sin@vD^nL^p ;
IntegersQ@m,n,pD
H* Basis: Cos@zD*Ha+b*Tan@zDL == a*Cos@zD + b*Sin@zD *L
H* TrigSimplifyAux@u_*cos@v_D^m_.*Ha_.+b_.*tan@v_D^2L^p_.D :=
u*Hb*Sin@vD^2+a*Cos@vD^2L^p ;
IntegersQ@m,pD && m==2*p *L
H* Basis: a+b*Tan@zD == Hb*Sin@zD+a*Cos@zDLCos@zD *L
TrigSimplifyAux@u_.*cos@v_D^m_.*Ha_.+b_.*tan@v_D^n_.L^p_.D :=
u*Cos@vD^Hm-n*pL*Hb*Sin@vD^n+a*Cos@vD^nL^p ;
IntegersQ@m,n,pD
H* Basis: Ha+b*Tan@zDLSec@zD == a*Cos@zD + b*Sin@zD *L
TrigSimplifyAux@u_*sec@v_D^m_.*Ha_.+b_.*tan@v_D^2L^p_.D :=
u*Hb*Sin@vD^2+a*Cos@vD^2L^p ;
IntegersQ@m,pD && m+2*p==0
H* Basis: Ha+b*Cot@zDLCsc@zD == a*Sin@zD + b*Cos@zD *L
TrigSimplifyAux@u_*csc@v_D^m_.*Ha_.+b_.*cot@v_D^2L^p_.D :=
u*Hb*Cos@vD^2+a*Sin@vD^2L^p ;
IntegersQ@m,pD && m+2*p==0 *L
H* H* Basis: If n is an integer, Sin@zD^H-nL*Ha*Cos@zD^n+b*Sin@zD^nL == b+a*Cot@zD^n *L
TrigSimplifyAux@sin@v_D^m_.*Ha_.*cos@v_D^n_.+b_.*sin@v_D^n_.L^p_D :=
Hb+a*Cot@vD^nL^p ;
IntegersQ@m,n,pD && n>0 && p<0 && m==-n*p
H* Basis: If n is an integer, Cos@zD^H-nL*Ha*Cos@zD^n+b*Sin@zD^nL == a+b*Tan@zD^n *L
TrigSimplifyAux@cos@v_D^m_.*Ha_.*cos@v_D^n_.+b_.*sin@v_D^n_.L^p_D :=
Ha+b*Tan@vD^nL^p ;
IntegersQ@m,n,pD && n>0 && p<0 && m==-n*p *L
H* H* Basis: If a^2+b^2=0, 1Ha*Cos@zD + b*Sin@zDL == Cos@zDa + Sin@zDb *L
TrigSimplifyAux@Ha_.*cos@v_D+b_.*sin@v_DL^n_D :=
HCos@vDa + Sin@vDbL^H-nL ;
IntegerQ@nD && n<0 && ZeroQ@a^2+b^2D *L
58 | Integration utility functions.m
TrigSimplifyAux@u_D := u
Factoring functions
ContentFactor
H* ContentFactor@expnD returns expn with the content of sum factors factored out. *L
H* Basis: a*b+a*c == a*Hb+cL *L
ContentFactor@expn_D :=
TimeConstrained@ContentFactorAux@expnD,TimeLimit,expnD;
ContentFactorAux@expn_D :=
If@AtomQ@expnD,
expn,
If@IntegerPowerQ@expnD,
If@SumQ@expn@@1DDD && NumericFactor@expn@@1,1DDD<0,
H-1L^expn@@2DD * ContentFactorAux@-expn@@1DDD^expn@@2DD,
ContentFactorAux@expn@@1DDD^expn@@2DDD,
If@ProductQ@expnD,
Module@8num=1,tmp<,
tmp=Map@Function@If@SumQ@ðD && NumericFactor@ð@@1DDD<0, num=-num; ContentFactorAux@-ðD, ContentFactorAux@ðDDD, expnD;
num*UnifyNegativeBaseFactors@tmpDD,
If@SumQ@expnD,
With@8lst=CommonFactors@Apply@List,expnDD<,
If@lst@@1DD===1 ÈÈ lst@@1DD===-1,
expn,
lst@@1DD*Apply@Plus,Rest@lstDDDD,
expnDDDD
H* UnifyNegativeBaseFactors@uD returns u with factors of the form H-vL^m and v^n where n is an integer replaced with H-1L^n*H-vL^
H* This should be done automatically by the host CAS! *L
UnifyNegativeBaseFactors@u_.*H-v_L^m_*v_^n_.D :=
UnifyNegativeBaseFactors@H-1L^n*u*H-vL^Hm+nLD ;
IntegerQ@nD
UnifyNegativeBaseFactors@u_D :=
u
H* If lst is a list of n terms, CommonFactors@lstD returns a n+1-element list whose first
element is the product of the factors common to all terms of lst, and whose remaining
elements are quotients of each term divided by the common factor. *L
CommonFactors @lst_D :=
Module@8lst1,lst2,lst3,lst4,common,base,num<,
lst1=Map@NonabsurdNumberFactors,lstD;
;
Integration utility functions.m | 59
lst1=Map@NonabsurdNumberFactors,lstD;
lst2=Map@AbsurdNumberFactors,lstD;
num=Apply@AbsurdNumberGCD,lst2D;
common=num;
lst2=Map@Function@ðnumD,lst2D;
While@True,
lst3=Map@LeadFactor,lst1D;
H If@Apply@SameQ,lst3D,
common=common*lst3@@1DD;
lst1=Map@RemainingFactors,lst1D,
If@MapAnd@Function@LogQ@ðD && IntegerQ@First@ðDD && First@ðD>0D,lst3D &&
MapAnd@RationalQ,lst4=Map@Function@FullSimplify@ðFirst@lst3DDD,lst3DD,
num=Apply@GCD,lst4D;
common=common*Log@HFirst@lst3D@@1DDL^numD;
lst2=Map2@Function@ð1*ð2numD,lst2,lst4D;
lst1=Map@RemainingFactors,lst1D,
lst4=Map@LeadDegree,lst1D;
If@Apply@SameQ,Map@LeadBase,lst1DD && MapAnd@RationalQ,lst4D,
num=Smallest@lst4D;
base=LeadBase@lst1@@1DDD;
H If@num!=0,
common=common*base^numD L;
lst2=Map2@Function@ð1*base^Hð2-numLD,lst2,lst4D;
lst1=Map@RemainingFactors,lst1D,
If@Length@lst1D==2 && ZeroQ@LeadBase@lst1@@1DDD+LeadBase@lst1@@2DDDD &&
NonzeroQ@lst1@@1DD-1D && IntegerQ@lst4@@1DDD && FractionQ@lst4@@2DDD,
num=Min@lst4D;
base=LeadBase@lst1@@2DDD;
H If@num!=0,
common=common*base^numD L;
lst2=8lst2@@1DD*H-1L^lst4@@1DD,lst2@@2DD<;
lst2=Map2@Function@ð1*base^Hð2-numLD,lst2,lst4D;
lst1=Map@RemainingFactors,lst1D,
If@Length@lst1D==2 && ZeroQ@LeadBase@lst1@@1DDD+LeadBase@lst1@@2DDDD &&
NonzeroQ@lst1@@2DD-1D && IntegerQ@lst4@@2DDD && FractionQ@lst4@@1DDD,
num=Min@lst4D;
base=LeadBase@lst1@@1DDD;
H If@num!=0,
common=common*base^numD L;
lst2=8lst2@@1DD,lst2@@2DD*H-1L^lst4@@2DD<;
lst2=Map2@Function@ð1*base^Hð2-numLD,lst2,lst4D;
lst1=Map@RemainingFactors,lst1D,
num=MostMainFactorPosition@lst3D;
lst2=ReplacePart@lst2,lst3@@numDD*lst2@@numDD,numD;
lst1=ReplacePart@lst1,RemainingFactors@lst1@@numDDD,numDDDDDD L;
If@MapAnd@Function@ð===1D,lst1D,
Return@Prepend@lst2,commonDDDDD
60 | Integration utility functions.m
MostMainFactorPosition@lst_ListD :=
Module@8factor=1,num=1,i<,
Do@If@FactorOrder@lst@@iDD,factorD>0,factor=lst@@iDD;num=iD,8i,Length@lstD<D;
numD
FactorOrder@u_,v_D :=
If@u===1,
If@v===1,
0,
-1D,
If@v===1,
1,
Order@u,vDDD
Smallest@num1_,num2_D :=
If@num1>0,
If@num2>0,
Min@num1,num2D,
0D,
If@num2>0,
0,
Max@num1,num2DDD
Smallest@lst_ListD :=
Module@8num=lst@@1DD<,
Scan@Function@num=Smallest@num,ðDD,Rest@lstDD;
numD
Integration utility functions.m | 61
MonomialFactor
H* MonomialFactor@u,xD returns the list 8n,v< where x^n*v==u and n is free of x. *L
MonomialFactor@u_,x_SymbolD :=
If@AtomQ@uD,
If@u===x,
81,1<,
80,u<D,
If@PowerQ@uD,
If@IntegerQ@u@@2DDD,
With@8lst=MonomialFactor@u@@1DD,xD<,
8lst@@1DD*u@@2DD,lst@@2DD^u@@2DD<D,
If@u@@1DD===x && FreeQ@u@@2DD,xD,
8u@@2DD,1<,
80,u<DD,
If@ProductQ@uD,
With@8lst1=MonomialFactor@First@uD,xD,lst2=MonomialFactor@Rest@uD,xD<,
8lst1@@1DD+lst2@@1DD,lst1@@2DD*lst2@@2DD<D,
If@SumQ@uD,
Module@8lst,deg<,
lst=Map@Function@MonomialFactor@ð,xDD,Apply@List,uDD;
deg=lst@@1,1DD;
Scan@Function@deg=MinimumDegree@deg,ð@@1DDDD,Rest@lstDD;
If@ZeroQ@degD ÈÈ RationalQ@degD && deg<0,
80,u<,
8deg,Apply@Plus,Map@Function@x^Hð@@1DD-degL*ð@@2DDD,lstDD<DD,
80,u<DDDD
MinimumDegree@deg1_,deg2_D :=
If@RationalQ@deg1D,
If@RationalQ@deg2D,
Min@deg1,deg2D,
deg1D,
If@RationalQ@deg2D,
deg2,
With@8deg=Simplify@deg1-deg2D<,
If@RationalQ@degD,
If@deg>0,
deg2,
deg1D,
If@OrderedQ@8deg1,deg2<D,
deg1,
deg2DDDDD
62 | Integration utility functions.m
ConstantFactor
H* ConstantFactor@u,xD returns a 2-element list of the factors of u@xD free of x and the
factors not free of u@xD. Common constant factors of the terms of sums are also collected. *L
ConstantFactor@u_,x_SymbolD :=
If@FreeQ@u,xD,
8u,1<,
If@AtomQ@uD,
81,u<,
If@PowerQ@uD && FreeQ@u@@2DD,xD,
Module@8lst=ConstantFactor@u@@1DD,xD,tmp<,
If@IntegerQ@u@@2DDD,
8lst@@1DD^u@@2DD,lst@@2DD^u@@2DD<,
tmp=PositiveFactors@lst@@1DDD;
If@tmp===1,
81,u<,
8tmp^u@@2DD,HNonpositiveFactors@lst@@1DDD*lst@@2DDL^u@@2DD<DDD,
If@ProductQ@uD,
With@8lst=Map@Function@ConstantFactor@ð,xDD,Apply@List,uDD<,
8Apply@Times,Map@First,lstDD,Apply@Times,Map@Function@ð@@2DDD,lstDD<D,
If@SumQ@uD,
With@8lst1=Map@Function@ConstantFactor@ð,xDD,Apply@List,uDD<,
If@Apply@SameQ,Map@Function@ð@@2DDD,lst1DD,
8Apply@Plus,Map@First,lst1DD,lst1@@1,2DD<,
With@8lst2=CommonFactors@Map@First,lst1DD<,
8First@lst2D,Apply@Plus,Map2@Times,Rest@lst2D,Map@Function@ð@@2DDD,lst1DDD<DDD,
81,u<DDDDD
H* PositiveFactors@uD returns the positive factors of u *L
PositiveFactors@u_D :=
If@ZeroQ@uD,
1,
If@RationalQ@uD,
Abs@uD,
If@PositiveQ@uD,
u,
If@ProductQ@uD,
Map@PositiveFactors,uD,
1DDDD
Integration utility functions.m | 63
H* NonpositiveFactors@uD returns the nonpositive factors of u *L
NonpositiveFactors@u_D :=
If@ZeroQ@uD,
u,
If@RationalQ@uD,
Sign@uD,
If@PositiveQ@uD,
1,
If@ProductQ@uD,
Map@NonpositiveFactors,uD,
uDDDD
Generalized polynomial functions
PolynomialInQ
è If u is a polynomial in v[x], PolynomialInQ[u,v,x] returns True; else it returns False.
PolynomialInQ@u_,v_,x_SymbolD :=
PolynomialInAuxQ@u,NonfreeFactors@NonfreeTerms@v,xD,xD,xD
PolynomialInAuxQ@u_,v_,x_D :=
If@u===v,
True,
If@AtomQ@uD,
u=!=x,
If@PowerQ@uD,
If@PowerQ@vD && u@@1DD===v@@1DD,
PositiveIntegerQ@u@@2DDv@@2DDD,
PositiveIntegerQ@u@@2DDD && PolynomialInAuxQ@u@@1DD,v,xDD,
If@SumQ@uD ÈÈ ProductQ@uD,
Catch@Scan@Function@If@Not@PolynomialInAuxQ@ð,v,xDD,Throw@FalseDDD,uD;TrueD,
FalseDDDD
ExponentIn
è If u[v] is a polynomial in w, GeneralizedExponent[u,v,x] returns the degree of the u[x].
ExponentIn@u_,v_,x_SymbolD :=
ExponentInAux@u,NonfreeFactors@NonfreeTerms@v,xD,xD,xD
64 | Integration utility functions.m
ExponentInAux@u_,v_,x_D :=
If@u===v,
1,
If@AtomQ@uD,
0,
If@PowerQ@uD,
If@PowerQ@vD && u@@1DD===v@@1DD,
u@@2DDv@@2DD,
u@@2DD*ExponentInAux@u@@1DD,v,xDD,
If@ProductQ@uD,
Apply@Plus,Map@Function@ExponentInAux@ð,v,xDD,Apply@List,uDDD,
Apply@Max,Map@Function@ExponentInAux@ð,v,xDD,Apply@List,uDDDDDDD
PolynomialInSubst
è If u is a polynomial in v[x], PolynomialInSubst[u,v,x] returns the polynomial u in x.
PolynomialInSubst@u_,v_,x_SymbolD :=
With@8w=NonfreeTerms@v,xD<,
ReplaceAll@PolynomialInSubstAux@u,NonfreeFactors@w,xD,xD,8x->Hx-FreeTerms@v,xDLFreeFactors@w,xD<DD
PolynomialInSubstAux@u_,v_,x_D :=
If@u===v,
x,
If@AtomQ@uD,
u,
If@PowerQ@uD,
If@PowerQ@vD && u@@1DD===v@@1DD,
x^Hu@@2DDv@@2DDL,
PolynomialInSubstAux@u@@1DD,v,xD^u@@2DDD,
Map@Function@PolynomialInSubstAux@ð,v,xDD,uDDDD
PolynomialDivide
è u and v are polynomials in x. PolynomialDivide[u,v,x] returns the polynomial quotient of u and v plus the polynomial remainder divided by v.
Integration utility functions.m | 65
PolynomialDivide@u_,v_,x_SymbolD :=
Module@8quo=PolynomialQuotient@u,v,xD,rem=PolynomialRemainder@u,v,xD,free,monomial<,
quo=Apply@Plus,Map@Function@Simp@Together@Coefficient@quo,x,ðD*x^ðD,xDD,Exponent@quo,x,ListDDD;
rem=Together@remD;
free=FreeFactors@rem,xD;
rem=NonfreeFactors@rem,xD;
monomial=x^Exponent@rem,x,MinD;
If@NegQ@Coefficient@rem,x,0DD, monomial=-monomialD;
rem=Apply@Plus,Map@Function@Simp@Together@Coefficient@rem,x,ðD*x^ðmonomialD,xDD,Exponent@rem,x,ListDDD;
H*rem=Simplify@remD; *L
If@BinomialQ@v,xD,
quo+free*monomial*remExpandToSum@v,xD,
quo+free*monomial*remvDD
è u[w] and v[w] are polynomials in w. PolynomialDivide[u,v,w,x] returns the polynomial quotient of u[x] and v[x] plus the polynomial remainder divided by v[x] with
x replaced by w.
PolynomialDivide@u_,v_,w_,x_SymbolD :=
ReplaceAll@PolynomialDivide@PolynomialInSubst@u,w,xD,PolynomialInSubst@v,w,xD,xD,8x->w<D
Expansion functions
ExpandToSum[u,x]
è ExpandToSum[u,v,x] returns v expanded into a sum of monomials of x and distributes u over v.
ExpandToSum@u_,v_,x_SymbolD :=
Module@8w=ExpandToSum@v,xD,r<,
r=NonfreeTerms@w,xD;
If@SumQ@rD,
u*FreeTerms@w,xD+Map@Function@MergeMonomials@u*ð,xDD,rD,
u*FreeTerms@w,xD+MergeMonomials@u*r,xDDD
è ExpandToSum[u,x] returns u expanded into a sum of monomials of x.
66 | Integration utility functions.m
ExpandToSum@u_,x_SymbolD :=
If@PolyQ@u,xD,
Apply@Plus,Map@Function@Coeff@u,x,ðD*x^ðD, Expon@u,x,ListDDD,
If@BinomialQ@u,xD,
Function@ð@@1DD + ð@@2DD*x^ð@@3DDD@BinomialParts@u,xDD,
If@TrinomialQ@u,xD,
Function@ð@@1DD + ð@@2DD*x^ð@@4DD + ð@@3DD*x^H2*ð@@4DDLD@TrinomialParts@u,xDD,
If@GeneralizedBinomialQ@u,xD,
Function@ð@@1DD*x^ð@@4DD + ð@@2DD*x^ð@@3DDD@GeneralizedBinomialParts@u,xDD,
If@GeneralizedTrinomialQ@u,xD,
Function@ð@@1DD*x^ð@@5DD + ð@@2DD*x^ð@@4DD + ð@@3DD*x^H2*ð@@4DD-ð@@5DDLD@GeneralizedTrinomialParts@u,xDD,
Print@"Warning: Unrecognized expression for expansion ",uD;
Expand@u,xDDDDDD
ExpandTrig[u,x]
ExpandTrig@u_,x_SymbolD :=
ActivateTrig@ExpandIntegrand@u,xDD
ExpandTrig@u_,v_,x_SymbolD :=
With@8w=ExpandTrig@v,xD,z=ActivateTrig@uD<,
If@SumQ@wD,
Map@Function@z*ðD,wD,
z*wDD
ExpandIntegrand[u,x]
Clear@ExpandIntegrandD;
ExpandIntegrand@u_,v_,x_SymbolD :=
Module@8w=ExpandIntegrand@v,xD,r<,
r=NonfreeTerms@w,xD;
If@SumQ@rD,
u*FreeTerms@w,xD+Map@Function@MergeMonomials@u*ð,xDD,rD,
u*FreeTerms@w,xD+MergeMonomials@u*r,xDDD
H* ExpandIntegrand@u_,x_SymbolD :=
With@8nn=FunctionOfPower@u,xD<,
ReplaceAll@ExpandIntegrand@SubstFor@x^nn,u,xD,xD,x->x^nnD ;
nn!=1D *L
Integration utility functions.m | 67
Basis: (a+b x)^m/(c+d x)==(b (a+b x)^(m-1))/d+((a d-b c) (a+b x)^(m-1))/(d (c+d x))
ExpandIntegrandAHa_.+b_.*x_L^m_.*f_^He_.*Hc_.+d_.*x_L^n_.LHg_.+h_.*x_L,x_SymbolE :=
With@8tmp=a*h-b*g<,
Module@8k<,
SimplifyTerm@tmp^mh^m,xD*f^He*Hc+d*xL^nLHg+h*xL +
Sum@SimplifyTerm@b*tmp^Hk-1Lh^k,xD*f^He*Hc+d*xL^nL*Ha+b*xL^Hm-kL,8k,1,m<DDD ;
FreeQ@8a,b,c,d,e,f,g,h<,xD && PositiveIntegerQ@mD && ZeroQ@b*c-a*dD
ExpandIntegrand@x_^m_.*He_+f_.*x_L^p_.*F_^Hb_.*Hc_.+d_.*x_L^n_.L,x_SymbolD :=
If@PositiveIntegerQ@m,pD && m<=p && HEqQ@n,1D ÈÈ ZeroQ@d*e-c*fDL,
ExpandLinearProduct@He+f*xL^p*F^Hb*Hc+d*xL^nL,x^m,e,f,xD,
If@PositiveIntegerQ@pD,
Distribute@x^m*F^Hb*Hc+d*xL^nL*Expand@He+f*xL^p,xD,Plus,TimesD,
ExpandIntegrand@F^Hb*Hc+d*xL^nL,x^m*He+f*xL^p,xDDD ;
FreeQ@8F,b,c,d,e,f,m,n,p<,xD
ExpandIntegrand@x_^m_.*He_+f_.*x_L^p_.*F_^Ha_.+b_.*Hc_.+d_.*x_L^n_.L,x_SymbolD :=
If@PositiveIntegerQ@m,pD && m<=p && HEqQ@n,1D ÈÈ ZeroQ@d*e-c*fDL,
ExpandLinearProduct@He+f*xL^p*F^Ha+b*Hc+d*xL^nL,x^m,e,f,xD,
If@PositiveIntegerQ@pD,
Distribute@x^m*F^Ha+b*Hc+d*xL^nL*Expand@He+f*xL^p,xD,Plus,TimesD,
ExpandIntegrand@F^Ha+b*Hc+d*xL^nL,x^m*He+f*xL^p,xDDD ;
FreeQ@8F,a,b,c,d,e,f,m,n,p<,xD
ExpandIntegrand@u_.*Ha_+b_.*F_^v_L^m_.*Hc_+d_.*F_^v_L^n_,x_SymbolD :=
With@8w=ReplaceAll@ExpandIntegrand@Ha+b*xL^m*Hc+d*xL^n,xD,x->F^vD<,
Map@Function@u*ðD,wD ;
SumQ@wDD ;
FreeQ@8F,a,b,c,d<,xD && IntegersQ@m,nD && n<0
ExpandIntegrand@u_*Ha_.+b_.*x_L^m_.*f_^He_.*Hc_.+d_.*x_L^n_.L,x_SymbolD :=
With@8v=ExpandIntegrand@u*Ha+b*xL^m,xD<,
Distribute@f^He*Hc+d*xL^nL*v,Plus,TimesD ;
SumQ@vDD ;
FreeQ@8a,b,c,d,e,f,m,n<,xD && PolynomialQ@u,xD
ExpandIntegrand@u_*Ha_.+b_.*x_L^m_.*Log@c_.*Hd_.+e_.*x_^n_.L^p_.D,x_SymbolD :=
ExpandIntegrand@Log@c*Hd+e*x^nL^pD,u*Ha+b*xL^m,xD ;
FreeQ@8a,b,c,d,e,m,n,p<,xD && PolynomialQ@u,xD
ExpandIntegrand@u_*f_^He_.*Hc_.+d_.*x_L^n_.L,x_SymbolD :=
If@EqQ@n,1D,
ExpandIntegrand@f^He*Hc+d*xL^nL,u,xD,
ExpandLinearProduct@f^He*Hc+d*xL^nL,u,c,d,xDD ;
FreeQ@8c,d,e,f,n<,xD && PolynomialQ@u,xD
68 | Integration utility functions.m
ExpandIntegrand@F_@u_D^m_.*Ha_+b_.*G_@u_DL^n_.,x_SymbolD :=
ReplaceAll@ExpandIntegrand@Ha+b*xL^nx^m,xD,x->G@uDD ;
FreeQ@8a,b<,xD && IntegersQ@m,nD && F@uD*G@uD===1
ExpandIntegrand@u_*Ha_.+b_.*Log@c_.*Hd_.*He_.+f_.*x_L^p_.L^q_.DL^n_,x_SymbolD :=
ExpandLinearProduct@Ha+b*Log@c*Hd*He+f*xL^pL^qDL^n,u,e,f,xD ;
FreeQ@8a,b,c,d,e,f,n,p,q<,xD && PolynomialQ@u,xD
ExpandIntegrand@u_*Ha_.+b_.*F_@c_.+d_.*x_DL^n_,x_SymbolD :=
ExpandLinearProduct@Ha+b*F@c+d*xDL^n,u,c,d,xD ;
FreeQ@8a,b,c,d,n<,xD && PolynomialQ@u,xD && MemberQ@8ArcSin,ArcCos,ArcSinh,ArcCosh<,FD
Basis: 1/(a x^n+b Sqrt[c+d x^(2 n)])==(a x^n-b Sqrt[c+d x^(2 n)])/(-b^2 c+(a^2-b^2 d) x^(2 n))
ExpandIntegrandAu_.Ha_.*x_^n_+b_.*Sqrt@c_+d_.*x_^j_DL,x_SymbolE :=
ExpandIntegrand@u*Ha*x^n-b*Sqrt@c+d*x^H2*nLDLH-b^2*c+Ha^2-b^2*dL*x^H2*nLL,xD ;
FreeQ@8a,b,c,d,n<,xD && ZeroQ@j-2*nD
Basis: (a+b x)^m/(c+d x)==(b (a+b x)^(m-1))/d+((a d-b c) (a+b x)^(m-1))/(d (c+d x))
ExpandIntegrandAHa_+b_.*x_L^m_Hc_+d_.*x_L,x_SymbolE :=
If@RationalQ@a,b,c,dD,
ExpandExpression@Ha+b*xL^mHc+d*xL,xD,
With@8tmp=a*d-b*c<,
Module@8k<,
SimplifyTerm@tmp^md^m,xDHc+d*xL + Sum@SimplifyTerm@b*tmp^Hk-1Ld^k,xD*Ha+b*xL^Hm-kL,8k,1,m<DDDD ;
FreeQ@8a,b,c,d<,xD && PositiveIntegerQ@mD
Basis: ((a+b x)^m (A+B x))/(c+d x)==(B (a+b x)^m)/d+((A d-B c) (a+b x)^m)/(d (c+d x))
ExpandIntegrandAHa_+b_.*x_L^m_.*HA_+B_.*x_LHc_+d_.*x_L,x_SymbolE :=
If@RationalQ@a,b,c,d,A,BD,
ExpandExpression@Ha+b*xL^m*HA+B*xLHc+d*xL,xD,
Module@8tmp1,tmp2<,
tmp1=HA*d-B*cLd;
tmp2=ExpandIntegrand@Ha+b*xL^mHc+d*xL,xD;
tmp2=If@SumQ@tmp2D, Map@Function@SimplifyTerm@tmp1*ð,xDD,tmp2D, SimplifyTerm@tmp1*tmp2,xDD;
SimplifyTerm@Bd,xD*Ha+b*xL^m + tmp2DD ;
FreeQ@8a,b,c,d,A,B<,xD && PositiveIntegerQ@mD
Integration utility functions.m | 69
H* If u is a polynomial in x, ExpandIntegrand@u*Ha+b*xL^m,xD expand u*Ha+b*xL^m into a sum of terms of the form A*Ha+b*xL^n. *L
ExpandIntegrand@u_*Ha_+b_.*x_L^m_,x_SymbolD :=
Module@8tmp1,tmp2<,
tmp1=ExpandLinearProduct@Ha+b*xL^m,u,a,b,xD;
If@Not@IntegerQ@mDD,
tmp1,
tmp2=ExpandExpression@u*Ha+b*xL^m,xD;
If@SumQ@tmp2D && LeafCount@tmp2D<=LeafCount@tmp1D+2,
tmp2,
tmp1DDD ;
FreeQ@8a,b,m<,xD && PolynomialQ@u,xD &&
Not@PositiveIntegerQ@mD && MatchQ@u,w_.*Hc_+d_.*xL^p_ ; FreeQ@8c,d<,xD && IntegerQ@pD && p>mDD
H* If u is a polynomial in x, ExpandIntegrand@u*Ha+b*xL^m,xD expand u*Ha+b*xL^m into a sum of terms of the form A*Ha+b*xL^n. *L
ExpandIntegrand@u_*v_^n_*Ha_+b_.*x_L^m_,x_SymbolD :=
Function@ExpandIntegrand@ð@@1DD*Ha+b*xL^FractionalPart@mD,xD + ExpandIntegrand@ð@@2DD*v^n*Ha+b*xL^m,xDD@
PolynomialQuotientRemainder@u,v^H-nL*Ha+b*xL^H-IntegerPart@mDL,xDD;
FreeQ@8a,b,m<,xD && NegativeIntegerQ@nD && Not@IntegerQ@mDD && PolynomialQ@u,xD && PolynomialQ@v,xD &&
RationalQ@mD && m<-1 && Exponent@u,xD>=-Hn+IntegerPart@mDL*Exponent@v,xD
H* If u is a polynomial in x, ExpandIntegrand@u*Ha+b*xL^m,xD expand u*Ha+b*xL^m into a sum of terms of the form A*Ha+b*xL^n. *L
ExpandIntegrand@u_*v_^n_*Ha_+b_.*x_L^m_,x_SymbolD :=
Function@ExpandIntegrand@ð@@1DD*Ha+b*xL^m,xD + ExpandIntegrand@ð@@2DD*v^n*Ha+b*xL^m,xDD@PolynomialQuotientRemainder@u,v^H-nL,xD
FreeQ@8a,b,m<,xD && NegativeIntegerQ@nD && Not@IntegerQ@mDD && PolynomialQ@u,xD && PolynomialQ@v,xD &&
Exponent@u,xD>=-n*Exponent@v,xD
Basis: Let r/s=(-(a/b))^(1/3), then 1/(a+b z^3)==r/(3a(r-s z))+(r(2 r+s z))/(3a(r^2+r s z+s^2 z^2))
H* ExpandIntegrandA1Ha_+b_.*u_^3L,x_SymbolE :=
With@8r=Numerator@Rt@-ab,3DD,s=Denominator@Rt@-ab,3DD<,
rH3*a*Hr-s*uLL + r*H2*r+s*uLH3*a*Hr^2+r*s*u+s^2*u^2LLD ;
FreeQ@8a,b<,xD *L
Basis: Let r/s=Sqrt[-(a/b)], then 1/(a+b z^2)==r/(2a(r-s z))+r/(2a(r+s z))
ExpandIntegrandA1Ha_+b_.*u_^n_L,x_SymbolE :=
With@8r=Numerator@Rt@-ab,2DD,s=Denominator@Rt@-ab,2DD<,
rH2*a*Hr-s*u^Hn2LLL + rH2*a*Hr+s*u^Hn2LLLD ;
FreeQ@8a,b<,xD && PositiveIntegerQ@n4D
70 | Integration utility functions.m
Basis: If nÎSuperPlus[Z], let r/s=(-(a/b))^(1/n), then 1/(a + b*z^n) == (r*Sum[1/(r - (-1)^(2*(k/n))*s*z), {k, 1, n}])/(a*n)
ExpandIntegrandA1Ha_+b_.*u_^n_L,x_SymbolE :=
With@8r=Numerator@Rt@-ab,nDD,s=Denominator@Rt@-ab,nDD<,
Module@8k<,
Sum@rHa*n*Hr-H-1L^H2*knL*s*uLL,8k,1,n<DDD ;
FreeQ@8a,b<,xD && IntegerQ@nD && n>1
Basis: If (m|(n-1)/2)ÎZ ß 0<=m<n, let r/s=(a/b)^(1/n), then z^m/(a + b*z^n) == (r*(-(r/s))^m*Sum[1/((-1)^(2*k*(m/n))*(r + (-1)^(2*(k/n))*s*z)), {k, 1,
n}])/(a*n) == (r*(-(r/s))^m*Sum[(-1)^(2*k*((m + 1)/n))/((-1)^(2*(k/n))*r + s*z), {k, 1, n}])/(a*n)
Note: If m+1 and n are not coprime, the second summation is used since the coefficient (-1)^(2 k (m+1)/n) will be simpler.
Note: The code reduces the exponents by their gcd.
ExpandIntegrandAu_^m_.Ha_+b_.*u_^n_L,x_SymbolE :=
With@8g=GCD@m,nD,r=Numerator@Rt@ab,nGCD@m,nDDD,s=Denominator@Rt@ab,nGCD@m,nDDD<,
Module@8k<,
If@CoprimeQ@m+g,nD,
Sum@r*H-rsL^HmgL*H-1L^H-2*k*mnLHa*n*Hr+H-1L^H2*k*gnL*s*u^gLL,8k,1,ng<D,
Sum@r*H-rsL^HmgL*H-1L^H2*k*Hm+gLnLHa*n*HH-1L^H2*k*gnL*r+s*u^gLL,8k,1,ng<DDDD ;
FreeQ@8a,b<,xD && IntegersQ@m,nD && 0<m<n && OddQ@nGCD@m,nDD && PosQ@abD
Basis: If r/s=(-(a/b))^(1/2), then z/(a+b z^2)==s/(2b(r+s z))-s/(2b(r-s z))==r^2/(2 a s (r-s z))-r^2/(2 a s (r+s z))
Basis: If (m|n)ÎZ ß 0<=m<n, let r/s=(-(a/b))^(1/n), then z^m/(a + b*z^n) == (r*(r/s)^m*Sum[1/((-1)^(2*k*(m/n))*(r - (-1)^(2*(k/n))*s*z)), {k, 1, n}])/(a*n) ==
(r*(r/s)^m*Sum[(-1)^(2*k*((m + 1)/n))/((-1)^(2*(k/n))*r - s*z), {k, 1, n}])/(a*n)
Note: If m+1 and n are not coprime, the second summation is used since the coefficient (-1)^(2 k (m+1)/n) will be simpler.
Note: The code reduces the exponents by their gcd.
ExpandIntegrandAu_^m_.Ha_+b_.*u_^n_L,x_SymbolE :=
With@8g=GCD@m,nD,r=Numerator@Rt@-ab,nGCD@m,nDDD,s=Denominator@Rt@-ab,nGCD@m,nDDD<,
If@ng==2,
sH2*b*Hr+s*u^gLL - sH2*b*Hr-s*u^gLL,
Module@8k<,
If@CoprimeQ@m+g,nD,
Sum@r*HrsL^HmgL*H-1L^H-2*k*mnLHa*n*Hr-H-1L^H2*k*gnL*s*u^gLL,8k,1,ng<D,
Sum@r*HrsL^HmgL*H-1L^H2*k*Hm+gLnLHa*n*HH-1L^H2*k*gnL*r-s*u^gLL,8k,1,ng<DDDDD ;
FreeQ@8a,b<,xD && IntegersQ@m,nD && 0<m<n
Integration utility functions.m | 71
Basis: If (m|n)ÎZ ß 0<=m<n, let r/s=(-(a/b))^(1/n), then (c + d*z^m)/(a + b*z^n) == (r*Sum[(c + (d*(r/s)^m)/(-1)^(2*k*(m/n)))/(r - (-1)^(2*(k/n))*s*z), {k, 1,
n}])/(a*n)
ExpandIntegrandAHc_+d_.*u_^m_.LHa_+b_.*u_^n_L,x_SymbolE :=
With@8r=Numerator@Rt@-ab,nDD,s=Denominator@Rt@-ab,nDD<,
Module@8k<,
Sum@Hr*c+r*d*HrsL^m*H-1L^H-2*k*mnLLHa*n*Hr-H-1L^H2*knL*s*uLL,8k,1,n<DDD ;
FreeQ@8a,b,c,d<,xD && IntegersQ@m,nD && 0<m<n
Basis: If (m|n,p)ÎZ ß 0<=m<p<n, let r/s=(-(a/b))^(1/n), then (c + d*z^m + e*z^p)/(a + b*z^n) == (r*Sum[(c + (d*(r/s)^m)/(-1)^(2*k*(m/n)) +
(e*(r/s)^p)/(-1)^(2*k*(p/n)))/(r - (-1)^(2*(k/n))*s*z), {k, 1, n}])/(a*n)
ExpandIntegrandAHc_.+d_.*u_^m_.+e_.*u_^p_LHa_+b_.*u_^n_L,x_SymbolE :=
With@8r=Numerator@Rt@-ab,nDD,s=Denominator@Rt@-ab,nDD<,
Module@8k<,
Sum@Hr*c+r*d*HrsL^m*H-1L^H-2*k*mnL+r*e*HrsL^p*H-1L^H-2*k*pnLLHa*n*Hr-H-1L^H2*knL*s*uLL,8k,1,n<DDD ;
FreeQ@8a,b,c,d,e<,xD && IntegersQ@m,n,pD && 0<m<p<n
Basis: If (m|n,p,q)ÎZ ß 0<=m<p<q<n, let r/s=(-(a/b))^(1/n), then (c + d*z^m + e*z^p + f*z^q)/(a + b*z^n) == (r*Sum[(c + (d*(r/s)^m)/(-1)^(2*k*(m/n)) +
(e*(r/s)^p)/(-1)^(2*k*(p/n)) + (f*(r/s)^q)/(-1)^(2*k*(q/n)))/(r - (-1)^(2*(k/n))*s*z), {k, 1, n}])/(a*n)
ExpandIntegrandAHc_.+d_.*u_^m_.+e_.*u_^p_+f_.*u_^q_LHa_+b_.*u_^n_L,x_SymbolE :=
With@8r=Numerator@Rt@-ab,nDD,s=Denominator@Rt@-ab,nDD<,
Module@8k<,
Sum@Hr*c+r*d*HrsL^m*H-1L^H-2*k*mnL+r*e*HrsL^p*H-1L^H-2*k*pnL+r*f*HrsL^q*H-1L^H-2*k*qnLLHa*n*Hr-H-1L^H2*knL*s*uLL,8k,1,n
FreeQ@8a,b,c,d,e,f<,xD && IntegersQ@m,n,p,qD && 0<m<p<q<n
Basis: If q=Sqrt[-a c], then a+c z^2==((-q+c z)(q+c z))/c
ExpandIntegrand@Ha_+c_.*u_^n_.L^p_,x_SymbolD :=
Module@8q<,
ReplaceAll@ExpandIntegrand@1c^p,H-q+c*xL^p*Hq+c*xL^p,xD,8q->Rt@-a*c,2D,x->u^Hn2L<DD ;
FreeQ@8a,c<,xD && IntegerQ@n2D && NegativeIntegerQ@pD
ExpandIntegrand@u_^m_.*Ha_.+c_.*u_^n_.L^p_,x_SymbolD :=
Module@8q<,
ReplaceAll@ExpandIntegrand@1c^p,x^m*H-q+c*x^Hn2LL^p*Hq+c*x^Hn2LL^p,xD,8q->Rt@-a*c,2D,x->u<DD ;
FreeQ@8a,c<,xD && IntegersQ@m,n2D && NegativeIntegerQ@pD && 0<m<n && m!=n2
Basis: If q=Sqrt[b^2-4 a c], then a+b z+c z^2 == (b-q+2 c z)(b+q+2 c z)/(4 c)
ExpandIntegrand@Ha_.+b_.*u_^n_.+c_.*u_^j_.L^p_,x_SymbolD :=
Module@8q<,
ReplaceAll@ExpandIntegrand@1H4^p*c^pL,Hb-q+2*c*xL^p*Hb+q+2*c*xL^p,xD,8q->Rt@b^2-4*a*c,2D,x->u^n<DD ;
FreeQ@8a,b,c<,xD && IntegerQ@nD && ZeroQ@j-2*nD && NegativeIntegerQ@pD && NonzeroQ@b^2-4*a*cD
72 | Integration utility functions.m
ExpandIntegrand@u_^m_.*Ha_.+b_.*u_^n_.+c_.*u_^j_.L^p_,x_SymbolD :=
Module@8q<,
ReplaceAll@ExpandIntegrand@1H4^p*c^pL,x^m*Hb-q+2*c*x^nL^p*Hb+q+2*c*x^nL^p,xD,8q->Rt@b^2-4*a*c,2D,x->u<DD ;
FreeQ@8a,b,c<,xD && IntegersQ@m,n,jD && ZeroQ@j-2*nD && NegativeIntegerQ@pD && 0<m<2*n && Not@m==n && p==-1D && NonzeroQ@b^2-4*a* D
Basis: If q=Sqrt[-(a/b)], then (c+d z)/(a+b z^2)==-((c-d q)/(2 b q(q+z)))-(c+d q)/(2 b q(q-z))
ExpandIntegrandAHc_.+d_.*u_^n_.LHa_+b_.*u_^j_.L,x_SymbolE :=
With@8q=Rt@-ab,2D<,
-Hc-d*qLH2*b*q*Hq+u^nLL - Hc+d*qLH2*b*q*Hq-u^nLLD ;
FreeQ@8a,b,c,d,n<,xD && ZeroQ@j-2*nD
Basis: If q=Sqrt[b^2-4a c] and r=(2 c d-b e)/q, then (d+e z)/(a+b z+c z^2)==(e+r)/(b-q+2 c z)+(e-r)/(b+q+2 c z)
ExpandIntegrandAHd_.+e_.*u_^n_.LHa_.+b_.*u_^n_.+c_.*u_^j_.L,x_SymbolE :=
With@8q=Rt@b^2-4*a*c,2D<, With@8r=TogetherSimplify@H2*c*d-b*eLqD<,
He+rLHb-q+2*c*u^nL + He-rLHb+q+2*c*u^nLDD ;
FreeQ@8a,b,c,d,e,n<,xD && ZeroQ@j-2*nD && NonzeroQ@b^2-4*a*cD
ExpandIntegrandAu_v_,x_SymbolE :=
With@8lst=CoefficientList@u,xD<,
Module@8i<,
lst@@-1DD*x^Exponent@u,xDv + Sum@lst@@iDD*x^Hi-1L,8i,1,Exponent@u,xD<DvDD ;
PolynomialQ@u,xD && PolynomialQ@v,xD && BinomialQ@v,xD && Exponent@u,xD==Exponent@v,xD-1>=2
ExpandIntegrandAu_v_,x_SymbolE :=
PolynomialDivide@u,v,xD ;
PolynomialQ@u,xD && PolynomialQ@v,xD && Exponent@u,xD>=Exponent@v,xD
ExpandIntegrand@u_*Ha_.*x_L^p_,x_SymbolD :=
ExpandToSum@Ha*xL^p,u,xD ;
Not@IntegerQ@pDD && PolynomialQ@u,xD
ExpandIntegrand@u_.*v_^p_,x_SymbolD :=
ExpandIntegrand@NormalizeIntegrand@v^p,xD,u,xD ;
Not@IntegerQ@pDD
ExpandIntegrand@u_,x_SymbolD :=
ExpandExpression@u,xD
Integration utility functions.m | 73
ExpandExpression[u,x]
ExpandExpression@u_,x_SymbolD :=
Module@8v,w<,
v=If@AlgebraicFunctionQ@u,xD && Not@RationalFunctionQ@u,xDD, ExpandAlgebraicFunction@u,xD, 0D;
If@SumQ@vD,
ExpandCleanup@v,xD,
v=SmartApart@u,xD;
If@SumQ@vD,
ExpandCleanup@v,xD,
v=SmartApart@RationalFunctionFactors@u,xD,x,xD;
If@SumQ@vD,
w=NonrationalFunctionFactors@u,xD;
ExpandCleanup@Map@Function@ð*wD,vD,xD,
v=Expand@u,xD;
If@SumQ@vD,
ExpandCleanup@v,xD,
v=Expand@uD;
If@SumQ@vD,
ExpandCleanup@v,xD,
SimplifyTerm@u,xDDDDDDD
ExpandCleanup@u_,x_SymbolD :=
Module@8v<,
v=CollectReciprocals@u,xD;
If@SumQ@vD,
v=Map@Function@SimplifyTerm@ð,xDD,vD;
If@SumQ@vD,
UnifySum@v,xD,
vD,
vDD
Basis: e/(a+b x)+f/(c+d x)==(c e+a f+(d e+b f) x)/(a c+(b c+a d) x+b d x^2)
CollectReciprocalsAu_.+e_Ha_+b_.*x_L+f_Hc_+d_.*x_L,x_SymbolE :=
CollectReciprocals@u+Hc*e+a*fLHa*c+b*d*x^2L,xD ;
FreeQ@8a,b,c,d,e,f<,xD && ZeroQ@b*c+a*dD && ZeroQ@d*e+b*fD
CollectReciprocalsAu_.+e_Ha_+b_.*x_L+f_Hc_+d_.*x_L,x_SymbolE :=
CollectReciprocals@u+Hd*e+b*fL*xHa*c+b*d*x^2L,xD ;
FreeQ@8a,b,c,d,e,f<,xD && ZeroQ@b*c+a*dD && ZeroQ@c*e+a*fD
CollectReciprocals@u_,x_SymbolD := u
74 | Integration utility functions.m
SmartApart[u,x]
H* SmartApart@u,xD returns the partial fraction expansion of u wrt x, avoiding the
strange behavior in the built-in Apart function that rationalizes denominators
involving fractional powers resulting in hard to integrate expressions. *L
SmartApart@u_,x_SymbolD :=
With@8alst=MakeAssocList@u,xD<,
With@8tmp=KernelSubst@Apart@GensymSubst@u,x,alstDD,x,alstD<,
If@tmp===Indeterminate, u, tmpDDD
SmartApart@u_,v_,x_SymbolD :=
With@8alst=MakeAssocList@u,xD<,
With@8tmp=KernelSubst@Apart@GensymSubst@u,x,alstD,vD,x,alstD<,
If@tmp===Indeterminate, u, tmpDDD
H* MakeAssocList@u,x,alstD returns an association list of gensymed symbols with the nonatomic
parameters of a u that are not integer powers, products or sums. *L
MakeAssocList@u_,x_Symbol,alst_List:8<D :=
If@AtomQ@uD,
alst,
If@IntegerPowerQ@uD,
MakeAssocList@u@@1DD,x,alstD,
If@ProductQ@uD ÈÈ SumQ@uD,
MakeAssocList@Rest@uD,x,MakeAssocList@First@uD,x,alstDD,
If@FreeQ@u,xD,
With@8tmp=Select@alst,Function@ð@@2DD===uD,1D<,
If@tmp===8<,
Append@alst,8Unique@"Rubi"D,u<D,
alstDD,
alstDDDD
H* GensymSubst@u,x,alstD returns u with the kernels in alst free of x replaced by gensymed names. *L
GensymSubst@u_,x_Symbol,alst_ListD :=
If@AtomQ@uD,
u,
If@IntegerPowerQ@uD,
GensymSubst@u@@1DD,x,alstD^u@@2DD,
If@ProductQ@uD ÈÈ SumQ@uD,
Map@Function@GensymSubst@ð,x,alstDD,uD,
If@FreeQ@u,xD,
With@8tmp=Select@alst,Function@ð@@2DD===uD,1D<,
If@tmp===8<,
u,
tmp@@1,1DDDD,
uDDDD
Integration utility functions.m | 75
H* KernelSubst@u,x,alstD returns u with the gensymed names in alst replaced by kernels free of x. *L
KernelSubst@u_,x_Symbol,alst_ListD :=
If@AtomQ@uD,
With@8tmp=Select@alst,Function@ð@@1DD===uD,1D<,
If@tmp===8<,
u,
tmp@@1,2DDDD,
If@IntegerPowerQ@uD,
With@8tmp=KernelSubst@u@@1DD,x,alstD<,
If@u@@2DD<0 && ZeroQ@tmpD,
Indeterminate,
tmp^u@@2DDDD,
If@ProductQ@uD ÈÈ SumQ@uD,
Map@Function@KernelSubst@ð,x,alstDD,uD,
uDDD
ExpandAlgebraicFunction
ExpandAlgebraicFunction@u_Plus*v_,x_SymbolD :=
Map@Function@ð*vD,uD ;
Not@FreeQ@u,xDD
ExpandAlgebraicFunction@u_Plus^n_*v_.,x_SymbolD :=
With@8w=Expand@u^n,xD<,
Map@Function@ð*vD,wD ;
SumQ@wDD ;
PositiveIntegerQ@nD && Not@FreeQ@u,xDD
UnifySum[u,x]
H* UnifySum@u,xD returns u with terms having indentical nonfree factors of x collected into a single term. *L
UnifySum@u_,x_SymbolD :=
If@SumQ@uD,
Apply@Plus,UnifyTerms@Apply@List,uD,xDD,
SimplifyTerm@u,xDD
H* lst is a list of terms. *L
H* UnifyTerms@lst,xD returns lst with terms collected into a single element. *L
UnifyTerms@lst_,x_D :=
If@lst===8<,
lst,
UnifyTerm@First@lstD,UnifyTerms@Rest@lstD,xD,xDD
76 | Integration utility functions.m
UnifyTerm@term_,lst_,x_D :=
If@lst===8<,
8term<,
With@8tmp=Simplify@First@lstDtermD<,
If@FreeQ@tmp,xD,
Prepend@Rest@lstD,H1+tmpL*termD,
Prepend@UnifyTerm@term,Rest@lstD,xD,First@lstDDDDD
ExpandLinearProduct[v,u,a,b,x]
H* If u is a polynomial in x, ExpandLinearProduct@v,u,a,b,xD expands v*u into a sum of terms of the form c*v*Ha+b*xL^n. *L
ExpandLinearProduct@v_,u_,a_,b_,x_SymbolD :=
Module@8lst<,
lst=CoefficientList@ReplaceAll@u,x->Hx-aLbD,xD;
lst=Map@Function@SimplifyTerm@ð,xDD,lstD;
Module@8k<,
Sum@v*lst@@kDD*Ha+b*xL^Hk-1L,8k,1,Length@lstD<DDD ;
FreeQ@8a,b<,xD && PolynomialQ@u,xD
ExpandTrigExpand[u,F,v,m,n,x]
ExpandTrigExpand@u_,F_,v_,m_,n_,x_SymbolD :=
With@8w=ReplaceAll@Expand@TrigExpand@F@n*xDD^m,xD,x->vD<,
If@SumQ@wD,
Map@Function@u*ðD,wD,
u*wDD
ExpandTrigReduce[u,v,x]
ExpandTrigReduce@u_,v_,x_SymbolD :=
With@8w=ExpandTrigReduce@v,xD<,
If@SumQ@wD,
Map@Function@u*ðD,wD,
u*wDD
H* This is necessary, because TrigReduce expands Sinh@n+vD and Cosh@n+vD to exponential form if n is a number. *L
ExpandTrigReduce@u_.*F_@n_+v_.D^m_.,x_SymbolD :=
Module@8nn<,
ExpandTrigReduce@u*F@nn+vD^m,xD . nn->nD;
MemberQ@8Sinh,Cosh<,FD && IntegerQ@mD && RationalQ@nD
ExpandTrigReduce@u_,x_SymbolD :=
ExpandTrigReduceAux@u,xD
Integration utility functions.m | 77
ExpandTrigReduceAux@u_,x_SymbolD :=
With@8v=Expand@TrigReduce@uDD<,
If@SumQ@vD,
Map@Function@NormalizeTrig@ð,xDD,vD,
NormalizeTrig@v,xDDD
NormalizeTrig@a_.*F_@u_D^n_.,x_SymbolD :=
a*F@ExpandToSum@u,xDD^n ;
FreeQ@8F,a,n<,xD && PolynomialQ@u,xD && Exponent@u,xD>0
NormalizeTrig@u_,x_SymbolD := u
ExpandTrigToExp[u,v,x]
Clear@ExpandTrigToExpD;
ExpandTrigToExp@u_,x_SymbolD := ExpandTrigToExp@1,u,xD
ExpandTrigToExp@u_,v_,x_SymbolD :=
Module@8w=TrigToExp@vD<,
w=If@SumQ@wD, Map@Function@SimplifyIntegrand@u*ð,xDD,wD, SimplifyIntegrand@u*w,xDD;
ExpandIntegrand@FreeFactors@w,xD,NonfreeFactors@w,xD,xDD
Distribution functions
Distrib
H* Distrib@u,vD returns the sum of u times each term of v. *L
Distrib@u_,v_D :=
If@SumQ@vD,
Map@Function@u*ðD,vD,
u*vD
Dist
H* Dist@u,vD returns the sum of u times each term of v, provided v is free of Int. *L
DownValues@DistD=8<;
UpValues@DistD=8<;
Dist : Dist@u_,v_,x_D+Dist@w_,v_,x_D :=
If@ZeroQ@u+wD,
0,
Dist@u+w,v,xDD
Dist : Dist@u_,v_,x_D-Dist@w_,v_,x_D :=
78 | Integration utility functions.m
Dist : Dist@u_,v_,x_D-Dist@w_,v_,x_D :=
If@ZeroQ@u-wD,
0,
Dist@u-w,v,xDD
Dist : w_*Dist@u_,v_,x_D :=
Dist@w*u,v,xD ;
w=!=-1
Dist@u_,Defer@DistD@v_,w_,x_D,x_D :=
Dist@u*v,w,xD
Dist@u_,v_*w_,x_D :=
Dist@u*v,w,xD ;
ShowSteps===True && FreeQ@v,IntD && Not@FreeQ@w,IntDD
Dist@u_,v_,x_D :=
If@u===1,
v,
If@u===0,
Print@"*** Warning ***: Dist@0,",v,",",x,"D"D;
0,
If@NumericFactor@uD<0 && NumericFactor@-uD>0,
-Dist@-u,v,xD,
If@SumQ@vD,
Map@Function@Dist@u,ð,xDD,vD,
If@FreeQ@v,IntD,
H* Simp@Simp@u,xD*v,xD, *L
Simp@u*v,xD,
H*If@ShowSteps=!=True,
Simp@u*v,xD,
Module@8w=Simp@u,xD<,
If@w=!=u,
Dist@w,v,xD, *L
With@8w=Simp@u*x^2,xDx^2<,
If@w=!=u && FreeQ@w,xD && w===Simp@w,xD && w===Simp@w*x^2,xDx^2,
Dist@w,v,xD,
If@ShowSteps=!=True,
Simp@u*v,xD,
Defer@DistD@u,v,xDDDDDDDDD
DistributeDegree
Integration utility functions.m | 79
H* DistributeDegree@u,mD returns the product of the factors of u each raised to the mth degree. *L
DistributeDegree@u_,m_D :=
If@AtomQ@uD,
u^m,
If@PowerQ@uD,
u@@1DD^Hu@@2DD*mL,
If@ProductQ@uD,
Map@Function@DistributeDegree@ð,mDD,uD,
u^mDDD
Function of functions
FunctionOfPower
H* FunctionOfPower@u,xD returns the gcd of the integer degrees of x in u. *L
H* FunctionOfPower@u_,x_SymbolD :=
FunctionOfPower@u,Null,xD
FunctionOfPower@u_,n_,x_D :=
If@FreeQ@u,xD,
n,
If@u===x,
1,
If@PowerQ@uD && u@@1DD===x && IntegerQ@u@@2DDD,
If@n===Null,
u@@2DD,
GCD@n,u@@2DDDD,
Module@8tmp=n<,
Scan@Function@tmp=FunctionOfPower@ð,tmp,xDD,uD;
tmpDDDD *L
FunctionOfLinear
H* If u HxL is equivalent to an expression of the form f Ha+b*xL and not the case that a==0 and
b==1, FunctionOfLinear@u,xD returns the list 8f HxL,a,b<; else it returns False. *L
FunctionOfLinear@u_,x_SymbolD :=
With@8lst=FunctionOfLinear@u,False,False,x,FalseD<,
If@AtomQ@lstD ÈÈ FalseQ@lst@@1DDD ÈÈ lst@@1DD===0 && lst@@2DD===1,
False,
8FunctionOfLinearSubst@u,lst@@1DD,lst@@2DD,xD,lst@@1DD,lst@@2DD<DD
80 | Integration utility functions.m
FunctionOfLinear@u_,a_,b_,x_,flag_D :=
If@FreeQ@u,xD,
8a,b<,
If@CalculusQ@uD,
False,
If@LinearQ@u,xD,
If@FalseQ@aD,
8Coefficient@u,x,0D,Coefficient@u,x,1D<,
With@8lst=CommonFactors@8b,Coefficient@u,x,1D<D<,
If@ZeroQ@Coefficient@u,x,0DD && Not@flagD,
80,lst@@1DD<,
If@ZeroQ@b*Coefficient@u,x,0D-a*Coefficient@u,x,1DD,
8alst@@2DD,lst@@1DD<,
80,1<DDDD,
If@PowerQ@uD && FreeQ@u@@1DD,xD,
FunctionOfLinear@Log@u@@1DDD*u@@2DD,a,b,x,FalseD,
Module@8lst<,
If@ProductQ@uD && NonzeroQ@Hlst=MonomialFactor@u,xDL@@1DDD,
If@False && IntegerQ@lst@@1DDD && lst@@1DD!=-1 && FreeQ@lst@@2DD,xD,
If@RationalQ@LeadFactor@lst@@2DDDD && LeadFactor@lst@@2DDD<0,
FunctionOfLinear@DivideDegreesOfFactors@-lst@@2DD,lst@@1DDD*x,a,b,x,FalseD,
FunctionOfLinear@DivideDegreesOfFactors@lst@@2DD,lst@@1DDD*x,a,b,x,FalseDD,
FalseD,
lst=8a,b<;
Catch@
Scan@Function@lst=FunctionOfLinear@ð,lst@@1DD,lst@@2DD,x,SumQ@uDD;
If@AtomQ@lstD,Throw@FalseDDD,uD;
lstDDDDDDD
FunctionOfLinearSubst@u_,a_,b_,x_D :=
If@FreeQ@u,xD,
u,
If@LinearQ@u,xD,
Module@8tmp=Coefficient@u,x,1D<,
tmp=If@tmp===b, 1, tmpbD;
Coefficient@u,x,0D-a*tmp+tmp*xD,
If@PowerQ@uD && FreeQ@u@@1DD,xD,
E^FullSimplify@FunctionOfLinearSubst@Log@u@@1DDD*u@@2DD,a,b,xDD,
Module@8lst<,
If@ProductQ@uD && NonzeroQ@Hlst=MonomialFactor@u,xDL@@1DDD,
If@RationalQ@LeadFactor@lst@@2DDDD && LeadFactor@lst@@2DDD<0,
-FunctionOfLinearSubst@DivideDegreesOfFactors@-lst@@2DD,lst@@1DDD*x,a,b,xD^lst@@1DD,
FunctionOfLinearSubst@DivideDegreesOfFactors@lst@@2DD,lst@@1DDD*x,a,b,xD^lst@@1DDD,
Map@Function@FunctionOfLinearSubst@ð,a,b,xDD,uDDDDDD
Integration utility functions.m | 81
H* DivideDegreesOfFactors@u,nD returns the product of the base of the factors of u raised to
the degree of the factors divided by n. *L
DivideDegreesOfFactors@u_,n_D :=
If@ProductQ@uD,
Map@Function@LeadBase@ðD^HLeadDegree@ðDnLD,uD,
LeadBase@uD^HLeadDegree@uDnLD
FunctionOfInverseLinear
H* If u is a function of an inverse linear binomial of the form 1Ha+b*xL,
FunctionOfInverseLinear@u,xD returns the list 8a,b<; else it returns False. *L
FunctionOfInverseLinear@u_,x_SymbolD :=
FunctionOfInverseLinear@u,Null,xD
FunctionOfInverseLinear@u_,lst_,x_D :=
If@FreeQ@u,xD,
lst,
If@u===x,
False,
If@QuotientOfLinearsQ@u,xD,
With@8tmp=Drop@QuotientOfLinearsParts@u,xD,2D<,
If@tmp@@2DD===0,
False,
If@lst===Null,
tmp,
If@ZeroQ@lst@@1DD*tmp@@2DD-lst@@2DD*tmp@@1DDD,
lst,
FalseDDDD,
If@CalculusQ@uD,
False,
Module@8tmp=lst<,Catch@
Scan@Function@If@AtomQ@tmp=FunctionOfInverseLinear@ð,tmp,xDD,Throw@FalseDDD,uD;
tmpDDDDDD
FunctionOfExponential
H* FunctionOfExponentialQ@u,xD returns True iff u is a function of F^v where F is a constant and v is linear in x, *L
H* and such an exponential explicitly occurs in u Hi.e. not just implicitly in hyperbolic functionsL. *L
FunctionOfExponentialQ@u_,x_SymbolD :=
Block@8$base$=Null,$expon$=Null,$exponFlag$=False<,
FunctionOfExponentialTest@u,xD && $exponFlag$D
82 | Integration utility functions.m
H* u is a function of F^v where v is linear in x. FunctionOfExponential@u,xD returns F^v. *L
FunctionOfExponential@u_,x_SymbolD :=
Block@8$base$=Null,$expon$=Null,$exponFlag$=False<,
FunctionOfExponentialTest@u,xD;
$base$^$expon$D
H* u is a function of F^v where v is linear in x. FunctionOfExponentialFunction@u,xD returns u with F^v replaced by x. *L
FunctionOfExponentialFunction@u_,x_SymbolD :=
Block@8$base$=Null,$expon$=Null,$exponFlag$=False<,
FunctionOfExponentialTest@u,xD;
SimplifyIntegrand@FunctionOfExponentialFunctionAux@u,xD,xDD
H* u is a function of F^v where v is linear in x, and the fluid variables $base$=F and $expon$=v. *L
H* FunctionOfExponentialFunctionAux@u,xD returns u with F^v replaced by x. *L
FunctionOfExponentialFunctionAux@u_,x_D :=
If@AtomQ@uD,
u,
If@PowerQ@uD && FreeQ@u@@1DD,xD && LinearQ@u@@2DD,xD,
If@ZeroQ@Coefficient@$expon$,x,0DD,
u@@1DD^Coefficient@u@@2DD,x,0D*x^FullSimplify@Log@u@@1DDD*Coefficient@u@@2DD,x,1DHLog@$base$D*Coefficient@$expon$,x,1DLD,
x^FullSimplify@Log@u@@1DDD*Coefficient@u@@2DD,x,1DHLog@$base$D*Coefficient@$expon$,x,1DLDD,
If@HyperbolicQ@uD && LinearQ@u@@1DD,xD,
Module@8tmp<,
tmp=x^FullSimplify@Coefficient@u@@1DD,x,1DHLog@$base$D*Coefficient@$expon$,x,1DLD;
If@SinhQ@uD,
tmp2-1H2*tmpL,
If@CoshQ@uD,
tmp2+1H2*tmpL,
If@TanhQ@uD,
Htmp-1tmpLHtmp+1tmpL,
If@CothQ@uD,
Htmp+1tmpLHtmp-1tmpL,
If@SechQ@uD,
2Htmp+1tmpL,
2Htmp-1tmpLDDDDDD,
If@PowerQ@uD && FreeQ@u@@1DD,xD && SumQ@u@@2DDD,
FunctionOfExponentialFunctionAux@u@@1DD^First@u@@2DDD,xD*FunctionOfExponentialFunctionAux@u@@1DD^Rest@u@@2DDD,xD,
Map@Function@FunctionOfExponentialFunctionAux@ð,xDD,uDDDDD
Integration utility functions.m | 83
H* FunctionOfExponentialTest@u,xD returns True iff u is a function of F^v where F is a constant and v is linear in x. *L
H* Before it is called, the fluid variables $base$ and $expon$ should be set to Null and $exponFlag$ to False. *L
H* If u is a function of F^v, $base$ and $expon$ are set to F and v, respectively. *L
H* If an explicit exponential occurs in u, $exponFlag$ is set to True. *L
FunctionOfExponentialTest@u_,x_D :=
If@FreeQ@u,xD,
True,
If@u===x ÈÈ CalculusQ@uD,
False,
If@PowerQ@uD && FreeQ@u@@1DD,xD && LinearQ@u@@2DD,xD,
$exponFlag$=True;
FunctionOfExponentialTestAux@u@@1DD,u@@2DD,xD,
If@HyperbolicQ@uD && LinearQ@u@@1DD,xD,
FunctionOfExponentialTestAux@E,u@@1DD,xD,
If@PowerQ@uD && FreeQ@u@@1DD,xD && SumQ@u@@2DDD,
FunctionOfExponentialTest@u@@1DD^First@u@@2DDD,xD && FunctionOfExponentialTest@u@@1DD^Rest@u@@2DDD,xD,
Catch@Scan@Function@If@Not@FunctionOfExponentialTest@ð,xDD,Throw@FalseDDD,uD; TrueDDDDDD
84 | Integration utility functions.m
FunctionOfExponentialTestAux@base_,expon_,x_D :=
If@$base$===Null,
$base$=base;
$expon$=expon;
True,
Module@8tmp<,
tmp=FullSimplify@Log@baseD*Coefficient@expon,x,1DHLog@$base$D*Coefficient@$expon$,x,1DLD;
If@Not@RationalQ@tmpDD,
False,
If@ZeroQ@Coefficient@$expon$,x,0DD ÈÈ NonzeroQ@tmp-FullSimplify@Log@baseD*Coefficient@expon,x,0DHLog@$base$D*Coefficient@$expon$
H If@PositiveIntegerQ@base,$base$D && base<$base$,
$base$=base;
$expon$=expon;
tmp=1tmpD L;
$expon$=Coefficient@$expon$,x,1D*xDenominator@tmpD;
If@tmp<0 && NegQ@Coefficient@$expon$,x,1DD,
$expon$=-$expon$;
True,
TrueD,
H If@PositiveIntegerQ@base,$base$D && base<$base$,
$base$=base;
$expon$=expon;
tmp=1tmpD L;
H*$expon$=If@SumQ@$expon$D, Map@Function@ðDenominator@tmpDD,$expon$D, $expon$Denominator@tmpDD; *L
$expon$=$expon$Denominator@tmpD;
If@tmp<0 && NegQ@Coefficient@$expon$,x,1DD,
$expon$=-$expon$;
True,
TrueDDDDD
Integration utility functions.m | 85
FunctionOfTrigOfLinearQ
H* If u is an algebraic function of trig functions of a linear function of x,
FunctionOfTrigOfLinearQ@u,xD returns True; else it returns False. *L
FunctionOfTrigOfLinearQ@u_,x_SymbolD :=
H* Not@MatchQ@u, Hc_.*f_@a_.+b_.*xDL^p_. ; FreeQ@8a,b,c,p<,xD && MemberQ@8Sin,Cos,Sec,Csc<,fDDD && *L
Not@MemberQ@8Null, False<, FunctionOfTrig@u,Null,xDDD && AlgebraicTrigFunctionQ@u,xD H* &&
RecognizedFunctionOfTrigQ@DeactivateTrig@u,xD,xD *L
H* If u is a function of trig functions of v where v is a linear function of x,
FunctionOfTrig@u,xD returns v; else it returns False. *L
FunctionOfTrig@u_,x_SymbolD :=
With@8v=FunctionOfTrig@ActivateTrig@uD,Null,xD<,
If@v===Null, False, vDD
FunctionOfTrig@u_,v_,x_D :=
If@AtomQ@uD,
If@u===x,
False,
vD,
If@TrigQ@uD && LinearQ@u@@1DD,xD,
If@v===Null,
u@@1DD,
With@8a=Coefficient@v,x,0D,b=Coefficient@v,x,1D,c=Coefficient@u@@1DD,x,0D,d=Coefficient@u@@1DD,x,1D<,
If@ZeroQ@a*d-b*cD && RationalQ@bdD,
aNumerator@bdD+b*xNumerator@bdD,
FalseDDD,
If@HyperbolicQ@uD && LinearQ@u@@1DD,xD,
If@v===Null,
I*u@@1DD,
With@8a=Coefficient@v,x,0D,b=Coefficient@v,x,1D,c=I*Coefficient@u@@1DD,x,0D,d=I*Coefficient@u@@1DD,x,1D<,
If@ZeroQ@a*d-b*cD && RationalQ@bdD,
aNumerator@bdD+b*xNumerator@bdD,
FalseDDD,
If@CalculusQ@uD,
False,
Module@8w=v<,Catch@
Scan@Function@If@FalseQ@w=FunctionOfTrig@ð,w,xDD,Throw@FalseDDD,uD;
wDDDDDD
86 | Integration utility functions.m
H* If u is algebraic function of trig functions, AlgebraicTrigFunctionQ@u,xD returns True; else it returns False. *L
AlgebraicTrigFunctionQ@u_,x_SymbolD :=
If@AtomQ@uD,
True,
If@TrigQ@uD && LinearQ@u@@1DD,xD,
True,
If@HyperbolicQ@uD && LinearQ@u@@1DD,xD,
True,
If@PowerQ@uD && FreeQ@u@@2DD,xD,
AlgebraicTrigFunctionQ@u@@1DD,xD,
If@ProductQ@uD ÈÈ SumQ@uD,
Catch@Scan@Function@If@Not@AlgebraicTrigFunctionQ@ð,xDD,Throw@FalseDDD,uD; TrueD,
FalseDDDDD
FunctionOfHyperbolic
H* If u is a function of hyperbolic trig functions of v where v is linear in x,
FunctionOfHyperbolic@u,xD returns v; else it returns False. *L
FunctionOfHyperbolic@u_,x_SymbolD :=
With@8v=FunctionOfHyperbolic@u,Null,xD<,
If@v===Null, False, vDD
FunctionOfHyperbolic@u_,v_,x_D :=
If@AtomQ@uD,
If@u===x,
False,
vD,
If@HyperbolicQ@uD && LinearQ@u@@1DD,xD,
If@v===Null,
u@@1DD,
With@8a=Coefficient@v,x,0D,b=Coefficient@v,x,1D,c=Coefficient@u@@1DD,x,0D,d=Coefficient@u@@1DD,x,1D<,
If@ZeroQ@a*d-b*cD && RationalQ@bdD,
aNumerator@bdD+b*xNumerator@bdD,
FalseDDD,
If@CalculusQ@uD,
False,
Module@8w=v<,Catch@
Scan@Function@If@FalseQ@w=FunctionOfHyperbolic@ð,w,xDD,Throw@FalseDDD,uD;
wDDDDD
Integration utility functions.m | 87
FunctionOfQ
H* v is a function of x.
If u is a function of v, FunctionOfQ@v,u,xD returns True; else it returns False. *L
FunctionOfQ@v_,u_,x_Symbol,PureFlag_:FalseD :=
If@FreeQ@u,xD,
False,
If@AtomQ@vD,
True,
If@Not@InertTrigFreeQ@uDD,
FunctionOfQ@v,ActivateTrig@uD,x,PureFlagD,
If@ProductQ@vD && Not@EqQ@FreeFactors@v,xD,1DD,
FunctionOfQ@NonfreeFactors@v,xD,u,x,PureFlagD,
If@PureFlag,
If@SinQ@vD ÈÈ CscQ@vD,
PureFunctionOfSinQ@u,v@@1DD,xD,
If@CosQ@vD ÈÈ SecQ@vD,
PureFunctionOfCosQ@u,v@@1DD,xD,
If@TanQ@vD,
PureFunctionOfTanQ@u,v@@1DD,xD,
If@CotQ@vD,
PureFunctionOfCotQ@u,v@@1DD,xD,
If@SinhQ@vD ÈÈ CschQ@vD,
PureFunctionOfSinhQ@u,v@@1DD,xD,
If@CoshQ@vD ÈÈ SechQ@vD,
PureFunctionOfCoshQ@u,v@@1DD,xD,
If@TanhQ@vD,
PureFunctionOfTanhQ@u,v@@1DD,xD,
If@CothQ@vD,
PureFunctionOfCothQ@u,v@@1DD,xD,
FunctionOfExpnQ@u,v,xD=!=FalseDDDDDDDD,
If@SinQ@vD ÈÈ CscQ@vD,
FunctionOfSinQ@u,v@@1DD,xD,
If@CosQ@vD ÈÈ SecQ@vD,
FunctionOfCosQ@u,v@@1DD,xD,
If@TanQ@vD ÈÈ CotQ@vD,
FunctionOfTanQ@u,v@@1DD,xD,
If@SinhQ@vD ÈÈ CschQ@vD,
FunctionOfSinhQ@u,v@@1DD,xD,
If@CoshQ@vD ÈÈ SechQ@vD,
FunctionOfCoshQ@u,v@@1DD,xD,
If@TanhQ@vD ÈÈ CothQ@vD,
FunctionOfTanhQ@u,v@@1DD,xD,
FunctionOfExpnQ@u,v,xD=!=FalseDDDDDDDDDDD
88 | Integration utility functions.m
FunctionOfExpnQ@u_,v_,x_D :=
If@u===v,
1,
If@AtomQ@uD,
If@u===x,
False,
0D,
If@CalculusQ@uD,
False,
If@PowerQ@uD && FreeQ@u@@2DD,xD,
If@ZeroQ@u@@1DD-vD,
If@IntegerQ@u@@2DDD, u@@2DD, 1D,
If@PowerQ@vD && FreeQ@v@@2DD,xD && ZeroQ@u@@1DD-v@@1DDD,
If@RationalQ@v@@2DDD,
If@RationalQ@u@@2DDD && IntegerQ@u@@2DDv@@2DDD && Hv@@2DD>0 ÈÈ u@@2DD<0L, u@@2DDv@@2DD, FalseD,
If@IntegerQ@Simplify@u@@2DDv@@2DDDD, Simplify@u@@2DDv@@2DDD, FalseDD,
FunctionOfExpnQ@u@@1DD,v,xDDD,
If@ProductQ@uD && Not@EqQ@FreeFactors@u,xD,1DD,
FunctionOfExpnQ@NonfreeFactors@u,xD,v,xD,
If@ProductQ@uD && ProductQ@vD,
Module@8deg1=FunctionOfExpnQ@First@uD,First@vD,xD,deg2<,
If@deg1===False,
False,
deg2=FunctionOfExpnQ@Rest@uD,Rest@vD,xD;
If@deg1===deg2 && FreeQ@Simplify@uv^deg1D,xD,
deg1,
FalseDDD,
With@8lst=Map@Function@FunctionOfExpnQ@ð,v,xDD,Apply@List,uDD<,
If@MemberQ@lst,FalseD,
False,
Apply@GCD,lstDDDDDDDDD
Pure function of trig functions predicates
H* If u is a pure function of Sin@vD andor Csc@vD, PureFunctionOfSinQ@u,v,xD returns True;
else it returns False. *L
PureFunctionOfSinQ@u_,v_,x_D :=
If@AtomQ@uD,
u=!=x,
If@CalculusQ@uD,
False,
If@TrigQ@uD && ZeroQ@u@@1DD-vD,
SinQ@uD ÈÈ CscQ@uD,
Catch@Scan@Function@If@Not@PureFunctionOfSinQ@ð,v,xDD,Throw@FalseDDD,uD;TrueDDDD
Integration utility functions.m | 89
H* If u is a pure function of Cos@vD andor Sec@vD, PureFunctionOfCosQ@u,v,xD returns True;
else it returns False. *L
PureFunctionOfCosQ@u_,v_,x_D :=
If@AtomQ@uD,
u=!=x,
If@CalculusQ@uD,
False,
If@TrigQ@uD && ZeroQ@u@@1DD-vD,
CosQ@uD ÈÈ SecQ@uD,
Catch@Scan@Function@If@Not@PureFunctionOfCosQ@ð,v,xDD,Throw@FalseDDD,uD;TrueDDDD
H* If u is a pure function of Tan@vD andor Cot@vD, PureFunctionOfTanQ@u,v,xD returns True;
else it returns False. *L
PureFunctionOfTanQ@u_,v_,x_D :=
If@AtomQ@uD,
u=!=x,
If@CalculusQ@uD,
False,
If@TrigQ@uD && ZeroQ@u@@1DD-vD,
TanQ@uD ÈÈ CotQ@uD,
Catch@Scan@Function@If@Not@PureFunctionOfTanQ@ð,v,xDD,Throw@FalseDDD,uD;TrueDDDD
H* If u is a pure function of Cot@vD, PureFunctionOfCotQ@u,v,xD returns True;
else it returns False. *L
PureFunctionOfCotQ@u_,v_,x_D :=
If@AtomQ@uD,
u=!=x,
If@CalculusQ@uD,
False,
If@TrigQ@uD && ZeroQ@u@@1DD-vD,
CotQ@uD,
Catch@Scan@Function@If@Not@PureFunctionOfCotQ@ð,v,xDD,Throw@FalseDDD,uD;TrueDDDD
90 | Integration utility functions.m
Function of trig functions predicates
H* If u is a function of Sin@vD, FunctionOfSinQ@u,v,xD returns True; else it returns False. *L
FunctionOfSinQ@u_,v_,x_D :=
If@AtomQ@uD,
u=!=x,
If@CalculusQ@uD,
False,
If@TrigQ@uD && IntegerQuotientQ@u@@1DD,vD,
If@OddQuotientQ@u@@1DD,vD,
H* Basis: If m odd, Sin@m*vD^n is a function of Sin@vD. *L
SinQ@uD ÈÈ CscQ@uD,
H* Basis: If m even, Cos@m*vD^n is a function of Sin@vD. *L
CosQ@uD ÈÈ SecQ@uDD,
If@IntegerPowerQ@uD && TrigQ@u@@1DDD && IntegerQuotientQ@u@@1,1DD,vD,
If@EvenQ@u@@2DDD,
H* Basis: If m integer and n even, Trig@m*vD^n is a function of Sin@vD. *L
True,
FunctionOfSinQ@u@@1DD,v,xDD,
If@ProductQ@uD,
If@CosQ@u@@1DDD && SinQ@u@@2DDD && ZeroQ@u@@1,1DD-v2D && ZeroQ@u@@2,1DD-v2D,
FunctionOfSinQ@Drop@u,2D,v,xD,
Module@8lst<,
lst=FindTrigFactor@Sin,Csc,u,v,FalseD;
If@ListQ@lstD && EvenQuotientQ@lst@@1DD,vD,
H* Basis: If m even and n odd, Sin@m*vD^n == Cos@vD*u where u is a function of Sin@vD. *L
FunctionOfSinQ@Cos@vD*lst@@2DD,v,xD,
lst=FindTrigFactor@Cos,Sec,u,v,FalseD;
If@ListQ@lstD && OddQuotientQ@lst@@1DD,vD,
H* Basis: If m odd and n odd, Cos@m*vD^n == Cos@vD*u where u is a function of Sin@vD. *L
FunctionOfSinQ@Cos@vD*lst@@2DD,v,xD,
lst=FindTrigFactor@Tan,Cot,u,v,TrueD;
If@ListQ@lstD,
H* Basis: If m integer and n odd, Tan@m*vD^n == Cos@vD*u where u is a function of Sin@vD. *L
FunctionOfSinQ@Cos@vD*lst@@2DD,v,xD,
Catch@Scan@Function@If@Not@FunctionOfSinQ@ð,v,xDD,Throw@FalseDDD,uD;TrueDDDDDD,
Catch@Scan@Function@If@Not@FunctionOfSinQ@ð,v,xDD,Throw@FalseDDD,uD;TrueDDDDDD
Integration utility functions.m | 91
H* If u is a function of Cos@vD, FunctionOfCosQ@u,v,xD returns True; else it returns False. *L
FunctionOfCosQ@u_,v_,x_D :=
If@AtomQ@uD,
u=!=x,
If@CalculusQ@uD,
False,
If@TrigQ@uD && IntegerQuotientQ@u@@1DD,vD,
H* Basis: If m integer, Cos@m*vD^n is a function of Cos@vD. *L
CosQ@uD ÈÈ SecQ@uD,
If@IntegerPowerQ@uD && TrigQ@u@@1DDD && IntegerQuotientQ@u@@1,1DD,vD,
If@EvenQ@u@@2DDD,
H* Basis: If m integer and n even, Trig@m*vD^n is a function of Cos@vD. *L
True,
FunctionOfCosQ@u@@1DD,v,xDD,
If@ProductQ@uD,
Module@8lst<,
lst=FindTrigFactor@Sin,Csc,u,v,FalseD;
If@ListQ@lstD,
H* Basis: If m integer and n odd, Sin@m*vD^n == Sin@vD*u where u is a function of Cos@vD. *L
FunctionOfCosQ@Sin@vD*lst@@2DD,v,xD,
lst=FindTrigFactor@Tan,Cot,u,v,TrueD;
If@ListQ@lstD,
H* Basis: If m integer and n odd, Tan@m*vD^n == Sin@vD*u where u is a function of Cos@vD. *L
FunctionOfCosQ@Sin@vD*lst@@2DD,v,xD,
Catch@Scan@Function@If@Not@FunctionOfCosQ@ð,v,xDD,Throw@FalseDDD,uD;TrueDDDD,
Catch@Scan@Function@If@Not@FunctionOfCosQ@ð,v,xDD,Throw@FalseDDD,uD;TrueDDDDDD
92 | Integration utility functions.m
H* If u is a function of the form f@Tan@vD,Cot@vDD where f is independent of x,
FunctionOfTanQ@u,v,xD returns True; else it returns False. *L
FunctionOfTanQ@u_,v_,x_D :=
If@AtomQ@uD,
u=!=x,
If@CalculusQ@uD,
False,
If@TrigQ@uD && IntegerQuotientQ@u@@1DD,vD,
TanQ@uD ÈÈ CotQ@uD ÈÈ EvenQuotientQ@u@@1DD,vD,
If@PowerQ@uD && EvenQ@u@@2DDD && TrigQ@u@@1DDD && IntegerQuotientQ@u@@1,1DD,vD,
True,
If@PowerQ@uD && EvenQ@u@@2DDD && SumQ@u@@1DDD,
FunctionOfTanQ@Expand@u@@1DD^2D,v,xD,
If@ProductQ@uD,
Module@8lst=ReapList@Scan@Function@If@Not@FunctionOfTanQ@ð,v,xDD,Sow@ðDDD,uDD<,
If@lst===8<,
True,
Length@lstD==2 && OddTrigPowerQ@lst@@1DD,v,xD && OddTrigPowerQ@lst@@2DD,v,xDDD,
Catch@Scan@Function@If@Not@FunctionOfTanQ@ð,v,xDD,Throw@FalseDDD,uD;TrueDDDDDDD
OddTrigPowerQ@u_,v_,x_D :=
If@SinQ@uD ÈÈ CosQ@uD ÈÈ SecQ@uD ÈÈ CscQ@uD,
OddQuotientQ@u@@1DD,vD,
If@PowerQ@uD,
OddQ@u@@2DDD && OddTrigPowerQ@u@@1DD,v,xD,
If@ProductQ@uD,
If@Not@EqQ@FreeFactors@u,xD,1DD,
OddTrigPowerQ@NonfreeFactors@u,xD,v,xD,
Module@8lst=ReapList@Scan@Function@If@Not@FunctionOfTanQ@ð,v,xDD,Sow@ðDDD,uDD<,
If@lst===8<,
True,
Length@lstD==1 && OddTrigPowerQ@lst@@1DD,v,xDDDD,
If@SumQ@uD,
Catch@Scan@Function@If@Not@OddTrigPowerQ@ð,v,xDD,Throw@FalseDDD,uD;TrueD,
FalseDDDD
Integration utility functions.m | 93
H* u is a function of the form f@Tan@vD,Cot@vDD where f is independent of x.
FunctionOfTanWeight@u,v,xD returns a nonnegative number if u is best considered a function
of Tan@vD; else it returns a negative number. *L
FunctionOfTanWeight@u_,v_,x_D :=
If@AtomQ@uD,
0,
If@CalculusQ@uD,
0,
If@TrigQ@uD && IntegerQuotientQ@u@@1DD,vD,
If@TanQ@uD && ZeroQ@u@@1DD-vD,
1,
If@CotQ@uD && ZeroQ@u@@1DD-vD,
-1,
0DD,
If@PowerQ@uD && EvenQ@u@@2DDD && TrigQ@u@@1DDD && IntegerQuotientQ@u@@1,1DD,vD,
If@TanQ@u@@1DDD ÈÈ CosQ@u@@1DDD ÈÈ SecQ@u@@1DDD,
1,
-1D,
If@ProductQ@uD,
If@Catch@Scan@Function@If@Not@FunctionOfTanQ@ð,v,xDD,Throw@FalseDDD,uD;TrueD,
Apply@Plus,Map@Function@FunctionOfTanWeight@ð,v,xDD,Apply@List,uDDD,
0D,
Apply@Plus,Map@Function@FunctionOfTanWeight@ð,v,xDD,Apply@List,uDDDDDDDD
H* If u HxL is equivalent to an expression of the form f HSin@vD,Cos@vD,Tan@vD,Cot@vD,Sec@vD,Csc@vDL
where f is independent of x, FunctionOfTrigQ@u,v,xD returns True; else it returns False. *L
FunctionOfTrigQ@u_,v_,x_SymbolD :=
If@AtomQ@uD,
u=!=x,
If@CalculusQ@uD,
False,
If@TrigQ@uD && IntegerQuotientQ@u@@1DD,vD,
True,
Catch@
Scan@Function@If@Not@FunctionOfTrigQ@ð,v,xDD,Throw@FalseDDD,uD;
TrueDDDD
94 | Integration utility functions.m
Pure function of hyperbolic functions predicates
H* If u is a pure function of Sinh@vD andor Csch@vD, PureFunctionOfSinhQ@u,v,xD returns True;
else it returns False. *L
PureFunctionOfSinhQ@u_,v_,x_D :=
If@AtomQ@uD,
u=!=x,
If@CalculusQ@uD,
False,
If@HyperbolicQ@uD && ZeroQ@u@@1DD-vD,
SinhQ@uD ÈÈ CschQ@uD,
Catch@Scan@Function@If@Not@PureFunctionOfSinhQ@ð,v,xDD,Throw@FalseDDD,uD;TrueDDDD
H* If u is a pure function of Cosh@vD andor Sech@vD, PureFunctionOfCoshQ@u,v,xD returns True;
else it returns False. *L
PureFunctionOfCoshQ@u_,v_,x_D :=
If@AtomQ@uD,
u=!=x,
If@CalculusQ@uD,
False,
If@HyperbolicQ@uD && ZeroQ@u@@1DD-vD,
CoshQ@uD ÈÈ SechQ@uD,
Catch@Scan@Function@If@Not@PureFunctionOfCoshQ@ð,v,xDD,Throw@FalseDDD,uD;TrueDDDD
H* If u is a pure function of Tanh@vD andor Coth@vD, PureFunctionOfTanhQ@u,v,xD returns True;
else it returns False. *L
PureFunctionOfTanhQ@u_,v_,x_D :=
If@AtomQ@uD,
u=!=x,
If@CalculusQ@uD,
False,
If@HyperbolicQ@uD && ZeroQ@u@@1DD-vD,
TanhQ@uD ÈÈ CothQ@uD,
Catch@Scan@Function@If@Not@PureFunctionOfTanhQ@ð,v,xDD,Throw@FalseDDD,uD;TrueDDDD
H* If u is a pure function of Coth@vD, PureFunctionOfCothQ@u,v,xD returns True;
else it returns False. *L
PureFunctionOfCothQ@u_,v_,x_D :=
If@AtomQ@uD,
u=!=x,
If@CalculusQ@uD,
False,
If@HyperbolicQ@uD && ZeroQ@u@@1DD-vD,
CothQ@uD,
Catch@Scan@Function@If@Not@PureFunctionOfCothQ@ð,v,xDD,Throw@FalseDDD,uD;TrueDDDD
Integration utility functions.m | 95
Function of hyperbolic functions predicates
H* If u is a function of Sinh@vD, FunctionOfSinhQ@u,v,xD returns True; else it returns False. *L
FunctionOfSinhQ@u_,v_,x_D :=
If@AtomQ@uD,
u=!=x,
If@CalculusQ@uD,
False,
If@HyperbolicQ@uD && IntegerQuotientQ@u@@1DD,vD,
If@OddQuotientQ@u@@1DD,vD,
H* Basis: If m odd, Sinh@m*vD^n is a function of Sinh@vD. *L
SinhQ@uD ÈÈ CschQ@uD,
H* Basis: If m even, Cos@m*vD^n is a function of Sinh@vD. *L
CoshQ@uD ÈÈ SechQ@uDD,
If@IntegerPowerQ@uD && HyperbolicQ@u@@1DDD && IntegerQuotientQ@u@@1,1DD,vD,
If@EvenQ@u@@2DDD,
H* Basis: If m integer and n even, Hyper@m*vD^n is a function of Sinh@vD. *L
True,
FunctionOfSinhQ@u@@1DD,v,xDD,
If@ProductQ@uD,
If@CoshQ@u@@1DDD && SinhQ@u@@2DDD && ZeroQ@u@@1,1DD-v2D && ZeroQ@u@@2,1DD-v2D,
FunctionOfSinhQ@Drop@u,2D,v,xD,
Module@8lst<,
lst=FindTrigFactor@Sinh,Csch,u,v,FalseD;
If@ListQ@lstD && EvenQuotientQ@lst@@1DD,vD,
H* Basis: If m even and n odd, Sinh@m*vD^n == Cosh@vD*u where u is a function of Sinh@vD. *L
FunctionOfSinhQ@Cosh@vD*lst@@2DD,v,xD,
lst=FindTrigFactor@Cosh,Sech,u,v,FalseD;
If@ListQ@lstD && OddQuotientQ@lst@@1DD,vD,
H* Basis: If m odd and n odd, Cosh@m*vD^n == Cosh@vD*u where u is a function of Sinh@vD. *L
FunctionOfSinhQ@Cosh@vD*lst@@2DD,v,xD,
lst=FindTrigFactor@Tanh,Coth,u,v,TrueD;
If@ListQ@lstD,
H* Basis: If m integer and n odd, Tanh@m*vD^n == Cosh@vD*u where u is a function of Sinh@vD. *L
FunctionOfSinhQ@Cosh@vD*lst@@2DD,v,xD,
Catch@Scan@Function@If@Not@FunctionOfSinhQ@ð,v,xDD,Throw@FalseDDD,uD;TrueDDDDDD,
Catch@Scan@Function@If@Not@FunctionOfSinhQ@ð,v,xDD,Throw@FalseDDD,uD;TrueDDDDDD
96 | Integration utility functions.m
H* If u is a function of Cosh@vD, FunctionOfCoshQ@u,v,xD returns True; else it returns False. *L
FunctionOfCoshQ@u_,v_,x_D :=
If@AtomQ@uD,
u=!=x,
If@CalculusQ@uD,
False,
If@HyperbolicQ@uD && IntegerQuotientQ@u@@1DD,vD,
H* Basis: If m integer, Cosh@m*vD^n is a function of Cosh@vD. *L
CoshQ@uD ÈÈ SechQ@uD,
If@IntegerPowerQ@uD && HyperbolicQ@u@@1DDD && IntegerQuotientQ@u@@1,1DD,vD,
If@EvenQ@u@@2DDD,
H* Basis: If m integer and n even, Hyper@m*vD^n is a function of Cosh@vD. *L
True,
FunctionOfCoshQ@u@@1DD,v,xDD,
If@ProductQ@uD,
Module@8lst<,
lst=FindTrigFactor@Sinh,Csch,u,v,FalseD;
If@ListQ@lstD,
H* Basis: If m integer and n odd, Sinh@m*vD^n == Sinh@vD*u where u is a function of Cosh@vD. *L
FunctionOfCoshQ@Sinh@vD*lst@@2DD,v,xD,
lst=FindTrigFactor@Tanh,Coth,u,v,TrueD;
If@ListQ@lstD,
H* Basis: If m integer and n odd, Tanh@m*vD^n == Sinh@vD*u where u is a function of Cosh@vD. *L
FunctionOfCoshQ@Sinh@vD*lst@@2DD,v,xD,
Catch@Scan@Function@If@Not@FunctionOfCoshQ@ð,v,xDD,Throw@FalseDDD,uD;TrueDDDD,
Catch@Scan@Function@If@Not@FunctionOfCoshQ@ð,v,xDD,Throw@FalseDDD,uD;TrueDDDDDD
Integration utility functions.m | 97
H* If u is a function of the form f@Tanh@vD,Coth@vDD where f is independent of x,
FunctionOfTanhQ@u,v,xD returns True; else it returns False. *L
FunctionOfTanhQ@u_,v_,x_D :=
If@AtomQ@uD,
u=!=x,
If@CalculusQ@uD,
False,
If@HyperbolicQ@uD && IntegerQuotientQ@u@@1DD,vD,
TanhQ@uD ÈÈ CothQ@uD ÈÈ EvenQuotientQ@u@@1DD,vD,
If@PowerQ@uD && EvenQ@u@@2DDD && HyperbolicQ@u@@1DDD && IntegerQuotientQ@u@@1,1DD,vD,
True,
If@PowerQ@uD && EvenQ@u@@2DDD && SumQ@u@@1DDD,
FunctionOfTanhQ@Expand@u@@1DD^2D,v,xD,
If@ProductQ@uD,
With@8lst=ReapList@Scan@Function@If@Not@FunctionOfTanhQ@ð,v,xDD,Sow@ðDDD,uDD<,
If@lst===8<,
True,
Length@lstD==2 && OddHyperbolicPowerQ@lst@@1DD,v,xD && OddHyperbolicPowerQ@lst@@2DD,v,xDDD,
Catch@Scan@Function@If@Not@FunctionOfTanhQ@ð,v,xDD,Throw@FalseDDD,uD;TrueDDDDDDD
OddHyperbolicPowerQ@u_,v_,x_D :=
If@SinhQ@uD ÈÈ CoshQ@uD ÈÈ SechQ@uD ÈÈ CschQ@uD,
OddQuotientQ@u@@1DD,vD,
If@PowerQ@uD,
OddQ@u@@2DDD && OddHyperbolicPowerQ@u@@1DD,v,xD,
If@ProductQ@uD,
If@Not@EqQ@FreeFactors@u,xD,1DD,
OddHyperbolicPowerQ@NonfreeFactors@u,xD,v,xD,
With@8lst=ReapList@Scan@Function@If@Not@FunctionOfTanhQ@ð,v,xDD,Sow@ðDDD,uDD<,
If@lst===8<,
True,
Length@lstD==1 && OddHyperbolicPowerQ@lst@@1DD,v,xDDDD,
If@SumQ@uD,
Catch@Scan@Function@If@Not@OddHyperbolicPowerQ@ð,v,xDD,Throw@FalseDDD,uD;TrueD,
FalseDDDD
98 | Integration utility functions.m
H* u is a function of the form f@Tanh@vD,Coth@vDD where f is independent of x.
FunctionOfTanhWeight@u,v,xD returns a nonnegative number if u is best considered a function
of Tanh@vD; else it returns a negative number. *L
FunctionOfTanhWeight@u_,v_,x_D :=
If@AtomQ@uD,
0,
If@CalculusQ@uD,
0,
If@HyperbolicQ@uD && IntegerQuotientQ@u@@1DD,vD,
If@TanhQ@uD && ZeroQ@u@@1DD-vD,
1,
If@CothQ@uD && ZeroQ@u@@1DD-vD,
-1,
0DD,
If@PowerQ@uD && EvenQ@u@@2DDD && HyperbolicQ@u@@1DDD && IntegerQuotientQ@u@@1,1DD,vD,
If@TanhQ@u@@1DDD ÈÈ CoshQ@u@@1DDD ÈÈ SechQ@u@@1DDD,
1,
-1D,
If@ProductQ@uD,
If@Catch@Scan@Function@If@Not@FunctionOfTanhQ@ð,v,xDD,Throw@FalseDDD,uD;TrueD,
Apply@Plus,Map@Function@FunctionOfTanhWeight@ð,v,xDD,Apply@List,uDDD,
0D,
Apply@Plus,Map@Function@FunctionOfTanhWeight@ð,v,xDD,Apply@List,uDDDDDDDD
H* If u HxL is equivalent to a function of the form f HSinh@vD,Cosh@vD,Tanh@vD,Coth@vD,Sech@vD,Csch@vDL
where f is independent of x, FunctionOfHyperbolicQ@u,v,xD returns True; else it returns False. *L
FunctionOfHyperbolicQ@u_,v_,x_SymbolD :=
If@AtomQ@uD,
u=!=x,
If@CalculusQ@uD,
False,
If@HyperbolicQ@uD && IntegerQuotientQ@u@@1DD,vD,
True,
Catch@Scan@Function@If@FunctionOfHyperbolicQ@ð,v,xD,Null,Throw@FalseDDD,uD;TrueDDDD
Integration utility functions.m | 99
H* If func@wD^m is a factor of u where m is odd and w is an integer multiple of v,
FindTrigFactor@func1,func2,u,v,TrueD returns the list 8w,ufunc@wD^n<; else it returns False. *L
H* If func@wD^m is a factor of u where m is odd and w is an integer multiple of v not equal to v,
FindTrigFactor@func1,func2,u,v,FalseD returns the list 8w,ufunc@wD^n<; else it returns False. *L
FindTrigFactor@func1_,func2_,u_,v_,flag_D :=
If@u===1,
False,
If@HHead@LeadBase@uDD===func1 ÈÈ Head@LeadBase@uDD===func2L &&
OddQ@LeadDegree@uDD &&
IntegerQuotientQ@LeadBase@uD@@1DD,vD &&
Hflag ÈÈ NonzeroQ@LeadBase@uD@@1DD-vDL,
8LeadBase@uD@@1DD, RemainingFactors@uD<,
With@8lst=FindTrigFactor@func1,func2,RemainingFactors@uD,v,flagD<,
If@AtomQ@lstD,
False,
8lst@@1DD, LeadFactor@uD*lst@@2DD<DDDD
H* If uv is an integer, IntegerQuotientQ@u,vD returns True; else it returns False. *L
IntegerQuotientQ@u_,v_D :=
H* u===v ÈÈ ZeroQ@u-vD ÈÈ IntegerQ@uvD *L
IntegerQ@Simplify@uvDD
H* If uv is odd, OddQuotientQ@u,vD returns True; else it returns False. *L
OddQuotientQ@u_,v_D :=
H* u===v ÈÈ ZeroQ@u-vD ÈÈ OddQ@uvD *L
OddQ@Simplify@uvDD
H* If uv is even, EvenQuotientQ@u,vD returns True; else it returns False. *L
EvenQuotientQ@u_,v_D :=
EvenQ@Simplify@uvDD
FunctionOfDensePolynomialsQ
H* If all occurrences of x in u HxL are in dense polynomials, FunctionOfDensePolynomialsQ@u,xD
returns True; else it returns False. *L
FunctionOfDensePolynomialsQ@u_,x_SymbolD :=
If@FreeQ@u,xD,
True,
If@PolynomialQ@u,xD,
Length@Exponent@u,x,ListDD>1,
Catch@
Scan@Function@If@FunctionOfDensePolynomialsQ@ð,xD,Null,Throw@FalseDDD,uD;
TrueDDD
100 | Integration utility functions.m
FunctionOfLog
H* If u HxL is equivalent to an expression of the form f HLog@a*x^nDL, FunctionOfLog@u,xD returns
the list 8f HxL,a*x^n,n<; else it returns False. *L
FunctionOfLog@u_,x_SymbolD :=
With@8lst=FunctionOfLog@u,False,False,xD<,
If@AtomQ@lstD ÈÈ FalseQ@lst@@2DDD,
False,
lstDD
FunctionOfLog@u_,v_,n_,x_D :=
If@AtomQ@uD,
If@u===x,
False,
8u,v,n<D,
If@CalculusQ@uD,
False,
Module@8lst<,
If@LogQ@uD && ListQ@lst=BinomialParts@u@@1DD,xDD && ZeroQ@lst@@1DDD,
If@FalseQ@vD ÈÈ u@@1DD===v,
8x,u@@1DD,lst@@3DD<,
FalseD,
lst=80,v,n<;
Catch@
8Map@Function@lst=FunctionOfLog@ð,lst@@2DD,lst@@3DD,xD;
If@AtomQ@lstD,Throw@FalseD,lst@@1DDDD,
uD,lst@@2DD,lst@@3DD<DDDDD
PowerVariableExpn
H* If m is an integer, u is an expression of the form f@Hc*xL^nD and g=GCD@m,nD>1,
PowerVariableExpn@u,m,xD returns the list 8x^HmgL*f@Hc*xL^HngLD,g,c<; else it returns False. *L
PowerVariableExpn@u_,m_,x_SymbolD :=
If@IntegerQ@mD,
With@8lst=PowerVariableDegree@u,m,1,xD<,
If@AtomQ@lstD,
False,
8x^Hmlst@@1DDL*PowerVariableSubst@u,lst@@1DD,xD, lst@@1DD, lst@@2DD<DD,
FalseD
Integration utility functions.m | 101
PowerVariableDegree@u_,m_,c_,x_SymbolD :=
If@FreeQ@u,xD,
8m, c<,
If@AtomQ@uD ÈÈ CalculusQ@uD,
False,
If@PowerQ@uD && FreeQ@u@@1DDx,xD,
If@ZeroQ@mD ÈÈ m===u@@2DD && c===u@@1DDx,
8u@@2DD, u@@1DDx<,
If@IntegerQ@u@@2DDD && IntegerQ@mD && GCD@m,u@@2DDD>1 && c===u@@1DDx,
8GCD@m,u@@2DDD, c<,
FalseDD,
Catch@Module@8lst=8m, c<<,
Scan@Function@lst=PowerVariableDegree@ð,lst@@1DD,lst@@2DD,xD;If@AtomQ@lstD,Throw@FalseDDD,uD;
lstDDDDD
PowerVariableSubst@u_,m_,x_SymbolD :=
If@FreeQ@u,xD ÈÈ AtomQ@uD ÈÈCalculusQ@uD,
u,
If@PowerQ@uD && FreeQ@u@@1DDx,xD,
x^Hu@@2DDmL,
Map@Function@PowerVariableSubst@ð,m,xDD,uDDD
EulerIntegrandQ
Note: If an Euler substitution should be used to integrate u wrt x, EulerIntegrandQ[u,x] returns True.
EulerIntegrandQ@Ha_.*x_+b_.*u_^n_L^p_,x_SymbolD :=
True ;
FreeQ@8a,b<,xD && IntegerQ@n+12D && QuadraticQ@u,xD && HNot@RationalQ@pDD ÈÈ NegativeIntegerQ@pD && Not@BinomialQ@u,xDDL
EulerIntegrandQ@v_^m_.*Ha_.*x_+b_.*u_^n_L^p_,x_SymbolD :=
True ;
FreeQ@8a,b<,xD && ZeroQ@u-vD && IntegersQ@2*m,n+12D && QuadraticQ@u,xD &&
HNot@RationalQ@pDD ÈÈ NegativeIntegerQ@pD && Not@BinomialQ@u,xDDL
EulerIntegrandQ@v_^m_.*Ha_.*x_+b_.*u_^n_L^p_,x_SymbolD :=
True ;
FreeQ@8a,b<,xD && ZeroQ@u-vD && IntegersQ@2*m,n+12D && QuadraticQ@u,xD &&
HNot@RationalQ@pDD ÈÈ NegativeIntegerQ@pD && Not@BinomialQ@u,xDDL
EulerIntegrandQ@u_^n_*v_^p_,x_SymbolD :=
True ;
NegativeIntegerQ@pD && IntegerQ@n+12D && QuadraticQ@u,xD && QuadraticQ@v,xD && Not@BinomialQ@v,xDD
EulerIntegrandQ@u_,x_SymbolD :=
False
102 | Integration utility functions.m
FunctionOfSquareRootOfQuadratic
H*
Euler substitution ð2:
If u is an expression of the form f HSqrt@a+b*x+c*x^2D,xL, f Hx,xL is a rational function, and
PosQ@cD, FunctionOfSquareRootOfQuadratic@u,xD returns the 3-element list 8
f HHa*Sqrt@cD+b*x+Sqrt@cD*x^2LHb+2*Sqrt@cD*xL,H-a+x^2LHb+2*Sqrt@cD*xLL*
Ha*Sqrt@cD+b*x+Sqrt@cD*x^2LHb+2*Sqrt@cD*xL^2,
Sqrt@cD*x+Sqrt@a+b*x+c*x^2D, 2 <;
Euler substitution ð1:
If u is an expression of the form f HSqrt@a+b*x+c*x^2D,xL, f Hx,xL is a rational function, and
PosQ@aD, FunctionOfSquareRootOfQuadratic@u,xD returns the two element list 8
f HHc*Sqrt@aD-b*x+Sqrt@aD*x^2LHc-x^2L,H-b+2*Sqrt@aD*xLHc-x^2LL*
Hc*Sqrt@aD-b*x+Sqrt@aD*x^2LHc-x^2L^2,
H-Sqrt@aD+Sqrt@a+b*x+c*x^2DLx, 1 <;
Euler substitution ð3:
If u is an expression of the form f HSqrt@a+b*x+c*x^2D,xL, f Hx,xL is a rational function, and
NegQ@aD and NegQ@cD, FunctionOfSquareRootOfQuadratic@u,xD returns the two element list 8
-Sqrt@b^2-4*a*cD*
f H-Sqrt@b^2-4*a*cD*xHc-x^2L,-Hb*c+c*Sqrt@b^2-4*a*cD+H-b+Sqrt@b^2-4*a*cDL*x^2LH2*c*Hc-x^2LLL*
xHc-x^2L^2,
2*c*Sqrt@a+b*x+c*x^2DHb-Sqrt@b^2-4*a*cD+2*c*xL, 3 <;
else it returns False. *L
FunctionOfSquareRootOfQuadratic@u_,x_SymbolD :=
If@MatchQ@u,x^m_.*Ha_+b_.*x^n_.L^p_ ; FreeQ@8a,b,m,n,p<,xDD,
False,
Module@8tmp=FunctionOfSquareRootOfQuadratic@u,False,xD<,
If@AtomQ@tmpD ÈÈ FalseQ@tmp@@1DDD,
False,
tmp=tmp@@1DD;
Module@8a=Coefficient@tmp,x,0D,b=Coefficient@tmp,x,1D,c=Coefficient@tmp,x,2D,sqrt,q,r<,
If@ZeroQ@aD && ZeroQ@bD ÈÈ ZeroQ@b^2-4*a*cD,
False,
If@PosQ@cD,
sqrt=Rt@c,2D;
q=a*sqrt+b*x+sqrt*x^2;
r=b+2*sqrt*x;
8Simplify@SquareRootOfQuadraticSubst@u,qr,H-a+x^2Lr,xD*qr^2D,
Simplify@sqrt*x+Sqrt@tmpDD,
2<,
If@PosQ@aD,
sqrt=Rt@a,2D;
;
Integration utility functions.m | 103
sqrt=Rt@a,2D;
q=c*sqrt-b*x+sqrt*x^2;
r=c-x^2;
8Simplify@SquareRootOfQuadraticSubst@u,qr,H-b+2*sqrt*xLr,xD*qr^2D,
Simplify@H-sqrt+Sqrt@tmpDLxD,
1<,
sqrt=Rt@b^2-4*a*c,2D;
r=c-x^2;
8Simplify@-sqrt*SquareRootOfQuadraticSubst@u,-sqrt*xr,-Hb*c+c*sqrt+H-b+sqrtL*x^2LH2*c*rL,xD*xr^2D,
FullSimplify@2*c*Sqrt@tmpDHb-sqrt+2*c*xLD,
3<DDDDDDD
FunctionOfSquareRootOfQuadratic@u_,v_,x_SymbolD :=
If@AtomQ@uD ÈÈ FreeQ@u,xD,
8v<,
If@PowerQ@uD && FreeQ@u@@2DD,xD,
If@FractionQ@u@@2DDD && Denominator@u@@2DDD==2 && PolynomialQ@u@@1DD,xD && Exponent@u@@1DD,xD==2,
If@HFalseQ@vD ÈÈ u@@1DD===vL,
8u@@1DD<,
FalseD,
FunctionOfSquareRootOfQuadratic@u@@1DD,v,xDD,
If@ProductQ@uD ÈÈ SumQ@uD,
Catch@Module@8lst=8v<<,
Scan@Function@lst=FunctionOfSquareRootOfQuadratic@ð,lst@@1DD,xD;If@AtomQ@lstD,Throw@FalseDDD,uD;
lstDD,
FalseDDD
H* SquareRootOfQuadraticSubst@u,vv,xx,xD returns u with fractional powers replaced by vv raised
to the power and x replaced by xx. *L
SquareRootOfQuadraticSubst@u_,vv_,xx_,x_SymbolD :=
If@AtomQ@uD ÈÈ FreeQ@u,xD,
If@u===x,
xx,
uD,
If@PowerQ@uD && FreeQ@u@@2DD,xD,
If@FractionQ@u@@2DDD && Denominator@u@@2DDD==2 && PolynomialQ@u@@1DD,xD && Exponent@u@@1DD,xD==2,
vv^Numerator@u@@2DDD,
SquareRootOfQuadraticSubst@u@@1DD,vv,xx,xD^u@@2DDD,
Map@Function@SquareRootOfQuadraticSubst@ð,vv,xx,xDD,uDDD
104 | Integration utility functions.m
Substitution functions
Subst
H* Subst@u,x,wD returns u with x replaced by w and resulting constant terms replaced by 0. *L
Subst@u_,x_Symbol,w_D :=
SimplifyAntiderivative@SubstAux@u,x,wD,xD
Subst@u_,Rule@x_Symbol,w_DD :=
SimplifyAntiderivative@SubstAux@u,x,wD,xD
Subst@u_,x_,w_D :=
SubstAux@u,x,wD
SubstAux@a_+b_.*x_,x_Symbol,c_.*F_@z_D^2D :=
a*Simplify@1-F@zD^2D ;
FreeQ@8a,b,c<,xD && MemberQ@8Sin,Cos,Sec,Csc,Cosh,Tanh,Coth,Sech<,FD && ZeroQ@a+b*cD
SubstAux@a_+b_.*x_,x_Symbol,c_.*F_@z_D^2D :=
a*Simplify@1+F@zD^2D ;
FreeQ@8a,b,c<,xD && MemberQ@8Tan,Cot,Sinh,Csch<,FD && ZeroQ@a-b*cD
SubstAux@a_+b_.*x_^2,x_Symbol,c_.*F_@z_DD :=
a*Simplify@1-F@zD^2D ;
FreeQ@8a,b,c<,xD && MemberQ@8Sin,Cos,Sec,Csc,Cosh,Tanh,Coth,Sech<,FD && ZeroQ@a+b*c^2D
SubstAux@a_+b_.*x_^2,x_Symbol,c_.*F_@z_DD :=
a*Simplify@1+F@zD^2D ;
FreeQ@8a,b,c<,xD && MemberQ@8Tan,Cot,Sinh,Csch<,FD && ZeroQ@a-b*c^2D
SubstAux@F_@a_.*x_^m_.D,x_Symbol,b_.*x_^n_D :=
Extract@8ArcCsc,ArcSec,ArcCot,ArcTan,ArcCos,ArcSin,ArcCsch,ArcSech,ArcCoth,ArcTanh,ArcCosh,ArcSinh<,
Position@8ArcSin,ArcCos,ArcTan,ArcCot,ArcSec,ArcCsc,ArcSinh,ArcCosh,ArcTanh,ArcCoth,ArcSech,ArcCsch<,FDD@@1DD @x^H-m*nLHa*b^mL
FreeQ@8a,b<,xD && PositiveIntegerQ@mD && NegativeIntegerQ@nD && MemberQ@8ArcSin,ArcCos,ArcTan,ArcCot,ArcSec,ArcCsc,ArcSinh,ArcCosh
Integration utility functions.m | 105
H* Subst@u,v,wD returns u with all nondummy occurences of v replaced by w *L
SubstAux@u_,v_,w_D :=
If@u===v,
w,
If@AtomQ@uD,
u,
If@PowerQ@uD,
If@PowerQ@vD && u@@1DD===v@@1DD && SumQ@u@@2DDD,
SubstAux@u@@1DD^First@u@@2DDD,v,wD*SubstAux@u@@1DD^Rest@u@@2DDD,v,wD,
SubstAux@u@@1DD,v,wD^SubstAux@u@@2DD,v,wDD,
If@Head@uD===Defer@SubstD,
If@u@@2DD===v ÈÈ FreeQ@u@@1DD,vD,
SubstAux@u@@1DD,u@@2DD,SubstAux@u@@3DD,v,wDD,
Defer@SubstD@u,v,wDD,
If@Head@uD===Defer@DistD,
Defer@DistD@SubstAux@u@@1DD,v,wD,SubstAux@u@@2DD,v,wD,u@@3DDD,
If@CalculusQ@uD && Not@FreeQ@v,u@@2DDDD ÈÈ HeldFormQ@uD && Head@uD=!=Defer@AppellF1D,
Defer@SubstD@u,v,wD,
Map@Function@SubstAux@ð,v,wDD,uDDDDDDD
SimplifyAntiderivative
è SimplifyAntiderivative[u,x] returns the simplest, continuous expression whose derivative wrt x equals the derivative of u wrt x.
è Basis: D[c*F[x], x] == c*D[F[x], x]
Clear@SimplifyAntiderivativeD;
SimplifyAntiderivative@c_*u_,x_SymbolD :=
With@8v=SimplifyAntiderivative@u,xD<,
If@SumQ@vD && NonsumQ@uD,
Map@Function@c*ðD,vD,
c*vDD ;
FreeQ@c,xD
è Basis: D[Log[c*F[x]], x] == D[Log[F[x]], x]
SimplifyAntiderivative@Log@c_*u_D,x_SymbolD :=
SimplifyAntiderivative@Log@uD,xD ;
FreeQ@c,xD
è Basis: D[Log[F[x]^n], x] == n*D[Log[F[x]], x]
SimplifyAntiderivative@Log@u_^n_D,x_SymbolD :=
n*SimplifyAntiderivative@Log@uD,xD ;
FreeQ@n,xD
è Basis: If FÎ{Log,ArcTan,ArcCot}, then D[F[G[x]], x] == -D[F[1/G[x]], x]
106 | Integration utility functions.m
SimplifyAntiderivative@F_@G_@u_DD,x_SymbolD :=
-SimplifyAntiderivative@F@1G@uDD,xD ;
MemberQ@8Log,ArcTan,ArcCot<,FD && MemberQ@8Cot,Sec,Csc,Coth,Sech,Csch<,GD
è Basis: If FÎ{ArcTanh,ArcCoth}, then D[F[G[x]], x] == D[F[1/G[x]], x]
SimplifyAntiderivative@F_@G_@u_DD,x_SymbolD :=
SimplifyAntiderivative@F@1G@uDD,xD ;
MemberQ@8ArcTanh,ArcCoth<,FD && MemberQ@8Cot,Sec,Csc,Coth,Sech,Csch<,GD
SimplifyAntiderivative@Log@F_@u_DD,x_SymbolD :=
-SimplifyAntiderivative@Log@1F@uDD,xD ;
MemberQ@8Cot,Sec,Csc,Coth,Sech,Csch<,FD
è Basis: D[Log[f^G[x]], x] == Log[f]*D[G[x], x]
SimplifyAntiderivative@Log@f_^u_D,x_SymbolD :=
Log@fD*SimplifyAntiderivative@u,xD ;
FreeQ@f,xD
è Basis: If a^2+b^2==0, then D[Log[a + b*Tan[F[x]]], x] == (b*D[F[x], x])/a - D[Log[Cos[F[x]]], x]
SimplifyAntiderivative@Log@a_+b_.*Tan@u_DD,x_SymbolD :=
ba*SimplifyAntiderivative@u,xD - SimplifyAntiderivative@Log@Cos@uDD,xD ;
FreeQ@8a,b<,xD && ZeroQ@a^2+b^2D
è Basis: If a^2+b^2==0, then D[Log[a + b*Cot[F[x]]], x] == -((b/a)*D[F[x], x]) - D[Log[Sin[F[x]]], x]
SimplifyAntiderivative@Log@a_+b_.*Cot@u_DD,x_SymbolD :=
-ba*SimplifyAntiderivative@u,xD - SimplifyAntiderivative@Log@Sin@uDD,xD ;
FreeQ@8a,b<,xD && ZeroQ@a^2+b^2D
è Note: Should also recognize that Tan[z/2]==Sin[z]/(1+Cos[z])==Tan[z]/(1+Sec[z])
SimplifyAntiderivative@ArcTan@a_.*Tan@u_DD,x_SymbolD :=
RectifyTangent@u,a,1,xD ;
FreeQ@a,xD && PositiveQ@a^2D && ComplexFreeQ@uD
è Basis: D[ArcCot[a*Tan[f[x]]], x] == -D[ArcTan[a*Tan[f[x]]], x]
SimplifyAntiderivative@ArcCot@a_.*Tan@u_DD,x_SymbolD :=
RectifyTangent@u,a,-1,xD ;
FreeQ@a,xD && PositiveQ@a^2D && ComplexFreeQ@uD
è Basis: ArcTan[a Tanh[z]]==-ArcTan[I a Tan[I z]]
Integration utility functions.m | 107
H* SimplifyAntiderivative@ArcTan@a_.*Tanh@u_DD,x_SymbolD :=
RectifyTangent@I*u,I*a,-1,xD ;
FreeQ@a,xD && PositiveQ@a^2D && ComplexFreeQ@uD *L
è Basis: D[ArcCot[a*Tanh[f[x]]], x] == -D[ArcTan[a*Tanh[f[x]]], x]
SimplifyAntiderivative@ArcCot@a_.*Tanh@u_DD,x_SymbolD :=
-SimplifyAntiderivative@ArcTan@a*Tanh@uDD,xD ;
FreeQ@a,xD && ComplexFreeQ@uD
è Basis: ArcTanh[a Tan[z]]==-I ArcTan[I a Tan[z]]
SimplifyAntiderivative@ArcTanh@a_.*Tan@u_DD,x_SymbolD :=
RectifyTangent@u,I*a,-I,xD ;
FreeQ@a,xD && PositiveQ@a^2D && ComplexFreeQ@uD
è Basis: D[ArcCoth[a*Tan[f[x]]], x] == -(I*D[ArcTan[I*a*Tan[f[x]]], x])
SimplifyAntiderivative@ArcCoth@a_.*Tan@u_DD,x_SymbolD :=
RectifyTangent@u,I*a,-I,xD ;
FreeQ@a,xD && PositiveQ@a^2D && ComplexFreeQ@uD
è Basis: ArcTanh[a Tanh[z]]==-I ArcTan[a Tan[I z]]
è Note: Although this makes the antiderivative continuous on the imaginary line, it makes it discontinous on the real line.
H* SimplifyAntiderivative@ArcTanh@a_.*Tanh@u_DD,x_SymbolD :=
RectifyTangent@I*u,a,-I,xD ;
FreeQ@a,xD && PositiveQ@a^2D && ComplexFreeQ@uD *L
è Basis: D[ArcTanh[Tanh[f[x]]], x] == D[f[x], x]
SimplifyAntiderivative@ArcTanh@Tanh@u_DD,x_SymbolD :=
SimplifyAntiderivative@u,xD
è Basis: D[ArcCoth[a*Tanh[f[x]]], x] == -(I*D[ArcTan[a*Tan[I*f[x]]], x])
è Note: Although this makes the antiderivative continuous on the imaginary line, it makes it discontinous on the real line.
H* SimplifyAntiderivative@ArcCoth@a_.*Tanh@u_DD,x_SymbolD :=
RectifyTangent@I*u,a,-I,xD ;
FreeQ@a,xD && PositiveQ@a^2D && ComplexFreeQ@uD *L
è Basis: D[ArcCoth[Tanh[f[x]]], x] == D[f[x], x]
SimplifyAntiderivative@ArcCoth@Tanh@u_DD,x_SymbolD :=
SimplifyAntiderivative@u,xD
108 | Integration utility functions.m
SimplifyAntiderivative@ArcCot@a_.*Cot@u_DD,x_SymbolD :=
RectifyCotangent@u,a,1,xD ;
FreeQ@a,xD && PositiveQ@a^2D && ComplexFreeQ@uD
è Basis: D[ArcTan[a*Cot[f[x]]], x] == -D[ArcCot[a*Cot[f[x]]], x]
SimplifyAntiderivative@ArcTan@a_.*Cot@u_DD,x_SymbolD :=
RectifyCotangent@u,a,-1,xD ;
FreeQ@a,xD && PositiveQ@a^2D && ComplexFreeQ@uD
è Basis: ArcCot[a Coth[z]]==ArcCot[I a Cot[I z]]
H* SimplifyAntiderivative@ArcCot@a_.*Coth@u_DD,x_SymbolD :=
RectifyCotangent@I*u,I*a,1,xD ;
FreeQ@a,xD && PositiveQ@a^2D && ComplexFreeQ@uD *L
è Basis: D[ArcTan[a*Coth[f[x]]], x] == -D[ArcTan[Tanh[f[x]]/a], x]
SimplifyAntiderivative@ArcTan@a_.*Coth@u_DD,x_SymbolD :=
-SimplifyAntiderivative@ArcTan@Tanh@uDaD,xD ;
FreeQ@a,xD && ComplexFreeQ@uD
è Basis: ArcCoth[a Cot[z]]==I ArcCot[I a Cot[z]]
SimplifyAntiderivative@ArcCoth@a_.*Cot@u_DD,x_SymbolD :=
RectifyCotangent@u,I*a,I,xD ;
FreeQ@a,xD && PositiveQ@a^2D && ComplexFreeQ@uD
è Basis: D[ArcTanh[a*Cot[f[x]]], x] == I*D[ArcCot[I*a*Cot[f[x]]], x]
SimplifyAntiderivative@ArcTanh@a_.*Cot@u_DD,x_SymbolD :=
RectifyCotangent@u,I*a,I,xD ;
FreeQ@a,xD && PositiveQ@a^2D && ComplexFreeQ@uD
è Basis: ArcCoth[a Coth[z]]==-I ArcCot[a Cot[I z]]
è Note: Although this makes the antiderivative continuous on the imaginary line, it makes it discontinous on the real line.
H* SimplifyAntiderivative@ArcCoth@a_.*Coth@u_DD,x_SymbolD :=
RectifyCotangent@I*u,a,-I,xD ;
FreeQ@a,xD && PositiveQ@a^2D && ComplexFreeQ@uD *L
è Basis: D[ArcCoth[Coth[f[x]]], x] == D[f[x], x]
SimplifyAntiderivative@ArcCoth@Coth@u_DD,x_SymbolD :=
SimplifyAntiderivative@u,xD
è Basis: D[ArcTanh[a*Coth[f[x]]], x] == D[ArcTanh[Tanh[f[x]]/a], x]
Integration utility functions.m | 109
SimplifyAntiderivative@ArcTanh@a_.*Coth@u_DD,x_SymbolD :=
SimplifyAntiderivative@ArcTanh@Tanh@uDaD,xD ;
FreeQ@a,xD && ComplexFreeQ@uD
è Basis: D[ArcTanh[Coth[f[x]]], x] == D[f[x], x]
SimplifyAntiderivative@ArcTanh@Coth@u_DD,x_SymbolD :=
SimplifyAntiderivative@u,xD
SimplifyAntiderivative@ArcTan@c_.*Ha_+b_.*Tan@u_DLD,x_SymbolD :=
RectifyTangent@u,a*c,b*c,1,xD ;
FreeQ@8a,b,c<,xD && PositiveQ@a^2*c^2D && PositiveQ@b^2*c^2D && ComplexFreeQ@uD
è Basis: ArcTanh[a+b Tan[z]]==-I ArcTan[I a+I b Tan[z]]
SimplifyAntiderivative@ArcTanh@c_.*Ha_+b_.*Tan@u_DLD,x_SymbolD :=
RectifyTangent@u,I*a*c,I*b*c,-I,xD ;
FreeQ@8a,b,c<,xD && PositiveQ@a^2*c^2D && PositiveQ@b^2*c^2D && ComplexFreeQ@uD
SimplifyAntiderivative@ArcTan@c_.*Ha_+b_.*Cot@u_DLD,x_SymbolD :=
RectifyCotangent@u,a*c,b*c,1,xD ;
FreeQ@8a,b,c<,xD && PositiveQ@a^2*c^2D && PositiveQ@b^2*c^2D && ComplexFreeQ@uD
è Basis: ArcTanh[a+b Cot[z]]==-I ArcTan[I a+I b Cot[z]]
SimplifyAntiderivative@ArcTanh@c_.*Ha_+b_.*Cot@u_DLD,x_SymbolD :=
RectifyCotangent@u,I*a*c,I*b*c,-I,xD ;
FreeQ@8a,b,c<,xD && PositiveQ@a^2*c^2D && PositiveQ@b^2*c^2D && ComplexFreeQ@uD
è Basis: D[ArcTan[a + b*Tan[F[x]] + c*Tan[F[x]]^2], x] == D[ArcTan[(c + (a - c - 1)*Cos[F[x]]^2 + b*Cos[F[x]]*Sin[F[x]])/(c + (a - c + 1)*Cos[F[x]]^2 +
b*Cos[F[x]]*Sin[F[x]])], x] == D[ArcTan[(a + c - 1 + (a - c - 1)*Cos[2*F[x]] + b*Sin[2*F[x]])/(a + c + 1 + (a - c + 1)*Cos[2*F[x]] + b*Sin[2*F[x]])], x]
SimplifyAntiderivative@ArcTan@a_.+b_.*Tan@u_D+c_.*Tan@u_D^2D,x_SymbolD :=
If@EvenQ@Denominator@NumericFactor@Together@uDDDD,
ArcTan@NormalizeTogether@Ha+c-1+Ha-c-1L*Cos@2*uD+b*Sin@2*uDLHa+c+1+Ha-c+1L*Cos@2*uD+b*Sin@2*uDLDD,
ArcTan@NormalizeTogether@Hc+Ha-c-1L*Cos@uD^2+b*Cos@uD*Sin@uDLHc+Ha-c+1L*Cos@uD^2+b*Cos@uD*Sin@uDLDDD ;
FreeQ@8a,b,c<,xD && ComplexFreeQ@uD
SimplifyAntiderivative@ArcTan@a_.+b_.*Hd_.+e_.*Tan@u_DL+c_.*Hf_.+g_.*Tan@u_DL^2D,x_SymbolD :=
SimplifyAntiderivative@ArcTan@a+b*d+c*f^2+Hb*e+2*c*f*gL*Tan@uD+c*g^2*Tan@uD^2D,xD ;
FreeQ@8a,b,c<,xD && ComplexFreeQ@uD
110 | Integration utility functions.m
è Basis: D[ArcTan[a + c*Tan[F[x]]^2], x] == D[ArcTan[(c + (a - c - 1)*Cos[F[x]]^2)/(c + (a - c + 1)*Cos[F[x]]^2)], x] == D[ArcTan[(a + c - 1 + (a - c 1)*Cos[2*F[x]])/(a + c + 1 + (a - c + 1)*Cos[2*F[x]])], x]
SimplifyAntiderivative@ArcTan@a_.+c_.*Tan@u_D^2D,x_SymbolD :=
If@EvenQ@Denominator@NumericFactor@Together@uDDDD,
ArcTan@NormalizeTogether@Ha+c-1+Ha-c-1L*Cos@2*uDLHa+c+1+Ha-c+1L*Cos@2*uDLDD,
ArcTan@NormalizeTogether@Hc+Ha-c-1L*Cos@uD^2LHc+Ha-c+1L*Cos@uD^2LDDD ;
FreeQ@8a,c<,xD && ComplexFreeQ@uD
SimplifyAntiderivative@ArcTan@a_.+c_.*Hf_.+g_.*Tan@u_DL^2D,x_SymbolD :=
SimplifyAntiderivative@ArcTan@a+c*f^2+H2*c*f*gL*Tan@uD+c*g^2*Tan@uD^2D,xD ;
FreeQ@8a,c<,xD && ComplexFreeQ@uD
è Basis: D[c, x] == D[0, x]
SimplifyAntiderivative@u_,x_SymbolD :=
If@FreeQ@u,xD,
0,
If@LogQ@uD,
Log@RemoveContent@u@@1DD,xDD,
If@SumQ@uD,
SimplifyAntiderivativeSum@Map@Function@SimplifyAntiderivative@ð,xDD,uD,xD,
uDDD
SimplifyAntiderivativeSum
Clear@SimplifyAntiderivativeSumD;
SimplifyAntiderivativeSum@v_.+A_.*Log@a_+b_.*Tan@u_D^n_.D+B_.*Log@Cos@u_DD,x_SymbolD :=
SimplifyAntiderivativeSum@v,xD + A*Log@RemoveContent@a*Cos@uD^n+b*Sin@uD^n,xDD ;
FreeQ@8a,b,A,B<,xD && IntegerQ@nD && ZeroQ@n*A-BD
SimplifyAntiderivativeSum@v_.+A_.*Log@a_+b_.*Cot@u_D^n_.D+B_.*Log@Sin@u_DD,x_SymbolD :=
SimplifyAntiderivativeSum@v,xD + A*Log@RemoveContent@a*Sin@uD^n+b*Cos@uD^n,xDD ;
FreeQ@8a,b,A,B<,xD && IntegerQ@nD && ZeroQ@n*A-BD
SimplifyAntiderivativeSum@v_.+A_.*Log@a_+b_.*Tan@u_D^n_.D+B_.*Log@c_+d_.*Tan@u_D^n_.D,x_SymbolD :=
SimplifyAntiderivativeSum@v,xD + A*Log@RemoveContent@a*Cos@uD^n+b*Sin@uD^n,xDD + B*Log@RemoveContent@c*Cos@uD^n+d*Sin@uD^n,xDD
FreeQ@8a,b,c,d,A,B<,xD && IntegerQ@nD && ZeroQ@A+BD
SimplifyAntiderivativeSum@v_.+A_.*Log@a_+b_.*Cot@u_D^n_.D+B_.*Log@c_+d_.*Cot@u_D^n_.D,x_SymbolD :=
SimplifyAntiderivativeSum@v,xD + A*Log@RemoveContent@b*Cos@uD^n+a*Sin@uD^n,xDD + B*Log@RemoveContent@d*Cos@uD^n+c*Sin@uD^n,xDD
FreeQ@8a,b,c,d,A,B<,xD && IntegerQ@nD && ZeroQ@A+BD
Integration utility functions.m | 111
SimplifyAntiderivativeSum@v_.+A_.*Log@a_+b_.*Tan@u_D^n_.D+B_.*Log@c_+d_.*Tan@u_D^n_.D+C_.*Log@e_+f_.*Tan@u_D^n_.D,x_SymbolD :=
SimplifyAntiderivativeSum@v,xD + A*Log@RemoveContent@a*Cos@uD^n+b*Sin@uD^n,xDD +
B*Log@RemoveContent@c*Cos@uD^n+d*Sin@uD^n,xDD + C*Log@RemoveContent@e*Cos@uD^n+f*Sin@uD^n,xDD ;
FreeQ@8a,b,c,d,e,f,A,B,C<,xD && IntegerQ@nD && ZeroQ@A+B+CD
SimplifyAntiderivativeSum@v_.+A_.*Log@a_+b_.*Cot@u_D^n_.D+B_.*Log@c_+d_.*Cot@u_D^n_.D+C_.*Log@e_+f_.*Cot@u_D^n_.D,x_SymbolD :=
SimplifyAntiderivativeSum@v,xD + A*Log@RemoveContent@b*Cos@uD^n+a*Sin@uD^n,xDD +
B*Log@RemoveContent@d*Cos@uD^n+c*Sin@uD^n,xDD + C*Log@RemoveContent@f*Cos@uD^n+e*Sin@uD^n,xDD ;
FreeQ@8a,b,c,d,e,f,A,B,C<,xD && IntegerQ@nD && ZeroQ@A+B+CD
SimplifyAntiderivativeSum@u_,x_SymbolD := u
RectifyTangent
è Basis: ArcTan[I a Tan[f[x]]]==I ArcTanh[a Tan[f[x]]]
è Basis: D[ArcTanh[(c/e)*Tan[f[x]]], x] == D[Log[e*Cos[f[x]] + c*Sin[f[x]]]/2 - Log[e*Cos[f[x]] - c*Sin[f[x]]]/2, x]
è Note: Note unlike the above, the log terms in the following two identities are real-valued when c, e and f[x] are real.
è Basis: D[ArcTanh[(c/e)*Tan[f[x]]], x] == D[Log[c^2 + e^2 - (c^2 - e^2)*Cos[2*f[x]] + 2*c*e*Sin[2*f[x]]]/4 - Log[c^2 + e^2 - (c^2 - e^2)*Cos[2*f[x]] 2*c*e*Sin[2*f[x]]]/4, x]
è Basis: D[ArcTanh[(c/e)*Tan[f[x]]], x] == D[Log[e^2 + 2*c*e*Cos[f[x]]*Sin[f[x]] + (c^2 - e^2)*Sin[f[x]]^2]/4 - Log[e^2 - 2*c*e*Cos[f[x]]*Sin[f[x]] + (c^2 e^2)*Sin[f[x]]^2]/4, x]
è Basis: D[ArcTan[a*Tan[f[x]]], x] == D[f[x] - ArcTan[Sin[2*f[x]]/((1 + a)/(1 - a) + Cos[2*f[x]])], x]
è Basis: D[ArcTan[a*Tan[f[x]]], x] == D[f[x] + ArcTan[(Cos[f[x]]*Sin[f[x]])/(1/(a - 1) + Sin[f[x]]^2)], x] == D[f[x] - ArcTan[(Cos[f[x]]*Sin[f[x]])/(a/(1 - a) +
Cos[f[x]]^2)], x]
è Note: If a>0 and f[x] is real, then 1/(1-a)-Sin[f[x]]^2 is nonzero and f[x]-ArcTan[(Cos[f[x]] Sin[f[x]])/(1/(1-a)-Sin[f[x]]^2)] is continuous, unlike ArcTan[a
Tan[f[x]]].
112 | Integration utility functions.m
H* RectifyTangent@u,a,b,xD returns an expression whose derivative equals the derivative of b*ArcTan@a*Tan@uDD wrt x. *L
RectifyTangent@u_,a_,b_,x_SymbolD :=
If@MatchQ@Together@aD,d_.*Complex@0,c_DD,
Module@8c=aI,e<,
If@NegativeQ@cD,
RectifyTangent@u,-a,-b,xD,
If@ZeroQ@c-1D,
If@EvenQ@Denominator@NumericFactor@Together@uDDDD,
I*b*ArcTanh@Sin@2*uDD2,
I*b*ArcTanh@2*Cos@uD*Sin@uDD2D,
e=SmartDenominator@cD;
c=c*e;
H* If@EvenQ@Denominator@NumericFactor@Together@uDDDD,
I*b*Log@RemoveContent@c^2+e^2-Hc^2-e^2L*Cos@2*uD+2*c*e*Sin@2*uD,xDD4 I*b*Log@RemoveContent@c^2+e^2-Hc^2-e^2L*Cos@2*uD-2*c*e*Sin@2*uD,xDD4,
I*b*Log@RemoveContent@e^2+2*c*e*Cos@uD*Sin@uD+Hc^2-e^2L*Sin@uD^2,xDD4 I*b*Log@RemoveContent@e^2-2*c*e*Cos@uD*Sin@uD+Hc^2-e^2L*Sin@uD^2,xDD4DDDD, *L
I*b*Log@RemoveContent@e*Cos@uD+c*Sin@uD,xDD2 I*b*Log@RemoveContent@e*Cos@uD-c*Sin@uD,xDD2DDD,
If@NegativeQ@aD,
RectifyTangent@u,-a,-b,xD,
If@ZeroQ@a-1D,
b*SimplifyAntiderivative@u,xD,
Module@8c,numr,denr<,
If@EvenQ@Denominator@NumericFactor@Together@uDDDD,
c=Simplify@H1+aLH1-aLD;
numr=SmartNumerator@cD;
denr=SmartDenominator@cD;
b*SimplifyAntiderivative@u,xD - b*ArcTan@NormalizeLeadTermSigns@denr*Sin@2*uDHnumr+denr*Cos@2*uDLDD,
If@PositiveQ@a-1D,
c=Simplify@1Ha-1LD;
numr=SmartNumerator@cD;
denr=SmartDenominator@cD;
b*SimplifyAntiderivative@u,xD + b*ArcTan@NormalizeLeadTermSigns@denr*Cos@uD*Sin@uDHnumr+denr*Sin@uD^2LDD,
c=Simplify@aH1-aLD;
numr=SmartNumerator@cD;
denr=SmartDenominator@cD;
b*SimplifyAntiderivative@u,xD - b*ArcTan@NormalizeLeadTermSigns@denr*Cos@uD*Sin@uDHnumr+denr*Cos@uD^2LDDDDDDDD
è Basis: ArcTan[I a+I b Tan[f[x]]]==I ArcTanh[a+b Tan[f[x]]]
è Basis: D[ArcTanh[c/e + (d/e)*Tan[f[x]]], x] == D[Log[(c + e)^2 + d^2 + ((c + e)^2 - d^2)*Cos[2*f[x]] + 2*(c + e)*d*Sin[2*f[x]]]/4 - Log[(c - e)^2 + d^2 + ((c - e)^2
- d^2)*Cos[2*f[x]] + 2*(c - e)*d*Sin[2*f[x]]]/4, x]
Integration utility functions.m | 113
è Basis: D[ArcTanh[c/e + (d/e)*Tan[f[x]]], x] == D[Log[(c + e)^2 + 2*(c + e)*d*Cos[f[x]]*Sin[f[x]] - ((c + e)^2 - d^2)*Sin[f[x]]^2]/4 - Log[(c - e)^2 + 2*(c e)*d*Cos[f[x]]*Sin[f[x]] - ((c - e)^2 - d^2)*Sin[f[x]]^2]/4, x]
è Basis: D[ArcTan[a + b*Tan[f[x]]], x] == D[f[x] + ArcTan[(2*a*b*Cos[2*f[x]] - (1 + a^2 - b^2)*Sin[2*f[x]])/(a^2 + (1 + b)^2 + (1 + a^2 - b^2)*Cos[2*f[x]] +
2*a*b*Sin[2*f[x]])], x]
è Basis: D[ArcTan[a + b*Tan[f[x]]], x] == D[f[x] - ArcTan[(a*b - 2*a*b*Cos[f[x]]^2 + (1 + a^2 - b^2)*Cos[f[x]]*Sin[f[x]])/(b*(1 + b) + (1 + a^2 - b^2)*Cos[f[x]]^2 +
2*a*b*Cos[f[x]]*Sin[f[x]])], x]
H* RectifyTangent@u,a,b,r,xD returns an expression whose derivative equals the derivative of r*ArcTan@a+b*Tan@uDD wrt x. *L
RectifyTangent@u_,a_,b_,r_,x_SymbolD :=
If@MatchQ@Together@aD,d_.*Complex@0,c_DD && MatchQ@Together@bD,d_.*Complex@0,c_DD,
Module@8c=aI,d=bI,e<,
If@NegativeQ@dD,
RectifyTangent@u,-a,-b,-r,xD,
e=SmartDenominator@Together@c+d*xDD;
c=c*e;
d=d*e;
If@EvenQ@Denominator@NumericFactor@Together@uDDDD,
I*r*Log@RemoveContent@Simplify@Hc+eL^2+d^2D+Simplify@Hc+eL^2-d^2D*Cos@2*uD+Simplify@2*Hc+eL*dD*Sin@2*uD,xDD4 I*r*Log@RemoveContent@Simplify@Hc-eL^2+d^2D+Simplify@Hc-eL^2-d^2D*Cos@2*uD+Simplify@2*Hc-eL*dD*Sin@2*uD,xDD4,
I*r*Log@RemoveContent@Simplify@Hc+eL^2D+Simplify@2*Hc+eL*dD*Cos@uD*Sin@uD-Simplify@Hc+eL^2-d^2D*Sin@uD^2,xDD4 I*r*Log@RemoveContent@Simplify@Hc-eL^2D+Simplify@2*Hc-eL*dD*Cos@uD*Sin@uD-Simplify@Hc-eL^2-d^2D*Sin@uD^2,xDD4DDD,
If@NegativeQ@bD,
RectifyTangent@u,-a,-b,-r,xD,
If@EvenQ@Denominator@NumericFactor@Together@uDDDD,
r*SimplifyAntiderivative@u,xD +
r*ArcTan@Simplify@H2*a*b*Cos@2*uD-H1+a^2-b^2L*Sin@2*uDLHa^2+H1+bL^2+H1+a^2-b^2L*Cos@2*uD+2*a*b*Sin@2*uDLDD,
r*SimplifyAntiderivative@u,xD r*ArcTan@ActivateTrig@Simplify@Ha*b-2*a*b*cos@uD^2+H1+a^2-b^2L*cos@uD*sin@uDLHb*H1+bL+H1+a^2-b^2L*cos@uD^2+2*a*b*cos@uD*sin@uD
è Basis: D[ArcTanh[a + b*Tanh[f[x]]], x] == D[f[x] - ArcTanh[(2*a*b*Cosh[2*f[x]] - (1 - a^2 - b^2)*Sinh[2*f[x]])/(a^2 - (1 + b)^2 - (1 - a^2 - b^2)*Cosh[2*f[x]] +
2*a*b*Sinh[2*f[x]])], x]
è Basis: D[ArcTanh[a + b*Tanh[f[x]]], x] == D[f[x] - ArcTanh[(a*b - 2*a*b*Cosh[f[x]]^2 + (1 - a^2 - b^2)*Cosh[f[x]]*Sinh[f[x]])/(b*(1 + b) + (1 - a^2 b^2)*Cosh[f[x]]^2 - 2*a*b*Cosh[f[x]]*Sinh[f[x]])], x]
H* SimplifyAntiderivative@ArcTanh@c_.*Ha_+b_.*Tanh@u_DLD,x_SymbolD :=
If@EvenQ@Denominator@NumericFactor@Together@uDDDD,
SimplifyAntiderivative@u,xD ArcTanh@NormalizeTogether@H2*a*b*c^2*Cosh@2*uD-H1-a^2*c^2-b^2*c^2L*Sinh@2*uDLHa^2*c^2-H1+b*cL^2-H1-a^2*c^2-b^2*c^2L*Cosh@2*u
SimplifyAntiderivative@u,xD ArcTanh@NormalizeTogether@Ha*b*c^2-2*a*b*c^2*Cosh@uD^2+H1-a^2*c^2-b^2*c^2L*Cosh@uD*Sinh@uDLHb*c*H1+b*cL+H1-a^2*c^2-b^2*c^2L*Cosh
FreeQ@8a,b,c<,xD *L
D
114 | Integration utility functions.m
RectifyCotangent
è Basis: ArcCot[I a Cot[f[x]]]==-I ArcCoth[a Cot[f[x]]]
è Basis: D[ArcCoth[(c/e)*Cot[f[x]]], x] == D[Log[c*Cos[f[x]] + e*Sin[f[x]]]/2 - Log[c*Cos[f[x]] - e*Sin[f[x]]]/2, x]
è Note: Note unlike the above, the log terms in the following two identities are real-valued when c, e and f[x] are real.
è Basis: D[ArcTanh[(c/e)*Cot[f[x]]], x] == D[Log[c^2 + e^2 + (c^2 - e^2)*Cos[2*f[x]] + 2*c*e*Sin[2*f[x]]]/4 - Log[c^2 + e^2 + (c^2 - e^2)*Cos[2*f[x]] 2*c*e*Sin[2*f[x]]]/4, x]
è Basis: D[ArcTanh[(c/e)*Cot[f[x]]], x] == D[Log[e^2 + (c^2 - e^2)*Cos[f[x]]^2 + 2*c*e*Cos[f[x]]*Sin[f[x]]]/4 - Log[e^2 + (c^2 - e^2)*Cos[f[x]]^2 2*c*e*Cos[f[x]]*Sin[f[x]]]/4, x]
è Basis: D[ArcCot[a*Cot[f[x]]], x] == D[f[x] + ArcTan[Sin[2*f[x]]/((1 + a)/(1 - a) - Cos[2*f[x]])], x]
è Basis: D[ArcCot[a*Cot[f[x]]], x] == D[f[x] - ArcTan[(Cos[f[x]]*Sin[f[x]])/(1/(a - 1) + Cos[f[x]]^2)], x] == D[f[x] + ArcTan[(Cos[f[x]]*Sin[f[x]])/(a/(1 - a) +
Sin[f[x]]^2)], x]
Integration utility functions.m | 115
H* RectifyCotangent@u,a,b,xD returns an expression whose derivative equals the derivative of b*ArcCot@a*Cot@uDD wrt x. *L
RectifyCotangent@u_,a_,b_,x_SymbolD :=
If@MatchQ@Together@aD,d_.*Complex@0,c_DD,
Module@8c=aI,e<,
If@NegativeQ@cD,
RectifyCotangent@u,-a,-b,xD,
If@ZeroQ@c-1D,
If@EvenQ@Denominator@NumericFactor@Together@uDDDD,
-I*b*ArcTanh@Sin@2*uDD2,
-I*b*ArcTanh@2*Cos@uD*Sin@uDD2D,
e=SmartDenominator@cD;
c=c*e;
H* If@EvenQ@Denominator@NumericFactor@Together@uDDDD,
-I*b*Log@RemoveContent@c^2+e^2+Hc^2-e^2L*Cos@2*uD+2*c*e*Sin@2*uD,xDD4 +
I*b*Log@RemoveContent@c^2+e^2+Hc^2-e^2L*Cos@2*uD-2*c*e*Sin@2*uD,xDD4,
-I*b*Log@RemoveContent@e^2+Hc^2-e^2L*Cos@uD^2+2*c*e*Cos@uD*Sin@uD,xDD4 +
I*b*Log@RemoveContent@e^2+Hc^2-e^2L*Cos@uD^2-2*c*e*Cos@uD*Sin@uD,xDD4DDDD, *L
-I*b*Log@RemoveContent@c*Cos@uD+e*Sin@uD,xDD2 +
I*b*Log@RemoveContent@c*Cos@uD-e*Sin@uD,xDD2DDD,
If@NegativeQ@aD,
RectifyCotangent@u,-a,-b,xD,
If@ZeroQ@a-1D,
b*SimplifyAntiderivative@u,xD,
Module@8c,numr,denr<,
If@EvenQ@Denominator@NumericFactor@Together@uDDDD,
c=Simplify@H1+aLH1-aLD;
numr=SmartNumerator@cD;
denr=SmartDenominator@cD;
b*SimplifyAntiderivative@u,xD + b*ArcTan@NormalizeLeadTermSigns@denr*Sin@2*uDHnumr-denr*Cos@2*uDLDD,
If@PositiveQ@a-1D,
c=Simplify@1Ha-1LD;
numr=SmartNumerator@cD;
denr=SmartDenominator@cD;
b*SimplifyAntiderivative@u,xD - b*ArcTan@NormalizeLeadTermSigns@denr*Cos@uD*Sin@uDHnumr+denr*Cos@uD^2LDD,
c=Simplify@aH1-aLD;
numr=SmartNumerator@cD;
denr=SmartDenominator@cD;
b*SimplifyAntiderivative@u,xD + b*ArcTan@NormalizeLeadTermSigns@denr*Cos@uD*Sin@uDHnumr+denr*Sin@uD^2LDDDDDDDD
è Basis: ArcTan[I a+I b Cot[f[x]]]==I ArcTanh[a+b Cot[f[x]]]
è Basis: D[ArcTanh[c/e + (d/e)*Cot[f[x]]], x] == D[Log[(c + e)^2 + d^2 - ((c + e)^2 - d^2)*Cos[2*f[x]] + 2*(c + e)*d*Sin[2*f[x]]]/4 - Log[(c - e)^2 + d^2 - ((c - e)^2 d^2)*Cos[2*f[x]] + 2*(c - e)*d*Sin[2*f[x]]]/4, x]
116 | Integration utility functions.m
è Basis: D[ArcTanh[c/e + (d/e)*Cot[f[x]]], x] == D[Log[(c + e)^2 - ((c + e)^2 - d^2)*Cos[f[x]]^2 + 2*(c + e)*d*Cos[f[x]]*Sin[f[x]]]/4 - Log[(c - e)^2 - ((c - e)^2 d^2)*Cos[f[x]]^2 + 2*(c - e)*d*Cos[f[x]]*Sin[f[x]]]/4, x]
è Basis: D[ArcTan[a + b*Cot[f[x]]], x] == D[-f[x] - ArcTan[(2*a*b*Cos[2*f[x]] + (1 + a^2 - b^2)*Sin[2*f[x]])/(a^2 + (1 + b)^2 - (1 + a^2 - b^2)*Cos[2*f[x]] +
2*a*b*Sin[2*f[x]])], x]
è Basis: D[ArcTan[a + b*Cot[f[x]]], x] == D[-f[x] - ArcTan[(a*b - 2*a*b*Sin[f[x]]^2 + (1 + a^2 - b^2)*Cos[f[x]]*Sin[f[x]])/(b*(1 + b) + (1 + a^2 - b^2)*Sin[f[x]]^2 +
2*a*b*Cos[f[x]]*Sin[f[x]])], x]
H* RectifyCotangent@u,a,b,r,xD returns an expression whose derivative equals the derivative of r*ArcTan@a+b*Cot@uDD wrt x. *L
RectifyCotangent@u_,a_,b_,r_,x_SymbolD :=
If@MatchQ@Together@aD,d_.*Complex@0,c_DD && MatchQ@Together@bD,d_.*Complex@0,c_DD,
Module@8c=aI,d=bI,e<,
If@NegativeQ@dD,
RectifyTangent@u,-a,-b,-r,xD,
e=SmartDenominator@Together@c+d*xDD;
c=c*e;
d=d*e;
If@EvenQ@Denominator@NumericFactor@Together@uDDDD,
I*r*Log@RemoveContent@Simplify@Hc+eL^2+d^2D-Simplify@Hc+eL^2-d^2D*Cos@2*uD+Simplify@2*Hc+eL*dD*Sin@2*uD,xDD4 I*r*Log@RemoveContent@Simplify@Hc-eL^2+d^2D-Simplify@Hc-eL^2-d^2D*Cos@2*uD+Simplify@2*Hc-eL*dD*Sin@2*uD,xDD4,
I*r*Log@RemoveContent@Simplify@Hc+eL^2D-Simplify@Hc+eL^2-d^2D*Cos@uD^2+Simplify@2*Hc+eL*dD*Cos@uD*Sin@uD,xDD4 I*r*Log@RemoveContent@Simplify@Hc-eL^2D-Simplify@Hc-eL^2-d^2D*Cos@uD^2+Simplify@2*Hc-eL*dD*Cos@uD*Sin@uD,xDD4DDD,
If@NegativeQ@bD,
RectifyCotangent@u,-a,-b,-r,xD,
If@EvenQ@Denominator@NumericFactor@Together@uDDDD,
-r*SimplifyAntiderivative@u,xD r*ArcTan@Simplify@H2*a*b*Cos@2*uD+H1+a^2-b^2L*Sin@2*uDLHa^2+H1+bL^2-H1+a^2-b^2L*Cos@2*uD+2*a*b*Sin@2*uDLDD,
-r*SimplifyAntiderivative@u,xD r*ArcTan@ActivateTrig@Simplify@Ha*b-2*a*b*sin@uD^2+H1+a^2-b^2L*cos@uD*sin@uDLHb*H1+bL+H1+a^2-b^2L*sin@uD^2+2*a*b*cos@uD*sin@uD
è Basis: D[ArcTanh[a + b*Coth[f[x]]], x] == D[f[x] - ArcTanh[(2*a*b*Cosh[2*f[x]] - (1 - a^2 - b^2)*Sinh[2*f[x]])/(-a^2 + (1 + b)^2 - (1 - a^2 - b^2)*Cosh[2*f[x]] +
2*a*b*Sinh[2*f[x]])], x]
è Basis: D[ArcTanh[a + b*Coth[f[x]]], x] == D[f[x] - ArcTanh[(a*b + 2*a*b*Sinh[f[x]]^2 - (1 - a^2 - b^2)*Cosh[f[x]]*Sinh[f[x]])/(b*(1 + b) - (1 - a^2 b^2)*Sinh[f[x]]^2 + 2*a*b*Cosh[f[x]]*Sinh[f[x]])], x]
H* SimplifyAntiderivative@ArcTanh@c_.*Ha_+b_.*Coth@u_DLD,x_SymbolD :=
If@EvenQ@Denominator@NumericFactor@Together@uDDDD,
SimplifyAntiderivative@u,xD ArcTanh@NormalizeTogether@H2*a*b*c^2*Cosh@2*uD-H1-a^2*c^2-b^2*c^2L*Sinh@2*uDLH-a^2*c^2+H1+b*cL^2-H1-a^2*c^2-b^2*c^2L*Cosh@2*
SimplifyAntiderivative@u,xD ArcTanh@NormalizeTogether@Ha*b*c^2+2*a*b*c^2*Sinh@uD^2-H1-a^2*c^2-b^2*c^2L*Cosh@uD*Sinh@uDLHb*c*H1+b*cL-H1-a^2*c^2-b^2*c^2L*Sinh
FreeQ@8a,b,c<,xD *L
D
Integration utility functions.m | 117
SmartNumerator@u_^n_D := SmartDenominator@u^H-nLD ; RationalQ@nD && n<0
SmartNumerator@u_*v_D := SmartNumerator@uD*SmartNumerator@vD
SmartNumerator@u_D := Numerator@uD
SmartDenominator@u_^n_D := SmartNumerator@u^H-nLD ; RationalQ@nD && n<0
SmartDenominator@u_*v_D := SmartDenominator@uD*SmartDenominator@vD
SmartDenominator@u_D := Denominator@uD
SubstFor
H* u is a function of v. SubstFor@w,v,u,xD returns w times u with v replaced by x. *L
SubstFor@w_,v_,u_,x_D :=
SimplifyIntegrand@w*SubstFor@v,u,xD,xD
118 | Integration utility functions.m
H* u is a function of v. SubstFor@v,u,xD returns u with v replaced by x. *L
SubstFor@v_,u_,x_D :=
If@AtomQ@vD,
Subst@u,v,xD,
If@Not@InertTrigFreeQ@uDD,
SubstFor@v,ActivateTrig@uD,xD,
If@Not@EqQ@FreeFactors@v,xD,1DD,
SubstFor@NonfreeFactors@v,xD,u,xFreeFactors@v,xDD,
If@SinQ@vD,
SubstForTrig@u,x,Sqrt@1-x^2D,v@@1DD,xD,
If@CosQ@vD,
SubstForTrig@u,Sqrt@1-x^2D,x,v@@1DD,xD,
If@TanQ@vD,
SubstForTrig@u,xSqrt@1+x^2D,1Sqrt@1+x^2D,v@@1DD,xD,
If@CotQ@vD,
SubstForTrig@u,1Sqrt@1+x^2D,xSqrt@1+x^2D,v@@1DD,xD,
If@SecQ@vD,
SubstForTrig@u,1Sqrt@1-x^2D,1x,v@@1DD,xD,
If@CscQ@vD,
SubstForTrig@u,1x,1Sqrt@1-x^2D,v@@1DD,xD,
If@SinhQ@vD,
SubstForHyperbolic@u,x,Sqrt@1+x^2D,v@@1DD,xD,
If@CoshQ@vD,
SubstForHyperbolic@u,Sqrt@-1+x^2D,x,v@@1DD,xD,
If@TanhQ@vD,
SubstForHyperbolic@u,xSqrt@1-x^2D,1Sqrt@1-x^2D,v@@1DD,xD,
If@CothQ@vD,
SubstForHyperbolic@u,1Sqrt@-1+x^2D,xSqrt@-1+x^2D,v@@1DD,xD,
If@SechQ@vD,
SubstForHyperbolic@u,1Sqrt@-1+x^2D,1x,v@@1DD,xD,
If@CschQ@vD,
SubstForHyperbolic@u,1x,1Sqrt@1+x^2D,v@@1DD,xD,
SubstForAux@u,v,xDDDDDDDDDDDDDDDD
Integration utility functions.m | 119
H* u is a function of v. SubstForAux@u,v,xD returns u with v replaced by x. *L
SubstForAux@u_,v_,x_D :=
If@u===v,
x,
If@AtomQ@uD,
If@PowerQ@vD && FreeQ@v@@2DD,xD && ZeroQ@u-v@@1DDD,
x^Simplify@1v@@2DDD,
uD,
If@PowerQ@uD && FreeQ@u@@2DD,xD,
If@ZeroQ@u@@1DD-vD,
x^u@@2DD,
If@PowerQ@vD && FreeQ@v@@2DD,xD && ZeroQ@u@@1DD-v@@1DDD,
x^Simplify@u@@2DDv@@2DDD,
SubstForAux@u@@1DD,v,xD^u@@2DDDD,
If@ProductQ@uD && Not@EqQ@FreeFactors@u,xD,1DD,
FreeFactors@u,xD*SubstForAux@NonfreeFactors@u,xD,v,xD,
If@ProductQ@uD && ProductQ@vD,
SubstForAux@First@uD,First@vD,xD,
Map@Function@SubstForAux@ð,v,xDD,uDDDDDD
H* u HvL is an expression of the form f HSin@vD,Cos@vD,Tan@vD,Cot@vD,Sec@vD,Csc@vDL. *L
H* SubstForTrig@u,sin,cos,v,xD returns the expression f Hsin,cos,sincos,cossin,1cos,1sinL. *L
SubstForTrig@u_,sin_,cos_,v_,x_D :=
If@AtomQ@uD,
u,
If@TrigQ@uD && IntegerQuotientQ@u@@1DD,vD,
If@u@@1DD===v ÈÈ ZeroQ@u@@1DD-vD,
If@SinQ@uD,
sin,
If@CosQ@uD,
cos,
If@TanQ@uD,
sincos,
If@CotQ@uD,
cossin,
If@SecQ@uD,
1cos,
1sinDDDDD,
Map@Function@SubstForTrig@ð,sin,cos,v,xDD,
ReplaceAll@TrigExpand@Head@uD@Simplify@u@@1DDvD*xDD,x->vDDD,
If@ProductQ@uD && CosQ@u@@1DDD && SinQ@u@@2DDD && ZeroQ@u@@1,1DD-v2D && ZeroQ@u@@2,1DD-v2D,
sin2*SubstForTrig@Drop@u,2D,sin,cos,v,xD,
Map@Function@SubstForTrig@ð,sin,cos,v,xDD,uDDDD
120 | Integration utility functions.m
H* u HvL is an expression of the form f HSinh@vD,Cosh@vD,Tanh@vD,Coth@vD,Sech@vD,Csch@vDL. *L
H* SubstForHyperbolic@u,sinh,cosh,v,xD returns the expression
f Hsinh,cosh,sinhcosh,coshsinh,1cosh,1sinhL. *L
SubstForHyperbolic@u_,sinh_,cosh_,v_,x_D :=
If@AtomQ@uD,
u,
If@HyperbolicQ@uD && IntegerQuotientQ@u@@1DD,vD,
If@u@@1DD===v ÈÈ ZeroQ@u@@1DD-vD,
If@SinhQ@uD,
sinh,
If@CoshQ@uD,
cosh,
If@TanhQ@uD,
sinhcosh,
If@CothQ@uD,
coshsinh,
If@SechQ@uD,
1cosh,
1sinhDDDDD,
Map@Function@SubstForHyperbolic@ð,sinh,cosh,v,xDD,
ReplaceAll@TrigExpand@Head@uD@Simplify@u@@1DDvD*xDD,x->vDDD,
If@ProductQ@uD && CoshQ@u@@1DDD && SinhQ@u@@2DDD && ZeroQ@u@@1,1DD-v2D && ZeroQ@u@@2,1DD-v2D,
sinh2*SubstForHyperbolic@Drop@u,2D,sinh,cosh,v,xD,
Map@Function@SubstForHyperbolic@ð,sinh,cosh,v,xDD,uDDDD
SubstForFractionalPowerOfLinear
H* If u has a subexpression of the form Ha+b*xL^HmnL where m and n>1 are integers,
SubstForFractionalPowerOfLinear@u,xD returns the list 8v,n,a+b*x,1b< where v is u
with subexpressions of the form Ha+b*xL^HmnL replaced by x^m and x replaced
by -ab+x^nb, and all times x^Hn-1L; else it returns False. *L
SubstForFractionalPowerOfLinear@u_,x_SymbolD :=
With@8lst=FractionalPowerOfLinear@u,1,False,xD<,
If@AtomQ@lstD ÈÈ FalseQ@lst@@2DDD,
False,
With@8n=lst@@1DD, a=Coefficient@lst@@2DD,x,0D, b=Coefficient@lst@@2DD,x,1D<,
With@8tmp=Simplify@x^Hn-1L*SubstForFractionalPower@u,lst@@2DD,n,-ab+x^nb,xDD<,
8NonfreeFactors@tmp,xD,n,lst@@2DD,FreeFactors@tmp,xDb<DDDD
Integration utility functions.m | 121
H* If u has a subexpression of the form Ha+b*xL^HmnL,
FractionalPowerOfLinear@u,1,False,xD returns 8n,a+b*x<; else it returns False. *L
FractionalPowerOfLinear@u_,n_,v_,x_D :=
If@AtomQ@uD ÈÈ FreeQ@u,xD,
8n,v<,
If@CalculusQ@uD,
False,
If@FractionalPowerQ@uD && LinearQ@u@@1DD,xD && HFalseQ@vD ÈÈ ZeroQ@u@@1DD-vDL,
8LCM@Denominator@u@@2DDD,nD,u@@1DD<,
Catch@Module@8lst=8n,v<<,
Scan@Function@If@AtomQ@lst=FractionalPowerOfLinear@ð,lst@@1DD,lst@@2DD,xDD,Throw@FalseDDD,uD;
lstDDDDD
InverseFunctionOfLinear
H* If u has a subexpression of the form g@a+b*xD where g is an inverse function,
InverseFunctionOfLinear@u,xD returns g@a+b*xD; else it returns False. *L
InverseFunctionOfLinear@u_,x_SymbolD :=
If@AtomQ@uD ÈÈ CalculusQ@uD ÈÈ FreeQ@u,xD,
False,
If@InverseFunctionQ@uD && LinearQ@u@@1DD,xD,
u,
Module@8tmp<,
Catch@
Scan@Function@If@Not@AtomQ@tmp=InverseFunctionOfLinear@ð,xDDD,Throw@tmpDDD,uD;
FalseDDDD
TryPureTanSubst
TryPureTanSubst@u_,x_SymbolD :=
H* Not@MatchQ@u,Log@v_DDD &&
Not@MatchQ@u,f_@v_D^2 ; LinearQ@v,xDDD &&
Not@MatchQ@u,ArcTan@a_.*Tan@v_DD ; FreeQ@a,xDDD &&
Not@MatchQ@u,ArcTan@a_.*Cot@v_DD ; FreeQ@a,xDDD &&
Not@MatchQ@u,ArcCot@a_.*Tan@v_DD ; FreeQ@a,xDDD &&
Not@MatchQ@u,ArcCot@a_.*Cot@v_DD ; FreeQ@a,xDDD &&
u===ExpandIntegrand@u,xD *L
Not@MatchQ@u,F_@c_.*Ha_.+b_.*G_@v_DLD ; FreeQ@8a,b,c<,xD && MemberQ@8ArcTan,ArcCot,ArcTanh,ArcCoth<,FD && MemberQ@8Tan,Cot,Tanh
122 | Integration utility functions.m
TryPureTanhSubst
TryTanhSubst@u_,x_SymbolD :=
FalseQ@FunctionOfLinear@u,xDD &&
Not@MatchQ@u,r_.*Hs_+t_L^n_. ; IntegerQ@nD && n>0DD &&
H*Not@MatchQ@u,Log@f_@xD^2D ; SinhCoshQ@fDDD && *L
Not@MatchQ@u,Log@v_DDD &&
NotAMatchQAu,1Ha_+b_.*f_@xD^n_L ; SinhCoshQ@fD && IntegerQ@nD && n>2EE &&
Not@MatchQ@u,f_@m_.*xD*g_@n_.*xD ; IntegersQ@m,nD && SinhCoshQ@fD && SinhCoshQ@gDDD &&
Not@MatchQ@u,r_.*Ha_.*s_^m_L^p_ ; FreeQ@8a,m,p<,xD && Not@m===2 && Hs===Sech@xD ÈÈ s===Csch@xDLDDD &&
u===ExpandIntegrand@u,xD
TryPureTanhSubst@u_,x_SymbolD :=
Not@MatchQ@u,Log@v_DDD &&
Not@MatchQ@u,ArcTanh@a_.*Tanh@v_DD
Not@MatchQ@u,ArcTanh@a_.*Coth@v_DD
Not@MatchQ@u,ArcCoth@a_.*Tanh@v_DD
Not@MatchQ@u,ArcCoth@a_.*Coth@v_DD
u===ExpandIntegrand@u,xD
;
;
;
;
FreeQ@a,xDDD
FreeQ@a,xDDD
FreeQ@a,xDDD
FreeQ@a,xDDD
&&
&&
&&
&&
Inert trig functions
InertTrigQ
InertTrigQ@f_D := MemberQ@8sin,cos,tan,cot,sec,csc<,fD
InertTrigQ@f_,g_D :=
If@f===g,
InertTrigQ@fD,
InertReciprocalQ@f,gD ÈÈ InertReciprocalQ@g,fDD
InertTrigQ@f_,g_,h_D := InertTrigQ@f,gD && InertTrigQ@g,hD
InertReciprocalQ@f_,g_D := f===sin && g===csc ÈÈ f===cos && g===sec ÈÈ f===tan && g===cot
InertTrigFreeQ@u_D := FreeQ@u,sinD && FreeQ@u,cosD && FreeQ@u,tanD && FreeQ@u,cotD && FreeQ@u,secD && FreeQ@u,cscD
ActivateTrig
ActivateTrig@u_D :=
ReplaceAll@u,8sin->Sin,cos->Cos,tan->Tan,cot->Cot,sec->Sec,csc->Csc<D
Integration utility functions.m | 123
DeactivateTrig
H* u is a function of trig functions of a linear function of x. *L
H* DeactivateTrig@u,xD returns u with the trig functions replaced with inert trig functions. *L
DeactivateTrig@u_,x_D :=
FixInertTrigFunction@DeactivateTrigAux@u,xD,xD
DeactivateTrigAux@u_,x_D :=
If@AtomQ@uD,
u,
If@TrigQ@uD && LinearQ@u@@1DD,xD,
With@8v=ExpandToSum@u@@1DD,xD<,
If@SinQ@uD,
sin@vD,
If@CosQ@uD,
cos@vD,
If@TanQ@uD,
tan@vD,
If@CotQ@uD,
cot@vD,
If@SecQ@uD,
sec@vD,
csc@vDDDDDDD,
If@HyperbolicQ@uD && LinearQ@u@@1DD,xD,
With@8v=ExpandToSum@I*u@@1DD,xD<,
If@SinhQ@uD,
-I*sin@vD,
If@CoshQ@uD,
cos@vD,
If@TanhQ@uD,
-I*tan@vD,
If@CothQ@uD,
I*cot@vD,
If@SechQ@uD,
sec@vD,
I*csc@vDDDDDDD,
Map@Function@DeactivateTrigAux@ð,xDD,uDDDD
124 | Integration utility functions.m
FixInertTrigFunction
Clear@FixInertTrigFunctionD
FixInertTrigFunction@a_*u_,x_D :=
a*FixInertTrigFunction@u,xD ;
FreeQ@a,xD
FixInertTrigFunction@u_.*Ha_*Hb_+v_LL^n_,x_D :=
FixInertTrigFunction@u*Ha*b+a*vL^n,xD ;
FreeQ@8a,b,n<,xD && Not@FreeQ@v,xDD
FixInertTrigFunction@csc@v_D^m_.*Hc_.*sin@w_DL^n_.,x_D :=
sin@vD^H-mL*Hc*sin@wDL^n ;
FreeQ@8c,n<,xD && IntegerQ@mD
FixInertTrigFunction@sec@v_D^m_.*Hc_.*cos@w_DL^n_.,x_D :=
cos@vD^H-mL*Hc*cos@wDL^n ;
FreeQ@8c,n<,xD && IntegerQ@mD
FixInertTrigFunction@cot@v_D^m_.*Hc_.*tan@w_DL^n_.,x_D :=
tan@vD^H-mL*Hc*tan@wDL^n ;
FreeQ@8c,n<,xD && IntegerQ@mD
FixInertTrigFunction@tan@v_D^m_.*Hc_.*cot@w_DL^n_.,x_D :=
cot@vD^H-mL*Hc*cot@wDL^n ;
FreeQ@8c,n<,xD && IntegerQ@mD
FixInertTrigFunction@cos@v_D^m_.*Hc_.*sec@w_DL^n_.,x_D :=
sec@vD^H-mL*Hc*sec@wDL^n ;
FreeQ@8c,n<,xD && IntegerQ@mD
FixInertTrigFunction@sin@v_D^m_.*Hc_.*csc@w_DL^n_.,x_D :=
csc@vD^H-mL*Hc*csc@wDL^n ;
FreeQ@8c,n<,xD && IntegerQ@mD
Integration utility functions.m | 125
FixInertTrigFunction@sec@v_D^m_.*Hc_.*sin@w_DL^n_.,x_D :=
cos@vD^H-mL*Hc*sin@wDL^n ;
FreeQ@8c,n<,xD && IntegerQ@mD
FixInertTrigFunction@csc@v_D^m_.*Hc_.*cos@w_DL^n_.,x_D :=
sin@vD^H-mL*Hc*cos@wDL^n ;
FreeQ@8c,n<,xD && IntegerQ@mD
FixInertTrigFunction@cos@v_D^m_.*Hc_.*tan@w_DL^n_.,x_D :=
sec@vD^H-mL*Hc*tan@wDL^n ;
FreeQ@8c,n<,xD && IntegerQ@mD
FixInertTrigFunction@sin@v_D^m_.*Hc_.*cot@w_DL^n_.,x_D :=
csc@vD^H-mL*Hc*cot@wDL^n ;
FreeQ@8c,n<,xD && IntegerQ@mD
FixInertTrigFunction@sin@v_D^m_.*Hc_.*sec@w_DL^n_.,x_D :=
csc@vD^H-mL*Hc*sec@wDL^n ;
FreeQ@8c,n<,xD && IntegerQ@mD
FixInertTrigFunction@cos@v_D^m_.*Hc_.*csc@w_DL^n_.,x_D :=
sec@vD^H-mL*Hc*csc@wDL^n ;
FreeQ@8c,n<,xD && IntegerQ@mD
126 | Integration utility functions.m
FixInertTrigFunction@cot@v_D^m_.*Hc_.*sin@w_DL^n_.,x_D :=
tan@vD^H-mL*Hc*sin@wDL^n ;
FreeQ@8c,n<,xD && IntegerQ@mD
FixInertTrigFunction@tan@v_D^m_.*Hc_.*cos@w_DL^n_.,x_D :=
cot@vD^H-mL*Hc*cos@wDL^n ;
FreeQ@8c,n<,xD && IntegerQ@mD
FixInertTrigFunction@csc@v_D^m_.*Hc_.*tan@w_DL^n_.,x_D :=
sin@vD^H-mL*Hc*tan@wDL^n ;
FreeQ@8c,n<,xD && IntegerQ@mD
FixInertTrigFunction@sec@v_D^m_.*Hc_.*cot@w_DL^n_.,x_D :=
cos@vD^H-mL*Hc*cot@wDL^n ;
FreeQ@8c,n<,xD && IntegerQ@mD
FixInertTrigFunction@cot@v_D^m_.*Hc_.*sec@w_DL^n_.,x_D :=
tan@vD^H-mL*Hc*sec@wDL^n ;
FreeQ@8c,n<,xD && IntegerQ@mD
FixInertTrigFunction@tan@v_D^m_.*Hc_.*csc@w_DL^n_.,x_D :=
cot@vD^H-mL*Hc*csc@wDL^n ;
FreeQ@8c,n<,xD && IntegerQ@mD
FixInertTrigFunction@sec@v_D^m_.*sec@w_D^n_.,x_D :=
cos@vD^H-mL*cos@wD^H-nL ;
IntegersQ@m,nD
FixInertTrigFunction@csc@v_D^m_.*csc@w_D^n_.,x_D :=
sin@vD^H-mL*sin@wD^H-nL ;
IntegersQ@m,nD
Integration utility functions.m | 127
FixInertTrigFunction@u_.*Hc_.*sin@v_D^n_.L^p_.*w_,x_D :=
Hc*sin@vD^nL^p*FixInertTrigFunction@u*w,xD ;
FreeQ@8c,p<,xD && PowerOfInertTrigSumQ@w,sin,xD
FixInertTrigFunction@u_.*Hc_.*cos@v_D^n_.L^p_.*w_,x_D :=
Hc*cos@vD^nL^p*FixInertTrigFunction@u*w,xD ;
FreeQ@8c,p<,xD && PowerOfInertTrigSumQ@w,cos,xD
FixInertTrigFunction@u_.*Hc_.*tan@v_D^n_.L^p_.*w_,x_D :=
Hc*tan@vD^nL^p*FixInertTrigFunction@u*w,xD ;
FreeQ@8c,p<,xD && PowerOfInertTrigSumQ@w,tan,xD
FixInertTrigFunction@u_.*Hc_.*cot@v_D^n_.L^p_.*w_,x_D :=
Hc*cot@vD^nL^p*FixInertTrigFunction@u*w,xD ;
FreeQ@8c,p<,xD && PowerOfInertTrigSumQ@w,cot,xD
FixInertTrigFunction@u_.*Hc_.*sec@v_D^n_.L^p_.*w_,x_D :=
Hc*sec@vD^nL^p*FixInertTrigFunction@u*w,xD ;
FreeQ@8c,p<,xD && PowerOfInertTrigSumQ@w,sec,xD
FixInertTrigFunction@u_.*Hc_.*csc@v_D^n_.L^p_.*w_,x_D :=
Hc*csc@vD^nL^p*FixInertTrigFunction@u*w,xD ;
FreeQ@8c,p<,xD && PowerOfInertTrigSumQ@w,csc,xD
FixInertTrigFunction@cot@v_D^m_.*Ha_+b_.*Hc_.*sin@w_DL^p_L^n_.,x_D :=
tan@vD^H-mL*Ha+b*Hc*sin@wDL^pL^n ;
FreeQ@8a,b,c,n,p<,xD && IntegerQ@mD
FixInertTrigFunction@u_.*tan@v_D^m_.*Ha_+b_.*sin@w_DL^n_.,x_D :=
sin@vD^mcos@vD^m*FixInertTrigFunction@u*Ha+b*sin@wDL^n,xD ;
FreeQ@8a,b,n<,xD && IntegerQ@mD
FixInertTrigFunction@u_.*cot@v_D^m_.*Ha_+b_.*sin@w_DL^n_.,x_D :=
cos@vD^msin@vD^m*FixInertTrigFunction@u*Ha+b*sin@wDL^n,xD ;
FreeQ@8a,b,n<,xD && IntegerQ@mD
FixInertTrigFunction@u_.*Hc_.*sec@v_D^n_.L^p_.*w_,x_D :=
Hc*cos@vD^H-nLL^p*FixInertTrigFunction@u*w,xD ;
FreeQ@8c,p<,xD && PowerOfInertTrigSumQ@w,sin,xD && IntegerQ@nD && IntegerQ@pD
FixInertTrigFunction@u_.*Hc_.*csc@v_D^n_.L^p_.*w_,x_D :=
Hc*sin@vD^H-nLL^p*FixInertTrigFunction@u*w,xD ;
FreeQ@8c,p<,xD && PowerOfInertTrigSumQ@w,sin,xD && IntegerQ@nD && IntegerQ@pD
128 | Integration utility functions.m
FixInertTrigFunction@tan@v_D^m_.*Ha_+b_.*Hc_.*cos@w_DL^p_L^n_.,x_D :=
cot@vD^H-mL*Ha+b*Hc*cos@wDL^pL^n ;
FreeQ@8a,b,c,n,p<,xD && IntegerQ@mD
FixInertTrigFunction@u_.*tan@v_D^m_.*Ha_+b_.*cos@w_DL^n_.,x_D :=
sin@vD^mcos@vD^m*FixInertTrigFunction@u*Ha+b*cos@wDL^n,xD ;
FreeQ@8a,b,n<,xD && IntegerQ@mD
FixInertTrigFunction@u_.*cot@v_D^m_.*Ha_+b_.*cos@w_DL^n_.,x_D :=
cos@vD^msin@vD^m*FixInertTrigFunction@u*Ha+b*cos@wDL^n,xD ;
FreeQ@8a,b,n<,xD && IntegerQ@mD
FixInertTrigFunction@u_.*Hc_.*csc@v_D^n_.L^p_.*w_,x_D :=
Hc*sin@vD^H-nLL^p*FixInertTrigFunction@u*w,xD ;
FreeQ@8c,p<,xD && PowerOfInertTrigSumQ@w,cos,xD && IntegerQ@nD
FixInertTrigFunction@u_.*Hc_.*sec@v_D^n_.L^p_.*w_,x_D :=
Hc*cos@vD^H-nLL^p*FixInertTrigFunction@u*w,xD ;
FreeQ@8c,p<,xD && PowerOfInertTrigSumQ@w,cos,xD && IntegerQ@nD
FixInertTrigFunction@u_.*Hc_.*cot@v_D^n_.L^p_.*w_,x_D :=
Hc*tan@vD^H-nLL^p*FixInertTrigFunction@u*w,xD ;
FreeQ@8c,p<,xD && PowerOfInertTrigSumQ@w,tan,xD && IntegerQ@nD
FixInertTrigFunction@u_.*cos@v_D^n_.*w_,x_D :=
sec@vD^H-nL*FixInertTrigFunction@u*w,xD ;
PowerOfInertTrigSumQ@w,tan,xD && IntegerQ@nD
FixInertTrigFunction@u_.*Hc_.*cos@v_D^n_L^p_.*w_,x_D :=
Hc*sec@vD^H-nLL^p*FixInertTrigFunction@u*w,xD ;
FreeQ@8c,p<,xD && PowerOfInertTrigSumQ@w,tan,xD && IntegerQ@nD
FixInertTrigFunction@u_.*Hc_.*csc@v_D^n_.L^p_.*w_,x_D :=
Hc*sin@vD^H-nLL^p*FixInertTrigFunction@u*w,xD ;
FreeQ@8c,p<,xD && PowerOfInertTrigSumQ@w,tan,xD && IntegerQ@nD
Integration utility functions.m | 129
FixInertTrigFunction@u_.*Hc_.*tan@v_D^n_.L^p_.*w_,x_D :=
Hc*cot@vD^H-nLL^p*FixInertTrigFunction@u*w,xD ;
FreeQ@8c,p<,xD && PowerOfInertTrigSumQ@w,cot,xD && IntegerQ@nD
FixInertTrigFunction@u_.*sin@v_D^n_.*w_,x_D :=
csc@vD^H-nL*FixInertTrigFunction@u*w,xD ;
PowerOfInertTrigSumQ@w,cot,xD && IntegerQ@nD
FixInertTrigFunction@u_.*Hc_.*sin@v_D^n_L^p_.*w_,x_D :=
Hc*csc@vD^H-nLL^p*FixInertTrigFunction@u*w,xD ;
FreeQ@8c,p<,xD && PowerOfInertTrigSumQ@w,cot,xD && IntegerQ@nD
FixInertTrigFunction@u_.*Hc_.*sec@v_D^n_.L^p_.*w_,x_D :=
Hc*cos@vD^H-nLL^p*FixInertTrigFunction@u*w,xD ;
FreeQ@8c,p<,xD && PowerOfInertTrigSumQ@w,cot,xD && IntegerQ@nD
FixInertTrigFunction@u_.*Hc_.*cos@v_D^n_.L^p_.*w_,x_D :=
Hc*sec@vD^H-nLL^p*FixInertTrigFunction@u*w,xD ;
FreeQ@8c,p<,xD && PowerOfInertTrigSumQ@w,sec,xD && IntegerQ@nD
FixInertTrigFunction@u_.*Hc_.*cot@v_D^n_.L^p_.*w_,x_D :=
Hc*tan@vD^H-nLL^p*FixInertTrigFunction@u*w,xD ;
FreeQ@8c,p<,xD && PowerOfInertTrigSumQ@w,sec,xD && IntegerQ@nD
FixInertTrigFunction@u_.*Hc_.*csc@v_D^n_.L^p_.*w_,x_D :=
Hc*sin@vD^H-nLL^p*FixInertTrigFunction@u*w,xD ;
FreeQ@8c,p<,xD && PowerOfInertTrigSumQ@w,sec,xD && IntegerQ@nD
FixInertTrigFunction@u_.*Hc_.*sin@v_D^n_.L^p_.*w_,x_D :=
Hc*csc@vD^H-nLL^p*FixInertTrigFunction@u*w,xD ;
FreeQ@8c,p<,xD && PowerOfInertTrigSumQ@w,csc,xD && IntegerQ@nD
FixInertTrigFunction@u_.*Hc_.*tan@v_D^n_.L^p_.*w_,x_D :=
Hc*cot@vD^H-nLL^p*FixInertTrigFunction@u*w,xD ;
FreeQ@8c,p<,xD && PowerOfInertTrigSumQ@w,csc,xD && IntegerQ@nD
FixInertTrigFunction@u_.*Hc_.*sec@v_D^n_.L^p_.*w_,x_D :=
Hc*cos@vD^H-nLL^p*FixInertTrigFunction@u*w,xD ;
FreeQ@8c,p<,xD && PowerOfInertTrigSumQ@w,csc,xD && IntegerQ@nD
130 | Integration utility functions.m
FixInertTrigFunction@u_.*tan@v_D^m_.*Ha_.*sin@v_D+b_.*cos@v_DL^n_.,x_D :=
sin@vD^m*cos@vD^H-mL*FixInertTrigFunction@u*Ha*sin@vD+b*cos@vDL^n,xD ;
FreeQ@8a,b,n<,xD && IntegerQ@mD
FixInertTrigFunction@u_.*cot@v_D^m_.*Ha_.*sin@v_D+b_.*cos@v_DL^n_.,x_D :=
cos@vD^m*sin@vD^H-mL*FixInertTrigFunction@u*Ha*sin@vD+b*cos@vDL^n,xD ;
FreeQ@8a,b,n<,xD && IntegerQ@mD
FixInertTrigFunction@u_.*sec@v_D^m_.*Ha_.*sin@v_D+b_.*cos@v_DL^n_.,x_D :=
cos@vD^H-mL*FixInertTrigFunction@u*Ha*sin@vD+b*cos@vDL^n,xD ;
FreeQ@8a,b,n<,xD && IntegerQ@mD
FixInertTrigFunction@u_.*csc@v_D^m_.*Ha_.*sin@v_D+b_.*cos@v_DL^n_.,x_D :=
sin@vD^H-mL*FixInertTrigFunction@u*Ha*sin@vD+b*cos@vDL^n,xD ;
FreeQ@8a,b,n<,xD && IntegerQ@mD
FixInertTrigFunction@f_@v_D^m_.*HA_.+B_.*g_@v_D+C_.*g_@v_D^2L,x_D :=
g@vD^H-mL*HA+B*g@vD+C*g@vD^2L ;
FreeQ@8A,B,C<,xD && IntegerQ@mD && HInertReciprocalQ@f,gD ÈÈ InertReciprocalQ@g,fDL
FixInertTrigFunction@f_@v_D^m_.*HA_.+C_.*g_@v_D^2L,x_D :=
g@vD^H-mL*HA+C*g@vD^2L ;
FreeQ@8A,C<,xD && IntegerQ@mD && HInertReciprocalQ@f,gD ÈÈ InertReciprocalQ@g,fDL
FixInertTrigFunction@f_@v_D^m_.*HA_.+B_.*g_@v_D+C_.*g_@v_D^2L*Ha_.+b_.*g_@v_DL^n_.,x_D :=
g@vD^H-mL*HA+B*g@vD+C*g@vD^2L*Ha+b*g@vDL^n ;
FreeQ@8a,b,A,B,C,n<,xD && IntegerQ@mD && HInertReciprocalQ@f,gD ÈÈ InertReciprocalQ@g,fDL
FixInertTrigFunction@f_@v_D^m_.*HA_.+C_.*g_@v_D^2L*Ha_.+b_.*g_@v_DL^n_.,x_D :=
g@vD^H-mL*HA+C*g@vD^2L*Ha+b*g@vDL^n ;
FreeQ@8a,b,A,C,n<,xD && IntegerQ@mD && HInertReciprocalQ@f,gD ÈÈ InertReciprocalQ@g,fDL
FixInertTrigFunction@u_,x_D := u
PowerOfInertTrigSumQ@u_,func_,x_D :=
MatchQ@u, Ha_+b_.*Hc_.*func@w_DL^p_.L^n_. ; FreeQ@8a,b,c,n,p<,xDD ÈÈ
MatchQ@u, Ha_.+b_.*Hd_.*func@w_DL^p_.+c_.*Hd_.*func@w_DL^q_.L^n_. ; FreeQ@8a,b,c,d,n,p,q<,xDD
KnownTrigIntegrandQ
KnownSineIntegrandQ@u_,x_SymbolD :=
KnownTrigIntegrandQ@8sin,cos<,u,xD
KnownTangentIntegrandQ@u_,x_SymbolD :=
KnownTrigIntegrandQ@8tan<,u,xD
Integration utility functions.m | 131
KnownCotangentIntegrandQ@u_,x_SymbolD :=
KnownTrigIntegrandQ@8cot<,u,xD
KnownSecantIntegrandQ@u_,x_SymbolD :=
KnownTrigIntegrandQ@8sec,csc<,u,xD
KnownTrigIntegrandQ@list_,u_,x_SymbolD :=
u===1 ÈÈ
MatchQ@u,Ha_.+b_.*func_@e_.+f_.*xDL^m_. ; MemberQ@list,funcD && FreeQ@8a,b,e,f,m<,xDD ÈÈ
MatchQ@u,Ha_.+b_.*func_@e_.+f_.*xDL^m_.*HA_.+B_.*func_@e_.+f_.*xDL ; MemberQ@list,funcD && FreeQ@8a,b,e,f,A,B,m<,xDD ÈÈ
MatchQ@u,HA_.+C_.*func_@e_.+f_.*xD^2L ; MemberQ@list,funcD && FreeQ@8e,f,A,C<,xDD ÈÈ
MatchQ@u,HA_.+B_.*func_@e_.+f_.*xD+C_.*func_@e_.+f_.*xD^2L ; MemberQ@list,funcD && FreeQ@8e,f,A,B,C<,xDD ÈÈ
MatchQ@u,Ha_.+b_.*func_@e_.+f_.*xDL^m_.*HA_.+C_.*func_@e_.+f_.*xD^2L ; MemberQ@list,funcD && FreeQ@8a,b,e,f,A,C,m<,xDD ÈÈ
MatchQ@u,Ha_.+b_.*func_@e_.+f_.*xDL^m_.*HA_.+B_.*func_@e_.+f_.*xD+C_.*func_@e_.+f_.*xD^2L ; MemberQ@list,funcD && FreeQ@8a,b,e
Derivative divides function
H* If the derivative of u wrt x is a constant wrt x, PiecewiseLinearQ@u,xD returns True;
else it returns False. *L
PiecewiseLinearQ@u_,v_,x_SymbolD :=
PiecewiseLinearQ@u,xD && PiecewiseLinearQ@v,xD
PiecewiseLinearQ@u_,x_SymbolD :=
LinearQ@u,xD H* && Not@MonomialQ@u,xDD *L ÈÈ
MatchQ@u,Log@c_.*F_^Hv_LD ; FreeQ@8F,c<,xD && LinearQ@v,xDD ÈÈ
MatchQ@u,F_@G_@v_DD ; LinearQ@v,xD && MemberQ@8
8ArcTanh,Tanh<,8ArcTanh,Coth<,8ArcCoth,Coth<,8ArcCoth,Tanh<,
8ArcTan,Tan<,8ArcTan,Cot<,8ArcCot,Cot<,8ArcCot,Tan<
<,8F,G<DD
H* If u divided by y is free of x, Divides@y,u,xD returns the quotient; else it returns False. *L
Divides@y_,u_,x_SymbolD :=
With@8v=Simplify@uyD<,
If@FreeQ@v,xD,
v,
FalseDD
132 | Integration utility functions.m
H* If y not equal to x, y is easy to differentiate wrt x, and u divided by the derivative of y
is free of x, DerivativeDivides@y,u,xD returns the quotient; else it returns False. *L
DerivativeDivides@y_,u_,x_SymbolD :=
If@MatchQ@y,a_.*x ; FreeQ@a,xDD,
False,
If@If@PolynomialQ@y,xD, PolynomialQ@u,xD && Exponent@u,xD==Exponent@y,xD-1, EasyDQ@y,xDD,
Module@8v=Block@8ShowSteps=False<, D@y,xDD<,
If@ZeroQ@vD,
False,
v=Simplify@uvD;
If@FreeQ@v,xD,
v,
FalseDDD,
FalseDD
Integration utility functions.m | 133
H* If u is easy to differentiate wrt x, EasyDQ@u,xD returns True; else it returns False. *L
EasyDQ@u_.*x_^m_.,x_SymbolD :=
EasyDQ@u,xD ;
FreeQ@m,xD
EasyDQ@u_,x_SymbolD :=
If@AtomQ@uD ÈÈ FreeQ@u,xD ÈÈ Length@uD==0,
True,
If@CalculusQ@uD,
False,
If@Length@uD==1,
EasyDQ@u@@1DD,xD,
If@BinomialQ@u,xD ÈÈ ProductOfLinearPowersQ@u,xD,
True,
If@RationalFunctionQ@u,xD && RationalFunctionExponents@u,xD===81,1<,
True,
If@ProductQ@uD,
If@FreeQ@First@uD,xD,
EasyDQ@Rest@uD,xD,
If@FreeQ@Rest@uD,xD,
EasyDQ@First@uD,xD,
FalseDD,
If@SumQ@uD,
EasyDQ@First@uD,xD && EasyDQ@Rest@uD,xD,
If@Length@uD==2,
If@FreeQ@u@@1DD,xD,
EasyDQ@u@@2DD,xD,
If@FreeQ@u@@2DD,xD,
EasyDQ@u@@1DD,xD,
FalseDD,
FalseDDDDDDDD
H* ProductOfLinearPowersQ@u,xD returns True iff u is a product of factors of the form v^n where v is linear in x. *L
ProductOfLinearPowersQ@u_,x_SymbolD :=
FreeQ@u,xD ÈÈ
MatchQ@u, v_^n_. ; LinearQ@v,xD && FreeQ@n,xDD ÈÈ
ProductQ@uD && ProductOfLinearPowersQ@First@uD,xD && ProductOfLinearPowersQ@Rest@uD,xD
134 | Integration utility functions.m
Simplest nth root function
Rt[u,n]
H* Rt@u,nD returns the simplest nth root of u. *L
Rt@u_,n_IntegerD :=
RtAux@TogetherSimplify@uD,nD
NthRoot[u,n]
NthRoot@u_,n_D := u^H1nL
TrigSquare[u]
H* If u is an expression of the form a-a*Sin@zD^2 or a-a*Cos@zD^2, TrigSquare@uD returns Cos@zD^2 or Sin@zD^2 respectively, else
TrigSquare@u_D :=
If@SumQ@uD,
With@8lst=SplitSum@Function@SplitProduct@TrigSquareQ,ðDD,uD<,
If@Not@AtomQ@lstDD && ZeroQ@lst@@1,2DD+lst@@2DDD,
If@Head@lst@@1,1DD@@1DDD===Sin,
lst@@2DD*Cos@lst@@1,1DD@@1,1DDD^2,
lst@@2DD*Sin@lst@@1,1DD@@1,1DDD^2D,
FalseDD,
FalseD
Simplest nth root helper functions
RtAux[u,n]
RtAux@u_,n_D :=
If@PowerQ@uD,
u@@1DD^Hu@@2DDnL,
If@ProductQ@uD,
Module@8lst<,
lst=SplitProduct@PositiveQ,uD;
If@ListQ@lstD,
RtAux@lst@@1DD,nD*RtAux@lst@@2DD,nD,
lst=SplitProduct@NegativeQ,uD;
If@ListQ@lstD,
If@EqQ@lst@@1DD,-1D,
With@8v=lst@@2DD<,
If@PowerQ@vD && NegativeQ@v@@2DDD,
1RtAux@-v@@1DD^H-v@@2DDL,nD,
If@ProductQ@vD,
If@ListQ@SplitProduct@SumBaseQ,vDD,
Integration utility functions.m | 135
If@ListQ@SplitProduct@SumBaseQ,vDD,
lst=SplitProduct@AllNegTermQ,vD;
If@ListQ@lstD,
RtAux@-lst@@1DD,nD*RtAux@lst@@2DD,nD,
lst=SplitProduct@NegSumBaseQ,vD;
If@ListQ@lstD,
RtAux@-lst@@1DD,nD*RtAux@lst@@2DD,nD,
lst=SplitProduct@SomeNegTermQ,vD;
If@ListQ@lstD,
RtAux@-lst@@1DD,nD*RtAux@lst@@2DD,nD,
lst=SplitProduct@SumBaseQ,vD;
RtAux@-lst@@1DD,nD*RtAux@lst@@2DD,nDDDD,
lst=SplitProduct@AtomBaseQ,vD;
If@ListQ@lstD,
RtAux@-lst@@1DD,nD*RtAux@lst@@2DD,nD,
RtAux@-First@vD,nD*RtAux@Rest@vD,nDDD,
If@OddQ@nD,
-RtAux@v,nD,
NthRoot@u,nDDDDD,
RtAux@-lst@@1DD,nD*RtAux@-lst@@2DD,nDD,
lst=SplitProduct@AllNegTermQ,uD;
If@ListQ@lstD && ListQ@SplitProduct@SumBaseQ,lst@@2DDDD,
RtAux@-lst@@1DD,nD*RtAux@-lst@@2DD,nD,
lst=SplitProduct@NegSumBaseQ,uD;
If@ListQ@lstD && ListQ@SplitProduct@NegSumBaseQ,lst@@2DDDD,
RtAux@-lst@@1DD,nD*RtAux@-lst@@2DD,nD,
Map@Function@RtAux@ð,nDD,uDDDDDD,
With@8v=TrigSquare@uD<,
If@Not@AtomQ@vDD,
RtAux@v,nD,
If@OddQ@nD && NegativeQ@uD,
-RtAux@-u,nD,
If@ComplexNumberQ@uD,
With@8a=Re@uD,b=Im@uD<,
If@Not@IntegerQ@aD && IntegerQ@bDD && IntegerQ@aHa^2+b^2LD && IntegerQ@bHa^2+b^2LD,
H* Basis: a+b*I==1HaHa^2+b^2L-bHa^2+b^2L*IL *L
1RtAux@aHa^2+b^2L-bHa^2+b^2L*I,nD,
NthRoot@u,nDDD,
NthRoot@u,nDDDDDDD
Factor base predicates
H* If u is an atom or an atom raised to an odd degree, AtomBaseQ@uD returns True; else it returns False. *L
AtomBaseQ@u_D :=
AtomQ@uD ÈÈ PowerQ@uD && OddQ@u@@2DDD && AtomBaseQ@u@@1DDD
136 | Integration utility functions.m
H* If u is an sum or a sum raised to an odd degree, SumBaseQ@uD returns True; else it returns False. *L
SumBaseQ@u_D :=
SumQ@uD ÈÈ PowerQ@uD && OddQ@u@@2DDD && SumBaseQ@u@@1DDD
H* If u is a sum or a sum raised to an odd degree whose lead term has a negative form, NegSumBaseQ@uD returns True; else it returns
NegSumBaseQ@u_D :=
SumQ@uD && NegQ@First@uDD ÈÈ PowerQ@uD && OddQ@u@@2DDD && NegSumBaseQ@u@@1DDD
H* If all terms of u have a negative form, AllNegTermQ@uD returns True; else it returns False. *L
AllNegTermQ@u_D :=
If@PowerQ@uD && OddQ@u@@2DDD,
AllNegTermQ@u@@1DDD,
If@SumQ@uD,
NegQ@First@uDD && AllNegTermQ@Rest@uDD,
NegQ@uDDD
H* If some term of u has a negative form, SomeNegTermQ@uD returns True; else it returns False. *L
SomeNegTermQ@u_D :=
If@PowerQ@uD && OddQ@u@@2DDD,
SomeNegTermQ@u@@1DDD,
If@SumQ@uD,
NegQ@First@uDD ÈÈ SomeNegTermQ@Rest@uDD,
NegQ@uDDD
TrigSquareQ[u]
H* If u is an expression of the form Sin@zD^2 or Cos@zD^2, TrigSquareQ@uD returns True, else it returns False. *L
TrigSquareQ@u_D :=
PowerQ@uD && EqQ@u@@2DD,2D && MemberQ@8Sin,Cos<,Head@u@@1DDDD
SplitProduct[func,u]
H* If func@vD is True for a factor v of u, SplitProduct@func,uD returns 8v, uv< where v is the first such factor; else it returns
SplitProduct@func_,u_D :=
If@ProductQ@uD,
If@func@First@uDD,
8First@uD, Rest@uD<,
With@8lst=SplitProduct@func,Rest@uDD<,
If@AtomQ@lstD,
False,
8lst@@1DD,First@uD*lst@@2DD<DDD,
If@func@uD,
8u, 1<,
FalseDD
Integration utility functions.m | 137
SplitSum[func,u]
H* If func@vD is nonatomic for a term v of u, SplitSum@func,uD returns 8func@vD, u-v< where v is the first such term; else it returns
SplitSum@func_,u_D :=
If@SumQ@uD,
If@Not@AtomQ@func@First@uDDDD,
8func@First@uDD, Rest@uD<,
With@8lst=SplitSum@func,Rest@uDD<,
If@AtomQ@lstD,
False,
8lst@@1DD,First@uD+lst@@2DD<DDD,
If@Not@AtomQ@func@uDDD,
8func@uD, 0<,
FalseDD
IntSum
H* If u is free of x or of the form c*Ha+b*xL^m, IntSum@u,xD returns the antiderivative of u wrt x;
else it returns d*Int@v,xD where d*v=u and d is free of x. *L
IntSum@u_,x_SymbolD :=
Simp@FreeTerms@u,xD*x,xD + IntTerm@NonfreeTerms@u,xD,xD
H* If u is of the form c*Ha+b*xL^m, IntTerm@u,xD returns the antiderivative of u wrt x;
else it returns d*Int@v,xD where d*v=u and d is free of x. *L
IntTermAc_.v_,x_SymbolE :=
Simp@c*Log@RemoveContent@v,xDDCoefficient@v,x,1D,xD ;
FreeQ@c,xD && LinearQ@v,xD
IntTerm@c_.*v_^m_.,x_SymbolD :=
Simp@c*v^Hm+1LHCoefficient@v,x,1D*Hm+1LL,xD ;
FreeQ@8c,m<,xD && NonzeroQ@m+1D && LinearQ@v,xD
IntTerm@u_,x_SymbolD :=
Map@Function@IntTerm@ð,xDD,uD ;
SumQ@uD
IntTerm@u_,x_SymbolD :=
Dist@FreeFactors@u,xD, Int@NonfreeFactors@u,xD,xD, xD
138 | Integration utility functions.m
Fix integration rules functions
RuleName[name]
$RuleNameList=8<;
RuleName@name_D :=
HAppendTo@$RuleNameList,nameD; NullL
FixIntRules[rulelist]
ClearAll@FixIntRules,FixIntRule,FixRhsIntRuleD
FixIntRules@D :=
HDownValues@IntD=FixIntRules@DownValues@IntDD; NullL
FixIntRules@rulelist_D :=
Module@8IntDownValues=DownValues@IntD,SubstDownValues=DownValues@SubstD,
SimpDownValues=DownValues@SimpD,DistDownValues=DownValues@DistD,lst,object<,
object=PrintTemporary@Row@8"Modifying ",Length@rulelistD," integration rules to distribute coefficients over sums..."<DD;
Clear@Int,Subst,Simp,DistD;
SetAttributes@8Simp,Dist,Int,Subst<,HoldAllD;
lst=Map@Function@FixIntRule@ð,ð@@1,1,2,1DDDD,rulelistD;
DownValues@IntD=IntDownValues;
DownValues@SubstD=SubstDownValues;
DownValues@SimpD=SimpDownValues;
DownValues@DistD=DistDownValues;
ClearAttributes@8Simp,Dist,Int,Subst<,HoldAllD;
NotebookDelete@objectD;
lstD
Integration utility functions.m | 139
FixIntRule[rule]
FixIntRule@RuleDelayed@lhs_,F_@G_@list_,F_@u_+v_,test2_DD,test1_DD,x_D :=
ReplacePart@RuleDelayed@lhs,F@G@list,F@u+v,test2DD,test1DD,882,1,2,1,1<->FixRhsIntRule@u,xD,82,1,2,1,2<->FixRhsIntRule@v,xD<D ;
F===Condition && HG===With ÈÈ G===Module ÈÈ G===BlockL
FixIntRule@RuleDelayed@lhs_,G_@list_,F_@u_+v_,test2_DDD,x_D :=
ReplacePart@RuleDelayed@lhs,G@list,F@u+v,test2DDD,882,2,1,1<->FixRhsIntRule@u,xD,82,2,1,2<->FixRhsIntRule@v,xD<D ;
F===Condition && HG===With ÈÈ G===Module ÈÈ G===BlockL
FixIntRule@RuleDelayed@lhs_,F_@G_@list_,u_+v_D,test_DD,x_D :=
ReplacePart@RuleDelayed@lhs,F@G@list,u+vD,testDD,882,1,2,1<->FixRhsIntRule@u,xD,82,1,2,2<->FixRhsIntRule@v,xD<D ;
F===Condition && HG===With ÈÈ G===Module ÈÈ G===BlockL
FixIntRule@RuleDelayed@lhs_,G_@list_,u_+v_DD,x_D :=
ReplacePart@RuleDelayed@lhs,G@list,u+vDD,882,2,1<->FixRhsIntRule@u,xD,82,2,2<->FixRhsIntRule@v,xD<D ;
HG===With ÈÈ G===Module ÈÈ G===BlockL
FixIntRule@RuleDelayed@lhs_,F_@u_+v_,test_DD,x_D :=
ReplacePart@RuleDelayed@lhs,F@u+v,testDD,882,1,1<->FixRhsIntRule@u,xD,82,1,2<->FixRhsIntRule@v,xD<D ;
F===Condition
FixIntRule@RuleDelayed@lhs_,u_+v_D,x_D :=
ReplacePart@RuleDelayed@lhs,u+vD,882,1<->FixRhsIntRule@u,xD,82,2<->FixRhsIntRule@v,xD<D
140 | Integration utility functions.m
FixIntRule@RuleDelayed@lhs_,F_@G_@list1_,F_@H_@list2_,u_D,test2_DD,test1_DD,x_D :=
ReplacePart@RuleDelayed@lhs,F@G@list1,F@H@list2,uD,test2DD,test1DD,82,1,2,1,2<->FixRhsIntRule@u,xDD ;
F===Condition && HG===With ÈÈ G===Module ÈÈ G===BlockL && HH===With ÈÈ H===Module ÈÈ H===BlockL
FixIntRule@RuleDelayed@lhs_,F_@G_@list1_,H_@list2_,u_DD,test1_DD,x_D :=
ReplacePart@RuleDelayed@lhs,F@G@list1,H@list2,uDD,test1DD,82,1,2,2<->FixRhsIntRule@u,xDD ;
F===Condition && HG===With ÈÈ G===Module ÈÈ G===BlockL && HH===With ÈÈ H===Module ÈÈ H===BlockL
FixIntRule@RuleDelayed@lhs_,F_@G_@list_,F_@H_@str1_,str2_,str3_,J_@u_DD,test2_DD,test1_DD,x_D :=
ReplacePart@RuleDelayed@lhs,F@G@list,F@H@str1,str2,str3,J@uDD,test2DD,test1DD,82,1,2,1,4,1<->FixRhsIntRule@u,xDD ;
F===Condition && HG===With ÈÈ G===Module ÈÈ G===BlockL && H===ShowStep && J===Hold
FixIntRule@RuleDelayed@lhs_,F_@G_@list_,F_@u_,test2_DD,test1_DD,x_D :=
ReplacePart@RuleDelayed@lhs,F@G@list,F@u,test2DD,test1DD,82,1,2,1<->FixRhsIntRule@u,xDD ;
F===Condition && HG===With ÈÈ G===Module ÈÈ G===BlockL
FixIntRule@RuleDelayed@lhs_,G_@list_,F_@u_,test2_DDD,x_D :=
ReplacePart@RuleDelayed@lhs,G@list,F@u,test2DDD,82,2,1<->FixRhsIntRule@u,xDD ;
F===Condition && HG===With ÈÈ G===Module ÈÈ G===BlockL
FixIntRule@RuleDelayed@lhs_,F_@G_@list_,u_D,test_DD,x_D :=
ReplacePart@RuleDelayed@lhs,F@G@list,uD,testDD,82,1,2<->FixRhsIntRule@u,xDD ;
F===Condition && HG===With ÈÈ G===Module ÈÈ G===BlockL
FixIntRule@RuleDelayed@lhs_,G_@list_,u_DD,x_D :=
ReplacePart@RuleDelayed@lhs,G@list,uDD,82,2<->FixRhsIntRule@u,xDD ;
HG===With ÈÈ G===Module ÈÈ G===BlockL
FixIntRule@RuleDelayed@lhs_,F_@u_,test_DD,x_D :=
ReplacePart@RuleDelayed@lhs,F@u,testDD,82,1<->FixRhsIntRule@u,xDD ;
F===Condition
FixIntRule@RuleDelayed@lhs_,u_D,x_D :=
ReplacePart@RuleDelayed@lhs,uD,82<->FixRhsIntRule@u,xDD
Integration utility functions.m | 141
FixRhsIntRule[rhs,x]
SetAttributes@FixRhsIntRule,HoldAllD;
FixRhsIntRule@u_+v_,x_D :=
FixRhsIntRule@u,xD+FixRhsIntRule@v,xD
FixRhsIntRule@u_-v_,x_D :=
FixRhsIntRule@u,xD-FixRhsIntRule@v,xD
FixRhsIntRule@-u_,x_D :=
-FixRhsIntRule@u,xD
FixRhsIntRule@a_*u_,x_D :=
Dist@a,u,xD ;
MemberQ@8Int,Subst<,Head@Unevaluated@uDDD
FixRhsIntRule@u_,x_D :=
If@Head@Unevaluated@uDD===Dist && Length@Unevaluated@uDD==2,
Insert@Unevaluated@uD,x,3D,
If@MemberQ@8Int,Subst,Defer@IntD,Simp,Dist<,Head@Unevaluated@uDDD,
u,
Simp@u,xDDD
© Copyright 2026 Paperzz