Taking some terms from a polynomial
You can use Jens's method from this answer:
expr[x_, y_] := 1 - x/2 - x^2/8 - x^3/16 + y/2 + (3 x y)/4 + (23 x^2 y)/16 + (27 x^3 y)/32 -
y^2/8 - (31 x y^2)/16 - (127 x^2 y^2)/64 - (351 x^3 y^2)/128 + y^3/16 +
(35 x y^3)/32 + (407 x^2 y^3)/128 + (1915 x^3 y^3)/256
expr2[x_, y_] = Normal[Series[expr[x t, y t], {t, 0, 4}]] /. t -> 1
(* 1 + 1/2 (-x + y) + 1/8 (-x^2 + 6 x y - y^2) + 1/16 (-x^3 + 23 x^2 y - 31 x y^2 + y^3) +
1/64 (54 x^3 y - 127 x^2 y^2 + 70 x y^3) *)
To obtain the OP's result
List @@ Expand[expr2[x, y]]
(* {1, -(x/2), -(x^2/8), -(x^3/16), y/2, (3 x y)/4, (23 x^2 y)/16, (
27 x^3 y)/32, -(y^2/8), -((31 x y^2)/16), -(127/64) x^2 y^2, y^3/16, (
35 x y^3)/32} *)
Sort @ Select[Exponent[# /. y -> x, x] < 5 &] @ MonomialList[ser]
TeXForm @ %
$\left\{1,-\frac{x}{2},-\frac{x^2}{8},-\frac{x^3}{16},\frac{y}{2},\frac{3 x y}{4},\frac{23 x^2 y}{16},\frac{27 x^3 y}{32},-\frac{y^2}{8},-\frac{31 x y^2}{16},-\frac{127}{64} x^2 y^2,\frac{y^3}{16},\frac{35 x y^3}{32}\right\}$
You can use CoefficientList
and select necessary items in the matrix:
ser =
1 - x/2 - x^2/8 - x^3/16 +
y/2 + (3 x y)/4 + (23 x^2 y)/16 + (27 x^3 y)/32 -
y^2/8 - (31 x y^2)/16 - (127 x^2 y^2)/64 - (351 x^3 y^2)/128 +
y^3/16 + (35 x y^3)/32 + (407 x^2 y^3)/128 + (1915 x^3 y^3)/256;
PolynomialQ[ser, x]
(* True *)
coef = CoefficientList[ser, {x, y}]
(* {{1, 1/2, -(1/8), 1/16}, {-(1/2), 3/4, -(31/16), 35/
32}, {-(1/8), 23/16, -(127/64), 407/128}, {-(1/16), 27/
32, -(351/128), 1915/256}} *)
List of necessary coefficients:
selectedCoef = Reverse@LowerTriangularize[Reverse@coef, 1]
(* {{1, 1/2, -(1/8), 1/16}, {-(1/2), 3/4, -(31/16), 35/
32}, {-(1/8), 23/16, -(127/64), 0}, {-(1/16), 27/32, 0, 0}} *)
Now you can build polynomial from this coefficients:
coefList = Expand@Fold[FromDigits[Reverse[#1], #2] &, selectedCoef, {x, y}]
(* 1 - x/2 - x^2/8 - x^3/16 + y/2 + (3 x y)/4 + (
23 x^2 y)/16 + (27 x^3 y)/32 - y^2/8 - (31 x y^2)/16 - (
127 x^2 y^2)/64 + y^3/16 + (35 x y^3)/32 *)
To get the result in form of list:
Sort@MonomialList[coefList]
(* {1, -(x/2), -(x^2/8), -(x^3/16), y/2, (3 x y)/4, (
23 x^2 y)/16, (
27 x^3 y)/32, -(y^2/8), -((31 x y^2)/
16), -(127/64) x^2 y^2, y^3/16, (35 x y^3)/32} *)