| Alternative 1 | |
|---|---|
| Error | 0.8 |
| Cost | 39620 |
\[\begin{array}{l}
t_0 := \sqrt{\frac{e^{2 \cdot x} - 1}{e^{x} - 1}}\\
\mathbf{if}\;t_0 \leq 2:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;\sqrt{2}\\
\end{array}
\]
(FPCore (x) :precision binary64 (sqrt (/ (- (exp (* 2.0 x)) 1.0) (- (exp x) 1.0))))
(FPCore (x)
:precision binary64
(let* ((t_0 (sqrt (/ (- (exp (* 2.0 x)) 1.0) (- (exp x) 1.0)))))
(if (<= t_0 1.2)
t_0
(+
(sqrt 2.0)
(*
0.5
(+
(/ x (sqrt 2.0))
(+
(* (pow x 2.0) (+ (* (sqrt 2.0) 0.25) (* (sqrt 8.0) -0.03125)))
(* (sqrt 2.0) (* (pow x 3.0) 0.036458333333333336)))))))))double code(double x) {
return sqrt(((exp((2.0 * x)) - 1.0) / (exp(x) - 1.0)));
}
double code(double x) {
double t_0 = sqrt(((exp((2.0 * x)) - 1.0) / (exp(x) - 1.0)));
double tmp;
if (t_0 <= 1.2) {
tmp = t_0;
} else {
tmp = sqrt(2.0) + (0.5 * ((x / sqrt(2.0)) + ((pow(x, 2.0) * ((sqrt(2.0) * 0.25) + (sqrt(8.0) * -0.03125))) + (sqrt(2.0) * (pow(x, 3.0) * 0.036458333333333336)))));
}
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 = sqrt(((exp((2.0d0 * x)) - 1.0d0) / (exp(x) - 1.0d0)))
if (t_0 <= 1.2d0) then
tmp = t_0
else
tmp = sqrt(2.0d0) + (0.5d0 * ((x / sqrt(2.0d0)) + (((x ** 2.0d0) * ((sqrt(2.0d0) * 0.25d0) + (sqrt(8.0d0) * (-0.03125d0)))) + (sqrt(2.0d0) * ((x ** 3.0d0) * 0.036458333333333336d0)))))
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.sqrt(((Math.exp((2.0 * x)) - 1.0) / (Math.exp(x) - 1.0)));
double tmp;
if (t_0 <= 1.2) {
tmp = t_0;
} else {
tmp = Math.sqrt(2.0) + (0.5 * ((x / Math.sqrt(2.0)) + ((Math.pow(x, 2.0) * ((Math.sqrt(2.0) * 0.25) + (Math.sqrt(8.0) * -0.03125))) + (Math.sqrt(2.0) * (Math.pow(x, 3.0) * 0.036458333333333336)))));
}
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.sqrt(((math.exp((2.0 * x)) - 1.0) / (math.exp(x) - 1.0))) tmp = 0 if t_0 <= 1.2: tmp = t_0 else: tmp = math.sqrt(2.0) + (0.5 * ((x / math.sqrt(2.0)) + ((math.pow(x, 2.0) * ((math.sqrt(2.0) * 0.25) + (math.sqrt(8.0) * -0.03125))) + (math.sqrt(2.0) * (math.pow(x, 3.0) * 0.036458333333333336))))) 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 = sqrt(Float64(Float64(exp(Float64(2.0 * x)) - 1.0) / Float64(exp(x) - 1.0))) tmp = 0.0 if (t_0 <= 1.2) tmp = t_0; else tmp = Float64(sqrt(2.0) + Float64(0.5 * Float64(Float64(x / sqrt(2.0)) + Float64(Float64((x ^ 2.0) * Float64(Float64(sqrt(2.0) * 0.25) + Float64(sqrt(8.0) * -0.03125))) + Float64(sqrt(2.0) * Float64((x ^ 3.0) * 0.036458333333333336)))))); 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 = sqrt(((exp((2.0 * x)) - 1.0) / (exp(x) - 1.0))); tmp = 0.0; if (t_0 <= 1.2) tmp = t_0; else tmp = sqrt(2.0) + (0.5 * ((x / sqrt(2.0)) + (((x ^ 2.0) * ((sqrt(2.0) * 0.25) + (sqrt(8.0) * -0.03125))) + (sqrt(2.0) * ((x ^ 3.0) * 0.036458333333333336))))); 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[Sqrt[N[(N[(N[Exp[N[(2.0 * x), $MachinePrecision]], $MachinePrecision] - 1.0), $MachinePrecision] / N[(N[Exp[x], $MachinePrecision] - 1.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[t$95$0, 1.2], t$95$0, N[(N[Sqrt[2.0], $MachinePrecision] + N[(0.5 * N[(N[(x / N[Sqrt[2.0], $MachinePrecision]), $MachinePrecision] + N[(N[(N[Power[x, 2.0], $MachinePrecision] * N[(N[(N[Sqrt[2.0], $MachinePrecision] * 0.25), $MachinePrecision] + N[(N[Sqrt[8.0], $MachinePrecision] * -0.03125), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[Sqrt[2.0], $MachinePrecision] * N[(N[Power[x, 3.0], $MachinePrecision] * 0.036458333333333336), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\sqrt{\frac{e^{2 \cdot x} - 1}{e^{x} - 1}}
\begin{array}{l}
t_0 := \sqrt{\frac{e^{2 \cdot x} - 1}{e^{x} - 1}}\\
\mathbf{if}\;t_0 \leq 1.2:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;\sqrt{2} + 0.5 \cdot \left(\frac{x}{\sqrt{2}} + \left({x}^{2} \cdot \left(\sqrt{2} \cdot 0.25 + \sqrt{8} \cdot -0.03125\right) + \sqrt{2} \cdot \left({x}^{3} \cdot 0.036458333333333336\right)\right)\right)\\
\end{array}
Results
if (sqrt.f64 (/.f64 (-.f64 (exp.f64 (*.f64 2 x)) 1) (-.f64 (exp.f64 x) 1))) < 1.19999999999999996Initial program 0.0
if 1.19999999999999996 < (sqrt.f64 (/.f64 (-.f64 (exp.f64 (*.f64 2 x)) 1) (-.f64 (exp.f64 x) 1))) Initial program 61.1
Taylor expanded in x around 0 0.6
Simplified0.6
[Start]0.6 | \[ \sqrt{2} + \left(0.5 \cdot \frac{\left(0.16666666666666666 - 0.5 \cdot \frac{0.5 - {\left(\frac{0.5}{\sqrt{2}}\right)}^{2}}{{\left(\sqrt{2}\right)}^{2}}\right) \cdot {x}^{3}}{\sqrt{2}} + \left(0.5 \cdot \frac{\left(0.5 - {\left(\frac{0.5}{\sqrt{2}}\right)}^{2}\right) \cdot {x}^{2}}{\sqrt{2}} + 0.5 \cdot \frac{x}{\sqrt{2}}\right)\right)
\] |
|---|---|
rational.json-simplify-1 [=>]0.6 | \[ \sqrt{2} + \color{blue}{\left(\left(0.5 \cdot \frac{\left(0.5 - {\left(\frac{0.5}{\sqrt{2}}\right)}^{2}\right) \cdot {x}^{2}}{\sqrt{2}} + 0.5 \cdot \frac{x}{\sqrt{2}}\right) + 0.5 \cdot \frac{\left(0.16666666666666666 - 0.5 \cdot \frac{0.5 - {\left(\frac{0.5}{\sqrt{2}}\right)}^{2}}{{\left(\sqrt{2}\right)}^{2}}\right) \cdot {x}^{3}}{\sqrt{2}}\right)}
\] |
rational.json-simplify-1 [=>]0.6 | \[ \sqrt{2} + \left(\color{blue}{\left(0.5 \cdot \frac{x}{\sqrt{2}} + 0.5 \cdot \frac{\left(0.5 - {\left(\frac{0.5}{\sqrt{2}}\right)}^{2}\right) \cdot {x}^{2}}{\sqrt{2}}\right)} + 0.5 \cdot \frac{\left(0.16666666666666666 - 0.5 \cdot \frac{0.5 - {\left(\frac{0.5}{\sqrt{2}}\right)}^{2}}{{\left(\sqrt{2}\right)}^{2}}\right) \cdot {x}^{3}}{\sqrt{2}}\right)
\] |
rational.json-simplify-2 [=>]0.6 | \[ \sqrt{2} + \left(\left(0.5 \cdot \frac{x}{\sqrt{2}} + \color{blue}{\frac{\left(0.5 - {\left(\frac{0.5}{\sqrt{2}}\right)}^{2}\right) \cdot {x}^{2}}{\sqrt{2}} \cdot 0.5}\right) + 0.5 \cdot \frac{\left(0.16666666666666666 - 0.5 \cdot \frac{0.5 - {\left(\frac{0.5}{\sqrt{2}}\right)}^{2}}{{\left(\sqrt{2}\right)}^{2}}\right) \cdot {x}^{3}}{\sqrt{2}}\right)
\] |
rational.json-simplify-51 [=>]0.6 | \[ \sqrt{2} + \left(\color{blue}{0.5 \cdot \left(\frac{\left(0.5 - {\left(\frac{0.5}{\sqrt{2}}\right)}^{2}\right) \cdot {x}^{2}}{\sqrt{2}} + \frac{x}{\sqrt{2}}\right)} + 0.5 \cdot \frac{\left(0.16666666666666666 - 0.5 \cdot \frac{0.5 - {\left(\frac{0.5}{\sqrt{2}}\right)}^{2}}{{\left(\sqrt{2}\right)}^{2}}\right) \cdot {x}^{3}}{\sqrt{2}}\right)
\] |
rational.json-simplify-2 [=>]0.6 | \[ \sqrt{2} + \left(0.5 \cdot \left(\frac{\left(0.5 - {\left(\frac{0.5}{\sqrt{2}}\right)}^{2}\right) \cdot {x}^{2}}{\sqrt{2}} + \frac{x}{\sqrt{2}}\right) + \color{blue}{\frac{\left(0.16666666666666666 - 0.5 \cdot \frac{0.5 - {\left(\frac{0.5}{\sqrt{2}}\right)}^{2}}{{\left(\sqrt{2}\right)}^{2}}\right) \cdot {x}^{3}}{\sqrt{2}} \cdot 0.5}\right)
\] |
Taylor expanded in x around -inf 0.6
Simplified0.6
[Start]0.6 | \[ \sqrt{2} + 0.5 \cdot \left(\left(0.5 \cdot \frac{1}{\sqrt{2}} - 0.25 \cdot \frac{1}{{\left(\sqrt{2}\right)}^{3}}\right) \cdot {x}^{2} + \left(\frac{\left(0.16666666666666666 - 0.25 \cdot \left(0.5 - 0.25 \cdot \frac{1}{{\left(\sqrt{2}\right)}^{2}}\right)\right) \cdot {x}^{3}}{\sqrt{2}} + \frac{x}{\sqrt{2}}\right)\right)
\] |
|---|---|
rational.json-simplify-41 [<=]0.6 | \[ \sqrt{2} + 0.5 \cdot \color{blue}{\left(\frac{x}{\sqrt{2}} + \left(\left(0.5 \cdot \frac{1}{\sqrt{2}} - 0.25 \cdot \frac{1}{{\left(\sqrt{2}\right)}^{3}}\right) \cdot {x}^{2} + \frac{\left(0.16666666666666666 - 0.25 \cdot \left(0.5 - 0.25 \cdot \frac{1}{{\left(\sqrt{2}\right)}^{2}}\right)\right) \cdot {x}^{3}}{\sqrt{2}}\right)\right)}
\] |
exponential.json-simplify-24 [=>]0.6 | \[ \sqrt{2} + 0.5 \cdot \left(\frac{x}{\sqrt{2}} + \left(\left(0.5 \cdot \frac{1}{\sqrt{2}} - 0.25 \cdot \frac{1}{\color{blue}{\sqrt{{2}^{3}}}}\right) \cdot {x}^{2} + \frac{\left(0.16666666666666666 - 0.25 \cdot \left(0.5 - 0.25 \cdot \frac{1}{{\left(\sqrt{2}\right)}^{2}}\right)\right) \cdot {x}^{3}}{\sqrt{2}}\right)\right)
\] |
metadata-eval [=>]0.6 | \[ \sqrt{2} + 0.5 \cdot \left(\frac{x}{\sqrt{2}} + \left(\left(0.5 \cdot \frac{1}{\sqrt{2}} - 0.25 \cdot \frac{1}{\sqrt{\color{blue}{8}}}\right) \cdot {x}^{2} + \frac{\left(0.16666666666666666 - 0.25 \cdot \left(0.5 - 0.25 \cdot \frac{1}{{\left(\sqrt{2}\right)}^{2}}\right)\right) \cdot {x}^{3}}{\sqrt{2}}\right)\right)
\] |
rational.json-simplify-49 [=>]0.6 | \[ \sqrt{2} + 0.5 \cdot \left(\frac{x}{\sqrt{2}} + \left(\left(0.5 \cdot \frac{1}{\sqrt{2}} - 0.25 \cdot \frac{1}{\sqrt{8}}\right) \cdot {x}^{2} + \color{blue}{{x}^{3} \cdot \frac{0.16666666666666666 - 0.25 \cdot \left(0.5 - 0.25 \cdot \frac{1}{{\left(\sqrt{2}\right)}^{2}}\right)}{\sqrt{2}}}\right)\right)
\] |
Applied egg-rr0.6
Simplified0.6
[Start]0.6 | \[ \sqrt{2} + 0.5 \cdot \left(\frac{x}{\sqrt{2}} + \left(\left(\left(-0.25 \cdot \left(\sqrt{8} \cdot 0.125 - \sqrt{2}\right)\right) \cdot {x}^{2} + {x}^{3} \cdot \left(\sqrt{2} \cdot 0.036458333333333336\right)\right) - 0\right)\right)
\] |
|---|---|
rational.json-simplify-5 [=>]0.6 | \[ \sqrt{2} + 0.5 \cdot \left(\frac{x}{\sqrt{2}} + \color{blue}{\left(\left(-0.25 \cdot \left(\sqrt{8} \cdot 0.125 - \sqrt{2}\right)\right) \cdot {x}^{2} + {x}^{3} \cdot \left(\sqrt{2} \cdot 0.036458333333333336\right)\right)}\right)
\] |
Final simplification0.4
| Alternative 1 | |
|---|---|
| Error | 0.8 |
| Cost | 39620 |
| Alternative 2 | |
|---|---|
| Error | 18.3 |
| Cost | 6464 |
herbie shell --seed 2023073
(FPCore (x)
:name "sqrtexp (problem 3.4.4)"
:precision binary64
(sqrt (/ (- (exp (* 2.0 x)) 1.0) (- (exp x) 1.0))))