
(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
(*
(- s)
(log
(-
(/
1.0
(+
(*
u
(-
(/ 1.0 (+ 1.0 (exp (/ (- (PI)) s))))
(/ 1.0 (+ 1.0 (exp (/ (PI) s))))))
(/ 1.0 (+ 1.0 (exp (* (/ 1.0 s) (* (PI) (log (E)))))))))
1.0))))\begin{array}{l}
\\
\left(-s\right) \cdot \log \left(\frac{1}{u \cdot \left(\frac{1}{1 + e^{\frac{-\mathsf{PI}\left(\right)}{s}}} - \frac{1}{1 + e^{\frac{\mathsf{PI}\left(\right)}{s}}}\right) + \frac{1}{1 + e^{\frac{1}{s} \cdot \left(\mathsf{PI}\left(\right) \cdot \log \mathsf{E}\left(\right)\right)}}} - 1\right)
\end{array}
Initial program 98.9%
lift-/.f32N/A
clear-numN/A
associate-/r/N/A
lower-*.f32N/A
lower-/.f3298.9
Applied rewrites98.9%
lift-PI.f32N/A
add-log-expN/A
*-un-lft-identityN/A
lift-PI.f32N/A
exp-prodN/A
log-powN/A
lower-*.f32N/A
lower-log.f32N/A
exp-1-eN/A
lower-E.f3298.9
Applied rewrites98.9%
(FPCore (u s)
:precision binary32
(*
(- s)
(log
(-
(/
1.0
(+
(*
u
(-
(/ 1.0 (+ 1.0 (exp (/ (- (PI)) s))))
(/ 1.0 (+ 1.0 (exp (/ (PI) s))))))
(/ 1.0 (+ 1.0 (exp (/ (* s -1.0) (* (- s) (/ s (PI)))))))))
1.0))))\begin{array}{l}
\\
\left(-s\right) \cdot \log \left(\frac{1}{u \cdot \left(\frac{1}{1 + e^{\frac{-\mathsf{PI}\left(\right)}{s}}} - \frac{1}{1 + e^{\frac{\mathsf{PI}\left(\right)}{s}}}\right) + \frac{1}{1 + e^{\frac{s \cdot -1}{\left(-s\right) \cdot \frac{s}{\mathsf{PI}\left(\right)}}}}} - 1\right)
\end{array}
Initial program 98.9%
lift-/.f32N/A
frac-2negN/A
neg-sub0N/A
lift-neg.f32N/A
div-subN/A
lift-neg.f32N/A
distribute-frac-neg2N/A
clear-numN/A
distribute-neg-fracN/A
metadata-evalN/A
frac-subN/A
lower-/.f32N/A
lower--.f32N/A
lower-*.f32N/A
lower-/.f32N/A
lower-*.f32N/A
lower-*.f32N/A
lower-/.f3298.9
Applied rewrites98.9%
Final simplification98.9%
(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 98.9%
(FPCore (u s)
:precision binary32
(*
(- s)
(log
(-
(/
1.0
(+
(*
u
(-
(/ 1.0 (+ 1.0 (exp (/ (- (PI)) s))))
(/ 1.0 (+ 1.0 (- 1.0 (/ (- (* (* (PI) (/ (PI) s)) -0.5) (PI)) s))))))
(/ 1.0 (+ 1.0 (exp (* (/ 1.0 s) (PI)))))))
1.0))))\begin{array}{l}
\\
\left(-s\right) \cdot \log \left(\frac{1}{u \cdot \left(\frac{1}{1 + e^{\frac{-\mathsf{PI}\left(\right)}{s}}} - \frac{1}{1 + \left(1 - \frac{\left(\mathsf{PI}\left(\right) \cdot \frac{\mathsf{PI}\left(\right)}{s}\right) \cdot -0.5 - \mathsf{PI}\left(\right)}{s}\right)}\right) + \frac{1}{1 + e^{\frac{1}{s} \cdot \mathsf{PI}\left(\right)}}} - 1\right)
\end{array}
Initial program 98.9%
lift-/.f32N/A
clear-numN/A
associate-/r/N/A
lower-*.f32N/A
lower-/.f3298.9
Applied rewrites98.9%
Taylor expanded in s around -inf
mul-1-negN/A
unsub-negN/A
lower--.f32N/A
lower-/.f32N/A
Applied rewrites97.0%
(FPCore (u s)
:precision binary32
(*
(- s)
(log
(-
(/
1.0
(+
(*
u
(-
(/ 1.0 (+ 1.0 (exp (/ (- (PI)) s))))
(/ 1.0 (+ 1.0 (+ (/ (PI) s) 1.0)))))
(/ 1.0 (+ 1.0 (exp (* (/ 1.0 s) (PI)))))))
1.0))))\begin{array}{l}
\\
\left(-s\right) \cdot \log \left(\frac{1}{u \cdot \left(\frac{1}{1 + e^{\frac{-\mathsf{PI}\left(\right)}{s}}} - \frac{1}{1 + \left(\frac{\mathsf{PI}\left(\right)}{s} + 1\right)}\right) + \frac{1}{1 + e^{\frac{1}{s} \cdot \mathsf{PI}\left(\right)}}} - 1\right)
\end{array}
Initial program 98.9%
lift-/.f32N/A
clear-numN/A
associate-/r/N/A
lower-*.f32N/A
lower-/.f3298.9
Applied rewrites98.9%
Taylor expanded in s around inf
+-commutativeN/A
lower-+.f32N/A
lower-/.f32N/A
lower-PI.f3294.6
Applied rewrites94.6%
(FPCore (u s)
:precision binary32
(let* ((t_0 (/ (PI) s)))
(*
(- s)
(log
(-
(/
1.0
(+
(* u (- (/ 1.0 (+ 1.0 1.0)) (/ 1.0 (+ 1.0 (exp t_0)))))
(/ 1.0 (+ 1.0 (pow (E) 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 + 1} - \frac{1}{1 + e^{t\_0}}\right) + \frac{1}{1 + {\mathsf{E}\left(\right)}^{t\_0}}} - 1\right)
\end{array}
\end{array}
Initial program 98.9%
Taylor expanded in s around inf
Applied rewrites37.3%
lift-exp.f32N/A
lift-/.f32N/A
clear-numN/A
div-invN/A
clear-numN/A
lift-/.f32N/A
exp-prodN/A
lower-pow.f32N/A
exp-1-eN/A
lower-E.f3237.3
Applied rewrites37.3%
(FPCore (u s) :precision binary32 (let* ((t_0 (/ 1.0 (+ 1.0 (exp (/ (PI) s)))))) (* (- s) (log (- (/ 1.0 (+ (* u (- (/ 1.0 (+ 1.0 1.0)) 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 + 1} - t\_0\right) + t\_0} - 1\right)
\end{array}
\end{array}
Initial program 98.9%
Taylor expanded in s around inf
Applied rewrites37.3%
(FPCore (u s)
:precision binary32
(let* ((t_0 (/ (PI) s)))
(*
(- s)
(log
(-
(/
1.0
(+
(*
u
(-
(/ 1.0 (+ 1.0 1.0))
(/ 1.0 (+ 1.0 (- 1.0 (/ (- (* (* (PI) t_0) -0.5) (PI)) s))))))
(/ 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(\frac{1}{1 + 1} - \frac{1}{1 + \left(1 - \frac{\left(\mathsf{PI}\left(\right) \cdot t\_0\right) \cdot -0.5 - \mathsf{PI}\left(\right)}{s}\right)}\right) + \frac{1}{1 + e^{t\_0}}} - 1\right)
\end{array}
\end{array}
Initial program 98.9%
Taylor expanded in s around inf
Applied rewrites37.3%
Taylor expanded in s around -inf
mul-1-negN/A
unsub-negN/A
lower--.f32N/A
lower-/.f32N/A
Applied rewrites37.3%
(FPCore (u s)
:precision binary32
(let* ((t_0 (/ (PI) s)))
(*
(- s)
(log
(-
(/
1.0
(+
(* u (- (/ 1.0 (+ 1.0 1.0)) (/ 1.0 (+ 1.0 (+ t_0 1.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(\frac{1}{1 + 1} - \frac{1}{1 + \left(t\_0 + 1\right)}\right) + \frac{1}{1 + e^{t\_0}}} - 1\right)
\end{array}
\end{array}
Initial program 98.9%
Taylor expanded in s around inf
Applied rewrites37.3%
Taylor expanded in s around inf
+-commutativeN/A
lower-+.f32N/A
lower-/.f32N/A
lower-PI.f3237.3
Applied rewrites37.3%
(FPCore (u s) :precision binary32 (let* ((t_0 (* (* (fma 0.5 u -0.25) (PI)) 4.0))) (fma (pow t_0 2.0) (/ 1.0 t_0) 0.0)))
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(\mathsf{fma}\left(0.5, u, -0.25\right) \cdot \mathsf{PI}\left(\right)\right) \cdot 4\\
\mathsf{fma}\left({t\_0}^{2}, \frac{1}{t\_0}, 0\right)
\end{array}
\end{array}
Initial program 98.9%
Taylor expanded in s around inf
Applied rewrites10.3%
Applied rewrites10.3%
Applied rewrites9.9%
Final simplification9.8%
(FPCore (u s) :precision binary32 (* (- (* 2.0 (PI)) (/ (PI) u)) u))
\begin{array}{l}
\\
\left(2 \cdot \mathsf{PI}\left(\right) - \frac{\mathsf{PI}\left(\right)}{u}\right) \cdot u
\end{array}
Initial program 98.9%
Taylor expanded in s around inf
Applied rewrites10.3%
Taylor expanded in u around inf
Applied rewrites5.1%
Taylor expanded in u around inf
Applied rewrites11.9%
Final simplification11.9%
(FPCore (u s) :precision binary32 (* (- u) (fma -2.0 (PI) (/ (PI) u))))
\begin{array}{l}
\\
\left(-u\right) \cdot \mathsf{fma}\left(-2, \mathsf{PI}\left(\right), \frac{\mathsf{PI}\left(\right)}{u}\right)
\end{array}
Initial program 98.9%
Taylor expanded in s around inf
Applied rewrites10.3%
Taylor expanded in u around inf
Applied rewrites5.1%
Taylor expanded in u around -inf
Applied rewrites11.5%
Final simplification11.5%
(FPCore (u s) :precision binary32 (- (PI)))
\begin{array}{l}
\\
-\mathsf{PI}\left(\right)
\end{array}
Initial program 98.9%
Taylor expanded in u around 0
mul-1-negN/A
lower-neg.f32N/A
lower-PI.f3211.5
Applied rewrites11.5%
Final simplification11.5%
(FPCore (u s) :precision binary32 0.0)
float code(float u, float s) {
return 0.0f;
}
real(4) function code(u, s)
real(4), intent (in) :: u
real(4), intent (in) :: s
code = 0.0e0
end function
function code(u, s) return Float32(0.0) end
function tmp = code(u, s) tmp = single(0.0); end
\begin{array}{l}
\\
0
\end{array}
Initial program 98.9%
lift-/.f32N/A
lift-PI.f32N/A
add-cube-cbrtN/A
associate-/l*N/A
lower-*.f32N/A
pow2N/A
lower-pow.f32N/A
lift-PI.f32N/A
lower-cbrt.f32N/A
lower-/.f32N/A
lift-PI.f32N/A
lower-cbrt.f3298.9
Applied rewrites98.9%
Taylor expanded in s around -inf
Applied rewrites7.9%
Taylor expanded in s around 0
Applied rewrites10.3%
herbie shell --seed 2024298
(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))))