ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Sat, 04 May 2013 17:48:05 +0200solving a set of equations involving both inequalities and equalitieshttps://ask.sagemath.org/question/10086/solving-a-set-of-equations-involving-both-inequalities-and-equalities/How to write a code in sage to find solutions of a set of equalities and inequalities in more than one variables.for example i want to find solutions for the equations $\sum_{1 \leq i \leq 3}x_i =10$ , x_1 < x_2 < x_3 . Fri, 03 May 2013 04:59:25 +0200https://ask.sagemath.org/question/10086/solving-a-set-of-equations-involving-both-inequalities-and-equalities/Comment by rickhg12hs for <p>How to write a code in sage to find solutions of a set of equalities and inequalities in more than one variables.for example i want to find solutions for the equations $\sum_{1 \leq i \leq 3}x_i =10$ , x_1 < x_2 < x_3 . </p>
https://ask.sagemath.org/question/10086/solving-a-set-of-equations-involving-both-inequalities-and-equalities/?comment=17769#post-id-17769Your commentary below seems to indicate that this question needs some serious clarification/correction.Sat, 04 May 2013 17:48:05 +0200https://ask.sagemath.org/question/10086/solving-a-set-of-equations-involving-both-inequalities-and-equalities/?comment=17769#post-id-17769Answer by Volker Braun for <p>How to write a code in sage to find solutions of a set of equalities and inequalities in more than one variables.for example i want to find solutions for the equations $\sum_{1 \leq i \leq 3}x_i =10$ , x_1 < x_2 < x_3 . </p>
https://ask.sagemath.org/question/10086/solving-a-set-of-equations-involving-both-inequalities-and-equalities/?answer=14879#post-id-14879Since everything is linear your solution set is a polyhedron. For simplicity, lets take it closed (use <= instead of <). Then:
sage: P = Polyhedron(eqns=[(-10,1,1,1)], ieqs=[(0,-1,1,0), (0,0,-1,1)])
sage: P.Hrepresentation()
(An equation (1, 1, 1) x - 10 == 0,
An inequality (-1, 1, 0) x + 0 >= 0,
An inequality (-1, -2, 0) x + 10 >= 0)
Edit: Lattice points with all variables being positive as well (which is probably what the question is about)
sage: P = Polyhedron(eqns=[(-10,1,1,1)], ieqs=[(0,-1,1,0), (0,0,-1,1), (0,1,0,0)])
sage: P.Hrepresentation()
(An equation (1, 1, 1) x - 10 == 0,
An inequality (-1, 1, 0) x + 0 >= 0,
An inequality (-1, -2, 0) x + 10 >= 0,
An inequality (1, 0, 0) x + 0 >= 0)
sage: P.integral_points()
((0, 0, 10),
(0, 1, 9),
(0, 2, 8),
(0, 3, 7),
(0, 4, 6),
(0, 5, 5),
(1, 1, 8),
(1, 2, 7),
(1, 3, 6),
(1, 4, 5),
(2, 2, 6),
(2, 3, 5),
(2, 4, 4),
(3, 3, 4))
Fri, 03 May 2013 12:46:19 +0200https://ask.sagemath.org/question/10086/solving-a-set-of-equations-involving-both-inequalities-and-equalities/?answer=14879#post-id-14879Comment by REKHA BISWAL for <p>Since everything is linear your solution set is a polyhedron. For simplicity, lets take it closed (use <= instead of <). Then:</p>
<pre><code>sage: P = Polyhedron(eqns=[(-10,1,1,1)], ieqs=[(0,-1,1,0), (0,0,-1,1)])
sage: P.Hrepresentation()
(An equation (1, 1, 1) x - 10 == 0,
An inequality (-1, 1, 0) x + 0 >= 0,
An inequality (-1, -2, 0) x + 10 >= 0)
</code></pre>
<p>Edit: Lattice points with all variables being positive as well (which is probably what the question is about)</p>
<pre><code>sage: P = Polyhedron(eqns=[(-10,1,1,1)], ieqs=[(0,-1,1,0), (0,0,-1,1), (0,1,0,0)])
sage: P.Hrepresentation()
(An equation (1, 1, 1) x - 10 == 0,
An inequality (-1, 1, 0) x + 0 >= 0,
An inequality (-1, -2, 0) x + 10 >= 0,
An inequality (1, 0, 0) x + 0 >= 0)
sage: P.integral_points()
((0, 0, 10),
(0, 1, 9),
(0, 2, 8),
(0, 3, 7),
(0, 4, 6),
(0, 5, 5),
(1, 1, 8),
(1, 2, 7),
(1, 3, 6),
(1, 4, 5),
(2, 2, 6),
(2, 3, 5),
(2, 4, 4),
(3, 3, 4))
</code></pre>
https://ask.sagemath.org/question/10086/solving-a-set-of-equations-involving-both-inequalities-and-equalities/?comment=17773#post-id-17773Is there any way to define polyhedron in terms of equations rather than points since the number of equations and number of variables might be too large in which case it would not be possible to write all equations in terms of tuples.?Sat, 04 May 2013 04:34:54 +0200https://ask.sagemath.org/question/10086/solving-a-set-of-equations-involving-both-inequalities-and-equalities/?comment=17773#post-id-17773Answer by rickhg12hs for <p>How to write a code in sage to find solutions of a set of equalities and inequalities in more than one variables.for example i want to find solutions for the equations $\sum_{1 \leq i \leq 3}x_i =10$ , x_1 < x_2 < x_3 . </p>
https://ask.sagemath.org/question/10086/solving-a-set-of-equations-involving-both-inequalities-and-equalities/?answer=14881#post-id-14881Using your example:
sage: var('x_1 x_2 x_3')
(x_1, x_2, x_3)
sage: solve([x_1+x_2+x_3==10, x_1 < x_2, x_2 < x_3], x_1, x_2, x_3)
[[x_1 == -x_2 - x_3 + 10, -1/2*x_3 + 5 < x_2, x_2 < x_3, (10/3) < x_3]]
Sat, 04 May 2013 05:15:56 +0200https://ask.sagemath.org/question/10086/solving-a-set-of-equations-involving-both-inequalities-and-equalities/?answer=14881#post-id-14881Comment by REKHA BISWAL for <p>Using your example:</p>
<pre><code>sage: var('x_1 x_2 x_3')
(x_1, x_2, x_3)
sage: solve([x_1+x_2+x_3==10, x_1 < x_2, x_2 < x_3], x_1, x_2, x_3)
[[x_1 == -x_2 - x_3 + 10, -1/2*x_3 + 5 < x_2, x_2 < x_3, (10/3) < x_3]]
</code></pre>
https://ask.sagemath.org/question/10086/solving-a-set-of-equations-involving-both-inequalities-and-equalities/?comment=17772#post-id-17772I want solutions in terms of tuples of integers not in terms of same equations in different form.Sat, 04 May 2013 05:28:41 +0200https://ask.sagemath.org/question/10086/solving-a-set-of-equations-involving-both-inequalities-and-equalities/?comment=17772#post-id-17772Comment by ppurka for <p>Using your example:</p>
<pre><code>sage: var('x_1 x_2 x_3')
(x_1, x_2, x_3)
sage: solve([x_1+x_2+x_3==10, x_1 < x_2, x_2 < x_3], x_1, x_2, x_3)
[[x_1 == -x_2 - x_3 + 10, -1/2*x_3 + 5 < x_2, x_2 < x_3, (10/3) < x_3]]
</code></pre>
https://ask.sagemath.org/question/10086/solving-a-set-of-equations-involving-both-inequalities-and-equalities/?comment=17771#post-id-17771You didn't mention in your original question that you want integer solutions (and probably only positive integer solutions). In general, the solution given by solve is not "in terms of the same equations". It is giving you general solutions where the solutions for x1 and x2 depend on the value x3 takes.
For *positive* integer solutions what you really want is partitions of 10. Then use the [Partitions class](http://www.sagemath.org/doc/reference/combinat/sage/combinat/partition.html) in Sage. After you get the solutions, eliminate those solutions that have repeated values in them. Alternatively, use the arguments in the `Partitions` command itself to impose such strict monotonicity properties.Sat, 04 May 2013 06:02:59 +0200https://ask.sagemath.org/question/10086/solving-a-set-of-equations-involving-both-inequalities-and-equalities/?comment=17771#post-id-17771Comment by REKHA BISWAL for <p>Using your example:</p>
<pre><code>sage: var('x_1 x_2 x_3')
(x_1, x_2, x_3)
sage: solve([x_1+x_2+x_3==10, x_1 < x_2, x_2 < x_3], x_1, x_2, x_3)
[[x_1 == -x_2 - x_3 + 10, -1/2*x_3 + 5 < x_2, x_2 < x_3, (10/3) < x_3]]
</code></pre>
https://ask.sagemath.org/question/10086/solving-a-set-of-equations-involving-both-inequalities-and-equalities/?comment=17770#post-id-17770sorry for the inconvenience.Actually i want to find all the lattice points of the polytope given by 20 equations.since i can not write all those 20 equations,hence i wanted to know if there is any code with which i can write equations in stead of tuples.Sat, 04 May 2013 07:17:57 +0200https://ask.sagemath.org/question/10086/solving-a-set-of-equations-involving-both-inequalities-and-equalities/?comment=17770#post-id-17770