MathGroup Archive 2009

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

Search the Archive

Re: reverse the order of replacements in a list of rules

  • To: mathgroup at smc.vnet.net
  • Subject: [mg105961] Re: reverse the order of replacements in a list of rules
  • From: "Norbert P." <bertapozar at gmail.com>
  • Date: Mon, 28 Dec 2009 04:56:18 -0500 (EST)
  • References: <hh73dl$lin$1@smc.vnet.net>

On Dec 26, 11:47 pm, sean <sean_inc... at yahoo.com> wrote:
> Hello group,
>
> This is kinda related with my earlier question about lumping
> parameters. now that I have lumped my parameters, I would like to
> define a new rule that reverses the lumping. I could od it manually,
> but it just seem there should be a better way of doing it..
>
> Suppose you have the following rule for replacing parameters. (in
> lumping, I used up all the letters in alphabet and about half of
> double struck letters. So the actual rule is very long.)
>
> toyrule = {k1 k2  -> a, k3 k4 k5 -> b, k4 k6 k7 -> c, k8 k9/k10 + k11 -
>
> > d }
>
> and so on and on.
>
> What I want to accomplish is now come up with reverse rule that with
> replace the lumped parameter with primitive parameters.
>
> revtoyrule = {a -> k1 k2,  b -> k3 k4 k5 ,  c-> k4 k6 k7, d-> k8 k9/
> k10 + k11}
>
> And so on.
>
> Thanks much in advance.
>
> Sean

Hi Sean,

the best way is to use Reverse with a 2nd argument 2 to reverse
elements at level 2, as in
In[1]:= Reverse[{k1 k2->a,k3 k4 k5->b,k4 k6 k7->c,k8 k9/k10+k11->d},2]
Out[1]= {a->k1 k2,b->k3 k4 k5,c->k4 k6 k7,d->k11+(k8 k9)/k10}

You can also use Part, as in
In[2]:= {k1 k2->a,k3 k4 k5->b,k4 k6 k7->c,k8 k9/k10+k11->d}[[All,
{2,1}]]
Out[2]= {a->k1 k2,b->k3 k4 k5,c->k4 k6 k7,d->k11+(k8 k9)/k10}

Best,
Norbert


  • Prev by Date: Re: reverse the order of replacements in a list of rules
  • Next by Date: Re: Re: problem with EvenQ
  • Previous by thread: Re: reverse the order of replacements in a list of rules
  • Next by thread: Best way to do contractions (arbitrary Tables with a Sum)?