(FPCore (x) :precision binary64 (/ 2.0 (+ (exp x) (exp (- x)))))
(FPCore (x) :precision binary64 (log (exp (exp (- (log (cosh x)))))))
double code(double x) {
return 2.0 / (exp(x) + exp(-x));
}
double code(double x) {
return log(exp(exp(-log(cosh(x)))));
}
real(8) function code(x)
real(8), intent (in) :: x
code = 2.0d0 / (exp(x) + exp(-x))
end function
real(8) function code(x)
real(8), intent (in) :: x
code = log(exp(exp(-log(cosh(x)))))
end function
public static double code(double x) {
return 2.0 / (Math.exp(x) + Math.exp(-x));
}
public static double code(double x) {
return Math.log(Math.exp(Math.exp(-Math.log(Math.cosh(x)))));
}
def code(x): return 2.0 / (math.exp(x) + math.exp(-x))
def code(x): return math.log(math.exp(math.exp(-math.log(math.cosh(x)))))
function code(x) return Float64(2.0 / Float64(exp(x) + exp(Float64(-x)))) end
function code(x) return log(exp(exp(Float64(-log(cosh(x)))))) end
function tmp = code(x) tmp = 2.0 / (exp(x) + exp(-x)); end
function tmp = code(x) tmp = log(exp(exp(-log(cosh(x))))); end
code[x_] := N[(2.0 / N[(N[Exp[x], $MachinePrecision] + N[Exp[(-x)], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[x_] := N[Log[N[Exp[N[Exp[(-N[Log[N[Cosh[x], $MachinePrecision]], $MachinePrecision])], $MachinePrecision]], $MachinePrecision]], $MachinePrecision]
\frac{2}{e^{x} + e^{-x}}
\log \left(e^{e^{-\log \cosh x}}\right)



Bits error versus x
Results
Initial program 0.0
Applied egg-rr0.2
Applied egg-rr0.2
Final simplification0.2
herbie shell --seed 2022162
(FPCore (x)
:name "Hyperbolic secant"
:precision binary64
(/ 2.0 (+ (exp x) (exp (- x)))))