
(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 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%
+-commutative100.0%
remove-double-neg100.0%
distribute-frac-neg100.0%
sub-neg100.0%
neg-mul-1100.0%
*-commutative100.0%
associate-/l*100.0%
*-commutative100.0%
distribute-rgt-out--100.0%
fma-define100.0%
sub-neg100.0%
metadata-eval100.0%
metadata-eval100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(if (<= y -3.8e+31)
(* x y)
(if (<= y -2.06e-159)
z
(if (<= y 2.65e-194)
(* x 0.5)
(if (<= y 2.2e-74)
z
(if (<= y 3.1e-23) (* x 0.5) (if (<= y 2.7e+107) z (* x y))))))))
double code(double x, double y, double z) {
double tmp;
if (y <= -3.8e+31) {
tmp = x * y;
} else if (y <= -2.06e-159) {
tmp = z;
} else if (y <= 2.65e-194) {
tmp = x * 0.5;
} else if (y <= 2.2e-74) {
tmp = z;
} else if (y <= 3.1e-23) {
tmp = x * 0.5;
} else if (y <= 2.7e+107) {
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 <= (-3.8d+31)) then
tmp = x * y
else if (y <= (-2.06d-159)) then
tmp = z
else if (y <= 2.65d-194) then
tmp = x * 0.5d0
else if (y <= 2.2d-74) then
tmp = z
else if (y <= 3.1d-23) then
tmp = x * 0.5d0
else if (y <= 2.7d+107) 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 <= -3.8e+31) {
tmp = x * y;
} else if (y <= -2.06e-159) {
tmp = z;
} else if (y <= 2.65e-194) {
tmp = x * 0.5;
} else if (y <= 2.2e-74) {
tmp = z;
} else if (y <= 3.1e-23) {
tmp = x * 0.5;
} else if (y <= 2.7e+107) {
tmp = z;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -3.8e+31: tmp = x * y elif y <= -2.06e-159: tmp = z elif y <= 2.65e-194: tmp = x * 0.5 elif y <= 2.2e-74: tmp = z elif y <= 3.1e-23: tmp = x * 0.5 elif y <= 2.7e+107: tmp = z else: tmp = x * y return tmp
function code(x, y, z) tmp = 0.0 if (y <= -3.8e+31) tmp = Float64(x * y); elseif (y <= -2.06e-159) tmp = z; elseif (y <= 2.65e-194) tmp = Float64(x * 0.5); elseif (y <= 2.2e-74) tmp = z; elseif (y <= 3.1e-23) tmp = Float64(x * 0.5); elseif (y <= 2.7e+107) tmp = z; else tmp = Float64(x * y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -3.8e+31) tmp = x * y; elseif (y <= -2.06e-159) tmp = z; elseif (y <= 2.65e-194) tmp = x * 0.5; elseif (y <= 2.2e-74) tmp = z; elseif (y <= 3.1e-23) tmp = x * 0.5; elseif (y <= 2.7e+107) tmp = z; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -3.8e+31], N[(x * y), $MachinePrecision], If[LessEqual[y, -2.06e-159], z, If[LessEqual[y, 2.65e-194], N[(x * 0.5), $MachinePrecision], If[LessEqual[y, 2.2e-74], z, If[LessEqual[y, 3.1e-23], N[(x * 0.5), $MachinePrecision], If[LessEqual[y, 2.7e+107], z, N[(x * y), $MachinePrecision]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.8 \cdot 10^{+31}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;y \leq -2.06 \cdot 10^{-159}:\\
\;\;\;\;z\\
\mathbf{elif}\;y \leq 2.65 \cdot 10^{-194}:\\
\;\;\;\;x \cdot 0.5\\
\mathbf{elif}\;y \leq 2.2 \cdot 10^{-74}:\\
\;\;\;\;z\\
\mathbf{elif}\;y \leq 3.1 \cdot 10^{-23}:\\
\;\;\;\;x \cdot 0.5\\
\mathbf{elif}\;y \leq 2.7 \cdot 10^{+107}:\\
\;\;\;\;z\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if y < -3.8000000000000001e31 or 2.7000000000000001e107 < y Initial program 100.0%
+-commutative100.0%
remove-double-neg100.0%
distribute-frac-neg100.0%
sub-neg100.0%
neg-mul-1100.0%
*-commutative100.0%
associate-/l*100.0%
*-commutative100.0%
distribute-rgt-out--100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in y around inf 67.6%
if -3.8000000000000001e31 < y < -2.05999999999999989e-159 or 2.6500000000000001e-194 < y < 2.2000000000000001e-74 or 3.0999999999999999e-23 < y < 2.7000000000000001e107Initial program 100.0%
+-commutative100.0%
remove-double-neg100.0%
distribute-frac-neg100.0%
sub-neg100.0%
neg-mul-1100.0%
*-commutative100.0%
associate-/l*100.0%
*-commutative100.0%
distribute-rgt-out--100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in x around 0 63.3%
if -2.05999999999999989e-159 < y < 2.6500000000000001e-194 or 2.2000000000000001e-74 < y < 3.0999999999999999e-23Initial program 100.0%
+-commutative100.0%
remove-double-neg100.0%
distribute-frac-neg100.0%
sub-neg100.0%
neg-mul-1100.0%
*-commutative100.0%
associate-/l*100.0%
*-commutative100.0%
distribute-rgt-out--100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in x around inf 63.3%
Taylor expanded in y around 0 63.3%
*-commutative63.3%
Simplified63.3%
Final simplification64.8%
(FPCore (x y z) :precision binary64 (if (<= z -6.5e+23) z (if (<= z 6e+49) (* x (+ y 0.5)) z)))
double code(double x, double y, double z) {
double tmp;
if (z <= -6.5e+23) {
tmp = z;
} else if (z <= 6e+49) {
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 <= (-6.5d+23)) then
tmp = z
else if (z <= 6d+49) 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 <= -6.5e+23) {
tmp = z;
} else if (z <= 6e+49) {
tmp = x * (y + 0.5);
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -6.5e+23: tmp = z elif z <= 6e+49: tmp = x * (y + 0.5) else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if (z <= -6.5e+23) tmp = z; elseif (z <= 6e+49) 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 <= -6.5e+23) tmp = z; elseif (z <= 6e+49) tmp = x * (y + 0.5); else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -6.5e+23], z, If[LessEqual[z, 6e+49], N[(x * N[(y + 0.5), $MachinePrecision]), $MachinePrecision], z]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -6.5 \cdot 10^{+23}:\\
\;\;\;\;z\\
\mathbf{elif}\;z \leq 6 \cdot 10^{+49}:\\
\;\;\;\;x \cdot \left(y + 0.5\right)\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if z < -6.4999999999999996e23 or 6.0000000000000005e49 < z Initial program 100.0%
+-commutative100.0%
remove-double-neg100.0%
distribute-frac-neg100.0%
sub-neg100.0%
neg-mul-1100.0%
*-commutative100.0%
associate-/l*100.0%
*-commutative100.0%
distribute-rgt-out--100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in x around 0 72.8%
if -6.4999999999999996e23 < z < 6.0000000000000005e49Initial program 100.0%
+-commutative100.0%
remove-double-neg100.0%
distribute-frac-neg100.0%
sub-neg100.0%
neg-mul-1100.0%
*-commutative100.0%
associate-/l*100.0%
*-commutative100.0%
distribute-rgt-out--100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in x around inf 81.1%
Final simplification77.1%
(FPCore (x y z) :precision binary64 (if (<= y -9e-5) (* x (+ y 0.5)) (if (<= y 1.85e+109) (+ z (* x 0.5)) (* x y))))
double code(double x, double y, double z) {
double tmp;
if (y <= -9e-5) {
tmp = x * (y + 0.5);
} else if (y <= 1.85e+109) {
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 <= (-9d-5)) then
tmp = x * (y + 0.5d0)
else if (y <= 1.85d+109) 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 <= -9e-5) {
tmp = x * (y + 0.5);
} else if (y <= 1.85e+109) {
tmp = z + (x * 0.5);
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -9e-5: tmp = x * (y + 0.5) elif y <= 1.85e+109: tmp = z + (x * 0.5) else: tmp = x * y return tmp
function code(x, y, z) tmp = 0.0 if (y <= -9e-5) tmp = Float64(x * Float64(y + 0.5)); elseif (y <= 1.85e+109) 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 <= -9e-5) tmp = x * (y + 0.5); elseif (y <= 1.85e+109) tmp = z + (x * 0.5); else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -9e-5], N[(x * N[(y + 0.5), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 1.85e+109], N[(z + N[(x * 0.5), $MachinePrecision]), $MachinePrecision], N[(x * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -9 \cdot 10^{-5}:\\
\;\;\;\;x \cdot \left(y + 0.5\right)\\
\mathbf{elif}\;y \leq 1.85 \cdot 10^{+109}:\\
\;\;\;\;z + x \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if y < -9.00000000000000057e-5Initial program 99.9%
+-commutative99.9%
remove-double-neg99.9%
distribute-frac-neg99.9%
sub-neg99.9%
neg-mul-199.9%
*-commutative99.9%
associate-/l*99.9%
*-commutative99.9%
distribute-rgt-out--99.9%
metadata-eval99.9%
Simplified99.9%
Taylor expanded in x around inf 66.5%
if -9.00000000000000057e-5 < y < 1.8500000000000001e109Initial program 100.0%
+-commutative100.0%
remove-double-neg100.0%
distribute-frac-neg100.0%
sub-neg100.0%
neg-mul-1100.0%
*-commutative100.0%
associate-/l*100.0%
*-commutative100.0%
distribute-rgt-out--100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in y around 0 94.3%
*-commutative94.3%
Simplified94.3%
if 1.8500000000000001e109 < y Initial program 100.0%
+-commutative100.0%
remove-double-neg100.0%
distribute-frac-neg100.0%
sub-neg100.0%
neg-mul-1100.0%
*-commutative100.0%
associate-/l*100.0%
*-commutative100.0%
distribute-rgt-out--100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in y around inf 66.7%
Final simplification83.4%
(FPCore (x y z) :precision binary64 (if (<= z -780000000.0) z (if (<= z 3.6e-11) (* x 0.5) z)))
double code(double x, double y, double z) {
double tmp;
if (z <= -780000000.0) {
tmp = z;
} else if (z <= 3.6e-11) {
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 <= (-780000000.0d0)) then
tmp = z
else if (z <= 3.6d-11) 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 <= -780000000.0) {
tmp = z;
} else if (z <= 3.6e-11) {
tmp = x * 0.5;
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -780000000.0: tmp = z elif z <= 3.6e-11: tmp = x * 0.5 else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if (z <= -780000000.0) tmp = z; elseif (z <= 3.6e-11) tmp = Float64(x * 0.5); else tmp = z; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -780000000.0) tmp = z; elseif (z <= 3.6e-11) tmp = x * 0.5; else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -780000000.0], z, If[LessEqual[z, 3.6e-11], N[(x * 0.5), $MachinePrecision], z]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -780000000:\\
\;\;\;\;z\\
\mathbf{elif}\;z \leq 3.6 \cdot 10^{-11}:\\
\;\;\;\;x \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if z < -7.8e8 or 3.59999999999999985e-11 < z Initial program 100.0%
+-commutative100.0%
remove-double-neg100.0%
distribute-frac-neg100.0%
sub-neg100.0%
neg-mul-1100.0%
*-commutative100.0%
associate-/l*100.0%
*-commutative100.0%
distribute-rgt-out--100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in x around 0 68.4%
if -7.8e8 < z < 3.59999999999999985e-11Initial program 100.0%
+-commutative100.0%
remove-double-neg100.0%
distribute-frac-neg100.0%
sub-neg100.0%
neg-mul-1100.0%
*-commutative100.0%
associate-/l*100.0%
*-commutative100.0%
distribute-rgt-out--100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in x around inf 83.4%
Taylor expanded in y around 0 43.9%
*-commutative43.9%
Simplified43.9%
Final simplification57.4%
(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%
+-commutative100.0%
remove-double-neg100.0%
distribute-frac-neg100.0%
sub-neg100.0%
neg-mul-1100.0%
*-commutative100.0%
associate-/l*100.0%
*-commutative100.0%
distribute-rgt-out--100.0%
metadata-eval100.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%
+-commutative100.0%
remove-double-neg100.0%
distribute-frac-neg100.0%
sub-neg100.0%
neg-mul-1100.0%
*-commutative100.0%
associate-/l*100.0%
*-commutative100.0%
distribute-rgt-out--100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in x around 0 45.3%
Final simplification45.3%
herbie shell --seed 2024080
(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))