# Split plus or minus into list [duplicate]

I would like

x= 2 \[PlusMinus] Sqrt[3]


to evaluate to

{x=2+Sqrt[3],x=2-Sqrt[3]}


Including any number of plus or minus symbols, so

x=(2 \[PlusMinus] Sqrt[3]) \[PlusMinus] 3


would evaluation to

{x=5+Sqrt[3],x=5-Sqrt[3],x=-1+Sqrt[3],x=-1-Sqrt[3]}


Any ideas?

Thanks

Does this work in every case you can think of?

Flatten[{2 \[PlusMinus] Sqrt[3],a \[PlusMinus] 4,
a \[PlusMinus] b \[PlusMinus] q}//.h__ \[PlusMinus] t__->{h+t,h-t}]


which returns

{2+Sqrt[3],2-Sqrt[3],4+a,-4+a,a+b+q,a-b+q,a+b-q,a-b-q}]


The h__ matches everything before \[PlusMinus], the t__ matches everything after, and the //. repeatedly turns any item that matches into two items until it is done and finally the Flatten discards any introduced { and }.

Preserving the x= in the output is a different issue and is trying to avoid the usual evaluation process. I don't see a simple way of doing that in every case. Perhaps someone else can show a clever way of doing that.

ClearAll[expandPlusMinus]
expandPlusMinus = Flatten @* ReplaceAll[PlusMinus -> ({+##, # - #2} &)];


Examples:

2 ± Sqrt[3] // expandPlusMinus

{2 + Sqrt[3], 2 - Sqrt[3]}

(2 ± Sqrt[3]) ± 3 // expandPlusMinus

{5 + Sqrt[3], 5 - Sqrt[3], -1 + Sqrt[3], -1 - Sqrt[3]}

2 ± Sqrt[3] // expandPlusMinus // Map[PromptForm[x, #] &]


(2 ± Sqrt[3]) ± 3 // expandPlusMinus //  Map[PromptForm[x, #] &]


Alternatively,

ClearAll[expandPlusMinus2]
expandPlusMinus2 = Block[{PlusMinus = Flatten@Through[{Plus, Subtract}@##] &}, #] &;


Examples:

2 ± Sqrt[3] // expandPlusMinus2

{2 + Sqrt[3], 2 - Sqrt[3]}

(2 ± Sqrt[3]) ± 3 // expandPlusMinus2

{5 + Sqrt[3], 5 - Sqrt[3], -1 + Sqrt[3], -1 - Sqrt[3]}