UnitBox¶
Status: Stable
documented, exercised by the test suite and/or worked examples, with no known limitations recorded.
Description¶
UnitBox[x]
gives 1 for -1/2 \<= x \<= 1/2 and 0 otherwise -- the rectangular pulse (box) function, closed at both endpoints.
Notes
The result is always exact. Exact symbolic real arguments are resolved by the same numerical certification UnitStep and Ramp use; non-real or unresolved arguments are left unevaluated. UnitBox is Listable.Examples (7)¶
Every input below was run against the current Mathilda build and its output recorded.
Basic examples (7)¶
In[1]:= UnitBox[0]
Out[1]= 1
In[2]:= UnitBox[1/2]
Out[2]= 1
In[3]:= UnitBox[-1/2]
Out[3]= 1
In[4]:= UnitBox[0.6]
Out[4]= 0
In[5]:= UnitBox[{-1, -0.5, 0, 0.5, 1}]
Out[5]= {0, 1, 1, 1, 0}
In[6]:= UnitBox[Pi]
Out[6]= 0
In[7]:= UnitBox[x]
Out[7]= UnitBox[x]
Implementation notes¶
Listable,NumericFunction,Orderless,Protected, matching Mathematica.Orderlessreflects the variadic multidimensional box (UnitBox[x, y, ...], likeUnitStep); this implementation evaluates the single-argument pulse.- The result is always exact -- an integer
0or1-- for real numeric input, includingReal/MPFRarguments. - Implemented by reusing
UnitStep's sign classifier twice, onx + 1/2and1/2 - x:xis in range iff neither shifted value is negative. Exact symbolic real arguments (Pi,Sqrt[2], ...) are therefore resolved by the same numerical certificationUnitStepandRampuse. - Non-real arguments (a
Complexwith non-zero imaginary part) and unresolved symbolic arguments are left unevaluated. - Fast paths.
UnitBoxhas a narrowing NDArray kernel (1iff-1/2 <= x <= 1/2, an exact integer, real→int and int→int arms likeUnitStep/Sign/Floor), so it threads over a visibleNDArray[...]and reads a packed buffer directly; it is on theAWARE/INT64_OKlists insrc/pack.c, and a packed or int64 array stays packed and exact. It also lowers inCompile[](and therefore auto-compiles), scalar and rank-1 array, as(x >= -1/2) (x <= 1/2)typed as an Integer. The scalar interpreter path still reusesUnitStep's sign classifier for exact symbolic-real certification. - Does not thread through
Intervalin this version:Floor/Ceilingare the only piecewise functions here that do, becauseIntervalthreading only supports monotone functions, andUnitBox(a two-sided box) isn't one.
Attributes: Listable, NumericFunction, Orderless, Protected.
References¶
See also: Orderless, UnitStep, Pi, Ramp, Complex, Sign, Floor, Interval
- Source:
src/info.c - Specification:
docs/spec/builtins/elementary-functions.md - Tests:
tests/test_unitbox.c