diff --git a/experiments/flower-snarks.py b/experiments/flower-snarks.py index b1e52438159ec28d90070202a41ee92a04064b5c..0d27620af5a1886d163548b53014ba44f2f80811 100755 --- a/experiments/flower-snarks.py +++ b/experiments/flower-snarks.py @@ -15,12 +15,49 @@ sys.path.append(os.path.dirname(__file__) + "/..") from graph_tools.all import * from sage.all import identity_matrix, QQ, DiGraph, matrix + +def deflate_eigenvector(M, u): + coord = min(( r for r in range(u.nrows()) if u[r, 0] > 0 ), key=lambda r: u[r, 0]) + a = M[coord, :] + return M - u * a / u[coord, 0] + + +def bound_spectral_radius(M, bound): + def norm(A): + """The matrix 1-norm. Max of the sum of columns. + + We do not use the norms from Sage because they are slow + for sprase matrices. + """ + sums = [ 0 ] * A.ncols() + for (r, c), v in A.dict().items(): + sums[c] += abs(v) + + return max(sums) + + X = M + p = 1 + + while True: + b = bound**p + n = norm(X) + print(" p=%i upper bound is %0.3lg" % (p, n**(1/p))) + + if n <= b: break + + X = X**2 + p *= 2 + + print(" %i <= %i**%i" % (n, bound, p)) + + def test_eigenvalue(M, x): H = M - x*identity_matrix(QQ, M.ncols(), sparse=True) if H.is_singular(): print(" Value %i is an eigenvalue of M with geometric multiplicity %i" % (x, H.ncols() - H.rank())) + def matrix_to_rev_graph(M): assert M.ncols() == M.nrows() return DiGraph([range(M.ncols()), M.dict().keys()], @@ -86,3 +123,9 @@ if __name__ == "__main__": if vec_[i, 0] > 0 and fin[0, i] > 0: print(" %s" % (S["variables"][i],)) + print("Check that 16 is the largest eigenvalue") + print(" Calculating deflation of the matrix") + D = deflate_eigenvector(M, vec_) + print(" Bounding the spectral radius by 15") + bound_spectral_radius(D, 15) +