Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

[tl:dr] The Symbolic Ring is not able to represent expressions such as (2/3) * (t - y) and directly uses associativity to "simplify" such an expression.[/tl;dr]

Another answer to your question, which is complementary to the other one. Since your expression is a polynomial with rational coefficients, the factorization is done using Singular. The code for this can be seen using E.factor?? and the part of interest is

f = self.polynomial(QQ)
w = repr(f.factor())
return symbolic_expression_from_string(w)

where self is the expression you want to factor (here self is E, that is 2/3 * t - 2/3 * y. At the first line, f gets the expression as a polynomial over QQ, and at the second line this polynomial f is factored, and w gets the string representation of the polynomial. If you try this by hand you get:

sage: f = (2/3*t - 2/3*y).polynomial(QQ)
sage: f.factor()
(2/3) * (t - y)
sage: repr(_) # underscore represents the last result
'(2/3) * (t - y)'

So you get the string representation of what you want. Now the third line converts the string back to a symbolic expression, and you can verify that you obtain the same result as with E.factor(), which is not what you want:

sage: from sage.calculus.calculus import symbolic_expression_from_string
sage: symbolic_expression_from_string('(2/3) * (t - y)')
2/3*t - 2/3*y

OK, so now what is the difficulty? The problem is that symbolic expressions automatically make some "simplifications" to the expressions you enter. Compare:

sage: (y - t) * (y + 2)
-(t - y)*(y + 2)
sage: (y - t) * (3 + 2)
-5*t + 5*y

As you can see, the integer sums are directly "reduced", associativity is used as soon as one operand of a multiplication is an integer (or a rational number, etc.). The current implementation of symbolic expressions is thus unable to represent the factorization you want. I am not able to dig in the code for symbolic expressions, so I cannot explain why some simplifications are performed and other are not. Yet, note that one aim of the Symbolic Ring is to present the results as the user would probably like to see them. Of course, this is ill-defined and results in problems like the one you are experiencing. As a rule of thumb, you should try to avoid the Symbolic Ring as much as possible, and work with more specialized rings as often as you can.