当前位置: 首页>>代码示例>>Python>>正文


Python PolynomialRing.gens方法代码示例

本文整理汇总了Python中sage.rings.polynomial.polynomial_ring_constructor.PolynomialRing.gens方法的典型用法代码示例。如果您正苦于以下问题:Python PolynomialRing.gens方法的具体用法?Python PolynomialRing.gens怎么用?Python PolynomialRing.gens使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在sage.rings.polynomial.polynomial_ring_constructor.PolynomialRing的用法示例。


在下文中一共展示了PolynomialRing.gens方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: TestMonomialsOfOrder

# 需要导入模块: from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing [as 别名]
# 或者: from sage.rings.polynomial.polynomial_ring_constructor.PolynomialRing import gens [as 别名]
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))
开发者ID:robertgoss,项目名称:Logarithmic-differential-forms,代码行数:29,代码来源:graded_module_test.py

示例2: TestConvertSymToPoly

# 需要导入模块: from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing [as 别名]
# 或者: from sage.rings.polynomial.polynomial_ring_constructor.PolynomialRing import gens [as 别名]
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)
开发者ID:robertgoss,项目名称:Logarithmic-differential-forms,代码行数:36,代码来源:logarithmic_form_test.py

示例3: TestWeightedMinDegree

# 需要导入模块: from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing [as 别名]
# 或者: from sage.rings.polynomial.polynomial_ring_constructor.PolynomialRing import gens [as 别名]
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);
开发者ID:robertgoss,项目名称:Logarithmic-differential-forms,代码行数:33,代码来源:graded_module_test.py

示例4: TestHomogeneousWieghts

# 需要导入模块: from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing [as 别名]
# 或者: from sage.rings.polynomial.polynomial_ring_constructor.PolynomialRing import gens [as 别名]
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)
开发者ID:robertgoss,项目名称:Logarithmic-differential-forms,代码行数:34,代码来源:logarithmic_forms_test.py

示例5: TestGradedModule

# 需要导入模块: from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing [as 别名]
# 或者: from sage.rings.polynomial.polynomial_ring_constructor.PolynomialRing import gens [as 别名]
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)
开发者ID:robertgoss,项目名称:Logarithmic-differential-forms,代码行数:61,代码来源:graded_module_test.py

示例6: cardinality

# 需要导入模块: from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing [as 别名]
# 或者: from sage.rings.polynomial.polynomial_ring_constructor.PolynomialRing import gens [as 别名]
    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))
开发者ID:mcognetta,项目名称:sage,代码行数:52,代码来源:derangements.py

示例7: whitney_divisor

# 需要导入模块: from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing [as 别名]
# 或者: from sage.rings.polynomial.polynomial_ring_constructor.PolynomialRing import gens [as 别名]
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
开发者ID:robertgoss,项目名称:Logarithmic-differential-forms,代码行数:9,代码来源:examples.py

示例8: automorphy_factor_vector

# 需要导入模块: from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing [as 别名]
# 或者: from sage.rings.polynomial.polynomial_ring_constructor.PolynomialRing import gens [as 别名]
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)
开发者ID:lalitkumarj,项目名称:OMSCategory,代码行数:29,代码来源:families_util+copy.py

示例9: rand_w_hom_divisor

# 需要导入模块: from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing [as 别名]
# 或者: from sage.rings.polynomial.polynomial_ring_constructor.PolynomialRing import gens [as 别名]
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
开发者ID:robertgoss,项目名称:Logarithmic-differential-forms,代码行数:30,代码来源:examples.py

示例10: braid_divisor

# 需要导入模块: from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing [as 别名]
# 或者: from sage.rings.polynomial.polynomial_ring_constructor.PolynomialRing import gens [as 别名]
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
开发者ID:robertgoss,项目名称:Logarithmic-differential-forms,代码行数:10,代码来源:examples.py

示例11: comp_prod

# 需要导入模块: from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing [as 别名]
# 或者: from sage.rings.polynomial.polynomial_ring_constructor.PolynomialRing import gens [as 别名]
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)
开发者ID:defeo,项目名称:ff_compositum,代码行数:10,代码来源:bench.py

示例12: breiskorn_pham_divisor

# 需要导入模块: from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing [as 别名]
# 或者: from sage.rings.polynomial.polynomial_ring_constructor.PolynomialRing import gens [as 别名]
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
开发者ID:robertgoss,项目名称:Logarithmic-differential-forms,代码行数:10,代码来源:examples.py

示例13: test_p_module_n_crossing

# 需要导入模块: from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing [as 别名]
# 或者: from sage.rings.polynomial.polynomial_ring_constructor.PolynomialRing import gens [as 别名]
 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)
开发者ID:robertgoss,项目名称:Logarithmic-differential-forms,代码行数:11,代码来源:logarithmic_forms_test.py

示例14: eu

# 需要导入模块: from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing [as 别名]
# 或者: from sage.rings.polynomial.polynomial_ring_constructor.PolynomialRing import gens [as 别名]
 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)))
开发者ID:MarkWatkins2014,项目名称:lmfdb,代码行数:11,代码来源:galois_reps.py

示例15: BezoutianQuadraticForm

# 需要导入模块: from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing [as 别名]
# 或者: from sage.rings.polynomial.polynomial_ring_constructor.PolynomialRing import gens [as 别名]
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
开发者ID:mcognetta,项目名称:sage,代码行数:58,代码来源:constructions.py


注:本文中的sage.rings.polynomial.polynomial_ring_constructor.PolynomialRing.gens方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。