\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 := \frac{1 - u}{1 + e^{\frac{\pi}{s}}}\\
t_1 := \frac{u}{1 + e^{\frac{-\pi}{s}}}\\
\left(-s\right) \cdot \log \left(\mathsf{fma}\left(\frac{1}{{t_1}^{3} + {t_0}^{3}}, t_1 \cdot t_1 + \left(t_0 \cdot t_0 - t_1 \cdot t_0\right), -1\right)\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 (/ (- 1.0 u) (+ 1.0 (exp (/ PI s)))))
(t_1 (/ u (+ 1.0 (exp (/ (- PI) s))))))
(*
(- s)
(log
(fma
(/ 1.0 (+ (pow t_1 3.0) (pow t_0 3.0)))
(+ (* t_1 t_1) (- (* t_0 t_0) (* t_1 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 = (1.0f - u) / (1.0f + expf(((float) M_PI) / s));
float t_1 = u / (1.0f + expf(-((float) M_PI) / s));
return -s * logf(fmaf((1.0f / (powf(t_1, 3.0f) + powf(t_0, 3.0f))), ((t_1 * t_1) + ((t_0 * t_0) - (t_1 * t_0))), -1.0f));
}



Bits error versus u



Bits error versus s
Initial program 0.3
Simplified0.3
Applied flip3-+_binary320.4
Applied associate-/r/_binary320.4
Applied fma-def_binary320.4
Final simplification0.4
herbie shell --seed 2022020
(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))))