Exemple #1
0
	def test_normPolyB2(self):
		NF = poly.NumberField(poly.Poly([8,29,15,1]))
		a = -8
		b = 3
		NF = poly.NumberField(poly.Poly([8,29,15,1]))
		polyNormB = NF.getPolyNormB(b)
		self.assertEqual(polyNormB.evaluate(a),-5696)
Exemple #2
0
	def test_numberfield_square2(self):
		# Brigg's example
		nfspoly = poly.Poly([8,29,15,1])
		NF = poly.NumberField(nfspoly)
		
		nfspolyd = NF(nfspoly.derivative())
		sqrt = NF(poly.Poly([3889976768, 3686043120, 599923511]))
		correctSquare = NF(poly.Poly([22939402657683071224L, 54100105785512562427L, 22455983949710645412L]))
		
		square = sqrt * sqrt
		self.assertEqual(square,correctSquare)
Exemple #3
0
	def test_numberfield_square1(self):
		# Spaans's example
		nfspoly = poly.Poly([161, 134, 2, 1])
		NF = poly.NumberField(nfspoly)
		nfspolyd = NF(nfspoly.derivative())
		
		sqrt = NF(poly.Poly([-41757429265579073242,-34105727598423382475,1681812579256330563]))
		correctSquare = NF(poly.Poly([21124198049840950371210079793023892077432,18523314201045731615331644622444823801483,884477920457388669411401815623954662863]))
		
		square = sqrt * sqrt
		self.assertEqual(square,correctSquare)
Exemple #4
0
	def test_numberfield_mult2(self):
		# Spaan's example
		nfspoly = poly.Poly([161, 134, 2, 1])
		NF = poly.NumberField(nfspoly)
		nfspolyd = NF(nfspoly.derivative())
		
		tomult = [[-92,-1],[-57,-1],[-23,-1],[-8,-1],[-7,-1],[2,-1],[10,-1],[17,-1],[29,-1],[35,-1],[84,-1],[115,-1],[139,-1],[-5,-2],[19,-2],[69,-2],[93,-2],[119,-2],[-542,-3],[-28,-3],[-23,-3],[-8,-3]]
		tomult = [NF(poly.Poly(x)) for x in tomult]
		
		correctProduct = NF(poly.Poly([21124198049840950371210079793023892077432,18523314201045731615331644622444823801483,884477920457388669411401815623954662863]))
		
		prod = multAllElements(NF(poly.Poly([1])),tomult)
		prod = prod * nfspolyd * nfspolyd
		self.assertEqual(prod,correctProduct)
Exemple #5
0
	def test_numberfield_mult1(self):
		# Briggs' example
		nfspoly = poly.Poly([8,29,15,1])
		NF = poly.NumberField(nfspoly)
		
		nfspolyd = NF(nfspoly.derivative())
		correctProduct = NF(poly.Poly([22939402657683071224L, 54100105785512562427L, 22455983949710645412L]))
		
		tomult = [[-1,1],[3,1],[13,1],[104,1],[3,2],[25,2],[-8,3],[48,5],[54,5],[-43,6],[-8,7],[11,7],[856,11]]
		tomult = [NF(poly.Poly(x)) for x in tomult]
		
		prod = multAllElements(NF(poly.Poly([1])),tomult)
		prod = prod * nfspolyd * nfspolyd
		self.assertEqual(prod,correctProduct)
Exemple #6
0
def main():
    nfspoly = poly.Poly([8, 29, 15, 1])
    NF = poly.NumberField(nfspoly)
    while (True):
        q = primemath.generateLargePrime(10)
        s = poly.getRootsModPFast(nfspoly, q)
        if (len(s) > 0):
            break
    s = s[0]

    print "special_q: f(%s) = 0 mod %s" % (s, q)

    while (True):
        p = primemath.generateLargePrime(7)
        r = poly.getRootsModPFast(nfspoly, p)
        if (len(r) > 0):
            break
    r = r[0]

    print "p: f(%s) = 0 mod %s" % (r, p)

    basis = find_sublattice_basis(q, s, p, r)
    print "basis: %s" % basis
    basis_r = reduce_basis(basis[0], basis[1])
    a0 = basis_r[0][0]
    b0 = basis_r[0][1]
    a1 = basis_r[1][0]
    b1 = basis_r[1][1]
    print "reduced basis: %s" % [[a0, b0], [a1, b1]]

    print "generating lattice points..."
    for i in range(-20, 20):
        for j in range(-20, 20):
            a = a0 * i + a1 * j
            b = b0 * i + b1 * j
            if (a == 0 or b == 0):
                continue
            NFelement = NF(poly.Poly([a, b]))
            if (NFelement.norm() % q == 0 and NFelement.norm() % p == 0):
                print "%s is q-divisible and p-divisible" % [a, b]
            else:
                raise AssertionError("%s is not q-divisible or p-divisible" %
                                     [a, b])
Exemple #7
0
def main():
    (n, nfsPoly, m, B, M, K) = files.loadParamsFile()
    NF = poly.NumberField(poly.Poly(nfsPoly))

    rfBase = files.loadFileArray("rfbase.txt")
    afBase = files.loadFileArray("afbase.txt")
    smooths = files.loadFileArray("smooths.txt")
    specialq = files.loadFileArray("specialq.txt")

    nOfSmooths = len(smooths)

    #smooths = sorted(smooths,key=hash)
    #smooths = sorted({hash(val): val for val in smooths}, key=hash)
    smooths = sorted({hash(val): val for val in smooths}.values(), key=hash)
    #for smooth in smooths:
    #print smooth

    print "%s duplicates removed." % (nOfSmooths - len(smooths))
    nOfSmooths = len(smooths)

    if (len(smooths) < K + len(specialq)):
        print "undersieved by %s." % ((K + len(specialq)) - len(smooths))
        raise AssertionError

    while (len(smooths) > K + len(specialq)):
        smooths.pop()

    print "%s extra relations removed." % (nOfSmooths - len(smooths))

    smoothsFile = open("smooths-fil.txt", "w")
    for smooth in smooths:
        smoothsFile.write(str(smooth) + "\n")

    rfBaseFile = open("rfbase-fil.txt", "w")
    for p in rfBase:
        rfBaseFile.write(str(p) + "\n")

    afBaseFile = open("afbase-fil.txt", "w")
    for p in afBase:
        afBaseFile.write(str(p) + "\n")
    for p in specialq:
        afBaseFile.write(str(p) + "\n")
    '''
Exemple #8
0
def main():
    nfspoly = poly.Poly([8, 29, 15, 1])
    NF = poly.NumberField(nfspoly)
    while (True):
        q = primemath.generateLargePrime(20)
        r = poly.getRootsModPFast(nfspoly, q)
        if (len(r) > 0):
            break
    r = r[0]

    print "special_q: f(%s) = 0 mod %s" % (r, q)

    basis = []
    b = 1
    for i in range(2):
        a = -b * r + i * q
        basis.append([a, b])

    print "basis: %s" % basis
    basis_r = reduce_basis(basis[0], basis[1])
    a0 = basis_r[0][0]
    b0 = basis_r[0][1]
    a1 = basis_r[1][0]
    b1 = basis_r[1][1]
    print "reduced basis: %s" % [[a0, b0], [a1, b1]]

    print "generating lattice points..."
    for i in range(-2, 2):
        for j in range(-2, 2):
            a = a0 * i + a1 * j
            b = b0 * i + b1 * j
            if (a == 0 or b == 0):
                continue
            NFelement = NF(poly.Poly([a, b]))
            if (NFelement.norm() % q == 0):
                print "%s is q-divisible" % [a, b]
            else:
                raise AssertionError("%s is not q-divisible" % [a, b])
Exemple #9
0
    for r in range(sideLen):
        if (zeroRow(matrix[r])):
            dep[r] = n & 1
            n >>= 1

    for r in range(sideLen):
        for c in range(r + 1, sideLen):
            if (matrix[r][c] == 1):
                dep[r] = (dep[c] + dep[r]) % 2

    return dep


if __name__ == '__main__':
    (n, nfsPoly, m, B, M, K) = files.loadParamsFile()
    NF = poly.NumberField(poly.Poly(nfsPoly))

    rfBase = files.loadFileArray("rfbase-fil.txt")
    rfBase = zip(*rfBase)[1]  #grab only the primes
    afBase = files.loadFileArray("afbase-fil.txt")
    qcBase = matrixmath.generateQCBase(n, afBase[-1][1], poly.Poly(nfsPoly))

    smooths = files.loadFileArray("smooths-fil.txt")
    print "Building matrix..."
    matrix = []
    for smoothPair in smooths:
        smoothPoly = poly.Poly(smoothPair)
        matrixRow = matrixmath.getMatrixRowRat(smoothPoly, m, rfBase)
        matrixRow.extend(matrixmath.getMatrixRowAlg(smoothPoly, NF, afBase))
        matrixRow.extend(matrixmath.getMatrixRowQC(smoothPoly, qcBase))
        matrixRow.extend([0] * (K - len(rfBase) - len(afBase) - len(qcBase) -
Exemple #10
0
    while (True):
        b += 1
        a = -b * s % q
        if (a == 0 or b == 0):
            continue
        if (float(basis1[0]) / a - float(basis1[1]) / b < 0.01):
            continue
        basis2 = [a, b]
        break

    return [basis1, basis2]


def sieve_special_q(q, s, I, J, rfBase, afBase, (n, nfsPoly, m, B, M, K)):
    nfsPoly = poly.Poly(nfsPoly)
    NF = poly.NumberField(nfsPoly)
    basis_q = find_lattice_basis(q, s)
    basis_q = reduce_basis(basis_q[0], basis_q[1])
    (qa0, qb0, qa1, qb1) = frankefy(basis_q)
    logB = math.log(B)
    lambd_a = 1.5
    lambd_r = 1.5

    sieve = [[0.0] * (J) for i in range(I)]
    print "sieving rational side..."
    for prime in rfBase:
        r = prime[0]
        p = prime[1]
        #print [r,p]
        basis_r = find_sublattice_basis(basis_q, p, r)
Exemple #11
0
	def test_norm(self):
		NF = poly.NumberField(poly.Poly([8,29,15,1]))
		smoothElement = NF(poly.Poly([-8,3]))
		self.assertEqual(smoothElement.norm(),-5696)
Exemple #12
0
	def test_normPolyB1(self):
		NF = poly.NumberField(poly.Poly([8,29,15,1]))
		b = -5
		testPolyNormB = NF.getPolyNormB(b)
		correctPolyNormB = poly.Poly([1000, 725, 75, 1])
		self.assertEqual(testPolyNormB, correctPolyNormB)