Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

This is because 1 is an Integer, not a polynomial or a symbolic expression:

sage: var("y")
y
sage: B = [1, x, y, x*y+3*y*2]
sage: 
sage: for term in B:
....:         print term, 'has parent', parent(term)
....: 
1 has parent Integer Ring
x has parent Symbolic Ring
y has parent Symbolic Ring
x*y + 6*y has parent Symbolic Ring

In Sage, you often coerce objects which live in one location into another (viewing "1" as a complex number, for example) by calling the parent. In this case, we can convert 1 by calling SR:

sage: parent(1)
Integer Ring
sage: SR(1)
1
sage: parent(SR(1))
Symbolic Ring

So in this case:

sage: for p in B:
....:         print p, SR(p).coefficients(x)
....: 
1 [[1, 0]]
x [[1, 1]]
y [[y, 0]]
x*y + 6*y [[6*y, 0], [y, 1]]

This is using the symbolic ring. There are more fundamental polynomial objects (type "PolynomalRing?" to look at some examples), but this should suffice here.

This is because 1 is an Integer, not a polynomial or a symbolic expression:

sage: var("y")
y
sage: B = [1, x, y, x*y+3*y*2]
sage: 
sage: for term in B:
....:         print term, 'has parent', parent(term)
....: 
1 has parent Integer Ring
x has parent Symbolic Ring
y has parent Symbolic Ring
x*y + 6*y has parent Symbolic Ring

In Sage, you often coerce objects which live in one location into another (viewing "1" as a complex number, for example) by calling the parent. In this case, we can convert 1 by calling SR:

sage: parent(1)
Integer Ring
sage: SR(1)
1
sage: parent(SR(1))
Symbolic Ring

So in this case:

sage: for p in B:
....:         print p, SR(p).coefficients(x)
....: 
1 [[1, 0]]
x [[1, 1]]
y [[y, 0]]
x*y + 6*y [[6*y, 0], [y, 1]]

This is using the symbolic ring. There are more fundamental polynomial objects (type "PolynomalRing?" "PolynomialRing?" to look at some examples), but this should suffice here.