1 /*************** -*- Mode: MACSYMA; Package: MAXIMA -*- ******************/
2 /***************************************************************************
4 *** Copyright (c) 1984 by William Schelter,University of Texas *****
5 *** All rights reserved *****
6 ***************************************************************************/
9 /* -*- Mode: MACSYMA -*- */
10 /* batch("me:test6a.mac");
11 It asked is a pos answred yes
12 and is i+1 zero or nonzero and I answered nonzero
13 so should add assume (a>0,not(equal(i+1,0))) */
17 (%pi*x^3*erf(x)+(sqrt(%pi)*x^2+sqrt(%pi))*%e^-x^2)/(3*%pi);
18 ev(diff(%,x),ratsimp);
22 'integrate(%e^(sqrt(a)*sqrt(y)),y,0,4);
23 'integrate(%e^(sqrt(a)*sqrt(y)),y,0,4);
24 changevar(%,y-z^2/a,z,y);
25 /* on lispm -2*('integrate(z*%e^abs(z),z,-2*sqrt(a),0))/a; */
26 - 'integrate(2*z*%e^abs(z)/a,z,-2*sqrt(a),0);
33 'integrate(f(x),x,a,b)+x;
34 'integrate(f(x),x,a,b)+x;
47 27*y^3+54*x*y^2+36*x^2*y+y+8*x^3+x+1;
48 27*y^3+54*x*y^2+36*x^2*y+y+8*x^3+x+1;
57 'limit(f(x)^g(x+1),x,0,minus);
58 'limit(f(x)^g(x+1),x,0,minus);
61 'limit(f(x)^g(x+1),x,0,minus);
62 'limit(f(x)^g(x+1),x,0,minus);
63 is(inpart(%,0) = nounify(limit));
68 b^4+4*a*b^3+6*a^2*b^2+4*a^3*b+a^4;
72 b^2*y^2+2*a*b*y^2+a^2*y^2+2*b^2*x*y+4*a*b*x*y+2*a^2*x*y+b^2*x^2+2*a*b*x^2+a^2*x^2;
74 (b^4+4*a*b^3+6*a^2*b^2+4*a^3*b+a^4)/(b^2*y^2+2*a*b*y^2+a^2*y^2+2*b^2*x*y+4*a*b*x*y+2*a^2*x*y+b^2*x^2+2*a*b*x^2+a^2*x^2);
78 (b^4+4*a*b^3+6*a^2*b^2+4*a^3*b+a^4)/(b^2*y^2+2*a*b*y^2+a^2*y^2+?mbox(2*b^2*x*y)+4*a*b*x*y+2*a^2*x*y+b^2*x^2+2*a*b*x^2+a^2*x^2);
94 /* Bug #4307: partswitch affects op and operatorp */
95 block([partswitch:false],errcatch(op('x)));
97 block([partswitch:true],errcatch(op('x)));
99 block([partswitch:false],errcatch(operatorp('x,'end)));
101 block([partswitch:true],errcatch(operatorp('x,'end)));
104 subst(a,x+y,x+(x+y)^2+y);
106 subst(-%i,%i,a+b*%i);
110 subst(x = 0,diff(sin(x),x));
112 errcatch(ev(diff(sin(x),x),x = 0));
114 (assume(not(equal(i,-1))),0);
116 ev(integrate(x^i,x),i = -1);
118 errcatch(subst(-1,i,integrate(x^i,x)));
124 ratsubst(a,x*y^2,x^4*y^8+x^4*y^3);
126 1+cos(x)+cos(x)^2+cos(x)^3+cos(x)^4;
127 cos(x)^4+cos(x)^3+cos(x)^2+cos(x)+1;
128 ratsubst(1-sin(x)^2,cos(x)^2,%);
129 sin(x)^4-3*sin(x)^2+cos(x)*(2-sin(x)^2)+3;
130 ratsubst(1-cos(x)^2,sin(x)^2,sin(x)^4);
131 cos(x)^4-2*cos(x)^2+1;
133 /* SF bug #2907: ratsubst(z, sin(x + 1), 0) crashes when radsubstflag = true */
135 ratsubst (z, sin(x + 1), 0), radsubstflag=true;
138 ratsubst (z, sin(2*x), 0), radsubstflag=true;
141 ratsubst (z, log(x + 1), 0), radsubstflag=true;
144 ratsubst (u, sqrt(x), x), radsubstflag=true;
147 /* additional ratsubst/radsubstflag cases -- dunno how meaningful these are, oh well */
149 ratsubst (z, sin(x + 1), 1 + sin(x + 1)^2), radsubstflag=false;
152 ratsubst (z, sin(x + 1), 1 + sin(x + 1)^2), radsubstflag=true;
155 ratsubst (z, sqrt(x + 1), 1 + (x + 1)^2), radsubstflag=false;
158 ratsubst (z, sqrt(x + 1), 1 + (x + 1)^2), radsubstflag=true;
161 ratsubst (z, sqrt(x + 1), 1 + (x + 1)^(3/2)), radsubstflag=false;
164 ratsubst (z, sqrt(x + 1), 1 + (x + 1)^(3/2)), radsubstflag=true;
167 /* SF bug #3658: "" */
169 ratsubst (1.1, x, 0.001*cos(x));
175 /* SF bug #4176: fullratsubst
176 In these examples, we make sure that both forms of calling
177 fullratsubst work as described in the documentation.
179 fullratsubst(3*z^8 + 13, z^9, 147*z^13 -637);
180 35721*z^8+1911*z^4+5733*z^3+17199*z^2+51597*z+154154;
182 fullratsubst(z^9 = 3*z^8 + 13, 147*z^13 -637);
183 35721*z^8+1911*z^4+5733*z^3+17199*z^2+51597*z+154154;
185 fullratsubst([z^9 = 3*z^8 + 13], 147*z^13 -637);
186 35721*z^8+1911*z^4+5733*z^3+17199*z^2+51597*z+154154;
189 /* The following are examples from the documentation for
190 fullratsubst, ratsubst and fullratsubstflag
192 lratsubst ([a^2 = b, c^2 = d], (a + e)*c*(a + c));
193 (d + a*c)*e + a*d + b*c;
195 lratsubst (a^2 = b, a^3);
198 ratsubst (b*a, a^2, a^3);
201 fullratsubst (b*a, a^2, a^3);
204 fullratsubst ([a^2 = b, b^2 = c, c^2 = a], a^3*b*c);
207 fullratsubst (a^2 = b*a, a^3);
210 /* SF bug #3376: fullratsubst doesn't catch infinite recursions
211 In this example, fullratsubst1 should loop exactly lrats_max_iter=30 times,
212 adding a power of b each time.
214 fullratsubst(b*a^2,a^2,a^3), lrats_max_iter=30;
217 /* SF bug #3706: lratsusbst causes bind stack overflow on large lists */
218 block([l:makelist(concat('x,i)=concat('x,i+1),i,0,5000)], lratsubst(l,x0)) $
221 /* SF bug #3154 lratsubst NOT as described in Help file */
222 lratsubst([[a=b,b=c]],a) $
225 /* first argument to lratsbust should throw an error */
226 errcatch(lratsubst([[a=b,b=c],[b=c]],a)) $
229 lratsubst ([phi_2 = 1.1], 0.001*cos(phi_2)), numer;
232 /* original example from #3658;
233 * note that this assumes load(lrats) already.
234 * result is not checked, just whether or not it runs without error.
236 block ([mat21,theta_1,mat22,phi_2,theta_2,mat23,t,t1,t2,fl,theta1,theta2,phi2,tt],
237 [mat21:matrix([cos(theta_1/2),
238 %i*sin(theta_1/2)],[%i*sin(theta_1/2),
240 mat22:matrix([cos(theta_2/2)
242 %i*sin(theta_2/2)*exp(%i*phi_2/2)],
243 [%i*sin(theta_2/2)*exp(-%i*phi_2/2),cos(theta_2/2)
246 t:expand(mat23[2,2]*mat23[1,1]),
247 t1:expand(demoivre(t)),
248 t2:trigsimp(trigreduce(2*t1-1))],
250 for theta1:0 thru %pi step 1.1 do
251 for theta2:0 thru %pi step 1.1 do
252 for phi2:0 thru 2*%pi step 1.1
253 do (tt:float(ev(lratsubst([theta_1=theta1,theta_2=theta2,phi_2=phi2],
254 abs(t2-(cos(theta_1)*cos(theta_2) - sin(theta_1)*sin(theta_2)*cos(phi_2)))),
256 if tt>1e-5 then(fl:false,disp(tt))),
261 /* SF bug #2012: "Lisp stack overflow with dpart." */
266 /* SF bug #3390: "?great mishandles box" */
268 ?great(box(x+t),-box(x+t));
271 ?great(-box(x+t),box(x+t));
274 /* SF bug #3848: "ratsubst error ZEROP: ((MMINUS) 1) is not a number" */
277 d:-(3^(3/2)*%i+1)^(1/2)/3,
279 -(sqrt(3^(3/2)*%i+1)/3);
281 ratsubst (1, 1, -1/2);