Ejemplo n.º 1
0
def FZ_param_list(n,markings):
    #n= 3*r-self.genus-1 #this is how I've seen it called
    #markings = self.markings
    
    if n < 0:
        return []
    final_list = []
    mmm = max((0,)+markings)
    markings_grouped = [0 for i in range(mmm)]
    for i in markings:
        markings_grouped[i-1] += 1
    markings_best = []
    for i in range(mmm):
        if markings_grouped[i] > 0:
            markings_best.append([i+1,markings_grouped[i]])
    for j in range(n//2 + 1):
        for n_vec in IntegerVectors(n-2*j,1+len(markings_best)):
            S_list = [[list(sigma) for sigma in Partitions(n_vec[0]).list() if sum(1 for l in sigma if (l % 3) == 2) == 0]]
            for i in range(len(markings_best)):
                S_list.append(Partitions(n_vec[i+1]+markings_best[i][1], length=markings_best[i][1]).list())
                S_list[-1] = [[k - 1 for k in sigma] for sigma in S_list[-1] if sum(1 for l in sigma if (l % 3) == 0) == 0]          

            for S in itertools.product(*S_list):
                final_list.append((tuple(S[0]), tuple([(markings_best[k][0], tuple(S[k+1])) for k in range(len(markings_best))])))
    return final_list
Ejemplo n.º 2
0
def _recursive_crank(p, t, n, known=[], style="standard"):
    from sage.all import Partitions
    if known == []:
        known = [
            _Igusa_braid_table(p, t, k, style=style)
            for k in range(_TABLE_CUTOFF + 1)
        ]
    k = len(known) + 1
    Zk = 0
    for L in Partitions(k):
        if len(L) > 1:
            if style == "reduced":
                L_factors = [_P(L), 1, t**(_binom_sum(L)), _factorial(len(L))]
            else:
                L_factors = [
                    _P(L), p**(1 - _reduce(lambda x, y: x + y - 1, L)),
                    t**(_binom_sum(L)),
                    _Poincare(L)(Y=-p**-1)
                ]
            lower_integrals = list(map(lambda z: known[z - 1], list(L)))
            L_term = _reduce(lambda x, y: x * y, L_factors + lower_integrals,
                             1)
            Zk += L_term
    if style == "reduced":
        Zk = Zk / (1 - t**(_binomial(k, 2)))
    else:
        Zk = Zk / (1 - p**(-k + 1) * t**(_binomial(k, 2)))
    known += [Zk]
    if k - 1 < n:
        return _recursive_crank(p, t, n, known=known, style=style)
    else:
        return known[n]
Ejemplo n.º 3
0
    def partition_function(self,w):
        '''
        Return the partition function F truncated at weight w.
        
        EXAMPLE:
        
        The partition function truncated at weight 10::
        
            sage: from cvolume import Fs
            sage: Fs.partition_function(10)
            1/6*t0^3*t1^3 + 1/8*t0^4*t1*t2 + 1/120*t0^5*t3 + 1/6*t0^3*t1^2 + 1/120*t1^5 + 1/24*t0^4*t2 + 1/6*t0*t1^3*t2 + 1/6*t0^2*t1*t2^2 + 1/8*t0^2*t1^2*t3 + 7/144*t0^3*t2*t3 + 1/36*t0^3*t1*t4 + 1/576*t0^4*t5 + 1/6*t0^3*t1 + 1/96*t1^4 + 1/8*t0*t1^2*t2 + 1/24*t0^2*t2^2 + 1/16*t0^2*t1*t3 + 1/144*t0^3*t4 + 1/6*t0^3 + 1/72*t1^3 + 1/12*t0*t1*t2 + 7/1440*t2^3 + 1/48*t0^2*t3 + 29/1440*t1*t2*t3 + 29/5760*t0*t3^2 + 1/192*t1^2*t4 + 11/1440*t0*t2*t4 + 1/288*t0*t1*t5 + 1/2304*t0^2*t6 + 1/48*t1^2 + 1/24*t0*t2 + 29/5760*t2*t3 + 1/384*t1*t4 + 607/2903040*t4^2 + 1/1152*t0*t5 + 503/1451520*t3*t5 + 77/414720*t2*t6 + 5/82944*t1*t7 + 1/82944*t0*t8 + 1/24*t1 + 1/1152*t4 + 1/82944*t7
        '''
        F_max_weight = self.F_weights.get((),-1)
        F = self.F_series.get((),T.zero()) 
        if w > F_max_weight:
            tic = time.time()
#             time_est = time_for_F(w) - time_for_F(F_max_weight)
#             if time_est > 120:
#                 command = input(f"    Partition function update might take more than {float2time(time_est,2)}. Do you want to \
#                 continue? Print 'n' to abort, to continue press Enter.")
#                 if command == 'n':
#                     sys.exit("The computation was aborted by user due to time constraints.")
            if self.verbose: print(f"    Updating the partition function F from max_weight {F_max_weight} to {w}...")
            for i in range(max(F_max_weight,0)+1,w+1):
                F += sum(coeff(par)*monom(par) for par in Partitions(i))
            self.F_weights[()] = w
            self.F_series[()] = F
            toc = time.time()
            if self.verbose: print(f"    Finished in: {float2time(toc-tic,2)}")
        return F
Ejemplo n.º 4
0
def all_symbols(sign, rank, D):
    symbols = list()
    # print D
    fac = Integer(D).factor()
    symbols = list()
    for p, v in fac:
        psymbols = list()
        parts = Partitions(v)
        exp_mult = list()
        for vs in parts:
            exponents = Set(list(vs))
            if len(vs) <= rank:
                mult = dict()
                for vv in exponents:
                    mult[vv] = list(vs).count(vv)
                exp_mult.append(mult)
        Dp = D // (p**v)
        for vs in exp_mult:
            # print "partition:", vs
            ell = list()
            if p == 2:
                for vv, mult in vs.iteritems():
                    ll = list()
                    for t in [0, 1]:  # even(0) or odd(1) type
                        for det in [1, 3, 5, 7]:  # the possible determinants
                            if mult % 2 == 0 and t == 0:
                                ll.append([vv, mult, det, 0, 0])
                            if mult == 1:
                                odds = [det]
                            elif mult == 2:
                                if det in [1, 7]:
                                    odds = [0, 2, 6]
                                else:
                                    odds = [2, 4, 6]
                            else:
                                odds = [
                                    o for o in range(8) if o % 2 == mult % 2
                                ]
                            for oddity in odds:
                                if t == 1:
                                    ll.append([vv, mult, det, 1, oddity])
                    ell.append(ll)
            else:
                for vv, mult in vs.iteritems():
                    ll = [[vv, mult, 1], [vv, mult, -1]]
                    ell.append(ll)
            l = list(itertools.product(*ell))
            l = map(lambda x: {p: list(x)}, l)
            psymbols = psymbols + l
        if len(symbols) == 0:
            symbols = psymbols
        else:
            symbols_new = list()
            for sym in symbols:
                for psym in psymbols:
                    newsym = deepcopy(sym)
                    newsym.update(psym)
                    symbols_new.append(newsym)
            symbols = symbols_new
    return symbols
Ejemplo n.º 5
0
def test_kontsevich_genus0_formula():
    from surface_dynamics.topological_recursion.kontsevich import psi_correlator

    # d1 + ... + dn = n-3
    # equivalently (d1+1) + ... + (dn+1) = 2n-3
    # <tau_{d1} ... tau_{dn}> = (n-3)! / prod d_i!
    for n in range(3, 10):
        for p in Partitions(2 * n - 3, length=n):
            p = tuple(i - 1 for i in p)
            val = QQ((factorial(n - 3), prod(factorial(d) for d in p)))
            assert psi_correlator(*p) == val, p
Ejemplo n.º 6
0
 def collapse_stars(self):
     star_locations = []
     for i, piece in enumerate(self.L):
         if piece.is_star():
             star_locations.append(i)
     numstars = len(star_locations)
     ed = self.extra_dim()
     for total in range(numstars + ed[0], numstars + ed[1] + 1):
         for partition in Partitions(total, length=numstars):
             newL = list(self.L)
             for i, loc in enumerate(star_locations):
                 newL[loc] = DecompPiece("%s"%(partition[i]))
             yield DecompList(newL, self.maxdim, self.external_q, self.external_g, self.qfield, self.OC)
Ejemplo n.º 7
0
def comb_partitions(n, verbose=True):
    if verbose:
        print(f"r:", "r_partitions")
    r_partitions = {}
    for r in range(n):
        for l in range(0, r + 1):
            r_partitions.setdefault(l, [])
            l_partitions = Partitions(r, length=l).list()
            # Sage .list() output is not a list, make it one
            l_partitions = [list(x) for x in l_partitions]
            r_partitions.get(l).extend(l_partitions)
    if verbose:
        for k, v in r_partitions.items():
            print(f"{k+1}:", v)
    return list(r_partitions.values())
Ejemplo n.º 8
0
 def __iter__(self):
     # compositions are an ordered decomposition as a sum of positive integers.
     # since we want to allow zeros and want to allow some dimension to be unallocated to clabels,
     # we add len(self.clabels) + 1 to the total, then subtract 1 from each summand in the composition.
     for comp in Compositions(len(self.clabels) + 1 + self.extrafactors, length=len(self.clabels)+1):
         labels = []
         i = 0
         for label in self.sorted_labels:
             if label in self.clabels:
                 labels.append(('%s.%s.%s'%(self.dim,self.q,label), self.clabels[label] + self.flabels[label] + comp[i] - 1))
                 i += 1
             else:
                 labels.append(('%s.%s.%s'%(self.dim,self.q,label), self.flabels[label]))
         for part in Partitions(comp[-1] - 1):
             for stretch in Insertions(labels, self.fdims + list(part), self.dim, self.q):
                 yield stretch
Ejemplo n.º 9
0
def test_kontsevich_genus1_formula():
    # from Andersen-Borot-Charbonnier-Delecroix-Giacchetto-Lewanski-Wheeler
    # appendix A

    from surface_dynamics.topological_recursion.kontsevich import psi_correlator

    # d1 + ... + dn = n
    # equivalently (d1+1) + ... + (dn+1) = 2n
    for n in range(1, 8):
        for p in Partitions(2 * n, length=n):
            p = tuple(i - 1 for i in p)
            s = sum(
                multinomial([i - j for i, j in zip(p, diff)]) *
                factorial(sum(diff) - 2)
                for diff in itertools.product([0, 1], repeat=n)
                if sum(diff) >= 2)
            assert 24 * psi_correlator(*p) == multinomial(p) - s, (p, s)
Ejemplo n.º 10
0
def decorate1_list(G,r):
    X = StrataGraph.Xvar
    G_deco = []
    G.compute_degree_vec()
      #print "compute_degree_vec ok"
    nr,nc = G.M.nrows(),G.M.ncols()
    two_list = []
    one_list = []
    for i in range(1,nr):
        for j in range(1,nc):
            if G.M[i,j] == 2:
                two_list.append([i,j])
            elif G.M[i,j] == 1:
                one_list.append([i,j])
    a = nr-1
    b = len(two_list)
    c = len(one_list)

    #dims = [[dim_form(G.M[i+1,0][0], G.degree(i+1), mod_type) for i in range(a)] for mod_type in range(moduli_type+1)]
    dims = [dim_form(G.M[i+1,0][0], G.degree(i+1)) for i in range(a)] 

    for vec in IntegerVectors(r,a+b+c):
        bad = False
        test_dims = vec[:a]
        for i in range(b):
            test_dims[two_list[i][0]-1] += vec[a+i]
        for i in range(c):
            test_dims[one_list[i][0]-1] += vec[a+b+i]
        #new_type = which_type
        #for mod_type in range(which_type,moduli_type+1):
        for i in range(a):
            if test_dims[i] > dims[i]:
                bad = True
                break
        #            new_type = mod_type + 1
        #            break
        if bad:
            continue
        #if new_type > moduli_type:
        #    continue
        S_list = []
        for i in range(a):
            #print i, vec, vec[i] 
            S_list.append(Partitions(vec[i]))
        for i in range(a,a+b):
            S_list.append([[vec[i]-j,j] for j in range(vec[i] // 2 + 1)])
        S = itertools.product(*S_list) #removed a * here

        for vec2 in S:
            G_copy = StrataGraph(G.M)
            for i in range(a):
                for j in vec2[i]:
                    G_copy.M[i+1,0] += X**j
            for i in range(a,a+b):
                G_copy.M[two_list[i-a][0],two_list[i-a][1]] += vec2[i][0]*X + vec2[i][1]*X**2
            for i in range(c):
                G_copy.M[one_list[i][0],one_list[i][1]] += vec[i+a+b]*X
            G_copy.compute_invariant()
            G_deco.append(G_copy) #[new_type].append(G_copy)
      #print "about to return"
    return G_deco
Ejemplo n.º 11
0
 def memo_Nlocal(g, n, stratum, labeled, mode):
     #print('Computing for (%s,%s,%s)...Cache size %s' % (g,n,stratum,len(cache_poly)))
     if not stratum or n != 2 - 2 * g + 1 / ZZ(2) * sum(
             stratum) or g < 0 or n < 1:
         return B.zero()
     if type(stratum) == list: stratum = tuple(stratum)
     if (g, n, stratum) in cache_poly:
         if labeled: return cache_poly[(g, n, stratum)]
         else:
             return cache_poly[(g, n, stratum)] / cache_labeling[(g, n,
                                                                  stratum)]
     if not labeled:
         memo_Nlocal(g, n, stratum, True, mode)
         return cache_poly[(g, n, stratum)] / cache_labeling[(g, n,
                                                              stratum)]
     #weight_check(g,n,stratum)
     m = [
         stratum.count(2 * i - 1)
         for i in range((max(stratum) + 1) / ZZ(2) + 1)
     ]
     if -1 in stratum:  # case with poles
         elderstratum = list(stratum)
         elderstratum.remove(-1)
         elderstratum.append(1)
         N_lab = memo_Nlocal(g, n + 1, elderstratum, True,
                             mode)(*vanish(b, [n + 1]))
         for i in range(len(elderstratum)):
             if elderstratum[i] > 1:
                 newstratum = list(elderstratum)
                 newstratum[i] = newstratum[i] - 2
                 N_lab -= elderstratum[i] * memo_Nlocal(
                     g, n, newstratum, True, mode)
         N_lab *= ZZ(1) / elderstratum.count(1)
         cache_poly[(g, n, stratum)] = N_lab
         cache_labeling[(g, n, stratum)] = ZZ(
             prod(
                 factorial(stratum.count(i))
                 for i in range(-1,
                                max(stratum) + 1)))
         return cache_poly[(g, n, stratum)]
     elif mode == 'derivative' or len(m) == 2:  # case without poles
         _Fs = stratum_to_F(g, n, stratum)
         deg = ZZ(3 * g - 3 + n - 1 / 2 * sum(d - 1 for d in stratum))
         M = sum(m[i] * (i - 1) for i in range(len(m)))
         mondeg = Partitions(deg + n, length=n)
         const = 2**(5 * g - 6 + 2 * n - 2 * M)
         labeling = prod(
             factorial(stratum.count(i))
             for i in range(1,
                            max(stratum) + 1))
         N_lab = ZZ(1)/const*labeling*sum(prod(ZZ(1)/factorial(d-1) for d in par)*\
                         prod(factorial(i) for i in par.to_exp())*\
                         _Fs.monomial_coefficient(prod(T.gen(d-1) for d in par))*\
                         sum(prod(B.gen(j)**(2*(sympar[j]-1)) for j in range(n)) for sympar in Permutations(par))\
                         for par in mondeg)
         cache_poly[(g, n, stratum)] = N_lab
         cache_labeling[(g, n, stratum)] = ZZ(
             prod(
                 factorial(stratum.count(i))
                 for i in range(-1,
                                max(stratum) + 1)))
         return cache_poly[(g, n, stratum)]
     elif mode == 'recursive':
         assert m[2] == 1 and len(
             m
         ) == 3, "'recursive' mode is only available for stratum = [3,1,1,...,-1,-1]"
         first_term = 2**4 * diff(
             memo_Nlocal(g, n + 1, [1] * (m[1] + 5), False, mode), b[n],
             4)(*vanish(b, [n + 1]))
         second_term = -ZZ(1) / 2 * 2 * memo_Nlocal(
             g - 1, n + 2, [1] *
             (m[1] + 3), False, mode)(*vanish(b, [n + 1, n + 2]))
         third_term = 0
         for par in OrderedSetPartitions(b[:n], 2):
             n_1, n_2 = len(par[0]), len(par[1])
             assert n_1 + n_2 == n
             third_term += -ZZ(1)/2*sum(memo_Nlocal(g_1,n_1+1,[1]*(4*g_1-4+2*(n_1+1)),False,mode)(*list(par[0])+[0]*(30-n_1))\
                     *memo_Nlocal(g-g_1,n_2+1,[1]*(4*(g-g_1)-4+2*(n_2+1)),False,mode)(*list(par[1])+[0]*(30-n_2))\
                               for g_1 in range(g+1))
         N_unlab = first_term + second_term + third_term
         cache_labeling[(g, n, stratum)] = ZZ(
             prod(
                 factorial(stratum.count(i))
                 for i in range(-1,
                                max(stratum) + 1)))
         cache_poly[(g, n,
                     stratum)] = N_unlab * cache_labeling[(g, n, stratum)]
         return cache_poly[(g, n, stratum)]