
(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 5 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 (pow x 2.0)))
double code(double x, double y, double z) {
return fma((z * -4.0), y, pow(x, 2.0));
}
function code(x, y, z) return fma(Float64(z * -4.0), y, (x ^ 2.0)) end
code[x_, y_, z_] := N[(N[(z * -4.0), $MachinePrecision] * y + N[Power[x, 2.0], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(z \cdot -4, y, {x}^{2}\right)
\end{array}
Initial program 99.6%
sub-neg99.6%
+-commutative99.6%
distribute-lft-neg-in99.6%
distribute-rgt-neg-in99.6%
metadata-eval99.6%
associate-*r*99.6%
*-commutative99.6%
*-commutative99.6%
fma-def100.0%
pow2100.0%
Applied egg-rr100.0%
Final simplification100.0%
(FPCore (x y z) :precision binary64 (fma x x (* (* z -4.0) y)))
double code(double x, double y, double z) {
return fma(x, x, ((z * -4.0) * y));
}
function code(x, y, z) return fma(x, x, Float64(Float64(z * -4.0) * y)) end
code[x_, y_, z_] := N[(x * x + N[(N[(z * -4.0), $MachinePrecision] * y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(x, x, \left(z \cdot -4\right) \cdot y\right)
\end{array}
Initial program 99.6%
fma-neg99.6%
associate-*l*99.6%
*-commutative99.6%
distribute-rgt-neg-in99.6%
distribute-rgt-neg-in99.6%
metadata-eval99.6%
Simplified99.6%
Final simplification99.6%
(FPCore (x y z) :precision binary64 (- (* x x) (* z (* y 4.0))))
double code(double x, double y, double z) {
return (x * x) - (z * (y * 4.0));
}
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) - (z * (y * 4.0d0))
end function
public static double code(double x, double y, double z) {
return (x * x) - (z * (y * 4.0));
}
def code(x, y, z): return (x * x) - (z * (y * 4.0))
function code(x, y, z) return Float64(Float64(x * x) - Float64(z * Float64(y * 4.0))) end
function tmp = code(x, y, z) tmp = (x * x) - (z * (y * 4.0)); end
code[x_, y_, z_] := N[(N[(x * x), $MachinePrecision] - N[(z * N[(y * 4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot x - z \cdot \left(y \cdot 4\right)
\end{array}
Initial program 99.6%
Final simplification99.6%
(FPCore (x y z) :precision binary64 (* -4.0 (* z y)))
double code(double x, double y, double z) {
return -4.0 * (z * y);
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (-4.0d0) * (z * y)
end function
public static double code(double x, double y, double z) {
return -4.0 * (z * y);
}
def code(x, y, z): return -4.0 * (z * y)
function code(x, y, z) return Float64(-4.0 * Float64(z * y)) end
function tmp = code(x, y, z) tmp = -4.0 * (z * y); end
code[x_, y_, z_] := N[(-4.0 * N[(z * y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
-4 \cdot \left(z \cdot y\right)
\end{array}
Initial program 99.6%
Taylor expanded in x around 0 51.1%
Final simplification51.1%
(FPCore (x y z) :precision binary64 (* (* z -4.0) y))
double code(double x, double y, double z) {
return (z * -4.0) * y;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (z * (-4.0d0)) * y
end function
public static double code(double x, double y, double z) {
return (z * -4.0) * y;
}
def code(x, y, z): return (z * -4.0) * y
function code(x, y, z) return Float64(Float64(z * -4.0) * y) end
function tmp = code(x, y, z) tmp = (z * -4.0) * y; end
code[x_, y_, z_] := N[(N[(z * -4.0), $MachinePrecision] * y), $MachinePrecision]
\begin{array}{l}
\\
\left(z \cdot -4\right) \cdot y
\end{array}
Initial program 99.6%
Taylor expanded in x around 0 51.1%
add-log-exp26.5%
*-un-lft-identity26.5%
log-prod26.5%
metadata-eval26.5%
add-log-exp51.1%
*-commutative51.1%
associate-*l*51.1%
Applied egg-rr51.1%
+-lft-identity51.1%
Simplified51.1%
Final simplification51.1%
herbie shell --seed 2024031
(FPCore (x y z)
:name "Graphics.Rasterific.QuadraticFormula:discriminant from Rasterific-0.6.1"
:precision binary64
(- (* x x) (* (* y 4.0) z)))