# Solve Inequalities

Posted 9 years ago
2784 Views
|
8 Replies
|
1 Total Likes
|
 Dear Experts, I'm trying to solve the inequality: fun2 = Compile[{x, y, a, b, c, d}, (2/3 a + 4/3 b x) (1 - y^2) + (1 - a) (2 c x^2 (1 - y^2) + 1/2 (1 - c) (1 - x^2) (1 + y^2) + 4/3 d (1 - x^2) y)] Reduce[ForAll[{x, y}, -1 < x < 1 && -1 < y < 1 && 0 < a < 1 && -1 < b < 1 && 0 < c < 1 && -3/4 (1 - c) < d < 3/4 (1 - c), fun2[x, y, a, b, c, d] > 0] && 0 < a < 1 && -1 < b < 1 && 0 < c < 1 && -3/4 (1 - c) < d < 3/4 (1 - c), {a, b}, Reals] Basically I would like to find the conditions on a and b that allow the expression to be always positive for every x and y (within their range, meaning -1 < x < 1 && -1 < y < 1)(a) I'm not sure whether the Mathematica code that I wrote will do the job(b) When I run this code it never ends, it's like it goes in an infinite loopSo my question is: is the Mathematica code correct ? If it is, is there a way to speed up the computation ?Many thanks for your support. Mauro.
8 Replies
Sort By:
Posted 9 years ago
 As I remember, the time taken by Reduce is double exponential in the complexity of the problem.
Posted 9 years ago
 Hi Frank, I see, I actually didn't know the actual use of Compile.The output you are showing to me is correct, and that's precisely what I was getting for my test function. But the actual problem in which I'm interested in is this one:fun2 = Function[{x, y, a, b, c, d}, (2/3 a + 4/3 b x) (1 - y^2) + (1 - a) (2 c x^2 (1 - y^2) + 1/2 (1 - c) (1 - x^2) (1 + y^2) + 4/3 d (1 - x^2) y)]Reduce[ForAll[{x, y}, -1 < x < 1 && -1 < y < 1 && 0 < a < 1 && -1 < b < 1 && 0 < c < 1 && -3/4 (1 - c) < d < 3/4 (1 - c), fun2[x, y, a, b, c, d] > 0] && 0 < a < 1 && -1 < b < 1 && 0 < c < 1 && -3/4 (1 - c) < d < 3/4 (1 - c), {a, b}, Reals]But, as I said, it takes forever to converge, and actually I don't even know if it will ever converge. But looking at it, it doesn't seem too complicated. I though that Mathematica could give me an answer in no time.Many thanks, - Mauro.
Posted 9 years ago
 Compile is designed to give numerical answers when given numerical inputs. By giving it symbolic inputs, you're causing it to eventually return a symbolic result. That's what your code hangs up. Is this what you're looking for? In:= fun1 = Function[{x, y, c, d}, 2 c x^2 (1 - y^2) + 1/2 (1 - c) (1 - x^2) (1 + y^2) + 4/3 d (1 - x^2) y]; In:= Reduce[ ForAll[{x, y}, -1 < x < 1 && -1 < y < 1 && 0 < c < 1 && -1 < d < 1, fun1[x, y, c, d] > 0] && 0 < c < 1 && -1 < d < 1, {d}, Reals] Out= 0 < c < 1 && 1/4 (-3 + 3 c) <= d <= 1/4 (3 - 3 c) 
Posted 9 years ago
 Hi Frank, the point is that my original version of the code seems to work, in the sense that if I use a simpler expression, it gives me the right answer. For instance: fun1 = Compile[{x, y, c, d}, 2 c x^2 (1 - y^2) + 1/2 (1 - c) (1 - x^2) (1 + y^2) + 4/3 d (1 - x^2) y] Reduce[ForAll[{x, y}, -1 < x < 1 && -1 < y < 1 && 0 < c < 1 && -1 < d < 1, fun1[x, y, c, d] > 0] && 0 < c < 1 && -1 < d < 1, {d}, Reals] The problem is that if I plug-in the expression in which I'm actually interested in, and I run the code, it keeps running forever.Therefore I was wondering whether there were ways to speed up the code, or to find out, somehow, infinite loops, or more performant ways to do the same thing and get an answer within a lifetime.In fact, my problem seems to me relatively simple, that a modern computer should be able to solve relatively quickly.Many thanks, - Mauro.
Posted 9 years ago
 It doesn't seem to add anything new. Here's something I did a while back that similar to what you're trying to do. I wanted to find the global minimum of x + y subject to x^2 + y^2 == 1 , using Reduce. In:= Reduce[ ForAll[{x, y}, x^2 + y^2 == 1, min <= x + y], {min, Reals}] Out= min <= -Sqrt 
Posted 9 years ago
 In:= Reduce[ ForAll[{x, y}, -1 < x < 1 && -1 < y < 1 && 0 < a < 1 && -1 < b < 1 && 0 < c < 1 && -3/4 (1 - c) < d < 3/4 (1 - c), expr > 0] && 0 < a < 1 && -1 < b < 1 && 0 < c < 1 && -3/4 (1 - c) < d < 3/4 (1 - c), {a, b, c, d, expr}, Reals] Out= 0 < a < 1 && -1 < b < 1 && 0 < c < 1 && 1/4 (-3 + 3 c) < d < 1/4 (3 - 3 c) && expr > 0 
Posted 9 years ago
 Rather than putting a compiled function inside Reduce, put the expr == (2/3 a + 4/3 b x) (1 - y^2) + (1 - a) (2 c x^2 (1 - y^2) + 1/2 (1 - c) (1 - x^2) (1 + y^2) + 4/3 d (1 - x^2) y) in and add expr to the list of variables.
Posted 9 years ago
 Dear Frank, many thanks for your reply. Since I'm relatively new in using Mathematica, can you please explain more explicitly how shall I write the code?I understood that is something like: expr == (2/3 a + 4/3 b x) (1 - y^2) + (1 - a) (2 c x^2 (1 - y^2) + 1/2 (1 - c) (1 - x^2) (1 + y^2) + 4/3 d (1 - x^2) y) Reduce[ForAll[{x, y}, -1 < x < 1 && -1 < y < 1 && 0 < a < 1 && -1 < b < 1 && 0 < c < 1 && -3/4 (1 - c) < d < 3/4 (1 - c), expr > 0] && 0 < a < 1 && -1 < b < 1 && 0 < c < 1 && -3/4 (1 - c) < d < 3/4 (1 - c), {a, b, expr2}, Reals] Many thanks, - Mauro.