MathGroup Archive 2004

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

Search the Archive

Re: conditionnal rule

  • To: mathgroup at
  • Subject: [mg51536] Re: conditionnal rule
  • From: Curt Fischer <crf3 at>
  • Date: Thu, 21 Oct 2004 22:21:01 -0400 (EDT)
  • References: <cl4t4i$8ee$>
  • Sender: owner-wri-mathgroup at

Wishmaster7 wrote:
> 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)

Here is one solution to your present example.  You will also want to 
investigate the Condition operator /; and the pattern test operator ?. 
Note that in Mathematica, a list can have length one, or zero, so your 
Length criterion is not the same as testing whether something is a list 
or not.


ListQ[expr] gives True if expr is a list, and False otherwise.


!expr is the logical NOT function. It gives False if expr is \
True, and True if it is False.



myRule={a,x_?(Not[ListQ[#]]&)}\[Rule] {a,d}




> 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: Extrapolation in mathematica
  • Next by Date: Re: conditionnal rule
  • Previous by thread: Re: conditionnal rule
  • Next by thread: Re: conditionnal rule