For my project, I need to solve for a matrix X given matrices Y and K. (XY=K) The elements of each matrix must be integers modulo a random 256-bit prime. My first attempt at solving this problem used SymPy's mod_inv(n)
function. The problem with this is that I'm running out of memory with matrices of around size 30. My next thought was to perform matrix factorization, as that might be less heavy on memory. However, SymPy seems to contain no solver that can find matrices modulo a number. Any workarounds or self-made code I could use?
相关问题
- how to define constructor for Python's new Nam
- streaming md5sum of contents of a large remote tar
- How to get the background from multiple images by
- Extract matrix elements using a vector of column i
- Evil ctypes hack in python
sympy
'sMatrix
class supports modular inverses. Here's an example modulo 5:The
rref
method for finding row-reduced echelon form supports a keywordiszerofunction
that indicates what entries within a matrix should be treated as zero. I believe the intended use is for numerical stability (treat small numbers as zero), but I have also used it for modular reduction.Here's an example modulo 5:
That's sort of correct, except that the matrix returned by
rref[0]
still has 5's in it and fractions. Deal with this by taking the mod and interpreting fractions as modular inverses: