
(FPCore (x y z) :precision binary64 (* (+ x y) z))
double code(double x, double y, double z) {
return (x + y) * 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) * z
end function
public static double code(double x, double y, double z) {
return (x + y) * z;
}
def code(x, y, z): return (x + y) * z
function code(x, y, z) return Float64(Float64(x + y) * z) end
function tmp = code(x, y, z) tmp = (x + y) * z; end
code[x_, y_, z_] := N[(N[(x + y), $MachinePrecision] * z), $MachinePrecision]
\begin{array}{l}
\\
\left(x + y\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) z))
double code(double x, double y, double z) {
return (x + y) * 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) * z
end function
public static double code(double x, double y, double z) {
return (x + y) * z;
}
def code(x, y, z): return (x + y) * z
function code(x, y, z) return Float64(Float64(x + y) * z) end
function tmp = code(x, y, z) tmp = (x + y) * z; end
code[x_, y_, z_] := N[(N[(x + y), $MachinePrecision] * z), $MachinePrecision]
\begin{array}{l}
\\
\left(x + y\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 z x (* z y)))
assert(x < y && y < z);
double code(double x, double y, double z) {
return fma(z, x, (z * y));
}
x, y, z = sort([x, y, z]) function code(x, y, z) return fma(z, x, Float64(z * y)) end
NOTE: x, y, and z should be sorted in increasing order before calling this function. code[x_, y_, z_] := N[(z * x + N[(z * y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\mathsf{fma}\left(z, x, z \cdot y\right)
\end{array}
Initial program 100.0%
*-commutative100.0%
distribute-lft-in98.4%
fma-define99.2%
Applied egg-rr99.2%
Final simplification99.2%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (or (<= y 1.62e-161) (and (not (<= y 3.6e-70)) (<= y 2.16e-10))) (* z x) (* z y)))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if ((y <= 1.62e-161) || (!(y <= 3.6e-70) && (y <= 2.16e-10))) {
tmp = z * x;
} else {
tmp = z * y;
}
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 ((y <= 1.62d-161) .or. (.not. (y <= 3.6d-70)) .and. (y <= 2.16d-10)) then
tmp = z * x
else
tmp = z * y
end if
code = tmp
end function
assert x < y && y < z;
public static double code(double x, double y, double z) {
double tmp;
if ((y <= 1.62e-161) || (!(y <= 3.6e-70) && (y <= 2.16e-10))) {
tmp = z * x;
} else {
tmp = z * y;
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): tmp = 0 if (y <= 1.62e-161) or (not (y <= 3.6e-70) and (y <= 2.16e-10)): tmp = z * x else: tmp = z * y return tmp
x, y, z = sort([x, y, z]) function code(x, y, z) tmp = 0.0 if ((y <= 1.62e-161) || (!(y <= 3.6e-70) && (y <= 2.16e-10))) tmp = Float64(z * x); else tmp = Float64(z * y); end return tmp end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp_2 = code(x, y, z)
tmp = 0.0;
if ((y <= 1.62e-161) || (~((y <= 3.6e-70)) && (y <= 2.16e-10)))
tmp = z * x;
else
tmp = z * y;
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[y, 1.62e-161], And[N[Not[LessEqual[y, 3.6e-70]], $MachinePrecision], LessEqual[y, 2.16e-10]]], N[(z * x), $MachinePrecision], N[(z * y), $MachinePrecision]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;y \leq 1.62 \cdot 10^{-161} \lor \neg \left(y \leq 3.6 \cdot 10^{-70}\right) \land y \leq 2.16 \cdot 10^{-10}:\\
\;\;\;\;z \cdot x\\
\mathbf{else}:\\
\;\;\;\;z \cdot y\\
\end{array}
\end{array}
if y < 1.62e-161 or 3.6000000000000002e-70 < y < 2.16000000000000004e-10Initial program 100.0%
Taylor expanded in x around inf 70.0%
*-commutative70.0%
Simplified70.0%
if 1.62e-161 < y < 3.6000000000000002e-70 or 2.16000000000000004e-10 < y Initial program 100.0%
Taylor expanded in x around 0 71.4%
Final simplification70.5%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (* z (+ x y)))
assert(x < y && y < z);
double code(double x, double y, double z) {
return z * (x + y);
}
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 = z * (x + y)
end function
assert x < y && y < z;
public static double code(double x, double y, double z) {
return z * (x + y);
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): return z * (x + y)
x, y, z = sort([x, y, z]) function code(x, y, z) return Float64(z * Float64(x + y)) end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp = code(x, y, z)
tmp = z * (x + y);
end
NOTE: x, y, and z should be sorted in increasing order before calling this function. code[x_, y_, z_] := N[(z * N[(x + y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
z \cdot \left(x + y\right)
\end{array}
Initial program 100.0%
Final simplification100.0%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (* z y))
assert(x < y && y < z);
double code(double x, double y, double z) {
return z * y;
}
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 = z * y
end function
assert x < y && y < z;
public static double code(double x, double y, double z) {
return z * y;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): return z * y
x, y, z = sort([x, y, z]) function code(x, y, z) return Float64(z * y) end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp = code(x, y, z)
tmp = z * y;
end
NOTE: x, y, and z should be sorted in increasing order before calling this function. code[x_, y_, z_] := N[(z * y), $MachinePrecision]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
z \cdot y
\end{array}
Initial program 100.0%
Taylor expanded in x around 0 48.7%
Final simplification48.7%
herbie shell --seed 2024076
(FPCore (x y z)
:name "Text.Parsec.Token:makeTokenParser from parsec-3.1.9, B"
:precision binary64
(* (+ x y) z))