
(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 5 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%
lift-*.f64N/A
sub-negN/A
+-commutativeN/A
lift-*.f64N/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-118) (fma y y x) (- (* y y))))
double code(double x, double y) {
double tmp;
if ((y * y) <= 1e-118) {
tmp = fma(y, y, x);
} else {
tmp = -(y * y);
}
return tmp;
}
function code(x, y) tmp = 0.0 if (Float64(y * y) <= 1e-118) 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-118], N[(y * y + x), $MachinePrecision], (-N[(y * y), $MachinePrecision])]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \cdot y \leq 10^{-118}:\\
\;\;\;\;\mathsf{fma}\left(y, y, x\right)\\
\mathbf{else}:\\
\;\;\;\;-y \cdot y\\
\end{array}
\end{array}
if (*.f64 y y) < 9.99999999999999985e-119Initial program 100.0%
lift-*.f64N/A
sub-negN/A
+-commutativeN/A
lift-*.f64N/A
distribute-lft-neg-inN/A
lower-fma.f64N/A
lower-neg.f64100.0
Applied rewrites100.0%
Applied rewrites91.5%
if 9.99999999999999985e-119 < (*.f64 y y) Initial program 100.0%
Taylor expanded in x around 0
mul-1-negN/A
lower-neg.f64N/A
unpow2N/A
lower-*.f6481.7
Applied rewrites81.7%
(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}
Initial program 100.0%
(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
sub-negN/A
+-commutativeN/A
lift-*.f64N/A
distribute-lft-neg-inN/A
lower-fma.f64N/A
lower-neg.f64100.0
Applied rewrites100.0%
Applied rewrites50.0%
(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
lower-neg.f64N/A
unpow2N/A
lower-*.f6450.6
Applied rewrites50.6%
distribute-rgt-neg-inN/A
neg-sub0N/A
flip--N/A
metadata-evalN/A
cancel-sign-sub-invN/A
lift-neg.f64N/A
+-lft-identityN/A
+-lft-identityN/A
associate-*r/N/A
*-commutativeN/A
associate-*l*N/A
sqr-negN/A
lift-neg.f64N/A
lift-neg.f64N/A
cube-multN/A
sqr-powN/A
unpow-prod-downN/A
lift-neg.f64N/A
lift-neg.f64N/A
sqr-negN/A
unpow-prod-downN/A
sqr-powN/A
unpow1N/A
pow-divN/A
metadata-evalN/A
Applied rewrites2.1%
herbie shell --seed 2024219
(FPCore (x y)
:name "Graphics.Rasterific.Shading:$sradialGradientWithFocusShader from Rasterific-0.6.1"
:precision binary64
(- x (* y y)))