
(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 4 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 1e+184) (fma x_m x_m (* (* y z) -4.0)) (* x_m x_m)))
x_m = fabs(x);
double code(double x_m, double y, double z) {
double tmp;
if (x_m <= 1e+184) {
tmp = fma(x_m, x_m, ((y * z) * -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 <= 1e+184) tmp = fma(x_m, x_m, Float64(Float64(y * z) * -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, 1e+184], N[(x$95$m * x$95$m + N[(N[(y * z), $MachinePrecision] * -4.0), $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 10^{+184}:\\
\;\;\;\;\mathsf{fma}\left(x\_m, x\_m, \left(y \cdot z\right) \cdot -4\right)\\
\mathbf{else}:\\
\;\;\;\;x\_m \cdot x\_m\\
\end{array}
\end{array}
if x < 1.00000000000000002e184Initial program 97.8%
lift--.f64N/A
sub-negN/A
lift-*.f64N/A
lower-fma.f64N/A
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
associate-*r*N/A
distribute-rgt-neg-inN/A
lower-*.f64N/A
lower-*.f64N/A
metadata-eval98.7
Applied rewrites98.7%
if 1.00000000000000002e184 < x Initial program 82.1%
Taylor expanded in z around 0
unpow2N/A
lower-*.f64100.0
Applied rewrites100.0%
Final simplification98.8%
x_m = (fabs.f64 x) (FPCore (x_m y z) :precision binary64 (if (<= x_m 6.1e+56) (* (* y z) -4.0) (* x_m x_m)))
x_m = fabs(x);
double code(double x_m, double y, double z) {
double tmp;
if (x_m <= 6.1e+56) {
tmp = (y * z) * -4.0;
} 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 <= 6.1d+56) then
tmp = (y * z) * (-4.0d0)
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 <= 6.1e+56) {
tmp = (y * z) * -4.0;
} else {
tmp = x_m * x_m;
}
return tmp;
}
x_m = math.fabs(x) def code(x_m, y, z): tmp = 0 if x_m <= 6.1e+56: tmp = (y * z) * -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 <= 6.1e+56) tmp = Float64(Float64(y * z) * -4.0); 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 <= 6.1e+56) tmp = (y * z) * -4.0; 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, 6.1e+56], N[(N[(y * z), $MachinePrecision] * -4.0), $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 6.1 \cdot 10^{+56}:\\
\;\;\;\;\left(y \cdot z\right) \cdot -4\\
\mathbf{else}:\\
\;\;\;\;x\_m \cdot x\_m\\
\end{array}
\end{array}
if x < 6.1000000000000001e56Initial program 98.5%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f6463.9
Applied rewrites63.9%
if 6.1000000000000001e56 < x Initial program 87.5%
Taylor expanded in z around 0
unpow2N/A
lower-*.f6494.7
Applied rewrites94.7%
Final simplification70.6%
x_m = (fabs.f64 x) (FPCore (x_m y z) :precision binary64 (fma (* z -4.0) y (* x_m x_m)))
x_m = fabs(x);
double code(double x_m, double y, double z) {
return fma((z * -4.0), y, (x_m * x_m));
}
x_m = abs(x) function code(x_m, y, z) return fma(Float64(z * -4.0), y, Float64(x_m * x_m)) end
x_m = N[Abs[x], $MachinePrecision] code[x$95$m_, y_, z_] := N[(N[(z * -4.0), $MachinePrecision] * y + N[(x$95$m * x$95$m), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
x_m = \left|x\right|
\\
\mathsf{fma}\left(z \cdot -4, y, x\_m \cdot x\_m\right)
\end{array}
Initial program 96.1%
lift--.f64N/A
sub-negN/A
+-commutativeN/A
lift-*.f64N/A
lift-*.f64N/A
associate-*l*N/A
*-commutativeN/A
distribute-lft-neg-inN/A
lower-fma.f64N/A
distribute-lft-neg-inN/A
lower-*.f64N/A
metadata-eval99.2
Applied rewrites99.2%
Final simplification99.2%
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 96.1%
Taylor expanded in z around 0
unpow2N/A
lower-*.f6452.8
Applied rewrites52.8%
herbie shell --seed 2024276
(FPCore (x y z)
:name "Graphics.Rasterific.QuadraticFormula:discriminant from Rasterific-0.6.1"
:precision binary64
(- (* x x) (* (* y 4.0) z)))