Wolfram Function Repository
Instant-use add-on functions for the Wolfram Language
Function Repository Resource:
A memory efficient form of solving linear systems modulo 2
ResourceFunction["BitStringLinearSolve"][{n1,n2,…},rhs,ncols]] solves the linear system {n1,n2,…}.x=rhs where {n1,n2,…} is a list of integers corresponding to bit vectors of length ncols, and rhs is an explicit vector of zeros and ones. |
Solve a simple example for a bit vector:
In[1]:= |
Out[1]= |
Create a random matrix of bit vectors and a random right hand side:
In[2]:= |
Out[5]= |
Solve the corresponding linear system modulo 2:
In[6]:= |
Out[6]= |
Create a large array of bit strings to use as a matrix, along with a suitable right hand side vector:
In[7]:= |
BitStringLinearSolve is especially useful when working with matrices that might otherwise require excessive memory:
In[8]:= |
Out[8]= |
Here is the matrix from which the bit vectors were created:
In[9]:= |
Out[9]= |
We see that the prior result agrees with LinearSolve:
In[10]:= |
Out[10]= |
In[11]:= |
Out[11]= |
Similarly, create a matrix of explicit 0‐1 vectors corresponding to the large integers:
In[12]:= |
LinearSolve is substantially slower as compared to BitStringLinearSolve:
In[13]:= |
Out[13]= |
Check that the results are the same:
In[14]:= |
Out[14]= |
Wolfram Language 11.3 (March 2018) or above
This work is licensed under a Creative Commons Attribution 4.0 International License