# How to Refine HeavisideTheta or UnitStep?

Look at the following chunk of code:

Assuming[x > 0, Refine@HeavisideTheta[x]]


It yields 1. However the same method does not work if x is an expression. The following commands returns the HevisideTheta unevaluated:

Refine[HeavisideTheta[V^2 - (χa - χr)^2/(a + r)^2],
V^2 - (χa - χr)^2/(a + r)^2 > 0]

Assuming[V^2 - (χa - χr)^2/(a + r)^2 > 0,
Refine@HeavisideTheta[V^2 - (χa - χr)^2/(a + r)^2]]


Simplify also does not work. Is it possible to evaluate this and similar expressions?

Update I found a remedy that solves all my problems. Here it is:

c2Mono = Reduce[{V > 0, V^2 - (χa - χr)^2/(a + r)^2 > 0,
r > a > 0, χr > χa}, χr]
n2Mono = ....;

UnitRule = {(HeavisideTheta[x_] | UnitStep[x_]) ->
Piecewise[{{1, x > 0}, {0, x < 0}}]}

n2Mono = FullSimplify[PiecewiseExpand[n2Mono /. UnitRule], c2Mono]
j2Mono = FullSimplify[PiecewiseExpand[j2Mono /. UnitRule], c2Mono]


### 1. Modify "AssumptionsMaxNonlinearVariables"

If you set the option value for "AssumptionsMaxNonlinearVariables" (which is a sub-option of the system option "SimplificationOptions") to a number larger than the number of variables in your input expression (say, 10) you get the desired simplification:

SetSystemOptions["SimplificationOptions" -> {"AssumptionsMaxNonlinearVariables" -> 10}];

FullSimplify[HeavisideTheta[V^2 - (χa - χr)^2/(a + r)^2], V^2 - (χa - χr)^2/(a + r)^2 > 0]


1

FullSimplify[UnitStep[V^2 - (χa - χr)^2/(a + r)^2], V^2 - (χa - χr)^2/(a + r)^2 > 0]


1

You can replace FullSimplify with Refine and get the same results:

Refine[HeavisideTheta[V^2 - (χa - χr)^2/(a + r)^2], V^2 - (χa - χr)^2/(a + r)^2 > 0]


1

Refine[UnitStep[V^2 - (χa - χr)^2/(a + r)^2], V^2 - (χa - χr)^2/(a + r)^2 > 0]


1

The default value for this sub-option is 4:

SystemOptions["Simp*"]


{"SimplificationOptions" -> {"AssumptionsMaxExponent" -> 25, "AssumptionsMaxNonlinearVariables" -> 4, "AssumptionsMaxVariables" -> 21, "AutosimplifyTrigs" -> True, "AutosimplifyTwoArgumentLog" -> True, "ConvertTrigsToRadicals" -> False, "FiniteSumMaxTerms" -> 30, "FunctionExpandMaxSteps" -> 15, "ListableFirst" -> True, "RestartELProver" -> False, "SimplifyMaxExponents" -> 100, "SimplifyToPiecewise" -> True}}

To reset the option to its default:

SetSystemOptions["SimplificationOptions" -> {"AssumptionsMaxNonlinearVariables" -> 4}]


### 2. Use PiecewiseExpand:

For UnitStep, PiecewiseExpand using assumptions in the second argument works:

PiecewiseExpand[UnitStep[V^2 - (χa - χr)^2/(a + r)^2], V^2 - (χa - χr)^2/(a + r)^2 > 0]


1

For HeavisideTheta it does not:

PiecewiseExpand[HeavisideTheta[V^2 - (χa - χr)^2/(a + r)^2],
V^2 - (χa - χr)^2/(a + r)^2 > 0]


HeavisideTheta[V^2 - (χa - χr)^2/(a + r)^2]

So a simple approach is to replace the head HeavisideTheta with UnitStep before

PiecewiseExpand[# /. HeavisideTheta -> UnitStep, V^2 - (χa - χr)^2/(a + r)^2 > 0] & @
HeavisideTheta[V^2 - (χa - χr)^2/(a + r)^2]


1