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 block ([powerdisp : false],
118 verify_display_2d ((x+1)/(x+2),
125 block ([powerdisp : true],
126 verify_display_2d ((x+1)/(x+2),
133 block ([powerdisp : false], verify_display_1d ((x+1)/(x+2), "(x+1)/(x+2)"));
136 block ([powerdisp : true], verify_display_1d ((x+1)/(x+2), "(1+x)/(2+x)"));
139 (H : ( n2 * s^2 + n1 * s + n0 ) / ( d2 * s^2 + d1 * s + d0 ), 0);
142 block ([powerdisp : false], verify_display_2d (H,
151 block ([powerdisp : true], verify_display_2d (H,
160 block ([powerdisp : false], verify_display_1d (H, "(n2*s^2+n1*s+n0)/(d2*s^2+d1*s+d0)"));
163 block ([powerdisp : true], verify_display_1d (H, "(n0+n1*s+n2*s^2)/(d0+d1*s+d2*s^2)"));
167 /* mailing list 2015-09-08: "Maxima 5.37.1 changes in behaviour when simp:false" */
173 [?second (p), ?third (p)]);
187 [?second (p), ?third (p)]);
197 block ([powerdisp : false], verify_display_2d (diff (x^n, x),
203 block ([powerdisp : true], verify_display_2d (diff (x^n, x),
209 block ([powerdisp : false], verify_display_1d (diff (x^n, x), "n*x^(n-1)"));
212 block ([powerdisp : true], verify_display_1d (diff (x^n, x), "n*x^(-1+n)"));
215 /* mailing list 2015-09-04: "Inconsistent ordering: (x+1)^2 becomes (1+x)^2, but x+1 stays x+1" */
217 block ([powerdisp : false], verify_display_2d ((x+1)^2,
223 block ([powerdisp : true], verify_display_2d ((x+1)^2,
229 block ([powerdisp : false], verify_display_1d ((x+1)^2, "(x+1)^2"));
231 block ([powerdisp : true], verify_display_1d ((x+1)^2, "(1+x)^2"));
234 block ([powerdisp : false], verify_display_2d ((x^3+x^2+x+1)^2,
240 block ([powerdisp : true], verify_display_2d ((x^3+x^2+x+1)^2,
246 block ([powerdisp : false], verify_display_1d ((x^3+x^2+x+1)^2, "(x^3+x^2+x+1)^2"));
248 block ([powerdisp : true], verify_display_1d ((x^3+x^2+x+1)^2, "(1+x+x^2+x^3)^2"));
251 block ([powerdisp : false], verify_display_2d (x+1,
256 block ([powerdisp : true], verify_display_2d (x+1,
261 block ([powerdisp : false], verify_display_1d (x+1, "x+1"));
263 block ([powerdisp : true], verify_display_1d (x+1, "1+x"));
266 block ([powerdisp : false], verify_display_2d (x^3+x^2+x+1,
272 block ([powerdisp : true], verify_display_2d (x^3+x^2+x+1,
278 block ([powerdisp : false], verify_display_1d (x^3+x^2+x+1, "x^3+x^2+x+1"));
280 block ([powerdisp : true], verify_display_1d (x^3+x^2+x+1, "1+x+x^2+x^3"));
283 block ([powerdisp : false], verify_display_2d (2^(x+1),
289 block ([powerdisp : true], verify_display_2d (2^(x+1),
295 block ([powerdisp : false], verify_display_1d (2^(x+1), "2^(x+1)"));
297 block ([powerdisp : true], verify_display_1d (2^(x+1), "2^(1+x)"));
300 block ([powerdisp : false], verify_display_2d (2^(x^3+x^2+x+1),
307 block ([powerdisp : true], verify_display_2d (2^(x^3+x^2+x+1),
314 block ([powerdisp : false], verify_display_1d (2^(x^3+x^2+x+1), "2^(x^3+x^2+x+1)"));
316 block ([powerdisp : true], verify_display_1d (2^(x^3+x^2+x+1), "2^(1+x+x^2+x^3)"));
319 /* SF bug #3046 "Changes of behaviour with simp:false" */
321 block ([simp:false], string((3/6)*x));
324 string (lambda ([], (2/2)*u));
325 "lambda([],(2/2)*u)";
327 /* SF bug #4090: "output formatting: -x-1 has redundant parentheses: (-x)-1" */
329 /* copied print_string_2d from rtest3.mac */
330 (print_string_2d (e) := with_default_2d_display (printf (false, "~m", e)), 0);
333 print_string_2d (-b-a);
340 print_string_2d (-c-a);
347 print_string_2d (-c-b);
354 print_string_2d (-c+b+a);
361 print_string_2d (-c+b-a);
368 print_string_2d (-c-b+a);
375 print_string_2d (-c-b-a);
382 print_string_2d (-a);
389 print_string_2d (a-b);
396 print_string_2d (a-c);
403 print_string_2d (b-a);
410 print_string_2d (b-c);
417 print_string_2d (c+b-a);
424 print_string_2d (c-a);
431 print_string_2d (c-b);
438 print_string_2d (c-b+a);
445 print_string_2d (c-b-a);
452 /* -a/b, (-a)/b, and -(a/b) all parse to the same thing,
453 * therefore we should expect all three to be displayed the same.
462 print_string_2d (-a/b);
471 print_string_2d (-(a/b));
480 print_string_2d ((-a)/b);
489 /* -(a + b)/c and (-(a + b))/c parse to the same thing,
490 * but -((a + b)/c) parses to something else,
491 * therefore we should expect the first two are displayed the same,
492 * and the third is something different.
495 is ((-(a + b))/c = -(a + b)/c);
498 is (-((a + b)/c) = -(a + b)/c);
501 print_string_2d (-(a + b)/c);
510 print_string_2d ((-(a + b))/c);
516 string ((-(a + b))/c);
519 print_string_2d (-((a + b)/c));
525 string (-((a + b)/c));