def _compute_eigenvector(s, l, m, gam, verbose=False, min_nmax=8): r""" Compute the eigenvector and the eigenvalue corresponding to (s, l, m, gam) INPUT: - ``s`` -- integer; the spin weight - ``l`` -- non-negative integer; the harmonic degree - ``m`` -- integer within the range ``[-l, l]``; the azimuthal number - ``gam`` -- spheroidicity parameter - ``verbose`` -- (default: ``False``) determines whether some details of the computation are printed out - ``min_nmax`` -- (default: 8) integer; floor for the evaluation of the parameter ``nmax``, which sets the highest degree of the spherical harmonic expansion as ``l+nmax``. """ nmax = ceil(abs(3 * gam / 2 - gam * gam / 250)) + min_nmax # FIXME : improve the estimate of nmax if nmax % 2 == 0: nmax += 1 lmin = max(abs(s), abs(m)) nmin = min(l - lmin, nmax) size = nmax + nmin + 1 mat = matrix(RDF, size, size) for i in range(1, size + 1): mat[i - 1, i - 1] = -kHat(s, l - nmin - 1 + i, m, gam) if i > 2: mat[i - 1, i - 3] = -k2(s, l - nmin - 3 + i, m, gam) if i > 1: mat[i - 1, i - 2] = -kTilde2(s, l - nmin + i - 2, m, gam) if (i < size): mat[i - 1, i] = -kTilde2(s, l - nmin + i - 1, m, gam) if (i < size - 1): mat[i - 1, i + 1] = -k2(s, l - nmin + i + -1, m, gam) if verbose: print("nmax: {}".format(nmax)) print("lmin: {}".format(lmin)) print("nmin: {}".format(nmin)) print("size: {}".format(size)) # show(mat) # Computation of the eigenvalues and eigenvectors: evlist = mat.eigenvectors_right() # list of triples, each triple being # (eigenvalue, [eigenvector], 1) sevlist = sorted(evlist, key=lambda x: x[0], reverse=True) egval, egvec, mult = sevlist[-(nmin + 1)] egvec = egvec[0] # since egvec is the single-element list [eigenvector] if verbose: print("eigenvalue: {}".format(egval)) print("eigenvector: {}".format(egvec)) check = mat * egvec - egval * egvec print("check: {}".format(check)) lamb = egval - s * (s + 1) - 2 * m * gam + gam * gam return lamb, egvec, nmin, nmax, lmin
def neighbor(self, pt, d): r""" Return the neighbors of the point pt in direction d. INPUT: - ``pt`` - tuple, point in Z^d - ``direction`` - integer, possible values are 1, 2, ..., d and -1, -2, ..., -d. EXAMPLES: sage: from slabbe import BondPercolationSample sage: S = BondPercolationSample(0.5,2) sage: S.neighbor((2,3),1) (3, 3) sage: S.neighbor((2,3),2) (2, 4) sage: S.neighbor((2,3),-1) (1, 3) sage: S.neighbor((2,3),-2) (2, 2) """ R = xrange(self._dimension) a = sgn(d) d = abs(d) return tuple(pt[k]+a if k==d-1 else pt[k] for k in R)
def neighbor(self, pt, d): r""" Return the neighbors of the point pt in direction d. INPUT: - ``pt`` - tuple, point in Z^d - ``direction`` - integer, possible values are 1, 2, ..., d and -1, -2, ..., -d. EXAMPLES: sage: from slabbe import BondPercolationSample sage: S = BondPercolationSample(0.5,2) sage: S.neighbor((2,3),1) (3, 3) sage: S.neighbor((2,3),2) (2, 4) sage: S.neighbor((2,3),-1) (1, 3) sage: S.neighbor((2,3),-2) (2, 2) """ R = xrange(self._dimension) a = sgn(d) d = abs(d) return tuple(pt[k] + a if k == d - 1 else pt[k] for k in R)
def discrepancy(self): r""" Return the discrepancy of the word. This is a distance to the euclidean line defined in [T1980]_. EXAMPLES:: sage: from slabbe.finite_word import discrepancy sage: w = words.ChristoffelWord(5,8) sage: w word: 0010010100101 sage: discrepancy(w) 12/13 :: sage: for c in w.conjugates(): print c, discrepancy(c) 0010010100101 12/13 0100101001010 7/13 1001010010100 10/13 0010100101001 10/13 0101001010010 7/13 1010010100100 12/13 0100101001001 8/13 1001010010010 9/13 0010100100101 11/13 0101001001010 6/13 1010010010100 11/13 0100100101001 9/13 1001001010010 8/13 REFERENCES: .. [T1980] R., Tijdeman. The chairman assignment problem. Discrete Mathematics 32, no 3 (1980): 323-30. doi:10.1016/0012-365X(80)90269-1. """ length = self.length() freq = { a: QQ((v, length)) for (a, v) in self.evaluation_dict().iteritems() } C = Counter() M = 0 for i, a in enumerate(self): C[a] += 1 MM = max(abs(freq[b] * (i + 1) - C[b]) for b in freq) M = max(M, MM) return M
def __init__(self, v, mod=None): r""" Constructor. Return the Christoffel set of edges. EXAMPLES:: sage: from slabbe import ChristoffelGraph sage: ChristoffelGraph((2,5)) Christoffel set of edges for normal vector v=(2, 5) """ self._v = vector(v) if mod: self._sum_v = mod else: self._sum_v = sum(abs(a) for a in v) DiscreteSubset.__init__(self, dimension=len(v), edge_predicate=self.has_edge)
def my_log(number): return floor(log(abs(number), 10.))