4
$\begingroup$

I'm testing the FindInstance capabilities and ran into one problem that behaves similarly with different types of inequalities. I calculate two points satisfying given inequalities:

FindInstance[Subscript[W, 1]^2 - 4 Subscript[W, 0] Subscript[W, 2] > 0 && Subscript[X, 1]^2 - 4 Subscript[X, 0] > 0 && Subscript[Y, 1]^2 - 4 Subscript[Y, 0] > 0 && Subscript[Z, 1]^2 - 4 Subscript[Z, 0] > 0 && -5 < Subscript[W, 2] <5 && -2 < Subscript[X, 1] < 2 && 1 < Subscript[Y, 1] < 2 && 1 < Subscript[Z, 1] < 2, Reduce`FreeVariables[{Subscript[W, 1]^2 - 4 Subscript[W, 0] Subscript[W, 2], Subscript[X, 1]^2 - 4 Subscript[X, 0], Subscript[Y, 1]^2 - 4 Subscript[Y, 0],Subscript[Z, 1]^2 - 4 Subscript[Z, 0], Subscript[W, 1] + Subscript[W, 2] (Subscript[S, 1])}], Reals, 2]

And when I add an additional inequality $-1 < W_1 + W_2 S_1 < 1$

FindInstance[Subscript[W, 1]^2 - 4 Subscript[W, 0] Subscript[W, 2] > 0 && Subscript[X, 1]^2 - 4 Subscript[X, 0] > 0 && Subscript[Y, 1]^2 - 4 Subscript[Y, 0] > 0 && Subscript[Z, 1]^2 - 4 Subscript[Z, 0] > 0 && -5 < Subscript[W, 2] <5 && -2 < Subscript[X, 1] < 2 && 1 < Subscript[Y, 1] < 2 && 1 < Subscript[Z, 1] < 2 && -1 < Subscript[W, 1] + Subscript[W, 2] (Subscript[S, 1]) < 1, Reduce`FreeVariables[{Subscript[W, 1]^2 - 4 Subscript[W, 0] Subscript[W, 2], Subscript[X, 1]^2 - 4 Subscript[X, 0], Subscript[Y, 1]^2 - 4 Subscript[Y, 0], Subscript[Z, 1]^2 - 4 Subscript[Z, 0], Subscript[W, 1] + Subscript[W, 2] (Subscript[S, 1])}], Reals, 2];

The calculation starts but cannot stop, i.e. identify these 2 points. I waited an hour, but the calculation never ended.

Although with the help of the NMinimize command, I can find one point quite quickly.

NMinimize[{Subscript[W, 1] + Subscript[W, 2] Subscript[S, 1], Subscript[W, 1]^2 - 4 Subscript[W, 0] Subscript[W, 2] > 0, Subscript[X, 1]^2 - 4 Subscript[X, 0] > 0, Subscript[Y, 1]^2 - 4 Subscript[Y, 0] > 0, Subscript[Z, 1]^2 - 4 Subscript[Z, 0] > 0, -1 < Subscript[W, 1] + Subscript[W, 2] Subscript[S, 1] < 1}, Reduce`FreeVariables[{Subscript[W, 1]^2 - 4 Subscript[W, 0] Subscript[W, 2], Subscript[X, 1]^2 - 4 Subscript[X, 0], Subscript[Y, 1]^2 - 4 Subscript[Y, 0], Subscript[Z, 1]^2 - 4 Subscript[Z, 0], Subscript[W, 1] + Subscript[W, 2] (Subscript[S, 1])}], Method -> {"RandomSearch", "SearchPoints" -> 1}]

Is there something wrong with the FindInstance settings?

$\endgroup$
6
$\begingroup$

FindInstance depends on the order of variables. In your example, you can reorder the variables (as Bob does in his answer) to get things to work:

expr = Subscript[W,1]^2 - 4 Subscript[W,0] Subscript[W,2] > 0 &&
    Subscript[X,1]^2-4 Subscript[X,0]>0 && 
    Subscript[Y,1]^2-4 Subscript[Y,0]>0 && 
    Subscript[Z,1]^2-4 Subscript[Z,0]>0 &&
    -5<Subscript[W,2]<5 &&
    -2<Subscript[X,1]<2 &&
    1<Subscript[Y,1]<2 &&
    1<Subscript[Z,1]<2 &&
    -1<Subscript[W,1]+Subscript[W,2] (Subscript[S,1])<1;

FindInstance[expr, RotateLeft @ Reduce`FreeVariables[expr], Reals, 2]

{{Subscript[W, 0] -> 0, Subscript[W, 1] -> -(9/202), Subscript[W, 2] -> 26/7, Subscript[X, 0] -> -96, Subscript[X, 1] -> -(24/13), Subscript[Y, 0] -> 1/4, Subscript[Y, 1] -> 98/51, Subscript[Z, 0] -> -105, Subscript[Z, 1] -> 45/34, Subscript[S, 1] -> -(35/188)}, {Subscript[W, 0] -> 0, Subscript[W, 1] -> -(9/202), Subscript[W, 2] -> 26/7, Subscript[X, 0] -> 19/202, Subscript[X, 1] -> -(88/73), Subscript[Y, 0] -> 163/269, Subscript[Y, 1] -> 205/114, Subscript[Z, 0] -> -105, Subscript[Z, 1] -> 45/34, Subscript[S, 1] -> -(35/188)}}

$\endgroup$
1
  • $\begingroup$ Similar problem. As soon as I replace replace S[1] with X[1]+Y[1]+Z[1] for example, the problem remains. $\endgroup$
    – dtn
    Jan 14 at 3:34
5
$\begingroup$

It is generally recommended to avoid subscripted variables and instead to use indexed variables. The indexed variables can be formatted to display as the corresponding subscripted variables.

Clear["Global`*"];

SeedRandom[1234];

(Format[#[n_]] := Subscript[#, n]) & /@ {S, W, X, Y, Z};

sys1 = W[1]^2 - 4 W[0] W[2] > 0 && -4 X[0] + X[1]^2 > 0 && -4 Y[0] + Y[1]^2 > 
    0 && -4 Z[0] + Z[1]^2 > 0 && -5 < W[2] < 5 && -2 < X[1] < 2 && 
   1 < Y[1] < 2 && 1 < Z[1] < 2;

vars1 = Reduce`FreeVariables[sys1];

FindInstance[sys1, vars1, Reals, 2]

enter image description here

sys2 = sys1 && -1 < W[1] + W[2] S[1] < 1;

vars2 = {vars1, S[1]} // Flatten;

FindInstance[sys2, vars2, Reals, 2]

enter image description here

$\endgroup$
4
  • $\begingroup$ Your method was the fastest. But if we replace S[1] with X[1]+Y[1]+Z[1] for example, the problem remains. He can't even count two points. $\endgroup$
    – dtn
    Jan 14 at 3:29
  • $\begingroup$ Replacing S[1] with (X[1]+Y[1]+Z[1]) there appears to be only one instance. Using varying values for RandomSeeding returns the same solution: {Subscript[W, 0] -> -(19/21), Subscript[W, 1] -> -(19/84), Subscript[W, 2] -> 0, Subscript[X, 0] -> -(19/21), Subscript[X, 1] -> 95/168, Subscript[Y, 0] -> 0, Subscript[Y, 1] -> 19/12, Subscript[Z, 0] -> 19/84, Subscript[Z, 1] -> 19/14} $\endgroup$
    – Bob Hanlon
    Jan 14 at 3:55
  • $\begingroup$ expr = Subscript[W, 1]^2 - 4 Subscript[W, 0] Subscript[W, 2] > 0 && Subscript[X, 1]^2 - 4 Subscript[X, 0] > 0 && Subscript[Y, 1]^2 - 4 Subscript[Y, 0] > 0 && Subscript[Z, 1]^2 - 4 Subscript[Z, 0] > 0 && -5 < Subscript[W, 2] <5 && -2 < Subscript[X, 1] < 2 && 1 < Subscript[Y, 1] < 2 && 1 < Subscript[Z, 1] < 2 && Subscript[W, 1] + (Subscript[X, 1] + Subscript[Y, 1] + Subscript[Z, 1]) < 100; /FindInstance[expr, RotateLeft@Reduce`FreeVariables[expr], Reals, 2]/ Here I put the new inequality. Two points were counted, but the calculation lasted about 15 minutes - this is a fabulous lot. $\endgroup$
    – dtn
    Jan 14 at 4:01
  • $\begingroup$ Addition: for comparison, I used the SemialgebraicComponentInstances command. Two points were found instantly. But I do not like the functionality of this command and the lack of the ability to select the number of points. Something is wrong with the FindInstance command. sys2 = sys1 && -1 < W[1] + X[1] + Y[1] + Z[1] < 1; vars2 = {vars1, S[1]} // Flatten; SemialgebraicComponentInstances[sys2, vars2] $\endgroup$
    – dtn
    Jan 14 at 4:12
3
$\begingroup$

Another way is Reduce the expr before use FindInstance.

FindInstance[Reduce[expr, Reals], Reduce`FreeVariables[expr], Reals,2]

enter image description here

$\endgroup$
1
  • $\begingroup$ Similar problem. As soon as I replace replace S[1] with X[1]+Y[1]+Z[1] for example, the problem remains. It seems that the problem is with the structure of the inequalities themselves and the boundary conditions. $\endgroup$
    – dtn
    Jan 14 at 3:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.