Mathematica : Plus Minus Evaluation

  • Mathematica
  • Thread starter Hepth
  • Start date
  • Tags
    Mathematica
In summary, the conversation discusses how to define the PlusMinus function in order to expand multiple terms with plus minuses and ultimately get the minimum and maximum values. A solution is proposed using the TagSetDelayed function and the NoPlusMinus fix to avoid unintended consequences. Another potential solution is using the PM function, which takes two values and returns an interval containing the minimum and maximum values.
  • #1
Hepth
Gold Member
464
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
  • #2
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:
  • #3
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!
 

1. What is the purpose of plus minus evaluation in Mathematica?

The plus minus evaluation in Mathematica allows for the simultaneous calculation of both the positive and negative values of a given expression. This is useful for generating multiple solutions to equations or for exploring the behavior of functions.

2. How is plus minus evaluation denoted in Mathematica?

In Mathematica, the plus minus symbol is denoted by the character "±" or by using the keyboard shortcut "Esc+ - Esc". It can also be represented by the function PlusMinus[x], where x is the expression to be evaluated.

3. Can plus minus evaluation be applied to any expression in Mathematica?

Yes, plus minus evaluation can be applied to any expression in Mathematica, including numbers, variables, and functions. However, it is important to note that the results may differ depending on the type of expression and the underlying rules and assumptions used by Mathematica.

4. How does Mathematica handle plus minus evaluation for complex numbers?

Mathematica follows the standard rules of complex arithmetic for plus minus evaluation, where the plus minus symbol is distributed to both the real and imaginary parts of a complex number. For example, PlusMinus[3+2I] would return {3+2I, 3-2I} as the two possible solutions.

5. Are there any limitations to using plus minus evaluation in Mathematica?

One limitation of plus minus evaluation is that the results may not be accurate for certain complex or highly nonlinear expressions. In such cases, it may be necessary to use other methods or techniques to obtain more precise solutions.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
256
  • MATLAB, Maple, Mathematica, LaTeX
Replies
6
Views
2K
  • Computing and Technology
Replies
4
Views
758
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
8K
  • Precalculus Mathematics Homework Help
Replies
1
Views
823
  • Calculus and Beyond Homework Help
Replies
6
Views
2K
  • Electrical Engineering
Replies
4
Views
817
Replies
3
Views
1K
  • Calculus and Beyond Homework Help
Replies
5
Views
1K
Back
Top