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: Clarification re. Curiosity concerning transformation rules for List

  • To: mathgroup at smc.vnet.net
  • Subject: [mg70981] Re: Clarification re. Curiosity concerning transformation rules for List
  • From: dh <dh at metrohm.ch>
  • Date: Fri, 3 Nov 2006 01:39:34 -0500 (EST)
  • References: <eicn7e$fts$1@smc.vnet.net>

Hi Andrew,
although I can not completely solve your problem, a partial solution 
seems possible.
You could define UpValues for the data type(s) you are working with. 
E.g. assume you are working with Real numbers:
Unprotect[Real];
Real /:{x_Real,x_Real}={};
now when you say: {1.,1.} you get {}, but {1.,2.} yields {1.,2.}
Daniel


Andrew Moylan wrote:
> I recently 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?
> ----
> 
> I received some replies suggesting that I use my proposed rule
> {x_,x_}->{} in combination with ReplaceAll to effect the transformation
> on a case-by-case basis. However, I am interested in whether it is
> possible to add a _definition_ so that the rule is _always_ applied.
> 
> I think I can clarify by way of an example:
> 
> Unprotect[Power];
> Power[x_, x_] = 0;
> 
> Now 4^3 evaluates to 64 as usual, but 4^4 evaluates to 0. However, the
> following fails because List has attribute Locked (as well as attribute
> Protected):
> 
> Unprotect[List];
> 
> This doesn't mean that transformation rules involving lists cannot ever
> be defined. We can use UpValues. For example:
> 
> AppendTo[UpValues[hello], {hello, x_} -> 0]
> 
> Now pairs with the symbol hello as their first element evaluate to
> zero: {hello, 1} evaluates to 0. But other lists are not affected: {1,
> 2} evaluates to {1, 2}.
> 
> However, the only way it was possible to add that definition was by
> attaching it as an UpValue for hello. Since there are no symbols in the
> rule {x_,x_}->{} (except List, which is locked), is it possible to make
> this definition? Is there a "global" set of transformation rules,
> always applied, but not attached to any particular symbol?
> 
> I hope this is clearer, instead of less clear ;-).
> 
> Cheers,
> 
> Andrew
> 


  • Prev by Date: Re: Context
  • Next by Date: Re: RE: Context headache
  • Previous by thread: Re: Clarification re. Curiosity concerning transformation rules for List
  • Next by thread: find roots