示例#1
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)
示例#2
0
文件: perm.py 项目: cool-RR/combi
 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)
示例#3
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 combi._python_toolbox import misc_tools
    return misc_tools.general_product(xrange(start, x + 1), start=1)
示例#4
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 combi._python_toolbox import misc_tools
    return misc_tools.general_product(xrange(start, x+1), start=1)
示例#5
0
def product(numbers):
    '''Get the product of all the numbers in `numbers`.'''
    from combi._python_toolbox import misc_tools
    return misc_tools.general_product(numbers, start=1)
示例#6
0
文件: misc.py 项目: cool-RR/combi
def product(numbers):
    '''Get the product of all the numbers in `numbers`.'''
    from combi._python_toolbox import misc_tools
    return misc_tools.general_product(numbers, start=1)