home *** CD-ROM | disk | FTP | other *** search
- (* ****************************************************************
- *
- * TABLE -- Table Lookup
- *
- **************************************************************** *)
-
- (* This is done here really to assist auto-loading on non-dumped Kernels*)
- Begin[ "Integrate`"]
-
- Unprotect[ TableLookUp]
-
- Clear[ TableLookUp]
-
- TableLookUp[$f_]:=
- Block[{$list,$c,$g,$factor,$k,$match,$i,$answer},
- TrcEnter[TableLookUp,$f];
- $list=FactorSquareFreeList[$f,Trig->True];
- $c=1;
- $g=1;
- Do[{$factor,$k}=$list[[$i]];
- If[FreeQ[$factor,X],
- $c=$c*$factor^$k,
- $g=$g*$factor^$k],
- {$i,Length[$list]}];
- $match=TableMatch[$g];
- $answer=If[SameQ[Head[$match],TableMatch],
- NOK,
- Dist[$c,$match]];
- TrcExit[TableLookUp,$answer];
- $answer]
-
- Foil[$rat1_,$rat2_]:=
- (* Distributive product. *)
- Block[{$i,$j,$answer},
- TrcEnter[Foil,$rat1,$rat2];
- $answer=If[Not[SameQ[Head[$rat1],Plus]],
- Dist[$rat1,$rat2],
- If[Not[SameQ[Head[$rat2],Plus]],
- Dist[$rat2,$rat1],
- Sum[Dist[$rat1[[$i]],$rat2],
- {$i,Length[$rat1]}]]];
- TrcExit[Foil,$answer];
- $answer]
-
- Dist[$rat1_,$rat2_]:=
- (* Distributive Law. *)
- Block[{$j,$answer},
- TrcEnter[Dist,$rat1,$rat2];
- $answer=If[Not[SameQ[Head[$rat2],Plus]],
- $rat1*$rat2,
- Sum[$rat1*$rat2[[$j]],
- {$j,Length[$rat2]}]];
- TrcExit[Dist,$answer];
- $answer]
-
- AlgebraicRoot[$g_,$h_]:=
- (* g^h where h is rational. Does not have to be principle root. *)
- Block[{$i,$answer},
- TrcEnter[AlgebraicRoot,$g,$h];
- $answer=Switch[Head[$g],
- Power, $g[[1]]^($g[[2]]*$h),
- Times, Product[AlgebraicRoot[$g[[$i]],$h],
- {$i,Length[$g]}],
- _, $g^$h];
- TrcExit[AlgebraicRoot,$answer];
- $answer]
-
- (* ****************************************************************
- *
- * Powers of X
- *
- **************************************************************** *)
-
- TableMatch[X^$a_.]:=
- Condition[
- If[And[NumberQ[$a],$a==-1],
- Log[X],
- X^($a+1)/($a+1)],
- And[FreeQ[$a,X],
- Or[NumberQ[$a],SameQ[Head[$a],Symbol]]]]
-
- (* ****************************************************************
- *
- * ExpIntegralEi, LogIntegral, CosIntegral, SinIntegral
- *
- **************************************************************** *)
-
- TableMatch[$g_^($a_.*X+$b_.)/($c_.*X+$d_.)]:=
- Condition[
- $g^($b-$a*$d/$c)*ExpIntegralEi[$a*Log[$g]*X+$a*Log[$g]*$d/$c]/$c,
- FreeQ[{$g,$a,$b,$c,$d},X]]
-
- TableMatch[ X^n_?OddQ Exp[a_. X^2 + c_.] ] :=
- Condition[
- Block[{den = 2*((-n-1)/2)!, limit = ((-n-1)/2)},
- -Exp[a X^2 + c] Sum[(k-1)!/den a^(limit-k) / X^(2 k), {k, 1, limit}] +
- a^limit ExpIntegralEi[a X^2] Exp[c]/den],
- FreeQ[{a, c}, X] && Negative[n]]
-
- TableMatch[ X^n_?EvenQ Exp[a_. X^2 + c_.] ] :=
- Condition[
- Block[{den = Factorial2[-n-1]},
- -Exp[a X^2 + c] * Sum[(2 a)^k Abs[-n-2k-3]!!/den X^(n + 2 k + 1),
- {k, 0, (-n-2)/2}] +
- (2a)^(-n/2)/den TableMatch[Exp[a X^2 + c]]],
- FreeQ[{a, c}, X] && Negative[n]]
-
- TableMatch[ E^(a_. X + b_.) (c_. X + d_.)^n_Integer?Negative ] :=
- Condition[
- Block[{den = (-n-1)!},
- -E^(a X + b) * Sum[(k-1)!/den a^(-n-k-1)/(c^(-n-k) (c X + d)^k),
- {k, 1, -n-1}] +
- a^(-n-1)/(den c^(-n)) E^(b-d a/c) ExpIntegralEi[a X + d a/c]],
- FreeQ[{a, b, c, d}, X]]
-
- TableMatch[ E^(a_. X + b_.)/X^2 ] := - E^(a X + b)/X +
- a Exp[b] ExpIntegralEi[a X] /; FreeQ[{a, b}, X]
-
- TableMatch[ X / (a_ + b_. Exp[c_. X + d_.]) ] :=
- X^2/(2 a) - X Log[1 + (b/a) Exp[c X + d]]/(a c) -
- PolyLog[2, -b Exp[c X + d] / a] /(a c^2) /; FreeQ[{a, b, c, d}, X]
-
- TableMatch[ X^n_Integer?Positive /(a_ + b_. Exp[c_. X + d_.]) ] :=
- Block[{num = -n! /a}, X^(n+1)/(a(n+1)) -
- X^n Log[1 + (b/a) Exp[c X + d]]/(a c) +
- Sum[num/(k-1)! X^(k-1) PolyLog[n+2-k, -(b/a) Exp[c X + d]] /(-c)^(n+2-k),
- {k, 1, n}] ] /; FreeQ[{a, b, c, d}, X]
-
- TableC1[$f_,$u_]:=
- (* Non-zero constant c==f/du or Fail. *)
- Block[{$c,$du},
- If[FreeQ[$u,X],Return[Fail]];
- $du=Together[D[$u,X]];
- If[$du==0,Return[Fail]];
- $c=Together[$f/$du];
- If[Not[FreeQ[$c,X]],Return[Fail]];
- $c]
-
- TableC2[$f_,$u_]:=
- (* Non-zero constant c==f*u/du or Fail. *)
- Block[{$c,$du},
- If[FreeQ[$u,X],Return[Fail]];
- $du=Together[D[$u,X]];
- If[$du==0,Return[Fail]];
- $c=Together[$f*$u/$du];
- If[Not[FreeQ[$c,X]],Return[Fail]];
- $c]
-
- TableMatch[$f_*E^$u_]:=
- Block[{$c},
- Condition[
- $c*ExpIntegralEi[$u],
- $c=TableC2[$f,$u];
- Not[SameQ[$c,Fail]]]]
-
- TableMatch[$f_*Cos[$u_]]:=
- Block[{$c},
- Condition[
- $c*CosIntegral[$u],
- $c=TableC2[$f,$u];
- Not[SameQ[$c,Fail]]]]
-
- TableMatch[$f_*Sin[$u_]]:=
- Block[{$c},
- Condition[
- $c*SinIntegral[$u],
- $c=TableC2[$f,$u];
- Not[SameQ[$c,Fail]]]]
-
- TableMatch[$f_*Cosh[$u_]]:=
- Block[{$c},
- Condition[
- $c*CoshIntegral[$u],
- $c=TableC2[$f,$u];
- Not[SameQ[$c,Fail]]]]
-
- TableMatch[$f_*Sinh[$u_]]:=
- Block[{$c},
- Condition[
- $c*SinhIntegral[$u],
- $c=TableC2[$f,$u];
- Not[SameQ[$c,Fail]]]]
-
- TableMatch[Exp[X] ExpIntegralEi[-X] ]:=
- Exp[X] ExpIntegralEi[X] - Log[X]
-
- TableMatch[Exp[b_. X] ExpIntegralEi[a_. X] ] :=
- Condition[
- (Exp[b X] ExpIntegralEi[a X] + Log[1 + b/a] -
- ExpIntegralEi[(a + b)X])/b,
- FreeQ[{a, b}, X] && !TrueQ[b/a==-1]]
-
- TableMatch[$a_^($b_^($c_.*X+$d_.))]:=
- Condition[
- ExpIntegralEi[$b^($c*X+$d)*Log[$a]]/($c*Log[$b]),
- FreeQ[{$a,$b,$c,$d},X]]
-
- TableMatch[Cos[$a_.*X+$b_.]/($c_.*X+$d_.)]:=
- Condition[
- Block[{$u,$v},
- $u=$b-$a*$d/$c;
- $v=$a*X+$a*$d/$c;
- 1/$c*Cos[$u]*CosIntegral[$v]-1/$c*Sin[$u]*SinIntegral[$v]],
- FreeQ[{$a,$b,$c,$d},X]]
-
- TableMatch[Sin[$a_.*X+$b_.]/($c_.*X+$d_.)]:=
- Condition[
- Block[{$u,$v},
- $u=$b-$a*$d/$c;
- $v=$a*X+$a*$d/$c;
- 1/$c*Sin[$u]*CosIntegral[$v]+1/$c*Cos[$u]*SinIntegral[$v]],
- FreeQ[{$a,$b,$c,$d},X]]
-
- TableMatch[$g_^($a_.*X^$n_.)/X]:=
- Condition[
- ExpIntegralEi[$a*Log[$g]*X^$n]/$n,
- FreeQ[{$g,$a,$n},X]]
-
- TableMatch[Cos[$a_.*X^$n_.]/X]:=
- Condition[
- CosIntegral[$a*X^$n]/$n,
- FreeQ[{$a,$n},X]]
-
- TableMatch[Sin[$a_.*X^$n_.]/X]:=
- Condition[
- SinIntegral[$a*X^$n]/$n,
- FreeQ[{$a,$n},X]]
-
- TableMatch[Sin[X]/($a_.+$b_.*X)]:=
- Condition[
- (SinIntegral[X+$a/$b]*Cos[$a/$b]/$b
- - CosIntegral[X+$a/$b]*Sin[$a/$b]/$b),
- FreeQ[{$a,$b},X]]
-
- TableMatch[Cos[X]/($a_.+$b_.*X)]:=
- Condition[
- (CosIntegral[X+$a/$b]*Cos[$a/$b]/$b
- + SinIntegral[X+$a/$b]*Sin[$a/$b]/$b),
- FreeQ[{$a,$b},X]]
-
- TableMatch[Log[X] Sin[X]]:=
- CosIntegral[X] - Cos[X] Log[X]
-
- TableMatch[Cos[X] Log[X]]:=
- Log[X] Sin[X] - SinIntegral[X]
-
- TableMatch[1/Log[$a_.*X+$b_.]]:=
- Condition[
- LogIntegral[$a*X+$b]/$a,
- FreeQ[{$a,$b},X]]
-
- TableMatch[X^$n_./Log[X]]:=
- Condition[
- ExpIntegralEi[($n+1)*Log[X]],
- FreeQ[$n, X] && !TrueQ[$n==-1]]
-
- TableMatch[$f_./Log[$u_]]:=
- Block[{$du,$c},
- Condition[
- $c*LogIntegral[$u],
- $c=TableC1[$f,$u];
- Not[SameQ[$c,Fail]]]]
-
- (* ****************************************************************
- *
- * ExpIntegralE
- *
- **************************************************************** *)
-
- TableMatch[$f_*ExpIntegralE[$n_,$u_]]:=
- Block[{$c},
- Condition[
- $c*ExpIntegralE[$n+1,$u],
- $c=TableC1[-$f,$u];
- And[FreeQ[$n,X],Not[SameQ[$c,Fail]]]]]
-
- (* ****************************************************************
- *
- * Erf, Erfi, FresnelC, FresnelS
- *
- **************************************************************** *)
-
- TableMatch[E^($a_.*X^2)]:=
- Condition[
- Block[{$sqrta},
- $sqrta=AlgebraicRoot[$a,1/2];
- 1/2*Pi^(1/2)*Erfi[$sqrta*X]/$sqrta],
- FreeQ[$a,X]]
-
- TableMatch[E^($a_.*X^2+$b_.*X+$c_.)]:=
- Condition[
- Block[{$sqrta},
- $sqrta=AlgebraicRoot[$a,1/2];
- ((1/2*E^(-$b^2/(4*$a) + $c)*Pi^(1/2)*Erfi[$sqrta*($b/(2*$a) + X)])
- /$sqrta)],
- FreeQ[{$a,$b,$c},X]]
-
- TableMatch[$g^($a_.*X^2)]:=
- Condition[
- Block[{$sqrta},
- $sqrta=AlgebraicRoot[$a,1/2];
- (1/2*Pi^(1/2)*Erfi[$sqrta*X*Log[$g]^(1/2)])/($sqrta*Log[$g]^(1/2))],
- FreeQ[{$g,$a},X]]
-
- TableMatch[$g_^($a_.*X^2+$b_.*X+$c_.)]:=
- Condition[
- Block[{$sqrta},
- $sqrta=AlgebraicRoot[$a,1/2];
- (($g^(-$b^2/(4*$a)+$c)*Pi^(1/2)*
- Erfi[(($b+2*$a*X)*Log[$g]^(1/2))/(2*$sqrta)])/
- (2*$sqrta*Log[$g]^(1/2)))],
- FreeQ[{$g,$a,$b,$c},X]]
-
- TableCSquared[$f_,$u_]:=
- (* Non-zero constant c==f^2*u/du^2 or Fail. *)
- Block[{$c,$du},
- If[FreeQ[$u,X],Return[Fail]];
- $du=Together[D[$u,X]];
- If[$du==0,Return[Fail]];
- $c=Together[$f^2*$u/$du^2];
- If[Not[FreeQ[$c,X]],Return[Fail]];
- $c]
-
- TableMatch[$f_*E^$g_]:=
- Block[{$dg,$csquared,$sqrtg,$c,$u},
- Condition[
- Block[{},
- $dg=Together[D[$g,X]];
- $sqrtg=AlgebraicRoot[$g,1/2];
- $c=Together[2*$f/$dg*$sqrtg];
- $u=Together[$c*$dg/(2*$f)];
- Sqrt[Pi]/2*$c*Erfi[$u]],
- Not[SameQ[TableCSquared[$f,$g],Fail]]]]
-
- TableMatch[$f_.*Cos[$g_]]:=
- Block[{$dg,$csquared,$sqrtg,$c,$u},
- Condition[
- Block[{},
- $dg=Together[D[$g,X]];
- $sqrtg=AlgebraicRoot[$g,1/2];
- $c=Together[Sqrt[2]*Sqrt[Pi]*$f/$dg*$sqrtg];
- $u=Together[$c*$dg/(Pi*$f)];
- $c*FresnelC[$u]],
- Not[SameQ[TableCSquared[$f,$g],Fail]]]]
-
- TableMatch[$f_.*Sin[$g_]]:=
- Block[{$dg,$csquared,$sqrtg,$c,$u},
- Condition[
- Block[{},
- $dg=Together[D[$g,X]];
- $sqrtg=AlgebraicRoot[$g,1/2];
- $c=Together[Sqrt[2]*Sqrt[Pi]*$f/$dg*$sqrtg];
- $u=Together[$c*$dg/(Pi*$f)];
- $c*FresnelS[$u]],
- Not[SameQ[TableCSquared[$f,$g],Fail]]]]
-
- (* ****************************************************************
- *
- * PolyLog
- *
- **************************************************************** *)
-
- TableMatch[Log[X]/(X-1)]:=
- -PolyLog[2,1-X]
-
- TableMatch[Log[X]/(1-X)]:=
- PolyLog[2,1-X]
-
- TableMatch[Log[1-X]/X]:=
- -PolyLog[2,X]
-
- TableMatch[Log[a_.*X+b_]/X]:=
- Condition[
- Log[a*X+b]*Log[-a*X/b]+PolyLog[2, a X/b+1],
- FreeQ[{a,b},X]]
-
- TableMatch[Log[X]/(a_.*X+b_)]:=
- Condition[
- Log[X]*Log[a*X/b+1]/a+PolyLog[2,-a*X/b]/a,
- FreeQ[{a,b},X]]
-
- TableMatch[Log[a_.*X+b_.]/(c_.*X+d_.)]:=
- Condition[
- (Log[a X + b] Log[a (c X + d)/(a d - b c)]/c
- +PolyLog[2, c (a X + b)/(b c - a d)]/c),
- FreeQ[{a,b,c,d}, X] && !TrueQ[a d - b c == 0]]
-
- TableMatch[PolyLog[n_Integer?Positive,X]/X]:=
- PolyLog[n+1,X]
-
- TableMatch[X^$m_.*PolyLog[$n_,X]]:=
- Condition[
- Block[{$c,$sum1,$sum2},
- $c=-1;
- $sum1=Sum[$c=-$c/($m+1);
- $c*X^($m+1)*PolyLog[$n-$i,X],
- {$i,0,$n-2}];
- $c=-$c/($m+1);
- $sum2=-$c*X^($m+1)*Log[1-X]+$c*Log[1-X];
- $sum3=Sum[$c*X^$i/$i,{$i,1,$m+1}];
- $sum1+$sum2+$sum3],
- And[SameQ[Head[$m],Integer],
- SameQ[Head[$n],Integer],
- $m>0,$n>0]]
-
- TableMatch[$f_*Log[$g_]]:=
- Block[{$c},
- Condition[
- $c*PolyLog[2,$u],
- $c=TableC2[-$f,1-$g];
- Not[SameQ[$c,Fail]]]]
-
- TableMatch[$f_.*PolyLog[$n_,$u_]]:=
- Block[{$c},
- Condition[
- $c*PolyLog[$n+1,$u],
- $c=TableC2[$f,$u];
- And[FreeQ[$n,X],Not[SameQ[$c,Fail]]]]]
-
- (* ****************************************************************
- *
- * Gamma, PolyGamma
- *
- **************************************************************** *)
-
- TableMatch[$f_.*Gamma[$u_]*PolyGamma[$u_]]:=
- Block[{$c},
- Condition[
- $c*Gamma[$u],
- $c=TableC1[$f,$u];
- Not[SameQ[$c,Fail]]]]
-
- TableMatch[$f_.*PolyGamma[$n_,$u_]]:=
- Block[{$c},
- Condition[
- $c*PolyGamma[$n-1,$u],
- $c=TableC1[$f,$u];
- And[FreeQ[$n,X],Not[SameQ[$c,Fail]]]]]
-
- TableMatch[E^(-X)*X^$a_]:=
- Condition[
- -Gamma[$a+1,X],
- FreeQ[$a,X]]
-
- (* ****************************************************************
- *
- * EllipticF, EllipticE, EllipticPi
- *
- **************************************************************** *)
-
- TableMatch[$f_.*(1-$m_*Sin[$phi_]^2)^(-1/2)]:=
- Block[{$dphi,$c},
- Condition[
- $c*EllipticF[$phi,$m],
- $c=TableC1[$f,$phi];
- And[FreeQ[$m,X],Not[SameQ[$c,Fail]]]]]
-
- TableMatch[$f_.*(1-$m_*Sin[$phi_]^2)^(1/2)]:=
- Block[{$dphi,$c},
- Condition[
- $c*EllipticE[$phi,$m],
- $c=TableC1[$f,$phi];
- And[FreeQ[$m,X],Not[SameQ[$c,Fail]]]]]
-
- (* TBW: This rule is OK, but there seems to be something wrong with
- the way it is being called. *)
- TableMatch[$f_.*(1-$m_*Sin[$phi_]^2)^(-1/2)*(1-$n_*Sin[$phi_]^2)^(-1)]:=
- Block[{$dphi,$c},
- Condition[
- $c*EllipticPi[$n,$phi,$m],
- $c=TableC1[$f,$phi];
- And[FreeQ[{$m,$n},X],Not[SameQ[$c,Fail]]]]]
-
- (* ****************************************************************
- *
- * TrigRules
- *
- *(1) These rules are used to clean up answers from integrals like
- *Integrate[E^(a*x)*Cos[b*x],x]. This is a somewhat hackish way
- *to avoid expressions like (a+I*b)(a-I*b)in the answer. Not the
- *perfect solution, though.
- **************************************************************** *)
-
- TrigRules=
- {Times[($x_+$y_)^$n_.,($x_+$z_)^$n_.]:>
- Condition[
- ($x^2-$y^2)^$n,
- And[IntegerQ[$n],SameQ[$y+$z,0]]],
- Times[($x_+$z_)^$n_.,($y_+$z_)^$n_.]:>
- Condition[
- (-$x^2+$z^2)^$n,
- And[IntegerQ[$n],SameQ[$x+$y,0]]]}
-
- Protect[ TableLookUp]
-
- End[]
-
- Null
-
-
-
-