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

src/sage/plot/plot.py: random doctest failure #33129

Open
tornaria opened this issue Jan 7, 2022 · 3 comments
Open

src/sage/plot/plot.py: random doctest failure #33129

tornaria opened this issue Jan 7, 2022 · 3 comments

Comments

@tornaria
Copy link
Contributor

tornaria commented Jan 7, 2022

sage -t --long --random-seed=314121851792717929490963296099377352180 src/sage/plot/plot.py
**********************************************************************
File "src/sage/plot/plot.py", line 1782, in sage.plot.plot.plot
Failed example:
    plot(f, (x, -3.5, 3.5), detect_poles='show', exclude=[-3..3], ymin=-5, ymax=5)
Expected:
    Graphics object consisting of 12 graphics primitives
Got:
    Graphics object consisting of 13 graphics primitives
**********************************************************************
1 item had failures:
   1 of 154 in sage.plot.plot.plot
    [461 tests, 1 failure, 60.91 s]
----------------------------------------------------------------------
sage -t --long --random-seed=314121851792717929490963296099377352180 src/sage/plot/plot.py  # 1 doctest failed
----------------------------------------------------------------------

Looks similar to #29954.

Component: doctest framework

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

@tornaria tornaria added this to the sage-9.5 milestone Jan 7, 2022
@DaveWitteMorris
Copy link
Member

comment:1

The problem seems to be that the plot routine occasionally decides there is a pole at x = 0, so it fills the gap in the graph with a vertical dashed gray line. This is hard to see because the extra line is on top of the y-axis. To see the effect more easily, you can run the following code:

while True:
    f(x) = (floor(x)+0.5) / (1-(x-0.5)^2)
    P = plot(f(x - 1), (x, -2.5, 4.5), detect_poles='show',
                exclude=[-2..4], ymin=-5, ymax=5)
    if "13" in str(P):
        bad_plot = P
        break
show(bad_plot)

If your experience is the same as mine, the graph will include a vertical dashed line from (1, -2/3) to (1, 2/3). (I didn't do any statistics, but the bad plot seems to happen once every few hundred tries.)

So this doesn't seem to be the same problem as #29954. Instead, it seems we need to make detect_poles smarter.

@fchapoton
Copy link
Contributor

comment:2

bump to 9.6

@fchapoton fchapoton modified the milestones: sage-9.5, sage-9.6 Jan 29, 2022
@mwageringel
Copy link

comment:3

Replying to @DaveWitteMorris:

Instead, it seems we need to make detect_poles smarter.

I agree. The routine for detecting poles computes the slope between consecutive plot points. In this example, the slope at the discontinuity is just very close to the threshold value, so sometimes a pole is detected there (I am a bit surprised this is not deterministic).

A simple attempt would be to increase the threshold a bit. Also, the detection determines the slope only in absolute terms, not relatively – probably it would be good to consider the y-range as well. For example, scaling your example by 10 always replicates the problem:

sage: f(x) = (floor(x)+0.5) / (1-(x-0.5)^2)
sage: plot(10*f(x - 1), (x, -2.5, 4.5), detect_poles='show', exclude=[-2..4], ymin=-50, ymax=50)
Launched png viewer for Graphics object consisting of 13 graphics primitives

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

5 participants