Skip to content
/ modint Public

Routines for calculating the Chinese Remainder

License

Notifications You must be signed in to change notification settings

shlomif/modint

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

46 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ModInt

Documentation Status Updates

Python implementation of the Chinese Remainder algorithm

Features

A usable implementation of the Chinese Remainder algorithm (see https://en.wikipedia.org/wiki/Chinese_remainder_theorem ) under the permissive MIT/Expat licence. Written because none other similarly-licensed ones could be found.

What this does is given two-or-more pairwise coprime bases integers and their corresponding moduli, it finds an integer that yields these moduli for all the bases.

Example

Here is an example:

from modint import ChineseRemainderConstructor, chinese_remainder

cr = ChineseRemainderConstructor([2, 5])
# Because 5 % 2 == 1 and 5 % 5 == 0
assert cr.rem([1, 0]) == 5
# Because 8 % 2 == 0 and 8 % 5 == 3
assert cr.rem([0, 3]) == 8

# Convenience function
assert chinese_remainder([2, 3, 7], [1, 2, 3]) == 17

Credits

This package was created with Cookiecutter and the audreyr/cookiecutter-pypackage project template.

About

Routines for calculating the Chinese Remainder

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published