Hi,

I'm trying to define in Mathematica (v 7.0) function such like this:

g=Function[x,Which[Mod[x,12]==0,0,Mod[x,12]==1,1,Mod[x,12]==2,2,Mod[x,12]==3,3,Mod[x,12]==4,4,Mod[x,12]==5,5,Mod[x,12]==6,6,Mod[x,12]==7,5,Mod[x,12]==8,4,Mod[x,12]==9,3,Mod[x,12]==10,2,Mod[x,12]==11,1,Head[x]==Rational,g[Round[x]]]]

And when I'm testing it, all works:

g[2/3]

1

But if I add more conditions using 'Head', as follows:

g=Function[x,Which[Mod[x,12]==0,0,Mod[x,12]==1,1,Mod[x,12]==2,2,Mod[x,12]==3,3,Mod[x,12]==4,4,Mod[x,12]==5,5,Mod[x,12]==6,6,Mod[x,12]==7,5,Mod[x,12]==8,4,Mod[x,12]==9,3,Mod[x,12]==10,2,Mod[x,12]==11,1,Head[x]==Rational,g[Round[x]], Head[x]==Power,x]]

the result for g[Sqrt[3]] is:

Which[Power==Rational,g[Round[Sqrt[3]]],Head[Sqrt[3]]==Power,Sqrt[3]]

Could someone explain me where is the error? How could I remake it?

Thanks in advance.