Re: syntax extension, precedence, Notation`

*To*: mathgroup at smc.vnet.net*Subject*: [mg106475] Re: syntax extension, precedence, Notation`*From*: Richard Fateman <fateman at cs.berkeley.edu>*Date*: Thu, 14 Jan 2010 05:46:36 -0500 (EST)*References*: <201001120949.EAA15726@smc.vnet.net> <hik8s7$6j4$1@smc.vnet.net>

Jaebum Jung wrote: > You might want to try Notation package. > > In[1]:= <<Notation` > In[2]:= BetterRules[x_->y_]:=x->y^2 > In[3]:= Notation[x__/! y_ \[DoubleLongLeftRightArrow] > ReplaceAll[x__,BetterRules[y_]]] > In[4]:= (x+y)/!(x->3) > Out[4]= 9+y > I tried Jaebum's suggestion , and while a useful hint, it doesn't work. 1. line 3 is not typed in but selected from a pop-up menu. 2. After doing that, the notation CAN be defined but... 3. Jaebum's example requires all 4 extra parentheses as in In[4], which I explicitly did not want. For people who know about parsing, "/!" has too high a binding power (precedence). 4. After further correspondence with Jaebum (thanks!), I found that Jaebum could not figure out how to alter the precedence of the new operator. It was clear to me that the Notations facility would be pretty useless if you could not set the precedence somehow, so I read some more. 5. I DID figure out how to alter the precedence; (I gather) it is based on the precedence of the character that begins the new operator. Thus the default precedence of the new operator "/!" is like the operator "/". We want the precedence to be more like "/.". Too bad. There may in fact be a way of altering precedence of an arbitrary new symbol, but I don't have a week to figure out the documentation and whether tags have something to do with it. Instead I picked another new operator, "=/." , since the precedence I want is lower precedence, more like = in Mathematica. (The table of operator precedence is in tutorial/OperatorInputForms) It works. Here's what happens: start by providing input that looks like Notation[x__ =/. y__ <==> ReplaceAll[x__,BetterRules[y__]]] but can't really be fully typed in .. you have to select from a palette that pops up when you do <<Notations` (In InputForm it looks like this ....) Notation`Private`myHold[ \(\*Notation`Private`makeHeldRowBoxOfBoxes[{x}, StandardForm, None] = \(/.\*Notation`Private`makeHeldRowBoxOfBoxes[{y}, StandardForm, None]\)\) ] Anyway, one can, in this case, write a+s^2+1/s^2+z =/. s^2->t and get a+t+1/t+z compare to a+s^2+1/s^2+z /. s^2->t which produces a +1/s^2+t+z, (also compare to Jaebum's solution that requires (a+s^2+1/s^2+z) /! (s^2->t) Other problems with Notations` : so far as I can tell, typing in the alleged InputForm does not do the same work as selection from the palette. While notebooks may be nice, I like to have a simple text script that can be (for example) put in email. Also, it seems that Notation` must be explicitly loaded, but perhaps there's some trick to making this happen automatically. RJF > > On 1/12/10 3:49 AM, Richard Fateman wrote: >> Is there a neat way to create a new symbol, >> say /!. so that >> >> expression /. BetterRules[rules] >> >> could be written as >> >> expression /!. rules >> >> I do not find writing something like >> >> (expression) ~BR~ (rules) >> >> to be quite adequate, especially with the extra parentheses. >> RJF >> >> >> > >

**References**:**syntax extension***From:*Richard Fateman <fateman@cs.berkeley.edu>

**trouble with a Binet in a generalized Pell recursion**

**Re: Re: Replace and ReplaceAll -- simple application**

**Re: syntax extension**

**Re: syntax extension, precedence, Notation`**