question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Return Poly.coeffs in the oder that were provided

See original GitHub issue

I think it would be useful to get the coefficients in the order that were provided to the constructor.

For example,

import galois
from galois import GF2

# 1 + x^4 + x^6
poly = galois.Poly([1, 0, 1, 0, 0, 0, 1], field=GF2, order="asc")
poly.coeffs

I would expect to respect the order="asc" and return

GF([1, 0, 1, 0, 0, 0, 1], order=2)

instead of

GF([1, 0, 0, 0, 1, 0, 1], order=2)

A bit offtopic, but why is descending order the default and preferred one (for __str__, Poly.string, etc.)? Would it make sense to use same order as numpy.polynomial.polynomial.Polynomial.coef, which is ascending?

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:12 (12 by maintainers)

github_iconTop GitHub Comments

1reaction
mhostettercommented, Nov 4, 2021

Hey. To be candid, the polynomial coefficient ordering was something I debated quite a bit. I settled on something and decided to wait for feedback from users.

I do think it’s a good idea to allow preservation of the coefficient ordering. Perhaps that could be accomplished by adding a Poly.order property that holds the order kwarg value used at construction, either "asc" or "desc". Then, Poly.coeffs would return the coefficients in Poly.order order.

Are you also suggesting that if the new property Poly.order = "asc" that str() and Poly.string should return the string representation of the polynomial with ascending degrees? For instance, Poly(1 + x^4 + x^6, GF(2)) and 1 + x^4 + x^6 when Poly.order = "asc"?

As to the default, again I debated that. I’m open to changing the default to ascending. I’ve seen that in other libraries ascending is common.

To be clear up a typo (I think) from your example… Since you specified order="asc", that polynomial is 1 + x^2 + x^6 not 1 + x^4 + x^6. Do you agree?

In [1]: import galois

In [2]: poly = galois.Poly([1, 0, 1, 0, 0, 0, 1], order="asc")

In [3]: poly
Out[3]: Poly(x^6 + x^2 + 1, GF(2))

# Currently, coefficients are always in descending order
In [4]: poly.coeffs
Out[4]: GF([1, 0, 0, 0, 1, 0, 1], order=2)
0reactions
iyanmvcommented, Jan 13, 2022

Yes, I think so. Thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Coefficients of polynomial - MATLAB coeffs - MathWorks
This MATLAB function returns coefficients of the polynomial p with respect to all variables determined in p by symvar.
Read more >
How to extract all coefficients in sympy - python - Stack Overflow
coeffs () returns a list containing all coefficients which has a value and ignores those whose coefficient is 0 whereas all_coeffs() returns all ......
Read more >
How to interpret coefficients from a polynomial model fit?
So we say help(poly) . The description says: Returns or evaluates orthogonal polynomials of degree 1 to degree over the specified set of...
Read more >
Polynomials Manipulation Module Reference
Construct polynomials from expressions. sympy.polys.polytools.degree(f, gen=0)[source]#. Return the degree of f in the given variable.
Read more >
galois.Poly — galois documentation - Read the Docs
galois.Poly¶ ; degrees. An array of the polynomial degrees in degree-descending order. ; field. The Galois field to which the coefficients belong. ;...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found