On Sep 8, 3:52 pm, andrew ewart <[email protected]> wrote:
> supose i have an input list (which is a list of unknown size) and
> where each term is a polynomial of form f(x,y)
> i want to define a function moniclist(list)
> such that the output makes each term of list monic wrt x
> eg
> if list=[2*x, x^2*y^2+x+1, 4*x^2+y^2+3]
> output would be[x, x^2+x+1, x^2+y^2+3]
I find the operation you are describing slightly disconcerting, but
(1)
[g+(1-g.coefficient(x^g.degree(x)))*x^g.degree(x) for g in list]
does the trick.
slightly faster:
(2)
def mon(g):
m = x^g.degree(x)
return g+(1-g.coefficient(m))*m
[mon(g) for g in list]
or as one-liner which annoyingly is slower than (2):
(3)
[(lambda m=x^g.degree(x): g+(1-g.coefficient(m))*m)() for g in list]
[Python could really use a syntax for variables locally scoped to an
expression]
Are you sure you just want to forget the coefficient of the highest
power of x, though? It sounds like a very strange operation.
--
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/sage-support
URL: http://www.sagemath.org