-
-
Notifications
You must be signed in to change notification settings - Fork 697
Description
The optional argument of the .reverse() method of univariate polynomials is interpreted inconsistently through different classes.
Rationals interpret is as "length":
sage: _.<x> = QQ[]
sage: (x+1).reverse(1)
1
sage: (x).reverse(1)
0The docstring for generic polynomials (inherited by CC, number fields, Polynomial_GF2X, Polynomial_ZZ_pEX, ...) says:
If an optional degree argument is given the coefficient list will
be truncated or zero padded as necessary and the reverse polynomial
will have the specified degree.
but the behaviour is inconsistent with it
sage: _.<x> = GF(2)[]
sage: (x+1).reverse(1)
x + 1
sage: (x).reverse(1)
1
sage: ['reverse' in cl.__dict__ for cl in inspect.getmro(x.__class__)]
[False, False, True, False, False, False, False, False, False, False]
sage: inspect.getmro(x.__class__)[2]
<type 'sage.rings.polynomial.polynomial_element.Polynomial'>Polynomial_zmod_flint and Polynomial_integer_dense_flint have the exact same docstring and behaviour, though they do not inherit .reverse() from the generic class:
sage: _.<x> = ZZ[]
sage: (x+1).reverse(1)
x + 1
sage: (x).reverse(1)
1
sage: ['reverse' in cl.__dict__ for cl in inspect.getmro(x.__class__)]
[True, True, False, False, False, False, False, False, False]
<type 'sage.rings.polynomial.polynomial_integer_dense_flint.Polynomial_integer_dense_flint'>Reals take no optional argument. The docstring says
Returns x!^d f(1/x) where d is the degree of f.
and the behaviour is consistent with it
sage: (x+1).reverse()
x + 1.00000000000000
sage: x.reverse()
1.00000000000000In my opinion the best behaviour is the one of the generic class, but the docstring should be amended to something similar to the last one, which is the proper mathematical definition. The behaviour of rationals should be corrected to conform to the other classes.
Component: commutative algebra
Keywords: polynomial univariate reverse
Author: Bruno Grenet
Branch/Commit: bd32a84
Reviewer: Frédéric Chapoton
Issue created by migration from https://trac.sagemath.org/ticket/15077