0
|
4667 Views
|
|
2 Total Likes
View groups...
Share
GROUPS:

# Pattern matching in self defined functions

Posted 11 years ago
 myCHcc[K_Integer] := Module[{CH}, CH = Drop[Tuples[{0, 1}, K], 1]]myCHcc[4.4]myCHccOLD[K_Integer] := Table[IntegerDigits[n, 2, K], {n, 1, 2^K - 1}];myCHccOLD[4.4]Hi all,??am reading the core languagehttp://www.wolfram.com/learningcenter/tutorialcollection/where there is an example on page 80.In the above code, myCHccOLD[4.4]is alright. butmyCHccOLD[4.4]runs into error. I expect the same out like myCHccOLD[4.4]What's the difference? I understand tha the two functions creat the same desired outputs. I am asking the differences between the pattern matching on the inputs.And further,myCHcc[K_ /; K > 2 ] := Module[{CH}, CH = Drop[Tuples[{0, 1}, K], 1]]myCHccOLD[K_ /; K > 2 ] :=   Table[IntegerDigits[n, 2, K], {n, 1, 2^K - 1}];And usingmyCHcc[K_ /; K > 2 ] := Module[{CH}, CH = Drop[Tuples[{0, 1}, K], 1]]myCHccOLD[K_ /; K > 2 ] :=   Table[IntegerDigits[n, 2, K], {n, 1, 2^K - 1}];myCHcc[1]myCHccOLD[1]does not give memyCHcc[1]myCHccOLD[1]as the patern does not match the rule of K>2How do I make sure that the input is an Interger also great 2 at the same time?myCHcc[K_Integer /; K > 2 ] := Module[{CH}, CH = Drop[Tuples[{0, 1}, K], 1]]Does not do that?