# how to permute bit strings and manipulate their elements

I want to write a function(has 2 paremeter, n=range,k=number of 1 digits) which finds all probable combinatorics of arbitrary bit strings and evaluate sum of tensor product and divide to sqrt(n) each elements. if you look at the example you all understand easily. and sorry for my bad english .

function[3,1]

(1\[CircleTimes]0\[CircleTimes]0)/Sqrt[3] + (0\[CircleTimes]1\
\[CircleTimes]0)/Sqrt[3] + (0\[CircleTimes]0\[CircleTimes]1)/Sqrt[3]


another example

function[4,2]

(1\[CircleTimes]1\[CircleTimes]0\[CircleTimes]0)/Sqrt[4] + (1\
\[CircleTimes]0\[CircleTimes]1\[CircleTimes]0)/Sqrt[4] + (1\
\[CircleTimes]0\[CircleTimes]0\[CircleTimes]1)/Sqrt[4] + (0\
\[CircleTimes]1\[CircleTimes]1\[CircleTimes]0)/Sqrt[4] + (0\
\[CircleTimes]1\[CircleTimes]0\[CircleTimes]1)/Sqrt[4] + (0\
\[CircleTimes]0\[CircleTimes]1\[CircleTimes]1)/Sqrt[4]

• You know how to get permutation from you previous quesiton what you should have mentioned. Now you can use for example this function circle[x_List] := 1/Sqrt[Length@x] CircleDot @@ x to map what you want. Try to use Mathematica notation here, here is no such thing as sqrt(n), also, please pay attention to the way you format your questions.
– Kuba
Sep 14, 2013 at 8:46

Using ybeltukov's function from your previous quesiton and the one I suggested in comments you can create what you need:

 f[n_, k_] := Permutations@UnitStep@Range[k-n, k-1]

circle[x_List] := 1/Sqrt[Length@x] CircleDot @@ x

function[n_, k_]:= circle /@ f[n, k] // Total


Oh, I see, I used CircleDot instead of CircleTimes. Doesn't matter in fact, let me leave it as it is :)

• @user2777109 so does it fit? I'm confused, you deleted the comment.
– Kuba
Sep 14, 2013 at 20:50
• yes,thank you. lastly, if i want to merge two functions in one.like this. f[n_, k_] := Permutations@UnitStep@Range[k-n, k-1] circle[x_List] := 1/Sqrt[Binomial[n, k]] CircleTimes @@ x function[n_, k_] := circle /@ f[n, k] // Total there is a fail about Binomial[n,k]. how can i correct it? Sep 14, 2013 at 20:53
• i would write like this f[n_, k_] := Permutations@UnitStep@Range[k - n, k - 1] circle[x_List] := 1/Sqrt[Binomial[n, k]] CircleTimes @@ x function[n_, k_] := circle /@ f[n, k] // Total and there is an error, i think it is in Binomial[n,k] Sep 14, 2013 at 21:13
• @user2777109 func[n_, k_] := Module[{perm, circle}, perm = Permutations@UnitStep@Range[k - n, k - 1]; circle[x_] := 1/Sqrt[Binomial[n, k]] CircleTimes @@ x; circle /@ perm // Total ]
– Kuba
Sep 14, 2013 at 21:24
• i really thank you very much. it was very important for me. you solved my problem Sep 14, 2013 at 21:33