1 /*************** -*- Mode: MACSYMA; Package: MAXIMA -*- ******************/
2 /***************************************************************************
4 *** Copyright (c) 1984 by William Schelter,University of Texas *****
5 *** All rights reserved *****
6 ***************************************************************************/
8 (reset(), kill(all),0);
11 integrate(x^(5/4)/(x+1)^(5/2),x,0,inf);
13 gradef(q(x),sin(x^2));
16 'diff(r(x),x,1)*sin(r(x)^2)/q(r(x));
20 ?nformat(?complex(1,2));
22 ?nformat(?/(1,2)); /* ?/(1,2) equivalent to (/ 1 2) in Lisp */
25 /* example for now-disable interval struct in src/nforma.lisp
26 ?typep(interval(1,2),?ri);
29 is(part(?complex(1,2),0)="+");
32 /* bug reported to mailing list 2013-05-22 */
35 a : make_array (fixnum, 3),
36 L : buildq ([a], lambda ([x], a[x])),
37 print (L, L(0))); /* print(L) --> calls NFORMAT and therefore tickles bug */
40 /* expressions like f(x)(y) */
42 (kill (f, x, y), f(x)(y));
45 (f(x)(y), [op (%%), args (%%)]);
48 (f(x)(y), [op (op (%%)), args (op (%%))]);
54 (kill (z), f(x)(y)(z));
57 (f(x)(y)(z), [op (%%), args (%%), op (op (%%)), args (op (%%)), op (op (op (%%))), args (op (op (%%)))]);
58 [f(x)(y), [z], f(x), [y], f, [x]];
60 ev (f(x)(y), f(u) := buildq ([u], lambda ([v], v*u)));
66 map (f(x), [1, 2, 3]);
67 [f(x)(1), f(x)(2), f(x)(3)];
69 (f(u) := subst (u, 'u, lambda ([v], v^u)),
71 [lambda ([v], v^x), y^x];
74 matchdeclare (xx, integerp),
75 tellsimp (f(xx), subst ('xx = xx, lambda ([a], a - xx))),
77 [lambda ([a], a - 1), y - 1];
79 (remrule (f, all), 0);
82 (matchdeclare ([xx, yy], integerp),
83 tellsimp (f(xx)(yy), yy*xx),
90 /* verify that subscripted functions are formatted without superfluous parentheses
91 * see SF bug #2998: "extra () in display2d:false output"
98 [string (li[2](x)), string (psi[3](y))];
99 ["li[2](x)", "psi[3](y)"];
101 /* further tests for #2998 combining subscripted functions with various user-defined operators */
103 block ([opsies : ["infixie", "prefixie", "postfixie", "naryie", "matchfixie", "nofixie"]],
104 apply (kill, opsies),
105 map (lambda ([f, a], apply (f, [a])), [infix, prefix, postfix, nary, lambda ([a], matchfix (a, a)), nofix], opsies),
106 kill (foo, bar, baz, a, b, c, x, y, z),
110 foo[x, y](a) infixie bar[z](b, c);
111 (foo[x, y](a)) infixie (bar[z](b, c));
113 string ((foo[x, y](a)) infixie (bar[z](b, c)));
114 "foo[x,y](a) infixie bar[z](b,c)";
116 bar[a, a](x, x) naryie baz[a](x, y) naryie prefixie foo[a, b](x, y);
117 (bar[a, a](x, x)) naryie (baz[a](x, y)) naryie (prefixie (foo[a, b](x, y)));
119 string ((bar[a, a](x, x)) naryie (baz[a](x, y)) naryie (prefixie (foo[a, b](x, y))));
120 "bar[a,a](x,x) naryie baz[a](x,y) naryie prefixie foo[a,b](x,y)";
122 matchfixie foo[1](z) matchfixie;
123 matchfixie (foo[1](z)) matchfixie;
125 string (matchfixie (foo[1](z)) matchfixie);
126 "matchfixiefoo[1](z)matchfixie";
128 /* ... and with built-in operators */
130 foo[x, y](a)^bar[z](b, c);
131 (foo[x, y](a))^(bar[z](b, c));
133 string ((foo[x, y](a))^(bar[z](b, c)));
134 "foo[x,y](a)^bar[z](b,c)";
136 bar[a, a](x, x) and baz[a](x, y) and not foo[a, b](x, y);
137 (bar[a, a](x, x)) and (baz[a](x, y)) and (not (foo[a, b](x, y)));
139 string ((bar[a, a](x, x)) and (baz[a](x, y)) and (not (foo[a, b](x, y))));
140 "bar[a,a](x,x) and baz[a](x,y) and not foo[a,b](x,y)";
145 string ([ (foo[1](z)) ]);
148 /* mailing list 2015-10-05: "Wrong result from integrate?" */
150 (kill(t, R), integrate(sqrt(sin(t)^2*R^2+(1-cos(t))^2*R^2),t,0,2*%pi));
153 /* SF bug #2845: "Avoid initialization-time compile in commac.lisp"
154 * Ensure that functions to strip trailing zero digits continue to work.
163 (string(2e7), %% = "2.0e+7" or %% = "2.0E+7" or %%);
166 (string(2e-7), %% = "2.0e-7" or %% = "2.0E-7" or %%);
169 (string(12345000000.0), %% = "1.2345e+10" or %% = "1.2345E+10" or %%);
172 (string(1/1024.0), %% = "9.765625e-4" or %% = "9.765625E-4" or %%);