# [Maxima] find integer

Andrej Vodopivec andrej.vodopivec at gmail.com
Wed Jan 11 03:31:29 CST 2012

```On Tue, Jan 10, 2012 at 6:00 PM, Raymond Toy <toy.raymond at gmail.com> wrote:
>
>
> On Sat, Jan 7, 2012 at 5:29 AM, Hans W. Hofmann <hawe at chefmail.de> wrote:
>>
>> Hi,
>>
>> I want to find values x to make
>>
>> [p1=-(4*x-300)/11,p2=-(35*x-1800)/44]
>>
>> p1 and p2 integer. How to do this in maxima?
>>
>
> Not sure if this is the best approach, but here is one way.
>
> solve(p1=(4*x-300)/11,x)
> solve(p2=(35*x-1800)/44,x);
>
> This gives two equations for x.  Make them equal so we get an equation in p1
> and p2, where p1 and p2 are integers.  This is a Diophantine equation.  A
> Google search shows that someone posted a Diophantine equation solver, but I
> can't find the code right now.  If I do it by hand, I get x = 44*r+64, where
> r is any integer.  This gives p1 = 16*r+4 and p2 = 35*r+10.
>
> Ray

There is a solve_lde function in the discrete package
(https://github.com/andrejv/discrete.mac):

(%i2) eliminate([p1=-(4*x-300)/11,p2=-(35*x-1800)/44], [x]);
(%o2) [-11*(-16*p2+35*p1-300)]
(%i3) solve_lde(%[1]);
(%o3) [p1=16*%k1-12,p2=35*%k1-45]
(%i4) subst(%, [p1=-(4*x-300)/11,p2=-(35*x-1800)/44]);
(%o4) [16*%k1-12=(300-4*x)/11,35*%k1-45=(1800-35*x)/44]
(%i5) solve(%[1], x);
(%o5) [x=108-44*%k1]

(of course %k1 is an integer)

Andrej
```