示例#1
0
def taylor_convergents(A,c=0,x=0):
    """
    Convergents of the Talyor Series defined by the sequence A and constant c, at x
    """
    
    require_iterable(["A"],[A])
    
    c = Fraction(c)
    x = Fraction(x)
    
    for P in taylor_sums(A,c):
        yield poly_eval(P,x)
示例#2
0
def dirichlet_terms(A,s):
    """
    Terms of the given Dirichlet series
    """
    
    require_integers(["s"], [s])
    require_geq(["s"], [s], 1)
    require_iterable(["A"],[A])
    
    for n,a in enumerate(A,1):
        f = Fraction(a)/Fraction(n**s)
        yield f
示例#3
0
def taylor_terms(A, c=0):
    """
    Coefficients of each term of the Talyor Series defined by the sequence A and constant c\n
    """

    require_iterable(["A"], [A])
    require_integers(["c"], [c])

    P = [1]

    for a in A:
        yield poly_mult([a], P)

        P = poly_mult([1, -c], P)
示例#4
0
def taylor_sums(A, c=0):
    """
    Coefficients of each partial sum of the Talyor Series defined by the sequence A and constant c\n
    """

    require_iterable(["A"], [A])
    require_integers(["c"], [c])

    S = [0]

    for P in taylor_terms(A, c):
        S = poly_sum(P, S)

        yield S
示例#5
0
def taylor_sums(A,c=0):
    """
    Coefficients of each partial sum of the Talyor Series defined by the sequence A and constant c
    """
    
    require_iterable(["A"],[A])
    
    c = Fraction(c)
    S = [Fraction(0)]
    
    for P in taylor_terms(A,c):
        S = poly_sum(P,S)
        
        yield S
示例#6
0
def taylor_terms(A,c=0):
    """
    Coefficients of each term of the Talyor Series defined by the sequence A and constant c
    """
    
    require_iterable(["A"],[A])
    
    P = [Fraction(1)]
    Q = [Fraction(1),Fraction(-c)]
    
    for a in A:
        yield poly_mult([a],P)
        
        P = poly_mult(Q,P)
示例#7
0
def dirichlet_sums(A,s):
    """
    Partial Sums of the given Dirichlet series
    """
    
    require_integers(["s"], [s])
    require_geq(["s"], [s], 1)
    require_iterable(["A"],[A])
    
    p = Fraction(0)
    
    for f in dirichlet_terms(A,s):
        p += f
        yield p
示例#8
0
def prime_product(P, inclusive=False):
    """
    Naturals such that all prime factors are in the set P
    
    Args:
        P -- an interable consisting of primes
        inclusive -- bool, if True only numbers divisible by all elements of P are included
    
    OEIS
    """

    require_iterable(["P"], [P])

    P = set(P)
    I = prod(P)

    for p in P:
        if not isprime(p):
            raise Exception(
                f"All elements of P must be prime, {p} is not prime")

    if inclusive:
        for n in arithmetic(I, I):
            m = n

            for p in P:
                while m % p == 0:
                    m //= p

            if m == 1:
                yield n

    else:
        for n in naturals(2):
            m = n

            for p in P:
                while m % p == 0:
                    m //= p

            if m == 1:
                yield n