Wolfram Function Repository
Instant-use add-on functions for the Wolfram Language
Function Repository Resource:
Find a small solution to a system of linear equations over the integers
ResourceFunction["SmallIntegerLinearSolve"][mat,rhs] finds a small solution for x to the system of integer linear equations mat.x=rhs. |
Solve a linear system with integer values:
| In[1]:= |
| Out[1]= |
Set up a random system over the integers:
| In[2]:= | ![]() |
Find a small integer solution:
| In[3]:= |
| Out[3]= |
Compare to the parametrized result from Solve for the corresponding system of explicit linear equations:
| In[4]:= |
| Out[4]= | ![]() |
Verify that the result of SmallIntegerLinearSolve is in the parametrized solution set:
| In[5]:= | ![]() |
| Out[5]= |
Set up and solve a random system over the integers:
| In[6]:= | ![]() |
| Out[6]= | ![]() |
Compare to the parametrized result from Solve for the corresponding system of explicit linear equations:
| In[7]:= | ![]() |
| Out[124]= | ![]() |
Verify that the small solution is in the parametrized solution set:
| In[125]:= | ![]() |
| Out[125]= |
Though it is far slower than SmallIntegerLinearSolve, one can find a minimal solution in terms of the 1-norm (sum of absolute values):
| In[126]:= | ![]() |
| Out[126]= | ![]() |
This new solution is indeed smaller in 1-norm than the small solution:
| In[127]:= |
| Out[127]= |
However, the small solution happens to be the smaller in Euclidean norm:
| In[128]:= |
| Out[128]= |
A system need not have an integer-valued solution:
| In[129]:= |
| Out[129]= |
This work is licensed under a Creative Commons Attribution 4.0 International License