Message Boards Message Boards

1
|
2122 Views
|
3 Replies
|
4 Total Likes
View groups...
Share
Share this post:

How to get disjunction elements into a list?

Posted 10 years ago

Some Mathematica results are returned as disjunctions in the form a || b || c , and the internal form is Or[a,b,c].

How do I convert this expression to a list { a, b, c }, for any number of elements in the original disjunction?

I'm a Mathematica beginner, and I can see several ways to do it 'manually', but I've learned enough about Mathematica to know that there is always a simple, clean way to do simple things like this.

Thanks in advance for any help.

POSTED BY: Doug Burkett
3 Replies

Simply change the Head of the expression (Or) to List, which can be done in many ways:

f=Or[a,b,c]
List@@f
Apply[List,f]
f/.Or->List
f[[0]]=List;
f

Hope that works for you!

POSTED BY: Sander Huisman
Posted 10 years ago

Great - just what I was looking for. Thanks a lot!

POSTED BY: Doug Burkett

Hope this helps:

In[1]:= Reduce[x^2 == 1, x]
Out[1]= x == -1 || x == 1

In[2]:= {ToRules[%]}
Out[2]= {{x -> -1}, {x -> 1}}

In[3]:= x /. %
Out[3]= {-1, 1}

In[4]:= Solve[x^2 == 1, x]
Out[4]= {{x -> -1}, {x -> 1}}

In[5]:= x /. %
Out[5]= {-1, 1}
POSTED BY: Szabolcs Horvát
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