#5251: [with patch, needs review] preparser bug in parsing the backslash "solve
right" notation
--------------------+-------------------------------------------------------
 Reporter:  was     |        Owner:  mhansen 
     Type:  defect  |       Status:  assigned
 Priority:  major   |    Milestone:  sage-3.3
Component:  misc    |   Resolution:          
 Keywords:          |  
--------------------+-------------------------------------------------------
Comment (by was):

 I read the stopping condition code, and realized it is easy to make up
 many other examples that break the \ notation, even after the above patch
 is applied:
 {{{
 sage: A = matrix(QQ,2,2,[1..4])
 sage: matrix(QQ,2,1,[1/3,"2/3"])  # valid notation

 [1/3]
 [2/3]
 sage: A \ matrix(QQ,2,1,[1/3,"2/3"])
 ------------------------------------------------------------
    File "<ipython console>", line 1
      A ._backslash_(
 matrix(QQ,Integer(2),Integer(1),[Integer(1)/Integer(3),)"2/3"])
 ^
 SyntaxError: invalid syntax

 sage: A \ matrix(QQ,2,1,[1/3,'2/3'])
 ------------------------------------------------------------
    File "<ipython console>", line 1
      A ._backslash_(
 matrix(QQ,Integer(2),Integer(1),[Integer(1)/Integer(3),)'2/3'])
 ^
 SyntaxError: invalid syntax

 sage: A \ matrix(QQ,2,1,[1/3,2*3])
 ------------------------------------------------------------
    File "<ipython console>", line 1
      A ._backslash_(
 matrix(QQ,Integer(2),Integer(1),[Integer(1)/Integer(3),Integer(2))*Integer(3)])
 ^
 SyntaxError: invalid syntax
 }}}

 The point of the stopping condition is that one should be able to do,
 e.g.,
 {{{
 A \ stuff # this does something,
 }}}
 and get
 {{{
 A._backslash_(stuff)  # this does something
 }}}
 instead of
 {{{
 A._backslash_(stuff  # this does something)
 }}}
 Another example:
 {{{
 A \ B + C
 }}}
 should become
 {{{
 A._backslash_(B) + C
 }}}

 Now that is *not* correctly parsed:
 {{{
 sage: preparse('A \ B + C')
 'A ._backslash_( B + C)'
 }}}
 It should be parsed to
 {{{
 A._backslash_(B) + C
 }}}

 Here is another that isn't correctly parsed:
 {{{
 sage: preparse( 'A\eval("C+D")' )
 'A._backslash_(eval()"C+D")'
 }}}

 It should be
 {{{
 A._backslash_(eval("C+D"))
 }}}

 Finally, the / was there before because of precedence.  I.e., the
 following
 is now wrong after the patch:
 {{{
 sage: preparse('A \\ x  / 5')
 'A ._backslash_( x  / Integer(5))'
 }}}
 but we should get
 {{{
 sage: preparse('A \\ x  / 5')
 'A ._backslash_( x ) / Integer(5)'
 }}}
 since precedence of backslash should be left to right (just like that of
 /).


 ----

 Comments:

 1. I find the backslash notation -- which is from Matlab -- very useful
 and do use it all the time. Otherwise, I wouldn't have noticed the bug I
 reported in this ticket.

 2. Clearly whoever (=me, of course!) implemented this in preparser.py did
 a very bad job, and this is an extremely buggy feature with the potential
 to lead to serious confusion and wrong answers.  It's not the sort of
 thing that should be implemented without using a more sophisticated
 parsing technique.

 3. I almost think it would be better that this feature didn't exist given
 the bugs I listed above.

-- 
Ticket URL: <http://trac.sagemath.org/sage_trac/ticket/5251#comment:2>
Sage <http://sagemath.org/>
Sage - Open Source Mathematical Software: Building the Car Instead of 
Reinventing the Wheel
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sage-trac" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/sage-trac?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to