For the input
UnitStep[Interval[{-4, 5}]]
I get
Interval[{0, 1}]
Why is this not Interval[{0,0}, {1,1}]
?
Mathematica Stack Exchange is a question and answer site for users of Wolfram Mathematica. It only takes a minute to sign up.
Sign up to join this communityI 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]},
System`Private`HoldSetValid[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)
Your example:
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), ∞}]
Listable
(seeAttributes@UnitStep
) and can deal with real-valued intervals. This information can be easily found in documentation pages. $\endgroup$ – Artes Nov 3 '13 at 14:30UnitStep[Interval[{-Pi, Pi}]]
yieldsInterval[{0, 1}]
, similarlySin[Interval[{-Pi, Pi}]]
yieldsInterval[{-1, 1}]
. What is your problem? $\endgroup$ – Artes Nov 3 '13 at 17:11UnitStep
just the set {0, 1}? I thought that's whatInterval[{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. $\endgroup$ – Michael E2 Nov 3 '13 at 17:23Listable
has anything to do with the problem.Tan[Interval[{1, 2}]]
returns disjoint intervalsInterval[{-Infinity, Tan[2]}, {Tan[1], Infinity}]
. IfUnitStep
worked correctly withInterval
,UnitStep[Interval[{a, b}]]
would return the range of values ofUnitStep
over that interval, eitherInterval[{0,0}]
,Interval[{1,1}]
, orInterval[{0,0}, {1,1}]
depending on the signs ofa
andb
. $\endgroup$ – Michael E2 Nov 3 '13 at 17:55