At 21:40 +0100 3/25/08, TSa wrote: >Doug McNutt wrote: >>Don't allow it ( = - f($x); )to become >> >>= f(-$x); ## wrong! > >Unless of course f does Linear, then you can factor out or in the >multiplication with -1 at will. So linearity of operators and >functions is a very interesting property for optimizers.

## Advertising

Well. . . I was going to let it pass but I had trouble sleeping this morning because of it. f($x) = constant + $x would certainly be considered a linear function with constant derivative but for that definition -f($x) is not the same as f(-$x). I think the appropriate term is antisymmetric to indicate -f(x) = f(-x). Examples would be sin(x), pow(x,3), 1/x, x**3. What worried me in the night is a comment in the Camel book that says the ** operator has a higher precedence than the unary minus with the clear implication, unfortunately true, that other languages declare the opposite. If that structure will persist into perl 6 there is a real danger that new postfix operators that are being talked about, multiplicative or additive inversion for example, may well need to be declared either symmetric or antisymmetric to keep an ambitious parser or optimizer under control. What is really needed is a more careful detection of the unary minus. In chalkboard algebra there is no such thing as a unary minus in an equation. A leading minus, one that follows an = sign or a left parenthesis, is interpreted as an implied subtraction from zero or perhaps an implied multiplication by negative unity. The unary minus only shows up in things like a list of numbers, the components of a vector (-1,2,-3) or numeric values arriving over a teletype link.. I think, but can't prove, that the discrepancy began with compiler compilers - yacc - where GUI programmers - Excel - saw an easy way to put formulas on a video tube. All they had to do was provide operator definitions and precedence rules. One possibility is to decide that unary minus does not exist in a replacement expression. Perform a "clear and subtract" assembly instruction. That would not matter for a common programming technique that defines a constant $negpi = -3.1416; instead of a real unary minus using *NEGPI = \-3.1416; or use constant NEGPI => -3.1416;. It's needs some updating but <http://macnauchtan.com/pub/precedence.html> is still on the net. The statements: = - f($x) - g($x); = - g($x) - f($x); should always return the same result regardless of whether f or g is implemented as a function, a method, or a postfix operator; and that should be true even if the - operator is overloaded. -- --> If you are presented a number as a percentage, and you do not clearly understand the numerator and the denominator involved, you are surely being lied to. <--