Loading [MathJax]/jax/output/HTML-CSS/jax.js
Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

To apply a transformation to all coefficients, use map_coefficients.

For example, say we want to add two to each coefficient.

The function xx+2 is denoted in Python by lambda x: x + 2.

sage: K.<x_00, x_10, x_01, x_11> = QQ []
sage: g = K.random_element()
sage: g
7/18*x_00*x_01 + 51*x_00*x_11 - 126*x_01*x_11 - x_10
sage: g.map_coefficients(lambda x: x + 2)
43/18*x_00*x_01 + 53*x_00*x_11 - 124*x_01*x_11 + x_10

In this case, 7/18 became 43/18, 51 became 53, -126 became -124, and -1 became +1.

click to hide/show revision 2
No.2 Revision

Apply a map to all coefficients of a polynomial

To apply a transformation map to all coefficients, coefficients of a polynomial, use map_coefficients.

For example, say we want to add two to each coefficient.

The function xx+2 is denoted in Python by lambda x: x + 2.

sage: K.<x_00, x_10, x_01, x_11> = QQ []
sage: g = K.random_element()
sage: g
7/18*x_00*x_01 + 51*x_00*x_11 - 126*x_01*x_11 - x_10
sage: g.map_coefficients(lambda x: x + 2)
43/18*x_00*x_01 + 53*x_00*x_11 - 124*x_01*x_11 + x_10

In this case, 7/18 became 43/18, 51 became 53, -126 became -124, and -1 became +1.

Note that this works around the question.

Accessing monomial xij for given i and j

For this, use string formatting. For instance:

sage: i = 0
sage: j = 1
sage: K(f'x_{i}{j}')
x_01