Average Error: 0.0 → 0.0
Time: 2.1s
Precision: binary64
\[\frac{2}{e^{x} + e^{-x}} \]
\[\begin{array}{l} t_0 := \sqrt{e^{x}}\\ \mathsf{expm1}\left(\mathsf{log1p}\left(\frac{2}{\mathsf{fma}\left(t_0, t_0, e^{-x}\right)}\right)\right) \end{array} \]
\frac{2}{e^{x} + e^{-x}}
\begin{array}{l}
t_0 := \sqrt{e^{x}}\\
\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{2}{\mathsf{fma}\left(t_0, t_0, e^{-x}\right)}\right)\right)
\end{array}
(FPCore (x) :precision binary64 (/ 2.0 (+ (exp x) (exp (- x)))))
(FPCore (x)
 :precision binary64
 (let* ((t_0 (sqrt (exp x))))
   (expm1 (log1p (/ 2.0 (fma t_0 t_0 (exp (- x))))))))
double code(double x) {
	return 2.0 / (exp(x) + exp(-x));
}
double code(double x) {
	double t_0 = sqrt(exp(x));
	return expm1(log1p(2.0 / fma(t_0, t_0, exp(-x))));
}

Error

Bits error versus x

Derivation

  1. Initial program 0.0

    \[\frac{2}{e^{x} + e^{-x}} \]
  2. Applied add-sqr-sqrt_binary640.0

    \[\leadsto \frac{2}{\color{blue}{\sqrt{e^{x}} \cdot \sqrt{e^{x}}} + e^{-x}} \]
  3. Applied fma-def_binary640.0

    \[\leadsto \frac{2}{\color{blue}{\mathsf{fma}\left(\sqrt{e^{x}}, \sqrt{e^{x}}, e^{-x}\right)}} \]
  4. Applied expm1-log1p-u_binary640.0

    \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{2}{\mathsf{fma}\left(\sqrt{e^{x}}, \sqrt{e^{x}}, e^{-x}\right)}\right)\right)} \]
  5. Final simplification0.0

    \[\leadsto \mathsf{expm1}\left(\mathsf{log1p}\left(\frac{2}{\mathsf{fma}\left(\sqrt{e^{x}}, \sqrt{e^{x}}, e^{-x}\right)}\right)\right) \]

Reproduce

herbie shell --seed 2022082 
(FPCore (x)
  :name "Hyperbolic secant"
  :precision binary64
  (/ 2.0 (+ (exp x) (exp (- x)))))