Piecewise function. It takes into account the case when the function is monotonally decreasing. Developed by AIA. 2014/03/10