home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ARM Club 3
/
TheARMClub_PDCD3.iso
/
hensa
/
maths
/
b116_1
/
jacal
/
test_math
< prev
next >
Wrap
Text File
|
1993-10-19
|
6KB
|
245 lines
/*From: mjt@juliet.anu.edu.au (Michael Thomas)
*/
set echogrammar standard;
verify(5^2, 25);
a:[[1,2,3],[5,2,7]];
b:[[3,2],[6,4]];
verify(b.a, [[13,10,23], [26,20,46]]);
c:[[1,3,5],[2,4,7]];
d:[2,4];
verify(c + d, [[3,5,7], [6,8,11]]);
verify(3+2, 5);
verify(e+d, [2 + e , 4 + e]);
verify(-[1,2,3], [-1 , -2 , -3]);
verify(3-7, -4);
verify(+/-3, 3 * %sqrt1);
verify((3 * %sqrt1)^2, 9);
verify(+/-(3 * %sqrt1), 3);
verify((x^2-y^2)/(x-y), x + y);
verify(1=2, 0 = -1);
verify((1+x)^4, 1 + 4* x + 6* x^2 + 4* x^3 + x^4);
a:[[1,0],[-1,1]];
verify(a^^3,[ [1,0], [-3,1]]);
verify(bunch(1,2,3),[1 , 2 , 3]);
verify(coeff((x+2)^4,x,0), 16);
verify(coeff((x+2)^4,x,1), 32);
verify(coeff((x+2)^4,x,2), 24);
verify(coeff((x+2)^4,x,3), 8);
verify(coeff((x+2)^4,x,4), 1);
verify(coeffs((x+2)^4,x), [16 , 32 , 24 , 8 , 1]);
verify(col([[1,2,4],[2,5,6]],2), [[2],[5]]);
verify(content(2*x*y+4*x^2*y^2,y), [2* x , y + 2 *x* y^2 ]);
verify(crossproduct([1,2,3],[4,2,5]),[4 , 7 , -6]);
verify(denom(4/5), 5);
a:[[1,2],[6,7]];
verify(determinant(a), -5);
verify(diagmatrix(12,3,a,s^2),
[[12, 0, 0, 0 ],
[0, 3, 0, 0 ],
[0, 0, a, 0 ],
[0, 0, 0, s^2]]);
verify(diagmatrix([1,2],2), [[[1 , 2], 0], [ 0, 2]]);
verify(divide(x^2+y^2,x-7*y^2,x), [x + 7* y^2 , y^2 + 49* y^4 ]);
verify(divide(-7,3), [-2 , -1]);
verify(divide(x^2+y^2+z^2,x+y+z), [- x - y + z , 2* x^2 + 2* x* y + 2* y^2 ]);
verify(divide(x^2+y^2+z^2,x+y+z,y), [- x + y - z , 2* x^2 + 2* x* z + 2*z^2 ]);
verify(divide(x^2+y^2+z^2,x+y+z,z), [- x - y + z , 2* x^2 + 2* x* y + 2* y^2 ]);
a:[1,2,3];
b:[3,1,5];
verify(dotproduct(a,b), 20);
verify(eliminate([x^2+y=0,x^3+y=0],[x]), 0 = y + y^2);
verify(eliminate([x+y+z=3,x^2+y^2+z^2=3,x^3+y^3+z^3=3],[x,y]), 0 = 1 - z);
verify(factor(120), [2 , 2 , 2 , 3 , 5]);
verify(factor(-120),[-1 , 2 , 2 , 2 , 3 , 5]);
w(t):=t+1;
verify(finv(w), lambda([@1], -1 + @1));
verify(gcd(x^4-y^4,x^6+y^6),x^2 + y^2);
verify(gcd(4,10), 2);
e4: lambda([@1 , @2], @1 + @2 );
verify(genmatrix(e4,3,5),
[[2, 3, 4, 5, 6],
[3, 4, 5, 6, 7],
[4, 5, 6, 7, 8]]);
verify(ident(4),
[[1, 0, 0, 0],
[0, 1, 0, 0],
[0, 0, 1, 0],
[0, 0, 0, 1]]);
e12 : lambda([x],x^2);
e13 : lambda([x,y,z],x*y*z);
verify(e12+e13, lambda([@1, @2, @3], @1^2 + @1* @2* @3));
verify(listofvars(x^2+y^3),[x , y]);
verify(listofvars((x^2+y^3)/(2*x^7+y*x+z)), [z , x , y]);
b:[[1,2,3],[3,1,5],[5,2,7]];
verify(minor(b,3,1),
[[2, 3],
[1, 5]]);
verify(mod(5,2), -1);
verify(mod(x^4+4,x^2=2), 8);
verify(num((x^2+y^2)/(x^2-y^2)), -(x^2 + y^2));
verify(num(7/4),7);
verify(num(7/(4/3)),21);
verify(or(x=2,y=3), 0 = -6 + 3 *x + (2 - x)* y);
/* verify(or(2,3), {x | 0 = 6 - 5 *x + x^2 }); */
verify(or(x=2,17), 17);
verify(discriminant(x^3-1,x), -27);
verify(rapply([[1,2,3],[1,4,6],3],2,3),6);
verify(rapply([a,b],2),b);
verify(rapply([a,b]), [a,b]);
verify(resultant(x^2+n,x^3+n,x), n^2 + n^3);
u:[[1,2,3],[1,5,3]];
verify(row(u,2), [1, 5, 3]);
verify(scalarmatrix(3,6),
[[6, 0, 0],
[0, 6, 0],
[0, 0, 6]]);
verify(sylvester(a0+a1*x+a2*x^2+a3*x^3,b0+b1*x+b2*x^2,x),
[[a3, a2, a1, a0, 0 ],
[0, a3, a2, a1, a0],
[b2, b1, b0, 0 , 0 ],
[0, b2, b1, b0, 0 ],
[0, 0, b2, b1, b0]]);
verify(differential(x^2+y^3), 2* x* x' + 3* y^2 * y');
verify((x^2+y^3)', 2*x*x' + 3*y^2*y');
verify((x^2+x*y^3)', 2*x*x' + 3*x*y^2*y'+ y^3*x');
q:[[1,1,1,1,1],[1,2,3,4,5]];
verify(transpose(q),
[[1, 1],
[1, 2],
[1, 3],
[1, 4],
[1, 5]]);
A:[1,0];
B:[1,3];
C:[1,2];
D:[0,0];
E:[1,3,0];
M : [
[1,2,3,0],
[3,7,4,2],
[4,4,5,6]
];
verify(rank([A]), 1);
verify(rank([E]), 1);
verify(rank(M), 3);
verify(rank([A,B,C]), 2);
verify(rank([A,B]), 2);
verify(rank([A,C]), 2);
verify(rank([B,C]), 2);
D: [[- k12 - k13, k21, k31],
[k12, - k23 - k21, k32],
[k13, k23, - k31 - k32]];
verify(determinant(D), 0);
/* Complex numbers */
verify((-1)^(1/2), %i);
verify((-1)^(2/2), -1);
verify((-1)^(3/2), -%i);
verify((-1)^(5/2), %i);
/* The old eliminate problem */
YN1: 2 * A1 + 2 * L1 * M1;
YN2: 4 * B1 - 2 * L1 * M1;
YN3: A1 + 2* B1;
verify(eliminate([YN1=0,YN2=0],[M1]), YN3=0);
YN1: 2 * A1 + 2 * L1 * M1 ^ 2;
YN2: 4 * B1 - 2 * L1 * M1 ^ 2;
YN3: A1 + 2* B1;
verify(eliminate([YN1=0,YN2=0],[M1]), YN3=0);
YN1: 2 * A1 + 2 * L1 * M1 ^ 3;
YN2: 4 * B1 - 2 * L1 * M1 ^ 3;
YN3: A1 + 2* B1;
verify(eliminate([YN1=0,YN2=0],[M1]), YN3=0);
YN1: 2 * A1 + 2 * L1 * M1 ^ 2;
YN2: 4 * B1 - 2 * L1 * M1;
YN3: A1 * L1 + 4* B1^2;
verify(eliminate([YN1=0,YN2=0],[M1]), YN3=0);
YN1: 2 * A1 + 2 * L1 * M1 ^ 3;
YN2: 4 * B1 - 2 * L1 * M1;
YN3: A1 * L1^2 + 8 * B1^3;
verify(eliminate([YN1=0,YN2=0],[M1]), YN3=0);
YN1: 2 * A1 + 2 * L1 * M1 ^ 2;
YN2: 4 * B1 - 2 * L1 * M1 ^ 3;
YN3: A1^3 * L1 + 4 * B1^2 * L1^2;
verify(eliminate([YN1=0,YN2=0],[M1]), YN3=0);
/* Manipulate the Gibbs equation */
verify({dU | T * dS = dU + P * dV - mu1 * dc1 - mu2 * dc2},
T*dS-P*dV+mu1*dc1+mu2*dc2);
verify({T | T * dS = dU + P * dV - mu1 * dc1 - mu2 * dc2},
(dU+P*dV-mu1*dc1-mu2*dc2)/dS);
verify({mu1 | T * dS = dU + P * dV - mu1 * dc1 - mu2 * dc2},
(dU+P*dV-T*dS-mu2*dc2)/dc1);
/* And again using the ' operator */
verify({U' | T * S' = U' + P * V' - mu1 * c1' - mu2 * c2'},
T*S'-P*V'+mu1*c1'+mu2*c2');
verify({T | T * S' = U' + P * V' - mu1 * c1' - mu2 * c2'},
(U'+P*V'-mu1*c1'-mu2*c2')/S');
verify({mu1 | T * S' = U' + P * V' - mu1 * c1' - mu2 * c2'},
(U'+P*V'-T*S'-mu2*c2')/c1');
/* Use a lambda expression for the power method of approximating a
dominant eigenvalue */
A: [[3,2], [-1,0]];
X: [[1], [1]];
set echogrammar null; /* because the next one crashes */
/*
power(a99, n99, x99): a99^^n99 . x99;
verify(power(A,3,X), [[29],[-13]]);
set echogrammar null;
*/