How to simplify list of rules? For example,
{{a -> 0},{a -> 0, b -> 0}, {a -> 0, c -> 0}}
should return {{a->0}}
since $(a=0)||(a=0\&\&b=0)||(a=0\&\&c=0)=(a=0)$.
Mathematica Stack Exchange is a question and answer site for users of Wolfram Mathematica. It only takes a minute to sign up.
Sign up to join this communityTo explain the other answerer's response, what you need to do is convert the rules into logical expressions, as a Rule
in the Wolfram Language just turns the left hand side into the right hand side. So the first step is to make all the Rule
s into Equal
s:
rules = {{a -> 0},{a -> 0, b -> 0}, {a -> 0, c -> 0}};
rules2 = ReplaceAll[rules, Rule -> Equal]
(*{{a == 0}, {a == 0, b == 0}, {a == 0, c == 0}}*)
ReplaceAll takes anything matching a given pattern, in this case Rule
, and replaces it with another expression, in this case Equal
Then you need to make this a logical And
expression, like this:
rules3 = Apply[And, rules2, {1}]
(*{a == 0, a == 0 && b == 0, a == 0 && c == 0}*)
Apply
changes the head of the second argument to the first argument. The third argument defines which level it happens on
Then you need to make the list into a logical Or
expression:
rules4 = Apply[Or, rules3]
(*a == 0 || (a == 0 && b == 0) || (a == 0 && c == 0)*)
Finally you use LogicalExpand
to convert this statement into it's simplest form:
LogicalExpand[rules4]
(*a == 0*)
The shorthand posted previously is from the shorthands of ReplaceAll
and Apply
.
@@
means Apply
@@@
means Apply
at level one
/.
means ReplaceAll
//
is suffix notation, so it does the right hand side on the left hand side.
Put together this makes the short version:
Or @@ And @@@ rules /. Rule -> Equal // LogicalExpand
((Or @@ (And @@@ rules)) /. Rule -> Equal) // LogicalExpand
but I couldn't "prove" it.
$\endgroup$
Nov 16, 2016 at 18:09
f@g
not the same as f[g]
?
$\endgroup$
Or @@ And @@@ r /. Rule -> Equal // LogicalExpand
{Or @@ And @@@ r /. Rule -> Equal // LogicalExpand} /. Equal -> Rule
$\endgroup$