I am almost finished moving the tests into folds in the copy of
MathPiper which is in branch. However, one of the PSolve tests is
currently throwing an exception that needs to be fixed. When you get a
chance, would you be willing to look at the cause of this exception
and see if you can fix it? If your answer is "yes" here are
instructions to get you started:
1) Check out branches/mathpiper_javascript_branch from the repository.
2) Delete org/mathpiper/JavaScript.java.
3) Build the system by running: ant build
4) Run build/classes/xxx_test.bat or .sh to run the tests only for PSolve.
The mathpiper_tests.log file that is generated shows all of the tests
that are run on PSolve up through the one that causes the exception.
The exception output includes a stack dump. If you go to the line in
the stack dump which reads "****** THE PROBLEM IS EITHER IMMEDIATELY
ABOVE THIS LINE OR IMMEDIATELY BELOW THIS LINE ******", you should be
able to see that ultimately an argument that is being passed to the
First function (which the exception message identifies as 0) is what
is causing the exception.
This version of MathPiper is not currently set up to run in
MathPiperIDE, but the text console is available by running: java
org.mathpiper.ui.text.consoles.Console from inside the build/classes
directory.
If you encounter difficulties (and you may because quite a bit has
been changed in this version of MathPiper) let me know.
Thanks,
Ted
I have included the test fold and the test log below. The test log is
configured to output each test as it is run to help with locating
problems.
After looking at this exception a bit myself I see that PSolve calls
YacasPSolve and YacasPSolve calls Factors. Since factoring is
currently only partially working in this version of MathPiper, I think
it is likely that this is the ultimate cause of the problem.
Thanks,
Ted
========================================= In scripts4/solve.PSolve.mpw
%mathpiper,name="PSolve",subtype="automatic_test"
/* Linear equations */
Testing(" Linear");
VerifySolve(PSolve(x,x), 0);
VerifySolve(PSolve(x+3*Sin(b)-1,x), 1-3*Sin(b));
VerifySolve(PSolve(2*x-a,x), a/2);
VerifySolve(PSolve(2*x-a,a), 2*x);
/* Quadratic equations */
Testing(" Quadratic");
VerifySolve(PSolve(x^2,x), 0);
VerifySolve(PSolve(4*x^2-1,x), {1/2,-1/2});
VerifySolve(PSolve(x^2+1,x), {I,-I});
VerifySolve(PSolve(x^2-3*x+2,x), {1,2});
/* Cubic equations */
Testing(" Cubic");
VerifySolve(PSolve(x^3,x), 0);
VerifySolve(PSolve(x^3-1,x), {1, Exp(2/3*Pi*I), Exp(-2/3*Pi*I)});
VerifySolve(PSolve(x^3+1,x), {-1, Exp(1/3*Pi*I), Exp(-1/3*Pi*I)});
VerifySolve(PSolve(x^3-3*x^2+2*x,x), {0,2,1});
/* Quartic equations */
Testing(" Quartic");
VerifySolve(PSolve(x^4,x), 0);
VerifySolve(PSolve(16*x^4-1,x), {1/2, -1/2, 1/2*I, -1/2*I});
VerifySolve(PSolve(x^4-x,x), {0, 1, Exp(2/3*Pi*I), Exp(-2/3*Pi*I)});
VerifySolve(PSolve(x^4+x,x), {0, -1, Exp(1/3*Pi*I), Exp(-1/3*Pi*I)});
%/mathpiper
=================== mathpiper_tests.log file ======================
Stack tracing is on: Result: True
Side Effects:
Stack tracing is on.
***** Tue Jul 19 17:41:15 EDT 2011 *****
***** MathPiper version: js.022 *****
================================================================
Testing PSolve in file </org/mathpiper/scripts4/solve/PSolve.mpw>:
Testing(" Linear");
-- Linear
VerifySolve(PSolve(x,x),0);
VerifySolve(PSolve(x+3*Sin(b)-1,x),1-3*Sin(b));
VerifySolve(PSolve(2*x-a,x),a/2);
VerifySolve(PSolve(2*x-a,a),2*x);
Testing(" Quadratic");
-- Quadratic
VerifySolve(PSolve(x^2,x),0);
VerifySolve(PSolve(4*x^2-1,x),{1/2,-1/2});
VerifySolve(PSolve(x^2+1,x),{I,-I});
VerifySolve(PSolve(x^2-3*x+2,x),{1,2});
Testing(" Cubic");
-- Cubic
VerifySolve(PSolve(x^3,x),0);
VerifySolve(PSolve(x^3-1,x),{1,Exp(2/3*Pi*I),Exp(-2/3*Pi*I)});
******************
File: /org/mathpiper/scripts4/solve/PSolve.mpw, Line: 22
PSolve(x^3-1,x)
evaluates to
0
which differs from
{1,Complex((-1)/2,Sqrt(3/4)),Complex((-1)/2,-Sqrt(3/4))}
******************
VerifySolve(PSolve(x^3+1,x),{-1,Exp(1/3*Pi*I),Exp(-1/3*Pi*I)});
VerifySolve(PSolve(x^3-3*x^2+2*x,x),{0,2,1});
Testing(" Quartic");
-- Quartic
VerifySolve(PSolve(x^4,x),0);
VerifySolve(PSolve(16*x^4-1,x),{1/2,-1/2,1/2*I,-1/2*I});
***EXCEPTION[ Invalid argument. Extra information: <The bad argument
is <0>>. In function "First" :
/org/mathpiper/scripts4/solve/PSolve.mpw, Line number: 30, Line
index: 30. internal.
========================================= Start Of Built In Function Stack Trace
0: If
1: -> VerifySolve'Equal(Eval(e1),Eval(e2))
2: -> True
3: ->
[
WriteString("******************");
NewLine();
ShowLine();
NewLine();
Write(e1);
NewLine();
WriteString(" evaluates to ");
NewLine();
Write(Eval(e1));
NewLine();
WriteString(" which differs from ");
NewLine();
Write(e2);
NewLine();
WriteString("******************");
NewLine();
False;
]
-----------------------------------------
4: PSolve(16*x^4-1,x)
-----------------------------------------
5: Prog
6: -> Local(u,factors,f,r,s)
7: -> u:=MakeUni(uni,var)
8: -> If(Type(u)="UniVariate" And And@Lambda({x},IsNumber(x) Or
IsRational(x))/@u[3],
[
Local(coeffs);
coeffs:=Rationalize(u[3]);
coeffs:=If(Length(coeffs)>1,Lcm(Denominator/@coeffs)*coeffs,(Denominator/@coeffs)*coeffs);
DestructiveReplace(u,3,coeffs);
factors:=If(Degree(u)>0,Factors(NormalForm(u)),{NormalForm(u),1});
],
[
factors:={{uni,1}};
])
9: -> r:={}
10: -> ForEach(f,factors)
[
s:=YacasPSolve(MakeUni(f[1],var));
r:=Union(r,If(IsList(s),s,{s}));
]
11: -> If(Length(r)=1,r[1],r)
-----------------------------------------
12: Prog
13: -> MacroLocal($item1)
14: -> If(IsString($listOrString1),
[
Local(index,stringLength);
stringLength:=Length($listOrString1);
index:=1;
While(index<=stringLength)
[
MacroBind($item1,$listOrString1[index]);
Eval($body1);
index++;
];
],
[
Local(foreachtail);
Bind(foreachtail,$listOrString1);
While(Not IsEqual(foreachtail,{}))
[
MacroBind($item1,First(foreachtail));
Eval($body1);
Bind(foreachtail,Rest(foreachtail));
];
])
-----------------------------------------
15: IsString($listOrString1)
-----------------------------------------
16: {
[
Local(index,stringLength);
stringLength:=Length($listOrString1);
index:=1;
While(index<=stringLength)
[
MacroBind($item1,$listOrString1[index]);
Eval($body1);
index++;
];
],
[
Local(foreachtail);
Bind(foreachtail,$listOrString1);
While(Not IsEqual(foreachtail,{}))
[
MacroBind($item1,First(foreachtail));
Eval($body1);
Bind(foreachtail,Rest(foreachtail));
];
]}
-----------------------------------------
17: Prog
18: -> Local(foreachtail)
19: -> Bind(foreachtail,$listOrString1)
20: -> While(Not IsEqual(foreachtail,{}))
[
MacroBind($item1,First(foreachtail));
Eval($body1);
Bind(foreachtail,Rest(foreachtail));
]
-----------------------------------------
21:
[
MacroBind($item1,First(foreachtail));
Eval($body1);
Bind(foreachtail,Rest(foreachtail));
]
-----------------------------------------
22: Prog
23: -> MacroBind($item1,First(foreachtail))
24: -> Eval($body1)
25: -> Bind(foreachtail,Rest(foreachtail))
-----------------------------------------
26: Prog
27: -> s:=YacasPSolve(MakeUni(f[1],var))
28: -> r:=Union(r,If(IsList(s),s,{s}))
-----------------------------------------
29: {Check(Not IsNumber(aLeftAssign),"Argument","Only a variable can
be placed on the left side of an :=
operator."),MacroBind(aLeftAssign,Eval(aRightAssign)),Eval(aLeftAssign)}
-----------------------------------------
30: MacroBind
31: -> aLeftAssign
32: -> Eval(aRightAssign)
-----------------------------------------
33: Eval
34: -> aRightAssign
-----------------------------------------
35: Prog
36: -> Local(coef4,a1,a2,a3,a4,y,y1,z,t,s)
37: -> coef4:=Coef(uni,4)
38: -> a1:=Coef(uni,3)/coef4
39: -> a2:=Coef(uni,2)/coef4
40: -> a3:=Coef(uni,1)/coef4
41: -> a4:=Coef(uni,0)/coef4
42: -> y1:=First(YacasPSolve(y^3-a2*y^2+(a1*a3-4*a4)*y+4*a2*a4-a3^2-a1^2*a4,y))
43: -> t:=Sqrt(y1^2/4-a4)
44: -> If(t=0,s:=Sqrt(y1+a1^2/4-a2),s:=(a1*y1-2*a3)/(4*t))
45: -> Concat(YacasPSolve(z^2+(a1/2+s)*z+y1/2+t,z),YacasPSolve(z^2+(a1/2-s)*z+y1/2-t,z))
========================================= End Of Built In Function Stack Trace
****** THE PROBLEM IS EITHER IMMEDIATELY ABOVE THIS LINE OR
IMMEDIATELY BELOW THIS LINE ******
========================================= Start Of User Function Stack Trace
0: Prog
1: -> aRightAssign =
First(YacasPSolve(y^3-a2*y^2+(a1*a3-4*a4)*y+4*a2*a4-a3^2-a1^2*a4,y))
2: -> aLeftAssign = y1
3: -> s = NULL
4: -> t = NULL
5: -> z = NULL
6: -> y1 = NULL
7: -> y = NULL
8: -> a4 = 0
9: -> a3 = 0
10: -> a2 = 0
11: -> a1 = 0
12: -> coef4 = 16
13: -> uni = UniVariate(x,4,{16})
-----------------------------------------
14: :=
15: -> aRightAssign =
First(YacasPSolve(y^3-a2*y^2+(a1*a3-4*a4)*y+4*a2*a4-a3^2-a1^2*a4,y))
16: -> aLeftAssign = y1
17: -> s = NULL
18: -> t = NULL
19: -> z = NULL
20: -> y1 = NULL
21: -> y = NULL
22: -> a4 = 0
23: -> a3 = 0
24: -> a2 = 0
25: -> a1 = 0
26: -> coef4 = 16
27: -> uni = UniVariate(x,4,{16})
-----------------------------------------
28: Prog
29: -> s = NULL
30: -> t = NULL
31: -> z = NULL
32: -> y1 = NULL
33: -> y = NULL
34: -> a4 = 0
35: -> a3 = 0
36: -> a2 = 0
37: -> a1 = 0
38: -> coef4 = 16
39: -> uni = UniVariate(x,4,{16})
-----------------------------------------
40: YacasPSolve
41: -> uni = UniVariate(x,4,{16})
-----------------------------------------
42: Prog
43: -> aRightAssign = YacasPSolve(MakeUni(f[1],var))
44: -> aLeftAssign = s
45: -> foreachtail = {16*x^4-1,1}
46: -> f = 16*x^4-1
47: -> $body1 =
[
s:=YacasPSolve(MakeUni(f[1],var));
r:=Union(r,If(IsList(s),s,{s}));
]
48: -> $listOrString1 = {16*x^4-1,1}
49: -> $item1 = f
50: -> s = NULL
51: -> r = {}
52: -> f = NULL
53: -> factors = {16*x^4-1,1}
54: -> u = UniVariate(x,0,{-1,0,0,0,16})
55: -> var = x
56: -> uni = 16*x^4-1
-----------------------------------------
57: :=
58: -> aRightAssign = YacasPSolve(MakeUni(f[1],var))
59: -> aLeftAssign = s
60: -> foreachtail = {16*x^4-1,1}
61: -> f = 16*x^4-1
62: -> $body1 =
[
s:=YacasPSolve(MakeUni(f[1],var));
r:=Union(r,If(IsList(s),s,{s}));
]
63: -> $listOrString1 = {16*x^4-1,1}
64: -> $item1 = f
65: -> s = NULL
66: -> r = {}
67: -> f = NULL
68: -> factors = {16*x^4-1,1}
69: -> u = UniVariate(x,0,{-1,0,0,0,16})
70: -> var = x
71: -> uni = 16*x^4-1
-----------------------------------------
72: Prog
73: -> foreachtail = {16*x^4-1,1}
74: -> f = 16*x^4-1
75: -> $body1 =
[
s:=YacasPSolve(MakeUni(f[1],var));
r:=Union(r,If(IsList(s),s,{s}));
]
76: -> $listOrString1 = {16*x^4-1,1}
77: -> $item1 = f
78: -> s = NULL
79: -> r = {}
80: -> f = NULL
81: -> factors = {16*x^4-1,1}
82: -> u = UniVariate(x,0,{-1,0,0,0,16})
83: -> var = x
84: -> uni = 16*x^4-1
-----------------------------------------
85: Prog
86: -> foreachtail = {16*x^4-1,1}
87: -> f = 16*x^4-1
88: -> $body1 =
[
s:=YacasPSolve(MakeUni(f[1],var));
r:=Union(r,If(IsList(s),s,{s}));
]
89: -> $listOrString1 = {16*x^4-1,1}
90: -> $item1 = f
91: -> s = NULL
92: -> r = {}
93: -> f = NULL
94: -> factors = {16*x^4-1,1}
95: -> u = UniVariate(x,0,{-1,0,0,0,16})
96: -> var = x
97: -> uni = 16*x^4-1
-----------------------------------------
98: Prog
99: -> foreachtail = {16*x^4-1,1}
100: -> f = 16*x^4-1
101: -> $body1 =
[
s:=YacasPSolve(MakeUni(f[1],var));
r:=Union(r,If(IsList(s),s,{s}));
]
102: -> $listOrString1 = {16*x^4-1,1}
103: -> $item1 = f
104: -> s = NULL
105: -> r = {}
106: -> f = NULL
107: -> factors = {16*x^4-1,1}
108: -> u = UniVariate(x,0,{-1,0,0,0,16})
109: -> var = x
110: -> uni = 16*x^4-1
-----------------------------------------
111: Prog
112: -> f = 16*x^4-1
113: -> $body1 =
[
s:=YacasPSolve(MakeUni(f[1],var));
r:=Union(r,If(IsList(s),s,{s}));
]
114: -> $listOrString1 = {16*x^4-1,1}
115: -> $item1 = f
116: -> s = NULL
117: -> r = {}
118: -> f = NULL
119: -> factors = {16*x^4-1,1}
120: -> u = UniVariate(x,0,{-1,0,0,0,16})
121: -> var = x
122: -> uni = 16*x^4-1
-----------------------------------------
123: Prog
124: -> $body1 =
[
s:=YacasPSolve(MakeUni(f[1],var));
r:=Union(r,If(IsList(s),s,{s}));
]
125: -> $listOrString1 = {16*x^4-1,1}
126: -> $item1 = f
127: -> s = NULL
128: -> r = {}
129: -> f = NULL
130: -> factors = {16*x^4-1,1}
131: -> u = UniVariate(x,0,{-1,0,0,0,16})
132: -> var = x
133: -> uni = 16*x^4-1
-----------------------------------------
134: ForEach
135: -> $body1 =
[
s:=YacasPSolve(MakeUni(f[1],var));
r:=Union(r,If(IsList(s),s,{s}));
]
136: -> $listOrString1 = {16*x^4-1,1}
137: -> $item1 = f
138: -> s = NULL
139: -> r = {}
140: -> f = NULL
141: -> factors = {16*x^4-1,1}
142: -> u = UniVariate(x,0,{-1,0,0,0,16})
143: -> var = x
144: -> uni = 16*x^4-1
-----------------------------------------
145: Prog
146: -> s = NULL
147: -> r = {}
148: -> f = NULL
149: -> factors = {16*x^4-1,1}
150: -> u = UniVariate(x,0,{-1,0,0,0,16})
151: -> var = x
152: -> uni = 16*x^4-1
-----------------------------------------
153: YacasPSolve
154: -> var = x
155: -> uni = 16*x^4-1
-----------------------------------------
156: PSolve
157: -> var = x
158: -> uni = 16*x^4-1
159: -> arg2 = x
160: -> arg1 = 16*x^4-1
-----------------------------------------
161: VerifySolve
162: -> e2 = {1/2,(-1)/2,Complex(0,1/2),Complex(0,(-1)/2)}
163: -> e1 = PSolve(16*x^4-1,x)
164: -> arg2 = {1/2,(-1)/2,Complex(0,1/2),Complex(0,(-1)/2)}
165: -> arg1 = PSolve(16*x^4-1,x)
-----------------------------------------
166: <START>
========================================= End Of User Function Stack Trace
In function: :=, ]EXCEPTION***