Math FPCore C Fortran Java Python Julia MATLAB Wolfram TeX \[\left(e^{x} - 2\right) + e^{-x}
\]
↓
\[\begin{array}{l}
t_0 := e^{-x}\\
\mathbf{if}\;\left(e^{x} - 2\right) + t_0 \leq 2 \cdot 10^{-11}:\\
\;\;\;\;x \cdot x + 0.08333333333333333 \cdot {x}^{4}\\
\mathbf{else}:\\
\;\;\;\;e^{x} + \left(t_0 + -2\right)\\
\end{array}
\]
(FPCore (x) :precision binary64 (+ (- (exp x) 2.0) (exp (- x)))) ↓
(FPCore (x)
:precision binary64
(let* ((t_0 (exp (- x))))
(if (<= (+ (- (exp x) 2.0) t_0) 2e-11)
(+ (* x x) (* 0.08333333333333333 (pow x 4.0)))
(+ (exp x) (+ t_0 -2.0))))) double code(double x) {
return (exp(x) - 2.0) + exp(-x);
}
↓
double code(double x) {
double t_0 = exp(-x);
double tmp;
if (((exp(x) - 2.0) + t_0) <= 2e-11) {
tmp = (x * x) + (0.08333333333333333 * pow(x, 4.0));
} else {
tmp = exp(x) + (t_0 + -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) :: t_0
real(8) :: tmp
t_0 = exp(-x)
if (((exp(x) - 2.0d0) + t_0) <= 2d-11) then
tmp = (x * x) + (0.08333333333333333d0 * (x ** 4.0d0))
else
tmp = exp(x) + (t_0 + (-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 t_0 = Math.exp(-x);
double tmp;
if (((Math.exp(x) - 2.0) + t_0) <= 2e-11) {
tmp = (x * x) + (0.08333333333333333 * Math.pow(x, 4.0));
} else {
tmp = Math.exp(x) + (t_0 + -2.0);
}
return tmp;
}
def code(x):
return (math.exp(x) - 2.0) + math.exp(-x)
↓
def code(x):
t_0 = math.exp(-x)
tmp = 0
if ((math.exp(x) - 2.0) + t_0) <= 2e-11:
tmp = (x * x) + (0.08333333333333333 * math.pow(x, 4.0))
else:
tmp = math.exp(x) + (t_0 + -2.0)
return tmp
function code(x)
return Float64(Float64(exp(x) - 2.0) + exp(Float64(-x)))
end
↓
function code(x)
t_0 = exp(Float64(-x))
tmp = 0.0
if (Float64(Float64(exp(x) - 2.0) + t_0) <= 2e-11)
tmp = Float64(Float64(x * x) + Float64(0.08333333333333333 * (x ^ 4.0)));
else
tmp = Float64(exp(x) + Float64(t_0 + -2.0));
end
return tmp
end
function tmp = code(x)
tmp = (exp(x) - 2.0) + exp(-x);
end
↓
function tmp_2 = code(x)
t_0 = exp(-x);
tmp = 0.0;
if (((exp(x) - 2.0) + t_0) <= 2e-11)
tmp = (x * x) + (0.08333333333333333 * (x ^ 4.0));
else
tmp = exp(x) + (t_0 + -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_] := Block[{t$95$0 = N[Exp[(-x)], $MachinePrecision]}, If[LessEqual[N[(N[(N[Exp[x], $MachinePrecision] - 2.0), $MachinePrecision] + t$95$0), $MachinePrecision], 2e-11], N[(N[(x * x), $MachinePrecision] + N[(0.08333333333333333 * N[Power[x, 4.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Exp[x], $MachinePrecision] + N[(t$95$0 + -2.0), $MachinePrecision]), $MachinePrecision]]]
\left(e^{x} - 2\right) + e^{-x}
↓
\begin{array}{l}
t_0 := e^{-x}\\
\mathbf{if}\;\left(e^{x} - 2\right) + t_0 \leq 2 \cdot 10^{-11}:\\
\;\;\;\;x \cdot x + 0.08333333333333333 \cdot {x}^{4}\\
\mathbf{else}:\\
\;\;\;\;e^{x} + \left(t_0 + -2\right)\\
\end{array}
Alternatives Alternative 1 Accuracy 99.8% Cost 26436
\[\begin{array}{l}
t_0 := e^{-x}\\
\mathbf{if}\;\left(e^{x} - 2\right) + t_0 \leq 2 \cdot 10^{-11}:\\
\;\;\;\;x \cdot x + 0.08333333333333333 \cdot {x}^{4}\\
\mathbf{else}:\\
\;\;\;\;e^{x} + \left(t_0 + -2\right)\\
\end{array}
\]
Alternative 2 Accuracy 96.5% Cost 13188
\[\begin{array}{l}
\mathbf{if}\;x \leq -5 \cdot 10^{+39}:\\
\;\;\;\;\sqrt{0.006944444444444444 \cdot {x}^{8}}\\
\mathbf{elif}\;x \leq 2.6:\\
\;\;\;\;x \cdot x + 0.08333333333333333 \cdot {x}^{4}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{expm1}\left(x\right)\\
\end{array}
\]
Alternative 3 Accuracy 93.7% Cost 7044
\[\begin{array}{l}
\mathbf{if}\;x \leq 2.6:\\
\;\;\;\;x \cdot x + 0.08333333333333333 \cdot {x}^{4}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{expm1}\left(x\right)\\
\end{array}
\]
Alternative 4 Accuracy 93.5% Cost 6788
\[\begin{array}{l}
\mathbf{if}\;x \leq -3.45:\\
\;\;\;\;0.08333333333333333 \cdot {x}^{4}\\
\mathbf{elif}\;x \leq 1.65:\\
\;\;\;\;x \cdot x\\
\mathbf{else}:\\
\;\;\;\;\mathsf{expm1}\left(x\right)\\
\end{array}
\]
Alternative 5 Accuracy 87.4% Cost 6596
\[\begin{array}{l}
\mathbf{if}\;x \leq 1.65:\\
\;\;\;\;x \cdot x\\
\mathbf{else}:\\
\;\;\;\;\mathsf{expm1}\left(x\right)\\
\end{array}
\]
Alternative 6 Accuracy 75.8% Cost 192
\[x \cdot x
\]
Alternative 7 Accuracy 26.3% Cost 64
\[0
\]