
(FPCore (x y) :precision binary64 (- x (* y y)))
double code(double x, double y) {
return x - (y * y);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = x - (y * y)
end function
public static double code(double x, double y) {
return x - (y * y);
}
def code(x, y): return x - (y * y)
function code(x, y) return Float64(x - Float64(y * y)) end
function tmp = code(x, y) tmp = x - (y * y); end
code[x_, y_] := N[(x - N[(y * y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x - y \cdot y
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 4 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y) :precision binary64 (- x (* y y)))
double code(double x, double y) {
return x - (y * y);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = x - (y * y)
end function
public static double code(double x, double y) {
return x - (y * y);
}
def code(x, y): return x - (y * y)
function code(x, y) return Float64(x - Float64(y * y)) end
function tmp = code(x, y) tmp = x - (y * y); end
code[x_, y_] := N[(x - N[(y * y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x - y \cdot y
\end{array}
(FPCore (x y) :precision binary64 (fma (- y) y x))
double code(double x, double y) {
return fma(-y, y, x);
}
function code(x, y) return fma(Float64(-y), y, x) end
code[x_, y_] := N[((-y) * y + x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(-y, y, x\right)
\end{array}
Initial program 100.0%
Taylor expanded in x around 0
*-lft-identityN/A
fp-cancel-sub-sign-invN/A
metadata-evalN/A
+-commutativeN/A
mul-1-negN/A
unpow2N/A
distribute-lft-neg-inN/A
lower-fma.f64N/A
lower-neg.f64100.0
Applied rewrites100.0%
(FPCore (x y) :precision binary64 (if (<= (* y y) 1e-29) (fma y y x) (* (- y) y)))
double code(double x, double y) {
double tmp;
if ((y * y) <= 1e-29) {
tmp = fma(y, y, x);
} else {
tmp = -y * y;
}
return tmp;
}
function code(x, y) tmp = 0.0 if (Float64(y * y) <= 1e-29) tmp = fma(y, y, x); else tmp = Float64(Float64(-y) * y); end return tmp end
code[x_, y_] := If[LessEqual[N[(y * y), $MachinePrecision], 1e-29], N[(y * y + x), $MachinePrecision], N[((-y) * y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \cdot y \leq 10^{-29}:\\
\;\;\;\;\mathsf{fma}\left(y, y, x\right)\\
\mathbf{else}:\\
\;\;\;\;\left(-y\right) \cdot y\\
\end{array}
\end{array}
if (*.f64 y y) < 9.99999999999999943e-30Initial program 100.0%
lift--.f64N/A
lift-*.f64N/A
sqr-abs-revN/A
sqr-neg-revN/A
fp-cancel-sub-sign-invN/A
distribute-lft-neg-inN/A
sqr-neg-revN/A
sqr-abs-revN/A
distribute-lft-neg-outN/A
unpow1N/A
metadata-evalN/A
sqrt-pow1N/A
pow2N/A
sqr-neg-revN/A
pow2N/A
sqrt-pow1N/A
metadata-evalN/A
unpow1N/A
lift-*.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f6492.8
Applied rewrites92.8%
if 9.99999999999999943e-30 < (*.f64 y y) Initial program 100.0%
Taylor expanded in x around 0
mul-1-negN/A
unpow2N/A
distribute-lft-neg-inN/A
lower-*.f64N/A
lower-neg.f6487.7
Applied rewrites87.7%
(FPCore (x y) :precision binary64 (fma y y x))
double code(double x, double y) {
return fma(y, y, x);
}
function code(x, y) return fma(y, y, x) end
code[x_, y_] := N[(y * y + x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(y, y, x\right)
\end{array}
Initial program 100.0%
lift--.f64N/A
lift-*.f64N/A
sqr-abs-revN/A
sqr-neg-revN/A
fp-cancel-sub-sign-invN/A
distribute-lft-neg-inN/A
sqr-neg-revN/A
sqr-abs-revN/A
distribute-lft-neg-outN/A
unpow1N/A
metadata-evalN/A
sqrt-pow1N/A
pow2N/A
sqr-neg-revN/A
pow2N/A
sqrt-pow1N/A
metadata-evalN/A
unpow1N/A
lift-*.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f6452.9
Applied rewrites52.9%
(FPCore (x y) :precision binary64 (* y y))
double code(double x, double y) {
return y * y;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = y * y
end function
public static double code(double x, double y) {
return y * y;
}
def code(x, y): return y * y
function code(x, y) return Float64(y * y) end
function tmp = code(x, y) tmp = y * y; end
code[x_, y_] := N[(y * y), $MachinePrecision]
\begin{array}{l}
\\
y \cdot y
\end{array}
Initial program 100.0%
Taylor expanded in x around 0
mul-1-negN/A
unpow2N/A
distribute-lft-neg-inN/A
lower-*.f64N/A
lower-neg.f6448.0
Applied rewrites48.0%
Applied rewrites2.1%
herbie shell --seed 2024327
(FPCore (x y)
:name "Graphics.Rasterific.Shading:$sradialGradientWithFocusShader from Rasterific-0.6.1"
:precision binary64
(- x (* y y)))