
(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 13 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 (/ (PI) s)))
(t_1 (+ 1.0 t_0))
(t_2 (exp (- (log1p t_0))))
(t_3 (exp (- (log1p (exp (/ (- (PI)) s))))))
(t_4 (* (- t_3 t_2) u)))
(*
(- s)
(log
(-
(/
1.0
(/
(* (- (* (- t_3 (/ 1.0 t_1)) u) t_2) (- (pow t_4 2.0) (pow t_1 -2.0)))
(pow (- t_4 t_2) 2.0)))
1.0)))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := e^{\frac{\mathsf{PI}\left(\right)}{s}}\\
t_1 := 1 + t\_0\\
t_2 := e^{-\mathsf{log1p}\left(t\_0\right)}\\
t_3 := e^{-\mathsf{log1p}\left(e^{\frac{-\mathsf{PI}\left(\right)}{s}}\right)}\\
t_4 := \left(t\_3 - t\_2\right) \cdot u\\
\left(-s\right) \cdot \log \left(\frac{1}{\frac{\left(\left(t\_3 - \frac{1}{t\_1}\right) \cdot u - t\_2\right) \cdot \left({t\_4}^{2} - {t\_1}^{-2}\right)}{{\left(t\_4 - t\_2\right)}^{2}}} - 1\right)
\end{array}
\end{array}
Initial program 98.8%
Applied rewrites98.8%
Applied rewrites98.8%
lift-exp.f32N/A
lift-neg.f32N/A
lift-log1p.f32N/A
lift-+.f32N/A
neg-logN/A
lift-+.f32N/A
lift-exp.f32N/A
lift-/.f32N/A
lift-PI.f32N/A
rem-exp-logN/A
lift-PI.f32N/A
lift-/.f32N/A
lift-exp.f32N/A
lift-+.f32N/A
lower-/.f3298.8
Applied rewrites98.8%
(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.8%
Taylor expanded in u around 0
*-commutativeN/A
lower-fma.f32N/A
Applied rewrites98.8%
(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.8%
Taylor expanded in u around inf
*-commutativeN/A
lower-*.f32N/A
Applied rewrites97.4%
(FPCore (u s)
:precision binary32
(*
(- s)
(log
(-
(/
1.0
(*
(-
(/ 1.0 (+ (exp (/ (- (PI)) s)) 1.0))
(/ 1.0 (+ (/ (fma 0.5 (* (PI) (PI)) (* s (+ (PI) s))) (* s 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}{\frac{\mathsf{fma}\left(0.5, \mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right), s \cdot \left(\mathsf{PI}\left(\right) + s\right)\right)}{s \cdot s} + 1}\right) \cdot u} - 1\right)
\end{array}
Initial program 98.8%
Taylor expanded in u around inf
*-commutativeN/A
lower-*.f32N/A
Applied rewrites97.4%
Taylor expanded in s around -inf
Applied rewrites95.9%
Taylor expanded in s around 0
Applied rewrites95.9%
(FPCore (u s)
:precision binary32
(*
(- s)
(log
(-
(/
1.0
(*
(-
(/ 1.0 (+ (exp (/ (- (PI)) s)) 1.0))
(/ 1.0 (+ (/ (* (PI) (fma 0.5 (PI) s)) (* s 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}{\frac{\mathsf{PI}\left(\right) \cdot \mathsf{fma}\left(0.5, \mathsf{PI}\left(\right), s\right)}{s \cdot s} + 1}\right) \cdot u} - 1\right)
\end{array}
Initial program 98.8%
Taylor expanded in u around inf
*-commutativeN/A
lower-*.f32N/A
Applied rewrites97.4%
Taylor expanded in s around -inf
Applied rewrites95.9%
Taylor expanded in s around 0
Applied rewrites95.9%
Applied rewrites95.9%
(FPCore (u s)
:precision binary32
(*
(- s)
(log
(-
(/
1.0
(*
(-
(/ 1.0 (+ (exp (/ (- (PI)) s)) 1.0))
(/ 1.0 (+ (/ (* 0.5 (* (PI) (PI))) (* s 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}{\frac{0.5 \cdot \left(\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\right)}{s \cdot s} + 1}\right) \cdot u} - 1\right)
\end{array}
Initial program 98.8%
Taylor expanded in u around inf
*-commutativeN/A
lower-*.f32N/A
Applied rewrites97.4%
Taylor expanded in s around -inf
Applied rewrites95.9%
Taylor expanded in s around 0
Applied rewrites95.9%
(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.8%
Taylor expanded in u around inf
*-commutativeN/A
lower-*.f32N/A
Applied rewrites97.4%
Taylor expanded in s around inf
Applied rewrites93.7%
(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.8%
Taylor expanded in u around inf
*-commutativeN/A
lower-*.f32N/A
Applied rewrites97.4%
Taylor expanded in s around inf
Applied rewrites36.8%
(FPCore (u s)
:precision binary32
(*
(- s)
(log
(-
(/
1.0
(*
(-
0.5
(/
1.0
(+ (fma -1.0 (/ (fma -0.5 (/ (* (PI) (PI)) s) (- (PI))) s) 1.0) 1.0)))
u))
1.0))))\begin{array}{l}
\\
\left(-s\right) \cdot \log \left(\frac{1}{\left(0.5 - \frac{1}{\mathsf{fma}\left(-1, \frac{\mathsf{fma}\left(-0.5, \frac{\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)}{s}, -\mathsf{PI}\left(\right)\right)}{s}, 1\right) + 1}\right) \cdot u} - 1\right)
\end{array}
Initial program 98.8%
Taylor expanded in u around inf
*-commutativeN/A
lower-*.f32N/A
Applied rewrites97.4%
Taylor expanded in s around -inf
Applied rewrites95.9%
Taylor expanded in s around inf
Applied rewrites36.8%
(FPCore (u s) :precision binary32 (* (- s) (* (fma (* u (PI)) 0.5 (* -0.25 (PI))) (/ -4.0 s))))
\begin{array}{l}
\\
\left(-s\right) \cdot \left(\mathsf{fma}\left(u \cdot \mathsf{PI}\left(\right), 0.5, -0.25 \cdot \mathsf{PI}\left(\right)\right) \cdot \frac{-4}{s}\right)
\end{array}
Initial program 98.8%
Taylor expanded in s around inf
associate-*r/N/A
*-commutativeN/A
associate-/l*N/A
lower-*.f32N/A
fp-cancel-sub-sign-invN/A
distribute-rgt-out--N/A
metadata-evalN/A
associate-*r*N/A
metadata-evalN/A
lower-fma.f32N/A
lower-*.f32N/A
lower-PI.f32N/A
lower-*.f32N/A
lower-PI.f32N/A
lower-/.f3211.9
Applied rewrites11.9%
(FPCore (u s) :precision binary32 (* (- s) (* (/ (fma (* u (PI)) -0.5 (* 0.25 (PI))) s) 4.0)))
\begin{array}{l}
\\
\left(-s\right) \cdot \left(\frac{\mathsf{fma}\left(u \cdot \mathsf{PI}\left(\right), -0.5, 0.25 \cdot \mathsf{PI}\left(\right)\right)}{s} \cdot 4\right)
\end{array}
Initial program 98.8%
Taylor expanded in s around -inf
*-commutativeN/A
lower-*.f32N/A
lower-/.f32N/A
fp-cancel-sub-sign-invN/A
distribute-rgt-out--N/A
metadata-evalN/A
associate-*r*N/A
metadata-evalN/A
lower-fma.f32N/A
lower-*.f32N/A
lower-PI.f32N/A
lower-*.f32N/A
lower-PI.f3211.9
Applied rewrites11.9%
(FPCore (u s) :precision binary32 (fma (* u (PI)) 2.0 (- (PI))))
\begin{array}{l}
\\
\mathsf{fma}\left(u \cdot \mathsf{PI}\left(\right), 2, -\mathsf{PI}\left(\right)\right)
\end{array}
Initial program 98.8%
Taylor expanded in u around 0
mul-1-negN/A
lower-neg.f32N/A
lower-PI.f3211.8
Applied rewrites11.8%
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.9
Applied rewrites11.9%
Applied rewrites11.9%
(FPCore (u s) :precision binary32 (- (PI)))
\begin{array}{l}
\\
-\mathsf{PI}\left(\right)
\end{array}
Initial program 98.8%
Taylor expanded in u around 0
mul-1-negN/A
lower-neg.f32N/A
lower-PI.f3211.8
Applied rewrites11.8%
herbie shell --seed 2024360
(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))))