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

gosper_iterator of continued fractions is unstable #32127

Open
mwageringel opened this issue Jul 4, 2021 · 2 comments
Open

gosper_iterator of continued fractions is unstable #32127

mwageringel opened this issue Jul 4, 2021 · 2 comments

Comments

@mwageringel
Copy link

sage -t --long --random-seed=5058 src/sage/rings/continued_fraction_gosper.py
**********************************************************************
File "src/sage/rings/continued_fraction_gosper.py", line 63, in sage.rings.continued_fraction_gosper.gosper_iterator.__init__
Failed example:
    continued_fraction((preperiod, period), x.value()) == continued_fraction((a*x.value()+b)/(c*x.value()+d))
Exception raised:
    Traceback (most recent call last):
      File "/usr/lib/python3.9/site-packages/sage/doctest/forker.py", line 714, in _run
        self.compile_and_execute(example, compiler, test.globs)
      File "/usr/lib/python3.9/site-packages/sage/doctest/forker.py", line 1133, in compile_and_execute
        exec(compiled, globs)
      File "<doctest sage.rings.continued_fraction_gosper.gosper_iterator.__init__[8]>", line 1, in <module>
        continued_fraction((preperiod, period), x.value()) == continued_fraction((a*x.value()+b)/(c*x.value()+d))
      File "/usr/lib/python3.9/site-packages/sage/rings/continued_fraction.py", line 2618, in continued_fraction
        x1, x2 = check_and_reduce_pair(x1, x2)
      File "/usr/lib/python3.9/site-packages/sage/rings/continued_fraction.py", line 2257, in check_and_reduce_pair
        raise ValueError("the elements of the period cannot be negative")
    ValueError: the elements of the period cannot be negative

which comes from this example and apparently should not return negative values:

sage: a, b, c, d = 6, -9, -2, 3
sage: from sage.rings.continued_fraction_gosper import gosper_iterator
sage: x = continued_fraction(([1,2],[3,4])); i = iter(gosper_iterator(a,b,c,d,x))
sage: list(i)
[-3]

Note that (6,-9) == -3 * (-2,3).

In #29979, a doctest was marked not tested because of this.

CC: @kliem @videlec

Component: number theory

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

@mwageringel
Copy link
Author

comment:1

See also [#29979 comment:27].

@mkoeppe mkoeppe modified the milestones: sage-9.4, sage-9.5 Jul 19, 2021
@mwageringel

This comment has been minimized.

@mkoeppe mkoeppe modified the milestones: sage-9.5, sage-9.6 Dec 18, 2021
@mkoeppe mkoeppe modified the milestones: sage-9.6, sage-9.7 May 3, 2022
@mkoeppe mkoeppe modified the milestones: sage-9.7, sage-9.8 Sep 19, 2022
@mkoeppe mkoeppe removed this from the sage-9.8 milestone Jan 29, 2023
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

2 participants