
(FPCore (f) :precision binary64 (let* ((t_0 (/ (PI) 4.0)) (t_1 (* t_0 f)) (t_2 (exp t_1)) (t_3 (exp (- t_1)))) (- (* (/ 1.0 t_0) (log (/ (+ t_2 t_3) (- t_2 t_3)))))))
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{\mathsf{PI}\left(\right)}{4}\\
t_1 := t\_0 \cdot f\\
t_2 := e^{t\_1}\\
t_3 := e^{-t\_1}\\
-\frac{1}{t\_0} \cdot \log \left(\frac{t\_2 + t\_3}{t\_2 - t\_3}\right)
\end{array}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 7 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (f) :precision binary64 (let* ((t_0 (/ (PI) 4.0)) (t_1 (* t_0 f)) (t_2 (exp t_1)) (t_3 (exp (- t_1)))) (- (* (/ 1.0 t_0) (log (/ (+ t_2 t_3) (- t_2 t_3)))))))
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{\mathsf{PI}\left(\right)}{4}\\
t_1 := t\_0 \cdot f\\
t_2 := e^{t\_1}\\
t_3 := e^{-t\_1}\\
-\frac{1}{t\_0} \cdot \log \left(\frac{t\_2 + t\_3}{t\_2 - t\_3}\right)
\end{array}
\end{array}
(FPCore (f)
:precision binary64
(let* ((t_0 (pow (pow (exp (PI)) 0.5) (- f))) (t_1 (* 0.25 (PI))))
(if (<= (* (/ (PI) 4.0) f) 0.002)
(* (/ (/ -4.0 (PI)) (PI)) (* (* t_1 -4.0) (log (tanh (* t_1 f)))))
(/ (- (log1p (- t_0)) (log1p t_0)) t_1))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := {\left({\left(e^{\mathsf{PI}\left(\right)}\right)}^{0.5}\right)}^{\left(-f\right)}\\
t_1 := 0.25 \cdot \mathsf{PI}\left(\right)\\
\mathbf{if}\;\frac{\mathsf{PI}\left(\right)}{4} \cdot f \leq 0.002:\\
\;\;\;\;\frac{\frac{-4}{\mathsf{PI}\left(\right)}}{\mathsf{PI}\left(\right)} \cdot \left(\left(t\_1 \cdot -4\right) \cdot \log \tanh \left(t\_1 \cdot f\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{\mathsf{log1p}\left(-t\_0\right) - \mathsf{log1p}\left(t\_0\right)}{t\_1}\\
\end{array}
\end{array}
if (*.f64 (/.f64 (PI.f64) #s(literal 4 binary64)) f) < 2e-3Initial program 5.7%
lift-neg.f64N/A
lift-*.f64N/A
*-commutativeN/A
lift-/.f64N/A
un-div-invN/A
Applied rewrites99.5%
Applied rewrites99.4%
lift-/.f64N/A
clear-numN/A
associate-/r/N/A
lower-*.f64N/A
lift-*.f64N/A
associate-/r*N/A
lift-*.f64N/A
*-commutativeN/A
metadata-evalN/A
div-invN/A
clear-numN/A
lift-/.f64N/A
lower-/.f6499.5
lift--.f64N/A
Applied rewrites99.5%
if 2e-3 < (*.f64 (/.f64 (PI.f64) #s(literal 4 binary64)) f) Initial program 9.2%
lift-neg.f64N/A
lift-*.f64N/A
*-commutativeN/A
lift-/.f64N/A
un-div-invN/A
Applied rewrites63.2%
Applied rewrites96.5%
(FPCore (f)
:precision binary64
(let* ((t_0 (* 0.25 (PI)))
(t_1 (* f t_0))
(t_2 (- (PI)))
(t_3 (/ (/ -4.0 (PI)) (PI)))
(t_4 (pow (exp -0.5) (* f (PI)))))
(if (<= (* (/ (PI) 4.0) f) 0.5)
(* t_3 (fma (- (log (cosh t_1))) t_2 (* (log (sinh t_1)) t_2)))
(* t_3 (* (* t_0 -4.0) (- (log1p (- t_4)) (log1p t_4)))))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := 0.25 \cdot \mathsf{PI}\left(\right)\\
t_1 := f \cdot t\_0\\
t_2 := -\mathsf{PI}\left(\right)\\
t_3 := \frac{\frac{-4}{\mathsf{PI}\left(\right)}}{\mathsf{PI}\left(\right)}\\
t_4 := {\left(e^{-0.5}\right)}^{\left(f \cdot \mathsf{PI}\left(\right)\right)}\\
\mathbf{if}\;\frac{\mathsf{PI}\left(\right)}{4} \cdot f \leq 0.5:\\
\;\;\;\;t\_3 \cdot \mathsf{fma}\left(-\log \cosh t\_1, t\_2, \log \sinh t\_1 \cdot t\_2\right)\\
\mathbf{else}:\\
\;\;\;\;t\_3 \cdot \left(\left(t\_0 \cdot -4\right) \cdot \left(\mathsf{log1p}\left(-t\_4\right) - \mathsf{log1p}\left(t\_4\right)\right)\right)\\
\end{array}
\end{array}
if (*.f64 (/.f64 (PI.f64) #s(literal 4 binary64)) f) < 0.5Initial program 6.1%
lift-neg.f64N/A
lift-*.f64N/A
*-commutativeN/A
lift-/.f64N/A
un-div-invN/A
Applied rewrites99.5%
Applied rewrites99.4%
lift-/.f64N/A
clear-numN/A
associate-/r/N/A
lower-*.f64N/A
lift-*.f64N/A
associate-/r*N/A
lift-*.f64N/A
*-commutativeN/A
metadata-evalN/A
div-invN/A
clear-numN/A
lift-/.f64N/A
lower-/.f6499.5
lift--.f64N/A
Applied rewrites99.5%
Applied rewrites99.5%
if 0.5 < (*.f64 (/.f64 (PI.f64) #s(literal 4 binary64)) f) Initial program 1.8%
lift-neg.f64N/A
lift-*.f64N/A
*-commutativeN/A
lift-/.f64N/A
un-div-invN/A
Applied rewrites60.1%
Applied rewrites60.1%
lift-/.f64N/A
clear-numN/A
associate-/r/N/A
lower-*.f64N/A
lift-*.f64N/A
associate-/r*N/A
lift-*.f64N/A
*-commutativeN/A
metadata-evalN/A
div-invN/A
clear-numN/A
lift-/.f64N/A
lower-/.f6460.1
lift--.f64N/A
Applied rewrites60.1%
lift-log.f64N/A
lift-tanh.f64N/A
tanh-def-cN/A
log-divN/A
lower--.f64N/A
Applied rewrites96.1%
(FPCore (f) :precision binary64 (let* ((t_0 (* 0.25 (PI)))) (* (/ (/ -4.0 (PI)) (PI)) (* (* t_0 -4.0) (log (tanh (* t_0 f)))))))
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 0.25 \cdot \mathsf{PI}\left(\right)\\
\frac{\frac{-4}{\mathsf{PI}\left(\right)}}{\mathsf{PI}\left(\right)} \cdot \left(\left(t\_0 \cdot -4\right) \cdot \log \tanh \left(t\_0 \cdot f\right)\right)
\end{array}
\end{array}
Initial program 5.9%
lift-neg.f64N/A
lift-*.f64N/A
*-commutativeN/A
lift-/.f64N/A
un-div-invN/A
Applied rewrites97.7%
Applied rewrites97.6%
lift-/.f64N/A
clear-numN/A
associate-/r/N/A
lower-*.f64N/A
lift-*.f64N/A
associate-/r*N/A
lift-*.f64N/A
*-commutativeN/A
metadata-evalN/A
div-invN/A
clear-numN/A
lift-/.f64N/A
lower-/.f6497.7
lift--.f64N/A
Applied rewrites97.7%
(FPCore (f) :precision binary64 (let* ((t_0 (* 0.25 (PI)))) (/ (log (tanh (* f t_0))) t_0)))
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 0.25 \cdot \mathsf{PI}\left(\right)\\
\frac{\log \tanh \left(f \cdot t\_0\right)}{t\_0}
\end{array}
\end{array}
Initial program 5.9%
lift-neg.f64N/A
lift-*.f64N/A
*-commutativeN/A
lift-/.f64N/A
un-div-invN/A
Applied rewrites97.7%
(FPCore (f)
:precision binary64
(*
(/ -1.0 (/ (PI) 4.0))
(log
(/
(fma
(* (fma (* 4.0 (PI)) -0.010416666666666666 (* 0.125 (PI))) f)
f
(/ 4.0 (PI)))
f))))\begin{array}{l}
\\
\frac{-1}{\frac{\mathsf{PI}\left(\right)}{4}} \cdot \log \left(\frac{\mathsf{fma}\left(\mathsf{fma}\left(4 \cdot \mathsf{PI}\left(\right), -0.010416666666666666, 0.125 \cdot \mathsf{PI}\left(\right)\right) \cdot f, f, \frac{4}{\mathsf{PI}\left(\right)}\right)}{f}\right)
\end{array}
Initial program 5.9%
Taylor expanded in f around 0
Applied rewrites94.6%
Applied rewrites94.6%
Final simplification94.6%
(FPCore (f) :precision binary64 (/ (log (* (* (PI) f) 0.25)) (* 0.25 (PI))))
\begin{array}{l}
\\
\frac{\log \left(\left(\mathsf{PI}\left(\right) \cdot f\right) \cdot 0.25\right)}{0.25 \cdot \mathsf{PI}\left(\right)}
\end{array}
Initial program 5.9%
lift-neg.f64N/A
lift-*.f64N/A
*-commutativeN/A
lift-/.f64N/A
un-div-invN/A
Applied rewrites97.7%
Taylor expanded in f around 0
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-PI.f6494.2
Applied rewrites94.2%
(FPCore (f) :precision binary64 (* (/ 4.0 (PI)) (log (* (* 0.25 (PI)) f))))
\begin{array}{l}
\\
\frac{4}{\mathsf{PI}\left(\right)} \cdot \log \left(\left(0.25 \cdot \mathsf{PI}\left(\right)\right) \cdot f\right)
\end{array}
Initial program 5.9%
lift-neg.f64N/A
lift-*.f64N/A
*-commutativeN/A
lift-/.f64N/A
un-div-invN/A
Applied rewrites97.7%
Taylor expanded in f around 0
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-PI.f6494.2
Applied rewrites94.2%
lift-/.f64N/A
lift-*.f64N/A
associate-/r*N/A
div-invN/A
metadata-evalN/A
associate-*r/N/A
lift-/.f64N/A
*-commutativeN/A
lower-*.f6494.0
Applied rewrites94.0%
herbie shell --seed 2024322
(FPCore (f)
:name "VandenBroeck and Keller, Equation (20)"
:precision binary64
(- (* (/ 1.0 (/ (PI) 4.0)) (log (/ (+ (exp (* (/ (PI) 4.0) f)) (exp (- (* (/ (PI) 4.0) f)))) (- (exp (* (/ (PI) 4.0) f)) (exp (- (* (/ (PI) 4.0) f)))))))))