This function interprets the provided expression as general rational expression, i.e. a fraction of two multivariate polynomials, and returns the set of generalized variables required for this interpretation. It does not apply any expansion during this process; would you expand it first using
variables would return the simple variables
y for both expressions.
(2*x + 3*y)/(z + 4) is a fully expanded simple rational expression, so
Rational.variables would return
Rational.expand would not have any effect.
On the other hand,
1/x + 1/y is only a rational expression if you interpret it as
(a + b)/1 where
Rational.variables returns the two generalized variables
Rational.expand would transform it into
(x + y)/(x*y), which is an equivalent simple rational expression.
Let’s have a look at your second expression,
(3/x^2 + 5*x)*(2*x+7)/(3*y-5). The polynomial in the denominator is fully expanded, but the numerator is essentially a product of two expressions. This can therefore be interpreted as a multivariate rational expression only as
a:=3/x^2 + 5*x,
c:=y. And indeed, this is exactly what is returned by
The first expression
(3/x^2 + 5*x)*(2*x+7)/(3*y-5) + 6*x/(4*y) as is does not have a denominator except
1, so the whole expression has to be interpreted as the multivariate polynomial numerator. Note that a division
a/b can be considered as product
a*(1/b). This way, we can rewrite the expression (again without applying any expansion) as
(3/x^2 + 5*x) * (2*x + 7) * 1/(3*y-5) + 6/4 * x * 1/y. And therefore
Rational.variables returns exactly these variable terms as generalized variables, as you printed in the question.
Does that make any sense?