
(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}
NOTE: y and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (fma x x (* y (* z -4.0))))
assert(y < z);
double code(double x, double y, double z) {
return fma(x, x, (y * (z * -4.0)));
}
y, z = sort([y, z]) function code(x, y, z) return fma(x, x, Float64(y * Float64(z * -4.0))) end
NOTE: y and z should be sorted in increasing order before calling this function. code[x_, y_, z_] := N[(x * x + N[(y * N[(z * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[y, z] = \mathsf{sort}([y, z])\\
\\
\mathsf{fma}\left(x, x, y \cdot \left(z \cdot -4\right)\right)
\end{array}
Initial program 99.2%
fma-neg99.6%
associate-*l*99.2%
*-commutative99.2%
distribute-rgt-neg-in99.2%
distribute-rgt-neg-in99.2%
metadata-eval99.2%
Simplified99.2%
Final simplification99.2%
NOTE: y and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (<= (* x x) 8.2e-44) (* -4.0 (* y z)) (* x x)))
assert(y < z);
double code(double x, double y, double z) {
double tmp;
if ((x * x) <= 8.2e-44) {
tmp = -4.0 * (y * z);
} else {
tmp = x * x;
}
return tmp;
}
NOTE: y and z should be sorted in increasing order before calling this function.
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) <= 8.2d-44) then
tmp = (-4.0d0) * (y * z)
else
tmp = x * x
end if
code = tmp
end function
assert y < z;
public static double code(double x, double y, double z) {
double tmp;
if ((x * x) <= 8.2e-44) {
tmp = -4.0 * (y * z);
} else {
tmp = x * x;
}
return tmp;
}
[y, z] = sort([y, z]) def code(x, y, z): tmp = 0 if (x * x) <= 8.2e-44: tmp = -4.0 * (y * z) else: tmp = x * x return tmp
y, z = sort([y, z]) function code(x, y, z) tmp = 0.0 if (Float64(x * x) <= 8.2e-44) tmp = Float64(-4.0 * Float64(y * z)); else tmp = Float64(x * x); end return tmp end
y, z = num2cell(sort([y, z])){:}
function tmp_2 = code(x, y, z)
tmp = 0.0;
if ((x * x) <= 8.2e-44)
tmp = -4.0 * (y * z);
else
tmp = x * x;
end
tmp_2 = tmp;
end
NOTE: y and z should be sorted in increasing order before calling this function. code[x_, y_, z_] := If[LessEqual[N[(x * x), $MachinePrecision], 8.2e-44], N[(-4.0 * N[(y * z), $MachinePrecision]), $MachinePrecision], N[(x * x), $MachinePrecision]]
\begin{array}{l}
[y, z] = \mathsf{sort}([y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;x \cdot x \leq 8.2 \cdot 10^{-44}:\\
\;\;\;\;-4 \cdot \left(y \cdot z\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot x\\
\end{array}
\end{array}
if (*.f64 x x) < 8.19999999999999984e-44Initial program 100.0%
associate-*l*99.2%
Simplified99.2%
Taylor expanded in x around 0 84.0%
if 8.19999999999999984e-44 < (*.f64 x x) Initial program 98.5%
associate-*l*98.5%
Simplified98.5%
Taylor expanded in x around inf 86.1%
unpow286.1%
Simplified86.1%
Final simplification85.1%
NOTE: y and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (- (* x x) (* y (* z 4.0))))
assert(y < z);
double code(double x, double y, double z) {
return (x * x) - (y * (z * 4.0));
}
NOTE: y and z should be sorted in increasing order before calling this function.
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 * (z * 4.0d0))
end function
assert y < z;
public static double code(double x, double y, double z) {
return (x * x) - (y * (z * 4.0));
}
[y, z] = sort([y, z]) def code(x, y, z): return (x * x) - (y * (z * 4.0))
y, z = sort([y, z]) function code(x, y, z) return Float64(Float64(x * x) - Float64(y * Float64(z * 4.0))) end
y, z = num2cell(sort([y, z])){:}
function tmp = code(x, y, z)
tmp = (x * x) - (y * (z * 4.0));
end
NOTE: y and z should be sorted in increasing order before calling this function. code[x_, y_, z_] := N[(N[(x * x), $MachinePrecision] - N[(y * N[(z * 4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[y, z] = \mathsf{sort}([y, z])\\
\\
x \cdot x - y \cdot \left(z \cdot 4\right)
\end{array}
Initial program 99.2%
associate-*l*98.8%
Simplified98.8%
Final simplification98.8%
NOTE: y and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (* x x))
assert(y < z);
double code(double x, double y, double z) {
return x * x;
}
NOTE: y and z should be sorted in increasing order before calling this function.
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
assert y < z;
public static double code(double x, double y, double z) {
return x * x;
}
[y, z] = sort([y, z]) def code(x, y, z): return x * x
y, z = sort([y, z]) function code(x, y, z) return Float64(x * x) end
y, z = num2cell(sort([y, z])){:}
function tmp = code(x, y, z)
tmp = x * x;
end
NOTE: y and z should be sorted in increasing order before calling this function. code[x_, y_, z_] := N[(x * x), $MachinePrecision]
\begin{array}{l}
[y, z] = \mathsf{sort}([y, z])\\
\\
x \cdot x
\end{array}
Initial program 99.2%
associate-*l*98.8%
Simplified98.8%
Taylor expanded in x around inf 55.4%
unpow255.4%
Simplified55.4%
Final simplification55.4%
herbie shell --seed 2023275
(FPCore (x y z)
:name "Graphics.Rasterific.QuadraticFormula:discriminant from Rasterific-0.6.1"
:precision binary64
(- (* x x) (* (* y 4.0) z)))