File: integrate.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 (74 lines) | stat: -rw-r--r-- 2,581 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

// verify that unknown integrals don't simplify
Verify(Integrate(x,a,b)Exp(Sin(x)),Integrate(x,a,b)Exp(Sin(x)));
Verify(Integrate(x    )Exp(Sin(x)),Integrate(x    )Exp(Sin(x)));

// Verify that Yacas cannot integrate these expressions.
// Yacas needs to return the integration unevaluated, or
// return a correct answer (if it happens to be able to do
// these integrals in the future).
TestNonIntegrable(_expr) <-- Verify(Type(expr) = "Integrate",True);

// The following two used to get the interpreter into an infinite
// loop. Fixed in version 1.0.51
// FIXED!!! TestNonIntegrable(Integrate(x)(x*Ln(x)));
TestNonIntegrable(Integrate(x)Sin(Exp(x)));
Verify(Integrate(x) x^(-1),Ln(x)); // Well done Jonathan! ;-)
Verify(Integrate(x) 1/x,Ln(x) );

Verify(Integrate(x) 1/x^2, -x^ -1 );
Verify(Integrate(x) 6/x^2, (-6)*x^-1);
Verify(Integrate(x) 3/Sin(x),3*Ln(1/Sin(x)-Cos(x)/Sin(x)) );

Verify(Integrate(x) Ln(x), x*Ln(x)-x );
Verify(Integrate(x) x^5000, x^5001/5001 );
Verify(Integrate(x) 1/Tan(x), Ln(Sin(x)) );
Verify(Integrate(x) 1/Cosh(x)^2, Tanh(x) );
Verify(Integrate(x) 1/Sqrt(3-x^2), ArcSin(x/Sqrt(3)) );
Verify(Integrate(x) Erf(x), x*Erf(x)+1/(Exp(x^2)*Sqrt(Pi)) );
Verify(Integrate(x) Sin(x)/(2*y+4),(-Cos(x))/(2*y+4));
Verify(Integrate(x, {logAbs -> True})1/x, Ln(Abs(x)));
Verify(Integrate(x,a,b, {logAbs -> True})1/x, Ln(Abs(b))-Ln(Abs(a)));


TestNonIntegrable(Integrate(x) x^(1/x));
TestNonIntegrable(Integrate(x) x^(Sin(x)));
TestNonIntegrable(Integrate(x) Exp(x^2));
TestNonIntegrable(Integrate(x) Sin(x^2));

TestMathPiper(Integrate(x,0,A)Sin(x),1 - Cos(A));
TestMathPiper(Integrate(x,0,A)x^2,(A^3)/3);
TestMathPiper(Integrate(x,0,A)Sin(B*x),1/B-Cos(A*B)/B);
TestMathPiper(Integrate(x,0,A)(x^2+2*x+1)/(x+1),(A^2)/2+A);
TestMathPiper(Integrate(x,0,A)(x+1)/(x^2+2*x+1),Ln(A+1));

// Check that threaded integration works
Verify((Integrate(x,0,1) {1,x*x,1+x})-{1,1/3,3/2},{0,0,0});


// Test MatchLinear: code heavily used with integration
LocalSymbols(TestMatchLinearTrue,TestMatchLinearFalse) [

  TestMatchLinearTrue(_var,_expr,_expected) <--
  [
    Local(a,b);
    Verify(MatchLinear(var,expr),True);
    a:=Simplify(Matched'a()-expected[1]);
    b:=Simplify(Matched'b()-expected[2]);
    `TestMathPiper(@a,0);
    `TestMathPiper(@b,0);
  ];
  TestMatchLinearFalse(_var,_expr) <--
  [
    Local(a,b);
    Verify(MatchLinear(var,expr),False);
  ];

  TestMatchLinearTrue(x,(R+1)*x+(T-1),{(R+1),(T-1)});
  TestMatchLinearTrue(x,x+T,{1,T});
  TestMatchLinearTrue(x,a*x+b,{a,b});
  TestMatchLinearFalse(x,Sin(x)*x+(T-1));
  TestMatchLinearFalse(x,x+Sin(x));

];