MathGroup Archive 2004

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

Search the Archive

An argument pattern problem: ranges and lists

  • To: mathgroup at smc.vnet.net
  • Subject: [mg52973] An argument pattern problem: ranges and lists
  • From: Simon Anders <simon.anders at uibk.ac.at>
  • Date: Sat, 18 Dec 2004 03:59:53 -0500 (EST)
  • Organization: University of Innsbruck, Austria
  • Sender: owner-wri-mathgroup at wolfram.com

Hi,

I am trying to use argument patterns to ensure that my function is only 
applied onto arguments which have the format
    pauli [_, _]
where the second argument should be an integer between 0 and 4.

So I defined a type
    pauliT = HoldPattern [pauli [_, s_Integer] /; s>=0 && s<=4];

and declared my function as follows:
   f [p:pauliT] := DoSomething

This works fine, but another function takes a pair of arguments
   g [p:{pauliT,pauliT}] := DoSomethingElse

This is never called, because the pattern cannot be matched.

I observed:

   pauliT = HoldPattern [pauli [_, s_Integer] /; s>=0 && s<=4];
   MatchQ[{pauli[1, 2], pauli[1, 3]}, {pauliT, pauliT}]
   --> False

The problem seems to be that I named the second argument 's', because if 
I delete this name, it matches:

   pauliT = HoldPattern [pauli [_, s_Integer]];
   MatchQ[{pauli[1, 2], pauli[1, 3]}, {pauliT, pauliT}]
   --> False

   pauliT = HoldPattern [pauli [_, _Integer]];
   MatchQ[{pauli[1, 2], pauli[1, 3]}, {pauliT, pauliT}]
   --> True

So, how do I specify the range condition correctly?

Thanks in advance,
   Simon




  • Prev by Date: Re: NIntegrate a list
  • Next by Date: Re: Mathematica slows down
  • Previous by thread: Re: Re: Differentiate of Abs[x] ???
  • Next by thread: Re: An argument pattern problem: ranges and lists