
(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 (+ (+ (/ x 2.0) (* x y)) z))
double code(double x, double y, double z) {
return ((x / 2.0) + (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 / 2.0d0) + (x * y)) + z
end function
public static double code(double x, double y, double z) {
return ((x / 2.0) + (x * y)) + z;
}
def code(x, y, z): return ((x / 2.0) + (x * y)) + z
function code(x, y, z) return Float64(Float64(Float64(x / 2.0) + Float64(x * y)) + z) end
function tmp = code(x, y, z) tmp = ((x / 2.0) + (x * y)) + z; end
code[x_, y_, z_] := N[(N[(N[(x / 2.0), $MachinePrecision] + N[(x * y), $MachinePrecision]), $MachinePrecision] + z), $MachinePrecision]
\begin{array}{l}
\\
\left(\frac{x}{2} + x \cdot y\right) + z
\end{array}
Initial program 100.0%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(if (<= y -510000000000.0)
(* x y)
(if (<= y -3.1e-76)
z
(if (<= y -1.4e-158)
(* x 0.5)
(if (<= y 3e-133)
z
(if (<= y 1.6e-5) (* x 0.5) (if (<= y 1.4e+34) z (* x y))))))))
double code(double x, double y, double z) {
double tmp;
if (y <= -510000000000.0) {
tmp = x * y;
} else if (y <= -3.1e-76) {
tmp = z;
} else if (y <= -1.4e-158) {
tmp = x * 0.5;
} else if (y <= 3e-133) {
tmp = z;
} else if (y <= 1.6e-5) {
tmp = x * 0.5;
} else if (y <= 1.4e+34) {
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 <= (-510000000000.0d0)) then
tmp = x * y
else if (y <= (-3.1d-76)) then
tmp = z
else if (y <= (-1.4d-158)) then
tmp = x * 0.5d0
else if (y <= 3d-133) then
tmp = z
else if (y <= 1.6d-5) then
tmp = x * 0.5d0
else if (y <= 1.4d+34) 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 <= -510000000000.0) {
tmp = x * y;
} else if (y <= -3.1e-76) {
tmp = z;
} else if (y <= -1.4e-158) {
tmp = x * 0.5;
} else if (y <= 3e-133) {
tmp = z;
} else if (y <= 1.6e-5) {
tmp = x * 0.5;
} else if (y <= 1.4e+34) {
tmp = z;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -510000000000.0: tmp = x * y elif y <= -3.1e-76: tmp = z elif y <= -1.4e-158: tmp = x * 0.5 elif y <= 3e-133: tmp = z elif y <= 1.6e-5: tmp = x * 0.5 elif y <= 1.4e+34: tmp = z else: tmp = x * y return tmp
function code(x, y, z) tmp = 0.0 if (y <= -510000000000.0) tmp = Float64(x * y); elseif (y <= -3.1e-76) tmp = z; elseif (y <= -1.4e-158) tmp = Float64(x * 0.5); elseif (y <= 3e-133) tmp = z; elseif (y <= 1.6e-5) tmp = Float64(x * 0.5); elseif (y <= 1.4e+34) tmp = z; else tmp = Float64(x * y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -510000000000.0) tmp = x * y; elseif (y <= -3.1e-76) tmp = z; elseif (y <= -1.4e-158) tmp = x * 0.5; elseif (y <= 3e-133) tmp = z; elseif (y <= 1.6e-5) tmp = x * 0.5; elseif (y <= 1.4e+34) tmp = z; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -510000000000.0], N[(x * y), $MachinePrecision], If[LessEqual[y, -3.1e-76], z, If[LessEqual[y, -1.4e-158], N[(x * 0.5), $MachinePrecision], If[LessEqual[y, 3e-133], z, If[LessEqual[y, 1.6e-5], N[(x * 0.5), $MachinePrecision], If[LessEqual[y, 1.4e+34], z, N[(x * y), $MachinePrecision]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -510000000000:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;y \leq -3.1 \cdot 10^{-76}:\\
\;\;\;\;z\\
\mathbf{elif}\;y \leq -1.4 \cdot 10^{-158}:\\
\;\;\;\;x \cdot 0.5\\
\mathbf{elif}\;y \leq 3 \cdot 10^{-133}:\\
\;\;\;\;z\\
\mathbf{elif}\;y \leq 1.6 \cdot 10^{-5}:\\
\;\;\;\;x \cdot 0.5\\
\mathbf{elif}\;y \leq 1.4 \cdot 10^{+34}:\\
\;\;\;\;z\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if y < -5.1e11 or 1.40000000000000004e34 < y Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in y around inf 80.9%
if -5.1e11 < y < -3.0999999999999997e-76 or -1.40000000000000001e-158 < y < 3.00000000000000019e-133 or 1.59999999999999993e-5 < y < 1.40000000000000004e34Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around 0 62.2%
if -3.0999999999999997e-76 < y < -1.40000000000000001e-158 or 3.00000000000000019e-133 < y < 1.59999999999999993e-5Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around inf 63.7%
Taylor expanded in y around 0 59.6%
Final simplification69.6%
(FPCore (x y z)
:precision binary64
(if (or (<= x -8.6e-125)
(not
(or (<= x -7.7e-146) (and (not (<= x -8.8e-191)) (<= x 1.25e-34)))))
(* x (+ y 0.5))
z))
double code(double x, double y, double z) {
double tmp;
if ((x <= -8.6e-125) || !((x <= -7.7e-146) || (!(x <= -8.8e-191) && (x <= 1.25e-34)))) {
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 ((x <= (-8.6d-125)) .or. (.not. (x <= (-7.7d-146)) .or. (.not. (x <= (-8.8d-191))) .and. (x <= 1.25d-34))) 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 ((x <= -8.6e-125) || !((x <= -7.7e-146) || (!(x <= -8.8e-191) && (x <= 1.25e-34)))) {
tmp = x * (y + 0.5);
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -8.6e-125) or not ((x <= -7.7e-146) or (not (x <= -8.8e-191) and (x <= 1.25e-34))): tmp = x * (y + 0.5) else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -8.6e-125) || !((x <= -7.7e-146) || (!(x <= -8.8e-191) && (x <= 1.25e-34)))) 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 ((x <= -8.6e-125) || ~(((x <= -7.7e-146) || (~((x <= -8.8e-191)) && (x <= 1.25e-34))))) tmp = x * (y + 0.5); else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -8.6e-125], N[Not[Or[LessEqual[x, -7.7e-146], And[N[Not[LessEqual[x, -8.8e-191]], $MachinePrecision], LessEqual[x, 1.25e-34]]]], $MachinePrecision]], N[(x * N[(y + 0.5), $MachinePrecision]), $MachinePrecision], z]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -8.6 \cdot 10^{-125} \lor \neg \left(x \leq -7.7 \cdot 10^{-146} \lor \neg \left(x \leq -8.8 \cdot 10^{-191}\right) \land x \leq 1.25 \cdot 10^{-34}\right):\\
\;\;\;\;x \cdot \left(y + 0.5\right)\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if x < -8.6000000000000004e-125 or -7.69999999999999997e-146 < x < -8.79999999999999992e-191 or 1.2500000000000001e-34 < x Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around inf 80.5%
if -8.6000000000000004e-125 < x < -7.69999999999999997e-146 or -8.79999999999999992e-191 < x < 1.2500000000000001e-34Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around 0 77.0%
Final simplification79.3%
(FPCore (x y z)
:precision binary64
(if (or (<= z -900000000000.0)
(not
(or (<= z -2.8e-41) (and (not (<= z -3.1e-103)) (<= z 5.7e-117)))))
(+ (* x y) z)
(* x (+ y 0.5))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -900000000000.0) || !((z <= -2.8e-41) || (!(z <= -3.1e-103) && (z <= 5.7e-117)))) {
tmp = (x * y) + z;
} 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 <= (-900000000000.0d0)) .or. (.not. (z <= (-2.8d-41)) .or. (.not. (z <= (-3.1d-103))) .and. (z <= 5.7d-117))) then
tmp = (x * y) + z
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 <= -900000000000.0) || !((z <= -2.8e-41) || (!(z <= -3.1e-103) && (z <= 5.7e-117)))) {
tmp = (x * y) + z;
} else {
tmp = x * (y + 0.5);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -900000000000.0) or not ((z <= -2.8e-41) or (not (z <= -3.1e-103) and (z <= 5.7e-117))): tmp = (x * y) + z else: tmp = x * (y + 0.5) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -900000000000.0) || !((z <= -2.8e-41) || (!(z <= -3.1e-103) && (z <= 5.7e-117)))) tmp = Float64(Float64(x * y) + z); else tmp = Float64(x * Float64(y + 0.5)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -900000000000.0) || ~(((z <= -2.8e-41) || (~((z <= -3.1e-103)) && (z <= 5.7e-117))))) tmp = (x * y) + z; else tmp = x * (y + 0.5); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -900000000000.0], N[Not[Or[LessEqual[z, -2.8e-41], And[N[Not[LessEqual[z, -3.1e-103]], $MachinePrecision], LessEqual[z, 5.7e-117]]]], $MachinePrecision]], N[(N[(x * y), $MachinePrecision] + z), $MachinePrecision], N[(x * N[(y + 0.5), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -900000000000 \lor \neg \left(z \leq -2.8 \cdot 10^{-41} \lor \neg \left(z \leq -3.1 \cdot 10^{-103}\right) \land z \leq 5.7 \cdot 10^{-117}\right):\\
\;\;\;\;x \cdot y + z\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(y + 0.5\right)\\
\end{array}
\end{array}
if z < -9e11 or -2.8000000000000002e-41 < z < -3.1000000000000001e-103 or 5.6999999999999999e-117 < z Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around 0 100.0%
Taylor expanded in y around inf 89.3%
if -9e11 < z < -2.8000000000000002e-41 or -3.1000000000000001e-103 < z < 5.6999999999999999e-117Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around inf 89.4%
Final simplification89.3%
(FPCore (x y z)
:precision binary64
(if (<= z -112000000000.0)
z
(if (<= z -4e-41)
(* x 0.5)
(if (<= z -5.5e-105) z (if (<= z 3.8e-116) (* x 0.5) z)))))
double code(double x, double y, double z) {
double tmp;
if (z <= -112000000000.0) {
tmp = z;
} else if (z <= -4e-41) {
tmp = x * 0.5;
} else if (z <= -5.5e-105) {
tmp = z;
} else if (z <= 3.8e-116) {
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 <= (-112000000000.0d0)) then
tmp = z
else if (z <= (-4d-41)) then
tmp = x * 0.5d0
else if (z <= (-5.5d-105)) then
tmp = z
else if (z <= 3.8d-116) 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 <= -112000000000.0) {
tmp = z;
} else if (z <= -4e-41) {
tmp = x * 0.5;
} else if (z <= -5.5e-105) {
tmp = z;
} else if (z <= 3.8e-116) {
tmp = x * 0.5;
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -112000000000.0: tmp = z elif z <= -4e-41: tmp = x * 0.5 elif z <= -5.5e-105: tmp = z elif z <= 3.8e-116: tmp = x * 0.5 else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if (z <= -112000000000.0) tmp = z; elseif (z <= -4e-41) tmp = Float64(x * 0.5); elseif (z <= -5.5e-105) tmp = z; elseif (z <= 3.8e-116) tmp = Float64(x * 0.5); else tmp = z; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -112000000000.0) tmp = z; elseif (z <= -4e-41) tmp = x * 0.5; elseif (z <= -5.5e-105) tmp = z; elseif (z <= 3.8e-116) tmp = x * 0.5; else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -112000000000.0], z, If[LessEqual[z, -4e-41], N[(x * 0.5), $MachinePrecision], If[LessEqual[z, -5.5e-105], z, If[LessEqual[z, 3.8e-116], N[(x * 0.5), $MachinePrecision], z]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -112000000000:\\
\;\;\;\;z\\
\mathbf{elif}\;z \leq -4 \cdot 10^{-41}:\\
\;\;\;\;x \cdot 0.5\\
\mathbf{elif}\;z \leq -5.5 \cdot 10^{-105}:\\
\;\;\;\;z\\
\mathbf{elif}\;z \leq 3.8 \cdot 10^{-116}:\\
\;\;\;\;x \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if z < -1.12e11 or -4.00000000000000002e-41 < z < -5.50000000000000029e-105 or 3.8000000000000001e-116 < z Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around 0 61.4%
if -1.12e11 < z < -4.00000000000000002e-41 or -5.50000000000000029e-105 < z < 3.8000000000000001e-116Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around inf 89.4%
Taylor expanded in y around 0 45.6%
Final simplification54.7%
(FPCore (x y z) :precision binary64 (if (or (<= y -0.5) (not (<= y 0.0034))) (+ (* x y) z) (+ z (* x 0.5))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -0.5) || !(y <= 0.0034)) {
tmp = (x * y) + z;
} 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.0034d0))) then
tmp = (x * y) + z
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.0034)) {
tmp = (x * y) + z;
} else {
tmp = z + (x * 0.5);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -0.5) or not (y <= 0.0034): tmp = (x * y) + z else: tmp = z + (x * 0.5) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -0.5) || !(y <= 0.0034)) tmp = Float64(Float64(x * y) + z); 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.0034))) tmp = (x * y) + z; 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.0034]], $MachinePrecision]], N[(N[(x * y), $MachinePrecision] + z), $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.0034\right):\\
\;\;\;\;x \cdot y + z\\
\mathbf{else}:\\
\;\;\;\;z + x \cdot 0.5\\
\end{array}
\end{array}
if y < -0.5 or 0.00339999999999999981 < y Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around 0 100.0%
Taylor expanded in y around inf 99.3%
if -0.5 < y < 0.00339999999999999981Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in y around 0 98.2%
Final simplification98.7%
(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 40.8%
Final simplification40.8%
herbie shell --seed 2023238
(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))