How to use Rules on Sequences?

• To: mathgroup at smc.vnet.net
• Subject: [mg29452] How to use Rules on Sequences?
• From: Detlef Mueller <dmueller at mathematik.uni-kassel.de>
• Date: Wed, 20 Jun 2001 04:36:31 -0400 (EDT)
• Organization: University of Kassel - Germany
• Sender: owner-wri-mathgroup at wolfram.com

```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: Simple question
• Next by Date: RE: Simple question
• Previous by thread: Re: Compositions and Relation Joins on Fuzzy Relations
• Next by thread: Re: How to use Rules on Sequences?