1
$\begingroup$

I have long results of a Reduce statement in the form of {(expr1) || (expr2) || (expr3) || ...}

I am looking for a way to split them into a list {expr1, expr2, expr3, ...}

Even better, I would be happy to split the internal expressions to lists at the '&&` operators as well.

$\endgroup$
  • $\begingroup$ So how do you want a mixture of Ands and Ors to be treated? $\endgroup$ – J. M. is in limbo Jul 16 '16 at 15:31
  • $\begingroup$ Luckily the || are outside the expressions, and internally the expressions only have &&. I would probably prefer to have it converted into some canonical form first. $\endgroup$ – Ron Jul 16 '16 at 15:35
  • $\begingroup$ Now that you bring it up: look at BooleanConvert[]. $\endgroup$ – J. M. is in limbo Jul 16 '16 at 15:41
  • 1
    $\begingroup$ In certain cases results of Reduce can be transformed into rules by using ToRules, then this post might be helpful Assign the results from a Solve to variable(s). Nevertheless you should remember that Reduce and Solve are not equivalent in general What is the difference between Reduce and Solve?. $\endgroup$ – Artes Jul 16 '16 at 15:42
  • $\begingroup$ That was helpful - thanks! (though ToRules didn't apply in this case). $\endgroup$ – Ron Jul 16 '16 at 16:17
2
$\begingroup$

When the expression is inside a List use Apply at level 1

list1 = {(expr1) || (expr2) || (expr3)};

List @@@ list1

(*  {{expr1, expr2, expr3}}  *)

list2 = {(expr1) && (expr2) && (expr3)};

List @@@ list2

(*  {{expr1, expr2, expr3}}  *)

If there is no external List then just use Apply

list3 = (expr1) || (expr2) || (expr3);

List @@ list3

(*  {expr1, expr2, expr3}  *)

list4 = (expr1) && (expr2) && (expr3);

List @@ list4

(*  {expr1, expr2, expr3}  *)
$\endgroup$
  • $\begingroup$ I found out Level does the same thing. Converting to normal form using BooleanConvert prior to applying it helped. Many thanks! $\endgroup$ – Ron Jul 16 '16 at 16:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.