#13246: Automatic exclusion of non-domain points in things like arcsec
-------------------------------------+-------------------------------------
Reporter: kcrisman | Owner: jason, was
Type: defect | Status: needs_work
Priority: major | Milestone: sage-6.3
Component: graphics | Resolution:
Keywords: | Merged in:
Authors: Punarbasu | Reviewers:
Purkayastha | Work issues:
Report Upstream: N/A | Commit:
Branch: | c31f63ed3860dbf2368ed17b3f54d8dd0ebf0331
u/ppurka/automatic_exclusion_of_non_domain_points_in_things_like_arcsec|
Stopgaps:
Dependencies: |
-------------------------------------+-------------------------------------
Comment (by kcrisman):
Thanks for this digging, ppurka. I have to say there isn't a lot in
[http://www.sagemath.org/mirror/src/changelogs/sage-5.11.txt that
changelog] that seems likely. Maybe #13933? But see below.
----
This ticket has exposed some bugs in trig.py as well.
{{{
sage: arcsec(-0.992725195401)
NaN
sage: arcsec(float(-0.992725195401))
<snip>
732 if parent is float:
733 return math.acos(1/x)
--> 734 return (1/x).arccos()
735
736 def _eval_numpy_(self, x):
AttributeError: 'complex' object has no attribute 'arccos'
}}}
Compare to behavior in Sage 5.2:
{{{
sage: arcsec(-0.992725195401)
arcsec(-0.992725195401000)
sage: arcsec(float(-0.992725195401))
arcsec(-0.992725195401)
sage:
}}}
Related, I think - none of these take things nicely.
{{{
sage: arccos(1+2*i)
arccos(2*I + 1)
sage: arccos(CC(1,2))
1.14371774040242 - 1.52857091948100*I
sage: arccos(CDF(1,2))
1.1437177404 - 1.52857091948*I
sage: arccos(complex(1,2))
<snip>
TypeError: Unable to convert x (='(1+2j)') to real number.
}}}
----
Anyway, I think I got it. Old behavior:
{{{
sage: arcsec(float(-0.992725195401))
arcsec(-0.992725195401)
}}}
This is because ''before'' #13933, `arcsec.__call__`, a `BuiltinFunction`
(**not** `GinacFunction`) was inheriting its `__call__` method directly
from `Function`. Then we hit
[http://git.sagemath.org/sage.git/tree/src/sage/symbolic/function.pyx#n459
this branch of the code] which turns the argument into a symbolic
argument.
But now, `arcsec` (still a `BuiltinFunction` now) uses the `__call__`
method from what used to be the method for only `GinacFunction`, but which
is now the method also for `BuiltinFunction`. So after doing the same
thing it did before, getting the symbolic version
{{{
sage: a = float(-0.992725195401)
KeyboardInterrupt
sage: res =
super(sage.symbolic.function.BuiltinFunction,arcsec).__call__(a,coerce=True)
sage: res
arcsec(-0.992725195401)
}}}
it now
[http://git.sagemath.org/sage.git/tree/src/sage/symbolic/function.pyx#n936
continues on instead of returning], and tries to evaluate `res` as a
complex, which causes us to go back to `_evalf_` of `arcsec`
{{{
sage: complex(res)
---------------------------------------------------------------------------
AttributeError: 'complex' object has no attribute 'arccos'
}}}
I'm not sure if the correct fix is to just make sure trig.py can handle
this, or whether this is a possible bug in the way `BuiltinFunction` was
changed. I'm going to ask at #13933.
----
Finally, from one of the original requesters, some more test cases.
Thanks for looking into this. The following page is a problem set in our
online text that has six interacts, the last two with my workaround for
handling arcsec(x) and arccsc(x), as well as their derivatives, which
involve 1/sqrt(x^2-1), another good test function, along with its
reciprocal, sqrt(x^2-1).
http://calculuscourse.maa.org/main2/Chapter5/Section5-5/Chapter5-5-6M.html
If you enter any of these in those last two "Graph" interacts (Problem 6
or 7), they will be drawn correctly -- because nothing is drawn between -1
and 1. [But arcsec(x/2) will cause an error message, and arcsec(2*x) will
not be completely drawn.] If you enter any of these in the third or
fourth interacts (Problems 4 and 5), there will either be an error message
(arcsec or arccsc) or the graph will be incorrectly drawn between 1 and -1
(sqrt(x^2-1) or 1/sqrt(x^2-1)).
I think the general class of functions for which this particular problem
exists is those for which the domain is interrupted by an interval of
finite length greater than 0. The inverse trig functions seem to involve
a different problem when trying to compute non-real values, but I don't
understand the error messages.
--
Ticket URL: <http://trac.sagemath.org/ticket/13246#comment:31>
Sage <http://www.sagemath.org>
Sage: Creating a Viable Open Source Alternative to Magma, Maple, Mathematica,
and MATLAB
--
You received this message because you are subscribed to the Google Groups
"sage-trac" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sage-trac.
For more options, visit https://groups.google.com/d/optout.