Possible Bug in Integrate of sign function?

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}]


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

Note this is version 11.3

• is it still wrong result if you do IntSign = Integrate[Sign[1 - xp], {xp, 0, x}, Assumptions -> x > 0] ? – Nasser Jun 6 '18 at 8:25
• No in this case it gives the correct result. Now the question is why mathematica gives the wrong result without that extra assumption. – Michael Jun 6 '18 at 8:29
• Possibly a bug, I think – t-smart Jun 6 '18 at 10:07
• 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] – Mariusz Iwaniuk Jun 6 '18 at 11:45

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] *)

• Thank you this is very clear this way. Great! – Michael Jun 26 '18 at 4:52