class TestConvertSymToPoly(unittest.TestCase):

  def setUp(self):
    self.poly_ring = PolynomialRing(QQ,"x",3);
    self.x = self.poly_ring.gens()[0];
    self.y = self.poly_ring.gens()[1];
    self.z = self.poly_ring.gens()[2];
    self.vars = var('x,y,z')
    
  def test_zero(self):
    zero = 0*self.vars[0]
    poly = convert_symbolic_to_polynomial(zero,self.poly_ring,self.vars)
    self.assertEqual(poly,self.poly_ring.zero())
    
  def test_convert(self):
    x = self.x
    y = self.y
    z = self.z
    sym_poly = 4*self.vars[0]**4 + self.vars[1]*self.vars[0]**12*self.vars[1]-self.vars[2]
    poly = convert_symbolic_to_polynomial(sym_poly,self.poly_ring,self.vars)
    self.assertEqual(poly,4*x**4+y*x**12*y-z)

  def test_convert_univarient(self):
    y = self.y
    sym_poly = 4*self.vars[1]**4 + self.vars[1]*self.vars[1]**12*self.vars[1]-self.vars[1]
    poly = convert_symbolic_to_polynomial(sym_poly,self.poly_ring,self.vars)
    self.assertEqual(poly,4*y**4+y*y**12*y-y)

  def test_convert_partial(self):
    y = self.y
    z = self.z
    sym_poly = 4*self.vars[2]**4 + self.vars[1]*self.vars[1]**12*self.vars[1]-self.vars[1]
    poly = convert_symbolic_to_polynomial(sym_poly,self.poly_ring,self.vars)
    self.assertEqual(poly,4*z**4+y*y**12*y-y)
class TestWeightedMinDegree(unittest.TestCase):

  def setUp(self):
    self.poly_ring = PolynomialRing(QQ,"x",3);
    self.x = self.poly_ring.gens()[0];
    self.y = self.poly_ring.gens()[1];
    self.z = self.poly_ring.gens()[2];

  def test_zero(self):
    self.assertEqual(wieghted_min_degree(self.poly_ring.zero(),[1,1,1]),0);
  
  def test_homogeneous(self):
    x = self.x;
    y = self.y;
    z = self.z;
    f = x**4 + 4*y*z**3 - z**2;
    self.assertEqual(wieghted_min_degree(f,[1,1,1]),2);

  def test_non_homogeneous(self):
    x = self.x;
    y = self.y;
    z = self.z;
    f = x**4 + 4*y*z**3 - z**2;
    self.assertEqual(wieghted_min_degree(f,[2,1,2]),4);

  def test_negative_wieghts(self):
    x = self.x;
    y = self.y;
    z = self.z;
    f = x**4 + 4*y*z**3 - z**2;
    self.assertEqual(wieghted_min_degree(f,[-1,-1,1]),-4);
class TestMonomialsOfOrder(unittest.TestCase):
 
  def setUp(self):
    self.poly_ring = PolynomialRing(QQ,"x",3);
    self.x = self.poly_ring.gens()[0];
    self.y = self.poly_ring.gens()[1];
    self.z = self.poly_ring.gens()[2];
  
  def test_zero(self):
    mons = [mon for mon in monomials_of_order(0,self.poly_ring,[1,1,1])]
    self.assertEqual(mons,[self.poly_ring.one()])

  def test_homogeneous_3(self):
    x = self.x;
    y = self.y;
    z = self.z;
    true_mons = Set([x**3,y**3,z**3,x**2*y,x**2*z,y**2*x,y**2*z,z**2*x,z**2*y,x*y*z])
    mons = [mon for mon in monomials_of_order(3,self.poly_ring,[1,1,1])]
    self.assertEqual(true_mons,Set(mons))

  def test_non_homogeneous_4(self):
    x = self.x;
    y = self.y;
    z = self.z;
    true_mons = Set([x**4,x**2*y,x*z,y**2])
    mons = [mon for mon in monomials_of_order(4,self.poly_ring,[1,2,3])]
    self.assertEqual(true_mons,Set(mons))
class TestHomogeneousWieghts(unittest.TestCase):

  def setUp(self):
    self.poly_ring = PolynomialRing(QQ,"x",3);
    self.x = self.poly_ring.gens()[0];
    self.y = self.poly_ring.gens()[1];
    self.z = self.poly_ring.gens()[2];
  
  def test_homogenous(self):
    x = self.x
    y = self.y
    z = self.z
    divisor = x*y*z + x**3 + z**3
    wieghts = homogenous_wieghts(divisor)
    #Test this works with a homogenous divisor
    self.assertEquals(wieghts,[3,1,1,1]);
    
  def test_weighted_homogenous(self):
    x = self.x
    y = self.y
    z = self.z
    divisor = x**2*y-z**2
    wieghts = homogenous_wieghts(divisor)
    #Test this works with a weighted homogenous divisor
    self.assertEquals(wieghts,[4,1,2,2])
  
  def test_not_homogenous(self):
    x = self.x
    y = self.y
    z = self.z
    divisor = x**2*y-x**3 + z +y**2;
    self.assertRaises(NotWieghtHomogeneousException,homogenous_wieghts,divisor)
class TestGradedModule(unittest.TestCase):
 
  def setUp(self):
    self.poly_ring = PolynomialRing(QQ,"x",3);
    self.x = self.poly_ring.gens()[0];
    self.y = self.poly_ring.gens()[1];
    self.z = self.poly_ring.gens()[2];

  def test_monomial_basis_zero(self):
    one = self.poly_ring.one()
    zero = self.poly_ring.zero()
    gm = GradedModule([[one,one,one,one]],[0,1,2,3],[1,2,3])
    self.assertEqual(gm.monomial_basis(0),[(one,zero,zero,zero)])

  def test_monomial_basis(self):
    x = self.x
    y = self.y
    one = self.poly_ring.one()
    zero = self.poly_ring.zero()
    gm = GradedModule([[one,one]],[0,1],[1,2,3])
    true_basis  = [(x**2,zero),(y,zero),(zero,x)]
    self.assertEqual(Set(gm.monomial_basis(2)),Set(true_basis))

  def test_homogeneous_parts_A(self):
    one = self.poly_ring.one()
    zero = self.poly_ring.zero()
    gm = GradedModule([[one,one]],[0,1],[1,2,3])
    parts = gm.get_homogeneous_parts([one,one])
    parts_true = { 0:[one,zero] , 1:[zero,one] }
    self.assertEqual(parts,parts_true)

  def test_homogeneous_parts_B(self):
    x = self.x
    y = self.y
    z = self.z
    one = self.poly_ring.one()
    zero = self.poly_ring.zero()
    gm = GradedModule([[one,one]],[0,1],[1,2,3])
    parts = gm.get_homogeneous_parts([x*y,x**3+z*y])
    self.assertEqual(parts,{3:[x*y,zero],4:[zero,x**3],6:[zero,z*y]})
  
  def test_homogeneous_part_basisA(self):
    x = self.x
    y = self.y
    z = self.z
    one = self.poly_ring.one()
    gm = GradedModule([[z,one,x**2 + y]],[0,1,2],[1,2,3])
    basis = gm.homogeneous_part_basis(6);
    self.assertEqual(len(basis),10)
 
  def test_homogeneous_part_basisB(self):
    #From bug found with ncd
    x = self.x
    y = self.y
    z = self.z
    zero = self.poly_ring.zero()
    gm = GradedModule([[zero, x*z, x*y], [zero, -x*z, zero], [y*z, zero, zero]],[1, 1, 1],[1, 1, 1])
    basis = gm.homogeneous_part_basis(3);
    self.assertEqual(len(basis),3)
Example #6
0
class TestLogaritmicDerivations(unittest.TestCase):
    def setUp(self):
        self.poly_ring = PolynomialRing(QQ, "x", 3)
        self.x = self.poly_ring.gens()[0]
        self.y = self.poly_ring.gens()[1]
        self.z = self.poly_ring.gens()[2]

    def test_normal_crossing(self):
        zero = self.poly_ring.zero()
        log_der = LogarithmicDerivations(self.x * self.y * self.z)
        free = SingularModule([[self.x, zero, zero], [zero, self.y, zero],
                               [zero, zero, self.z]])
        self.assertTrue(log_der.equals(free))
Example #7
0
    def cardinality(self):
        r"""
        Counts the number of derangements of a positive integer, a
        list, or a string.  The list or string may contain repeated
        elements.  If an integer `n` is given, the value returned
        is the number of derangements of `[1, 2, 3, \ldots, n]`.

        For an integer, or a list or string with all elements
        distinct, the value is obtained by the standard result
        `D_2 = 1, D_3 = 2, D_n = (n-1) (D_{n-1} + D_{n-2})`.

        For a list or string with repeated elements, the number of
        derangements is computed by Macmahon's theorem. If the numbers
        of repeated elements are `a_1, a_2, \ldots, a_k` then the number
        of derangements is given by the coefficient of `x_1 x_2 \cdots
        x_k` in the expansion of `\prod_{i=0}^k (S - s_i)^{a_i}` where
        `S = x_1 + x_2 + \cdots + x_k`.

        EXAMPLES::

            sage: D = Derangements(5)
            sage: D.cardinality()
            44
            sage: D = Derangements([1,44,918,67,254])
            sage: D.cardinality()
            44
            sage: D = Derangements(['A','AT','CAT','CATS','CARTS'])
            sage: D.cardinality()
            44
            sage: D = Derangements('UNCOPYRIGHTABLE')
            sage: D.cardinality()
            481066515734
            sage: D = Derangements([1,1,2,2,3,3])
            sage: D.cardinality()
            10
            sage: D = Derangements('SATTAS')
            sage: D.cardinality()
            10
            sage: D = Derangements([1,1,2,2,2])
            sage: D.cardinality()
            0
        """
        if self.__multi:
            sL = set(self._set)
            A = [self._set.count(i) for i in sL]
            R = PolynomialRing(QQ, 'x', len(A))
            S = sum(i for i in R.gens())
            e = prod((S-x)**y for (x, y) in zip(R.gens(), A))
            return Integer(e.coefficient(dict([(x, y) for (x, y) in zip(R.gens(), A)])))
        return self._count_der(len(self._set))
Example #8
0
File: linear.py Project: hahaXD/TDK
 def gidentify(self, idedge, eql_edges=None):
     import sage.all
     if eql_edges is not None:
         eql_edges_uf = edges_union_find (eql_edges)
     else:
         eql_edges_uf = []
     from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing
     from sage.rings.rational_field import QQ
     from sage.rings.ideal import Ideal
     from sage.symbolic.ring import var
     e  = generateEdges(self)
     e2 = generateEdges(self, "X_", "e_")
     variables = list(e2.values()) + list(e.values())
     ring = PolynomialRing(QQ, variables)
     gens = ring.gens()
     e = replaceDictVals(e, variables, gens)
     e2 = replaceDictVals(e2, variables, gens)
     if eql_edges is not None:
         for eql_edge in eql_edges:
             e[eql_edge[1]] = e[eql_edges_uf[eql_edge[1]]]
             e[eql_edge[0]] = e[eql_edges_uf[eql_edge[0]]]
     cov1 = generateCovarianceEquations(self, e)
     cov2 = generateCovarianceEquations(self, e2)
     eqns = [cov1[k] - cov2[k] for k in cov1]
     dc_vars  = [e2[k] for k in e2 if k != idedge and k not in eql_edges_uf]
     core_basis = Ideal(eqns).elimination_ideal(dc_vars).groebner_basis()
     if eql_edges is not None:
         eql_vars = [e2[k] for k in e2 if k != idedge and k in eql_edges_uf]
         core_eqns = [k for k in core_basis]
         for eql_edge in eql_edges:
             core_eqns.append(e2[eql_edge[0]] - e2[eql_edge[1]])
         core_basis = Ideal(core_eqns).elimination_ideal(eql_vars).groebner_basis()
     return core_basis, e2[idedge], e
Example #9
0
    def __init__(this, p, category=None):
        """
        TESTS::

            sage: from yacop.testing.testalgebra import Testclass1
            sage: X=Testclass1(5)
            sage: X.monomial((2,1,8,0))
            x^2*a*y^8
            sage: X.monomial((3,0,-17,1))
            x^3*b/y^17

            sage: from yacop.utils.region import region
            sage: X._manual_test_left_action(region(tmax=20))
            1126 non-zero multiplications checked
            sage: X._manual_test_left_conj_action(region(tmax=20)) # long time
            1148 non-zero multiplications checked

        """
        # must admit the "category" keyword for suspendability
        R = PolynomialRing(FiniteField(p), "x,a,y,b")
        x, a, y, b = R.gens()
        I = R.ideal([a**2, b**2])
        degs = lambda idx: (1, -1, 0) if (idx & 1) else (2, 0, 0)
        SteenrodAlgebraBase.__init__(this,
                                     R, [degs(n) for n in range(4)],
                                     I,
                                     SteenrodAlgebra(p),
                                     category=category)
def whitney_divisor(var=None):
  if var:
    poly_ring = PolynomialRing(QQ,3,var)
  else:
    poly_ring = PolynomialRing(QQ,3,"xyz")
  gens = poly_ring.gens()
  return gens[0]**2*gens[1]-gens[2]**2
def automorphy_factor_vector(p, a, c, k, chi, p_prec, var_prec, R):
    """
    EXAMPLES::
        
        sage: from sage.modular.pollack_stevens.families_util import automorphy_factor_vector
        sage: automorphy_factor_vector(3, 1, 3, 0, None, 4, 3, PowerSeriesRing(ZpCA(3), 'w'))
        [1 + O(3^20), O(3^21) + (3 + 3^2 + 2*3^3 + O(3^21))*w + (3^2 + 2*3^3 + O(3^22))*w^2, O(3^22) + (3^2 + 2*3^3 + O(3^22))*w + (2*3^2 + O(3^22))*w^2, O(3^22) + (3^2 + 3^3 + O(3^22))*w + (2*3^3 + O(3^23))*w^2]
    """
    S = PolynomialRing(R, 'z')
    z = S.gens()[0]
    w = R.gen()
    aut = S(1)
    for n in range(1, var_prec):
        LB = logpp_binom(n, p, p_prec)
        ta = ZZ(Qp(p, 2 * max(p_prec, var_prec)).teichmuller(a))
        arg = (a / ta - 1) / p + c / (p * ta) * z
        aut += LB(arg) * (w ** n)
    aut *= (ta ** k)
    if not (chi is None):
        aut *= chi(a)
    aut = aut.list()
    len_aut = len(aut)
    if len_aut == p_prec:
        return aut
    elif len_aut > p_prec:
        return aut[:p_prec]
    return aut + [R.zero_element()] * (p_prec - len_aut)
def rand_w_hom_divisor(n,degs=None,mon_num=None,var="z"):
  if degs==None:
    degs = [randrange(2,6) for _ in range(n)]
  deg = sum(degs)
  if mon_num==None:
    mon_num = randrange(2,8)
  poly_ring = PolynomialRing(QQ,n,var)
  div = poly_ring.zero()
  min_w = min(degs)
  for i in range(mon_num):
    expo = [0]*n
    cur_deg = 0
    while cur_deg!=deg:
      if cur_deg>deg:
        expo = [0]*n
        cur_deg = 0
      if deg-cur_deg<min_w:
        expo = [0]*n
        cur_deg = 0
      next_g = randrange(0,n)
      expo[next_g] += 1
      cur_deg += degs[next_g]
    coeff = randrange(-n,n)/n
    mon = poly_ring.one()
    for i,e in enumerate(expo):
      mon *= poly_ring.gens()[i]**e
    div += coeff*mon
  return div
Example #13
0
def whitney_divisor(var=None):
    if var:
        poly_ring = PolynomialRing(QQ, 3, var)
    else:
        poly_ring = PolynomialRing(QQ, 3, "xyz")
    gens = poly_ring.gens()
    return gens[0]**2 * gens[1] - gens[2]**2
Example #14
0
File: linear.py Project: hahaXD/TDK
    def solve_by_random_weights(self, idedge, eql_edge):

        from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing
        from sage.rings.rational_field import QQ
        from sage.rings.ideal import Ideal
        from sage.symbolic.ring import var
        e  = generateEdges(self)
        e2 = generateEdges(self, "X_", "e_")
        variables = list(e2.values())
        ring = PolynomialRing(QQ, variables)
        gens = ring.gens()
        q = [i for i in range(1, len(e) + 2)]
        rnd.shuffle(q)
        for idx, e_t in enumerate(e):
            e[e_t] = q[idx]
        e[eql_edge[0]] = q[-1]
        e[eql_edge[1]] = e[eql_edge[0]]
        e2 = replaceDictVals(e2, variables, gens)
        cov1 = generateCovarianceEquations(self, e)
        cov2 = generateCovarianceEquations(self, e2)
        eqns = [cov1[k] - cov2[k] for k in cov1]
        eqns.append(e2[eql_edge[0]] - e2[eql_edge[1]])
        dc_vars  = [e2[k] for k in e2 if k != idedge]
        core_basis = Ideal(eqns).elimination_ideal(dc_vars).groebner_basis()
        return core_basis, e2[idedge]
Example #15
0
def breiskorn_pham_divisor(n, var="z"):
    poly_ring = PolynomialRing(QQ, n, var)
    for i, g in enumerate(poly_ring.gens()):
        if i == 0:
            div = g**3
        else:
            div += g**2
    return div
def braid_divisor(n,var="z"):
  poly_ring = PolynomialRing(QQ,n,var)
  div = poly_ring.one()
  gens = poly_ring.gens()
  for i in range(n):
    for j in range(i+1,n):
      div *= (gens[i]-gens[j])
  return div
Example #17
0
def comp_prod(P, Q):
    n = Q.degree()
    K = P.base_ring()
    A = PolynomialRing(K, 'X')
    X = A.gen()
    AA = PolynomialRing(K, 'Y,Z')
    Y, Z = AA.gens()
    return P(Y).resultant(AA(Y**n * Q(Z/Y)), Y)(1,X)
def breiskorn_pham_divisor(n,var="z"):
  poly_ring = PolynomialRing(QQ,n,var)
  for i,g in enumerate(poly_ring.gens()):
    if i==0:
      div = g**3
    else:
      div += g**2
  return div
Example #19
0
 def eu(p):
     """
     local euler factor
     """
     f = rho.local_factor(p)
     co = [ZZ(round(x)) for x in f.coeffs()]
     R = PolynomialRing(QQ, "T")
     T = R.gens()[0]
     return sum( co[n] * T**n for n in range(len(co)))
 def test_p_module_n_crossing(self):
   #Make sure this doesnt throw an error - fix bug
   for i in range(4,5):
     p_ring = PolynomialRing(QQ,i,"z")
     crossing = p_ring.one()
     for g in p_ring.gens():
       crossing *= g
     logdf = LogarithmicDifferentialForms(crossing)
     logdf.p_module(i-1)
Example #21
0
def _eta_relations_helper(eta1, eta2, degree, qexp_terms, labels, verbose):
    r"""
    Helper function used by eta_poly_relations. Finds a basis for the
    space of linear relations between the first qexp_terms of the
    `q`-expansions of the monomials
    `\eta_1^i * \eta_2^j` for `0 \le i,j < degree`,
    and calculates a Groebner basis for the ideal generated by these
    relations.

    Liable to return meaningless results if qexp_terms isn't at least
    `1 + d*(m_1,m_2)` where

    .. math::

       m_i = min(0, {\text degree of the pole of $\eta_i$ at $\infty$})

    as then 1 will be in the ideal.

    EXAMPLE::

        sage: from sage.modular.etaproducts import _eta_relations_helper
        sage: r,s = EtaGroup(4).basis()
        sage: _eta_relations_helper(r,s,4,100,['a','b'],False)
        [a*b - a + 16]
        sage: _eta_relations_helper(EtaProduct(26, {2:2,13:2,26:-2,1:-2}),EtaProduct(26, {2:4,13:2,26:-4,1:-2}),3,12,['a','b'],False) # not enough terms, will return rubbish
        [1]
    """

    indices = [(i,j) for j in range(degree) for i in range(degree)]
    inf = CuspFamily(eta1.level(), 1)

    pole_at_infinity = -(min([0, eta1.order_at_cusp(inf)]) + min([0,eta2.order_at_cusp(inf)]))*degree
    if verbose: print "Trying all coefficients from q^%s to q^%s inclusive" % (-pole_at_infinity, -pole_at_infinity + qexp_terms - 1)

    rows = []
    for j in xrange(qexp_terms):
        rows.append([])
    for i in indices:
        func = (eta1**i[0]*eta2**i[1]).qexp(qexp_terms)
        for j in xrange(qexp_terms):
            rows[j].append(func[j - pole_at_infinity])
    M = matrix(rows)
    V = M.right_kernel()
    if V.dimension() == 0:
        if verbose: print "No polynomial relation of order %s valid for %s terms" % (degree, qexp_terms)
        return None
    if V.dimension() >= 1:
        #print "Found relation: "
        R = PolynomialRing(QQ, 2, labels)
        x,y = R.gens()
        relations = []
        for c in V.basis():
            relations.append(sum( [ c[v] * x**indices[v][0] * y**indices[v][1] for v in xrange(len(indices))]))
            #print relations[-1], " = 0"
        id = R.ideal(relations)
        return id.groebner_basis()
Example #22
0
def BezoutianQuadraticForm(f, g):
    r"""
    Compute the Bezoutian of two polynomials defined over a common base ring.  This is defined by

    .. MATH::

        {\rm Bez}(f, g) := \frac{f(x) g(y) - f(y) g(x)}{y - x}

    and has size defined by the maximum of the degrees of `f` and `g`.

    INPUT:

    - `f`, `g` -- polynomials in `R[x]`, for some ring `R`

    OUTPUT:

    a quadratic form over `R`

    EXAMPLES::

        sage: R = PolynomialRing(ZZ, 'x')
        sage: f = R([1,2,3])
        sage: g = R([2,5])
        sage: Q = BezoutianQuadraticForm(f, g) ; Q
        Quadratic form in 2 variables over Integer Ring with coefficients:
        [ 1 -12 ]
        [ * -15 ]

    AUTHORS:

    - Fernando Rodriguez-Villegas, Jonathan Hanke -- added on 11/9/2008

    """
    ## Check that f and g are polynomials with a common base ring
    if not is_Polynomial(f) or not is_Polynomial(g):
        raise TypeError("Oops!  One of your inputs is not a polynomial. =(")
    if f.base_ring() != g.base_ring():                   ## TO DO:  Change this to allow coercion!
        raise TypeError("Oops!  These polynomials are not defined over the same coefficient ring.")

    ## Initialize the quadratic form
    R = f.base_ring()
    P = PolynomialRing(R, ['x','y'])
    a, b = P.gens()
    n = max(f.degree(), g.degree())
    Q = QuadraticForm(R, n)

    ## Set the coefficients of Bezoutian
    bez_poly = (f(a) * g(b) - f(b) * g(a)) // (b - a)    ## Truncated (exact) division here
    for i in range(n):
        for j in range(i, n):
            if i == j:
                Q[i,j] = bez_poly.coefficient({a:i,b:j})
            else:
                Q[i,j] = bez_poly.coefficient({a:i,b:j}) * 2

    return Q
Example #23
0
def new_automorphy_factor_vector(p, a, c, k, chi, p_prec, var_prec, R):
    #if not R.is_capped_relative():
    #    Rcr =
    if p_prec > R.precision_cap():
        raise ValueError("Specified p-adic precision, p_prec, should be at most that of R.")
    S = PolynomialRing(R, 'z')
    z = S.gens()[0]
    w = R.gen()
    aut = S(R1, p_prec)
    ta = R.teichmuller(R(a, p_prec))
def is_convergent(n, den):
    r"""
    TESTS::

        sage: import itertools
        sage: from surface_dynamics.misc.generalized_multiple_zeta_values import is_convergent
        sage: V = FreeModule(ZZ, 3)
        sage: va = V((1,0,0)); va.set_immutable()
        sage: vb = V((0,1,0)); vb.set_immutable()
        sage: vc = V((0,0,1)); vc.set_immutable()
        sage: vd = V((1,1,0)); vd.set_immutable()
        sage: ve = V((1,0,1)); ve.set_immutable()
        sage: vf = V((0,1,1)); vf.set_immutable()
        sage: vg = V((1,1,1)); vg.set_immutable()
        sage: gens = [va,vb,vc,vd,ve,vf,vg]
        sage: N = 0
        sage: for p in itertools.product([0,1,2], repeat=7): # optional: mzv
        ....:     if sum(map(bool,p)) == 3 and is_convergent(3, list(zip(gens,p))):
        ....:         print(p)
        ....:         N += 1
        (0, 0, 0, 0, 1, 1, 2)
        (0, 0, 0, 0, 1, 2, 1)
        (0, 0, 0, 0, 1, 2, 2)
        (0, 0, 0, 0, 2, 1, 1)
        (0, 0, 0, 0, 2, 1, 2)
        (0, 0, 0, 0, 2, 2, 1)
        (0, 0, 0, 0, 2, 2, 2)
        (0, 0, 0, 1, 0, 1, 2)
        ...
        (2, 0, 2, 0, 0, 2, 0)
        (2, 0, 2, 2, 0, 0, 0)
        (2, 1, 0, 0, 0, 0, 2)
        (2, 1, 0, 0, 0, 2, 0)
        (2, 2, 0, 0, 0, 0, 2)
        (2, 2, 0, 0, 0, 2, 0)
        (2, 2, 0, 0, 2, 0, 0)
        (2, 2, 2, 0, 0, 0, 0)
        sage: print(N) # optional: mzv
        125
    """
    from sage.geometry.polyhedron.constructor import Polyhedron
    from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing

    assert all(len(v) == n for v, p in den), (n, den)

    # TODO: fast code path

    R = PolynomialRing(QQ, 'x', n)
    x = R.gens()
    den_poly = prod(linear_form(R, v)**p for v, p in den)
    newton_polytope = Polyhedron(vertices=den_poly.exponents(),
                                 rays=negative_rays(n))
    V = newton_polytope.intersection(Polyhedron(rays=[[1] * n])).vertices()
    r = max(max(v.vector()) for v in V)
    return r > 1
Example #25
0
            def expand(self, n, alphabet='x'):
                r"""
                Expands the quasi-symmetric function written in the monomial basis in
                `n` variables.

                INPUT:

                - ``n`` -- an integer
                - ``alphabet`` -- (default:'x') a string

                OUTPUT:

                - The quasi-symmetric function ``self`` expressed in the ``n`` variables
                  described by ``alphabet``.

                .. TODO:: accept an *alphabet* as input

                EXAMPLES::

                    sage: M = QuasiSymmetricFunctions(QQ).Monomial()
                    sage: M[4,2].expand(3)
                    x0^4*x1^2 + x0^4*x2^2 + x1^4*x2^2

                One can use a different set of variable by using the
                optional argument ``alphabet``::

                    sage: M=QuasiSymmetricFunctions(QQ).Monomial()
                    sage: M[2,1,1].expand(4,alphabet='y')
                    y0^2*y1*y2 + y0^2*y1*y3 + y0^2*y2*y3 + y1^2*y2*y3

                TESTS::

                    sage: (3*M([])).expand(2)
                    3
                    sage: M[4,2].expand(0)
                    0
                    sage: M([]).expand(0)
                    1
                """
                from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing
                M = self.parent()
                P = PolynomialRing(M.base_ring(), n, alphabet)
                x = P.gens()
                def on_basis(comp, i):
                    if not comp:
                        return P.one()
                    elif len(comp) > i:
                        return P.zero()
                    else:
                        return x[i-1]**comp[-1] * on_basis(comp[:-1], i-1) + \
                                                  on_basis(comp,      i-1)
                return M._apply_module_morphism(self, lambda comp: on_basis(comp,n),
                                                codomain = P)
Example #26
0
class TestConvertPolyToSym(unittest.TestCase):
    def setUp(self):
        self.poly_ring = PolynomialRing(QQ, "x", 3)
        self.x = self.poly_ring.gens()[0]
        self.y = self.poly_ring.gens()[1]
        self.z = self.poly_ring.gens()[2]
        self.vars = var('x,y,z')

    def test_zero(self):
        zero = self.poly_ring.zero()
        poly = convert_polynomial_to_symbolic(zero, self.vars)
        self.assertEqual(poly, 0)

    def test_convert(self):
        x = self.x
        y = self.y
        z = self.z
        poly = 4 * x**4 + y * x**12 * y - z
        sym_poly = 4 * self.vars[0]**4 + self.vars[1] * self.vars[
            0]**12 * self.vars[1] - self.vars[2]
        con_poly = convert_polynomial_to_symbolic(poly, self.vars)
        self.assertEqual(sym_poly, con_poly)
class TestConvertPolyToSym(unittest.TestCase):

  def setUp(self):
    self.poly_ring = PolynomialRing(QQ,"x",3);
    self.x = self.poly_ring.gens()[0];
    self.y = self.poly_ring.gens()[1];
    self.z = self.poly_ring.gens()[2];
    self.vars = var('x,y,z')
    
  def test_zero(self):
    zero = self.poly_ring.zero()
    poly = convert_polynomial_to_symbolic(zero,self.vars)
    self.assertEqual(poly,0)
    
  def test_convert(self):
    x = self.x
    y = self.y
    z = self.z
    poly = 4*x**4+y*x**12*y-z
    sym_poly = 4*self.vars[0]**4 + self.vars[1]*self.vars[0]**12*self.vars[1]-self.vars[2]
    con_poly = convert_polynomial_to_symbolic(poly,self.vars)
    self.assertEqual(sym_poly,con_poly)
Example #28
0
class TestConvertSymToPoly(unittest.TestCase):
    def setUp(self):
        self.poly_ring = PolynomialRing(QQ, "x", 3)
        self.x = self.poly_ring.gens()[0]
        self.y = self.poly_ring.gens()[1]
        self.z = self.poly_ring.gens()[2]
        self.vars = var('x,y,z')

    def test_zero(self):
        zero = 0 * self.vars[0]
        poly = convert_symbolic_to_polynomial(zero, self.poly_ring, self.vars)
        self.assertEqual(poly, self.poly_ring.zero())

    def test_convert(self):
        x = self.x
        y = self.y
        z = self.z
        sym_poly = 4 * self.vars[0]**4 + self.vars[1] * self.vars[
            0]**12 * self.vars[1] - self.vars[2]
        poly = convert_symbolic_to_polynomial(sym_poly, self.poly_ring,
                                              self.vars)
        self.assertEqual(poly, 4 * x**4 + y * x**12 * y - z)

    def test_convert_univarient(self):
        y = self.y
        sym_poly = 4 * self.vars[1]**4 + self.vars[1] * self.vars[
            1]**12 * self.vars[1] - self.vars[1]
        poly = convert_symbolic_to_polynomial(sym_poly, self.poly_ring,
                                              self.vars)
        self.assertEqual(poly, 4 * y**4 + y * y**12 * y - y)

    def test_convert_partial(self):
        y = self.y
        z = self.z
        sym_poly = 4 * self.vars[2]**4 + self.vars[1] * self.vars[
            1]**12 * self.vars[1] - self.vars[1]
        poly = convert_symbolic_to_polynomial(sym_poly, self.poly_ring,
                                              self.vars)
        self.assertEqual(poly, 4 * z**4 + y * y**12 * y - y)
Example #29
0
def automorphy_factor_vector(p, a, c, k, chi, p_prec, var_prec, R):
    S = PolynomialRing(R, 'z')
    z = S.gens()[0]
    w = R.gen()
    aut = S(1)
    for n in range(1, var_prec):
        LB = logpp_binom(n, p, p_prec)
        ta = ZZ(Qp(p, 2 * max(p_prec, var_prec)).teichmuller(a))
        arg = (a / ta - 1) / p + c / (p * ta) * z
        aut += LB(arg) * (w ** n)
    aut *= (ta ** k)
    if not (chi is None):
        aut *= chi(a)    
    return Sequence(aut)
Example #30
0
def automorphy_factor_vector(p, a, c, k, chi, p_prec, var_prec, R):
    """
    EXAMPLES::
        
        sage: from sage.modular.pollack_stevens.families_util import automorphy_factor_vector
        sage: automorphy_factor_vector(3, 1, 3, 0, None, 4, 3, PowerSeriesRing(ZpCA(3), 'w'))
        [1 + O(3^20), O(3^21) + (3 + 3^2 + 2*3^3 + O(3^21))*w + (3^2 + 2*3^3 + O(3^22))*w^2, O(3^22) + (3^2 + 2*3^3 + O(3^22))*w + (2*3^2 + O(3^22))*w^2, O(3^22) + (3^2 + 3^3 + O(3^22))*w + (2*3^3 + O(3^23))*w^2]
        sage: automorphy_factor_vector(3, 1, 3, 2, None, 4, 3, PowerSeriesRing(ZpCA(3), 'w'))
        [1 + O(3^20),
         O(3^21) + (3 + 3^2 + 2*3^3 + O(3^21))*w + (3^2 + 2*3^3 + O(3^22))*w^2,
         O(3^22) + (3^2 + 2*3^3 + O(3^22))*w + (2*3^2 + O(3^22))*w^2,
         O(3^22) + (3^2 + 3^3 + O(3^22))*w + (2*3^3 + O(3^23))*w^2]
        sage: p, a, c, k, chi, p_prec, var_prec, R = 11, -3, 11, 0, None, 6, 4, PowerSeriesRing(ZpCA(11, 6), 'w')
        sage: automorphy_factor_vector(p, a, c, k, chi, p_prec, var_prec, R)
        [1 + O(11^6) + (7*11^2 + 4*11^3 + 11^4 + 9*11^5 + 3*11^6 + 10*11^7 + O(11^8))*w + (2*11^3 + 2*11^5 + 2*11^6 + 6*11^7 + 8*11^8 + O(11^9))*w^2 + (6*11^4 + 4*11^5 + 5*11^6 + 6*11^7 + 4*11^9 + O(11^10))*w^3,
         O(11^7) + (7*11 + 11^2 + 2*11^3 + 3*11^4 + 4*11^5 + 3*11^6 + O(11^7))*w + (2*11^2 + 4*11^3 + 5*11^4 + 10*11^5 + 10*11^6 + 2*11^7 + O(11^8))*w^2 + (6*11^3 + 6*11^4 + 2*11^5 + 9*11^6 + 9*11^7 + 2*11^8 + O(11^9))*w^3,
         O(11^8) + (3*11^2 + 4*11^4 + 2*11^5 + 6*11^6 + 10*11^7 + O(11^8))*w + (8*11^2 + 7*11^3 + 8*11^4 + 8*11^5 + 11^6 + O(11^8))*w^2 + (3*11^3 + 9*11^4 + 10*11^5 + 5*11^6 + 10*11^7 + 11^8 + O(11^9))*w^3,
         O(11^9) + (8*11^3 + 3*11^4 + 3*11^5 + 7*11^6 + 2*11^7 + 6*11^8 + O(11^9))*w + (10*11^3 + 6*11^5 + 7*11^6 + O(11^9))*w^2 + (4*11^3 + 11^4 + 8*11^8 + O(11^9))*w^3,
         O(11^10) + (2*11^4 + 9*11^5 + 8*11^6 + 5*11^7 + 4*11^8 + 6*11^9 + O(11^10))*w + (6*11^5 + 3*11^6 + 5*11^7 + 7*11^8 + 4*11^9 + O(11^10))*w^2 + (2*11^4 + 8*11^6 + 2*11^7 + 9*11^8 + 7*11^9 + O(11^10))*w^3,
         O(11^11) + (2*11^5 + 10*11^6 + 10*11^7 + 10*11^8 + 10*11^9 + 10*11^10 + O(11^11))*w + (5*11^5 + 10*11^6 + 10*11^7 + 10*11^8 + 10*11^9 + 10*11^10 + O(11^11))*w^2 + (2*11^5 + 10*11^6 + 10*11^7 + 10*11^8 + 10*11^9 + 10*11^10 + O(11^11))*w^3]
        sage: k = 2
        sage: automorphy_factor_vector(p, a, c, k, chi, p_prec, var_prec, R)
        [9 + 6*11^2 + 11^3 + 9*11^4 + 8*11^5 + O(11^6) + (8*11^2 + 8*11^3 + 10*11^4 + 6*11^5 + 5*11^7 + O(11^8))*w + (7*11^3 + 11^4 + 8*11^5 + 9*11^7 + 10*11^8 + O(11^9))*w^2 + (10*11^4 + 7*11^5 + 7*11^6 + 3*11^7 + 8*11^8 + 4*11^9 + O(11^10))*w^3,
         O(11^7) + (8*11 + 3*11^2 + 6*11^3 + 11^4 + 6*11^5 + 11^6 + O(11^7))*w + (7*11^2 + 4*11^3 + 5*11^4 + 10*11^6 + 5*11^7 + O(11^8))*w^2 + (10*11^3 + 3*11^4 + 4*11^5 + 7*11^6 + 10*11^7 + 3*11^8 + O(11^9))*w^3,
         O(11^8) + (5*11^2 + 2*11^3 + 10*11^4 + 3*11^5 + 8*11^6 + 7*11^7 + O(11^8))*w + (6*11^2 + 3*11^3 + 5*11^4 + 11^5 + 5*11^6 + 9*11^7 + O(11^8))*w^2 + (5*11^3 + 6*11^4 + 5*11^5 + 2*11^6 + 9*11^7 + 6*11^8 + O(11^9))*w^3,
         O(11^9) + (6*11^3 + 11^5 + 8*11^6 + 9*11^7 + 2*11^8 + O(11^9))*w + (2*11^3 + 8*11^4 + 4*11^5 + 6*11^6 + 11^7 + 8*11^8 + O(11^9))*w^2 + (3*11^3 + 11^4 + 3*11^5 + 11^6 + 5*11^7 + 6*11^8 + O(11^9))*w^3,
         O(11^10) + (7*11^4 + 5*11^5 + 3*11^6 + 10*11^7 + 10*11^8 + 11^9 + O(11^10))*w + (10*11^5 + 9*11^6 + 6*11^7 + 6*11^8 + 10*11^9 + O(11^10))*w^2 + (7*11^4 + 11^5 + 7*11^6 + 5*11^7 + 6*11^8 + 2*11^9 + O(11^10))*w^3,
         O(11^11) + (7*11^5 + 3*11^6 + 8*11^8 + 5*11^9 + 8*11^10 + O(11^11))*w + (11^5 + 6*11^6 + 7*11^7 + 11^8 + 2*11^10 + O(11^11))*w^2 + (7*11^5 + 3*11^6 + 8*11^8 + 5*11^9 + 8*11^10 + O(11^11))*w^3]
    """
    S = PolynomialRing(R, 'z')
    z = S.gens()[0]
    w = R.gen()
    aut = S(1)
    for n in range(1, var_prec):
        ## RP: I doubled the precision in "z" here to account for the loss of precision from plugging in arg in below
        ## This should be done better.
        LB = logpp_binom(n, p, ceil(p_prec * (p-1)/(p-2)))
        ta = ZZ(Qp(p, 2 * max(p_prec, var_prec)).teichmuller(a))
        arg = (a / ta - 1) / p + c / (p * ta) * z
        aut += LB(arg).truncate(p_prec) * (w ** n)
    aut *= (ta ** k)
    #if not (chi is None):
    #    aut *= chi(a)
    aut = aut.list()
    len_aut = len(aut)
    if len_aut == p_prec:
        return aut
    elif len_aut > p_prec:
        return aut[:p_prec]
    return aut + [R.zero_element()] * (p_prec - len_aut)
Example #31
0
 def eu(p):
     """
     local euler factor
     """
     if self.selfdual:
         K = QQ
     else:
         K = ComplexField()
     R = PolynomialRing(K, "T")
     T = R.gens()[0]
     if self.conductor % p != 0:
         return  1 - ComplexField()(chi(p)) * T
     else:
         return R(1)
Example #32
0
    def divisor_of_function(self, r):
        """
        Return the divisor of a function on a curve.

        INPUT: r is a rational function on X

        OUTPUT:


        -  ``list`` - The divisor of r represented as a list of
           coefficients and points. (TODO: This will change to a more
           structural output in the future.)


        EXAMPLES::

            sage: F = GF(5)
            sage: P2 = AffineSpace(2, F, names = 'xy')
            sage: R = P2.coordinate_ring()
            sage: x, y = R.gens()
            sage: f = y^2 - x^9 - x
            sage: C = Curve(f)
            sage: K = FractionField(R)
            sage: r = 1/x
            sage: C.divisor_of_function(r)     # todo: not implemented (broken)
                  [[-1, (0, 0, 1)]]
            sage: r = 1/x^3
            sage: C.divisor_of_function(r)     # todo: not implemented (broken)
                  [[-3, (0, 0, 1)]]
        """
        F = self.base_ring()
        f = self.defining_polynomial()
        pts = self.places_on_curve()
        numpts = len(pts)
        R = f.parent()
        x,y = R.gens()
        R0 = PolynomialRing(F,3,names = [str(x),str(y),"t"])
        vars0 = R0.gens()
        t = vars0[2]
        divf = []
        for pt0 in pts:
            if pt0[2] != F(0):
                lcs = self.local_coordinates(pt0,5)
                yt = lcs[1]
                xt = lcs[0]
                ldg = degree_lowest_rational_function(r(xt,yt),t)
                if ldg[0] != 0:
                    divf.append([ldg[0],pt0])
        return divf
    def canonical_scheme(self, t=None):
        """
        Return the canonical scheme.

        This is a scheme that contains this hypergeometric motive in its cohomology.

        EXAMPLES::

            sage: from sage.modular.hypergeometric_motive import HypergeometricData as Hyp
            sage: H = Hyp(cyclotomic=([3],[4]))
            sage: H.gamma_list()
            [-1, 2, 3, -4]
            sage: H.canonical_scheme()
            Spectrum of Quotient of Multivariate Polynomial Ring
            in X0, X1, Y0, Y1 over Fraction Field of Univariate Polynomial Ring
            in t over Rational Field by the ideal
            (X0 + X1 - 1, Y0 + Y1 - 1, (-t)*X0^2*X1^3 + 27/64*Y0*Y1^4)

            sage: H = Hyp(gamma_list=[-2, 3, 4, -5])
            sage: H.canonical_scheme()
            Spectrum of Quotient of Multivariate Polynomial Ring
            in X0, X1, Y0, Y1 over Fraction Field of Univariate Polynomial Ring
            in t over Rational Field by the ideal
            (X0 + X1 - 1, Y0 + Y1 - 1, (-t)*X0^3*X1^4 + 1728/3125*Y0^2*Y1^5)

        REFERENCES:

        [Kat1991]_, section 5.4
        """
        if t is None:
            t = FractionField(QQ['t']).gen()
        basering = t.parent()
        gamma_pos = [u for u in self.gamma_list() if u > 0]
        gamma_neg = [u for u in self.gamma_list() if u < 0]
        N_pos = len(gamma_pos)
        N_neg = len(gamma_neg)
        varX = ['X{}'.format(i) for i in range(N_pos)]
        varY = ['Y{}'.format(i) for i in range(N_neg)]
        ring = PolynomialRing(basering, varX + varY)
        gens = ring.gens()
        X = gens[:N_pos]
        Y = gens[N_pos:]
        eq0 = ring.sum(X) - 1
        eq1 = ring.sum(Y) - 1
        eq2_pos = ring.prod(X[i] ** gamma_pos[i] for i in range(N_pos))
        eq2_neg = ring.prod(Y[j] ** -gamma_neg[j] for j in range(N_neg))

        ideal = ring.ideal([eq0, eq1, self.M_value() * eq2_neg - t * eq2_pos])
        return Spec(ring.quotient(ideal))