Group Abstract Group Abstract

Message Boards Message Boards

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

Variable as an argument to Part

Posted 3 days 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 2 days ago

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?

POSTED BY: Sasha Mandra
Posted 2 days ago

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.

POSTED BY: Eric Rimbey
Posted 3 days 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