Skip to content

Commit

Permalink
Trac #32774: Bug in continued fraction doctest
Browse files Browse the repository at this point in the history
Part of #32544:

{{{
sage -t --long --random-seed=77478494819088915365500074763386376542
src/sage/rings/continued_fraction.py
**********************************************************************
File "src/sage/rings/continued_fraction.py", line 265, in
sage.rings.continued_fraction.rat_interval_cf_list
Failed example:
    for prec in range(10,54):
        R = RealIntervalField(20)
        for _ in range(100):
            x = R.random_element() * R.random_element() +
R.random_element() / 100
            l = x.lower().exact_rational()
            u = x.upper().exact_rational()
            cf = rat_interval_cf_list(l,u)
            a = continued_fraction(cf).value()
            b = continued_fraction(cf+[1]).value()
            if a > b:
                a,b = b,a
            assert a <= l
            assert b >= u
Exception raised:
    Traceback (most recent call last):
      File "/home/jonathan/Applications/sage/local/lib/python3.8/site-
packages/sage/doctest/forker.py", line 694, in _run
        self.compile_and_execute(example, compiler, test.globs)
      File "/home/jonathan/Applications/sage/local/lib/python3.8/site-
packages/sage/doctest/forker.py", line 1088, in compile_and_execute
        exec(compiled, globs)
      File "<doctest
sage.rings.continued_fraction.rat_interval_cf_list[2]>", line 8, in
<module>
        a = continued_fraction(cf).value()
      File "/home/jonathan/Applications/sage/local/lib/python3.8/site-
packages/sage/rings/continued_fraction.py", line 2625, in
continued_fraction
        x1, x2 = check_and_reduce_pair(x)
      File "/home/jonathan/Applications/sage/local/lib/python3.8/site-
packages/sage/rings/continued_fraction.py", line 2254, in
check_and_reduce_pair
        raise ValueError("continued fraction can not represent
infinity")
    ValueError: continued fraction can not represent infinity
**********************************************************************
1 item had failures:
   1 of   4 in sage.rings.continued_fraction.rat_interval_cf_list
    [437 tests, 1 failure, 5.09 s]
-------------------------------------------------------------
}}}

URL: https://trac.sagemath.org/32774
Reported by: gh-kliem
Ticket author(s): Jonathan Kliem
Reviewer(s): Kwankyu Lee
  • Loading branch information
Release Manager committed Oct 29, 2021
2 parents 0ddec55 + e1664ff commit 1277457
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/sage/rings/continued_fraction.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,11 +264,13 @@ def rat_interval_cf_list(r1, r2):
sage: rat_interval_cf_list(257/113, 5224/2297)
[2, 3, 1, 1, 1, 4]
sage: for prec in range(10,54):
....: R = RealIntervalField(20)
....: R = RealIntervalField(prec)
....: for _ in range(100):
....: x = R.random_element() * R.random_element() + R.random_element() / 100
....: l = x.lower().exact_rational()
....: u = x.upper().exact_rational()
....: if l.floor() != u.floor():
....: continue
....: cf = rat_interval_cf_list(l,u)
....: a = continued_fraction(cf).value()
....: b = continued_fraction(cf+[1]).value()
Expand Down

0 comments on commit 1277457

Please sign in to comment.