
(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 12 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)) 1.0))
(t_1 (/ 1.0 t_0))
(t_2 (* (- (/ 1.0 (+ (exp (/ (- (PI)) s)) 1.0)) t_1) u)))
(*
(- s)
(log (- (/ 1.0 (/ (- (pow t_0 -2.0) (pow t_2 2.0)) (- t_1 t_2))) 1.0)))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := e^{\frac{\mathsf{PI}\left(\right)}{s}} + 1\\
t_1 := \frac{1}{t\_0}\\
t_2 := \left(\frac{1}{e^{\frac{-\mathsf{PI}\left(\right)}{s}} + 1} - t\_1\right) \cdot u\\
\left(-s\right) \cdot \log \left(\frac{1}{\frac{{t\_0}^{-2} - {t\_2}^{2}}{t\_1 - t\_2}} - 1\right)
\end{array}
\end{array}
Initial program 99.0%
lift-/.f32N/A
clear-numN/A
associate-/r/N/A
lower-*.f32N/A
lower-/.f3299.0
Applied rewrites99.0%
Applied rewrites99.0%
(FPCore (u s)
:precision binary32
(let* ((t_0 (/ (PI) s)) (t_1 (/ 1.0 (+ 1.0 (exp t_0)))))
(if (<=
(*
(- s)
(log
(-
(/ 1.0 (+ (* u (- (/ 1.0 (+ 1.0 (exp (/ (- (PI)) s)))) t_1)) t_1))
1.0)))
-5.000000015855384e-29)
(* (- s) (log (- (/ 1.0 (fma t_0 -0.25 0.5)) 1.0)))
(fma (* (PI) (fma -0.5 u 0.25)) -4.0 0.0))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{\mathsf{PI}\left(\right)}{s}\\
t_1 := \frac{1}{1 + e^{t\_0}}\\
\mathbf{if}\;\left(-s\right) \cdot \log \left(\frac{1}{u \cdot \left(\frac{1}{1 + e^{\frac{-\mathsf{PI}\left(\right)}{s}}} - t\_1\right) + t\_1} - 1\right) \leq -5.000000015855384 \cdot 10^{-29}:\\
\;\;\;\;\left(-s\right) \cdot \log \left(\frac{1}{\mathsf{fma}\left(t\_0, -0.25, 0.5\right)} - 1\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{PI}\left(\right) \cdot \mathsf{fma}\left(-0.5, u, 0.25\right), -4, 0\right)\\
\end{array}
\end{array}
if (*.f32 (neg.f32 s) (log.f32 (-.f32 (/.f32 #s(literal 1 binary32) (+.f32 (*.f32 u (-.f32 (/.f32 #s(literal 1 binary32) (+.f32 #s(literal 1 binary32) (exp.f32 (/.f32 (neg.f32 (PI.f32)) s)))) (/.f32 #s(literal 1 binary32) (+.f32 #s(literal 1 binary32) (exp.f32 (/.f32 (PI.f32) s)))))) (/.f32 #s(literal 1 binary32) (+.f32 #s(literal 1 binary32) (exp.f32 (/.f32 (PI.f32) s)))))) #s(literal 1 binary32)))) < -5.00000002e-29Initial program 99.1%
Taylor expanded in s around -inf
mul-1-negN/A
unsub-negN/A
lower--.f32N/A
lower-/.f32N/A
Applied rewrites-0.0%
Applied rewrites2.8%
Taylor expanded in u around 0
Applied rewrites8.6%
Applied rewrites8.6%
if -5.00000002e-29 < (*.f32 (neg.f32 s) (log.f32 (-.f32 (/.f32 #s(literal 1 binary32) (+.f32 (*.f32 u (-.f32 (/.f32 #s(literal 1 binary32) (+.f32 #s(literal 1 binary32) (exp.f32 (/.f32 (neg.f32 (PI.f32)) s)))) (/.f32 #s(literal 1 binary32) (+.f32 #s(literal 1 binary32) (exp.f32 (/.f32 (PI.f32) s)))))) (/.f32 #s(literal 1 binary32) (+.f32 #s(literal 1 binary32) (exp.f32 (/.f32 (PI.f32) s)))))) #s(literal 1 binary32)))) Initial program 98.9%
Taylor expanded in s around -inf
Applied rewrites15.2%
(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}
Initial program 99.0%
(FPCore (u s)
:precision binary32
(*
(- s)
(log
(-
(/
(/ 1.0 u)
(- (/ 1.0 (+ (exp (/ (- (PI)) s)) 1.0)) (/ 1.0 (+ (exp (/ (PI) s)) 1.0))))
1.0))))\begin{array}{l}
\\
\left(-s\right) \cdot \log \left(\frac{\frac{1}{u}}{\frac{1}{e^{\frac{-\mathsf{PI}\left(\right)}{s}} + 1} - \frac{1}{e^{\frac{\mathsf{PI}\left(\right)}{s}} + 1}} - 1\right)
\end{array}
Initial program 99.0%
lift-/.f32N/A
clear-numN/A
associate-/r/N/A
lower-*.f32N/A
lower-/.f3299.0
Applied rewrites99.0%
Applied rewrites99.0%
Taylor expanded in u around -inf
associate-/r*N/A
lower-/.f32N/A
lower-/.f32N/A
lower--.f32N/A
lower-/.f32N/A
+-commutativeN/A
lower-+.f32N/A
lower-exp.f32N/A
associate-*r/N/A
lower-/.f32N/A
mul-1-negN/A
lower-neg.f32N/A
lower-PI.f32N/A
lower-/.f32N/A
Applied rewrites97.6%
(FPCore (u s)
:precision binary32
(let* ((t_0 (+ (/ (PI) s) 1.0)))
(*
(- s)
(log
(-
(/
1.0
(+
(* (- (/ 1.0 (+ (exp (/ (- (PI)) s)) 1.0)) (/ 1.0 (+ t_0 1.0))) u)
(/ 1.0 (+ 1.0 t_0))))
1.0)))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{\mathsf{PI}\left(\right)}{s} + 1\\
\left(-s\right) \cdot \log \left(\frac{1}{\left(\frac{1}{e^{\frac{-\mathsf{PI}\left(\right)}{s}} + 1} - \frac{1}{t\_0 + 1}\right) \cdot u + \frac{1}{1 + t\_0}} - 1\right)
\end{array}
\end{array}
Initial program 99.0%
Taylor expanded in s around inf
+-commutativeN/A
associate-+l+N/A
associate-*r/N/A
unpow2N/A
times-fracN/A
+-commutativeN/A
lower-fma.f32N/A
lower-/.f32N/A
unpow2N/A
associate-/l*N/A
lower-*.f32N/A
lower-PI.f32N/A
lower-/.f32N/A
lower-PI.f32N/A
+-commutativeN/A
lower-+.f32N/A
lower-/.f32N/A
lower-PI.f3295.7
Applied rewrites95.7%
lift-*.f32N/A
*-commutativeN/A
lower-*.f3295.7
Applied rewrites39.0%
Taylor expanded in s around inf
+-commutativeN/A
lower-+.f32N/A
lower-/.f32N/A
lower-PI.f3236.6
Applied rewrites36.6%
Taylor expanded in s around inf
Applied rewrites88.0%
(FPCore (u s)
:precision binary32
(let* ((t_0 (/ (PI) s)))
(*
(- s)
(log
(- (/ 1.0 (fma (fma 0.0 u (* 0.5 t_0)) u (+ 0.5 (* -0.25 t_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(\mathsf{fma}\left(0, u, 0.5 \cdot t\_0\right), u, 0.5 + -0.25 \cdot t\_0\right)} - 1\right)
\end{array}
\end{array}
Initial program 99.0%
Taylor expanded in s around -inf
mul-1-negN/A
unsub-negN/A
lower--.f32N/A
lower-/.f32N/A
Applied rewrites-0.0%
Applied rewrites2.8%
Taylor expanded in u around 0
Applied rewrites10.3%
Applied rewrites4.3%
(FPCore (u s)
:precision binary32
(let* ((t_0 (/ (PI) s)))
(if (<= s 7.999999837289519e-31)
(* (- s) (log (- (/ 1.0 (fma (* 0.5 t_0) u (fma -0.25 t_0 0.5))) 1.0)))
(* (- s) (log (- (/ 1.0 (fma t_0 -0.25 0.5)) 1.0))))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{\mathsf{PI}\left(\right)}{s}\\
\mathbf{if}\;s \leq 7.999999837289519 \cdot 10^{-31}:\\
\;\;\;\;\left(-s\right) \cdot \log \left(\frac{1}{\mathsf{fma}\left(0.5 \cdot t\_0, u, \mathsf{fma}\left(-0.25, t\_0, 0.5\right)\right)} - 1\right)\\
\mathbf{else}:\\
\;\;\;\;\left(-s\right) \cdot \log \left(\frac{1}{\mathsf{fma}\left(t\_0, -0.25, 0.5\right)} - 1\right)\\
\end{array}
\end{array}
if s < 7.99999984e-31Initial program 99.1%
Taylor expanded in s around -inf
mul-1-negN/A
unsub-negN/A
lower--.f32N/A
lower-/.f32N/A
Applied rewrites-0.0%
Applied rewrites2.8%
Taylor expanded in u around 0
Applied rewrites16.1%
Applied rewrites15.7%
if 7.99999984e-31 < s Initial program 99.0%
Taylor expanded in s around -inf
mul-1-negN/A
unsub-negN/A
lower--.f32N/A
lower-/.f32N/A
Applied rewrites-0.0%
Applied rewrites2.9%
Taylor expanded in u around 0
Applied rewrites8.8%
Applied rewrites8.8%
(FPCore (u s)
:precision binary32
(*
(- s)
(log
(-
(-
(fma -4.0 (/ (fma (* 0.5 (PI)) u (* 0.25 (PI))) s) 2.0)
(* -2.0 (/ (PI) s)))
1.0))))\begin{array}{l}
\\
\left(-s\right) \cdot \log \left(\left(\mathsf{fma}\left(-4, \frac{\mathsf{fma}\left(0.5 \cdot \mathsf{PI}\left(\right), u, 0.25 \cdot \mathsf{PI}\left(\right)\right)}{s}, 2\right) - -2 \cdot \frac{\mathsf{PI}\left(\right)}{s}\right) - 1\right)
\end{array}
Initial program 99.0%
lift-/.f32N/A
clear-numN/A
associate-/r/N/A
lower-*.f32N/A
lower-/.f3299.0
Applied rewrites99.0%
Applied rewrites99.0%
Taylor expanded in s around inf
lower--.f32N/A
Applied rewrites22.2%
(FPCore (u s) :precision binary32 (* (* (* (- (/ 0.25 u) 0.5) u) (PI)) -4.0))
\begin{array}{l}
\\
\left(\left(\left(\frac{0.25}{u} - 0.5\right) \cdot u\right) \cdot \mathsf{PI}\left(\right)\right) \cdot -4
\end{array}
Initial program 99.0%
lift-/.f32N/A
clear-numN/A
associate-/r/N/A
lower-*.f32N/A
lower-/.f3299.0
Applied rewrites99.0%
Taylor expanded in s around -inf
*-commutativeN/A
lower-*.f32N/A
cancel-sign-sub-invN/A
*-commutativeN/A
distribute-rgt-out--N/A
metadata-evalN/A
associate-*r*N/A
metadata-evalN/A
*-commutativeN/A
distribute-lft-inN/A
+-commutativeN/A
*-commutativeN/A
lower-*.f32N/A
+-commutativeN/A
lower-fma.f32N/A
lower-PI.f3211.1
Applied rewrites11.1%
Taylor expanded in u around inf
Applied rewrites11.3%
Final simplification11.3%
(FPCore (u s) :precision binary32 (* (* (+ (* -0.5 u) 0.25) (PI)) -4.0))
\begin{array}{l}
\\
\left(\left(-0.5 \cdot u + 0.25\right) \cdot \mathsf{PI}\left(\right)\right) \cdot -4
\end{array}
Initial program 99.0%
lift-/.f32N/A
clear-numN/A
associate-/r/N/A
lower-*.f32N/A
lower-/.f3299.0
Applied rewrites99.0%
Taylor expanded in s around -inf
*-commutativeN/A
lower-*.f32N/A
cancel-sign-sub-invN/A
*-commutativeN/A
distribute-rgt-out--N/A
metadata-evalN/A
associate-*r*N/A
metadata-evalN/A
*-commutativeN/A
distribute-lft-inN/A
+-commutativeN/A
*-commutativeN/A
lower-*.f32N/A
+-commutativeN/A
lower-fma.f32N/A
lower-PI.f3211.1
Applied rewrites11.1%
Applied rewrites11.3%
Final simplification11.3%
(FPCore (u s) :precision binary32 (* (* (fma -0.5 u 0.25) (PI)) -4.0))
\begin{array}{l}
\\
\left(\mathsf{fma}\left(-0.5, u, 0.25\right) \cdot \mathsf{PI}\left(\right)\right) \cdot -4
\end{array}
Initial program 99.0%
lift-/.f32N/A
clear-numN/A
associate-/r/N/A
lower-*.f32N/A
lower-/.f3299.0
Applied rewrites99.0%
Taylor expanded in s around -inf
*-commutativeN/A
lower-*.f32N/A
cancel-sign-sub-invN/A
*-commutativeN/A
distribute-rgt-out--N/A
metadata-evalN/A
associate-*r*N/A
metadata-evalN/A
*-commutativeN/A
distribute-lft-inN/A
+-commutativeN/A
*-commutativeN/A
lower-*.f32N/A
+-commutativeN/A
lower-fma.f32N/A
lower-PI.f3211.1
Applied rewrites11.1%
Final simplification11.1%
(FPCore (u s) :precision binary32 (- (PI)))
\begin{array}{l}
\\
-\mathsf{PI}\left(\right)
\end{array}
Initial program 99.0%
Taylor expanded in u around 0
mul-1-negN/A
lower-neg.f32N/A
lower-PI.f3211.1
Applied rewrites11.1%
herbie shell --seed 2024323
(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))))