ASKSAGE: Sage Q&A Forum - Individual question feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Sat, 08 Oct 2011 15:12:20 -0500Finding integer solutions to systems of polynomial equationshttps://ask.sagemath.org/question/8360/finding-integer-solutions-to-systems-of-polynomial-equations/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 intgers. 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?Fri, 07 Oct 2011 05:52:03 -0500https://ask.sagemath.org/question/8360/finding-integer-solutions-to-systems-of-polynomial-equations/Answer by kcrisman for <p>Hi,</p>
<p>I am trying to do something very simple but have been struggling.</p>
<p>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<em>A+b</em>B,
where I want to assume that a and b are intgers. 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.</p>
<p>I have tried something like this-</p>
<p>R.< A,B > = ZZ[]</p>
<p>f = A+B</p>
<p>var('a', domain = ZZ)</p>
<p>var('b', domain = ZZ)</p>
<p>g = a<em>A+b</em>B</p>
<p>solve(f-g==0,a,b),</p>
<p>but what it gives me is [a == -((b-1)*B-A)/A, [1]].</p>
<p>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?</p>
https://ask.sagemath.org/question/8360/finding-integer-solutions-to-systems-of-polynomial-equations/?answer=12725#post-id-12725This 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.Fri, 07 Oct 2011 06:36:59 -0500https://ask.sagemath.org/question/8360/finding-integer-solutions-to-systems-of-polynomial-equations/?answer=12725#post-id-12725Comment by Nathan for <p>This isn't an answer, but one thing that could be useful in general with integers is to do </p>
<pre><code>assume(A,'integer')
</code></pre>
<p>But <code>solve</code> 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). </p>
<p>I am not really sure how the <code>domain</code> parameter influences things.</p>
https://ask.sagemath.org/question/8360/finding-integer-solutions-to-systems-of-polynomial-equations/?comment=21167#post-id-21167I 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.Fri, 07 Oct 2011 08:51:56 -0500https://ask.sagemath.org/question/8360/finding-integer-solutions-to-systems-of-polynomial-equations/?comment=21167#post-id-21167Comment by kcrisman for <p>This isn't an answer, but one thing that could be useful in general with integers is to do </p>
<pre><code>assume(A,'integer')
</code></pre>
<p>But <code>solve</code> 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). </p>
<p>I am not really sure how the <code>domain</code> parameter influences things.</p>
https://ask.sagemath.org/question/8360/finding-integer-solutions-to-systems-of-polynomial-equations/?comment=21166#post-id-21166Right, 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...Sat, 08 Oct 2011 15:12:20 -0500https://ask.sagemath.org/question/8360/finding-integer-solutions-to-systems-of-polynomial-equations/?comment=21166#post-id-21166