| Alternative 1 | |
|---|---|
| Error | 0.68% |
| Cost | 19648 |
\[{2}^{0.25} \cdot \left|{2}^{0.25} \cdot x\right|
\]
(FPCore (x) :precision binary64 (sqrt (* (* 2.0 x) x)))
(FPCore (x) :precision binary64 (if (<= x -5e-310) (* x (- (sqrt 2.0))) (* (pow 2.0 0.25) (* (pow 2.0 0.25) x))))
double code(double x) {
return sqrt(((2.0 * x) * x));
}
double code(double x) {
double tmp;
if (x <= -5e-310) {
tmp = x * -sqrt(2.0);
} else {
tmp = pow(2.0, 0.25) * (pow(2.0, 0.25) * x);
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
code = sqrt(((2.0d0 * x) * x))
end function
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= (-5d-310)) then
tmp = x * -sqrt(2.0d0)
else
tmp = (2.0d0 ** 0.25d0) * ((2.0d0 ** 0.25d0) * x)
end if
code = tmp
end function
public static double code(double x) {
return Math.sqrt(((2.0 * x) * x));
}
public static double code(double x) {
double tmp;
if (x <= -5e-310) {
tmp = x * -Math.sqrt(2.0);
} else {
tmp = Math.pow(2.0, 0.25) * (Math.pow(2.0, 0.25) * x);
}
return tmp;
}
def code(x): return math.sqrt(((2.0 * x) * x))
def code(x): tmp = 0 if x <= -5e-310: tmp = x * -math.sqrt(2.0) else: tmp = math.pow(2.0, 0.25) * (math.pow(2.0, 0.25) * x) return tmp
function code(x) return sqrt(Float64(Float64(2.0 * x) * x)) end
function code(x) tmp = 0.0 if (x <= -5e-310) tmp = Float64(x * Float64(-sqrt(2.0))); else tmp = Float64((2.0 ^ 0.25) * Float64((2.0 ^ 0.25) * x)); end return tmp end
function tmp = code(x) tmp = sqrt(((2.0 * x) * x)); end
function tmp_2 = code(x) tmp = 0.0; if (x <= -5e-310) tmp = x * -sqrt(2.0); else tmp = (2.0 ^ 0.25) * ((2.0 ^ 0.25) * x); end tmp_2 = tmp; end
code[x_] := N[Sqrt[N[(N[(2.0 * x), $MachinePrecision] * x), $MachinePrecision]], $MachinePrecision]
code[x_] := If[LessEqual[x, -5e-310], N[(x * (-N[Sqrt[2.0], $MachinePrecision])), $MachinePrecision], N[(N[Power[2.0, 0.25], $MachinePrecision] * N[(N[Power[2.0, 0.25], $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision]]
\sqrt{\left(2 \cdot x\right) \cdot x}
\begin{array}{l}
\mathbf{if}\;x \leq -5 \cdot 10^{-310}:\\
\;\;\;\;x \cdot \left(-\sqrt{2}\right)\\
\mathbf{else}:\\
\;\;\;\;{2}^{0.25} \cdot \left({2}^{0.25} \cdot x\right)\\
\end{array}
Results
if x < -4.999999999999985e-310Initial program 47.65
Taylor expanded in x around -inf 0.68
Simplified0.68
[Start]0.68 | \[ -1 \cdot \left(\sqrt{2} \cdot x\right)
\] |
|---|---|
mul-1-neg [=>]0.68 | \[ \color{blue}{-\sqrt{2} \cdot x}
\] |
distribute-rgt-neg-in [=>]0.68 | \[ \color{blue}{\sqrt{2} \cdot \left(-x\right)}
\] |
if -4.999999999999985e-310 < x Initial program 48.74
Applied egg-rr1.05
Applied egg-rr0.68
Final simplification0.68
| Alternative 1 | |
|---|---|
| Error | 0.68% |
| Cost | 19648 |
| Alternative 2 | |
|---|---|
| Error | 2.05% |
| Cost | 19584 |
| Alternative 3 | |
|---|---|
| Error | 0.6% |
| Cost | 13252 |
| Alternative 4 | |
|---|---|
| Error | 0.69% |
| Cost | 6788 |
| Alternative 5 | |
|---|---|
| Error | 49.39% |
| Cost | 6592 |
herbie shell --seed 2023104
(FPCore (x)
:name "sqrt B (should all be same)"
:precision binary64
(sqrt (* (* 2.0 x) x)))