Is there a way to get the homogeneous part of certain degree of a (multivariate) polynomial?
Every multivariate polynomial $f\in\Bbb F[x_1,\ldots,x_n]$ of degree $d$ can be written as $f = f_0+f_1+\cdots+f_d$, where $f_i$ is a homogeneous polynomial of degree $i$. Is there a direct way to get each $f_i$ given $f$ in SageMath? For a specific application I have where I only need $f_d$ I am homogenizing and then setting $h=0$, and based on this I wrote an ugly script that recursively finds $f_i$.
Is there a cleaner (and more efficient) way to do this?
Thanks for the help!
EDIT:
This is the code I'm using to obtain $f_d$ from $f$
fd = R( f.homogenize()(h=0) )
where R is the multivariate polynomial ring (parent of $f$). If I want $f_{d-1}$ for example, I can define $g$ as $f - f_d$ and apply the line to $g$. This recursive definition is not satisfactory since to get $f_i$ I need to have all $f_{i+1},\ldots,f_d$ first, which is inefficient. Also, that trick of homogenizing, evaluating $h=0$ and coercing the result back to the original polynomial ring is not very neat.
Hint: if you provide your code, the collective wisdom of Ask Sage answerers may help improve it!
@slelievre Ok! I'm new in this forum, thanks for pointing that out! I've edited my answer, hopefully that helps :)