| Alternative 1 | |
|---|---|
| Error | 0.4 |
| Cost | 33220 |
\[\begin{array}{l}
t_0 := \frac{e^{2 \cdot x} - 1}{e^{x} - 1}\\
\mathbf{if}\;t_0 \leq 1.5:\\
\;\;\;\;\sqrt{t_0}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{{x}^{2} \cdot 0.5 + \left(2 + x\right)}\\
\end{array}
\]
(FPCore (x) :precision binary64 (sqrt (/ (- (exp (* 2.0 x)) 1.0) (- (exp x) 1.0))))
(FPCore (x)
:precision binary64
(let* ((t_0 (/ (- (exp (* 2.0 x)) 1.0) (- (exp x) 1.0))))
(if (<= t_0 1.5)
(sqrt t_0)
(sqrt
(+
(* (pow x 2.0) 0.5)
(+ (+ 2.0 x) (* (pow x 3.0) 0.16666666666666666)))))))double code(double x) {
return sqrt(((exp((2.0 * x)) - 1.0) / (exp(x) - 1.0)));
}
double code(double x) {
double t_0 = (exp((2.0 * x)) - 1.0) / (exp(x) - 1.0);
double tmp;
if (t_0 <= 1.5) {
tmp = sqrt(t_0);
} else {
tmp = sqrt(((pow(x, 2.0) * 0.5) + ((2.0 + x) + (pow(x, 3.0) * 0.16666666666666666))));
}
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) :: t_0
real(8) :: tmp
t_0 = (exp((2.0d0 * x)) - 1.0d0) / (exp(x) - 1.0d0)
if (t_0 <= 1.5d0) then
tmp = sqrt(t_0)
else
tmp = sqrt((((x ** 2.0d0) * 0.5d0) + ((2.0d0 + x) + ((x ** 3.0d0) * 0.16666666666666666d0))))
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 t_0 = (Math.exp((2.0 * x)) - 1.0) / (Math.exp(x) - 1.0);
double tmp;
if (t_0 <= 1.5) {
tmp = Math.sqrt(t_0);
} else {
tmp = Math.sqrt(((Math.pow(x, 2.0) * 0.5) + ((2.0 + x) + (Math.pow(x, 3.0) * 0.16666666666666666))));
}
return tmp;
}
def code(x): return math.sqrt(((math.exp((2.0 * x)) - 1.0) / (math.exp(x) - 1.0)))
def code(x): t_0 = (math.exp((2.0 * x)) - 1.0) / (math.exp(x) - 1.0) tmp = 0 if t_0 <= 1.5: tmp = math.sqrt(t_0) else: tmp = math.sqrt(((math.pow(x, 2.0) * 0.5) + ((2.0 + x) + (math.pow(x, 3.0) * 0.16666666666666666)))) 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) t_0 = Float64(Float64(exp(Float64(2.0 * x)) - 1.0) / Float64(exp(x) - 1.0)) tmp = 0.0 if (t_0 <= 1.5) tmp = sqrt(t_0); else tmp = sqrt(Float64(Float64((x ^ 2.0) * 0.5) + Float64(Float64(2.0 + x) + Float64((x ^ 3.0) * 0.16666666666666666)))); 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) t_0 = (exp((2.0 * x)) - 1.0) / (exp(x) - 1.0); tmp = 0.0; if (t_0 <= 1.5) tmp = sqrt(t_0); else tmp = sqrt((((x ^ 2.0) * 0.5) + ((2.0 + x) + ((x ^ 3.0) * 0.16666666666666666)))); 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_] := Block[{t$95$0 = N[(N[(N[Exp[N[(2.0 * x), $MachinePrecision]], $MachinePrecision] - 1.0), $MachinePrecision] / N[(N[Exp[x], $MachinePrecision] - 1.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, 1.5], N[Sqrt[t$95$0], $MachinePrecision], N[Sqrt[N[(N[(N[Power[x, 2.0], $MachinePrecision] * 0.5), $MachinePrecision] + N[(N[(2.0 + x), $MachinePrecision] + N[(N[Power[x, 3.0], $MachinePrecision] * 0.16666666666666666), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]]
\sqrt{\frac{e^{2 \cdot x} - 1}{e^{x} - 1}}
\begin{array}{l}
t_0 := \frac{e^{2 \cdot x} - 1}{e^{x} - 1}\\
\mathbf{if}\;t_0 \leq 1.5:\\
\;\;\;\;\sqrt{t_0}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{{x}^{2} \cdot 0.5 + \left(\left(2 + x\right) + {x}^{3} \cdot 0.16666666666666666\right)}\\
\end{array}
Results
if (/.f64 (-.f64 (exp.f64 (*.f64 2 x)) 1) (-.f64 (exp.f64 x) 1)) < 1.5Initial program 0.1
if 1.5 < (/.f64 (-.f64 (exp.f64 (*.f64 2 x)) 1) (-.f64 (exp.f64 x) 1)) Initial program 61.4
Taylor expanded in x around 0 0.5
Simplified0.5
[Start]0.5 | \[ \sqrt{0.16666666666666666 \cdot {x}^{3} + \left(2 + \left(0.5 \cdot {x}^{2} + x\right)\right)}
\] |
|---|---|
rational.json-simplify-41 [=>]0.5 | \[ \sqrt{0.16666666666666666 \cdot {x}^{3} + \color{blue}{\left(0.5 \cdot {x}^{2} + \left(x + 2\right)\right)}}
\] |
rational.json-simplify-1 [<=]0.5 | \[ \sqrt{0.16666666666666666 \cdot {x}^{3} + \left(0.5 \cdot {x}^{2} + \color{blue}{\left(2 + x\right)}\right)}
\] |
rational.json-simplify-41 [=>]0.5 | \[ \sqrt{\color{blue}{0.5 \cdot {x}^{2} + \left(\left(2 + x\right) + 0.16666666666666666 \cdot {x}^{3}\right)}}
\] |
rational.json-simplify-2 [=>]0.5 | \[ \sqrt{\color{blue}{{x}^{2} \cdot 0.5} + \left(\left(2 + x\right) + 0.16666666666666666 \cdot {x}^{3}\right)}
\] |
rational.json-simplify-2 [=>]0.5 | \[ \sqrt{{x}^{2} \cdot 0.5 + \left(\left(2 + x\right) + \color{blue}{{x}^{3} \cdot 0.16666666666666666}\right)}
\] |
Final simplification0.4
| Alternative 1 | |
|---|---|
| Error | 0.4 |
| Cost | 33220 |
| Alternative 2 | |
|---|---|
| Error | 17.8 |
| Cost | 6464 |
herbie shell --seed 2023075
(FPCore (x)
:name "sqrtexp (problem 3.4.4)"
:precision binary64
(sqrt (/ (- (exp (* 2.0 x)) 1.0) (- (exp x) 1.0))))