# How can I make the output of Reduce more readable (with a tree)?

Oftentimes, the output of Reduce is quite difficult to read because it has too many && and || included in it.

For example the output of Reduce[expr]//Simplify for a particular expr I had was:

(ϵc ==
0 && ((ex == 0 &&
ey == 0 && (ez ϵb !=
0 || (ez != 0 && ϵb == 0))) || (ey !=
0 && ϵb !=
0 && (nr == Sqrt[ey ϵa + ex ϵb]/Sqrt[ey] ||
nr + Sqrt[ey ϵa + ex ϵb]/Sqrt[ey] ==
0) && (ex - I ey == 0 || ex + I ey == 0)) || (ez !=
0 && ϵb ==
0 && (nr == Sqrt[ϵa] ||
nr + Sqrt[ϵa] == 0)))) || (ez ==
0 && ((ϵb ==
0 && (nr == Sqrt[ϵa] ||
nr + Sqrt[ϵa] == 0) && (ex != 0 ||
ey != 0)) || (ey != 0 && ϵb !=
0 && (nr == Sqrt[ey ϵa + ex ϵb]/Sqrt[ey] ||
nr + Sqrt[ey ϵa + ex ϵb]/Sqrt[ey] ==
0) && (ex - I ey == 0 || ex + I ey == 0))))


I was thinking it would be easier to read this if it were displayed as a tree. However TreeForm[%] returns: which is not much better.

Annother question suggested truncating the tree, in which case you get:

Also not great.

What I would like is to split up the tree by logic symbols, but to have the leaves of the tree be the individual equations.

## How can I get the tree to terminate at equations?

As in I'd want expressions that look like nr == Sqrt[ea] to be connected in a tree of Ands and Ors. It's difficult because the number of levels may be different for different parts of the tree. Any ideas?

There are plenty of new functionalities for manipulating and styling trees in v13 (some of them present already in v12.3).

For example:

exprTree[expr_] :=
RulesTree[
TreeRules[ExpressionTree[expr]] /. (e : (Except[And | Or] -> __)) :>
TreeExpression[RulesTree[e]],
TreeLayout -> {"LayeredDigraphEmbedding", "Orientation" -> Left},
TreeElementStyle -> {TreeCases[And] -> LightRed,
TreeCases[Or] -> LightBlue, TreeCases[_Equal] -> LightGreen,
TreeCases[_Unequal] -> LightYellow}, AspectRatio -> 1]

exprTree[expr]


expr//.{eq_Equal:>ToString[eq,StandardForm],neq_Unequal:>ToString[neq,StandardForm]}


@Domen has provided an answer based on tree manipulation. Here my idea is to "atomize" the equations. Besides the ToString method, we can also atomize the equations with some undocumented functions.

c_wrap /; SystemPrivateHoldNotValidQ[c] := (
SystemPrivateHoldSetValid[c];
SystemPrivateHoldSetNoEntry[c]
);

get[wrap[data_]]:=
data;

wrap/:MakeBoxes[c_wrap,format_]:=
With[{data=get[c]},MakeBoxes[data,format]];

expr/.{eq:_Equal|_Unequal:>wrap[eq]}//ExpressionTree


This method does not work for TreeForm comparing with ToString since my format definition wrap/:... does not handle tree forms.