
(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}
NOTE: x should be positive before calling this function (FPCore (x y z) :precision binary64 (if (<= x 1e+167) (fma x x (* (* z -4.0) y)) (pow x 2.0)))
x = abs(x);
double code(double x, double y, double z) {
double tmp;
if (x <= 1e+167) {
tmp = fma(x, x, ((z * -4.0) * y));
} else {
tmp = pow(x, 2.0);
}
return tmp;
}
x = abs(x) function code(x, y, z) tmp = 0.0 if (x <= 1e+167) tmp = fma(x, x, Float64(Float64(z * -4.0) * y)); else tmp = x ^ 2.0; end return tmp end
NOTE: x should be positive before calling this function code[x_, y_, z_] := If[LessEqual[x, 1e+167], N[(x * x + N[(N[(z * -4.0), $MachinePrecision] * y), $MachinePrecision]), $MachinePrecision], N[Power[x, 2.0], $MachinePrecision]]
\begin{array}{l}
x = |x|\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq 10^{+167}:\\
\;\;\;\;\mathsf{fma}\left(x, x, \left(z \cdot -4\right) \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;{x}^{2}\\
\end{array}
\end{array}
if x < 1e167Initial program 97.4%
fma-neg98.3%
associate-*l*98.7%
distribute-rgt-neg-in98.7%
*-commutative98.7%
distribute-rgt-neg-in98.7%
metadata-eval98.7%
Simplified98.7%
if 1e167 < x Initial program 92.3%
Taylor expanded in x around inf 100.0%
Final simplification98.8%
NOTE: x should be positive before calling this function (FPCore (x y z) :precision binary64 (fma (* z -4.0) y (pow x 2.0)))
x = abs(x);
double code(double x, double y, double z) {
return fma((z * -4.0), y, pow(x, 2.0));
}
x = abs(x) function code(x, y, z) return fma(Float64(z * -4.0), y, (x ^ 2.0)) end
NOTE: x should be positive before calling this function code[x_, y_, z_] := N[(N[(z * -4.0), $MachinePrecision] * y + N[Power[x, 2.0], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
x = |x|\\
\\
\mathsf{fma}\left(z \cdot -4, y, {x}^{2}\right)
\end{array}
Initial program 96.9%
sub-neg96.9%
+-commutative96.9%
distribute-lft-neg-in96.9%
distribute-rgt-neg-in96.9%
metadata-eval96.9%
associate-*r*97.2%
*-commutative97.2%
*-commutative97.2%
fma-def99.2%
pow299.2%
Applied egg-rr99.2%
Final simplification99.2%
NOTE: x should be positive before calling this function (FPCore (x y z) :precision binary64 (if (<= x 1e+154) (- (* x x) (* z (* y 4.0))) (pow x 2.0)))
x = abs(x);
double code(double x, double y, double z) {
double tmp;
if (x <= 1e+154) {
tmp = (x * x) - (z * (y * 4.0));
} else {
tmp = pow(x, 2.0);
}
return tmp;
}
NOTE: x should be positive 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 <= 1d+154) then
tmp = (x * x) - (z * (y * 4.0d0))
else
tmp = x ** 2.0d0
end if
code = tmp
end function
x = Math.abs(x);
public static double code(double x, double y, double z) {
double tmp;
if (x <= 1e+154) {
tmp = (x * x) - (z * (y * 4.0));
} else {
tmp = Math.pow(x, 2.0);
}
return tmp;
}
x = abs(x) def code(x, y, z): tmp = 0 if x <= 1e+154: tmp = (x * x) - (z * (y * 4.0)) else: tmp = math.pow(x, 2.0) return tmp
x = abs(x) function code(x, y, z) tmp = 0.0 if (x <= 1e+154) tmp = Float64(Float64(x * x) - Float64(z * Float64(y * 4.0))); else tmp = x ^ 2.0; end return tmp end
x = abs(x) function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= 1e+154) tmp = (x * x) - (z * (y * 4.0)); else tmp = x ^ 2.0; end tmp_2 = tmp; end
NOTE: x should be positive before calling this function code[x_, y_, z_] := If[LessEqual[x, 1e+154], N[(N[(x * x), $MachinePrecision] - N[(z * N[(y * 4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[Power[x, 2.0], $MachinePrecision]]
\begin{array}{l}
x = |x|\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq 10^{+154}:\\
\;\;\;\;x \cdot x - z \cdot \left(y \cdot 4\right)\\
\mathbf{else}:\\
\;\;\;\;{x}^{2}\\
\end{array}
\end{array}
if x < 1.00000000000000004e154Initial program 97.4%
if 1.00000000000000004e154 < x Initial program 92.9%
Taylor expanded in x around inf 100.0%
Final simplification97.7%
NOTE: x should be positive before calling this function (FPCore (x y z) :precision binary64 (- (* x x) (* z (* y 4.0))))
x = abs(x);
double code(double x, double y, double z) {
return (x * x) - (z * (y * 4.0));
}
NOTE: x should be positive 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 = (x * x) - (z * (y * 4.0d0))
end function
x = Math.abs(x);
public static double code(double x, double y, double z) {
return (x * x) - (z * (y * 4.0));
}
x = abs(x) def code(x, y, z): return (x * x) - (z * (y * 4.0))
x = abs(x) function code(x, y, z) return Float64(Float64(x * x) - Float64(z * Float64(y * 4.0))) end
x = abs(x) function tmp = code(x, y, z) tmp = (x * x) - (z * (y * 4.0)); end
NOTE: x should be positive before calling this function code[x_, y_, z_] := N[(N[(x * x), $MachinePrecision] - N[(z * N[(y * 4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
x = |x|\\
\\
x \cdot x - z \cdot \left(y \cdot 4\right)
\end{array}
Initial program 96.9%
Final simplification96.9%
NOTE: x should be positive before calling this function (FPCore (x y z) :precision binary64 (* -4.0 (* z y)))
x = abs(x);
double code(double x, double y, double z) {
return -4.0 * (z * y);
}
NOTE: x should be positive 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) * (z * y)
end function
x = Math.abs(x);
public static double code(double x, double y, double z) {
return -4.0 * (z * y);
}
x = abs(x) def code(x, y, z): return -4.0 * (z * y)
x = abs(x) function code(x, y, z) return Float64(-4.0 * Float64(z * y)) end
x = abs(x) function tmp = code(x, y, z) tmp = -4.0 * (z * y); end
NOTE: x should be positive before calling this function code[x_, y_, z_] := N[(-4.0 * N[(z * y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
x = |x|\\
\\
-4 \cdot \left(z \cdot y\right)
\end{array}
Initial program 96.9%
Taylor expanded in x around 0 51.6%
Final simplification51.6%
herbie shell --seed 2023308
(FPCore (x y z)
:name "Graphics.Rasterific.QuadraticFormula:discriminant from Rasterific-0.6.1"
:precision binary64
(- (* x x) (* (* y 4.0) z)))