| Alternative 1 | |
|---|---|
| Accuracy | 99.3% |
| Cost | 6788 |
\[\begin{array}{l}
\mathbf{if}\;x \leq -2 \cdot 10^{-310}:\\
\;\;\;\;x \cdot \left(-\sqrt{2}\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot \sqrt{2}\\
\end{array}
\]
(FPCore (x) :precision binary64 (sqrt (* (* 2.0 x) x)))
(FPCore (x) :precision binary64 (if (<= x -2e-310) (* (pow 2.0 0.25) (* (sqrt (sqrt 2.0)) (- x))) (* x (sqrt 2.0))))
double code(double x) {
return sqrt(((2.0 * x) * x));
}
double code(double x) {
double tmp;
if (x <= -2e-310) {
tmp = pow(2.0, 0.25) * (sqrt(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) * x))
end function
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= (-2d-310)) then
tmp = (2.0d0 ** 0.25d0) * (sqrt(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 * x) * x));
}
public static double code(double x) {
double tmp;
if (x <= -2e-310) {
tmp = Math.pow(2.0, 0.25) * (Math.sqrt(Math.sqrt(2.0)) * -x);
} else {
tmp = x * Math.sqrt(2.0);
}
return tmp;
}
def code(x): return math.sqrt(((2.0 * x) * x))
def code(x): tmp = 0 if x <= -2e-310: tmp = math.pow(2.0, 0.25) * (math.sqrt(math.sqrt(2.0)) * -x) else: tmp = x * math.sqrt(2.0) return tmp
function code(x) return sqrt(Float64(Float64(2.0 * x) * x)) end
function code(x) tmp = 0.0 if (x <= -2e-310) tmp = Float64((2.0 ^ 0.25) * Float64(sqrt(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) * x)); end
function tmp_2 = code(x) tmp = 0.0; if (x <= -2e-310) tmp = (2.0 ^ 0.25) * (sqrt(sqrt(2.0)) * -x); else tmp = x * sqrt(2.0); end tmp_2 = tmp; end
code[x_] := N[Sqrt[N[(N[(2.0 * x), $MachinePrecision] * x), $MachinePrecision]], $MachinePrecision]
code[x_] := If[LessEqual[x, -2e-310], N[(N[Power[2.0, 0.25], $MachinePrecision] * N[(N[Sqrt[N[Sqrt[2.0], $MachinePrecision]], $MachinePrecision] * (-x)), $MachinePrecision]), $MachinePrecision], N[(x * N[Sqrt[2.0], $MachinePrecision]), $MachinePrecision]]
\sqrt{\left(2 \cdot x\right) \cdot x}
\begin{array}{l}
\mathbf{if}\;x \leq -2 \cdot 10^{-310}:\\
\;\;\;\;{2}^{0.25} \cdot \left(\sqrt{\sqrt{2}} \cdot \left(-x\right)\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot \sqrt{2}\\
\end{array}
Results
if x < -1.999999999999994e-310Initial program 51.6%
Applied egg-rr0.0%
Applied egg-rr2.3%
Applied egg-rr51.4%
Simplified51.4%
[Start]51.4 | \[ {2}^{0.25} \cdot \sqrt{x \cdot \left(x \cdot \sqrt{2}\right)}
\] |
|---|---|
associate-*r* [=>]51.4 | \[ {2}^{0.25} \cdot \sqrt{\color{blue}{\left(x \cdot x\right) \cdot \sqrt{2}}}
\] |
*-commutative [=>]51.4 | \[ {2}^{0.25} \cdot \sqrt{\color{blue}{\sqrt{2} \cdot \left(x \cdot x\right)}}
\] |
Taylor expanded in x around -inf 99.3%
Simplified99.3%
[Start]99.3 | \[ {2}^{0.25} \cdot \left(-1 \cdot \left(\sqrt{\sqrt{2}} \cdot x\right)\right)
\] |
|---|---|
mul-1-neg [=>]99.3 | \[ {2}^{0.25} \cdot \color{blue}{\left(-\sqrt{\sqrt{2}} \cdot x\right)}
\] |
distribute-rgt-neg-in [=>]99.3 | \[ {2}^{0.25} \cdot \color{blue}{\left(\sqrt{\sqrt{2}} \cdot \left(-x\right)\right)}
\] |
if -1.999999999999994e-310 < x Initial program 52.6%
Taylor expanded in x around 0 99.3%
Final simplification99.3%
| Alternative 1 | |
|---|---|
| Accuracy | 99.3% |
| Cost | 6788 |
| Alternative 2 | |
|---|---|
| Accuracy | 51.2% |
| Cost | 6592 |
herbie shell --seed 2023129
(FPCore (x)
:name "sqrt B (should all be same)"
:precision binary64
(sqrt (* (* 2.0 x) x)))