
(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 and y should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (fma z y (* z x)))
assert(x < y);
double code(double x, double y, double z) {
return fma(z, y, (z * x));
}
x, y = sort([x, y]) function code(x, y, z) return fma(z, y, Float64(z * x)) end
NOTE: x and y 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] = \mathsf{sort}([x, y])\\
\\
\mathsf{fma}\left(z, y, z \cdot x\right)
\end{array}
Initial program 100.0%
*-commutative100.0%
+-commutative100.0%
distribute-lft-in100.0%
Applied egg-rr100.0%
fma-def100.0%
Applied egg-rr100.0%
Final simplification100.0%
NOTE: x and y should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (<= y 3.3e-127) (* z x) (* z y)))
assert(x < y);
double code(double x, double y, double z) {
double tmp;
if (y <= 3.3e-127) {
tmp = z * x;
} else {
tmp = z * y;
}
return tmp;
}
NOTE: x and y 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 <= 3.3d-127) then
tmp = z * x
else
tmp = z * y
end if
code = tmp
end function
assert x < y;
public static double code(double x, double y, double z) {
double tmp;
if (y <= 3.3e-127) {
tmp = z * x;
} else {
tmp = z * y;
}
return tmp;
}
[x, y] = sort([x, y]) def code(x, y, z): tmp = 0 if y <= 3.3e-127: tmp = z * x else: tmp = z * y return tmp
x, y = sort([x, y]) function code(x, y, z) tmp = 0.0 if (y <= 3.3e-127) tmp = Float64(z * x); else tmp = Float64(z * y); end return tmp end
x, y = num2cell(sort([x, y])){:}
function tmp_2 = code(x, y, z)
tmp = 0.0;
if (y <= 3.3e-127)
tmp = z * x;
else
tmp = z * y;
end
tmp_2 = tmp;
end
NOTE: x and y should be sorted in increasing order before calling this function. code[x_, y_, z_] := If[LessEqual[y, 3.3e-127], N[(z * x), $MachinePrecision], N[(z * y), $MachinePrecision]]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\begin{array}{l}
\mathbf{if}\;y \leq 3.3 \cdot 10^{-127}:\\
\;\;\;\;z \cdot x\\
\mathbf{else}:\\
\;\;\;\;z \cdot y\\
\end{array}
\end{array}
if y < 3.29999999999999981e-127Initial program 100.0%
Taylor expanded in x around inf 62.4%
if 3.29999999999999981e-127 < y Initial program 100.0%
Taylor expanded in x around 0 70.1%
Final simplification64.9%
NOTE: x and y should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (* z (+ y x)))
assert(x < y);
double code(double x, double y, double z) {
return z * (y + x);
}
NOTE: x and y 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;
public static double code(double x, double y, double z) {
return z * (y + x);
}
[x, y] = sort([x, y]) def code(x, y, z): return z * (y + x)
x, y = sort([x, y]) function code(x, y, z) return Float64(z * Float64(y + x)) end
x, y = num2cell(sort([x, y])){:}
function tmp = code(x, y, z)
tmp = z * (y + x);
end
NOTE: x and y 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] = \mathsf{sort}([x, y])\\
\\
z \cdot \left(y + x\right)
\end{array}
Initial program 100.0%
Final simplification100.0%
NOTE: x and y should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (* z y))
assert(x < y);
double code(double x, double y, double z) {
return z * y;
}
NOTE: x and y 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;
public static double code(double x, double y, double z) {
return z * y;
}
[x, y] = sort([x, y]) def code(x, y, z): return z * y
x, y = sort([x, y]) function code(x, y, z) return Float64(z * y) end
x, y = num2cell(sort([x, y])){:}
function tmp = code(x, y, z)
tmp = z * y;
end
NOTE: x and y should be sorted in increasing order before calling this function. code[x_, y_, z_] := N[(z * y), $MachinePrecision]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
z \cdot y
\end{array}
Initial program 100.0%
Taylor expanded in x around 0 54.9%
Final simplification54.9%
herbie shell --seed 2023181
(FPCore (x y z)
:name "Text.Parsec.Token:makeTokenParser from parsec-3.1.9, B"
:precision binary64
(* (+ x y) z))