| Alternative 1 | |
|---|---|
| Error | 0.01% |
| Cost | 6592 |
\[\frac{1}{\cosh x}
\]
(FPCore (x) :precision binary64 (/ 2.0 (+ (exp x) (exp (- x)))))
(FPCore (x) :precision binary64 (pow (sqrt (cosh x)) -2.0))
double code(double x) {
return 2.0 / (exp(x) + exp(-x));
}
double code(double x) {
return pow(sqrt(cosh(x)), -2.0);
}
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 = sqrt(cosh(x)) ** (-2.0d0)
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.pow(Math.sqrt(Math.cosh(x)), -2.0);
}
def code(x): return 2.0 / (math.exp(x) + math.exp(-x))
def code(x): return math.pow(math.sqrt(math.cosh(x)), -2.0)
function code(x) return Float64(2.0 / Float64(exp(x) + exp(Float64(-x)))) end
function code(x) return sqrt(cosh(x)) ^ -2.0 end
function tmp = code(x) tmp = 2.0 / (exp(x) + exp(-x)); end
function tmp = code(x) tmp = sqrt(cosh(x)) ^ -2.0; end
code[x_] := N[(2.0 / N[(N[Exp[x], $MachinePrecision] + N[Exp[(-x)], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[x_] := N[Power[N[Sqrt[N[Cosh[x], $MachinePrecision]], $MachinePrecision], -2.0], $MachinePrecision]
\frac{2}{e^{x} + e^{-x}}
{\left(\sqrt{\cosh x}\right)}^{-2}
Results
Initial program 0.01
Taylor expanded in x around inf 0.01
Simplified0.01
[Start]0.01 | \[ \frac{2}{e^{-x} + e^{x}}
\] |
|---|---|
metadata-eval [<=]0.01 | \[ \frac{\color{blue}{1 \cdot 2}}{e^{-x} + e^{x}}
\] |
associate-*l/ [<=]0.01 | \[ \color{blue}{\frac{1}{e^{-x} + e^{x}} \cdot 2}
\] |
associate-/r/ [<=]0.01 | \[ \color{blue}{\frac{1}{\frac{e^{-x} + e^{x}}{2}}}
\] |
+-commutative [=>]0.01 | \[ \frac{1}{\frac{\color{blue}{e^{x} + e^{-x}}}{2}}
\] |
cosh-def [<=]0.01 | \[ \frac{1}{\color{blue}{\cosh x}}
\] |
Applied egg-rr0.03
Simplified0.02
[Start]0.03 | \[ {\left(\sqrt{\cosh x}\right)}^{-1} \cdot {\left(\sqrt{\cosh x}\right)}^{-1}
\] |
|---|---|
pow-sqr [=>]0.02 | \[ \color{blue}{{\left(\sqrt{\cosh x}\right)}^{\left(2 \cdot -1\right)}}
\] |
metadata-eval [=>]0.02 | \[ {\left(\sqrt{\cosh x}\right)}^{\color{blue}{-2}}
\] |
Final simplification0.02
| Alternative 1 | |
|---|---|
| Error | 0.01% |
| Cost | 6592 |
| Alternative 2 | |
|---|---|
| Error | 1.3% |
| Cost | 841 |
| Alternative 3 | |
|---|---|
| Error | 23.11% |
| Cost | 713 |
| Alternative 4 | |
|---|---|
| Error | 23.42% |
| Cost | 585 |
| Alternative 5 | |
|---|---|
| Error | 23.1% |
| Cost | 448 |
| Alternative 6 | |
|---|---|
| Error | 49.22% |
| Cost | 64 |
herbie shell --seed 2023102
(FPCore (x)
:name "Hyperbolic secant"
:precision binary64
(/ 2.0 (+ (exp x) (exp (- x)))))