
(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 (+ (/ 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(x / 2.0) + Float64(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[(x / 2.0), $MachinePrecision] + N[(N[(x * y), $MachinePrecision] + z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x}{2} + \left(x \cdot y + z\right)
\end{array}
Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
(FPCore (x y z)
:precision binary64
(if (<= z -2.5e-5)
z
(if (<= z -1.7e-189)
(* x y)
(if (<= z 1.75e-158) (* x 0.5) (if (<= z 4.5e-48) (* x y) z)))))
double code(double x, double y, double z) {
double tmp;
if (z <= -2.5e-5) {
tmp = z;
} else if (z <= -1.7e-189) {
tmp = x * y;
} else if (z <= 1.75e-158) {
tmp = x * 0.5;
} else if (z <= 4.5e-48) {
tmp = x * y;
} 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.5d-5)) then
tmp = z
else if (z <= (-1.7d-189)) then
tmp = x * y
else if (z <= 1.75d-158) then
tmp = x * 0.5d0
else if (z <= 4.5d-48) then
tmp = x * y
else
tmp = z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= -2.5e-5) {
tmp = z;
} else if (z <= -1.7e-189) {
tmp = x * y;
} else if (z <= 1.75e-158) {
tmp = x * 0.5;
} else if (z <= 4.5e-48) {
tmp = x * y;
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -2.5e-5: tmp = z elif z <= -1.7e-189: tmp = x * y elif z <= 1.75e-158: tmp = x * 0.5 elif z <= 4.5e-48: tmp = x * y else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if (z <= -2.5e-5) tmp = z; elseif (z <= -1.7e-189) tmp = Float64(x * y); elseif (z <= 1.75e-158) tmp = Float64(x * 0.5); elseif (z <= 4.5e-48) tmp = Float64(x * y); else tmp = z; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -2.5e-5) tmp = z; elseif (z <= -1.7e-189) tmp = x * y; elseif (z <= 1.75e-158) tmp = x * 0.5; elseif (z <= 4.5e-48) tmp = x * y; else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -2.5e-5], z, If[LessEqual[z, -1.7e-189], N[(x * y), $MachinePrecision], If[LessEqual[z, 1.75e-158], N[(x * 0.5), $MachinePrecision], If[LessEqual[z, 4.5e-48], N[(x * y), $MachinePrecision], z]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.5 \cdot 10^{-5}:\\
\;\;\;\;z\\
\mathbf{elif}\;z \leq -1.7 \cdot 10^{-189}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;z \leq 1.75 \cdot 10^{-158}:\\
\;\;\;\;x \cdot 0.5\\
\mathbf{elif}\;z \leq 4.5 \cdot 10^{-48}:\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if z < -2.50000000000000012e-5 or 4.49999999999999988e-48 < z Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around 0 63.7%
if -2.50000000000000012e-5 < z < -1.7000000000000001e-189 or 1.75000000000000006e-158 < z < 4.49999999999999988e-48Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in y around inf 60.6%
if -1.7000000000000001e-189 < z < 1.75000000000000006e-158Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around inf 98.1%
Taylor expanded in y around 0 63.3%
*-commutative63.3%
Simplified63.3%
(FPCore (x y z) :precision binary64 (if (or (<= y -0.5) (not (<= y 0.5))) (+ (* x y) z) (- z (* x -0.5))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -0.5) || !(y <= 0.5)) {
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.5d0))) 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.5)) {
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.5): 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.5)) 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.5))) 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.5]], $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.5\right):\\
\;\;\;\;x \cdot y + z\\
\mathbf{else}:\\
\;\;\;\;z - x \cdot -0.5\\
\end{array}
\end{array}
if y < -0.5 or 0.5 < 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%
fma-define100.0%
sub-neg100.0%
metadata-eval100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in y around inf 99.3%
fma-undefine99.3%
Applied egg-rr99.3%
if -0.5 < y < 0.5Initial program 100.0%
+-commutative100.0%
remove-double-neg100.0%
distribute-neg-in100.0%
distribute-frac-neg100.0%
distribute-rgt-neg-out100.0%
unsub-neg100.0%
+-commutative100.0%
+-commutative100.0%
*-commutative100.0%
cancel-sign-sub-inv100.0%
neg-mul-1100.0%
*-commutative100.0%
associate-/l*100.0%
distribute-lft-out--100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in y around 0 98.2%
*-commutative98.2%
Simplified98.2%
Final simplification98.7%
(FPCore (x y z) :precision binary64 (if (or (<= x -9.8e+117) (not (<= x 1.9e+32))) (* x (+ y 0.5)) (+ (* x y) z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -9.8e+117) || !(x <= 1.9e+32)) {
tmp = x * (y + 0.5);
} else {
tmp = (x * y) + 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 <= (-9.8d+117)) .or. (.not. (x <= 1.9d+32))) then
tmp = x * (y + 0.5d0)
else
tmp = (x * y) + z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -9.8e+117) || !(x <= 1.9e+32)) {
tmp = x * (y + 0.5);
} else {
tmp = (x * y) + z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -9.8e+117) or not (x <= 1.9e+32): tmp = x * (y + 0.5) else: tmp = (x * y) + z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -9.8e+117) || !(x <= 1.9e+32)) tmp = Float64(x * Float64(y + 0.5)); else tmp = Float64(Float64(x * y) + z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -9.8e+117) || ~((x <= 1.9e+32))) tmp = x * (y + 0.5); else tmp = (x * y) + z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -9.8e+117], N[Not[LessEqual[x, 1.9e+32]], $MachinePrecision]], N[(x * N[(y + 0.5), $MachinePrecision]), $MachinePrecision], N[(N[(x * y), $MachinePrecision] + z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -9.8 \cdot 10^{+117} \lor \neg \left(x \leq 1.9 \cdot 10^{+32}\right):\\
\;\;\;\;x \cdot \left(y + 0.5\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot y + z\\
\end{array}
\end{array}
if x < -9.8000000000000002e117 or 1.9000000000000002e32 < x Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around inf 88.5%
if -9.8000000000000002e117 < x < 1.9000000000000002e32Initial 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%
Taylor expanded in y around inf 86.5%
fma-undefine86.5%
Applied egg-rr86.5%
Final simplification87.3%
(FPCore (x y z) :precision binary64 (if (or (<= x -2.5e-36) (not (<= x 6.6e-66))) (* x (+ y 0.5)) z))
double code(double x, double y, double z) {
double tmp;
if ((x <= -2.5e-36) || !(x <= 6.6e-66)) {
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.5d-36)) .or. (.not. (x <= 6.6d-66))) 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.5e-36) || !(x <= 6.6e-66)) {
tmp = x * (y + 0.5);
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -2.5e-36) or not (x <= 6.6e-66): tmp = x * (y + 0.5) else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -2.5e-36) || !(x <= 6.6e-66)) 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.5e-36) || ~((x <= 6.6e-66))) tmp = x * (y + 0.5); else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -2.5e-36], N[Not[LessEqual[x, 6.6e-66]], $MachinePrecision]], N[(x * N[(y + 0.5), $MachinePrecision]), $MachinePrecision], z]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.5 \cdot 10^{-36} \lor \neg \left(x \leq 6.6 \cdot 10^{-66}\right):\\
\;\;\;\;x \cdot \left(y + 0.5\right)\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if x < -2.50000000000000002e-36 or 6.5999999999999998e-66 < x Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around inf 80.8%
if -2.50000000000000002e-36 < x < 6.5999999999999998e-66Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around 0 73.0%
Final simplification77.4%
(FPCore (x y z) :precision binary64 (if (or (<= x -740000.0) (not (<= x 4.7e+32))) (* x 0.5) z))
double code(double x, double y, double z) {
double tmp;
if ((x <= -740000.0) || !(x <= 4.7e+32)) {
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 ((x <= (-740000.0d0)) .or. (.not. (x <= 4.7d+32))) 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 ((x <= -740000.0) || !(x <= 4.7e+32)) {
tmp = x * 0.5;
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -740000.0) or not (x <= 4.7e+32): tmp = x * 0.5 else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -740000.0) || !(x <= 4.7e+32)) tmp = Float64(x * 0.5); else tmp = z; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -740000.0) || ~((x <= 4.7e+32))) tmp = x * 0.5; else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -740000.0], N[Not[LessEqual[x, 4.7e+32]], $MachinePrecision]], N[(x * 0.5), $MachinePrecision], z]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -740000 \lor \neg \left(x \leq 4.7 \cdot 10^{+32}\right):\\
\;\;\;\;x \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if x < -7.4e5 or 4.70000000000000023e32 < x Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around inf 84.6%
Taylor expanded in y around 0 46.9%
*-commutative46.9%
Simplified46.9%
if -7.4e5 < x < 4.70000000000000023e32Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around 0 64.4%
Final simplification56.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%
remove-double-neg100.0%
distribute-neg-in100.0%
distribute-frac-neg100.0%
distribute-rgt-neg-out100.0%
unsub-neg100.0%
+-commutative100.0%
+-commutative100.0%
*-commutative100.0%
cancel-sign-sub-inv100.0%
neg-mul-1100.0%
*-commutative100.0%
associate-/l*100.0%
distribute-lft-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%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around 0 42.0%
herbie shell --seed 2024185
(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))