Mathematica Mathematica : Plus Minus Evaluation

  • Thread starter Thread starter Hepth
  • Start date Start date
  • Tags Tags
    Mathematica
Hepth
Science Advisor
Gold Member
Messages
457
Reaction score
40
If I have :

(1 \[PlusMinus] 5) * 5

I want it to read

5 \[PlusMinus] 25


Does anyone know how to get it to evaluate those?

Then get to expand multiple terms with plus minuses in them, and ultimately get a min and max of the value. Such as :

(a +- b)(c+-d)/(e+-f)

where all values are positive real.
 
Physics news on Phys.org
Since PlusMinus[a_, b_] does not have a built-in meaning, you have to define it.
You can use the TagSetDelayed function for this:
Code:
PlusMinus /: (a_ \[PlusMinus] b_)*c_ := (a*c) \[PlusMinus] (b*c)
The "PlusMinus /:" at the start of the line indicates that this definition is not telling you anything about the head of the expression (if you left it out you would be trying to re-define multiplication in a rather silly way) but that the definition is a statement about the function PlusMinus.
You can check the result using
Code:
UpValues[PlusMinus]
and test it with
Code:
(1 \[PlusMinus] 5)*3
3 (1 \[PlusMinus] 5)

Note however, that this may have unintended consequences, e.g.
Code:
(1 \[PlusMinus] 3)*(5 \[PlusMinus] 3)
will now apply the rule with a = 1, b = 3 and c = 5 \[PlusMinus] 3 and give you something you did not probably mean.

You can work around this using fixes like (note: if you try this, quit your kernel, otherwise the definition above will take precedence)
Code:
NoPlusMinus := FreeQ[#, PlusMinus] &
PlusMinus /: (a_?NoPlusMinus \[PlusMinus] b_?NoPlusMinus)*c_?NoPlusMinus := (a*c) \[PlusMinus] (b*c)
which will only apply the rule if a, b and c are free of PlusMinus'es themselves, but that quickly gets very tricky and if you try hard enough you can probably always find an expression to produce undesired results.
 
Last edited:
I think I got something to work using :
PM[a_, b_] := Interval[{a - b, a + b}]

Then using max/min after all calculations to get the limits. Thanks though!
 

Similar threads

  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 6 ·
Replies
6
Views
4K
  • · Replies 3 ·
Replies
3
Views
3K
  • · Replies 5 ·
Replies
5
Views
8K
  • · Replies 6 ·
Replies
6
Views
5K
  • · Replies 52 ·
2
Replies
52
Views
13K
  • · Replies 1 ·
Replies
1
Views
6K
  • · Replies 30 ·
2
Replies
30
Views
7K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 4 ·
Replies
4
Views
8K