rtoy / maxima

A Clone of Maxima's repo
Other
0 stars 0 forks source link

Inefficient resimplification with dosimp set to T #577

Closed rtoy closed 3 months ago

rtoy commented 3 months ago

Imported from SourceForge on 2024-07-03 01:59:51 Created by tomasriker on 2016-12-01 03:06:49 Original: https://sourceforge.net/p/maxima/bugs/3255


Resimplification of an expression happens at quite some places within Maxima. It is currently implemented as follows: A global flag dosimp is set to T, then simplifya is called. When dosimp is T, simplifya ignores the 'simp tag at the beginning of the internal representation of an expression and simplifies it anyway. This is problematic because the advantage of the 'simp tag cannot be used during resimplification. It may happen that the same subexpression is simplified multiple times. An extreme example can easily be constructed where normal simplification finishes instantly and resimplification takes several seconds:

m1(x) := false$
m2(x) := false$
m3(x) := false$
m4(x) := false$
m5(x) := false$
matchdeclare(M1, m1)$
matchdeclare(M2, m2)$
matchdeclare(M3, m3)$
matchdeclare(M4, m4)$
matchdeclare(M5, m5)$
tellsimp(F(M1), 42)$
tellsimp(F(M2), 43)$
tellsimp(F(M3), 44)$
tellsimp(F(M4), 45)$
tellsimp(F(M5), 46)$

/* Normal simplification finishes instantly: */
showtime : true$
F(F(F(F(F(F(F(F(x))))))))$

/* Resimplification takes several seconds: */
?resimplify(%)$

Tracing the rule functions shows that during resimplification, they are called many times for the same subexpression. This is because the dosimp flag is set to T, and therefore already simplified subexpressions are treated as unsimplified.

Proposed fix: When simplifya sees that dosimp is set to T, it should remove all 'simp tags from the entire expression, then set dosimp to nil and continue simplifying normally. This way, intermediate simplified subexpressions don't have to be resimplified.

rtoy commented 3 months ago

Imported from SourceForge on 2024-07-03 01:59:52 Created by tomasriker on 2016-12-02 03:43:00 Original: https://sourceforge.net/p/maxima/bugs/3255/#bc92


Fixed by commit [0e4ed4].

rtoy commented 3 months ago

Imported from SourceForge on 2024-07-03 01:59:56 Created by tomasriker on 2016-12-02 03:43:16 Original: https://sourceforge.net/p/maxima/bugs/3255/#8ac1