1 /*******************************************************************************
3 * Tests of hypergeometric functions
5 ******************************************************************************/
10 assume(notequal(z,0));
13 /*******************************************************************************
15 * Test of hypergeometric function 0F0
17 ******************************************************************************/
22 /* ---------- Specific values ----------------------------------------------- */
36 /*******************************************************************************
40 ******************************************************************************/
45 /* ---------- Specific values ----------------------------------------------- */
54 /* --- For x = 1 the result depends on the sign of a --- */
56 /* a is negative -> 0 */
61 hgfred([-1],[],1.0b0);
64 /* a is positive -> inf or infinity */
65 limit(hgfred([1],[],x),x,1);
68 limit(hgfred([2],[],x),x,1);
71 /* Maxima does not check the sign of a symbolic expression for a.
72 * The result is always 0.
78 /* The following two cases should give a Maxima error. But they do not.
79 * The reason is, that Maxima always simplifies 0^expr -> 0.
80 * That is a problem of simpexpt and not of $hgfred.
82 errcatch(hgfred([xp],[],1));
84 errcatch(hgfred([-xn],[],1));
90 /*******************************************************************************
94 ******************************************************************************/
96 /* --- General simplification in terms of bessel_i and bessel_j --- */
99 bessel_i(b-1,2*sqrt(x))*gamma(b)*x^(1/2-b/2);
102 bessel_j(b-1,2*sqrt(x))*gamma(b)*x^(1/2-b/2);
104 /* ---------- Specific values ----------------------------------------------- */
110 hgfred([],[b], 0.0b0);
113 /* --- b = n/2 and z = x^2/4 --- */
115 /* The results are in terms of bessel_i and bessel_j and a half integral order.
116 * We expand the Bessel functions and get results in terms of trigonometric
120 hgfred([],[1/2],x^2/4),besselexpand:true;
122 hgfred([],[1/2],-x^2/4),besselexpand:true;
125 hgfred([],[-1/2], x^2/4), besselexpand:true;
127 hgfred([],[-1/2], -x^2/4), besselexpand:true;
130 hgfred([],[3/2],x^2/4), besselexpand:true;
132 hgfred([],[3/2],-x^2/4), besselexpand:true;
135 hgfred([],[-3/2],x^2/4), besselexpand:true;
136 (3*x*sinh(x)+(-x^2-3)*cosh(x))/-3;
137 hgfred([],[-3/2],-x^2/4), besselexpand:true;
138 (3*x*sin(x)+(3-x^2)*cos(x))/3;
140 /*******************************************************************************
142 * Hypergeometric 1F1 - Confluent hypergeometric function
144 ******************************************************************************/
146 /* ---------- Specific values ----------------------------------------------- */
152 hgfred([a],[b],0.0b0);
155 /* ---------- 1F1(a; a; z) -------------------------------------------------- */
161 /* ---------- 1F1(a; a+n; z) for n= 1, 2 ------------------------------------ */
164 hgfred([a],[a+1],-z);
165 a*z^(-a)*gamma_incomplete_lower(a,z);
167 hgfred([a],[a+1],-z),prefer_gamma_incomplete:true;
168 (a*gamma_incomplete(a,z)-a*gamma(a))/-z^a;
170 hgfred([a],[a+2],-z);
171 z^(-a-1)*((a^2+a)*gamma_incomplete_lower(a,z)*z+(-a^2-a)*gamma_incomplete_lower(a+1,z));
173 hgfred([a],[a+2],-z),prefer_gamma_incomplete:true;
174 -z^(-a-1)*(((a^2+a)*gamma_incomplete(a,z)+(-a^2-a)*gamma(a))*z
175 +(-a^2-a)*gamma_incomplete(a+1,z)+(a^2+a)*gamma(a+1));
177 /* ---------- 1F1(a; a-n; z) for n = -1, -2 --------------------------------- */
183 z^2*%e^z/((a-2)*(a-1))+2*z*%e^z/(a-2)+%e^z;
185 /* ---------- Test 1F1 polynomials ------------------------------------------ */
187 /* First the cases, when we have a symbolic negative integer */
194 hgfred([-n],[1/2],z);
195 (-1)^n*n!*hermite(2*n,sqrt(z))/(2*n)!;
197 hgfred([-n],[3/2],z);
198 (-1)^n*2^((2*n+1)/-2+n-1/2)*n!*hermite(2*n+1,sqrt(z))/((2*n+1)!*sqrt(z));
201 gamma(b)*n!*gen_laguerre(n,b-1,z)/gamma(n+b);
208 /* Check for specific values */
216 -z^7/5040+7*z^6/720-7*z^5/40+35*z^4/24-35*z^3/6+21*z^2/2-7*z+1;
219 /*5040*gen_laguerre(7,c-1,z)*gamma(c)/gamma(c+7)$*/
220 -z^7/(c*(c+1)*(c+2)*(c+3)*(c+4)*(c+5)*(c+6))
221 +7*z^6/(c*(c+1)*(c+2)*(c+3)*(c+4)*(c+5))-21*z^5/(c*(c+1)*(c+2)*(c+3)*(c+4))
222 +35*z^4/(c*(c+1)*(c+2)*(c+3))-35*z^3/(c*(c+1)*(c+2))+21*z^2/(c*(c+1))-7*z/c+1;
225 * Note that this formula is in terms of He but we want just H.
226 * A&S 22.5.18 gives the relationship between He and H:
228 * He(n,x) = 2^(-n/2)*H(n,x/sqrt(2))
230 hgfred([-4],[1/2],z^2/2);
231 /*hermite(8,z/sqrt(2))/1680;*/
232 z^8/105-4*z^6/15+2*z^4-4*z^2+1;
234 hgfred([-2],[1/2],z);
235 /*hermite(4,sqrt(z))/12$*/
238 hgfred([-2],[3/2],z);
239 /*hermite(5,sqrt(z))/(120*sqrt(z));*/
243 hgfred([-4],[3/2],z^2/2);
244 /*hermite(9,z/sqrt(2))/(15120*sqrt(2)*z)$*/
245 z^8/945-4*z^6/105+2*z^4/5-4*z^2/3+1;
247 /* ---------- 1F1(a; 2*a; x) ------------------------------------------------ */
250 16^(a/2)*bessel_i((2*a-1)/2,x/2)*gamma((2*a+1)/2)*x^(1/2-a)*%e^(x/2)/2;
252 hgfred([a],[2*a],-x);
253 16^(a/2)*bessel_i((2*a-1)/2,x/2)*gamma((2*a+1)/2)*x^(1/2-a)*%e^-(x/2)/2;
256 hgfred([v+1/2],[2*v+1],2*%i*z);
257 4^(v/2)*bessel_j(v,z)*gamma(v+1)*exp(%i*z)/z^v$
260 hgfred([v+1/2],[2*v+1],2*z);
261 4^(v/2)*bessel_i(v,z)*gamma(v+1)*exp(z)/z^v$
264 expand(hgfred([n+1],[2*n+2],2*%i*z));
265 sqrt(2)*4^(n/2)*bessel_j(n+1/2,z)*gamma(n+3/2)*z^(-n-1/2)*%e^(%i*z);
268 expand(hgfred([-n],[-2*n],2*%i*z));
269 bessel_j(-n-1/2,z)*gamma(1/2-n)*z^(n+1/2)*%e^(%i*z)/(sqrt(2)*4^(n/2));
272 expand(hgfred([n+1],[2*n+2],2*z));
273 sqrt(2)*4^(n/2)*bessel_i(n+1/2,z)*gamma(n+3/2)*z^(-n-1/2)*%e^z;
275 /* ---------- 1F1(n+1/2; m; z) for m, n integer ----------------------------- */
278 ((bessel_i(1,x/2)+bessel_i(0,x/2))*x+bessel_i(0,x/2))*%e^(x/2);
281 (bessel_i(1,x/2)+bessel_i(0,x/2))*%e^(x/2);
284 ((4*bessel_i(1,x/2)-4*bessel_i(0,x/2))*x+16*bessel_i(1,x/2))*%e^(x/2)/x^2;
286 /* ---------- 1F1(1/2-n,m,x) for m, n integer ------------------------------- */
288 hgfred([-1/2],[1],x);
289 ((bessel_i(1,x/2)-bessel_i(0,x/2))*x+bessel_i(0,x/2))*%e^(x/2);
291 hgfred([-1/2],[2],x);
292 ((2*bessel_i(1,x/2)-2*bessel_i(0,x/2))*x
293 -bessel_i(1,x/2)+3*bessel_i(0,x/2))
296 hgfred([-1/2],[4],x);
297 ((16*bessel_i(1,x/2)-16*bessel_i(0,x/2))*x^3
298 +(40*bessel_i(0,x/2)-24*bessel_i(1,x/2))*x^2
299 +(4*bessel_i(0,x/2)-20*bessel_i(1,x/2))*x-16*bessel_i(1,x/2))
303 /* ---------- 1F1(a; 2*a+n) for n an integer -------------------------------- */
305 hgfred([1/3],[2*1/3+1],x);
306 (2^(2/3)*gamma(5/6)*bessel_i(5/6,x/2)
307 -2^(2/3)*bessel_i(-1/6,x/2)*gamma(5/6))
308 *x^(1/6)*%e^(x/2)/-2;
310 hgfred([1/3],[2*1/3+2],x);
311 (2^(2/3)*gamma(5/6)*bessel_i(11/6,x/2)
312 -5*2^(2/3)*gamma(5/6)*bessel_i(5/6,x/2)
313 +2^(8/3)*bessel_i(-1/6,x/2)*gamma(5/6))
316 /* ---------- 1F1(a; 2*a-n) for n an integer -------------------------------- */
318 hgfred([1/3],[2*1/3-1],x);
319 (3*bessel_i(-1/6,x/2)+3*bessel_i(-7/6,x/2))
320 *gamma(5/6)*x^(7/6)*%e^(x/2)/-2^(4/3);
322 hgfred([1/3],[2*1/3-2],x);
323 (45*bessel_i(-1/6,x/2)+63*bessel_i(-7/6,x/2)+18*bessel_i(-13/6,x/2))
324 *gamma(5/6)*x^(13/6)*%e^(x/2)/(7*2^(10/3));
326 /*******************************************************************************
330 ******************************************************************************/
332 /* ---------- Test 2F0 polynomials ------------------------------------------ */
339 hgfred([-n,-n+1/2],[],-1/z^2),radexpand:all;
340 hermite(2*n,z)/(2^(2*n)*z^(2*n));
342 hgfred([-n,-n-1/2],[],-1/z^2),radexpand:all;
343 2^((-2*n-1)/2-(2*n+1)/2)*hermite(2*n+1,z)*z^(-2*n-1);
346 n!*gen_laguerre(n,-n-b,-1/z)*z^n;
353 /* Test 2F0 polynomials for specific values */
355 ratsimp(hgfred([-3,-3+1/2],[],z));
356 /*-hermite(6,%i/sqrt(z))*z^3/64$*/
357 (15*z^3+90*z^2+60*z+8)/8;
359 ratsimp(hgfred([-3-1/2,-3],[],z));
360 /*%i*hermite(7,%i/sqrt(z))*z^(7/2)/128$*/
361 (105*z^3+210*z^2+84*z+8)/8;
363 hgfred([-2,-4],[],z);
364 /*2*gen_laguerre(2,2,-1/z)*z^2$*/
365 12*(2/(3*z)+1/(12*z^2)+1)*z^2;
367 /* Test that 2F0([a,b],...) = 2F0([b,a],...) */
368 hgfred([-4,-2],[],z);
369 /*2*gen_laguerre(2,2,-1/z)*z^2$*/
370 12*(2/(3*z)+1/(12*z^2)+1)*z^2;
372 /*******************************************************************************
376 ******************************************************************************/
378 /* ---------- 2F1(a,b; c; 0) ------------------------------------------------ */
382 hgfred([a,b],[c],0.0);
384 hgfred([a,b],[c],0.0b0);
387 /* More examples from bug reports */
389 /* Bug ID: 1531688 - hgfred([ ], [ ], 0) */
395 /* Bug ID: 1857562 - hgfred([a,b],[c], 0) -/--> 1 */
398 hgfred([3,9],[77],0);
401 /* ---------- 2F1(a,b; a; z) and 2F1(a,b; b; z) ----------------------------- */
409 /* ---------- 2F1(a,b; b-n; z) works for n a positive integer --------------- */
411 /* This is a test of the routine splitpfq */
413 hgfred([a,b],[b-1],z);
414 a*(1-z)^(-a-1)*z/(b-1)+1/(1-z)^a;
416 hgfred([a,b],[b-2],z);
417 a*(a+1)*(1-z)^(-a-2)*z^2/((b-2)*(b-1))+2*a*(1-z)^(-a-1)*z/(b-2)+1/(1-z)^a;
419 /* ---------- 2F1(a,b; b+1; z) ---------------------------------------------- */
421 hgfred([a,b],[b+1],z); /* No soution, a noun form */
422 %f[2,1]([a,b],[b+1],z);
424 /* ---------- 2F1(a,b; a+b-1/2; z) ------------------------------------------ */
426 /* This function is reduced to 2F1(a,b; a+b+1/2).
427 * This is a test of the routines gered1 and legf20 called from legfun.*/
429 result:hgfred([a,b],[a+b-1/2],z);
430 2^(b+a-3/2)*assoc_legendre_p(b-a-1/2,-b-a+3/2,sqrt(1-z))*gamma(b+a-1/2)
434 /* Check for two special cases a=-1/2, b=2 and b=3 */
436 result - hgfred([-1/2,2],[-1/2+2-1/2],z), a=-1/2,b=2,ratsimp;
439 result - hgfred([-1/2,3],[-1/2+3-1/2],z), a=-1/2,b=3,ratsimp;
442 /* ---------- 2F1(a,b; a+b+1/2; z) ------------------------------------------ */
444 /* This is a test of routine legf20 called from legfun */
446 result:hgfred([a,b],[a+b+1/2],z);
447 assoc_legendre_p(b-a-1/2,-b-a+1/2,sqrt(1-z))
448 *2^(b+a-1/2)*gamma(b+a+1/2)*z^((-b-a+1/2)/2);
450 /* Check for two special cases a=2, b=-3/2 and a=3, b=-5/2 */
452 result - hgfred([2,-3/2],[2-3/2+1/2],z), a=2, b=-3/2, ratsimp;
455 result - hgfred([3,-5/2],[3-5/2+1/2],z), a=3, b=-5/2, ratsimp;
458 /* ---------- 2F1(a,b; a+b+3/2; z) ------------------------------------------ */
460 /* This is reduced to 2F1(a,b; a+b+1/2).
461 * The implementation does not work as expected because the associated
462 * legendre function is not fully implemented.
465 result:hgfred([a,b],[a+b+3/2],z);
466 (b+a+1/2)*(1-z)^(3/2)
467 *(2^(b+a-3/2)*assoc_legendre_p(b-a-1/2,-b-a+1/2,sqrt(1-z))
468 *gamma(b+a+1/2)*z^((-b-a+1/2)/2)
470 +(-b-a+1/2)*2^(b+a-3/2)*assoc_legendre_p(b-a-1/2,-b-a+1/2,sqrt(1-z))
471 *gamma(b+a+1/2)*z^((-b-a+1/2)/2-1)
473 +2^(b+a-3/2)*gamma(b+a+1/2)
474 *(2*b*assoc_legendre_p(b-a+1/2,-b-a+1/2,sqrt(1-z))
475 -(b-a+1/2)*assoc_legendre_p(b-a-1/2,-b-a+1/2,sqrt(1-z))
476 *sqrt(1-z))*z^((-b-a+1/2)/2-1)
480 /* --- Check for specific values --- */
482 /* These tests fail because the current implementation of the
483 * associated legendre function is not complete.
486 result - hgfred([-1,3/2],[-1+3/2+3/2],z), a=-1, b=3/2, ratsimp;
489 result - hgfred([-1,5/2],[-1+5/2+3/2],z), a=-1, b=5/2, ratsimp;
492 result - hgfred([-2,5/2],[-2+5/2+3/2],z), a=-2, b=5/2, ratsimp;
495 /* ---------- 2F1(a,b; a-b+1; z) -------------------------------------------- */
497 /* Test of the routine legf16 called from legfun.
498 * Maxima distinguishes a solution for x<0 from a solution from x>0.
499 * This has to be checked in more detail.
505 result:hgfred([a,b],[a-b+1],x);
506 gamma(-b+a+1)*assoc_legendre_p(b-1,b-a,(x+1)/(1-x))*x^((b-a)/2)/(1-x)^b;
508 /* Check for some values */
510 result - hgfred([1,1],[1-1+1],x), a=1, b=1, ratsimp;
513 /* Fails because the associated legendre function is not fully implemented */
514 result - hgfred([2,1],[2-1+1],x), a=2, b=1, ratsimp;
517 /* Fails because of different phase factor, we expect 1/(1-x)^3 */
518 result - hgfred([3,2],[3-2+1],x), a=3, b=2, radcan;
521 /* Now the second result for a negative argument */
523 hgfred([a,b],[a-b+1],-x);
524 gamma(-b+a+1)*assoc_legendre_p(b-1,b-a,(1-x)/(x+1))*x^((b-a)/2)/(x+1)^b;
529 /* ---------- 2F1(a,b; a-b+2; z) -------------------------------------------- */
531 hgfred([a,b],[a-b+2],x); /* No solution, a noun form */
532 %f[2,1]([a,b],[-b+a+2],x);
534 /* ---------- 2F1(a,b; (a+b)/2; z) ------------------------------------------ */
536 hgfred([a,b],[(a+b)/2],x); /* No solution, a noun form */
537 %f[2,1]([a,b],[b/2+a/2],x);
539 /* ---------- 2F1(a,b; (a+b+1)/2; z) ---------------------------------------- */
541 /* Test of the routine legf14 and gered1 called from legfun.
542 * Maxima distinguishes 0 < x < 1 from x < 0 and x > 1.
543 * This has to be checked in more detail.
544 * For this case we have no examples for specific values of a and b, because
545 * the order and degree of the legendre function can not be an integer at
546 * the same time, the legendre function does not simplify to a simple result.
552 hgfred([a,b],[(a+b+1)/2],x);
553 assoc_legendre_p(b/2-a/2-1/2,-b/2-a/2+1/2,1-2*x)
554 *gamma(b/2+a/2+1/2)*(1-x)^(-b/2+(b/2+a/2-1/2)/2-a/2+1/2)*x^((-b/2-a/2+1/2)/2);
559 /* ---------- 2F1(a,b; (a+b)/2+1; z) ---------------------------------------- */
561 hgfred([a,b],[(a+b)/2+1],x); /* No solution, noun form */
562 %f[2,1]([a,b],[b/2+a/2+1],x);
564 /* ---------- 2F1(a,b; 2*b; z) ---------------------------------------------- */
566 /* Test of routine legf36 called from legfun
567 * For this case Maxima does not distinguish 0 < x< 1 from x<0 and x>1.
568 * This might be not correct. Further tests are needed.
571 result:hgfred([a,b],[2*b],x);
572 %e^-(%i*%pi*(b-a))*2^(1-(b-a)/2)*assoc_legendre_q(b-1,b-a,2/x-1)*gamma(2*b)
573 *(2/x-2)^((b-a)/2)*x^((b-a)/2-b)
574 /(gamma(b)*gamma(2*b-a));
576 /* Check for specific values */
578 /* Fails because of different phase, we expect -log(1-x)/x */
579 result - hgfred([1,1],[2*1],x), a=1, b=1, ratsimp;
582 /* Fails, we can not reproduce the expected result -3*(3*log(3)-4)/4 */
583 result - hgfred([1,2],[2*2],-2), a=1, b=2, x=-2, ratsimp;
586 /* ---------- 2F1(a,b; 1/2; z) ---------------------------------------------- */
588 hgfred([a,b],[1/2],x); /* No solution, noun form */
589 %f[2,1]([a,b],[1/2],x);
591 /* ---------- 2F1(a,a+1/2; c; z) -------------------------------------------- */
593 /* Test of routine legf24 called from legfun.
594 * Maxima distingushes x<0 and x>0. We get a problem with the phase of the
595 * result. More tests are needed.
601 result:hgfred([a,a+1/2],[c],x);
602 2^(c-1)*gamma(c)*assoc_legendre_p(c-2*a-1,1-c,1/sqrt(1-x))*(1-x)^((1-c)/-2-a)
605 /* Fails because of different sign. The expected result is (x+2)/2 */
606 result - hgfred([-3/2,-3/2+1/2],[3],x), a=-3/2, c=3, ratsimp;
612 /* ---------- 2F1(a,1-a; c; z) ---------------------------------------------- */
614 /* Test for legf14 called from legfun.
615 * Maxima distinguishes 0 < x < 1 from x>1 and x<1.
616 * We look only at the result for 0 < x < 1. More tests are needed.
622 result:hgfred([a,1-a],[c],x);
623 assoc_legendre_p(a-1,1-c,1-2*x)*gamma(c)*(1-x)^((c-1)/2)*x^((1-c)/2);
625 /* We can verify the general result for some specific values */
627 result - hgfred([2,1-2],[1],x), a=2, c=1, ratsimp;
630 result - hgfred([3,1-3],[1],x), a=3, c=1, ratsimp;
636 /* ---------- 2F1(a,2-a; c; z) ---------------------------------------------- */
638 hgfred([a,2-a],[c],x); /* No solution, noun form */
639 %f[2,1]([a,2-a],[c],x);
641 /* ---------- 2F1(a,3-a; c; z) ---------------------------------------------- */
643 hgfred([a,3-a],[c],x); /* No solution, noun form */
644 %f[2,1]([a,3-a],[c],x);
646 /* ---------- 2F1(-n,b; c; z) ----------------------------------------------- */
648 /* We have extended 2f1polys to handle symbolic negative integers.
649 * Furthermore, we can suppress the expansion of polynomials with the user
650 * flag expand_polynomials.
658 hgfred([-n,b],[c],z),expand_polynomials:false;
659 n!*jacobi_p(n,c-1,-n-c+b,1-2*z)/pochhammer(c,n);
666 /* ---------- 2F1(a,a/2+1; a/2; z) ------------------------------------------ */
668 /* Test of splitpfq */
670 hgfred([a,a/2+1],[a/2],z);
671 2*(1-z)^(-a-1)*z+1/(1-z)^a;
673 /* ---------- 2F1(a,a+1/2; 2*a-1; z) ---------------------------------------- */
677 result:hgfred([a,a+1/2],[2*a-1],z),ratsimp;
678 ((2-2*a)*2^(2*a)*z^4+sqrt(1-z)*((12*a-11)*2^(2*a)*z^3+(58-76*a)*2^(2*a)*z^2
679 +(128*a-80)*2^(2*a)*z
681 +(38*a-32)*2^(2*a)*z^3+(94-132*a)*2^(2*a)*z^2
682 +(160*a-96)*2^(2*a)*z+(32-64*a)*2^(2*a))
683 /((4-8*a)*(sqrt(1-z)+1)^(2*a)*z^4+sqrt(1-z)
684 *((32*a-16)*(sqrt(1-z)+1)^(2*a)*z^3
685 +(64-128*a)*(sqrt(1-z)+1)^(2*a)*z^2
686 +(160*a-80)*(sqrt(1-z)+1)^(2*a)*z
687 +(32-64*a)*(sqrt(1-z)+1)^(2*a))
688 +(80*a-40)*(sqrt(1-z)+1)^(2*a)*z^3
689 +(100-200*a)*(sqrt(1-z)+1)^(2*a)*z^2
690 +(192*a-96)*(sqrt(1-z)+1)^(2*a)*z
691 +(32-64*a)*(sqrt(1-z)+1)^(2*a));
693 /* A check for specific values is correct, but we do not get the simple expected
694 * result 2^(-3/2). The answer from Maxima is
695 * (3465*2^(5/2)+19601)/(19601*2^(3/2)+55440),
696 * which looks much more complicate. */
697 result - hgfred([1,1+1/2],[2*1-1],-1), a=1, z=-1, ratsimp;
700 /* ---------- 2F1(a,a+1/2; 2*a; z) ------------------------------------------ */
702 /* Test of routine hyp-cos */
704 hgfred([a,a+1/2],[2*a],z);
705 2^(2*a-1)*(sqrt(1-z)+1)^(1-2*a)/sqrt(1-z);
707 /* ---------- 2F1(a,a+1/2; 2*a+1; z) ---------------------------------------- */
709 /* Test of routine hyp-cos */
711 hgfred([a,a+1/2],[2*a+1],z);
712 2^(2*a)/(sqrt(1-z)+1)^(2*a);
714 /* ---------- 2F1(a,a+1/2; 1/2; z) ------------------------------------------ */
716 /* Test of routine trig-log */
722 hgfred([a,a+1/2],[1/2],z^2);
723 1/2*((z+1)^(-2*a)+(1-z)^(-2*a));
725 hgfred([a,a+1/2],[1/2],x);
726 (1/(sqrt(x)+1)^(2*a)+1/(1-sqrt(x))^(2*a))/2;
728 hgfred([a,a+1/2],[1/2],-x);
729 cos(2*a*atan(sqrt(x)))/(x+1)^a;
734 /* ---------- 2F1(a,a+1/2; 3/2; z) ------------------------------------------ */
737 hgfred([a,a+1/2],[3/2],z^2);
738 ((z+1)^(1-2*a)-(1-z)^(1-2*a))/2/(1-2*a)/z;
740 /* ---------- 2F1(a,-a; 1/2; z) --------------------------------------------- */
742 /* Test of trig-log */
747 hgfred([a,-a],[1/2],x);
748 cos(2*a*asin(sqrt(x)));
753 /* For a negative integer we get a polynomial */
760 hgfred([n,-n],[1/2],z);
761 chebyshev_t(n,1-2*z);
773 /* ---------- 2F1(n,m; k; z), n,m,k integers -------------------------------- */
778 /* For three integers result in terms of log(1-x) */
781 -2*(log(1-x)/x+1/x+log(1-x)*(1-x)/x^2);
784 -3*(-1/((1-x)*x)-2*log(1-x)/x^2-2/x^2-2*log(1-x)*(1-x)/x^3)*(1-x);
786 /* a or b can be a symbol declared to be an integer */
789 2*((1/x-1)/(n-1)+1)/((2-n)*x)+2*(1-x)^(2-n)/((n-2)*(n-1)*x^2);
792 2*((1/x-1)/(2-n)+1)*(1-x)^(1-n)/((n-1)*x)+2/((1-n)*(2-n)*x^2);
794 /* a,b,c integer and z=-1 */
796 hgfred([1,1],[2],-1);
799 hgfred([1,1],[3],-1);
802 hgfred([1,1],[4], -1);
805 hgfred([1,1],[5],-1);
808 hgfred([1,2],[3], -1);
811 /* a,b,c integer and z=1/2 */
813 hgfred([1,3],[2],1/2);
816 hgfred([1,4],[2],1/2);
819 hgfred([1,4],[3],1/2);
822 hgfred([1,5],[2],1/2);
825 /* a,b,c integer and z=1 */
833 /* Bug ID: 1869296 - hgfred([1,2],[6],1) bogus*/
838 /* ---------- More tests ---------------------------------------------------- */
840 /* Tests of confluent hypergeometric function */
843 /* Bessel functions */
849 expand(hgfred([1],[2],-2*%i*z));
853 expand(hgfred([1],[2],2*z));
857 hgfred([1/2],[3/2],-z^2);
858 sqrt(%pi)/2/abs(z)*erf(abs(z))$
861 hgfred([1],[3/2],z^2);
862 sqrt(%pi)*exp(z^2)*erf(abs(z))/2/abs(z)$
864 /* Hypergeometric function 2F1 tests
874 hgfred([1/2,1], [3/2], z^2);
875 log((1+z)/(1-z))/(2*z)$
878 hgfred([1/2,1], [3/2], -z^2);
882 hgfred([1/2,1/2], [3/2], z^2);
885 hgfred([1,1], [3/2], z^2);
886 asin(z)/z/sqrt(1-z^2)$
889 hgfred([1/2,1/2], [3/2], -z^2);
890 log(z+sqrt(1+z^2))/z$
892 hgfred([1,1], [3/2], -z^2);
893 log(z+sqrt(1+z^2))/z/sqrt(1+z^2)$
900 hgfred([-a,a],[1/2],-z^2);
901 ((z+sqrt(1+z^2))^(2*a) + (sqrt(1+z^2)-z)^(2*a))/2$
904 hgfred([a,1-a],[1/2],-z^2);
905 ((sqrt(1+z^2)+z)^(2*a-1)+(sqrt(1+z^2)-z)^(2*a-1))/2/sqrt(1+z^2)$
908 hgfred([a,a+1/2],[1+2*a],z);
909 2^(2*a)/(1+sqrt(1-z))^(2*a)$
911 hgfred([a+1,a+1/2],[1+2*a],z);
912 2^(2*a)/(1+sqrt(1-z))^(2*a)/sqrt(1-z)$
915 hgfred([a,a+1/2],[2*a],z);
916 2^(2*a-1)/sqrt(1-z)*(1+sqrt(1-z))^(1-2*a)$
919 hgfred([a,1-a],[3/2],sin(z)^2),triginverses:all;
920 sin((1-2*a)*z)/sin(z)/(1-2*a)$
923 hgfred([a,2-a],[3/2],sin(z)^2),triginverses:all;
924 sin((2-2*a)*z)/(2-2*a)/(sin(z)*cos(z))$
927 assume(not(equal(sin(z),0)));
928 [not equal(sin(z),0)]$
930 hgfred([-a,a],[1/2],sin(z)^2),triginverses:all;
934 hgfred([a,1-a],[1/2],sin(z)^2),triginverses:all;
935 cos((2*a-1)*z)/cos(z)$
938 assume(not(equal(tan(z),0)));
939 [not equal(tan(z), 0)]$
941 hgfred([a,a+1/2],[1/2],-tan(z)^2),triginverses:all;
942 cos(z)^(2*a)*cos(2*a*z)$
948 hgfred([-n,n],[1/2],x);
949 cos(2*n*asin(sqrt(x)))$
951 hgfred([-10,10],[1/2],x),expand_polynomials:false;
952 chebyshev_t(10,1-2*x)$
960 hgfred([-n,n+1],[1],x1);
961 legendre_p(n,1-2*x1);
964 * Is there a bug in that formula?
965 * http://functions.wolfram.com/HypergeometricFunctions/LegendreP2General/26/01/02/
966 * shows the formula with (1+z) and (1-z).
968 * But this differs from formula 14 in Higher Transcendental
969 * Functions, which agrees with A&S.
973 * P(v,u,z) = (z+1)^(u/2)*(z-1)^(-u/2)/gamma(1-u)*F(-v, 1+v; 1-u,(1-z)/2)
977 * This tests the legf14 function.
981 radcan(((z1+1)/(z1-1))^(u/2)/gamma(1-u)*hgfred([-v,v+1],[1-u],(1-z1)/2));
982 assoc_legendre_p(v,u,z1)$
986 * F(a,1-a;c;x) = gamma(c)*(-x)^(1/2-c/2)*(1-x)^(c/2-1/2)*P(-a,1-c,1-2*x)
988 * This tests the legf14 function.
990 radcan(hgfred([a,1-a],[c],z1)*(-z1)^(c/2-1/2)*(1-z1)^(1/2-c/2)/gamma(c));
991 assoc_legendre_p(a-1, 1-c, 1-2*z1)$
995 * F(a,a+1/2;c;z) = 2^(c-1)*gamma(c)*z^(1/2-c/2)*(1-z)^(c/2-a-1/2)*P(2*a-c,1-c,1/sqrt(1-z))
997 * Test for legf24 function.
1001 radcan(hgfred([a,a+1/2],[c],zg1)*2^(1-c)*zg1^(c/2-1/2)*(1-zg1)^(1/2+a-c/2)/gamma(c));
1002 /* Use A&S 8.2.1 to get this */
1003 assoc_legendre_p(c-2*a-1,1-c,1/sqrt(1-zg1))$
1005 radcan(2^u*(zg1^2-1)^(-u/2)*zg1^(v+u)/gamma(1-u)*hgfred([-v/2-u/2,1/2-v/2-u/2],[1-u],1-1/zg1^2));
1006 assoc_legendre_p(v,u,zg1)$
1010 * F(a,b;a+b+1/2;z) = 2^(a+b-1/2)*gamma(a+b+1/2)*(-z)^(1/2-a-b)*P(a-b-1/2,1/2-a-b,sqrt(1-z))
1011 * Test for legf20 function.
1015 expand(ratsimp(2^(1/2-a-b)*(x2)^(1/2*(a+b-1/2))/gamma(a+b+1/2)*hgfred([a,b],[a+b+1/2],x2)));
1016 assoc_legendre_p(b-a-1/2,1/2-a-b,sqrt(1-x2))$
1018 2^m*(1-z1^2)^(-m/2)/gamma(1-m)*hgfred([1/2+n/2-m/2, -n/2-m/2], [1-m], 1-z1^2);
1019 assoc_legendre_p(n,m,z1)$
1023 * exp(-%i*m*%pi)*Q(n,m,z) =
1024 * 2^n*gamma(1+n)*gamma(1+n+m)*(z+1)^(m/2-n-1)*(z-1)^(-m/2)/gamma(2+2*n)
1025 * *hgfred([1+n-m,1+n],[2+2*n],2/(1+z))
1027 * Test for legf36 function.
1029 expand(radcan(hgfred([a,b],[2*b],z)*2^(-2*b)*sqrt(%pi)/gamma(b+1/2)*gamma(2*b-a)*z^b*(1-z)^((a-b)/2)*exp(%i*%pi*(b-a))));
1031 * Maxima doesn't expand gamma(2*b) which would cancel the other
1032 * terms, so we leave it in.
1034 2*sqrt(%pi)*assoc_legendre_q(b-1,b-a,2/z-1)*gamma(2*b)/(2^(2*b)*gamma(b)*gamma(b+1/2))$
1036 hgfred([a,b],[2*b],z) - hgfred([b,a],[2*b],z);
1039 exp(%i*%pi*u)*2^v*gamma(1+v)*gamma(1+v+u)*(z+1)^(u/2-v-1)*(z-1)^(-u/2)/gamma(2+2*v)*hgfred([1+v-u,1+v],[2+2*v],2/(1+z));
1040 assoc_legendre_q(v, u, z)$
1045 * F(a,b;a-b+1;z) = gamma(a-b+1)*z^(b/2-a/2)*(1-z)^(-b)*P(-b,b-a,(1+z)/(1-z))
1047 * Test for legf16 function
1051 hgfred([a,b],[a-b+1],zp1);
1052 gamma(-b+a+1)*assoc_legendre_p(b-1,b-a,(1+zp1)/(1-zp1))*zp1^((b-a)/2)*(1-zp1)^(-b)$
1055 * Test for legf16 function
1057 2^(-v)*(zp1+1)^(u/2+v)*(zp1-1)^(-u/2)/gamma(1-u)*ratsimp(hgfred([-v,-v-u],[1-u],(zp1-1)/(zp1+1)));
1058 assoc_legendre_p(v, u, zp1)$
1060 /* Regression tests */
1064 /* F([...,0,...],[non-zero], z) is 1 */
1065 hgfred([a,0],[c], z);
1068 /* F([non-zero],[...,zero or neg integer,...],z) is undefined */
1069 hgfred([a,b],[0],z);
1070 %f[2,1]([a,b],[0],z)$
1072 hgfred([a,b],[c,4,-3],z);
1073 %f[2,3]([a,b],[c,4,-3],z)$
1075 /* F([...,neg integer,...],[...],z) is a polynomial */
1078 /* Test 2F1 polynomials */
1080 hgfred([-2,1],[1/2],z);
1081 /*8*jacobi_p(2,-1/2,-3/2,1-2*z)/3$*/
1084 /* F(a,b;c;z) = F(b,a;c;z) */
1085 hgfred([1,2],[3],z);
1086 -2*(log(1-z)/z+1/z+log(1-z)*(1-z)/z^2)$
1088 hgfred([1,2],[3],z)-hgfred([2,1],[3],z);
1092 * Test F(a,b;c;z) for some integral values of a,b,c.
1093 * These can all be written in terms of F(1,1;2;z).
1098 * diff((1-z)^(a+b-c)*F(a,b;c;z),z,n) = poch(c-a,n)*poch(c-b,n)/poch(c,n)*
1099 * (1-z)^(a+b-c-n)*F(a,b;c+n;z)
1101 * With a=b=1 and c = 2, we have
1103 * diff(F(1,1;2;z),z,n) = poch(1,n)*poch(1,n)/poch(2,n)*(1-z)^(-n)*F(1,1;2+n,z)
1105 * And A&S 15.1.3 says F(1,1;2;z) = -log(1-z)/z.
1107 * So F(1,1;2+n;z) = diff(F(1,1;2;z),z,n)*(1-z)^n*poch(2,n)/poch(1,n)/poch(1,n)
1109 * F(1,1;3;z) = diff(F(1,1;2;z),z,1)*(1-z)*2/1!/1!
1110 * = 2*(1-z)*diff(F(1,1;2;z),z,1)
1111 * F(1,1;4;z) = diff(F(1,1;2;z),z,2)*(1-z)^2*(2*3)/2!/2!
1112 * = 3/2*(1-z)^2*diff(F(1,1;2;z),z,2);
1115 hgfred([1,1],[3],z);
1116 2*(1/((1-z)*z)+log(1-z)/z^2)*(1-z)$
1118 hgfred([1,1],[4],z);
1119 3*(1/((1-z)^2*z)-2/((1-z)*z^2)-2*log(1-z)/z^3)*(1-z)^2/2$
1123 * diff((1-z)^(a+n-1)*F(a,b;c;z),z,n)
1124 * = (-1)^n*poch(a,n)*poch(c-b,n)/poch(c,n)*(1-z)^(a-1)*F(a+n,b;c+n;z)
1127 * F(a+n,b;c+n;z) = (-1)^n*poch(c,n)/poch(a,n)/poch(c-b,n)*(1-z)^(1-a)
1128 * *diff((1-z)^(a+n-1)*F(a,b;c;z),z,n)
1131 * F(1+n,1;2+n;z) = (-1)^n*poch(2,n)/n!/n!*diff((1-z)^n*F(1,1;2;z),z,n)
1133 * F(2,1;3;z) = -1*2*diff((1-z)*F(1,1;2;z),z,1)
1134 * F(3,1;4;z) = (2*3)/2!/2!*diff((1-z)^2*F(1,1;2;z),z,2)
1136 hgfred([2,1],[3],z);
1137 -2*(log(1-z)/z+1/z+log(1-z)*(1-z)/z^2)$
1139 hgfred([3,1],[4],z);
1140 3*(-2*log(1-z)/z-3/z-4*log(1-z)*(1-z)/z^2-2*(1-z)/z^2
1141 -2*log(1-z)*(1-z)^2/z^3)
1146 * diff(F(a,b;c;z),z,n) = poch(a,n)*poch(b,n)/poch(c,n)*F(a+n,b+n;c+n;z)
1150 * F(a+n,b+n;c+n;z) = poch(c,n)/poch(a,n)/poch(b,n)*diff(F(a,b;c;z),z,n)
1152 * F(1+n,1+n;2+n;z) = poch(2,n)/n!/n!*diff(F(1,1;2;z),z,n)
1154 * F(2,2;3;z) = 2*diff(F(1,1;2;z),z,1);
1155 * F(3,3;4;z) = 2*3/2!/2!*diff(f(1,1;2;z),z,2)
1158 hgfred([2,2],[3],z);
1159 2*(1/((1-z)*z)+log(1-z)/z^2)$
1161 hgfred([3,3],[4],z);
1162 3*(1/((1-z)^2*z)-2/((1-z)*z^2)-2*log(1-z)/z^3)/2$
1166 * F(a,b;c;z) = A*z^(-a)*F(a,a-c+1;a+b-c+1;1-1/z)
1167 * + B*(1-z)^(c-a-b)*z^(a-c)*F(c-a,1-a;c-a-b+1,1-1/z)
1169 * where A = gamma(c)*gamma(c-a-b)/gamma(c-a)/gamma(c-b)
1170 * B = gamma(c)*gamma(a+b-c)/gamma(a)/gamma(b)
1172 * F(2,b;3;z) = A*z^(-2)*F(2,0;b;1-1/z) + B*(1-z)^(1-b)*z^(-1)*F(1,-1;2-b;1-1/z)
1173 * where A = gamma(3)*gamma(1-b)/gamma(1)/gamma(3-b) = 2*gamma(1-b)/gamma(3-b)
1174 * B = gamma(3)*gamma(b-1)/gamma(2)/gamma(b) = 2*gamma(b-1)/gamma(b)
1176 * And we know that F(2,0;b;1-1/z) = 1 and
1177 * F(1,-1;2-b;1-1/z) = jacobi_p(1,1-b,b-2,1-2*(1-1/z))/(2-b).
1179 * This tests geredf in hyp.lisp.
1182 declare(ia,integer,ib,integer,ic,integer);
1185 hgfred([2,ib],[3],z),gamma_expand:true; /*Expand gamma function */
1186 /*2*jacobi_p(1,1-ib,ib-2,1-2*(1-1/z))*gamma(ib-1)*(1-z)^(1-ib)/((2-ib)*gamma(ib)*z)
1187 +2*gamma(1-ib)/(gamma(3-ib)*z^2)$*/
1188 2*((1/z-1)/(2-ib)+1)*(1-z)^(1-ib)/((ib-1)*z)+2/((1-ib)*(2-ib)*z^2);
1191 * Test of step4, which handles F(a,b;c;z) when a+b is an integer and
1192 * c + 1/2 is an integer.
1200 * First test. F(a,-a;3/2;z)
1201 * A&S 15.2.6 tells us how to compute this:
1203 * diff((1-z)^(a+b-c)*F(a,b;c;z),z,n)
1204 * = poch(c-a,n)*poch(c-b,n)/poch(c,n)*(1-z)^(a+b-c-n)*F(a,b;c+n;z)
1208 * diff((1-z)^(-1/2)*F(a,-a;1/2;z),z,1)
1209 * = poch(1/2-a,1)*poch(1/2+a,n)/poch(1/2,n)*(1-z)^(-3/2)*F(a,-a;3/2;z)
1210 * = (1/2-a)*(1/2+a)/(1/2)*(1-z)^(-3/2)*F(a,-a;3/2;z)
1213 * F(a,-a;3/2;z) = (1-z)^(3/2)*2/(1/2-a)/(1/2+a)*diff((1-z)^(-1/2)*F(a,-a;1/2;z),z,1)
1215 * A&S 15.1.11 and 15.1.17 tells us what F(a,-a;1/2;z) is.
1218 hgfred([-a,a],[3/2],zn)-(1-zn)^(3/2)*(1/2)/(1/2-a)/(1/2+a)*diff((1-zn)^(-1/2)*hgfred([-a,a],[1/2],zn),zn,1);
1226 * diff(z^(a+n-1)*F(a,b;c;z),z,n) = poch(a,n)*z^(a-1)*F(a+n,b;c;z)
1230 * F(a+n,b;c;z) = z^(1-a)/poch(a,n)*diff(z^(a+n-1)*F(a,b;c;z),z,n)
1232 * In this case, we have
1234 * F(a+2,-a;1/2;z) = z^(1-a)/poch(a,2)*diff(z^(a+1)*F(a,-a;c;z),z,2)
1236 hgfred([a+2,-a],[1/2],zn)-zn^(1-a)/(a*(a+1))*diff(zn^(a+1)*hgfred([a,-a],[1/2],zn),zn,2);
1246 * diff(z^(c-a+m-1)*(1-z)^(a+b-c)*F(a,b;c;z),z,m)
1247 * = poch(c-a,m)*z^(c-a-1)*(1-z)^(a+b-c-m)*F(a-m,b;c;z)
1251 * diff(z^(1/2-a)*(1-z)^(-1/2)*F(a,-a;1/2;z),z,1)
1252 * = poch(1/2-a,1)*z^(-a-1/2)*(1-z)^(-3/2)*F(a-1,-a;1/2;z)
1255 * = (1-z)^(3/2)*z^(a+1/2)/(1/2-a)*diff(z^(1/2-a)*(1-z)^(-1/2)*F(a,-a;1/2;z),z,1)
1258 ratsimp(hgfred([a-1,-a],[1/2],zn)-(1-zn)^(3/2)*zn^(a+1/2)/(1/2-a)*diff(zn^(1/2-a)*(1-zn)^(-1/2)*hgfred([a,-a],[1/2],zn),zn,1));
1266 * diff(z^(c-1)*F(a,b;c;z),z,n) = poch(c-n,n)*z^(c-n-1)*F(a,b;c-n;z)
1269 * diff(z^(a+m-1)*F(a,b;c;z),z,m) = poch(a,n)*z^(a-1)*F(a+n,b;c;z)
1272 * diff(z^(-1/2)*F(a,-a;1/2;z),z,1) = poch(1/2-1,1)*z^(1/2-1-1)*F(a,-a;-1/2;z)
1274 * F(a,-a;-1/2;z) = z^(3/2)/poch(-1/2,1)*diff(z^(-1/2)*F(a,-a;1/2;z),z,1)
1277 ratsimp(hgfred([a,-a],[-1/2],zn) - zn^(3/2)/(-1/2)*diff(zn^(-1/2)*hgfred([a,-a],[1/2],zn),zn,1));
1285 * diff(z^(c-1)*F(a,b;c;z),z,n)
1286 * = poch(c-n,n)*z^(c-n-1)*F(a;b;c-n;z)
1289 * diff(z^(c-1)*(1-z)^(b-c+n)*F(a,b;c;z),z,n)
1290 * - poch(c-n,n)*z^(c-n-1)*(1-z)^(b-c)*F(a-n,b;c-n;z)
1293 * diff(z^(-1/2)*(1-z)^(-a+1/2)*F(a,-a;1/2;z),z,1)
1294 * = poch(-1/2,1)*z^(-3/2)*(1-z)^(-a-1/2)*F(a-1,-a;-1/2;z)
1296 * F(a-1,-a;-1/2;z) = z^(3/2)*(1-z)^(a+1/2)/poch(-1/2,1)*diff(z^(-1/2)*(1-z)^(-a+1/2)*F(a,-a;1/2;z),z,1)
1299 ratsimp(hgfred([a-1,-a],[-1/2],zn) - zn^(3/2)*(1-zn)^(a+1/2)/(-1/2)*diff(zn^(-1/2)*(1-zn)^(-a+1/2)*hgfred([a,-a],[1/2],zn),zn,1));
1307 * diff(z^(c-a+n-1)*(1-z)^(a+b-c)*F(a,b;c;z),z,n)
1308 * = poch(c-a,n)*z^(c-a-1)*(1-z)^(a+b-c-n)*F(a-n,b;c;z)
1311 * diff(z^(c-1)*(1-z)^(b-c+n)*F(a,b;c;z),z,n)
1312 * = poch(c-n,n)*z^(c-n-1)*(1-z)^(b-c)*F(a-n,b;c-n;z)
1316 * diff(z^(-a+1-1/2)*(1-z)^(-1/2)*F(a,-a;1/2;z),z,1)
1317 * = poch(1/2-a,1)*z^(-a-1/2)*(1-z)^(-1/2-1)*F(a-1,-a;1/2;z)
1318 * = (1/2-a)*z^(-a-1/2)*(1-z)^(-3/2)*F(a-1,-a;-1/2;z)
1320 * diff(z^(-1/2)*(1-z)^(-a-1/2+1)*F(a-1,-a;1/2;z),z,1)
1321 * = poch(1/2-1,1)*z^(-1-1/2)*(1-z)^(-a-1/2)*F(a-2,-a;-1/2;z)
1322 * = -1/2*z^(-3/2)*(1-z)^(-a-1/2)*F(a-2,-a;-1/2;z)
1325 * G(z) = z^(-a-1/2)*(1-z)^(-3/2)*F(a-1,-a;1/2;z)
1326 * = (1/2-a)^(-1)*diff(z^(-a+1/2)*(1-z)^(-1/2)*F(a,-a;1/2;z),z,1)
1329 * = z^(3/2)*(1-z)^(a+1/2)/(-1/2)
1330 * *diff(z^(-1/2)*(1-z)^(-a+1/2)*F(a-1,-a;1/2;z),z,1)
1331 * = z^(3/2)*(1-z)^(a+1/2)/(-1/2)
1332 * *diff(z^a*(1-z)^(2-a)*G(z),z,n)
1335 ratsimp(hgfred([a-2,-a],[-1/2],zn) -
1336 zn^(3/2)*(1-zn)^(a+1/2)/(-1/2)*(1/2-a)^(-1)*
1337 diff(zn^a*(1-zn)^(2-a)
1338 *diff(zn^(-a+1/2)*(1-zn)^(-1/2)*hgfred([a,-a],[1/2],zn),zn,1)
1345 * This is easily derived from F(1,1;3/2;z) via A&S 15.2.3:
1347 * diff(z^(a+n-1)*F(a,b;c;z),z,n) = poch(a,n)*z^(a-1)*F(a+n,b;c;z)
1349 * And from A&S 15.1.6, F(1,1;3/2;z^2) = asin(z)/z/sqrt(1-z^2).
1352 * diff(z*F(1,1;3/2;z),z,1) = poch(1,1)*F(2,1;3/2;z)
1357 /* Tests step4-int */
1358 hgfred([1,2],[3/2],zn) - diff(zn*hgfred([1,1],[3/2],zn),zn,1);
1362 * Some tests of splitpfq
1368 * diff(z^(a+n-1)*F(a,b;c;z),z,n) = poch(a,n)*z^(a-1)*F(a+n,b;c;z)
1372 * F(a+n,b;c;z) = z^(1-a)/poch(a,n)*diff(z^(a+n-1)*F(a,b;c;z),z,n)
1376 * F(a+3,b;a+2;z) = z^(1-a-2)/poch(a+2,1)*diff(z^(a+2+1-1)*F(a+2;b;a+2;z),z,1)
1377 * = z^(-1-a)/(a+2)*diff(z^(a+2)*F(b;;z),z,1)
1378 * F(b;;z) = (1-z)^(-b)
1380 * F(a+3,b;a+2,z) = z^(-1-a)/(a+2)*diff(z^(a+2)*(1-z)^(-b),z,1)
1382 multthru(hgfred([a+3,b],[a+2],z));
1383 b*(1-z)^(-b-1)*z/(a+2)+1/(1-z)^b$
1386 * F(a+4,b;a+2;z) = z^(1-a-2)/poch(a+2,2)*diff(z^(a+2+2-1)*F(a+2;b;a+2;z),z,2)
1387 * = z^(-1-a)/(a+2)/(a+3)*diff(z^(a+3)*F(b;;z),z,2)
1390 ratsimp(hgfred([b,a+4],[a+2],z)-
1391 (b*(b+1)*(1-z)^(-b-2)*z^2/((a+2)*(a+3))
1392 +2*b*(1-z)^(-b-1)*z/(a+2)+1/(1-z)^b));
1396 * Bug 1155241: F(1/2,-1/2;3/2,z)
1398 * Applying A&S 15.3.3 gives
1400 * F(1/2,-1/2;3/2,z) = (1-z)^(3/2)*F(1,2;3/2;z)
1402 * And we know what F(1,2;3/2;z) is.
1404 * Alternatively, apply A&S 15.2.5 to get
1406 * diff(z*(1-z)^(-1/2)*F(1/2,1/2;3/2;z),z,1)
1407 * = (1-z)^(-3/2)*F(-1/2,1/2;3/2;z)
1409 * Both of these give the same answer:
1411 * (sqrt(1-z)*sqrt(z)+asin(sqrt(z)))/(2*sqrt(z))
1415 (assume(zp > 0), true);
1418 ratsimp(hgfred([1/2,-1/2],[3/2],zp));
1419 (sqrt(1-zp)*sqrt(zp)+asin(sqrt(zp)))/(2*sqrt(zp))$
1426 * F(s,s+1/2;2*s+2;z) can be derived from F(s,s+1/2;2*s+1;z) via
1429 * F(a,b;c+n;z) = poch(c,n)/poch(c-a,n)/poch(c-b,n)*(1-z)^(c+n-a-b)
1430 * *diff((1-z)^(a+b-c)*F(a,b;c;z)),z,n)
1432 * F(s,s+1/2;2*s+2;z)
1433 * = (2*s+1)/(s+1)/(s+1/2)*(1-z)^(3/2)
1434 * *diff((1-z)^(-1/2)*F(s,s+1/2;2*s+1;z),z,1)
1438 hgfred([s,s+1/2],[2*s+2],z)
1439 - (2*s+1)/(s+1)/(s+1/2)*(1-z)^(3/2)
1440 *diff((1-z)^(-1/2)*hgfred([s,s+1/2],[2*s+1],z),z,1);
1443 hgfred([s,s+1/2],[2*s+2],z) - hgfred([s+1/2,s],[2*s+2],z);
1447 * F(s+2,s+1/2;2*s+1;z) can be derived from F(s,s+1/2;2*s+1;z) via
1450 * F(a+n,b;c;z) = z^(1-a)/poch(a,n)*diff(z^(a+n-1)*fun,z,n)
1452 * F(s+2,s+1/2;2*s+1;z)
1453 * = z^(1-s)/(s*(s+1))*diff(z^(s+1)*F(s,s+1/2;2*s+1;z),z,2)
1457 hgfred([s+2,s+1/2],[2*s+1],z)
1458 - z^(1-s)/s/(s+1)*diff(z^(s+1)*hgfred([s,s+1/2],[2*s+1],z),z,2);
1461 hgfred([s+2,s+1/2],[2*s+1],z)-hgfred([s+1/2,s+2],[2*s+1],z);
1465 * F(s-1,s+1/2;2*s+1;z) can be derived from F(s,s+1/2;2*s+1;z) via
1468 * F(a-n,b;c;z) = 1/poch(c-a,n)*z^(1+a-c)*(1-z)^(c+n-a-b)
1469 * *diff(z^(c-a+n-1)*(1-z)^(a+b-c)*F(a,b;c;z),z,n)
1471 * F(s-1,s+1/2;2*s+1;z)
1472 * = 1/(s+1)*z^(-s)*(1-z)^(3/2)
1473 * *diff(z^(s+1)*(1-z)^(-1/2)*F(s,s+1/2;2*s+1;z),z,1)
1477 hgfred([s-1,s+1/2],[2*s+1],z)
1478 - 1/(s+1)*z^(-s)*(1-z)^(3/2)
1479 *diff(z^(s+1)*(1-z)^(-1/2)*hgfred([s,s+1/2],[2*s+1],z),z,1);
1482 hgfred([s-1,s+1/2],[2*s+1],z) - hgfred([s+1/2,s-1],[2*s+1],z);
1486 * F(s-1,s+1/2;2*s+2;z) can be derived from F(s,s+1/2;2*s+1;z) via
1489 * F(a-n,b;c;z) = 1/poch(c-a,n)*z^(1+a-c)*(1-z)^(c+n-a-b)
1490 * *diff(z^(c-a+n-1)*(1-z)^(a+b-c)*F(a,b;c;z),z,n)
1494 * F(a,b;c+n;z) = poch(c,n)/poch(c-a,n)/poch(c-b,n)*(1-z)^(c+n-a-b)
1495 * *diff((1-z)^(a+b-c)*F(a,b;c;z)),z,n)
1498 * F(s-1,s+1/2;2*s+2;z)
1499 * = 1/(s+2)*z^(-s-1)*(1-z)^(5/2)
1500 * *diff(z^(s+2)*(1-z)^(-3/2)*F(s,s+1/2;2*s+2;z)),z,1)
1502 * F(s,s+1/2;2*s+2;z)
1503 * = (2*s+1)/(s+1)/(s+1/2)*(1-z)^(3/2)
1504 * *diff((1-z)^(-1/2)*F(s,s+1/2;2*s+1;z),z,1)
1507 hgfred([s-1,s+1/2],[2*s+2],z)
1508 - 1/(s+2)*z^(-s-1)*(1-z)^(5/2)
1509 *diff(z^(s+2)*(1-z)^(-3/2)
1510 *(2*s+1)/(s+1)/(s+1/2)*(1-z)^(3/2)
1511 *diff((1-z)^(-1/2)*hgfred([s,s+1/2],[2*s+1],z),z,1)
1515 hgfred([s-1,s+1/2],[2*s+2],z) - hgfred([s+1/2,s-1],[2*s+2],z);
1520 /* Table of Integral Transforms */
1521 /* Formula 36, p 147 */
1522 specint(exp(-a*exp(-t))*exp(-p*t),t);
1523 a^(-p)*gamma_incomplete_lower(p,a)$
1525 /* Formula 37, p 147 */
1526 specint(exp(-a*exp(t))*exp(-p*t),t);
1527 a^p*gamma_incomplete(-p,a)$
1529 /* Formula 16, p 217 */
1530 (assume(2*v+2*u+1>0),true);
1532 (assume(2*v-2*u+1>0),true);
1534 specint(t^(v-1)*%w[k,u](a*t)*exp(-p*t),t);
1535 a^(u+1/2)*(p+a/2)^(-v-u-1/2)*gamma(v-u+1/2)*gamma(v+u+1/2)
1536 *%f[2,1]([v+u+1/2,u-k+1/2],[v-k+1],(p-a/2)/(p+a/2))
1541 * Formula 24, p. 178.
1542 * The symbol %ei has gone. The new function is expintegral_ei.
1544 specint(expintegral_ei(t)*exp(-p*t),t);
1548 * Formula 25, p. 178
1550 * t^(-1/2)*expintegral_ei(-t)
1551 * -> -2*%pi/sqrt(p)*log(sqrt(p)+sqrt(p+1))
1552 * This is equivalent to:
1553 * -> -2*%pi/sqrt(p)*asinh(sqrt(p))
1555 * The result of Maxima is equivalent to
1556 * -> -2*sqrt(%pi)/sqrt(p)*asinh(sqrt(p))
1558 * This differs by a factor sqrt(%pi) from the result above.
1559 * I (DK) think Maxima is correct.
1561 * Maxima will ask for the sign of 2*psey-1.
1562 * We add this fact to the database and get the a result.
1564 (assume(2*?psey-1>0),done);
1566 ratsimp(specint(t^(-1/2)*expintegral_ei(-t)*exp(-p*t),t));
1567 -sqrt(%pi)*(log(sqrt(p+1)+sqrt(p))-log(sqrt(p+1)-sqrt(p)))/sqrt(p);
1568 (forget(2*?psey-1>0),done);
1572 * Formula 26, p. 178
1575 * -> -(p^2+a^2)^(-1)*(a/2*log((p+1)^2+a^2) - p*atan(a/(p+1)))
1577 ratsimp(rectform(specint(sin(a*t)*expintegral_ei(-t)*exp(-p*t),t)));
1578 (2*p*atan(a/(p+1))-a*log(p^2+2*p+a^2+1))/(2*p^2+2*a^2);
1581 * Formula 27, p. 178
1584 * -> -(p^2+a^2)^(-1)*(p/2*log((p+1)^2+a^2) + a*atan(a/(p+1)))
1586 ratsimp(rectform(specint(cos(a*t)*expintegral_ei(-t)*exp(-p*t),t)));
1587 -((2*a*atan(a/(p+1))+p*log(p^2+2*p+a^2+1))/(2*p^2+2*a^2));
1590 * Formula 34, p. 179
1592 * exp(b*t)*gamma_incomplete_lower(v,a*t)
1593 * -> gamma(v)*a^v*(p-b)^(-1)*(p+a-b)^(-v)
1595 (assume(p>b,v>-1),0);
1597 radcan(specint(exp(b*t)*gamma_incomplete_lower(v,a*t)*exp(-p*t),t));
1598 a^v*gamma(v+1)/((p-b)*(p-b+a)^v*v);
1603 * kbateman[0](t) -> 1/(p+1)
1606 radcan(specint(kbateman[0](t)*exp(-p*t),t));
1610 * More tests, based on special values from
1611 * http://functions.wolfram.com/HypergeometricFunctions/Hypergeometric3F2/03/
1613 * These tests mostly provided by Edmond Orignac
1615 ratsimp(hgfred([-1/2,1/2,2],[1,3/2],x)-
1616 (3/4*sqrt(1-x)+1/4*asin(sqrt(x))/sqrt(x)));
1619 ratsimp(hgfred([-1/2,1/2,2],[1,5/2],x)-
1620 (3*(sqrt(x)*sqrt(1-x)*(6*x-1)+(4*x+1)*asin(sqrt(x)))/(32*x**(3/2))));
1623 ratsimp(hgfred([-1/2,1/2,5/2],[3/2,3/2],x)-
1624 (1/3*asin(sqrt(x))/sqrt(x)+2/3*sqrt(1-x)));
1627 ratsimp(hgfred([-1/2,1,3/2],[1/2,2],x)-
1628 (2*((1+2*x)*sqrt(1-x)-1)/(3*x)));
1631 ratsimp(factor(hgfred([-1/2,1,3/2],[1/2,3],x))-
1632 (4*(-2*(2*x+3)*(1-x)**(3/2)-5*x+6)/(15*x**2)));
1635 ratsimp(factor(hgfred([-1/2,1,5/2],[1/2,1/2],x))-
1636 1/3*((8*x^2-13*x+3)/(1-x)^2-8*sqrt(x)*atanh(sqrt(x))));
1639 ratsimp(factor(hgfred([-1/2,1,5/2],[1/2,3/2],x))-
1640 1/3*((3-4*x)/(1-x)-4*sqrt(x)*atanh(sqrt(x))));
1643 ratsimp(factor(hgfred([-1/2,1,5/2],[3/2,3/2],x))-
1644 1/3*((1-2*x)*atanh(sqrt(x))/sqrt(x)+2));
1647 ratsimp(factor(hgfred([-1/2,1,3],[2,2],x))-
1648 ((2-(2-5*x)*sqrt(1-x))/(6*x)));
1652 ratsimp(hgfred([-1/2,3/2,3/2],[1/2,5/2],x)-
1653 (-3/4*asin(sqrt(x))/x**(3/2)+3*(1+x-2*x**2)/(4*sqrt(1-x)*x)));
1657 ratsimp(hgfred([-1/2,3/2,3],[5/2,2],x)-
1658 ((3*sqrt(x)*sqrt(1-x)*(10*x-1)+3*asin(sqrt(x)))/(32*x**(3/2))));
1662 * Tests for 2F1. From
1663 * http://functions.wolfram.com/HypergeometricFunctions/Hypergeometric2F1/03/06/01/
1668 hgfred([a,b],[a],z);
1671 hgfred([a,b],[b],z);
1674 ratsimp(hgfred([a,b],[b-1],z)
1675 -((1-z)^(-a-1)*(b+(a-b+1)*z-1)/(b-1)));
1679 * http://functions.wolfram.com/HypergeometricFunctions/Hypergeometric2F1/03/06/04/
1682 ratsimp(hgfred([a,a/2+1],[a/2],z)
1683 - (1-z)^(-a-1)*(z+1));
1686 hgfred([a,a+1/2],[2*a],z);
1687 2^(2*a-1)*(sqrt(1-z)+1)^(1-2*a)/sqrt(1-z);
1690 hgfred([a,a+1/2],[2*a+1],z);
1691 2^(2*a)*(sqrt(1-z)+1)^(-2*a);
1693 hgfred([a,a+1/2],[1/2],zp);
1694 ((1+sqrt(zp))^(-2*a)+(1-sqrt(zp))^(-2*a))/2;
1696 ratsimp(hgfred([a,a+1/2],[3/2],z)
1697 -((1-sqrt(z))^(1-2*a)-(sqrt(z)+1)^(1-2*a))/(2*(2*a-1)*sqrt(z)));
1700 hgfred([a,-a],[1/2],zp);
1701 cos(2*a*asin(sqrt(zp)));
1703 hgfred([a,1-a],[1/2],zp);
1704 cos((2*a-1)*asin(sqrt(zp)))/sqrt(1-zp);
1706 hgfred([a,1-a],[1],x1);
1707 legendre_p(a-1,1-2*x1);
1709 hgfred([a,1-a],[3/2],z);
1710 sin((1-2*a)*asin(sqrt(z)))/((1-2*a)*sqrt(z));
1712 hgfred([a,2-a],[3/2],z);
1713 sin((2-2*a)*asin(sqrt(z)))/((2-2*a)*sqrt(1-z)*sqrt(z));
1716 * http://functions.wolfram.com/HypergeometricFunctions/Hypergeometric2F1/03/07/01/
1719 factor(hgfred([-1/2,-1/2],[1/2],zp));
1720 asin(sqrt(zp))*sqrt(zp) + sqrt(1 - zp);
1722 ratsimp(factor(hgfred([-1/2,-1/2],[3/2],zp))-
1723 1/4*((2*zp+1)*asin(sqrt(zp))/sqrt(zp)+3*sqrt(1-zp)));
1726 ratsimp(factor(hgfred([-1/2,-1/2],[5/2],zp))-
1727 3/64/zp^(3/2)*(sqrt(1-zp)*sqrt(zp)*(1+14*zp)+(8*zp^2+8*zp-1)*asin(sqrt(zp)))
1731 ratsimp(factor(hgfred([-1/2,-1/2],[7/2],zp))-
1732 5/768/zp^(5/2)*(sqrt(1-zp)*sqrt(zp)*(-3+16*zp+92*zp^2)+3*(16*zp^3+24*zp^2-6*zp+1)*asin(sqrt(zp)))
1737 * http://functions.wolfram.com/HypergeometricFunctions/Hypergeometric2F1/03/07/02/
1740 ratsimp(factor(hgfred([-1/2,1/2],[3/2],zp))-
1741 (asin(sqrt(zp))+sqrt(zp)*sqrt(1-zp))/2/sqrt(zp)
1745 ratsimp(factor(hgfred([-1/2,1/2],[5/2],zp))-
1746 3/16/zp^(3/2)*(sqrt(1-zp)*sqrt(zp)*(1+2*zp)+(4*zp-1)*asin(sqrt(zp)))
1750 ratsimp(factor(hgfred([-1/2,1/2],[7/2],zp))-
1751 5/128/zp^(5/2)*(sqrt(1-zp)*sqrt(zp)*(3+2*zp)*(4*zp-1)+3*(8*zp^2-4*zp+1)*asin(sqrt(zp)))
1756 * http://functions.wolfram.com/HypergeometricFunctions/Hypergeometric2F1/03/07/03/
1759 hgfred([-1/2,1],[1/2],zp);
1760 1-sqrt(zp)*atanh(sqrt(zp));
1762 ratsimp(factor(hgfred([-1/2,1],[3/2],zp))-
1763 1/2*(1-(zp-1)/sqrt(zp)*atanh(sqrt(zp)))
1767 ratsimp(factor(hgfred([-1/2,1],[2],zp))-
1768 2/3/zp*(1-(1-zp)^(3/2))
1772 ratsimp(factor(hgfred([-1/2,1],[5/2],zp))-
1773 3/8/zp^(3/2)*(sqrt(zp)*(zp+1)-(zp-1)^2*atanh(sqrt(zp)))
1777 ratsimp(factor(hgfred([-1/2,1],[3],zp))-
1778 4/15/zp^2*(-2+5*zp+2*(1-zp)^(5/2))
1782 ratsimp(factor(hgfred([-1/2,1],[7/2],zp))-
1783 (-5/48/zp^(5/2)*(3*atanh(sqrt(zp))*(zp-1)^3+sqrt(zp)*(-3*zp^2-8*zp+3)))
1787 ratsimp(factor(hgfred([-1/2,1],[4],zp))-
1788 (-(2*(8*(1-zp)^(7/2)-35*zp^2+28*zp-8))/(35*zp^3))
1793 * http://functions.wolfram.com/HypergeometricFunctions/Hypergeometric2F1/03/07/04/
1796 ratsimp(factor(hgfred([-1/2,3/2],[1/2],zp))-
1801 ratsimp(factor(hgfred([-1/2,3/2],[5/2],zp))-
1802 3/8/zp^(3/2)*(sqrt(1-zp)*sqrt(zp)*(-1+2*zp)+asin(sqrt(zp)))
1806 ratsimp(factor(hgfred([-1/2,3/2],[7/2],zp))-
1807 5/32/zp^(5/2)*(sqrt(1-zp)*sqrt(zp)*(3-4*zp+4*zp^2)+(6*zp-3)*asin(sqrt(zp)))
1812 * http://functions.wolfram.com/HypergeometricFunctions/Hypergeometric2F1/03/07/05/
1815 ratsimp(factor(hgfred([-1/2,2],[1/2],zp))-
1816 (3*zp-3*(zp-1)*atanh(sqrt(zp))*sqrt(zp)-2)/2/(zp-1)
1820 ratsimp(factor(hgfred([-1/2,2],[1],zp))-
1821 (2-3*zp)/2/sqrt(1-zp)
1825 ratsimp(factor(hgfred([-1/2,2],[3/2],zp))-
1826 1/4*((1-3*zp)/sqrt(zp)*atanh(sqrt(zp))+3)
1830 ratsimp(factor(hgfred([-1/2,2],[3],zp))-
1831 4/15/zp^2*(sqrt(1-zp)*(zp-1)*(2+3*zp)+2)
1835 ratsimp(factor(hgfred([-1/2,2],[5/2],zp))-
1836 1/16/zp^(3/2)*(3*sqrt(zp)*(3*zp-1)+(-9*zp^2+6*zp+3)*atanh(sqrt(zp)))
1840 ratsimp(factor(hgfred([-1/2,2],[4],zp))-
1841 8/35/zp^3*(-4+7*zp+sqrt(1-zp)*(zp-1)^2*(4+3*zp))
1845 ratsimp(factor(hgfred([-1/2,2],[7/2],zp))-
1846 (-5/32/zp^(5/2)*(3*(zp+1)*atanh(sqrt(zp))*(zp-1)^2+sqrt(zp)*(-3*zp^2+2*zp-3)))
1851 * http://functions.wolfram.com/HypergeometricFunctions/Hypergeometric2F1/03/07/06/
1854 ratsimp(factor(hgfred([-1/2,5/2],[1/2],zp))-
1855 (8*zp^2-12*zp+3)/3/(1-zp)^(3/2)
1859 ratsimp(factor(hgfred([-1/2,5/2],[3/2],zp))-
1860 (3-4*zp)/3/sqrt(1-zp)
1864 ratsimp(factor(hgfred([-1/2,5/2],[7/2],zp))-
1865 5/48/zp^(5/2)*(sqrt(1-zp)*sqrt(zp)*(1+2*zp)*(-3+4*zp)+3*asin(sqrt(zp)))
1870 * http://functions.wolfram.com/HypergeometricFunctions/Hypergeometric2F1/03/07/07/
1873 ratsimp(factor(hgfred([-1/2,3],[1/2],zp))-
1874 (-15*sqrt(zp)*atanh(sqrt(zp))*(zp-1)^2+15*zp^2-25*zp+8)/8/(zp-1)^2
1878 ratsimp(factor(hgfred([-1/2,3],[1],zp))-
1879 (15*zp^2-24*zp+8)/8/(1-zp)^(3/2)
1883 ratsimp(factor(hgfred([-1/2,3],[3/2],zp))-
1884 (sqrt(zp)*(15*zp-13)-3*(5*zp^2-6*zp+1)*atanh(sqrt(zp)))/16/(zp-1)/sqrt(zp)
1888 ratsimp(factor(hgfred([-1/2,3],[2],zp))-
1889 (4-5*zp)/4/sqrt(1-zp)
1893 ratsimp(factor(hgfred([-1/2,3],[5/2],zp))-
1894 3/64/zp^(3/2)*(sqrt(zp)*(15*zp-1)+(-15*zp^2+6*zp+1)*atanh(sqrt(zp)))
1898 ratsimp(factor(hgfred([-1/2,3],[7/2],zp))-
1899 (-5/128/zp^(5/2)*(sqrt(zp)*(-15*zp^2+4*zp+3)+3*(5*zp^3-3*zp^2-zp-1)*atanh(sqrt(zp))))
1903 ratsimp(factor(hgfred([-1/2,3],[4],zp))-
1904 2/35/zp^3*(8-(1-zp)^(3/2)*(8+12*zp+15*zp^2))
1909 * http://functions.wolfram.com/HypergeometricFunctions/Hypergeometric2F1/03/07/08/
1912 ratsimp(factor(hgfred([-1/2,7/2],[1/2],zp))-
1913 (5-30*zp+40*zp^2-16*zp^3)/5/(1-zp)^(5/2)
1917 ratsimp(factor(hgfred([-1/2,7/2],[3/2],zp))-
1918 (24*zp^2-40*zp+15)/15/(1-zp)^(3/2)
1922 ratsimp(factor(hgfred([-1/2,7/2],[5/2],zp))-
1923 (5-6*zp)/5/sqrt(1-zp)
1928 * http://functions.wolfram.com/HypergeometricFunctions/Hypergeometric2F1/03/07/09/
1931 ratsimp(factor(hgfred([-1/2,4],[1/2],zp))-
1932 1/48/(zp-1)^3*(-105*sqrt(zp)*atanh(sqrt(zp))*(zp-1)^3+105*zp^3-280*zp^2+231*zp-48)
1936 ratsimp(factor(hgfred([-1/2,4],[1],zp))-
1937 (16-72*zp+90*zp^2-35*zp^3)/16/(1-zp)^(5/2)
1941 ratsimp(factor(hgfred([-1/2,4],[3/2],zp))-
1942 (sqrt(zp)*(105*zp^2-190*zp+81)-15*(zp-1)^2*(7*zp-1)*atanh(sqrt(zp)))/96/(zp-1)^2/sqrt(zp)
1946 ratsimp(factor(hgfred([-1/2,4],[2],zp))-
1947 (35*zp^2-60*zp+24)/24/(1-zp)^(3/2)
1951 ratsimp(factor(hgfred([-1/2,4],[5/2],zp))-
1952 (sqrt(zp)*(105*zp^2-100*zp+3)-3*(35*zp^3-45*zp^2+9*zp+1)*atanh(sqrt(zp)))/128/(zp-1)/zp^(3/2)
1956 ratsimp(factor(hgfred([-1/2,4],[3],zp))-
1957 (6-7*zp)/6/sqrt(1-zp)
1961 ratsimp(factor(hgfred([-1/2,4],[7/2],zp))-
1962 5/768/zp^(5/2)*(sqrt(zp)*(105*zp^2-10*zp-3)-3*(35*zp^3-15*zp^2-3*zp-1)*atanh(sqrt(zp)))
1967 * http://functions.wolfram.com/HypergeometricFunctions/Hypergeometric2F1/03/07/20/
1970 ratsimp(factor(hgfred([1/2,1],[-1/2],zp))-
1975 hgfred([1/2,1],[3/2],zp);
1976 log((sqrt(zp)+1)/(1-sqrt(zp)))/(2*sqrt(zp));
1978 ratsimp(factor(hgfred([1/2,1],[2],zp))-
1983 ratsimp(factor(hgfred([1/2,1],[5/2],zp))-
1984 3/2/zp^(3/2)*((zp-1)*atanh(sqrt(zp))+sqrt(zp))
1988 ratsimp(factor(hgfred([1/2,1],[3],zp))-
1989 (-4/3/zp^2*((2*sqrt(1-zp)-3)*zp-2*sqrt(1-zp)+2))
1993 ratsimp(factor(hgfred([1/2,1],[7/2],zp))-
1994 5/8/zp^(5/2)*(3*atanh(sqrt(zp))*(zp-1)^2+sqrt(zp)*(5*zp-3))
1998 ratsimp(factor(hgfred([1/2,1],[4],zp))-
1999 (2*(-8*(1-zp)^(5/2)+15*zp^2-20*zp+8))/5/zp^3
2004 * http://functions.wolfram.com/HypergeometricFunctions/Hypergeometric2F1/03/07/22/
2007 factor(hgfred([1/2,2],[-1/2],z));
2010 ratsimp(factor(hgfred([1/2,2],[1],zp))-
2011 (2-zp)/2/(1-zp)^(3/2)
2015 ratsimp(factor(hgfred([1/2,2],[3/2],zp))-
2016 1/2*(atanh(sqrt(zp))/sqrt(zp)+1/(1-zp))
2020 ratsimp(factor(hgfred([1/2,2],[5/2],zp))-
2021 ((3*(zp+1)/4/zp^(3/2)*atanh(sqrt(zp))-3/4/zp))
2025 ratsimp(factor(hgfred([1/2,2],[3],zp))-
2026 4/3/zp^2*(2-(zp+2)*sqrt(1-zp))
2030 ratsimp(factor(hgfred([1/2,2],[7/2],zp))-
2031 15/16/zp^(5/2)*((zp^2+2*zp-3)*atanh(sqrt(zp))-(zp-3)*sqrt(zp))
2035 ratsimp(factor(hgfred([1/2,2],[4],zp))-
2036 8/5/zp^3*(-sqrt(1-zp)*zp^2+(5-3*sqrt(1-zp))*zp+4*sqrt(1-zp)-4)
2041 * http://functions.wolfram.com/HypergeometricFunctions/Hypergeometric2F1/03/07/24/
2044 ratsimp(hgfred([1/2,3],[-1/2],z) - (1-7*z)/(z-1)^4);
2047 ratsimp(factor(hgfred([1/2,3],[1],z))-
2048 (3*z^2-8*z+8)/8/(1-z)^(5/2)
2052 ratsimp(factor(hgfred([1/2,3],[3/2],zp))-
2053 (3*atanh(sqrt(zp))*(zp-1)^2+sqrt(zp)*(5-3*zp))/8/(zp-1)^2/sqrt(zp)
2057 ratsimp(factor(hgfred([1/2,3],[2],zp))-
2058 (4-3*zp)/4/(1-zp)^(3/2)
2062 ratsimp(factor(hgfred([1/2,3],[5/2],zp))-
2063 3/16/(zp-1)/zp^(3/2)*(sqrt(zp)*(1-3*zp)+(3*zp^2-2*zp-1)*atanh(sqrt(zp)))
2067 ratsimp(factor(hgfred([1/2,3],[7/2],zp))-
2068 15/64/zp^(5/2)*((3*zp^2+2*zp+3)*atanh(sqrt(zp))-3*sqrt(zp)*(zp+1))
2075 hgfred([a,b],[a,c],z);
2078 /* test with exponentials */
2080 /* Part 1: exponential times polynomial */
2082 ratsimp(factor(hgfred([3/2,3/2],[1/2,1/2],x))-
2083 exp(x)*(4*x^2+8*x+1));
2086 ratsimp(factor(hgfred([3/2,2],[1/2,1],x))-
2087 exp(x)*(2*x^2+5*x+1));
2090 ratsimp(factor(hgfred([3/2,3],[1/2,2],x))-
2091 exp(x)*(2*x^2+7*x+2)/2);
2094 ratsimp(factor(hgfred([2,2],[1,1],x))-
2095 exp(x)*(x^2+3*x+1));
2098 ratsimp(factor(hgfred([3,3],[2,2],x))-
2099 exp(x)*(x^2+5*x+4)/4);
2102 ratsimp(factor(hgfred([3,3],[1,2],x))-
2103 exp(x)*(x^3+8*x^2+14*x+4)/4);
2106 /* Part 2: exponential times rational fraction */
2108 ratsimp(factor(exponentialize(expand(block([gamma_expand:true], hgfred([1,3/2],[1/2,2],x)))))-
2109 (exp(x)*(2*x-1)+1)/x);
2112 ratsimp(factor(exponentialize(expand(block([gamma_expand:true], hgfred([1,5/2],[3/2,2],x)))))-
2113 (exp(x)*(2*x+1)-1)/(3*x));
2116 ratsimp(factor(exponentialize(expand(block([gamma_expand:true], hgfred([1,3],[2,2],x)))))-
2117 (exp(x)*(x+1)-1)/(2*x));
2121 /* test with incomplete gamma */
2123 hgfred([1/2,b],[3/2,b+1],x);
2124 b*(sqrt(%pi/x)*erfi(sqrt(x))-(-x)^(-b)*(gamma(b)-gamma_incomplete(b,-z)))/(2*b-1)$
2127 /* Note: I am unsure about Maxima notation for the incomplete gamma
2131 erfi is implemented as a simplifying function. The following definition no
2132 longer works. When erf_representation is ERF the simplifier transform erfi to
2133 a representation in terms of erf.
2134 (erfi(x) := -%i*erf(%i*x),0);
2138 erf_representation : erf;
2141 ratsimp(factor(hgfred([-1/2,3/2],[1/2,1/2],x))-
2142 (exp(x)-2*sqrt(%pi)*sqrt(x)*erfi(sqrt(x))));
2146 ratsimp(factor(hgfred([-1/2,2],[1/2,1],x))-
2147 (exp(x)-3/2*sqrt(%pi)*sqrt(x)*erfi(sqrt(x))));
2151 ratsimp(factor(hgfred([-1/2,5/2],[1/2,3/2],x))-
2152 (exp(x)-4/3*sqrt(%pi)*sqrt(x)*erfi(sqrt(x))));
2155 ratsimp(factor(hgfred([-1/2,3],[1/2,2],x))-
2156 (exp(x)-5/4*sqrt(%pi)*sqrt(x)*erfi(sqrt(x))));
2159 erf_representation : false;
2163 ratsimp(factor(hgfred([(-1)/2,1],[1/2,2],x))-
2164 (1/(3*x)*(exp(x)*(2*x+1)-2*sqrt(%pi)*erfi(sqrt(x))*x^(3/2)-1)));
2169 hgfred([(-1)/2,1],[1/2,3],x);
2170 1/(15*x^2)*(exp(x)*(8*x^2+4*x+2)-8*sqrt(%pi)*erfi(sqrt(x))*x^(5/2)-2*(5*x+3))$
2174 hgfred([(-1)/2,1],[3/2,2],x);
2175 1/(6*x)*(2*exp(x)*(x-1)+sqrt(%pi)*sqrt(x)*erfi(sqrt(x))*(3-2*x)+2)$
2179 hgfred([(-1)/2,1],[3/2,3],x);
2180 2/(15*x^2)*(exp(x)*(2*x^2-4*x-1)+sqrt(%pi)*x^(3/2)*erfi(sqrt(x))*(5-2*x)+5*z+1)$
2183 /* Tests with erf */
2184 ratsimp(factor(block([gamma_expand:true], hgfred([1,3],[1/2,2],x)))-
2185 (2*x+4+sqrt(%pi)*sqrt(x)*(2*x+5)*exp(x)*erf(sqrt(x)))/4);
2191 /* Tests with modified bessel functions I_0 and I_1 */
2194 hgfred([1,3/2],[2,2],x);
2195 2*(exp(x/2)*bessel_i(0,x/2)-1)/x$
2199 hgfred([1/2,5/2],[3/2,2],x);
2200 exp(x/2)*(3*bessel_i(0,x/2)-bessel_i(1,x/2))/3$
2204 hgfred([1/2,3],[2,2],x);
2205 exp(x/2)*(2*bessel_i(0,x/2)-bessel_i(1,x/2))/2$
2209 hgfred([-1/2,3/2],[1/2,1],x);
2210 exp(x/2)*((1-2*x)*bessel_i(0,x/2)+*x*bessel_i(1,x/2))$
2214 hgfred([(-1)/2,1],[2,2],x);
2215 1/(9*x)*(4*exp(x/2)*x*(x-2)*bessel_i(1,x/2)-2*exp(x/2)*(2*x^2-6*x+3)*bessel_i(0,x/2)+6)$
2219 hgfred([(-1)/2,1],[2,3],x);
2220 4/(45*x)*(exp(x/2)*(4*x^2-14*x+3)*bessel_i(1,x/2)-exp(x/2)*(4*x^2-18*x+15)*bessel_i(0,x/2)+15)$
2224 /* Test with exponential integral */
2227 hgfred([1,1],[2,2],x);
2228 (2*%ei(x)+log(1/x)-log(x)-2%gamma)/(2*x)$
2230 /* The above formula may be simplificated by noting
2231 log(1/x)=-log(x) for x>0; the expression might be in terms of E1 instead
2240 * http://functions.wolfram.com/HypergeometricFunctions/Hypergeometric3F2/03/08/05/
2243 factor(hgfred([-1/2,1/2,2],[1,3/2],zp));
2244 (3*sqrt(1-zp)*sqrt(zp)+asin(sqrt(zp)))/(4*sqrt(zp));
2246 ratsimp(factor(hgfred([-1/2,1/2,2],[1,5/2],zp))-
2247 3*(sqrt(1-zp)*sqrt(zp)*(6*zp-1)+(4*zp+1)*asin(sqrt(zp)))/(32*zp^(3/2)));
2251 * http://functions.wolfram.com/HypergeometricFunctions/Hypergeometric3F2/03/08/06/
2254 factor(hgfred([-1/2,1/2,5/2],[3/2,3/2],zp));
2255 (2*sqrt(1-zp)*sqrt(zp)+asin(sqrt(zp)))/(3*sqrt(zp));
2258 * http://functions.wolfram.com/HypergeometricFunctions/Hypergeometric3F2/03/08/07/
2261 ratsimp(factor(hgfred([-1/2,1/2,3],[1,3/2],zp))
2262 -(sqrt(zp)*(13-15*zp)+3*sqrt(1-zp)*asin(sqrt(zp)))/(16*sqrt(zp)*sqrt(1-zp)));
2265 ratsimp(factor(hgfred([-1/2,1/2,3],[1,5/2],zp))
2266 -(3*sqrt(1-zp)*sqrt(zp)*(30*zp-1)+3*(12*zp+1)*asin(sqrt(zp)))/(128*zp^(3/2)));
2269 factor(hgfred([-1/2,1/2,3],[3/2,2],zp));
2270 (5*sqrt(1-zp)*sqrt(zp)+3*asin(sqrt(zp)))/(8*sqrt(zp));
2272 ratsimp(factor(hgfred([-1/2,1/2,3],[5/2,2],zp))
2273 -3*(sqrt(1-zp)*sqrt(zp)*(10*zp+1)+(12*zp-1)*asin(sqrt(zp)))/(64*zp^(3/2)));
2277 * http://functions.wolfram.com/HypergeometricFunctions/Hypergeometric3F2/03/08/09/
2280 ratsimp(factor(hgfred([-1/2,1,3/2],[1/2,2],z))
2281 -2*((1+2*z)*sqrt(1-z)-1)/(3*z));
2284 ratsimp(factor(hgfred([-1/2,1,3/2],[1/2,3],z))
2285 -4*(-2*(2*z+3)*(1-z)^(3/2)-5*z+6)/(15*z^2));
2289 * http://functions.wolfram.com/HypergeometricFunctions/Hypergeometric3F2/03/08/11/
2292 ratsimp(factor(hgfred([-1/2,1,5/2],[1/2,2],z))
2293 -2*(4*z*(1-2*z)-sqrt(1-z)+1)/(9*sqrt(1-z)*z));
2296 ratsimp(factor(hgfred([-1/2,1,5/2],[1/2,3],z))
2297 -4*(-5*z+2*sqrt(1-z)*(8*z^2+4*z+3)-6)/(45*z^2));
2301 ratsimp(factor(hgfred([-1/2,1,5/2],[3/2,2],z))
2302 -2*(1-(1-4*z)*sqrt(1-z))/(9*z));
2305 ratsimp(factor(hgfred([-1/2,1,5/2],[3/2,3],z))
2306 -4*(5*z+2-2*(4*z+1)*(1-z)^(3/2))/(45*z^2));
2310 * http://functions.wolfram.com/HypergeometricFunctions/Hypergeometric3F2/03/08/13/
2312 ratsimp(factor(hgfred([-1/2,3/2,3/2],[1/2,1/2],z))
2313 -(4*z^2-6*z+1)/(1-z)^(3/2));
2316 ratsimp(factor(hgfred([-1/2,3/2,3/2],[1/2,5/2],zp))
2317 -3*(sqrt(zp)*(-2*zp^2+zp+1)-sqrt(1-zp)*asin(sqrt(zp)))/(4*sqrt(1-zp)*zp^(3/2)));
2321 * http://functions.wolfram.com/HypergeometricFunctions/Hypergeometric3F2/03/08/14/
2323 ratsimp(factor(hgfred([-1/2,3/2,2],[1/2,1],z))
2324 -(6*z^2-9*z+2)/(2*(1-z)^(3/2)));
2327 ratsimp(factor(hgfred([-1/2,3/2,2],[1/2,3],z))
2328 -4*((2*z^2+z+2)*sqrt(1-z)-2)/(5*z^2));
2331 ratsimp(factor(hgfred([-1/2,3/2,2],[1,5/2],zp))
2332 -3*(sqrt(zp)*sqrt(1-zp)*(6*zp+1)-asin(sqrt(zp)))/(16*zp^(3/2)));
2336 * http://functions.wolfram.com/HypergeometricFunctions/Hypergeometric3F2/03/08/15/
2339 ratsimp(factor(hgfred([-1/2,3/2,5/2],[1/2,1/2],z))
2340 -(-16*z^3+40*z^2-30*z+3)/(3*(1-z)^(5/2)));
2344 * http://functions.wolfram.com/HypergeometricFunctions/Hypergeometric3F2/03/08/16/
2347 ratsimp(factor(hgfred([-1/2,3/2,3],[1/2,1],z))
2348 -(-30*z^3+75*z^2-56*z+8)/(8*(1-z)^(5/2)));
2352 ratsimp(factor(hgfred([-1/2,3/2,3],[1/2,2],z))
2353 -(10*z^2-15*z+4)/(4*(1-z)^(3/2)));
2357 * http://functions.wolfram.com/HypergeometricFunctions/Hypergeometric3F2/03/08/17/
2360 ratsimp(factor(hgfred([-1/2,2,2],[1,1],z))
2361 -(9*z^2-14*z+4)/(4*(1-z)^(3/2)));
2364 ratsimp(factor(hgfred([-1/2,2,2],[1,3],z))
2365 -2*((9*z^2+2*z+4)*sqrt(1-z)-4)/(15*z^2));
2369 * http://functions.wolfram.com/HypergeometricFunctions/Hypergeometric3F2/03/08/18/
2372 ratsimp(factor(hgfred([-1/2,2,5/2],[1/2,1],z))
2373 -(2-15*z+20*z^2-8*z^3)/(2*(1-z)^(5/2)));
2376 ratsimp(factor(hgfred([-1/2,2,5/2],[1/2,3],z))
2377 -4*(-8*z^3+4*z^2+z+2*sqrt(1-z)-2)/(15*z^2*sqrt(1-z)));
2380 ratsimp(factor(hgfred([-1/2,2,5/2],[1,3/2],z))
2381 -(12*z^2-19*z+6)/(6*(1-z)^(3/2)));
2384 ratsimp(factor(hgfred([-1/2,2,5/2],[3,3/2],z))
2385 -4/(45*z^2)*((12*z^2+z+2)*sqrt(1-z)-2));
2389 * http://functions.wolfram.com/HypergeometricFunctions/Hypergeometric3F2/03/08/19/
2392 ratsimp(factor(hgfred([-1/2,2,3],[1,1],z))
2393 -(-45*z^3+114*z^2-88*z+16)/16/(1-z)^(5/2));
2397 * http://functions.wolfram.com/HypergeometricFunctions/Hypergeometric3F2/03/08/20/
2400 ratsimp(factor(hgfred([-1/2,5/2,5/2],[1/2,1/2],z))
2401 -(64*z^4-224*z^3+280*z^2-144*z+9)/9/(1-z)^(7/2));
2404 ratsimp(factor(hgfred([-1/2,5/2,5/2],[1/2,3/2],z))
2405 -(-32*z^3+80*z^2-60*z+9)/9/(1-z)^(5/2));
2408 ratsimp(factor(hgfred([-1/2,5/2,5/2],[3/2,3/2],z))
2409 -(16*z^2-26*z+9)/9/(1-z)^(3/2));
2413 * http://functions.wolfram.com/HypergeometricFunctions/Hypergeometric3F2/03/08/21/
2416 ratsimp(factor(hgfred([-1/2,5/2,3],[1/2,1],z))
2417 -(40*z^4-140*z^3+175*z^2-88*z+8)/8/(1-z)^(7/2));
2420 ratsimp(factor(hgfred([-1/2,5/2,3],[1/2,2],z))
2421 -(-40*z^3+100*z^2-75*z+12)/12/(1-z)^(5/2));
2424 ratsimp(factor(hgfred([-1/2,5/2,3],[3/2,1],z))
2425 -(-20*z^3+51*z^2-40*z+8)/8/(1-z)^(5/2));
2428 ratsimp(factor(hgfred([-1/2,5/2,3],[3/2,2],z))
2429 -(20*z^2-33*z+12)/12/(1-z)^(3/2));
2433 * http://functions.wolfram.com/HypergeometricFunctions/Hypergeometric3F2/03/08/22/
2436 ratsimp(factor(hgfred([-1/2,3,3],[1,1],z))
2437 -(225*z^4-792*z^3+1000*z^2-512*z+64)/64/(1-z)^(7/2));
2440 ratsimp(factor(hgfred([-1/2,3,3],[1,2],z))
2441 -(-75*z^3+192*z^2-152*z+32)/32/(1-z)^(5/2));
2444 ratsimp(factor(hgfred([-1/2,3,3],[2,2],z))
2445 -(25*z^2-42*z+16)/16/(1-z)^(3/2));
2448 /*******************************************************************************
2449 * Bug ID: 2847387 - hgfred([3/2,-b],[5/2],-1) bogus and
2450 * Bug ID: 2876277 - hgfred([3/2,-2],[5/2],-x) not fully simplified
2452 * Some examples to show that we get correct and simple results.
2453 * Reference: wolframalpha.com
2456 hgfred([3/2,3],[5/2],-1);
2459 hgfred([3/2,-2],[5/2],-1);
2462 hgfred([3/2,-2],[5/2],1);
2465 declare(a,noninteger);
2468 ratsimp(hgfred([a,-2],[5/2],-1));
2469 1/35*(4*a^2+32*a+35);
2471 ratsimp(hgfred([a,-2],[5/2],1));
2472 1/35*(4*a^2-24*a+35);
2474 ratsimp(hgfred([-2,1],[1/2],z));
2477 /******************************************************************************/
2479 /* Bug 3495182: hgfred([-n/2, (n-1)/2],[1],x) --> error
2481 * Just check that we don't get an error.
2484 hgfred([-n/2, (n-1)/2],[1],x);
2485 %f[2,1]([-n/2, n/2-1/2],[1],x);
2488 * Bug 3578373: hgfred([-1/2,a+1],[a+2],x);
2490 * Just check that we don't get an error about 0 to a negative exponent.
2492 hgfred([-1/2,a+1],[a+2],x);
2493 %f[2,1]([-1/2, a+1], [a+2], x);