Group Abstract Group Abstract

Message Boards Message Boards

0
|
1.4K Views
|
5 Replies
|
4 Total Likes
View groups...
Share
Share this post:

Variable as an argument to Part

Posted 8 months ago

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}]
POSTED BY: Sasha Mandra
5 Replies

Simplify is built for algebraic simplification, while Part is a programming construct. They don't mix together.

POSTED BY: Gianluca Gorni
Posted 8 months ago
POSTED BY: Sasha Mandra
Posted 8 months ago
POSTED BY: Eric Rimbey
Posted 8 months ago

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}]
POSTED BY: Eric Rimbey

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}]]]
 ]
POSTED BY: Michael Rogers
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard