\left(-s\right) \cdot \log \left(\frac{1}{u \cdot \left(\frac{1}{1 + e^{\frac{-\pi}{s}}} - \frac{1}{1 + e^{\frac{\pi}{s}}}\right) + \frac{1}{1 + e^{\frac{\pi}{s}}}} - 1\right)
\begin{array}{l}
t_0 := \sqrt{e^{-\log \left(\frac{s}{\pi}\right)}}\\
\left(-s\right) \cdot \log \left(\frac{1}{\frac{u}{1 + e^{\frac{-\pi}{s}}} + \frac{1 - u}{1 + e^{t_0 \cdot t_0}}} + -1\right)
\end{array}
(FPCore (u s)
:precision binary32
(*
(- s)
(log
(-
(/
1.0
(+
(*
u
(- (/ 1.0 (+ 1.0 (exp (/ (- PI) s)))) (/ 1.0 (+ 1.0 (exp (/ PI s))))))
(/ 1.0 (+ 1.0 (exp (/ PI s))))))
1.0))))(FPCore (u s)
:precision binary32
(let* ((t_0 (sqrt (exp (- (log (/ s PI)))))))
(*
(- s)
(log
(+
(/
1.0
(+
(/ u (+ 1.0 (exp (/ (- PI) s))))
(/ (- 1.0 u) (+ 1.0 (exp (* t_0 t_0))))))
-1.0)))))float code(float u, float s) {
return -s * logf((1.0f / ((u * ((1.0f / (1.0f + expf(-((float) M_PI) / s))) - (1.0f / (1.0f + expf(((float) M_PI) / s))))) + (1.0f / (1.0f + expf(((float) M_PI) / s))))) - 1.0f);
}
float code(float u, float s) {
float t_0 = sqrtf(expf(-logf(s / ((float) M_PI))));
return -s * logf((1.0f / ((u / (1.0f + expf(-((float) M_PI) / s))) + ((1.0f - u) / (1.0f + expf(t_0 * t_0))))) + -1.0f);
}



Bits error versus u



Bits error versus s
Results
Initial program 0.3
Simplified0.3
Applied clear-num_binary320.3
Applied add-exp-log_binary320.3
Applied rec-exp_binary320.3
Applied add-sqr-sqrt_binary320.3
Final simplification0.3
herbie shell --seed 2021329
(FPCore (u s)
:name "Sample trimmed logistic on [-pi, pi]"
:precision binary32
:pre (and (and (<= 2.328306437e-10 u) (<= u 1.0)) (and (<= 0.0 s) (<= s 1.0651631)))
(* (- s) (log (- (/ 1.0 (+ (* u (- (/ 1.0 (+ 1.0 (exp (/ (- PI) s)))) (/ 1.0 (+ 1.0 (exp (/ PI s)))))) (/ 1.0 (+ 1.0 (exp (/ PI s)))))) 1.0))))