Skip to content

ResidueClass ​

k mod nk \bmod n as a VALUE — an element of Z/nZ\mathbb{Z}/n\mathbb{Z} that arithmetic stays inside, after Sage's Mod(a, m). compute-engine's head, strict about moduli: IntegerMod is its Sage-flavoured sibling.

ResidueClass(k, n)the residue class of kk, normalised into [0,n)[0, n)
SageMathMod(k, n)
ResidueClass(u/v, n)a rational reads as u⋅v−1u \cdot v^{-1}, when vv is a unit mod nn
SageMathMod(u/v, n)
ResidueClass(ResidueClass(k, m), n)the same class read in Z/nZ\mathbb{Z}/n\mathbb{Z}, for n∣mn \mid m
SageMathMod(k, m)
Typed signatures
TypePackageApplies
(any, any) -> valuecompute-enginealways
(any, any) -> valueresiduesreplaces compute-enginealways

Domain: Modular arithmetic

Details
  • Mod answers an integer; ResidueClass IS the class, so +, ·, / and powers of it are computed in Z/nZ\mathbb{Z}/n\mathbb{Z} — a negative power inverts, and dividing by a non-unit leaves the call standing
  • A bare integer or rational next to a class is read in the same ring
  • Classes of different moduli never combine: the sum stays as written, so x+y−y=xx + y - y = x holds. Sage's coercion to Z/gcd⁡(m,n)\mathbb{Z}/\gcd(m, n) is not followed; IntegerMod follows it
  • ChineseRemainder of classes is the class mod lcm⁡\operatorname{lcm} that reduces to each, and MultiplicativeOrder of a unit is its order
  • The elements of QuotientRing(Integers, n), Z/nZ\mathbb{Z}/n\mathbb{Z}
  • Written k‾n\overline{k}_{n}; a \pmod{n} is read as a class too, a \bmod n is still Mod, and a \equiv b \pmod{n} is still a congruence
  • A call that declines — dividing by a non-unit — stays unevaluated with a ResidueClass::ninv message, after Wolfram's PowerMod::ninv
  • IntegerMod, the head's old name, is now the Sage-flavoured sibling: the same arithmetic, with classes of different moduli combined in Z/gcd⁡(m,n)\mathbb{Z}/\gcd(m, n)

Examples

10 more kept as data, checked against the oracles
Basic #
live ↗
In10‾7\overline{10}_{7}Out3‾7\overline{3}_{7}

1/31/3 is the inverse of 3: 3⋅5=15≡13 \cdot 5 = 15 \equiv 1

live ↗
In13(mod7)\frac{1}{3}\pmod{7}Out5‾7\overline{5}_{7}

Fermat: 36≡1(mod7)3^6 \equiv 1 \pmod 7

live ↗
In(3‾7)6(\overline{3}_{7})^6Out1‾7\overline{1}_{7}
Scope #
live ↗
In13‾7\frac{1}{\overline{3}_{7}}Out5‾7\overline{5}_{7}
Applications #
live ↗
InChineseRemainder(2‾3,3‾5)\mathrm{ChineseRemainder}(\overline{2}_{3}, \overline{3}_{5})Out8‾15\overline{8}_{15}
live ↗
InMultiplicativeOrder(2‾7)\mathrm{MultiplicativeOrder}(\overline{2}_{7})Out33
Possible issues #

classes of different moduli do not combine: the sum stays as written

live ↗
In2‾4+(1‾6)\overline{2}_{4}+(\overline{1}_{6})Out2‾4+(1‾6)\overline{2}_{4}+(\overline{1}_{6})

2 is not a unit mod 4, and the message says so

live ↗
In12‾4\frac{1}{\overline{2}_{4}}Out12‾4\frac{1}{\overline{2}_{4}}

odd mod 4 and even mod 6 at once: no such class

live ↗
InChineseRemainder(1‾4,2‾6)\mathrm{ChineseRemainder}(\overline{1}_{4}, \overline{2}_{6})OutChineseRemainder(1‾4,2‾6)\mathrm{ChineseRemainder}(\overline{1}_{4}, \overline{2}_{6})
About
Examples19
CrosswalkSageMath

Implementation

mappedwolframpackages/oracle/src/mappings.ts

Wolfram's Mod/PowerMod answer a plain Integer, not a persistent ring element -- the same distinction this head's own details draw against our own Mod. FiniteField/FiniteFieldElement DOES keep a residue as a persistent value with +, ·, ^-1 (kernel-verified: FiniteField[7][3]+FiniteField[7][5] = FiniteFieldElement[.., {1}], FiniteField[7][3]^-1 = {5}, matching this head's own examples) -- but only for prime modulus; FiniteField[4] silently reinterprets 4 as GF(2^2), a different structure with no zero divisors, not the ring Z/4Z this head also supports (kernel-verified wrong for our composite-modulus examples), and FiniteField[6] errors outright. No single template is safe across this head's mixed prime/composite examples, so it stays unmapped for wolfram.

mappedsagepackages/oracle/src/mappings.ts

See also: IntegerMod, QuotientRing, Mod, ChineseRemainder, AdicNumeral