Exemple #1
0
def sigma(n, x=1):
    '''sigma(int) -> int
    
    Divisor's sigma function'''

    if n == 1:
        return 1
    return product(sumexp(p**x, k) for p, k in group(factorized(n)))
Exemple #2
0
def divisors(n):
    '''divisors(number) -> list

    Positive divisors of the number, e.g. divisors(15) -> [1, 3, 5, 15]'''

    if not n:
        return []
    factor_set = ({p**i for i in range(k+1)} for p, k in group(factorized(n)))
    return sorted(product(c) for c in cartesian_product(*factor_set))
Exemple #3
0
def phi(n):
    '''Duality number-function data type.

    as number: phi -> 1.618033988...
        Golden Ratio, real number where phi == 1 + 1/phi.

    as function: phi(number) -> number
        Euler's totient, number of all 0 < a < n where gcd(a, n) == 1.'''

    if n == 1:
        return 1
    return product((p-1) * p**(k-1) for p, k in group(factorized(n)))