Processing math: 100%

First time here? Check out the FAQ!

Ask Your Question
1

Finding integer solutions to systems of polynomial equations

asked 13 years ago

Nathan gravatar image

updated 0 years ago

vdelecroix gravatar image

Hi,

I am trying to do something very simple but have been struggling.

Here is a simplified example that I can't get to work. I want to define polynomials with integer coefficients, say

f(A,B) = A+B, 
g(A,B) = a*A+b*B

where I want to assume that a and b are integers. I want the solver to give me the values of a and b so that f-g is equal to zero as a polynomial in A and B. So, I want it to give me a== 1, b== 1.

I have tried something like this-

R.< A,B > = ZZ[]
f = A+B
var('a', domain = ZZ)
var('b', domain = ZZ)
g = a*A+b*B
solve(f-g==0,a,b),

but what it gives me is [a == -((b-1)*B-A)/A, [1]].

How do I define variables a and b which are integers, but unknown integers? No matter what I seem to do, they are put in Symbolic Ring. How do I get the solve command to give me integer solutions to a set of linear equations?

Preview: (hide)

Comments

There may be infinitely many solutions to your equation. What kind of answer do you expect in that case?

Max Alekseyev gravatar imageMax Alekseyev ( 0 years ago )

2 Answers

Sort by » oldest newest most voted
1

answered 0 years ago

Emmanuel Charpentier gravatar image

updated 0 years ago

Not a full answer, but it seems that Sympy can find your special solution :

sage:  import sympy
sage: a, b = sympy.symbols("a, b", integer=True)
sage: A, B = sympy.symbols("A, B")
sage: f=A+B
sage: g=a*A+b*B
sage: sympy.solve(f-g, (a, b))
{a: 1, b: 1}

Now, your problem may have more solutions than that. Start with Maxima's solution (after a change of notations) :

sage: var("x, y, X, Y")
(x, y, X, Y)
sage: Sol=(X+Y-(x*X+y*Y)==0).solve((x, y)) ; Sol
[[x == -(Y*(r5 - 1) - X)/X, y == r5]]

A bit of algebraic mangling gives us :

sage: (Sol[0][0].subs(Sol[0][1].rhs()==Sol[0][1].lhs()).expand().collect_common_factors()-1).factor()
x - 1 == -Y*(y - 1)/X

which tells us that for any (integer) y, (x,y) is a solution iif Y(1y)X is integer. This is possible iif XY is rational.

I believe that this describes the whole set of solutions, but I'd be glad to be demonstrated wrong.

Numerical example :

sage: (S:=(X+Y-(x*X+y*Y)==0).subs({X:5*sqrt(3), Y:3*sqrt(3)}).solve((x, y)))[0][0].subs(S[0][1].rhs()==S[0][1].lhs())
x == -3/5*y + 8/5

which shows that the non-trivial solutions are of the form (3k5,k),kZ;

HTH,

Preview: (hide)
link
0

answered 13 years ago

kcrisman gravatar image

This isn't an answer, but one thing that could be useful in general with integers is to do

assume(A,'integer')

But solve in general is via Maxima, which will assume you are using "normal" real or complex variables, and this doesn't help (because Maxima explicitly avoids your assumptions in solving, because it is assumed you are using dummy variables in solve commands).

I am not really sure how the domain parameter influences things.

Preview: (hide)
link

Comments

I have tried using assume(a,'integer) but a still seems to be in the Symbolic Ring. It still gives me an answer for a which is often not an integer for different values of A and B.

Nathan gravatar imageNathan ( 13 years ago )

Right, which is why this wasn't an answer, but just some related information you might find useful. 'a' will always be in the symbolic ring unless you change it to a polynomial ring. You would probably have to use integer programming techniques of some kind...

kcrisman gravatar imagekcrisman ( 13 years ago )

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 13 years ago

Seen: 5,190 times

Last updated: Jul 08 '24