
(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}
x_m = (fabs.f64 x) (FPCore (x_m y z) :precision binary64 (if (<= x_m 2e+197) (fma x_m x_m (* y (* z -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+197) {
tmp = fma(x_m, x_m, (y * (z * -4.0)));
} 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 <= 2e+197) tmp = fma(x_m, x_m, Float64(y * Float64(z * -4.0))); 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, 2e+197], N[(x$95$m * x$95$m + N[(y * N[(z * -4.0), $MachinePrecision]), $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^{+197}:\\
\;\;\;\;\mathsf{fma}\left(x\_m, x\_m, y \cdot \left(z \cdot -4\right)\right)\\
\mathbf{else}:\\
\;\;\;\;{x\_m}^{2}\\
\end{array}
\end{array}
if x < 1.9999999999999999e197Initial program 98.7%
fma-neg99.1%
associate-*l*99.1%
*-commutative99.1%
distribute-rgt-neg-in99.1%
distribute-rgt-neg-in99.1%
metadata-eval99.1%
Simplified99.1%
if 1.9999999999999999e197 < x Initial program 86.7%
Taylor expanded in x around inf 100.0%
Final simplification99.2%
x_m = (fabs.f64 x) (FPCore (x_m y z) :precision binary64 (if (<= x_m 4.5e+133) (- (* 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 <= 4.5e+133) {
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 <= 4.5d+133) 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 <= 4.5e+133) {
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 <= 4.5e+133: 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 <= 4.5e+133) tmp = Float64(Float64(x_m * x_m) - Float64(z * Float64(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 <= 4.5e+133) 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, 4.5e+133], N[(N[(x$95$m * x$95$m), $MachinePrecision] - N[(z * N[(y * 4.0), $MachinePrecision]), $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 4.5 \cdot 10^{+133}:\\
\;\;\;\;x\_m \cdot x\_m - z \cdot \left(y \cdot 4\right)\\
\mathbf{else}:\\
\;\;\;\;{x\_m}^{2}\\
\end{array}
\end{array}
if x < 4.49999999999999985e133Initial program 99.1%
if 4.49999999999999985e133 < x Initial program 88.6%
Taylor expanded in x around inf 97.7%
Final simplification98.8%
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 97.3%
Final simplification97.3%
x_m = (fabs.f64 x) (FPCore (x_m y z) :precision binary64 (* -4.0 (* y z)))
x_m = fabs(x);
double code(double x_m, double y, double z) {
return -4.0 * (y * z);
}
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 = (-4.0d0) * (y * z)
end function
x_m = Math.abs(x);
public static double code(double x_m, double y, double z) {
return -4.0 * (y * z);
}
x_m = math.fabs(x) def code(x_m, y, z): return -4.0 * (y * z)
x_m = abs(x) function code(x_m, y, z) return Float64(-4.0 * Float64(y * z)) end
x_m = abs(x); function tmp = code(x_m, y, z) tmp = -4.0 * (y * z); end
x_m = N[Abs[x], $MachinePrecision] code[x$95$m_, y_, z_] := N[(-4.0 * N[(y * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
x_m = \left|x\right|
\\
-4 \cdot \left(y \cdot z\right)
\end{array}
Initial program 97.3%
Taylor expanded in x around 0 50.3%
Final simplification50.3%
x_m = (fabs.f64 x) (FPCore (x_m y z) :precision binary64 (* y (* z -4.0)))
x_m = fabs(x);
double code(double x_m, double y, double z) {
return y * (z * -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 = y * (z * (-4.0d0))
end function
x_m = Math.abs(x);
public static double code(double x_m, double y, double z) {
return y * (z * -4.0);
}
x_m = math.fabs(x) def code(x_m, y, z): return y * (z * -4.0)
x_m = abs(x) function code(x_m, y, z) return Float64(y * Float64(z * -4.0)) end
x_m = abs(x); function tmp = code(x_m, y, z) tmp = y * (z * -4.0); end
x_m = N[Abs[x], $MachinePrecision] code[x$95$m_, y_, z_] := N[(y * N[(z * -4.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
x_m = \left|x\right|
\\
y \cdot \left(z \cdot -4\right)
\end{array}
Initial program 97.3%
Taylor expanded in x around 0 50.3%
*-commutative50.3%
associate-*r*50.3%
*-commutative50.3%
Simplified50.3%
Final simplification50.3%
herbie shell --seed 2024051
(FPCore (x y z)
:name "Graphics.Rasterific.QuadraticFormula:discriminant from Rasterific-0.6.1"
:precision binary64
(- (* x x) (* (* y 4.0) z)))