
(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 x (+ y 0.5) z))
double code(double x, double y, double z) {
return fma(x, (y + 0.5), z);
}
function code(x, y, z) return fma(x, Float64(y + 0.5), z) end
code[x_, y_, z_] := N[(x * N[(y + 0.5), $MachinePrecision] + z), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(x, y + 0.5, z\right)
\end{array}
(FPCore (x y z)
:precision binary64
(if (<= y -0.5)
(* x y)
(if (<= y -1.05e-180)
(* x 0.5)
(if (<= y 1.2e-192)
z
(if (<= y 3.5e-52)
(* x 0.5)
(if (<= y 6e-35)
z
(if (<= y 1.25e-7) (* x 0.5) (if (<= y 4.2e+102) z (* x y)))))))))
double code(double x, double y, double z) {
double tmp;
if (y <= -0.5) {
tmp = x * y;
} else if (y <= -1.05e-180) {
tmp = x * 0.5;
} else if (y <= 1.2e-192) {
tmp = z;
} else if (y <= 3.5e-52) {
tmp = x * 0.5;
} else if (y <= 6e-35) {
tmp = z;
} else if (y <= 1.25e-7) {
tmp = x * 0.5;
} else if (y <= 4.2e+102) {
tmp = z;
} else {
tmp = x * y;
}
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)) then
tmp = x * y
else if (y <= (-1.05d-180)) then
tmp = x * 0.5d0
else if (y <= 1.2d-192) then
tmp = z
else if (y <= 3.5d-52) then
tmp = x * 0.5d0
else if (y <= 6d-35) then
tmp = z
else if (y <= 1.25d-7) then
tmp = x * 0.5d0
else if (y <= 4.2d+102) then
tmp = z
else
tmp = x * y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -0.5) {
tmp = x * y;
} else if (y <= -1.05e-180) {
tmp = x * 0.5;
} else if (y <= 1.2e-192) {
tmp = z;
} else if (y <= 3.5e-52) {
tmp = x * 0.5;
} else if (y <= 6e-35) {
tmp = z;
} else if (y <= 1.25e-7) {
tmp = x * 0.5;
} else if (y <= 4.2e+102) {
tmp = z;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -0.5: tmp = x * y elif y <= -1.05e-180: tmp = x * 0.5 elif y <= 1.2e-192: tmp = z elif y <= 3.5e-52: tmp = x * 0.5 elif y <= 6e-35: tmp = z elif y <= 1.25e-7: tmp = x * 0.5 elif y <= 4.2e+102: tmp = z else: tmp = x * y return tmp
function code(x, y, z) tmp = 0.0 if (y <= -0.5) tmp = Float64(x * y); elseif (y <= -1.05e-180) tmp = Float64(x * 0.5); elseif (y <= 1.2e-192) tmp = z; elseif (y <= 3.5e-52) tmp = Float64(x * 0.5); elseif (y <= 6e-35) tmp = z; elseif (y <= 1.25e-7) tmp = Float64(x * 0.5); elseif (y <= 4.2e+102) tmp = z; else tmp = Float64(x * y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -0.5) tmp = x * y; elseif (y <= -1.05e-180) tmp = x * 0.5; elseif (y <= 1.2e-192) tmp = z; elseif (y <= 3.5e-52) tmp = x * 0.5; elseif (y <= 6e-35) tmp = z; elseif (y <= 1.25e-7) tmp = x * 0.5; elseif (y <= 4.2e+102) tmp = z; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -0.5], N[(x * y), $MachinePrecision], If[LessEqual[y, -1.05e-180], N[(x * 0.5), $MachinePrecision], If[LessEqual[y, 1.2e-192], z, If[LessEqual[y, 3.5e-52], N[(x * 0.5), $MachinePrecision], If[LessEqual[y, 6e-35], z, If[LessEqual[y, 1.25e-7], N[(x * 0.5), $MachinePrecision], If[LessEqual[y, 4.2e+102], z, N[(x * y), $MachinePrecision]]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -0.5:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;y \leq -1.05 \cdot 10^{-180}:\\
\;\;\;\;x \cdot 0.5\\
\mathbf{elif}\;y \leq 1.2 \cdot 10^{-192}:\\
\;\;\;\;z\\
\mathbf{elif}\;y \leq 3.5 \cdot 10^{-52}:\\
\;\;\;\;x \cdot 0.5\\
\mathbf{elif}\;y \leq 6 \cdot 10^{-35}:\\
\;\;\;\;z\\
\mathbf{elif}\;y \leq 1.25 \cdot 10^{-7}:\\
\;\;\;\;x \cdot 0.5\\
\mathbf{elif}\;y \leq 4.2 \cdot 10^{+102}:\\
\;\;\;\;z\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
(FPCore (x y z)
:precision binary64
(if (<= z -1.26e+190)
z
(if (or (<= z -5.2e+137) (and (not (<= z -0.032)) (<= z 5.1e+75)))
(* x (+ y 0.5))
z)))
double code(double x, double y, double z) {
double tmp;
if (z <= -1.26e+190) {
tmp = z;
} else if ((z <= -5.2e+137) || (!(z <= -0.032) && (z <= 5.1e+75))) {
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 <= (-1.26d+190)) then
tmp = z
else if ((z <= (-5.2d+137)) .or. (.not. (z <= (-0.032d0))) .and. (z <= 5.1d+75)) 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 <= -1.26e+190) {
tmp = z;
} else if ((z <= -5.2e+137) || (!(z <= -0.032) && (z <= 5.1e+75))) {
tmp = x * (y + 0.5);
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -1.26e+190: tmp = z elif (z <= -5.2e+137) or (not (z <= -0.032) and (z <= 5.1e+75)): tmp = x * (y + 0.5) else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if (z <= -1.26e+190) tmp = z; elseif ((z <= -5.2e+137) || (!(z <= -0.032) && (z <= 5.1e+75))) 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 <= -1.26e+190) tmp = z; elseif ((z <= -5.2e+137) || (~((z <= -0.032)) && (z <= 5.1e+75))) tmp = x * (y + 0.5); else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -1.26e+190], z, If[Or[LessEqual[z, -5.2e+137], And[N[Not[LessEqual[z, -0.032]], $MachinePrecision], LessEqual[z, 5.1e+75]]], N[(x * N[(y + 0.5), $MachinePrecision]), $MachinePrecision], z]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.26 \cdot 10^{+190}:\\
\;\;\;\;z\\
\mathbf{elif}\;z \leq -5.2 \cdot 10^{+137} \lor \neg \left(z \leq -0.032\right) \land z \leq 5.1 \cdot 10^{+75}:\\
\;\;\;\;x \cdot \left(y + 0.5\right)\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
(FPCore (x y z) :precision binary64 (if (or (<= x -5e+15) (not (<= x 1020000000000.0))) (* x (+ y 0.5)) (+ z (* x y))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -5e+15) || !(x <= 1020000000000.0)) {
tmp = x * (y + 0.5);
} else {
tmp = z + (x * y);
}
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 ((x <= (-5d+15)) .or. (.not. (x <= 1020000000000.0d0))) then
tmp = x * (y + 0.5d0)
else
tmp = z + (x * y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -5e+15) || !(x <= 1020000000000.0)) {
tmp = x * (y + 0.5);
} else {
tmp = z + (x * y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -5e+15) or not (x <= 1020000000000.0): tmp = x * (y + 0.5) else: tmp = z + (x * y) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -5e+15) || !(x <= 1020000000000.0)) tmp = Float64(x * Float64(y + 0.5)); else tmp = Float64(z + Float64(x * y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -5e+15) || ~((x <= 1020000000000.0))) tmp = x * (y + 0.5); else tmp = z + (x * y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -5e+15], N[Not[LessEqual[x, 1020000000000.0]], $MachinePrecision]], N[(x * N[(y + 0.5), $MachinePrecision]), $MachinePrecision], N[(z + N[(x * y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -5 \cdot 10^{+15} \lor \neg \left(x \leq 1020000000000\right):\\
\;\;\;\;x \cdot \left(y + 0.5\right)\\
\mathbf{else}:\\
\;\;\;\;z + x \cdot y\\
\end{array}
\end{array}
(FPCore (x y z) :precision binary64 (if (or (<= y -0.5) (not (<= y 0.5))) (+ z (* x y)) (- z (* x -0.5))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -0.5) || !(y <= 0.5)) {
tmp = z + (x * y);
} 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 <= 0.5d0))) then
tmp = z + (x * y)
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 <= 0.5)) {
tmp = z + (x * y);
} else {
tmp = z - (x * -0.5);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -0.5) or not (y <= 0.5): tmp = z + (x * y) else: tmp = z - (x * -0.5) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -0.5) || !(y <= 0.5)) tmp = Float64(z + Float64(x * y)); 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 <= 0.5))) tmp = z + (x * y); 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, 0.5]], $MachinePrecision]], N[(z + N[(x * y), $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 0.5\right):\\
\;\;\;\;z + x \cdot y\\
\mathbf{else}:\\
\;\;\;\;z - x \cdot -0.5\\
\end{array}
\end{array}
(FPCore (x y z) :precision binary64 (if (or (<= x -7.2e+15) (not (<= x 180000000000.0))) (* x 0.5) z))
double code(double x, double y, double z) {
double tmp;
if ((x <= -7.2e+15) || !(x <= 180000000000.0)) {
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 ((x <= (-7.2d+15)) .or. (.not. (x <= 180000000000.0d0))) 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 ((x <= -7.2e+15) || !(x <= 180000000000.0)) {
tmp = x * 0.5;
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -7.2e+15) or not (x <= 180000000000.0): tmp = x * 0.5 else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -7.2e+15) || !(x <= 180000000000.0)) tmp = Float64(x * 0.5); else tmp = z; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -7.2e+15) || ~((x <= 180000000000.0))) tmp = x * 0.5; else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -7.2e+15], N[Not[LessEqual[x, 180000000000.0]], $MachinePrecision]], N[(x * 0.5), $MachinePrecision], z]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -7.2 \cdot 10^{+15} \lor \neg \left(x \leq 180000000000\right):\\
\;\;\;\;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 2023350
(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))