Skip to content

Commit 2e2c4f2

Browse files
committed
Merge branch 'u/tkarn/inf-poly-subs-34581' of https://github.com/sagemath/sagetrac-mirror into u/tscrim/key_polynomials-34414
2 parents 710cfbb + a56e345 commit 2e2c4f2

File tree

1 file changed

+25
-22
lines changed

1 file changed

+25
-22
lines changed

src/sage/rings/polynomial/infinite_polynomial_element.py

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,9 @@
5858
returns non-negative integers, then ``c^P`` means to apply ``P`` to
5959
the variable indices occurring in ``c``.
6060
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`::
6364
6465
sage: R.<x,y> = InfinitePolynomialRing(QQ)
6566
sage: f = x[1] + x[1]*x[2]*x[3]
@@ -450,25 +451,30 @@ def __getattr__(self, s):
450451

451452
def subs(self, fixed=None, **kwargs):
452453
"""
453-
Substitute variables in an infinite polynomial.
454+
Substitute variables in ``self``.
454455
455456
INPUT:
456457
457-
- ``fixed`` - (optional) dict with variable:value pairs
458-
- ``**kwargs`` - names parameters
458+
- ``fixed`` -- (optional) ``dict`` with ``{variable:value}`` pairs
459+
- ``**kwargs`` -- named parameters
459460
460461
OUTPUT:
461-
a new polynomial
462+
463+
the resulting substitution
462464
463465
EXAMPLES::
464466
465467
sage: R.<x,y> = InfinitePolynomialRing(QQ)
466468
sage: f = x[1] + x[1]*x[2]*x[3]
467469
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 generators of the infinite polynomial ring
472+
or as a string::
469473
470474
sage: f.subs({x[1]: x[0]})
471475
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
472478
473479
Passing the variables as names parameters::
474480
@@ -484,9 +490,7 @@ def subs(self, fixed=None, **kwargs):
484490
sage: g.subs({y[0]: x[0]})
485491
x_1 + x_0
486492
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::
490494
491495
sage: M = matrix([[1,0],[0,2]])
492496
sage: N = matrix([[0,3],[4,0]])
@@ -498,16 +502,17 @@ def subs(self, fixed=None, **kwargs):
498502
[ 1 9]
499503
[12 4]
500504
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``::
502507
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
511516
512517
TESTS::
513518
@@ -519,9 +524,7 @@ def subs(self, fixed=None, **kwargs):
519524
if fixed:
520525
if not isinstance(fixed, dict):
521526
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)
525528
try:
526529
return self(**kwargs)
527530
except TypeError:

0 commit comments

Comments
 (0)