
(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 x x (* y (* z -4.0))))
double code(double x, double y, double z) {
return fma(x, x, (y * (z * -4.0)));
}
function code(x, y, z) return fma(x, x, Float64(y * Float64(z * -4.0))) end
code[x_, y_, z_] := N[(x * x + N[(y * N[(z * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(x, x, y \cdot \left(z \cdot -4\right)\right)
\end{array}
Initial program 97.3%
fmm-def98.8%
associate-*l*99.2%
*-commutative99.2%
distribute-rgt-neg-in99.2%
distribute-rgt-neg-in99.2%
metadata-eval99.2%
Simplified99.2%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* z (* y 4.0)))) (if (<= t_0 1e+285) (- (* x x) t_0) (* -4.0 (* y z)))))
double code(double x, double y, double z) {
double t_0 = z * (y * 4.0);
double tmp;
if (t_0 <= 1e+285) {
tmp = (x * x) - t_0;
} else {
tmp = -4.0 * (y * z);
}
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) :: t_0
real(8) :: tmp
t_0 = z * (y * 4.0d0)
if (t_0 <= 1d+285) then
tmp = (x * x) - t_0
else
tmp = (-4.0d0) * (y * z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = z * (y * 4.0);
double tmp;
if (t_0 <= 1e+285) {
tmp = (x * x) - t_0;
} else {
tmp = -4.0 * (y * z);
}
return tmp;
}
def code(x, y, z): t_0 = z * (y * 4.0) tmp = 0 if t_0 <= 1e+285: tmp = (x * x) - t_0 else: tmp = -4.0 * (y * z) return tmp
function code(x, y, z) t_0 = Float64(z * Float64(y * 4.0)) tmp = 0.0 if (t_0 <= 1e+285) tmp = Float64(Float64(x * x) - t_0); else tmp = Float64(-4.0 * Float64(y * z)); end return tmp end
function tmp_2 = code(x, y, z) t_0 = z * (y * 4.0); tmp = 0.0; if (t_0 <= 1e+285) tmp = (x * x) - t_0; else tmp = -4.0 * (y * z); end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(z * N[(y * 4.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, 1e+285], N[(N[(x * x), $MachinePrecision] - t$95$0), $MachinePrecision], N[(-4.0 * N[(y * z), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := z \cdot \left(y \cdot 4\right)\\
\mathbf{if}\;t\_0 \leq 10^{+285}:\\
\;\;\;\;x \cdot x - t\_0\\
\mathbf{else}:\\
\;\;\;\;-4 \cdot \left(y \cdot z\right)\\
\end{array}
\end{array}
if (*.f64 (*.f64 y #s(literal 4 binary64)) z) < 9.9999999999999998e284Initial program 100.0%
if 9.9999999999999998e284 < (*.f64 (*.f64 y #s(literal 4 binary64)) z) Initial program 59.0%
Taylor expanded in x around 0 88.2%
Final simplification99.2%
(FPCore (x y z) :precision binary64 (if (<= (* x x) 6.4e-77) (* -4.0 (* y z)) (- (* x x) (* y (* z -4.0)))))
double code(double x, double y, double z) {
double tmp;
if ((x * x) <= 6.4e-77) {
tmp = -4.0 * (y * z);
} else {
tmp = (x * x) - (y * (z * -4.0));
}
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) <= 6.4d-77) then
tmp = (-4.0d0) * (y * z)
else
tmp = (x * x) - (y * (z * (-4.0d0)))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x * x) <= 6.4e-77) {
tmp = -4.0 * (y * z);
} else {
tmp = (x * x) - (y * (z * -4.0));
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x * x) <= 6.4e-77: tmp = -4.0 * (y * z) else: tmp = (x * x) - (y * (z * -4.0)) return tmp
function code(x, y, z) tmp = 0.0 if (Float64(x * x) <= 6.4e-77) tmp = Float64(-4.0 * Float64(y * z)); else tmp = Float64(Float64(x * x) - Float64(y * Float64(z * -4.0))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x * x) <= 6.4e-77) tmp = -4.0 * (y * z); else tmp = (x * x) - (y * (z * -4.0)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[N[(x * x), $MachinePrecision], 6.4e-77], N[(-4.0 * N[(y * z), $MachinePrecision]), $MachinePrecision], N[(N[(x * x), $MachinePrecision] - N[(y * N[(z * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \cdot x \leq 6.4 \cdot 10^{-77}:\\
\;\;\;\;-4 \cdot \left(y \cdot z\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot x - y \cdot \left(z \cdot -4\right)\\
\end{array}
\end{array}
if (*.f64 x x) < 6.39999999999999999e-77Initial program 99.2%
Taylor expanded in x around 0 91.1%
if 6.39999999999999999e-77 < (*.f64 x x) Initial program 95.7%
Taylor expanded in y around 0 95.7%
rem-square-sqrt48.2%
fabs-sqr48.2%
rem-square-sqrt83.9%
fabs-neg83.9%
distribute-lft-neg-in83.9%
metadata-eval83.9%
*-commutative83.9%
*-commutative83.9%
associate-*r*83.9%
rem-square-sqrt47.0%
fabs-sqr47.0%
rem-square-sqrt78.9%
associate-*r*78.9%
*-commutative78.9%
associate-*r*78.9%
Simplified78.9%
(FPCore (x y z) :precision binary64 (* -4.0 (* y z)))
double code(double x, double y, double z) {
return -4.0 * (y * z);
}
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) * (y * z)
end function
public static double code(double x, double y, double z) {
return -4.0 * (y * z);
}
def code(x, y, z): return -4.0 * (y * z)
function code(x, y, z) return Float64(-4.0 * Float64(y * z)) end
function tmp = code(x, y, z) tmp = -4.0 * (y * z); end
code[x_, y_, z_] := N[(-4.0 * N[(y * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
-4 \cdot \left(y \cdot z\right)
\end{array}
Initial program 97.3%
Taylor expanded in x around 0 53.0%
herbie shell --seed 2024170
(FPCore (x y z)
:name "Graphics.Rasterific.QuadraticFormula:discriminant from Rasterific-0.6.1"
:precision binary64
(- (* x x) (* (* y 4.0) z)))