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

Linear system solver for GF2 #541

Closed
wants to merge 4 commits into from
Closed

Linear system solver for GF2 #541

wants to merge 4 commits into from

Conversation

Scurrra
Copy link

@Scurrra Scurrra commented Mar 9, 2024

I needed a solver for linear systems over GF2 for simple codes decoding, but the library only has a solver that just inverts the coefficient matrix A requiring matrix A be square. I found this solution in Julia and translated it. The solve function can be invoked using np.linalg.solve (i.e. galois.GF2._solve) and using galois.GF2._solve. As I modified the old function calling style I would say that it works (build succeeded), and it works well in may project.

Copy link

codecov bot commented Mar 9, 2024

Codecov Report

Attention: Patch coverage is 52.94118% with 24 lines in your changes are missing coverage. Please review.

Project coverage is 96.07%. Comparing base (25baec4) to head (cd1fc57).

❗ Current head cd1fc57 differs from pull request most recent head 288aff8. Consider uploading reports for the commit 288aff8 to get more accurate results

Files Patch % Lines
src/galois/_fields/_gf2.py 52.94% 24 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #541      +/-   ##
==========================================
- Coverage   96.44%   96.07%   -0.38%     
==========================================
  Files          46       46              
  Lines        5911     5962      +51     
==========================================
+ Hits         5701     5728      +27     
- Misses        210      234      +24     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@mhostetter
Copy link
Owner

Thanks for the pull request.

I needed a solver for linear systems over GF2 for simple codes decoding, but the library only has a solver that just inverts the coefficient matrix A requiring matrix A be square.

Are you trying to solve a over-determined system? Are there "bit errors" involved? Or are all equations consistent?

The solve function can be invoked using np.linalg.solve (i.e. galois.GF2._solve) and using galois.GF2._solve.

I don't like overloading np.linalg.solve(), since that should only operate on square matrices. np.linalg.lstsq(), however, is intended for over-determined systems. Perhaps this should hook into there.

@Scurrra
Copy link
Author

Scurrra commented Mar 12, 2024

Are you trying to solve a over-determined system?

Yes. I am decoding code words back into informational messages (I don't know proper terms in English, sorry).

I changed solve to lstsq for overloading, but saved galois.GF2.solve. Anyway, there is no such solver for other fields in the library.

I also want to add Galois rings (issue #280) to the library in another pr. I have already implemented it in Julia (SimplePolynomialRing.jl).

@mhostetter
Copy link
Owner

I changed solve to lstsq for overloading, but saved galois.GF2.solve. Anyway, there is no such solver for other fields in the library.

Which algorithm is implemented here? It's likely the algorithm should work in other fields. If so, I'd like to implement it so it can work in any field.

I also want to add Galois rings (issue #280) to the library in another pr. I have already implemented it in Julia (SimplePolynomialRing.jl).

Cool. But please work with me before starting work. There is significant architecture implications.

@Scurrra
Copy link
Author

Scurrra commented Mar 12, 2024

Which algorithm is implemented here? It's likely the algorithm should work in other fields. If so, I'd like to implement it so it can work in any field.

To be honest, I don't know the name of the algorithm (I contacted the author of that library and it's name were not mentioned). It seems that the algorithm is optimized for GF2.

Cool. But please work with me before starting work. There is significant architecture implications.

I figured it out, and definitely liked it. How can I contact you to get instructions?

@dimbleby
Copy link

dimbleby commented Apr 27, 2024

this feels like quite a lot of ceremony, for what is essentially just:

    puzzle = np.c_[A, b]
    reduced = puzzle.row_reduce()
    solution = reduced[:, -1]

@mhostetter
Copy link
Owner

@Scurrra I tend to agree with @dimbleby. I believe this is simply achieved using row reduction via Gaussian elimination, as he pointed out. I don't think there is a clean place to put this in the API. I'm closing for now. If you have other ideas of how to incorporate, feel free to reach out.

@mhostetter mhostetter closed this Jun 22, 2024
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

Successfully merging this pull request may close these issues.

3 participants