
(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 (cbrt (PI))))
(*
(log
(-
(/
1.0
(+
(/ 1.0 (+ (exp (* (/ (- t_0) -1.0) (/ (pow t_0 2.0) s))) 1.0))
(*
(-
(/ -1.0 (- (exp (/ (PI) s)) -1.0))
(/ -1.0 (- (exp (/ (- (PI)) s)) -1.0)))
u)))
1.0))
(- s))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt[3]{\mathsf{PI}\left(\right)}\\
\log \left(\frac{1}{\frac{1}{e^{\frac{-t\_0}{-1} \cdot \frac{{t\_0}^{2}}{s}} + 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) \cdot \left(-s\right)
\end{array}
\end{array}
Initial program 99.0%
lift-/.f32N/A
frac-2negN/A
lift-PI.f32N/A
add-cube-cbrtN/A
distribute-rgt-neg-inN/A
neg-mul-1N/A
*-commutativeN/A
times-fracN/A
lower-*.f32N/A
lower-/.f32N/A
pow2N/A
lower-pow.f32N/A
lift-PI.f32N/A
lower-cbrt.f32N/A
lower-/.f32N/A
lower-neg.f32N/A
lift-PI.f32N/A
lower-cbrt.f3299.0
Applied rewrites99.0%
Final simplification99.0%
(FPCore (u s)
:precision binary32
(let* ((t_0 (/ -1.0 (- (exp (/ (PI) s)) -1.0))))
(*
(log
(-
(/ 1.0 (- (* (- t_0 (/ -1.0 (- (exp (/ (- (PI)) s)) -1.0))) u) t_0))
1.0))
(- s))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{-1}{e^{\frac{\mathsf{PI}\left(\right)}{s}} - -1}\\
\log \left(\frac{1}{\left(t\_0 - \frac{-1}{e^{\frac{-\mathsf{PI}\left(\right)}{s}} - -1}\right) \cdot u - t\_0} - 1\right) \cdot \left(-s\right)
\end{array}
\end{array}
Initial program 99.0%
Final simplification99.0%
(FPCore (u s)
:precision binary32
(*
(log
(-
(/
1.0
(*
(-
(/ -1.0 (- (exp (/ (PI) s)) -1.0))
(/ -1.0 (- (exp (/ (- (PI)) s)) -1.0)))
u))
1.0))
(- s)))\begin{array}{l}
\\
\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) \cdot \left(-s\right)
\end{array}
Initial program 99.0%
Taylor expanded in u around inf
*-commutativeN/A
lower-*.f32N/A
Applied rewrites98.0%
Final simplification98.0%
(FPCore (u s)
:precision binary32
(let* ((t_0 (/ (PI) s)) (t_1 (* t_0 (PI))))
(*
(log
(-
(/
-1.0
(-
(*
(-
(/ -1.0 (- (fma (/ 0.5 s) t_1 (- 1.0 t_0)) -1.0))
(/ -1.0 (- (- 1.0 (/ (- (* -0.5 t_1) (PI)) s)) -1.0)))
u)
(/ -1.0 (- -1.0 (exp t_0)))))
1.0))
(- s))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{\mathsf{PI}\left(\right)}{s}\\
t_1 := t\_0 \cdot \mathsf{PI}\left(\right)\\
\log \left(\frac{-1}{\left(\frac{-1}{\mathsf{fma}\left(\frac{0.5}{s}, t\_1, 1 - t\_0\right) - -1} - \frac{-1}{\left(1 - \frac{-0.5 \cdot t\_1 - \mathsf{PI}\left(\right)}{s}\right) - -1}\right) \cdot u - \frac{-1}{-1 - e^{t\_0}}} - 1\right) \cdot \left(-s\right)
\end{array}
\end{array}
Initial program 99.0%
Taylor expanded in s around inf
Applied rewrites37.9%
Taylor expanded in s around -inf
mul-1-negN/A
unsub-negN/A
lower--.f32N/A
lower-/.f32N/A
Applied rewrites37.9%
Taylor expanded in s around inf
associate-+r+N/A
+-commutativeN/A
associate-*r/N/A
unpow2N/A
times-fracN/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
mul-1-negN/A
unsub-negN/A
lower--.f32N/A
lower-/.f32N/A
lower-PI.f326.4
Applied rewrites7.7%
Final simplification8.1%
(FPCore (u s)
:precision binary32
(let* ((t_0 (/ (PI) s)))
(*
(log
(-
(/
1.0
(-
(*
(-
(/ 1.0 (- 1.0 -1.0))
(/ 1.0 (- (- 1.0 (/ (- (* -0.5 (* t_0 (PI))) (PI)) s)) -1.0)))
u)
(/ -1.0 (- (exp t_0) -1.0))))
1.0))
(- s))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{\mathsf{PI}\left(\right)}{s}\\
\log \left(\frac{1}{\left(\frac{1}{1 - -1} - \frac{1}{\left(1 - \frac{-0.5 \cdot \left(t\_0 \cdot \mathsf{PI}\left(\right)\right) - \mathsf{PI}\left(\right)}{s}\right) - -1}\right) \cdot u - \frac{-1}{e^{t\_0} - -1}} - 1\right) \cdot \left(-s\right)
\end{array}
\end{array}
Initial program 99.0%
Taylor expanded in s around inf
Applied rewrites37.9%
Taylor expanded in s around -inf
mul-1-negN/A
unsub-negN/A
lower--.f32N/A
lower-/.f32N/A
Applied rewrites37.9%
Final simplification37.9%
(FPCore (u s)
:precision binary32
(let* ((t_0 (/ (PI) s)))
(*
(log
(-
(/
-1.0
(-
(*
(-
(/ -1.0 (- 1.0 -1.0))
(/ -1.0 (- (- 1.0 (/ (* -0.5 (* t_0 (PI))) s)) -1.0)))
u)
(/ -1.0 (- -1.0 (exp t_0)))))
1.0))
(- s))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{\mathsf{PI}\left(\right)}{s}\\
\log \left(\frac{-1}{\left(\frac{-1}{1 - -1} - \frac{-1}{\left(1 - \frac{-0.5 \cdot \left(t\_0 \cdot \mathsf{PI}\left(\right)\right)}{s}\right) - -1}\right) \cdot u - \frac{-1}{-1 - e^{t\_0}}} - 1\right) \cdot \left(-s\right)
\end{array}
\end{array}
Initial program 99.0%
Taylor expanded in s around inf
Applied rewrites37.9%
Taylor expanded in s around -inf
mul-1-negN/A
unsub-negN/A
lower--.f32N/A
lower-/.f32N/A
Applied rewrites37.9%
Taylor expanded in s around 0
Applied rewrites37.9%
Final simplification37.9%
(FPCore (u s)
:precision binary32
(let* ((t_0 (/ (PI) s)))
(*
(log
(-
(/
-1.0
(-
(*
(- (/ -1.0 (- 1.0 -1.0)) (/ -1.0 (- (* (* t_0 (PI)) (/ 0.5 s)) -1.0)))
u)
(/ -1.0 (- -1.0 (exp t_0)))))
1.0))
(- s))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{\mathsf{PI}\left(\right)}{s}\\
\log \left(\frac{-1}{\left(\frac{-1}{1 - -1} - \frac{-1}{\left(t\_0 \cdot \mathsf{PI}\left(\right)\right) \cdot \frac{0.5}{s} - -1}\right) \cdot u - \frac{-1}{-1 - e^{t\_0}}} - 1\right) \cdot \left(-s\right)
\end{array}
\end{array}
Initial program 99.0%
Taylor expanded in s around inf
Applied rewrites37.9%
Taylor expanded in s around -inf
mul-1-negN/A
unsub-negN/A
lower--.f32N/A
lower-/.f32N/A
Applied rewrites37.9%
Taylor expanded in s around 0
Applied rewrites37.9%
Final simplification37.9%
(FPCore (u s)
:precision binary32
(let* ((t_0 (/ (PI) s)))
(*
(log
(-
(/
1.0
(-
(* (- (/ 1.0 (- 1.0 -1.0)) (/ 1.0 (- (+ t_0 1.0) -1.0))) u)
(/ -1.0 (- (exp t_0) -1.0))))
1.0))
(- s))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{\mathsf{PI}\left(\right)}{s}\\
\log \left(\frac{1}{\left(\frac{1}{1 - -1} - \frac{1}{\left(t\_0 + 1\right) - -1}\right) \cdot u - \frac{-1}{e^{t\_0} - -1}} - 1\right) \cdot \left(-s\right)
\end{array}
\end{array}
Initial program 99.0%
Taylor expanded in s around inf
Applied rewrites37.9%
Taylor expanded in s around inf
lower-+.f32N/A
lower-/.f32N/A
lower-PI.f3237.9
Applied rewrites37.9%
Final simplification37.9%
(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%
Taylor expanded in u around 0
mul-1-negN/A
lower-neg.f32N/A
lower-PI.f3211.5
Applied rewrites11.5%
Taylor expanded in s around -inf
*-commutativeN/A
lower-*.f32N/A
cancel-sign-sub-invN/A
distribute-rgt-out--N/A
metadata-evalN/A
*-commutativeN/A
metadata-evalN/A
associate-*r*N/A
*-commutativeN/A
distribute-rgt-outN/A
lower-*.f32N/A
lower-PI.f32N/A
lower-fma.f3211.5
Applied rewrites11.5%
Applied rewrites11.7%
Final simplification11.7%
(FPCore (u s) :precision binary32 (* (* (- (PI)) u) 2.0))
\begin{array}{l}
\\
\left(\left(-\mathsf{PI}\left(\right)\right) \cdot u\right) \cdot 2
\end{array}
Initial program 99.0%
Taylor expanded in u around 0
mul-1-negN/A
lower-neg.f32N/A
lower-PI.f3211.5
Applied rewrites11.5%
Taylor expanded in s around -inf
*-commutativeN/A
lower-*.f32N/A
cancel-sign-sub-invN/A
distribute-rgt-out--N/A
metadata-evalN/A
*-commutativeN/A
metadata-evalN/A
associate-*r*N/A
*-commutativeN/A
distribute-rgt-outN/A
lower-*.f32N/A
lower-PI.f32N/A
lower-fma.f3211.5
Applied rewrites11.5%
Taylor expanded in u around inf
Applied rewrites4.9%
Applied rewrites12.6%
Final simplification12.6%
(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.5
Applied rewrites11.5%
herbie shell --seed 2024268
(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))))