
(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 9 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 (exp (- (log1p (exp (/ (PI) s))))))
(t_1 (fma (- (exp (- (log1p (exp (/ (- (PI)) s))))) t_0) u t_0))
(t_2 (+ (/ 1.0 t_1) 1.0)))
(* (- s) (log (/ (- (* (pow t_1 -2.0) t_2) t_2) (pow t_2 2.0))))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := e^{-\mathsf{log1p}\left(e^{\frac{\mathsf{PI}\left(\right)}{s}}\right)}\\
t_1 := \mathsf{fma}\left(e^{-\mathsf{log1p}\left(e^{\frac{-\mathsf{PI}\left(\right)}{s}}\right)} - t\_0, u, t\_0\right)\\
t_2 := \frac{1}{t\_1} + 1\\
\left(-s\right) \cdot \log \left(\frac{{t\_1}^{-2} \cdot t\_2 - t\_2}{{t\_2}^{2}}\right)
\end{array}
\end{array}
Initial program 98.9%
Applied rewrites99.0%
(FPCore (u s)
:precision binary32
(let* ((t_0 (exp (- (log1p (exp (/ (PI) s))))))
(t_1 (fma (- (exp (- (log1p (exp (/ (- (PI)) s))))) t_0) u t_0)))
(* (- s) (log (/ (- (pow t_1 -2.0) 1.0) (+ (/ 1.0 t_1) 1.0))))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := e^{-\mathsf{log1p}\left(e^{\frac{\mathsf{PI}\left(\right)}{s}}\right)}\\
t_1 := \mathsf{fma}\left(e^{-\mathsf{log1p}\left(e^{\frac{-\mathsf{PI}\left(\right)}{s}}\right)} - t\_0, u, t\_0\right)\\
\left(-s\right) \cdot \log \left(\frac{{t\_1}^{-2} - 1}{\frac{1}{t\_1} + 1}\right)
\end{array}
\end{array}
Initial program 98.9%
lift--.f32N/A
flip--N/A
lower-/.f32N/A
Applied rewrites99.0%
(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
(*
(- 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 rewrites98.6%
(FPCore (u s) :precision binary32 (let* ((t_0 (/ 1.0 (+ (exp (/ (PI) s)) 1.0)))) (* (- s) (log (- (/ 1.0 (fma (- 0.5 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(0.5 - 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%
Taylor expanded in s around inf
Applied rewrites37.5%
(FPCore (u s) :precision binary32 (* (- s) (log (- 1.0 (/ (- (PI)) s)))))
\begin{array}{l}
\\
\left(-s\right) \cdot \log \left(1 - \frac{-\mathsf{PI}\left(\right)}{s}\right)
\end{array}
Initial program 98.9%
Taylor expanded in s around inf
Applied rewrites10.1%
Taylor expanded in s around -inf
fp-cancel-sign-sub-invN/A
lower--.f32N/A
metadata-evalN/A
lower-*.f32N/A
lower-/.f32N/A
Applied rewrites25.3%
Taylor expanded in u around 0
Applied rewrites25.5%
(FPCore (u s) :precision binary32 (fma (PI) -1.0 (* (* (PI) u) 2.0)))
\begin{array}{l}
\\
\mathsf{fma}\left(\mathsf{PI}\left(\right), -1, \left(\mathsf{PI}\left(\right) \cdot u\right) \cdot 2\right)
\end{array}
Initial program 98.9%
Taylor expanded in u around 0
mul-1-negN/A
lower-neg.f32N/A
lower-PI.f3210.9
Applied rewrites10.9%
Taylor expanded in s around inf
lower-*.f32N/A
fp-cancel-sub-sign-invN/A
metadata-evalN/A
lower-fma.f32N/A
distribute-rgt-out--N/A
metadata-evalN/A
lower-*.f32N/A
lower-PI.f32N/A
lower-*.f32N/A
lower-PI.f3211.0
Applied rewrites11.0%
Applied rewrites11.0%
(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.f3210.9
Applied rewrites10.9%
(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.f3210.9
Applied rewrites10.9%
Applied rewrites10.9%
Applied rewrites4.5%
herbie shell --seed 2024358
(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))))