Question: Splitting a polynomial into even and odd terms

I would like to split a polynomial into even and odd terms. Has this capability been provided in a package? PolynomialTools seems the obvious choice, but doesn't do this. Here's one approach
SplitPolynomialEvenOdd := proc(poly::polynom(anything,v), v)
description "return the even and odd parts of a polynomial in v";
local p;
    p := collect(poly,v);
    if p::`+` then
        return selectremove(t -> degree(t,v)::even, p);
    elif degree(p,v)::even then
        return (p,0);
        return (0,p);
    end if;
end proc:

SplitPolynomialEvenOdd(x^2 + 3*x + 1, x);
                                  x  + 1, 3 x
Please Wait...