
(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%
+-commutative99.6%
*-commutative99.6%
distribute-rgt-neg-in99.6%
fma-def99.6%
distribute-rgt-neg-in99.6%
metadata-eval99.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 (<= x -1.72e-15) x (if (<= x 0.0026) (* -4.0 (* z y)) x)))
assert(y < z);
double code(double x, double y, double z) {
double tmp;
if (x <= -1.72e-15) {
tmp = x;
} else if (x <= 0.0026) {
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 (x <= (-1.72d-15)) then
tmp = x
else if (x <= 0.0026d0) 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 (x <= -1.72e-15) {
tmp = x;
} else if (x <= 0.0026) {
tmp = -4.0 * (z * y);
} else {
tmp = x;
}
return tmp;
}
[y, z] = sort([y, z]) def code(x, y, z): tmp = 0 if x <= -1.72e-15: tmp = x elif x <= 0.0026: tmp = -4.0 * (z * y) else: tmp = x return tmp
y, z = sort([y, z]) function code(x, y, z) tmp = 0.0 if (x <= -1.72e-15) tmp = x; elseif (x <= 0.0026) 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 (x <= -1.72e-15)
tmp = x;
elseif (x <= 0.0026)
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[LessEqual[x, -1.72e-15], x, If[LessEqual[x, 0.0026], N[(-4.0 * N[(z * y), $MachinePrecision]), $MachinePrecision], x]]
\begin{array}{l}
[y, z] = \mathsf{sort}([y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.72 \cdot 10^{-15}:\\
\;\;\;\;x\\
\mathbf{elif}\;x \leq 0.0026:\\
\;\;\;\;-4 \cdot \left(z \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if x < -1.7199999999999999e-15 or 0.0025999999999999999 < x Initial program 99.3%
Taylor expanded in x around inf 78.6%
if -1.7199999999999999e-15 < x < 0.0025999999999999999Initial program 100.0%
Taylor expanded in x around 0 77.9%
Final simplification78.3%
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 53.1%
Final simplification53.1%
herbie shell --seed 2023214
(FPCore (x y z)
:name "Diagrams.Solve.Polynomial:quadForm from diagrams-solve-0.1, A"
:precision binary64
(- x (* (* y 4.0) z)))