VandenBroeck and Keller, Equation (20)

Percentage Accurate: 6.6% → 99.0%
Time: 8.6s
Alternatives: 1
Speedup: 4.1×

Specification

?
\[\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} \]
(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}
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}

Local Percentage Accuracy vs ?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Accuracy vs Speed?

Herbie found 1 alternatives:

AlternativeAccuracySpeedup
The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Initial Program: 6.6% accurate, 1.0× speedup?

\[\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} \]
(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}
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}

Alternative 1: 99.0% accurate, 4.1× speedup?

\[\frac{\log \tanh \left(0.7853981633974483 \cdot f\right) \cdot 4}{\mathsf{PI}\left(\right)} \]
(FPCore (f)
 :precision binary64
 (/ (* (log (tanh (* 0.7853981633974483 f))) 4.0) (PI)))
\frac{\log \tanh \left(0.7853981633974483 \cdot f\right) \cdot 4}{\mathsf{PI}\left(\right)}
Derivation
  1. Initial program 6.6%

    \[-\frac{1}{\frac{\mathsf{PI}\left(\right)}{4}} \cdot \log \left(\frac{e^{\frac{\mathsf{PI}\left(\right)}{4} \cdot f} + e^{-\frac{\mathsf{PI}\left(\right)}{4} \cdot f}}{e^{\frac{\mathsf{PI}\left(\right)}{4} \cdot f} - e^{-\frac{\mathsf{PI}\left(\right)}{4} \cdot f}}\right) \]
  2. Applied rewrites97.1%

    \[\leadsto \color{blue}{\frac{\log \left(\frac{\sinh \left(f \cdot \left(0.25 \cdot \mathsf{PI}\left(\right)\right)\right)}{\cosh \left(\left(f \cdot \mathsf{PI}\left(\right)\right) \cdot -0.25\right)}\right) \cdot 4}{\mathsf{PI}\left(\right)}} \]
  3. Applied rewrites99.0%

    \[\leadsto \frac{\log \color{blue}{\tanh \left(\left(\mathsf{PI}\left(\right) \cdot 0.25\right) \cdot f\right)} \cdot 4}{\mathsf{PI}\left(\right)} \]
  4. Evaluated real constant99.0%

    \[\leadsto \frac{\log \tanh \left(\color{blue}{0.7853981633974483} \cdot f\right) \cdot 4}{\mathsf{PI}\left(\right)} \]
  5. Add Preprocessing

Reproduce

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