
(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 18 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 (/ 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 99.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.5%
(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 rewrites98.5%
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.5
Applied rewrites97.5%
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.5
Applied rewrites97.5%
(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 rewrites98.5%
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.5
Applied rewrites97.5%
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.5
Applied rewrites97.5%
(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 rewrites98.5%
Taylor expanded in s around inf
lower-+.f32N/A
lift-/.f32N/A
lift-PI.f3294.9
Applied rewrites94.9%
(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 rewrites98.5%
Taylor expanded in s around inf
Applied rewrites37.5%
(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 rewrites98.5%
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.5
Applied rewrites97.5%
Taylor expanded in s around inf
Applied rewrites37.5%
(FPCore (u s)
:precision binary32
(*
(- s)
(log
(+
1.0
(* -4.0 (/ (fma -0.0625 (fma 4.0 (PI) (* 8.0 (PI))) (* 0.5 (PI))) s))))))\begin{array}{l}
\\
\left(-s\right) \cdot \log \left(1 + -4 \cdot \frac{\mathsf{fma}\left(-0.0625, \mathsf{fma}\left(4, \mathsf{PI}\left(\right), 8 \cdot \mathsf{PI}\left(\right)\right), 0.5 \cdot \mathsf{PI}\left(\right)\right)}{s}\right)
\end{array}
Initial program 99.0%
Applied rewrites99.0%
Taylor expanded in s around inf
Applied rewrites25.6%
Taylor expanded in u around 0
lower-*.f32N/A
lower-/.f32N/A
lift-*.f32N/A
lift-PI.f32N/A
lift-fma.f32N/A
lift-PI.f32N/A
lift-*.f32N/A
lift-PI.f32N/A
lift-fma.f3225.7
Applied rewrites25.7%
(FPCore (u s) :precision binary32 (* (- s) (log (- (- 2.0 (* -0.25 (/ (fma 4.0 (PI) (* 8.0 (PI))) s))) 1.0))))
\begin{array}{l}
\\
\left(-s\right) \cdot \log \left(\left(2 - -0.25 \cdot \frac{\mathsf{fma}\left(4, \mathsf{PI}\left(\right), 8 \cdot \mathsf{PI}\left(\right)\right)}{s}\right) - 1\right)
\end{array}
Initial program 99.0%
Applied rewrites99.0%
Taylor expanded in s around inf
Applied rewrites25.5%
Taylor expanded in s around inf
Applied rewrites25.6%
(FPCore (u s) :precision binary32 (* (- s) (log (fma (/ (fma (* (PI) 0.5) u (* -0.25 (PI))) s) -4.0 1.0))))
\begin{array}{l}
\\
\left(-s\right) \cdot \log \left(\mathsf{fma}\left(\frac{\mathsf{fma}\left(\mathsf{PI}\left(\right) \cdot 0.5, u, -0.25 \cdot \mathsf{PI}\left(\right)\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.6%
Final simplification25.6%
(FPCore (u s)
:precision binary32
(*
(- s)
(/
(*
u
(fma
4.0
(- (* -0.25 (PI)) (* 0.25 (PI)))
(* 4.0 (/ (fma -0.5 (PI) (* -0.0625 (fma -8.0 (PI) (* -4.0 (PI))))) u))))
s)))\begin{array}{l}
\\
\left(-s\right) \cdot \frac{u \cdot \mathsf{fma}\left(4, -0.25 \cdot \mathsf{PI}\left(\right) - 0.25 \cdot \mathsf{PI}\left(\right), 4 \cdot \frac{\mathsf{fma}\left(-0.5, \mathsf{PI}\left(\right), -0.0625 \cdot \mathsf{fma}\left(-8, \mathsf{PI}\left(\right), -4 \cdot \mathsf{PI}\left(\right)\right)\right)}{u}\right)}{s}
\end{array}
Initial program 99.0%
Applied rewrites99.0%
Taylor expanded in s around -inf
Applied rewrites11.6%
Taylor expanded in u around inf
lower-*.f32N/A
lower-fma.f32N/A
lift-*.f32N/A
lift-PI.f32N/A
lift-*.f32N/A
lift-PI.f32N/A
lift--.f32N/A
Applied rewrites11.6%
(FPCore (u s) :precision binary32 (* (- s) (fma 4.0 (/ (* u (- (* -0.25 (PI)) (* 0.25 (PI)))) s) (* 4.0 (/ (fma -0.5 (PI) (* -0.0625 (fma -8.0 (PI) (* -4.0 (PI))))) s)))))
\begin{array}{l}
\\
\left(-s\right) \cdot \mathsf{fma}\left(4, \frac{u \cdot \left(-0.25 \cdot \mathsf{PI}\left(\right) - 0.25 \cdot \mathsf{PI}\left(\right)\right)}{s}, 4 \cdot \frac{\mathsf{fma}\left(-0.5, \mathsf{PI}\left(\right), -0.0625 \cdot \mathsf{fma}\left(-8, \mathsf{PI}\left(\right), -4 \cdot \mathsf{PI}\left(\right)\right)\right)}{s}\right)
\end{array}
Initial program 99.0%
Applied rewrites99.0%
Taylor expanded in s around -inf
Applied rewrites11.6%
Taylor expanded in u around 0
lower-fma.f32N/A
Applied rewrites11.6%
(FPCore (u s) :precision binary32 (fma 4.0 (* u (- (* 0.25 (PI)) (* -0.25 (PI)))) (* 4.0 (fma -0.0625 (fma 4.0 (PI) (* 8.0 (PI))) (* 0.5 (PI))))))
\begin{array}{l}
\\
\mathsf{fma}\left(4, u \cdot \left(0.25 \cdot \mathsf{PI}\left(\right) - -0.25 \cdot \mathsf{PI}\left(\right)\right), 4 \cdot \mathsf{fma}\left(-0.0625, \mathsf{fma}\left(4, \mathsf{PI}\left(\right), 8 \cdot \mathsf{PI}\left(\right)\right), 0.5 \cdot \mathsf{PI}\left(\right)\right)\right)
\end{array}
Initial program 99.0%
Applied rewrites99.0%
Taylor expanded in s around inf
Applied rewrites11.6%
(FPCore (u s) :precision binary32 (* (- s) (* (/ (fma (* (PI) 0.5) u (* -0.25 (PI))) s) -4.0)))
\begin{array}{l}
\\
\left(-s\right) \cdot \left(\frac{\mathsf{fma}\left(\mathsf{PI}\left(\right) \cdot 0.5, u, -0.25 \cdot \mathsf{PI}\left(\right)\right)}{s} \cdot -4\right)
\end{array}
Initial program 99.0%
Taylor expanded in s around inf
*-commutativeN/A
lower-*.f32N/A
Applied rewrites11.6%
(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.6%
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.6
Applied rewrites11.6%
(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.6%
(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.6%
Taylor expanded in u around 0
lower-fma.f32N/A
lift-PI.f32N/A
lower-*.f32N/A
lower-*.f32N/A
lift-PI.f3211.6
Applied rewrites11.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
lift-neg.f32N/A
lift-PI.f3211.5
Applied rewrites11.5%
herbie shell --seed 2025028
(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))))