
(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 8.5e+172) (fma x x (* y (* z -4.0))) (* x x)))
x = abs(x);
double code(double x, double y, double z) {
double tmp;
if (x <= 8.5e+172) {
tmp = fma(x, x, (y * (z * -4.0)));
} else {
tmp = x * x;
}
return tmp;
}
x = abs(x) function code(x, y, z) tmp = 0.0 if (x <= 8.5e+172) tmp = fma(x, x, Float64(y * Float64(z * -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, 8.5e+172], N[(x * x + N[(y * N[(z * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x * x), $MachinePrecision]]
\begin{array}{l}
x = |x|\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq 8.5 \cdot 10^{+172}:\\
\;\;\;\;\mathsf{fma}\left(x, x, y \cdot \left(z \cdot -4\right)\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot x\\
\end{array}
\end{array}
if x < 8.50000000000000053e172Initial program 97.3%
fma-neg98.2%
*-commutative98.2%
*-commutative98.2%
associate-*l*98.2%
distribute-lft-neg-in98.2%
*-commutative98.2%
distribute-rgt-neg-in98.2%
metadata-eval98.2%
Simplified98.2%
if 8.50000000000000053e172 < x Initial program 94.3%
Taylor expanded in x around inf 100.0%
unpow2100.0%
Simplified100.0%
Final simplification98.4%
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 96.9%
sub-neg96.9%
+-commutative96.9%
distribute-rgt-neg-out96.9%
associate-*l*96.9%
fma-def99.2%
*-commutative99.2%
distribute-lft-neg-in99.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 1.15e+146) (- (* x x) (* z (* y 4.0))) (* x x)))
x = abs(x);
double code(double x, double y, double z) {
double tmp;
if (x <= 1.15e+146) {
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 <= 1.15d+146) 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 <= 1.15e+146) {
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 <= 1.15e+146: 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 <= 1.15e+146) 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 <= 1.15e+146) 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, 1.15e+146], 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 1.15 \cdot 10^{+146}:\\
\;\;\;\;x \cdot x - z \cdot \left(y \cdot 4\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot x\\
\end{array}
\end{array}
if x < 1.15e146Initial program 97.2%
if 1.15e146 < x Initial program 94.9%
Taylor expanded in x around inf 100.0%
unpow2100.0%
Simplified100.0%
Final simplification97.7%
NOTE: x should be positive before calling this function (FPCore (x y z) :precision binary64 (if (<= (* x x) 1.65e+117) (* y (* z -4.0)) (* x x)))
x = abs(x);
double code(double x, double y, double z) {
double tmp;
if ((x * x) <= 1.65e+117) {
tmp = y * (z * -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 * x) <= 1.65d+117) then
tmp = y * (z * (-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 * x) <= 1.65e+117) {
tmp = y * (z * -4.0);
} else {
tmp = x * x;
}
return tmp;
}
x = abs(x) def code(x, y, z): tmp = 0 if (x * x) <= 1.65e+117: tmp = y * (z * -4.0) else: tmp = x * x return tmp
x = abs(x) function code(x, y, z) tmp = 0.0 if (Float64(x * x) <= 1.65e+117) tmp = Float64(y * Float64(z * -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 * x) <= 1.65e+117) tmp = y * (z * -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[N[(x * x), $MachinePrecision], 1.65e+117], N[(y * N[(z * -4.0), $MachinePrecision]), $MachinePrecision], N[(x * x), $MachinePrecision]]
\begin{array}{l}
x = |x|\\
\\
\begin{array}{l}
\mathbf{if}\;x \cdot x \leq 1.65 \cdot 10^{+117}:\\
\;\;\;\;y \cdot \left(z \cdot -4\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot x\\
\end{array}
\end{array}
if (*.f64 x x) < 1.6499999999999999e117Initial program 100.0%
Taylor expanded in x around 0 78.4%
*-commutative78.4%
associate-*r*78.4%
*-commutative78.4%
Simplified78.4%
if 1.6499999999999999e117 < (*.f64 x x) Initial program 93.3%
Taylor expanded in x around inf 91.8%
unpow291.9%
Simplified91.9%
Final simplification84.7%
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 96.9%
Taylor expanded in x around inf 57.9%
unpow257.9%
Simplified57.9%
Final simplification57.9%
herbie shell --seed 2023297
(FPCore (x y z)
:name "Graphics.Rasterific.QuadraticFormula:discriminant from Rasterific-0.6.1"
:precision binary64
(- (* x x) (* (* y 4.0) z)))