# Correcting HeavisideTheta in MM11.3 for generating the same results with UnitStep in MM5.2

The UnitStep was replaced with the HeavisideTheta after the version 6.0 (reference here), but some differences confused me between the old and the new version as the follows (For convenience, the f[x] is simplified). I want to know how to correct the HeavisideTheta in the Mathematica V11.3 for generating the same results with UnitStep in MM5.2. For the problem, I have proposed some methods( here and here), but which didn't give the result I want. Thanks.

Code in V11.3

f[x_] := 1;
Integrate[f[x]*HeavisideTheta[x], {x, 0, ∞}]
Integrate[f[x]*HeavisideTheta[x], {x, -∞, ∞}]
Integrate[f[x]*D[HeavisideTheta[x], x], {x, 0, ∞}]
Integrate[
f[x]*D[HeavisideTheta[x], x], {x, -∞, ∞}]


Code in V5.2

f[x_]:=1;
Integrate[f[x]*UnitStep[x],{x,0,∞}]
Integrate[f[x]*UnitStep[x],{x,-∞,∞}]
Integrate[f[x]*D[UnitStep[x],x],{x,0,∞}]
Integrate[f[x]*D[UnitStep[x],x],{x,-∞,∞}]


The results in V11.3

The results in V5.2

• In 3rd example, what you need seems to be HeavisideTheta[0] == 1/2, but you mentioned you want HeavisideTheta[0] to be 1 here. Does your goal change? Or this is a special case? Commented May 11, 2020 at 4:05
• BTW, it's worth mentioning that the behavior of UnitStep in v5.2 is inconsistent, f[Infinity] UnitStep[Infinity] - f[0] UnitStep[0] - Integrate[f'[x] UnitStep[x], {x, 0, Infinity}] gives 0. Commented May 11, 2020 at 7:13
• @xzczd, Thanks for your attention. I wanted HeavisideTheta[0] to be 1, because UnitStep[0]=1 in V5.2 (you can check it through the help document of V5.2), I just want to realize the function of UnitStep in V5.2 by using the HeavisideTheta inV11.3 (HeavisideTheta, no value in 0 point). But today, this time, the 3rd example show us that HeavisideTheta[0] should be 1/2, they will give the same result. In a word, on the one hand, HeavisideTheta[0] should be 1 because UnitStep[0]=1 in V5.2, on the other hand, HeavisideTheta[0] should be 1/2 because the 3rd example. Commented May 11, 2020 at 12:07
• Well, as pointed out in my last comment, the design of UnitStep in v5.2 is self-contradictory. If your legacy code has made use of such feature, then things become a little troublesome. It's not too hard to find work-around for this 4 examples, but I doubt if the solution can be extended to more general cases. Do you have something, say, a complete summarization of the feature of UnitStep in v5.2? Or perhaps you can show a bigger example indicating what exactly you're trying to do? Commented May 12, 2020 at 1:28
• I'm sorry, but it's my stupid insistence that I only discuss Mathematica in public. And, honestly speaking, I'm not in the mood to solve extremely localized problem, either. Commented May 13, 2020 at 1:43

Here's my work-around. Not sure if it can be applied to your real problem, but it can at least help you to construct a sample closer to your real problem, I think.

We define the following 2 functions:

ClearAll[unitStep, v52]

SetAttributes[v52, HoldAll]
v52[expr_Integrate] :=
Check[expr /. HeavisideTheta[0] -> 1/2, ∞ NIntegrate @@ Unevaluated@expr //
Quiet, Integrate::idiv]

SetAttributes[unitStep, Listable]
unitStep[x_?NumericQ] = UnitStep[x];
unitStep[x_] = HeavisideTheta[x];


v52 is a function only for Integrate[…], once idiv warning is generated, it replaces the output with ±∞, and any HeavisideTheta[0] generated by Integrate will be replaced by 1/2.

unitStep is equivalent to UnitStep for numeric inputs, and equivalent to HeavisideTheta for symbolic inputs.

Some examples:

unitStep[{-1, 1, 0}]
(* {0, 1, 1} *)

unitStep'[x]
(* DiracDelta[x] *)

v52@Integrate[f[x] unitStep[x], {x, 0, ∞}]

(* Integrate::idiv *)
(* ∞ *)

v52@Integrate[-f[x] unitStep[x], {x, 0, ∞}]

(* Integrate::idiv *)
(* -∞ *)

v52@Integrate[f[x] unitStep[x], {x, -∞, ∞}]

(* Integrate::idiv *)
(* ∞ *)

v52@Integrate[-f[x] unitStep[x], {x, -∞, ∞}]

(* Integrate::idiv *)
(* -∞ *)

v52@Integrate[f[x] D[unitStep[x], x], {x, 0, ∞}]
(* 1/2 *)

v52@Integrate[f[x] D[unitStep[x], x], {x, -∞, ∞}]
(* 1 *)

• Thanks for your solution. Commented Jun 17, 2020 at 10:07