
(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 10 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 (- (log1p (exp (/ (PI) s))))))
(t_1
(* (fma (- (exp (- (log1p (exp (/ (- (PI)) s))))) t_0) u t_0) 2.0)))
(* (- s) (log (/ (- 2.0 t_1) t_1)))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := e^{-\mathsf{log1p}\left(e^{\frac{\mathsf{PI}\left(\right)}{s}}\right)}\\
t_1 := \mathsf{fma}\left(e^{-\mathsf{log1p}\left(e^{\frac{-\mathsf{PI}\left(\right)}{s}}\right)} - t\_0, u, t\_0\right) \cdot 2\\
\left(-s\right) \cdot \log \left(\frac{2 - t\_1}{t\_1}\right)
\end{array}
\end{array}
Initial program 99.0%
lift--.f32N/A
lift-/.f32N/A
metadata-evalN/A
frac-subN/A
lower-/.f32N/A
Applied rewrites99.1%
(FPCore (u s)
:precision binary32
(let* ((t_0 (exp (- (log1p (exp (/ (PI) s)))))))
(*
(- s)
(log
(expm1
(- (log (fma (- (exp (- (log1p (exp (/ (- (PI)) s))))) t_0) u t_0))))))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := e^{-\mathsf{log1p}\left(e^{\frac{\mathsf{PI}\left(\right)}{s}}\right)}\\
\left(-s\right) \cdot \log \left(\mathsf{expm1}\left(-\log \left(\mathsf{fma}\left(e^{-\mathsf{log1p}\left(e^{\frac{-\mathsf{PI}\left(\right)}{s}}\right)} - t\_0, u, t\_0\right)\right)\right)\right)
\end{array}
\end{array}
Initial program 99.0%
Applied rewrites99.0%
(FPCore (u s)
:precision binary32
(let* ((t_0 (exp (/ (PI) s))))
(*
(- s)
(log
(-
(/
1.0
(*
u
(-
(- (/ 1.0 (- (exp (/ (- (PI)) s)) -1.0)) (/ 1.0 (- t_0 -1.0)))
(/ -1.0 (fma t_0 u 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}{u \cdot \left(\left(\frac{1}{e^{\frac{-\mathsf{PI}\left(\right)}{s}} - -1} - \frac{1}{t\_0 - -1}\right) - \frac{-1}{\mathsf{fma}\left(t\_0, u, u\right)}\right)} - 1\right)
\end{array}
\end{array}
Initial program 99.0%
Taylor expanded in u around -inf
mul-1-negN/A
distribute-lft-neg-inN/A
lower-*.f32N/A
lower-neg.f32N/A
lower--.f32N/A
Applied rewrites99.0%
Final simplification99.0%
(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%
Taylor expanded in u around 0
*-commutativeN/A
lower-fma.f32N/A
Applied rewrites99.0%
Final simplification99.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.4%
Final simplification98.4%
(FPCore (u s) :precision binary32 (* (- s) (log (fma (/ (* -0.25 (PI)) s) -4.0 1.0))))
\begin{array}{l}
\\
\left(-s\right) \cdot \log \left(\mathsf{fma}\left(\frac{-0.25 \cdot \mathsf{PI}\left(\right)}{s}, -4, 1\right)\right)
\end{array}
Initial program 99.0%
Taylor expanded in s around inf
+-commutativeN/A
*-commutativeN/A
lower-fma.f32N/A
Applied rewrites25.0%
Taylor expanded in u around 0
lower-*.f32N/A
lower-PI.f3225.2
Applied rewrites25.2%
(FPCore (u s) :precision binary32 (* u (fma 2.0 (PI) (/ (- (PI)) u))))
\begin{array}{l}
\\
u \cdot \mathsf{fma}\left(2, \mathsf{PI}\left(\right), \frac{-\mathsf{PI}\left(\right)}{u}\right)
\end{array}
Initial program 99.0%
Taylor expanded in s around inf
*-commutativeN/A
lower-*.f32N/A
Applied rewrites11.1%
Taylor expanded in u around inf
lower-*.f32N/A
+-commutativeN/A
lower-fma.f32N/A
lower-PI.f32N/A
associate-*r/N/A
lower-/.f32N/A
mul-1-negN/A
lower-neg.f32N/A
lower-PI.f3211.1
Applied rewrites11.1%
(FPCore (u s) :precision binary32 (* (fma (* (PI) 0.5) u (* -0.25 (PI))) 4.0))
\begin{array}{l}
\\
\mathsf{fma}\left(\mathsf{PI}\left(\right) \cdot 0.5, u, -0.25 \cdot \mathsf{PI}\left(\right)\right) \cdot 4
\end{array}
Initial program 99.0%
Taylor expanded in s around inf
*-commutativeN/A
lower-*.f32N/A
Applied rewrites11.1%
(FPCore (u s) :precision binary32 (fma 2.0 (* u (PI)) (- (PI))))
\begin{array}{l}
\\
\mathsf{fma}\left(2, u \cdot \mathsf{PI}\left(\right), -\mathsf{PI}\left(\right)\right)
\end{array}
Initial program 99.0%
Taylor expanded in s around inf
*-commutativeN/A
lower-*.f32N/A
Applied rewrites11.1%
Taylor expanded in u around 0
+-commutativeN/A
lower-fma.f32N/A
lower-*.f32N/A
lower-PI.f32N/A
mul-1-negN/A
lower-neg.f32N/A
lower-PI.f3211.1
Applied rewrites11.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.f3210.8
Applied rewrites10.8%
herbie shell --seed 2025026
(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))))