
(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 100.0%
sub-neg100.0%
+-commutative100.0%
associate-*l*99.6%
distribute-rgt-neg-in99.6%
fma-def99.6%
*-commutative99.6%
distribute-rgt-neg-in99.6%
metadata-eval99.6%
Simplified99.6%
Final simplification99.6%
NOTE: y and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (<= x -9.5e-15) (* x x) (if (<= x 6.6e+27) (* -4.0 (* y z)) (* x x))))
assert(y < z);
double code(double x, double y, double z) {
double tmp;
if (x <= -9.5e-15) {
tmp = x * x;
} else if (x <= 6.6e+27) {
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 <= (-9.5d-15)) then
tmp = x * x
else if (x <= 6.6d+27) 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 <= -9.5e-15) {
tmp = x * x;
} else if (x <= 6.6e+27) {
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 <= -9.5e-15: tmp = x * x elif x <= 6.6e+27: 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 <= -9.5e-15) tmp = Float64(x * x); elseif (x <= 6.6e+27) 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 <= -9.5e-15)
tmp = x * x;
elseif (x <= 6.6e+27)
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, -9.5e-15], N[(x * x), $MachinePrecision], If[LessEqual[x, 6.6e+27], 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 -9.5 \cdot 10^{-15}:\\
\;\;\;\;x \cdot x\\
\mathbf{elif}\;x \leq 6.6 \cdot 10^{+27}:\\
\;\;\;\;-4 \cdot \left(y \cdot z\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot x\\
\end{array}
\end{array}
if x < -9.5000000000000005e-15 or 6.5999999999999996e27 < x Initial program 100.0%
associate-*l*100.0%
Simplified100.0%
Taylor expanded in x around inf 83.0%
unpow283.0%
Simplified83.0%
if -9.5000000000000005e-15 < x < 6.5999999999999996e27Initial program 100.0%
associate-*l*99.2%
Simplified99.2%
Taylor expanded in x around 0 87.3%
Final simplification85.2%
NOTE: y and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (<= x -5.4e-15) (* x x) (if (<= x 3.9e+27) (* y (* z -4.0)) (* x x))))
assert(y < z);
double code(double x, double y, double z) {
double tmp;
if (x <= -5.4e-15) {
tmp = x * x;
} else if (x <= 3.9e+27) {
tmp = y * (z * -4.0);
} 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-15)) then
tmp = x * x
else if (x <= 3.9d+27) then
tmp = y * (z * (-4.0d0))
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-15) {
tmp = x * x;
} else if (x <= 3.9e+27) {
tmp = y * (z * -4.0);
} else {
tmp = x * x;
}
return tmp;
}
[y, z] = sort([y, z]) def code(x, y, z): tmp = 0 if x <= -5.4e-15: tmp = x * x elif x <= 3.9e+27: tmp = y * (z * -4.0) else: tmp = x * x return tmp
y, z = sort([y, z]) function code(x, y, z) tmp = 0.0 if (x <= -5.4e-15) tmp = Float64(x * x); elseif (x <= 3.9e+27) tmp = Float64(y * Float64(z * -4.0)); 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-15)
tmp = x * x;
elseif (x <= 3.9e+27)
tmp = y * (z * -4.0);
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-15], N[(x * x), $MachinePrecision], If[LessEqual[x, 3.9e+27], N[(y * N[(z * -4.0), $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^{-15}:\\
\;\;\;\;x \cdot x\\
\mathbf{elif}\;x \leq 3.9 \cdot 10^{+27}:\\
\;\;\;\;y \cdot \left(z \cdot -4\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot x\\
\end{array}
\end{array}
if x < -5.40000000000000018e-15 or 3.8999999999999999e27 < x Initial program 100.0%
associate-*l*100.0%
Simplified100.0%
Taylor expanded in x around inf 83.0%
unpow283.0%
Simplified83.0%
if -5.40000000000000018e-15 < x < 3.8999999999999999e27Initial program 100.0%
associate-*l*99.2%
Simplified99.2%
Taylor expanded in x around 0 87.3%
expm1-log1p-u59.3%
expm1-udef38.9%
log1p-udef38.9%
add-exp-log66.9%
Applied egg-rr66.9%
+-commutative66.9%
associate--l+87.3%
*-commutative87.3%
metadata-eval87.3%
associate-*l*86.6%
Simplified86.6%
Final simplification84.8%
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 100.0%
associate-*l*99.6%
Simplified99.6%
Final simplification99.6%
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 100.0%
associate-*l*99.6%
Simplified99.6%
Taylor expanded in x around inf 53.0%
unpow253.0%
Simplified53.0%
Final simplification53.0%
herbie shell --seed 2023195
(FPCore (x y z)
:name "Graphics.Rasterific.QuadraticFormula:discriminant from Rasterific-0.6.1"
:precision binary64
(- (* x x) (* (* y 4.0) z)))