1 /*************** -*- Mode: MACSYMA; Package: MAXIMA -*- ******************/
2 /***************************************************************************
4 *** Copyright (c) 1984 by William Schelter,University of Texas *****
5 *** All rights reserved *****
6 ***************************************************************************/
11 deftaylor(f(x),x^2+sum(x^i/(2^i*i!^2),i,4,inf));
13 taylor(%e^sqrt(f(x)),x,0,4);
14 1+x+x^2/2+3073*x^3/18432+12817*x^4/307200$
16 ev(x+sin(3*x)/sin(x),trigexpand,expand);
17 -sin(x)^2+3*cos(x)^2+x$
18 trigexpand(sin(10*x+y));
19 cos(10*x)*sin(y)+sin(10*x)*cos(y)$
20 -sin(x)^2+3*cos(x)^2+x;
21 -sin(x)^2+3*cos(x)^2+x$
22 expand(trigreduce(%));
24 declare(j,integer,e,even,o,odd);
26 sin(x+(e+1/2)*%pi),expand;
28 sin(x+(o+1/2)*%pi),expand;
30 (linel:500,diff(exp(x^2+y)/(x+y),x,2));
31 4*x^2*%e^(y+x^2)/(y+x)+2*%e^(y+x^2)/(y+x)-4*x*%e^(y+x^2)/(y+x)^2 +2*%e^(y+x^2)/(y+x)^3$
34 "block([%1,%2,%3,%4],%1:y+x,%2:x^2,%3:%e^(y+%2),%4:1/%1,4*%2*%4*%3+2*%4*%3-(4*x*%3)/%1^2+(2*%3)/%1^3)"$
38 laplace(%e^(2*t+a)*sin(t)*t,t,s);
39 %e^a*(2*s-4)/(s^2-4*s+5)^2$
40 'integrate(sinh(a*x)*f(t-x),x,0,t)+b*f(t) = t^2;
41 'integrate(f(t-x)*sinh(a*x),x,0,t)+b*f(t) = t^2$
43 expand(laplace(%,t,s),0,0);
44 ''(expand(b*laplace(f(t),t,s)+a*laplace(f(t),t,s)/(s^2-a^2) = 2/s^3,0,0))$
46 linsolve([%],['laplace(f(t),t,s)]);
47 ['laplace(f(t),t,s) = (2*s^2-2*a^2)/(b*s^5+(a-a^2*b)*s^3)]$
52 assume(a>0,b>0,a*b>1);
55 f(t)=-2*cosh(sqrt(a*b*(a*b-1))*t/b)/(a^3*b^2-2*a^2*b+a)+a*t^2/(a*b-1)+2/(a^3*b^2-2*a^2*b+a)$
56 forget(a>0,b>0,a*b>1);
59 /* bug reported to mailing list 2015-02-16: expand phenomenon */
61 block ([f1, f2], f1:y=(x+1)*(x+3), f2:expand(f1), string (expand(f1)=expand(f2)));
62 "(y = x^2+4*x+3) = (y = x^2+4*x+3)";
64 string ((a = b) = (c = d));
67 /* following is supposed to test pretty printing code path
68 * not sure if embedded newline will be recognized appropriately on Windows
71 with_default_2d_display(
72 s : make_string_output_stream (),
73 with_stdout (s, print ((a = b) = (c = d))),
74 stuff : get_output_stream_string (s),
83 string ((a foo b) foo (c foo d));
84 "(a foo b) foo (c foo d)";
86 /* following is supposed to test pretty printing code path
87 * not sure if embedded newline will be recognized appropriately on Windows
90 with_default_2d_display(
91 s : make_string_output_stream (),
92 with_stdout (s, print ((a foo b) foo (c foo d))),
93 stuff : get_output_stream_string (s),
96 "(a foo b) foo (c foo d)
102 /* mailing list 2015-09-08 and SF bug #3019: "transfer function" */
104 (verify_display_2d (expr, expected_output) :=
106 with_default_2d_display
107 (S : make_string_output_stream (),
108 with_stdout (S, print (expr)),
109 output : get_output_stream_string (S),
111 if is (output = expected_output) then true else [expected_output, output])),
112 verify_display_1d (expr, expected_output) :=
113 block ([output : string (expr)], if is (output = expected_output) then true else [expected_output, output]),
117 /* increase linel so next few test cases avoid Lisp error when run_testsuite(display_all = true)
118 * workaround for SF bug https://sourceforge.net/p/maxima/bugs/4234/
124 block ([powerdisp : false, display2d_unicode: false],
125 verify_display_2d ((x+1)/(x+2),
132 block ([powerdisp : true, display2d_unicode: false],
133 verify_display_2d ((x+1)/(x+2),
143 block ([powerdisp : false], verify_display_1d ((x+1)/(x+2), "(x+1)/(x+2)"));
146 block ([powerdisp : true], verify_display_1d ((x+1)/(x+2), "(1+x)/(2+x)"));
149 (H : ( n2 * s^2 + n1 * s + n0 ) / ( d2 * s^2 + d1 * s + d0 ), 0);
152 block ([powerdisp : false, display2d_unicode: false], verify_display_2d (H,
161 block ([powerdisp : true, display2d_unicode: false], verify_display_2d (H,
170 block ([powerdisp : false], verify_display_1d (H, "(n2*s^2+n1*s+n0)/(d2*s^2+d1*s+d0)"));
173 block ([powerdisp : true], verify_display_1d (H, "(n0+n1*s+n2*s^2)/(d0+d1*s+d2*s^2)"));
177 /* mailing list 2015-09-08: "Maxima 5.37.1 changes in behaviour when simp:false" */
183 [?second (p), ?third (p)]);
197 [?second (p), ?third (p)]);
207 block ([powerdisp : false], verify_display_2d (diff (x^n, x),
213 block ([powerdisp : true], verify_display_2d (diff (x^n, x),
219 block ([powerdisp : false], verify_display_1d (diff (x^n, x), "n*x^(n-1)"));
222 block ([powerdisp : true], verify_display_1d (diff (x^n, x), "n*x^(-1+n)"));
225 /* mailing list 2015-09-04: "Inconsistent ordering: (x+1)^2 becomes (1+x)^2, but x+1 stays x+1" */
227 block ([powerdisp : false], verify_display_2d ((x+1)^2,
233 block ([powerdisp : true], verify_display_2d ((x+1)^2,
239 block ([powerdisp : false], verify_display_1d ((x+1)^2, "(x+1)^2"));
241 block ([powerdisp : true], verify_display_1d ((x+1)^2, "(1+x)^2"));
244 block ([powerdisp : false], verify_display_2d ((x^3+x^2+x+1)^2,
250 block ([powerdisp : true], verify_display_2d ((x^3+x^2+x+1)^2,
256 block ([powerdisp : false], verify_display_1d ((x^3+x^2+x+1)^2, "(x^3+x^2+x+1)^2"));
258 block ([powerdisp : true], verify_display_1d ((x^3+x^2+x+1)^2, "(1+x+x^2+x^3)^2"));
261 block ([powerdisp : false], verify_display_2d (x+1,
266 block ([powerdisp : true], verify_display_2d (x+1,
271 block ([powerdisp : false], verify_display_1d (x+1, "x+1"));
273 block ([powerdisp : true], verify_display_1d (x+1, "1+x"));
276 block ([powerdisp : false], verify_display_2d (x^3+x^2+x+1,
282 block ([powerdisp : true], verify_display_2d (x^3+x^2+x+1,
288 block ([powerdisp : false], verify_display_1d (x^3+x^2+x+1, "x^3+x^2+x+1"));
290 block ([powerdisp : true], verify_display_1d (x^3+x^2+x+1, "1+x+x^2+x^3"));
293 block ([powerdisp : false], verify_display_2d (2^(x+1),
299 block ([powerdisp : true], verify_display_2d (2^(x+1),
305 block ([powerdisp : false], verify_display_1d (2^(x+1), "2^(x+1)"));
307 block ([powerdisp : true], verify_display_1d (2^(x+1), "2^(1+x)"));
310 block ([powerdisp : false], verify_display_2d (2^(x^3+x^2+x+1),
317 block ([powerdisp : true], verify_display_2d (2^(x^3+x^2+x+1),
324 block ([powerdisp : false], verify_display_1d (2^(x^3+x^2+x+1), "2^(x^3+x^2+x+1)"));
326 block ([powerdisp : true], verify_display_1d (2^(x^3+x^2+x+1), "2^(1+x+x^2+x^3)"));
329 /* SF bug #3046 "Changes of behaviour with simp:false" */
331 block ([simp:false], string((3/6)*x));
334 string (lambda ([], (2/2)*u));
335 "lambda([],(2/2)*u)";
337 /* SF bug #4090: "output formatting: -x-1 has redundant parentheses: (-x)-1" */
339 /* copied print_string_2d from rtest3.mac */
340 (print_string_2d (e) := with_default_2d_display (printf (false, "~m", e)), 0);
343 print_string_2d (-b-a);
350 print_string_2d (-c-a);
357 print_string_2d (-c-b);
364 print_string_2d (-c+b+a);
371 print_string_2d (-c+b-a);
378 print_string_2d (-c-b+a);
385 print_string_2d (-c-b-a);
392 print_string_2d (-a);
399 print_string_2d (a-b);
406 print_string_2d (a-c);
413 print_string_2d (b-a);
420 print_string_2d (b-c);
427 print_string_2d (c+b-a);
434 print_string_2d (c-a);
441 print_string_2d (c-b);
448 print_string_2d (c-b+a);
455 print_string_2d (c-b-a);
462 /* -a/b, (-a)/b, and -(a/b) all parse to the same thing,
463 * therefore we should expect all three to be displayed the same.
472 block ([display2d_unicode: false], print_string_2d (-a/b));
481 block ([display2d_unicode: false], print_string_2d (-(a/b)));
490 block ([display2d_unicode: false], print_string_2d ((-a)/b));
499 /* -(a + b)/c and (-(a + b))/c parse to the same thing,
500 * but -((a + b)/c) parses to something else,
501 * therefore we should expect the first two are displayed the same,
502 * and the third is something different.
505 is ((-(a + b))/c = -(a + b)/c);
508 is (-((a + b)/c) = -(a + b)/c);
511 block ([display2d_unicode: false], print_string_2d (-(a + b)/c));
520 block ([display2d_unicode: false], print_string_2d ((-(a + b))/c));
526 string ((-(a + b))/c);
529 block ([display2d_unicode: false], print_string_2d (-((a + b)/c)));
535 string (-((a + b)/c));
538 /* SF bug #4092: "Repeated factorial (n!)! displayed the same as double factorial n!!" */
540 (kill (n), with_default_2d_display(printf (false, "~m", (n!)!)));
544 printf (false, "~a", (n!)!);
548 "\\left(n!\\right)!";
550 /* verify that "!" continues to interact correctly with other operators */
561 '(n! := if n = 0 then 1 else n*(n - 1)!);
562 (n!) := (if (n = 0) then 1 else (n*((n - 1)!)));
568 (n!) : ((m!) : (o!));
571 (n!) := ((m!) : (o!));
573 /* verify double factorial symbol continues to work the same */
582 genfact(genfact(n, n/2, 2), genfact(n, n/2, 2)/2, 2);
585 genfact(n!, n!/2, 2);
588 genfact(m, m/2, 2)*genfact(n, n/2, 2);