Open tornaria opened 1 year ago
I am not sure how good of a practice it is to base such decisions on certain doctests. This could cause problems for expressions that are 0 but otherwise look very complicated, e.g.,
sage: sin(x)^2 + cos(x)^2 - 1
cos(x)^2 + sin(x)^2 - 1
Yet I agree the result will be the same.
I am not sure if we can guarantee the result will be in SR
, but there is an is_trivial_zero()
that we could use. It won't deal with things that are 0
but expressed in a complicated way. We could safeguard this by checking that the parent of the left-hand side is SR
though. This will have nearly all of the speed of avoiding complicated SR
checks (although Maxima should be faster at this) but also avoid things that are trivially 0
.
Is there an existing issue for this?
Did you read the documentation and troubleshoot guide?
Environment
Steps To Reproduce
Expected Behavior
It takes less than 10ms.
Actual Behavior
It takes more than 50s.
Additional Information
This line
is run for several symbolic expressions taking a significant time (up to ~ 2s for some expressions).
On one hand, this test is repeated several times for the same expression. If each expression is tested only once the total time goes from ~54s down to ~12s.
On the other hand, this is still slow: if this test is removed the total time goes down to ~ 5ms.
Here's a proof of concept:
With this in place:
If I understand the code, removing the test will still give a correct answer, maybe including some subexpressions that vanish. An alternative would be to simplify at the end, which takes < 2s in this case, although it doesn't seem to change anything.
@tscrim you are the last person to touch this code, or else you may be able to point out who knows about it. If it were up to me, I'd just remove the check for zero. In any other case, the test has to be marked
# long time
of course.