File: xTestSolve.mpw

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 (139 lines) | stat: -rw-r--r-- 5,315 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
%mathpiper,title="xTestSolve"

Use("proposed.rep/xSolve.mpi");

//########################################################################
//       T E S T I N G     T E S T I N G     T E S T I N G
//########################################################################

iDebug := False;
//iDebug := True;

// a bunch of expressions for testing
expressions := {};
Push( expressions, {a,{}} );
Push( expressions, {0,{{x==x}}} );
Push( expressions, {x-5,{{x==5}}} );
Push( expressions, {x-a,{{x==a}}} );
Push( expressions, {12*x+5==29,{{x==2}}} );
Push( expressions, {5*x-15==5*(x-3),{x==x}} );
Push( expressions, {5*x-15==5*(x-4),{}} );

Push( expressions, {x^2-4,{x==2,x==(-2)}} );
Push( expressions, {x^2-a^2,{x==a,x==(-a)}} );
Push( expressions, {2*x^2+9*x==18,{x==3/2,x==(-6)}} );
Push( expressions, {5*x^2==25*x, {x==0,x==5}} );

Push( expressions, {2*x/5-x/3==2,{x==30}});
Push( expressions, {2/x-3/2==7/(2*x),{x==(-1)}});
Push( expressions, {2/(x-3)-3/(x+3)==12/(x^2-9),{}});
Push( expressions, {3/(x^2+x-2)-1/(x^2-1)==7/(2*(x^2+3*x+2)),{x==3}});
Push( expressions, {1+1/x==6/x^2,{x==2,x==(-3)}});

Push( expressions, {Sqrt(x)-3,{x==9}});
Push( expressions, {Sqrt(x-3),{x==3}});
Push( expressions, {Sqrt(x-3)==2, {x==7}});
Push( expressions, {Sqrt(2*x)==Sqrt(x+1), {x==1}});
Push( expressions, {Sqrt(x)==x, {x==1,x==0}});
Push( expressions, {Sqrt(x+2)-2*x==1,{x==1/4} } );
Push( expressions, {Sqrt(x+2)+2*x==1,{x==(5 - Sqrt(41))/8} } );
Push( expressions, {Sqrt(9*x^2+4)-3*x==1,{x==1/2} } );
Push( expressions, {Sqrt(x+1)-Sqrt(x)==-2,{} } );
Push( expressions, {Sqrt(3*x-5)-Sqrt(2*x+3)==-1,{x==3} } );

Push( expressions, {Exp(x)==4, {x==Ln(4)}});
Push( expressions, {Exp(x)==Abs(a), {x==Ln(Abs(a))}});
Push( expressions, {Ln(x)==4, {x==Exp(4)}});
Push( expressions, {Ln(x)==a, {x==Exp(a)}});

Push( expressions, {(x+6)/2-(3*x+36)/4==4, {x==-40} } );
Push( expressions, {(x-3)*(x-4)==x^2-2, {x==2} } );
Push( expressions, {a*x-2*b*c==d,{x==(2*b*c+d)/a} } );
Push( expressions, {(36-4*x)/(x^2-9)-(2+3*x)/(3-x)==(3*x-2)/(x+3),{x==-2} } );
Push( expressions, {(x^2-1)^(1/3)==2,{x==3,x==(-3)} } );

Push( expressions, {x^4-53*x^2+196==0, {x==(-7),x==(-2),x==2,x==7} } );
Push( expressions, {x^3-8==0, {x==2,x==-1+I*Sqrt(3),x==-1-I*Sqrt(3)} } );
Push( expressions, {x^(2/3)+x^(1/3)-2==0, {x==1,x==(-8)} } );
Push( expressions, {Sqrt(x)-(1/4)*x==1, {x==4} } );
Push( expressions, {(1/4)*x-Sqrt(x)==-1, {x==4} } );

Push( expressions, {{x-y==1,3*x+2*y==13}, {x==3,y==2} } );
Push( expressions, {{x-y-1==0,2*y+3*x-13==0}, {x==3,y==2} } ); 

//Push( expressions, {, {} } );

//Push( expressions, {,{{},{},{},{}}} );

NewLine(2);  Tell("TEST xSolve()");
t1 := SystemTimer();
expressions := Reverse(expressions);
Local(i);           i := 0;
Local(iCorrect);    iCorrect := 0;
ForEach(q,expressions)
[
    i := i + 1;     
    Check(i<100, ">>>>> FORCED STOP <<<<<");
    f := q[1];
    If( f = blank, 
        [
            i := i - 1;
            NewLine();
        ],
        [
            //If(i=23 Or i=26 Or i=40,iDebug:=True,iDebug:=False);
            
            Local(vars);
            g := q[2];
            NewLine();
            Tell(i,"-------------------------------");
            Tell(">>> Test xSolve() on the expression: ",f);
            stk := {};
            vars := VarList(f);
            If(IsList(f),
                [
                    If(iDebug=True,Tell("   system"));
                    r := xSolve(f,vars);
                    SysOut("      xSolve(f,vars) ==> ",r);
                ],
                [
                    If(iDebug=True,Tell("    single"));
                    r   := xSolve(f,x);
                    SysOut("      xSolve(f,x) ==> ",r);
                ]
            );
            //If(IsList(f),Break());
            rmg := Simplify(Expand(UnFlatten(r-g,"+",0)));
            If(iDebug=True,Tell("rmg",rmg));
            If(iDebug And IsList(rmg),Tell(Listify(rmg)));
            If( IsZero(rmg) Or IsZeroVector(rmg), 
                [SysOut("             Answer is CORRECT"); iCorrect:=iCorrect+1;],
                [
                  If(iDebug=True,Tell("check rmg a little more"));
                  Local(Lrmg,Lrmg2,Lrmg3);
                  Lrmg := Listify(rmg);
                  If(iDebug=True,Tell("Listify rmg",Lrmg));
                  If(Lrmg[1] != UnFlatten,
                    [
                       Lrmg2 := Listify(Lrmg[2]);
                       Lrmg3 := Listify(Lrmg[3]);
                       If(iDebug=True,Tell("LL",{Lrmg2,Lrmg3}));
                       If(CloseEnough(Lrmg2[3],Lrmg3[3],10),
                         [SysOut("             Answer is CORRECT"); iCorrect:=iCorrect+1;],
                         [SysOut("             Answer is WRONG:  should be ",g  );]
                       );
                    ],
                    SysOut("             Answer is WRONG:  should be ",g  )
                  );
                ]                               
            );
            //SysOut("             Answer is WRONG:  it should be ",g);
        ]
    );     
];
NewLine(2);
Tell("DONE",{iCorrect,i});
t2 := SystemTimer();
Echo("Time taken:  ",N((t2-t1)/10^9)," sec");

%/mathpiper