unlisted
ubuntu2004# -*- coding: utf-8 -*-1r"""2The possible different moduli.3"""45import numbers67# Moduli types8MODULI_SM = 0 # smooth (no edge, just the trivial graph)9MODULI_RT = 1 # rational tails (tree with genus 0 vertices but one)10MODULI_CT = 2 # compact type (tree with any kind of vertices)11MODULI_TL = 3 # tree like (tree with self-loops)12MODULI_ST = 4 # stable curves (general case)1314_moduli_to_str = {15MODULI_SM: 'sm', # smooth curves16MODULI_RT: 'rt', # rational tails17MODULI_CT: 'ct', # compact type18MODULI_TL: 'tl', # tree like19MODULI_ST: 'st' # all stable curves20}21_str_to_moduli = {v: k for k, v in _moduli_to_str.items()}222324def get_moduli(arg, default=MODULI_ST, DRpy=False):25if DRpy:26return min(3, get_moduli(arg, default))27if arg is None:28return default29elif isinstance(arg, str):30try:31return _str_to_moduli[arg]32except KeyError:33raise ValueError('invalid moduli {!r}'.format(arg))34elif isinstance(arg, numbers.Integral):35if arg < MODULI_SM or arg > MODULI_ST:36raise ValueError('invalid moduli {!r}'.format(arg))37return int(arg)38else:39raise TypeError("invalid moduli; must be a string 'sm', 'rt', 'ct', 'tl', or 'st' (got {!r})".format(arg))404142def socle_degree(g, n, moduli):43if moduli == MODULI_ST:44# stable curves45return 3 * g - 3 + n46elif moduli == MODULI_TL:47# tree-like48# TODO: this is an over estimation. It is very likely that the socle dimension49# is smaller.50return 3 * g - 3 + n51elif moduli == MODULI_CT:52# compact type53return 2 * g - 3 + n54elif moduli == MODULI_RT:55# rational tails56return g - 2 + n - (g == 0)57elif moduli == MODULI_SM:58# smooth59return g - 1 + (g == 0) - (n == 0)60else:61raise ValueError('unknown moduli')626364