2
$\begingroup$

When integrating the Sign function mathematica seems to give me a wrong result

IntSign = (Integrate[Sign[1 - xp], {xp, 0, x}])
Plot[{Sign[1 - x], IntSign}, {x, 0, 2}]

In orange the integral and in blue the sign function itself

Why is mathematica calculating this wrong? Or is this my fault?

Note this is version 11.3

$\endgroup$
  • 2
    $\begingroup$ is it still wrong result if you do IntSign = Integrate[Sign[1 - xp], {xp, 0, x}, Assumptions -> x > 0] ? $\endgroup$ – Nasser Jun 6 '18 at 8:25
  • $\begingroup$ No in this case it gives the correct result. Now the question is why mathematica gives the wrong result without that extra assumption. $\endgroup$ – Michael Jun 6 '18 at 8:29
  • 1
    $\begingroup$ Possibly a bug, I think $\endgroup$ – t-smart Jun 6 '18 at 10:07
  • 4
    $\begingroup$ It's not a bug,Try: Integrate[Sign[1 - xp], {xp, 0, x}, Assumptions -> x > 1] , Out-> 2-x or Integrate[Sign[1 - xp], {xp, 0, x}, Assumptions -> -2 < x < 2] $\endgroup$ – Mariusz Iwaniuk Jun 6 '18 at 11:45
5
$\begingroup$

Integrate does not seem to be producing a great answer in this case. I will pass this along to the relevant team for further investigation to see if we can't improve it.

But the first answer is not wrong, in general. Note that while Sign is often defined as a piecewise function on the reals, in Mathematica it is a function on the complexes, essentially x/Abs[x]. This means it is nowhere differentiable, and therefore not easily integrable, either (the result is contour-dependent). Since in your original input you provided no conditions on x, Integrate attempted to give you an answer valid in some part of the complex plane, and end up with one that is discontinuous. If you just tell Integrate that x is real, it will give you a continuous answer:

Integrate[Sign[1 - xp], {xp, 0, x}, Assumptions -> Element[x, Reals]]
(* Piecewise[{{2 - x, x > 1}, {x, Inequality[0, Less, x, LessEqual, 1] || x  < 0}}, 0] *)

An even easier solution to start out by telling integrate you live in the real world by using RealSign. RealSign is equal to Sign on the reals, but undefined for complex inputs, allowed many automatic simplications to take place. For example:

Integrate[RealSign[1 - xp], {xp, 0, x}]
(* 1 + Piecewise[{{1 - x, x > 1}}, -1 + x], which is continuous *)

Also:

D[RealSign[1 - xp], xp]
(* -Piecewise[{{0, 1 - xp != 0}}, Indeterminate] *)
$\endgroup$
  • $\begingroup$ Thank you this is very clear this way. Great! $\endgroup$ – Michael Jun 26 '18 at 4:52

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.