\\ some basic examples, labeled and unlabeled \\ load the admissible constructions from lecture \r operators \\ nonzero sequences of a single element = the positive integers as an OGF Z = seq(x+O(x^11))-1; \\ partitions = multisets of integers Part = mset(Z); \\ compositions = sequences of integers Comp = seq(Z); \\ necklaces with n beads of 2 different colors. N2 = cyc(2*x + O(x^11)); \\ necklaces of total mass n with beads of 5 different colors, 2 \\ having mass 1 and 3 having mass 2. N5 = cyc(2*x + 3*x^2 + O(x^11)); \\ necklaces with n labeled beads of 2 different colors. N2l = lcyc(2*x + O(x^11)); \\ some iterative solutions to recursive constructions \\ first load a helper function to solve recursions. this applies a \\ function iteratively to a power series to find the solution to a \\ recursive specification. \r iterate \\ plane trees, defined recursively as P = X * seq(P) f = t -> x*seq(t); \\ a function defining the recursion. this tells gp that f is a function \\ taking t to x * seq(t) P = iterate(f, 10); \\ compute solution up to x^10 P = iterate(f); \\ if you omit the precision, a default value of 20 is used \\ "plane tree partitions": the composition of P with Z PTP = subst(P,x,Z); \\ abstract, unlabeled rooted trees: Tul = X * MSet(Tl) f = t -> x*mset(t); Tul = iterate(f, 20); \\ balanced 2-3 trees \\ the specification is Y = X + Y[X^2 + X^3] f = t -> x + subst(t,x,x^2+x^3); Y = iterate(f, 20); \\ labeled rooted trees \\ the specification is Tl = X * Sets(Tl) f = t -> x * lset(t); Tl = iterate(f, 10); \\ this yields the expected series \\ x + x^2 + 3/2*x^3 + 8/3*x^4 + 125/24*x^5 + 54/5*x^6 + 16807/720*x^7 + 16384/315*x^8 + 531441/4480*x^9 + O(x^10) \\ which is an EGF. to see the coefficients one can use the builtin function serlaplace \\ serlaplace(Tl) \\ returns \\ x + 2*x^2 + 9*x^3 + 64*x^4 + 625*x^5 + 7776*x^6 + 117649*x^7 + 2097152*x^8 + 43046721*x^9 + O(x^10) \\ another way ... we have the identity Tl * exp(-Tl) = x, which means \\ Tl is the series inverse to x * exp(-x). so we can use the builtin \\ gp function serreverse to do Lagrange inversion: \\ serreverse(x * exp(-x)) \\ which recovers Tl