id,summary,reporter,owner,description,type,status,priority,milestone,component,resolution,keywords,cc,merged,author,reviewer,upstream,work_issues,branch,commit,dependencies,stopgaps
15077,Inconsistency in polynomial .reverse(n),defeo,,"The optional argument of the `.reverse()` method of univariate polynomials is interpreted inconsistently through different classes.
Rationals interpret is as ""length"":
{{{#!python
sage: _. = QQ[]
sage: (x+1).reverse(1)
1
sage: (x).reverse(1)
0
}}}
The 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
{{{#!python
sage: _. = 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]
}}}
`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:
{{{#!python
sage: _. = 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]
}}}
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
{{{#!python
sage: (x+1).reverse()
x + 1.00000000000000
sage: x.reverse()
1.00000000000000
}}}
In 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.",defect,needs_review,minor,sage-duplicate/invalid/wontfix,commutative algebra,,polynomial univariate reverse,mmezzarobba jhpalmieri,,,,N/A,,,,,