5
$\begingroup$

How do I evaluate and expand an expression containing PlusMinus such that:

N[PlusMinus[1, 1]]

returns

2, 0

I'm stuck at PlusMinus[1, 1] giving me 1 \[PlusMinus] 1 ($1 \pm 1$) which is not very helpful for when I'm trying to evaluate larger equations in decimal form.

Are there scalable alternatives?


Edit: I don't have to use N[ ], a different function is perfectly fine (as long as I get a decimal answer).

$\endgroup$
7
  • 2
    $\begingroup$ PlusMinus[1, 1] /. PlusMinus[a_, b_] :> {a + b, a - b} $\endgroup$
    – Syed
    May 14 at 6:18
  • $\begingroup$ @Syed Thank you, that is exactly what I'm after. Feel free to post that as an answer and I will mark it as correct $\endgroup$ May 14 at 6:21
  • 2
    $\begingroup$ With v12.0 or later, use Around[1, 1] $\endgroup$
    – Bob Hanlon
    May 14 at 6:23
  • 2
    $\begingroup$ I will request Bob Hanlon to write an answer about using PlusMinus and Around as I don't know much about Around at this point. $\endgroup$
    – Syed
    May 14 at 6:35
  • 1
    $\begingroup$ Around is what I'd recommend too, if you're managing uncertainty. You can also easily convert an Around expression into an Interval by just prefixing it (Interval[Around[1,1]]), and Intervals can be used in nice ways too—see the help docs. To do what you want to do here, you could do MinMax[Interval[Around[1,1]]]. (You could also streamline this by defining e.g. extrema[a_Around] := MinMax[Interval[a]].) $\endgroup$
    – thorimur
    May 14 at 6:49

1 Answer 1

7
$\begingroup$
Clear["Global`*"]

a = Around[1, 1]

enter image description here

a == Around[NormalDistribution[1, 1]]

(* True *)

b = Around[3, 1]

enter image description here

b == Around[NormalDistribution[3, 1]]

(* True *)

a + b

enter image description here

Compare with

dist = TransformedDistribution[a2 + b2,
   {a2 \[Distributed] NormalDistribution[1., 1.],
    b2 \[Distributed] NormalDistribution[3., 1.]}];

#[dist] & /@ {Mean, StandardDeviation}

(* {4., 1.41421} *)

EDIT: As recommended by @thorimur, if the purpose is not to represent uncertainty, then use Interval

a = Interval@Around[1., 1.] // Chop

(* Interval[{0, 2.}] *)

MinMax@a

(* {0, 2.} *)

b = Interval@Around[3., 1.]

(* Interval[{2., 4.}] *)

MinMax@b

(* {2., 4.} *)

c = IntervalUnion[a, b]

(* Interval[{0, 4.}] *)

MinMax@c

(* {0, 4.} *)

d = a + b

(* Interval[{2., 6.}] *)

MinMax@d

(* {2., 6.} *)

Or use CenteredInterval

a = CenteredInterval[1., 1.]

enter image description here

Information[a, "Bounds"] // N

(* {-1.86265*10^-9, 2.} *)

b = CenteredInterval[3., 1.]

enter image description here

Information[b, "Bounds"] // N

(* {2., 4.} *)

c = IntervalUnion[a, b]

enter image description here

Information[c, "Bounds"] // N

(* {-7.45058*10^-9, 4.} *)

d = a + b

enter image description here

Information[d, "Bounds"] // N

(* {2., 6.} *)
$\endgroup$
1
  • 1
    $\begingroup$ I'll note that in terms of the original question ("evaluating" plus-or-minus), OP specifically seems to want e.g. MinMax@Interval@Around[1,1] so as to give {0,2}. $\endgroup$
    – thorimur
    May 14 at 22:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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