Average Error: 0.0 → 0.0
Time: 1.3s
Precision: binary64
\[\frac{2}{e^{x} + e^{-x}} \]
\[\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{1}{\cosh x}\right)\right) \]
(FPCore (x) :precision binary64 (/ 2.0 (+ (exp x) (exp (- x)))))
(FPCore (x) :precision binary64 (expm1 (log1p (/ 1.0 (cosh x)))))
double code(double x) {
	return 2.0 / (exp(x) + exp(-x));
}
double code(double x) {
	return expm1(log1p((1.0 / cosh(x))));
}
public static double code(double x) {
	return 2.0 / (Math.exp(x) + Math.exp(-x));
}
public static double code(double x) {
	return Math.expm1(Math.log1p((1.0 / Math.cosh(x))));
}
def code(x):
	return 2.0 / (math.exp(x) + math.exp(-x))
def code(x):
	return math.expm1(math.log1p((1.0 / math.cosh(x))))
function code(x)
	return Float64(2.0 / Float64(exp(x) + exp(Float64(-x))))
end
function code(x)
	return expm1(log1p(Float64(1.0 / cosh(x))))
end
code[x_] := N[(2.0 / N[(N[Exp[x], $MachinePrecision] + N[Exp[(-x)], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[x_] := N[(Exp[N[Log[1 + N[(1.0 / N[Cosh[x], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]] - 1), $MachinePrecision]
\frac{2}{e^{x} + e^{-x}}
\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{1}{\cosh x}\right)\right)

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. Applied egg-rr0.2

    \[\leadsto \color{blue}{\log \left(e^{\frac{2}{2 \cdot \cosh x}}\right)} \]
  3. Applied egg-rr0.5

    \[\leadsto \color{blue}{\frac{\frac{2}{\sqrt{2 \cdot \cosh x}}}{\sqrt{2 \cdot \cosh x}}} \]
  4. Applied egg-rr0.0

    \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{1}{\cosh x}\right)\right)} \]
  5. Final simplification0.0

    \[\leadsto \mathsf{expm1}\left(\mathsf{log1p}\left(\frac{1}{\cosh x}\right)\right) \]

Reproduce

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