Average Error: 0.0 → 0.0
Time: 2.4s
Precision: 64
\[\frac{2}{e^{x} + e^{-x}}\]
\[\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{2}{e^{x} + e^{-x}}\right)\right)\]
\frac{2}{e^{x} + e^{-x}}
\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{2}{e^{x} + e^{-x}}\right)\right)
double code(double x) {
	return (2.0 / (exp(x) + exp(-x)));
}
double code(double x) {
	return expm1(log1p((2.0 / (exp(x) + exp(-x)))));
}

Error

Bits error versus x

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation

  1. Initial program 0.0

    \[\frac{2}{e^{x} + e^{-x}}\]
  2. Using strategy rm
  3. Applied expm1-log1p-u0.0

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

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

Reproduce

herbie shell --seed 2020106 +o rules:numerics
(FPCore (x)
  :name "Hyperbolic secant"
  :precision binary64
  (/ 2 (+ (exp x) (exp (- x)))))