Greetings, everyone!
How to get Wolfram to do this kind of work:
mm = {a, b};
FullSimplify[Or[mm[[i]] == a, mm[[i]] == b], Assumptions -> i \[Element] {1, 2}]
Greetings, everyone!
How to get Wolfram to do this kind of work:
mm = {a, b};
FullSimplify[Or[mm[[i]] == a, mm[[i]] == b], Assumptions -> i \[Element] {1, 2}]
Perhaps:
mm = {a, b};
Assuming[i == 1 || i == 2,
FullSimplify[Reduce[{Or[mm[[i]] == a, mm[[i]] == b], $Assumptions}]]
]
Or:
mm = {a, b};
Assuming[i == 1 || i == 2,
FullSimplify[
Reduce[Quiet[{Or[mm[[i]] == a,
mm[[i]] == b], $Assumptions}, {Part::pkspec1}]]]
]
Maybe something like
mm = {a, b};
Or @@ Flatten[Outer[#1 == mm[[#2]] &, {a, b}, {1, 2}]]
or
Or @@ Flatten[Outer[#1 === mm[[#2]] &, {a, b}, {1, 2}]]
But unless you can show why you need to use Part to check every target location, I’d suggest an entirely different strategy:
ContainsAny[mm, {a, b}]
Or if you want to test against a sublist:
nn = {a, z, b, y};
ContainsAny[Take[nn, {2, 3}], {a, b}]
Or if the sublist is not contiguous:
ContainsAny[nn[[{1, 4}]], {a, b}]
You guys amaze me with your ingenuity! Thank you. But I’d like more. The problem is very simple. To get around the restriction on the use of variables in the Part function. Suppose we have a matrix of arbitrary dimension that has some internal symmetry. To find this symmetry, we need to select certain elements from the matrix, compose a certain formula from them and check whether it is fulfilled or not. For this purpose it is necessary to use variables. Only with their help you can determine the selection of elements from the matrix. Isn’t it?
You seem stuck on the idea that there is some “restriction on the use of variables in the Part function”. There is no such restriction. During the evaluation process, such variables must evaluate to valid part specifications, but there is no general restriction against variables. I’m not sure if we need to dive into the details of Mathematica’s evaluation process, but that might be necessary to get you to abandon that belief.
For your problem about finding symmetries, I can’t imagine why it couldn’t be done with “normal” or idiomatic Mathematica code as opposed to using a layer of indirection with Assumptions/Assuming. Maybe you should provide us with a slightly more representative example of your problem.
Simplify is built for algebraic simplification, while Part is a programming construct. They don’t mix together.