
(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 97.7%
sub-neg97.7%
+-commutative97.7%
associate-*l*97.3%
distribute-rgt-neg-in97.3%
fma-def98.9%
*-commutative98.9%
distribute-rgt-neg-in98.9%
metadata-eval98.9%
Simplified98.9%
Final simplification98.9%
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 97.7%
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 (or (<= (* x x) 1.3e-64)
(and (not (<= (* x x) 140.0)) (<= (* x x) 2.2e+94)))
(* y (* z -4.0))
(* x x)))assert(y < z);
double code(double x, double y, double z) {
double tmp;
if (((x * x) <= 1.3e-64) || (!((x * x) <= 140.0) && ((x * x) <= 2.2e+94))) {
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 * x) <= 1.3d-64) .or. (.not. ((x * x) <= 140.0d0)) .and. ((x * x) <= 2.2d+94)) 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 * x) <= 1.3e-64) || (!((x * x) <= 140.0) && ((x * x) <= 2.2e+94))) {
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 * x) <= 1.3e-64) or (not ((x * x) <= 140.0) and ((x * x) <= 2.2e+94)): 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 ((Float64(x * x) <= 1.3e-64) || (!(Float64(x * x) <= 140.0) && (Float64(x * x) <= 2.2e+94))) 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 * x) <= 1.3e-64) || (~(((x * x) <= 140.0)) && ((x * x) <= 2.2e+94)))
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[Or[LessEqual[N[(x * x), $MachinePrecision], 1.3e-64], And[N[Not[LessEqual[N[(x * x), $MachinePrecision], 140.0]], $MachinePrecision], LessEqual[N[(x * x), $MachinePrecision], 2.2e+94]]], 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 \cdot x \leq 1.3 \cdot 10^{-64} \lor \neg \left(x \cdot x \leq 140\right) \land x \cdot x \leq 2.2 \cdot 10^{+94}:\\
\;\;\;\;y \cdot \left(z \cdot -4\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot x\\
\end{array}
\end{array}
if (*.f64 x x) < 1.3e-64 or 140 < (*.f64 x x) < 2.20000000000000012e94Initial program 100.0%
associate-*l*100.0%
Simplified100.0%
Taylor expanded in x around 0 87.5%
associate-*r*87.5%
*-commutative87.5%
associate-*l*87.5%
Simplified87.5%
if 1.3e-64 < (*.f64 x x) < 140 or 2.20000000000000012e94 < (*.f64 x x) Initial program 95.6%
associate-*l*94.9%
Simplified94.9%
Taylor expanded in x around inf 89.4%
unpow289.4%
Simplified89.4%
Final simplification88.5%
NOTE: y and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (<= (* x x) 1.6e+294) (- (* x x) (* y (* z 4.0))) (* x x)))
assert(y < z);
double code(double x, double y, double z) {
double tmp;
if ((x * x) <= 1.6e+294) {
tmp = (x * x) - (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 * x) <= 1.6d+294) then
tmp = (x * x) - (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 * x) <= 1.6e+294) {
tmp = (x * x) - (y * (z * 4.0));
} else {
tmp = x * x;
}
return tmp;
}
[y, z] = sort([y, z]) def code(x, y, z): tmp = 0 if (x * x) <= 1.6e+294: tmp = (x * x) - (y * (z * 4.0)) else: tmp = x * x return tmp
y, z = sort([y, z]) function code(x, y, z) tmp = 0.0 if (Float64(x * x) <= 1.6e+294) tmp = Float64(Float64(x * x) - 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 * x) <= 1.6e+294)
tmp = (x * x) - (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[N[(x * x), $MachinePrecision], 1.6e+294], N[(N[(x * x), $MachinePrecision] - N[(y * N[(z * 4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x * x), $MachinePrecision]]
\begin{array}{l}
[y, z] = \mathsf{sort}([y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;x \cdot x \leq 1.6 \cdot 10^{+294}:\\
\;\;\;\;x \cdot x - y \cdot \left(z \cdot 4\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot x\\
\end{array}
\end{array}
if (*.f64 x x) < 1.5999999999999999e294Initial program 100.0%
associate-*l*100.0%
Simplified100.0%
if 1.5999999999999999e294 < (*.f64 x x) Initial program 92.7%
associate-*l*91.6%
Simplified91.6%
Taylor expanded in x around inf 97.6%
unpow297.6%
Simplified97.6%
Final simplification99.2%
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 97.7%
associate-*l*97.3%
Simplified97.3%
Taylor expanded in x around inf 56.1%
unpow256.1%
Simplified56.1%
Final simplification56.1%
herbie shell --seed 2023230
(FPCore (x y z)
:name "Graphics.Rasterific.QuadraticFormula:discriminant from Rasterific-0.6.1"
:precision binary64
(- (* x x) (* (* y 4.0) z)))