Martin Rubey <[EMAIL PROTECTED]> writes:
> I also add a test for branch cuts that shows another feature of the new
> functionality: useful error messages.
New version including bug reports for atan.
Martin
\documentclass{article}
\usepackage{axiom}
\begin{document}
\title{\$SPAD/src/input elemnum.input}
\author{The Axiom Team}
\maketitle
\begin{abstract}
\end{abstract}
\eject
\tableofcontents
\eject
\section{License}
<<license>>=
--Copyright The Numerical Algorithms Group Limited 1991.
@
<<*>>=
<<license>>
)set break resume
)expose UnittestCount UnittestAux Unittest
-- SMW June 26, 1991.
testsuite "elemnum"
inverses := _
["exp log x", _
"log exp x", _
"sin asin x", "cos acos x", "tan atan x", "cot acot x", "csc acsc x",_
"sec asec x", _
"asin sin x", "acos cos x", "atan tan x", "acot cot x", "acsc csc x",_
"asec sec x", _
"sinh asinh x", "cosh acosh x", "tanh atanh x", "coth acoth x", _
"csch acsch x", "sech asech x", _
"asinh sinh x", "acosh cosh x", "atanh tanh x", "acoth coth x", _
"acsch csch x", "asech sech x"];
anySubstring?(l: List String, x: String): Boolean ==
-- any?(e +-> match("*" e "*", x, char "*") > 0, l)
any?(e +-> integer(stringMatch("*" e "*", x, CHARACTER("*")$Lisp)$Lisp) >
0, l)
testcaseNoClear "0.7 Float"
x := 0.7::Float
errlist := ["acsc x", "asec x", "acosh x", "acoth x"]
for ex in inverses | not anySubstring?(errlist, ex) repeat
testRealEquals(ex, "x")
-- cannot loop over errlist, since error breaks the loop
testLibraryError "acsc x"
testLibraryError "asec x"
testLibraryError "acosh x"
testLibraryError "acoth x"
testcaseNoClear "0.7 DoubleFloat"
x := 0.7::DoubleFloat
for ex in inverses | not anySubstring?(errlist, ex) repeat
testRealEquals(ex, "x")
testLibraryError "acsc x"
testLibraryError "asec x"
testLibraryError "acosh x"
testLibraryError "acoth x"
testcaseNoClear "1.1 Float"
x := 1.1::Float
errlist := ["asin x", "acos x", "atanh x", "asech x"]
for ex in inverses | not anySubstring?(errlist, ex) repeat
testRealEquals(ex, "x")
testLibraryError "asin x"
testLibraryError "acos x"
testLibraryError "atanh x"
testLibraryError "asech x"
testcaseNoClear "1.1 DoubleFloat"
x := 1.1::DoubleFloat
for ex in inverses | not anySubstring?(errlist, ex) repeat
testRealEquals(ex, "x")
testLibraryError "asin x"
testLibraryError "acos x"
testLibraryError "atanh x"
testLibraryError "asech x"
testinverseFloats(a, b, n) ==
-- not declaring x and not converting s1, m1 as numbers to strings leads to the
-- strings being interpreted as Expressions, not Floats
free x
m1 := if n = 1 or n = 4 then 0 else 1
s1 := if n = 1 or n = 4 then 1 else -1
s2 := if n = 1 or n = 2 then 1 else -1
x := complex(s1*a, s2*b)
for ex in inverses repeat
if member?(ex, ["acos cos x", "asec sec x", _
"acosh cosh x", "asech sech x"])
then testComplexEquals(concat [string s1, "*", ex], "x")
else if ex = "acot cot x"
then testComplexEquals(concat [ex, " - ", string m1, "*%pi"], "x")
else testComplexEquals(ex, "x")
testcaseNoClear "Complex Float"
)clear value x
x:Complex Float
ba := 0.7::Float;
bb := 1.1::Float;
testinverseFloats(ba, bb, 1); -- test 0.7 + 1.1*%i
testinverseFloats(ba, bb, 2); -- test -0.7 + 1.1*%i
testinverseFloats(ba, bb, 3); -- test -0.7 - 1.1*%i
testinverseFloats(ba, bb, 4); -- test 0.7 - 1.1*%i
testcaseNoClear "Complex DoubleFloat"
)clear value x
x:Complex DFLOAT
sa := 0.7::DoubleFloat;
sb := 1.1::DoubleFloat;
testinverseFloats(sa, sb, 1);
testinverseFloats(sa, sb, 2);
testinverseFloats(sa, sb, 3);
testinverseFloats(sa, sb, 4);
testsuite "branch cuts"
testcaseNoClear "atan"
testLibraryError("atan(%i::Complex Float)")
testLibraryError("atan(-%i::Complex Float)")
testLibraryError("atan(%i::Complex DFLOAT)")
testLibraryError("atan(-%i::Complex DFLOAT)")
DirD := eval(D(atan(x0+(x1-x0)*t), t)::EXPR FLOAT, t=0)
tmax := 10
tdiff := 1.0e-8
-- t = 0..tmax
-- x = -2..2
Y t == -2.0 + t/tmax * 4.0
X y0 == sqrt(-y0^2 + 4.0)/2.0
-- t = 0: arg1 is on the negative x-axis, arg2 in quadrant II
for t in 0..tmax-1 repeat
arg1 := (%i * Y t + X Y t)::Complex Float
arg2 := (%i * Y(t+tdiff) + X Y(t+tdiff))::Complex Float
corr := (eval(DirD, [x0=arg1, x1=arg2]))::Complex Float
testComplexEquals("atan arg1 + corr", "atan arg2")
testComplexEquals("atan(arg1::Complex DFLOAT) + corr",
"atan(arg2::Complex DFLOAT)")
Y t == 2.0 - t/tmax * 4.0
X y0 == -sqrt(-y0^2 + 4.0)/2.0
-- t = tmax: arg1 is on the positive x-axis, arg2 in quadrant IV
for t in 0..tmax-1 repeat
arg1 := (%i * Y t + X Y t)::Complex Float
arg2 := (%i * Y(t+tdiff) + X Y(t+tdiff))::Complex Float
corr := (eval(DirD, [x0=arg1, x1=arg2]))::Complex Float
testComplexEquals("atan arg1 + corr", "atan arg2")
testComplexEquals("atan(arg1::Complex DFLOAT) + corr",
"atan(arg2::Complex DFLOAT)")
testcaseNoClear "asin"
DirD := eval(D(asin(x0+(x1-x0)*t), t)::EXPR FLOAT, t=0)
tmax := 10
tdiff := 1.0e-8
-- t = 0..tmax
-- x = -2..2
X t == -2.0 + t/tmax * 4.0
Y x0 == sqrt(-x0^2 + 4.0)/2.0
-- t = 0: arg1 is on the negative x-axis, arg2 in quadrant II
for t in 0..tmax-1 repeat
arg1 := (X t + %i * Y X t)::Complex Float
arg2 := (X(t+tdiff) + %i * Y X(t+tdiff))::Complex Float
corr := (eval(DirD, [x0=arg1, x1=arg2]))::Complex Float
testComplexEquals("asin arg1 + corr", "asin arg2")
testComplexEquals("asin(arg1::Complex DFLOAT) + corr",
"asin(arg2::Complex DFLOAT)")
X t == 2.0 - t/tmax * 4.0
Y x0 == -sqrt(-x0^2 + 4.0)/2.0
-- t = tmax: arg1 is on the positive x-axis, arg2 in quadrant IV
for t in 0..tmax-1 repeat
arg1 := (X t + %i * Y X t)::Complex Float
arg2 := (X(t+tdiff) + %i * Y X(t+tdiff))::Complex Float
corr := (eval(DirD, [x0=arg1, x1=arg2]))::Complex Float
testComplexEquals("asin arg1 + corr", "asin arg2")
testComplexEquals("asin(arg1::Complex DFLOAT) + corr",
"asin(arg2::Complex DFLOAT)")
expected() ==
messagePrint("testsuite | testcases: failed (total) | tests: failed
(total)")$OutputForm;
messagePrint("elemnum 0 (6) 0
(312)")$OutputForm;
messagePrint("branchcuts 1 (1) 3
(40)")$OutputForm
statistics()
expected()
@
\eject
\begin{thebibliography}{99}
\bibitem{1} nothing
\end{thebibliography}
\end{document}
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"FriCAS - computer algebra system" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/fricas-devel?hl=en
-~----------~----~----~----~------~----~------~--~---