| Alternative 1 | |
|---|---|
| Error | 17.5 |
| Cost | 6464 |
\[\sqrt{2}
\]
(FPCore (x) :precision binary64 (sqrt (/ (- (exp (* 2.0 x)) 1.0) (- (exp x) 1.0))))
(FPCore (x) :precision binary64 (if (<= x -4.2e-6) (sqrt (/ (- (exp (* 2.0 x)) 1.0) (- (exp x) 1.0))) (sqrt (+ x 2.0))))
double code(double x) {
return sqrt(((exp((2.0 * x)) - 1.0) / (exp(x) - 1.0)));
}
double code(double x) {
double tmp;
if (x <= -4.2e-6) {
tmp = sqrt(((exp((2.0 * x)) - 1.0) / (exp(x) - 1.0)));
} else {
tmp = sqrt((x + 2.0));
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
code = sqrt(((exp((2.0d0 * x)) - 1.0d0) / (exp(x) - 1.0d0)))
end function
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= (-4.2d-6)) then
tmp = sqrt(((exp((2.0d0 * x)) - 1.0d0) / (exp(x) - 1.0d0)))
else
tmp = sqrt((x + 2.0d0))
end if
code = tmp
end function
public static double code(double x) {
return Math.sqrt(((Math.exp((2.0 * x)) - 1.0) / (Math.exp(x) - 1.0)));
}
public static double code(double x) {
double tmp;
if (x <= -4.2e-6) {
tmp = Math.sqrt(((Math.exp((2.0 * x)) - 1.0) / (Math.exp(x) - 1.0)));
} else {
tmp = Math.sqrt((x + 2.0));
}
return tmp;
}
def code(x): return math.sqrt(((math.exp((2.0 * x)) - 1.0) / (math.exp(x) - 1.0)))
def code(x): tmp = 0 if x <= -4.2e-6: tmp = math.sqrt(((math.exp((2.0 * x)) - 1.0) / (math.exp(x) - 1.0))) else: tmp = math.sqrt((x + 2.0)) return tmp
function code(x) return sqrt(Float64(Float64(exp(Float64(2.0 * x)) - 1.0) / Float64(exp(x) - 1.0))) end
function code(x) tmp = 0.0 if (x <= -4.2e-6) tmp = sqrt(Float64(Float64(exp(Float64(2.0 * x)) - 1.0) / Float64(exp(x) - 1.0))); else tmp = sqrt(Float64(x + 2.0)); end return tmp end
function tmp = code(x) tmp = sqrt(((exp((2.0 * x)) - 1.0) / (exp(x) - 1.0))); end
function tmp_2 = code(x) tmp = 0.0; if (x <= -4.2e-6) tmp = sqrt(((exp((2.0 * x)) - 1.0) / (exp(x) - 1.0))); else tmp = sqrt((x + 2.0)); end tmp_2 = tmp; end
code[x_] := N[Sqrt[N[(N[(N[Exp[N[(2.0 * x), $MachinePrecision]], $MachinePrecision] - 1.0), $MachinePrecision] / N[(N[Exp[x], $MachinePrecision] - 1.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
code[x_] := If[LessEqual[x, -4.2e-6], N[Sqrt[N[(N[(N[Exp[N[(2.0 * x), $MachinePrecision]], $MachinePrecision] - 1.0), $MachinePrecision] / N[(N[Exp[x], $MachinePrecision] - 1.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], N[Sqrt[N[(x + 2.0), $MachinePrecision]], $MachinePrecision]]
\sqrt{\frac{e^{2 \cdot x} - 1}{e^{x} - 1}}
\begin{array}{l}
\mathbf{if}\;x \leq -4.2 \cdot 10^{-6}:\\
\;\;\;\;\sqrt{\frac{e^{2 \cdot x} - 1}{e^{x} - 1}}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{x + 2}\\
\end{array}
Results
if x < -4.1999999999999996e-6Initial program 0.1
if -4.1999999999999996e-6 < x Initial program 62.1
Taylor expanded in x around 0 0.4
Simplified0.4
[Start]0.4 | \[ \sqrt{2 + x}
\] |
|---|---|
rational_best.json-simplify-1 [=>]0.4 | \[ \sqrt{\color{blue}{x + 2}}
\] |
Final simplification0.3
| Alternative 1 | |
|---|---|
| Error | 17.5 |
| Cost | 6464 |
herbie shell --seed 2023089
(FPCore (x)
:name "sqrtexp (problem 3.4.4)"
:precision binary64
(sqrt (/ (- (exp (* 2.0 x)) 1.0) (- (exp x) 1.0))))