2
$\begingroup$

I need to simplify a set of solutions of a system, say for example:

A := (a[1] == 3 && a[2] <= 1 && b[1] <= 5) || (a[1] == 3 && a[2] == 1 && b[1] == -7)

I care only about a[1] and a[2] but I can not use Eliminate since I have inequalities. So one solution is:

Simplify[Reduce[Exists[{b[1]}, A]]]

a[1] == 3 && a[2] <= 1

It works! But since I have a large system (many b's) I need to automate this. Since:

Array[b, 1]

{b[1]}

I tried:

Simplify[Reduce[Exists[Array[b,1],A]]]

a[1] == 3 && a[2] <= 1 && b[1] <= 5

The second method yields the wrong outcome! What am I doing wrong here?

$\endgroup$
3
  • $\begingroup$ I just noticed you deleted your other question... did you get an answer? I was midway through writing one... $\endgroup$
    – rm -rf
    Commented Mar 28, 2013 at 23:59
  • $\begingroup$ sorry for wasting your time! after digging more I found this mathematica.stackexchange.com/questions/3070/… which solves my other problem. thanks. $\endgroup$ Commented Mar 29, 2013 at 1:24
  • $\begingroup$ Ok, no problem. In any case, what you had was mostly fine; you just needed to use HoldPattern. For example, HoldPattern[a@# == _] -> True & /@ Range@5 will generate replacement rules for a[1] through a[5] $\endgroup$
    – rm -rf
    Commented Mar 29, 2013 at 1:38

2 Answers 2

4
$\begingroup$

Exists has attribute HoldAll:

Attributes[Exists]
(* {HoldAll, Protected, ReadProtected} *)

You need to do

Simplify@Reduce@Exists[Evaluate@Array[b, 1], A]
(* a[1] == 3 && a[2] <= 1 *)
$\endgroup$
1
  • $\begingroup$ Heh, guess you beat me to it. Didn't see your answer until I entered mine. $\endgroup$
    – VF1
    Commented Mar 27, 2013 at 0:43
3
$\begingroup$

Exists has the attribute HoldAll:

Attributes[Exists]
(* {HoldAll, Protected, ReadProtected} *)

As such, specifying Exists[Array[b, 1], A] in your argument for Reduce is the same thing as telling that there is exists a value for the symbol of the form Array[b,1], verbatim, which makes A true.

Using Evaluate to make sure that Array is expanded into its appropriate set of values, you can achieve the desired result:

Simplify[Reduce[Exists[Evaluate[Array[b, 1]], A]]]
(* a[1] == 3 && a[2] <= 1 *)
$\endgroup$
2
  • $\begingroup$ LOL! Our answers are identical! :D $\endgroup$
    – Federico
    Commented Mar 27, 2013 at 0:43
  • $\begingroup$ We also adopted the same style for posting code: code followed by (* return value *). You just wrote a little more explanation. I'm tired instead, 2AM here... Good night! $\endgroup$
    – Federico
    Commented Mar 27, 2013 at 0:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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