Skip to content

The initialization of fmpz_series and fmpq_series objects isn’t correct when another series is passed as the val. #304

@Jatinbhardwaj-093

Description

@Jatinbhardwaj-093

In the following routine:

def __init__(self, val=None, prec=None):
if prec is None:
self._prec = getcap()
else:
self._prec = prec
if self._prec < 0:
self._prec = -1
if val is not None:
if typecheck(val, fmpz_series):
fmpz_poly_set(self.val, (<fmpz_series>val).val)
self._prec = min((<fmpz_series>val)._prec, getcap())
elif typecheck(val, fmpz_poly):
fmpz_poly_set(self.val, (<fmpz_poly>val).val)
elif typecheck(val, list):
fmpz_poly_set_list(self.val, val)
else:
fmpz_poly_set_list(self.val, [val])
fmpz_poly_truncate(self.val, max(0, self._prec))

When setting the precision for a new series, the code currently compares the given series’s precision with the global cap. However, for correctness, it should compare it with self.prec (i.e., the already processed precision of the target object).

>>> from flint import fmpz_series
>>> x = fmpz_series([0,1], 5)
>>> fmpz_series(x, 4)
x + O(x^5)

It should be x + O(x^4) but instead, due to comparing with gcap (which is 10), the precision logic behaves incorrectly, producing an unintended result.


Originally identified by @oscarbenjamin
Original comment: sympy/sympy#28109 (comment)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions