ChineseRemainder
The smallest non-negative integer congruent to each ri modulo the corresponding mi.
✓ checked against that system · ! checked, with disagreements (hover a chip)Wikipedia
Chinese remainder theoremMathWorldChineseRemainderTheoremWikidataQ193878Encyclopedia of MathematicsChinese_remainder_theoremBritannicatopic/Chinese-remainder-theoremWolfram LanguageChineseRemainder✓Rosetta CodeChinese remainder theoremChineseRemainder([r1, r2, …], [m1, m2, …])smallest non-negative with for every .ChineseRemainder([r1, r2, …], [m1, m2, …], d)the smallest such with .ChineseRemainder(ResidueClass(r1, m1), ResidueClass(r2, m2), …)the ResidueClass class mod that reduces to eachSageMath
CRT_list(r1, m1)SymPycrt(m1, r1)[0]Typed signatures
| Type | Package | Applies |
|---|---|---|
(collection<any>, collection<any>) -> integer | compute-engine | always |
(value+) -> value | residuesreplaces compute-engine | always |
Details
- When the moduli are pairwise coprime, the result is unique modulo by the Chinese remainder theorem.
- A solution exists for non-coprime moduli only when the remainders agree on every shared factor; otherwise the system is inconsistent.
- An inconsistent system is left unevaluated, with a
ChineseRemainder::nsolmessage naming the two congruences that clash. - A third argument asks for the smallest solution instead, as Wolfram's does.
Examples
Scope #
over classes, the answer is a class — and reading ResidueNumerals([3, 5, 7]) digits back with FromDigits is the same computation
InOut
Properties #
Possible issues #
No solution exists when the remainders are inconsistent at , so the call stays unevaluated and says why
live ↗InOut
About
| Examples | 11 |
|---|---|
| Checked against | Wolfram Language 10 agreeSageMath 6 agree1 errorSymPy 7 agree1 error |
| Crosswalk | WikipediaMathWorldWikidataEncyclopedia of MathematicsBritannicaWolfram LanguageSageMathSymPyRosetta Code |
Implementation
mapped
sagepackages/oracle/src/mappings.tsmapped
sympypackages/oracle/src/mappings.tscrt answers None where no solution exists; the third argument, a least solution at or above a bound, is not mapped.
See also: Mod, ResidueClass, FromDigits