
(FPCore (x y z) :precision binary64 (+ (+ (/ x 2.0) (* y x)) z))
double code(double x, double y, double z) {
return ((x / 2.0) + (y * x)) + 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 / 2.0d0) + (y * x)) + z
end function
public static double code(double x, double y, double z) {
return ((x / 2.0) + (y * x)) + z;
}
def code(x, y, z): return ((x / 2.0) + (y * x)) + z
function code(x, y, z) return Float64(Float64(Float64(x / 2.0) + Float64(y * x)) + z) end
function tmp = code(x, y, z) tmp = ((x / 2.0) + (y * x)) + z; end
code[x_, y_, z_] := N[(N[(N[(x / 2.0), $MachinePrecision] + N[(y * x), $MachinePrecision]), $MachinePrecision] + z), $MachinePrecision]
\begin{array}{l}
\\
\left(\frac{x}{2} + y \cdot x\right) + z
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 8 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (+ (+ (/ x 2.0) (* y x)) z))
double code(double x, double y, double z) {
return ((x / 2.0) + (y * x)) + 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 / 2.0d0) + (y * x)) + z
end function
public static double code(double x, double y, double z) {
return ((x / 2.0) + (y * x)) + z;
}
def code(x, y, z): return ((x / 2.0) + (y * x)) + z
function code(x, y, z) return Float64(Float64(Float64(x / 2.0) + Float64(y * x)) + z) end
function tmp = code(x, y, z) tmp = ((x / 2.0) + (y * x)) + z; end
code[x_, y_, z_] := N[(N[(N[(x / 2.0), $MachinePrecision] + N[(y * x), $MachinePrecision]), $MachinePrecision] + z), $MachinePrecision]
\begin{array}{l}
\\
\left(\frac{x}{2} + y \cdot x\right) + z
\end{array}
(FPCore (x y z) :precision binary64 (fma y x (+ z (* x 0.5))))
double code(double x, double y, double z) {
return fma(y, x, (z + (x * 0.5)));
}
function code(x, y, z) return fma(y, x, Float64(z + Float64(x * 0.5))) end
code[x_, y_, z_] := N[(y * x + N[(z + N[(x * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(y, x, z + x \cdot 0.5\right)
\end{array}
(FPCore (x y z)
:precision binary64
(if (<= y -17000.0)
(* y x)
(if (<= y -3.7e-165)
z
(if (<= y -7e-226)
(* x 0.5)
(if (<= y 1.15e-299)
z
(if (<= y 6e-226) (* x 0.5) (if (<= y 2.2e+44) z (* y x))))))))
double code(double x, double y, double z) {
double tmp;
if (y <= -17000.0) {
tmp = y * x;
} else if (y <= -3.7e-165) {
tmp = z;
} else if (y <= -7e-226) {
tmp = x * 0.5;
} else if (y <= 1.15e-299) {
tmp = z;
} else if (y <= 6e-226) {
tmp = x * 0.5;
} else if (y <= 2.2e+44) {
tmp = z;
} else {
tmp = y * x;
}
return tmp;
}
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 <= (-17000.0d0)) then
tmp = y * x
else if (y <= (-3.7d-165)) then
tmp = z
else if (y <= (-7d-226)) then
tmp = x * 0.5d0
else if (y <= 1.15d-299) then
tmp = z
else if (y <= 6d-226) then
tmp = x * 0.5d0
else if (y <= 2.2d+44) then
tmp = z
else
tmp = y * x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -17000.0) {
tmp = y * x;
} else if (y <= -3.7e-165) {
tmp = z;
} else if (y <= -7e-226) {
tmp = x * 0.5;
} else if (y <= 1.15e-299) {
tmp = z;
} else if (y <= 6e-226) {
tmp = x * 0.5;
} else if (y <= 2.2e+44) {
tmp = z;
} else {
tmp = y * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -17000.0: tmp = y * x elif y <= -3.7e-165: tmp = z elif y <= -7e-226: tmp = x * 0.5 elif y <= 1.15e-299: tmp = z elif y <= 6e-226: tmp = x * 0.5 elif y <= 2.2e+44: tmp = z else: tmp = y * x return tmp
function code(x, y, z) tmp = 0.0 if (y <= -17000.0) tmp = Float64(y * x); elseif (y <= -3.7e-165) tmp = z; elseif (y <= -7e-226) tmp = Float64(x * 0.5); elseif (y <= 1.15e-299) tmp = z; elseif (y <= 6e-226) tmp = Float64(x * 0.5); elseif (y <= 2.2e+44) tmp = z; else tmp = Float64(y * x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -17000.0) tmp = y * x; elseif (y <= -3.7e-165) tmp = z; elseif (y <= -7e-226) tmp = x * 0.5; elseif (y <= 1.15e-299) tmp = z; elseif (y <= 6e-226) tmp = x * 0.5; elseif (y <= 2.2e+44) tmp = z; else tmp = y * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -17000.0], N[(y * x), $MachinePrecision], If[LessEqual[y, -3.7e-165], z, If[LessEqual[y, -7e-226], N[(x * 0.5), $MachinePrecision], If[LessEqual[y, 1.15e-299], z, If[LessEqual[y, 6e-226], N[(x * 0.5), $MachinePrecision], If[LessEqual[y, 2.2e+44], z, N[(y * x), $MachinePrecision]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -17000:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;y \leq -3.7 \cdot 10^{-165}:\\
\;\;\;\;z\\
\mathbf{elif}\;y \leq -7 \cdot 10^{-226}:\\
\;\;\;\;x \cdot 0.5\\
\mathbf{elif}\;y \leq 1.15 \cdot 10^{-299}:\\
\;\;\;\;z\\
\mathbf{elif}\;y \leq 6 \cdot 10^{-226}:\\
\;\;\;\;x \cdot 0.5\\
\mathbf{elif}\;y \leq 2.2 \cdot 10^{+44}:\\
\;\;\;\;z\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
(FPCore (x y z) :precision binary64 (if (or (<= y -0.16) (not (<= y 4.2e+46))) (* x (+ y 0.5)) (- z (* x -0.5))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -0.16) || !(y <= 4.2e+46)) {
tmp = x * (y + 0.5);
} else {
tmp = z - (x * -0.5);
}
return tmp;
}
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 <= (-0.16d0)) .or. (.not. (y <= 4.2d+46))) then
tmp = x * (y + 0.5d0)
else
tmp = z - (x * (-0.5d0))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -0.16) || !(y <= 4.2e+46)) {
tmp = x * (y + 0.5);
} else {
tmp = z - (x * -0.5);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -0.16) or not (y <= 4.2e+46): tmp = x * (y + 0.5) else: tmp = z - (x * -0.5) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -0.16) || !(y <= 4.2e+46)) tmp = Float64(x * Float64(y + 0.5)); else tmp = Float64(z - Float64(x * -0.5)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -0.16) || ~((y <= 4.2e+46))) tmp = x * (y + 0.5); else tmp = z - (x * -0.5); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -0.16], N[Not[LessEqual[y, 4.2e+46]], $MachinePrecision]], N[(x * N[(y + 0.5), $MachinePrecision]), $MachinePrecision], N[(z - N[(x * -0.5), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -0.16 \lor \neg \left(y \leq 4.2 \cdot 10^{+46}\right):\\
\;\;\;\;x \cdot \left(y + 0.5\right)\\
\mathbf{else}:\\
\;\;\;\;z - x \cdot -0.5\\
\end{array}
\end{array}
(FPCore (x y z) :precision binary64 (if (or (<= y -0.5) (not (<= y 2.2e-7))) (+ z (* y x)) (- z (* x -0.5))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -0.5) || !(y <= 2.2e-7)) {
tmp = z + (y * x);
} else {
tmp = z - (x * -0.5);
}
return tmp;
}
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 <= (-0.5d0)) .or. (.not. (y <= 2.2d-7))) then
tmp = z + (y * x)
else
tmp = z - (x * (-0.5d0))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -0.5) || !(y <= 2.2e-7)) {
tmp = z + (y * x);
} else {
tmp = z - (x * -0.5);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -0.5) or not (y <= 2.2e-7): tmp = z + (y * x) else: tmp = z - (x * -0.5) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -0.5) || !(y <= 2.2e-7)) tmp = Float64(z + Float64(y * x)); else tmp = Float64(z - Float64(x * -0.5)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -0.5) || ~((y <= 2.2e-7))) tmp = z + (y * x); else tmp = z - (x * -0.5); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -0.5], N[Not[LessEqual[y, 2.2e-7]], $MachinePrecision]], N[(z + N[(y * x), $MachinePrecision]), $MachinePrecision], N[(z - N[(x * -0.5), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -0.5 \lor \neg \left(y \leq 2.2 \cdot 10^{-7}\right):\\
\;\;\;\;z + y \cdot x\\
\mathbf{else}:\\
\;\;\;\;z - x \cdot -0.5\\
\end{array}
\end{array}
(FPCore (x y z) :precision binary64 (if (<= z -4.5e+122) z (if (<= z 9000000.0) (* x (+ y 0.5)) z)))
double code(double x, double y, double z) {
double tmp;
if (z <= -4.5e+122) {
tmp = z;
} else if (z <= 9000000.0) {
tmp = x * (y + 0.5);
} else {
tmp = z;
}
return tmp;
}
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 (z <= (-4.5d+122)) then
tmp = z
else if (z <= 9000000.0d0) then
tmp = x * (y + 0.5d0)
else
tmp = z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= -4.5e+122) {
tmp = z;
} else if (z <= 9000000.0) {
tmp = x * (y + 0.5);
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -4.5e+122: tmp = z elif z <= 9000000.0: tmp = x * (y + 0.5) else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if (z <= -4.5e+122) tmp = z; elseif (z <= 9000000.0) tmp = Float64(x * Float64(y + 0.5)); else tmp = z; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -4.5e+122) tmp = z; elseif (z <= 9000000.0) tmp = x * (y + 0.5); else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -4.5e+122], z, If[LessEqual[z, 9000000.0], N[(x * N[(y + 0.5), $MachinePrecision]), $MachinePrecision], z]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -4.5 \cdot 10^{+122}:\\
\;\;\;\;z\\
\mathbf{elif}\;z \leq 9000000:\\
\;\;\;\;x \cdot \left(y + 0.5\right)\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
(FPCore (x y z) :precision binary64 (if (<= z -9.5e-79) z (if (<= z 7e-19) (* x 0.5) z)))
double code(double x, double y, double z) {
double tmp;
if (z <= -9.5e-79) {
tmp = z;
} else if (z <= 7e-19) {
tmp = x * 0.5;
} else {
tmp = z;
}
return tmp;
}
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 (z <= (-9.5d-79)) then
tmp = z
else if (z <= 7d-19) then
tmp = x * 0.5d0
else
tmp = z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= -9.5e-79) {
tmp = z;
} else if (z <= 7e-19) {
tmp = x * 0.5;
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -9.5e-79: tmp = z elif z <= 7e-19: tmp = x * 0.5 else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if (z <= -9.5e-79) tmp = z; elseif (z <= 7e-19) tmp = Float64(x * 0.5); else tmp = z; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -9.5e-79) tmp = z; elseif (z <= 7e-19) tmp = x * 0.5; else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -9.5e-79], z, If[LessEqual[z, 7e-19], N[(x * 0.5), $MachinePrecision], z]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -9.5 \cdot 10^{-79}:\\
\;\;\;\;z\\
\mathbf{elif}\;z \leq 7 \cdot 10^{-19}:\\
\;\;\;\;x \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
(FPCore (x y z) :precision binary64 (- z (* x (- -0.5 y))))
double code(double x, double y, double z) {
return z - (x * (-0.5 - y));
}
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 * ((-0.5d0) - y))
end function
public static double code(double x, double y, double z) {
return z - (x * (-0.5 - y));
}
def code(x, y, z): return z - (x * (-0.5 - y))
function code(x, y, z) return Float64(z - Float64(x * Float64(-0.5 - y))) end
function tmp = code(x, y, z) tmp = z - (x * (-0.5 - y)); end
code[x_, y_, z_] := N[(z - N[(x * N[(-0.5 - y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
z - x \cdot \left(-0.5 - y\right)
\end{array}
(FPCore (x y z) :precision binary64 z)
double code(double x, double y, double z) {
return z;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = z
end function
public static double code(double x, double y, double z) {
return z;
}
def code(x, y, z): return z
function code(x, y, z) return z end
function tmp = code(x, y, z) tmp = z; end
code[x_, y_, z_] := z
\begin{array}{l}
\\
z
\end{array}
herbie shell --seed 2024008
(FPCore (x y z)
:name "Data.Histogram.Bin.BinF:$cfromIndex from histogram-fill-0.8.4.1"
:precision binary64
(+ (+ (/ x 2.0) (* y x)) z))