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

Add solver for linear Diophantine equations #159

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

xavierleroy
Copy link
Contributor

This PR adds Z.solve_linear_congruences , a solver for linear Diophantine equations of one variable:

    a₁·x` = b₁ mod m₁ /\ ... /\ aₙ·x = bₙ mod mₙ

This includes the Chinese remainder theorem as a special case (with aᵢ = 1).

I wrote this code several times in the past, once to implement RSA in Cryptokit, the other times for programming / mathematical puzzles such as the Euler project. The interface and implementation in this PR is taken from https://github.com/gmevel/euler-lib , which uses OCaml's plain int instead of arbitrary-precision integers.

Maybe this function is too specialized for a library such as Zarith. On the other hand, it's nontrivial code that nicely complements the existing number-theoretic functions of Zarith.

Solves linear Diophantine equations of one variable.
Generalization of the Chinese remainder theorem.
@xavierleroy xavierleroy changed the title Add for linear Diophantine equations Add solver for linear Diophantine equations Jan 16, 2025
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.

1 participant