
(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 4 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 (fma z (* y -4.0) x))
assert(y < z);
double code(double x, double y, double z) {
return fma(z, (y * -4.0), x);
}
y, z = sort([y, z]) function code(x, y, z) return fma(z, Float64(y * -4.0), x) end
NOTE: y and z should be sorted in increasing order before calling this function. code[x_, y_, z_] := N[(z * N[(y * -4.0), $MachinePrecision] + x), $MachinePrecision]
\begin{array}{l}
[y, z] = \mathsf{sort}([y, z])\\
\\
\mathsf{fma}\left(z, y \cdot -4, x\right)
\end{array}
Initial program 99.6%
sub-neg99.6%
distribute-rgt-neg-out99.6%
+-commutative99.6%
distribute-rgt-neg-out99.6%
distribute-lft-neg-in99.6%
*-commutative99.6%
fma-def99.7%
distribute-rgt-neg-in99.7%
metadata-eval99.7%
Simplified99.7%
Final simplification99.7%
NOTE: y and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (or (<= z -1.75e-180) (not (<= z 92000000000000.0))) (* -4.0 (* z y)) x))
assert(y < z);
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.75e-180) || !(z <= 92000000000000.0)) {
tmp = -4.0 * (z * y);
} 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 ((z <= (-1.75d-180)) .or. (.not. (z <= 92000000000000.0d0))) then
tmp = (-4.0d0) * (z * y)
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 ((z <= -1.75e-180) || !(z <= 92000000000000.0)) {
tmp = -4.0 * (z * y);
} else {
tmp = x;
}
return tmp;
}
[y, z] = sort([y, z]) def code(x, y, z): tmp = 0 if (z <= -1.75e-180) or not (z <= 92000000000000.0): tmp = -4.0 * (z * y) else: tmp = x return tmp
y, z = sort([y, z]) function code(x, y, z) tmp = 0.0 if ((z <= -1.75e-180) || !(z <= 92000000000000.0)) tmp = Float64(-4.0 * Float64(z * y)); else tmp = x; end return tmp end
y, z = num2cell(sort([y, z])){:}
function tmp_2 = code(x, y, z)
tmp = 0.0;
if ((z <= -1.75e-180) || ~((z <= 92000000000000.0)))
tmp = -4.0 * (z * y);
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[z, -1.75e-180], N[Not[LessEqual[z, 92000000000000.0]], $MachinePrecision]], N[(-4.0 * N[(z * y), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}
[y, z] = \mathsf{sort}([y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.75 \cdot 10^{-180} \lor \neg \left(z \leq 92000000000000\right):\\
\;\;\;\;-4 \cdot \left(z \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -1.75e-180 or 9.2e13 < z Initial program 99.5%
Taylor expanded in x around 0 66.4%
if -1.75e-180 < z < 9.2e13Initial program 100.0%
Taylor expanded in x around inf 70.8%
Final simplification67.7%
NOTE: y and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (- x (* z (* y 4.0))))
assert(y < z);
double code(double x, double y, double z) {
return x - (z * (y * 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 - (z * (y * 4.0d0))
end function
assert y < z;
public static double code(double x, double y, double z) {
return x - (z * (y * 4.0));
}
[y, z] = sort([y, z]) def code(x, y, z): return x - (z * (y * 4.0))
y, z = sort([y, z]) function code(x, y, z) return Float64(x - Float64(z * Float64(y * 4.0))) end
y, z = num2cell(sort([y, z])){:}
function tmp = code(x, y, z)
tmp = x - (z * (y * 4.0));
end
NOTE: y and z should be sorted in increasing order before calling this function. code[x_, y_, z_] := N[(x - N[(z * N[(y * 4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[y, z] = \mathsf{sort}([y, z])\\
\\
x - z \cdot \left(y \cdot 4\right)
\end{array}
Initial program 99.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)
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 99.6%
Taylor expanded in x around inf 45.6%
Final simplification45.6%
herbie shell --seed 2023287
(FPCore (x y z)
:name "Diagrams.Solve.Polynomial:quadForm from diagrams-solve-0.1, A"
:precision binary64
(- x (* (* y 4.0) z)))