
(FPCore (x y) :precision binary64 (+ (* x x) (* y y)))
double code(double x, double y) {
return (x * x) + (y * y);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (x * x) + (y * y)
end function
public static double code(double x, double y) {
return (x * x) + (y * y);
}
def code(x, y): return (x * x) + (y * y)
function code(x, y) return Float64(Float64(x * x) + Float64(y * y)) end
function tmp = code(x, y) tmp = (x * x) + (y * y); end
code[x_, y_] := N[(N[(x * x), $MachinePrecision] + N[(y * y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot x + y \cdot y
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 2 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y) :precision binary64 (+ (* x x) (* y y)))
double code(double x, double y) {
return (x * x) + (y * y);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (x * x) + (y * y)
end function
public static double code(double x, double y) {
return (x * x) + (y * y);
}
def code(x, y): return (x * x) + (y * y)
function code(x, y) return Float64(Float64(x * x) + Float64(y * y)) end
function tmp = code(x, y) tmp = (x * x) + (y * y); end
code[x_, y_] := N[(N[(x * x), $MachinePrecision] + N[(y * y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot x + y \cdot y
\end{array}
x_m = (fabs.f64 x) y_m = (fabs.f64 y) NOTE: x_m and y_m should be sorted in increasing order before calling this function. (FPCore (x_m y_m) :precision binary64 (fma y_m y_m (* x_m x_m)))
x_m = fabs(x);
y_m = fabs(y);
assert(x_m < y_m);
double code(double x_m, double y_m) {
return fma(y_m, y_m, (x_m * x_m));
}
x_m = abs(x) y_m = abs(y) x_m, y_m = sort([x_m, y_m]) function code(x_m, y_m) return fma(y_m, y_m, Float64(x_m * x_m)) end
x_m = N[Abs[x], $MachinePrecision] y_m = N[Abs[y], $MachinePrecision] NOTE: x_m and y_m should be sorted in increasing order before calling this function. code[x$95$m_, y$95$m_] := N[(y$95$m * y$95$m + N[(x$95$m * x$95$m), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
x_m = \left|x\right|
\\
y_m = \left|y\right|
\\
[x_m, y_m] = \mathsf{sort}([x_m, y_m])\\
\\
\mathsf{fma}\left(y\_m, y\_m, x\_m \cdot x\_m\right)
\end{array}
Initial program 100.0%
+-commutative100.0%
fma-define100.0%
pow2100.0%
Applied egg-rr100.0%
unpow2100.0%
Applied egg-rr100.0%
x_m = (fabs.f64 x) y_m = (fabs.f64 y) NOTE: x_m and y_m should be sorted in increasing order before calling this function. (FPCore (x_m y_m) :precision binary64 (+ (* x_m x_m) (* y_m y_m)))
x_m = fabs(x);
y_m = fabs(y);
assert(x_m < y_m);
double code(double x_m, double y_m) {
return (x_m * x_m) + (y_m * y_m);
}
x_m = abs(x)
y_m = abs(y)
NOTE: x_m and y_m should be sorted in increasing order before calling this function.
real(8) function code(x_m, y_m)
real(8), intent (in) :: x_m
real(8), intent (in) :: y_m
code = (x_m * x_m) + (y_m * y_m)
end function
x_m = Math.abs(x);
y_m = Math.abs(y);
assert x_m < y_m;
public static double code(double x_m, double y_m) {
return (x_m * x_m) + (y_m * y_m);
}
x_m = math.fabs(x) y_m = math.fabs(y) [x_m, y_m] = sort([x_m, y_m]) def code(x_m, y_m): return (x_m * x_m) + (y_m * y_m)
x_m = abs(x) y_m = abs(y) x_m, y_m = sort([x_m, y_m]) function code(x_m, y_m) return Float64(Float64(x_m * x_m) + Float64(y_m * y_m)) end
x_m = abs(x);
y_m = abs(y);
x_m, y_m = num2cell(sort([x_m, y_m])){:}
function tmp = code(x_m, y_m)
tmp = (x_m * x_m) + (y_m * y_m);
end
x_m = N[Abs[x], $MachinePrecision] y_m = N[Abs[y], $MachinePrecision] NOTE: x_m and y_m should be sorted in increasing order before calling this function. code[x$95$m_, y$95$m_] := N[(N[(x$95$m * x$95$m), $MachinePrecision] + N[(y$95$m * y$95$m), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
x_m = \left|x\right|
\\
y_m = \left|y\right|
\\
[x_m, y_m] = \mathsf{sort}([x_m, y_m])\\
\\
x\_m \cdot x\_m + y\_m \cdot y\_m
\end{array}
Initial program 100.0%
herbie shell --seed 2024180
(FPCore (x y)
:name "Graphics.Rasterific.Linear:$cquadrance from Rasterific-0.6.1"
:precision binary64
(+ (* x x) (* y y)))