I've read lots of examples here on how to set one matrix Equal
to another, but how do you nest And
and Or
around several different equalities for values a matrix of variables can take on? Using what I've found so far, I've been able to cobble something together that works, but surely someone knows a better way?
The idea: Variables V
can take on the values in either A
or B
or C
.
Minimum Working Example:
Apply[And, Apply[Or, MapThread[Equal,
{Table[v[i], {c, 3}, {i, 10}]\[Transpose],
Table[{-1, 0, 1}, {i, 10}]}, 2], {1}]]
Good output:
(v[1] == -1 || v[1] == 0 || v[1] == 1) && (v[2] == -1 || v[2] == 0 || v[2] == 1) &&
(v[3] == -1 || v[3] == 0 || v[3] == 1) && (v[4] == -1 || v[4] == 0 || v[4] == 1) &&
(v[5] == -1 || v[5] == 0 || v[5] == 1) && (v[6] == -1 || v[6] == 0 || v[6] == 1) &&
(v[7] == -1 || v[7] == 0 || v[7] == 1) && (v[8] == -1 || v[8] == 0 || v[8] == 1) &&
(v[9] == -1 || v[9] == 0 || v[9] == 1) && (v[10] == -1 || v[10] == 0 || v[10] == 1)
Ideally the answer would be something of the form
And[Or[V=={A,B,C}]]
instead of the heavy use of Table
like I have, so we can see what's happening and adapt it for other problems.