Repository navigation
a = b (mod n) is a congruence: a relation between integers with the modulus written once at the end, decided for numbers and for a polynomial difference the modulus divides - #1419
Merged
Conversation
…odulus written once at the end, decided for numbers and for a polynomial difference the modulus divides Item 1 of the #1409 docket, and the redesign the book's notation remark asks for: "in mathematics, mod is a relation, not an operator or function". The remainder operator `a mod n` stays what it is, a number; the relation is a new node, Congruentf(Left, Right, Modulus), meaning `n divides a - b`. Read as `a = b (mod n)` and as `a ≡ b (mod n)`, the modulus once at the end of the line and applying to every link of a chain, which is the conjunction of its links; printed in the ASCII spelling, since Stringize prints `implies` rather than the arrow and the Unicode output is #1242's flag; in LaTeX `a \equiv b \pmod{n}`; in SymPy `Eq(Mod(a - b, n), 0)`. `(mod n)` after an order comparison, or `≡` without a modulus, is a parse error, and a bracket that opens on `mod` is a modulus rather than an implicit product. Decided where `n | a - b` is: outright for integers (5^6 = 1 (mod 7), -1 = 9 (mod 10); modulo 0 is equality, the modulus's sign is immaterial), NaN off the integers, and for symbols where the difference is a polynomial every term of which the modulus divides -- (n - a)^2 = a^2 (mod n) and the freshman's dream (x + y)^p = x^p + y^p (mod p) at a prime are True, while (x + y)^4 = x^4 + y^4 (mod 4) stays, since 6 x^2 y^2 is a multiple of 4 for some x, y and not others. Part of #1409. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura
This was referenced Sep 18, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Item 1 of the #1409 docket, and the redesign the book's notation remark asks for — "in mathematics, mod is a relation, not an operator or function". The remainder operator
a mod nstays what it is, a number; the relation is a new node,Congruentf(Left, Right, Modulus), meaningn divides a - b.Spelling (per the thread, and #1242): read as
a = b (mod n)and asa ≡ b (mod n)— the modulus once at the end of the line, applying to every link of a chain, which is the conjunction of its links; printed in the ASCII spelling, asStringizeprintsimpliesrather than the arrow; LaTeXa \equiv b \pmod{n}; SymPyEq(Mod(a - b, n), 0).(mod n)after an order comparison, or≡without a modulus, is a parse error. One exception to implicit multiplication: a bracket that opens onmodis a modulus, sob (mod n)is notb * (mod n).Decided where
n | a - bis:5^6 = 1 (mod 7)→True(Example 6.5.12),-1 = 9 (mod 10)→True,37457 = 38201 (mod 10)→False,2^1 = 2^4 (mod 3)→False(Problem 6.7.11's spoof: exponents are not reduced); modulo0is equality; the modulus's sign is immaterial, as inn divides a - b;NaNoff the integers (1/2 = 1 (mod 3),i = 1 (mod 3)), likedivides;(n - a)^2 = a^2 (mod n)→True(§6.5.5 Try 2:n² − 2an),(x + y)^p = x^p + y^p (mod p)→Trueforp = 2, 3, 5, 7(Problem 6.7.22),a + n = a (mod n),a n = 0 (mod n)— while(x + y)^4 = x^4 + y^4 (mod 4)stays as written, since6x²y²is a multiple of 4 for somex, yand not others (the test pins bothx = y = 1→Falseandx = y = 2→True).Not in this PR: solving
a x = b (mod n), inverses, CRT — item 3 of the docket, which sits on this node.Tests:
CongruenceTest— the chapter-6 rows above, chains, printing round trip in both spellings, LaTeX, SymPy, the entry points (MathS.NumberTheory.Congruent,Entity.CongruentTo), the operator untouched, the four parse errors. The reflective node lists (EveryNodeSurvivesEveryPipelineTest,EntitySerializationTest,StringizeRoundTrip) pick the node up on their own;PublicApi.txt+23;Syntax.mdhas a paragraph; BREAKING-CHANGES.md rows measured on a v2.5.0 build (every spelling was a parse error). Full suite green locally.Part of #1409.
🤖 Generated with Claude Code
https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura