
(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 6 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 (let* ((t_0 (- (* x x) (* z (* y 4.0))))) (if (<= t_0 INFINITY) t_0 (- (* x x) (* y (* z -4.0))))))
double code(double x, double y, double z) {
double t_0 = (x * x) - (z * (y * 4.0));
double tmp;
if (t_0 <= ((double) INFINITY)) {
tmp = t_0;
} else {
tmp = (x * x) - (y * (z * -4.0));
}
return tmp;
}
public static double code(double x, double y, double z) {
double t_0 = (x * x) - (z * (y * 4.0));
double tmp;
if (t_0 <= Double.POSITIVE_INFINITY) {
tmp = t_0;
} else {
tmp = (x * x) - (y * (z * -4.0));
}
return tmp;
}
def code(x, y, z): t_0 = (x * x) - (z * (y * 4.0)) tmp = 0 if t_0 <= math.inf: tmp = t_0 else: tmp = (x * x) - (y * (z * -4.0)) return tmp
function code(x, y, z) t_0 = Float64(Float64(x * x) - Float64(z * Float64(y * 4.0))) tmp = 0.0 if (t_0 <= Inf) tmp = t_0; else tmp = Float64(Float64(x * x) - Float64(y * Float64(z * -4.0))); end return tmp end
function tmp_2 = code(x, y, z) t_0 = (x * x) - (z * (y * 4.0)); tmp = 0.0; if (t_0 <= Inf) tmp = t_0; else tmp = (x * x) - (y * (z * -4.0)); end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(x * x), $MachinePrecision] - N[(z * N[(y * 4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, Infinity], t$95$0, N[(N[(x * x), $MachinePrecision] - N[(y * N[(z * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot x - z \cdot \left(y \cdot 4\right)\\
\mathbf{if}\;t\_0 \leq \infty:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;x \cdot x - y \cdot \left(z \cdot -4\right)\\
\end{array}
\end{array}
if (-.f64 (*.f64 x x) (*.f64 (*.f64 y #s(literal 4 binary64)) z)) < +inf.0Initial program 100.0%
if +inf.0 < (-.f64 (*.f64 x x) (*.f64 (*.f64 y #s(literal 4 binary64)) z)) Initial program 0.0%
Taylor expanded in y around 0 0.0%
rem-square-sqrt0.0%
fabs-sqr0.0%
rem-square-sqrt0.0%
fabs-neg0.0%
distribute-lft-neg-in0.0%
metadata-eval0.0%
*-commutative0.0%
*-commutative0.0%
associate-*r*0.0%
rem-square-sqrt0.0%
fabs-sqr0.0%
rem-square-sqrt80.0%
*-commutative80.0%
associate-*r*80.0%
*-commutative80.0%
Simplified80.0%
Final simplification99.6%
(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 98.0%
fma-neg98.4%
associate-*l*98.4%
*-commutative98.4%
distribute-rgt-neg-in98.4%
distribute-rgt-neg-in98.4%
metadata-eval98.4%
Simplified98.4%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* y (* z -4.0)))) (if (<= (* x x) 6e-26) t_0 (- (* x x) t_0))))
double code(double x, double y, double z) {
double t_0 = y * (z * -4.0);
double tmp;
if ((x * x) <= 6e-26) {
tmp = t_0;
} else {
tmp = (x * x) - t_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) :: t_0
real(8) :: tmp
t_0 = y * (z * (-4.0d0))
if ((x * x) <= 6d-26) then
tmp = t_0
else
tmp = (x * x) - t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = y * (z * -4.0);
double tmp;
if ((x * x) <= 6e-26) {
tmp = t_0;
} else {
tmp = (x * x) - t_0;
}
return tmp;
}
def code(x, y, z): t_0 = y * (z * -4.0) tmp = 0 if (x * x) <= 6e-26: tmp = t_0 else: tmp = (x * x) - t_0 return tmp
function code(x, y, z) t_0 = Float64(y * Float64(z * -4.0)) tmp = 0.0 if (Float64(x * x) <= 6e-26) tmp = t_0; else tmp = Float64(Float64(x * x) - t_0); end return tmp end
function tmp_2 = code(x, y, z) t_0 = y * (z * -4.0); tmp = 0.0; if ((x * x) <= 6e-26) tmp = t_0; else tmp = (x * x) - t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(y * N[(z * -4.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(x * x), $MachinePrecision], 6e-26], t$95$0, N[(N[(x * x), $MachinePrecision] - t$95$0), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := y \cdot \left(z \cdot -4\right)\\
\mathbf{if}\;x \cdot x \leq 6 \cdot 10^{-26}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;x \cdot x - t\_0\\
\end{array}
\end{array}
if (*.f64 x x) < 6.00000000000000023e-26Initial program 100.0%
Taylor expanded in y around 0 100.0%
rem-square-sqrt52.6%
fabs-sqr52.6%
rem-square-sqrt60.7%
fabs-neg60.7%
distribute-lft-neg-in60.7%
metadata-eval60.7%
*-commutative60.7%
*-commutative60.7%
associate-*r*60.7%
rem-square-sqrt15.4%
fabs-sqr15.4%
rem-square-sqrt16.9%
*-commutative16.9%
associate-*r*16.9%
*-commutative16.9%
Simplified16.9%
Taylor expanded in x around 0 6.7%
metadata-eval6.7%
rem-square-sqrt5.4%
fabs-sqr5.4%
rem-square-sqrt45.4%
fabs-mul45.4%
associate-*r*45.4%
*-commutative45.4%
rem-square-sqrt44.4%
fabs-sqr44.4%
rem-square-sqrt89.1%
associate-*r*89.1%
*-commutative89.1%
*-commutative89.1%
*-commutative89.1%
Simplified89.1%
if 6.00000000000000023e-26 < (*.f64 x x) Initial program 96.6%
Taylor expanded in y around 0 96.6%
rem-square-sqrt51.3%
fabs-sqr51.3%
rem-square-sqrt89.6%
fabs-neg89.6%
distribute-lft-neg-in89.6%
metadata-eval89.6%
*-commutative89.6%
*-commutative89.6%
associate-*r*89.6%
rem-square-sqrt47.0%
fabs-sqr47.0%
rem-square-sqrt86.9%
*-commutative86.9%
associate-*r*86.9%
*-commutative86.9%
Simplified86.9%
(FPCore (x y z) :precision binary64 (if (<= x 2.8e+279) (* y (* z -4.0)) (* 4.0 (* y z))))
double code(double x, double y, double z) {
double tmp;
if (x <= 2.8e+279) {
tmp = y * (z * -4.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) :: tmp
if (x <= 2.8d+279) then
tmp = y * (z * (-4.0d0))
else
tmp = 4.0d0 * (y * z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= 2.8e+279) {
tmp = y * (z * -4.0);
} else {
tmp = 4.0 * (y * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= 2.8e+279: tmp = y * (z * -4.0) else: tmp = 4.0 * (y * z) return tmp
function code(x, y, z) tmp = 0.0 if (x <= 2.8e+279) tmp = Float64(y * Float64(z * -4.0)); else tmp = Float64(4.0 * Float64(y * z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= 2.8e+279) tmp = y * (z * -4.0); else tmp = 4.0 * (y * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, 2.8e+279], N[(y * N[(z * -4.0), $MachinePrecision]), $MachinePrecision], N[(4.0 * N[(y * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 2.8 \cdot 10^{+279}:\\
\;\;\;\;y \cdot \left(z \cdot -4\right)\\
\mathbf{else}:\\
\;\;\;\;4 \cdot \left(y \cdot z\right)\\
\end{array}
\end{array}
if x < 2.8000000000000002e279Initial program 98.4%
Taylor expanded in y around 0 98.4%
rem-square-sqrt50.9%
fabs-sqr50.9%
rem-square-sqrt77.0%
fabs-neg77.0%
distribute-lft-neg-in77.0%
metadata-eval77.0%
*-commutative77.0%
*-commutative77.0%
associate-*r*77.0%
rem-square-sqrt34.1%
fabs-sqr34.1%
rem-square-sqrt55.8%
*-commutative55.8%
associate-*r*55.8%
*-commutative55.8%
Simplified55.8%
Taylor expanded in x around 0 5.3%
metadata-eval5.3%
rem-square-sqrt4.5%
fabs-sqr4.5%
rem-square-sqrt26.5%
fabs-mul26.5%
associate-*r*26.6%
*-commutative26.6%
rem-square-sqrt24.1%
fabs-sqr24.1%
rem-square-sqrt47.5%
associate-*r*47.5%
*-commutative47.5%
*-commutative47.5%
*-commutative47.5%
Simplified47.5%
if 2.8000000000000002e279 < x Initial program 88.9%
Taylor expanded in y around 0 88.9%
rem-square-sqrt77.8%
fabs-sqr77.8%
rem-square-sqrt88.9%
fabs-neg88.9%
distribute-lft-neg-in88.9%
metadata-eval88.9%
*-commutative88.9%
*-commutative88.9%
associate-*r*88.9%
rem-square-sqrt22.2%
fabs-sqr22.2%
rem-square-sqrt100.0%
*-commutative100.0%
associate-*r*100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around 0 13.7%
(FPCore (x y z) :precision binary64 (if (<= x 1.15e+278) (* -4.0 (* y z)) (* 4.0 (* y z))))
double code(double x, double y, double z) {
double tmp;
if (x <= 1.15e+278) {
tmp = -4.0 * (y * z);
} 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) :: tmp
if (x <= 1.15d+278) then
tmp = (-4.0d0) * (y * z)
else
tmp = 4.0d0 * (y * z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= 1.15e+278) {
tmp = -4.0 * (y * z);
} else {
tmp = 4.0 * (y * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= 1.15e+278: tmp = -4.0 * (y * z) else: tmp = 4.0 * (y * z) return tmp
function code(x, y, z) tmp = 0.0 if (x <= 1.15e+278) tmp = Float64(-4.0 * Float64(y * z)); else tmp = Float64(4.0 * Float64(y * z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= 1.15e+278) tmp = -4.0 * (y * z); else tmp = 4.0 * (y * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, 1.15e+278], N[(-4.0 * N[(y * z), $MachinePrecision]), $MachinePrecision], N[(4.0 * N[(y * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1.15 \cdot 10^{+278}:\\
\;\;\;\;-4 \cdot \left(y \cdot z\right)\\
\mathbf{else}:\\
\;\;\;\;4 \cdot \left(y \cdot z\right)\\
\end{array}
\end{array}
if x < 1.1499999999999999e278Initial program 98.4%
Taylor expanded in x around 0 47.5%
if 1.1499999999999999e278 < x Initial program 88.9%
Taylor expanded in y around 0 88.9%
rem-square-sqrt77.8%
fabs-sqr77.8%
rem-square-sqrt88.9%
fabs-neg88.9%
distribute-lft-neg-in88.9%
metadata-eval88.9%
*-commutative88.9%
*-commutative88.9%
associate-*r*88.9%
rem-square-sqrt22.2%
fabs-sqr22.2%
rem-square-sqrt100.0%
*-commutative100.0%
associate-*r*100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around 0 13.7%
(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 98.0%
Taylor expanded in x around 0 45.8%
herbie shell --seed 2024144
(FPCore (x y z)
:name "Graphics.Rasterific.QuadraticFormula:discriminant from Rasterific-0.6.1"
:precision binary64
(- (* x x) (* (* y 4.0) z)))