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

error in factoring non-monic polynomial< gf_element > #4

Open
benediamond opened this issue Nov 11, 2018 · 0 comments
Open

error in factoring non-monic polynomial< gf_element > #4

benediamond opened this issue Nov 11, 2018 · 0 comments

Comments

@benediamond
Copy link
Contributor

benediamond commented Nov 11, 2018

There appears to be a bug when attempting to factor a non-monic polynomial< gf_element > f over a finite field F_q. indeed:

#include <LiDIA/galois_field.h>
#include <LiDIA/gf_polynomial.h>
#include <LiDIA/factorization.h>

int main(int argc, const char * argv[]) {
  galois_field F(61, 2);
  polynomial< gf_element > f = randomize(F, 5);
  std::cout << f << std::endl;
  factorization< gf_polynomial > f_fact;
  factor(f_fact, f);
  std::cout << "factored: " << f_fact << std::endl;
}

yields:

(12 * x+ 11) * y^5 + (34) * y^4 + (19 * x+ 27) * y^3 + (19 * x+ 56) * y^2 + (10 * x+ 8) * y + (37 * x+ 2)
libc++abi.dylib: terminating with uncaught exception of type LiDIA::generic_error: common_field::arguments are different fields
Abort trap: 6

However,

#include <LiDIA/galois_field.h>
#include <LiDIA/gf_polynomial.h>
#include <LiDIA/factorization.h>

int main(int argc, const char * argv[]) {
  galois_field F(61, 2);
  polynomial< gf_element > f = randomize(F, 5);
  divide(f, f, f.lead_coeff());
  std::cout << f << std::endl;
  factorization< gf_polynomial > f_fact;
  factor(f_fact, f);
  std::cout << "factored: " << f_fact << std::endl;
}

yields

y^5 + (59 * x+ 37) * y^4 + (15 * x+ 43) * y^3 + (29 * x+ 8) * y^2 + (2 * x+ 3) * y + (25 * x+ 58)
factored: [ [y+ (56 * x+ 13),1],[y^2 + (6 * x+ 36) * y + (43 * x+ 42),1],[y^2 + (58 * x+ 49) * y + (52 * x+ 3),1] ]

I narrowed down the offending function call to lines 493 and 239, respectively, in the following two snippets:
https://github.com/mkoeppe/LiDIA/blob/f10edd172f858b46caf8efb45c79a742cc2407f1/src/finite_fields/factorization/gf_polynomial/gf_berlekamp.cc#L491-L494
https://github.com/mkoeppe/LiDIA/blob/f10edd172f858b46caf8efb45c79a742cc2407f1/src/base/include/LiDIA/factorization.h#L237-L240
In this setting, ff and a wind up as the scalar quantity which originally appeared as f's leading coefficient. Not sure exactly what's going on, but this appears to be a bug. Please let me know if you can help clarify this, and then I can put together a pull request. Thanks for your work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant