
    gfq                        d Z ddlmZmZmZmZ ddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddlZddlmZmZ ddlmZmZmZ ddlmZmZ ddlmZmZmZmZ ddlmZmZ 	 d#d	Zd
 Zd Zd Z	 	 d$dZ d Z!	 d#dZ"	 	 d%dZ#	 	 	 d&dZ$	 	 	 d'dZ%d(dZ&dddddd fdZ'd%dZ(	 	 	 	 	 d)dZ)	 	 	 	 	 	 	 d*dZ*	 	 d+dZ+d fdZ,d  Z-d! Z.e/d"k(  r( ee ja                                 e
jb                          yy),zP
PyMRT: code that is now deprecated but can still be useful for legacy scripts.
    )divisionabsolute_importprint_functionunicode_literalsN)INFOPATH)VERB_LVL
D_VERB_LVLVERB_LVL_NAMES)elapsedreport)msgdbgfmtfmtm)HAS_JITjitc                    i ddddddddd	d
dddddddddddddddddddddd }||v r||   }n||j                         v r|}nd!}|r1t        j                  j                         rd"j	                  | |#      S | S )$a  
    Add color TTY-compatible color code to a string, for pretty-printing.

    DEPRECATED! (use `blessed` module)

    Args:
        text (str): The text to color.
        color (str|int|None): Identifier for the color coding.
            Lowercase letters modify the forground color.
            Uppercase letters modify the background color.
            Available colors:

             - r/R: red
             - g/G: green
             - b/B: blue
             - c/C: cyan
             - m/M: magenta
             - y/Y: yellow (brown)
             - k/K: black (gray)
             - w/W: white (gray)

    Returns:
        text (str): The colored text.

    See also:
        tty_colors
    r   g    b"   c$   m#   y!   w%   k   R)   G*   B,   C.   M-   Y+   W/   K(   Nz[1;{color}m{}[1;m)color)valuessysstdoutisattyformat)textr5   
tty_colors	tty_colors       n/var/dept/share/cheung/public_html/OutSchool/python/env/lib/python3.12/site-packages/flyingcircus/_obsolete.pytty_colorifyr?      s   <Rbr#&,/58">A2GJBRbr#&,/58">A2GJBJ
 
u%		*##%	%		SZZ&&(*11$i1HH    c                 t    | dk(  xs | dk7  xr | dz   }d}|s||z  | k  r| |z   }|dz  }|s	||z  | k  r| S )a  
    Determine if num is a prime number.

    A prime number is only divisible by 1 and itself.
    0 and 1 are considered special cases; in this implementations they are
    considered primes.

    It is implemented by directly testing for possible factors.

    Args:
        val (int): The number to check for primality.
            Only works for numbers larger than 1.

    Returns:
        is_divisible (bool): The result of the primality.

    Examples:
        >>> is_prime_verbose(100)
        False
        >>> is_prime_verbose(101)
        True
        >>> is_prime_verbose(-100)
        False
        >>> is_prime_verbose(-101)
        True
        >>> is_prime_verbose(2 ** 17)
        False
        >>> is_prime_verbose(17 * 19)
        False
        >>> is_prime_verbose(2 ** 17 - 1)
        True
        >>> is_prime_verbose(0)
        False
        >>> is_prime_verbose(1)
        False
              )valis_divisibleis      r>   is_prime_verboserI   O   sb    L !8;q :#']L	Aq1us{!G}	Q q1us{ r@   c                 z    | dk  r|  } | dz  s| dkD  ryt        dt        | dz        dz   d      D ]	  }| |z  r	 y y)a  
    Determine if num is a prime number.

    A prime number is only divisible by 1 and itself.
    0 and 1 are considered special cases; in this implementations they are
    considered primes.

    It is implemented by directly testing for possible factors.

    Args:
        val (int): The number to check for primality.
            Only works for numbers larger than 1.

    Returns:
        is_divisible (bool): The result of the primality.

    Examples:
        >>> is_prime_optimized(100)
        False
        >>> is_prime_optimized(101)
        True
        >>> is_prime_optimized(-100)
        False
        >>> is_prime_optimized(-101)
        True
        >>> is_prime_optimized(2 ** 17)
        False
        >>> is_prime_optimized(17 * 19)
        False
        >>> is_prime_optimized(2 ** 17 - 1)
        True
        >>> is_prime_optimized(0)
        True
        >>> is_prime_optimized(1)
        True
    r   rC   FrD   g      ?rB   T)rangeint)rF   rH   s     r>   is_prime_optimizedrM      sW    L Qwd!Gq1c#*o)1- a r@   c                     | d   | d   z
  S )a'  
    Calculate the (signed) size of an interval given as a 2-tuple (A,B)

    DEPRECATED! (by `numpy.ptp()`)

    Args:
        interval (float,float): Interval for computation

    Returns:
        val (float): The converted value

    Examples:
        >>> interval_size((0, 1))
        1
    rB   r   rE   )intervals    r>   interval_sizerP      s      A;!$$r@   c              #     K   t        |      s#	 t        |      }|rt        j                  |      }| D ]0  } ||      s| 	 t        |      r ||      n
t        |       2 y# t        $ r |f}d}Y ]w xY w# t        $ r Y  yw xY ww)a
  
    Replace items matching a specific condition.

    This is fairly useless:

    If `replace` is callable:
        replace_iter(items, condition, replace)
    becomes:
        [replace(x) if condition(x) else x for x in items]

    If `replace` is not Iterable:
        list(replace_iter(items, condition, replace))
    becomes:
        [replace if condition(x) else x for x in items]

    If `replace` is Iterable and cycle == False:
        list(replace_iter(items, condition, replace))
    becomes:
        iter_replace = iter(replace)
        [next(iter_replace) if condition(x) else x for x in items]

    If `replace` is Iterable and cycle == True:
        list(replace_iter(items, condition, replace))
    becomes:
        iter_replace = itertools.cycle(replace)
        [next(iter_replace) if condition(x) else x for x in items]


    Args:
        items (Iterable): The input items.
        condition (callable): The condition for the replacement.
        replace (any|Iterable|callable): The replacement.
            If Iterable, its elements are used for replacement.
            If callable, it is applied to the elements matching `condition`.
            Otherwise, the object itself is used.
        cycle (bool): Cycle through the replace.
            If True and `replace` is Iterable, its elements are cycled through.
            Otherwise `items` beyond last replacement are lost.

    Yields:
        item: The next item from items or its replacement.

    Examples:
        >>> ll = list(range(10))
        >>> list(replace_iter(ll, lambda x: x % 2 == 0))
        [None, 1, None, 3, None, 5, None, 7, None, 9]
        >>> list(replace_iter(ll, lambda x: x % 2 == 0, lambda x: x ** 2))
        [0, 1, 4, 3, 16, 5, 36, 7, 64, 9]
        >>> list(replace_iter(ll, lambda x: x % 2 == 0, 100))
        [100, 1, 100, 3, 100, 5, 100, 7, 100, 9]
        >>> list(replace_iter(ll, lambda x: x % 2 == 0, range(10, 0, -1)))
        [10, 1, 9, 3, 8, 5, 7, 7, 6, 9]
        >>> list(replace_iter(ll, lambda x: x % 2 == 0, range(10, 8, -1)))
        [10, 1, 9, 3, 10, 5, 9, 7, 10, 9]
        >>> list(replace_iter(
        ...     ll, lambda x: x % 2 == 0, range(10, 8, -1), False))
        [10, 1, 9, 3]

        >>> ll = list(range(10))
        >>> (list(replace_iter(ll, lambda x: x % 2 == 0, lambda x: x ** 2))
        ...     == [x ** 2 if x % 2 == 0 else x for x in ll])
        True
        >>> (list(replace_iter(ll, lambda x: x % 2 == 0, 'X'))
        ...     == ['X' if x % 2 == 0 else x for x in ll])
        True
        >>> iter_ascii_letters = iter(string.ascii_letters)
        >>> (list(replace_iter(ll, lambda x: x % 2 == 0, string.ascii_letters))
        ...     == [next(iter_ascii_letters) if x % 2 == 0 else x for x in ll])
        True
    TN)callableiter	TypeError	itertoolscyclenextStopIteration)items	conditionreplacerV   items        r>   replace_iterr]      s     V G	7mG oog.G J'/'8gdmd7mK  	jGE	 ! sK   BA' )B A;$B'A85B7A88B;	BBBBc                       dk  r    dv ry dz  r dkD  r
 dz  r dkD  sy dk(  s dk(  ryt         fdt        j                   d      D              ryy)	a  
    Determine if number is prime.

    WARNING! DO NOT USE THIS ALGORITHM AS IT IS EXTREMELY INEFFICIENT!

    A prime number is only divisible by 1 and itself.
    0 and 1 are considered special cases; in this implementations they are
    considered primes.

    It is implemented by using the binomial triangle primality test.
    This is known to be extremely inefficient.

    Args:
        val (int): The number to check for primality.
            Only works for numbers larger than 1.

    Returns:
        is_divisible (bool): The result of the primality.

    Examples:
        >>> is_prime_binomial(100)
        False
        >>> is_prime_binomial(101)
        True
        >>> is_prime_binomial(-100)
        False
        >>> is_prime_binomial(-101)
        True
        >>> is_prime_binomial(2 ** 17)
        False
        >>> is_prime_binomial(17 * 19)
        False
        >>> is_prime_binomial(2 ** 13 - 1)
        True
        >>> is_prime_binomial(0)
        True
        >>> is_prime_binomial(1)
        True

    See Also:
        - flyingcircus.is_prime()
        - flyingcircus.primes_range()
        - https://en.wikipedia.org/wiki/Prime_number
    r   )r   rB   TrC   rD   Fc              3   4   K   | ]  }|d kD  r|z     ywrB   NrE   ).0nrF   s     r>   	<genexpr>z$is_prime_binomial.<locals>.<genexpr>W  s&      1u SMs   )full)allfcget_binomial_coeffs)rF   s   `r>   is_prime_binomialrh   "  st    Z Qwd
f}1WqsQw37	SAX	 #%#9#9#E#J 
 r@   c                     | dk  r|  } dnDt        t              r t        t        j                  d            nt        t                    D ]  }| |z  r	| |k  c S  t        j                        }t        fdt        d|dz         D              }t        t        j                  ||d   |z   fz               }t        |      }d}|d   }||z  | k  r!| |z  sy|||   z  }|dz  }||z  }||z  | k  r!y)aH  
    Determine if a number is prime.

    This uses a wheel factorization implementation.

    A prime number is only divisible by 1 and itself.
    0 and 1 are considered special cases; in this implementations they are
    considered primes.

    It is implemented by testing for possible factors using wheel increment.

    Args:
        num (int): The number to check for primality.
            Only works for numbers larger than 1.
        wheel (int|Sequence[int]|None): The generators of the wheel.
            If int, this is the number of prime numbers to use (must be > 1),
            generated using `flyingcircus.gen_primes()`.
            If Sequence, it must consist of the first N prime numbers in
            increasing order.
            If None, uses a hard-coded (2, 3) wheel, which is faster
            for smaller inputs.

    Returns:
        is_divisible (bool): The result of the primality.

    Examples:
        >>> is_prime_wheel(100)
        False
        >>> is_prime_wheel(101)
        True
        >>> is_prime_wheel(-100)
        False
        >>> is_prime_wheel(-101)
        True
        >>> is_prime_wheel(2 ** 17)
        False
        >>> is_prime_wheel(17 * 19)
        False
        >>> is_prime_wheel(2 ** 17 - 1)
        True
        >>> is_prime_wheel(2 ** 31 - 1)
        True
        >>> is_prime_wheel(2 ** 17 - 1, 2)
        True
        >>> is_prime_wheel(2 ** 17 - 1, (2, 3))
        True
        >>> is_prime_wheel(2 ** 17 - 1, (2, 3, 5))
        True
        >>> is_prime_wheel(0)
        True
        >>> is_prime_wheel(1)
        True

    See Also:
        - flyingcircus.is_prime()
        - flyingcircus.primes_range()

    References:
        - https://en.wikipedia.org/wiki/Prime_number
        - https://en.wikipedia.org/wiki/Trial_division
        - https://en.wikipedia.org/wiki/Wheel_factorization
    r   rC   rD   rC   c              3   L   K   | ]  t        fd D              r  yw)c              3   P   K   | ]  }t        j                  |      d k(    ywr`   )mathgcd)ra   r#   rb   s     r>   rc   z+is_prime_wheel.<locals>.<genexpr>.<genexpr>  s      2qtxx1~"2s   #&N)re   )ra   rb   wheels    @r>   rc   z!is_prime_wheel.<locals>.<genexpr>  s'      42E22 	
4s    $FrB   T)
isinstancerL   listrf   
get_primestuplesortedprodrK   difflen)	numro   r#   
prod_wheelcoprimesdeltas
len_deltasjrH   s	    `       r>   is_prime_wheelr~   `  s   D Qwd}	E3	R]]5!,-fUm$ Qw!8O J 4JN+4 4H 2778x{Z'?&AABCFVJ	AA
a%3,a	VAY	Q	Z a%3, r@   rC   rD   c              #   d   K   d ||z  }d}|| k  r| |r||z  }d}n||z  }d}|| k  ryyw)a  
    Generate steps for `step_sort()` (Shell sort).

    These are of the form a ** n * b ** m with n == m or n == m + 1

    Args:
        n (int): The length of the sequence.
        a (int): The first number.
        b (int): The second number.

    Yields:
        int: The next step.

    Examples:
        >>> list(steps_alt(100000))
        [1, 6, 18, 36, 108, 216, 648, 1296, 3888, 7776, 23328, 46656]
        >>> list(steps_alt(100000, 3, 2))
        [1, 6, 12, 36, 72, 216, 432, 1296, 2592, 7776, 15552, 46656, 93312]
    rB   r   NrE   )rb   ar   xps        r>   	steps_altr     sO     . G	AA	A
a%FAAFAA a%   +00c              #      K   	 |D ]  }|  	 |z  |z  }|| k  r| ||z  |z  }|| k  ryy# t         $ r	 d}| Y 2w xY ww)uj  
    Generate steps for `step_sort()` (Shell sort).

    These are of the form: x(k) = m * x(k - 1) // d
    with some initial predefined values.

    Must be that `m > d`.

    If `init=(1, 4, 10, 23, 57, 132, 301, 701), m=9, d=4` this has been
    empirically suggested as yielding optimum empirical performances in the
    average case [Ciura2001], but unknown worst-case.
    If `init=(1, 4,), m=9, d=4` this is very close to yielding near-optimal
    empirical performances in the average case [Tokuda1992], but unknown
    worst-case.

    Args:
        n (int): The length of the sequence.
        init (Iterable[int]): The initial sequence.
        m (int): The multiplier for subsequent values.
        d (int): The divider for subsequent values.

    Yields:
        int: The next step.

    Examples:
        >>> list(steps_m_d(50000))
        [1, 4, 10, 23, 57, 132, 301, 701, 1577, 3548, 7983, 17961, 40412]
        >>> list(steps_m_d(50000, (1, 4)))
        [1, 4, 9, 20, 45, 101, 227, 510, 1147, 2580, 5805, 13061, 29387]

    See Also:
        - Ciura, Marcin (2001). "Best Increments for the Average Case of
          Shellsort" (PDF). In Freiwalds, Rusins (ed.). Proceedings of the
          13th International Symposium on Fundamentals of Computation Theory.
          London: Springer-Verlag. pp. 106–117. ISBN 978-3-540-42487-1
        - Tokuda, Naoyuki (1992). "An Improved Shellsort". In van Leeuven,
          Jan (ed.). Proceedings of the IFIP 12th World Computer Congress on
          Algorithms, Software, Architecture. Amsterdam: North-Holland
          Publishing Co. pp. 449–457. ISBN 978-0-444-89747-3.
    rB   N)
ValueError)rb   initr   dr   s        r>   	steps_m_dr     sk     Z 	AG	
 	
A
A
a%EQJ a%	  s*   A1 AAA AAAc              #   j   K   t        |      r ||       } |  	 | |z  |z  } | dkD  r|  nd yw)uY  
    Generate steps for `step_sort()` (Shell sort).

    These are of the form: x(k) = m * x(k - 1) // d
    with initial value equal `n`.

    Must be that `d > m`.

    If `d=11, m=4`, this is yielding near-optimal empirical performances
    in the average case [Gonnet1991], but unknown worst-case.

    Args:
        n (int): The length of the sequence.
        d (int): The divider for subsequent values.
        m (int): The multiplier for subsequent values.
        stopping (callable|None): The modifier for the stopping value.
            If None, defaults to `n`.
            If callable, must have the signature: stopping(int): int.
            The input is `n`.

    Yields:
        int: The next step.

    Examples:
        >>> list(steps_d_m(100000))
        [45454, 20660, 9390, 4268, 1940, 881, 400, 181, 82, 37, 16, 7, 3, 1]

    See Also:
        - Gonnet, Gaston H.; Baeza-Yates, Ricardo (1991). "Shellsort".
          Handbook of Algorithms and Data Structures: In Pascal and C (2nd
          ed.). Reading, Massachusetts: Addison-Wesley. pp. 161–163.
          ISBN 978-0-201-41607-7.
    rB   NrR   )rb   r   r   stoppings       r>   	steps_d_mr     sH     L QK
EQJq5GG s   13rB   c              #   r   K   || k  r.| t        t        j                  |            }|dz  }|| k  r-yyw)a~  
    Generate steps for `step_sort()` (Shell sort).

    These follow an exponential law.

    Args:
        n (int): The length of the sequence.
        x (int): The initial value.
        k (int): The initial exponent.

    Yields:
        int: The next step.

    Examples:
        >>> list(steps_exp(100000))
        [1, 7, 20, 54, 148, 403, 1096, 2980, 8103, 22026, 59874]
    rB   N)rL   rm   exp)rb   r   r#   s      r>   	steps_expr   Q  s8     $ a%	Q a%   277c                     | dz  S )NrD   rE   )r   s    r>   <lambda>r   q  s
    16 r@   c              #   r   K   t        |      r ||       } || k  r| ||z  |z   |z  }|dz  }|| k  ryyw)u[  
    Generate steps for `step_sort()` (Shell sort).

    These are of the form: x(k) = (b ** k + c) // d
    with some initial value.

    With `x=1, k=2, b=2, c=-1, d=1, stopping=None` this has worst-case
    complexity O(n √n) [Hibbard1963].
    With `x=1, k=2, b=2, c=1, d=1, stopping=None` this has worst-case
    complexity O(n √n) [Papernov1965].
    With `x=1, k=2, b=3, c=-1, d=2, stopping=lambda x: x // 3` this has
    worst-case complexity O(n √n) [Knuth1973].

    Args:
        n (int): The length of the sequence.
        x (int): The initial value.
        k (int): The initial exponent.
        b (int): The base.
        c (int): The constant term.
        d (int): The deonominator.
        stopping (callable|None): The modifier for the stopping value.
            If None, defaults to `n`.
            If callable, must have the signature: stopping(int): int.
            The input is `n`.

    Yields:
        int: The next step.

    Examples:
        >>> list(steps_pow_k(500000))
        [1, 4, 13, 40, 121, 364, 1093, 3280, 9841, 29524, 88573]
        >>> list(steps_pow_k(20000, x=1, k=2, b=2, c=-1, d=1, stopping=None))
        [1, 3, 7, 15, 31, 63, 127, 255, 511, 1023, 2047, 4095, 8191, 16383]
        >>> list(steps_pow_k(20000, x=1, k=2, b=2, c=1, d=1, stopping=None))
        [1, 5, 9, 17, 33, 65, 129, 257, 513, 1025, 2049, 4097, 8193, 16385]

    See Also:
        - Knuth, Donald E. (1997). "Shell's method". The Art of Computer
          Programming. Volume 3: Sorting and Searching (2nd ed.). Reading,
          Massachusetts: Addison-Wesley. pp. 83–95. ISBN 978-0-201-89685-5.
    rB   Nr   )rb   r   r#   r   r   r   r   s          r>   steps_pow_kr   j  sJ     b QK
a%!VaZA	Q a%r   c              #      K   t        j                  |       }t        |      D ]/  }t        |dz         D ]  }||z
  }||z  ||z  z  }|| k  s|  1 yw)uX  
    Generate steps for `step_sort()` (Shell sort).

    These are of the form: x(k) = (a ** i) * (b ** j)
    with some initial value.

    With `a=2, b=3` this has worst-case complexity O(n log² n) [Pratt1971].
    However, for applications, other sequences are preferred as they perform
    generally faster, even if they have inferior worst-case complexity.

    Args:
        n (int): The length of the sequence.
        a (int): The first base.
        b (int): The second base.

    Yields:
        int: The next step.

    Examples:
        >>> sorted(steps_bi_factors(100))
         [1, 2, 3, 4, 6, 8, 9, 12, 16, 18, 24, 27, 32, 36, 48, 54, 72, 81]

    See Also:
        - Pratt, Vaughan Ronald (1979). Shellsort and Sorting Networks
          (Outstanding Dissertations in the Computer Sciences). Garland.
          ISBN 978-0-8240-4406-0.
    rB   N)rf   ilog2rK   )rb   r   r   r   r#   rH   r}   r   s           r>   steps_bi_factorsr     se     8 	A1X q1u 	AAAQaA1u		s   A
A	Ac           
   #      K   t        |      dz
  || k  r;| |t        fdt        t        ||            D              z   }dz  || k  r:yyw)uH  
    Generate steps for `step_sort()` (Shell sort).

    These are of the form: x(k) = (b ** k + c) // d
    with some initial value.

    With `x=1, k=0, a=(1, 3), b=(4, 2), c=1` this has worst-case complexity
    O(n ^ (4/3)) [Sedgewick1985].

    Args:
        n (int): The length of the sequence.
        x (int): The initial value.
        k (int): The initial exponent.
        a (int): The amplitudes.
            Must match the number of elements.
        b (int): The bases.
        c (int): The constant term.

    Yields:
        int: The next step.

    Examples:
        >>> list(steps_sum_pow_k(2000000))
        [1, 8, 23, 77, 281, 1073, 4193, 16577, 65921, 262913, 1050113]

    See Also:
        - Sedgewick, Robert (1998). Algorithms in C. 1 (3rd ed.).
          Addison-Wesley. pp. 273–281. ISBN 978-0-201-31452-6.
    rB   c              3   F   K   | ]  \  }\  }}||z   |z
  z  z    y wNrE   )ra   rH   a_ib_ir#   offsets       r>   rc   z"steps_sum_pow_k.<locals>.<genexpr>  s3      7:C #!f*q.))7s   !N)rw   sum	enumeratezip)rb   r   r#   r   r   r   r   s     `   @r>   steps_sum_pow_kr     s`     H VaZF
a% 7!*3q!9!57 7 7 	
Q a%s   AAAc              #   d   K   || k  r'| ||dz   z  ||z  z  |z   |z  |z   }|dz  }|| k  r&yyw)u[  
    Generate steps for `step_sort()` (Shell sort).

    These are of the form: x(k) = (m ** (k + 1) // d ** k + a) // b + c
    with some initial value.

    With `x=1, k=1, m=9, d=4, a=-4, b=5, c=1` this has near optimal empirical
    average-case complexity [Tokuda1992].

    This is very similar, but not identical to:
     `steps_m_d(init=(1, 4), m=9, d=4)`.

    Args:
        n (int): The length of the sequence.
        x (int): The initial value.
        k (int): The initial exponent.
        a (int): The amplitudes.
            Must match the number of elements.
        b (int): The bases.
        c (int): The constant term.

    Yields:
        int: The next step.

    Examples:
        >>> list(steps_pow_frac(50000))
        [1, 4, 9, 20, 46, 103, 233, 525, 1182, 2660, 5985, 13467, 30301]

    See Also:
        - Tokuda, Naoyuki (1992). "An Improved Shellsort". In van Leeuven,
          Jan (ed.). Proceedings of the IFIP 12th World Computer Congress on
          Algorithms, Software, Architecture. Amsterdam: North-Holland
          Publishing Co. pp. 449–457. ISBN 978-0-444-89747-3.
    rB   NrE   )rb   r   r#   r   r   r   r   r   s           r>   steps_pow_fracr     sL     V a%1q5\Q!V#a'A-1	Q a%r   c           	   #      K   |	|| kD  rdnd}|t        j                  |      }t        t        t	        || z
  |dz         |z        dz         D ]  }| ||z  z   }|rt	        ||      }|  yw)a  
    Generate a sequence that steps linearly from start to stop.

    Args:
        start (int|float): The starting value.
        stop (int|float): The final value.
            This value is present in the resulting sequence only if the step is
            a multiple of the interval size.
        step (int|float): The step value.
            If None, it is automatically set to unity (with appropriate sign).
        precision (int): The number of decimal places to use for rounding.
            If None, this is estimated from the `step` paramenter.

    Yields:
        item (int|float): the next element of the sequence.

    Examples:
        >>> list(sequence(0, 1, 0.1))
        [0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0]
        >>> list(sequence(0, 1, 0.3))
        [0.0, 0.3, 0.6, 0.9]
        >>> list(sequence(0, 10, 1))
        [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
        >>> list(sequence(0.4, 4.6, 0.72))
        [0.4, 1.12, 1.84, 2.56, 3.28, 4.0]
        >>> list(sequence(0.4, 4.72, 0.72, 2))
        [0.4, 1.12, 1.84, 2.56, 3.28, 4.0, 4.72]
        >>> list(sequence(0.4, 4.72, 0.72, 4))
        [0.4, 1.12, 1.84, 2.56, 3.28, 4.0, 4.72]
        >>> list(sequence(0.4, 4.72, 0.72, 1))
        [0.4, 1.1, 1.8, 2.6, 3.3, 4.0, 4.7]
        >>> list(sequence(0.73, 5.29))
        [0.73, 1.73, 2.73, 3.73, 4.73]
        >>> list(sequence(-3.5, 3.5))
        [-3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5]
        >>> list(sequence(3.5, -3.5))
        [3.5, 2.5, 1.5, 0.5, -0.5, -1.5, -2.5, -3.5]
        >>> list(sequence(10, 1, -1))
        [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]
        >>> list(sequence(10, 1, 1))
        []
        >>> list(sequence(10, 20, 10))
        [10, 20]
        >>> list(sequence(10, 20, 15))
        [10]
    NrB   r   )rf   guess_decimalsrK   rL   round)startstopstep	precisionrH   r\   s         r>   sequencer   *  s     f |5Lqb%%d+	3uTE\9q=9D@AAEF q4xy)D
	s   A-A/c                     | |z   S r   rE   )r   r   s     r>   r   r   k  s
    !a% r@   c           
          t        t        |             D cg c]'  }t        j                  |t	        |       d|dz          ) c}S c c}w )a  
    Cumulatively apply the specified function to the elements of the list.

    Args:
        items (Iterable): The items to process.
        func (callable): func(x,y) -> z
            The function applied cumulatively to the first n items of the list.
            Defaults to cumulative sum.

    Returns:
        lst (list): The cumulative list.

    See Also:
        itertools.accumulate.
    Examples:
        >>> accumulate(list(range(5)))
        [0, 1, 3, 6, 10]
        >>> accumulate(list(range(5)), lambda x, y: (x + 1) * y)
        [0, 1, 4, 15, 64]
        >>> accumulate([1, 2, 3, 4, 5, 6, 7, 8], lambda x, y: x * y)
        [1, 2, 6, 24, 120, 720, 5040, 40320]
    NrB   )rK   rw   	functoolsreducerq   )rY   funcrH   s      r>   
accumulater   i  sI    6 s5z"$ 	tE{6AE23$ $ $s   ,Ac                 :    i }| D ]  }|j                  |        |S )a  
    Merge dictionaries into a new dict (new keys overwrite the old ones).

    This is obsoleted by `flyingcircus.join()`.

    Args:
        items (Iterable[dict]): Dictionaries to be merged together.

    Returns:
        merged (dict): The merged dict (new keys overwrite the old ones).

    Examples:
        >>> d1 = {1: 2, 3: 4, 5: 6}
        >>> d2 = {2: 1, 4: 3, 6: 5}
        >>> d3 = {1: 1, 3: 3, 6: 5}
        >>> dd = merge_dicts((d1, d2))
        >>> print(tuple(sorted(dd.items())))
        ((1, 2), (2, 1), (3, 4), (4, 3), (5, 6), (6, 5))
        >>> dd = merge_dicts((d1, d3))
        >>> print(tuple(sorted(dd.items())))
        ((1, 1), (3, 3), (5, 6), (6, 5))
    )update)rY   mergedr\   s      r>   merge_dictsr     s)    . F dMr@   c                       fd}|S )WIPc                    ddl m} d}d}||fz   }|D ]B  }	  ||      }|j                  | d      }|j                  d       |j	                  d       |}  n  	|       S # t
        t        t        t        f$ r}||u r|Y d }~rd }~ww xY w)Nr   )import_module)gzipbz2builtinsrbrB   )fp)		importlibr   openreadseekOSErrorIOErrorAttributeErrorImportError)
r   r   zip_module_namesfallback_module_nameopen_module_namesopen_module_nameopen_moduletmp_fper   s
            r>   _wrappedz)transparent_compression.<locals>._wrapped  s    + )),0D/FF 1 	
+,<=$))"d3A
 A	 r{ WnkB #';;G <s   +A""B;BBrE   )r   r   s   ` r>   transparent_compressionr     s    * Or@   __main__r   )NTrj   ))rB      
      9      i-  i  	   r   )      N)rB   rC   )rB   r   )rB   rD   )r   rC   rB   )rB   rB   r   r   r   rB   )NN)2__doc__
__future__r   r   r   r   osr7   rm   r   docteststringrU   flyingcircusrf   r   r   r	   r
   r   r   r   r   r   r   r   r   r   r?   rI   rM   rP   r]   rh   r~   r   r   r   r   r   r   r   r   r   r   r   r   __name__striptestmodrE   r@   r>   <module>r      sV  C C
 
 
       # = = ( , , % ,`,`-b%. 	Z|:@ [B 
!N /

	6x 
	/f6 



!6t"P 



*` 





.j 	;B  $><8 zGOO r@   