
(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: x, 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))
assert(x < y && y < z);
double code(double x, double y, double z) {
return fma(y, (z * -4.0), x);
}
x, y, z = sort([x, y, z]) function code(x, y, z) return fma(y, Float64(z * -4.0), x) end
NOTE: x, y, and z should be sorted in increasing order before calling this function. code[x_, y_, z_] := N[(y * N[(z * -4.0), $MachinePrecision] + x), $MachinePrecision]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\mathsf{fma}\left(y, z \cdot -4, x\right)
\end{array}
Initial program 100.0%
sub-neg100.0%
distribute-rgt-neg-out100.0%
+-commutative100.0%
associate-*l*99.6%
distribute-rgt-neg-in99.6%
*-commutative99.6%
fma-define99.6%
distribute-rgt-neg-in99.6%
metadata-eval99.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 (<= x -9.5e+133) x (if (<= x 1.22e+53) (* y (* z -4.0)) x)))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if (x <= -9.5e+133) {
tmp = x;
} else if (x <= 1.22e+53) {
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 (x <= (-9.5d+133)) then
tmp = x
else if (x <= 1.22d+53) 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 (x <= -9.5e+133) {
tmp = x;
} else if (x <= 1.22e+53) {
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 x <= -9.5e+133: tmp = x elif x <= 1.22e+53: 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 (x <= -9.5e+133) tmp = x; elseif (x <= 1.22e+53) 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 (x <= -9.5e+133)
tmp = x;
elseif (x <= 1.22e+53)
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[LessEqual[x, -9.5e+133], x, If[LessEqual[x, 1.22e+53], 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}\;x \leq -9.5 \cdot 10^{+133}:\\
\;\;\;\;x\\
\mathbf{elif}\;x \leq 1.22 \cdot 10^{+53}:\\
\;\;\;\;y \cdot \left(z \cdot -4\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if x < -9.49999999999999996e133 or 1.21999999999999999e53 < x Initial program 100.0%
associate-*l*98.9%
Simplified98.9%
Taylor expanded in x around inf 84.2%
if -9.49999999999999996e133 < x < 1.21999999999999999e53Initial program 100.0%
associate-*l*100.0%
Simplified100.0%
Taylor expanded in x around 0 73.0%
*-commutative73.0%
associate-*r*73.0%
Simplified73.0%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (- x (* y (* z 4.0))))
assert(x < y && y < z);
double code(double x, double y, double z) {
return x - (y * (z * 4.0));
}
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 * (z * 4.0d0))
end function
assert x < y && y < z;
public static double code(double x, double y, double z) {
return x - (y * (z * 4.0));
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): return x - (y * (z * 4.0))
x, y, z = sort([x, y, z]) function code(x, y, z) return Float64(x - Float64(y * Float64(z * 4.0))) end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp = code(x, y, z)
tmp = x - (y * (z * 4.0));
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[(z * 4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
x - y \cdot \left(z \cdot 4\right)
\end{array}
Initial program 100.0%
associate-*l*99.6%
Simplified99.6%
Final simplification99.6%
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 48.4%
herbie shell --seed 2024149
(FPCore (x y z)
:name "Diagrams.Solve.Polynomial:quadForm from diagrams-solve-0.1, A"
:precision binary64
(- x (* (* y 4.0) z)))