Example #1
0
def test():
    assert general_product((1, 2, 3)) == 6
    assert general_product((1, 2, 3, 4)) == 24
    assert general_product(
        ((0, 1), 2, 3)) == (0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1)
    assert general_product(
        (2, 3), start=(0, 1)) == (0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1)
def test():
    assert general_product((1, 2, 3)) == 6
    assert general_product((1, 2, 3, 4)) == 24
    assert general_product(((0, 1), 2, 3)) == (0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0,
                                               1)
    assert general_product((2, 3), start=(0, 1)) == (0, 1, 0, 1, 0, 1, 0, 1, 0,
                                                     1, 0, 1)
    
Example #3
0
 def __pow__(self, exponent):
     '''Raise the perm by the power of `exponent`.'''
     assert isinstance(exponent, numbers.Integral)
     if exponent <= -1:
         return self.inverse ** (- exponent)
     elif exponent == 0:
         return self.nominal_perm_space[0]
     else:
         assert exponent >= 1
         return misc_tools.general_product((self,) * exponent)
Example #4
0
 def __pow__(self, exponent):
     '''Raise the perm by the power of `exponent`.'''
     assert isinstance(exponent, numbers.Integral)
     if exponent <= -1:
         return self.inverse**(-exponent)
     elif exponent == 0:
         return self.nominal_perm_space[0]
     else:
         assert exponent >= 1
         return misc_tools.general_product((self, ) * exponent)
Example #5
0
def factorial(x, start=1):
    '''
    Calculate a factorial.
    
    This differs from the built-in `math.factorial` in that it allows a `start`
    argument. If one is given, the function returns `(x!)/(start!)`.
    
    Examples:
    
        >>> factorial(5)
        120
        >>> factorial(5, 3)
        60

    '''
    from python_toolbox import misc_tools
    return misc_tools.general_product(range(start, x+1), start=1)
Example #6
0
def factorial(x, start=1):
    '''
    Calculate a factorial.
    
    This differs from the built-in `math.factorial` in that it allows a `start`
    argument. If one is given, the function returns `(x!)/(start!)`.
    
    Examples:
    
        >>> factorial(5)
        120
        >>> factorial(5, 3)
        60

    '''
    from python_toolbox import misc_tools
    return misc_tools.general_product(range(start, x+1), start=1)
Example #7
0
def product(numbers):
    '''Get the product of all the numbers in `numbers`.'''
    from python_toolbox import misc_tools
    return misc_tools.general_product(numbers, start=1)
Example #8
0
def product(numbers):
    '''Get the product of all the numbers in `numbers`.'''
    from python_toolbox import misc_tools
    return misc_tools.general_product(numbers, start=1)