Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NotImplementedError: Ax=B has unique solution in integers #7

Open
ikmMaierBTUCS opened this issue Feb 5, 2025 · 1 comment
Open

Comments

@ikmMaierBTUCS
Copy link

I regularly get this "error", e.g. when running "solve([[2,1],[3,1]],[12,13])".
I completely agree that there is a unique solution. But why does it give me an error instead of the solution? Am I misunderstanding what the function should be used for? Should I use a different function, when I just want to get an integer solution for a linear equation?

@ikmMaierBTUCS
Copy link
Author

I opted for the following solution now:

def intlinsolve(base,image):
try:
return solve(base,image)[0]
except NotImplementedError:
print('unique solution')
return [round(i) for i in np.dot(np.linalg.inv(np.array(base, dtype=np.float64)),image)]

Whenever the integer solution of base*x=image is unique, I let it be calculated as x=base^(-1)*image and round the coefficients of x to assure that they are ints.
I note though that theoretically there could be situations, where there is only one integer solution but several. In this case, np.linalg.inv() would fail, because base would not be invertible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant