Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2006
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2006

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Curiosity concerning transformation rules for List

  • To: mathgroup at smc.vnet.net
  • Subject: [mg70963] Re: Curiosity concerning transformation rules for List
  • From: "Andrew Moylan" <andrew.j.moylan at gmail.com>
  • Date: Fri, 3 Nov 2006 01:39:08 -0500 (EST)
  • References: <ei4ktg$dbf$1@smc.vnet.net><eicnb9$fvk$1@smc.vnet.net>

A couple of notes.

I think this:
  > In[ ]:=  {x_, x_} := 0
is not going to work for another reason, namely, SetDelayed is
overloaded for Lists to allow statements like
  {one, two} = {1, 2};

I guess by the very definition of the Locked attribute, I can accept
that no DownValues (or UpValues) are permitted for the List symbol.

The heart of my question is: Since Mathematica _does_ generally allow
definitions involving List (albeit with those definitions not attached
to the List symbol), is it possible to make definitions that involve
List and zero other symbols?

 Andrew


Philipp wrote:
> 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?


  • Prev by Date: Re: Conceptual Issues with NonlinearRegress[]
  • Next by Date: Re: Clarification re. Curiosity concerning transformation rules for List
  • Previous by thread: Re: Curiosity concerning transformation rules for List
  • Next by thread: message question