home *** CD-ROM | disk | FTP | other *** search
/ Piper's Pit BBS/FTP: ibm 0010 - 0019 / ibm0010-0019 / ibm0010.tar / ibm0010 / DERIVE.ZIP / SPECIAL.MTH < prev    next >
Encoding:
Text File  |  1990-02-23  |  7.9 KB  |  278 lines

  1. "File:    SPECIAL.MTH  (c)       02/23/90          Soft Warehouse, Inc."
  2.  
  3. "Special Functions, Probability Distributions & Constants --"
  4.  
  5. "Reference: Abramowitz & Stegun, Handbook of Mathematical Functions, Dover."
  6.  
  7. "PART 1, CONSTANTS:"
  8.  
  9. "Lower-case gamma = lim(sum(1/k,k,1,m) - ln m, m, inf), to 25 sig. digits:"
  10.  
  11. EULER_GAMMA:=0.577215664901532860606512
  12.  
  13. "PART 2, EXPONENTIAL AND LOGARITHMIC INTEGRALS:"
  14.  
  15. "A series for the exponential integral, Ei(x)=-int(ê^-t/t,t,-x,inf), x>0:"
  16.  
  17. EI(x,m):=EULER_GAMMA+LN(x)+SUM(x^k_/(k_*k_!),k_,1,m)
  18.  
  19. "A series for the logarithmic integral, li(x)=int(1/ln t,t,0,x), x>1:"
  20.  
  21. LI(x,m):=EI(LN(x),m)
  22.  
  23. "The nth exponential integral, approximating inf by 10 (2+|z|):"
  24.  
  25. EN(n,z):=INT(#e^(-z*t_)/t_^n,t_,1,INF)
  26.  
  27. "An asymptotic series for the nth exponential integral as z -> inf:"
  28.  
  29. EN_ASYMP(n,z,m):=#e^(-z)/z*SUM(PERM(n+k_-1,k_)/(-z)^k_,k_,0,m)
  30.  
  31. "A degree m power series approximation for EN (1, z):"
  32.  
  33. E1(z,m):=-EULER_GAMMA-LN(z)-SUM((-z)^k_/(k_*k_!),k_,1,m)
  34.  
  35. "The sine integral.  Use Taylor on the integral to get a power series:"
  36.  
  37. SI(z):=INT(SIN(t_)/t_,t_,0,z)
  38.  
  39. "The cosine integral.  Use Taylor on the integral to get a power series:"
  40.  
  41. CI(z):=EULER_GAMMA+LN(z)+INT((COS(t_)-1)/t_,t_,0,z)
  42.  
  43. "PART 3, RELATIVES OF THE GAMMA FUNCTION:"
  44.  
  45. "Generalized Pochhammer symbol, (a)x:"
  46.  
  47. POCHHAMMER(a,x):=GAMMA(a+x)/GAMMA(a)
  48.  
  49. "Tail-truncated aprx. to PSI(z) = (d/dz gamma(z))/gamma(z), for |phase z|<PI/2~
  50. :"
  51.  
  52. PSI(z):=LN(z)-1/(2*z)-2*INT(t_/((t_^2+z^2)*(#e^(2*PI*t_)-1)),t_,0,INF)
  53.  
  54. "An m-term + tail aprx. to POLYGAMMA(n,z) = (d/dz)^(n) PSI(z) for z/=0,-1,-2,.~
  55. ..:"
  56.  
  57. "For about 6 significant digits use m about 5 |z| n^-.75 + 18 n^-.9"
  58.  
  59. POLYGAMMA(n,z,m):=(-1)^(n-1)*n!*(1/(n*(z+m+1/2)^n)+SUM((z+k_)^(-n-1),k_,0,m))
  60.  
  61. "The incomplete gamma function for RE(z)>0:"
  62.  
  63. INCOMPLETE_GAMMA(z,w):=1/GAMMA(z)*(w^z/z+INT((#e^(-t_)-1)*t_^(z-1),t_,0,w))
  64.  
  65. "A series useful near where the above is indeterminate at z=0,-1,-2,..."
  66.  
  67. INCOMPLETE_GAMMA_SERIES(z,w,m):=#e^(-w)*w^z*SUM(w^(m-k_)/GAMMA(z+m-k_+1),k_,0,~
  68. m)
  69.  
  70. "The complete beta function:"
  71.  
  72. BETA(z,w):=GAMMA(z)*GAMMA(w)/GAMMA(z+w)
  73.  
  74. "The incomplete Beta function or distribution, using singularity cancellation:"
  75.  
  76. INCOMPLETE_BETA(x,z,w):=(x^z/z+(1-(1-x)^w)/w+INT(t_^(z-1)*((1-t_)^(w-1)-1)-(1-~
  77. t_)^(w-1),t_,0,x))/BETA(z,w)
  78.  
  79. "PART 4, RELATIVES OF THE ERROR FUNCTION:"
  80.  
  81. "The Fresnel sine integral:"
  82.  
  83. FRESNEL_S(z):=INT(SIN(PI*t_^2/2),t_,0,z)
  84.  
  85. "A series approximation to the Fresnel sine integral:"
  86.  
  87. FRESNEL_S_SERIES(z,m):=SUM((-1)^k_*(PI/2)^(2*k_+1)*z^(4*k_+3)/((2*k_+1)!*(4*k_~
  88. +3)),k_,0,m)
  89.  
  90. "The Fresnel cosine integral:"
  91.  
  92. FRESNEL_C(z):=INT(COS(PI*t_^2/2),t_,0,z)
  93.  
  94. "A series approximation to the Fresnel cosine integral:"
  95.  
  96. FRESNEL_C_SERIES(z,m):=SUM((-1)^k_*(PI/2)^(2*k_)*z^(4*k_+1)/((2*k_)!*(4*k_+1))~
  97. ,k_,0,m)
  98.  
  99. "PART 5, BESSEL FUNCTIONS:"
  100.  
  101. "The nth order Bessel function of the first kind with RE(n) > -1/2:"
  102.  
  103. BESSEL_J(n,z):=(z/2)^n/(SQRT(PI)*GAMMA(n+1/2))*INT(COS(z*COS(t_))*SIN(t_)^(2*n~
  104. ),t_,0,PI)
  105.  
  106. "The truncated Taylor series is more efficient for |z| < about 10:"
  107.  
  108. BESSEL_J_SERIES(n,z,m):=(z/2)^n*SUM((-z^2/4)^k_/(k_!*(n+k_)!),k_,0,m)
  109.  
  110. "An asymptotic form with error O(#e^IM(z)/|z|) as |z| --> inf"
  111.  
  112. BESSEL_J_ASYMP(n,z):=SQRT(2/(PI*z))*COS(z-(n+1/2)*PI/2)
  113.  
  114. "The nth-order Bessel function of the 2nd kind for noninteger n:"
  115.  
  116. BESSEL_Y(n,z):=(BESSEL_J(n,z)*COS(n*PI)-BESSEL_J(-n,z))/SIN(n*PI)
  117.  
  118. "An asymptotic form with error O(#e^IM(z)/|z|) as |z| --> inf"
  119.  
  120. BESSEL_Y_ASYMP(n,z):=SQRT(2/(PI*z))*SIN(z-(n+1/2)*PI/2)
  121.  
  122. "The Airy function Ai(z):"
  123.  
  124. AI(z):=SQRT(-z)/3*(BESSEL_J(1/3,2*(-z)^(3/2)/3)+BESSEL_J(-1/3,2*(-z)^(3/2)/3))
  125.  
  126. "The BAiry function Bi(z):"
  127.  
  128. BI(z):=SQRT(-z/3)*(BESSEL_J(1/3,2*(-z)^(3/2)/3)-BESSEL_J(-1/3,2*(-z)^(3/2)/3))
  129.  
  130. "PART 6, HYPERGEOMETRIC FUNCTIONS:"
  131.  
  132. "Kummer's confluent hypergeometric function 1F1(a;b;z), with singularities sub~
  133. tracted:"
  134.  
  135. KUM_AUX(a,b,z):=(1/2)^a/a+INT(t_^(a-1)*(#e^(z*t_)*(1-t_)^(b-a-1)-1),t_,0,1/2)
  136.  
  137. KUMMER(a,b,z):=GAMMA(b)/(GAMMA(b-a)*GAMMA(a))*(KUM_AUX(a,b,z)+#e^z*KUM_AUX(b-a~
  138. ,b,-z))
  139.  
  140. "A truncated series for Kummer's confluent hypergeometric function:"
  141.  
  142. KUMMER_SERIES(a,b,z,m):=GAMMA(b)/GAMMA(a)*SUM(GAMMA(a+k_)*z^k_/(GAMMA(b+k_)*k_~
  143. !),k_,0,m)
  144.  
  145. "The Gauss hypergeometric function 2F1(a,b,c,z), using singularity cancellatio~
  146. n:"
  147.  
  148. HYP_AUX(a,b,c,z):=(1/2)^b/b+INT(t_^(b-1)*((1-t_)^(c-b-1)*(1-t_*z)^(-a)-1),t_,0~
  149. ,1/2)
  150.  
  151. HYPERGEOMETRIC(a,b,c,z):=GAMMA(c)/(GAMMA(b)*GAMMA(c-b))*(HYP_AUX(a,b,c,z)+(1-z~
  152. )^(-a)*HYP_AUX(a,c-b,c,z/(z-1)))
  153.  
  154. "A truncated series for the Gauss hypergeometric function:"
  155.  
  156. HYPERGEOMETRIC_SERIES(a,b,c,z,m):=GAMMA(c)/(GAMMA(a)*GAMMA(b))*SUM(GAMMA(a+k_)~
  157. *GAMMA(b+k_)*z^k_/(GAMMA(c+k_)*k_!),k_,0,m)
  158.  
  159. "PART 7, ELLIPTIC INTEGRALS:"
  160.  
  161. "Elliptic integral of the 1st kind:"
  162.  
  163. ELLIPTIC_F(a,m):=INT(1/SQRT(1-m*SIN(t_)^2),t_,0,a)
  164.  
  165. "Elliptic integral of the 2nd kind:"
  166.  
  167. ELLIPTIC_E(a,m):=INT(SQRT(1-m*SIN(t_)^2),t_,0,a)
  168.  
  169. "Elliptic integral of the 3rd kind:"
  170.  
  171. ELLIPTIC_PI(a,n,m):=INT(1/((1-n*SIN(t_)^2)*SQRT(1-m*SIN(t_)^2)),t_,0,a)
  172.  
  173. "PART 8, ORTHOGONAL POLYNOMIALS:"
  174.  
  175. "Chebychev polynomials of the 1st kind, T(n,x):"
  176.  
  177. CHEBYCHEV_T(n,x):=SQRT(PI*(1-x^2))/((-2)^n*GAMMA(n+1/2))*DIF((1-x^2)^(n-1/2),x~
  178. ,n)
  179.  
  180. "Chebychev polynomials of the 2nd kind, U(n,x):"
  181.  
  182. CHEBYCHEV_U(n,x):=(-(n+1)*SQRT(PI)/((-2)^(n+1)*GAMMA(n+3/2)*SQRT(1-x^2))*DIF((~
  183. 1-x^2)^(n+1/2),x,n))
  184.  
  185. "Legendre polynomials, P(n,x):"
  186.  
  187. LEGENDRE_P(n,x):=DIF((1-x^2)^n,x,n)/((-2)^n*n!)
  188.  
  189. "Associated Legendre 'polynomials':"
  190.  
  191. ASSOCIATED_LEGENDRE_P(n,m,x):=(-1)^m*(1-x^2)^(m/2)*DIF(LEGENDRE_P(n,x),x,m)
  192.  
  193. "Hermite polynomials, H(n,x):"
  194.  
  195. HERMITE_H(n,x):=(-1)^n*#e^(x^2)*DIF(#e^(-x^2),x,n)
  196.  
  197. HERMITE_HE(n,x):=HERMITE_H(n,x/SQRT(2))
  198.  
  199. "Weber Parabolic Cylinder functions D(n,x):"
  200.  
  201. WEBER_D(n,x):=#e^(-x^2/4)*HERMITE_HE(n,x)
  202.  
  203. "Generalized Laguerre polys L(n,a,x).  a=0 gives ordinary Laguerre polys:"
  204.  
  205. GENERALIZED_LAGUERRE(n,a,x):=#e^x/(x^a*n!)*DIF(x^(a+n)/#e^x,x,n)
  206.  
  207. "The generalized Jacobi polynomials, P(n,a,b,x):"
  208.  
  209. JACOBI_P(n,a,b,x):=DIF((1-x)^a*(1-x)^b*(1-x^2)^n,x,n)/((-2)^n*n!*(1-x)^a*(1-x)~
  210. ^b)
  211.  
  212. "The Gegenbauer ultra-spherical polynomials, C(n,a,x):"
  213.  
  214. GEGENBAUER_C(n,a,x):=GAMMA(a+1/2)*GAMMA(n+2*a)/((-2)^n*n!*GAMMA(2*a)*GAMMA(a+n~
  215. +1/2)*(1-x^2)^(a-1/2))*DIF((1-x^2)^(n+a-1/2),x,n)
  216.  
  217. "PART 9, RELATIVES OF THE ZETA FUNCTION:"
  218.  
  219. "An m-term plus tail aprx to the Riemann zeta function for RE(s)>1."
  220.  
  221. ZETA(s,m):=(m+1/2)^(1-s)/(s-1)+SUM(k^(-s),k,1,m)
  222.  
  223. "An m+1 term plus tail aprx to the Hurwitz zeta fcn for a+k/=0 & RE(s)>1"
  224.  
  225. HURWITZ_ZETA(s,a,m):=(m+a+1/2)^(1-s)/(s-1)+SUM((k_+a)^(-s),k_,0,m)
  226.  
  227. "A degree-m approximation to the Lerch transcendent:"
  228.  
  229. LERCH_PHI(z,s,a,m):=SUM(z^k_/(a+k_)^s,k_,0,m)
  230.  
  231. "A degree-m approximation to the Jonquiere's polylogarithms LIn(z):"
  232.  
  233. POLYLOG(n,z,m):=SUM(z^k_/k_^n,k_,1,m)
  234.  
  235. "An integral definition of the dilogarithm POLYLOG(1,z), a special case of Spe~
  236. nce's integrals:"
  237.  
  238. DILOG(x):=INT(LN(t_)/(1-t_),t_,1,x)
  239.  
  240. "PART 10, PROBABILITY DENSITIES AND DISTRIBUTIONS:"
  241.  
  242. "Poisson probability density:"
  243.  
  244. POISSON_DENSITY(k,t):=#e^(-t)*t^k/k!
  245.  
  246. "Poisson probability distribution:"
  247.  
  248. POISSON_DISTRIBUTION(k,t):=SUM(POISSON_DENSITY(j_,t),j_,0,k)
  249.  
  250. "The binomial probability density:"
  251.  
  252. BINOMIAL_DENSITY(k,n,p):=COMB(n,k)*p^k*(1-p)^(n-k)
  253.  
  254. "The binomial cumulative probability distribution:"
  255.  
  256. BINOMIAL_DISTRIBUTION(k,n,p):=SUM(BINOMIAL_DENSITY(j_,n,p),j_,0,MIN(k,n))
  257.  
  258. "Hypergeometric probability density:"
  259.  
  260. HYPERGEOMETRIC_DENSITY(k,n,m,j):=COMB(m,k)*COMB(j-m,n-k)/COMB(j,n)
  261.  
  262. "Hypergeometric cumulative probability distribution:"
  263.  
  264. HYPERGEOMETRIC_DISTRIBUTION(k,n,m,j):=SUM(HYPERGEOMETRIC_DENSITY(i_,n,m,j),i_,~
  265. MAX(0,n-j+m),MIN(k,n,m))
  266.  
  267. "The Student's-t cumulative probability distribution:"
  268.  
  269. STUDENT(x,d):=1-INCOMPLETE_BETA(d/2,1/2,d/(d+x^2))
  270.  
  271. "The F cumulative probability distribution:"
  272.  
  273. F_DISTRIBUTION(x,d1,d2):=INCOMPLETE_BETA(d2/2,d1/2,d2/(d2+d1*x))
  274.  
  275. "The Chi-Square cumulative probability distribution function:"
  276.  
  277. CHI_SQ(x,d):=INCOMPLETE_GAMMA(d/2,x/2)
  278.