Polys work marvelously. They are speedy, cover a vast domain of polynomials, can take in functions like cos(x), 1/x as generators. So, Polys are extended easy to domains which are not exactly polynomial mathematically. Sympy is sympy much thanks to polys. But it is not complete.
Due to the vast powers that the Expr/Poly class has provided us with, large expressions are easy to form and common in calculations, resulting in expression blowup. Factorizing a matrix with simple elements like x, x+1, x**2 in it give factor matrices with very large expressions, all of which, when simplified give simple and small expressions. It is evident that sympy lacks somewhere.
What is lacks is expressions under division. The polys are smart enough to handle addition, subtraction and division, but for division, it doesn’t use any of its computation power. Thus the fundamental for operations are not complete in the true sense.
Many algorithms, especially linear algebra, assume that the elements it is operating on belong to a field, that is division is possible. Sympy expr’s will perform brilliantly if division is made clean.
In : a Out: x In : a=(a+1)**-1 In : a Out: 1 ───── x + 1 In : a=(a+1)**-1 In : a Out: 1 ───────── 1 1 + ───── x + 1 In : a=(a+1)**-1 In : a Out: 1 ───────────── 1 1 + ───────── 1 1 + ───── x + 1 In : a=(a+1)**-1 In : a Out: 1 ───────────────── 1 1 + ───────────── 1 1 + ───────── 1 1 + ───── x + 1 In : a=(a+1)**-1 In : a Out: 1 ───────────────────── 1 1 + ───────────────── 1 1 + ───────────── 1 1 + ───────── 1 1 + ───── x + 1 In : a.simplify() Out: 3⋅x + 5 ─────── 5⋅x + 8
The big expression on 23 simplified to the simplest Rational Function. Why wasn’t it simplified automatically ?
According to me, a should be simplified automatically, the very first time in Out. Out should be
x + 1 ───── x + 2
This would be easy with a Frac class.
The reason why I’m pitching so much for a Frac class is because, when I knew that sympy polys can take in cos(x), 1/x as gens, I knew that if we implement the Frac class, almost all of symbolic needs are done for. The fundamental four operators, +,-,*,/ will be implemented in the true sense in sympy. Of course things like sqrt will still not be supported by the Frac class, but it is often to see things like
⎽⎽⎽ ╲╱ x + x ───────── 3/2 x + 1
which can be treated as a Frac with generator x**1/2.
Sympy will be able to operate on common expressions like
4⋅sin(x) + 5⋅cos(x) + 4 ───────────────────────── 11⋅sin(x) + 2⋅cos(x) + 12
Currently, if the above expression is a, then
In : (a+1)**-1 Out: 1 ───────────────────────────── 4⋅sin(x) + 5⋅cos(x) + 4 ───────────────────────── + 1 11⋅sin(x) + 2⋅cos(x) + 12
which is just sad.
Hence, IMHO, the Frac class would be a great step forward for sympy, and would be a great asset of sympy.