Navigation :
truncate
truncate, function
def pure truncate(d: ranvar, low: number, high: number): ranvar
Returns the conditional ranvar of d restricted to [low, high].
Example
d = ranvar.uniform(1, 6)
dTrunc = truncate(d, 2, 4)
show summary "Means" with
mean(d) as "raw"
mean(dTrunc) as "truncated"
This outputs the following list:
| Label |
Value |
| raw |
3.5 |
| truncated |
3 |
truncate(d, low, high) redistributes mass inside [low, high], unlike
min(max(d, low), high) which piles mass on the bounds.
If low is above the support of d, the result is dirac(low). If high is
below the support of d, the result is dirac(high).
Decimal bounds are supported and equivalent to truncate(d, floor(low),
ceiling(high)).
Errors
If low > high, Envision reports:
truncate(_, 9, 7): expected 9 smaller or equal to 7.
See also