1
$\begingroup$

Is there a documentation for the function Simplify`PWToUnitStep? This is a function which can be used to express a Piecewise function as a sum of UnitStep functions. I used it in the following way (in the last line of the provided code):

hfun[h_, J1_, J2_] := Sign[h] (Abs[h] - (Abs[J2] - Abs[J1]))/2
Jfun[h_, J1_, J2_] := (Abs[J2] + Abs[J1] - Abs[h])/2
Field1Evolution[h_, J1_, J2_] := 
 Piecewise[{{Sign[h] J1, 
    Abs[J2] >= Abs[J1] && 
     Abs[h] >= Abs[J1] + Abs[J2]}, {Sign[J1] hfun[h, J1, J2], 
    Abs[J2] >= Abs[J1] && (Abs[J2] + Abs[J1]) > 
      Abs[h] && (Abs[J2] - Abs[J1]) < Abs[h]}, {0, 
    Abs[J2] >= Abs[J1] && (Abs[J2] - Abs[J1]) >= Abs[h]}, {Sign[h] J1,
     Abs[J1] > Abs[J2] && 
     Abs[h] >= Abs[J2] + Abs[J1]}, {Sign[J1] hfun[h, J1, J2], 
    Abs[J1] > Abs[J2] && (Abs[J2] + Abs[J1]) > 
      Abs[h] && (Abs[J1] - Abs[J2]) < Abs[h]}, {Sign[J1] h, 
    Abs[J1] > Abs[J2] && (Abs[J1] - Abs[J2]) >= Abs[h]}}]

Simplify`PWToUnitStep[Field1Evolution[h, J1, J2]]

but the output includes some terms like 1 - UnitStep[-Abs[J1] + Abs[J2]] instead of simply UnitStep[+Abs[J1] - Abs[J2]], I know that the two expressions are the same but I would like the second as output, for some reasons. Can someone help me in getting only terms with UnitStep instead of `1-Unitstep`?

$\endgroup$
5
  • 2
    $\begingroup$ Your premise is wrong. Take a look at the documentation of UnitStep: It is equal to $0$ for $x<0$ and $1$ for $x\geq0$. Hence 1 - UnitStep[x] is not equivalent to UnitStep[-x], because of the discontinuity at $x=0$: 1 - UnitStep[0] == 0 while UnitStep[-0] == 1. You can also take a look at this image to see the transformations that the undocumented (!) function Simplify`PWToUnitStep makes. $\endgroup$ Commented Apr 30, 2024 at 16:42
  • $\begingroup$ Oh thanks @Domen. You basically answered my question. For my purposes >= or > is the same, thus puttin >= or <= every time I had > or <, respectively, I would get UnitStep instead of 1-UnitStep. I am sorry for my error, thank again! $\endgroup$ Commented Apr 30, 2024 at 16:54
  • 1
    $\begingroup$ And Simplify`PWToUnitStep is undocumented, we have posts listing useful undocumented functions though: mathematica.stackexchange.com/a/133530/1871 $\endgroup$ Commented May 1, 2024 at 4:28
  • $\begingroup$ At least we may have a look at kitchen by ?"Simplify`*". Click on any of the entries in that long list, there is no documentation. $\endgroup$ Commented May 1, 2024 at 5:06
  • 3
    $\begingroup$ @RuthMurphy, note that you likely won't be able to completely avoid 1 - UnitStep, beacuse sooner or later you need the negation of $\geq$ or $\leq$, which leads to $<$ and $>$. Take a look at this example: s = Simplify`PWToUnitStep[Piecewise[{{1, a >= b}, {2, b >= c}}]]. The first term in the output represents $a \geq b$, but the second term correctly represents $a<b \wedge b\geq c$. If you blindly replace 1 - UnitStep[x] with UnitStep[-x], you will get wrong result for the edge cases: {s, s /. 1 - UnitStep[x_] :> UnitStep[-x]} /. {a -> 1, b -> 1, c -> 1} results in {1, 3}. $\endgroup$ Commented May 1, 2024 at 7:40

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.