MathGroup Archive 2006

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

Search the Archive

Re: Condition in replacement rule

  • To: mathgroup at smc.vnet.net
  • Subject: [mg67781] Re: Condition in replacement rule
  • From: Bill Rowe <readnewsciv at earthlink.net>
  • Date: Fri, 7 Jul 2006 07:13:07 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

On 7/6/06 at 6:52 AM, wandering.the.cosmos at gmail.com wrote:

>I have a replacement rule that goes like

>A[V,W_] -> A[V,W] + B[W]

>but I want to perform this replacement if and only if V and W are
>not the same. It seems

>A[V,W_/;W!=V] -> A[V,W] + B[W]

>does not seem to work. How should I do this?

Using RuleDelayed the following should work

A[V_,W_]:>If[W != V, A[V,W]+B[W], A[V,W]]

Checking to confirm

In[2]:=
A[1, 2] /. A[V_, W_] :> If[W != V, A[V, W] + B[W], 
    A[V, W]]

Out[2]=
A[1, 2] + B[2]

In[3]:=
A[1, 1] /. A[V_, W_] :> If[W != V, A[V, W] + B[W], 
    A[V, W]]

Out[3]=
A[1, 1]
--
To reply via email subtract one hundred and four


  • Prev by Date: RE: Subscript for a variable
  • Next by Date: RE:Simplest question: How to control some values in Input dialog box
  • Previous by thread: Condition in replacement rule
  • Next by thread: Re: Condition in replacement rule