Skip to content

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
Rafael-SOWNet merged 1 commit into
masterfrom
congruence-statement
Sep 18, 2026
Merged

Rafael-SOWNet merged 1 commit into
masterfrom
congruence-statement

Conversation

@Rafael-SOWNet

Copy link
Copy Markdown
Member

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.

Spelling (per the thread, and #1242): read as a = b (mod n) and as a ≡ 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, as Stringize prints implies rather than the arrow; LaTeX a \equiv b \pmod{n}; SymPy Eq(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 on mod is a modulus, so b (mod n) is not b * (mod n).

Decided where n | a - b is:

  • integers outright: 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); modulo 0 is equality; the modulus's sign is immaterial, as in n divides a - b;
  • NaN off the integers (1/2 = 1 (mod 3), i = 1 (mod 3)), like divides;
  • symbols where the difference is a polynomial every term of which the modulus divides: (n - a)^2 = a^2 (mod n) → True (§6.5.5 Try 2: n² − 2an), (x + y)^p = x^p + y^p (mod p) → True for p = 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, since 6x²y² is a multiple of 4 for some x, y and not others (the test pins both x = y = 1 → False and x = 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.md has 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

…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant