
(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 (/ (PI) s))
(t_1 (+ 1.0 (exp t_0)))
(t_2 (/ 1.0 t_1))
(t_3 (* u (- (/ 1.0 (+ 1.0 (pow (exp -1.0) t_0))) t_2))))
(* (- s) (log (- (/ (- t_3 t_2) (- (pow t_3 2.0) (pow t_1 -2.0))) 1.0)))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{\mathsf{PI}\left(\right)}{s}\\
t_1 := 1 + e^{t\_0}\\
t_2 := \frac{1}{t\_1}\\
t_3 := u \cdot \left(\frac{1}{1 + {\left(e^{-1}\right)}^{t\_0}} - t\_2\right)\\
\left(-s\right) \cdot \log \left(\frac{t\_3 - t\_2}{{t\_3}^{2} - {t\_1}^{-2}} - 1\right)
\end{array}
\end{array}
Initial program 99.0%
Applied rewrites99.1%
Taylor expanded in s around 0
Applied rewrites99.1%
(FPCore (u s)
:precision binary32
(let* ((t_0 (exp (/ (PI) s))))
(*
(- s)
(log
(-
(/
1.0
(*
(-
(+ (/ 1.0 (* u (+ 1.0 t_0))) (/ 1.0 (+ (exp (/ (- (PI)) s)) 1.0)))
(/ 1.0 (+ t_0 1.0)))
u))
1.0)))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := e^{\frac{\mathsf{PI}\left(\right)}{s}}\\
\left(-s\right) \cdot \log \left(\frac{1}{\left(\left(\frac{1}{u \cdot \left(1 + t\_0\right)} + \frac{1}{e^{\frac{-\mathsf{PI}\left(\right)}{s}} + 1}\right) - \frac{1}{t\_0 + 1}\right) \cdot u} - 1\right)
\end{array}
\end{array}
Initial program 99.0%
Taylor expanded in u around inf
*-commutativeN/A
lower-*.f32N/A
Applied rewrites99.1%
Taylor expanded in u around 0
lower-/.f32N/A
lower-*.f32N/A
lower-+.f32N/A
lower-exp.f32N/A
lower-/.f32N/A
lower-PI.f3299.1
Applied rewrites99.1%
(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 99.0%
Applied rewrites99.0%
(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 99.0%
Taylor expanded in u around inf
*-commutativeN/A
lower-*.f32N/A
Applied rewrites98.2%
(FPCore (u s)
:precision binary32
(let* ((t_0 (/ (PI) s)))
(*
(- s)
(log
(-
(/
1.0
(+
(* u (- (/ 1.0 (+ 1.0 (exp (/ (- (PI)) s)))) (/ 1.0 (+ 2.0 t_0))))
(/ 1.0 (+ 1.0 (+ 1.0 (fma 0.5 (/ (* (PI) (PI)) (* s s)) 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}{2 + t\_0}\right) + \frac{1}{1 + \left(1 + \mathsf{fma}\left(0.5, \frac{\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)}{s \cdot s}, t\_0\right)\right)}} - 1\right)
\end{array}
\end{array}
Initial program 99.0%
Taylor expanded in s around inf
lower-+.f32N/A
lower-/.f32N/A
lower-PI.f3295.6
Applied rewrites95.6%
Taylor expanded in s around inf
lower-+.f32N/A
lower-fma.f32N/A
lower-/.f32N/A
unpow2N/A
lower-*.f32N/A
lower-PI.f32N/A
lower-PI.f32N/A
unpow2N/A
lower-*.f32N/A
lower-/.f32N/A
lower-PI.f3293.3
Applied rewrites93.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 t_0)))
(/ 1.0 (+ 2.0 (fma 0.5 (/ (* (PI) (PI)) (* s s)) 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}{t\_0}\right) + \frac{1}{2 + \mathsf{fma}\left(0.5, \frac{\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)}{s \cdot s}, t\_0\right)}} - 1\right)
\end{array}
\end{array}
Initial program 99.0%
Taylor expanded in s around inf
lower-+.f32N/A
lower-/.f32N/A
lower-PI.f3295.6
Applied rewrites95.6%
Taylor expanded in s around 0
lower-/.f32N/A
lower-PI.f3295.6
Applied rewrites95.6%
Taylor expanded in s around inf
lower-+.f32N/A
lower-fma.f32N/A
lower-/.f32N/A
unpow2N/A
lower-*.f32N/A
lower-PI.f32N/A
lower-PI.f32N/A
unpow2N/A
lower-*.f32N/A
lower-/.f32N/A
lower-PI.f3293.3
Applied rewrites93.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 t_0)))
(/ 1.0 (+ 2.0 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}{t\_0}\right) + \frac{1}{2 + t\_0}} - 1\right)
\end{array}
\end{array}
Initial program 99.0%
Taylor expanded in s around inf
lower-+.f32N/A
lower-/.f32N/A
lower-PI.f3295.6
Applied rewrites95.6%
Taylor expanded in s around 0
lower-/.f32N/A
lower-PI.f3295.6
Applied rewrites95.6%
Taylor expanded in s around inf
lower-+.f32N/A
lower-/.f32N/A
lower-PI.f3286.1
Applied rewrites86.1%
(FPCore (u s)
:precision binary32
(let* ((t_0 (/ (PI) s)))
(*
(- s)
(log
(-
(/ 1.0 (+ (* u (- 0.5 (/ 1.0 (+ 2.0 t_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(0.5 - \frac{1}{2 + t\_0}\right) + \frac{1}{1 + e^{t\_0}}} - 1\right)
\end{array}
\end{array}
Initial program 99.0%
Taylor expanded in s around inf
lower-+.f32N/A
lower-/.f32N/A
lower-PI.f3295.6
Applied rewrites95.6%
Taylor expanded in s around inf
Applied rewrites37.6%
(FPCore (u s)
:precision binary32
(let* ((t_0 (/ (PI) s)))
(*
(- s)
(log
(-
(/ 1.0 (+ (* u (- 0.5 (/ 1.0 t_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(0.5 - \frac{1}{t\_0}\right) + \frac{1}{1 + e^{t\_0}}} - 1\right)
\end{array}
\end{array}
Initial program 99.0%
Taylor expanded in s around inf
lower-+.f32N/A
lower-/.f32N/A
lower-PI.f3295.6
Applied rewrites95.6%
Taylor expanded in s around 0
lower-/.f32N/A
lower-PI.f3295.6
Applied rewrites95.6%
Taylor expanded in s around inf
Applied rewrites37.6%
(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 99.0%
Taylor expanded in s around inf
+-commutativeN/A
*-commutativeN/A
lower-fma.f32N/A
Applied rewrites25.4%
Taylor expanded in u around 0
lower-+.f32N/A
lower-/.f32N/A
lower-PI.f3225.5
Applied rewrites25.5%
(FPCore (u s) :precision binary32 (* u (fma -1.0 (/ (PI) u) (* 2.0 (PI)))))
\begin{array}{l}
\\
u \cdot \mathsf{fma}\left(-1, \frac{\mathsf{PI}\left(\right)}{u}, 2 \cdot \mathsf{PI}\left(\right)\right)
\end{array}
Initial program 99.0%
Taylor expanded in s around inf
*-commutativeN/A
lower-*.f32N/A
Applied rewrites11.3%
Taylor expanded in u around inf
lower-*.f32N/A
lower-fma.f32N/A
lower-/.f32N/A
lower-PI.f32N/A
lower-*.f32N/A
lower-PI.f3211.3
Applied rewrites11.3%
(FPCore (u s) :precision binary32 (fma -1.0 (PI) (* 2.0 (* u (PI)))))
\begin{array}{l}
\\
\mathsf{fma}\left(-1, \mathsf{PI}\left(\right), 2 \cdot \left(u \cdot \mathsf{PI}\left(\right)\right)\right)
\end{array}
Initial program 99.0%
Taylor expanded in s around inf
*-commutativeN/A
lower-*.f32N/A
Applied rewrites11.3%
Taylor expanded in u around 0
lower-fma.f32N/A
lower-PI.f32N/A
lower-*.f32N/A
lower-*.f32N/A
lower-PI.f3211.3
Applied rewrites11.3%
(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 2025044
(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))))