IntegerMod
as a VALUE, after Sage's Mod(k, n): ResidueClass whose classes of different moduli combine in .
IntegerMod(k, n)the class of , normalised into , as for ResidueClass(k, n)Mod(k, n)SymPyGF(n, symmetric=False)(k)IntegerMod(u/v, n)a rational reads as , when is a unit mod Mod(u/v, n)SymPyGF(n, symmetric=False)(u/v)Typed signatures
| Type | Package | Applies |
|---|---|---|
(any, any) -> residue | residues | always |
Details
- The Sage-flavoured sibling of ResidueClass, which is compute-engine's strict head and never combines classes of two moduli.
IntegerModis built on it: same normalisation, same ring arithmetic, andChineseRemainder,MultiplicativeOrderand membership in QuotientRing(Integers, n) read it as the class it is - Two classes meet in , the largest ring both reduce to, and the answer lives there: . This is Sage's coercion, and the divergence from compute-engine, which leaves that sum as written
- A bare integer next to a class is read in the class's ring, never the other way:
- Equality and
!=compare in the common ring too, soIntegerMod(2, 4) == IntegerMod(0, 2)isTrue - Moduli with have no ring but the trivial one, which Sage rejects; the call stays as written. A class mod 1 is the exception: it is 0 in the zero ring , which every ring reduces to, so it absorbs any class beside it. Sage does the same, though a sum of three still raises when a coprime pair comes before the mod 1 class; ours does not depend on order Dividing by a class that is not a unit in the common ring stays unevaluated too, with a
ResidueClass::ninvmessage - A
ResidueClassnext to anIntegerModnever combines: pick one head, as the two behaviours differ, and the sum stays as written - Mod and
IntegerModdiffer:Mod(17, 5)is the remainder , a plain number, whileIntegerMod(17, 5)is the class and keeps its modulus. Sage'sMod(a, m)builds a class, so it isIntegerMod(a, m)here, and compute-engine'sModfollows Wolfram's - Written and read as (and as
(a mod m)in TraditionalForm), fenced whole so sums and products of classes stay unambiguous.a \pmod{n}reads as ResidueClass anda \bmod nas Mod, so type this form or the call to get anIntegerMod
Examples
20 more kept as data, checked against the oraclesScope #
Possible issues #
the strict head leaves it unevaluated; IntegerMod combines the same classes in (see above)
About
| Examples | 35 |
|---|---|
| Checked against | SageMath 25 agree2 differ8 errorSymPy 19 agree8 differ4 unevaluated1 errorWolfram Language 1 agreempmath 1 agreeJulia 1 agreeRust 1 agree |
| Crosswalk | SageMathSymPy |
Implementation
wolframpackages/oracle/src/mappings.tsWolfram has no residue value that follows Sage's coercion: Mod/PowerMod answer a plain Integer, and FiniteField[n] keeps a residue as a persistent value but only for prime n (FiniteField[4] is GF(2^2), not Z/4Z), with no coercion between fields.
sagepackages/oracle/src/mappings.tssympypackages/oracle/src/mappings.tsSymPy's Mod is the plain remainder; the residue value is the element of GF(n), which for a composite n is Z/n. A class of one modulus does not combine with one of another, where Sage's coercion takes them to Z/gcd. Power and Divide over a residue skip their S() wrap (emit.ts), which would lift a class to its integer.
See also: ResidueClass, QuotientRing, Mod, ChineseRemainder