
(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}
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (<= (* y 4.0) -4e+209) (* y (- (/ (pow x 2.0) y) (* 4.0 z))) (fma x x (* y (* z -4.0)))))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if ((y * 4.0) <= -4e+209) {
tmp = y * ((pow(x, 2.0) / y) - (4.0 * z));
} else {
tmp = fma(x, x, (y * (z * -4.0)));
}
return tmp;
}
x, y, z = sort([x, y, z]) function code(x, y, z) tmp = 0.0 if (Float64(y * 4.0) <= -4e+209) tmp = Float64(y * Float64(Float64((x ^ 2.0) / y) - Float64(4.0 * z))); else tmp = fma(x, x, Float64(y * Float64(z * -4.0))); end return tmp end
NOTE: x, y, and z should be sorted in increasing order before calling this function. code[x_, y_, z_] := If[LessEqual[N[(y * 4.0), $MachinePrecision], -4e+209], N[(y * N[(N[(N[Power[x, 2.0], $MachinePrecision] / y), $MachinePrecision] - N[(4.0 * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x * x + N[(y * N[(z * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;y \cdot 4 \leq -4 \cdot 10^{+209}:\\
\;\;\;\;y \cdot \left(\frac{{x}^{2}}{y} - 4 \cdot z\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(x, x, y \cdot \left(z \cdot -4\right)\right)\\
\end{array}
\end{array}
if (*.f64 y #s(literal 4 binary64)) < -4.0000000000000003e209Initial program 94.1%
Taylor expanded in y around inf 100.0%
if -4.0000000000000003e209 < (*.f64 y #s(literal 4 binary64)) Initial program 98.3%
fmm-def98.7%
associate-*l*98.7%
*-commutative98.7%
distribute-rgt-neg-in98.7%
distribute-rgt-neg-in98.7%
metadata-eval98.7%
Simplified98.7%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (fma x x (* y (* z -4.0))))
assert(x < y && y < z);
double code(double x, double y, double z) {
return fma(x, x, (y * (z * -4.0)));
}
x, y, z = sort([x, y, z]) function code(x, y, z) return fma(x, x, Float64(y * Float64(z * -4.0))) end
NOTE: x, y, and z should be sorted in increasing order before calling this function. code[x_, y_, z_] := N[(x * x + N[(y * N[(z * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\mathsf{fma}\left(x, x, y \cdot \left(z \cdot -4\right)\right)
\end{array}
Initial program 98.0%
fmm-def98.4%
associate-*l*98.4%
*-commutative98.4%
distribute-rgt-neg-in98.4%
distribute-rgt-neg-in98.4%
metadata-eval98.4%
Simplified98.4%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (let* ((t_0 (- (* x x) (* (* y 4.0) z)))) (if (<= t_0 INFINITY) t_0 (* 4.0 (* y z)))))
assert(x < y && y < z);
double code(double x, double y, double z) {
double t_0 = (x * x) - ((y * 4.0) * z);
double tmp;
if (t_0 <= ((double) INFINITY)) {
tmp = t_0;
} else {
tmp = 4.0 * (y * z);
}
return tmp;
}
assert x < y && y < z;
public static double code(double x, double y, double z) {
double t_0 = (x * x) - ((y * 4.0) * z);
double tmp;
if (t_0 <= Double.POSITIVE_INFINITY) {
tmp = t_0;
} else {
tmp = 4.0 * (y * z);
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): t_0 = (x * x) - ((y * 4.0) * z) tmp = 0 if t_0 <= math.inf: tmp = t_0 else: tmp = 4.0 * (y * z) return tmp
x, y, z = sort([x, y, z]) function code(x, y, z) t_0 = Float64(Float64(x * x) - Float64(Float64(y * 4.0) * z)) tmp = 0.0 if (t_0 <= Inf) tmp = t_0; else tmp = Float64(4.0 * Float64(y * z)); end return tmp end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp_2 = code(x, y, z)
t_0 = (x * x) - ((y * 4.0) * z);
tmp = 0.0;
if (t_0 <= Inf)
tmp = t_0;
else
tmp = 4.0 * (y * z);
end
tmp_2 = tmp;
end
NOTE: x, y, and z should be sorted in increasing order before calling this function.
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(x * x), $MachinePrecision] - N[(N[(y * 4.0), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, Infinity], t$95$0, N[(4.0 * N[(y * z), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
t_0 := x \cdot x - \left(y \cdot 4\right) \cdot z\\
\mathbf{if}\;t\_0 \leq \infty:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;4 \cdot \left(y \cdot z\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%
associate-*r*80.0%
*-commutative80.0%
associate-*r*80.0%
Simplified80.0%
Taylor expanded in x around 0 80.0%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (let* ((t_0 (* (* y 4.0) z))) (if (<= t_0 2e+125) (- (* x x) t_0) (* y (- (* x (/ x y)) (* 4.0 z))))))
assert(x < y && y < z);
double code(double x, double y, double z) {
double t_0 = (y * 4.0) * z;
double tmp;
if (t_0 <= 2e+125) {
tmp = (x * x) - t_0;
} else {
tmp = y * ((x * (x / y)) - (4.0 * z));
}
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) :: t_0
real(8) :: tmp
t_0 = (y * 4.0d0) * z
if (t_0 <= 2d+125) then
tmp = (x * x) - t_0
else
tmp = y * ((x * (x / y)) - (4.0d0 * z))
end if
code = tmp
end function
assert x < y && y < z;
public static double code(double x, double y, double z) {
double t_0 = (y * 4.0) * z;
double tmp;
if (t_0 <= 2e+125) {
tmp = (x * x) - t_0;
} else {
tmp = y * ((x * (x / y)) - (4.0 * z));
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): t_0 = (y * 4.0) * z tmp = 0 if t_0 <= 2e+125: tmp = (x * x) - t_0 else: tmp = y * ((x * (x / y)) - (4.0 * z)) return tmp
x, y, z = sort([x, y, z]) function code(x, y, z) t_0 = Float64(Float64(y * 4.0) * z) tmp = 0.0 if (t_0 <= 2e+125) tmp = Float64(Float64(x * x) - t_0); else tmp = Float64(y * Float64(Float64(x * Float64(x / y)) - Float64(4.0 * z))); end return tmp end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp_2 = code(x, y, z)
t_0 = (y * 4.0) * z;
tmp = 0.0;
if (t_0 <= 2e+125)
tmp = (x * x) - t_0;
else
tmp = y * ((x * (x / y)) - (4.0 * z));
end
tmp_2 = tmp;
end
NOTE: x, y, and z should be sorted in increasing order before calling this function.
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(y * 4.0), $MachinePrecision] * z), $MachinePrecision]}, If[LessEqual[t$95$0, 2e+125], N[(N[(x * x), $MachinePrecision] - t$95$0), $MachinePrecision], N[(y * N[(N[(x * N[(x / y), $MachinePrecision]), $MachinePrecision] - N[(4.0 * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
t_0 := \left(y \cdot 4\right) \cdot z\\
\mathbf{if}\;t\_0 \leq 2 \cdot 10^{+125}:\\
\;\;\;\;x \cdot x - t\_0\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(x \cdot \frac{x}{y} - 4 \cdot z\right)\\
\end{array}
\end{array}
if (*.f64 (*.f64 y #s(literal 4 binary64)) z) < 1.9999999999999998e125Initial program 100.0%
if 1.9999999999999998e125 < (*.f64 (*.f64 y #s(literal 4 binary64)) z) Initial program 89.1%
Taylor expanded in y around inf 97.8%
pow297.8%
associate-/l*100.0%
Applied egg-rr100.0%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (<= (* x x) 6.5e-11) (* -4.0 (* y z)) (- (* x x) (* y (* z -4.0)))))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if ((x * x) <= 6.5e-11) {
tmp = -4.0 * (y * z);
} else {
tmp = (x * x) - (y * (z * -4.0));
}
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) <= 6.5d-11) then
tmp = (-4.0d0) * (y * z)
else
tmp = (x * x) - (y * (z * (-4.0d0)))
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) <= 6.5e-11) {
tmp = -4.0 * (y * z);
} else {
tmp = (x * x) - (y * (z * -4.0));
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): tmp = 0 if (x * x) <= 6.5e-11: tmp = -4.0 * (y * z) else: tmp = (x * x) - (y * (z * -4.0)) return tmp
x, y, z = sort([x, y, z]) function code(x, y, z) tmp = 0.0 if (Float64(x * x) <= 6.5e-11) tmp = Float64(-4.0 * Float64(y * z)); else tmp = Float64(Float64(x * x) - Float64(y * Float64(z * -4.0))); 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) <= 6.5e-11)
tmp = -4.0 * (y * z);
else
tmp = (x * x) - (y * (z * -4.0));
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], 6.5e-11], 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}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;x \cdot x \leq 6.5 \cdot 10^{-11}:\\
\;\;\;\;-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.49999999999999953e-11Initial program 100.0%
Taylor expanded in x around 0 81.3%
if 6.49999999999999953e-11 < (*.f64 x x) Initial program 96.0%
Taylor expanded in y around 0 96.0%
rem-square-sqrt52.8%
fabs-sqr52.8%
rem-square-sqrt85.6%
fabs-neg85.6%
distribute-lft-neg-in85.6%
metadata-eval85.6%
*-commutative85.6%
*-commutative85.6%
associate-*r*85.6%
rem-square-sqrt42.4%
fabs-sqr42.4%
rem-square-sqrt80.7%
associate-*r*80.7%
*-commutative80.7%
associate-*r*80.7%
Simplified80.7%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (* -4.0 (* y z)))
assert(x < y && y < z);
double code(double x, double y, double z) {
return -4.0 * (y * z);
}
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 = (-4.0d0) * (y * z)
end function
assert x < y && y < z;
public static double code(double x, double y, double z) {
return -4.0 * (y * z);
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): return -4.0 * (y * z)
x, y, z = sort([x, y, z]) function code(x, y, z) return Float64(-4.0 * Float64(y * z)) end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp = code(x, y, z)
tmp = -4.0 * (y * z);
end
NOTE: x, y, and z should be sorted in increasing order before calling this function. code[x_, y_, z_] := N[(-4.0 * N[(y * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
-4 \cdot \left(y \cdot z\right)
\end{array}
Initial program 98.0%
Taylor expanded in x around 0 51.4%
herbie shell --seed 2024165
(FPCore (x y z)
:name "Graphics.Rasterific.QuadraticFormula:discriminant from Rasterific-0.6.1"
:precision binary64
(- (* x x) (* (* y 4.0) z)))