1
$\begingroup$

Here's a minimal working example of a problem I'm having:

FindInstance[#, {a, b}] & @@@ {{a + b > 1, a + b < 2}, {a + b > 2, a + b < 3}}
(*{{{a -> 0, b -> 2}}, {{a -> 0, b -> 3}}}*)

Obviously this is not what I'm after, as $a+b<2$ is not satisfied in the first and $a+b<3$ is not satisfied in the second case. Individually they work fine:

FindInstance[{a + b > 1, a + b < 2}, {a, b}]
(*{{a -> 0, b -> 3/2}}*)

And:

FindInstance[{a + b > 2, a + b < 3}, {a, b}]
(*{{a -> 0, b -> 5/2}}*)

I'm guessing my issue is something to do with the evaluation order. Or maybe it's only reading the first inequality in each constraint list? What am I missing here?

EDIT: I've changed the title to reflect the error in my understanding.

$\endgroup$
2
  • $\begingroup$ @Mr.Wizard Should I delete the question? $\endgroup$
    – Shane
    Mar 23, 2015 at 18:25
  • 1
    $\begingroup$ Shane, unless things have changed the existence of a positively-voted answer means you will be unable to delete your own question. But there is no need for that. For the most part duplicates are not deleted; they serve as useful entry points from search engines that redirect to the original. Incidentally it is probably best not to think of @@@ as "Map Apply" as Map is not involved. Either function (Map or Apply) can be specified to operate at any level or contiguous range of levels within an expression. @@@ is Apply with a levelspec of {1}. $\endgroup$
    – Mr.Wizard
    Mar 24, 2015 at 3:35

1 Answer 1

3
$\begingroup$

Use this instead:

FindInstance[#, {a, b}]& /@ {a + b > 1 && a + b < 2, a + b > 2 && a + b < 3}

or, in fact, this:

FindInstance[#, {a, b}]& /@ {{a + b > 1, a + b < 2}, {a + b > 2, a + b < 3}}
$\endgroup$
2
  • $\begingroup$ You're right. I'm just getting confused between Map and Apply like an idiot! I can keep my constraints in list form, though, and just use /@ in place of @@@. Thanks! (I'll accept when it lets me) $\endgroup$
    – Shane
    Mar 23, 2015 at 16:28
  • $\begingroup$ Yeah you're right. Just edited the answer to reflect this. $\endgroup$
    – Taiki
    Mar 23, 2015 at 16:30

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