Ramp¶
Status: Stable
documented, exercised by the test suite and/or worked examples, with no known limitations recorded.
Description¶
Ramp[x]
gives x for x >= 0 and 0 for x \< 0 -- the positive part of x, and the standard spelling of a rectified linear unit.
Notes
The zero returned for a negative argument carries the argument's own exactness: Ramp\[-1.\] is 0. and Ramp\[-3\] is the exact 0, so a Real list maps to a Real list and an integer list to an integer one. Non-real arguments, and symbolic ones whose sign cannot be decided, are left unevaluated. Ramp is Listable and a NumericFunction.Examples (5)¶
Every input below was run against the current Mathilda build and its output recorded.
Basic examples (5)¶
In[1]:= Ramp[{-1., 0., 2.5}]
Out[1]= {0.0, 0.0, 2.5}
In[2]:= Ramp[{-3, 0, 4}]
Out[2]= {0, 0, 4}
In[3]:= Ramp[{-1/2, 3/4}]
Out[3]= {0, 3/4}
In[4]:= Ramp[1 - Sqrt[2]]
Out[4]= 0
In[5]:= Ramp[1. + 2. I]
Out[5]= Ramp[1.0 + 2.0*I]
Implementation notes¶
Listable,NumericFunction,Protected.- The zero returned for a negative argument carries the argument's own
exactness:
Ramp[-1.]is0.andRamp[-3]is the exact0. AReallist therefore maps to aReallist and an integer list to an integer one, with no mixed-head result -- unlikeClip, which returns the bound at a clipped position and so can put an exactIntegerinto a machine-real answer. - Exact symbolic real arguments are resolved by the same numerical
certification
UnitStepuses, soRamp[Sqrt[2] - 1]gives-1 + Sqrt[2]andRamp[1 - Sqrt[2]]gives0. - Non-real arguments (a
Complexwith non-zero imaginary part) and symbolic arguments whose sign cannot be certified are left unevaluated. - A packed list of
Reals is handled by a threaded buffer kernel (seepacked-arrays.md); an integer buffer materialises, which changes speed and not the answer.
Attributes: Listable, NumericFunction, Protected.
References¶
See also: Clip, UnitStep, Complex
- Source:
src/info.c - Specification:
docs/spec/builtins/elementary-functions.md - Tests:
tests/test_interval.c - Tests:
tests/test_packed_list.c