MathGroup Archive 2004

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

Search the Archive

Re: conditionnal rule


myList={{a,b},{c,d}};

myList/.{a_,x_?(!(Head[#]===List)&)}->{a,d}

{{a, d}, {c, d}}

myList/.{a_,x_?(Head[#]==Symbol&)}->{a,d}

{{a, d}, {c, d}}

myList/.{a_,x_?AtomQ}->{a,d}

{{a, d}, {c, d}}

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

{{a, d}, {c, d}}


Bob Hanlon

> 
> From: darkness_wizard at hotmail.com (Wishmaster7)
To: mathgroup at smc.vnet.net
> Date: 2004/10/20 Wed AM 01:21:19 EDT
> To: mathgroup at smc.vnet.net
> Subject: [mg51521] [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)
> 
> 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 ?
> 
> 


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