Re: Curiosity concerning transformation rules for List

*To*: mathgroup at smc.vnet.net*Subject*: [mg70949] Re: Curiosity concerning transformation rules for List*From*: "Philipp" <Philipp.M.O at gmail.com>*Date*: Thu, 2 Nov 2006 06:48:19 -0500 (EST)*References*: <ei4ktg$dbf$1@smc.vnet.net>

This a very interesting question. I don't have an answer for it. I THINK IT DESERVES AN ANSWER FROM THE MATHEMATICA CREW. To restate your problem, you want to know how to assign DownValue to a Locked symbol such as List[...] function/operator ? In your example the assignments would be In[ ]:= List /: List[x_, x_] := 0 or equivalently, In[ ]:= {x_, x_} := 0 which, if successful, should result in In[ ]:= {a, a} {{a, b, c}, {a, b, c}} {a, a, a} Out[ ]= 0 0 {a, a, a} In[ ]:= Information["List"] {e1, e2, ... } is a list of elements. {x_, x_} := 0 Attributes[List] = {Locked, Protected} In[ ]:= DownValues[List] Out[ ]= {{x_, x_} :> 0} The above overloading of List is conceptually analogous to overloading Plus as in the following example; In[1]:= Unprotect[Plus]; Clear[Plus]; Plus /: Plus[x_, x_] := 0 (* or, x_ + x_ := 0 *) Protect[Plus]; In[5]:= v = 5; In[6]:= v + v In[7]:= Pi + Pi In[8]:= h[v] + h[v] Out[6]= 10 Out[7]= 0 Out[8]= 0 In[9]:= Information["Plus"] "x + y + z represents a sum of terms." Attributes[Plus] = {Flat, Listable, NumericFunction, OneIdentity, Orderless, Protected} x_ + x_ := 0 Default[Plus] := 0 In[10]:= DownValues[Plus] Out[10]= {HoldPattern[x_ + x_] :> 0} I hope we will get an answer. Cheers, Philipp P.S. Notice that v + v (Out[6]) still evaluates as if Plus wasn't overloaded. This is due to the fact that Plus transformation rules regarding NumberQ[] entities are alwa Andrew Moylan wrote: > Since the List symbol is locked, I am curious about the possibility (or > otherwise) of giving definitions for which the left-hand-side of the > transformation rule contains only the List symbol. Here's an arbitrary, > explicit example: > > Is it possible to make a definition such that: any list of two > identical elements evaluates to the empty list? E.g. {x_, x_} -> {}. > > I can't see any way this transformation rule can be added. It's not > possible to modify the DownValues for List; and there are no > first-level symbols to which an UpValue can be added. Does anyone have > any ideas?