File: calculus.mpt

package info (click to toggle)
mathpiper 0.81f%2Bsvn4469%2Bdfsg3-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 36,572 kB
  • sloc: java: 57,479; lisp: 13,721; objc: 1,300; xml: 988; makefile: 114; awk: 95; sh: 38
file content (151 lines) | stat: -rw-r--r-- 5,173 bytes parent folder | download | duplicates (4)
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
f():=[];//Echo(CurrentFile()," line ",CurrentLine());
Testing("UnaryFunctionInverses");
Verify(Sin(ArcSin(a)),a);  f();
Verify(Cos(ArcCos(a)),a);  f();

//TODO ??? Verify(Tan(ArcTan(a)),a);
//TODO ??? this is not always the correct answer! Verify(ArcTan(Tan(a)),a);
Verify(Tan(Pi/2),Infinity); f();
Verify(Tan(Pi),0); f();

Verify( Limit(x,Infinity) Sin(x), Undefined ); f();
Verify( Limit(x,Infinity) Cos(x), Undefined ); f();
Verify( Limit(x,Infinity) Tan(x), Undefined ); f();
Verify( Limit(x,Infinity) Gamma(x), Infinity ); f();
Verify( Limit(x,Infinity) Abs(x), Infinity ); f();
Verify( Limit(x,Infinity) x!, Infinity); f();
Verify( Sin(x)/Cos(x), Tan(x) ); f();
Verify( TrigSimpCombine(Sin(x)^2 + Cos(x)^2), 1 ); f();

Verify( Sinh(x)-Cosh(x), Exp(-x)); f();
Verify( Sinh(x)+Cosh(x), Exp(x) ); f();
Verify( Sinh(x)/Cosh(x), Tanh(x) ); f();
Verify( Sinh(Infinity), Infinity); f();
Verify( Sinh(x)*Csch(x), 1); f();
Verify( 1/Coth(x), Tanh(x) ); f();
Verify(2+I*3,Complex(2,3)); f();
Verify(Magnitude(I+1),Sqrt(2)); f();

Verify(Re(2+I*3),2); f();
Verify(Im(2+I*3),3); f();
// Shouldn't these be in linalg.yts?
Verify(ZeroVector(3),{0,0,0}); f();
Verify(BaseVector(2,3),{0,1,0}); f();
Verify(Identity(3),{{1,0,0},{0,1,0},{0,0,1}}); f();

Testing("Derivatives");
Verify(Differentiate(x) a,0); f();
Verify(Differentiate(x) x,1); f();
Verify(Differentiate(x) (x+x),2); f();
Verify(Differentiate(x) (x*x),2*x); f();
Verify(Differentiate(x) Differentiate(x) Sin(x),-Sin(x)); f();

Testing("Limits");
Verify( Limit(x,0,Right) Ln(x)*Sin(x), 0 ); f();
KnownFailure( Limit(k,Infinity) ((k-phi)/k)^(k+1/2) = Exp(-phi) ); f();

// tests adapted from mpreduce

Verify(Limit(x,0)Sin(x)/x, 1);
Verify(Limit(x,0)Sin(x)^2/x, 0);
Verify(Limit(x,1)Sin(x)/x, Sin(1));
/* This is actually a tricky one - for complex it should bring 
   infinity but for real it's undefined. BTW, reduce seems 
   to get it wrong */
Verify(Limit(x,0)1/x, Undefined); 
Verify(Limit(x,0)(Sin(x)-x)/x^3, -1/6);
Verify(Limit(x,Infinity)x*Sin(1/x), 1);
/* reduce seems to get it wrong */
Verify(Limit(x,0)Sin(x)/x^2, Undefined);
Verify(Limit(x,Infinity)x^2*Sin(1/x), Infinity);

// tests adapted from mpreduce

Verify(Limit(x,2)x^2-6*x+4,-4);
Verify(Limit(x,-1)(x+3)*(2*x-1)/(x^2+3*x-2), 3/2);
Verify(Limit(h,0)(Sqrt(4+h)-2)/h, 1/4);
Verify(Limit(x,4)(Sqrt(x)-2)/(4-x), -1/4);
Verify(Limit(x,2)(x^2-4)/(x-2), 4);
Verify(Limit(x,-1)1/(2*x-5), -1/7);
Verify(Limit(x,1)Sqrt(x)/(x+1), 1/2);
Verify(Limit(x,Infinity)(2*x+5)/(3*x-2), 2/3);
Verify(Limit(x,1)(1/(x+3)-2/(3*x+5))/(x-1), 1/32);
Verify(Limit(x,0)Sin(3*x)/x, 3);
Verify(Limit(x,0)(1-Cos(x))/x^2, 1/2);
Verify(Limit(x,0)(6*x-Sin(2*x))/(2*x+3*Sin(4*x)), 2/7);
Verify(Limit(x,0)(1-2*Cos(x)+Cos(2*x))/x^2, -1);
Verify(Simplify(Limit(x,0)(3*Sin(Pi*x) - Sin(3*Pi*x))/x^3), 4*Pi^3);
Verify(Limit(x,0)(Cos(a*x)-Cos(b*x))/x^2, (-a^2 + b^2)/2);
Verify(Limit(x,0)(Exp(x)-1)/x, 1);
Verify(Limit(x,0)(a^x-b^x)/x, Ln(a) - Ln(b));

// tests adapted from mpreduce

Verify(Limit(x,0)Sinh(2*x)^2/Ln(1+x^2), 4);
// The limit seems to hang mathpiper
//Verify(Limit(x,Infinity)x^2*(Exp(1/x)-1)*(Ln(x+2)-Ln(x)),2);
// another tricky problem with the result depending on the sign of 
// alpha; I'm not sure how we should deal with it
//Limit(x,Infinity)x^alpha*Ln(x+1)^2/Ln(x);
Verify(Limit(x,0)(2*Cosh(x)-2-x^2)/Ln(1+x^2)^2, 1/12);
Verify(Limit(x,0)(x*Sinh(x)-2+2*Cosh(x))/(x^4+2*x^2), 1);
Verify(Limit(x,0)(2*Sinh(x)-Tanh(x))/(Exp(x)-1), 1);
Verify(Limit(x,0)x*Tanh(x)/(Sqrt(1-x^2)-1), -2);
Verify(Limit(x,0)(2*Ln(1+x)+x^2-2*x)/x^3, 2/3);
Verify(Limit(x,0)(Exp(5*x)-2*x)^(1/x), Exp(3));
Verify(Limit(x,Infinity)Ln(Ln(x))/Ln(x)^2, 0);

// tests adapted from mpreduce

Verify(Limit(x,0)(Exp(x)-1)/x, 1);
Verify(Limit(x,1)((1-x)/Ln(x))^2, 1);
Verify(Limit(x,0)x/(Exp(x)-1), 1);
Verify(Limit(x,0)x/Ln(x), 0);
Verify(Limit(x,Infinity)Ln(1+x)/Ln(x), 1);
Verify(Limit(x,Infinity)Ln(x)/Sqrt(x), 0);
Verify(Limit(x,0,Right)Sqrt(x)/Sin(x), Infinity);
Verify(Limit(x,0)x*Ln(x), 0);
Verify(Limit(x,0)Ln(x)/Ln(2*x), 1);
Verify(Limit(x,0)x*Ln(x)*(1+x), 0);
Verify(Limit(x,Infinity)Ln(x)/x,0);
Verify(Limit(x,Infinity)Ln(x)/Sqrt(x),0);
Verify(Limit(x,Infinity)Ln(x), Infinity);
Verify(Limit(x,0)Ln(x+1)/Sin(x), 1);
// Seems to hang mathpiper
//Verify(Limit(x,0)Ln(x+1/x)*Sin(x), 0);
Verify(Limit(x,0)-Ln(1+x)*(x+2)/Sin(x), -2);
Verify(Limit(x,Infinity)Ln(x+1)^2/Sqrt(x), 0);
Verify(Limit(x,Infinity)(Ln(x+1)-Ln(x)), 0);
Verify(Limit(x,Infinity)-Ln(x+1)^2/Ln(Ln(x)), -Infinity);

// Verify argument checking
[
    Verify(Limit(n, Infinity) 2 + 11/n, 2);
    Local(n, exception);
    n := 5;
    exception := False;
    ExceptionCatch(Limit(n, Infinity) 2 + 11/n, exception := True);
    Verify(exception, True); 
];

[
  Local(z);
  // This function satisfies Laplaces eqn: Differentiate(x,2)z + Differentiate(y,2)z = 0
  z:= ArcTan((2*x*y)/(x^2 - y^2)); f();
  Verify(Simplify((Differentiate(x,2) z) + Differentiate(y,2) z), 0 );
];


Testing("Pslq");
VerifyPslq(left,right):=
[
  If(left=right,
    Verify(True,True),
    `Verify(@left,-(@right)));
];

VerifyPslq(Pslq({ Pi+2*Exp(1) , Pi , Exp(1) },20),{1,-1,-2}); f();
VerifyPslq(Pslq({ 2*Pi+3*Exp(1) , Pi , Exp(1) },20),{1,-2,-3}); f();