Opened 3 years ago
Closed 3 years ago
#21365 closed defect (fixed)
doctest fix for: cot(float) returns complex
Reported by:  paulmasson  Owned by:  

Priority:  major  Milestone:  sage7.5 
Component:  symbolics  Keywords:  
Cc:  Merged in:  
Authors:  Ralf Stephan  Reviewers:  Travis Scrimshaw 
Report Upstream:  N/A  Work issues:  
Branch:  c0ef7a5 (Commits)  Commit:  c0ef7a5fcc0f14e1c5fb108ceedd6eba5c63aa36 
Dependencies:  Stopgaps: 
Description (last modified by )
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().
Change History (17)
comment:1 Changed 3 years ago by
 Component changed from symbolics to graphics
comment:2 Changed 3 years ago by
comment:3 Changed 3 years ago by
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.
comment:4 Changed 3 years ago by
 Component changed from graphics to symbolics
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).
comment:5 Changed 3 years ago by
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).
comment:6 Changed 3 years ago by
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.
comment:7 Changed 3 years ago by
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.
comment:8 Changed 3 years ago by
 Description modified (diff)
 Summary changed from Plot of cot() fails on real axis to cot(float) returns complex
comment:9 Changed 3 years ago by
 Report Upstream changed from N/A to Reported upstream. No feedback yet.
comment:10 Changed 3 years ago by
 Report Upstream changed from Reported upstream. No feedback yet. to Fixed upstream, in a later stable release.
 Status changed from new to needs_info
Will be fixed in the next release of Pynac.
comment:11 Changed 3 years ago by
 Milestone changed from sage7.4 to sageduplicate/invalid/wontfix
 Status changed from needs_info to needs_review
I confirm this is fixed in #21623 so this ticked is duplicate.
comment:12 Changed 3 years ago by
 Reviewers set to Travis Scrimshaw
 Status changed from needs_review to positive_review
Confirmed as well.
comment:13 Changed 3 years ago by
 Milestone changed from sageduplicate/invalid/wontfix to sage7.6
 Report Upstream changed from Fixed upstream, in a later stable release. to N/A
 Status changed from positive_review to needs_work
 Summary changed from cot(float) returns complex to doctest fix for: cot(float) returns complex
I'll reuse this ticket for the doctests.
comment:14 Changed 3 years ago by
 Branch set to u/rws/doctest_fix_for__cot_float__returns_complex
comment:15 Changed 3 years ago by
 Commit set to c0ef7a5fcc0f14e1c5fb108ceedd6eba5c63aa36
 Reviewers Travis Scrimshaw deleted
 Status changed from needs_work to needs_review
New commits:
c0ef7a5  21365: add doctests

comment:16 Changed 3 years ago by
 Milestone changed from sage7.6 to sage7.5
 Reviewers set to Travis Scrimshaw
 Status changed from needs_review to positive_review
comment:17 Changed 3 years ago by
 Branch changed from u/rws/doctest_fix_for__cot_float__returns_complex to c0ef7a5fcc0f14e1c5fb108ceedd6eba5c63aa36
 Resolution set to fixed
 Status changed from positive_review to closed
real(cot(x))
works too.