Python Forum

Full Version: Positive integral solutions for Linear Diophantine Equation
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello All,

Say I want to find all POSITIVE INTEGRAL solutions for a,b for this linear equation:
a + 2b = 5 and the solutions are:

a|5|3|1|
----------
b|0|1|2|


import sympy
a,b = symbols('a b', integer=True)
solve( a*1 + b*2 - 5, [a,b])
which gives me the following output:

[(5 - 2*b, b)]
How to go next to extract the possible numerical solutions as given in the table? is there any built-in function in sympy for that?
https://docs.sympy.org/latest/guides/sol...ight=solve

Look under "Use the solution result"
(Jan-12-2023, 10:26 PM)deanhystad Wrote: [ -> ]https://docs.sympy.org/latest/guides/sol...ight=solve

Look under "Use the solution result"

Thanks deanhystad,
Somehow I can't figure it out, can you help further?
Not really. I didn't really understand your question when I replied. Since then I realized my mistake and did some research trying to improve my response. I came up with nothing. Sorry.
The integer solutions of a n + b m = r are well known mathematically. I would start from the expression of their solutions.