
(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 7 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 (+ z (* (+ 0.5 y) x)))
double code(double x, double y, double z) {
return z + ((0.5 + y) * x);
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = z + ((0.5d0 + y) * x)
end function
public static double code(double x, double y, double z) {
return z + ((0.5 + y) * x);
}
def code(x, y, z): return z + ((0.5 + y) * x)
function code(x, y, z) return Float64(z + Float64(Float64(0.5 + y) * x)) end
function tmp = code(x, y, z) tmp = z + ((0.5 + y) * x); end
code[x_, y_, z_] := N[(z + N[(N[(0.5 + y), $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
z + \left(0.5 + y\right) \cdot x
\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
(if (<= y -6e+64)
(* y x)
(if (<= y -3.8e-126)
z
(if (<= y -5.7e-241)
(* 0.5 x)
(if (<= y 5.8e-223)
z
(if (<= y 4.1e-52) (* 0.5 x) (if (<= y 8.2e+52) z (* y x))))))))
double code(double x, double y, double z) {
double tmp;
if (y <= -6e+64) {
tmp = y * x;
} else if (y <= -3.8e-126) {
tmp = z;
} else if (y <= -5.7e-241) {
tmp = 0.5 * x;
} else if (y <= 5.8e-223) {
tmp = z;
} else if (y <= 4.1e-52) {
tmp = 0.5 * x;
} else if (y <= 8.2e+52) {
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 <= (-6d+64)) then
tmp = y * x
else if (y <= (-3.8d-126)) then
tmp = z
else if (y <= (-5.7d-241)) then
tmp = 0.5d0 * x
else if (y <= 5.8d-223) then
tmp = z
else if (y <= 4.1d-52) then
tmp = 0.5d0 * x
else if (y <= 8.2d+52) 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 <= -6e+64) {
tmp = y * x;
} else if (y <= -3.8e-126) {
tmp = z;
} else if (y <= -5.7e-241) {
tmp = 0.5 * x;
} else if (y <= 5.8e-223) {
tmp = z;
} else if (y <= 4.1e-52) {
tmp = 0.5 * x;
} else if (y <= 8.2e+52) {
tmp = z;
} else {
tmp = y * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -6e+64: tmp = y * x elif y <= -3.8e-126: tmp = z elif y <= -5.7e-241: tmp = 0.5 * x elif y <= 5.8e-223: tmp = z elif y <= 4.1e-52: tmp = 0.5 * x elif y <= 8.2e+52: tmp = z else: tmp = y * x return tmp
function code(x, y, z) tmp = 0.0 if (y <= -6e+64) tmp = Float64(y * x); elseif (y <= -3.8e-126) tmp = z; elseif (y <= -5.7e-241) tmp = Float64(0.5 * x); elseif (y <= 5.8e-223) tmp = z; elseif (y <= 4.1e-52) tmp = Float64(0.5 * x); elseif (y <= 8.2e+52) tmp = z; else tmp = Float64(y * x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -6e+64) tmp = y * x; elseif (y <= -3.8e-126) tmp = z; elseif (y <= -5.7e-241) tmp = 0.5 * x; elseif (y <= 5.8e-223) tmp = z; elseif (y <= 4.1e-52) tmp = 0.5 * x; elseif (y <= 8.2e+52) tmp = z; else tmp = y * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -6e+64], N[(y * x), $MachinePrecision], If[LessEqual[y, -3.8e-126], z, If[LessEqual[y, -5.7e-241], N[(0.5 * x), $MachinePrecision], If[LessEqual[y, 5.8e-223], z, If[LessEqual[y, 4.1e-52], N[(0.5 * x), $MachinePrecision], If[LessEqual[y, 8.2e+52], z, N[(y * x), $MachinePrecision]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -6 \cdot 10^{+64}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;y \leq -3.8 \cdot 10^{-126}:\\
\;\;\;\;z\\
\mathbf{elif}\;y \leq -5.7 \cdot 10^{-241}:\\
\;\;\;\;0.5 \cdot x\\
\mathbf{elif}\;y \leq 5.8 \cdot 10^{-223}:\\
\;\;\;\;z\\
\mathbf{elif}\;y \leq 4.1 \cdot 10^{-52}:\\
\;\;\;\;0.5 \cdot x\\
\mathbf{elif}\;y \leq 8.2 \cdot 10^{+52}:\\
\;\;\;\;z\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if y < -6.0000000000000004e64 or 8.1999999999999999e52 < y Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in y around inf 76.2%
if -6.0000000000000004e64 < y < -3.7999999999999999e-126 or -5.6999999999999998e-241 < y < 5.8000000000000001e-223 or 4.09999999999999988e-52 < y < 8.1999999999999999e52Initial program 99.9%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around 0 63.8%
if -3.7999999999999999e-126 < y < -5.6999999999999998e-241 or 5.8000000000000001e-223 < y < 4.09999999999999988e-52Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around inf 63.2%
Taylor expanded in y around 0 63.2%
Final simplification68.9%
(FPCore (x y z)
:precision binary64
(if (<= z -5.3e+177)
z
(if (or (<= z -9.5e+113) (and (not (<= z -9.5e-15)) (<= z 3.8e+42)))
(* (+ 0.5 y) x)
z)))
double code(double x, double y, double z) {
double tmp;
if (z <= -5.3e+177) {
tmp = z;
} else if ((z <= -9.5e+113) || (!(z <= -9.5e-15) && (z <= 3.8e+42))) {
tmp = (0.5 + y) * x;
} 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.3d+177)) then
tmp = z
else if ((z <= (-9.5d+113)) .or. (.not. (z <= (-9.5d-15))) .and. (z <= 3.8d+42)) then
tmp = (0.5d0 + y) * x
else
tmp = z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= -5.3e+177) {
tmp = z;
} else if ((z <= -9.5e+113) || (!(z <= -9.5e-15) && (z <= 3.8e+42))) {
tmp = (0.5 + y) * x;
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -5.3e+177: tmp = z elif (z <= -9.5e+113) or (not (z <= -9.5e-15) and (z <= 3.8e+42)): tmp = (0.5 + y) * x else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if (z <= -5.3e+177) tmp = z; elseif ((z <= -9.5e+113) || (!(z <= -9.5e-15) && (z <= 3.8e+42))) tmp = Float64(Float64(0.5 + y) * x); else tmp = z; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -5.3e+177) tmp = z; elseif ((z <= -9.5e+113) || (~((z <= -9.5e-15)) && (z <= 3.8e+42))) tmp = (0.5 + y) * x; else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -5.3e+177], z, If[Or[LessEqual[z, -9.5e+113], And[N[Not[LessEqual[z, -9.5e-15]], $MachinePrecision], LessEqual[z, 3.8e+42]]], N[(N[(0.5 + y), $MachinePrecision] * x), $MachinePrecision], z]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -5.3 \cdot 10^{+177}:\\
\;\;\;\;z\\
\mathbf{elif}\;z \leq -9.5 \cdot 10^{+113} \lor \neg \left(z \leq -9.5 \cdot 10^{-15}\right) \land z \leq 3.8 \cdot 10^{+42}:\\
\;\;\;\;\left(0.5 + y\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if z < -5.2999999999999997e177 or -9.5000000000000001e113 < z < -9.5000000000000005e-15 or 3.7999999999999998e42 < z Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around 0 74.3%
if -5.2999999999999997e177 < z < -9.5000000000000001e113 or -9.5000000000000005e-15 < z < 3.7999999999999998e42Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around inf 85.1%
Final simplification80.3%
(FPCore (x y z) :precision binary64 (if (or (<= x -9.5e+44) (not (<= x 1.8e+62))) (* (+ 0.5 y) x) (+ z (* y x))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -9.5e+44) || !(x <= 1.8e+62)) {
tmp = (0.5 + y) * x;
} else {
tmp = z + (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 ((x <= (-9.5d+44)) .or. (.not. (x <= 1.8d+62))) then
tmp = (0.5d0 + y) * x
else
tmp = z + (y * x)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -9.5e+44) || !(x <= 1.8e+62)) {
tmp = (0.5 + y) * x;
} else {
tmp = z + (y * x);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -9.5e+44) or not (x <= 1.8e+62): tmp = (0.5 + y) * x else: tmp = z + (y * x) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -9.5e+44) || !(x <= 1.8e+62)) tmp = Float64(Float64(0.5 + y) * x); else tmp = Float64(z + Float64(y * x)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -9.5e+44) || ~((x <= 1.8e+62))) tmp = (0.5 + y) * x; else tmp = z + (y * x); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -9.5e+44], N[Not[LessEqual[x, 1.8e+62]], $MachinePrecision]], N[(N[(0.5 + y), $MachinePrecision] * x), $MachinePrecision], N[(z + N[(y * x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -9.5 \cdot 10^{+44} \lor \neg \left(x \leq 1.8 \cdot 10^{+62}\right):\\
\;\;\;\;\left(0.5 + y\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;z + y \cdot x\\
\end{array}
\end{array}
if x < -9.5000000000000004e44 or 1.8e62 < x Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around inf 86.9%
if -9.5000000000000004e44 < x < 1.8e62Initial 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 88.1%
Final simplification87.6%
(FPCore (x y z) :precision binary64 (if (or (<= y -1.9e+14) (not (<= y 1.25e-6))) (+ z (* y x)) (+ z (* 0.5 x))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.9e+14) || !(y <= 1.25e-6)) {
tmp = z + (y * x);
} else {
tmp = z + (0.5 * 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 <= (-1.9d+14)) .or. (.not. (y <= 1.25d-6))) then
tmp = z + (y * x)
else
tmp = z + (0.5d0 * x)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -1.9e+14) || !(y <= 1.25e-6)) {
tmp = z + (y * x);
} else {
tmp = z + (0.5 * x);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1.9e+14) or not (y <= 1.25e-6): tmp = z + (y * x) else: tmp = z + (0.5 * x) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1.9e+14) || !(y <= 1.25e-6)) tmp = Float64(z + Float64(y * x)); else tmp = Float64(z + Float64(0.5 * x)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -1.9e+14) || ~((y <= 1.25e-6))) tmp = z + (y * x); else tmp = z + (0.5 * x); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -1.9e+14], N[Not[LessEqual[y, 1.25e-6]], $MachinePrecision]], N[(z + N[(y * x), $MachinePrecision]), $MachinePrecision], N[(z + N[(0.5 * x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.9 \cdot 10^{+14} \lor \neg \left(y \leq 1.25 \cdot 10^{-6}\right):\\
\;\;\;\;z + y \cdot x\\
\mathbf{else}:\\
\;\;\;\;z + 0.5 \cdot x\\
\end{array}
\end{array}
if y < -1.9e14 or 1.2500000000000001e-6 < 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 100.0%
if -1.9e14 < y < 1.2500000000000001e-6Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in y around 0 98.5%
Final simplification99.2%
(FPCore (x y z) :precision binary64 (if (<= z -2e-32) z (if (<= z 7e+35) (* 0.5 x) z)))
double code(double x, double y, double z) {
double tmp;
if (z <= -2e-32) {
tmp = z;
} else if (z <= 7e+35) {
tmp = 0.5 * x;
} 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 <= (-2d-32)) then
tmp = z
else if (z <= 7d+35) then
tmp = 0.5d0 * x
else
tmp = z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= -2e-32) {
tmp = z;
} else if (z <= 7e+35) {
tmp = 0.5 * x;
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -2e-32: tmp = z elif z <= 7e+35: tmp = 0.5 * x else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if (z <= -2e-32) tmp = z; elseif (z <= 7e+35) tmp = Float64(0.5 * x); else tmp = z; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -2e-32) tmp = z; elseif (z <= 7e+35) tmp = 0.5 * x; else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -2e-32], z, If[LessEqual[z, 7e+35], N[(0.5 * x), $MachinePrecision], z]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2 \cdot 10^{-32}:\\
\;\;\;\;z\\
\mathbf{elif}\;z \leq 7 \cdot 10^{+35}:\\
\;\;\;\;0.5 \cdot x\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if z < -2.00000000000000011e-32 or 7.0000000000000001e35 < z Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around 0 68.4%
if -2.00000000000000011e-32 < z < 7.0000000000000001e35Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around inf 85.1%
Taylor expanded in y around 0 37.5%
Final simplification52.7%
(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 42.7%
Final simplification42.7%
herbie shell --seed 2023176
(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))