Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inconsistency in polynomial .reverse(n) #15077

Closed
defeo opened this issue Aug 22, 2013 · 12 comments
Closed

Inconsistency in polynomial .reverse(n) #15077

defeo opened this issue Aug 22, 2013 · 12 comments

Comments

@defeo
Copy link
Member

defeo commented Aug 22, 2013

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)
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

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.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.

CC: @mezzarobba @jhpalmieri

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

@defeo defeo added this to the sage-6.1 milestone Aug 22, 2013
@sagetrac-vbraun-spam sagetrac-vbraun-spam mannequin modified the milestones: sage-6.1, sage-6.2 Jan 30, 2014
@sagetrac-vbraun-spam sagetrac-vbraun-spam mannequin modified the milestones: sage-6.2, sage-6.3 May 6, 2014
@sagetrac-vbraun-spam sagetrac-vbraun-spam mannequin modified the milestones: sage-6.3, sage-6.4 Aug 10, 2014
@sagetrac-jakobkroeker
Copy link
Mannequin

sagetrac-jakobkroeker mannequin commented Jul 9, 2016

Stopgaps: inconsistentAnswer

@fchapoton
Copy link
Contributor

comment:6

This is obsolete. QQ['x'] now works as the other cases.

@fchapoton fchapoton removed this from the sage-6.4 milestone May 17, 2019
@jhpalmieri
Copy link
Member

comment:7

There remain two issues: unifying the documentation, and also the version for RR does not allow for an optional argument. Low priority, but I say we keep this open.

@jhpalmieri
Copy link
Member

Changed stopgaps from inconsistentAnswer to none

@bgrenet
Copy link
Contributor

bgrenet commented Aug 22, 2019

comment:8

There remained actually more issues. The issue for QQ['x'] was indeed fixed by ticket #21194 but that ticket only fixed some of the inconsistencies. Those that I have noticed and fix are:

  • No degree parameter for polynomials over RR (as already mentioned);
  • No degree parameter for polynomials over Zmod(...) using NTL;
  • Several inconsistencies in the documentation (polynomials over ZZ and Zmod(...) using Flint, polynomials over p-adics).

I hope I didn't forgot anything!

@bgrenet
Copy link
Contributor

bgrenet commented Aug 22, 2019

Author: Bruno Grenet

@bgrenet
Copy link
Contributor

bgrenet commented Aug 22, 2019

Branch: u/bruno/15077_reverse_consistency

@bgrenet bgrenet added this to the sage-8.9 milestone Aug 22, 2019
@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Aug 22, 2019

Branch pushed to git repo; I updated commit sha1. New commits:

64c41ef15077: reverse for real polynomial with optional parameter
1fc2a6e15077: Update docstring+tests for Flint (integer & zmod)
7fec02415077: Make reverse consistent for NTL rings
bd32a8415077: Make reverse for poly over padics consistent with other implementations

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Aug 22, 2019

Commit: bd32a84

@fchapoton
Copy link
Contributor

comment:10

ok, let it be

@fchapoton
Copy link
Contributor

Reviewer: Frédéric Chapoton

@vbraun
Copy link
Member

vbraun commented Nov 16, 2019

Changed branch from u/bruno/15077_reverse_consistency to bd32a84

@vbraun vbraun closed this as completed in 381ddac Nov 16, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants