Exemple #1
0
    def eliminate_error(n, s):
        """Eliminate error term of given asymptotic order n.

        The stream s must be based on halving h at each step
        for the formula used here to work."""
        while True:
            a, b, s = unpack(2, s, k=1)
            yield (b * 2**n - a) / (2**(n - 1))
Exemple #2
0
 def len_gt(k, s):
     # see also unpythonic.slicing.islice; could implement as  return islice(s)[k + 1]
     a, _ = unpack(1, drop(k, s))
     return a  # None if no item
Exemple #3
0
 def euler_transform(s):
     while True:
         a, b, c, s = unpack(3, s, k=1)
         yield c - ((c - b)**2 / (a - 2 * b + c))
Exemple #4
0
 def order(s):
     """Estimate asymptotic order of s, consuming the first three terms."""
     a, b, c, _ = unpack(3, s)
     return round(log2(abs((a - c) / (b - c)) - 1))
Exemple #5
0
 def within(eps, s):  # in real code, prefer unpythonic.it.within
     while True:
         # unpack with peek (but be careful, the rewinded tail is a tee'd copy)
         a, b, s = unpack(2, s, k=1)
         if abs(a - b) < eps:
             return b
Exemple #6
0
 def len_gt(k, s):
     a, _ = unpack(1, drop(k, s))
     return a  # None if no item
Exemple #7
0
 def within(eps, s):
     while True:
         # unpack with peek (but be careful, the rewinded tail is a tee'd copy)
         a, b, s = unpack(2, s, k=1)
         if abs(a - b) < eps:
             return b