Math FPCore C Fortran Java Python Julia MATLAB Wolfram TeX \[\left(e^{x} - 2\right) + e^{-x}
\]
↓
\[\begin{array}{l}
\mathbf{if}\;\left(e^{x} - 2\right) + e^{-x} \leq 0.0005:\\
\;\;\;\;0.002777777777777778 \cdot {x}^{6} + \left({x}^{2} + \left(0.08333333333333333 \cdot {x}^{4} + 4.96031746031746 \cdot 10^{-5} \cdot {x}^{8}\right)\right)\\
\mathbf{else}:\\
\;\;\;\;2 \cdot \cosh x - 2\\
\end{array}
\]
(FPCore (x) :precision binary64 (+ (- (exp x) 2.0) (exp (- x)))) ↓
(FPCore (x)
:precision binary64
(if (<= (+ (- (exp x) 2.0) (exp (- x))) 0.0005)
(+
(* 0.002777777777777778 (pow x 6.0))
(+
(pow x 2.0)
(+
(* 0.08333333333333333 (pow x 4.0))
(* 4.96031746031746e-5 (pow x 8.0)))))
(- (* 2.0 (cosh x)) 2.0))) double code(double x) {
return (exp(x) - 2.0) + exp(-x);
}
↓
double code(double x) {
double tmp;
if (((exp(x) - 2.0) + exp(-x)) <= 0.0005) {
tmp = (0.002777777777777778 * pow(x, 6.0)) + (pow(x, 2.0) + ((0.08333333333333333 * pow(x, 4.0)) + (4.96031746031746e-5 * pow(x, 8.0))));
} else {
tmp = (2.0 * cosh(x)) - 2.0;
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
code = (exp(x) - 2.0d0) + exp(-x)
end function
↓
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (((exp(x) - 2.0d0) + exp(-x)) <= 0.0005d0) then
tmp = (0.002777777777777778d0 * (x ** 6.0d0)) + ((x ** 2.0d0) + ((0.08333333333333333d0 * (x ** 4.0d0)) + (4.96031746031746d-5 * (x ** 8.0d0))))
else
tmp = (2.0d0 * cosh(x)) - 2.0d0
end if
code = tmp
end function
public static double code(double x) {
return (Math.exp(x) - 2.0) + Math.exp(-x);
}
↓
public static double code(double x) {
double tmp;
if (((Math.exp(x) - 2.0) + Math.exp(-x)) <= 0.0005) {
tmp = (0.002777777777777778 * Math.pow(x, 6.0)) + (Math.pow(x, 2.0) + ((0.08333333333333333 * Math.pow(x, 4.0)) + (4.96031746031746e-5 * Math.pow(x, 8.0))));
} else {
tmp = (2.0 * Math.cosh(x)) - 2.0;
}
return tmp;
}
def code(x):
return (math.exp(x) - 2.0) + math.exp(-x)
↓
def code(x):
tmp = 0
if ((math.exp(x) - 2.0) + math.exp(-x)) <= 0.0005:
tmp = (0.002777777777777778 * math.pow(x, 6.0)) + (math.pow(x, 2.0) + ((0.08333333333333333 * math.pow(x, 4.0)) + (4.96031746031746e-5 * math.pow(x, 8.0))))
else:
tmp = (2.0 * math.cosh(x)) - 2.0
return tmp
function code(x)
return Float64(Float64(exp(x) - 2.0) + exp(Float64(-x)))
end
↓
function code(x)
tmp = 0.0
if (Float64(Float64(exp(x) - 2.0) + exp(Float64(-x))) <= 0.0005)
tmp = Float64(Float64(0.002777777777777778 * (x ^ 6.0)) + Float64((x ^ 2.0) + Float64(Float64(0.08333333333333333 * (x ^ 4.0)) + Float64(4.96031746031746e-5 * (x ^ 8.0)))));
else
tmp = Float64(Float64(2.0 * cosh(x)) - 2.0);
end
return tmp
end
function tmp = code(x)
tmp = (exp(x) - 2.0) + exp(-x);
end
↓
function tmp_2 = code(x)
tmp = 0.0;
if (((exp(x) - 2.0) + exp(-x)) <= 0.0005)
tmp = (0.002777777777777778 * (x ^ 6.0)) + ((x ^ 2.0) + ((0.08333333333333333 * (x ^ 4.0)) + (4.96031746031746e-5 * (x ^ 8.0))));
else
tmp = (2.0 * cosh(x)) - 2.0;
end
tmp_2 = tmp;
end
code[x_] := N[(N[(N[Exp[x], $MachinePrecision] - 2.0), $MachinePrecision] + N[Exp[(-x)], $MachinePrecision]), $MachinePrecision]
↓
code[x_] := If[LessEqual[N[(N[(N[Exp[x], $MachinePrecision] - 2.0), $MachinePrecision] + N[Exp[(-x)], $MachinePrecision]), $MachinePrecision], 0.0005], N[(N[(0.002777777777777778 * N[Power[x, 6.0], $MachinePrecision]), $MachinePrecision] + N[(N[Power[x, 2.0], $MachinePrecision] + N[(N[(0.08333333333333333 * N[Power[x, 4.0], $MachinePrecision]), $MachinePrecision] + N[(4.96031746031746e-5 * N[Power[x, 8.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(2.0 * N[Cosh[x], $MachinePrecision]), $MachinePrecision] - 2.0), $MachinePrecision]]
\left(e^{x} - 2\right) + e^{-x}
↓
\begin{array}{l}
\mathbf{if}\;\left(e^{x} - 2\right) + e^{-x} \leq 0.0005:\\
\;\;\;\;0.002777777777777778 \cdot {x}^{6} + \left({x}^{2} + \left(0.08333333333333333 \cdot {x}^{4} + 4.96031746031746 \cdot 10^{-5} \cdot {x}^{8}\right)\right)\\
\mathbf{else}:\\
\;\;\;\;2 \cdot \cosh x - 2\\
\end{array}
Alternatives Alternative 1 Accuracy 100.0% Cost 39940
\[\begin{array}{l}
\mathbf{if}\;\left(e^{x} - 2\right) + e^{-x} \leq 0.0005:\\
\;\;\;\;0.002777777777777778 \cdot {x}^{6} + \left({x}^{2} + \left(0.08333333333333333 \cdot {x}^{4} + 4.96031746031746 \cdot 10^{-5} \cdot {x}^{8}\right)\right)\\
\mathbf{else}:\\
\;\;\;\;2 \cdot \cosh x - 2\\
\end{array}
\]
Alternative 2 Accuracy 100.0% Cost 26884
\[\begin{array}{l}
\mathbf{if}\;\left(e^{x} - 2\right) + e^{-x} \leq 0.0005:\\
\;\;\;\;\left(0.002777777777777778 \cdot {x}^{6} + 0.08333333333333333 \cdot {x}^{4}\right) + x \cdot x\\
\mathbf{else}:\\
\;\;\;\;2 \cdot \cosh x - 2\\
\end{array}
\]
Alternative 3 Accuracy 99.7% Cost 26436
\[\begin{array}{l}
t_0 := e^{-x}\\
\mathbf{if}\;\left(e^{x} - 2\right) + t_0 \leq 2 \cdot 10^{-11}:\\
\;\;\;\;0.08333333333333333 \cdot {x}^{4} + x \cdot x\\
\mathbf{else}:\\
\;\;\;\;e^{x} + \left(t_0 + -2\right)\\
\end{array}
\]
Alternative 4 Accuracy 99.8% Cost 7176
\[\begin{array}{l}
\mathbf{if}\;x \leq -0.0058:\\
\;\;\;\;2 \cdot \cosh x - 2\\
\mathbf{elif}\;x \leq 2.6:\\
\;\;\;\;0.08333333333333333 \cdot {x}^{4} + x \cdot x\\
\mathbf{else}:\\
\;\;\;\;\mathsf{expm1}\left(x\right)\\
\end{array}
\]
Alternative 5 Accuracy 99.5% Cost 6852
\[\begin{array}{l}
\mathbf{if}\;x \leq -0.000205:\\
\;\;\;\;2 \cdot \cosh x - 2\\
\mathbf{elif}\;x \leq 1.65:\\
\;\;\;\;x \cdot x\\
\mathbf{else}:\\
\;\;\;\;\mathsf{expm1}\left(x\right)\\
\end{array}
\]
Alternative 6 Accuracy 95.1% Cost 6788
\[\begin{array}{l}
\mathbf{if}\;x \leq -4.4:\\
\;\;\;\;0.002777777777777778 \cdot {x}^{6}\\
\mathbf{elif}\;x \leq 1.65:\\
\;\;\;\;x \cdot x\\
\mathbf{else}:\\
\;\;\;\;\mathsf{expm1}\left(x\right)\\
\end{array}
\]
Alternative 7 Accuracy 87.1% Cost 6596
\[\begin{array}{l}
\mathbf{if}\;x \leq 1.65:\\
\;\;\;\;x \cdot x\\
\mathbf{else}:\\
\;\;\;\;\mathsf{expm1}\left(x\right)\\
\end{array}
\]
Alternative 8 Accuracy 75.4% Cost 192
\[x \cdot x
\]
Alternative 9 Accuracy 4.4% Cost 64
\[x
\]