
(FPCore (x y z) :precision binary64 (- (* x x) (* (* y 4.0) z)))
double code(double x, double y, double z) {
return (x * x) - ((y * 4.0) * z);
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (x * x) - ((y * 4.0d0) * z)
end function
public static double code(double x, double y, double z) {
return (x * x) - ((y * 4.0) * z);
}
def code(x, y, z): return (x * x) - ((y * 4.0) * z)
function code(x, y, z) return Float64(Float64(x * x) - Float64(Float64(y * 4.0) * z)) end
function tmp = code(x, y, z) tmp = (x * x) - ((y * 4.0) * z); end
code[x_, y_, z_] := N[(N[(x * x), $MachinePrecision] - N[(N[(y * 4.0), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot x - \left(y \cdot 4\right) \cdot z
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 4 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (- (* x x) (* (* y 4.0) z)))
double code(double x, double y, double z) {
return (x * x) - ((y * 4.0) * z);
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (x * x) - ((y * 4.0d0) * z)
end function
public static double code(double x, double y, double z) {
return (x * x) - ((y * 4.0) * z);
}
def code(x, y, z): return (x * x) - ((y * 4.0) * z)
function code(x, y, z) return Float64(Float64(x * x) - Float64(Float64(y * 4.0) * z)) end
function tmp = code(x, y, z) tmp = (x * x) - ((y * 4.0) * z); end
code[x_, y_, z_] := N[(N[(x * x), $MachinePrecision] - N[(N[(y * 4.0), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot x - \left(y \cdot 4\right) \cdot z
\end{array}
(FPCore (x y z) :precision binary64 (fma (* z -4.0) y (* x x)))
double code(double x, double y, double z) {
return fma((z * -4.0), y, (x * x));
}
function code(x, y, z) return fma(Float64(z * -4.0), y, Float64(x * x)) end
code[x_, y_, z_] := N[(N[(z * -4.0), $MachinePrecision] * y + N[(x * x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(z \cdot -4, y, x \cdot x\right)
\end{array}
Initial program 99.2%
lift--.f64N/A
sub-negN/A
+-commutativeN/A
lift-*.f64N/A
lift-*.f64N/A
associate-*l*N/A
*-commutativeN/A
distribute-lft-neg-inN/A
lower-fma.f64N/A
*-commutativeN/A
distribute-rgt-neg-inN/A
lower-*.f64N/A
metadata-eval100.0
Applied rewrites100.0%
(FPCore (x y z) :precision binary64 (if (<= (* x x) 2.2e+79) (* (* z -4.0) y) (* x x)))
double code(double x, double y, double z) {
double tmp;
if ((x * x) <= 2.2e+79) {
tmp = (z * -4.0) * y;
} else {
tmp = x * x;
}
return tmp;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: tmp
if ((x * x) <= 2.2d+79) then
tmp = (z * (-4.0d0)) * y
else
tmp = x * x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x * x) <= 2.2e+79) {
tmp = (z * -4.0) * y;
} else {
tmp = x * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x * x) <= 2.2e+79: tmp = (z * -4.0) * y else: tmp = x * x return tmp
function code(x, y, z) tmp = 0.0 if (Float64(x * x) <= 2.2e+79) tmp = Float64(Float64(z * -4.0) * y); else tmp = Float64(x * x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x * x) <= 2.2e+79) tmp = (z * -4.0) * y; else tmp = x * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[N[(x * x), $MachinePrecision], 2.2e+79], N[(N[(z * -4.0), $MachinePrecision] * y), $MachinePrecision], N[(x * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \cdot x \leq 2.2 \cdot 10^{+79}:\\
\;\;\;\;\left(z \cdot -4\right) \cdot y\\
\mathbf{else}:\\
\;\;\;\;x \cdot x\\
\end{array}
\end{array}
if (*.f64 x x) < 2.1999999999999999e79Initial program 100.0%
Taylor expanded in x around 0
lower-*.f64N/A
lower-*.f6480.2
Applied rewrites80.2%
Applied rewrites80.2%
if 2.1999999999999999e79 < (*.f64 x x) Initial program 97.8%
Taylor expanded in x around inf
unpow2N/A
lower-*.f6493.3
Applied rewrites93.3%
(FPCore (x y z) :precision binary64 (if (<= (* x x) 2.2e+79) (* -4.0 (* z y)) (* x x)))
double code(double x, double y, double z) {
double tmp;
if ((x * x) <= 2.2e+79) {
tmp = -4.0 * (z * y);
} else {
tmp = x * x;
}
return tmp;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: tmp
if ((x * x) <= 2.2d+79) then
tmp = (-4.0d0) * (z * y)
else
tmp = x * x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x * x) <= 2.2e+79) {
tmp = -4.0 * (z * y);
} else {
tmp = x * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x * x) <= 2.2e+79: tmp = -4.0 * (z * y) else: tmp = x * x return tmp
function code(x, y, z) tmp = 0.0 if (Float64(x * x) <= 2.2e+79) tmp = Float64(-4.0 * Float64(z * y)); else tmp = Float64(x * x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x * x) <= 2.2e+79) tmp = -4.0 * (z * y); else tmp = x * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[N[(x * x), $MachinePrecision], 2.2e+79], N[(-4.0 * N[(z * y), $MachinePrecision]), $MachinePrecision], N[(x * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \cdot x \leq 2.2 \cdot 10^{+79}:\\
\;\;\;\;-4 \cdot \left(z \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot x\\
\end{array}
\end{array}
if (*.f64 x x) < 2.1999999999999999e79Initial program 100.0%
Taylor expanded in x around 0
lower-*.f64N/A
lower-*.f6480.2
Applied rewrites80.2%
if 2.1999999999999999e79 < (*.f64 x x) Initial program 97.8%
Taylor expanded in x around inf
unpow2N/A
lower-*.f6493.3
Applied rewrites93.3%
Final simplification85.0%
(FPCore (x y z) :precision binary64 (* x x))
double code(double x, double y, double z) {
return x * x;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = x * x
end function
public static double code(double x, double y, double z) {
return x * x;
}
def code(x, y, z): return x * x
function code(x, y, z) return Float64(x * x) end
function tmp = code(x, y, z) tmp = x * x; end
code[x_, y_, z_] := N[(x * x), $MachinePrecision]
\begin{array}{l}
\\
x \cdot x
\end{array}
Initial program 99.2%
Taylor expanded in x around inf
unpow2N/A
lower-*.f6451.2
Applied rewrites51.2%
herbie shell --seed 2024232
(FPCore (x y z)
:name "Graphics.Rasterific.QuadraticFormula:discriminant from Rasterific-0.6.1"
:precision binary64
(- (* x x) (* (* y 4.0) z)))