
(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 (fma (+ 0.5 y) x z))
double code(double x, double y, double z) {
return fma((0.5 + y), x, z);
}
function code(x, y, z) return fma(Float64(0.5 + y), x, z) end
code[x_, y_, z_] := N[(N[(0.5 + y), $MachinePrecision] * x + z), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(0.5 + y, x, 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%
fma-def100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(if (or (<= x -6.8e+117)
(not (or (<= x -1e+72) (and (not (<= x -3.9e-94)) (<= x 2.8e-63)))))
(* (+ 0.5 y) x)
z))
double code(double x, double y, double z) {
double tmp;
if ((x <= -6.8e+117) || !((x <= -1e+72) || (!(x <= -3.9e-94) && (x <= 2.8e-63)))) {
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 ((x <= (-6.8d+117)) .or. (.not. (x <= (-1d+72)) .or. (.not. (x <= (-3.9d-94))) .and. (x <= 2.8d-63))) 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 ((x <= -6.8e+117) || !((x <= -1e+72) || (!(x <= -3.9e-94) && (x <= 2.8e-63)))) {
tmp = (0.5 + y) * x;
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -6.8e+117) or not ((x <= -1e+72) or (not (x <= -3.9e-94) and (x <= 2.8e-63))): tmp = (0.5 + y) * x else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -6.8e+117) || !((x <= -1e+72) || (!(x <= -3.9e-94) && (x <= 2.8e-63)))) 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 ((x <= -6.8e+117) || ~(((x <= -1e+72) || (~((x <= -3.9e-94)) && (x <= 2.8e-63))))) tmp = (0.5 + y) * x; else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -6.8e+117], N[Not[Or[LessEqual[x, -1e+72], And[N[Not[LessEqual[x, -3.9e-94]], $MachinePrecision], LessEqual[x, 2.8e-63]]]], $MachinePrecision]], N[(N[(0.5 + y), $MachinePrecision] * x), $MachinePrecision], z]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -6.8 \cdot 10^{+117} \lor \neg \left(x \leq -1 \cdot 10^{+72} \lor \neg \left(x \leq -3.9 \cdot 10^{-94}\right) \land x \leq 2.8 \cdot 10^{-63}\right):\\
\;\;\;\;\left(0.5 + y\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if x < -6.8000000000000002e117 or -9.99999999999999944e71 < x < -3.9000000000000002e-94 or 2.8000000000000002e-63 < x Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around inf 81.6%
if -6.8000000000000002e117 < x < -9.99999999999999944e71 or -3.9000000000000002e-94 < x < 2.8000000000000002e-63Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around 0 74.4%
Final simplification78.5%
(FPCore (x y z) :precision binary64 (if (<= z -1.8e-65) z (if (<= z -1.12e-226) (* 0.5 x) (if (<= z 4.8e+54) (* y x) z))))
double code(double x, double y, double z) {
double tmp;
if (z <= -1.8e-65) {
tmp = z;
} else if (z <= -1.12e-226) {
tmp = 0.5 * x;
} else if (z <= 4.8e+54) {
tmp = 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 <= (-1.8d-65)) then
tmp = z
else if (z <= (-1.12d-226)) then
tmp = 0.5d0 * x
else if (z <= 4.8d+54) then
tmp = 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 <= -1.8e-65) {
tmp = z;
} else if (z <= -1.12e-226) {
tmp = 0.5 * x;
} else if (z <= 4.8e+54) {
tmp = y * x;
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -1.8e-65: tmp = z elif z <= -1.12e-226: tmp = 0.5 * x elif z <= 4.8e+54: tmp = y * x else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if (z <= -1.8e-65) tmp = z; elseif (z <= -1.12e-226) tmp = Float64(0.5 * x); elseif (z <= 4.8e+54) tmp = Float64(y * x); else tmp = z; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -1.8e-65) tmp = z; elseif (z <= -1.12e-226) tmp = 0.5 * x; elseif (z <= 4.8e+54) tmp = y * x; else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -1.8e-65], z, If[LessEqual[z, -1.12e-226], N[(0.5 * x), $MachinePrecision], If[LessEqual[z, 4.8e+54], N[(y * x), $MachinePrecision], z]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.8 \cdot 10^{-65}:\\
\;\;\;\;z\\
\mathbf{elif}\;z \leq -1.12 \cdot 10^{-226}:\\
\;\;\;\;0.5 \cdot x\\
\mathbf{elif}\;z \leq 4.8 \cdot 10^{+54}:\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if z < -1.7999999999999999e-65 or 4.79999999999999997e54 < z Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around 0 66.0%
if -1.7999999999999999e-65 < z < -1.11999999999999992e-226Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around inf 82.8%
Taylor expanded in y around 0 56.4%
if -1.11999999999999992e-226 < z < 4.79999999999999997e54Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in y around inf 57.4%
Final simplification62.0%
(FPCore (x y z) :precision binary64 (if (or (<= y -0.05) (not (<= y 2.8e+34))) (* (+ 0.5 y) x) (+ z (* 0.5 x))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -0.05) || !(y <= 2.8e+34)) {
tmp = (0.5 + 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 <= (-0.05d0)) .or. (.not. (y <= 2.8d+34))) then
tmp = (0.5d0 + 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 <= -0.05) || !(y <= 2.8e+34)) {
tmp = (0.5 + y) * x;
} else {
tmp = z + (0.5 * x);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -0.05) or not (y <= 2.8e+34): tmp = (0.5 + y) * x else: tmp = z + (0.5 * x) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -0.05) || !(y <= 2.8e+34)) tmp = Float64(Float64(0.5 + 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 <= -0.05) || ~((y <= 2.8e+34))) tmp = (0.5 + y) * x; else tmp = z + (0.5 * x); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -0.05], N[Not[LessEqual[y, 2.8e+34]], $MachinePrecision]], N[(N[(0.5 + y), $MachinePrecision] * x), $MachinePrecision], N[(z + N[(0.5 * x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -0.05 \lor \neg \left(y \leq 2.8 \cdot 10^{+34}\right):\\
\;\;\;\;\left(0.5 + y\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;z + 0.5 \cdot x\\
\end{array}
\end{array}
if y < -0.050000000000000003 or 2.80000000000000008e34 < y Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around inf 69.6%
if -0.050000000000000003 < y < 2.80000000000000008e34Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in y around 0 98.5%
Final simplification85.4%
(FPCore (x y z) :precision binary64 (if (<= z -7e-68) z (if (<= z 1.5e+15) (* 0.5 x) z)))
double code(double x, double y, double z) {
double tmp;
if (z <= -7e-68) {
tmp = z;
} else if (z <= 1.5e+15) {
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 <= (-7d-68)) then
tmp = z
else if (z <= 1.5d+15) 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 <= -7e-68) {
tmp = z;
} else if (z <= 1.5e+15) {
tmp = 0.5 * x;
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -7e-68: tmp = z elif z <= 1.5e+15: tmp = 0.5 * x else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if (z <= -7e-68) tmp = z; elseif (z <= 1.5e+15) tmp = Float64(0.5 * x); else tmp = z; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -7e-68) tmp = z; elseif (z <= 1.5e+15) tmp = 0.5 * x; else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -7e-68], z, If[LessEqual[z, 1.5e+15], N[(0.5 * x), $MachinePrecision], z]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -7 \cdot 10^{-68}:\\
\;\;\;\;z\\
\mathbf{elif}\;z \leq 1.5 \cdot 10^{+15}:\\
\;\;\;\;0.5 \cdot x\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if z < -7.00000000000000026e-68 or 1.5e15 < z Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around 0 63.2%
if -7.00000000000000026e-68 < z < 1.5e15Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around inf 85.9%
Taylor expanded in y around 0 41.5%
Final simplification54.0%
(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 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.8%
Final simplification42.8%
herbie shell --seed 2023199
(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))