Average Error: 61.7 → 1.6
Time: 17.4s
Precision: binary64
\[-\frac{1}{\frac{\pi}{4}} \cdot \log \left(\frac{e^{\frac{\pi}{4} \cdot f} + e^{-\frac{\pi}{4} \cdot f}}{e^{\frac{\pi}{4} \cdot f} - e^{-\frac{\pi}{4} \cdot f}}\right)\]
\[\begin{array}{l} \mathbf{if}\;\frac{\pi}{4} \cdot f \leq 0.0003726407836163889:\\ \;\;\;\;-4 \cdot \frac{\log \left(\frac{1}{f}\right) + 2 \cdot \log \left(2 \cdot \sqrt{\frac{1}{\pi}}\right)}{\pi}\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array}\]
-\frac{1}{\frac{\pi}{4}} \cdot \log \left(\frac{e^{\frac{\pi}{4} \cdot f} + e^{-\frac{\pi}{4} \cdot f}}{e^{\frac{\pi}{4} \cdot f} - e^{-\frac{\pi}{4} \cdot f}}\right)
\begin{array}{l}
\mathbf{if}\;\frac{\pi}{4} \cdot f \leq 0.0003726407836163889:\\
\;\;\;\;-4 \cdot \frac{\log \left(\frac{1}{f}\right) + 2 \cdot \log \left(2 \cdot \sqrt{\frac{1}{\pi}}\right)}{\pi}\\

\mathbf{else}:\\
\;\;\;\;0\\

\end{array}
(FPCore (f)
 :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)))))))))
(FPCore (f)
 :precision binary64
 (if (<= (* (/ PI 4.0) f) 0.0003726407836163889)
   (* -4.0 (/ (+ (log (/ 1.0 f)) (* 2.0 (log (* 2.0 (sqrt (/ 1.0 PI)))))) PI))
   0.0))
double code(double f) {
	return -((1.0 / (((double) M_PI) / 4.0)) * log((exp((((double) M_PI) / 4.0) * f) + exp(-((((double) M_PI) / 4.0) * f))) / (exp((((double) M_PI) / 4.0) * f) - exp(-((((double) M_PI) / 4.0) * f)))));
}
double code(double f) {
	double tmp;
	if (((((double) M_PI) / 4.0) * f) <= 0.0003726407836163889) {
		tmp = -4.0 * ((log(1.0 / f) + (2.0 * log(2.0 * sqrt(1.0 / ((double) M_PI))))) / ((double) M_PI));
	} else {
		tmp = 0.0;
	}
	return tmp;
}

Error

Bits error versus f

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation

  1. Split input into 2 regimes
  2. if (*.f64 (/.f64 PI.f64 4) f) < 3.72640783616388883e-4

    1. Initial program 62.5

      \[-\frac{1}{\frac{\pi}{4}} \cdot \log \left(\frac{e^{\frac{\pi}{4} \cdot f} + e^{-\frac{\pi}{4} \cdot f}}{e^{\frac{\pi}{4} \cdot f} - e^{-\frac{\pi}{4} \cdot f}}\right)\]
    2. Simplified62.5

      \[\leadsto \color{blue}{\log \left(\frac{e^{\frac{\pi}{4} \cdot f} + {\left(e^{-0.25}\right)}^{\left(\pi \cdot f\right)}}{e^{\frac{\pi}{4} \cdot f} - {\left(e^{-0.25}\right)}^{\left(\pi \cdot f\right)}}\right) \cdot \frac{-4}{\pi}}\]
    3. Taylor expanded around 0 0.5

      \[\leadsto \color{blue}{\left(\log \left(\frac{2}{0.25 \cdot \pi - \pi \cdot \log \left(e^{-0.25}\right)}\right) - \log f\right)} \cdot \frac{-4}{\pi}\]
    4. Simplified0.5

      \[\leadsto \color{blue}{\left(\log \left(\frac{2}{\pi \cdot 0.5}\right) - \log f\right)} \cdot \frac{-4}{\pi}\]
    5. Using strategy rm
    6. Applied add-sqr-sqrt_binary640.5

      \[\leadsto \left(\log \color{blue}{\left(\sqrt{\frac{2}{\pi \cdot 0.5}} \cdot \sqrt{\frac{2}{\pi \cdot 0.5}}\right)} - \log f\right) \cdot \frac{-4}{\pi}\]
    7. Applied log-prod_binary640.5

      \[\leadsto \left(\color{blue}{\left(\log \left(\sqrt{\frac{2}{\pi \cdot 0.5}}\right) + \log \left(\sqrt{\frac{2}{\pi \cdot 0.5}}\right)\right)} - \log f\right) \cdot \frac{-4}{\pi}\]
    8. Applied associate--l+_binary640.5

      \[\leadsto \color{blue}{\left(\log \left(\sqrt{\frac{2}{\pi \cdot 0.5}}\right) + \left(\log \left(\sqrt{\frac{2}{\pi \cdot 0.5}}\right) - \log f\right)\right)} \cdot \frac{-4}{\pi}\]
    9. Simplified0.5

      \[\leadsto \left(\log \left(\sqrt{\frac{2}{\pi \cdot 0.5}}\right) + \color{blue}{\left(\log \left(\sqrt{\frac{4}{\pi}}\right) - \log f\right)}\right) \cdot \frac{-4}{\pi}\]
    10. Taylor expanded around inf 0.5

      \[\leadsto \color{blue}{-4 \cdot \frac{\log \left(\frac{1}{f}\right) + 2 \cdot \log \left(2 \cdot \sqrt{\frac{1}{\pi}}\right)}{\pi}}\]

    if 3.72640783616388883e-4 < (*.f64 (/.f64 PI.f64 4) f)

    1. Initial program 30.4

      \[0\]
  3. Recombined 2 regimes into one program.
  4. Final simplification1.6

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{\pi}{4} \cdot f \leq 0.0003726407836163889:\\ \;\;\;\;-4 \cdot \frac{\log \left(\frac{1}{f}\right) + 2 \cdot \log \left(2 \cdot \sqrt{\frac{1}{\pi}}\right)}{\pi}\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array}\]

Alternatives

Reproduce

herbie shell --seed 2021097 
(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)))))))))