| Alternative 1 | |
|---|---|
| Error | 0.4 |
| Cost | 6852 |
\[\begin{array}{l}
\mathbf{if}\;x \leq -5 \cdot 10^{-310}:\\
\;\;\;\;\sqrt{2} \cdot \left(-x\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{\sqrt{2}}{\frac{1}{x}}\\
\end{array}
\]
(FPCore (x) :precision binary64 (sqrt (+ (* x x) (* x x))))
(FPCore (x) :precision binary64 (if (<= x -5e-310) (* (sqrt 2.0) (- x)) (/ (* (sqrt 2.0) -0.25) (/ 0.25 (- x)))))
double code(double x) {
return sqrt(((x * x) + (x * x)));
}
double code(double x) {
double tmp;
if (x <= -5e-310) {
tmp = sqrt(2.0) * -x;
} else {
tmp = (sqrt(2.0) * -0.25) / (0.25 / -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 <= (-5d-310)) then
tmp = sqrt(2.0d0) * -x
else
tmp = (sqrt(2.0d0) * (-0.25d0)) / (0.25d0 / -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 <= -5e-310) {
tmp = Math.sqrt(2.0) * -x;
} else {
tmp = (Math.sqrt(2.0) * -0.25) / (0.25 / -x);
}
return tmp;
}
def code(x): return math.sqrt(((x * x) + (x * x)))
def code(x): tmp = 0 if x <= -5e-310: tmp = math.sqrt(2.0) * -x else: tmp = (math.sqrt(2.0) * -0.25) / (0.25 / -x) return tmp
function code(x) return sqrt(Float64(Float64(x * x) + Float64(x * x))) end
function code(x) tmp = 0.0 if (x <= -5e-310) tmp = Float64(sqrt(2.0) * Float64(-x)); else tmp = Float64(Float64(sqrt(2.0) * -0.25) / Float64(0.25 / Float64(-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 <= -5e-310) tmp = sqrt(2.0) * -x; else tmp = (sqrt(2.0) * -0.25) / (0.25 / -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, -5e-310], N[(N[Sqrt[2.0], $MachinePrecision] * (-x)), $MachinePrecision], N[(N[(N[Sqrt[2.0], $MachinePrecision] * -0.25), $MachinePrecision] / N[(0.25 / (-x)), $MachinePrecision]), $MachinePrecision]]
\sqrt{x \cdot x + x \cdot x}
\begin{array}{l}
\mathbf{if}\;x \leq -5 \cdot 10^{-310}:\\
\;\;\;\;\sqrt{2} \cdot \left(-x\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{\sqrt{2} \cdot -0.25}{\frac{0.25}{-x}}\\
\end{array}
Results
if x < -4.999999999999985e-310Initial program 30.6
Simplified30.6
[Start]30.6 | \[ \sqrt{x \cdot x + x \cdot x}
\] |
|---|---|
rational.json-simplify-44 [=>]30.6 | \[ \sqrt{\color{blue}{x \cdot \left(x + x\right)}}
\] |
Taylor expanded in x around -inf 0.4
Simplified0.4
[Start]0.4 | \[ -1 \cdot \left(\sqrt{2} \cdot x\right)
\] |
|---|---|
rational.json-simplify-24 [=>]0.4 | \[ \color{blue}{\sqrt{2} \cdot \left(-1 \cdot x\right)}
\] |
rational.json-simplify-50 [=>]0.4 | \[ \sqrt{2} \cdot \color{blue}{\left(x \cdot -1\right)}
\] |
rational.json-simplify-38 [=>]0.4 | \[ \sqrt{2} \cdot \color{blue}{\left(-x\right)}
\] |
if -4.999999999999985e-310 < x Initial program 30.9
Simplified30.9
[Start]30.9 | \[ \sqrt{x \cdot x + x \cdot x}
\] |
|---|---|
rational.json-simplify-44 [=>]30.9 | \[ \sqrt{\color{blue}{x \cdot \left(x + x\right)}}
\] |
Taylor expanded in x around 0 0.4
Applied egg-rr0.5
Applied egg-rr0.8
Applied egg-rr0.5
Final simplification0.4
| Alternative 1 | |
|---|---|
| Error | 0.4 |
| Cost | 6852 |
| Alternative 2 | |
|---|---|
| Error | 0.4 |
| Cost | 6788 |
| Alternative 3 | |
|---|---|
| Error | 31.8 |
| Cost | 6592 |
herbie shell --seed 2023073
(FPCore (x)
:name "sqrt A (should all be same)"
:precision binary64
(sqrt (+ (* x x) (* x x))))