Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Questions about how frac, numer, denom flags work with expand #19560

Open
sylee957 opened this issue Jun 15, 2020 · 0 comments
Open

Questions about how frac, numer, denom flags work with expand #19560

sylee957 opened this issue Jun 15, 2020 · 0 comments
Labels

Comments

@sylee957
Copy link
Member

sylee957 commented Jun 15, 2020

I have investigated how frac, numer, denom flags are defined to work for polynomial expressions.

>>> from sympy import *
>>> w, x, y, z = symbols('w x y z')
>>> a, b, c, d = symbols('a b c d')
>>> expr = (a + b)*(c + d)/(w + x)/(y + z)
>>> expr.expand(frac=False, numer=False, denom=False)
a*c/(w*y + w*z + x*y + x*z) + a*d/(w*y + w*z + x*y + x*z) + b*c/(w*y + w*z + x*y + x*z) + b*d/(w*y + w*z + x*y + x*z)
>>> expr.expand(frac=True, numer=False, denom=False)
(a*c + a*d + b*c + b*d)/(w*y + w*z + x*y + x*z)
>>> expr.expand(frac=False, numer=True, denom=False)
(a*c + a*d + b*c + b*d)/((w + x)*(y + z))
>>> expr.expand(frac=False, numer=False, denom=True)
(a + b)*(c + d)/(w*y + w*z + x*y + x*z)

But I also notice that things are not working consistently if the expression is not a single rational expression, but an addition of rational expressions.

>>> expr = (a + b)/(w + x)/(y + z) + (c + d)/(w + x)/(y + z)
>>> expr.expand(frac=False, numer=False, denom=False)
a/(w*y + w*z + x*y + x*z) + b/(w*y + w*z + x*y + x*z) + c/(w*y + w*z + x*y + x*z) + d/(w*y + w*z + x*y + x*z)
>>> expr.expand(frac=True, numer=False, denom=False)
a/(w*y + w*z + x*y + x*z) + b/(w*y + w*z + x*y + x*z) + c/(w*y + w*z + x*y + x*z) + d/(w*y + w*z + x*y + x*z)
>>> expr.expand(frac=False, numer=True, denom=False)
a/(w*y + w*z + x*y + x*z) + b/(w*y + w*z + x*y + x*z) + c/(w*y + w*z + x*y + x*z) + d/(w*y + w*z + x*y + x*z)
>>> expr.expand(frac=False, numer=False, denom=True)
(a + b)/((w + x)*(y + z)) + (c + d)/((w + x)*(y + z))

Because 1,2,3 results are actually expanding the denominator even if denom=False, and fourth result is not expanding the denominator even if denom=True

And I wonder the above results are issue and should be handled like

// expand with denom=True
(a + b)/(w + x)/(y + z) + (c + d)/(w + x)/(y + z) => 
(a + b)/(w*y + w*z + x*y + x*z) + (c + d)/(w + x)/(w*y + w*z + x*y + x*z)

// expand with numer=True
(a + b)*(c + d)/(w + x) + (e + f)*(g + h)/(w + x) => 
(a*c + a*d + b*c + b*d)/(w + x) + (e*g + e*h + f*g + f*h)/(w + x)

// expand with frac=True
(a + b)*(c + d)/(w + x)/(y + z) + (e + f)*(g + h)/(w + x)/(y + z) => 
(a*c + a*d + b*c + b*d)/(w*y + w*z + x*y + x*z) + (e*g + e*h + f*g + f*h)/(w*y + w*z + x*y + x*z)
@sylee957 sylee957 added the core label Jun 15, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant