
(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}
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (fma (* z -4.0) y (* x x)))
assert(x < y && y < z);
double code(double x, double y, double z) {
return fma((z * -4.0), y, (x * x));
}
x, y, z = sort([x, y, z]) function code(x, y, z) return fma(Float64(z * -4.0), y, Float64(x * x)) end
NOTE: x, y, and z should be sorted in increasing order before calling this function. code[x_, y_, z_] := N[(N[(z * -4.0), $MachinePrecision] * y + N[(x * x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\mathsf{fma}\left(z \cdot -4, y, x \cdot x\right)
\end{array}
Initial program 97.7%
sub-neg97.7%
+-commutative97.7%
distribute-lft-neg-in97.7%
distribute-rgt-neg-in97.7%
metadata-eval97.7%
associate-*r*97.7%
*-commutative97.7%
*-commutative97.7%
fma-def98.8%
pow298.8%
Applied egg-rr98.8%
unpow298.8%
Applied egg-rr98.8%
Final simplification98.8%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (fma x x (* (* z -4.0) y)))
assert(x < y && y < z);
double code(double x, double y, double z) {
return fma(x, x, ((z * -4.0) * y));
}
x, y, z = sort([x, y, z]) function code(x, y, z) return fma(x, x, Float64(Float64(z * -4.0) * y)) end
NOTE: x, y, and z should be sorted in increasing order before calling this function. code[x_, y_, z_] := N[(x * x + N[(N[(z * -4.0), $MachinePrecision] * y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\mathsf{fma}\left(x, x, \left(z \cdot -4\right) \cdot y\right)
\end{array}
Initial program 97.7%
fma-neg98.4%
associate-*l*98.4%
*-commutative98.4%
distribute-rgt-neg-in98.4%
distribute-rgt-neg-in98.4%
metadata-eval98.4%
Simplified98.4%
Final simplification98.4%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (<= (* x x) 5e+239) (- (* x x) (* z (* y 4.0))) (* x x)))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if ((x * x) <= 5e+239) {
tmp = (x * x) - (z * (y * 4.0));
} else {
tmp = x * x;
}
return tmp;
}
NOTE: x, 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) <= 5d+239) then
tmp = (x * x) - (z * (y * 4.0d0))
else
tmp = x * x
end if
code = tmp
end function
assert x < y && y < z;
public static double code(double x, double y, double z) {
double tmp;
if ((x * x) <= 5e+239) {
tmp = (x * x) - (z * (y * 4.0));
} else {
tmp = x * x;
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): tmp = 0 if (x * x) <= 5e+239: tmp = (x * x) - (z * (y * 4.0)) else: tmp = x * x return tmp
x, y, z = sort([x, y, z]) function code(x, y, z) tmp = 0.0 if (Float64(x * x) <= 5e+239) tmp = Float64(Float64(x * x) - Float64(z * Float64(y * 4.0))); else tmp = Float64(x * x); end return tmp end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp_2 = code(x, y, z)
tmp = 0.0;
if ((x * x) <= 5e+239)
tmp = (x * x) - (z * (y * 4.0));
else
tmp = x * x;
end
tmp_2 = tmp;
end
NOTE: x, y, and z should be sorted in increasing order before calling this function. code[x_, y_, z_] := If[LessEqual[N[(x * x), $MachinePrecision], 5e+239], N[(N[(x * x), $MachinePrecision] - N[(z * N[(y * 4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x * x), $MachinePrecision]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;x \cdot x \leq 5 \cdot 10^{+239}:\\
\;\;\;\;x \cdot x - z \cdot \left(y \cdot 4\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot x\\
\end{array}
\end{array}
if (*.f64 x x) < 5.00000000000000007e239Initial program 100.0%
if 5.00000000000000007e239 < (*.f64 x x) Initial program 92.5%
Taylor expanded in x around inf 97.5%
unpow296.3%
Applied egg-rr97.5%
Final simplification99.2%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (<= (* x x) 2.3e+46) (* -4.0 (* z y)) (* x x)))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if ((x * x) <= 2.3e+46) {
tmp = -4.0 * (z * y);
} else {
tmp = x * x;
}
return tmp;
}
NOTE: x, 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) <= 2.3d+46) then
tmp = (-4.0d0) * (z * y)
else
tmp = x * x
end if
code = tmp
end function
assert x < y && y < z;
public static double code(double x, double y, double z) {
double tmp;
if ((x * x) <= 2.3e+46) {
tmp = -4.0 * (z * y);
} else {
tmp = x * x;
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): tmp = 0 if (x * x) <= 2.3e+46: tmp = -4.0 * (z * y) else: tmp = x * x return tmp
x, y, z = sort([x, y, z]) function code(x, y, z) tmp = 0.0 if (Float64(x * x) <= 2.3e+46) tmp = Float64(-4.0 * Float64(z * y)); else tmp = Float64(x * x); end return tmp end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp_2 = code(x, y, z)
tmp = 0.0;
if ((x * x) <= 2.3e+46)
tmp = -4.0 * (z * y);
else
tmp = x * x;
end
tmp_2 = tmp;
end
NOTE: x, y, and z should be sorted in increasing order before calling this function. code[x_, y_, z_] := If[LessEqual[N[(x * x), $MachinePrecision], 2.3e+46], N[(-4.0 * N[(z * y), $MachinePrecision]), $MachinePrecision], N[(x * x), $MachinePrecision]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;x \cdot x \leq 2.3 \cdot 10^{+46}:\\
\;\;\;\;-4 \cdot \left(z \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot x\\
\end{array}
\end{array}
if (*.f64 x x) < 2.3000000000000001e46Initial program 100.0%
Taylor expanded in x around 0 87.8%
if 2.3000000000000001e46 < (*.f64 x x) Initial program 95.0%
Taylor expanded in x around inf 91.1%
unpow297.5%
Applied egg-rr91.1%
Final simplification89.3%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (* x x))
assert(x < y && y < z);
double code(double x, double y, double z) {
return x * x;
}
NOTE: x, 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 x < y && y < z;
public static double code(double x, double y, double z) {
return x * x;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): return x * x
x, y, z = sort([x, y, z]) function code(x, y, z) return Float64(x * x) end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp = code(x, y, z)
tmp = x * x;
end
NOTE: x, y, and z should be sorted in increasing order before calling this function. code[x_, y_, z_] := N[(x * x), $MachinePrecision]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
x \cdot x
\end{array}
Initial program 97.7%
Taylor expanded in x around inf 54.6%
unpow298.8%
Applied egg-rr54.6%
Final simplification54.6%
herbie shell --seed 2023332
(FPCore (x y z)
:name "Graphics.Rasterific.QuadraticFormula:discriminant from Rasterific-0.6.1"
:precision binary64
(- (* x x) (* (* y 4.0) z)))