Use both values of $\pm$ in equations
The following function performs the transformation I've suggested in the comments:
Options[PMReduce] = {"SynchronizePM" -> False};
PMReduce[eqns_, vars_, dom_: Complexes, OptionsPattern[]] := Module[
{
pEqns,
params,
i = 0,
step = Boole[! OptionValue@"SynchronizePM"]
}, {pEqns, params} = Reap[
Flatten@{eqns} //. {
(a_ ± b_) :> (a + Sow[C[i += step]] b),
(a_ ∓ b_) :> (a - Sow[C[i += step]] b)
}
];
Reduce[
Append[
pEqns,
And @@ (# == 1 || # == -1 & /@ First@params)
],
vars,
dom
]
]
The "SynchronizePM"
option controls whether the ±
should be changed synchronously (i.e. a±b±c
to a+b+c||a-b-c
)
Examples:
PMReduce[Abs[x ± 2] ± 3 == 0, x, Reals]
(* (C[1] == -1 && C[2] == -1 && x == -1)
|| (C[1] == -1 && C[2] == -1 && x == 5)
|| (C[1] == -1 && C[2] == 1 && x == -5)
|| (C[1] == -1 && C[2] == 1 && x == 1) *)
PMReduce[Abs[x ± 2] ± 3 == 0, x, Reals, "SynchronizePM" -> True]
(* (C[0] == -1 && x == -1)
|| (C[0] == -1 && x == 5) *)
I may need to give this more thought but it seems to me you actually want Or
.
For example:
a_: 0 ± n_ := a - n || a + n
Solve[x ± 2 == 0, x]
Solve[Abs[x ± 2] ± 3 == 0, x]
{{x -> -2}, {x -> 2}} {{x -> -5}, {x -> -1}, {x -> 1}, {x -> 5}}
In light of your edit to include Plot
we could either allow the expansion above and modify Plot
to operate on Or
, or we could modify both Solve
and Plot
(etc.) to specially handle ±
. Doing my best to read between the lines I think you prefer the latter, so I'll illustrate that.
ClearAll[PlusMinus]
Plot;
Unprotect[Plot];
PrependTo[DownValues[Plot],
HoldPattern[Plot[expr_, arg___]] /; ! TrueQ[$plotPlusMinus] :>
Block[{$plotPlusMinus = True},
Plot[#, arg] &[expr //. a_: 0 ± n_ :> {a - n, a + n}]
]
];
Protect[Plot];
Plot[x + Sin[±x] ± 1/2, {x, 0, 8}]
Notes
This assumes the plot function is composed of Listable functions; if that does not hold manual threading can be added, but I first want to know if this is moving in a direction that pleases you or not.
I did not localize the Plot variable(s). That can be done but again I first want to know if this is going to be useful.
Little improving magnificent code from user Lukas Lang:
SOLVE[eqns_, vars_, dom_: Complexes] := {{ToRules[Module[{pEqns, params, i = 0}, {pEqns, params} =
Reap[Flatten@{eqns} //. (a_ \[PlusMinus] b_) :> (a + Sow[f[i++]] b)];
Reduce[Append[pEqns, And @@ (# == 1 || # == -1 & /@ First@params)], vars, dom]]]}[[All, -1]]}
SOLVE[x ± 2 == 0, x]
(* {{x -> 2, x -> -2}} *)
SOLVE[Abs[x ± 2] ± 3 == 0, x, Reals]
(* {{x -> -1, x -> 5, x -> -5, x -> 1}} *)