# How to unfolding (expand) logical expression?

How to expand the following expression

(b == 0 || b == \[Pi] ) && (a == 0 || a == \[Pi])) || (3 a == 2 \[Pi] &&
3 b == 4 \[Pi]) || (3 a == 4 \[Pi] && 3 b == 2 \[Pi])


to the following solutions?

b=0,a=0
b=0,a=\pi
b=\pi,a=0
b=\pi,a=\pi
b=2\pi/4,a=2\pi/3
b=2\pi/3,a=2\pi/4


I tried the function LogicalExpand, but it gives me False.

Could anyone help? Thanks!

• Use Reduce. But you'll need to fix your code. There's an extra ) in (a == 0 || a == \[Pi])) and \Pi needs to be changed to Pi or \[Pi].
– JimB
Feb 12, 2022 at 16:07
• @JimB Thanks! Reduce[((b == 0 || b == \[Pi]) && (a == 0 || a == \[Pi])) || (3 a == 2 \[Pi] && 3 b == 4 \[Pi]) || (3 a == 4 \[Pi] && 3 b == 2 \[Pi])] still gives false..
– M.K
Feb 12, 2022 at 16:11
• You must have had previous assignments to a and/or b (which is what @BobHanlon 's answer with Clear["Global*"] fixes).
– JimB
Feb 12, 2022 at 16:47
• @JimB It works! Thank you so much!
– M.K
Feb 12, 2022 at 20:37

## 2 Answers

Clear["Global*"]

expr = ((b == 0 || b == π) && (a == 0 || a == π)) || (3 a == 2 π &&
3 b == 4 π) || (3 a == 4 π && 3 b == 2 π);

rules = {(val_ == n_*sym_Symbol) :> (sym == val/n),
(val_ == sym_Symbol) :> sym == val};

ReverseSort /@ ((List @@ (List @@@ (expr // LogicalExpand)) /. rules))

(* {{b == 0, a == 0}, {b == π, a == 0}, {b == 0, a == π}, {b == π,
a == π}, {b == (4 π)/3, a == (2 π)/3}, {b == (2 π)/3,
a == (4 π)/3}} *)


Alternatively,

ReverseSort /@ ((expr // LogicalExpand) /. {Or -> List, And -> List} /. rules)

(* {{b == 0, a == 0}, {b == π, a == 0}, {b == 0, a == π}, {b == π,
a == π}, {b == (4 π)/3, a == (2 π)/3}, {b == (2 π)/3,
a == (4 π)/3}} *)

% === %%

(* True *)

ClearAll[reOrg]

reOrg = ReplaceAll[Or | And -> List] @* Map[Reduce[#, {b, a}] &];


Example:

ClearAll[a, b, expr]

expr = ((b ==  0 || b == π) && (a == 0 || a == π)) ||
(3 a == 2 π && 3 b == 4 π) || (3 a == 4 π && 3 b == 2 π);

reOrg @ expr

{{b == 0, a == 0}, {b == 0, a == π}, {b == π, a == 0}, {b == π, a == π},
{b == (4 π)/3, a == (2 π)/3}, {b == (2 π)/3, a == (4 π)/3}}

TeXForm @ Column @ %


$$\begin{array}{l} \{b=0,a=0\} \\ \{b=0,a=\pi \} \\ \{b=\pi ,a=0\} \\ \{b=\pi ,a=\pi \} \\ \left\{b=\frac{4 \pi }{3},a=\frac{2 \pi }{3}\right\} \\ \left\{b=\frac{2 \pi }{3},a=\frac{4 \pi }{3}\right\} \\ \end{array}$$