Function Composition

28 views
Skip to first unread message

Dan Buchoff

unread,
Dec 13, 2014, 4:13:13 PM12/13/14
to sy...@googlegroups.com
What's the right way to compose a multivariate polynomial with a unary polynomial in an argument other than the first?

A simple example is:
f = (x, y) ↦ x + y
g = y ↦ 2⋅y
f composed with g = (x, y) ↦ x + 2⋅y

I've tried substitution which doesn't seem to even give a valid polynomial (is a polynomial with expressions as generators even mathematically meaningful?):
>>> Poly("x+y").subs(S("y"),"y*2")
Poly(x + 2*y, x, 2*y, domain='ZZ')

I've also tried composition, but this seems to only compose in the first argument (and for some reason only works for polynomials):
>>> Poly("x+y").compose(Poly("y*2",S("y")))
Poly(3*y, x, y, domain='ZZ')

And evaluating on polynomial arguments:
>>> Poly("x+y")(Poly("x"),Poly("2*y"))
Poly(x, x, domain='ZZ') + Poly(2*y, y, domain='ZZ')

Aaron Meurer

unread,
Dec 13, 2014, 7:35:51 PM12/13/14
to sy...@googlegroups.com
Perhaps use as_poly to convert the multivariate polynomial into a
univariate polynomial.

Aaron Meurer
> --
> You received this message because you are subscribed to the Google Groups
> "sympy" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to sympy+un...@googlegroups.com.
> To post to this group, send email to sy...@googlegroups.com.
> Visit this group at http://groups.google.com/group/sympy.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/sympy/0b83ff7e-b2ba-4409-9e5e-bba22585b9e7%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages