
(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 4 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, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (fma (* z -4.0) y (* x x)))
assert(x < y && y < z);
double code(double x, double y, double z) {
return fma((z * -4.0), y, (x * x));
}
x, y, z = sort([x, y, z]) function code(x, y, z) return fma(Float64(z * -4.0), y, Float64(x * x)) end
NOTE: x, y, and z should be sorted in increasing order before calling this function. code[x_, y_, z_] := N[(N[(z * -4.0), $MachinePrecision] * y + N[(x * x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\mathsf{fma}\left(z \cdot -4, y, x \cdot x\right)
\end{array}
Initial program 98.8%
lift--.f64N/A
sub-negN/A
+-commutativeN/A
lift-*.f64N/A
lift-*.f64N/A
associate-*l*N/A
*-commutativeN/A
distribute-lft-neg-inN/A
lower-fma.f64N/A
distribute-lft-neg-inN/A
lower-*.f64N/A
metadata-eval99.2
Applied rewrites99.2%
Final simplification99.2%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (<= (* x x) 1.65e+149) (* y (* z -4.0)) (* x x)))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if ((x * x) <= 1.65e+149) {
tmp = y * (z * -4.0);
} else {
tmp = x * x;
}
return tmp;
}
NOTE: x, y, and z should be sorted in increasing order 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+149) then
tmp = y * (z * (-4.0d0))
else
tmp = x * x
end if
code = tmp
end function
assert x < y && y < z;
public static double code(double x, double y, double z) {
double tmp;
if ((x * x) <= 1.65e+149) {
tmp = y * (z * -4.0);
} else {
tmp = x * x;
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): tmp = 0 if (x * x) <= 1.65e+149: tmp = y * (z * -4.0) else: tmp = x * x return tmp
x, y, z = sort([x, y, z]) function code(x, y, z) tmp = 0.0 if (Float64(x * x) <= 1.65e+149) tmp = Float64(y * Float64(z * -4.0)); else tmp = Float64(x * x); end return tmp end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp_2 = code(x, y, z)
tmp = 0.0;
if ((x * x) <= 1.65e+149)
tmp = y * (z * -4.0);
else
tmp = x * x;
end
tmp_2 = tmp;
end
NOTE: x, y, and z should be sorted in increasing order before calling this function. code[x_, y_, z_] := If[LessEqual[N[(x * x), $MachinePrecision], 1.65e+149], N[(y * N[(z * -4.0), $MachinePrecision]), $MachinePrecision], N[(x * x), $MachinePrecision]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;x \cdot x \leq 1.65 \cdot 10^{+149}:\\
\;\;\;\;y \cdot \left(z \cdot -4\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot x\\
\end{array}
\end{array}
if (*.f64 x x) < 1.65e149Initial program 100.0%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f6481.3
Applied rewrites81.3%
Applied rewrites81.3%
if 1.65e149 < (*.f64 x x) Initial program 96.6%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f6412.1
Applied rewrites12.1%
Applied rewrites12.1%
Taylor expanded in x around inf
unpow2N/A
lower-*.f6494.4
Applied rewrites94.4%
Final simplification85.9%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (fma x x (* (* y z) -4.0)))
assert(x < y && y < z);
double code(double x, double y, double z) {
return fma(x, x, ((y * z) * -4.0));
}
x, y, z = sort([x, y, z]) function code(x, y, z) return fma(x, x, Float64(Float64(y * z) * -4.0)) end
NOTE: x, y, and z should be sorted in increasing order before calling this function. code[x_, y_, z_] := N[(x * x + N[(N[(y * z), $MachinePrecision] * -4.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\mathsf{fma}\left(x, x, \left(y \cdot z\right) \cdot -4\right)
\end{array}
Initial program 98.8%
lift--.f64N/A
sub-negN/A
lift-*.f64N/A
lower-fma.f64N/A
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
associate-*r*N/A
distribute-rgt-neg-inN/A
lower-*.f64N/A
lower-*.f64N/A
metadata-eval99.2
Applied rewrites99.2%
Final simplification99.2%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (* x x))
assert(x < y && y < z);
double code(double x, double y, double z) {
return x * x;
}
NOTE: x, y, and z should be sorted in increasing order 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
assert x < y && y < z;
public static double code(double x, double y, double z) {
return x * x;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): return x * x
x, y, z = sort([x, y, z]) function code(x, y, z) return Float64(x * x) end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp = code(x, y, z)
tmp = x * x;
end
NOTE: x, y, and z should be sorted in increasing order before calling this function. code[x_, y_, z_] := N[(x * x), $MachinePrecision]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
x \cdot x
\end{array}
Initial program 98.8%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f6457.3
Applied rewrites57.3%
Applied rewrites57.3%
Taylor expanded in x around inf
unpow2N/A
lower-*.f6450.5
Applied rewrites50.5%
herbie shell --seed 2024308
(FPCore (x y z)
:name "Graphics.Rasterific.QuadraticFormula:discriminant from Rasterific-0.6.1"
:precision binary64
(- (* x x) (* (* y 4.0) z)))