
(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) NOTE: x_m and y should be sorted in increasing order before calling this function. (FPCore (x_m y) :precision binary64 (fma y y (* x_m x_m)))
x_m = fabs(x);
assert(x_m < y);
double code(double x_m, double y) {
return fma(y, y, (x_m * x_m));
}
x_m = abs(x) x_m, y = sort([x_m, y]) function code(x_m, y) return fma(y, y, Float64(x_m * x_m)) end
x_m = N[Abs[x], $MachinePrecision] NOTE: x_m and y should be sorted in increasing order before calling this function. code[x$95$m_, y_] := N[(y * y + N[(x$95$m * x$95$m), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
x_m = \left|x\right|
\\
[x_m, y] = \mathsf{sort}([x_m, y])\\
\\
\mathsf{fma}\left(y, y, x\_m \cdot x\_m\right)
\end{array}
Initial program 100.0%
lift-*.f64N/A
lift-*.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f64100.0
Applied rewrites100.0%
x_m = (fabs.f64 x) NOTE: x_m and y should be sorted in increasing order before calling this function. (FPCore (x_m y) :precision binary64 (* y y))
x_m = fabs(x);
assert(x_m < y);
double code(double x_m, double y) {
return y * y;
}
x_m = abs(x)
NOTE: x_m and y should be sorted in increasing order before calling this function.
real(8) function code(x_m, y)
real(8), intent (in) :: x_m
real(8), intent (in) :: y
code = y * y
end function
x_m = Math.abs(x);
assert x_m < y;
public static double code(double x_m, double y) {
return y * y;
}
x_m = math.fabs(x) [x_m, y] = sort([x_m, y]) def code(x_m, y): return y * y
x_m = abs(x) x_m, y = sort([x_m, y]) function code(x_m, y) return Float64(y * y) end
x_m = abs(x);
x_m, y = num2cell(sort([x_m, y])){:}
function tmp = code(x_m, y)
tmp = y * y;
end
x_m = N[Abs[x], $MachinePrecision] NOTE: x_m and y should be sorted in increasing order before calling this function. code[x$95$m_, y_] := N[(y * y), $MachinePrecision]
\begin{array}{l}
x_m = \left|x\right|
\\
[x_m, y] = \mathsf{sort}([x_m, y])\\
\\
y \cdot y
\end{array}
Initial program 100.0%
Taylor expanded in x around 0
unpow2N/A
lower-*.f6452.3
Applied rewrites52.3%
herbie shell --seed 2024216
(FPCore (x y)
:name "Graphics.Rasterific.Linear:$cquadrance from Rasterific-0.6.1"
:precision binary64
(+ (* x x) (* y y)))