
(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+196) (fma x x (* z (* y -4.0))) (* x x)))
x = abs(x);
double code(double x, double y, double z) {
double tmp;
if (x <= 1e+196) {
tmp = fma(x, x, (z * (y * -4.0)));
} else {
tmp = x * x;
}
return tmp;
}
x = abs(x) function code(x, y, z) tmp = 0.0 if (x <= 1e+196) tmp = fma(x, x, Float64(z * Float64(y * -4.0))); else tmp = Float64(x * x); end return tmp end
NOTE: x should be positive before calling this function code[x_, y_, z_] := If[LessEqual[x, 1e+196], N[(x * x + N[(z * N[(y * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x * x), $MachinePrecision]]
\begin{array}{l}
x = |x|\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq 10^{+196}:\\
\;\;\;\;\mathsf{fma}\left(x, x, z \cdot \left(y \cdot -4\right)\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot x\\
\end{array}
\end{array}
if x < 9.9999999999999995e195Initial program 99.1%
fma-neg99.6%
*-commutative99.6%
distribute-rgt-neg-in99.6%
distribute-rgt-neg-in99.6%
metadata-eval99.6%
Simplified99.6%
if 9.9999999999999995e195 < x Initial program 86.7%
Taylor expanded in x around inf 100.0%
unpow2100.0%
Simplified100.0%
Final simplification99.6%
NOTE: x should be positive before calling this function (FPCore (x y z) :precision binary64 (fma y (* z -4.0) (* x x)))
x = abs(x);
double code(double x, double y, double z) {
return fma(y, (z * -4.0), (x * x));
}
x = abs(x) function code(x, y, z) return fma(y, Float64(z * -4.0), Float64(x * x)) end
NOTE: x should be positive before calling this function code[x_, y_, z_] := N[(y * N[(z * -4.0), $MachinePrecision] + N[(x * x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
x = |x|\\
\\
\mathsf{fma}\left(y, z \cdot -4, x \cdot x\right)
\end{array}
Initial program 97.6%
sub-neg97.6%
+-commutative97.6%
associate-*l*97.6%
distribute-rgt-neg-in97.6%
fma-def99.2%
*-commutative99.2%
distribute-rgt-neg-in99.2%
metadata-eval99.2%
Simplified99.2%
Final simplification99.2%
NOTE: x should be positive before calling this function (FPCore (x y z) :precision binary64 (if (<= x 6.8e+145) (- (* x x) (* z (* y 4.0))) (* x x)))
x = abs(x);
double code(double x, double y, double z) {
double tmp;
if (x <= 6.8e+145) {
tmp = (x * x) - (z * (y * 4.0));
} else {
tmp = x * x;
}
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 <= 6.8d+145) then
tmp = (x * x) - (z * (y * 4.0d0))
else
tmp = x * x
end if
code = tmp
end function
x = Math.abs(x);
public static double code(double x, double y, double z) {
double tmp;
if (x <= 6.8e+145) {
tmp = (x * x) - (z * (y * 4.0));
} else {
tmp = x * x;
}
return tmp;
}
x = abs(x) def code(x, y, z): tmp = 0 if x <= 6.8e+145: tmp = (x * x) - (z * (y * 4.0)) else: tmp = x * x return tmp
x = abs(x) function code(x, y, z) tmp = 0.0 if (x <= 6.8e+145) tmp = Float64(Float64(x * x) - Float64(z * Float64(y * 4.0))); else tmp = Float64(x * x); end return tmp end
x = abs(x) function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= 6.8e+145) tmp = (x * x) - (z * (y * 4.0)); else tmp = x * x; end tmp_2 = tmp; end
NOTE: x should be positive before calling this function code[x_, y_, z_] := If[LessEqual[x, 6.8e+145], N[(N[(x * x), $MachinePrecision] - N[(z * N[(y * 4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x * x), $MachinePrecision]]
\begin{array}{l}
x = |x|\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq 6.8 \cdot 10^{+145}:\\
\;\;\;\;x \cdot x - z \cdot \left(y \cdot 4\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot x\\
\end{array}
\end{array}
if x < 6.7999999999999998e145Initial program 99.5%
if 6.7999999999999998e145 < x Initial program 86.8%
Taylor expanded in x around inf 97.4%
unpow297.4%
Simplified97.4%
Final simplification99.2%
NOTE: x should be positive before calling this function (FPCore (x y z) :precision binary64 (if (<= (* x x) 1.8e-107) (* -4.0 (* y z)) (* x x)))
x = abs(x);
double code(double x, double y, double z) {
double tmp;
if ((x * x) <= 1.8e-107) {
tmp = -4.0 * (y * z);
} else {
tmp = x * x;
}
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 * x) <= 1.8d-107) then
tmp = (-4.0d0) * (y * z)
else
tmp = x * x
end if
code = tmp
end function
x = Math.abs(x);
public static double code(double x, double y, double z) {
double tmp;
if ((x * x) <= 1.8e-107) {
tmp = -4.0 * (y * z);
} else {
tmp = x * x;
}
return tmp;
}
x = abs(x) def code(x, y, z): tmp = 0 if (x * x) <= 1.8e-107: tmp = -4.0 * (y * z) else: tmp = x * x return tmp
x = abs(x) function code(x, y, z) tmp = 0.0 if (Float64(x * x) <= 1.8e-107) tmp = Float64(-4.0 * Float64(y * z)); else tmp = Float64(x * x); end return tmp end
x = abs(x) function tmp_2 = code(x, y, z) tmp = 0.0; if ((x * x) <= 1.8e-107) tmp = -4.0 * (y * z); else tmp = x * x; end tmp_2 = tmp; end
NOTE: x should be positive before calling this function code[x_, y_, z_] := If[LessEqual[N[(x * x), $MachinePrecision], 1.8e-107], N[(-4.0 * N[(y * z), $MachinePrecision]), $MachinePrecision], N[(x * x), $MachinePrecision]]
\begin{array}{l}
x = |x|\\
\\
\begin{array}{l}
\mathbf{if}\;x \cdot x \leq 1.8 \cdot 10^{-107}:\\
\;\;\;\;-4 \cdot \left(y \cdot z\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot x\\
\end{array}
\end{array}
if (*.f64 x x) < 1.79999999999999988e-107Initial program 100.0%
Taylor expanded in x around 0 91.3%
if 1.79999999999999988e-107 < (*.f64 x x) Initial program 96.0%
Taylor expanded in x around inf 82.4%
unpow282.4%
Simplified82.4%
Final simplification86.1%
NOTE: x should be positive before calling this function (FPCore (x y z) :precision binary64 (* x x))
x = abs(x);
double code(double x, double y, double z) {
return x * x;
}
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
end function
x = Math.abs(x);
public static double code(double x, double y, double z) {
return x * x;
}
x = abs(x) def code(x, y, z): return x * x
x = abs(x) function code(x, y, z) return Float64(x * x) end
x = abs(x) function tmp = code(x, y, z) tmp = x * x; end
NOTE: x should be positive before calling this function code[x_, y_, z_] := N[(x * x), $MachinePrecision]
\begin{array}{l}
x = |x|\\
\\
x \cdot x
\end{array}
Initial program 97.6%
Taylor expanded in x around inf 55.6%
unpow255.6%
Simplified55.6%
Final simplification55.6%
herbie shell --seed 2023221
(FPCore (x y z)
:name "Graphics.Rasterific.QuadraticFormula:discriminant from Rasterific-0.6.1"
:precision binary64
(- (* x x) (* (* y 4.0) z)))