1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197
|
Use("testers.mpi");
DoNext(_string) <--
[
NextTest("<font color=0000ff>" : string : "</font>");
NewLine();
];
Echo({"<HTML><BODY BGCOLOR=\"ffffff\"><PRE><font size=4>"});
Echo({"An assorted selection of the tests found in the Wester benchmark"});
StartTests();
/*
*/
DoNext("Compute 50!");
BenchShow(50!);
DoNext("Compute the prime decomposition of 6!.");
BenchShow(ans:=Factors(6!));
Echo({"This list contains lists of two elements. This list should
be interpreted as "});
BenchShow(PrettyForm(FW(ans)));
DoNext("Compute 1/2 + ... + 1/10.");
BenchShow(Sum(i,2,10,1/i));
DoNext("Compute a numerical approximation of e^(Pi*sqrt(163)) to 50 digits.");
BenchCall(BuiltinPrecisionSet(50));
BenchShow(N(Exp(Pi*Sqrt(163))));
DoNext("Compute an infinite decimal representation of 1/7");
BenchShow(Decimal(1/7));
DoNext("Compute the first terms of the continued fraction of Pi.");
BenchShow(PrettyForm(ContFrac(Internal'Pi())));
DoNext("Simplify sqrt(2*sqrt(3)+4).");
BenchShow(RadSimp(Sqrt(2*Sqrt(3)+4)));
DoNext("Simplify sqrt(14+3*sqrt(3+2*sqrt(5-12*sqrt(3-2*sqrt(2))))).");
BenchShow(RadSimp(Sqrt(14+3*Sqrt(3+2*Sqrt(5-12*Sqrt(3-2*Sqrt(2)))))));
DoNext("Simplify 2*infinity-3.");
BenchShow(2*Infinity-3);
Echo({"Infinity is also defined for comparisons like a < Infinity"});
DoNext("Compute the normal form of (x^2-4)/(x^2+4x+4).");
BenchShow(PrettyForm(GcdReduce((x^2-4)/(x^2+4*x+4),x)));
DoNext("Expand (x+1)^5, then differentiate and factorize.");
BenchCall(ans:=Factors(D(x)Expand((x+1)^5)));
BenchShow(PrettyForm(FW(ans)));
DoNext("Simplify sqrt(997) - (997^3)^(1/6).");
BenchShow(RadSimp(Sqrt(997) - (997^3)^(1/6)));
DoNext("Simplify sqrt(999983) - (999983^3)^(1/6).");
BenchShow(RadSimp(Sqrt(999983) - (999983^3)^(1/6)));
DoNext("Recognize that (2^(1/3)+4^(1/3))^3-6*(2^(1/3)+4^(1/3)) - 6 is 0.");
BenchShow(RadSimp( (2^(1/3)+4^(1/3))^3-6*(2^(1/3)+4^(1/3)) - 6));
DoNext("Simplify log e^z into z only for -Pi < Im(z) <= Pi.");
BenchShow(Simplify(Ln(Exp(z))));
DoNext("Invert the 2x2 matrix [[a,b],[1,ab]]. ");
BenchCall(A:={{a,b},{1,a*b}});
BenchShow(ans:=Inverse(A));
BenchShow(TableForm(Simplify(ans)));
DoNext("Find the eigenvalues of the matrix [[5, -3, -7],[-2, 1, 2],[ 2, -3, -4]].");
BenchCall(A:={{5,-3,-7},{-2,1,2},{2,-3,-4}});
BenchShow(EigenValues(A));
DoNext("Compute the limit of (1-cos x)/x^2 when x goes to zero. ");
BenchShow(Limit(x,0)(1-Cos(x))/(x^2));
DoNext("Compute the derivative of |x|.");
BenchShow(D(x)Abs(x));
DoNext("Compute an antiderivative of |x|.");
BenchShow(AntiDeriv(x,Abs(x)));
DoNext("Compute the derivative of |x| (piecewise defined).");
BenchShow(D(x)(if (x<0) (-x) else x));
DoNext("Compute the antiderivative of |x| (piecewise defined).");
BenchShow( AntiDeriv(x,if (x<0) (-x) else x));
DoNext("Compute the first terms of the Taylor expansion of 1/sqrt(1-v^2/c^2) at v=0. ");
BenchCall(ans:=Taylor(v,0,4)Sqrt(1/(1-v^2/c^2)));
BenchCall(ans:=Simplify(ans));
BenchShow(PrettyForm(ans));
DoNext("Compute the inverse of the square of the above expansion. ");
BenchCall(ans:=Taylor(v,0,4)(1/ans)^2);
BenchShow(PrettyForm(Simplify(ans)));
DoNext("Compute the Taylor expansion of tan(x) at x=0 by dividing the expansion of sin(x) by that of cos(x). ");
BenchCall(ans1:=Taylor(x,0,5)(Sin(x)/Cos(x)));
BenchCall(PrettyForm(ans1));
BenchCall(ans2:=Taylor(x,0,5)Tan(x));
BenchCall(PrettyForm(ans2));
BenchShow(ans1-ans2);
DoNext("Compute the Legendre polynomials directly.");
BenchCall(10 # Legendre(0,_x) <-- 1);
BenchCall(20 # Legendre(n_IsInteger,_x) <--
[
Local(result);
result:=[
Local(x);
Expand((1/(2^n*(n!))) * Deriv(x,n)Expand((x^2-1)^n,x));
];
Eval(result);
]);
BenchCall(ForEach(item,Table(Legendre(i,x),i,0,4,1))PrettyForm(item));
DoNext("Compute the Legendre polynomials recursively, using their recurrence of order 2. ");
BenchCall(10 # LegendreRecursive(0,_x) <-- 1);
BenchCall(20 # LegendreRecursive(1,_x) <-- x);
BenchCall(30 # LegendreRecursive(n_IsPositiveInteger,_x) <--
Expand(((2*n - 1)*x*LegendreRecursive(n-1,x)-(n - 1)*LegendreRecursive(n-2,x))/n));
BenchCall(ForEach(item,Table(LegendreRecursive(i,x),i,0,4,1))PrettyForm(item));
DoNext("Evaluate the fourth Legendre polynomial at 1. ");
BenchShow(Legendre(4,1));
DoNext("Define the polynomial p = sum( i=1..5, ai*x^i ). ");
BenchCall(ans:=Sum(MakeVector(a,5)*(FillList(x,5)^(1 .. 5))));
BenchCall(PrettyForm(ans));
DoNext("Apply Horner\'s rule to the above polynomial.");
BenchCall(ans:=Sum(MakeVector(a,5)*(FillList(x,5)^(1 .. 5))));
BenchCall(PrettyForm(Horner(ans,x)));
DoNext("Compute the first terms of the continued fraction of Pi. ");
BenchCall(pi:=N(Pi,20));
BenchCall(a:=ContFrac(pi,6));
BenchCall(PrettyForm(a));
DoNext("Compute an infinite decimal representation of 1/7. ");
BenchShow(Decimal(1/7));
Echo({"This result means that the decimal expansion of 1/7 is
0.142857142857142...."});
DoNext("Evaluate TRUE and FALSE. ");
BenchShow(True And False);
DoNext("Solve the equation tan(x) = 1. ");
BenchShow(Solve(Tan(x)==1,x));
DoNext("Revert the Taylor expansion of sin(y) + cos(y) at y=0. ");
BenchCall(t:=InverseTaylor(y,0,6)Sin(y)+Cos(y));
BenchCall(PrettyForm(t));
Echo({"And check that it is in fact the inverse up to degree 5:"});
BenchCall(s:=Taylor(y,0,6)Sin(y)+Cos(y));
BenchShow(BigOh(Subst(y,s)t,y,6));
DoNext("Solve the linear (dependent) system x+y+z=6,2x+y+2z=10,x+3y+z=10.");
BenchShow(OldSolve({x+y+z==6,2*x+y+2*z==10,x+3*y+z==10},{x,y,z}));
DoNext("Evaluate True And False");
BenchShow(True And False);
BenchShow(CanProve(True And False));
DoNext("Simplify x or (not x)");
BenchShow(CanProve(x Or Not x));
DoNext("Simplify x or y or (x and y)");
BenchShow(CanProve(x Or y Or (x And y)));
Echo({curline," examples done"});
Echo({"</FONT></PRE></BODY></HTML>"});
|