
(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}
Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around 0 100.0%
+-commutative100.0%
*-commutative100.0%
fma-udef100.0%
+-commutative100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(if (<= y -4.8e+161)
(* x y)
(if (<= y -1e+147)
z
(if (<= y -2.35e+24)
(* x y)
(if (<= y 7.5e-298)
z
(if (<= y 1.12e-138) (* x 0.5) (if (<= y 8.5e+22) z (* x y))))))))
double code(double x, double y, double z) {
double tmp;
if (y <= -4.8e+161) {
tmp = x * y;
} else if (y <= -1e+147) {
tmp = z;
} else if (y <= -2.35e+24) {
tmp = x * y;
} else if (y <= 7.5e-298) {
tmp = z;
} else if (y <= 1.12e-138) {
tmp = x * 0.5;
} else if (y <= 8.5e+22) {
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 <= (-4.8d+161)) then
tmp = x * y
else if (y <= (-1d+147)) then
tmp = z
else if (y <= (-2.35d+24)) then
tmp = x * y
else if (y <= 7.5d-298) then
tmp = z
else if (y <= 1.12d-138) then
tmp = x * 0.5d0
else if (y <= 8.5d+22) 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 <= -4.8e+161) {
tmp = x * y;
} else if (y <= -1e+147) {
tmp = z;
} else if (y <= -2.35e+24) {
tmp = x * y;
} else if (y <= 7.5e-298) {
tmp = z;
} else if (y <= 1.12e-138) {
tmp = x * 0.5;
} else if (y <= 8.5e+22) {
tmp = z;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -4.8e+161: tmp = x * y elif y <= -1e+147: tmp = z elif y <= -2.35e+24: tmp = x * y elif y <= 7.5e-298: tmp = z elif y <= 1.12e-138: tmp = x * 0.5 elif y <= 8.5e+22: tmp = z else: tmp = x * y return tmp
function code(x, y, z) tmp = 0.0 if (y <= -4.8e+161) tmp = Float64(x * y); elseif (y <= -1e+147) tmp = z; elseif (y <= -2.35e+24) tmp = Float64(x * y); elseif (y <= 7.5e-298) tmp = z; elseif (y <= 1.12e-138) tmp = Float64(x * 0.5); elseif (y <= 8.5e+22) tmp = z; else tmp = Float64(x * y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -4.8e+161) tmp = x * y; elseif (y <= -1e+147) tmp = z; elseif (y <= -2.35e+24) tmp = x * y; elseif (y <= 7.5e-298) tmp = z; elseif (y <= 1.12e-138) tmp = x * 0.5; elseif (y <= 8.5e+22) tmp = z; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -4.8e+161], N[(x * y), $MachinePrecision], If[LessEqual[y, -1e+147], z, If[LessEqual[y, -2.35e+24], N[(x * y), $MachinePrecision], If[LessEqual[y, 7.5e-298], z, If[LessEqual[y, 1.12e-138], N[(x * 0.5), $MachinePrecision], If[LessEqual[y, 8.5e+22], z, N[(x * y), $MachinePrecision]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -4.8 \cdot 10^{+161}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;y \leq -1 \cdot 10^{+147}:\\
\;\;\;\;z\\
\mathbf{elif}\;y \leq -2.35 \cdot 10^{+24}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;y \leq 7.5 \cdot 10^{-298}:\\
\;\;\;\;z\\
\mathbf{elif}\;y \leq 1.12 \cdot 10^{-138}:\\
\;\;\;\;x \cdot 0.5\\
\mathbf{elif}\;y \leq 8.5 \cdot 10^{+22}:\\
\;\;\;\;z\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if y < -4.7999999999999998e161 or -9.9999999999999998e146 < y < -2.35e24 or 8.49999999999999979e22 < y Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around 0 100.0%
+-commutative100.0%
*-commutative100.0%
fma-udef100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in y around inf 73.8%
if -4.7999999999999998e161 < y < -9.9999999999999998e146 or -2.35e24 < y < 7.49999999999999987e-298 or 1.1199999999999999e-138 < y < 8.49999999999999979e22Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around 0 100.0%
+-commutative100.0%
*-commutative100.0%
fma-udef100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in x around 0 64.6%
if 7.49999999999999987e-298 < y < 1.1199999999999999e-138Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around inf 60.1%
Taylor expanded in y around 0 60.1%
Final simplification68.2%
(FPCore (x y z)
:precision binary64
(if (<= z -9.2e+57)
z
(if (or (<= z -2.15e+26) (and (not (<= z -2.35e-94)) (<= z 5.8e+103)))
(* x (+ y 0.5))
z)))
double code(double x, double y, double z) {
double tmp;
if (z <= -9.2e+57) {
tmp = z;
} else if ((z <= -2.15e+26) || (!(z <= -2.35e-94) && (z <= 5.8e+103))) {
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 <= (-9.2d+57)) then
tmp = z
else if ((z <= (-2.15d+26)) .or. (.not. (z <= (-2.35d-94))) .and. (z <= 5.8d+103)) 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 <= -9.2e+57) {
tmp = z;
} else if ((z <= -2.15e+26) || (!(z <= -2.35e-94) && (z <= 5.8e+103))) {
tmp = x * (y + 0.5);
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -9.2e+57: tmp = z elif (z <= -2.15e+26) or (not (z <= -2.35e-94) and (z <= 5.8e+103)): tmp = x * (y + 0.5) else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if (z <= -9.2e+57) tmp = z; elseif ((z <= -2.15e+26) || (!(z <= -2.35e-94) && (z <= 5.8e+103))) 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 <= -9.2e+57) tmp = z; elseif ((z <= -2.15e+26) || (~((z <= -2.35e-94)) && (z <= 5.8e+103))) tmp = x * (y + 0.5); else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -9.2e+57], z, If[Or[LessEqual[z, -2.15e+26], And[N[Not[LessEqual[z, -2.35e-94]], $MachinePrecision], LessEqual[z, 5.8e+103]]], N[(x * N[(y + 0.5), $MachinePrecision]), $MachinePrecision], z]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -9.2 \cdot 10^{+57}:\\
\;\;\;\;z\\
\mathbf{elif}\;z \leq -2.15 \cdot 10^{+26} \lor \neg \left(z \leq -2.35 \cdot 10^{-94}\right) \land z \leq 5.8 \cdot 10^{+103}:\\
\;\;\;\;x \cdot \left(y + 0.5\right)\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if z < -9.1999999999999995e57 or -2.1499999999999999e26 < z < -2.35000000000000002e-94 or 5.7999999999999997e103 < z Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around 0 100.0%
+-commutative100.0%
*-commutative100.0%
fma-udef100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in x around 0 76.8%
if -9.1999999999999995e57 < z < -2.1499999999999999e26 or -2.35000000000000002e-94 < z < 5.7999999999999997e103Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around inf 82.2%
Final simplification79.8%
(FPCore (x y z) :precision binary64 (if (or (<= z -3e-95) (not (<= z 9.2e-79))) (+ z (* x y)) (* x (+ y 0.5))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -3e-95) || !(z <= 9.2e-79)) {
tmp = z + (x * y);
} else {
tmp = x * (y + 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 ((z <= (-3d-95)) .or. (.not. (z <= 9.2d-79))) then
tmp = z + (x * y)
else
tmp = x * (y + 0.5d0)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -3e-95) || !(z <= 9.2e-79)) {
tmp = z + (x * y);
} else {
tmp = x * (y + 0.5);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -3e-95) or not (z <= 9.2e-79): tmp = z + (x * y) else: tmp = x * (y + 0.5) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -3e-95) || !(z <= 9.2e-79)) tmp = Float64(z + Float64(x * y)); else tmp = Float64(x * Float64(y + 0.5)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -3e-95) || ~((z <= 9.2e-79))) tmp = z + (x * y); else tmp = x * (y + 0.5); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -3e-95], N[Not[LessEqual[z, 9.2e-79]], $MachinePrecision]], N[(z + N[(x * y), $MachinePrecision]), $MachinePrecision], N[(x * N[(y + 0.5), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -3 \cdot 10^{-95} \lor \neg \left(z \leq 9.2 \cdot 10^{-79}\right):\\
\;\;\;\;z + x \cdot y\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(y + 0.5\right)\\
\end{array}
\end{array}
if z < -3e-95 or 9.20000000000000047e-79 < z Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around 0 100.0%
flip-+81.4%
associate-*l/77.9%
metadata-eval77.9%
Applied egg-rr77.9%
Taylor expanded in y around inf 88.4%
if -3e-95 < z < 9.20000000000000047e-79Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around inf 91.2%
Final simplification89.4%
(FPCore (x y z) :precision binary64 (if (or (<= y -4.5e+23) (not (<= y 0.5))) (+ z (* x y)) (+ z (/ x 2.0))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -4.5e+23) || !(y <= 0.5)) {
tmp = z + (x * y);
} else {
tmp = z + (x / 2.0);
}
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 <= (-4.5d+23)) .or. (.not. (y <= 0.5d0))) then
tmp = z + (x * y)
else
tmp = z + (x / 2.0d0)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -4.5e+23) || !(y <= 0.5)) {
tmp = z + (x * y);
} else {
tmp = z + (x / 2.0);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -4.5e+23) or not (y <= 0.5): tmp = z + (x * y) else: tmp = z + (x / 2.0) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -4.5e+23) || !(y <= 0.5)) tmp = Float64(z + Float64(x * y)); else tmp = Float64(z + Float64(x / 2.0)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -4.5e+23) || ~((y <= 0.5))) tmp = z + (x * y); else tmp = z + (x / 2.0); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -4.5e+23], N[Not[LessEqual[y, 0.5]], $MachinePrecision]], N[(z + N[(x * y), $MachinePrecision]), $MachinePrecision], N[(z + N[(x / 2.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -4.5 \cdot 10^{+23} \lor \neg \left(y \leq 0.5\right):\\
\;\;\;\;z + x \cdot y\\
\mathbf{else}:\\
\;\;\;\;z + \frac{x}{2}\\
\end{array}
\end{array}
if y < -4.49999999999999979e23 or 0.5 < y Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around 0 100.0%
flip-+59.2%
associate-*l/53.3%
metadata-eval53.3%
Applied egg-rr53.3%
Taylor expanded in y around inf 99.5%
if -4.49999999999999979e23 < y < 0.5Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around 0 98.9%
Final simplification99.2%
(FPCore (x y z) :precision binary64 (if (<= z -5.2e-104) z (if (<= z 5.4e-80) (* x 0.5) z)))
double code(double x, double y, double z) {
double tmp;
if (z <= -5.2e-104) {
tmp = z;
} else if (z <= 5.4e-80) {
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 <= (-5.2d-104)) then
tmp = z
else if (z <= 5.4d-80) 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 <= -5.2e-104) {
tmp = z;
} else if (z <= 5.4e-80) {
tmp = x * 0.5;
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -5.2e-104: tmp = z elif z <= 5.4e-80: tmp = x * 0.5 else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if (z <= -5.2e-104) tmp = z; elseif (z <= 5.4e-80) tmp = Float64(x * 0.5); else tmp = z; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -5.2e-104) tmp = z; elseif (z <= 5.4e-80) tmp = x * 0.5; else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -5.2e-104], z, If[LessEqual[z, 5.4e-80], N[(x * 0.5), $MachinePrecision], z]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -5.2 \cdot 10^{-104}:\\
\;\;\;\;z\\
\mathbf{elif}\;z \leq 5.4 \cdot 10^{-80}:\\
\;\;\;\;x \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if z < -5.20000000000000005e-104 or 5.4000000000000004e-80 < z Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around 0 100.0%
+-commutative100.0%
*-commutative100.0%
fma-udef100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in x around 0 64.6%
if -5.20000000000000005e-104 < z < 5.4000000000000004e-80Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around inf 91.0%
Taylor expanded in y around 0 41.1%
Final simplification56.2%
(FPCore (x y z) :precision binary64 (+ z (* x (+ y 0.5))))
double code(double x, double y, double z) {
return z + (x * (y + 0.5));
}
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 + 0.5d0))
end function
public static double code(double x, double y, double z) {
return z + (x * (y + 0.5));
}
def code(x, y, z): return z + (x * (y + 0.5))
function code(x, y, z) return Float64(z + Float64(x * Float64(y + 0.5))) end
function tmp = code(x, y, z) tmp = z + (x * (y + 0.5)); end
code[x_, y_, z_] := N[(z + N[(x * N[(y + 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
z + x \cdot \left(y + 0.5\right)
\end{array}
Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around 0 100.0%
Final simplification100.0%
(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}
Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around 0 100.0%
+-commutative100.0%
*-commutative100.0%
fma-udef100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in x around 0 44.8%
Final simplification44.8%
herbie shell --seed 2023196
(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))