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

enter image description here

The results in V5.2

enter image description here

xzczd
  • 65,995
  • 9
  • 163
  • 468
likehust
  • 693
  • 3
  • 8
  • 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? – xzczd May 11 '20 at 04: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. – xzczd May 11 '20 at 07: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. – likehust May 11 '20 at 12:07
  • 2
    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? – xzczd May 12 '20 at 01:28
  • @xzczd can you sent an email to likeleetemp(AT)gmail(DOT)com ? I want to sent my code's file to your email, it's not convenient to paste here because the codes are too large. – likehust May 13 '20 at 00:19
  • 1
    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. – xzczd May 13 '20 at 01:43
  • Just checked in v5.0, the first 2 examples all give Integrate::idiv warning and return unevaluated so I can't check further, but I wonder what's the output of Integrate[-UnitStep[x],{x,0,∞}] and Integrate[-UnitStep[x],{x,-∞,∞}] in v5.2? – xzczd May 13 '20 at 02:01
  • @xzczd, thanks. Integrate[-UnitStep[x],{x,0,∞}] gives -∞ , and Integrate[-UnitStep[x],{x,-∞,∞}] gives Integrate::idiv: Integral of UnitStep[x] does not converge on {-∞,∞}, -∞. Hope it helps you find the answer. – likehust May 13 '20 at 03:17

1 Answers1

3

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 *)
xzczd
  • 65,995
  • 9
  • 163
  • 468