| Alternative 1 | |
|---|---|
| Error | 0.4 |
| Cost | 13252 |
\[\begin{array}{l}
\mathbf{if}\;x \leq -2 \cdot 10^{-310}:\\
\;\;\;\;\sqrt{2} \cdot \left(-x\right)\\
\mathbf{else}:\\
\;\;\;\;\sqrt{x + x} \cdot \sqrt{x}\\
\end{array}
\]
(FPCore (x) :precision binary64 (sqrt (+ (* x x) (* x x))))
(FPCore (x) :precision binary64 (if (<= x -2e-310) (* (sqrt (* x -2.0)) (sqrt (- x))) (* (sqrt (+ x x)) (sqrt x))))
double code(double x) {
return sqrt(((x * x) + (x * x)));
}
double code(double x) {
double tmp;
if (x <= -2e-310) {
tmp = sqrt((x * -2.0)) * sqrt(-x);
} else {
tmp = sqrt((x + x)) * sqrt(x);
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
code = sqrt(((x * x) + (x * x)))
end function
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= (-2d-310)) then
tmp = sqrt((x * (-2.0d0))) * sqrt(-x)
else
tmp = sqrt((x + x)) * sqrt(x)
end if
code = tmp
end function
public static double code(double x) {
return Math.sqrt(((x * x) + (x * x)));
}
public static double code(double x) {
double tmp;
if (x <= -2e-310) {
tmp = Math.sqrt((x * -2.0)) * Math.sqrt(-x);
} else {
tmp = Math.sqrt((x + x)) * Math.sqrt(x);
}
return tmp;
}
def code(x): return math.sqrt(((x * x) + (x * x)))
def code(x): tmp = 0 if x <= -2e-310: tmp = math.sqrt((x * -2.0)) * math.sqrt(-x) else: tmp = math.sqrt((x + x)) * math.sqrt(x) return tmp
function code(x) return sqrt(Float64(Float64(x * x) + Float64(x * x))) end
function code(x) tmp = 0.0 if (x <= -2e-310) tmp = Float64(sqrt(Float64(x * -2.0)) * sqrt(Float64(-x))); else tmp = Float64(sqrt(Float64(x + x)) * sqrt(x)); end return tmp end
function tmp = code(x) tmp = sqrt(((x * x) + (x * x))); end
function tmp_2 = code(x) tmp = 0.0; if (x <= -2e-310) tmp = sqrt((x * -2.0)) * sqrt(-x); else tmp = sqrt((x + x)) * sqrt(x); end tmp_2 = tmp; end
code[x_] := N[Sqrt[N[(N[(x * x), $MachinePrecision] + N[(x * x), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
code[x_] := If[LessEqual[x, -2e-310], N[(N[Sqrt[N[(x * -2.0), $MachinePrecision]], $MachinePrecision] * N[Sqrt[(-x)], $MachinePrecision]), $MachinePrecision], N[(N[Sqrt[N[(x + x), $MachinePrecision]], $MachinePrecision] * N[Sqrt[x], $MachinePrecision]), $MachinePrecision]]
\sqrt{x \cdot x + x \cdot x}
\begin{array}{l}
\mathbf{if}\;x \leq -2 \cdot 10^{-310}:\\
\;\;\;\;\sqrt{x \cdot -2} \cdot \sqrt{-x}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{x + x} \cdot \sqrt{x}\\
\end{array}
Results
if x < -1.999999999999994e-310Initial program 31.0
Simplified31.0
[Start]31.0 | \[ \sqrt{x \cdot x + x \cdot x}
\] |
|---|---|
rational_best-simplify-63 [=>]31.0 | \[ \sqrt{\color{blue}{x \cdot \left(x + x\right)}}
\] |
Applied egg-rr0.4
if -1.999999999999994e-310 < x Initial program 30.3
Simplified30.3
[Start]30.3 | \[ \sqrt{x \cdot x + x \cdot x}
\] |
|---|---|
rational_best-simplify-63 [=>]30.3 | \[ \sqrt{\color{blue}{x \cdot \left(x + x\right)}}
\] |
Applied egg-rr0.4
Final simplification0.4
| Alternative 1 | |
|---|---|
| Error | 0.4 |
| Cost | 13252 |
| Alternative 2 | |
|---|---|
| Error | 0.4 |
| Cost | 6788 |
| Alternative 3 | |
|---|---|
| Error | 31.6 |
| Cost | 6592 |
herbie shell --seed 2023100
(FPCore (x)
:name "sqrt A (should all be same)"
:precision binary64
(sqrt (+ (* x x) (* x x))))