1 (ratprint : false, kill (all));
61 args(ceiling(rat(x)));
64 args(ceiling(rat(a+b)));
70 ceiling(5 + ceiling(x));
73 ceiling(ceiling(x) + ceiling(y));
74 ceiling(x) + ceiling(y)$
76 ceiling(ceiling(x) - ceiling(y));
77 ceiling(x) - ceiling(y)$
79 ceiling(ceiling(x) * ceiling(y));
80 ceiling(x) * ceiling(y)$
82 ceiling(6 * ceiling(x) - 28 * ceiling(y));
83 6 * ceiling(x) - 28 * ceiling(y)$
88 (declare(n,integer),0);
118 (declare(m,integer),0);
136 ceiling(6*n - 28 * m);
145 (forget(m < 0, n >0), 0);
169 ceiling(x + 10!) + floor(-x - 10!);
172 ceiling(a/b + 1909) + floor(-a/b - 1909);
190 (kill(x,numerval),0);
193 (kill(xx), assume(0 < xx, xx < 1),0);
208 (kill(xx), assume(0 <= xx, xx < 1),0);
217 (kill(xx), assume(0 < xx, xx <= 1),0);
226 (assume(-1 < yy, yy < 0),0);
235 (kill(yy), assume(-1 <= yy, yy < 0),0);
244 (kill(yy), assume(-1 < yy, yy <= 0),0);
256 ceiling(asin(-107) -42);
257 ceiling(asin(-107)) - 42$
259 /* SF bug #1653672 */
261 trigsimp(floor(asin(cos(sqrt(2))^2 + sin(sqrt(2))^2 - 1/7)));
264 trigsimp(ceiling(asin(cos(sqrt(2))^2 + sin(sqrt(2))^2 - 1/7)));
267 /* SF bug #1644378 */
269 (x : ?bigfloatone,0);
272 (ceiling(log(2)), is(x = ?bigfloatone));
281 ceiling(5 * signum(x));
282 ceiling(5 * signum(x))$
284 ceiling(charfun(x < 5) + 7);
287 ceiling(max(34, abs(n)!, n * m, n + m, n^8));
288 max(34, abs(n)!, n * m, n + m, n^8)$
290 (declare(ne,even, no, odd),0);
296 ceiling(ne * no / 2);
314 (remove(ne,even, no,odd),0);
317 (remove(n,integer),remove(m,integer),0);
344 charfun(integerp(3));
347 charfun(integerp(sqrt(5)));
350 (p : charfun(x < 1), subst(x=5,p));
353 (p : charfun(x < 1), subst(x=-10,p));
359 (p : charfun(not(equal(x,1))),0);
369 charfun(not(equal(z,1)))$
371 (p : charfun(-1 < x and x < 1),0);
389 block ([prederror : true], charfun (x < 1));
394 is(compare(1,2) = "<");
397 is(compare(2,1) = ">");
400 is(compare(2,2) = "=");
403 is(compare(x,abs(x)) = "<=");
406 is(compare(abs(x),x) = ">=");
409 is(compare(1/x,0) = "#");
424 is(compare(%i,%i) = "=");
427 is(compare(a < b, a < b) = "=");
430 is(compare(rat(x),x) = "=");
433 compare([1,2],[5,6]);
439 /* With revision 1.15 of maxmin.lisp this result has changed to notcomparable */
440 is(compare(infinity,infinity) = "=");
443 is(compare(inf,inf) = "=");
446 compare(infinity,inf);
449 is(compare(inf,-minf) = "=");
452 is(compare(inf,inf+7) = "=");
455 is(compare(inf,minf) = ">");
458 is(compare(inf,-inf) = ">");
461 is(compare(minf,-minf) = "<");
464 is(compare(log(x), log(x) + 1) = "<");
467 is(compare(log(x), log(x)) = "=");
470 is(compare(acosh(x^2+1), acosh(x^2+1) + 1) = "<");
506 featurep(5.6b0, even);
509 featurep(5.7b0, odd);
524 featurep(false, even);
530 featurep(false, odd);
533 featurep([false], odd);
539 featurep(rat(a<b),even);
542 featurep(5 = 7, odd);
545 featurep([2,4,6],even);
548 (declare(ni, integer, me, even, no, odd, ne, even, mo,odd),0);
557 featurep(2*ni, even);
560 featurep(2*ni+1,odd);
569 featurep(abs(me),even);
572 featurep(abs(mo),odd);
575 featurep(ni * me, even);
578 featurep(ni * no, odd);
581 featurep(me + ne, even);
584 featurep(me - ne, even)$
587 featurep(7*me - 9*ne, even)$
590 featurep(no * mo, odd);
593 featurep(no + mo, odd);
596 featurep(me^7, even);
602 featurep(me^(-9), even);
608 featurep(no^(-7), odd);
611 featurep(no^ni, even);
614 featurep(ne^%i, even);
617 featurep(rat(x+x*y,x), even);
620 featurep(rat(ne),even);
623 featurep(rat(ne^2 + 5 * ne),even);
626 featurep(rat(no), odd);
629 /* ... open it close it, break it fix it, ... declare it, remove it */
631 (remove(ni, integer, me, even, no, odd, ne, even, mo,odd),0);
707 floor(floor(x) + floor(y));
710 floor(floor(x) - floor(y));
713 floor(floor(x) * floor(y));
716 floor(6 * floor(x) + 28 * floor(y));
717 6 * floor(x) + 28 * floor(y)$
722 (declare(n,integer),0);
731 (declare(np,integer),0);
758 (declare(m,integer),0);
824 floor(1007^3 + 9/17);
839 floor(max(n,6) + 1/3);
848 floor(5 * n - 7 * m);
851 floor(5 * n - 7 * m + 1/8);
857 floor(2 * n + 5 + 3/%pi);
860 is(floor(sqrt(117)) <= sqrt(117));
863 floor(107! / 2) + ceiling(107! / 2) - 107!;
866 floor(-107! / 2) + ceiling(-107! / 2) + 107!;
869 sum(floor(k * 17 / 5),k,1,4);
872 sum(floor(k * 17 / 507),k,1,506);
875 ceiling(x) + floor(-x);
878 sum(floor((41 + k)/27),k,0,26);
881 sum(floor((-41 + k)/27),k,0,26);
884 sum(floor(%pi + k/56),k,0,55) - floor(56 * %pi);
887 sum(floor(-sqrt(1932) + k/56),k,0,55) - floor(-56 * sqrt(1932));
891 floor(sqrt(978) + sqrt(979)) - floor(sqrt(4* 978 + 2));
897 floor(acos(67) + 42);
898 floor(acos(67)) + 42$
900 /* See "Concrete Mathematics", 3.27, page 87. */
902 sum(floor(sqrt(k)),k,1,25^2-1);
903 25^2 * 25 - 25^3 / 3 - 25^2/2 - 25/6$
905 expand(floor(sqrt(5) * (sqrt(5) - 1/sqrt(5))));
908 floor(10! * sqrt(5) *(sqrt(5) - 1/sqrt(5)) + 1/(10^6 *%pi));
911 floor(10! * sqrt(5) *(sqrt(5) - 1/sqrt(5)) + 1/(10^9 *%pi));
914 floor(sqrt(5) *(sqrt(5) - 1/sqrt(5)) + 1/(10^15 *%pi));
917 floor(sqrt(5) *(sqrt(5) - 1/sqrt(5)) + 1/(10^159 *%pi) + 1/2);
920 (declare(ne,even, no, odd),0);
941 (remove(ne,even, no,odd),forget(np >= 0), 0);
944 (forget(m < 0, n >0), remove(n,integer),remove(m,integer), remove(np,integer), 0);
948 featurep(-1,integer);
957 featurep(%pi,integer);
963 featurep(-x,integer);
966 featurep(signum(x),integer);
969 featurep(charfun(a < b),integer);
972 featurep(floor(2001 + x/z),integer);
975 featurep(ceiling(a*b+c),integer);
978 (declare(ne,even,no,odd, ni, integer),0);
981 featurep(ni,integer);
984 featurep(ni + 8, integer);
987 featurep(ni + ne, integer);
990 featurep(abs(ni + 371)!,integer);
993 featurep(23 * ne,integer);
996 featurep(-23 * ne + 15,integer);
999 featurep(ni^89,integer);
1002 featurep(ni^-89,integer);
1005 featurep(ni / ne,integer);
1008 featurep(abs(ni),integer);
1011 featurep(ni^(no^2), integer);
1014 featurep(abs(ni), integer);
1017 featurep(abs(ne/2),integer);
1020 (remove(ne,even,no,odd,ni,integer),0);
1063 lmax(makelist(1/i,i,1,1000));
1066 lmin(makelist(1/i,i,1,1000));
1069 (maxmin_effort : 3,0);
1072 /*---boundary cases---*/
1079 /*----singleton cases---*/
1093 (assume(-1 < x, x < 1),0);
1108 (forget(-1 < x, x < 1),0);
1156 /*--- extended reals ---*/
1206 min(a,min(b,min(c,d)));
1209 max(a,max(b,max(c,d)));
1212 max(max(a,b),max(c,d));
1215 min(min(a,b),min(c,d));
1218 /*--non-comparable cases--*/
1220 (xx : max(und,false,true,%i,ind,3,4,5), cons(op(xx), args(xx)));
1221 [max, 5, %i, ind, und, true, false]$
1223 (xx : min(und,false,true,%i,ind,3,4,5), cons(op(xx), args(xx)));
1224 [min, 3, %i, ind, und, true, false]$
1226 (xx : max(a < b, a,a,b), cons(op(xx), args(xx)));
1229 (xx : min(a # b, a,a,b,a), cons(op(xx), args(xx)));
1234 (remvalue(xx),max(a,b,a));
1240 max(a,b) - max(b,b,a);
1243 min(a,b) - min(a,a,a,b);
1255 max(u,n,k,u+1,n+2,k+3);
1258 min(u,n,k,u+1,n+2,k+3);
1264 /*--CRE expressions----*/
1266 ratdisrep(max(x,rat(x)));
1269 ratdisrep(min(x,rat(x)))$
1272 ratdisrep(max(rat(x*y)));
1275 ratdisrep(max(rat(x^2+y,x), rat(x^2+y,y)));
1278 /*--absolute values---*/
1286 max(abs(x),5*abs(x), 7*abs(x));
1289 min(abs(x),5*abs(x), 7*abs(x));
1292 max(acos(x), acos(x) + 1);
1295 min(log(x), log(x) + %pi);
1301 (median(a,b,c) := min(max(a,b),max(b,c),max(a,c)),0);
1316 median(abs(x),0,-abs(x));
1322 median(exp(x+1), exp(x+2), exp(x));
1325 /*-- try a higher value of maxmin_effort ----*/
1327 (maxmin_effort : 3,0);
1345 max(-cos(x^2), cos(x), cos(x^2));
1346 max(cos(x), abs(cos(x^2)))$
1348 min(-cos(x^2), cos(x), cos(x^2));
1349 min(cos(x), -abs(cos(x^2)))$
1351 /*--try a higher maxmin_effort-----*/
1353 (maxmin_effort : 10,0);
1401 [mod(5.0, 3.0), mod(5.0, -3.0), mod(-5.0, 3.0), mod(-5.0, -3.0)];
1402 [2.0, -1.0, 1.0, -2.0];
1404 [mod(5.0b0, 3.0b0), mod(5.0b0, -3.0b0), mod(-5.0b0, 3.0b0), mod(-5.0b0, -3.0b0)];
1405 [2.0b0, -1.0b0, 1.0b0, -2.0b0];
1407 /* I'd rather do this up to 10^6 at least but it takes too long. Oh well. */
1408 every (lambda ([k], mod(float(k*k), float(k)) = 0.0), makelist (k, k, 1, 10000));
1411 every (lambda ([k], mod(bfloat(k*k), bfloat(k)) = 0.0b0), makelist (k, k, 1, 10000));
1429 floor(sqrt(5)) + mod(sqrt(5),1);
1432 floor(-sqrt(5)) + mod(-sqrt(5),1);
1438 /* Some tests for rat(float) */
1443 makelist(ratdisrep(rat(0.333333)),ratepsilon,[1e-1,1e-2,1e-3,1e-4,1e-5, 1e-7, 1e-15, 1e-100, 1e-300]);
1444 [1/3,1/3,1/3,1/3,1/3,333332/999997,333333/1000000,333333/1000000,333333/1000000]$
1446 makelist(ratdisrep(rat(float(%e))),ratepsilon,[1e-1,1e-2,1e-3,1e-4,1e-5, 1e-7, 1e-15, 1e-100, 1e-300]);
1447 [8/3,19/7,87/32,193/71,1264/465,2721/1001,28245729/10391023,325368125/119696244,325368125/119696244]$
1452 ratdisrep(map('rat,[0.1415914,0.0,-0.9999,0.99999,-1.0001,1.00001,0.501099]));
1453 [16/113,0,-1,1,-1,1,227/453]$
1455 /* Denormalized numbers -- SF bug 3777 */
1457 setify(makelist(float(rat(1.2345e-320))-1.2345e-320,ratepsilon,[1e-1,1e-2,1e-3,1e-4,1e-5, 1e-7, 2e-15, 1e-100, 1e-300]));
1460 /* Wait for 3778 to be fixed */
1461 /* setify(makelist(float(rat(-1.5432e-320))-1.5432e-320,ratepsilon,[1e-1,1e-2,1e-3,1e-4,1e-5, 1e-7, 2e-15, 1e-100, 1e-300])); */
1464 (ratepsilon:2e-15,0);
1485 rationalize(0.25b0);
1488 rationalize(2.5b-1);
1491 rationalize(0.35b0 - 3.5b-1);
1500 rationalize(100.125b0);
1503 rationalize(-100.125b0);
1518 rationalize(infinity);
1533 rationalize(log(0.25 * x - 0.5));
1536 rationalize([u,n,k]);
1542 rationalize(a^^0.125);
1545 block([ratprint : false], rationalize(rat(a+b + 0.125)));
1546 (8 * a + 8 * b + 1)/8$
1548 block([ratprint : false], rationalize(rat(1+x+x^2.0)));
1551 rationalize(matrix([a,0.25],[-a,2.0^z]));
1552 matrix([a,1/4],[-a,2^z]);
1554 rationalize([[0.75],[m,j,w],[-2.0],[a.m.h]]);
1555 [[3/4],[m,j,w],[-2],[a.m.h]]$
1557 rationalize(f(-0.1875) + %pi * 3.0);
1560 rationalize(f(-0.1875b0) + %pi * 3.0);
1563 rationalize(a = 2.5);
1566 rationalize(abs(x - 0.1875));
1572 rationalize(0.09375 < 0.3984375);
1575 rationalize(0.09375b0 < 0.3984375b0);
1578 (reset (fpprec), 0);
1581 /* SF bug 1703298 max leads to UND error */
1586 max(1/(q-1),1/(q-1));
1589 sort(args(max(1/(q-1),1/(q-2))));
1590 ''(sort([1/(q-1),1/(q-2)]))$
1592 is(compare(1/(q-1),minf) = ">");
1595 is(compare(minf, 1/(q-1)) = "<");
1598 /* SF bug 1703376 max(inf, ...) doesn't simplify to inf */
1606 /* SF bug 1764114 signum misses simp rule */
1608 (tellsimpafter (signum(x), zzz), signum(-x));
1611 floor(log(8) / log(2));
1614 ceiling(log(8) / log(2));
1617 floor(log(125) / log(5) + 42 / 5);
1620 ceiling(log(125) / log(5) + 42 / 5);
1623 /* SF bug [ 1220227 ] MIN is not correct (problem with "is" function) */
1625 (f(h,k,l):=(h^k)*((1/h)*k*(1+l)+(d-k)*2*l),
1626 g(h,k,l):=2*d*l+(h^k)*((1/h)*k*(1-l)-(d-k)*2*l),
1629 aa: f((1-v)^(1/2),2,l),
1636 block([ratprint : false],min (aa, bb, cc, dd));
1637 min(3.0*sqrt(1-v),1.0*sqrt(v)+2.0,(1.5/(1-v)+1.0)*(1-v))$
1639 block([ratprint : false], ratsimp (bb - dd));
1642 block ([prederror : false], is (cc > aa));
1645 block ([prederror : false], is (cc > bb));
1648 block ([prederror : false], is (cc > dd));
1651 /* SF bug [ 1995595 ] sign(max(7,x) - max(6,x)) --> error */
1653 sign (max (7, foo543) - max (6, foo543));
1656 /* SF bug [ 2144225 ] rationalize bug / fix (?) */
1657 map('rationalize, [cos(s)]);
1660 map(lambda([s], rationalize(s)), [cos(s)]);
1663 integrate(floor(x),x);
1664 (-floor(x)+2*x-1)*floor(x)/2$
1666 integrate(floor(x),x,0,3);
1669 integrate(ceiling(x),x);
1670 (-ceiling(x)+2*x+1)*ceiling(x)/2$
1672 integrate(ceiling(x),x,0,4);
1675 (remvalue(d, l, aa, bb, cc, dd),0);
1678 /* Bug report ID: 2123651 - min and max of imaginary and real numbers
1679 * These are the examples from the bug report.
1682 (xx : min(%i*inf,inf), cons(op(xx), args(xx)));
1685 (xx : min(%i*minf,minf), cons(op(xx), args(xx)));
1686 [min, minf,%i*minf];
1688 (xx : min(%i*inf,inf), cons(op(xx), args(xx)));
1691 (xx : min(%i*minf,minf), cons(op(xx), args(xx)));
1694 (xx : min(%i*-inf,-inf), cons(op(xx), args(xx)));
1695 [min, - %i*inf, minf]$
1697 (xx : min(%i*-inf,minf), cons(op(xx), args(xx)));
1698 [min, - %i*inf, minf]$
1700 (xx : min(%i*minf,-inf), cons(op(xx), args(xx)));
1701 [min, minf,%i*minf];
1703 (xx : max(%i*minf,inf), cons(op(xx), args(xx)));
1706 (xx : max(%i*minf,minf), cons(op(xx), args(xx)));
1707 [max, minf,%i*minf];
1709 (xx : max(%i*inf,inf), cons(op(xx), args(xx)));
1712 (xx : max(%i*-inf,-inf), cons(op(xx), args(xx)));
1715 (xx : max(%i*minf,minf), cons(op(xx), args(xx)));
1718 (xx : max(7*%i*inf+4*inf,4*%i*inf+3), cons(op(xx), args(xx)));
1719 [max, 4*%i*inf+3,7*%i*inf+4*inf];
1721 (xx : min(7*%i*inf+4*inf,4*%i*inf+3), cons(op(xx), args(xx)));
1722 [min,4*%i*inf+3,7*%i*inf+4*inf]$
1724 (xx : min(7*%i*minf+4*inf,4*%i*minf+3), cons(op(xx), args(xx)));
1725 [min,4*%i*minf+3,7*%i*minf+4*inf]$
1727 (xx : min(7*%i*minf+4*inf,4*%i*-inf+3), cons(op(xx), args(xx)));
1728 [min,4*%i*-inf+3,7*%i*minf+4*inf];
1730 (remvalue(xx), min(-inf,minf));
1736 /* mailing list 2016-03-11: "bfloat divide bad; WAS: nonzero remainder of mod(x*x, x) where x is a small integer float or bigfloat" */
1738 sublist (makelist (i, i, 1, 1000), lambda ([i], float(i*i)/float(i) - float(i) # 0.0));
1741 sublist (makelist (i, i, 1, 1000), lambda ([i], float(i)/float(i) # 1.0));
1744 sublist (makelist (i, i, 1, 1000), lambda ([i], bfloat(i*i)/bfloat(i) - bfloat(i) # 0b0));
1747 sublist (makelist (i, i, 1, 1000), lambda ([i], bfloat(i)/bfloat(i) # 1b0));
1750 sublist (makelist (i, i, 1, 1000), lambda ([i], mod (float(i*i), float(i)) # 0.0));
1753 sublist (makelist (i, i, 1, 1000), lambda ([i], mod (float(i), float(i)) # 0.0));
1756 sublist (makelist (i, i, 1, 1000), lambda ([i], mod (bfloat(i*i), bfloat(i)) # 0b0));
1759 sublist (makelist (i, i, 1, 1000), lambda ([i], mod (bfloat(i), bfloat(i)) # 0b0));
1762 /* See #3736 Quoting either min or max inhibits simplification */
1775 (reset(ratprint),0);