MathGroup Archive 2001

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

Search the Archive

Re: How to use Rules on Sequences?

  • To: mathgroup at
  • Subject: [mg29510] Re: How to use Rules on Sequences?
  • From: Detlef Mueller <dmueller at>
  • Date: Sat, 23 Jun 2001 01:46:52 -0400 (EDT)
  • Organization: University of Kassel - Germany
  • References: <9gs2m5$k3u$>
  • Sender: owner-wri-mathgroup at

BobHanlon at wrote:

Thanks to you, Jens, Orestis and the others!

> a=2;
> L = {{1,m1},{2,1},{3,m3}, {4,m4}};
> % /. {a, m_} :> {a, m-1} /. {x___, {a, 0}, y___} :> {x, y}
> {{1, m1}, {3, m3}, {4, m4}}
Mh, an answer, making one regret to have asked :) ,
quiet simple and natural.

> The inverse is then
> L == ((Last /@
>           Split[Sort[Append[%, {a, 0}]], #2[[1]]===#1[[1]]&]) /. {a,
>           m_} :> {a, m+1})
This one is more tricky. 

I should translate it for I want to write my text readable for
folks with a native Language different from Mathematica :)

{a, 0} is appended, Sort moves it to the right place (great, 
that Sort works this way).

Then the last Elements of the "Runs" are extractet via Mapping, 
using that{a, 0} is less than any apearing {a,i}.

Yes, i think, i understood.

I should mention, that the List in Question are normaly
very short, say two up to five elements (then I am kind
of mind-blocked, because i.e. Sorting looks like overkill
to me).

> True
> Emil[1,2,3,2,0,a,b,c] //.
>   Emil[s___, x_, y_?Positive, x_, e___] :> Emil[s, x, 0, x, e]
> Emil[1, 2, 0, 0, 0, a, b, c]

This works fine for Emil :)
I hat an Idea to have a rule not using any 
But I see, this simply cannot happen in 
So my Problem that x_, y_?Positive, x_ :> SUBST
isn't syntactically correct, has no Importance,
{x__[y___, a_, z___] ->x[y,SUBST,z]} suffices, 
because "everything is a Function".

Thanks, again

 Detlef Mueller

  • Prev by Date: RE: Originality
  • Next by Date: Re: Mathematica and Powerpoint
  • Previous by thread: Re: How to use Rules on Sequences?
  • Next by thread: FW: How to use Rules on Sequences?