
(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 3 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 2e+218) (fma x_m x_m (* z (* y -4.0))) (* x_m x_m)))
x_m = fabs(x);
double code(double x_m, double y, double z) {
double tmp;
if (x_m <= 2e+218) {
tmp = fma(x_m, x_m, (z * (y * -4.0)));
} else {
tmp = x_m * x_m;
}
return tmp;
}
x_m = abs(x) function code(x_m, y, z) tmp = 0.0 if (x_m <= 2e+218) tmp = fma(x_m, x_m, Float64(z * Float64(y * -4.0))); else tmp = Float64(x_m * x_m); end return tmp end
x_m = N[Abs[x], $MachinePrecision] code[x$95$m_, y_, z_] := If[LessEqual[x$95$m, 2e+218], N[(x$95$m * x$95$m + N[(z * N[(y * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x$95$m * x$95$m), $MachinePrecision]]
\begin{array}{l}
x_m = \left|x\right|
\\
\begin{array}{l}
\mathbf{if}\;x\_m \leq 2 \cdot 10^{+218}:\\
\;\;\;\;\mathsf{fma}\left(x\_m, x\_m, z \cdot \left(y \cdot -4\right)\right)\\
\mathbf{else}:\\
\;\;\;\;x\_m \cdot x\_m\\
\end{array}
\end{array}
if x < 2.00000000000000017e218Initial program 98.2%
sub-negN/A
accelerator-lowering-fma.f64N/A
*-commutativeN/A
distribute-rgt-neg-inN/A
*-lowering-*.f64N/A
distribute-rgt-neg-inN/A
*-lowering-*.f64N/A
metadata-eval99.1
Applied egg-rr99.1%
if 2.00000000000000017e218 < x Initial program 89.7%
Taylor expanded in x around inf
unpow2N/A
*-lowering-*.f64100.0
Simplified100.0%
x_m = (fabs.f64 x) (FPCore (x_m y z) :precision binary64 (if (<= x_m 3.7e+33) (* -4.0 (* z y)) (* x_m x_m)))
x_m = fabs(x);
double code(double x_m, double y, double z) {
double tmp;
if (x_m <= 3.7e+33) {
tmp = -4.0 * (z * y);
} else {
tmp = x_m * x_m;
}
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 <= 3.7d+33) then
tmp = (-4.0d0) * (z * y)
else
tmp = x_m * x_m
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 <= 3.7e+33) {
tmp = -4.0 * (z * y);
} else {
tmp = x_m * x_m;
}
return tmp;
}
x_m = math.fabs(x) def code(x_m, y, z): tmp = 0 if x_m <= 3.7e+33: tmp = -4.0 * (z * y) else: tmp = x_m * x_m return tmp
x_m = abs(x) function code(x_m, y, z) tmp = 0.0 if (x_m <= 3.7e+33) tmp = Float64(-4.0 * Float64(z * y)); else tmp = Float64(x_m * x_m); end return tmp end
x_m = abs(x); function tmp_2 = code(x_m, y, z) tmp = 0.0; if (x_m <= 3.7e+33) tmp = -4.0 * (z * y); else tmp = x_m * x_m; end tmp_2 = tmp; end
x_m = N[Abs[x], $MachinePrecision] code[x$95$m_, y_, z_] := If[LessEqual[x$95$m, 3.7e+33], N[(-4.0 * N[(z * y), $MachinePrecision]), $MachinePrecision], N[(x$95$m * x$95$m), $MachinePrecision]]
\begin{array}{l}
x_m = \left|x\right|
\\
\begin{array}{l}
\mathbf{if}\;x\_m \leq 3.7 \cdot 10^{+33}:\\
\;\;\;\;-4 \cdot \left(z \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;x\_m \cdot x\_m\\
\end{array}
\end{array}
if x < 3.6999999999999999e33Initial program 97.8%
Taylor expanded in x around 0
*-lowering-*.f64N/A
*-lowering-*.f6466.5
Simplified66.5%
if 3.6999999999999999e33 < x Initial program 95.7%
Taylor expanded in x around inf
unpow2N/A
*-lowering-*.f6493.2
Simplified93.2%
Final simplification73.8%
x_m = (fabs.f64 x) (FPCore (x_m y z) :precision binary64 (* x_m x_m))
x_m = fabs(x);
double code(double x_m, double y, double z) {
return x_m * x_m;
}
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
end function
x_m = Math.abs(x);
public static double code(double x_m, double y, double z) {
return x_m * x_m;
}
x_m = math.fabs(x) def code(x_m, y, z): return x_m * x_m
x_m = abs(x) function code(x_m, y, z) return Float64(x_m * x_m) end
x_m = abs(x); function tmp = code(x_m, y, z) tmp = x_m * x_m; end
x_m = N[Abs[x], $MachinePrecision] code[x$95$m_, y_, z_] := N[(x$95$m * x$95$m), $MachinePrecision]
\begin{array}{l}
x_m = \left|x\right|
\\
x\_m \cdot x\_m
\end{array}
Initial program 97.3%
Taylor expanded in x around inf
unpow2N/A
*-lowering-*.f6455.0
Simplified55.0%
herbie shell --seed 2024199
(FPCore (x y z)
:name "Graphics.Rasterific.QuadraticFormula:discriminant from Rasterific-0.6.1"
:precision binary64
(- (* x x) (* (* y 4.0) z)))