| Alternative 1 | |
|---|---|
| Error | 2.11% |
| Cost | 25920 |
\[{\left({\left(\sqrt[3]{x \cdot \sqrt{2}}\right)}^{2}\right)}^{1.5}
\]
(FPCore (x) :precision binary64 (sqrt (* 2.0 (pow x 2.0))))
(FPCore (x) :precision binary64 (if (<= x -1e-310) (* (sqrt 2.0) (- x)) (* x (sqrt 2.0))))
double code(double x) {
return sqrt((2.0 * pow(x, 2.0)));
}
double code(double x) {
double tmp;
if (x <= -1e-310) {
tmp = sqrt(2.0) * -x;
} else {
tmp = x * sqrt(2.0);
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
code = sqrt((2.0d0 * (x ** 2.0d0)))
end function
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= (-1d-310)) then
tmp = sqrt(2.0d0) * -x
else
tmp = x * sqrt(2.0d0)
end if
code = tmp
end function
public static double code(double x) {
return Math.sqrt((2.0 * Math.pow(x, 2.0)));
}
public static double code(double x) {
double tmp;
if (x <= -1e-310) {
tmp = Math.sqrt(2.0) * -x;
} else {
tmp = x * Math.sqrt(2.0);
}
return tmp;
}
def code(x): return math.sqrt((2.0 * math.pow(x, 2.0)))
def code(x): tmp = 0 if x <= -1e-310: tmp = math.sqrt(2.0) * -x else: tmp = x * math.sqrt(2.0) return tmp
function code(x) return sqrt(Float64(2.0 * (x ^ 2.0))) end
function code(x) tmp = 0.0 if (x <= -1e-310) tmp = Float64(sqrt(2.0) * Float64(-x)); else tmp = Float64(x * sqrt(2.0)); end return tmp end
function tmp = code(x) tmp = sqrt((2.0 * (x ^ 2.0))); end
function tmp_2 = code(x) tmp = 0.0; if (x <= -1e-310) tmp = sqrt(2.0) * -x; else tmp = x * sqrt(2.0); end tmp_2 = tmp; end
code[x_] := N[Sqrt[N[(2.0 * N[Power[x, 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
code[x_] := If[LessEqual[x, -1e-310], N[(N[Sqrt[2.0], $MachinePrecision] * (-x)), $MachinePrecision], N[(x * N[Sqrt[2.0], $MachinePrecision]), $MachinePrecision]]
\sqrt{2 \cdot {x}^{2}}
\begin{array}{l}
\mathbf{if}\;x \leq -1 \cdot 10^{-310}:\\
\;\;\;\;\sqrt{2} \cdot \left(-x\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot \sqrt{2}\\
\end{array}
Results
if x < -9.999999999999969e-311Initial program 47.99
Simplified47.99
[Start]47.99 | \[ \sqrt{2 \cdot {x}^{2}}
\] |
|---|---|
unpow2 [=>]47.99 | \[ \sqrt{2 \cdot \color{blue}{\left(x \cdot x\right)}}
\] |
Taylor expanded in x around -inf 0.67
Simplified0.67
[Start]0.67 | \[ -1 \cdot \left(\sqrt{2} \cdot x\right)
\] |
|---|---|
*-commutative [<=]0.67 | \[ -1 \cdot \color{blue}{\left(x \cdot \sqrt{2}\right)}
\] |
mul-1-neg [=>]0.67 | \[ \color{blue}{-x \cdot \sqrt{2}}
\] |
*-commutative [=>]0.67 | \[ -\color{blue}{\sqrt{2} \cdot x}
\] |
distribute-rgt-neg-in [=>]0.67 | \[ \color{blue}{\sqrt{2} \cdot \left(-x\right)}
\] |
if -9.999999999999969e-311 < x Initial program 47.73
Simplified47.73
[Start]47.73 | \[ \sqrt{2 \cdot {x}^{2}}
\] |
|---|---|
unpow2 [=>]47.73 | \[ \sqrt{2 \cdot \color{blue}{\left(x \cdot x\right)}}
\] |
Taylor expanded in x around 0 0.68
Final simplification0.67
| Alternative 1 | |
|---|---|
| Error | 2.11% |
| Cost | 25920 |
| Alternative 2 | |
|---|---|
| Error | 2.04% |
| Cost | 19584 |
| Alternative 3 | |
|---|---|
| Error | 48.82% |
| Cost | 6592 |
herbie shell --seed 2023103
(FPCore (x)
:name "sqrt D (should all be same)"
:precision binary64
(sqrt (* 2.0 (pow x 2.0))))