
(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}
x_m = (fabs.f64 x) (FPCore (x_m y z) :precision binary64 (if (<= x_m 5e+167) (fma x_m x_m (* (* z -4.0) y)) (pow x_m 2.0)))
x_m = fabs(x);
double code(double x_m, double y, double z) {
double tmp;
if (x_m <= 5e+167) {
tmp = fma(x_m, x_m, ((z * -4.0) * y));
} 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 <= 5e+167) tmp = fma(x_m, x_m, Float64(Float64(z * -4.0) * y)); 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, 5e+167], N[(x$95$m * x$95$m + N[(N[(z * -4.0), $MachinePrecision] * y), $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 5 \cdot 10^{+167}:\\
\;\;\;\;\mathsf{fma}\left(x_m, x_m, \left(z \cdot -4\right) \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;{x_m}^{2}\\
\end{array}
\end{array}
if x < 4.9999999999999997e167Initial program 98.2%
fma-neg98.7%
associate-*l*98.7%
*-commutative98.7%
distribute-rgt-neg-in98.7%
distribute-rgt-neg-in98.7%
metadata-eval98.7%
Simplified98.7%
if 4.9999999999999997e167 < x Initial program 93.1%
Taylor expanded in x around inf 100.0%
Final simplification98.8%
x_m = (fabs.f64 x) (FPCore (x_m y z) :precision binary64 (fma (* z -4.0) y (pow x_m 2.0)))
x_m = fabs(x);
double code(double x_m, double y, double z) {
return fma((z * -4.0), y, pow(x_m, 2.0));
}
x_m = abs(x) function code(x_m, y, z) return fma(Float64(z * -4.0), y, (x_m ^ 2.0)) end
x_m = N[Abs[x], $MachinePrecision] code[x$95$m_, y_, z_] := N[(N[(z * -4.0), $MachinePrecision] * y + N[Power[x$95$m, 2.0], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
x_m = \left|x\right|
\\
\mathsf{fma}\left(z \cdot -4, y, {x_m}^{2}\right)
\end{array}
Initial program 97.6%
sub-neg97.6%
+-commutative97.6%
distribute-lft-neg-in97.6%
distribute-rgt-neg-in97.6%
metadata-eval97.6%
associate-*r*97.6%
*-commutative97.6%
*-commutative97.6%
fma-def99.6%
pow299.6%
Applied egg-rr99.6%
Final simplification99.6%
x_m = (fabs.f64 x) (FPCore (x_m y z) :precision binary64 (if (<= x_m 2.8e+138) (- (* 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 <= 2.8e+138) {
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 <= 2.8d+138) 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 <= 2.8e+138) {
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 <= 2.8e+138: 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 <= 2.8e+138) 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 <= 2.8e+138) 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, 2.8e+138], 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 2.8 \cdot 10^{+138}:\\
\;\;\;\;x_m \cdot x_m - z \cdot \left(y \cdot 4\right)\\
\mathbf{else}:\\
\;\;\;\;{x_m}^{2}\\
\end{array}
\end{array}
if x < 2.8000000000000001e138Initial program 98.6%
if 2.8000000000000001e138 < x Initial program 91.2%
Taylor expanded in x around inf 97.1%
Final simplification98.4%
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.6%
Final simplification97.6%
x_m = (fabs.f64 x) (FPCore (x_m y z) :precision binary64 (* -4.0 (* z y)))
x_m = fabs(x);
double code(double x_m, double y, double z) {
return -4.0 * (z * y);
}
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) * (z * y)
end function
x_m = Math.abs(x);
public static double code(double x_m, double y, double z) {
return -4.0 * (z * y);
}
x_m = math.fabs(x) def code(x_m, y, z): return -4.0 * (z * y)
x_m = abs(x) function code(x_m, y, z) return Float64(-4.0 * Float64(z * y)) end
x_m = abs(x); function tmp = code(x_m, y, z) tmp = -4.0 * (z * y); end
x_m = N[Abs[x], $MachinePrecision] code[x$95$m_, y_, z_] := N[(-4.0 * N[(z * y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
x_m = \left|x\right|
\\
-4 \cdot \left(z \cdot y\right)
\end{array}
Initial program 97.6%
Taylor expanded in x around 0 49.2%
Final simplification49.2%
x_m = (fabs.f64 x) (FPCore (x_m y z) :precision binary64 (* (* z -4.0) y))
x_m = fabs(x);
double code(double x_m, double y, double z) {
return (z * -4.0) * y;
}
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 = (z * (-4.0d0)) * y
end function
x_m = Math.abs(x);
public static double code(double x_m, double y, double z) {
return (z * -4.0) * y;
}
x_m = math.fabs(x) def code(x_m, y, z): return (z * -4.0) * y
x_m = abs(x) function code(x_m, y, z) return Float64(Float64(z * -4.0) * y) end
x_m = abs(x); function tmp = code(x_m, y, z) tmp = (z * -4.0) * y; end
x_m = N[Abs[x], $MachinePrecision] code[x$95$m_, y_, z_] := N[(N[(z * -4.0), $MachinePrecision] * y), $MachinePrecision]
\begin{array}{l}
x_m = \left|x\right|
\\
\left(z \cdot -4\right) \cdot y
\end{array}
Initial program 97.6%
Taylor expanded in x around 0 49.2%
add-log-exp22.9%
*-un-lft-identity22.9%
log-prod22.9%
metadata-eval22.9%
add-log-exp49.2%
*-commutative49.2%
associate-*l*49.2%
*-commutative49.2%
Applied egg-rr49.2%
Final simplification49.2%
herbie shell --seed 2024011
(FPCore (x y z)
:name "Graphics.Rasterific.QuadraticFormula:discriminant from Rasterific-0.6.1"
:precision binary64
(- (* x x) (* (* y 4.0) z)))