You are on page 1of 2

#!/Library/Frameworks/Python.framework/Versions/3.5/bin/python3.

##!/usr/bin/python3.5

import sys

import time

import mpmath

import mysql.connector

from mpmath import *

from zeros import *

from primes import *

from pi import *

from e import *

from itertools import combinations

import gmpy2

from zeros1 import *

tolerance = 0.0000000001

def _index_(z, cursor):

q = "SELECT val FROM zeros1 where id="+str(z)

cursor.execute(q)

rows = cursor.fetchall()

if len(rows) > 0 and len(rows[0]) > 0:

return float(rows[0][0])

else:

print("Value out of range. Please adjust tolerance.")

sys.exit(1)

return -1

def search(x, dd, cursor):

cd = 1000

cnt = 1

cnt2 = 1

while cd > dd:

z = _index_(cnt, cursor)

if z < 0:

break

dz = z + x

cnt2 = cnt+ 1

z2 = _index_(cnt2, cursor)

if z2 < 0:

break

delta = abs(z2-z)

_delta = delta

while _delta < x:

cnt2 = cnt2 + 1

z2 = _index_(cnt2, cursor)

if z2 < 0:

break

delta = _delta

_delta = abs(z2-z)

if z2 < 0:

break

cd = abs(delta-x)

if cd <=dd:

break

cnt = cnt + 1

return cnt, cnt2

def factorize(v, cursor):

global tolerance

s = str(v)

sz = gmpy2.mpz(s)

r = gmpy2.f_mod(sz, 7)

rep = 1

if int(r) == 0:

pass

else:

while r != gmpy2.mpz(0):

s = s + str(v)

rep = rep + 1

sz = gmpy2.mpz(s)

r = gmpy2.f_mod(sz, 7)

l = len(s)

if gmpy2.get_context().precision < l:

gmpy2.get_context().precision = l + 5

_s = s

s = gmpy2.mpfr("." + str(s))

#print(s)

#print("rep: "+ str(rep))

l = int(len(str(v)) / 2) + 1

cnt2 = 0

cnt = 1

h = 0

eigenvals = []

while (h < l):

s = gmpy2.mul(s, 2)

b = gmpy2.sub(s, 1)

if float(b) > 0 and cnt % rep == 0:

h = h + 1

#print("Iteration : "+ str(cnt2 + 1) + " , " + "cnt: " + str(cnt) + " :: "+ str(s))

ratio = gmpy2.div(gmpy2.mpfr(s), gmpy2.mpfr(b))

rs = str(ratio)

eigenvals.append(str(rs))

if float(b) > 0:

s = s - 1

cnt = cnt + 1

print(eigenvals)

factor = []

for x in eigenvals:

p1, p2 = search(float(x), tolerance, cursor)

factor.append(str(abs(p1-p2)))

print(factor)

return None

if __name__ == "__main__":

gmpy2.get_context().precision = 1024

num = str(sys.argv[1])

cnx = mysql.connector.connect(user='root', password='root', database='intfact')

cursor = cnx.cursor()

factor = factorize(num, cursor)

#print(factor)

cursor.close()

cnx.close()

You might also like