wxMaxima-developers / wxmaxima

A gui for the computer algebra system Maxima built with wxWidgets
https://wxMaxima-developers.github.io/wxmaxima/
Other
467 stars 96 forks source link

The sum() inserts extra parentheses #1536

Open tigran123 opened 3 years ago

tigran123 commented 3 years ago

Maxima normally displays the sum on the terminal like this:

$ rmaxima
Maxima 5.44.0 http://maxima.sourceforge.net
using Lisp SBCL 2.1.2
Distributed under the GNU Public License. See the file COPYING.
Dedicated to the memory of William Schelter.
The function bug_report() provides bug reporting information.
(%i1) 'sum(k,k,1,n)=ev(sum(k,k,1,n),simpsum,factor);
                               n
                              ====
                              \         n (n + 1)
(%o1)                          >    k = ---------
                              /             2
                              ====
                              k = 1

However, wxMaxima inserts parentheses around k above, i.e. shows (k) inside the sum sign, instead of just k.

gunterkoenigsmann commented 3 years ago

The reason why I introduced that parenthesis was that in an output like

     sum k + L

I never found a good way to visually discern if the L is part of the sum or if it is added to the result of the sum.

tigran123 commented 3 years ago

Yes, I understand that. But if you check Maxima on Android 3.2.1 it does this intelligently, i.e. for things like sum(k,k,1,n) it shows no parenthesis, but for sum(k+k^2,k,1,n) it puts them around the expression. Can't you implement the same logic in wxMaxima somehow?

robert-dodier commented 1 week ago

For what it's worth, the right way to handle parentheses is probably to assign RBP and LBP properties (right binding power and left binding power, i.e. operator precedence) for sum. On first glance, I'm guessing the binding power (not sure if left or right) for sum needs to be lower than for =.

I see that Maxima itself doesn't display the above expression with any parentheses. Maybe Maxima needs them too -- I don't know right now.

gunterkoenigsmann commented 1 week ago

WxMaxima assigns it's own binding powers to some symbols which I believe to be dangerous as of Maxima changes it's binding powers that might cause consistency problems.