1
$\begingroup$

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!

$\endgroup$
4
  • 2
    $\begingroup$ 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]. $\endgroup$
    – JimB
    Feb 12, 2022 at 16:07
  • $\begingroup$ @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.. $\endgroup$
    – M.K
    Feb 12, 2022 at 16:11
  • $\begingroup$ You must have had previous assignments to a and/or b (which is what @BobHanlon 's answer with Clear["Global*"]` fixes). $\endgroup$
    – JimB
    Feb 12, 2022 at 16:47
  • $\begingroup$ @JimB It works! Thank you so much! $\endgroup$
    – M.K
    Feb 12, 2022 at 20:37

2 Answers 2

2
$\begingroup$
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 *)
$\endgroup$
1
$\begingroup$
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}$

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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