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