Repository navigation
Add the Modulus option to RowReduce, NullSpace, MatrixRank, Inverse and LinearSolve - #2010
Open
tombouctou wants to merge 2 commits into
Open
tombouctou wants to merge 2 commits into
tombouctou wants to merge 2 commits into
Conversation
…nd LinearSolve With Modulus -> p for a prime p, these compute over the integers mod p with plain Gaussian elimination on Python ints. Entries may be integers or rationals whose denominator is invertible mod p. Modulus -> 0 keeps ordinary arithmetic; a modulus that is not a prime, or a symbolic entry, leaves the expression unevaluated. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Strickland's LambdaAlgebra.m, run in WMA, shows that NullSpace with Modulus gives the vectors in decreasing order of their free column, so do the same. The random tests assigned x, m and p in the shared test session, which broke later tests that use x as a symbol; use Module. 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.
RowReduce,NullSpace,MatrixRank,InverseandLinearSolvedid not accept theModulusoption, so for exampleNullSpace[{{1, 1}, {1, 1}}, Modulus -> 2]stayed unevaluated. This adds it for a prime modulus, as described in the WMA docs ("If p is zero, ordinary arithmetic is used").What it does. With
Modulus -> pthe matrix entries are reduced modpand the computation is plain Gaussian elimination on Python ints (new modulemathics/eval/numbers/linalg_modular.py). Entries may be integers, or rationals whose denominator is invertible modp. Results are integers in0..p-1:Conventions:
RowReducegives the reduced row echelon form, as withoutModulus.NullSpacegives one vector per non-pivot column, with 1 in that column and 0 in the other non-pivot columns, in decreasing order of that column. That order is what WMA gives: running Strickland'sLambdaAlgebra.m(below) reproduces his WMA-computed homology bases exactly only with this order. The exactNullSpace(withoutModulus) currently lists them in increasing order; I left that alone here.LinearSolvesets the free variables to 0.Inverse::singandLinearSolve::nosolmessages.What it does not do. A modulus that is not a prime (WMA says the computation "may fail" then), a non-integer modulus, a symbolic entry, or a denominator divisible by
pleave the expression unevaluated.Modulus -> 0keeps the current code path.Tests. Doc examples, plus
test_linalg_modulusandtest_linalg_modulus_randomintest/builtin/numbers/test_linalg.py; the random test checks the defining properties (rank + nullity,m . ns == 0,m . x == b,m . Inverse[m] == 1mod p) on 60 random matrices. pytest and the doctests give the same results as on master; the only failures are environmental ones that also fail on master. mypy is clean.Motivation and a larger check: Strickland's
LambdaAlgebra.m(https://strickland1.org/toda/) computes the homology of the mod-2 lambda algebra with all five functions andModulus -> 2, and hisLambdaData.mstores the results computed in WMA. With this PR (and theTransposeandMapAtfixes in #2007 and #2008) Mathics3 reproduces exactly, in the same order, his homology, boundary and non-boundary bases and his canonical forms: 218 of the 296 tridegrees inLambdaData.m(4225 canonical forms), with no difference. The remaining 78 are too slow to finish under Mathics3 in reasonable time; the largest would take days. For comparison, under Wolfram Engine 15 the same script computes all 296 in under a minute and matchesLambdaData.mexactly.🤖 Generated with Claude Code