
(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 y (* z x)))
assert(x < y && y < z);
double code(double x, double y, double z) {
return fma(z, y, (z * x));
}
x, y, z = sort([x, y, z]) function code(x, y, z) return fma(z, y, Float64(z * x)) end
NOTE: x, y, and z should be sorted in increasing order before calling this function. code[x_, y_, z_] := N[(z * y + N[(z * x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\mathsf{fma}\left(z, y, z \cdot x\right)
\end{array}
Initial program 100.0%
*-commutative100.0%
+-commutative100.0%
distribute-lft-in99.2%
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 (<= x -7.4e-47) (* z x) (* z y)))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if (x <= -7.4e-47) {
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 (x <= (-7.4d-47)) 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 (x <= -7.4e-47) {
tmp = z * x;
} else {
tmp = z * y;
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): tmp = 0 if x <= -7.4e-47: 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 (x <= -7.4e-47) 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 (x <= -7.4e-47)
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[LessEqual[x, -7.4e-47], N[(z * x), $MachinePrecision], N[(z * y), $MachinePrecision]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq -7.4 \cdot 10^{-47}:\\
\;\;\;\;z \cdot x\\
\mathbf{else}:\\
\;\;\;\;z \cdot y\\
\end{array}
\end{array}
if x < -7.4000000000000001e-47Initial program 100.0%
Taylor expanded in x around inf 79.7%
*-commutative79.7%
Simplified79.7%
if -7.4000000000000001e-47 < x Initial program 100.0%
Taylor expanded in x around 0 63.0%
Final simplification67.9%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (* z (+ y x)))
assert(x < y && y < z);
double code(double x, double y, double z) {
return z * (y + 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 = z * (y + x)
end function
assert x < y && y < z;
public static double code(double x, double y, double z) {
return z * (y + x);
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): return z * (y + x)
x, y, z = sort([x, y, z]) function code(x, y, z) return Float64(z * Float64(y + x)) end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp = code(x, y, z)
tmp = z * (y + x);
end
NOTE: x, y, and z should be sorted in increasing order before calling this function. code[x_, y_, z_] := N[(z * N[(y + x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
z \cdot \left(y + x\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 52.3%
Final simplification52.3%
herbie shell --seed 2024059
(FPCore (x y z)
:name "Text.Parsec.Token:makeTokenParser from parsec-3.1.9, B"
:precision binary64
(* (+ x y) z))