
(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 14 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))))
(*
(- 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.0%
Taylor expanded in u around 0
lower-/.f32N/A
lower-*.f32N/A
lift-/.f32N/A
lift-PI.f32N/A
lift-exp.f32N/A
lift-+.f3299.0
Applied rewrites99.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%
Applied rewrites99.0%
(FPCore (u s)
:precision binary32
(let* ((t_0 (- (PI))))
(*
(- s)
(log
(-
(/
1.0
(+
(*
u
(-
(/ 1.0 (+ 1.0 (exp (/ t_0 s))))
(/ 1.0 (fma (/ (fma (/ (* (PI) (PI)) s) -0.5 t_0) s) -1.0 2.0))))
(/ 1.0 (+ 1.0 (exp (/ (PI) s))))))
1.0)))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := -\mathsf{PI}\left(\right)\\
\left(-s\right) \cdot \log \left(\frac{1}{u \cdot \left(\frac{1}{1 + e^{\frac{t\_0}{s}}} - \frac{1}{\mathsf{fma}\left(\frac{\mathsf{fma}\left(\frac{\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)}{s}, -0.5, t\_0\right)}{s}, -1, 2\right)}\right) + \frac{1}{1 + e^{\frac{\mathsf{PI}\left(\right)}{s}}}} - 1\right)
\end{array}
\end{array}
Initial program 99.0%
Taylor expanded in s around -inf
+-commutativeN/A
*-commutativeN/A
lower-fma.f32N/A
Applied rewrites97.6%
(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 rewrites97.6%
(FPCore (u s)
:precision binary32
(*
(- s)
(log
(-
(/
1.0
(*
(-
(/ 1.0 (+ (exp (/ (- (PI)) s)) 1.0))
(/ 1.0 (+ 2.0 (/ (fma 0.5 (* (PI) (PI)) (* s (PI))) (* s s)))))
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}{2 + \frac{\mathsf{fma}\left(0.5, \mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right), s \cdot \mathsf{PI}\left(\right)\right)}{s \cdot s}}\right) \cdot u} - 1\right)
\end{array}
Initial program 99.0%
Taylor expanded in u around inf
*-commutativeN/A
lower-*.f32N/A
Applied rewrites97.6%
Taylor expanded in s around inf
lower-+.f32N/A
lower-fma.f32N/A
lower-/.f32N/A
unpow2N/A
lower-*.f32N/A
lift-PI.f32N/A
lift-PI.f32N/A
unpow2N/A
lower-*.f32N/A
lift-/.f32N/A
lift-PI.f3297.0
Applied rewrites97.0%
Taylor expanded in s around 0
lower-/.f32N/A
lower-fma.f32N/A
pow2N/A
lift-*.f32N/A
lift-PI.f32N/A
lift-PI.f32N/A
lower-*.f32N/A
lift-PI.f32N/A
pow2N/A
lift-*.f3297.0
Applied rewrites97.0%
Final simplification97.0%
(FPCore (u s)
:precision binary32
(*
(- s)
(log
(-
(/
1.0
(*
(-
(/ 1.0 (+ (exp (/ (- (PI)) s)) 1.0))
(/ 1.0 (/ (fma 0.5 (* (PI) (PI)) (* s (PI))) (* s s))))
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}{\frac{\mathsf{fma}\left(0.5, \mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right), s \cdot \mathsf{PI}\left(\right)\right)}{s \cdot s}}\right) \cdot u} - 1\right)
\end{array}
Initial program 99.0%
Taylor expanded in u around inf
*-commutativeN/A
lower-*.f32N/A
Applied rewrites97.6%
Taylor expanded in s around inf
lower-+.f32N/A
lower-fma.f32N/A
lower-/.f32N/A
unpow2N/A
lower-*.f32N/A
lift-PI.f32N/A
lift-PI.f32N/A
unpow2N/A
lower-*.f32N/A
lift-/.f32N/A
lift-PI.f3297.0
Applied rewrites97.0%
Taylor expanded in s around 0
lower-/.f32N/A
lower-fma.f32N/A
pow2N/A
lift-*.f32N/A
lift-PI.f32N/A
lift-PI.f32N/A
lower-*.f32N/A
lift-PI.f32N/A
pow2N/A
lift-*.f3297.0
Applied rewrites97.0%
Final simplification97.0%
(FPCore (u s)
:precision binary32
(*
(- s)
(log
(-
(/
1.0
(* (- (/ 1.0 (+ (exp (/ (- (PI)) s)) 1.0)) (/ 1.0 (+ 2.0 (/ (PI) s)))) 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}{2 + \frac{\mathsf{PI}\left(\right)}{s}}\right) \cdot u} - 1\right)
\end{array}
Initial program 99.0%
Taylor expanded in u around inf
*-commutativeN/A
lower-*.f32N/A
Applied rewrites97.6%
Taylor expanded in s around inf
lower-+.f32N/A
lift-/.f32N/A
lift-PI.f3295.8
Applied rewrites95.8%
Final simplification95.8%
(FPCore (u s) :precision binary32 (* (- s) (log (- (/ 1.0 (* (- 0.5 (/ 1.0 (+ (exp (/ (PI) s)) 1.0))) u)) 1.0))))
\begin{array}{l}
\\
\left(-s\right) \cdot \log \left(\frac{1}{\left(0.5 - \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 rewrites97.6%
Taylor expanded in s around inf
Applied rewrites37.3%
(FPCore (u s)
:precision binary32
(*
(- s)
(log
(-
(/
1.0
(*
(- 0.5 (/ 1.0 (+ 2.0 (fma 0.5 (/ (* (PI) (PI)) (* s s)) (/ (PI) s)))))
u))
1.0))))\begin{array}{l}
\\
\left(-s\right) \cdot \log \left(\frac{1}{\left(0.5 - \frac{1}{2 + \mathsf{fma}\left(0.5, \frac{\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)}{s \cdot s}, \frac{\mathsf{PI}\left(\right)}{s}\right)}\right) \cdot u} - 1\right)
\end{array}
Initial program 99.0%
Taylor expanded in u around inf
*-commutativeN/A
lower-*.f32N/A
Applied rewrites97.6%
Taylor expanded in s around inf
lower-+.f32N/A
lower-fma.f32N/A
lower-/.f32N/A
unpow2N/A
lower-*.f32N/A
lift-PI.f32N/A
lift-PI.f32N/A
unpow2N/A
lower-*.f32N/A
lift-/.f32N/A
lift-PI.f3297.0
Applied rewrites97.0%
Taylor expanded in s around inf
Applied rewrites37.3%
Final simplification37.3%
(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 rewrites24.9%
Taylor expanded in u around 0
lower-+.f32N/A
lift-/.f32N/A
lift-PI.f3225.0
Applied rewrites25.0%
(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.1%
Taylor expanded in u around inf
lower-*.f32N/A
lower-fma.f32N/A
lower-/.f32N/A
lift-PI.f32N/A
lower-*.f32N/A
lift-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 -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.1%
Taylor expanded in u around 0
lower-fma.f32N/A
lift-PI.f32N/A
lower-*.f32N/A
lower-*.f32N/A
lift-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
lift-neg.f32N/A
lift-PI.f3210.9
Applied rewrites10.9%
herbie shell --seed 2025043
(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))))