
(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 6 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 (or (<= y -0.5) (not (<= y 0.0078))) (+ (* x y) z) (+ z (* x 0.5))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -0.5) || !(y <= 0.0078)) {
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.0078d0))) 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.0078)) {
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.0078): 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.0078)) 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.0078))) 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.0078]], $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.0078\right):\\
\;\;\;\;x \cdot y + z\\
\mathbf{else}:\\
\;\;\;\;z + x \cdot 0.5\\
\end{array}
\end{array}
if y < -0.5 or 0.0077999999999999996 < y Initial program 100.0%
remove-double-neg100.0%
distribute-frac-neg100.0%
neg-mul-1100.0%
associate-/l*100.0%
associate-/r/100.0%
distribute-lft-neg-in100.0%
distribute-rgt-out100.0%
remove-double-neg100.0%
distribute-neg-in100.0%
sub-neg100.0%
fma-def100.0%
sub-neg100.0%
distribute-neg-in100.0%
sub-neg100.0%
fma-def100.0%
Simplified100.0%
Taylor expanded in y around inf 98.6%
if -0.5 < y < 0.0077999999999999996Initial program 100.0%
remove-double-neg100.0%
distribute-frac-neg100.0%
neg-mul-1100.0%
associate-/l*99.9%
associate-/r/100.0%
distribute-lft-neg-in100.0%
distribute-rgt-out100.0%
remove-double-neg100.0%
distribute-neg-in100.0%
sub-neg100.0%
fma-def100.0%
sub-neg100.0%
distribute-neg-in100.0%
sub-neg100.0%
fma-def100.0%
Simplified100.0%
Taylor expanded in y around 0 98.8%
Final simplification98.7%
(FPCore (x y z) :precision binary64 (if (<= y -3.4e+56) (* x y) (if (<= y 1.42e+23) (+ z (* x 0.5)) (* x y))))
double code(double x, double y, double z) {
double tmp;
if (y <= -3.4e+56) {
tmp = x * y;
} else if (y <= 1.42e+23) {
tmp = z + (x * 0.5);
} 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 <= (-3.4d+56)) then
tmp = x * y
else if (y <= 1.42d+23) then
tmp = z + (x * 0.5d0)
else
tmp = x * y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -3.4e+56) {
tmp = x * y;
} else if (y <= 1.42e+23) {
tmp = z + (x * 0.5);
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -3.4e+56: tmp = x * y elif y <= 1.42e+23: tmp = z + (x * 0.5) else: tmp = x * y return tmp
function code(x, y, z) tmp = 0.0 if (y <= -3.4e+56) tmp = Float64(x * y); elseif (y <= 1.42e+23) tmp = Float64(z + Float64(x * 0.5)); else tmp = Float64(x * y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -3.4e+56) tmp = x * y; elseif (y <= 1.42e+23) tmp = z + (x * 0.5); else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -3.4e+56], N[(x * y), $MachinePrecision], If[LessEqual[y, 1.42e+23], N[(z + N[(x * 0.5), $MachinePrecision]), $MachinePrecision], N[(x * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.4 \cdot 10^{+56}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;y \leq 1.42 \cdot 10^{+23}:\\
\;\;\;\;z + x \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if y < -3.40000000000000001e56 or 1.42000000000000004e23 < y Initial program 100.0%
remove-double-neg100.0%
distribute-frac-neg100.0%
neg-mul-1100.0%
associate-/l*100.0%
associate-/r/100.0%
distribute-lft-neg-in100.0%
distribute-rgt-out100.0%
remove-double-neg100.0%
distribute-neg-in100.0%
sub-neg100.0%
fma-def100.0%
sub-neg100.0%
distribute-neg-in100.0%
sub-neg100.0%
fma-def100.0%
Simplified100.0%
Taylor expanded in y around inf 100.0%
Taylor expanded in y around inf 81.0%
if -3.40000000000000001e56 < y < 1.42000000000000004e23Initial program 100.0%
remove-double-neg100.0%
distribute-frac-neg100.0%
neg-mul-1100.0%
associate-/l*99.9%
associate-/r/100.0%
distribute-lft-neg-in100.0%
distribute-rgt-out100.0%
remove-double-neg100.0%
distribute-neg-in100.0%
sub-neg100.0%
fma-def100.0%
sub-neg100.0%
distribute-neg-in100.0%
sub-neg100.0%
fma-def100.0%
Simplified100.0%
Taylor expanded in y around 0 95.7%
Final simplification90.0%
(FPCore (x y z) :precision binary64 (if (<= y -7.8e+59) (* x y) (if (<= y 4.6e+17) z (* x y))))
double code(double x, double y, double z) {
double tmp;
if (y <= -7.8e+59) {
tmp = x * y;
} else if (y <= 4.6e+17) {
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 <= (-7.8d+59)) then
tmp = x * y
else if (y <= 4.6d+17) 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 <= -7.8e+59) {
tmp = x * y;
} else if (y <= 4.6e+17) {
tmp = z;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -7.8e+59: tmp = x * y elif y <= 4.6e+17: tmp = z else: tmp = x * y return tmp
function code(x, y, z) tmp = 0.0 if (y <= -7.8e+59) tmp = Float64(x * y); elseif (y <= 4.6e+17) tmp = z; else tmp = Float64(x * y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -7.8e+59) tmp = x * y; elseif (y <= 4.6e+17) tmp = z; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -7.8e+59], N[(x * y), $MachinePrecision], If[LessEqual[y, 4.6e+17], z, N[(x * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -7.8 \cdot 10^{+59}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;y \leq 4.6 \cdot 10^{+17}:\\
\;\;\;\;z\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if y < -7.80000000000000043e59 or 4.6e17 < y Initial program 100.0%
remove-double-neg100.0%
distribute-frac-neg100.0%
neg-mul-1100.0%
associate-/l*100.0%
associate-/r/100.0%
distribute-lft-neg-in100.0%
distribute-rgt-out100.0%
remove-double-neg100.0%
distribute-neg-in100.0%
sub-neg100.0%
fma-def100.0%
sub-neg100.0%
distribute-neg-in100.0%
sub-neg100.0%
fma-def100.0%
Simplified100.0%
Taylor expanded in y around inf 100.0%
Taylor expanded in y around inf 81.0%
if -7.80000000000000043e59 < y < 4.6e17Initial program 100.0%
remove-double-neg100.0%
distribute-frac-neg100.0%
neg-mul-1100.0%
associate-/l*99.9%
associate-/r/100.0%
distribute-lft-neg-in100.0%
distribute-rgt-out100.0%
remove-double-neg100.0%
distribute-neg-in100.0%
sub-neg100.0%
fma-def100.0%
sub-neg100.0%
distribute-neg-in100.0%
sub-neg100.0%
fma-def100.0%
Simplified100.0%
Taylor expanded in x around 0 55.8%
Final simplification65.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%
remove-double-neg100.0%
distribute-frac-neg100.0%
neg-mul-1100.0%
associate-/l*99.9%
associate-/r/100.0%
distribute-lft-neg-in100.0%
distribute-rgt-out100.0%
remove-double-neg100.0%
distribute-neg-in100.0%
sub-neg100.0%
fma-def100.0%
sub-neg100.0%
distribute-neg-in100.0%
sub-neg100.0%
fma-def100.0%
Simplified100.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%
remove-double-neg100.0%
distribute-frac-neg100.0%
neg-mul-1100.0%
associate-/l*99.9%
associate-/r/100.0%
distribute-lft-neg-in100.0%
distribute-rgt-out100.0%
remove-double-neg100.0%
distribute-neg-in100.0%
sub-neg100.0%
fma-def100.0%
sub-neg100.0%
distribute-neg-in100.0%
sub-neg100.0%
fma-def100.0%
Simplified100.0%
Taylor expanded in x around 0 41.9%
Final simplification41.9%
herbie shell --seed 2023268
(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))