Re: How to use Rules on Sequences?

• To: mathgroup at smc.vnet.net
• Subject: [mg29478] Re: How to use Rules on Sequences?
• From: "Orestis Vantzos" <atelesforos at hotmail.com>
• Date: Thu, 21 Jun 2001 01:56:52 -0400 (EDT)
• Organization: National Technical University of Athens, Greece
• References: <9gpo0n\$hd8\$1@smc.vnet.net>
• Sender: owner-wri-mathgroup at wolfram.com

```Say you want to replace the pattern x_y_ with x+y...then you use the rule
{L___,x_y_,R___}:>{L, x+y, R}probably repeatedly:
myList//.{L___,x_y_,R___}:>{L, x+y, R}
I am not sure if this the most efficient method, but it is how you would do
it with patterns.
Orestis

"Detlef Mueller" <dmueller at mathematik.uni-kassel.de> wrote in message
news:9gpo0n\$hd8\$1 at smc.vnet.net...
> Hello,
>
> I am faced to the following Problem:
>
> given a List of Pairs of the Form
>
> L = {{a1,m1},{a2,m2}, ... ,{ai,mi}}
>
> and a Number a, I want to replace the Pair
> {a, mj}, if it appears in the List by
> {a, mj-1}.
>
> This Job is done by
> L /. {{a,_m}->{a,m-1}}.
>
> Now I want to remove an Item of the Form
> {a,0} entirely from The List.
>
> Can this be done by applying rules (without
> leaving Null-Entrys), or is "Select" the only
> Way?
> (By the way: L is sorted with respect to the first Elements
> of the Sublists, this first elements are unic identifiers.
> Another Question is to replace an {a,_m} in L by {a,m+1},
> if it exists or else insert {a,1} in the propper
> Place - the inverse Operation of the above desribed
> one. Suerly not difficult to realize - but what might
> be the most efficient Method?)
>
> More general, I wonder, how to replace
> a Pattern in a Sequence - for example to change
> every occurence of "x_, y_?positive, x_" in a Sequence
> by "x,0,x".
>
> Say
>
> Emil[1,2,3,2,0,a,b,c]/.R ---> (Replacing ... 2,3,2 ... )
> Emil[1,2,0,2,0,a,b,c]/.R ---> (Replacing ... 0,2,0 ... )
> Emil[1,2,0,0,0,a,b,c]/.R      (No more changes).
>
> I Fail to write down a syntactically correct rule R to
> do this Job.
>
> Greetings
>   Detlef Mueller
>
>

```

• Prev by Date: Re: How to use Rules on Sequences?
• Next by Date: Re: Re: Reentrant Functions
• Previous by thread: Re: How to use Rules on Sequences?
• Next by thread: Re: How to use Rules on Sequences?