58
58
returns non-negative integers, then ``c^P`` means to apply ``P`` to
59
59
the variable indices occurring in ``c``.
60
60
61
- If you want to substitute variables more generally, use the ``.subs``
62
- method::
61
+ If you want to substitute variables you can use the standard polynomial
62
+ methods, such as
63
+ :meth:`~sage.rings.polynomial.infinite_polynomial_element.InfinitePolynomial_sparse.subs`::
63
64
64
65
sage: R.<x,y> = InfinitePolynomialRing(QQ)
65
66
sage: f = x[1] + x[1]*x[2]*x[3]
@@ -450,25 +451,30 @@ def __getattr__(self, s):
450
451
451
452
def subs (self , fixed = None , ** kwargs ):
452
453
"""
453
- Substitute variables in an infinite polynomial .
454
+ Substitute variables in ``self`` .
454
455
455
456
INPUT:
456
457
457
- - ``fixed`` - (optional) dict with variable:value pairs
458
- - ``**kwargs`` - names parameters
458
+ - ``fixed`` -- (optional) `` dict`` with ``{ variable:value}`` pairs
459
+ - ``**kwargs`` -- named parameters
459
460
460
461
OUTPUT:
461
- a new polynomial
462
+
463
+ the resulting substitution
462
464
463
465
EXAMPLES::
464
466
465
467
sage: R.<x,y> = InfinitePolynomialRing(QQ)
466
468
sage: f = x[1] + x[1]*x[2]*x[3]
467
469
468
- Passing ``fixed={x[1]: x[0]}``. Note that the keys::
470
+ Passing ``fixed={x[1]: x[0]}``. Note that the keys may be given
471
+ using the ``.__getitem__`` method of the infinite polynomial
472
+ generator ``x_*`` or as a string::
469
473
470
474
sage: f.subs({x[1]: x[0]})
471
475
x_3*x_2*x_0 + x_0
476
+ sage: f.subs({'x_1': x[0]})
477
+ x_3*x_2*x_0 + x_0
472
478
473
479
Passing the variables as names parameters::
474
480
@@ -484,9 +490,7 @@ def subs(self, fixed=None, **kwargs):
484
490
sage: g.subs({y[0]: x[0]})
485
491
x_1 + x_0
486
492
487
- The substitution can also handle matrices. It will
488
- return a matrix whose entries are polynomials in countably
489
- many variables::
493
+ The substitution can also handle matrices::
490
494
491
495
sage: M = matrix([[1,0],[0,2]])
492
496
sage: N = matrix([[0,3],[4,0]])
@@ -498,16 +502,17 @@ def subs(self, fixed=None, **kwargs):
498
502
[ 1 9]
499
503
[12 4]
500
504
501
- You can only pass one of ``fixed`` or ``kwargs`` at a time::
505
+ If you pass both ``fixed`` and ``kwargs``, any conflicts
506
+ will defer to ``fixed``::
502
507
503
- sage: g.subs(fixed={x[0]: M}, x_1=N )
504
- Traceback (most recent call last):
505
- ...
506
- ValueError: pass only one of fixed or kwargs
507
- sage: g .subs({x[0]: M}, x_1=N )
508
- Traceback (most recent call last):
509
- ...
510
- ValueError: pass only one of fixed or kwargs
508
+ sage: R.<x,y> = InfinitePolynomialRing(QQ )
509
+ sage: f = x[0]
510
+ sage: f.subs({x[0]:1})
511
+ 1
512
+ sage: f .subs(x_0=5 )
513
+ 5
514
+ sage: f.subs({x[0]:1}, x_0=5)
515
+ 1
511
516
512
517
TESTS::
513
518
@@ -519,9 +524,7 @@ def subs(self, fixed=None, **kwargs):
519
524
if fixed :
520
525
if not isinstance (fixed , dict ):
521
526
raise ValueError ('fixed must be a dict' )
522
- if kwargs :
523
- raise ValueError ('pass only one of fixed or kwargs' )
524
- kwargs = fixed
527
+ kwargs .update (fixed )
525
528
try :
526
529
return self (** kwargs )
527
530
except TypeError :
0 commit comments