
(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 (+ 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%
distribute-rgt-neg-out100.0%
unsub-neg100.0%
neg-mul-1100.0%
associate-/l*99.9%
associate-/r/100.0%
distribute-rgt-out--100.0%
metadata-eval100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(if (or (<= x -1.05e+17)
(not
(or (<= x -8.5e-52) (and (not (<= x -2.55e-116)) (<= x 5.6e-140)))))
(* x (+ y 0.5))
z))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.05e+17) || !((x <= -8.5e-52) || (!(x <= -2.55e-116) && (x <= 5.6e-140)))) {
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 <= (-1.05d+17)) .or. (.not. (x <= (-8.5d-52)) .or. (.not. (x <= (-2.55d-116))) .and. (x <= 5.6d-140))) 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 <= -1.05e+17) || !((x <= -8.5e-52) || (!(x <= -2.55e-116) && (x <= 5.6e-140)))) {
tmp = x * (y + 0.5);
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.05e+17) or not ((x <= -8.5e-52) or (not (x <= -2.55e-116) and (x <= 5.6e-140))): tmp = x * (y + 0.5) else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.05e+17) || !((x <= -8.5e-52) || (!(x <= -2.55e-116) && (x <= 5.6e-140)))) 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 <= -1.05e+17) || ~(((x <= -8.5e-52) || (~((x <= -2.55e-116)) && (x <= 5.6e-140))))) tmp = x * (y + 0.5); else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.05e+17], N[Not[Or[LessEqual[x, -8.5e-52], And[N[Not[LessEqual[x, -2.55e-116]], $MachinePrecision], LessEqual[x, 5.6e-140]]]], $MachinePrecision]], N[(x * N[(y + 0.5), $MachinePrecision]), $MachinePrecision], z]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.05 \cdot 10^{+17} \lor \neg \left(x \leq -8.5 \cdot 10^{-52} \lor \neg \left(x \leq -2.55 \cdot 10^{-116}\right) \land x \leq 5.6 \cdot 10^{-140}\right):\\
\;\;\;\;x \cdot \left(y + 0.5\right)\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if x < -1.05e17 or -8.50000000000000006e-52 < x < -2.5500000000000001e-116 or 5.6000000000000005e-140 < x 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%
distribute-rgt-neg-out100.0%
unsub-neg100.0%
neg-mul-1100.0%
associate-/l*99.9%
associate-/r/100.0%
distribute-rgt-out--100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in z around 0 83.7%
if -1.05e17 < x < -8.50000000000000006e-52 or -2.5500000000000001e-116 < x < 5.6000000000000005e-140Initial 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%
distribute-rgt-neg-out100.0%
unsub-neg100.0%
neg-mul-1100.0%
associate-/l*100.0%
associate-/r/100.0%
distribute-rgt-out--100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in z around inf 73.3%
Final simplification80.6%
(FPCore (x y z) :precision binary64 (if (or (<= y -0.5) (not (<= y 0.5))) (+ z (* x y)) (- z (* x -0.5))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -0.5) || !(y <= 0.5)) {
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.5d0))) 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.5)) {
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.5): 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.5)) 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.5))) 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.5]], $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.5\right):\\
\;\;\;\;z + x \cdot y\\
\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-neg-in100.0%
distribute-frac-neg100.0%
distribute-rgt-neg-out100.0%
unsub-neg100.0%
distribute-rgt-neg-out100.0%
unsub-neg100.0%
neg-mul-1100.0%
associate-/l*100.0%
associate-/r/100.0%
distribute-rgt-out--100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in y around inf 97.7%
mul-1-neg97.7%
*-commutative97.7%
distribute-rgt-neg-in97.7%
Simplified97.7%
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%
distribute-rgt-neg-out100.0%
unsub-neg100.0%
neg-mul-1100.0%
associate-/l*99.8%
associate-/r/100.0%
distribute-rgt-out--100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in y around 0 99.3%
*-commutative99.3%
Simplified99.3%
Final simplification98.5%
(FPCore (x y z) :precision binary64 (if (<= y -0.019) (* x (+ y 0.5)) (if (<= y 1.1e+19) (- z (* x -0.5)) (* x y))))
double code(double x, double y, double z) {
double tmp;
if (y <= -0.019) {
tmp = x * (y + 0.5);
} else if (y <= 1.1e+19) {
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 <= (-0.019d0)) then
tmp = x * (y + 0.5d0)
else if (y <= 1.1d+19) 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 <= -0.019) {
tmp = x * (y + 0.5);
} else if (y <= 1.1e+19) {
tmp = z - (x * -0.5);
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -0.019: tmp = x * (y + 0.5) elif y <= 1.1e+19: tmp = z - (x * -0.5) else: tmp = x * y return tmp
function code(x, y, z) tmp = 0.0 if (y <= -0.019) tmp = Float64(x * Float64(y + 0.5)); elseif (y <= 1.1e+19) 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 <= -0.019) tmp = x * (y + 0.5); elseif (y <= 1.1e+19) tmp = z - (x * -0.5); else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -0.019], N[(x * N[(y + 0.5), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 1.1e+19], N[(z - N[(x * -0.5), $MachinePrecision]), $MachinePrecision], N[(x * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -0.019:\\
\;\;\;\;x \cdot \left(y + 0.5\right)\\
\mathbf{elif}\;y \leq 1.1 \cdot 10^{+19}:\\
\;\;\;\;z - x \cdot -0.5\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if y < -0.0189999999999999995Initial 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%
distribute-rgt-neg-out100.0%
unsub-neg100.0%
neg-mul-1100.0%
associate-/l*100.0%
associate-/r/100.0%
distribute-rgt-out--100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in z around 0 81.6%
if -0.0189999999999999995 < y < 1.1e19Initial 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%
distribute-rgt-neg-out100.0%
unsub-neg100.0%
neg-mul-1100.0%
associate-/l*99.8%
associate-/r/100.0%
distribute-rgt-out--100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in y around 0 97.4%
*-commutative97.4%
Simplified97.4%
if 1.1e19 < y 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%
distribute-rgt-neg-out100.0%
unsub-neg100.0%
neg-mul-1100.0%
associate-/l*100.0%
associate-/r/100.0%
distribute-rgt-out--100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in y around inf 75.5%
Final simplification88.6%
(FPCore (x y z) :precision binary64 (if (or (<= y -9e+57) (not (<= y 1.15e+19))) (* x y) z))
double code(double x, double y, double z) {
double tmp;
if ((y <= -9e+57) || !(y <= 1.15e+19)) {
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 ((y <= (-9d+57)) .or. (.not. (y <= 1.15d+19))) 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 ((y <= -9e+57) || !(y <= 1.15e+19)) {
tmp = x * y;
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -9e+57) or not (y <= 1.15e+19): tmp = x * y else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -9e+57) || !(y <= 1.15e+19)) tmp = Float64(x * y); else tmp = z; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -9e+57) || ~((y <= 1.15e+19))) tmp = x * y; else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -9e+57], N[Not[LessEqual[y, 1.15e+19]], $MachinePrecision]], N[(x * y), $MachinePrecision], z]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -9 \cdot 10^{+57} \lor \neg \left(y \leq 1.15 \cdot 10^{+19}\right):\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if y < -8.99999999999999991e57 or 1.15e19 < y 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%
distribute-rgt-neg-out100.0%
unsub-neg100.0%
neg-mul-1100.0%
associate-/l*100.0%
associate-/r/100.0%
distribute-rgt-out--100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in y around inf 80.2%
if -8.99999999999999991e57 < y < 1.15e19Initial 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%
distribute-rgt-neg-out100.0%
unsub-neg100.0%
neg-mul-1100.0%
associate-/l*99.8%
associate-/r/100.0%
distribute-rgt-out--100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in z around inf 44.3%
Final simplification59.7%
(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-neg-in100.0%
distribute-frac-neg100.0%
distribute-rgt-neg-out100.0%
unsub-neg100.0%
distribute-rgt-neg-out100.0%
unsub-neg100.0%
neg-mul-1100.0%
associate-/l*99.9%
associate-/r/100.0%
distribute-rgt-out--100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in z around inf 34.7%
Final simplification34.7%
herbie shell --seed 2024021
(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))