sympy function compose - bizzare results

Viewed 29

I'm trying to compose two functions and I get a bizzare result '''

#!/usr/bin/python
from sympy import *
init_printing(use_unicode=True)
x= symbols('x')
f = x/(x+1);
g = x/(x+2);
print(compose(f,g))

This shows : x/((x + 1)*(x + 2))

Should be x/(2x+2)

I don't get it. Does anyone has an idea?

Thanks

1 Answers

Despite being available in the top-level sympy namespace under the plain name compose, sympy.compose doesn't actually do general function composition.

sympy.compose is actually sympy.polys.polytools.compose. It's actually a function for polynomial composition. When you try to compose x/(x+1) and x/(x+2), it ends up interpreting these inputs as multivariate polynomials in 3 variables, x, 1/(x+1), and 1/(x+2), and the results are total nonsense.

Related