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] *)
IntSign = Integrate[Sign[1 - xp], {xp, 0, x}, Assumptions -> x > 0]
? $\endgroup$Integrate[Sign[1 - xp], {xp, 0, x}, Assumptions -> x > 1]
,Out-> 2-x
orIntegrate[Sign[1 - xp], {xp, 0, x}, Assumptions -> -2 < x < 2]
$\endgroup$