Ask Your Question
0

Obtain a particular solution for a system of inequalities whose variables can only take certain values

asked 2019-08-09 12:07:47 +0100

DanDan gravatar image

updated 2019-08-10 15:16:16 +0100

I want to get a particular solution (assuming it exists) of a system of inequalities, with 4 variables, having that those variables can take only certain values. What I have so far is:

SRC = 64 

a, b, c, d = var('a', 'b', 'c', 'd')

assume(a >= 1 and a <= 8)
assume(b >=4 and b <= 512)
assume(c >= 2 and c <= 128)
assume(d, 'integer')

eq1 = (SRC / a) * b <= 418
eq2 = (((SRC / a) * b) / c) / d <= 200
eq3 = ((SRC / a) * b) / c <= 480


res = solve([eq1, eq2, eq3], a, b, c, d=1)

for i in res:
    print(i)

The first result I obtain is:

[a < 0, 0 < c, -d > 0, 25*a*c*d - 8*b > 0, -15*a*c + 2*b > 0]

As you can see, a < 0, but I have stated that a must be greater than 1. Why this happens?

How can I obtain a particular solution (if it exists)?

edit retag flag offensive close merge delete

Comments

What is SRC?

slelievre gravatar imageslelievre ( 2019-08-10 00:10:35 +0100 )edit

Sorry, it is a constant. Edited for fixing it.

DanDan gravatar imageDanDan ( 2019-08-10 15:16:44 +0100 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2019-08-10 23:31:56 +0100

Emmanuel Charpentier gravatar image

Well, Sage doesn't checks its solutions against the assumptions. So you have to add them to the system of inequations you're trying to solve:

SRC=64
a, b, c, d = var('a', 'b', 'c', 'd')
Cns=[a >= 1, a <= 8, b >=4, b <= 512, c >= 2, c <= 128]
eq1 = (SRC / a) * b <= 418
eq2 = (((SRC / a) * b) / c) / d <= 200
eq3 = ((SRC / a) * b) / c <= 480

Since we note that eq3 is redundant against eq2:

sage: eq3.subs(d==1)
64*b/(a*c) <= 480

We can build our set of inequations quite easily:

Sys=copy(Cns)
Sys.append(eq1)
Sys.append(eq2.subs(d==1))

which is easily, if a bit slowly) solved:

sage: %time Sol=solve(Sys,[a,b,c])
CPU times: user 19.1 s, sys: 47.9 ms, total: 19.2 s
Wall time: 16.4 s

The solution seems a bit intricate:

sage: len(Sol)
54

but it could be considerably simplified with a bit of rewriting:

sage: for s in Sol:
....:     print(s)
....:     
[max(1, 32/209*b) < a, a < 8, 4 < b, b < (209/4), 2 < c, c < 128, 25*a*c - 8*b == 0]
[max(1, 32/209*b) < a, a < 8, 4 < b, b < (209/4), 2 < c, c < 128, 25*a*c - 8*b > 0]
[a == 1, 4 < b, b < (209/32), 2 < c, c < 128, -8*b + 25*c == 0]
[a == 1, 4 < b, b < (209/32), 2 < c, c < 128, -8*b + 25*c > 0]
[a == 1, b == 4, 2 < c, c < 128, 25*c - 32 == 0]
[a == 1, b == 4, 2 < c, c < 128, 25*c - 32 > 0]
[a == 1, b == 4, c == 2, 18 == 0]
[a == 1, b == 4, c == 2, 18 > 0]
[a == 1, b == 4, c == 128, 3168 == 0]
[a == 1, b == 4, c == 128, 3168 > 0]
[a == 1, b == (209/32), 2 < c, c < 128, 25*c - 209/4 == 0]
[a == 1, b == (209/32), 2 < c, c < 128, 25*c - 209/4 > 0]
[a == 1, b == (209/32), c == 2, (-9/4) == 0]
[a == 1, b == (209/32), c == 2, (-9/4) > 0]
[a == 1, b == (209/32), c == 128, (12591/4) == 0]
[a == 1, b == (209/32), c == 128, (12591/4) > 0]
[a == 1, c == 2, 4 < b, b < (209/32), -8*b + 50 == 0]
[a == 1, c == 2, 4 < b, b < (209/32), -8*b + 50 > 0]
[a == 1, c == 128, 4 < b, b < (209/32), -8*b + 3200 == 0]
[a == 1, c == 128, 4 < b, b < (209/32), -8*b + 3200 > 0]
[a == 8, 4 < b, b < (209/4), 2 < c, c < 128, -8*b + 200*c == 0]
[a == 8, 4 < b, b < (209/4), 2 < c, c < 128, -8*b + 200*c > 0]
[a == 8, b == 4, 2 < c, c < 128, 200*c - 32 == 0]
[a == 8, b == 4, 2 < c, c < 128, 200*c - 32 > 0]
[a == 8, b == 4, c == 2, 368 == 0]
[a == 8, b == 4, c == 2, 368 > 0]
[a == 8, b == 4, c == 128, 25568 == 0]
[a == 8, b == 4, c == 128, 25568 > 0]
[a == 8, b == (209/4), 2 < c, c < 128, 200*c - 418 == 0]
[a == 8, b == (209/4), 2 < c, c < 128, 200*c - 418 > 0]
[a == 8, b == (209/4), c == 2, -18 == 0]
[a == 8, b == (209/4), c == 2, -18 > 0]
[a == 8, b == (209/4), c == 128, 25182 == 0]
[a == 8, b == (209/4), c == 128, 25182 > 0]
[a == 8, c == 2, 4 < b, b < (209/4), -8*b + 400 == 0]
[a == 8, c == 2, 4 < b, b < (209/4), -8*b + 400 > 0]
[a == 8, c == 128, 4 < b, b < (209/4), -8*b + 25600 == 0]
[a == 8, c == 128, 4 < b, b < (209/4), -8*b + 25600 > 0]
[a == 32/209*b, (209/32) < b, b < (209/4), 2 < c, c < 128, 800/209*b*c - 8*b == 0]
[a == 32/209*b, (209/32) < b, b < (209/4), 2 < c, c < 128, 800/209*b*c - 8*b > 0]
[b == 4, 1 < a, a < 8, 2 < c, c < 128, 25*a*c - 32 == 0]
[b == 4, 1 < a, a < 8, 2 < c, c < 128, 25*a*c - 32 > 0]
[b == 4, c == 2, 1 < a, a < 8, 50*a - 32 == 0]
[b == 4, c == 2, 1 < a, a < 8, 50*a - 32 > 0]
[b == 4, c == 128, 1 < a, a < 8, 3200*a - 32 == 0]
[b == 4, c == 128, 1 < a, a < 8, 3200*a - 32 > 0]
[b == 209/32*a, c == 2, 1 < a, a < 8, -9/4*a == 0]
[b == 209/32*a, c == 2, 1 < a, a < 8, -9/4*a > 0]
[b == 209/32*a, c == 128, 1 < a, a < 8, 12591/4*a == 0]
[b == 209/32*a, c == 128, 1 < a, a < 8, 12591/4*a > 0]
[c == 2, max(1, 32/209*b) < a, a < 8, 4 < b, b < (209/4), 50*a - 8*b == 0]
[c == 2, max(1, 32/209*b) < a, a < 8, 4 < b, b < (209/4), 50*a - 8*b > 0]
[c == 128, max(1, 32/209*b) < a, a < 8, 4 < b, b < (209/4), 3200*a - 8*b == 0]
[c == 128, max(1, 32/209*b) < a, a < 8, 4 < b, b < (209/4), 3200*a - 8*b > 0]

Supposing u<v, Sage insist to write [[u==t,...],[u<t, t<v, ...], [t==v, ...]] in place of [u<=t, t<=v, ...]. It is certainly possible to write something for automatically rewrite this, but I'm not currently aware of how...

Cheating a bit :

sage: %time MSol=mathematica.Reduce(Sys,[a,b,c])
CPU times: user 6.76 ms, sys: 0 ns, total: 6.76 ms
Wall time: 31.3 ms
sage: MSol
Inequality[1, LessEqual, a, LessEqual, 8] && 
 ((Inequality[4, LessEqual, b, LessEqual, (25*a)/4] && 
   Inequality[2, LessEqual, c, LessEqual, 128]) || 
  (Inequality[(25*a)/4, Less, b, LessEqual, (209*a)/32] && 
   Inequality[(8*b)/(25*a), LessEqual, c, LessEqual, 128]))

faster and considerably terset (but not as explicit) as Sage's solution...

HTH,

edit flag offensive delete link more

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: 2019-08-09 12:07:47 +0100

Seen: 299 times

Last updated: Aug 10 '19