MathGroup Archive 2004

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

Search the Archive

Re: conditionnal rule

  • To: mathgroup at smc.vnet.net
  • Subject: [mg51527] Re: [mg51499] conditionnal rule
  • From: "Wolf, Hartmut" <Hartmut.Wolf at t-systems.com>
  • Date: Thu, 21 Oct 2004 22:20:42 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com


>-----Original Message-----
>From: Wishmaster7 [mailto:darkness_wizard at hotmail.com]
To: mathgroup at smc.vnet.net
>Sent: Wednesday, October 20, 2004 7:21 AM
>To: mathgroup at smc.vnet.net
>Subject: [mg51527] [mg51499] conditionnal rule
>
>
>hi all !!
>
>I want to apply a rule under a certain condition. here is the 
>example : 
>
>myList = {{a, b}, {c, d}};
>
>myList //. {a,x_}->{a,d}
>
>apply this rule if Length[x]===1 (this means that x can not be a list)
>
Doesn't! Means any expression of length one.


>I tried something like : 
>
>myList //. {a_,x_}->{c,d}/;Length[x]===1
>
>or
>
>myList //. {a_,x_?Length[x]===1}->{c,d}/
>
>but it does not work.
>
>can someone help me ?
>
>

Such

myList //. {a, x_} :> {a, d}
---> {{a, d}, {c, d}}

myList //. {a, x_} :> {a, d} /; Length[x] === 0
---> {{a, d}, {c, d}}

myList //. {a, x_} /; Length[x] === 0 :> {a, d} 
---> {{a, d}, {c, d}}

myList //. {a, x_ /; Length[x] === 0} :> {a, d} 
---> {{a, d}, {c, d}}

myList //. {a, x_?(Length[#] === 0 &)} :> {a, d} 
---> {{a, d}, {c, d}}


Of course AtomQ[x] would be a better way to express Length[x] === 0.  But did you mean that?

--
Hartmut Wolf


  • Prev by Date: Re: conditionnal rule
  • Next by Date: Re: Extrapolation in mathematica
  • Previous by thread: Re: conditionnal rule
  • Next by thread: Formatting numbers for output