
(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 (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-lft-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 -1.25e+54)
(* x y)
(if (<= y 5.8e-286)
z
(if (<= y 1.06e-103) (* x 0.5) (if (<= y 1.4e+86) z (* x y))))))
double code(double x, double y, double z) {
double tmp;
if (y <= -1.25e+54) {
tmp = x * y;
} else if (y <= 5.8e-286) {
tmp = z;
} else if (y <= 1.06e-103) {
tmp = x * 0.5;
} else if (y <= 1.4e+86) {
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 <= (-1.25d+54)) then
tmp = x * y
else if (y <= 5.8d-286) then
tmp = z
else if (y <= 1.06d-103) then
tmp = x * 0.5d0
else if (y <= 1.4d+86) 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 <= -1.25e+54) {
tmp = x * y;
} else if (y <= 5.8e-286) {
tmp = z;
} else if (y <= 1.06e-103) {
tmp = x * 0.5;
} else if (y <= 1.4e+86) {
tmp = z;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -1.25e+54: tmp = x * y elif y <= 5.8e-286: tmp = z elif y <= 1.06e-103: tmp = x * 0.5 elif y <= 1.4e+86: tmp = z else: tmp = x * y return tmp
function code(x, y, z) tmp = 0.0 if (y <= -1.25e+54) tmp = Float64(x * y); elseif (y <= 5.8e-286) tmp = z; elseif (y <= 1.06e-103) tmp = Float64(x * 0.5); elseif (y <= 1.4e+86) tmp = z; else tmp = Float64(x * y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -1.25e+54) tmp = x * y; elseif (y <= 5.8e-286) tmp = z; elseif (y <= 1.06e-103) tmp = x * 0.5; elseif (y <= 1.4e+86) tmp = z; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -1.25e+54], N[(x * y), $MachinePrecision], If[LessEqual[y, 5.8e-286], z, If[LessEqual[y, 1.06e-103], N[(x * 0.5), $MachinePrecision], If[LessEqual[y, 1.4e+86], z, N[(x * y), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.25 \cdot 10^{+54}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;y \leq 5.8 \cdot 10^{-286}:\\
\;\;\;\;z\\
\mathbf{elif}\;y \leq 1.06 \cdot 10^{-103}:\\
\;\;\;\;x \cdot 0.5\\
\mathbf{elif}\;y \leq 1.4 \cdot 10^{+86}:\\
\;\;\;\;z\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if y < -1.25000000000000001e54 or 1.40000000000000002e86 < y Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around inf 75.3%
+-commutative75.3%
Simplified75.3%
Taylor expanded in y around inf 75.3%
if -1.25000000000000001e54 < y < 5.7999999999999996e-286 or 1.06000000000000004e-103 < y < 1.40000000000000002e86Initial program 100.0%
+-commutative100.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-lft-out--100.0%
cancel-sign-sub100.0%
distribute-lft-neg-in100.0%
distribute-rgt-neg-in100.0%
neg-sub0100.0%
associate-+l-100.0%
neg-sub0100.0%
+-commutative100.0%
sub-neg100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in y around inf 65.4%
associate-*r*65.4%
neg-mul-165.4%
Simplified65.4%
Taylor expanded in z around inf 57.7%
if 5.7999999999999996e-286 < y < 1.06000000000000004e-103Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around inf 66.8%
+-commutative66.8%
Simplified66.8%
Taylor expanded in y around 0 66.8%
*-commutative66.8%
Simplified66.8%
Final simplification66.5%
(FPCore (x y z) :precision binary64 (if (or (<= x -2.6e-103) (not (<= x 4.8e-135))) (* x (+ y 0.5)) z))
double code(double x, double y, double z) {
double tmp;
if ((x <= -2.6e-103) || !(x <= 4.8e-135)) {
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 <= (-2.6d-103)) .or. (.not. (x <= 4.8d-135))) 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 <= -2.6e-103) || !(x <= 4.8e-135)) {
tmp = x * (y + 0.5);
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -2.6e-103) or not (x <= 4.8e-135): tmp = x * (y + 0.5) else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -2.6e-103) || !(x <= 4.8e-135)) 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 <= -2.6e-103) || ~((x <= 4.8e-135))) tmp = x * (y + 0.5); else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -2.6e-103], N[Not[LessEqual[x, 4.8e-135]], $MachinePrecision]], N[(x * N[(y + 0.5), $MachinePrecision]), $MachinePrecision], z]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.6 \cdot 10^{-103} \lor \neg \left(x \leq 4.8 \cdot 10^{-135}\right):\\
\;\;\;\;x \cdot \left(y + 0.5\right)\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if x < -2.59999999999999996e-103 or 4.7999999999999997e-135 < x Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around inf 76.7%
+-commutative76.7%
Simplified76.7%
if -2.59999999999999996e-103 < x < 4.7999999999999997e-135Initial program 100.0%
+-commutative100.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-lft-out--100.0%
cancel-sign-sub100.0%
distribute-lft-neg-in100.0%
distribute-rgt-neg-in100.0%
neg-sub0100.0%
associate-+l-100.0%
neg-sub0100.0%
+-commutative100.0%
sub-neg100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in y around inf 96.0%
associate-*r*96.0%
neg-mul-196.0%
Simplified96.0%
Taylor expanded in z around inf 75.8%
Final simplification76.4%
(FPCore (x y z) :precision binary64 (if (or (<= z -9e-64) (not (<= z 2.15e+17))) (+ z (* x y)) (* x (+ y 0.5))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -9e-64) || !(z <= 2.15e+17)) {
tmp = z + (x * y);
} 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 <= (-9d-64)) .or. (.not. (z <= 2.15d+17))) then
tmp = z + (x * y)
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 <= -9e-64) || !(z <= 2.15e+17)) {
tmp = z + (x * y);
} else {
tmp = x * (y + 0.5);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -9e-64) or not (z <= 2.15e+17): tmp = z + (x * y) else: tmp = x * (y + 0.5) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -9e-64) || !(z <= 2.15e+17)) tmp = Float64(z + Float64(x * y)); else tmp = Float64(x * Float64(y + 0.5)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -9e-64) || ~((z <= 2.15e+17))) tmp = z + (x * y); else tmp = x * (y + 0.5); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -9e-64], N[Not[LessEqual[z, 2.15e+17]], $MachinePrecision]], N[(z + N[(x * y), $MachinePrecision]), $MachinePrecision], N[(x * N[(y + 0.5), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -9 \cdot 10^{-64} \lor \neg \left(z \leq 2.15 \cdot 10^{+17}\right):\\
\;\;\;\;z + x \cdot y\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(y + 0.5\right)\\
\end{array}
\end{array}
if z < -9.00000000000000019e-64 or 2.15e17 < z Initial program 100.0%
+-commutative100.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-lft-out--100.0%
cancel-sign-sub100.0%
distribute-lft-neg-in100.0%
distribute-rgt-neg-in100.0%
neg-sub0100.0%
associate-+l-100.0%
neg-sub0100.0%
+-commutative100.0%
sub-neg100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in y around inf 89.6%
associate-*r*89.6%
neg-mul-189.6%
Simplified89.6%
cancel-sign-sub89.6%
+-commutative89.6%
Applied egg-rr89.6%
if -9.00000000000000019e-64 < z < 2.15e17Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around inf 86.9%
+-commutative86.9%
Simplified86.9%
Final simplification88.4%
(FPCore (x y z) :precision binary64 (if (or (<= y -0.5) (not (<= y 0.0002))) (+ z (* x y)) (- z (* x -0.5))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -0.5) || !(y <= 0.0002)) {
tmp = z + (x * y);
} 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.0002d0))) then
tmp = z + (x * y)
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.0002)) {
tmp = z + (x * y);
} else {
tmp = z - (x * -0.5);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -0.5) or not (y <= 0.0002): tmp = z + (x * y) else: tmp = z - (x * -0.5) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -0.5) || !(y <= 0.0002)) tmp = Float64(z + Float64(x * y)); 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.0002))) tmp = z + (x * y); 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.0002]], $MachinePrecision]], N[(z + N[(x * y), $MachinePrecision]), $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.0002\right):\\
\;\;\;\;z + x \cdot y\\
\mathbf{else}:\\
\;\;\;\;z - x \cdot -0.5\\
\end{array}
\end{array}
if y < -0.5 or 2.0000000000000001e-4 < y Initial program 100.0%
+-commutative100.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-lft-out--100.0%
cancel-sign-sub100.0%
distribute-lft-neg-in100.0%
distribute-rgt-neg-in100.0%
neg-sub0100.0%
associate-+l-100.0%
neg-sub0100.0%
+-commutative100.0%
sub-neg100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in y around inf 99.0%
associate-*r*99.0%
neg-mul-199.0%
Simplified99.0%
cancel-sign-sub99.0%
+-commutative99.0%
Applied egg-rr99.0%
if -0.5 < y < 2.0000000000000001e-4Initial program 100.0%
+-commutative100.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-lft-out--100.0%
cancel-sign-sub100.0%
distribute-lft-neg-in100.0%
distribute-rgt-neg-in100.0%
neg-sub0100.0%
associate-+l-100.0%
neg-sub0100.0%
+-commutative100.0%
sub-neg100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in y around 0 98.5%
*-commutative98.5%
Simplified98.5%
Final simplification98.8%
(FPCore (x y z) :precision binary64 (if (<= z -2.8e-64) z (if (<= z 6.8e+19) (* x 0.5) z)))
double code(double x, double y, double z) {
double tmp;
if (z <= -2.8e-64) {
tmp = z;
} else if (z <= 6.8e+19) {
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 <= (-2.8d-64)) then
tmp = z
else if (z <= 6.8d+19) 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 <= -2.8e-64) {
tmp = z;
} else if (z <= 6.8e+19) {
tmp = x * 0.5;
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -2.8e-64: tmp = z elif z <= 6.8e+19: tmp = x * 0.5 else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if (z <= -2.8e-64) tmp = z; elseif (z <= 6.8e+19) tmp = Float64(x * 0.5); else tmp = z; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -2.8e-64) tmp = z; elseif (z <= 6.8e+19) tmp = x * 0.5; else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -2.8e-64], z, If[LessEqual[z, 6.8e+19], N[(x * 0.5), $MachinePrecision], z]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.8 \cdot 10^{-64}:\\
\;\;\;\;z\\
\mathbf{elif}\;z \leq 6.8 \cdot 10^{+19}:\\
\;\;\;\;x \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if z < -2.80000000000000004e-64 or 6.8e19 < z Initial program 100.0%
+-commutative100.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-lft-out--100.0%
cancel-sign-sub100.0%
distribute-lft-neg-in100.0%
distribute-rgt-neg-in100.0%
neg-sub0100.0%
associate-+l-100.0%
neg-sub0100.0%
+-commutative100.0%
sub-neg100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in y around inf 89.6%
associate-*r*89.6%
neg-mul-189.6%
Simplified89.6%
Taylor expanded in z around inf 61.7%
if -2.80000000000000004e-64 < z < 6.8e19Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around inf 86.9%
+-commutative86.9%
Simplified86.9%
Taylor expanded in y around 0 38.7%
*-commutative38.7%
Simplified38.7%
Final simplification51.5%
(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%
+-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-lft-out--100.0%
cancel-sign-sub100.0%
distribute-lft-neg-in100.0%
distribute-rgt-neg-in100.0%
neg-sub0100.0%
associate-+l-100.0%
neg-sub0100.0%
+-commutative100.0%
sub-neg100.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%
+-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-lft-out--100.0%
cancel-sign-sub100.0%
distribute-lft-neg-in100.0%
distribute-rgt-neg-in100.0%
neg-sub0100.0%
associate-+l-100.0%
neg-sub0100.0%
+-commutative100.0%
sub-neg100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in y around inf 77.3%
associate-*r*77.3%
neg-mul-177.3%
Simplified77.3%
Taylor expanded in z around inf 40.8%
Final simplification40.8%
herbie shell --seed 2024046
(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))