Parsing 2^-3*4 (WAS Maxima latex output)



Maxima is probably on its 2nd parser (Macsyma on its 3rd, I think).

Sometimes the implementation of stuff like 2^-3*4 is done by making a
preliminary scan over the expression to be parsed and replacing occurrences
of unary minus  and unary plus by different operators.  This is then parsed
by a "normal" parser.  

I would be perfectly comfortable with a language that does not mimic
Fortran, but requires very slightly more discipline in this respect.

  My kids learned not to say "minus 2"  but to say "negative 2"  for unary
minus.  (Not from me...) Their teacher was right in some sense, that is,
4-2  is  four minus two.
Or 4 plus negative 2.  


Since we allow unary negation, as well as unary plus then we are allowing
---2     same as -2.  4+++2  same as 6.
And x--+--y  is x+y.


The fact that these are legal Maxima statements gives me pause.

RJF

 

> -----Original Message-----
> From: maxima-bounces at math.utexas.edu [mailto:maxima-
> bounces at math.utexas.edu] On Behalf Of Robert Dodier
> Sent: Wednesday, November 01, 2006 8:44 PM
> To: Richard Fateman
> Cc: macrakis at alum.mit.edu; Maxima list
> Subject: Re: [Maxima] Parsing 2^-3*4 (WAS Maxima latex output)
> 
> On 10/25/06, Richard Fateman <fateman at cs.berkeley.edu> wrote:
> 
> > I think that it is basically a hack on the parser to allow 2 operators
> to be
> > adjacent, in each case of the unary - or unary +.  One way around this
> is to
> > forbid 2 adjacent operators, and anyone who is tempted to use this
> > construction would get an error message, and then would insert
> parentheses
> > as appropriate.
> 
> Now that, surely, is a real hack.
> 
> > This discussion happened at least two previous times between 1968 and
> 1974.
> 
> A testament to the longevity of this topic, and this project ....
> If we're lucky we'll have the same discussion in 2048 as well.
> 
> > > By the way, this business with operator precedence bears on
> > > at least one reported bug, which has to do with the value of
> > > 1/+3*2 (or something like that). At present Maxima says that
> > > is 1/6, which consistent with F77. That is a consequence of
> > > the right binding power for + , which is 100 (i.e. less than * ).
> > > We could resolve that bug by approving the current behavior,
> > > and changing rbp of - to be 100 also, for consistency. Just a thought.
> 
> I've thought twice about this, and I've decided that it would be
> less surprising to give + the same rbp as - (namely 134).
> Then 1/-3*2 => -2/3 (current behavior) and 1/+3*2 => 2/3 (new).
> After making that change, run_testsuite reports no unexpected errors.
> 
> Comments?
> 
> All the best
> Robert
> _______________________________________________
> Maxima mailing list
> Maxima at math.utexas.edu
> http://www.math.utexas.edu/mailman/listinfo/maxima