I have an expression that involves many Sign
functions. I want to expand this in the piecewise format.
My function is:
exp = 2 Sign[t] (1/2 (-1 + e) - 1/2 (1 + e) Sign[t]) + (1/2 (-1 + e1) +
1/2 (1 + e1) Sign[d - t1]) (-1 + Sign[t1]) - (1/2 (-e + e1) +
1/2 (e + e1) Sign[d + t - t1]) (-1 +
Sign[-t + t1]) - (1/2 (-1 + e2) + 1/2 (1 + e2) Sign[d - t2]) (-1 +
Sign[t2]) + (1/2 (-e + e2) + 1/2 (e + e2) Sign[d + t - t2]) (-1 +
Sign[-t + t2]) +
2 (1/2 (-e1 + e2) + 1/2 (e1 + e2) Sign[t1 - t2]) Sign[-t1 + t2]
Here, all variables can be regarded as real.
Using the answer provided in Converting HeavisideTheta[]s and Sign[]s functions to a single Piecewise[], I also borrow a user-defined function:
ToPiecewise[f_] :=
PiecewiseExpand[
f /. {Sign[x_] :> Piecewise[{{1, x >= 0}, {-1, x < 0}}]}]
What I want to eavluate is
ToPiecewise[exp]
but this is extremely slow! (Furthermore, aborting (Alt + .) does not work and I had to quit the kernel.) Surprisingly, if I consider a single term, for example the first one and evaluate
ToPiecewise[2 Sign[t] (1/2 (-1 + e) - 1/2 (1 + e) Sign[t])]
then the answer comes immediately. This happens for all other single terms. Why this strange behavior happen?