ModularInverse
The with , when is a unit mod .
✓ checked against that system · ! checked, with disagreements (hover a chip)Wolfram Language
ModularInverse!ModularInverse(a, m)the inverse of modulo , in SageMath
enumeratio_inverse_mod(a, m)SymPymod_inverse(a, m)Oscarinvmod(ZZ(a), ZZ(m))Juliainvmod(ZZ(a), ZZ(m))Rustmod_inverse(a, m)ModularInverse(z, m)over the Gaussian integersSageMath
enumeratio_inverse_mod(z, m)SymPymod_inverse(z, m)Oscarinvmod(ZZ(z), ZZ(m))Juliainvmod(ZZ(z), ZZ(m))Rustmod_inverse(z, m)Typed signatures
| Type | Package | Applies |
|---|---|---|
(integer, integer) -> integer | compute-engine | always |
(number, number) -> number | number-theoryreplaces compute-engine | always |
Details
- Exists exactly when is a unit; the call is otherwise left unevaluated.
- Read off the Bézout coefficient of ExtendedGCD.
- For Gaussian integers, Wolfram reduces the inverse into part by part for a positive rational-integer , and as Mod does otherwise.
Plot
Examples
24 more kept as data, checked against the oraclesProperties #
About
| Examples | 45 |
|---|---|
| Checked against | Wolfram Language 44 agree1 differSageMath 38 agree7 errorSymPy 18 agree4 differ23 errorOscar 15 agreeJulia 19 agree26 errorRust 19 agree2 differ1 error |
| Crosswalk | Wolfram LanguageSageMathSymPyOscarJuliaRust |
Implementation
mapped
oscarpackages/oracle/src/mappings.tsmapped
wolframpackages/oracle/src/mappings.tsWolfram's own ModularInverse (not PowerMod[a, -1, m]): PowerMod's negative-exponent path checks invertibility of a mod the NORM of a Gaussian m, not m itself, and wrongly declines some invertible cases ModularInverse gets right — e.g. ModularInverse(11 - 7i, 7 + 4i) = -1 + 2i, where PowerMod[11 - 7I, -1, 7 + 4I] errors because 11 - 7i shares a factor with N(7 + 4i) = 65.
mapped
sagepackages/oracle/src/mappings.tsmapped
sympypackages/oracle/src/mappings.tsSymPy's mod_inverse raises where no inverse exists, and for a negative modulus gives a result in (m, 0] as ours does. It reads a non-integer argument (a Gaussian integer) as an ordinary number rather than reducing it in the Gaussian integers.
mapped
juliapackages/oracle/src/mappings.tsmapped
rustpackages/oracle/src/mappings.ts See also: PowerMod, ExtendedGCD, PowerModList