# inequalities in sagemath

var('x y M a b c d A B C D t u v S T U V')
eq1 = 3*(((2*3367-3*y+1)/24)+3*x*(x+1)/2)+1-V == 0
eq2 = -3367+3*x*(x+1)/2-3*y*(y-1)/2+(3*x+1)*(3*x+2)/2 == 0
eq3 = 3*(((2*V-3*v+1)/24)+3*x*(x+1)/2)+1-U == 0
eq4 = V+3*v*(v-1)/2-12*x*(x+1)/2-1 == 0
eq5 = 3*(((2*U-3*u+1)/24)+3*x*(x+1)/2)+1-T == 0
eq6 = U+3*u*(u-1)/2-12*x*(x+1)/2-1 == 0
eq7 = 3*(((2*T-3*t+1)/24)+3*x*(x+1)/2)+1-S == 0
eq8 = T+3*t*(t-1)/2-12*x*(x+1)/2-1 == 0
eq9 = 3*(((2*S-3*1+1)/24)+3*x*(x+1)/2)+1-S == 0

eq18 = -M+9*((2*3367 - 3*y + 1)/24+(y-1)*(y+1)/8)+1 == 0
eq19 = 3*((2*M - 3*(x+1) + 1)/24 + (3*x*(x + 1))/2) + 1 - A == 0
eq20 = -M + (3*x*(x + 1))/2 - (3*x*(x + 1))/2 + ((3*x + 1)*(3*x + 2))/2 == 0
eq21 = 3*((2*A - 3*a + 1)/24 + (3*x*(x + 1))/2) + 1 - B == 0
eq22 = A + (3*a*(a - 1))/2 - (12*x*(x + 1))/2 - 1 == 0
eq23 = 3*((2*B - 3*b + 1)/24 + (3*x*(x + 1))/2) + 1 - C == 0
eq24 = B + (3*b*(b - 1))/2 - (12*x*(x + 1))/2 - 1 == 0
eq25 = 3*((2*C - 3*c + 1)/24 + (3*x*(x + 1))/2) + 1 - D == 0
eq26 = C + (3*c*(c - 1))/2 - (12*x*(x + 1))/2 - 1 == 0
eq26 = 3*((2*D - 3*d + 1)/24 + (3*x*(x + 1))/2) + 1 - S == 0
eq27 = D + (3*d*(d - 1))/2 - (12*x*(x + 1))/2 - 1 == 0
eq28 = 3*((2*S - 3*1 + 1)/24 + (3*x*(x + 1))/2) + 1 - S == 0
eq29 = x-24 == 0

assume(x-1 >= 0 , y-1 >= 0 , A-M > 0 , B-A > 0 , C-B > 0 , D-C > 0 , S-D >0 , V-3367 > 0 , U-V > 0 , T-U > 0 , S-T > 0)

solutions = solve([eq1,eq2,eq3,eq4,eq5,eq6,eq7,eq8,eq9,eq18,eq19,eq20,eq21,eq22,eq23,eq24,eq25,eq26,eq27,eq28,eq29],x,y,M,a,b,c,d,A,B,C,D,t,u,v,S,T,U,V)
sol0 = solutions[0]
print(sol0[0])
print(sol0[1])
print(sol0[2])
print(sol0[3])
print(sol0[4])
print(sol0[5])
print(sol0[6])
print(sol0[7])
print(sol0[8])
print(sol0[9])
print(sol0[10])
print(sol0[11])
print(sol0[12])
print(sol0[13])
print(sol0[14])
print(sol0[15])
print(sol0[16])
print(sol0[17])


output

(x, y, M, a, b, c, d, A, B, C, D, t, u, v, S, T, U, V)
x == 24
y == 13
M == 2701
a == -12
b == (13/2)
c == (-149/16)
d == 1
A == 3367
B == (28379/8)
C == (114737/32)
D == 3601
t == -1
u == -3
v == 7
S == 3601
T == 3598
U == 3583
V == 3538


Error D==S but assume(.... , S-D > 0 , .....)

How do you use assumes () well?

edit retag close merge delete

This is indeed unfortunate. The assumption works for elementary systems

sage: assume(x > 0)
sage: solve([x == -1], x)
[]
sage: solve([x == 0], x)
[]
sage: solve([x == 1], x)
[x == 1]


But in your situation the solver get confused...

( 2021-04-11 10:48:29 +0100 )edit

@vdelecroix how do i know when and if this bug will be fixed?

( 2021-04-11 11:13:56 +0100 )edit

Sort by ยป oldest newest most voted

I don't know what solve is doing (with inequalities/assumptions), but here your system of polynomial equations has finitely many solutions, so you can filter out those satisfying the inequalities:

R.<x,y,M,a,b,c,d,A,B,C,D,t,u,v,S,T,U,V> = PolynomialRing(QQ)

eq1 = 3*(((2*3367-3*y+1)/24)+3*x*(x+1)/2)+1-V
eq2 = -3367+3*x*(x+1)/2-3*y*(y-1)/2+(3*x+1)*(3*x+2)/2
eq3 = 3*(((2*V-3*v+1)/24)+3*x*(x+1)/2)+1-U
eq4 = V+3*v*(v-1)/2-12*x*(x+1)/2-1
eq5 = 3*(((2*U-3*u+1)/24)+3*x*(x+1)/2)+1-T
eq6 = U+3*u*(u-1)/2-12*x*(x+1)/2-1
eq7 = 3*(((2*T-3*t+1)/24)+3*x*(x+1)/2)+1-S
eq8 = T+3*t*(t-1)/2-12*x*(x+1)/2-1
eq9 = 3*(((2*S-3*1+1)/24)+3*x*(x+1)/2)+1-S
eq18 = -M+9*((2*3367 - 3*y + 1)/24+(y-1)*(y+1)/8)+1
eq19 = 3*((2*M - 3*(x+1) + 1)/24 + (3*x*(x + 1))/2) + 1 - A
eq20 = -M + (3*x*(x + 1))/2 - (3*x*(x + 1))/2 + ((3*x + 1)*(3*x + 2))/2
eq21 = 3*((2*A - 3*a + 1)/24 + (3*x*(x + 1))/2) + 1 - B
eq22 = A + (3*a*(a - 1))/2 - (12*x*(x + 1))/2 - 1
eq23 = 3*((2*B - 3*b + 1)/24 + (3*x*(x + 1))/2) + 1 - C
eq24 = B + (3*b*(b - 1))/2 - (12*x*(x + 1))/2 - 1
eq25 = 3*((2*C - 3*c + 1)/24 + (3*x*(x + 1))/2) + 1 - D
eq26 = C + (3*c*(c - 1))/2 - (12*x*(x + 1))/2 - 1
eq26 = 3*((2*D - 3*d + 1)/24 + (3*x*(x + 1))/2) + 1 - S
eq27 = D + (3*d*(d - 1))/2 - (12*x*(x + 1))/2 - 1
eq28 = 3*((2*S - 3*1 + 1)/24 + (3*x*(x + 1))/2) + 1 - S
eq29 = x-24

I = R.ideal([eq1,eq2,eq3,eq4,eq5,eq6,eq7,eq8,eq9,eq18,eq19,eq20,eq21,eq22,eq23,eq24,eq25,eq26,eq27,eq28,eq29])
nonneg = [x-1, y-1]
pos = [A-M, B-A, C-B, D-C, S-D, V-3367, U-V, T-U, S-T]
for sol in I.variety():
if all(lhs.subs(sol) >= 0 for lhs in nonneg) and all(lhs.subs(sol) > 0 for lhs in pos):
print(sol)


Output:

{V: 3538, U: 3583, T: 3598, S: 3601, v: 7, u: -3, t: -1, D: 3598, C: 3583, B: 3538, A: 3367, d: -1, c: -3, b: 7, a: 13, M: 2701, y: 13, x: 24}
{V: 3538, U: 3583, T: 3598, S: 3601, v: 7, u: -3, t: -1, D: 3598, C: 28703/8, B: 3538, A: 3367, d: -1, c: 1/4, b: -6, a: 13, M: 2701, y: 13, x: 24}
{V: 3538, U: 3583, T: 3598, S: 3601, v: 7, u: -3, t: -1, D: 3598, C: 114881/32, B: 28379/8, A: 3367, d: -1, c: 27/16, b: -11/2, a: -12, M: 2701, y: 13, x: 24}
{V: 3538, U: 3583, T: 3598, S: 3601, v: 7, u: -3, t: -1, D: 3598, C: 114737/32, B: 28379/8, A: 3367, d: -1, c: -21/16, b: 13/2, a: -12, M: 2701, y: 13, x: 24}

more

I don't think it's a good method, because if you exclude "eq29 = x-24" it takes too long to solve and my computer can't do it. If you want to know my problem look here https://ask.sagemath.org/question/566...

( 2021-04-11 14:33:24 +0100 )edit

This equation is not removed in Ricardo's answer. Computing the set of solutions in this particular example is relatively fast

sage: %time I.variety()
CPU times: user 134 ms, sys: 6.72 ms, total: 141 ms
Wall time: 142 ms
[{V: 3538, U: 3583, T: 3598, S: 3601, v: 7, u: -3, t: -1, D: 3601, C: 3583, B: 3538, A: 3367, d: 1, c: -11, b: 7, a: 13, M: 2701, y: 13, x: 24},
...

( 2021-04-11 22:05:14 +0100 )edit