Repository navigation
Add PolynomialMod for an integer modulus - #2005
Open
tombouctou wants to merge 1 commit into
Open
tombouctou wants to merge 1 commit into
tombouctou wants to merge 1 commit into
Conversation
PolynomialMod[poly, m] with a positive integer m expands poly and reduces each integer coefficient to 0..m-1. As in WMA, parts that are not polynomials, such as f[1] or Sin[x], are treated as variables, so PolynomialMod[3 f[1] + 2 f[2], 2] gives f[1]. Rational, Real and Complex coefficients, a polynomial modulus and lists are not handled yet; those cases stay unevaluated. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
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.
PolynomialModis not defined in Mathics3, so evenPolynomialMod[3 x ^ 2 + 2 x + 1, 2]stays unevaluated. This adds it for the common case of a positive integer modulus.What it does.
PolynomialMod[poly, m]with a positive integermexpandspoly(with the existingexpand_polynomial) and reduces each integer coefficient to0..m-1. As in WMA, parts that are not polynomials, such asf[1]orSin[x], are treated as variables:Code that works with formal sums mod 2 relies on this, e.g.
PolynomialMod[del /@ x, 2]where the terms are words likew[3, 1, 1].What it does not do yet. It leaves these unevaluated rather than guess at WMA's conventions:
poly.Tests. The doc examples above, plus
test_polynomialmodintest/builtin/numbers/test_algebra.py, which covers negative coefficients, terms that cancel to 0, non-polynomial parts, and each case left unevaluated. pytest and the doctests give the same results as on master. The only failures are environmental ones that also fail on master: XML/ZIP/JPEGFileFormat, and the CLI tests that needmathicson the PATH. mypy is clean on both changed modules.🤖 Generated with Claude Code