
(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 15 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 (/ (PI) s)))
(*
(- s)
(log
(-
(/
1.0
(+
(*
u
(- (/ 1.0 (+ 1.0 (exp (/ (- (PI)) s)))) (/ 1.0 (+ 1.0 (exp t_0)))))
(/ 1.0 (+ 1.0 (pow (E) 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}{u \cdot \left(\frac{1}{1 + e^{\frac{-\mathsf{PI}\left(\right)}{s}}} - \frac{1}{1 + e^{t\_0}}\right) + \frac{1}{1 + {\mathsf{E}\left(\right)}^{t\_0}}} - 1\right)
\end{array}
\end{array}
Initial program 98.9%
lift-exp.f32N/A
lift-/.f32N/A
clear-numN/A
div-invN/A
clear-numN/A
lift-/.f32N/A
exp-prodN/A
lower-pow.f32N/A
exp-1-eN/A
lower-E.f3298.9
Applied rewrites98.9%
(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 98.9%
(FPCore (u s)
:precision binary32
(let* ((t_0 (/ (PI) s)))
(*
(- s)
(log
(-
(/
1.0
(+
(*
u
(-
(/ 1.0 (+ 1.0 (exp (/ (- (PI)) s))))
(/ 1.0 (+ 1.0 (- 1.0 (/ (- (* (* (PI) t_0) -0.5) (PI)) s))))))
(/ 1.0 (+ 1.0 (exp 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}{u \cdot \left(\frac{1}{1 + e^{\frac{-\mathsf{PI}\left(\right)}{s}}} - \frac{1}{1 + \left(1 - \frac{\left(\mathsf{PI}\left(\right) \cdot t\_0\right) \cdot -0.5 - \mathsf{PI}\left(\right)}{s}\right)}\right) + \frac{1}{1 + e^{t\_0}}} - 1\right)
\end{array}
\end{array}
Initial program 98.9%
Taylor expanded in s around -inf
mul-1-negN/A
unsub-negN/A
lower--.f32N/A
lower-/.f32N/A
Applied rewrites96.9%
(FPCore (u s)
:precision binary32
(*
(- s)
(log
(-
(/
1.0
(+
(*
u
(-
(/ 1.0 (+ 1.0 (exp (/ (- (PI)) s))))
(/ 1.0 (+ 1.0 (+ (/ (PI) s) 1.0)))))
(/ 1.0 (+ 1.0 (exp (* (/ 1.0 s) (PI)))))))
1.0))))\begin{array}{l}
\\
\left(-s\right) \cdot \log \left(\frac{1}{u \cdot \left(\frac{1}{1 + e^{\frac{-\mathsf{PI}\left(\right)}{s}}} - \frac{1}{1 + \left(\frac{\mathsf{PI}\left(\right)}{s} + 1\right)}\right) + \frac{1}{1 + e^{\frac{1}{s} \cdot \mathsf{PI}\left(\right)}}} - 1\right)
\end{array}
Initial program 98.9%
Taylor expanded in s around inf
+-commutativeN/A
lower-+.f32N/A
lower-/.f32N/A
lower-PI.f3294.3
Applied rewrites94.3%
lift-/.f32N/A
clear-numN/A
associate-/r/N/A
lower-*.f32N/A
lower-/.f3294.3
Applied rewrites94.3%
(FPCore (u s)
:precision binary32
(let* ((t_0 (/ (PI) s)))
(*
(- s)
(log
(-
(/
1.0
(+
(*
u
(- (/ 1.0 (+ 1.0 (exp (/ (- (PI)) s)))) (/ 1.0 (+ 1.0 (+ t_0 1.0)))))
(/ 1.0 (+ 1.0 (exp 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}{u \cdot \left(\frac{1}{1 + e^{\frac{-\mathsf{PI}\left(\right)}{s}}} - \frac{1}{1 + \left(t\_0 + 1\right)}\right) + \frac{1}{1 + e^{t\_0}}} - 1\right)
\end{array}
\end{array}
Initial program 98.9%
Taylor expanded in s around inf
+-commutativeN/A
lower-+.f32N/A
lower-/.f32N/A
lower-PI.f3294.3
Applied rewrites94.3%
(FPCore (u s)
:precision binary32
(*
(- s)
(log
(-
(/
1.0
(+
(* u (- (/ 1.0 (+ 1.0 (exp (/ (- (PI)) s)))) (/ 1.0 (+ 1.0 1.0))))
(/ 1.0 (+ 1.0 (exp (/ (PI) s))))))
1.0))))\begin{array}{l}
\\
\left(-s\right) \cdot \log \left(\frac{1}{u \cdot \left(\frac{1}{1 + e^{\frac{-\mathsf{PI}\left(\right)}{s}}} - \frac{1}{1 + 1}\right) + \frac{1}{1 + e^{\frac{\mathsf{PI}\left(\right)}{s}}}} - 1\right)
\end{array}
Initial program 98.9%
Taylor expanded in s around inf
Applied rewrites37.2%
(FPCore (u s)
:precision binary32
(let* ((t_0 (/ (PI) s)))
(if (<= s 1.0000000168623835e-16)
(*
(- s)
(log (- (/ 1.0 (fma (* (* -0.5 u) (- (PI))) (/ 1.0 s) 0.5)) 1.0)))
(*
(- s)
(log
(-
(/ 1.0 (* (- u) (fma (/ (- 0.5 (* 0.25 t_0)) u) -1.0 (* -0.5 t_0))))
1.0))))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{\mathsf{PI}\left(\right)}{s}\\
\mathbf{if}\;s \leq 1.0000000168623835 \cdot 10^{-16}:\\
\;\;\;\;\left(-s\right) \cdot \log \left(\frac{1}{\mathsf{fma}\left(\left(-0.5 \cdot u\right) \cdot \left(-\mathsf{PI}\left(\right)\right), \frac{1}{s}, 0.5\right)} - 1\right)\\
\mathbf{else}:\\
\;\;\;\;\left(-s\right) \cdot \log \left(\frac{1}{\left(-u\right) \cdot \mathsf{fma}\left(\frac{0.5 - 0.25 \cdot t\_0}{u}, -1, -0.5 \cdot t\_0\right)} - 1\right)\\
\end{array}
\end{array}
if s < 1.00000002e-16Initial 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 rewrites12.3%
Taylor expanded in u around inf
Applied rewrites12.2%
Taylor expanded in u around inf
Applied rewrites12.2%
if 1.00000002e-16 < s Initial program 98.8%
Taylor expanded in s around -inf
mul-1-negN/A
unsub-negN/A
lower--.f32N/A
lower-/.f32N/A
Applied rewrites-0.0%
Taylor expanded in u around -inf
Applied rewrites7.9%
(FPCore (u s)
:precision binary32
(let* ((t_0 (- (PI))))
(if (<= s 3.0000001167615996e-16)
(* (- s) (log (- (/ 1.0 (fma (* (* -0.5 u) t_0) (/ 1.0 s) 0.5)) 1.0)))
(* (- s) (log (- (/ 1.0 (fma (fma -0.5 u 0.25) (/ t_0 s) 0.5)) 1.0))))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := -\mathsf{PI}\left(\right)\\
\mathbf{if}\;s \leq 3.0000001167615996 \cdot 10^{-16}:\\
\;\;\;\;\left(-s\right) \cdot \log \left(\frac{1}{\mathsf{fma}\left(\left(-0.5 \cdot u\right) \cdot t\_0, \frac{1}{s}, 0.5\right)} - 1\right)\\
\mathbf{else}:\\
\;\;\;\;\left(-s\right) \cdot \log \left(\frac{1}{\mathsf{fma}\left(\mathsf{fma}\left(-0.5, u, 0.25\right), \frac{t\_0}{s}, 0.5\right)} - 1\right)\\
\end{array}
\end{array}
if s < 3.0000001e-16Initial 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 rewrites12.2%
Taylor expanded in u around inf
Applied rewrites12.1%
Taylor expanded in u around inf
Applied rewrites12.1%
if 3.0000001e-16 < s Initial program 98.8%
Taylor expanded in s around -inf
mul-1-negN/A
unsub-negN/A
lower--.f32N/A
lower-/.f32N/A
Applied rewrites-0.0%
Applied rewrites7.2%
Applied rewrites7.2%
(FPCore (u s) :precision binary32 (if (<= s 2.000000033724767e-16) (fma (fma (* 0.5 (PI)) u (* -0.25 (pow (PI) 1.0))) 4.0 (* (/ 0.0 s) -0.5)) (* (- s) (log (- (/ 1.0 (fma (fma -0.5 u 0.25) (/ (- (PI)) s) 0.5)) 1.0)))))
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;s \leq 2.000000033724767 \cdot 10^{-16}:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(0.5 \cdot \mathsf{PI}\left(\right), u, -0.25 \cdot {\mathsf{PI}\left(\right)}^{1}\right), 4, \frac{0}{s} \cdot -0.5\right)\\
\mathbf{else}:\\
\;\;\;\;\left(-s\right) \cdot \log \left(\frac{1}{\mathsf{fma}\left(\mathsf{fma}\left(-0.5, u, 0.25\right), \frac{-\mathsf{PI}\left(\right)}{s}, 0.5\right)} - 1\right)\\
\end{array}
\end{array}
if s < 2.00000003e-16Initial program 99.0%
lift-exp.f32N/A
lift-/.f32N/A
clear-numN/A
div-invN/A
clear-numN/A
lift-/.f32N/A
exp-prodN/A
lower-pow.f32N/A
exp-1-eN/A
lower-E.f3299.0
Applied rewrites99.0%
Taylor expanded in s around inf
Applied rewrites6.3%
Applied rewrites7.2%
Taylor expanded in u around 0
Applied rewrites4.4%
if 2.00000003e-16 < s Initial program 98.8%
Taylor expanded in s around -inf
mul-1-negN/A
unsub-negN/A
lower--.f32N/A
lower-/.f32N/A
Applied rewrites-0.0%
Applied rewrites7.3%
Applied rewrites7.3%
Final simplification2.6%
(FPCore (u s) :precision binary32 (* (* (PI) (/ (- (* (* -0.5 u) (* -0.5 u)) 0.0625) (- (* -0.5 u) 0.25))) -4.0))
\begin{array}{l}
\\
\left(\mathsf{PI}\left(\right) \cdot \frac{\left(-0.5 \cdot u\right) \cdot \left(-0.5 \cdot u\right) - 0.0625}{-0.5 \cdot u - 0.25}\right) \cdot -4
\end{array}
Initial program 98.9%
Taylor expanded in s around -inf
*-commutativeN/A
lower-*.f32N/A
cancel-sign-sub-invN/A
metadata-evalN/A
*-commutativeN/A
*-commutativeN/A
distribute-rgt-out--N/A
metadata-evalN/A
associate-*l*N/A
distribute-lft-outN/A
lower-*.f32N/A
lower-PI.f32N/A
lower-fma.f3211.1
Applied rewrites11.1%
Applied rewrites11.4%
(FPCore (u s) :precision binary32 (* (- (* 2.0 (PI)) (/ (PI) u)) u))
\begin{array}{l}
\\
\left(2 \cdot \mathsf{PI}\left(\right) - \frac{\mathsf{PI}\left(\right)}{u}\right) \cdot u
\end{array}
Initial program 98.9%
Taylor expanded in s around -inf
*-commutativeN/A
lower-*.f32N/A
cancel-sign-sub-invN/A
metadata-evalN/A
*-commutativeN/A
*-commutativeN/A
distribute-rgt-out--N/A
metadata-evalN/A
associate-*l*N/A
distribute-lft-outN/A
lower-*.f32N/A
lower-PI.f32N/A
lower-fma.f3211.1
Applied rewrites11.1%
Taylor expanded in u around inf
Applied rewrites11.4%
(FPCore (u s) :precision binary32 (* (+ (* (* -0.5 u) (PI)) (* 0.25 (PI))) -4.0))
\begin{array}{l}
\\
\left(\left(-0.5 \cdot u\right) \cdot \mathsf{PI}\left(\right) + 0.25 \cdot \mathsf{PI}\left(\right)\right) \cdot -4
\end{array}
Initial program 98.9%
Taylor expanded in s around -inf
*-commutativeN/A
lower-*.f32N/A
cancel-sign-sub-invN/A
metadata-evalN/A
*-commutativeN/A
*-commutativeN/A
distribute-rgt-out--N/A
metadata-evalN/A
associate-*l*N/A
distribute-lft-outN/A
lower-*.f32N/A
lower-PI.f32N/A
lower-fma.f3211.1
Applied rewrites11.1%
Applied rewrites11.4%
(FPCore (u s) :precision binary32 (* (* (PI) (+ (* -0.5 u) 0.25)) -4.0))
\begin{array}{l}
\\
\left(\mathsf{PI}\left(\right) \cdot \left(-0.5 \cdot u + 0.25\right)\right) \cdot -4
\end{array}
Initial program 98.9%
Taylor expanded in s around -inf
*-commutativeN/A
lower-*.f32N/A
cancel-sign-sub-invN/A
metadata-evalN/A
*-commutativeN/A
*-commutativeN/A
distribute-rgt-out--N/A
metadata-evalN/A
associate-*l*N/A
distribute-lft-outN/A
lower-*.f32N/A
lower-PI.f32N/A
lower-fma.f3211.1
Applied rewrites11.1%
Applied rewrites11.4%
(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 s around -inf
*-commutativeN/A
lower-*.f32N/A
cancel-sign-sub-invN/A
metadata-evalN/A
*-commutativeN/A
*-commutativeN/A
distribute-rgt-out--N/A
metadata-evalN/A
associate-*l*N/A
distribute-lft-outN/A
lower-*.f32N/A
lower-PI.f32N/A
lower-fma.f3211.1
Applied rewrites11.1%
(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.1
Applied rewrites11.1%
herbie shell --seed 2024322
(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))))