Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

doctest fix for: cot(float) returns complex #21365

Closed
paulmasson mannequin opened this issue Aug 29, 2016 · 22 comments
Closed

doctest fix for: cot(float) returns complex #21365

paulmasson mannequin opened this issue Aug 29, 2016 · 22 comments

Comments

@paulmasson
Copy link
Mannequin

paulmasson mannequin commented Aug 29, 2016

sage: cot(float(.1))
(9.966644423259224+0j)

This causes a plot of cot() on the real axis to fail. Sample output:

sage: set_verbose(1)
sage: plot(cot(x),(x,.1,.5),plot_points=5)
verbose 1 (3743: plot.py, generate_plot_points) can't convert complex to float
Unable to compute f(0.1) (time = 1.604825)
verbose 1 (3743: plot.py, generate_plot_points) can't convert complex to float
Unable to compute f(0.199629500548) (time = 1.615858)
verbose 1 (3743: plot.py, generate_plot_points) can't convert complex to float
Unable to compute f(0.263010079144) (time = 1.616164)
verbose 1 (3743: plot.py, generate_plot_points) can't convert complex to float
Unable to compute f(0.373209060982) (time = 1.616497)
verbose 1 (3743: plot.py, generate_plot_points) can't convert complex to float
Unable to compute f(0.5) (time = 1.616673)
verbose 0 (3743: plot.py, generate_plot_points) WARNING: When plotting, failed to evaluate function at 5 points.
verbose 0 (3743: plot.py, generate_plot_points) Last error message: 'can't convert complex to float'
Launched png viewer for Graphics object consisting of 0 graphics primitives

There is no problem plotting 1/tan().

Component: symbolics

Author: Ralf Stephan

Branch/Commit: c0ef7a5

Reviewer: Travis Scrimshaw

Issue created by migration from https://trac.sagemath.org/ticket/21365

@paulmasson paulmasson mannequin added this to the sage-7.4 milestone Aug 29, 2016
@paulmasson paulmasson mannequin added c: symbolics labels Aug 29, 2016
@rwst
Copy link

rwst commented Sep 2, 2016

comment:2

real(cot(x)) works too.

@rwst
Copy link

rwst commented Sep 2, 2016

comment:3

When inserting a print at this line:
https://github.com/pynac/pynac/blob/master/ginac/inifcns_trig.cpp#L777
in order to print what is returned there I get:

9.96664442325922
verbose 1 (3743: plot.py, generate_plot_points) can't convert complex to float
Unable to compute f(0.1) (time = 0.176)
...

which is exactly cot(0.1) and does not look complex. So Pynac does not seem the direct cause of it.

@paulmasson
Copy link
Mannequin Author

paulmasson mannequin commented Sep 6, 2016

comment:4

I downloaded older binaries to determine the version in which this error first occurs. The cotangent plots just fine in 7.1 and fails in 7.2.

Sage 7.2.rc1 included Pynac 0.6.5, which is precisely the last time the cotangent function was modified in Pynac. That is unlikely to be a coincidence.

This is not a graphics issue. The plotting method returning the error hasn't been modified in years. And this is not the first time in my experience a change in Pynac has had consequences for plotting (#20818).

@paulmasson paulmasson mannequin added c: symbolics and removed c: graphics labels Sep 6, 2016
@tscrim
Copy link
Collaborator

tscrim commented Sep 6, 2016

comment:5

The issue is when you pass a floating point, not a sage.rings.real_mpfr.RealLiteral:

sage: cot(float(0.5))
(1.8304877217124513+0j)

in contrast with:

sage: type(sin(float(1.1)))
<type 'float'>

Thus the bug is likely coming from that the internal plot functions use python/machine floating points as they are Python (i.e., not run through the Sage preparser).

@tscrim
Copy link
Collaborator

tscrim commented Sep 6, 2016

comment:6

Tracing slightly further, the python math (which is the first place the code checks) does not have a cot function. Looking into it more now.

@tscrim
Copy link
Collaborator

tscrim commented Sep 6, 2016

comment:7

Okay, I'm not quite sure what happens. It seems to fall into the generic Function.__call__, but I'm just tracing through the logical output at this point.

@paulmasson

This comment has been minimized.

@paulmasson paulmasson mannequin changed the title Plot of cot() fails on real axis cot(float) returns complex Sep 14, 2016
@paulmasson
Copy link
Mannequin Author

paulmasson mannequin commented Sep 16, 2016

Upstream: Reported upstream. No feedback yet.

@paulmasson
Copy link
Mannequin Author

paulmasson mannequin commented Sep 16, 2016

comment:10

Will be fixed in the next release of Pynac.

@paulmasson
Copy link
Mannequin Author

paulmasson mannequin commented Sep 16, 2016

Changed upstream from Reported upstream. No feedback yet. to Fixed upstream, in a later stable release.

@paulmasson paulmasson mannequin added the s: needs info label Sep 16, 2016
@rwst
Copy link

rwst commented Oct 6, 2016

comment:11

I confirm this is fixed in #21623 so this ticked is duplicate.

@rwst rwst removed this from the sage-7.4 milestone Oct 6, 2016
@tscrim
Copy link
Collaborator

tscrim commented Oct 6, 2016

Reviewer: Travis Scrimshaw

@tscrim
Copy link
Collaborator

tscrim commented Oct 6, 2016

comment:12

Confirmed as well.

@rwst
Copy link

rwst commented Nov 5, 2016

Changed upstream from Fixed upstream, in a later stable release. to none

@rwst
Copy link

rwst commented Nov 5, 2016

comment:13

I'll reuse this ticket for the doctests.

@rwst rwst added this to the sage-7.6 milestone Nov 5, 2016
@rwst rwst changed the title cot(float) returns complex doctest fix for: cot(float) returns complex Nov 5, 2016
@rwst
Copy link

rwst commented Nov 5, 2016

@rwst
Copy link

rwst commented Nov 5, 2016

Changed reviewer from Travis Scrimshaw to none

@rwst
Copy link

rwst commented Nov 5, 2016

Commit: c0ef7a5

@rwst
Copy link

rwst commented Nov 5, 2016

New commits:

c0ef7a521365: add doctests

@rwst
Copy link

rwst commented Nov 5, 2016

Author: Ralf Stephan

@tscrim
Copy link
Collaborator

tscrim commented Nov 5, 2016

Reviewer: Travis Scrimshaw

@vbraun
Copy link
Member

vbraun commented Nov 8, 2016

Changed branch from u/rws/doctest_fix_for__cot_float__returns_complex to c0ef7a5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants