@@ -445,6 +445,8 @@ def __init__(self, R):
445
445
if R .ngens () != 1 :
446
446
raise ValueError ("must be 1 generator" )
447
447
LaurentPolynomialRing_generic .__init__ (self , R )
448
+ from sage .rings .integer_ring import IntegerRing
449
+ self ._indices = IntegerRing ()
448
450
449
451
Element = LaurentPolynomial_univariate
450
452
@@ -561,6 +563,12 @@ def _element_constructor_(self, x):
561
563
562
564
return self .element_class (self , x )
563
565
566
+ def monomial (self , arg ):
567
+ r"""
568
+ Return the monomial with the given exponent.
569
+ """
570
+ return self .element_class (self , {arg : self .base_ring ().one ()})
571
+
564
572
def __reduce__ (self ):
565
573
"""
566
574
Used in pickling.
@@ -591,6 +599,9 @@ def __init__(self, R):
591
599
if not R .base_ring ().is_integral_domain ():
592
600
raise ValueError ("base ring must be an integral domain" )
593
601
LaurentPolynomialRing_generic .__init__ (self , R )
602
+ from sage .modules .free_module import FreeModule
603
+ from sage .rings .integer_ring import IntegerRing
604
+ self ._indices = FreeModule (IntegerRing (), R .ngens ())
594
605
595
606
Element = LazyImport ('sage.rings.polynomial.laurent_polynomial_mpair' , 'LaurentPolynomial_mpair' )
596
607
@@ -605,7 +616,7 @@ def _repr_(self):
605
616
"""
606
617
return "Multivariate Laurent Polynomial Ring in %s over %s" % (", " .join (self ._R .variable_names ()), self ._R .base_ring ())
607
618
608
- def monomial (self , * args ):
619
+ def monomial (self , * exponents ):
609
620
r"""
610
621
Return the monomial whose exponents are given in argument.
611
622
@@ -629,14 +640,27 @@ def monomial(self, *args):
629
640
sage: L.monomial(1, 2, 3) # needs sage.modules
630
641
Traceback (most recent call last):
631
642
...
632
- TypeError: tuple key must have same length as ngens
633
- """
634
- if len (args ) != self .ngens ():
635
- raise TypeError ("tuple key must have same length as ngens" )
643
+ TypeError: tuple key (1, 2, 3) must have same length as ngens (= 2)
644
+
645
+ We also allow to specify the exponents in a single tuple::
646
+
647
+ sage: L.monomial((-1, 2)) # needs sage.modules
648
+ x0^-1*x1^2
636
649
650
+ sage: L.monomial((-1, 2, 3)) # needs sage.modules
651
+ Traceback (most recent call last):
652
+ ...
653
+ TypeError: tuple key (-1, 2, 3) must have same length as ngens (= 2)
654
+ """
637
655
from sage .rings .polynomial .polydict import ETuple
638
- m = ETuple (args , int (self .ngens ()))
639
- return self .element_class (self , self .polynomial_ring ().one (), m )
656
+ if len (exponents ) == 1 and isinstance ((e := exponents [0 ]), (tuple , ETuple )):
657
+ exponents = e
658
+
659
+ if len (exponents ) != self .ngens ():
660
+ raise TypeError (f"tuple key { exponents } must have same length as ngens (= { self .ngens ()} )" )
661
+
662
+ m = ETuple (exponents , int (self .ngens ()))
663
+ return self .element_class (self , self .polynomial_ring ().base_ring ().one (), m )
640
664
641
665
def _element_constructor_ (self , x , mon = None ):
642
666
"""
0 commit comments