Waldek Hebisch <[EMAIL PROTECTED]> writes:
> > Waldek, I test values of asin on a circle around the origin with radius 2.
> > Is this what you had in mind?
> >
>
> I am not sure what you intend to test, but the test I have in mind is like:
>
> steps := 1000
> h := %pi/steps
> -- need to choose correct constant, 5.0 is just w wild guess
> eps := 5.0/steps
> valp := asin(2*exp(%i*h))
> for i in 2..(steps-1) repeat
> valn := asin(2*exp(%i*h*i)
> norm(valn-valp) > eps => error "Jump detected"
> valp := valn
Well, that's very very close to what I did at first, without the symbolic
derivative. Your circle is much better than mine, however...
> IIUC you test that numerical derivative agrees with symbolic one, which is a
> different test -- given seqence of points x_n, your test will detect jump
> between x_n and x_n+tdiff, but miss jumps between x_n+tdiff and x_{n+1}. The
> test I wrote above is designed to detect jumps between x_n and x_{n+1}.
I chose not to look for jumps between x_n and x_{n+1} because that way I can
have much fewer steps. If the number of steps is small, than norm(valn-valp)
will be rather big...
Do you think it makes much difference to also look for jumps between x_n and
x_{n+1}? OK, I see, it does. I have to check the timing however. Your test
seems to run much quicker than mine...
Here is the rewritten test. There are quite a few failures. The branchcuts
from HyperSpec/Body/f_sinh_.htm are still missing.
I wonder whether calling
eval(atan x, x, 2.0+%i)
simply calls atan$Complex(Float) in the end. I guess so. It would only make
sense to check special values of atan, that are simplified in EXPR, wouldn't
it?
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 "branchcuts"
tmax := 100
testAbsolutePrecision((1/tmax)::Float)
testAbsolutePrecision((1/tmax)::DoubleFloat)
testRelativePrecision((1/tmax)::Float)
testRelativePrecision((1/tmax)::DoubleFloat)
testCircle(radius, begPolar, begCartesian, angle, f) ==
free valOld
free valNew
arg := begCartesian
valOld := f(arg)
for t in 1..tmax-1 repeat
-- output arg
arg := radius*exp(%i*(angle/tmax*t+begPolar))
valNew := f(arg)
testComplexEquals("valOld", "valNew")
valOld := valNew
-- output arg
testcaseNoClear "sqrt"
-- branchcuts
testCircle(2.0, -%pi, -2.0::Complex(FLOAT), -2*%pi, sqrt$Complex(Float))
testCircle(2.0, -%pi, -2.0::Complex(DFLOAT), -2*%pi, sqrt$Complex(DFLOAT))
testcaseNoClear "log"
-- branchcuts
testCircle(2.0, -%pi, -2.0::Complex(FLOAT), -2*%pi, log$Complex(Float))
testCircle(2.0, -%pi, -2.0::Complex(DFLOAT), -2*%pi, log$Complex(DFLOAT))
-- singularities
testLibraryError("log(0.0::Complex Float)")
testLibraryError("log(0.0::Complex DFLOAT)")
testcaseNoClear "atan"
-- branchcuts right circle
testCircle(2.0, -%pi/2.0, -2.0*%i::Complex(FLOAT), %pi, atan$Complex(Float))
testCircle(2.0, -%pi/2.0, -2.0*%i::Complex(DFLOAT), %pi, atan$Complex(DFLOAT))
-- branchcuts left circle
testCircle(2.0, %pi/2.0, 2.0*%i::Complex(FLOAT), %pi, atan$Complex(Float))
testCircle(2.0, %pi/2.0, 2.0*%i::Complex(DFLOAT), %pi, atan$Complex(DFLOAT))
-- singularities
testLibraryError("atan(%i::Complex Float)")
testLibraryError("atan(-%i::Complex Float)")
testLibraryError("atan(%i::Complex DFLOAT)")
testLibraryError("atan(-%i::Complex DFLOAT)")
testcaseNoClear "asin"
-- branchcuts upper circle
testCircle(2.0, -%pi, -2.0::Complex(FLOAT), -%pi, asin$Complex(Float))
testCircle(2.0, -%pi, -2.0::Complex(DFLOAT), -%pi, asin$Complex(DFLOAT))
-- branchcuts lower circle
testCircle(2.0, 0.0, 2.0::Complex(FLOAT), -%pi, asin$Complex(Float))
testCircle(2.0, 0.0, 2.0::Complex(DFLOAT), -%pi, asin$Complex(DFLOAT))
testcaseNoClear "acos"
-- branchcuts upper circle
testCircle(2.0, -%pi, -2.0::Complex(FLOAT), -%pi, acos$Complex(Float))
testCircle(2.0, -%pi, -2.0::Complex(DFLOAT), -%pi, acos$Complex(DFLOAT))
-- branchcuts lower circle
testCircle(2.0, 0.0, 2.0::Complex(FLOAT), -%pi, acos$Complex(Float))
testCircle(2.0, 0.0, 2.0::Complex(DFLOAT), -%pi, acos$Complex(DFLOAT))
expected() ==
messagePrint("testsuite | testcases: failed (total) | tests: failed
(total)")$OutputForm;
messagePrint("elemnum 0 (6) 0
(312)")$OutputForm;
messagePrint("branchcuts 4 (5) 16
(1590)")$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
-~----------~----~----~----~------~----~------~--~---