Ask Your Question

Revision history [back]

Thanks for your report. The problem comes from the fact that you can not create quadratic field with very large D

sage: QuadraticField(4**1000+1)
Traceback (most recent call last):
...
ValueError: Cannot convert NaN or infinity to Pari float

I opened the ticket #23459 to track the issue.

Thanks for your report. The problem comes from the fact that you can not create quadratic field with very large D

sage: QuadraticField(4**1000+1)
Traceback (most recent call last):
...
ValueError: Cannot convert NaN or infinity to Pari float

I opened the ticket #23459 to track the issue.

EDIT: in the mean time you can use the following modification of value that I adapted from the .value() method of the continued fraction

def periodic_cf_value(cf):
    from sage.rings.continued_fraction import last_two_convergents

    if cf._x1 and cf._x1[0] < 0:
        return -(-cf).value()

    if cf._x2[0] is Infinity:
        return cf._rational_()

    # determine the equation for the purely periodic cont. frac. determined
    # by self._x2
    p0,q0,p1,q1 = last_two_convergents(cf._x2)

    # now x is one of the root of the equation
    #   q1 x^2 + (q0 - p1) x - p0 = 0
    D = (q0-p1)**2 + 4*q1*p0
    x = ((p1 - q0) + sqrt(D)) / (2*q1)

    # we add the preperiod
    p0,q0,p1,q1 = last_two_convergents(cf._x1)
    return (p1*x + p0) / (q1*x + q0)

With the above function you can do with your list l

sage: x = continued_fraction(l)
sage: v = periodic_cf_value(x)

However, the number obtained is a symbolic number not that easy to work with

sage: parent(v)
Symbolic Ring