Exemple #1
0
def gammaincc(a, x, dps=50, maxterms=10*10*10*10*10*10*10*10):
    """Compute gammaincc exactly like mpmath does but allow for more
    terms in hypercomb. See

    mpmath/functions/expintegrals.py#L187

    in the mpmath github repository.

    """
    with mp.workdps(dps):
        z, a = a, x

        if mp.isint(z):
            try:
                # mpmath has a fast integer path
                return mpf2float(mp.gammainc(z, a=a, regularized=True))
            except mp.libmp.NoConvergence:
                pass
        nega = mp.fneg(a, exact=True)
        G = [z]
        # Use 2F0 series when possible; fall back to lower gamma representation
        try:
            def h(z):
                r = z-1
                return [([mp.exp(nega), a], [1, r], [], G, [1, -r], [], 1/nega)]
            return mpf2float(mp.hypercomb(h, [z], force_series=True))
        except mp.libmp.NoConvergence:
            def h(z):
                T1 = [], [1, z-1], [z], G, [], [], 0
                T2 = [-mp.exp(nega), a, z], [1, z, -1], [], G, [1], [1+z], a
                return T1, T2
            return mpf2float(mp.hypercomb(h, [z], maxterms=maxterms))
def ask_drop(db, tables, name):
    if tables:
        print "Existing stored {} tables:\n{}\n".format(
            name,
            "\n".join("{}. {}".format(i + 1, t) for i, t in enumerate(tables)))

        if len(tables) > 0:
            cont = raw_input(
                "{} stored {} tables to drop. Drop all? Y/[n] or list of comma-separated numbers "
                .format(len(tables), name))

            if cont == "Y":
                drop_tables(db, tables)
                return

            else:
                selections = cont.split(",")
                if all(isint(s) and int(s) >= 1 for s in selections):
                    drop_tables(db, [tables[int(s) - 1] for s in selections])
                    return

            print "No {} tables were dropped.".format(name)

    else:
        print "There are no {} tables.".format(name)
Exemple #3
0
def gammaincc(a, x, dps=50, maxterms=10**8):
    """Compute gammaincc exactly like mpmath does but allow for more
    terms in hypercomb. See

    mpmath/functions/expintegrals.py#L187

    in the mpmath github repository.

    """
    with mp.workdps(dps):
        z, a = a, x
        
        if mp.isint(z):
            try:
                # mpmath has a fast integer path
                return mpf2float(mp.gammainc(z, a=a, regularized=True))
            except mp.libmp.NoConvergence:
                pass
        nega = mp.fneg(a, exact=True)
        G = [z]
        # Use 2F0 series when possible; fall back to lower gamma representation
        try:
            def h(z):
                r = z-1
                return [([mp.exp(nega), a], [1, r], [], G, [1, -r], [], 1/nega)]
            return mpf2float(mp.hypercomb(h, [z], force_series=True))
        except mp.libmp.NoConvergence:
            def h(z):
                T1 = [], [1, z-1], [z], G, [], [], 0
                T2 = [-mp.exp(nega), a, z], [1, z, -1], [], G, [1], [1+z], a
                return T1, T2
            return mpf2float(mp.hypercomb(h, [z], maxterms=maxterms))
Exemple #4
0
def getRoot( n, k ):
    if isinstance( n, RPNMeasurement ):
        return n.getRoot( k )

    if not isint( k ):
        return power( n, fdiv( 1, k ) )
    else:
        return root( n, k )
Exemple #5
0
def getRoot(n, k):
    if isinstance(n, RPNMeasurement):
        return n.getRoot(k)

    if not isint(k):
        return power(n, fdiv(1, k))

    return root(n, k)
Exemple #6
0
def isKthPower(n, k):
    if not isint(k, gaussian=True):
        raise ValueError('integer argument expected')

    if k == 1:
        return 1

    if im(n):
        # I'm not sure why this is necessary...
        if re(n) == 0:
            return isKthPower(im(n), k)

        # We're looking for a Gaussian integer among any of the roots.
        for i in [autoprec(root)(n, k, i) for i in arange(k)]:
            if isint(i, gaussian=True):
                return 1

        return 0

    rootN = autoprec(root)(n, k)
    return 1 if isint(rootN, gaussian=True) else 0
Exemple #7
0
def isKthPower( n, k ):
    if not isint( k, gaussian=True ) and isint( k ):
        raise ValueError( 'integer arguments expected' )

    if k == 1:
        return 1
    elif k < 1:
        raise ValueError( 'a positive power k is expected' )

    if im( n ):
        # I'm not sure why this is necessary...
        if re( n ) == 0:
            return isKthPower( im( n ), k )

        # We're looking for a Gaussian integer among any of the roots.
        for i in [ autoprec( root )( n, k, i ) for i in arange( k ) ]:
            if isint( i, gaussian=True ):
                return 1

        return 0
    else:
        rootN = autoprec( root )( n, k )
        return 1 if isint( rootN, gaussian=True ) else 0
Exemple #8
0
    def _does_have_int_positive_roots(poly):
        """For a poly2sympoly of deg(poly2sympoly) < 3 (after factoring out any power of x^n), check if it has integer
        positive roots.
        Returns a boolean."""
        poly = BasicEnumPolyParams._factor_out_polynom(poly)
        if len(poly) == 0:
            return True
        elif len(poly) == 1:
            return False
        ## # elif len(poly) == 2 and (poly[0] / poly[1]).is_integer() and (poly[0] > 0) != (poly[1] > 0):
        elif len(poly) == 2 and isint(poly[0] / poly[1]) and (poly[0] > 0) != (poly[1] > 0):
            return True
        elif len(poly) == 3:
            discrim = (poly[1]**2-4*poly[0]*poly[2])
            if discrim < 0:
                return False
            discrim **= 0.5
            ## # if ((discrim - poly[1])/(2*poly[0])).is_integer():
            if isint((discrim - poly[1])/(2*poly[0])) and ((discrim - poly[1])/(2*poly[0]) > 0):
                return True
            if isint((-discrim - poly[1])/(2*poly[0])) and ((-discrim - poly[1])/(2*poly[0]) > 0):
                return True

        return False
def getHardMinYForD3(d):
    '''
    failed at 61 when used 120 bits for precision (succeeded at 53, 46)
    '''
    print('trying {}'.format(d))
    mp.prec = EULER66_NEEDED_PRECISION_IN_BITS

    dRoot = mp.mpf(d).sqrt()

    for potentY, dRootMulPotentY in multiplesGenerator2(dRoot):
        if EULER66_D_ROOT_MUL_Y_MIN_VAL_AFTER_DEC_POINT < zeroLeftToDecPoint(
                dRootMulPotentY):
            print(potentY)
            if mpmath.isint((d * potentY**2 + 1).sqrt()):
                print(d, potentY)
                print()
                return potentY
Exemple #10
0
d = reduce(operator.mul, [cc[0] for cc in c])
print(f"{d=}")

e = [(d / cc[0], cc[1] * d / cc[0]) for cc in c]
print(f"{e=}")

f = reduce(operator.add, [ee[0] for ee in e])
print(f"{f=}")

g = reduce(operator.add, [ee[1] for ee in e])
print(f"{g=}")

for x in count():
    t = (mpmath.mpf(d) * mpmath.mpf(x) - mpmath.mpf(g)) / mpmath.mpf(f)
    # if t.is_integer():
    if mpmath.isint(t):
        # print(x, t, test)
        v1 = (mpmath.mpf(f) * t + mpmath.mpf(g)) % mpmath.mpf(d)
        if v1 != 0:
            v2 = min(v1, d - v1)
            print(f"{t=} was close by {v2=}")
            continue
        printt(a, int(t), t, v1)
        exit()

exit()


def f1(t):
    return (t + 0) % 67
def safeHasSquareRoot(num):
    return mpmath.isint(mpmath.sqrt(num))