Message Boards Message Boards

0
|
3554 Views
|
2 Replies
|
3 Total Likes
View groups...
Share
Share this post:

[?] Solve/Reduce systems with an array of variables?

Posted 6 years ago

As a simple example I want to reduce the equation d1+2*d2==2, where d1 and d2 are either 0 or 1. This is easy:

In[147]:= Reduce[{d1 + 2 d2 == 2, d1 == 0 || d1 == 1, 
  d2 == 0 || d2 == 1}, {d1, d2}]

Out[147]= d1 == 0 && d2 == 1

But if I use an array d[i] instead of d1, d2 for the unknown variables, I cannot get it to work. The following seems to be syntactically correct, but it does not work:

In[152]:= Reduce[{d[1] + 2 d[2] == 2, 
  ForAll[i, d[i] == 0 || d[i] == 1]}, d]

During evaluation of In[152]:= Reduce::nsmet: This system cannot be solved with the methods available to Reduce.

Out[152]= Reduce[{d[1] + 2 d[2] == 2, \!\(
\*SubscriptBox[\(\[ForAll]\), \(i\)]\((d[i] == 0 || d[i] == 1)\)\)},
  d]

Of course this example ist extremely simplified. I need some solution for a large d-Array of variables and some equation containing them.

POSTED BY: Werner Geiger
2 Replies

Quantifier elimination will not handle an index as a polynomial variable. Instead map the conditions over the variables.

Reduce[Flatten[{d[1] + 2 d[2] == 2, 
   Map[d[#] == 0 || d[#] == 1 &, Range[2]]}], d]

(* d[2] == 1 && d[1] == 0 *)
POSTED BY: Daniel Lichtblau
Posted 6 years ago

Thanks a lot, Daniel. This works perfectly.

I did not try it for a large number of d[i], which would yield a large system of equations for Reduce. But I need it only for 5 to 20 indexed variables anyway.

POSTED BY: Werner Geiger
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