I want to create a function in Mathematica which accomplishes the following:

$$[f(a,b,c)]^+_- = f(a^+,b^+,c^+)-f(a^-,b^-,c^-)$$

where $f$ is any function (has 3 arguments above but this need not be the case) and $a,b,c$ are arguments (though there may be more). I am dealing with some boundary conditions across interfaces which require me to evaluate "jumps" in discontinuous quantities.

What I would like to do is something that accomplishes the following, returning symbolic variables which can be used later:

  • $[\mu]^+_-=\mu^+-\mu^-$
  • $\left[\frac{1}{\mu}\right]^+_-=\frac{1}{\mu^+}-\frac{1}{\mu_-}$
  • $\left[\frac{ab^2}{\sqrt{c}}\right]^+_-=\frac{a^+{b^+}^2}{\sqrt{c^+}}-\frac{a^-{b^-}^2}{\sqrt{c^-}}$

I want to be able to input any expression inside the brackets (although in this case the expression will be called as an argument to a function) and this expression needs to have an arbitrary number of variables. It would also be highly desirable this could be done entry-wise to a vector whose entries are expressions (themselves each of an arbitrary number of variables).

A bit of research tells me that the Map function might do what I want, but I'm not yet skilled enough in Mathematica to implement it properly. Could somebody point me into the right direction?

I have found something which does what I want but I am having trouble converting it into a function. Think of the subscript $v^+$ and $l$ as taking place of the $+$ and $-$ as above.

enter image description here

Two more things I want to accomplish:

  • How can I write this as a function which takes any algebraic expression and returns an analogous result?
  • How can I make sure that it is the variable that is subscripted rather than the expression in each case (e.g. I want $\frac{1}{\sqrt{c_{v^+}}}$ not $\frac{1}{\sqrt{c}}_{v^+}$).
  • $\begingroup$ What do e.g. $a^+$ and $a^-$ mean? $\endgroup$
    – MarcoB
    Dec 4, 2019 at 1:20
  • $\begingroup$ They mean the value of $a$ above and below some interface respectively. It's not actually a calculation I am after, just a generation of two symbolic variables. $\endgroup$
    – user68730
    Dec 4, 2019 at 16:04

3 Answers 3


Interpreting your $a^+$ and $a^-$ as limits from above and below, (and in one dimension), this function takes the limit from above and from below and then takes the difference:

jump[q_, x_, val_] := Limit[q[x], x -> val, Direction -> "FromAbove"] - 
                      Limit[q[x], x -> val, Direction -> "FromBelow"]

So for example, say we have a discontinuous function:

q[x_] := Piecewise[{{x^2, x < 0}, {x + 1, x > 0}}];
Plot[q[x], {x, -2, 2}]

enter image description here

Then we can evaluate at points of continuity and get zero, or evaluate at points of discontinuity, and get the size of the jump:

{jump[q, x, -1], jump[q, x, 0], jump[q, x, 1]}
{0, 1, 0}

Does this do what you want? Are you looking for additional formatting of input or output?

Attributes[jump] = HoldFirst;
jump[fn_[args__]] := fn[args] - fn @@ -{args}

jump[f[a, b, c]]
-f[-a, -b, -c] + f[a, b, c]

Following your update please try this and report its utility. Parameters f and g can be changed to whatever symbol modifier you please.

jump[f_, g_][expr_] := 
 Subtract @@ (expr /. {{v : # :> f@v}, {v : # :> g@v}}) &[
  Alternatives @@ Variables[expr]]

jump[Subscript[#, v] &, Subscript[#, l] &][a b^2/Sqrt[c]]

Output as $LaTeX$:

$\frac{a_v b_v^2}{\sqrt{c_v}}-\frac{a_l b_l^2}{\sqrt{c_l}}$

  • $\begingroup$ Not quite. As strange as it seems, what I am after is more of a symbolic generation than a calculation, so a, b and c don't strictly need to be taken to be positive as above. $\endgroup$
    – user68730
    Dec 4, 2019 at 16:12

I've found a solution which does what I want.

VLJump [expr_] := 
   Map[# -> Subscript[#, SuperPlus[v]] &, Variables[expr]]] - 
  ReplaceAll[expr, Map[# -> Subscript[#, l] &, Variables[expr]]]

enter image description here


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.