1 /*******************************************************************************
5 * The examples show what a Maxima user can expect from the sqrt function.
6 * Examples are taken from functions.wolfram.com.
8 ******************************************************************************/
10 /* ---------- Initialization ------------------------------------------------ */
15 (reset(domain), reset(radexpand), done);
18 /* ---------- Specific values ----------------------------------------------- */
20 sqrt([0, 0.0, 0.0b0]);
23 sqrt([-1, -1.0, -1.0b0]);
24 [%i, 1.0*%i, 1.0b0*%i];
26 /* Maxima does not simplify -%i -> -(-1)^(3/4) */
28 [(-1)^(1/4), sqrt(-%i)];
30 /* --- Polarform of specific values --- */
35 polarform(sqrt([-1, %i, -%i]));
36 [%e^(%i*%pi/2), %e^(%i*%pi/4), %e^(-%i*%pi/4)];
41 /* ---------- Values at infinities ------------------------------------------ */
43 /* Only limit can handle infinities. We check this. */
45 limit([sqrt(inf), sqrt(-inf), sqrt(minf), sqrt(-minf), sqrt(infinity)]);
46 [inf, infinity, infinity, inf, infinity];
50 limit(sqrt(x),x,-inf);
52 limit(sqrt(x),x,minf);
54 limit(sqrt(x),x,-minf);
57 /* ---------- Numerical evaluation ------------------------------------------ */
59 /* Check only for some values to be sure that it works */
61 (closeto(value,compare,tol):=
64 abse:abs(value-compare),if(abse<tol) then true else abse),
68 /* --- Float precision --- */
72 0.707106781186547524400844362104849039284835937688474036588339868995366239,
78 0.899453719973933636130613791812127819163772491812606935297702716148303720 +
79 0.555892970251421171992048047897569250691057814997037061577650731037508243*%i,
85 0.500000000000000000000000000000000000000000000000000000000000000000000000 +
86 0.500000000000000000000000000000000000000000000000000000000000000000000000*%i,
92 0.555892970251421171992048047897569250691057814997037061577650731037508243 +
93 0.899453719973933636130613791812127819163772491812606935297702716148303720*%i,
99 0.707106781186547524400844362104849039284835937688474036588339868995366239*%i,
105 0.555892970251421171992048047897569250691057814997037061577650731037508243 -
106 0.899453719973933636130613791812127819163772491812606935297702716148303720*%i,
112 0.500000000000000000000000000000000000000000000000000000000000000000000000 -
113 0.500000000000000000000000000000000000000000000000000000000000000000000000*%i,
119 0.899453719973933636130613791812127819163772491812606935297702716148303720 -
120 0.555892970251421171992048047897569250691057814997037061577650731037508243*%i,
124 /* --- Bigfloat precision with fpprec 72 --- */
126 (save_fpprec: fpprec, fpprec: 72);
131 0.707106781186547524400844362104849039284835937688474036588339868995366239b0,
137 0.899453719973933636130613791812127819163772491812606935297702716148303720b0 +
138 0.555892970251421171992048047897569250691057814997037061577650731037508243b0*%i,
144 0.500000000000000000000000000000000000000000000000000000000000000000000000b0 +
145 0.500000000000000000000000000000000000000000000000000000000000000000000000b0*%i,
151 0.555892970251421171992048047897569250691057814997037061577650731037508243b0 +
152 0.899453719973933636130613791812127819163772491812606935297702716148303720b0*%i,
158 0.707106781186547524400844362104849039284835937688474036588339868995366239b0*%i,
164 0.555892970251421171992048047897569250691057814997037061577650731037508243b0 -
165 0.899453719973933636130613791812127819163772491812606935297702716148303720b0*%i,
171 0.500000000000000000000000000000000000000000000000000000000000000000000000b0 -
172 0.500000000000000000000000000000000000000000000000000000000000000000000000b0*%i,
178 0.899453719973933636130613791812127819163772491812606935297702716148303720b0 -
179 0.555892970251421171992048047897569250691057814997037061577650731037508243b0*%i,
186 /* ---------- Mirror symmetry ----------------------------------------------- */
188 /* We have no Mirror symmetry on the real negative axis. Maxima knows this. */
190 conjugate(sqrt(2+%i*y));
193 conjugate(sqrt(-2+%i*y));
194 conjugate(sqrt(-2+%i*y));
196 conjugate(sqrt(x+%i*y));
197 conjugate(sqrt(x+%i*y));
202 conjugate(sqrt(x+%i*y));
208 /* ---------- Series representations ---------------------------------------- */
210 /* Check taylor expansion */
212 taylor(sqrt(x), x, x0, 2);
213 sqrt(x0)+sqrt(x0)*(x-x0)/2/x0-sqrt(x0)*(x-x0)^2/8/x0^2;
215 /* Check taylor expansion as an argument to sqrt */
216 sqrt(taylor(x,x,x0,2));
217 sqrt(x0)+sqrt(x0)*(x-x0)/2/x0-sqrt(x0)*(x-x0)^2/8/x0^2;
219 taylor(sqrt(x), x, 1, 3);
220 1 + (x-1)/2 - (x-1)^2/8 + (x-1)^3/16;
222 taylor(sqrt(x+1), x, 0, 3);
225 taylor(sqrt(x), x, inf, 2);
228 /* ---------- Differential equations ---------------------------------------- */
232 %e_to_numlog:true; /* Simplify %e^log(x) -> x */
235 ode2('diff(y,x)-y/(2*x), y, x);
238 ode2(4*'diff(y,x,2)*x^2+y, y, x);
239 y=sqrt(x)*(%k1 + %k2*log(x)/2);
244 ode2('diff(y,x)-'diff(g(x),x)/(2*g(x))*y, y,x);
247 ode2('diff(y,x)-('diff(g(x),x)/(2*g(x))+'diff(h(x),x)/h(x))*y, y, x), expand;
248 y=%c*h(x)*sqrt(g(x));
250 remove([y,g,h], depends);
255 /* ---------- Transformations and argument simplifications ------------------ */
263 /* --- sqrt(-z) --- */
266 [sqrt(-z), sqrt(-x), %i*sqrt(xp)];
268 sqrt([-1/2, -3/4, -1, -3/2, -2]);
269 [%i/sqrt(2), %i*sqrt(3)/2, %i, %i*sqrt(3)/sqrt(2), %i*sqrt(2)];
274 /* --- sqrt(%i*z) --- */
276 sqrt([%i*z,%i*x,%i*xp]);
277 [sqrt(%i*z), sqrt(%i*x), (-1)^(1/4)*sqrt(xp)];
279 sqrt([%i*1/2, %i*3/4, %i, %i*3/2, %i*2]);
280 [(-1)^(1/4)/sqrt(2), (-1)^(1/4)*sqrt(3)/2, (-1)^(1/4),
281 (-1)^(1/4)*sqrt(3)/sqrt(2), (-1)^(1/4)*sqrt(2)];
283 sqrt([%i*(xp+2), %i*xp+%i*2]);
284 [(-1)^(1/4)*sqrt(xp+2),sqrt(%i*xp+%i*2)];
286 /* --- sqrt(-%i*z) --- */
288 sqrt([-%i*z,-%i*x,-%i*xp]);
289 [sqrt(-%i*z), sqrt(-%i*x), sqrt(-%i)*sqrt(xp)];
291 sqrt([-%i*1/2, -%i*3/4, -%i, -%i*3/2, -%i*2]);
292 [sqrt(-%i)/sqrt(2), sqrt(-%i)*sqrt(3)/2, sqrt(-%i),
293 sqrt(-%i)*sqrt(3)/sqrt(2), sqrt(-%i)*sqrt(2)];
295 sqrt([-%i*(xp+2), -%i*xp-%i*2]);
296 [sqrt(-%i)*sqrt(xp+2),sqrt(-%i*xp-%i*2)];
298 /* --- sqrt(1/z) --- */
300 sqrt(1/xp) - 1/sqrt(xp);
302 sqrt(1/-xp) + 1/sqrt(-xp);
304 sqrt(1/-xn) - 1/sqrt(-xn);
307 /* --- sqrt(-1/z) --- */
309 sqrt([-1/x, -1/xp, -1/xn, -1/(xn-2), -1/(xp+2)]);
310 [%i/sqrt(x), %i/sqrt(xp), 1/sqrt(-xn), 1/sqrt(-xn+2), %i/sqrt(xp+2)];
312 /* --- sqrt(%i/z) --- */
314 sqrt([%i/x, %i/xp, %i/xn, %i/(xn-2), %i/(xp+2)]);
315 [sqrt(%i/x), (-1)^(1/4)/sqrt(xp), sqrt(-%i)/sqrt(-xn), sqrt(-%i)/sqrt(-xn+2),
316 (-1)^(1/4)/sqrt(xp+2)];
318 /* --- sqrt(-%i/z) --- */
320 sqrt([-%i/x, -%i/xp, -%i/xn, -%i/(xn-2), -%i/(xp+2)]);
321 [sqrt(-%i/x), sqrt(-%i)/sqrt(xp), (-1)^(1/4)/sqrt(-xn), (-1)^(1/4)/sqrt(-xn+2),
322 sqrt(-%i)/sqrt(xp+2)];
324 /* --- Half-angle formula --- */
329 /* --- Multiple arguments for products --- */
337 sqrt(b*z); /* Do not simplify if the sign is not known to be positive */
343 radcan(sqrt(-z^2-z));
346 /* --- Multiple arguments for quotients --- */
348 radcan(sqrt(z)/sqrt(z+1));
351 radcan(sqrt(z/(z-1)));
354 /* radcan always simplifies sqrt(z1/z2) -> sqrt(z1)/sqrt(z2).
355 * That is not correct.
358 declare([z1,z2],complex);
364 /* More examples of this type */
366 radcan(sqrt(z/(1-z)));
367 sqrt(z)*sqrt(1/(1-z));
369 radcan(sqrt(-z/(1+z)));
370 sqrt(z)*sqrt(1/(-1+-z));
372 /* --- Power of arguments --- */
374 sqrt([z^2, x^2, xp^2, xn^2]);
375 [sqrt(z^2), abs(x), xp, -xn];
377 (domain:complex, done);
380 res:sqrt(-z^2); /* Wrong: Maxima simplifies to %i*sqrt(z) */
383 res,z=%i; /* We insert %i and get a wrong sign */
386 (reset(domain), done);
389 /* --- Exponent of arguments --- */
391 /* Maxima simplifes immediately sqrt(exp(z)) -> exp(z/2)
392 * That is wrong for imagpart(z) > %pi or < -%pi
393 * We give an example.
396 sqrt(exp(2*%pi*%i)); /* That is the expected result */
399 sqrt(exp(%i*y)); /* This expression simplifies wrongly */
402 %,y=2*%pi; /* We get a wrong sign */
405 /* ---------- Nested sqrt functions ----------------------------------------- */
407 /* The following 19 examples should simplify or evaluate to zero for all real
408 * or complex numbers. We check this. This way we can detect simplification
409 * errors for the sqrt function.
412 (domain:complex, done);
415 /* --- Example 1 --- */
417 /* Wrong simplification because of sqrt(1/z) -> 1/sqrt(z) */
419 expr(z):=sqrt(-1-z)*sqrt(1/(1+z))*sqrt(1/z)*sqrt(-z)+1;
420 expr(z):=sqrt(-1-z)*sqrt(1/(1+z))*sqrt(1/z)*sqrt(-z)+1;
422 /* Check correct simplification of expression */
424 sqrt(-1-z)*sqrt(1/(1+z))*sqrt(1/z)*sqrt(-z)+1;
426 closeto(float(rectform(res)),0.0,1e-15), z=1/2;
428 closeto(float(rectform(res)),0.0,1e-15), z=-1/2; /* wrong -> 2 */
430 closeto(float(rectform(res)),0.0,1e-15), z=%i/2;
432 closeto(float(rectform(res)),0.0,1e-15), z=-%i/2;
434 closeto(float(rectform(res)),0.0,1e-15), z=1/2+%i;
436 closeto(float(rectform(res)),0.0,1e-15), z=-1/2+%i;
438 closeto(float(rectform(res)),0.0,1e-15), z=-1/2-%i;
440 closeto(float(rectform(res)),0.0,1e-15), z=1/2-%i;
443 /* --- Example 2 --- */
445 /* Wrong simplification because of sqrt(-1/z) -> 1/sqrt(-z) */
447 expr(z):=sqrt((z-1)/z)*sqrt(z/(1-z))-sqrt(-1/z)*sqrt(z);
448 expr(z):=sqrt((z-1)/z)*sqrt(z/(1-z))-sqrt(-1/z)*sqrt(z);
450 /* Check correct simplification of equation */
452 sqrt((z-1)/z)*sqrt(z/(1-z))-sqrt(-1/z)*sqrt(z);
454 closeto(float(rectform(res)),0.0,1e-15), z=1/2; /* Wrong -> 2 */
456 closeto(float(rectform(res)),0.0,1e-15), z=-1/2;
458 closeto(float(rectform(res)),0.0,1e-15), z=%i/2;
460 closeto(float(rectform(res)),0.0,1e-15), z=-%i/2;
462 closeto(float(rectform(res)),0.0,1e-15), z=1/2+%i;
464 closeto(float(rectform(res)),0.0,1e-15), z=-1/2+%i;
466 closeto(float(rectform(res)),0.0,1e-15), z=-1/2-%i;
468 closeto(float(rectform(res)),0.0,1e-15), z=1/2-%i;
471 /* --- Example 3 --- */
473 /* Wrong simplification because of sqrt(z^2)/sqrt(-z^2) -> -%i */
475 expr(z):=sqrt(sqrt(z^2+1)-1)/sqrt(1-sqrt(z^2+1))-sqrt(z^2)/sqrt(-z^2);
476 expr(z):=sqrt(sqrt(z^2+1)-1)/sqrt(1-sqrt(z^2+1))-sqrt(z^2)/sqrt(-z^2);
478 /* Check correct simplification of equation */
480 sqrt(sqrt(z^2+1)-1)/sqrt(1-sqrt(z^2+1))-sqrt(z^2)/sqrt(-z^2);
482 closeto(float(rectform(res)),0.0,1e-15), z=1/2;
484 closeto(float(rectform(res)),0.0,1e-15), z=-1/2;
486 closeto(float(rectform(res)),0.0,1e-15), z=%i/2; /* Wrong -> 2 */
488 closeto(float(rectform(res)),0.0,1e-15), z=-%i/2; /* Wrong -> 2 */
490 closeto(float(rectform(res)),0.0,1e-15), z=1/2+%i; /* Wrong -> 2 */
492 closeto(float(rectform(res)),0.0,1e-15), z=-1/2+%i;
494 closeto(float(rectform(res)),0.0,1e-15), z=-1/2-%i; /* Wrong -> 2 */
496 closeto(float(rectform(res)),0.0,1e-15), z=1/2-%i;
499 /* --- Example 4 --- */
501 /* Wrong simplification sqrt(-z^2)/sqrt(z^2) -> %i */
503 expr(z):=sqrt(sqrt(1-z^2)-1)/sqrt(1-sqrt(1-z^2))-sqrt(-z^2)/sqrt(z^2);
504 expr(z):=sqrt(sqrt(1-z^2)-1)/sqrt(1-sqrt(1-z^2))-sqrt(-z^2)/sqrt(z^2);
506 /* Check correct simplification of equation */
508 sqrt(sqrt(1-z^2)-1)/sqrt(1-sqrt(1-z^2))-sqrt(-z^2)/sqrt(z^2);
510 closeto(float(rectform(res)),0.0,1e-15), z=1/2;
512 closeto(float(rectform(res)),0.0,1e-15), z=-1/2;
514 closeto(float(rectform(res)),0.0,1e-15), z=%i/2; /* Wrong -> 2 */
516 closeto(float(rectform(res)),0.0,1e-15), z=-%i/2; /* Wrong -> 2 */
518 closeto(float(rectform(res)),0.0,1e-15), z=1/2+%i; /* Wrong -> 2 */
520 closeto(float(rectform(res)),0.0,1e-15), z=-1/2+%i;
522 closeto(float(rectform(res)),0.0,1e-15), z=-1/2-%i; /* Wrong -> 2 */
524 closeto(float(rectform(res)),0.0,1e-15), z=1/2-%i;
527 /* --- Example 5 --- */
529 /* Wrong simplification sqrt(-1/z) -> 1/sqrt(-z) */
531 expr(z):=sqrt(sqrt(z^2+1)-z)/sqrt(z-sqrt(z^2+1))+sqrt(z)*sqrt(-1/z);
532 expr(z):=sqrt(sqrt(z^2+1)-z)/sqrt(z-sqrt(z^2+1))+sqrt(z)*sqrt(-1/z);
534 /* Check correct simplification of equation */
536 sqrt(sqrt(z^2+1)-z)/sqrt(z-sqrt(z^2+1))+sqrt(z)*sqrt(-1/z);
538 closeto(float(rectform(res)),0.0,1e-15), z=1/2; /* Wrong -> 2 */
540 closeto(float(rectform(res)),0.0,1e-15), z=-1/2;
542 closeto(float(rectform(res)),0.0,1e-15), z=%i/2;
544 closeto(float(rectform(res)),0.0,1e-15), z=-%i/2;
546 closeto(float(rectform(res)),0.0,1e-15), z=1/2+%i;
548 closeto(float(rectform(res)),0.0,1e-15), z=-1/2+%i;
550 closeto(float(rectform(res)),0.0,1e-15), z=-1/2-%i;
552 closeto(float(rectform(res)),0.0,1e-15), z=1/2-%i;
555 /* --- Example 6 --- */
557 /* Wrong simplification sqrt(1/z) -> 1/sqrt(z) */
559 expr(z):=sqrt(z+sqrt(z^2+1))/sqrt(-z-sqrt(z^2+1))+sqrt(-z)*sqrt(1/z);
560 expr(z):=sqrt(z+sqrt(z^2+1))/sqrt(-z-sqrt(z^2+1))+sqrt(-z)*sqrt(1/z);
562 /* Check correct simplification of equation */
564 sqrt(z+sqrt(z^2+1))/sqrt(-z-sqrt(z^2+1))+sqrt(-z)*sqrt(1/z);
566 closeto(float(rectform(res)),0.0,1e-15), z=1/2;
568 closeto(float(rectform(res)),0.0,1e-15), z=-1/2; /* Wrong -> 2 */
570 closeto(float(rectform(res)),0.0,1e-15), z=%i/2;
572 closeto(float(rectform(res)),0.0,1e-15), z=-%i/2;
574 closeto(float(rectform(res)),0.0,1e-15), z=1/2+%i;
576 closeto(float(rectform(res)),0.0,1e-15), z=-1/2+%i;
578 closeto(float(rectform(res)),0.0,1e-15), z=-1/2-%i;
580 closeto(float(rectform(res)),0.0,1e-15), z=1/2-%i;
583 /* --- Example 7 --- */
585 /* This expression does not simplify at all. All numeric values are correct.
586 * rootscontract gives the result 2*%i. That is wrong. Because we have no
587 * problem with the simplification of the expression, the error is in
588 * rootscontract for this example */
590 expr(z):=sqrt(sqrt(1-z^2)-%i*z)/sqrt(%i*z-sqrt(1-z^2))+sqrt(%i*z)*sqrt(%i/z);
591 expr(z):=sqrt(sqrt(1-z^2)-%i*z)/sqrt(%i*z-sqrt(1-z^2))+sqrt(%i*z)*sqrt(%i/z);
593 /* Check correct simplification of equation */
595 sqrt(sqrt(1-z^2)-%i*z)/sqrt(%i*z-sqrt(1-z^2))+sqrt(%i*z)*sqrt(%i/z);
597 closeto(float(rectform(res)),0.0,1e-15), z=1/2;
599 closeto(float(rectform(res)),0.0,1e-15), z=-1/2;
601 closeto(float(rectform(res)),0.0,1e-15), z=%i/2;
603 closeto(float(rectform(res)),0.0,1e-15), z=-%i/2;
605 closeto(float(rectform(res)),0.0,1e-15), z=1/2+%i;
607 closeto(float(rectform(res)),0.0,1e-15), z=-1/2+%i;
609 closeto(float(rectform(res)),0.0,1e-15), z=-1/2-%i;
611 closeto(float(rectform(res)),0.0,1e-15), z=1/2-%i;
614 /* --- Example 8 --- */
616 /* This expression does not simplify at all. All numeric values are correct.
617 * rootscontract gives the result 2*%i. That is wrong. Because we have no
618 * problem with the simplification of the expression, the error is in
619 * rootscontract for this example. See also example 7.
622 expr(z):=sqrt(%i*z+sqrt(1-z^2))/sqrt(-%i*z-sqrt(1-z^2))+sqrt(-%i*z)*sqrt(-%i/z);
623 expr(z):=sqrt(%i*z+sqrt(1-z^2))/sqrt(-%i*z-sqrt(1-z^2))+sqrt(-%i*z)*sqrt(-%i/z);
625 /* Check correct simplification of equation */
627 sqrt(%i*z+sqrt(1-z^2))/sqrt(-%i*z-sqrt(1-z^2))+sqrt(-%i*z)*sqrt(-%i/z);
629 closeto(float(rectform(res)),0.0,1e-15), z=1/2;
631 closeto(float(rectform(res)),0.0,1e-15), z=-1/2;
633 closeto(float(rectform(res)),0.0,1e-15), z=%i/2;
635 closeto(float(rectform(res)),0.0,1e-15), z=-%i/2;
637 closeto(float(rectform(res)),0.0,1e-15), z=1/2+%i;
639 closeto(float(rectform(res)),0.0,1e-15), z=-1/2+%i;
641 closeto(float(rectform(res)),0.0,1e-15), z=-1/2-%i;
643 closeto(float(rectform(res)),0.0,1e-15), z=1/2-%i;
646 /* --- Example 9 --- */
648 /* This examples simplifies to zero immediately. This is by accident.
649 * We know that the applied simplifications are not correct.
652 expr(z):=sqrt(z^2/(1-sqrt(1-z^2)))*sqrt((1-sqrt(1-z^2))/z^2)-1;
653 expr(z):=sqrt(z^2/(1-sqrt(1-z^2)))*sqrt((1-sqrt(1-z^2))/z^2)-1;
655 /* Check correct simplification of equation */
657 sqrt(z^2/(1-sqrt(1-z^2)))*sqrt((1-sqrt(1-z^2))/z^2)-1;
659 closeto(float(rectform(res)),0.0,1e-15), z=1/2;
661 closeto(float(rectform(res)),0.0,1e-15), z=-1/2;
663 closeto(float(rectform(res)),0.0,1e-15), z=%i/2;
665 closeto(float(rectform(res)),0.0,1e-15), z=-%i/2;
667 closeto(float(rectform(res)),0.0,1e-15), z=1/2+%i;
669 closeto(float(rectform(res)),0.0,1e-15), z=-1/2+%i;
671 closeto(float(rectform(res)),0.0,1e-15), z=-1/2-%i;
673 closeto(float(rectform(res)),0.0,1e-15), z=1/2-%i;
676 /* --- Example 10 --- */
678 /* Wrong simplification sqrt(1/z) -> 1/sqrt(z) */
680 expr(z):=sqrt(z/(sqrt(z^2+1)-z))*sqrt((sqrt(z^2+1)-z)/z)-sqrt(1/(z^2+1))*sqrt(z^2+1)-sqrt(1/z)*sqrt(z)+1;
681 expr(z):=sqrt(z/(sqrt(z^2+1)-z))*sqrt((sqrt(z^2+1)-z)/z)-sqrt(1/(z^2+1))*sqrt(z^2+1)-sqrt(1/z)*sqrt(z)+1;
683 /* Check correct simplification of equation */
685 sqrt(z/(sqrt(z^2+1)-z))*sqrt((sqrt(z^2+1)-z)/z)-sqrt(1/(z^2+1))*sqrt(z^2+1)-sqrt(1/z)*sqrt(z)+1;
687 closeto(float(rectform(res)),0.0,1e-15), z=1/2;
689 closeto(float(rectform(res)),0.0,1e-15), z=-1/2;
691 closeto(float(rectform(res)),0.0,1e-15), z=%i/2; /* Wrong -> 2 */
693 closeto(float(rectform(res)),0.0,1e-15), z=-%i/2; /* Wrong -> 2 */
695 closeto(float(rectform(res)),0.0,1e-15), z=1/2+%i;
697 closeto(float(rectform(res)),0.0,1e-15), z=-1/2+%i;
699 closeto(float(rectform(res)),0.0,1e-15), z=-1/2-%i;
701 closeto(float(rectform(res)),0.0,1e-15), z=1/2-%i;
704 /* --- Example 11 --- */
706 /* This example is correct:
707 * No simplification of this expression. All numeric results are correct.
708 * radcan does not simplify too. That is not wrong.
709 * rootscontract simplifies correctly to zero.
712 expr(z):=sqrt(sqrt(z)-1)*sqrt(sqrt(z)+1)-sqrt(z-1);
713 expr(z):=sqrt(sqrt(z)-1)*sqrt(sqrt(z)+1)-sqrt(z-1);
715 /* Check correct simplification of equation */
717 sqrt(sqrt(z)-1)*sqrt(sqrt(z)+1)-sqrt(z-1);
719 closeto(float(rectform(res)),0.0,1e-15), z=1/2;
721 closeto(float(rectform(res)),0.0,1e-15), z=-1/2;
723 closeto(float(rectform(res)),0.0,1e-15), z=%i/2;
725 closeto(float(rectform(res)),0.0,1e-15), z=-%i/2;
727 closeto(float(rectform(res)),0.0,1e-15), z=1/2+%i;
729 closeto(float(rectform(res)),0.0,1e-15), z=-1/2+%i;
731 closeto(float(rectform(res)),0.0,1e-15), z=-1/2-%i;
733 closeto(float(rectform(res)),0.0,1e-15), z=1/2-%i;
736 /* --- Example 12 --- */
738 /* This example is correct:
739 * No simplification of this expression. All numeric results are correct.
740 * radcan does not simplify too. That is not wrong.
741 * rootscontract simplifies correctly to zero. See also example 11.
744 expr(z):=sqrt(sqrt(z+1)-1)*sqrt((sqrt(z+1)+1))-sqrt(z);
745 expr(z):=sqrt(sqrt(z+1)-1)*sqrt((sqrt(z+1)+1))-sqrt(z);
747 /* Check correct simplification of equation */
749 sqrt(sqrt(z+1)-1)*sqrt((sqrt(z+1)+1))-sqrt(z);
751 closeto(float(rectform(res)),0.0,1e-15), z=1/2;
753 closeto(float(rectform(res)),0.0,1e-15), z=-1/2;
755 closeto(float(rectform(res)),0.0,1e-15), z=%i/2;
757 closeto(float(rectform(res)),0.0,1e-15), z=-%i/2;
759 closeto(float(rectform(res)),0.0,1e-15), z=1/2+%i;
761 closeto(float(rectform(res)),0.0,1e-15), z=-1/2+%i;
763 closeto(float(rectform(res)),0.0,1e-15), z=-1/2-%i;
765 closeto(float(rectform(res)),0.0,1e-15), z=1/2-%i;
768 /* --- Example 13 --- */
770 /* This example does not simplify. All numeric results are correct.
771 * radcan gives a modified result, which is correct too.
772 * rootscontract gives a wrong expression.
775 expr(z):=sqrt(2)*sqrt(1-sqrt(1-z))*sqrt(sqrt(1-z)+%i*sqrt(z))/(%i*(1-sqrt(1-z))+sqrt(z))-1;
776 expr(z):=sqrt(2)*sqrt(1-sqrt(1-z))*sqrt(sqrt(1-z)+%i*sqrt(z))/(%i*(1-sqrt(1-z))+sqrt(z))-1;
778 /* Check correct simplification of equation */
780 sqrt(2)*sqrt(1-sqrt(1-z))*sqrt(sqrt(1-z)+%i*sqrt(z))/(%i*(1-sqrt(1-z))+sqrt(z))-1;
782 closeto(float(rectform(res)),0.0,1e-15), z=1/2;
784 closeto(float(rectform(res)),0.0,1e-15), z=-1/2;
786 closeto(float(rectform(res)),0.0,1e-15), z=%i/2;
788 closeto(float(rectform(res)),0.0,1e-15), z=-%i/2;
790 closeto(float(rectform(res)),0.0,1e-15), z=1/2+%i;
792 closeto(float(rectform(res)),0.0,1e-15), z=-1/2+%i;
794 closeto(float(rectform(res)),0.0,1e-15), z=-1/2-%i;
796 closeto(float(rectform(res)),0.0,1e-15), z=1/2-%i;
799 /* --- Example 14 --- */
801 /* This example does not simplify. All numeric results are correct.
802 * radcan gives the correct result zero.
803 * rootscontract gives a wrong expression.
806 expr(z):=sqrt(1-z)*(1+z-%i*sqrt(1-z^2))/(sqrt(z+1)*(1-z+%i*sqrt(1-z^2)))+%i;
807 expr(z):=sqrt(1-z)*(1+z-%i*sqrt(1-z^2))/(sqrt(z+1)*(1-z+%i*sqrt(1-z^2)))+%i;
809 /* Check correct simplification of equation */
811 sqrt(1-z)*(1+z-%i*sqrt(1-z^2))/(sqrt(z+1)*(1-z+%i*sqrt(1-z^2)))+%i;
813 closeto(float(rectform(res)),0.0,1e-15), z=1/2;
815 closeto(float(rectform(res)),0.0,1e-15), z=-1/2;
817 closeto(float(rectform(res)),0.0,1e-15), z=%i/2;
819 closeto(float(rectform(res)),0.0,1e-15), z=-%i/2;
821 closeto(float(rectform(res)),0.0,1e-15), z=1/2+%i;
823 closeto(float(rectform(res)),0.0,1e-15), z=-1/2+%i;
825 closeto(float(rectform(res)),0.0,1e-15), z=-1/2-%i;
827 closeto(float(rectform(res)),0.0,1e-15), z=1/2-%i;
830 /* --- Example 15 --- */
832 /* This example does not simplify. All numeric results are correct.
833 * radcan gives the correct result zero.
834 * rootscontract gives a wrong expression.
837 expr(z):=sqrt(1-z)*(1+z+%i*sqrt(1-z^2))/(sqrt(z+1)*(1-z-%i*sqrt(1-z^2)))-%i;
838 expr(z):=sqrt(1-z)*(1+z+%i*sqrt(1-z^2))/(sqrt(z+1)*(1-z-%i*sqrt(1-z^2)))-%i;
840 /* Check correct simplification of equation */
842 sqrt(1-z)*(1+z+%i*sqrt(1-z^2))/(sqrt(z+1)*(1-z-%i*sqrt(1-z^2)))-%i;
844 closeto(float(rectform(res)),0.0,1e-15), z=1/2;
846 closeto(float(rectform(res)),0.0,1e-15), z=-1/2;
848 closeto(float(rectform(res)),0.0,1e-15), z=%i/2;
850 closeto(float(rectform(res)),0.0,1e-15), z=-%i/2;
852 closeto(float(rectform(res)),0.0,1e-15), z=1/2+%i;
854 closeto(float(rectform(res)),0.0,1e-15), z=-1/2+%i;
856 closeto(float(rectform(res)),0.0,1e-15), z=-1/2-%i;
858 closeto(float(rectform(res)),0.0,1e-15), z=1/2-%i;
861 /* --- Example 16 --- */
863 /* This example does not simplify. All numeric results are correct.
864 * radcan gives a changed expression, which is correct too.
865 * rootscontract gives only a small change.
868 expr(z):=1/sqrt(1-sqrt(z))+1/sqrt(1+sqrt(z))-sqrt(2)*sqrt(sqrt(1-z)+1)/sqrt(1-z);
869 expr(z):=1/sqrt(1-sqrt(z))+1/sqrt(1+sqrt(z))-sqrt(2)*sqrt(sqrt(1-z)+1)/sqrt(1-z);
871 /* Check correct simplification of equation */
873 1/sqrt(1-sqrt(z))+1/sqrt(1+sqrt(z))-sqrt(2)*sqrt(sqrt(1-z)+1)/sqrt(1-z);
875 closeto(float(rectform(res)),0.0,1e-15), z=1/2;
877 closeto(float(rectform(res)),0.0,1e-15), z=-1/2;
879 closeto(float(rectform(res)),0.0,1e-15), z=%i/2;
881 closeto(float(rectform(res)),0.0,1e-15), z=-%i/2;
883 closeto(float(rectform(res)),0.0,1e-15), z=1/2+%i;
885 closeto(float(rectform(res)),0.0,1e-15), z=-1/2+%i;
887 closeto(float(rectform(res)),0.0,1e-15), z=-1/2-%i;
889 closeto(float(rectform(res)),0.0,1e-15), z=1/2-%i;
892 /* --- Example 17 --- */
894 /* This example does not simplify. All numeric results are correct.
895 * radcan gives a changed expression, which is correct too.
896 * rootscontract gives only a small change.
899 expr(z):=1/sqrt(1-sqrt(z))-1/sqrt(1+sqrt(z))-sqrt(2)*sqrt(1-sqrt(1-z))/sqrt(1-z);
900 expr(z):=1/sqrt(1-sqrt(z))-1/sqrt(1+sqrt(z))-sqrt(2)*sqrt(1-sqrt(1-z))/sqrt(1-z);
902 /* Check correct simplification of equation */
904 1/sqrt(1-sqrt(z))-1/sqrt(1+sqrt(z))-sqrt(2)*sqrt(1-sqrt(1-z))/sqrt(1-z);
906 closeto(float(rectform(res)),0.0,1e-15), z=1/2;
908 closeto(float(rectform(res)),0.0,1e-15), z=-1/2;
910 closeto(float(rectform(res)),0.0,1e-15), z=%i/2;
912 closeto(float(rectform(res)),0.0,1e-15), z=-%i/2;
914 closeto(float(rectform(res)),0.0,1e-15), z=1/2+%i;
916 closeto(float(rectform(res)),0.0,1e-15), z=-1/2+%i;
918 closeto(float(rectform(res)),0.0,1e-15), z=-1/2-%i;
920 closeto(float(rectform(res)),0.0,1e-15), z=1/2-%i;
923 /* --- Example 18 --- */
925 /* All numeric values are correct. radcan and rootscontract does not
926 * change the expression.
929 expr(z):=sqrt(1+sqrt(z))+sqrt(1-sqrt(z))-sqrt(2)*sqrt(1+sqrt(1-z));
930 expr(z):=sqrt(1+sqrt(z))+sqrt(1-sqrt(z))-sqrt(2)*sqrt(1+sqrt(1-z));
932 /* Check correct simplification of equation */
934 sqrt(1+sqrt(z))+sqrt(1-sqrt(z))-sqrt(2)*sqrt(1+sqrt(1-z));
936 closeto(float(rectform(res)),0.0,1e-15), z=1/2;
938 closeto(float(rectform(res)),0.0,1e-15), z=-1/2;
940 closeto(float(rectform(res)),0.0,1e-15), z=%i/2;
942 closeto(float(rectform(res)),0.0,1e-15), z=-%i/2;
944 closeto(float(rectform(res)),0.0,1e-15), z=1/2+%i;
946 closeto(float(rectform(res)),0.0,1e-15), z=-1/2+%i;
948 closeto(float(rectform(res)),0.0,1e-15), z=-1/2-%i;
950 closeto(float(rectform(res)),0.0,1e-15), z=1/2-%i;
953 /* --- Example 19 --- */
955 /* All numeric values are correct. radcan and rootscontract does not
956 * change the expression.
959 expr(z):=sqrt(1+sqrt(z))-sqrt(1-sqrt(z))-sqrt(2)*sqrt(1-sqrt(1-z));
960 expr(z):=sqrt(1+sqrt(z))-sqrt(1-sqrt(z))-sqrt(2)*sqrt(1-sqrt(1-z));
962 /* Check correct simplification of equation */
964 sqrt(1+sqrt(z))-sqrt(1-sqrt(z))-sqrt(2)*sqrt(1-sqrt(1-z));
966 closeto(float(rectform(res)),0.0,1e-15), z=1/2;
968 closeto(float(rectform(res)),0.0,1e-15), z=-1/2;
970 closeto(float(rectform(res)),0.0,1e-15), z=%i/2;
972 closeto(float(rectform(res)),0.0,1e-15), z=-%i/2;
974 closeto(float(rectform(res)),0.0,1e-15), z=1/2+%i;
976 closeto(float(rectform(res)),0.0,1e-15), z=-1/2+%i;
978 closeto(float(rectform(res)),0.0,1e-15), z=-1/2-%i;
980 closeto(float(rectform(res)),0.0,1e-15), z=1/2-%i;
983 (reset(domain), done);
986 /* ---------- Complex characteristics --------------------------------------- */
988 /* --- Real part --- */
990 realpart(sqrt(x+%i*y));
991 (x^2+y^2)^(1/4)*cos(1/2*atan2(y,x));
993 /* --- Imaginary part --- */
995 imagpart(sqrt(x+%i*y));
996 (x^2+y^2)^(1/4)*sin(1/2*atan2(y,x));
998 /* --- Absolute value --- */
1003 /* --- Argument --- */
1008 /* --- Conjugate value --- */
1010 conjugate(sqrt(xp+%i*y));
1013 rectform(conjugate(sqrt(xp+%i*y)));
1014 (xp^2+y^2)^(1/4)*cos(1/2*atan(y/xp))-%i*(xp^2+y^2)^(1/4)*sin(1/2*atan(y/xp));
1016 /* --- Signum value --- */
1018 /* Maxima has no signum function for complex expressions */
1029 /* ---------- Differentiation ----------------------------------------------- */
1037 /* ---------- Integration --------------------------------------------------- */
1039 /* --- Indefinite integration --- */
1041 integrate(sqrt(z),z);
1044 /* --- Definite integration --- */
1046 integrate(sqrt(t),t,0,1);
1049 integrate(sqrt(t)*log(t),t,0,1);
1052 /* Maxima does not know the general result: -> 2/3*2F1(3/2,-a;5/2;-1) */
1053 integrate(sqrt(t)*(t+1)^a,t,0,1);
1054 'integrate(sqrt(t)*(t+1)^a,t,0,1);
1056 /* Maxima can evaluate the integral for a an integer or a half integral value */
1057 integrate(sqrt(t)*(t+1)^2,t,0,1);
1060 integrate(sqrt(t)*(t+1)^-2,t,0,1);
1063 integrate(sqrt(t)*(t+1)^(1/2),t,0,1);
1064 (-log(sqrt(2)+1)+log(1-sqrt(2))+3*2^(3/2))/8-(%i*%pi)/8$
1066 integrate(sqrt(t)*(t+1)^(-1/2),t,0,1);
1067 (-log(sqrt(2)+1)/2)+log(sqrt(2)-1)/2+sqrt(2);
1069 integrate(sqrt(t)*(t+1)^(3/2),t,0,1);
1070 (-(3*log(sqrt(2)+1))+3*log(1-sqrt(2))+25*2^(3/2))/48-(%i*%pi)/16$
1072 integrate(sqrt(t)*(t+1)^(-3/2),t,0,1);
1073 log(sqrt(2)+1)-log(sqrt(2)-1)-sqrt(2);
1075 /* ---------- Integral transforms ------------------------------------------- */
1077 /* --- Laplace transform --- */
1079 laplace(sqrt(t),t,s);
1080 sqrt(%pi)/(2*s^(3/2));
1082 /* Maxima does not know the inverse laplace transform
1083 * -> -1/(2*t^(3/2)*sqrt(%pi)
1088 /* ---------- Limits -------------------------------------------------------- */
1093 limit(sqrt(z)/b^z,z,inf);
1099 limit(sqrt(z)*log(z),z,0);
1102 limit(log(z)/sqrt(z),z,inf);
1105 /* ---------- Representation through hypergeometric functions --------------- */
1107 hgfred([-1/2],[],1-z);
1110 hgfred([],[], 1/2*log(z)), %e_to_numlog:true;
1113 hgfred([-1/2,b],[b],1-z);
1116 (reset(domain), done);
1119 /* bug reported to mailing list 2018-11-01: "radcan(sqrt(-1/(sqrt(-3)+1))*sqrt(2))" */
1121 radcan (sqrt(-1/(sqrt(-3)+1))*sqrt(2));
1122 sqrt(2)/sqrt(-sqrt(3)*%i - 1);
1124 radcan (sqrt(-1/(sqrt(-3)+1)));
1125 1/sqrt(-sqrt(3)*%i - 1);
1127 radcan (sqrt(1/(sqrt(-3)+1))*sqrt(2));
1128 sqrt(2)/sqrt((sqrt(3)*%i + 1));