Evaluate a list

Hi,

Suppose for example E =[x,x^2,x+1] is a list of elements in ZZ[x]. Let K be a number field defined in Sage

K.<a> = NumberField(f(x))


for some irreducible polynomial $f(x)$. Then how can one evaluate the list E by setting $x=a$ and $x=\sigma(a)$ (conjugate of a) in Sage?

edit retag close merge delete

Sort by » oldest newest most voted

You can use the subs method of polynomials:

sage: x = polygen(ZZ)
sage: K.<a>= NumberField(x^2+1)
sage: (x^2).subs(x=a)
-1


Now, if you want to apply it to all elements of a list E, you can use Python's list comprehension:

sage: [p.subs(x=a) for p in E]
[a, -1, a + 1]


Or, for the conjugate:

sage: [p.subs(x=a.conjugate()) for p in E]
[-a, -1, -a + 1]


Note that in the univariate case, you can directly call the polynomial:

sage: (x^2)(a)
-1
sage: [p(a) for p in E]
[a, -1, a + 1]
sage: [p(a.conjugate()) for p in E]
[-a, -1, -a + 1]

more

Thanks very much, T,monteil. You save me the day!

( 2016-02-11 22:35:01 +0200 )edit

Stats

Seen: 703 times

Last updated: Feb 11 '16