3
$\begingroup$

Quite simply, I am wondering if there is a cleaner (and more easily altered) way to write a system of conditions for an evaluation. For instance, suppose I have something like (I don't think a real MWE is needed here)

FindInstance[a1 && a2 &&...&& an]

where each a is a conditional expression.

Is there a way to write this as something like the following?

Conditions1 = a1 && a2 && a3;
Conditions2 = a4 && a5 &&...&& an;
FindInstance[Conditions1 && Conditions2]

Any more practical alternatives are greatly appreciated.

$\endgroup$
6
$\begingroup$

Short answer: Yes.

Because And has the attribute Flat, And[a, b, And[c, And[d, e]], And[f, g]] is the same as And[a,b,c,d,e,f,g]:

And[a, b, And[c, And[d, e]], And[f, g]] 
 a && b && c && d && e && f && g  
And[a, b, c, d, e, f, g]
 a && b && c && d && e && f && g   

Using the example conditions for cvgmt's answer:

conditions1 = And[x + y > 0, x y > 0]
x + y > 0 && x y > 0
conditions2 = And[x > 1, y < 5]
 x > 1 && y < 5 
And[conditions1, conditions2]

x + y > 0 && x y > 0 && x > 1 && y < 5

FindInstance[conditions1 && conditions2, {x, y}]
{{x -> 2, y -> 5/2}} 

Note: Re the argument expr in FindInstance[expr, ...]

FindInstance >> Details and Options:

enter image description here

and Reduce >> Details and Options:

enter image description here

So, you can also do

FindInstance[{conditions1, conditions2}, {x, y}]
{{x -> 2, y -> 5/2}}
$\endgroup$
3
$\begingroup$
conditions1 = {x + y > 0, x*y > 0};
conditions2 = {x > 1, y < 5};
FindInstance[Join[conditions1, conditions2], {x, y}]
$\endgroup$

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.