I believe that all of these expressions are equivalent but ideally expr.cancel.factor() and expr.factor() would give the same result. In other words factor should make cancel redundant and both should be able to eliminate any cancelable demoninators. The fact that factor does not remove the denominator is because the numerator and denominator are not being factored over the same field. Otherwise an**2 + 1 in the denominator would factor:
After fixing gh-26497 I find the following for the OP example:
I believe that all of these expressions are equivalent but ideally
expr.cancel.factor()
andexpr.factor()
would give the same result. In other wordsfactor
should makecancel
redundant and both should be able to eliminate any cancelable demoninators. The fact that factor does not remove the denominator is because the numerator and denominator are not being factored over the same field. Otherwisean**2 + 1
in the denominator would factor:This is also a bug although much less serious.
Reproducer: