@@ -1562,6 +1562,62 @@ def dict(self):
1562
1562
"""
1563
1563
return self .lift ().dict ()
1564
1564
1565
+ def __call__ (self , * values , ** kwargs ):
1566
+ r"""
1567
+ Evaluate the reduced expression of this element at ``x``, where ``x``
1568
+ is either the tuple of values to evaluate in, a dictionary indicating
1569
+ to which value is each generator evaluated, or keywords giving
1570
+ the value to which generators should be evaluated.
1571
+
1572
+ INPUT:
1573
+
1574
+ - ``values`` -- (optional) either a tuple or a dictionary
1575
+
1576
+ OUTPUT:
1577
+
1578
+ this element evaluated in the given values
1579
+
1580
+ EXAMPLES::
1581
+
1582
+ sage: A.<x,y,z,t> = GradedCommutativeAlgebra(QQ, degrees=(1, 2, 2, 3))
1583
+ sage: f = x*y - 5*y*z + 7*x*y^2*z^3*t
1584
+ sage: f(3, y, x^2, x*z)
1585
+ 3*y
1586
+ sage: f(x=3)
1587
+ 21*y^2*z^3*t - 5*y*z + 3*y
1588
+ sage: f({x:3, z:x^2})
1589
+ 3*y
1590
+
1591
+ If the wrong number of values is provided, it results in an error::
1592
+
1593
+ sage: f(3, 5, y)
1594
+ Traceback (most recent call last):
1595
+ ...
1596
+ ValueError: number of arguments does not match number of variables in parent
1597
+
1598
+ """
1599
+ gens = self .parent ().gens ()
1600
+ if len (values ) == 1 and isinstance (values [0 ], dict ):
1601
+ images = list (gens )
1602
+ for (i , g ) in enumerate (gens ):
1603
+ if g in values [0 ].keys ():
1604
+ images [i ] = values [0 ][g ]
1605
+ elif len (values ) == len (gens ):
1606
+ images = list (values )
1607
+ elif values :
1608
+ raise ValueError ("number of arguments does not match number of variables in parent" )
1609
+ else :
1610
+ images = list (gens )
1611
+ for (i , g ) in enumerate (gens ):
1612
+ gstr = str (g )
1613
+ if gstr in kwargs .keys ():
1614
+ images [i ] = kwargs [gstr ]
1615
+ res = 0
1616
+ for (m , c ) in self .dict ().items ():
1617
+ term = prod ([gen ** y for (y , gen ) in zip (m , images )], c )
1618
+ res += term
1619
+ return res
1620
+
1565
1621
def basis_coefficients (self , total = False ):
1566
1622
"""
1567
1623
Return the coefficients of this homogeneous element with
0 commit comments