
(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: 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(y < z);
double code(double x, double y, double z) {
return x - (y * (4.0 * z));
}
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 - (y * (4.0d0 * z))
end function
assert y < z;
public static double code(double x, double y, double z) {
return x - (y * (4.0 * z));
}
[y, z] = sort([y, z]) def code(x, y, z): return x - (y * (4.0 * z))
y, z = sort([y, z]) function code(x, y, z) return Float64(x - Float64(y * Float64(4.0 * z))) end
y, z = num2cell(sort([y, z])){:}
function tmp = code(x, y, z)
tmp = x - (y * (4.0 * z));
end
NOTE: 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}
[y, z] = \mathsf{sort}([y, z])\\
\\
x - y \cdot \left(4 \cdot z\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 (if (or (<= y -6.2e+117) (not (<= y 4e-160))) (* y (* z -4.0)) x))
assert(y < z);
double code(double x, double y, double z) {
double tmp;
if ((y <= -6.2e+117) || !(y <= 4e-160)) {
tmp = y * (z * -4.0);
} else {
tmp = 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 ((y <= (-6.2d+117)) .or. (.not. (y <= 4d-160))) then
tmp = y * (z * (-4.0d0))
else
tmp = x
end if
code = tmp
end function
assert y < z;
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -6.2e+117) || !(y <= 4e-160)) {
tmp = y * (z * -4.0);
} else {
tmp = x;
}
return tmp;
}
[y, z] = sort([y, z]) def code(x, y, z): tmp = 0 if (y <= -6.2e+117) or not (y <= 4e-160): tmp = y * (z * -4.0) else: tmp = x return tmp
y, z = sort([y, z]) function code(x, y, z) tmp = 0.0 if ((y <= -6.2e+117) || !(y <= 4e-160)) tmp = Float64(y * Float64(z * -4.0)); else tmp = x; end return tmp end
y, z = num2cell(sort([y, z])){:}
function tmp_2 = code(x, y, z)
tmp = 0.0;
if ((y <= -6.2e+117) || ~((y <= 4e-160)))
tmp = y * (z * -4.0);
else
tmp = 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[y, -6.2e+117], N[Not[LessEqual[y, 4e-160]], $MachinePrecision]], N[(y * N[(z * -4.0), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}
[y, z] = \mathsf{sort}([y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;y \leq -6.2 \cdot 10^{+117} \lor \neg \left(y \leq 4 \cdot 10^{-160}\right):\\
\;\;\;\;y \cdot \left(z \cdot -4\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -6.1999999999999995e117 or 4e-160 < y Initial program 100.0%
associate-*l*99.3%
Simplified99.3%
Taylor expanded in x around 0 64.8%
associate-*r*64.8%
*-commutative64.8%
associate-*r*64.0%
Simplified64.0%
if -6.1999999999999995e117 < y < 4e-160Initial program 100.0%
associate-*l*100.0%
Simplified100.0%
Taylor expanded in x around inf 71.3%
Final simplification67.6%
NOTE: y and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 x)
assert(y < z);
double code(double x, double y, double z) {
return 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
end function
assert y < z;
public static double code(double x, double y, double z) {
return x;
}
[y, z] = sort([y, z]) def code(x, y, z): return x
y, z = sort([y, z]) function code(x, y, z) return x end
y, z = num2cell(sort([y, z])){:}
function tmp = code(x, y, z)
tmp = x;
end
NOTE: y and z should be sorted in increasing order before calling this function. code[x_, y_, z_] := x
\begin{array}{l}
[y, z] = \mathsf{sort}([y, z])\\
\\
x
\end{array}
Initial program 100.0%
associate-*l*99.6%
Simplified99.6%
Taylor expanded in x around inf 54.2%
Final simplification54.2%
herbie shell --seed 2023275
(FPCore (x y z)
:name "Diagrams.Solve.Polynomial:quadForm from diagrams-solve-0.1, A"
:precision binary64
(- x (* (* y 4.0) z)))