Message Boards Message Boards

0
|
6979 Views
|
2 Replies
|
0 Total Likes
View groups...
Share
Share this post:

Precedence for Undefined Operator

Posted 9 years ago

Is it possible to assign a Precedence for an operator that has no defined meaning? Here is an example. I am using CircleTimes and LeftRightArrow. I rather like LeftRightArrow because it represents a symmetrical product and rather looks like that. But I would like to have LeftRightArrow have a higher precedence than CircleTimes.

Attributes[LeftRightArrow] = {Orderless};

The following uses the Tilde notation and (somewhat surprisingly) gives what I want. However I don't want to use the heavier Tilde notation.

LeftRightArrow[w,x] ~ LeftRightArrow ~ LeftRightArrow[y,z] ~ CircleTimes ~ s

Rather, I would be entering the expression using a palette so the expression would look like this:

(v\[LeftRightArrow]u)\[LeftRightArrow](t\[LeftRightArrow]s)\[CircleTimes]a

And that uses the higher precedence of CircleTImes. I know I could add an extra set of parentheses but I would prefer to have a simple way to assign the precedence to LeftRightArrow. (When I tried to use PrecedenceForm, my PasteButton didn't work correctly.)

The entire matter of user definition of precedence seems to be ill designed and extremely poorly documented. For operators that have no built in definition it should be allowable and easy to assign a Precedence - perhaps as an Attribute.

2 Replies

Thanks Bruce. I did submit the suggestion and Wolfram Support replied that they had submitted a formal suggestions report for the developers.

If there are others that think Mathematica could use a more unified and better documented method of defining precedence for operators without built-in meaning it might be helpful to chime in and give some support.

My suggestion was as follows:

I would like to suggest that WRI improve its usage and documentation of operator precedence, and specifically with regard to infix operators that have no build-in meaning. It would also be nice to have a wider choice of such operators.

My motivation for this is that I’m working with John Browne with his Grassmann Algebra application and trying to extend it to a Grassmann Calculus application that includes general tensor operations. I can use CircleTimes for a general tensor product, Wedge for the antisymmetric exterior products and I need an infix operator for symmetrical products. I would like to use LeftRightArrow because it looks like and seems to imply symmetrical interchange. However it has lower precedence than CircleTimes and thus would require manual insertion of precedence. I will reluctantly use instead UpArrow, which has a better precedence.

The handling of Precedence seems to be somewhat scattered, disparate and poorly documented.

For example: 1) Precedence gives the precedence of an operator but there is no usage message for it and no Function page. 2) It is very difficult to find the tutorial/OperatorInputForms page. The PrecedenceForm page does not give a link to it, nor does it give a link to the Precedence command. The OperatorInputForms page does not give the actual precedence numbers nor does it include all the operators without built-in meaning. 3) SyntaxForm seems to be another method of specifying precedence in some constructions such as InterpretationBox. However, it is not fully integrated into Mathematica and is extremely poorly documented as to how one would use it to specify precedence. Frankly, I would just as soon see it junked in favor of a unified precedence system.

Perhaps there is more to the use of precedence in Mathematica than I am aware. Nevertheless, it would be nice if there were a uniform system based on the precedence number, Precedence[operator]. Something like Precedence[LeftRightArrow] = 575.1 say. But only allowed to affect a set of operators without a built-in meaning. (This should be based on a set of absolutely protected precedencies with others allowed to be changed.)

It would also be very useful if there was a larger set of undefined operator symbols, such as in MathML for example.

Better yet, it would be nice if one could construct operator symbols (say in an InterpretationBox) using StyleBox and other Box constructions. I use MakeBoxes constructions quite frequently without too much difficulty. However, I find the documentation for MakeExpression, especially as an inverse to MakeBoxes, quite skimpy and difficult to follow.

It is also important to me that I can use these infix operators in PasteButtons and patterns.

I suggest that a better facility for introducing operators with precedence would be quite useful to users, and especially to mathematicians, who certainly are great at inventing notations that are difficult to anticipate.

Finally, it is sometimes suggested to use the Notation package for this. I have spent many days trying to understand the usage of that package. I find it far too difficult to use and I think ill-designed. I certainly wouldn’t like to load it as part of my application. Although I might agree if you’re really an expert at the Notation package you can do some useful things, I would much prefer to write my own MakeBoxes and MakeExpression routines and proceed down that path. That seems to merge better into the rest of Mathematica.

I have not tried it myself, but supposedly it can be done with the Notations package. See
http://reference.wolfram.com/language/Notation/tutorial/ComplexPatternsAndAdvancedFeatures.html

(This demonstrates your complaint that it is not easy.)

I did not find an existing formal suggestion on this. Please feel free to send one via http://www.wolfram.com/support/contact/email/?topic=Technical . The clearer and more specific the suggestion, the more likely to get developer interest.

POSTED BY: Bruce Miller
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract