Beispiel #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)
Beispiel #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
Beispiel #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)
Beispiel #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
Beispiel #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
Beispiel #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)
Beispiel #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
Beispiel #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