Is there a way to do linear algebra and matrix manipulation in a finite field in Python? I need to be able to find the null space of a non-square matrix in the finite field F2. I currently can't find a way to do this. I have tried the galois package, but it does not support the scipy null space function. It is easy to compute the null space in sympy, however I do not know how to work in a finite field in sympy.
Python linear algebra in a finite field
1.9k Views Asked by fran At
2
There are 2 best solutions below
0
Bob
On
That's how I would approach as well.
Null space for floating point numbers is usually implemented using SVD or some other robust algorithm, for your GF(2) field it you can simply use a gaussian elimination, since there is no rounding.
Here goes an example
import numpy as np
import galois
# Initialize GF(2) and a random matrix to serve as an example
M,N = 7, 4
GF2 = galois.GF(2)
A = GF2.Random((M, N))
# B is an augmented matrix [A | I]
B = GF2.Zeros((M, M+N));
B[:, :N] = A
for i in range(M):
B[i, N+i] = 1;
for i in range(M):
B[i, N+i] = 1;
# Run gaussian elimination
k = 0;
for j in range(N):
i = j;
for i in range(k, M):
if B[i,j] != 0:
if i != j:
B[[i,k],:] = B[[k,i],:]
break;
if B[k,j] == 0:
continue;
for i in range(j+1, M):
if B[i,j]:
B[i,j:] += B[k,j:];
k += 1;
C = B[k:, N:]
# C should be the left null space of A
C @ A # should be zero
Related Questions in PYTHON
- How to store a date/time in sqlite (or something similar to a date)
- Instagrapi recently showing HTTPError and UnknownError
- How to Retrieve Data from an MySQL Database and Display it in a GUI?
- How to create a regular expression to partition a string that terminates in either ": 45" or ",", without the ": "
- Python Geopandas unable to convert latitude longitude to points
- Influence of Unused FFN on Model Accuracy in PyTorch
- Seeking Python Libraries for Removing Extraneous Characters and Spaces in Text
- Writes to child subprocess.Popen.stdin don't work from within process group?
- Conda has two different python binarys (python and python3) with the same version for a single environment. Why?
- Problem with add new attribute in table with BOTO3 on python
- Can't install packages in python conda environment
- Setting diagonal of a matrix to zero
- List of numbers converted to list of strings to iterate over it. But receiving TypeError messages
- Basic Python Question: Shortening If Statements
- Python and regex, can't understand why some words are left out of the match
Related Questions in PYTHON-3.X
- SQLAlchemy 2 Can't add additional column when specifying __table__
- Writes to child subprocess.Popen.stdin don't work from within process group?
- Platform Generation for a Sky Hop clone
- What's the best way to breakup a large test in pytest
- chess endgame engine in Python doesn't work perfectly
- Function to create matrix of zeros and ones, with a certain density of ones
- how to create a polars dataframe giving the colum-names from a list
- Django socketio process
- How to decode audio stream using tornado websocket?
- Getting website metadata (Excel VBA/Python)
- How to get text and other elements to display over the Video in Tkinter?
- Tkinter App - My Toplevel window is not appearing. App is stuck in mainloop
- Can I use local resources for mp4 playback?
- How to pass the value of a function of one class to a function of another with the @property decorator
- Python ModuleNotFoundError for command line tools built with setup.py
Related Questions in MATRIX
- Setting diagonal of a matrix to zero
- CUDA matrix inversion
- Function to create matrix of zeros and ones, with a certain density of ones
- DirectX 9 With No SDK Installed - How To Translate a D3DMATRIX?
- Using the sympy module to compute the matrix multiplication involving symbols
- Rendering a visualisation of matrix using pygame
- I do not receive iOS push notifications from Element Matrix Notify
- Matrix reconstruction by SVD in tensorflow
- Why does the following code detect this matrix as a non-singular matrix?
- Bound for product of matrices
- iterating through raster bands to perform calculation
- How to make a heatmap and the matrix for it?
- MATLAB: Turn every element of complex matrix into another matrix
- Matrix calculated based on the previous value
- Matlab array of structure
Related Questions in LINEAR-ALGEBRA
- Bound for product of matrices
- How to get scaling from transformation matrix
- Mahalanobis distance computation in Python
- Iterative Matrix-Vector Product Eigensolvers in Python
- How to Implement Back Substitution for Solving Linear Systems in Python?
- How to get integer answers while solving a chemical equation using Numpy
- is numpy representation a column vector?
- what is the direct method of finding nth power value of matrix say A is 2x2 matrix with say 2 2 3 4 values...now i want [A] ^n
- Move the points in the graph linearly when a point is moved up/down and edge values should be fixed in Javascript
- chol(x,pivot=TRUE) does not have attribute pivot in R
- How to tell when calculating an Intercept Point between two moving objects, when it will never intercept?
- Why do I get back different eigenvectors that I put in?
- Trying to use scipy to solve system of linear equations but having trouble
- Extrinsic camera matrix if translation performs before rotation
- Ensure trivial solution is found to matrix equation
Related Questions in FINITE-FIELD
- Custom scalar type with Eigen : Inverting compiles for 4x4 matrices, but not for 5x5 matrices
- SVD of finite field matrix
- Which finite fields are generated automatically by Nemo (which uses flint)
- Galois Reed Solomon
- In python, how to find a primitive element of finite field?
- Is there no basic finite field calculation function on MATLAB?
- Is there a way to Forward Error Correct (FEC RS) an Alphabet of 36 chars?
- Solving a large system of linear equations over the finite field F2
- Julia: Adding a multivariate polynomial to a univariate polynomial
- Julia ERROR: 'Can't Promote to Common Type' for multivariate polynomials in Nemo Library
- Optimal frequency of modulo operation in finite field arithmetic implementation
- fast and efficient matrix multiplication in GF(2) field - python
- Is there an efficient algorithm to compute the Jacobsthal matrix or quadratic character in GF(q)?
- Is there any way to plot xy diagram of points of elliptic curve over finite field with huge number p defined by standard EC (p-192,p-256...)?
- Modelling finite field arithmetic mod p in Z3
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
Popular # Hahtags
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
I'm the author of the galois library you mentioned. As noted by other comments, this capability is easy to add, so I added it in galois#259. It is now available in v0.0.24 (released today 02/12/2022).
Here is the documentation for computing the null space
FieldArray.null_space()that you desire.Here's an example computing the row space and left null space.
Here's the column space and null space.