
(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 17 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 (+ (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)))
(*
(- s)
(log
(-
(/
1.0
(fma
(-
(/ 1.0 (+ (exp (/ (- (PI)) s)) 1.0))
(/
1.0
(+
2.0
(fma
0.16666666666666666
(* t_0 (* t_0 t_0))
(fma 0.5 (/ (* (PI) (PI)) (* s s)) t_0)))))
u
(/ 1.0 (+ (exp t_0) 1.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}{\mathsf{fma}\left(\frac{1}{e^{\frac{-\mathsf{PI}\left(\right)}{s}} + 1} - \frac{1}{2 + \mathsf{fma}\left(0.16666666666666666, t\_0 \cdot \left(t\_0 \cdot t\_0\right), \mathsf{fma}\left(0.5, \frac{\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)}{s \cdot s}, t\_0\right)\right)}, u, \frac{1}{e^{t\_0} + 1}\right)} - 1\right)
\end{array}
\end{array}
Initial program 99.0%
Applied rewrites99.0%
Taylor expanded in s around inf
lower-+.f32N/A
lower-fma.f32N/A
cube-div-revN/A
lower-pow.f32N/A
lift-/.f32N/A
lift-PI.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.f3298.0
Applied rewrites98.0%
lift-pow.f32N/A
lift-PI.f32N/A
lift-/.f32N/A
cube-multN/A
times-fracN/A
lift-*.f32N/A
lift-PI.f32N/A
lift-PI.f32N/A
lift-/.f32N/A
lift-*.f32N/A
lower-*.f32N/A
lift-/.f32N/A
lift-PI.f3298.0
lift-*.f32N/A
lift-/.f32N/A
lift-PI.f32N/A
lift-PI.f32N/A
lift-*.f32N/A
times-fracN/A
lower-*.f32N/A
Applied rewrites98.0%
Final simplification98.0%
(FPCore (u s)
:precision binary32
(*
(- s)
(log
(-
(/
1.0
(fma
(-
(/ 1.0 (+ (exp (/ (- (PI)) s)) 1.0))
(/ 1.0 (+ 2.0 (/ (+ (PI) (* 0.5 (/ (* (PI) (PI)) s))) s))))
u
(/ 1.0 (+ (exp (/ (PI) s)) 1.0))))
1.0))))\begin{array}{l}
\\
\left(-s\right) \cdot \log \left(\frac{1}{\mathsf{fma}\left(\frac{1}{e^{\frac{-\mathsf{PI}\left(\right)}{s}} + 1} - \frac{1}{2 + \frac{\mathsf{PI}\left(\right) + 0.5 \cdot \frac{\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)}{s}}{s}}, u, \frac{1}{e^{\frac{\mathsf{PI}\left(\right)}{s}} + 1}\right)} - 1\right)
\end{array}
Initial program 99.0%
Applied rewrites99.0%
Taylor expanded in s around inf
lower-+.f32N/A
lower-fma.f32N/A
cube-div-revN/A
lower-pow.f32N/A
lift-/.f32N/A
lift-PI.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.f3298.0
Applied rewrites98.0%
Taylor expanded in s around inf
lower-/.f32N/A
lower-+.f32N/A
lift-PI.f32N/A
lower-*.f32N/A
lower-/.f32N/A
pow2N/A
lift-*.f32N/A
lift-PI.f32N/A
lift-PI.f3297.3
Applied rewrites97.3%
Final simplification97.3%
(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 rewrites96.6%
(FPCore (u s) :precision binary32 (let* ((t_0 (/ 1.0 (+ (exp (/ (PI) s)) 1.0)))) (* (- s) (log (- (/ 1.0 (fma (- 0.5 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(0.5 - t\_0, u, t\_0\right)} - 1\right)
\end{array}
\end{array}
Initial program 99.0%
Applied rewrites99.0%
Taylor expanded in s around inf
Applied rewrites38.6%
Final simplification38.6%
(FPCore (u s)
:precision binary32
(let* ((t_0 (/ (PI) s)))
(*
(- s)
(log
(-
(/
1.0
(+
(* u (- 0.5 (/ 1.0 (+ 2.0 (fma 0.5 (/ (* (PI) (PI)) (* s s)) 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 + \mathsf{fma}\left(0.5, \frac{\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)}{s \cdot s}, t\_0\right)}\right) + \frac{1}{1 + e^{t\_0}}} - 1\right)
\end{array}
\end{array}
Initial program 99.0%
Taylor expanded in s around inf
+-commutativeN/A
lower-fma.f32N/A
lift-/.f32N/A
lift-PI.f324.9
Applied rewrites4.9%
Taylor expanded in s around inf
lower-+.f32N/A
lift-/.f32N/A
lift-PI.f324.9
Applied rewrites4.9%
Taylor expanded in s around inf
Applied rewrites38.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.f3238.6
Applied rewrites38.6%
(FPCore (u s)
:precision binary32
(let* ((t_0 (/ (PI) s)))
(*
(- s)
(log
(-
(/ 1.0 (fma 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}{\mathsf{fma}\left(u, 0.5 - \frac{1}{2 + t\_0}, \frac{1}{1 + e^{t\_0}}\right)} - 1\right)
\end{array}
\end{array}
Initial program 99.0%
Taylor expanded in s around inf
+-commutativeN/A
lower-fma.f32N/A
lift-/.f32N/A
lift-PI.f324.9
Applied rewrites4.9%
Taylor expanded in s around inf
lower-+.f32N/A
lift-/.f32N/A
lift-PI.f324.9
Applied rewrites4.9%
Taylor expanded in s around inf
Applied rewrites38.6%
Applied rewrites38.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
+-commutativeN/A
lower-fma.f32N/A
lift-/.f32N/A
lift-PI.f324.9
Applied rewrites4.9%
Taylor expanded in s around inf
lower-+.f32N/A
lift-/.f32N/A
lift-PI.f324.9
Applied rewrites4.9%
Taylor expanded in s around inf
Applied rewrites38.6%
Taylor expanded in s around 0
lift-/.f32N/A
lift-PI.f3238.6
Applied rewrites38.6%
(FPCore (u s)
:precision binary32
(*
(- s)
(log
(-
(/
1.0
(+
(* u (- 0.5 (/ 1.0 (+ 2.0 (/ (PI) s)))))
(/
1.0
(+ 1.0 (- 1.0 (/ (fma -1.0 (PI) (* -0.5 (/ (* (PI) (PI)) s))) s))))))
1.0))))\begin{array}{l}
\\
\left(-s\right) \cdot \log \left(\frac{1}{u \cdot \left(0.5 - \frac{1}{2 + \frac{\mathsf{PI}\left(\right)}{s}}\right) + \frac{1}{1 + \left(1 - \frac{\mathsf{fma}\left(-1, \mathsf{PI}\left(\right), -0.5 \cdot \frac{\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)}{s}\right)}{s}\right)}} - 1\right)
\end{array}
Initial program 99.0%
Taylor expanded in s around inf
+-commutativeN/A
lower-fma.f32N/A
lift-/.f32N/A
lift-PI.f324.9
Applied rewrites4.9%
Taylor expanded in s around inf
lower-+.f32N/A
lift-/.f32N/A
lift-PI.f324.9
Applied rewrites4.9%
Taylor expanded in s around inf
Applied rewrites38.6%
Taylor expanded in s around -inf
lower-+.f32N/A
lower-*.f32N/A
lower-/.f32N/A
lower-fma.f32N/A
lift-PI.f32N/A
lower-*.f32N/A
lower-/.f32N/A
unpow2N/A
lower-*.f32N/A
lift-PI.f32N/A
lift-PI.f3237.1
Applied rewrites37.1%
Final simplification37.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 (+ 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(0.5 - \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
+-commutativeN/A
lower-fma.f32N/A
lift-/.f32N/A
lift-PI.f324.9
Applied rewrites4.9%
Taylor expanded in s around inf
lower-+.f32N/A
lift-/.f32N/A
lift-PI.f324.9
Applied rewrites4.9%
Taylor expanded in s around inf
Applied rewrites38.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.f3237.1
Applied rewrites37.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 (+ 1.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(0.5 - \frac{1}{2 + t\_0}\right) + \frac{1}{1 + \left(1 + t\_0\right)}} - 1\right)
\end{array}
\end{array}
Initial program 99.0%
Taylor expanded in s around inf
+-commutativeN/A
lower-fma.f32N/A
lift-/.f32N/A
lift-PI.f324.9
Applied rewrites4.9%
Taylor expanded in s around inf
lower-+.f32N/A
lift-/.f32N/A
lift-PI.f324.9
Applied rewrites4.9%
Taylor expanded in s around inf
Applied rewrites38.6%
Taylor expanded in s around inf
lower-+.f32N/A
lift-/.f32N/A
lift-PI.f3236.4
Applied rewrites36.4%
(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.0%
Taylor expanded in u around 0
lower-+.f32N/A
lift-/.f32N/A
lift-PI.f3225.2
Applied rewrites25.2%
(FPCore (u s)
:precision binary32
(*
(- s)
(/
(fma
4.0
(* u (- (* -0.25 (PI)) (* 0.25 (PI))))
(* 4.0 (fma -0.5 (PI) (* -0.0625 (fma -8.0 (PI) (* -4.0 (PI)))))))
s)))\begin{array}{l}
\\
\left(-s\right) \cdot \frac{\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.5, \mathsf{PI}\left(\right), -0.0625 \cdot \mathsf{fma}\left(-8, \mathsf{PI}\left(\right), -4 \cdot \mathsf{PI}\left(\right)\right)\right)\right)}{s}
\end{array}
Initial program 99.0%
Applied rewrites99.0%
Taylor expanded in s around -inf
Applied rewrites12.5%
(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 rewrites12.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 rewrites12.5%
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.f3212.5
Applied rewrites12.5%
(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 rewrites12.5%
Taylor expanded in u around 0
lower-fma.f32N/A
lift-PI.f32N/A
lower-*.f32N/A
lower-*.f32N/A
lift-PI.f3212.5
Applied rewrites12.5%
(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.f3212.3
Applied rewrites12.3%
herbie shell --seed 2025037
(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))))