Mathematica 9 is now available
Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2008

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

Search the Archive

Fwd: substitution within a substitution list

  • To: mathgroup at smc.vnet.net
  • Subject: [mg88581] Fwd: [mg88551] substitution within a substitution list
  • From: Christopher Carlson <carlson at wolfram.com>
  • Date: Fri, 9 May 2008 03:23:21 -0400 (EDT)
  • References: <E1C692A6-A5D7-407C-9030-9167D7F709C2@wolfram.com>

Begin forwarded message:

> From: Christopher Carlson <carlson at wolfram.com>
> Date: May 8, 2008 11:03:37 AM CDT
> To: mathgroup at smc.vnet.net
> Cc: Bipin <bipin.caz at googlemail.com>
> Subject: Re: [mg88551] substitution within a substitution list
>
> On May 8, 2008, at 3:13 AM, Bipin wrote:
>> HI,
>>
>> I'm trying to find a way of changing the substitution values within a
>> substitution list.
>>
>> For example, if I have the following substitution list:-
>>
>> subs = {a->1, b->2, c->2}
>>
>> I want to programmatically replace the value associated with 'b' from
>> 2 to 20, ie ending up with
>>
>> subs = {a->1, b->20, c->2}
>>
>> Does anyone know of a mathematica function for doing this?
>>
>> Bipin.
>
>
> You can use
>
> 	subs /. HoldPattern[b -> _] :> (b -> 20)
>
> or even something like
>
> 	subs /. HoldPattern[b -> x_] :> (b -> 10 x)
>
> Christopher Carlson
> User Interface Group
> Wolfram Research, Inc.

HoldPattern is not necessary here.  These suffice:

	subs /. (b -> _) -> (b -> 20)

	subs /. (b -> x_) :> (b -> 10 x)

Christopher Carlson
User Interface Group
Wolfram Research, Inc.


  • Prev by Date: Re: substitution within a substitution list
  • Next by Date: Solving Large Overdetermined Systems
  • Previous by thread: Re: substitution within a substitution list
  • Next by thread: Re: substitution within a substitution list