# Simplify list of rules

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)$.

To 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 Rules into Equals:

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

• Great explanation. You could maybe even add something about the order with which the shorthands are evaluated. By experience, I know it's evaluated as such ((Or @@ (And @@@ rules)) /. Rule -> Equal) // LogicalExpand but I couldn't "prove" it. Nov 16 '16 at 18:09
• @anderstood See when is f@g not the same as f[g]? Nov 16 '16 at 18:27
Or @@ And @@@ r /. Rule -> Equal // LogicalExpand

• If you want to have a rule in the end, you have to replace it back after the expression is simplified like this: {Or @@ And @@@ r /. Rule -> Equal // LogicalExpand} /. Equal -> Rule Nov 16 '16 at 22:13
• @Stitch yep, there are also double brackets but I decided that should be enough and OP should be able to adjust it for specific needs.
– Kuba
Nov 17 '16 at 6:41