
(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+54) (fma y y x) (* (- y) y)))
double code(double x, double y) {
double tmp;
if ((y * y) <= 1e+54) {
tmp = fma(y, y, x);
} else {
tmp = -y * y;
}
return tmp;
}
function code(x, y) tmp = 0.0 if (Float64(y * y) <= 1e+54) 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+54], N[(y * y + x), $MachinePrecision], N[((-y) * y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \cdot y \leq 10^{+54}:\\
\;\;\;\;\mathsf{fma}\left(y, y, x\right)\\
\mathbf{else}:\\
\;\;\;\;\left(-y\right) \cdot y\\
\end{array}
\end{array}
if (*.f64 y y) < 1.0000000000000001e54Initial 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%
lift-neg.f64N/A
neg-sub0N/A
flip3--N/A
metadata-evalN/A
sub0-negN/A
cube-negN/A
lift-neg.f64N/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
metadata-evalN/A
+-lft-identityN/A
distribute-rgt-outN/A
+-commutativeN/A
+-lft-identityN/A
pow2N/A
pow-divN/A
metadata-evalN/A
unpow189.7
Applied rewrites89.7%
if 1.0000000000000001e54 < (*.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.f6494.5
Applied rewrites94.5%
(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%
lift-neg.f64N/A
neg-sub0N/A
flip3--N/A
metadata-evalN/A
sub0-negN/A
cube-negN/A
lift-neg.f64N/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
metadata-evalN/A
+-lft-identityN/A
distribute-rgt-outN/A
+-commutativeN/A
+-lft-identityN/A
pow2N/A
pow-divN/A
metadata-evalN/A
unpow152.2
Applied rewrites52.2%
(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.f6449.4
Applied rewrites49.4%
Applied rewrites2.0%
herbie shell --seed 2024298
(FPCore (x y)
:name "Graphics.Rasterific.Shading:$sradialGradientWithFocusShader from Rasterific-0.6.1"
:precision binary64
(- x (* y y)))