Windows installer: Update help text for the maxima_longnames program.
[maxima/cygwin.git] / tests / rtest11.mac
blobf462b1de419dedb47ed1898f26a5ef0cb46aed24
1 /*************** -*- Mode: MACSYMA; Package: MAXIMA -*-  ******************/
2 /***************************************************************************
3 ***                                                                    *****
4 ***     Copyright (c) 1984 by William Schelter,University of Texas     *****
5 ***     All rights reserved                                            *****
6 ***************************************************************************/
9 (kill(all), use_fast_arrays: true, 0);
11 display(b[1,2]);
12 done$
13 exp1:integrate(1/(x^3+2),x);  
14 -log(x^2-2^(1/3)*x+2^(2/3))/(6*2^(2/3))+atan((2*x-2^(1/3))/(2^(1/3)*sqrt(3)))
15                                         /(2^(2/3)*sqrt(3))
16                                        +log(x+2^(1/3))/(3*2^(2/3));
17 /* tops 20 got exp1 below but exp2 is also ok.*/
18 /* lispm got
19 -2^(1/3)*log(2^(2/3)*x^2-2*x+2*2^(1/3))/12
20  +2^(1/3)*atan((2*2^(2/3)*x-2)/(2*sqrt(3)))/(2*sqrt(3))
21  +2^(1/3)*log(x+2^(1/3))/6$ */
22 exp2:diff(exp1,x);
23 1/(3*((2*x-2^(1/3))^2/(3*2^(2/3))+1))-(2*x-2^(1/3))
24                                /(6*2^(2/3)*(x^2-2^(1/3)*x+2^(2/3)))
25                               +1/(3*2^(2/3)*(x+2^(1/3)))$  
26                                 
27 /* was 1/(3*((2*2^(2/3)*x-2)^2/12+1))-2^(1/3)*(2*2^(2/3)*x-2)
28                                /(12*(2^(2/3)*x^2-2*x+2*2^(1/3)))
29                               +2^(1/3)/(6*(x+2^(1/3)))$
30                                 which is equal
31 */                              
32 radcan(exp2);
33 1/(x^3+2)$
34 (exp1:-log(x^2-2^(1/3)*x+2^(2/3))/(6*2^(2/3))+atan((2*x-2^(1/3))/(2^(1/3)*sqrt(3)))
35                                         /(2^(2/3)*sqrt(3))
36                                        +log(x+2^(1/3))/(3*2^(2/3)),0);
39 /* It's not easy to test reveal. Let's not worry about it too much. */
40 expand(reveal(exp1,2),0,0);
41 Negterm + 2 * Quotient$
43 expand(reveal(exp1,3),0,0);
44 log/Product(2)+atan/Product(2)-Quotient$
46 g(l):=catch(map(lambda([x],if x < 0 then throw(x) else f(x)),l));
47 g(l):=catch(map(lambda([x],if x < 0 then throw(x) else f(x)),l))$
48 g([1,2,3,7]);
49 [f(1),f(2),f(3),f(7)]$
50 g([1,2,-3,7]);
51 -3$
53 (kill(b),0);
56 exp1:y^2+b*x;
57 y^2+b*x$
59 orderless(y);
60 done$
62 y^2+b*x;
63 b*x+y^2$
65 string(%-exp1);
66 "y^2-y^2"$
68 unorder();
69 [y]$
70 exp:a^2+b*x;
71 b*x+a^2$
72 ordergreat(a);
73 done$
75 a^2+b*x;
76 a^2+b*x$
78 string(%-exp);
79 "a^2-a^2"$
81 unorder();
82 [a]$
84 exp:a^2+b*x;
85 b*x+a^2$
87 ordergreat(a);
88 done$
90 a^2+b*x;
91 a^2+b*x$
93 string(%-exp);
94 "a^2-a^2"$
96 unorder();
97 [a]$
98 declare(f,linear);
99 done$
100 f(2*a+3*b);
101 3*f(b)+2*f(a)$
102 f(2*x+y,x);
103 f(1,x)*y+2*f(x,x)$
104 declare (c1, constant);
105 done;
106 f (x*c1/2 + 2*y/c1);
107 c1*f(x)/2 + 2*f(y)/c1;
108 declare(f,additive);
109 done$
110 f(2*a+3*b);
111 3*f(b)+2*f(a)$
112 declare(f,outative);
113 done$
114 f(2*a);
115 2*f(a)$
116 declare(f,multiplicative);
117 done$
118 f(2*a*b);
119 2*f(a)*f(b)$
120 (kill(functions),declare(g,lassociative));
121 done$
122 g(g(a,b),g(c,d));
123 g(g(g(a,b),c),d)$
124 g(g(a,b),g(c,d))-g(a,g(b,g(c,d)));
126 declare(g,rassociative);
127 done$
128 g(g(a,b),g(c,d));
129 g(g(g(a,b),c),d)$
130 g(g(a,b),g(c,d))-g(a,g(b,g(c,d)));
132 (kill(h),declare(h,commutative));
133 done$
134 h(x,z,y);
135 h(x,y,z)$
136 (kill(h),declare(h,symmetric));
137 done$
138 h(x,z,y);
139 h(x,y,z)$
140 (kill(h),declare(h,antisymmetric));
141 done$
142 h(x,z,y);
143 -h(x,y,z)$
144 h[x,z,y]$
145 -h[x,y,z];
146 (kill(all),declare(j,nary));
147 done$
148 j(j(a,b),j(c,d));
149 j(a,b,c,d)$
150 declare(f,oddfun);
151 done$
152 f(-x);
153 -f(x)$
154 declare(g,evenfun);
155 done$
156 g(-x);
157 g(x)$
158 (kill(all),kill(g),declare(f,posfun));
159 done$
160 is(f(x) > 0);
161 true$
163 (kill (foo), declare (foo, [nary, symmetric]));
164 done;
166 foo (a, 1, h, 2, z, d, %pi);
167 foo (1, 2, %pi, a, d, h, z);
169 foo (a, foo (1, foo (h, 2), z), foo (d, %pi));
170 foo (1, 2, %pi, a, d, h, z);
172 (kill(all),b[1,x]:1);
175 (array(f,2,3),0);
178 arrayinfo(b);
179 [hash_table, true, [1, x]]$
180 /* tops 20:  this is incompatible difference [hashed,2,[1,x]]$ */
181 arrayinfo(f);
182 [declared,2,[2,3]]$
183 block([use_fast_arrays:false],kill(bb),bb[1,x]:7,arrayinfo(bb));
184 [hashed, 2, [1, x]];
185 block([use_fast_arrays:true],kill(bb),bb[1,x]:7,arrayinfo(bb));
186 [hash_table, true, [1, x]]$
187 properties(?cons);
188 ["system function"]$
189 assume(var1 > 0);
190 [var1 > 0]$
191 properties(var1);
192 ["database info",var1 > 0]$
193 var2:2;
195 properties(var2);
196 [value]$
197 gradef(r,x,x/r);
199 gradef(r,y,y/r);
201 printprops(r,atomgrad);
202 done$
203 propvars(atomgrad);
204 [r]$
205 gradef(r,x,x/r);
207 gradef(r,y,y/r);
209 printprops(r,atomgrad);
210 done$
211 propvars(atomgrad);
212 [r]$
213 put(%e,transcendental,type);
214 transcendental$
215 put(%pi,transcendental,type);
216 transcendental$
217 block([algebraic:false],put(%i,algebraic,type));
218 false$
219 typeof(x):=block([q],if numberp(x) then return(algebraic),
220        if not atom(x) then return(maplist(typeof,x)),q:get(x,type),
221        if q = false then error("not numeric") else q);
222 typeof(x):=block([q],if numberp(x) then return(algebraic),
223        if not atom(x) then return(maplist(typeof,x)),q:get(x,type),
224        if q = false then error("not numeric") else q)$
225 block([algebraic:false],errcatch(typeof(2*%e+x*%pi)));
227 block([algebraic:false],typeof(2*%e+%pi));
228 [transcendental,[false,transcendental]]$
229 is(x^2 >= 2*x-1);
230 true$
231 assume(a > 1);
232 [a > 1]$
233 is(log(log(a+1)+1) > 0 and a^2+1 > 2*a);
234 true$
235 freeof(y,sin(x+2*y));
236 false$
237 freeof(cos(y),"*",sin(y)+cos(x));
238 true$
240 /* freeof should try both noun and verb forms */
242 (kill (f, g, h, x, n), 0);
245 freeof (sin, sin (x));
246 false;
248 freeof (integrate, 'integrate (f(x), x));
249 false;
251 freeof (diff, 'diff (f(x), x));
252 false;
254 freeof (sum, 'sum (f(x), x, 1, n));
255 false;
257 freeof (limit, 'limit (f(x), x, inf));
258 false;
260 freeof (sin, f (g (1 + sin (h (x)))));
261 false;
263 freeof (integrate, f (g (x - 'integrate (h (x), x))));
264 false;
266 freeof (diff, f (g (x * 'diff (h (x), x, 3))));
267 false;
269 freeof (sum, f (g (x / 'sum (h (x), x, 2, n))));
270 false;
272 freeof (limit, f (g (x ^ 'limit (h (x), x, inf))));
273 false;
275 /* Additional freeof tests */
277 lfreeof([x],y);
278 true$
279 lfreeof([x],y+z);
280 true$
281 lfreeof([x,y],y+z);
282 false$
283 use_fast_arrays: false;
284 false;
286 /* Check various lambda list possibilities */
287 freeof (x, lambda ([], x));
288 false$
289 freeof (x, lambda ([x], x));
290 true$
291 freeof (x, lambda (['x], x));
292 true$
293 freeof (x, lambda ([[x]], x));
294 true$
295 freeof (x, lambda ([['x]], x));
296 true$
298 freeof (x, 'block ([x], x));
299 true$
300 freeof (x, 'block ([x : foo], x));
301 true$
303 /* Check the loop variable */
304 freeof (x, '(for x thru 3 do print (x)));
305 true$
306 freeof (x, '(for x in [1, 2, 3] do print (x)));
307 true$
309 /* It would be nice to test foreign language characters here.
310  * Is there a way to make such tests independent of environment stuff like $LANG ??
311  */
313 declare ("|~`", alphabetic);
314 done;
316 [member ('alphabetic, properties ("|")), member ('alphabetic, properties ("`")), member ('alphabetic, properties ("~"))];
317 [true, true, true];
319 ~`||`~ : ~|^`~ - |~^~`;
320 ~|^`~ - |~^~`;
322 (kill (~`||`~), ~`||`~);
323 '~`||`~;
325 (remove ("`~", alphabetic), remove ("|", alphabetic));
326 done;
328 [member ('alphabetic, properties ("|")), member ('alphabetic, properties ("`")), member ('alphabetic, properties ("~"))];
329 [false, false, false];
331 /* SF bug #3320: "Cannot declare string of one character as alphabetic"
332  */
334 kill (a, b, c, foo, bar, baz);
335 done;
337 [foo, bar, baz] : [a\+b, a+b, a + b];
338 [a\+b, b + a, b + a];
340 [is(foo = bar), is(foo = baz), is(bar = baz)];
341 [false, false, true];
343 [symbolp(foo), symbolp(bar), symbolp(baz)];
344 [true, false, false];
346 declare ("+", alphabetic);
347 done;
349 [foo, bar, baz] : [a\+b, a+b, a + b];
350 [a\+b, a\+b, b + a];
352 [is(foo = bar), is(foo = baz), is(bar = baz)];
353 [true, false, false];
355 [symbolp(foo), symbolp(bar), symbolp(baz)];
356 [true, true, false];
358 remove ("+", alphabetic);
359 done;
361 [foo, bar, baz] : [a\+b, a+b, a + b];
362 [a\+b, b + a, b + a];
364 [is(foo = bar), is(foo = baz), is(bar = baz)];
365 [false, false, true];
367 [symbolp(foo), symbolp(bar), symbolp(baz)];
368 [true, false, false];
370 /* Verify that time functions are defined and return numbers.
371  * Don't bother trying to verify if the values are reasonable.
372  */
373 [integerp (absolute_real_time ()), floatnump (elapsed_real_time ()), floatnump (elapsed_run_time ())];
374 [true, true, true];
376 stringp (timedate ());
377 true;
379 stringp (timedate (100*365*24*3600));
380 true;
382 /* date formatting */
384 timedate (0, 0);
385 "1900-01-01 00:00:00+00:00";
387 timedate (86400, -1927/225);
388 "1900-01-01 15:26:00-08:34";
390 timedate (86400, 1927/225);
391 "1900-01-02 08:34:00+08:34";
393 timedate (0, float (0));
394 "1900-01-01 00:00:00+00:00";
396 timedate (86400, float (-1927/225));
397 "1900-01-01 15:26:00-08:34";
399 timedate (86400, float (1927/225));
400 "1900-01-02 08:34:00+08:34";
402 /* date parsing */
404 parse_timedate (timedate (86400));
405 86400;
407 parse_timedate (timedate (86401));
408 86401;
410 parse_timedate (timedate (87400));
411 87400;
413 parse_timedate (timedate (1000000));
414 1000000;
416 parse_timedate (timedate (1000000000));
417 1000000000;
419 parse_timedate (timedate (10000000000));
420 10000000000;
422 parse_timedate (timedate (86400, 8.75));
423 86400;
425 parse_timedate (timedate (86401, -1/4));
426 86401;
428 parse_timedate (timedate (87400, 24));
429 87400;
431 parse_timedate (timedate (1000000, -24.0));
432 1000000;
434 parse_timedate (timedate (1000000000, 0));
435 1000000000;
437 parse_timedate (timedate (10000000000, float (1927/225)));
438 10000000000;
440 map (parse_timedate,
441 ["1951-02-28 05:39:56,000-08",
442  "1951-02-28 05:39:56.000-08",
443  "1951-02-28 05:39:56,000-08:00",
444  "1951-02-28 05:39:56,000-0800",
445  "1951-02-28 05:39:56.000-08:00",
446  "1951-02-28 05:39:56.000-0800",
447  "1951-02-28 05:39:56-08",
448  "1951-02-28 05:39:56-08:00",
449  "1951-02-28 05:39:56-0800",
450  "1951-02-28T05:39:56,000-08",
451  "1951-02-28T05:39:56.000-08",
452  "1951-02-28T05:39:56,000-08:00",
453  "1951-02-28T05:39:56,000-0800",
454  "1951-02-28T05:39:56.000-08:00",
455  "1951-02-28T05:39:56.000-0800",
456  "1951-02-28T05:39:56-08",
457  "1951-02-28T05:39:56-08:00",
458  "1951-02-28T05:39:56-0800"]);
459 [1614433196, 1614433196, 1614433196, 1614433196, 1614433196, 1614433196, 1614433196, 1614433196, 1614433196,
460  1614433196, 1614433196, 1614433196, 1614433196, 1614433196, 1614433196, 1614433196, 1614433196, 1614433196];
462 map (parse_timedate,
463 ["2029-11-03 15:29:53-00:00",
464  "2029-11-03 15:29:53-0000",
465  "2029-11-03 15:29:53-00",
466  "2029-11-03 15:29:53+00:00",
467  "2029-11-03 15:29:53+0000",
468  "2029-11-03 15:29:53+00",
469  "2029-11-03 15:29:53Z",
470  "2029-11-03T15:29:53-00:00",
471  "2029-11-03T15:29:53-0000",
472  "2029-11-03T15:29:53-00",
473  "2029-11-03T15:29:53+00:00",
474  "2029-11-03T15:29:53+0000",
475  "2029-11-03T15:29:53+00",
476  "2029-11-03T15:29:53Z"]);
477 [4097402993, 4097402993, 4097402993, 4097402993, 4097402993, 4097402993, 4097402993,
478  4097402993, 4097402993, 4097402993, 4097402993, 4097402993, 4097402993, 4097402993];
480 map (parse_timedate,
482  "1900-01-02 00:00:00+24:00",
483  "1900-01-01 23:00:00+23:00",
484  "1900-01-01 22:00:00+22:00",
485  "1900-01-01 21:00:00+21:00",
486  "1900-01-01 20:00:00+20:00",
487  "1900-01-01 19:00:00+19:00",
488  "1900-01-01 18:00:00+18:00",
489  "1900-01-01 17:00:00+17:00",
490  "1900-01-01 16:00:00+16:00",
491  "1900-01-01 15:00:00+15:00",
492  "1900-01-01 14:00:00+14:00",
493  "1900-01-01 13:00:00+13:00",
494  "1900-01-01 12:00:00+12:00",
495  "1900-01-01 11:00:00+11:00",
496  "1900-01-01 10:00:00+10:00",
497  "1900-01-01 09:00:00+09:00",
498  "1900-01-01 08:00:00+08:00",
499  "1900-01-01 07:00:00+07:00",
500  "1900-01-01 06:00:00+06:00",
501  "1900-01-01 05:00:00+05:00",
502  "1900-01-01 04:00:00+04:00",
503  "1900-01-01 03:00:00+03:00",
504  "1900-01-01 02:00:00+02:00",
505  "1900-01-01 01:00:00+01:00",
506  "1900-01-01 00:00:00+00:00",
507  "1900-01-01Z",
508  "1900-01-01 00:00:00-00:00",
509  "1899-12-31 23:00:00-01:00",
510  "1899-12-31 22:00:00-02:00",
511  "1899-12-31 21:00:00-03:00",
512  "1899-12-31 20:00:00-04:00",
513  "1899-12-31 19:00:00-05:00",
514  "1899-12-31 18:00:00-06:00",
515  "1899-12-31 17:00:00-07:00",
516  "1899-12-31 16:00:00-08:00",
517  "1899-12-31 15:00:00-09:00",
518  "1899-12-31 14:00:00-10:00",
519  "1899-12-31 13:00:00-11:00",
520  "1899-12-31 12:00:00-12:00",
521  "1899-12-31 11:00:00-13:00",
522  "1899-12-31 10:00:00-14:00",
523  "1899-12-31 09:00:00-15:00",
524  "1899-12-31 08:00:00-16:00",
525  "1899-12-31 07:00:00-17:00",
526  "1899-12-31 06:00:00-18:00",
527  "1899-12-31 05:00:00-19:00",
528  "1899-12-31 04:00:00-20:00",
529  "1899-12-31 03:00:00-21:00",
530  "1899-12-31 02:00:00-22:00",
531  "1899-12-31 01:00:00-23:00",
532  "1899-12-31 00:00:00-24:00"]);
533 [0, 0, 0, 0, 0, 0,  0, 0, 0, 0, 0, 0,
534  0, 0, 0, 0, 0, 0,  0, 0, 0, 0, 0, 0,
535  0, 0, 0, 0, 0, 0,  0, 0, 0, 0, 0, 0,
536  0, 0, 0, 0, 0, 0,  0, 0, 0, 0, 0, 0,
537  0, 0, 0];
539 map (parse_timedate,
540 ["1995-08-15 11:01:48-12:00",
541  "1995-08-15 12:01:48-11:00",
542  "1995-08-15 13:01:48-10:00",
543  "1995-08-15 14:01:48-09:00",
544  "1995-08-15 15:01:48-08:00",
545  "1995-08-15 16:01:48-07:00",
546  "1995-08-15 17:01:48-06:00",
547  "1995-08-15 18:01:48-05:00",
548  "1995-08-15 19:01:48-04:00",
549  "1995-08-15 20:01:48-03:00",
550  "1995-08-15 21:01:48-02:00",
551  "1995-08-15 22:01:48-01:00",
552  "1995-08-15 23:01:48+00:00",
553  "1995-08-16 00:01:48+01:00",
554  "1995-08-16 01:01:48+02:00",
555  "1995-08-16 02:01:48+03:00",
556  "1995-08-16 03:01:48+04:00",
557  "1995-08-16 04:01:48+05:00",
558  "1995-08-16 05:01:48+06:00",
559  "1995-08-16 06:01:48+07:00",
560  "1995-08-16 07:01:48+08:00",
561  "1995-08-16 08:01:48+09:00",
562  "1995-08-16 09:01:48+10:00",
563  "1995-08-16 10:01:48+11:00",
564  "1995-08-16 11:01:48+12:00",
565  "1995-08-15 10:54:48-12:07",
566  "1995-08-15 11:54:48-11:07",
567  "1995-08-15 12:54:48-10:07",
568  "1995-08-15 13:54:48-09:07",
569  "1995-08-15 14:54:48-08:07",
570  "1995-08-15 15:54:48-07:07",
571  "1995-08-15 16:54:48-06:07",
572  "1995-08-15 17:54:48-05:07",
573  "1995-08-15 18:54:48-04:07",
574  "1995-08-15 19:54:48-03:07",
575  "1995-08-15 20:54:48-02:07",
576  "1995-08-15 21:54:48-01:07",
577  "1995-08-15 23:08:48+00:07",
578  "1995-08-16 00:08:48+01:07",
579  "1995-08-16 01:08:48+02:07",
580  "1995-08-16 02:08:48+03:07",
581  "1995-08-16 03:08:48+04:07",
582  "1995-08-16 04:08:48+05:07",
583  "1995-08-16 05:08:48+06:07",
584  "1995-08-16 06:08:48+07:07",
585  "1995-08-16 07:08:48+08:07",
586  "1995-08-16 08:08:48+09:07",
587  "1995-08-16 09:08:48+10:07",
588  "1995-08-16 10:08:48+11:07",
589  "1995-08-16 11:08:48+12:07"]);
590 [3017516508, 3017516508, 3017516508, 3017516508, 3017516508,
591  3017516508, 3017516508, 3017516508, 3017516508, 3017516508,
592  3017516508, 3017516508, 3017516508, 3017516508, 3017516508,
593  3017516508, 3017516508, 3017516508, 3017516508, 3017516508,
594  3017516508, 3017516508, 3017516508, 3017516508, 3017516508,
595  3017516508, 3017516508, 3017516508, 3017516508, 3017516508,
596  3017516508, 3017516508, 3017516508, 3017516508, 3017516508,
597  3017516508, 3017516508, 3017516508, 3017516508, 3017516508,
598  3017516508, 3017516508, 3017516508, 3017516508, 3017516508,
599  3017516508, 3017516508, 3017516508, 3017516508, 3017516508];
601 map (parse_timedate,
602 ["1937-01-08 19:23:57Z",
603  "1937-01-08 19:23:57.4Z",
604  "1937-01-08 19:23:57,4Z",
605  "1937-01-08 19:23:57.49Z",
606  "1937-01-08 19:23:57,49Z",
607  "1937-01-08 19:23:57.492Z",
608  "1937-01-08 19:23:57,492Z",
609  "1937-01-08 19:23:57.4927Z",
610  "1937-01-08 19:23:57,4927Z",
611  "1937-01-08 19:23:57.49275Z",
612  "1937-01-08 19:23:57,49275Z",
613  "1937-01-08 19:23:57.492756Z",
614  "1937-01-08 19:23:57,492756Z"]);
615 ''(1168284237 + [0, 4/10, 4/10, 49/100, 49/100, 492/1000, 492/1000,
616                  4927/10000, 4927/10000, 49275/100000, 49275/100000,
617                  492756/1000000, 492756/1000000]);
619 map (parse_timedate,
620 ["2016-08-06 20:30:39-07:00", "1939-04-07 03:37:19-08:00",
621  "1905-12-14 08:56:45-08:00", "1904-07-09 13:46:49-08:00",
622  "1907-10-12 18:35:02-08:00", "2023-02-05 13:03:42-08:00",
623  "1971-12-28 15:31:52-08:00", "1929-06-05 17:51:35-08:00",
624  "1929-02-17 15:26:28-08:00", "1997-08-16 10:17:57-07:00"]);
625 [3679529439, 1239017839, 187808205, 142638409, 245471702,
626  3884619822, 2271799912, 928633895, 919293988, 3080740677];
628 map (parse_timedate,
629 ["    2016-08-06 20:30:39-07:00    ", "     1939-04-07 03:37:19-08:00",
630  "1905-12-14 08:56:45-08:00     ", "                1904-07-09 13:46:49-08:00",
632 1907-10-12 18:35:02-08:00", "2023-02-05 13:03:42-08:00
636    1971-12-28 15:31:52-08:00", "
638 1929-06-05 17:51:35-08:00
641  "1929-02-17 15:26:28-08:00            ", "       1997-08-16 10:17:57-07:00       "]);
642 [3679529439, 1239017839, 187808205, 142638409, 245471702,
643  3884619822, 2271799912, 928633895, 919293988, 3080740677];
645 map (parse_timedate,
646 ["2016-08-06 20:30:39 (America/Los_Angeles)",
647  "1939-04-07 03:37:19 (GMT-8)",
648  "1905-12-14 8:56:45",
649  "1904-7-1",
650  "1907-10-12 18:35:02-8:00",
651  "2023-02-05 13:03:42-08:0",
652  "1971-12-28 15:31:52:123",
653  "1929-06-05 7:51:35-08:00",
654  "1929-02-17 15:26:28 -08:00",
655  "1997-08-16 10.17.57",
656  "2015-01-12  01:02:03",
657  "1982-05-28 T18:17:16"]);
658 [false, false, false, false, false,
659  false, false, false, false, false,
660  false, false];
662 /* test cases adapted from similar examples for timedate/parse_timedate */
664 decode_time (0, 0);
665 [1900, 1, 1, 0, 0, 0, 0];
667 /* output differs from similar timedate because decode_time doesn't round tz offset */
668 decode_time (86400, -1927/225);
669 [1900, 1, 1, 15, 26, 8, -1927/225];
671 /* output differs from similar timedate because decode_time doesn't round tz offset */
672 decode_time (86400, 1927/225);
673 [1900, 1, 2, 8, 33, 52, 1927/225];
675 decode_time (0, float (0));
676 [1900, 1, 1, 0, 0, 0, 0];
678 /* output differs from similar timedate because decode_time doesn't round tz offset */
679 decode_time (86400, float (-1927/225));
680 [1900, 1, 1, 15, 26, 8, -1927/225];
682 /* output differs from similar timedate because decode_time doesn't round tz offset */
683 decode_time (86400, float (1927/225));
684 [1900, 1, 2, 8, 33, 52, 1927/225];
686 encode_time (1951, 2, 28, 5, 39, 56, -8);
687 1614433196;
689 decode_time (1614433196, -8);
690 [1951, 2, 28, 5, 39, 56, -8];
692 encode_time (2029, 11, 3, 15, 29, 53, 0);
693 4097402993;
695 decode_time (4097402993, 0);
696 [2029, 11, 3, 15, 29, 53, 0];
698 map (lambda ([l], apply (encode_time, l)),
699 [[1900, 1, 2, 0, 0, 0, +24],
700  [1900, 1, 1, 23, 0, 0, +23],
701  [1900, 1, 1, 22, 0, 0, +22],
702  [1900, 1, 1, 21, 0, 0, +21],
703  [1900, 1, 1, 20, 0, 0, +20],
704  [1900, 1, 1, 19, 0, 0, +19],
705  [1900, 1, 1, 18, 0, 0, +18],
706  [1900, 1, 1, 17, 0, 0, +17],
707  [1900, 1, 1, 16, 0, 0, +16],
708  [1900, 1, 1, 15, 0, 0, +15],
709  [1900, 1, 1, 14, 0, 0, +14],
710  [1900, 1, 1, 13, 0, 0, +13],
711  [1900, 1, 1, 12, 0, 0, +12],
712  [1900, 1, 1, 11, 0, 0, +11],
713  [1900, 1, 1, 10, 0, 0, +10],
714  [1900, 1, 1, 9, 0, 0, +09],
715  [1900, 1, 1, 8, 0, 0, +08],
716  [1900, 1, 1, 7, 0, 0, +07],
717  [1900, 1, 1, 6, 0, 0, +06],
718  [1900, 1, 1, 5, 0, 0, +05],
719  [1900, 1, 1, 4, 0, 0, +04],
720  [1900, 1, 1, 3, 0, 0, +03],
721  [1900, 1, 1, 2, 0, 0, +02],
722  [1900, 1, 1, 1, 0, 0, +01],
723  [1900, 1, 1, 0, 0, 0, +00],
724  [1900, 1, 1, 0, 0, 0, -00],
725  [1899, 12, 31, 23, 0, 0, -01],
726  [1899, 12, 31, 22, 0, 0, -02],
727  [1899, 12, 31, 21, 0, 0, -03],
728  [1899, 12, 31, 20, 0, 0, -04],
729  [1899, 12, 31, 19, 0, 0, -05],
730  [1899, 12, 31, 18, 0, 0, -06],
731  [1899, 12, 31, 17, 0, 0, -07],
732  [1899, 12, 31, 16, 0, 0, -08],
733  [1899, 12, 31, 15, 0, 0, -09],
734  [1899, 12, 31, 14, 0, 0, -10],
735  [1899, 12, 31, 13, 0, 0, -11],
736  [1899, 12, 31, 12, 0, 0, -12],
737  [1899, 12, 31, 11, 0, 0, -13],
738  [1899, 12, 31, 10, 0, 0, -14],
739  [1899, 12, 31, 9, 0, 0, -15],
740  [1899, 12, 31, 8, 0, 0, -16],
741  [1899, 12, 31, 7, 0, 0, -17],
742  [1899, 12, 31, 6, 0, 0, -18],
743  [1899, 12, 31, 5, 0, 0, -19],
744  [1899, 12, 31, 4, 0, 0, -20],
745  [1899, 12, 31, 3, 0, 0, -21],
746  [1899, 12, 31, 2, 0, 0, -22],
747  [1899, 12, 31, 1, 0, 0, -23],
748  [1899, 12, 31, 0, 0, 0, -24]]);
749 [0, 0, 0, 0, 0, 0,  0, 0, 0, 0, 0, 0,
750  0, 0, 0, 0, 0, 0,  0, 0, 0, 0, 0, 0,
751  0, 0, 0, 0, 0, 0,  0, 0, 0, 0, 0, 0,
752  0, 0, 0, 0, 0, 0,  0, 0, 0, 0, 0, 0,
753  0, 0];
755 map (lambda ([tz], decode_time (0, tz)),
756      append (makelist (24 - h, h, 0, 24), makelist (-h, h, 0, 24)));
757 [[1900, 1, 2, 0, 0, 0, +24],
758  [1900, 1, 1, 23, 0, 0, +23],
759  [1900, 1, 1, 22, 0, 0, +22],
760  [1900, 1, 1, 21, 0, 0, +21],
761  [1900, 1, 1, 20, 0, 0, +20],
762  [1900, 1, 1, 19, 0, 0, +19],
763  [1900, 1, 1, 18, 0, 0, +18],
764  [1900, 1, 1, 17, 0, 0, +17],
765  [1900, 1, 1, 16, 0, 0, +16],
766  [1900, 1, 1, 15, 0, 0, +15],
767  [1900, 1, 1, 14, 0, 0, +14],
768  [1900, 1, 1, 13, 0, 0, +13],
769  [1900, 1, 1, 12, 0, 0, +12],
770  [1900, 1, 1, 11, 0, 0, +11],
771  [1900, 1, 1, 10, 0, 0, +10],
772  [1900, 1, 1, 9, 0, 0, +09],
773  [1900, 1, 1, 8, 0, 0, +08],
774  [1900, 1, 1, 7, 0, 0, +07],
775  [1900, 1, 1, 6, 0, 0, +06],
776  [1900, 1, 1, 5, 0, 0, +05],
777  [1900, 1, 1, 4, 0, 0, +04],
778  [1900, 1, 1, 3, 0, 0, +03],
779  [1900, 1, 1, 2, 0, 0, +02],
780  [1900, 1, 1, 1, 0, 0, +01],
781  [1900, 1, 1, 0, 0, 0, +00],
782  [1900, 1, 1, 0, 0, 0, -00],
783  [1899, 12, 31, 23, 0, 0, -01],
784  [1899, 12, 31, 22, 0, 0, -02],
785  [1899, 12, 31, 21, 0, 0, -03],
786  [1899, 12, 31, 20, 0, 0, -04],
787  [1899, 12, 31, 19, 0, 0, -05],
788  [1899, 12, 31, 18, 0, 0, -06],
789  [1899, 12, 31, 17, 0, 0, -07],
790  [1899, 12, 31, 16, 0, 0, -08],
791  [1899, 12, 31, 15, 0, 0, -09],
792  [1899, 12, 31, 14, 0, 0, -10],
793  [1899, 12, 31, 13, 0, 0, -11],
794  [1899, 12, 31, 12, 0, 0, -12],
795  [1899, 12, 31, 11, 0, 0, -13],
796  [1899, 12, 31, 10, 0, 0, -14],
797  [1899, 12, 31, 9, 0, 0, -15],
798  [1899, 12, 31, 8, 0, 0, -16],
799  [1899, 12, 31, 7, 0, 0, -17],
800  [1899, 12, 31, 6, 0, 0, -18],
801  [1899, 12, 31, 5, 0, 0, -19],
802  [1899, 12, 31, 4, 0, 0, -20],
803  [1899, 12, 31, 3, 0, 0, -21],
804  [1899, 12, 31, 2, 0, 0, -22],
805  [1899, 12, 31, 1, 0, 0, -23],
806  [1899, 12, 31, 0, 0, 0, -24]];
808 map (lambda ([tz], decode_time (3017516508, tz)), makelist (h, h, -12, 12));
809 [[1995, 8, 15, 11, 1, 48, -12],
810  [1995, 8, 15, 12, 1, 48, -11],
811  [1995, 8, 15, 13, 1, 48, -10],
812  [1995, 8, 15, 14, 1, 48, -09],
813  [1995, 8, 15, 15, 1, 48, -08],
814  [1995, 8, 15, 16, 1, 48, -07],
815  [1995, 8, 15, 17, 1, 48, -06],
816  [1995, 8, 15, 18, 1, 48, -05],
817  [1995, 8, 15, 19, 1, 48, -04],
818  [1995, 8, 15, 20, 1, 48, -03],
819  [1995, 8, 15, 21, 1, 48, -02],
820  [1995, 8, 15, 22, 1, 48, -01],
821  [1995, 8, 15, 23, 1, 48, +00],
822  [1995, 8, 16, 0, 1, 48, +01],
823  [1995, 8, 16, 1, 1, 48, +02],
824  [1995, 8, 16, 2, 1, 48, +03],
825  [1995, 8, 16, 3, 1, 48, +04],
826  [1995, 8, 16, 4, 1, 48, +05],
827  [1995, 8, 16, 5, 1, 48, +06],
828  [1995, 8, 16, 6, 1, 48, +07],
829  [1995, 8, 16, 7, 1, 48, +08],
830  [1995, 8, 16, 8, 1, 48, +09],
831  [1995, 8, 16, 9, 1, 48, +10],
832  [1995, 8, 16, 10, 1, 48, +11],
833  [1995, 8, 16, 11, 1, 48, +12]];
835 map (lambda ([tz], decode_time (3017516508, tz)),
836      append (makelist (-(12 - h + 7/60), h, 0, 11),
837              makelist (+(h + 7/60), h, 0, 12)));
838 [[1995, 8, 15, 10, 54, 48, -12 - 7/60],
839  [1995, 8, 15, 11, 54, 48, -11 - 7/60],
840  [1995, 8, 15, 12, 54, 48, -10 - 7/60],
841  [1995, 8, 15, 13, 54, 48, -09 - 7/60],
842  [1995, 8, 15, 14, 54, 48, -08 - 7/60],
843  [1995, 8, 15, 15, 54, 48, -07 - 7/60],
844  [1995, 8, 15, 16, 54, 48, -06 - 7/60],
845  [1995, 8, 15, 17, 54, 48, -05 - 7/60],
846  [1995, 8, 15, 18, 54, 48, -04 - 7/60],
847  [1995, 8, 15, 19, 54, 48, -03 - 7/60],
848  [1995, 8, 15, 20, 54, 48, -02 - 7/60],
849  [1995, 8, 15, 21, 54, 48, -01 - 7/60],
850  [1995, 8, 15, 23, 8, 48, +00 + 7/60],
851  [1995, 8, 16, 0, 8, 48, +01 + 7/60],
852  [1995, 8, 16, 1, 8, 48, +02 + 7/60],
853  [1995, 8, 16, 2, 8, 48, +03 + 7/60],
854  [1995, 8, 16, 3, 8, 48, +04 + 7/60],
855  [1995, 8, 16, 4, 8, 48, +05 + 7/60],
856  [1995, 8, 16, 5, 8, 48, +06 + 7/60],
857  [1995, 8, 16, 6, 8, 48, +07 + 7/60],
858  [1995, 8, 16, 7, 8, 48, +08 + 7/60],
859  [1995, 8, 16, 8, 8, 48, +09 + 7/60],
860  [1995, 8, 16, 9, 8, 48, +10 + 7/60],
861  [1995, 8, 16, 10, 8, 48, +11 + 7/60],
862  [1995, 8, 16, 11, 8, 48, +12 + 7/60]];
864 map (lambda ([l], apply (encode_time, l)),
865 [[2016, 8, 6, 20, 30, 39, -7], [1939, 4, 7, 3, 37, 19, -8],
866  [1905, 12, 14, 8, 56, 45, -8], [1904, 7, 9, 13, 46, 49, -8],
867  [1907, 10, 12, 18, 35, 2, -8], [2023, 2, 5, 13, 3, 42, -8],
868  [1971, 12, 28, 15, 31, 52, -8], [1929, 6, 5, 17, 51, 35, -8],
869  [1929, 2, 17, 15, 26, 28, -8], [1997, 8, 16, 10, 17, 57, -7]]);
870 [3679529439, 1239017839, 187808205, 142638409, 245471702,
871  3884619822, 2271799912, 928633895, 919293988, 3080740677];
873 map (lambda ([l], apply (decode_time, l)),
874 [[3679529439, -7], [1239017839, -8], [187808205, -8], [142638409, -8], [245471702, -8],
875  [3884619822, -8], [2271799912, -8], [928633895, -8], [919293988, -8], [3080740677, -7]]);
876 [[2016, 8, 6, 20, 30, 39, -7], [1939, 4, 7, 3, 37, 19, -8],
877  [1905, 12, 14, 8, 56, 45, -8], [1904, 7, 9, 13, 46, 49, -8],
878  [1907, 10, 12, 18, 35, 2, -8], [2023, 2, 5, 13, 3, 42, -8],
879  [1971, 12, 28, 15, 31, 52, -8], [1929, 6, 5, 17, 51, 35, -8],
880  [1929, 2, 17, 15, 26, 28, -8], [1997, 8, 16, 10, 17, 57, -7]];
882 /* encode_time and decode_time should be inverses, for a given timezone offset. */
884 (unix_epoch_seconds : parse_timedate ("1970-01-01 00:00:00+00:00"),
885  encode_decode_test_with_tz_offset () :=
886    block ([t, m, t_decoded, t_decoded_encoded, tz_offset],
887      t : random (2^32 + unix_epoch_seconds),
888      m : random (3),
889      tz_offset : random (48*60^m) / 60^m - 24,
890      t_decoded : decode_time (t, tz_offset),
891      t_decoded_encoded : apply (encode_time, t_decoded),
892      if t_decoded_encoded = t
893        then true
894        else ('apply (encode_time, 'decode_time (t, tz_offset)) = t_decoded_encoded) # t),
895   sublist (makelist (encode_decode_test_with_tz_offset (), 200), lambda ([e], e # true)));
898 (encode_decode_test_with_tz_default () :=
899    block ([t, t_decoded, t_decoded_encoded],
900      t : random (2^32 + unix_epoch_seconds),
901      t_decoded : decode_time (t),
902      t_decoded_encoded : apply (encode_time, t_decoded),
903      if t_decoded_encoded = t
904        then true
905        else ('apply (encode_time, 'decode_time (t)) = t_decoded_encoded) # t),
906   sublist (makelist (encode_decode_test_with_tz_default (), 200), lambda ([e], e # true)));
909 (decode_encode_test_with_tz_offset () :=
910    block ([m, args_mins, args_maxs, args_scale, n, tz_offset, a, a_encoded, a_encoded_decoded],
911      m : random (3),
912      args_mins : [1901, 1,  1,  0,  0,  0],
913      args_maxs : [ 200,12, 28, 24, 60, 60*10^m],
914      args_scale: [   1, 1,  1,  1,  1, 10^m],
915      n : 1 + random (6),
916      tz_offset : random (48*60^m) / 60^m - 24,
917      a : append (makelist (args_mins[i] + random (args_maxs[i])/args_scale[i], i, 1, n),
918                  makelist (args_mins[i], i, n + 1, 6),
919                  [tz_offset]),
920      a_encoded : apply (encode_time, a),
921      a_encoded_decoded : decode_time (a_encoded, tz_offset),
922      if a_encoded_decoded = a
923         then true
924         else ('decode_time (funmake (encode_time, a), tz_offset) = a_encoded_decoded) # a),
925   sublist (makelist (decode_encode_test_with_tz_offset (), 200), lambda ([e], e # true)));
928 (decode_encode_test_with_tz_default () :=
929    block ([m, args_mins, args_maxs, args_scale, n, a, a_encoded, a_encoded_decoded],
930      m : random (3),
931      args_mins : [1901, 1,  1,  0,  0,  0],
932      args_maxs : [ 200,12, 28, 24, 60, 60*10^m],
933      args_scale: [   1, 1,  1,  1,  1, 10^m],
934      n : 1 + random (6),
935      a : append (makelist (args_mins[i] + random (args_maxs[i])/args_scale[i], i, 1, n),
936                  makelist (args_mins[i], i, n + 1, 6)),
937      a_encoded : apply (encode_time, a),
938      a_encoded_decoded : decode_time (a_encoded),
939      if firstn (a_encoded_decoded, 6) = a
940         then true
941         else ('decode_time (funmake (encode_time, a)) = a_encoded_decoded) # a),
942   sublist (makelist (decode_encode_test_with_tz_default (), 200), lambda ([e], e # true)));
945 /* Do the right thing when listarray and arrayinfo are called within
946  * a function and the name of the formal argument coincides with the
947  * name of the actual argument. (Was a bug in ARRAYINFO-AUX.)
948  */
950 (foo(x) := apply (arrayinfo, [x]),
951  bar(x) := listarray (x),
952  kill (x),
953  x[1] : 1234,
954  foo(x));
955 [hashed, 1, [1]];
957 bar(x);
958 [1234];
960 (kill(y),
961  y[2] : 2345,
962  foo(y));
963 [hashed, 1, [2]];
965 bar(y);
966 [2345];
968 /* constant declaration -- bug reported to mailing list 2009-05-02 */
970 (kill (aa, xx, yy, zz), sort (listofvars (xx + yy * zz)));
971 [xx, yy, zz];
973 (aa : newcontext (), declare (zz, constant));
974 done;
976 facts (aa);
977 [kind (zz, constant)];
979 [featurep (xx, constant), featurep (yy, constant), featurep (zz, constant)];
980 [false, false, true];
982 constantp (zz);
983 true;
985 sort (listofvars (xx + yy * zz));
986 [xx, yy];
988 constantp (sin(xx)/exp(yy) + %pi^zz);
989 false;
991 declare ([xx, yy], constant);
992 done;
994 sort (facts (aa));
995 [kind (xx, constant), kind (yy, constant), kind (zz, constant)];
997 [featurep (xx, constant), featurep (yy, constant), featurep (zz, constant)];
998 [true, true, true];
1000 constantp (sin(xx)/exp(yy) + %pi^zz);
1001 true;
1003 kill (zz);
1004 done;
1006 sort (facts (aa));
1007 [kind (xx, constant), kind (yy, constant)];
1009 [featurep (xx, constant), featurep (yy, constant), featurep (zz, constant)];
1010 [true, true, false];
1012 constantp (zz);
1013 false;
1015 listofvars (xx + yy * zz);
1016 [zz];
1018 constantp (sin(xx)/exp(yy));
1019 true;
1021 constantp (sin(xx)/exp(yy) + %pi^zz);
1022 false;
1024 kill (xx, yy);
1025 done;
1027 facts (aa);
1030 [constantp (xx), constantp (yy), constantp (zz), constantp (xx + yy + zz)];
1031 [false, false, false, false];
1033 sort (listofvars (xx + yy * zz));
1034 [xx, yy, zz];
1036 killcontext (aa);
1037 done;
1039 /* tellsimp interaction with rassociative declaration
1040  * from the mailing list circa 2011-03-25
1041  */
1043 (kill (zand, zor, a, b, c), declare (zand, rassociative));
1044 done;
1046 zand (a, zand (b, c));
1047 zand (a, zand (b, c));
1049 zand (zand (a, b), c);
1050 zand (a, zand (b, c));
1052 (matchdeclare ([var1, var2, var3], all),
1053  tellsimp (zand (zor (var1, var2), var3), zor (zand (var1, var3), zand (var2, var3))),
1054  tellsimp (zand (var1, zor (var2, var3)), zor (zand (var1, var2), zand (var1, var3))),
1055  0);
1058 zand (zor (a, b), c);
1059 zor (zand (a, c), zand (b, c));
1061 zand (a, zor (b, c));
1062 zor (zand (a, b), zand (a, c));
1064 zand (a, zand (b, c));
1065 zand (a, zand (b, c));
1067 zand (zand (a, b), c);
1068 zand (a, zand (b, c));
1070 /* try it w/ lassociative as well */
1072 (remove (zand, rassociative), declare (zand, lassociative));
1073 done;
1075 zand (zand (a, b), c);
1076 zand (zand (a, b), c);
1078 zand (a, zand (b, c));
1079 zand (zand (a, b), c);
1081 zand (zor (a, b), c);
1082 zor (zand (a, c), zand (b, c));
1084 zand (a, zor (b, c));
1085 zor (zand (a, b), zand (a, c));
1087 /* another lassociative/rassociative bug, tickled by rule which returns an atom
1088  * reported to mailing list 2015-03-16: "Requesting advice on simplification rules for user-defined operators"
1089  */
1091 kill (a, b, c, d, e, f, z);
1092 done;
1094 (kill ("wedge"),
1095  nary ("wedge"),
1096  declare ("wedge", [commutative, lassociative]),
1097  matchdeclare (var, true),
1098  0);
1101 (tellsimpafter (0 wedge var, 0),
1102  0);
1105 ev (a wedge (b wedge (c wedge (0 wedge d))) wedge (e wedge f), infeval);
1108 (kill ("wedge"),
1109  nary ("wedge"),
1110  declare ("wedge", [commutative, rassociative]),
1111  matchdeclare (var, true),
1112  0);
1115 (tellsimpafter (var wedge z, z),
1116  0);
1119 ev (a wedge (b wedge (c wedge (z wedge d))) wedge (e wedge f), infeval);
1122 /* some tests for partition */
1124 (kill (foo, u, e1, e2, e3),
1125  e1 : 'at ('diff (foo (u), u), u = 0),
1126  e2 : 'integrate (foo (u), u, 0, 1),
1127  e3 : 'sum (foo (u), u, 1, n),
1128  [freeof (u, e1), freeof (u, e2), freeof (u, e3)]);
1129 [true, true, true];
1131 partition (e1 * sin (u), u);
1132 [''e1, sin (u)];
1134 partition (e2 * sin (u), u);
1135 [''e2, sin (u)];
1137 partition (e3 * sin (u), u);
1138 [''e3, sin (u)];
1140 integrate (e1 * cos (u), u);
1141 sin (u) * ''e1;
1143 integrate (e1 * cos (u), u, 1, 2);
1144 (sin (2) - sin (1)) * ''e1;
1146 integrate (e2 * cos (u), u);
1147 sin (u) * ''e2;
1149 integrate (e2 * cos (u), u, 1, 2);
1150 (sin (2) - sin (1)) * ''e2;
1152 integrate (e3 * cos (u), u);
1153 sin (u) * ''e3;
1155 integrate (e3 * cos (u), u, 1, 2);
1156 (sin (2) - sin (1)) * ''e3;
1158 diff (e1 * sin (u), u);
1159 ''e1 * cos (u);
1161 diff (e2 * sin (u), u);
1162 ''e2 * cos (u);
1164 diff (e3 * sin (u), u);
1165 ''e3 * cos (u);
1167 (reset(use_fast_arrays),1);
1170 /* ensure that remove(..., rule) works OK when applied to a string */
1172 remove ("ierieidkkcmxc", rule);
1173 done;