Exemplo n.º 1
0
def orthogonalityDefect(basis):
    n = len(basis)
    gsBasis = gramSchmidtOrthogonalization(basis)[0]
    defect = 0.0

    for i in range(n):
        defect += math.log10(op.norm(basis[i]) / op.norm(gsBasis[i]))

    return defect
Exemplo n.º 2
0
def isLLLReduced(basis, delta=BKZ_constants.delta):
    n = len(basis)
    gsBasis, coeff = GSO.gramSchmidtOrthogonalization(basis)

    if not GSO.isSizeReduced(coeff):
        print('ERROR: basis is not size reduced')
        # print( coeff )
        return False

    for i in range(n - 1):
        if not Lovasz(op.norm(gsBasis[i]), op.norm(gsBasis[i + 1]),
                      coeff[i + 1][i], delta):
            print('ERROR: basis fails Lovasz condition at ' + str(i + 1))
            return False

    return True
Exemplo n.º 3
0
def enumerate( basis, gsBasis, coeff, n, level, x, R, shortVec, w, combination ):
    eps = BKZ_constants.eps

    if level < 0:
        curVec = op.scale(basis[0],x[n-1])

        for i in range(1,n):
            curVec = op.add(curVec,op.scale(basis[i],x[n-1-i]))

        r = op.norm(curVec)

        if r > eps and R > r + eps:
            # utils.printShortSolutions(x,curVec)
            shortVec = curVec
            R = r
            combination = list(reversed(x))
            # print( "Found a shorter vector of norm ", r )

        return ( R, shortVec, combination )

    else:
        alpha = 0

        for i in range(level+1,n):
            alpha += x[n-1-i] * coeff[i][level]

        all0 = op.allZeros(x)
        lowerBound, upperBound = getBounds( R, w, op.norm(gsBasis[level]), alpha, all0 )

        i = upperBound
        while i >= lowerBound:
            y = list(x)
            y.append(i)
            res = enumerate( basis, gsBasis, coeff, n, level-1, y, R, shortVec, w + ( (i+alpha)**2 )*op.normSq(gsBasis[level]), combination )

            if res[0] + eps < R:
                R = res[0]
                shortVec = res[1]
                combination = res[2]
                lowerBound, upperBound = getBounds( R, w, op.norm(gsBasis[level]), alpha, all0 )

            i -= 1

        return R, shortVec, combination
Exemplo n.º 4
0
def printShortSolutions(x, v):
    n = len(x)
    msg = 'Norm: ' + str(round(op.norm(v), 2)) + ' '

    for i in range(n - 1, -1, -1):
        if x[i] != 0:
            msg = msg + 'x' + str(n - i) + '=' + str(x[i]) + ' '

    msg = msg + ' gives ' + str(v)
    print(msg)
Exemplo n.º 5
0
def volume(B, orthogonal=False):
    if not orthogonal:
        B = gramSchmidtOrthogonalization(B)[0]

    vol = 1.0
    n = len(B)

    for i in range(n):
        vol *= (op.norm(B[i]))**(1.0 / n)

    return vol
Exemplo n.º 6
0
def printVectorWithNorm(v):
    print('Norm = ' + str(round(op.norm(v), 2)) + ' Vec: ' + str(v))