
(FPCore (u s)
:precision binary32
(let* ((t_0 (/ 1.0 (+ 1.0 (exp (/ (PI) s))))))
(*
(- s)
(log
(-
(/ 1.0 (+ (* u (- (/ 1.0 (+ 1.0 (exp (/ (- (PI)) s)))) t_0)) t_0))
1.0)))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{1}{1 + e^{\frac{\mathsf{PI}\left(\right)}{s}}}\\
\left(-s\right) \cdot \log \left(\frac{1}{u \cdot \left(\frac{1}{1 + e^{\frac{-\mathsf{PI}\left(\right)}{s}}} - t\_0\right) + t\_0} - 1\right)
\end{array}
\end{array}
Sampling outcomes in binary32 precision:
Herbie found 11 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (u s)
:precision binary32
(let* ((t_0 (/ 1.0 (+ 1.0 (exp (/ (PI) s))))))
(*
(- s)
(log
(-
(/ 1.0 (+ (* u (- (/ 1.0 (+ 1.0 (exp (/ (- (PI)) s)))) t_0)) t_0))
1.0)))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{1}{1 + e^{\frac{\mathsf{PI}\left(\right)}{s}}}\\
\left(-s\right) \cdot \log \left(\frac{1}{u \cdot \left(\frac{1}{1 + e^{\frac{-\mathsf{PI}\left(\right)}{s}}} - t\_0\right) + t\_0} - 1\right)
\end{array}
\end{array}
(FPCore (u s)
:precision binary32
(let* ((t_0 (/ 1.0 (+ (exp (/ (PI) s)) 1.0))))
(*
(- s)
(log
(-
(/ 1.0 (fma (- (/ 1.0 (+ (exp (/ (- (PI)) s)) 1.0)) t_0) u t_0))
1.0)))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{1}{e^{\frac{\mathsf{PI}\left(\right)}{s}} + 1}\\
\left(-s\right) \cdot \log \left(\frac{1}{\mathsf{fma}\left(\frac{1}{e^{\frac{-\mathsf{PI}\left(\right)}{s}} + 1} - t\_0, u, t\_0\right)} - 1\right)
\end{array}
\end{array}
Initial program 98.9%
Taylor expanded in u around 0
*-commutativeN/A
lower-fma.f32N/A
Applied rewrites98.9%
(FPCore (u s)
:precision binary32
(let* ((t_0 (/ (PI) s)))
(*
(- s)
(log
(-
(/
1.0
(fma
(-
(/ 1.0 (+ (exp (/ (- (PI)) s)) 1.0))
(/ 1.0 (+ (+ 1.0 (fma 0.5 (/ (* (PI) (PI)) (* s s)) t_0)) 1.0)))
u
(/ 1.0 (+ (exp t_0) 1.0))))
1.0)))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{\mathsf{PI}\left(\right)}{s}\\
\left(-s\right) \cdot \log \left(\frac{1}{\mathsf{fma}\left(\frac{1}{e^{\frac{-\mathsf{PI}\left(\right)}{s}} + 1} - \frac{1}{\left(1 + \mathsf{fma}\left(0.5, \frac{\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)}{s \cdot s}, t\_0\right)\right) + 1}, u, \frac{1}{e^{t\_0} + 1}\right)} - 1\right)
\end{array}
\end{array}
Initial program 98.9%
Taylor expanded in u around 0
*-commutativeN/A
lower-fma.f32N/A
Applied rewrites98.9%
Taylor expanded in s around inf
Applied rewrites97.6%
(FPCore (u s)
:precision binary32
(*
(- s)
(log
(-
(/
1.0
(*
(- (/ 1.0 (+ (exp (/ (- (PI)) s)) 1.0)) (/ 1.0 (+ (exp (/ (PI) s)) 1.0)))
u))
1.0))))\begin{array}{l}
\\
\left(-s\right) \cdot \log \left(\frac{1}{\left(\frac{1}{e^{\frac{-\mathsf{PI}\left(\right)}{s}} + 1} - \frac{1}{e^{\frac{\mathsf{PI}\left(\right)}{s}} + 1}\right) \cdot u} - 1\right)
\end{array}
Initial program 98.9%
Taylor expanded in u around inf
*-commutativeN/A
lower-*.f32N/A
Applied rewrites97.5%
(FPCore (u s)
:precision binary32
(let* ((t_0 (- (PI))))
(*
(- s)
(log
(-
(/
1.0
(*
(-
(/ 1.0 (+ (exp (/ t_0 s)) 1.0))
(/
1.0
(+ (fma (/ (fma (/ (* (PI) (PI)) s) -0.5 t_0) s) -1.0 1.0) 1.0)))
u))
1.0)))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := -\mathsf{PI}\left(\right)\\
\left(-s\right) \cdot \log \left(\frac{1}{\left(\frac{1}{e^{\frac{t\_0}{s}} + 1} - \frac{1}{\mathsf{fma}\left(\frac{\mathsf{fma}\left(\frac{\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)}{s}, -0.5, t\_0\right)}{s}, -1, 1\right) + 1}\right) \cdot u} - 1\right)
\end{array}
\end{array}
Initial program 98.9%
Taylor expanded in u around inf
*-commutativeN/A
lower-*.f32N/A
Applied rewrites97.5%
Taylor expanded in s around -inf
Applied rewrites96.6%
(FPCore (u s)
:precision binary32
(*
(- s)
(log
(-
(/
1.0
(*
(-
(/ 1.0 (+ (exp (/ (- (PI)) s)) 1.0))
(/ 1.0 (+ (+ (/ (PI) s) 1.0) 1.0)))
u))
1.0))))\begin{array}{l}
\\
\left(-s\right) \cdot \log \left(\frac{1}{\left(\frac{1}{e^{\frac{-\mathsf{PI}\left(\right)}{s}} + 1} - \frac{1}{\left(\frac{\mathsf{PI}\left(\right)}{s} + 1\right) + 1}\right) \cdot u} - 1\right)
\end{array}
Initial program 98.9%
Taylor expanded in u around inf
*-commutativeN/A
lower-*.f32N/A
Applied rewrites97.5%
Taylor expanded in s around inf
Applied rewrites94.9%
(FPCore (u s) :precision binary32 (* (- s) (log (- (/ 1.0 (* (- 0.5 (/ 1.0 (+ (exp (/ (PI) s)) 1.0))) u)) 1.0))))
\begin{array}{l}
\\
\left(-s\right) \cdot \log \left(\frac{1}{\left(0.5 - \frac{1}{e^{\frac{\mathsf{PI}\left(\right)}{s}} + 1}\right) \cdot u} - 1\right)
\end{array}
Initial program 98.9%
Taylor expanded in u around inf
*-commutativeN/A
lower-*.f32N/A
Applied rewrites97.5%
Taylor expanded in s around inf
Applied rewrites37.3%
(FPCore (u s)
:precision binary32
(*
(- s)
(log
(-
(fma
(/
(fma
(fma (* (* (* 0.5 (PI)) -1.0) 0.5) u (* -0.25 (PI)))
-8.0
(* 0.25 (* (PI) -12.0)))
s)
-1.0
2.0)
1.0))))\begin{array}{l}
\\
\left(-s\right) \cdot \log \left(\mathsf{fma}\left(\frac{\mathsf{fma}\left(\mathsf{fma}\left(\left(\left(0.5 \cdot \mathsf{PI}\left(\right)\right) \cdot -1\right) \cdot 0.5, u, -0.25 \cdot \mathsf{PI}\left(\right)\right), -8, 0.25 \cdot \left(\mathsf{PI}\left(\right) \cdot -12\right)\right)}{s}, -1, 2\right) - 1\right)
\end{array}
Initial program 98.9%
Applied rewrites98.8%
Taylor expanded in s around -inf
+-commutativeN/A
*-commutativeN/A
lower-fma.f32N/A
Applied rewrites24.9%
(FPCore (u s) :precision binary32 (let* ((t_0 (/ (PI) s))) (* (- s) (log (- (fma t_0 1.0 (fma u (* (* 0.5 t_0) -4.0) 2.0)) 1.0)))))
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{\mathsf{PI}\left(\right)}{s}\\
\left(-s\right) \cdot \log \left(\mathsf{fma}\left(t\_0, 1, \mathsf{fma}\left(u, \left(0.5 \cdot t\_0\right) \cdot -4, 2\right)\right) - 1\right)
\end{array}
\end{array}
Initial program 98.9%
Applied rewrites98.8%
lift-/.f32N/A
Applied rewrites98.9%
Taylor expanded in s around -inf
lower--.f32N/A
Applied rewrites24.9%
(FPCore (u s) :precision binary32 (* (* (PI) (fma 0.5 u -0.25)) 4.0))
\begin{array}{l}
\\
\left(\mathsf{PI}\left(\right) \cdot \mathsf{fma}\left(0.5, u, -0.25\right)\right) \cdot 4
\end{array}
Initial program 98.9%
Taylor expanded in u around 0
lower-/.f32N/A
lower-PI.f3211.4
Applied rewrites11.4%
Taylor expanded in s around inf
*-commutativeN/A
lower-*.f32N/A
Applied rewrites11.7%
Applied rewrites11.7%
(FPCore (u s) :precision binary32 (fma 2.0 (* (PI) u) (- (PI))))
\begin{array}{l}
\\
\mathsf{fma}\left(2, \mathsf{PI}\left(\right) \cdot u, -\mathsf{PI}\left(\right)\right)
\end{array}
Initial program 98.9%
Taylor expanded in u around 0
lower-/.f32N/A
lower-PI.f3211.4
Applied rewrites11.4%
Taylor expanded in s around inf
*-commutativeN/A
lower-*.f32N/A
Applied rewrites11.7%
Taylor expanded in u around 0
Applied rewrites11.7%
(FPCore (u s) :precision binary32 (- (PI)))
\begin{array}{l}
\\
-\mathsf{PI}\left(\right)
\end{array}
Initial program 98.9%
Taylor expanded in u around 0
mul-1-negN/A
lower-neg.f32N/A
lower-PI.f3211.5
Applied rewrites11.5%
herbie shell --seed 2025006
(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))))