
(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 11 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
(*
(log
(-
(/
1.0
(+
(/ 1.0 (+ (exp (/ (* (PI) s) (* s s))) 1.0))
(*
(-
(/ -1.0 (+ (exp (/ (PI) s)) 1.0))
(/ -1.0 (+ (exp (/ (- (PI)) s)) 1.0)))
u)))
1.0))
(- s)))\begin{array}{l}
\\
\log \left(\frac{1}{\frac{1}{e^{\frac{\mathsf{PI}\left(\right) \cdot s}{s \cdot s}} + 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) \cdot \left(-s\right)
\end{array}
Initial program 98.9%
lift-/.f32N/A
remove-double-negN/A
lift-neg.f32N/A
neg-sub0N/A
div-subN/A
frac-2negN/A
metadata-evalN/A
lift-neg.f32N/A
frac-subN/A
lower-/.f32N/A
lower--.f32N/A
lower-*.f32N/A
lower-*.f32N/A
lower-*.f3298.9
Applied rewrites98.9%
lift-/.f32N/A
frac-2negN/A
distribute-frac-negN/A
lift--.f32N/A
lift-*.f32N/A
mul0-lftN/A
neg-sub0N/A
frac-2negN/A
distribute-frac-neg2N/A
lower-/.f32N/A
Applied rewrites98.9%
Final simplification98.9%
(FPCore (u s)
:precision binary32
(let* ((t_0 (/ (PI) s)) (t_1 (/ -1.0 (+ (exp t_0) 1.0))))
(if (<=
(*
(log
(-
-1.0
(/
-1.0
(- (* (- t_1 (/ -1.0 (+ (exp (/ (- (PI)) s)) 1.0))) u) t_1))))
(- s))
-9.9999998245167e-14)
(fma (/ (* (* (/ 0.0 u) u) u) s) -0.5 (* -4.0 (* (fma -0.5 u 0.25) (PI))))
(*
(log
(-
(-
(fma (/ (fma (* 0.5 (PI)) u (* 0.25 (PI))) s) -4.0 2.0)
(* -2.0 t_0))
1.0))
(- s)))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{\mathsf{PI}\left(\right)}{s}\\
t_1 := \frac{-1}{e^{t\_0} + 1}\\
\mathbf{if}\;\log \left(-1 - \frac{-1}{\left(t\_1 - \frac{-1}{e^{\frac{-\mathsf{PI}\left(\right)}{s}} + 1}\right) \cdot u - t\_1}\right) \cdot \left(-s\right) \leq -9.9999998245167 \cdot 10^{-14}:\\
\;\;\;\;\mathsf{fma}\left(\frac{\left(\frac{0}{u} \cdot u\right) \cdot u}{s}, -0.5, -4 \cdot \left(\mathsf{fma}\left(-0.5, u, 0.25\right) \cdot \mathsf{PI}\left(\right)\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\log \left(\left(\mathsf{fma}\left(\frac{\mathsf{fma}\left(0.5 \cdot \mathsf{PI}\left(\right), u, 0.25 \cdot \mathsf{PI}\left(\right)\right)}{s}, -4, 2\right) - -2 \cdot t\_0\right) - 1\right) \cdot \left(-s\right)\\
\end{array}
\end{array}
if (*.f32 (neg.f32 s) (log.f32 (-.f32 (/.f32 #s(literal 1 binary32) (+.f32 (*.f32 u (-.f32 (/.f32 #s(literal 1 binary32) (+.f32 #s(literal 1 binary32) (exp.f32 (/.f32 (neg.f32 (PI.f32)) s)))) (/.f32 #s(literal 1 binary32) (+.f32 #s(literal 1 binary32) (exp.f32 (/.f32 (PI.f32) s)))))) (/.f32 #s(literal 1 binary32) (+.f32 #s(literal 1 binary32) (exp.f32 (/.f32 (PI.f32) s)))))) #s(literal 1 binary32)))) < -9.99999982e-14Initial program 99.1%
Taylor expanded in s around -inf
Applied rewrites9.0%
Applied rewrites7.8%
Taylor expanded in u around -inf
Applied rewrites16.5%
Applied rewrites7.2%
if -9.99999982e-14 < (*.f32 (neg.f32 s) (log.f32 (-.f32 (/.f32 #s(literal 1 binary32) (+.f32 (*.f32 u (-.f32 (/.f32 #s(literal 1 binary32) (+.f32 #s(literal 1 binary32) (exp.f32 (/.f32 (neg.f32 (PI.f32)) s)))) (/.f32 #s(literal 1 binary32) (+.f32 #s(literal 1 binary32) (exp.f32 (/.f32 (PI.f32) s)))))) (/.f32 #s(literal 1 binary32) (+.f32 #s(literal 1 binary32) (exp.f32 (/.f32 (PI.f32) s)))))) #s(literal 1 binary32)))) Initial program 98.8%
lift-/.f32N/A
remove-double-negN/A
lift-neg.f32N/A
neg-sub0N/A
div-subN/A
frac-2negN/A
metadata-evalN/A
lift-neg.f32N/A
frac-subN/A
lower-/.f32N/A
lower--.f32N/A
lower-*.f32N/A
lower-*.f32N/A
lower-*.f3298.8
Applied rewrites98.8%
Applied rewrites98.7%
Taylor expanded in s around inf
lower--.f32N/A
Applied rewrites20.9%
Final simplification16.8%
(FPCore (u s)
:precision binary32
(let* ((t_0 (/ -1.0 (+ (exp (/ (PI) s)) 1.0))))
(*
(log
(-
-1.0
(/ -1.0 (- (* (- t_0 (/ -1.0 (+ (exp (/ (- (PI)) s)) 1.0))) u) t_0))))
(- s))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{-1}{e^{\frac{\mathsf{PI}\left(\right)}{s}} + 1}\\
\log \left(-1 - \frac{-1}{\left(t\_0 - \frac{-1}{e^{\frac{-\mathsf{PI}\left(\right)}{s}} + 1}\right) \cdot u - t\_0}\right) \cdot \left(-s\right)
\end{array}
\end{array}
Initial program 98.9%
Final simplification98.9%
(FPCore (u s)
:precision binary32
(*
(log
(-
-1.0
(/
(/ -1.0 u)
(-
(/ -1.0 (+ (exp (/ (PI) s)) 1.0))
(/ -1.0 (+ (exp (/ (- (PI)) s)) 1.0))))))
(- s)))\begin{array}{l}
\\
\log \left(-1 - \frac{\frac{-1}{u}}{\frac{-1}{e^{\frac{\mathsf{PI}\left(\right)}{s}} + 1} - \frac{-1}{e^{\frac{-\mathsf{PI}\left(\right)}{s}} + 1}}\right) \cdot \left(-s\right)
\end{array}
Initial program 98.9%
Taylor expanded in u around inf
lower--.f32N/A
Applied rewrites98.0%
Final simplification98.0%
(FPCore (u s)
:precision binary32
(let* ((t_0 (/ (* (PI) (PI)) s)))
(fma
(*
(* u u)
(fma -4.0 (+ (/ t_0 u) t_0) (* (fma (/ (PI) u) (/ (PI) s) t_0) 4.0)))
-0.5
(* (fma (* -0.5 u) (PI) (* 0.25 (PI))) -4.0))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)}{s}\\
\mathsf{fma}\left(\left(u \cdot u\right) \cdot \mathsf{fma}\left(-4, \frac{t\_0}{u} + t\_0, \mathsf{fma}\left(\frac{\mathsf{PI}\left(\right)}{u}, \frac{\mathsf{PI}\left(\right)}{s}, t\_0\right) \cdot 4\right), -0.5, \mathsf{fma}\left(-0.5 \cdot u, \mathsf{PI}\left(\right), 0.25 \cdot \mathsf{PI}\left(\right)\right) \cdot -4\right)
\end{array}
\end{array}
Initial program 98.9%
Taylor expanded in s around -inf
Applied rewrites8.4%
Applied rewrites10.4%
Taylor expanded in u around inf
Applied rewrites11.0%
Final simplification11.0%
(FPCore (u s) :precision binary32 (fma (/ (* (* (/ 0.0 u) u) u) s) -0.5 (* (- (* 2.0 (PI)) (/ (PI) u)) u)))
\begin{array}{l}
\\
\mathsf{fma}\left(\frac{\left(\frac{0}{u} \cdot u\right) \cdot u}{s}, -0.5, \left(2 \cdot \mathsf{PI}\left(\right) - \frac{\mathsf{PI}\left(\right)}{u}\right) \cdot u\right)
\end{array}
Initial program 98.9%
Taylor expanded in s around -inf
Applied rewrites7.8%
Applied rewrites7.3%
Taylor expanded in u around -inf
Applied rewrites11.0%
Taylor expanded in u around inf
Applied rewrites11.3%
Final simplification11.3%
(FPCore (u s) :precision binary32 (fma (/ (* (* (/ 0.0 u) u) u) s) -0.5 (* (+ (* (* -0.5 u) (PI)) (* 0.25 (PI))) -4.0)))
\begin{array}{l}
\\
\mathsf{fma}\left(\frac{\left(\frac{0}{u} \cdot u\right) \cdot u}{s}, -0.5, \left(\left(-0.5 \cdot u\right) \cdot \mathsf{PI}\left(\right) + 0.25 \cdot \mathsf{PI}\left(\right)\right) \cdot -4\right)
\end{array}
Initial program 98.9%
Taylor expanded in s around -inf
Applied rewrites8.2%
Applied rewrites7.3%
Taylor expanded in u around -inf
Applied rewrites11.0%
Applied rewrites11.3%
Final simplification11.3%
(FPCore (u s) :precision binary32 (fma (/ (* (* (/ 0.0 u) u) u) s) -0.5 (* -4.0 (* (fma -0.5 u 0.25) (PI)))))
\begin{array}{l}
\\
\mathsf{fma}\left(\frac{\left(\frac{0}{u} \cdot u\right) \cdot u}{s}, -0.5, -4 \cdot \left(\mathsf{fma}\left(-0.5, u, 0.25\right) \cdot \mathsf{PI}\left(\right)\right)\right)
\end{array}
Initial program 98.9%
Taylor expanded in s around -inf
Applied rewrites8.0%
Applied rewrites7.9%
Taylor expanded in u around -inf
Applied rewrites11.0%
Applied rewrites7.0%
Final simplification11.0%
(FPCore (u s) :precision binary32 (* (/ (+ (* -2.0 (PI)) (/ (PI) u)) (- u)) (* u u)))
\begin{array}{l}
\\
\frac{-2 \cdot \mathsf{PI}\left(\right) + \frac{\mathsf{PI}\left(\right)}{u}}{-u} \cdot \left(u \cdot u\right)
\end{array}
Initial program 98.9%
Taylor expanded in s around -inf
Applied rewrites7.8%
Taylor expanded in s around 0
Applied rewrites10.1%
Taylor expanded in u around -inf
Applied rewrites11.3%
Final simplification11.3%
(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.0
Applied rewrites11.0%
(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%
Taylor expanded in s around -inf
Applied rewrites8.0%
Taylor expanded in s around 0
Applied rewrites10.1%
Taylor expanded in s around 0
Applied rewrites10.1%
herbie shell --seed 2024304
(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))))