Weaker wording for infinite continued fraction?

61 views
Skip to first unread message

Georgi Guninski

unread,
Aug 11, 2025, 3:52:11 AMAug 11
to sage-...@googlegroups.com
I believe real constant $C$ is irrational iff its continued fraction
is infinite.
There are many famous constants which irrationality is unknown.
For a lot of constants sage gives exception:
```
sage: cf=list(continued_fraction(catalan))
ValueError: the length is infinite!
```

Should the error use weaker wording?

Another test is coercing to QQ and there the wording is better:
```
sage: QQ(catalan)
TypeError: unable to convert catalan to a rational

Georgi Guninski

unread,
Aug 11, 2025, 4:22:22 AMAug 11
to sage-...@googlegroups.com
```
sage: cf=list(continued_fraction(catalan))
ValueError: the length is infinite!
```
To clarify: it is an open problem if catalan is irrational and the
error gives definite answer.

Nils Bruin

unread,
Aug 11, 2025, 4:31:49 PMAug 11
to sage-devel
Locally, the routine performs consistently with its documentation:

Init signature: sage.rings.continued_fraction.ContinuedFraction_real(x)
Docstring:    
Continued fraction of a real (exact) number.

This class simply wraps a real number into an attribute (that can be
accessed through the method "value()"). The number is assumed to be
irrational.

A fully rigorous verson would require a proof of irrationality of x as part of the input; probably.

The value error from `list` is specific to the type, so its terminology could be toned down, but worse things happen if the constructor gets called with a rational argument:

sage: sage.rings.continued_fraction.ContinuedFraction_real(355/113)
[3; 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ...]

compare with:

sage: continued_fraction(355/113)
[3; 7, 16]

Concerning:

sage: QQ(catalan)
TypeError: unable to convert catalan to a rational

that's entirely reasonable, since sage doesn't know catalan to be rational and hence cannot do the conversion. No claim about the rationality of catalan is made.

Georgi Guninski

unread,
Aug 16, 2025, 1:55:50 AMAug 16
to sage-...@googlegroups.com
>Init signature: sage.rings.continued_fraction.ContinuedFraction_real(x)
>Docstring:
> Continued fraction of a real (exact) number.

I am not using this constructor, using the constructor of
`continued_fraction` whose documentation doesn't assume irrational
number. Check the testcases and the differences for trivially
rational values.
Reply all
Reply to author
Forward
0 new messages