
(FPCore (x y z) :precision binary64 (- x (* (* y 4.0) z)))
double code(double x, double y, double z) {
return 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 - ((y * 4.0d0) * z)
end function
public static double code(double x, double y, double z) {
return x - ((y * 4.0) * z);
}
def code(x, y, z): return x - ((y * 4.0) * z)
function code(x, y, z) return Float64(x - Float64(Float64(y * 4.0) * z)) end
function tmp = code(x, y, z) tmp = x - ((y * 4.0) * z); end
code[x_, y_, z_] := N[(x - N[(N[(y * 4.0), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x - \left(y \cdot 4\right) \cdot z
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 3 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (- x (* (* y 4.0) z)))
double code(double x, double y, double z) {
return 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 - ((y * 4.0d0) * z)
end function
public static double code(double x, double y, double z) {
return x - ((y * 4.0) * z);
}
def code(x, y, z): return x - ((y * 4.0) * z)
function code(x, y, z) return Float64(x - Float64(Float64(y * 4.0) * z)) end
function tmp = code(x, y, z) tmp = x - ((y * 4.0) * z); end
code[x_, y_, z_] := N[(x - N[(N[(y * 4.0), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
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 (- x (* y (* 4.0 z))))
assert(x < y && y < z);
double code(double x, double y, double z) {
return x - (y * (4.0 * z));
}
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 - (y * (4.0d0 * z))
end function
assert x < y && y < z;
public static double code(double x, double y, double z) {
return x - (y * (4.0 * z));
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): return x - (y * (4.0 * z))
x, y, z = sort([x, y, z]) function code(x, y, z) return Float64(x - Float64(y * Float64(4.0 * z))) end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp = code(x, y, z)
tmp = x - (y * (4.0 * z));
end
NOTE: x, y, and z should be sorted in increasing order before calling this function. code[x_, y_, z_] := N[(x - N[(y * N[(4.0 * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
x - y \cdot \left(4 \cdot z\right)
\end{array}
Initial program 100.0%
associate-*l*99.6%
Simplified99.6%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (or (<= z -1.56e-21) (not (<= z 4.6e-44))) (* y (* z -4.0)) x))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.56e-21) || !(z <= 4.6e-44)) {
tmp = y * (z * -4.0);
} else {
tmp = 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 ((z <= (-1.56d-21)) .or. (.not. (z <= 4.6d-44))) then
tmp = y * (z * (-4.0d0))
else
tmp = 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 ((z <= -1.56e-21) || !(z <= 4.6e-44)) {
tmp = y * (z * -4.0);
} else {
tmp = x;
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): tmp = 0 if (z <= -1.56e-21) or not (z <= 4.6e-44): tmp = y * (z * -4.0) else: tmp = x return tmp
x, y, z = sort([x, y, z]) function code(x, y, z) tmp = 0.0 if ((z <= -1.56e-21) || !(z <= 4.6e-44)) tmp = Float64(y * Float64(z * -4.0)); else tmp = x; end return tmp end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp_2 = code(x, y, z)
tmp = 0.0;
if ((z <= -1.56e-21) || ~((z <= 4.6e-44)))
tmp = y * (z * -4.0);
else
tmp = 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[Or[LessEqual[z, -1.56e-21], N[Not[LessEqual[z, 4.6e-44]], $MachinePrecision]], N[(y * N[(z * -4.0), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.56 \cdot 10^{-21} \lor \neg \left(z \leq 4.6 \cdot 10^{-44}\right):\\
\;\;\;\;y \cdot \left(z \cdot -4\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -1.55999999999999999e-21 or 4.59999999999999996e-44 < z Initial program 100.0%
associate-*l*99.4%
Simplified99.4%
Taylor expanded in x around 0 68.7%
*-commutative68.7%
associate-*r*68.1%
Simplified68.1%
if -1.55999999999999999e-21 < z < 4.59999999999999996e-44Initial program 100.0%
associate-*l*100.0%
Simplified100.0%
Taylor expanded in x around inf 76.4%
Final simplification71.4%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 x)
assert(x < y && y < z);
double code(double x, double y, double z) {
return 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
end function
assert x < y && y < z;
public static double code(double x, double y, double z) {
return x;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): return x
x, y, z = sort([x, y, z]) function code(x, y, z) return x end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp = code(x, y, z)
tmp = x;
end
NOTE: x, y, and z should be sorted in increasing order before calling this function. code[x_, y_, z_] := x
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
x
\end{array}
Initial program 100.0%
associate-*l*99.6%
Simplified99.6%
Taylor expanded in x around inf 49.8%
herbie shell --seed 2024160
(FPCore (x y z)
:name "Diagrams.Solve.Polynomial:quadForm from diagrams-solve-0.1, A"
:precision binary64
(- x (* (* y 4.0) z)))