# 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 .

edit retag close merge delete

Your commentary below seems to indicate that this question needs some serious clarification/correction.

( 2013-05-04 17:48:05 +0200 )edit

Sort by » oldest newest most voted

Since 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))

more

Is 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.?

( 2013-05-04 04:34:54 +0200 )edit

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]]

more

I want solutions in terms of tuples of integers not in terms of same equations in different form.

( 2013-05-04 05:28:41 +0200 )edit
1

You 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.

( 2013-05-04 06:02:59 +0200 )edit

sorry 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.

( 2013-05-04 07:17:57 +0200 )edit