Message Boards Message Boards

0
|
3461 Views
|
8 Replies
|
1 Total Likes
View groups...
Share
Share this post:

Solve Inequalities

Posted 11 years ago

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 loop

So 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.
POSTED BY: Mauro Dinardo
8 Replies

As I remember, the time taken by Reduce is double exponential in the complexity of the problem.

POSTED BY: Frank Kampas
Posted 11 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 BY: Mauro Dinardo

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[1]:= 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[2]:= 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[2]= 0 < c < 1 && 1/4 (-3 + 3 c) <= d <= 1/4 (3 - 3 c)
POSTED BY: Frank Kampas
Posted 11 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 BY: Mauro Dinardo

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[32]:= Reduce[
 ForAll[{x, y}, x^2 + y^2 == 1, min <= x + y], {min, Reals}]

Out[32]= min <= -Sqrt[2]
POSTED BY: Frank Kampas
In[33]:= 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[33]= 0 < a < 1 && -1 < b < 1 && 0 < c < 1 && 
 1/4 (-3 + 3 c) < d < 1/4 (3 - 3 c) && expr > 0
POSTED BY: Frank Kampas

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 BY: Frank Kampas
Posted 11 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.

POSTED BY: Mauro Dinardo
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract