
(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: y and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (fma y (* z -4.0) (* x x)))
assert(y < z);
double code(double x, double y, double z) {
return fma(y, (z * -4.0), (x * x));
}
y, z = sort([y, z]) function code(x, y, z) return fma(y, Float64(z * -4.0), Float64(x * x)) end
NOTE: y and z should be sorted in increasing order before calling this function. code[x_, y_, z_] := N[(y * N[(z * -4.0), $MachinePrecision] + N[(x * x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[y, z] = \mathsf{sort}([y, z])\\
\\
\mathsf{fma}\left(y, z \cdot -4, x \cdot x\right)
\end{array}
Initial program 98.0%
sub-neg98.0%
+-commutative98.0%
associate-*l*98.0%
distribute-rgt-neg-in98.0%
fma-def99.2%
*-commutative99.2%
distribute-rgt-neg-in99.2%
metadata-eval99.2%
Simplified99.2%
Final simplification99.2%
NOTE: y and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (fma x x (* z (* y -4.0))))
assert(y < z);
double code(double x, double y, double z) {
return fma(x, x, (z * (y * -4.0)));
}
y, z = sort([y, z]) function code(x, y, z) return fma(x, x, Float64(z * Float64(y * -4.0))) end
NOTE: y and z should be sorted in increasing order before calling this function. code[x_, y_, z_] := N[(x * x + N[(z * N[(y * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[y, z] = \mathsf{sort}([y, z])\\
\\
\mathsf{fma}\left(x, x, z \cdot \left(y \cdot -4\right)\right)
\end{array}
Initial program 98.0%
fma-neg98.4%
*-commutative98.4%
distribute-rgt-neg-in98.4%
distribute-rgt-neg-in98.4%
metadata-eval98.4%
Simplified98.4%
Final simplification98.4%
NOTE: y and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (<= x -5.4e+54) (* x x) (if (<= x 2.4e-9) (* -4.0 (* y z)) (* x x))))
assert(y < z);
double code(double x, double y, double z) {
double tmp;
if (x <= -5.4e+54) {
tmp = x * x;
} else if (x <= 2.4e-9) {
tmp = -4.0 * (y * z);
} else {
tmp = x * x;
}
return tmp;
}
NOTE: 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 <= (-5.4d+54)) then
tmp = x * x
else if (x <= 2.4d-9) then
tmp = (-4.0d0) * (y * z)
else
tmp = x * x
end if
code = tmp
end function
assert y < z;
public static double code(double x, double y, double z) {
double tmp;
if (x <= -5.4e+54) {
tmp = x * x;
} else if (x <= 2.4e-9) {
tmp = -4.0 * (y * z);
} else {
tmp = x * x;
}
return tmp;
}
[y, z] = sort([y, z]) def code(x, y, z): tmp = 0 if x <= -5.4e+54: tmp = x * x elif x <= 2.4e-9: tmp = -4.0 * (y * z) else: tmp = x * x return tmp
y, z = sort([y, z]) function code(x, y, z) tmp = 0.0 if (x <= -5.4e+54) tmp = Float64(x * x); elseif (x <= 2.4e-9) tmp = Float64(-4.0 * Float64(y * z)); else tmp = Float64(x * x); end return tmp end
y, z = num2cell(sort([y, z])){:}
function tmp_2 = code(x, y, z)
tmp = 0.0;
if (x <= -5.4e+54)
tmp = x * x;
elseif (x <= 2.4e-9)
tmp = -4.0 * (y * z);
else
tmp = x * x;
end
tmp_2 = tmp;
end
NOTE: y and z should be sorted in increasing order before calling this function. code[x_, y_, z_] := If[LessEqual[x, -5.4e+54], N[(x * x), $MachinePrecision], If[LessEqual[x, 2.4e-9], N[(-4.0 * N[(y * z), $MachinePrecision]), $MachinePrecision], N[(x * x), $MachinePrecision]]]
\begin{array}{l}
[y, z] = \mathsf{sort}([y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq -5.4 \cdot 10^{+54}:\\
\;\;\;\;x \cdot x\\
\mathbf{elif}\;x \leq 2.4 \cdot 10^{-9}:\\
\;\;\;\;-4 \cdot \left(y \cdot z\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot x\\
\end{array}
\end{array}
if x < -5.40000000000000022e54 or 2.4e-9 < x Initial program 96.9%
associate-*l*96.1%
Simplified96.1%
Taylor expanded in x around inf 84.6%
unpow284.6%
Simplified84.6%
if -5.40000000000000022e54 < x < 2.4e-9Initial program 99.2%
associate-*l*100.0%
Simplified100.0%
Taylor expanded in x around 0 89.9%
Final simplification87.3%
NOTE: y and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (- (* x x) (* y (* z 4.0))))
assert(y < z);
double code(double x, double y, double z) {
return (x * x) - (y * (z * 4.0));
}
NOTE: 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) - (y * (z * 4.0d0))
end function
assert y < z;
public static double code(double x, double y, double z) {
return (x * x) - (y * (z * 4.0));
}
[y, z] = sort([y, z]) def code(x, y, z): return (x * x) - (y * (z * 4.0))
y, z = sort([y, z]) function code(x, y, z) return Float64(Float64(x * x) - Float64(y * Float64(z * 4.0))) end
y, z = num2cell(sort([y, z])){:}
function tmp = code(x, y, z)
tmp = (x * x) - (y * (z * 4.0));
end
NOTE: y and z should be sorted in increasing order before calling this function. code[x_, y_, z_] := N[(N[(x * x), $MachinePrecision] - N[(y * N[(z * 4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[y, z] = \mathsf{sort}([y, z])\\
\\
x \cdot x - y \cdot \left(z \cdot 4\right)
\end{array}
Initial program 98.0%
associate-*l*98.0%
Simplified98.0%
Final simplification98.0%
NOTE: y and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (* x x))
assert(y < z);
double code(double x, double y, double z) {
return x * x;
}
NOTE: 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 y < z;
public static double code(double x, double y, double z) {
return x * x;
}
[y, z] = sort([y, z]) def code(x, y, z): return x * x
y, z = sort([y, z]) function code(x, y, z) return Float64(x * x) end
y, z = num2cell(sort([y, z])){:}
function tmp = code(x, y, z)
tmp = x * x;
end
NOTE: y and z should be sorted in increasing order before calling this function. code[x_, y_, z_] := N[(x * x), $MachinePrecision]
\begin{array}{l}
[y, z] = \mathsf{sort}([y, z])\\
\\
x \cdot x
\end{array}
Initial program 98.0%
associate-*l*98.0%
Simplified98.0%
Taylor expanded in x around inf 51.1%
unpow251.1%
Simplified51.1%
Final simplification51.1%
herbie shell --seed 2023182
(FPCore (x y z)
:name "Graphics.Rasterific.QuadraticFormula:discriminant from Rasterific-0.6.1"
:precision binary64
(- (* x x) (* (* y 4.0) z)))