Windows installer: update wxMaxima.
[maxima/cygwin.git] / tests / rtest_equal.mac
blob676b1e1fefe4f5fb6d54b9a9ceb84a04aa8adc5f
1 (prederror : false,0);
2 0$
4 /* bug 1489164 */
5 is(equal(%i,0));
6 false$
8 /* bug 1547584 */
9 is(equal([a],[a,b]));
10 false$
12 /* bug 1435600 */
13 is(equal(false,false));
14 true$
16 is(equal(false,true));
17 false$
19 is(equal(true,true));
20 true$
22 /* bug 1496329 */
23 is(equal(rat(matrix([x])),matrix([x])));
24 true$
26 is (equal (ident (2), rat (ident (2))));
27 true$
29 /* bug 649669*/
30 is(equal([x],[rat(x)]));
31 true$
33 /* bug 990924 */
34 is(equal((%e^(%i*z)-%e^-(%i*z)), 0));
35 unknown$
37 /* bug 851436 */
39 is(equal(rat((x+y+a)^3,x),rat((x+y+a)^3,y)));
40 true$
42 /* bug 884947  */
44 is(equal([1],[1]));
45 true$
47 is(equal([0],[1]));
48 false$
50 is(equal([a,0],[a,1]));
51 false$
53 is(equal([a,b],[a,c]));
54 unknown$
56 /* bug 812968 */
58 is(equal(x/(2*x*sqrt(2)) - 1/(2*x*sqrt(2)), (x-1)/(2*x*sqrt(2))));
59 true$
61 is(equal(1/sqrt(2),sqrt(2)/2));
62 true$
64 /* bug 902694 */
66 is(equal(ind,ind));
67 false$
69 is(equal(und,und));
70 false$
72 /* bug 885795 */
74 (assume(equal(i,j)),0);
77 is(equal(x[i], x[j]));
78 true$
80 is(equal(f(i),f(j)));
81 true$
83 (forget(equal(i,j)),0);
86 is(equal(inf,infinity));
87 false$
89 is(equal(minf,minf));
90 true$
92 is(equal(minf,infinity));
93 false$
95 is(equal(minf,und));
96 false$
98 is(equal(minf,ind));
99 false$
102 is(equal(%i,0));
103 false$
105 is(equal(%i, x));
106 false$
108 is(equal(%i,x + %i));
109 unknown$
111 is(equal(und, x));
112 false$
114 is(equal(inf, x));
115 false$
117 is(equal(inf,0));
118 false$
120 is(equal(infinity,x));
121 false$
123 is(equal(0,1));
124 false$
126 is(equal(0.23, 9.78));
127 false$
129 is(equal(0.23, 9.78b0));
130 false$
132 is(equal(23/10, 9.78b0));
133 false$
135 is(equal(7,[1,2,3]));
136 false$
138 is(equal(%pi,22/7));
139 false$
141 is(equal(1/sqrt(2), sqrt(2)/2));
142 true$
144 is(equal(x,x));
145 true$
147 is(equal(x,x+%pi));
148 false$
150 is(equal((x+1)^2, x^2 + 2*x+1));
151 true$
153 is(equal(x,0));
154 unknown$
156 is(equal(x,%i));
157 false$
159 is(equal(x + %i,x));
160 false$
162 is(equal(x^2+1,x^2/5));
163 false$
165 is(equal(%i*x,%i));
166 unknown$
168 is(equal([a],[b]));
169 unknown$
171 is(equal([a],[a,b]));
172 false$
174 is(equal([a],[a]));
175 true$
177 is(equal(a < b, a <= b));
178 false$
180 is(equal(a <= b, a <= b));
181 true$
183 is(equal(rat(x),x));
184 true$
186 is(equal(matrix([x]), rat(matrix([x]))));
187 true$
189 is(equal(matrix([x,y]), matrix([x,z])));
190 unknown$
192 is(equal(matrix([x,y],[p,q]), matrix([p,q],[x,y])));
193 unknown$
195 is(equal(matrix([x,y],[p,q]), matrix([p,q,s],[x,y,8])));
196 false$
198 is(equal(set(u,n,k), set(u,n,k,u,n,k)));
199 true$
201 is(equal(set(a,b,c), set(b,a,a)));
202 unknown$
204 is(equal(abs(1 + %i*z), z - %i));
205 false$
208 (assume(equal(x,y),equal(y,z)),0);
211 is(equal(x,z));
212 true$
214 is(equal([x],[z]));
215 true$
217 is(equal(f(x), f(z)));
218 true$
220 is(equal(f(x,y) + %pi, f(y,z) + %pi));
221 true$
223 is(equal(rat(x,y), rat(z,x)));
224 true$
226 is(equal(matrix([x,y],[4,5]), matrix([y,z],[4,5])));
227 true$
229 is(equal(matrix([x,y],[4,5]), matrix([y,z],[4,15])));
230 false$
232 is(equal(set(x,z),set(x)));
233 true$
235 is(equal(set(x,sqrt(2)), set(z,sqrt(2))));
236 true$
238 is(equal(x + %i * y, y + %i * z));
239 true$
241 is(equal(exp(%i * x), exp(%i * z)));
242 true$
244 is(equal([x,x],[y,z]));
245 true$
247 is(equal([y,y],[x,z]));
248 true$
250 is(equal(x+y,2*z));
251 true$
253 is(equal(x+y+z/3, 7*x/3));
254 true$
256 is(equal(max(x,a),max(y,a)));
257 true$
259 is(equal(max(x,y,z,8), max(x,8)));
260 true$
262 (forget(equal(x,y), equal(y,z)),0);
265 is(equal(zeroa, zerob));
266 false$
268 is(equal([zeroa],[zerob]));
269 false$
271 is(equal(matrix(),matrix()));
272 true$
274 is(equal(matrix([]),matrix([])));
275 true$
277 is(equal(matrix([]),matrix([],[])));
278 false$
280 is(equal([],[]));
281 true$
283 is(equal(set(),set()));
284 true$
286 is(equal(a = b, a = b));
287 true$
289 is(equal(a = b, b = a));
290 unknown$
292 is(equal(a < b, b < a));
293 unknown$
295 is(equal(7,[a,b]));
296 false$
298 is(equal([a,b],7));
299 false$
301 is(equal([a,b], a = b));
302 false$
304 is(equal(a=b,[a,b]));
305 false$
307 is(equal(a < b, b <= b))$
308 false$
310 is(equal([true], []));
311 false$
313 is(equal([true], [true]));
314 true$
316 is(equal([false], [true]));
317 false$
319 is(equal(false,[false]));
320 false$
322 (oak : set(macrocarpa, rubra, alba),0);
325 is(equal([macrocarpa, rubra, alba],oak))        ;
326 false$
328 is(equal(oak, [macrocarpa, rubra, alba]));
329 false$
331 is(equal(set(macrocarpa, rubra, alba),oak));
332 true$
334 is(equal(oak, set(macrocarpa, rubra, alba)));
335 true$
337 (assume(equal(macrocarpa, burr), equal(rubra,red), equal(alba,white)),0);
340 is(equal(oak,set(burr,red,white)));
341 true$
343 (remvalue(oak),0);
346 (forget(equal(macrocarpa, burr), equal(rubra,red), equal(alba,white)),0);
349 (assume(equal(a,b),equal(b,c),equal(c,d)),0);
352 is(equal(a*d,b*c));
353 true$
355 is(equal(a+b+c, 2*a+d));
356 true$
358 is(equal(a+b^2-c^3, b + a^2 - a^3));
359 true$
361 is(equal(f(a,b,c),f(d,b,a)));
362 true$
364 is(equal(set(1,a,d^2), set(1+a-d,d,a,b,c-a+d,a^2)));
365 true$
367 (forget(equal(a,b),equal(b,c),equal(c,d)),0);
370 is(equal(lambda([], 9), lambda([], 9)));
371 true$
373 is(equal(lambda([], x), lambda([], y)));
374 unknown$
376 is(equal(lambda([x], x), lambda([z],z)));
377 true$
379 is(equal(lambda([x], x), lambda([z],z^2)));
380 unknown$
382 is(equal(lambda([x,y], x), lambda([z],z)));
383 false$
385 is(equal(lambda([x],true), lambda([z],false)));
386 false$
388 is(equal(lambda([x],false), lambda([z],false)));
389 true$
391 (assume(equal(p,0)),0);
394 is(equal(lambda([x],x+p), lambda([y],y-p)));
395 true$
397 (forget(equal(p,0)),0);
400 is(equal(sum(1/kk,kk,1,n), sum(1/ii,ii,1,n)));
401 true$
403 is(equal(sum(1/kk,kk,1,m), sum(1/ii,ii,1,n)));
404 unknown$
406 is(equal(sqrt(5) - sum(%pi/kk,kk,1,n), sqrt(5) - sum(%pi/ii,ii,1,n)));
407 true$
409 is(equal(sqrt(5) - sum(%pi/kk,kk,1,m), sqrt(5) - sum(%pi/ii,ii,1,n)));
410 unknown$
412 is(equal(sum(sqrt(2)/i^2,i,1,inf), sum(sqrt(2)/j^2,j,1,inf)));
413 true$
415 is(equal(sum(sum(1/(i+j),i,1,j),j,1,n), sum(sum(1/(ii+jj),ii,1,jj),jj,1,n)));
416 true$
418 is(equal(sum(product((ii+jj)^2,ii,1,42*jj),jj,-7,n), sum(product((i+j)^2,i,1,42*j),j,-7,n)));
419 true$
421 is(equal(set(a), set(inf)));
422 false$
424 is(equal([a], [inf]));
425 false$
427 is(equal(set(a,b,c), set(a,b,c,minf)));
428 false$
430 is(equal(set(a,b,c), set(a,b,c,d)));
431 unknown$
433 is(equal(set(a), set(und)));
434 false$
436 is(equal(set(inf,und), set(inf,und)));
437 true$
439 is(equal(set(a), set(a,inf)));
440 false$
442 is(equal(set(a,inf),set(a)));
443 false$
445 is(equal(set(a,b), set(a,inf)));
446 false$
448 /* Ensure that equal is happy to compare objects of any
449  * Maxima or Lisp types.
451  * Stuff checked here (various Lisp types omitted):
453  *  string
454  *  Lisp array
455  *  Maxima declared array
456  *  Maxima undeclared array
457  */
459 (string1a : "FOO",
460  string1b : "FOO",
461  string2 : "BAR",
463  larray1a : make_array (any, 5),
464  fillarray (larray1a, makelist (i, i, 1, 5)),
465  larray1b : make_array (any, 5),
466  fillarray (larray1b, makelist (i, i, 1, 5)),
467  larray2 : make_array (any, 5),
468  fillarray (larray2, makelist (i^2, i, 1, 5)),
469  larray3 : make_array (any, 10),
470  fillarray (larray3, makelist (i, i, 1, 10)),
472  array (marray_declared_1, fixnum, 3, 4),
473  fillarray (marray_declared_1, makelist (i, i, 1, 20)),
474  array (marray_declared_2, fixnum, 3, 4),
475  fillarray (marray_declared_2, makelist (i, i, 1, 20)),
476  array (marray_declared_3, flonum, 3, 4),
477  fillarray (marray_declared_3, makelist (float(i), i, 1, 20)),
478  array (marray_declared_4, fixnum, 4, 3),
479  fillarray (marray_declared_4, makelist (2*i, i, 1, 20)),
481  marray_undeclared_1 [foo, bar] : 1234,
482  marray_undeclared_1 [baz, quux] : 2345,
483  marray_undeclared_2 [foo, bar] : 1234,
484  marray_undeclared_2 [baz, quux] : 2345,
485  marray_undeclared_3 [foo, bar] : 3456,
486  marray_undeclared_3 [baz, quux] : 4567,
487  marray_undeclared_4 [foo, bar, baz] : 5678,
489  marray_array_fcn_1 [u, v, w] := u*v*w,
490  marray_array_fcn_1 [2, 3, 4],
491  marray_array_fcn_1 [a, b, c],
492  marray_array_fcn_2 [u, v, w] := u*v*w,
493  marray_array_fcn_2 [2, 3, 4],
494  marray_array_fcn_2 [a, b, c],
495  marray_array_fcn_3 [u, v, w] := u*v*w,
496  marray_array_fcn_3 [7, x, 4],
497  marray_array_fcn_3 [a, 3, c],
498  marray_array_fcn_4 [u, v, w] := u + v + w,
499  marray_array_fcn_4 [2, 3, 4],
500  marray_array_fcn_4 [a, b, c],
502  marray_subscripted_fcn_1 [a, b] (x, y) := x^a + y^b,
503  marray_subscripted_fcn_1 [3, 2] (u, 7),
504  marray_subscripted_fcn_1 [m, n] (2, z),
505  marray_subscripted_fcn_2 [a, b] (x, y) := x^a + y^b,
506  marray_subscripted_fcn_2 [3, 2] (u, 7),
507  marray_subscripted_fcn_2 [m, n] (2, z),
508  marray_subscripted_fcn_3 [a, b] (x, y) := x^a + y^b,
509  marray_subscripted_fcn_3 [2, 5] (8, q),
510  marray_subscripted_fcn_3 [1, t] (9, e),
511  marray_subscripted_fcn_4 [a, b] (x, y) := a*x - b*y,
512  marray_subscripted_fcn_4 [3, 2] (u, 7),
513  marray_subscripted_fcn_4 [m, n] (2, z),
515  0);
518 /* Comparisons to same type */
520 is (equal (string1a, string1b));
521 true;
523 is (equal (string1a, string2));
524 false;
526 is (equal (larray1a, larray1b));
527 true;
529 is (equal (larray1a, larray2));
530 false;
532 is (equal (larray1a, larray3));
533 false;
535 is (equal (marray_declared_1, marray_declared_2));
536 true;
538 is (equal (marray_declared_1, marray_declared_3));
539 true;
541 is (equal (marray_declared_1, marray_declared_4));
542 false;
544 is (equal (marray_undeclared_1, marray_undeclared_2));
545 true;
547 is (equal (marray_undeclared_1, marray_undeclared_3));
548 false;
550 is (equal (marray_undeclared_1, marray_undeclared_4));
551 false;
553 is (equal (marray_array_fcn_1, marray_array_fcn_2));
554 true;
556 /* This test fails at present because array functions are
557  * compared via arrayinfo and listarray output,
558  * but array functions should be compared via their AEXPR properties.
559  */
560 is (equal (marray_array_fcn_1, marray_array_fcn_3));
561 true;
563 is (equal (marray_array_fcn_1, marray_array_fcn_4));
564 false;
566 is (equal (marray_subscripted_fcn_1, marray_subscripted_fcn_2));
567 true;
569 /* This test fails at present because subscripted functions are
570  * compared via arrayinfo and listarray output,
571  * but subscripted functions should be compared via their AEXPR properties.
572  */
573 is (equal (marray_subscripted_fcn_1, marray_subscripted_fcn_3));
574 true;
576 is (equal (marray_subscripted_fcn_1, marray_subscripted_fcn_4));
577 unknown; /* comparison of non-identical lambda expressions yields unknown */
579 /* Comparisons to different type */
581 /* No automatic type conversion */
582 is (equal (string1a, larray1a));
583 false;
585 is (equal (string1a, 1234));
586 false;
588 /* No automatic type conversion */
589 is (equal (string1a, 'FOO));
590 false;
592 is (equal (string1a, sin('x)));
593 false;
596 is (equal (larray1a, string1a));
597 false;
599 is (equal (larray1a, 1234));
600 false;
602 is (equal (larray1a, 'FOO));
603 false;
605 is (equal (larray1a, sin('x)));
606 false;
608 /* No automatic conversions between array types */
610 (similar_lisp_array : make_array (fixnum, 4, 5),
611  fillarray (similar_lisp_array, makelist (i, i, 1, 20)),
612  is (equal (marray_declared_1, similar_lisp_array)));
613 false;
615 (for i:0 thru 3
616    do for j:0 thru 4
617      do similar_undeclared_marray [i, j] : i*5 + j + 1,
618  is (equal (marray_declared_1, similar_undeclared_marray)));
619 false;
621 /* No automatic conversions between array and list or matrix */
623 (similar_nested_list : [[1, 2, 3, 4, 5], [6, 7, 8, 9, 10], [11, 12, 13, 14, 15], [16, 17, 18, 19, 20]],
624  is (equal (marray_declared_1, similar_nested_list)));
625 false;
627 (similar_matrix : apply (matrix, similar_nested_list),
628  is (equal (marray_declared_1, similar_matrix)));
629 false;
631 /* Comparisons via = */
633 /* Comparisons to same type */
635 is (string1a = string1b);
636 true;
638 is (string1a = string2);
639 false;
641 is (larray1a = larray1b);
642 true;
644 is (larray1a = larray2);
645 false;
647 is (larray1a = larray3);
648 false;
651 /* Comparisons to different type */
653 /* No automatic type conversion */
654 is (string1a = larray1a);
655 false;
657 is (string1a = 1234);
658 false;
660 /* No automatic type conversion */
661 is (string1a = 'FOO);
662 false;
664 is (string1a = sin('x));
665 false;
668 /* No automatic type conversion */
669 is (larray1a = string1a);
670 false;
672 is (larray1a = 1234);
673 false;
675 is (larray1a = 'FOO);
676 false;
678 is (larray1a = sin('x));
679 false;
682 /* Comparison of arrays with multiple dimensions and non-literal elements */
684 (a1 : make_array (any, 10),
685  a2a : make_array (any, 2, 5),
686  a2b : make_array (any, 2, 5),
687  a3 : make_array (any, 3, 5),
688  0);
691 [is (equal (a1, a2a)), is (equal (a1, a3)), is (equal (a2a, a3))];
692 [false, false, false];
694 (a2a [1, 4] : 1234, a2b [1, 4] : '(x/(1 - x)), is (equal (a2a, a2b)));
695 unknown;
697 (a2a [1, 4] : '(1/(1/x - 1)), a2b [1, 4] : '(x/(1 - x)), is (equal (a2a, a2b)));
698 true;
700 is(notequal(exp(x),0));
701 true$
703 is(notequal(exp(%i * x),0));
704 true$
706 is(notequal(exp(x - sqrt(3) * x^2 + 42*%i),0));
707 true$
709 is(notequal(%i * exp(x),0));
710 true$
712 is(notequal(exp(minf),0));
713 false$
715 is(equal(sqrt(1-x^2), conjugate(sqrt(1-x^2))));
716 unknown$
718 (assume(-1 < x, x < 1),0);
721 is(equal(sqrt(1-x^2), conjugate(sqrt(1-x^2))));
722 true$
724 /* SF bug 2869181 */
726 is(equal(exp(%i * x),0));
727 false$
729 is(equal(0, exp(%i * x)));
730 false$
732 (forget(-1 < x, x < 1),0);
735 /* verify literal equality of CREs, especially as subexpressions */
737 (kill (a, x, y, foo),
738  block ([x : rat(a), y : rat(a)],
739   [is (x = y), is ([x] = [y]), is (matrix ([x]) = matrix ([y])), is (foo (x) = foo (y))]));
740 [true, true, true, true];
742 /* from mailing list 2014-08-16 "bind stack overflow in loop"
743  * is(equal(n, m)) needlessly poops n and m into assume database
744  * can't examine assume database directly so here just verify there's no stack overflow
745  */
746 for i thru 10000 do is (equal (i, 10000));
747 done;
749 /* SF bug # 2768: "notequal" tries to put multiprecision rational numbers into floats */
751 /* substitute X for x in original expression to work around
752  * leftover database stuff about x (that's a bug btw)
753  */
754 (foo : 84644440725961403098463183554485799389772425728699536724546678651368471662755793858191462623325951275455550962101277270763335324980423888503086416881487600951168887632284102290001262851926718316596582705934285641705714110547524777517804311041930987129930496818273454551255885915706318740821679919000000000000000000000*X/422165920314471048721358275854632323285179941428330150821135511815100042994592631347355397175387243022779234708963662480477375868719044084318634583443223137428890926160543699705457864438134730545535596936604372279922247951010042249163649352110753480952771747316504857000652757440826179465253453626540111934123296968384641+2097152/10460353203, 0);
757 is (notequal (foo, 0));
758 unknown;
760 is (equal (foo, 0));
761 unknown;
763 is (foo > 0);
764 unknown;