Update AUTHORS file using admin/list_authors.pl.
[maxima/cygwin.git] / tests / rtest3.mac
blobae3c449315abb1b49d714ce4ff7952e1b600be21
1 /*************** -*- Mode: MACSYMA; Package: MAXIMA -*-  ******************/
2 /***************************************************************************
3 ***                                                                    *****
4 ***     Copyright (c) 1984 by William Schelter,University of Texas     *****
5 ***     All rights reserved                                            *****
6 ***************************************************************************/
9 /* rtest3 */                                            
10 kill(all);
11 done;
12 for a from -3 step 7 thru 26 do ldisplay(a);
13 done$
14 s:0;
16 for i while i <= 10 do s:s+i;
17 done$
19 55$
20 series:1;
22 term:exp(sin(x));
23 %e^sin(x)$
24 for p unless p > 7 do
25     (term:diff(term,x)/p,series:series+subst(x = 0,term)*x^p);
26 done$
27 series;
28 x^7/90-x^6/240-x^5/15-x^4/8+x^2/2+x+1$
29 poly:0;
31 for i thru 5 do (for j from i step -1 thru 1 do poly:poly+i*x^j);
32 done$
33 poly;
34 5*x^5+9*x^4+12*x^3+14*x^2+15*x$
35 guess:-3.0;
36 -3.0$
37 for i thru 10 do
38     (guess:subst(guess,x,0.5*(x+10/x)),
39      if abs(guess^2-10) < 5.0e-5 then return(guess));
40 -3.162280701754386;
41 /* -3.1622806$ */
42 for count from 2 next 3*count thru 20 do ldisplay(count);
43 done$
44 x:1000;
45 1000$
46 thru 10 while x # 0 do x:0.5*(x+5/x);
47 done$
49 2.282429035887867$
50 remvalue(x);
51 [x]$
52 newton(f,guess):=block([numer,y],local(f,df,x,guess),numer:true,
53        define(df(x),diff(f(x),x)),
54        do (y:df(guess),if y = 0 then error("derivative at",guess,"is zero"),
55            guess:guess-f(guess)/y,
56            if abs(f(guess)) < 5.0e-6 then return(guess)));
57 newton(f,guess):=block([numer,y],local(f,df,x,guess),numer:true,
58        define(df(x),diff(f(x),x)),
59        do (y:df(guess),if y = 0 then error("derivative at",guess,"is zero"),
60            guess:guess-f(guess)/y,
61            if abs(f(guess)) < 5.0e-6 then return(guess)))$
62 sqr(x):=x^2-5.0;
63 sqr(x):=x^2-5.0$
64 newton(sqr,1000);
65 2.236068027062195; 
66 for f in [log,rho,atan] do ldisp(f(1.0));
67 done$
68 ev(concat(e,linenum-1),numer);
69 e10$
70 kill(functions,values,arrays);
71 done$
72 done;
73 done$
74 exp:diff(x*f(x),x);
75 x*'diff(f(x),x,1)+f(x)$
76 f(x):=sin(x);
77 f(x):=sin(x)$
78 ev(exp,diff);
79 sin(x)+x*cos(x)$
82 x:3;
86 'x;
88 f(x):=x^2;
89 f(x):=x^2$
90 'f(2);
91 'f(2)$
92 ev(%,f);
94 '(f(2));
95 f(2)$
96 f(2);
98 sum(i!,i,1,4);
99 33$
100 'sum(i!,i,1,4);
101 'sum(i!,i,1,4)$
102 remvalue(x);
103 [x]$
104 'integrate(f(x),x,a,b);
105 'integrate(x^2,x,a,b)$
106 for i thru 5 do s:s+i^2;
107 done$
108 exp:s;
109 s+55$
110 ev(%,s:0);
112 ev(exp);
113 s+110$
114 exp:'sum(g(i),i,0,n);
115 'sum(g(i),i,0,n)$
116 z*%e^z;
117 z*%e^z$
118 ev(%,z:x^2);
119 x^2*%e^x^2$
120 subst(x^2,z,exp);
121 'sum(g(i),i,0,n)$
122 a:%;
123 'sum(g(i),i,0,n)$
124 a+1;
125 'sum(g(i),i,0,n)+1$
126 kill(a,y);
127 done$
130 declare(integrate,noun);
131 done$
132 integrate(y^2,y);
133 integrate(y^2,y)$
134 ''integrate(y^2,y);
135 y^3/3$
136 f(y):=diff(y*log(y),y,2);
137 f(y):=diff(y*log(y),y,2)$
138 f(y):=1/y;
139 f(y):=1/y$
140 c10;
141 c10$
142 (x+y)^3;
143 (y+x)^3$
144 diff(%,x);
145 3*(y+x)^2$
146 y:x^2+1;
147 x^2+1$
149 /* begin fix */
150 kill(all);
151 done;
152  ev(%e^x*sin(x)^2,exponentialize);
153  -%e^x*(%e^(%i*x)-%e^-(%i*x))^2/4;
154   integrate(%,x);
155 -((%e^((2*%i+1)*x)/(2*%i+1)+%e^((1-2*%i)*x)/(1-2*%i)-2*%e^x)/4); 
156  ev(%,demoivre);
157  -((%e^x*(%i*sin(2*x)+cos(2*x))/(2*%i+1)
158       +%e^x*(cos(2*x)-%i*sin(2*x))/(1-2*%i)-2*%e^x)
159       /4);
160  ans:ev(%,ratexpand);
161  -%e^x*sin(2*x)/5-%e^x*cos(2*x)/10+%e^x/2;
162  ev(ans,x:1,numer)-ev(ans,x:0,numer);
163  0.5779160182042402;
164  (fpprec : 35, 0);
165  0;
166  ev(ans,x:1,bfloat)-ev(ans,x:0,bfloat);
167  5.7791601820424019599988308251707781b-1;
168  integrate(%e^x*sin(x)^2,x);
169  -(((2*%e^x*sin(2*x)+%e^x*cos(2*x)-5*%e^x)/10));
170  trigreduce(%);
171  -((2*%e^x*sin(2*x)+%e^x*cos(2*x)-5*%e^x)/10);
172  % - ans,ratsimp;
173  0 ;
174  reset (fpprec);
175  [fpprec];
177 /* end fix*/
179 ev(sin(x),%emode);
180 sin(x)$
181 sin(%pi/12)+tan(%pi/6);
182 sin(%pi/12)+1/sqrt(3)$
183 ev(%,numer);
184 0.8361693142921465;
185 /* tops 20 : 0.83616931$ */
186 sin(1);
187 sin(1)$
188 ev(sin(1),numer);
189 0.8414709848078965$
190 beta(1/2,2/5);
191 beta(1/2,2/5)$
192 ev(%,numer);
193 3.679093980405881;
194 /* tops 20: 3.67909265$ */
195 diff(atanh(sqrt(x)),x);
196 1/(2*(1-x)*sqrt(x))$
197 fpprec:25;
199 sin(5.0b-1);
200 4.794255386042030002732879b-1$
201 (reset (fpprec), 0);
203 /*begin fix */
204  exp:cos(x)^2-sin(x)^2;
205  cos(x)^2-sin(x)^2$
206  ev(%,x:%pi/3);
207  -1/2$
208  diff(exp,x);
209  -4*cos(x)*sin(x)$
210  integrate(exp,x);
211  (sin(2*x)/2+x)/2-(x-sin(2*x)/2)/2$
212  expand(%);
213  sin(2*x)/2$
214  trigexpand(%);
215  cos(x)*sin(x)$
216  trigreduce(%);
217  sin(2*x)/2$
218  diff(%,x);
219  cos(2*x)$
220  %-exp,trigreduce,ratsimp;
221   0;
222 /*end fix*/
223 sech(x)^2*sinh(x)*tanh(x)/coth(x)^2+cosh(x)^2*sech(x)^2*tanh(x)/coth(x)^2
224                                    +sech(x)^2*tanh(x)/coth(x)^2;
225 sech(x)^2*sinh(x)*tanh(x)/coth(x)^2+cosh(x)^2*sech(x)^2*tanh(x)/coth(x)^2
226                                    +sech(x)^2*tanh(x)/coth(x)^2$
227 trigsimp(%);
228 (sinh(x)^5+sinh(x)^4+2*sinh(x)^3)/cosh(x)^5$
229 /* These are from the trgsmp.dem file.  
230  * I (rtoy) hand-verified these results (using maxima, of course)
231  */
232 (1-sin(x)^2)*cos(x)/cos(x)^2+tan(x)*sec(x)^2;
233 (1-sin(x)^2)*cos(x)/cos(x)^2+tan(x)*sec(x)^2$
234 trigsimp(%);
235 (sin(x)+cos(x)^4)/cos(x)^3$
237 tan(x)^2+sec(x)^2/(1-tan(x)*sec(x));
238 tan(x)^2+sec(x)^2/(1-tan(x)*sec(x))$
239 trigsimp(%);
240 (sin(x)^4+sin(x)^3-1)/(cos(x)^2*sin(x)-cos(x)^4)$
242 (sin(x)^4-6*cos(x)^2*sin(x)^2+4*(cos(x)^2-sin(x)^2)+8*sin(x)+cos(x)^4+3)/(8*cos(x)^3);
243 (sin(x)^4-6*cos(x)^2*sin(x)^2+4*(cos(x)^2-sin(x)^2)+8*sin(x)+cos(x)^4+3)/(8*cos(x)^3)$
244 trigsimp(%);
245 (sin(x)+cos(x)^4)/cos(x)^3$
248 sech(x)^2*sinh(x)*tanh(x)/coth(x)^2+cosh(x)^2*sech(x)^2*tanh(x)/coth(x)^2+sech(x)^2*tanh(x)/coth(x)^2;
249 sech(x)^2*sinh(x)*tanh(x)/coth(x)^2+cosh(x)^2*sech(x)^2*tanh(x)/coth(x)^2+sech(x)^2*tanh(x)/coth(x)^2$
250 trigsimp(%);
251 (sinh(x)^5+sinh(x)^4+2*sinh(x)^3)/cosh(x)^5$
253 -sech(x)^5*(sinh(x)^5+2*(sinh(x)^4+6*cosh(x)^2*sinh(x)^2+cosh(x)^4)-13*(sinh(x)^3+3*cosh(x)^2*sinh(x))+10*cosh(x)^2*sinh(x)^3-8*(sinh(x)^2+cosh(x)^2)+5*cosh(x)^4*sinh(x)+34*sinh(x)+6)/16;
254 -sech(x)^5*(sinh(x)^5+2*(sinh(x)^4+6*cosh(x)^2*sinh(x)^2+cosh(x)^4)-13*(sinh(x)^3+3*cosh(x)^2*sinh(x))+10*cosh(x)^2*sinh(x)^3-8*(sinh(x)^2+cosh(x)^2)+5*cosh(x)^4*sinh(x)+34*sinh(x)+6)/16$
255 trigsimp(%);
256 -((sinh(x)^5+sinh(x)^4-2*sinh(x)^3)/cosh(x)^5)$
258 cos(x)*(sec(x)^2*tan(x)+1)-sec(x)^2*sin(x)-cos(x);
259 cos(x)*(sec(x)^2*tan(x)+1)-sec(x)^2*sin(x)-cos(x)$
260 trigsimp(%);
263 v*cos(x)*sec(x)^2*tan(x)+(-v*sec(x)^2-2*'diff(v,x))*sin(x)+'diff(v,x)*cos(x)*sec(x)+'diff(v,x,2)*cos(x);
264 v*cos(x)*sec(x)^2*tan(x)+(-v*sec(x)^2-2*'diff(v,x))*sin(x)+'diff(v,x)*cos(x)*sec(x)+'diff(v,x,2)*cos(x)$
265 trigsimp(%);
266 -2*'diff(v,x,1)*sin(x)+'diff(v,x,2)*cos(x)+'diff(v,x,1)$
268 triginverses : all;
269 all;
271 sinh(acosh(x));
272 sqrt(x-1)*sqrt(x+1);
274 sinh(atanh(x));
275 x/(sqrt(1-x)*sqrt(x+1));
277 cosh(asinh(x));
278 sqrt(x^2+1);
280 cosh(atanh(x));
281 1/(sqrt(1-x)*sqrt(x+1));
283 tanh(asinh(x));
284 x/sqrt(x^2+1);
286 tanh(acosh(x));
287 sqrt(x-1)*sqrt(x+1)/x;
289 /* A few checks to see that triginverses false disables the above transformations */
290 triginverses: false;
291 false;
293 cos(acosh(x));
294 cos(acosh(x));
296 triginverses : all;
297 all;
299 /* SF bug # 1981518, Calling desolve inside a "for...do" makes it loop endlessly
300  * (protect against endless loop by throw--catch in case bug is triggered)
301  */
302 catch (block ([foo:1],
303  for i thru 3 do (ilt (1/s, s, t),
304  if foo > 3 then throw ('i = i) else foo : foo + 1)));
305 done;
307 /* bug reported to mailing list 2009-05-09
308  * unexpected behavior in for loop with variable step
309  */
311 block ([L : []], for r:0 thru 7 step +2 do L : cons (r, L), L);
312 [6, 4, 2, 0];
314 block ([L : []], for r:7 thru 0 step -2 do L : cons (r, L), L);
315 [1, 3, 5, 7];
317 block ([L : [], r0 : 0, r1 : 7, s : +2], for r:r0 thru r1 step s do L : cons (r, L), L);
318 [6, 4, 2, 0];
320 block ([L : [], r0 : 7, r1 : 0, s : -2], for r:r0 thru r1 step s do L : cons (r, L), L);
321 [1, 3, 5, 7];
323 /* step is evaluated once at start of loop, so these loops are defined */
325 block ([L : [], s : +2], for i:1 thru 10 step s do L : cons (s : -s, L), L);
326 [-2, 2, -2, 2, -2];
328 block ([L : [], s : -2], for i:10 thru 1 step s do L : cons (s : -s, L), L);
329 [2, -2, 2, -2, 2];
331 /* bug reported to mailing list 2009-05-13 "reset ( radexpand,  domain )"
333  * display2d is a resettable option variable. We save the value of display2d
334  * and restore it after the reset. This allows to run the testsuite in both
335  * display modes.
336  */
337 (save:display2d, done);
338 done$
339 (reset (), [radexpand, domain]);
340 [true, real];
341 (display2d:save, done);
342 done$
344 [radexpand, domain] : [all, complex];
345 [all, complex];
347 reset (radexpand, domain);
348 [radexpand, domain];
350 [radexpand, domain];
351 [true, real];
353 ([foo, bar, baz] : [1, 2, 3],
354  /* should ignore these non-defmvar's */
355  reset (foo, bar, baz));
358 /* verify that ORDFNA can handle CRE.
359  */
360 (kill (a, b), [doallmxops, doscmxops] : [false, false], 0);
363 b*matrix([rat(a)]);
364 b*matrix([''(rat(a))]);
366 (reset (doallmxops, doscmxops), 0);
369 /* SF bug #2936: stack overflow in integrate */
371 kill (x, A, B, MU, SIGMA);
372 done;
374 trigsimp (gamma_incomplete (1, log (x)));
375 gamma_incomplete (1, log (x));
377 trigsimp ((%i*gamma_incomplete(1,(1-2*log(x))^2/4)*(1-2*log(x))^2)
378            /(2*log(x)-1)^2);
379 %i*gamma_incomplete(1,(4*log(x)^2-4*log(x)+1)/4)$
381 trigsimp (integrate (%e^((-log(x)^2)-1)*log(x),x));
382 -(%e^-(3/4)*(2*gamma_incomplete(1,(4*log(x)^2-4*log(x)+1)/4)*abs(2*log(x)-1)
383             +2*gamma_incomplete(1/2,(4*log(x)^2-4*log(x)+1)/4)*log(x)
384             -gamma_incomplete(1/2,(4*log(x)^2-4*log(x)+1)/4)))
385  /(4*abs(2*log(x)-1))$
387 /* throw away results of integrate, just make sure it runs without crashing */
388 block ([foo, bar, ctxt],
389   foo : exp(-(log(x) - MU)*(log(x) - MU)/(2*SIGMA*SIGMA))/(x*SIGMA*sqrt(2*%pi)),
390   bar : (log(B) - log(x*SIGMA) + ((x-A)*(x-A)/(2*B*B) - (log(x) -MU)*(log(x) -MU)/(2*SIGMA*SIGMA))),
391   [foo, bar] : subst ([A=2, MU=3], [foo, bar]),
392   ctxt : newcontext (),
393   assume (SIGMA > 0, B > 0),
394   integrate (expand (foo*bar), x),
395   integrate (expand (foo*bar), x, 2, inf),
396   killcontext (ctxt),
397   0);
400 /* mailing list 2015-09-07: How can I catch this error? "errcatch" doesn't do the trick. */
402 /* result for this test will change if ever "quotient by zero" bug is fixed */
403 errcatch (integrate(ev(ratsimp(1/(x^(5/2)+3*x^(1/3))),algebraic),x));
406 (kill (foo, bar, baz), foo () := bar (), bar () := (errcatch (integrate(ev(ratsimp(1/(x^(5/2)+3*x^(1/3))),algebraic),x)), throw ('baz)), catch (foo ()));
407 baz;
409 /* This bug can be fixed by changing simplus to simplify 2^(3/2)*x^2 - sqrt(2)*x^2
410 to sqrt(2)*x^2. Until this bug is fixed, we'll errcatch this test. */
411 errcatch (integrate (exp(2^(3/2)*x^2 - sqrt(2)*x^2), x));
412 [-((sqrt(%pi)*%i*erf(2^(1/4)*%i*x))/2^(5/4))];
414 (kill (quux), bar () := (errcatch (integrate (exp(2^(3/2)*x^2 - sqrt(2)*x^2), x)), throw ('quux)), catch (foo ()));
415 quux;
417 /* result for this test will change if ever "quotient by zero" bug is fixed */
418 errcatch (taylor(coth(x), x, %i*%pi, 0));
421 (kill (mumble), bar () := (errcatch (taylor(coth(x), x, %i*%pi, 0)), throw ('mumble)), catch (foo ()));
422 mumble;
424 /* Verify that some special variables that were recently given DEFMVAR's are now resettable.
425  * If ever the default values of these variables are changed,
426  * some of the following tests will fail.
427  * In that case just update these tests to use the new default value.
428  */
430 (kill(mydefaults),
431  mydefaults['verbose] : false,
432  mydefaults['exptsubst] : false,
433  mydefaults['partswitch] : false,
434  mydefaults['inflag] : false,
435  mydefaults['derivsubst] : false,
436  mydefaults['opsubst] : true,
437  mydefaults['demoivre] : false,
438  mydefaults['nointegrate] : false,
439  mydefaults['tlimswitch] : true,
440  mydefaults['limsubst] : false,
441  mydefaults['abconvtest] : false,
442  mydefaults['packagefile] : false,
443  mydefaults['factlim] : 100000,
444  mydefaults['cflength] : 1,
445  mydefaults['taylordepth] : 3,
446  mydefaults['maxtaydiff] : 4,
447  mydefaults['lhospitallim] : 4,
448  mydefaults['linel] : 79,
449  0);
452 (reset (),
453  every (lambda ([v], is(mydefaults[v] = ev(v))), flatten (rest (arrayinfo (mydefaults), 2))));
454 true;
456 (myflags : '[verbose, exptsubst, partswitch, inflag, derivsubst, opsubst, demoivre,
457              nointegrate, tlimswitch, limsubst, abconvtest, packagefile],
458  /* "not" causes an extra evaluation of its argument,
459   * so this next line won't work as expected if "not" ever becomes
460   * simplifying operator; update this test case as needed if that
461   * ever comes to pass.
462   */
463  myflags :: map ("not", myflags),
464  ev (myflags));
465 [true, true, true, true, true, false, true, true, false, true, true, true];
467 map (reset, myflags);
468 [[verbose], [exptsubst], [partswitch], [inflag], [derivsubst], [opsubst], [demoivre],
469  [nointegrate], [tlimswitch], [limsubst], [abconvtest], [packagefile]];
471 ev (myflags);
472 [false, false, false, false, false, true, false, false, true, false, false, false];
474 (myvals : '[factlim, cflength, taylordepth, maxtaydiff, lhospitallim, linel],
475  myvals :: makelist (99, v, myvals),
476  ev (myvals));
477 [99, 99, 99, 99, 99, 99];
479 map (reset, myvals);
480 [[factlim], [cflength], [taylordepth], [maxtaydiff], [lhospitallim], [linel]];
482 ev (myvals);
483 [100000, 1, 3, 4, 4, 79];
485 declare_index_properties
486  (A, [],
487   B, [postsubscript],
488   C, [postsubscript, postsuperscript],
489   D, [postsubscript, postsuperscript, presuperscript],
490   E, [postsubscript, postsuperscript, presuperscript, presubscript],
491   F, [postsubscript, postsuperscript, presuperscript, presubscript,
492       postsubscript, postsuperscript, presuperscript, presubscript],
493   G, [postsubscript, postsuperscript, presuperscript, presubscript,
494       postsuperscript, presubscript]);
495 done;
497 map (get_index_properties, '[A, B, C, D, E, F, G]);
498 [[],
499  [postsubscript],
500  [postsubscript, postsuperscript],
501  [postsubscript, postsuperscript, presuperscript],
502  [postsubscript, postsuperscript, presuperscript, presubscript],
503  [postsubscript, postsuperscript, presuperscript, presubscript,
504   postsubscript, postsuperscript, presuperscript, presubscript],
505  [postsubscript, postsuperscript, presuperscript, presubscript,
506   postsuperscript, presubscript]];
508 kill (a, b, c, d, w, x, y, z);
509 done;
511 /* This business about capturing the output to a string and comparing that
512  * is a little fragile in the sense that changing invisible stuff (trailing
513  * spaces, newline character) can make these tests fail.
514  * But the pretty printer code changes very infrequently,
515  * and also I believe that these tests should work the same on Windows as
516  * on Unix-like platforms, because TERPRI (according to CLHS) just outputs #\Newline.
517  * Changing this file from NL to CR-NL line endings will presumably
518  * make these tests fail.
519  */
521 with_default_2d_display ([S: make_string_output_stream ()],
522   with_stdout (S, ?terpri (), print (A[x])),
523   get_output_stream_string (S));
525 A  
529 with_default_2d_display ([S: make_string_output_stream ()],
530   with_stdout (S, ?terpri (), print (B[x])),
531   get_output_stream_string (S));
533 B  
537 with_default_2d_display ([S: make_string_output_stream ()],
538   with_stdout (S, ?terpri (), print (C[x, y])),
539   get_output_stream_string (S));
542 C  
546 with_default_2d_display ([S: make_string_output_stream ()],
547   with_stdout (S, ?terpri (), print (D[x, y, z])),
548   get_output_stream_string (S));
550 z y
551  D  
552   x
555 with_default_2d_display ([S: make_string_output_stream ()],
556   with_stdout (S, ?terpri (), print (E[w, x, y, z])),
557   get_output_stream_string (S));
559 y x
560  E  
561 z w
564 with_default_2d_display ([S: make_string_output_stream ()],
565   with_stdout (S, ?terpri (), print (F[a, b, c, d, w, x, y, z])),
566   get_output_stream_string (S));
568 c, y b, x
569     F     
570 d, z a, w
573 with_default_2d_display ([S: make_string_output_stream ()],
574   with_stdout (S, ?terpri (), print (G[a, b, c, d, w, x])),
575   get_output_stream_string (S));
577    c b, w
578     G     
579 d, x a
582 with_default_2d_display ([S: make_string_output_stream ()],
583   with_stdout (S, ?terpri (), print (G[a, B[a], C[a, b], D[a, b, c], E[a, b, c, d], F[a, b, c, d, w, x, y, z]])),
584   get_output_stream_string (S));
586              b     c b
587             C  B ,  E
588              a  a  d a
589               G        
590 c b  c, y b, x a
591  D ,     F
592   a  d, z a, w
595 with_default_2d_display ([S: make_string_output_stream ()],
596   with_stdout (S, ?terpri (), print (sqrt (G[a, b, c, d, w, x]))),
597   get_output_stream_string (S));
599         c b, w
600 sqrt(    G    ) 
601      d, x a
604 with_default_2d_display ([S: make_string_output_stream ()],
605   with_stdout (S, ?terpri (), print ((1 - G[a, b, c, d, w, x])/E[1, 1/2, 2/3, 17/29])),
606   get_output_stream_string (S));
608        c b, w
609 1 -     G
610     d, x a
611 ------------- 
612     2/3 1/2
613        E
614   17/29 1
617 remove_index_properties (A, B, C, D, E, F, G);
618 done;
620 map (get_index_properties, '[A, B, C, D, E, F, G]);
621 [[], [], [], [], [], [], []];
623 /* email from Oleg Nesterov 2020-05-21: "maxima: bug in dsumprod() ?" */
625 (print_string_2d (e) := with_default_2d_display (printf (false, "~m", e)), 0);
628 print_string_2d (lsum(1/f(g(x)/h(x)), x, LOOOOOOOOONG_EXPR));
629 "====
630 \\                         1
631  >                     -------
632 /                        g(x)
633 ====                   f(----)
634 x in LOOOOOOOOONG_EXPR   h(x)
637 /* other examples which call DSUMPROD in test suite */
639 print_string_2d ('sum(x^k / k,k,1,inf));
640 "inf
641 ====   k
642 \\     x
643  >    --
644 /     k
645 ====
646 k = 1
649 print_string_2d (subst (k = \*index, 'sum(x^k / k,k,1,inf)));
650 "inf
651 ====        *index
652 \\          x
653  >         -------
654 /          *index
655 ====
656 *index = 1
659 print_string_2d ('sum(i!,i,1,4));
660 " 4
661 ====
663  >    i!
665 ====
666 i = 1
669 print_string_2d ('sum(g(i),i,0,n));
670 " n
671 ====
673  >    g(i)
675 ====
676 i = 0
679 print_string_2d ('sum(g(i),i,0,n) + 1);
680 " n
681 ====
683  >    g(i) + 1
685 ====
686 i = 0
689 print_string_2d (foo: unsum(product(i^2,i,1,n),n));
690 " n - 1
691  /===\\
692   ! !   2
693 ( ! !  i ) (n - 1) (n + 1)
694   ! !
695  i = 1
698 print_string_2d (nusum(foo,n,1,n));
699 "  n
700 /===\\
701  ! !   2
702  ! !  i  - 1
703  ! !
704 i = 1
707 print_string_2d (powerseries(log(sin(x)/x),x,0));
708 "inf
709 ====        i2  2 i2 - 1             2 i2
710 \\      (- 1)   2         bern(2 i2) x
711  >     ----------------------------------
712 /                  i2 (2 i2)!
713 ====
714 i2 = 1
717 print_string_2d (product((x^i+1)^2.5,i,1,inf)/(x^2+1));
718 " inf
719 /===\\
720  ! !    i     2.5
721  ! !  (x  + 1)
722  ! !
723 i = 1
724 -----------------
725       2
726      x  + 1
729 /* additional DSUMPROD examples */
731 print_string_2d ('lsum(1/(1+f(x)/2), kskdsksdkkdksdksd, w999393293923939losl));
732 "====
733 \\                                            1
734  >                                        --------
735 /                                         f(x)
736 ====                                      ---- + 1
737 kskdsksdkkdksdksd in w999393293923939losl  2
740 print_string_2d ('lsum(1/(1+f(x)/2), kskdsksdkkdksdksd, w999393293923939losl^2));
741 "====
742 \\                                             1
743  >                                         --------
744 /                                          f(x)
745 ====                                       ---- + 1
746                                          2  2
747 kskdsksdkkdksdksd in w999393293923939losl
750 print_string_2d ('lsum(1/(1+f(x)/2), kskdsksdkkdksdksd, w999393293923939losl^skdkskdsk));
751 "====
752 \\                                                     1
753  >                                                 --------
754 /                                                  f(x)
755 ====                                               ---- + 1
756                                          skdkskdsk  2
757 kskdsksdkkdksdksd in w999393293923939losl
760 /* ensure that nounified operators are displayed same as verbs
761  * follow-on work for bug reported to mailing list 2020-09-13: "Function name for matrix/vector dot product?"
762  */
764 kill (foo, x, y, z, a, b, c);
765 done;
767 print_string_2d (' "'"(foo));
768 "'foo
771 print_string_2d (' ":"(foo, 123));
772 "foo : 123
775 print_string_2d (' "::"(foo, 123));
776 "foo :: 123
779 print_string_2d (' ":="(foo(a, b), [x, y, z]));
780 "foo(a, b) := [x, y, z]
783 print_string_2d (' "::="(foo(a, b), [x, y, z]));
784 "foo(a, b) ::= [x, y, z]
787 print_string_2d (' "!"(4));
791 print_string_2d (' "^"(2, x));
792 " x
796 print_string_2d (' "^^"(a, b));
797 " <b>
801 print_string_2d (' "."(a, b, c));
802 "a . b . c
805 print_string_2d (' ?rat(a, b));
811 print_string_2d (' "/"(a, b));
817 print_string_2d (' "*"(a, b, c));
818 "a b c
821 print_string_2d (' "+"(a, b, c));
822 "a + b + c
825 print_string_2d (' "-"(a));
826 "- a
829 print_string_2d ('?marrow(a, b));
830 "a -> b
833 print_string_2d (' ">"(a, b));
834 "a > b
837 print_string_2d (' ">="(a, b));
838 "a >= b
841 print_string_2d (' "="(a, b));
842 "a = b
845 print_string_2d (' "#"(a, b));
846 "a # b
849 print_string_2d (' "<="(a, b));
850 "a <= b
853 print_string_2d (' "<"(a, b));
854 "a < b
857 print_string_2d (' "not"(a));
858 "not a
861 print_string_2d (' "and"(a, b));
862 "a and b
865 print_string_2d (' "or"(a, b));
866 "a or b
869 print_string_2d ('?mprogn(a, b, c));
870 "(a, b, c)
873 print_string_2d ('?mlist(a, b, c));
874 "[a, b, c]
877 /* example from mailing list 2019-04-02: "maxima lists" */
878 print_string_2d ('[x][1]);
879 "[x]
880    1
883 print_string_2d ('?mangle(a, b, c));
884 "<a, b, c>
887 print_string_2d ('?mcomma(a, b, c));
888 "a, b, c
891 print_string_2d ('?mabs(a));
892 "abs(a)
895 print_string_2d ('matrix([a, b, c]));
896 "[ a  b  c ]
899 print_string_2d ('?mbox(a));
900 "\"\"\"
901 \"a\"
902 \"\"\"
905 print_string_2d ('?mlabox (a, b));
906 "b\"\"
907 \"a\"
908 \"\"\"
911 print_string_2d ('?mtext ("hello"));
912 "hello
915 block ([linel: 65], print_string_2d ('?mlabel (a, b)));
916 "(a)                             b
920  * Test exponent of printed bigfloat is correct when number is rounded.
921  */
922 (fpprec:64, fpprintprec:16, done);
923 done;
925 print_string_2d(0.99999999999999999999b0);
926 "1.0b0
929 print_string_2d(1.99999999999999999999b0);
930 "2.0b0
933 bftrunc:false;
934 false;
936 print_string_2d(0.99999999999999999999b0);
937 "1.000000000000000b0
940 print_string_2d(1.99999999999999999999b0);
941 "2.000000000000000b0
944 (reset(fpprec, fpprintprec), done);
945 done;