
(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}
x_m = (fabs.f64 x) (FPCore (x_m y z) :precision binary64 (if (<= x_m 5e+218) (fma x_m x_m (* (* z -4.0) y)) (pow x_m 2.0)))
x_m = fabs(x);
double code(double x_m, double y, double z) {
double tmp;
if (x_m <= 5e+218) {
tmp = fma(x_m, x_m, ((z * -4.0) * y));
} else {
tmp = pow(x_m, 2.0);
}
return tmp;
}
x_m = abs(x) function code(x_m, y, z) tmp = 0.0 if (x_m <= 5e+218) tmp = fma(x_m, x_m, Float64(Float64(z * -4.0) * y)); else tmp = x_m ^ 2.0; end return tmp end
x_m = N[Abs[x], $MachinePrecision] code[x$95$m_, y_, z_] := If[LessEqual[x$95$m, 5e+218], N[(x$95$m * x$95$m + N[(N[(z * -4.0), $MachinePrecision] * y), $MachinePrecision]), $MachinePrecision], N[Power[x$95$m, 2.0], $MachinePrecision]]
\begin{array}{l}
x_m = \left|x\right|
\\
\begin{array}{l}
\mathbf{if}\;x\_m \leq 5 \cdot 10^{+218}:\\
\;\;\;\;\mathsf{fma}\left(x\_m, x\_m, \left(z \cdot -4\right) \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;{x\_m}^{2}\\
\end{array}
\end{array}
if x < 4.99999999999999983e218Initial program 97.0%
fma-neg98.3%
associate-*l*98.7%
*-commutative98.7%
distribute-rgt-neg-in98.7%
distribute-rgt-neg-in98.7%
metadata-eval98.7%
Simplified98.7%
if 4.99999999999999983e218 < x Initial program 90.5%
Taylor expanded in x around inf 100.0%
Final simplification98.8%
x_m = (fabs.f64 x) (FPCore (x_m y z) :precision binary64 (fma (* z -4.0) y (pow x_m 2.0)))
x_m = fabs(x);
double code(double x_m, double y, double z) {
return fma((z * -4.0), y, pow(x_m, 2.0));
}
x_m = abs(x) function code(x_m, y, z) return fma(Float64(z * -4.0), y, (x_m ^ 2.0)) end
x_m = N[Abs[x], $MachinePrecision] code[x$95$m_, y_, z_] := N[(N[(z * -4.0), $MachinePrecision] * y + N[Power[x$95$m, 2.0], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
x_m = \left|x\right|
\\
\mathsf{fma}\left(z \cdot -4, y, {x\_m}^{2}\right)
\end{array}
Initial program 96.5%
sub-neg96.5%
+-commutative96.5%
distribute-lft-neg-in96.5%
distribute-rgt-neg-in96.5%
metadata-eval96.5%
associate-*r*96.9%
*-commutative96.9%
*-commutative96.9%
fma-define98.4%
pow298.4%
Applied egg-rr98.4%
Final simplification98.4%
x_m = (fabs.f64 x) (FPCore (x_m y z) :precision binary64 (if (<= x_m 2e+154) (- (* x_m x_m) (* (* z y) 4.0)) (pow x_m 2.0)))
x_m = fabs(x);
double code(double x_m, double y, double z) {
double tmp;
if (x_m <= 2e+154) {
tmp = (x_m * x_m) - ((z * y) * 4.0);
} else {
tmp = pow(x_m, 2.0);
}
return tmp;
}
x_m = abs(x)
real(8) function code(x_m, y, z)
real(8), intent (in) :: x_m
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: tmp
if (x_m <= 2d+154) then
tmp = (x_m * x_m) - ((z * y) * 4.0d0)
else
tmp = x_m ** 2.0d0
end if
code = tmp
end function
x_m = Math.abs(x);
public static double code(double x_m, double y, double z) {
double tmp;
if (x_m <= 2e+154) {
tmp = (x_m * x_m) - ((z * y) * 4.0);
} else {
tmp = Math.pow(x_m, 2.0);
}
return tmp;
}
x_m = math.fabs(x) def code(x_m, y, z): tmp = 0 if x_m <= 2e+154: tmp = (x_m * x_m) - ((z * y) * 4.0) else: tmp = math.pow(x_m, 2.0) return tmp
x_m = abs(x) function code(x_m, y, z) tmp = 0.0 if (x_m <= 2e+154) tmp = Float64(Float64(x_m * x_m) - Float64(Float64(z * y) * 4.0)); else tmp = x_m ^ 2.0; end return tmp end
x_m = abs(x); function tmp_2 = code(x_m, y, z) tmp = 0.0; if (x_m <= 2e+154) tmp = (x_m * x_m) - ((z * y) * 4.0); else tmp = x_m ^ 2.0; end tmp_2 = tmp; end
x_m = N[Abs[x], $MachinePrecision] code[x$95$m_, y_, z_] := If[LessEqual[x$95$m, 2e+154], N[(N[(x$95$m * x$95$m), $MachinePrecision] - N[(N[(z * y), $MachinePrecision] * 4.0), $MachinePrecision]), $MachinePrecision], N[Power[x$95$m, 2.0], $MachinePrecision]]
\begin{array}{l}
x_m = \left|x\right|
\\
\begin{array}{l}
\mathbf{if}\;x\_m \leq 2 \cdot 10^{+154}:\\
\;\;\;\;x\_m \cdot x\_m - \left(z \cdot y\right) \cdot 4\\
\mathbf{else}:\\
\;\;\;\;{x\_m}^{2}\\
\end{array}
\end{array}
if x < 2.00000000000000007e154Initial program 97.7%
Taylor expanded in y around 0 98.1%
*-commutative98.1%
Simplified98.1%
if 2.00000000000000007e154 < x Initial program 89.7%
Taylor expanded in x around inf 94.9%
Final simplification97.6%
x_m = (fabs.f64 x) (FPCore (x_m y z) :precision binary64 (- (* x_m x_m) (* z (* y 4.0))))
x_m = fabs(x);
double code(double x_m, double y, double z) {
return (x_m * x_m) - (z * (y * 4.0));
}
x_m = abs(x)
real(8) function code(x_m, y, z)
real(8), intent (in) :: x_m
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (x_m * x_m) - (z * (y * 4.0d0))
end function
x_m = Math.abs(x);
public static double code(double x_m, double y, double z) {
return (x_m * x_m) - (z * (y * 4.0));
}
x_m = math.fabs(x) def code(x_m, y, z): return (x_m * x_m) - (z * (y * 4.0))
x_m = abs(x) function code(x_m, y, z) return Float64(Float64(x_m * x_m) - Float64(z * Float64(y * 4.0))) end
x_m = abs(x); function tmp = code(x_m, y, z) tmp = (x_m * x_m) - (z * (y * 4.0)); end
x_m = N[Abs[x], $MachinePrecision] code[x$95$m_, y_, z_] := N[(N[(x$95$m * x$95$m), $MachinePrecision] - N[(z * N[(y * 4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
x_m = \left|x\right|
\\
x\_m \cdot x\_m - z \cdot \left(y \cdot 4\right)
\end{array}
Initial program 96.5%
Final simplification96.5%
x_m = (fabs.f64 x) (FPCore (x_m y z) :precision binary64 (- (* x_m x_m) (* (* z y) 4.0)))
x_m = fabs(x);
double code(double x_m, double y, double z) {
return (x_m * x_m) - ((z * y) * 4.0);
}
x_m = abs(x)
real(8) function code(x_m, y, z)
real(8), intent (in) :: x_m
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (x_m * x_m) - ((z * y) * 4.0d0)
end function
x_m = Math.abs(x);
public static double code(double x_m, double y, double z) {
return (x_m * x_m) - ((z * y) * 4.0);
}
x_m = math.fabs(x) def code(x_m, y, z): return (x_m * x_m) - ((z * y) * 4.0)
x_m = abs(x) function code(x_m, y, z) return Float64(Float64(x_m * x_m) - Float64(Float64(z * y) * 4.0)) end
x_m = abs(x); function tmp = code(x_m, y, z) tmp = (x_m * x_m) - ((z * y) * 4.0); end
x_m = N[Abs[x], $MachinePrecision] code[x$95$m_, y_, z_] := N[(N[(x$95$m * x$95$m), $MachinePrecision] - N[(N[(z * y), $MachinePrecision] * 4.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
x_m = \left|x\right|
\\
x\_m \cdot x\_m - \left(z \cdot y\right) \cdot 4
\end{array}
Initial program 96.5%
Taylor expanded in y around 0 96.9%
*-commutative96.9%
Simplified96.9%
Final simplification96.9%
x_m = (fabs.f64 x) (FPCore (x_m y z) :precision binary64 (* (* z -4.0) y))
x_m = fabs(x);
double code(double x_m, double y, double z) {
return (z * -4.0) * y;
}
x_m = abs(x)
real(8) function code(x_m, y, z)
real(8), intent (in) :: x_m
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (z * (-4.0d0)) * y
end function
x_m = Math.abs(x);
public static double code(double x_m, double y, double z) {
return (z * -4.0) * y;
}
x_m = math.fabs(x) def code(x_m, y, z): return (z * -4.0) * y
x_m = abs(x) function code(x_m, y, z) return Float64(Float64(z * -4.0) * y) end
x_m = abs(x); function tmp = code(x_m, y, z) tmp = (z * -4.0) * y; end
x_m = N[Abs[x], $MachinePrecision] code[x$95$m_, y_, z_] := N[(N[(z * -4.0), $MachinePrecision] * y), $MachinePrecision]
\begin{array}{l}
x_m = \left|x\right|
\\
\left(z \cdot -4\right) \cdot y
\end{array}
Initial program 96.5%
Taylor expanded in x around 0 53.5%
associate-*r*53.5%
*-commutative53.5%
associate-*r*53.5%
Simplified53.5%
Final simplification53.5%
herbie shell --seed 2024071
(FPCore (x y z)
:name "Graphics.Rasterific.QuadraticFormula:discriminant from Rasterific-0.6.1"
:precision binary64
(- (* x x) (* (* y 4.0) z)))