# The UnitStep function and Intervals

For the input

UnitStep[Interval[{-4, 5}]]


I get

Interval[{0, 1}]


Why is this not Interval[{0,0}, {1,1}]?

• Because it is Listable (see Attributes@UnitStep) and can deal with real-valued intervals. This information can be easily found in documentation pages. – Artes Nov 3 '13 at 14:30
• I understand that, but your comment is suggesting an answer to my question: UnitStep is merely threading itself over the Interval, and doesn't "know" that it's an Interval that could result in a tighter interval result? Is that correct? – payne Nov 3 '13 at 15:23
• @MichaelE2 What do you mean by incorrect interval? UnitStep[Interval[{-Pi, Pi}]] yields Interval[{0, 1}], similarly Sin[Interval[{-Pi, Pi}]] yields Interval[{-1, 1}]. What is your problem? – Artes Nov 3 '13 at 17:11
• @Artes Isn't the range of UnitStep just the set {0, 1}? I thought that's what Interval[{0, 0}, {1, 1}] represents. Perhaps, I'm wrong, but that's how I understood it. Interval[{0,1}] represents all reals between 0 and 1. That's incorrect. – Michael E2 Nov 3 '13 at 17:23
• @Artes I don't think Listable has anything to do with the problem. Tan[Interval[{1, 2}]] returns disjoint intervals Interval[{-Infinity, Tan[2]}, {Tan[1], Infinity}]. If UnitStep worked correctly with Interval, UnitStep[Interval[{a, b}]] would return the range of values of UnitStep over that interval, either Interval[{0,0}], Interval[{1,1}], or Interval[{0,0}, {1,1}] depending on the signs of a and b. – Michael E2 Nov 3 '13 at 17:55

I think there is a bug with Interval. What I find for this moment:

$$\begin{array} {c|c|c|c} \text{Function} & \text{Interval} & \text{Result} & \text{Should be}\\ \hline \text{UnitStep} & [-4,5] & [0,1] & [0,0],[1,1]\\ \text{Sign} & [0,1] & [-1,1] & [0,0],[1,1]\\ \text{Round} & [0,2] & [0,2] & [0,0],[1,1],[2,2]\\ \text{Floor} & [0,2] & [0,2] & [0,0],[1,1],[2,2]\\ \text{Ceiling} & [0,2] & [0,2] & [0,0],[1,1],[2,2]\\ \end{array}$$

Also almost all polynomials are working incorrectly

ChebyshevT[3, Interval[{-1, 1}]

Interval[{-7, 7}]


It is well known that the Chebyshev polynomials of the first kind $T_n(x)$ have values from $-1$ to $1$ if $-1\le x \le 1$.

 Plot[ChebyshevT[3, x], {x, -1, 1}]


The problem is that the polynomials are expanded first

ChebyshevT[3, x]

-3 x + 4 x^3


And then Interval[{-1, 1}] is substituted

-3 Interval[{-1, 1}] + 4 Interval[{-1, 1}]^3

Interval[{-7, 7}]


You can use FunctionRange to find the range of a function as a set of inequalities/equalities. For example:

FunctionRange[{UnitStep[x], -4 < x < 5}, x, y]


y == 0 || y == 1

Here is a function to convert to Interval objects from inequalities from my answer to 28790:

bounds[inequality_, x_] := First @ RegionBounds[ImplicitRegion[inequality, x]]

ToInterval[inequality_, x_] := With[{rng = bounds[inequality, x]},
SystemPrivateHoldSetValid[Interval[rng]]
]

t:ToInterval[_Or, _] := IntervalUnion @@ Thread[Unevaluated @ t, Or]


and the reverse:

FromInterval[Interval[a___],x_]:=Less[#1,x,#2]& @@@ Unevaluated[Or[a]]


With these functions we can define an function IntervalRange to find the range of a function as an Interval object:

IntervalRange::nmet = "Unable to find the range with the available methods.";

IntervalRange[f_, i_Interval] := With[
{reg = Catch[iRange[f, FromInterval[i, x], x], "FRFailure"]},
reg /; reg =!= $Failed ] iRange[f_, reg_, x_] := Module[{prec = Precision[reg], rng}, rng = Quiet[ Check[ FunctionRange[{f[x], SetPrecision[reg, prec+10]}, x, y], Message[RangeInterval::nmet]; Throw[$Failed, "FRFailure"],

FunctionRange::nmet
],
FunctionRange::nmet
];
ToInterval[N[rng, prec], y]
]

iRange[f_, reg_Or, x_] := IntervalUnion @@ (iRange[f, #, x]& /@ reg)


IntervalRange[UnitStep, Interval[{-4, 5}]]


Interval[{0, 0}, {1, 1}]

Some other examples:

IntervalRange[Function[x, ChebyshevT[3, x]], Interval[{-1, 1}]]


Interval[{-1, 1}]

and:

IntervalRange[Function[x, x + x^2], Interval[{-∞, ∞}]]


Interval[{-(1/4), ∞}]