Blitz logo

Blitz Support :

From: Alex Fore (agf_at_[hidden])
Date: 2003-06-07 13:15:46


I have looked through the manual, the source code, and the support
archives. That said I don't think I have seen a way to do what I would
like to.

I have a array that I would like to re-index. I see that there is a
method of doing this, but from looking at the source and manual, I get
the impression that this just makes a linear transformation on the
indices.

What I would like to do is map the indices in this fashion:

(0,1,2,3,4,5,6,7) ---> (0,2,1,3,4,6,5,7)
(0,1,2,3,4,5,6,7) ---> (0,4,1,5,2,6,3,7)

So when I refer to A(i,j) it refers to A(map(i),map(j)). I realize that
if I was doing this on an element by element basis, I could just make a
list and do exactly the above. But what I need to do is get this new
view of the data, then I know what various subarrays of this array look
like. Then I want to remap the indices back. I can't use range because
there is no simple relation between each index that is adjacent to it.

I could do this by creating a new array, and looping over columns, then
create another array and loop over rows, but I would prefer to simply
create a new view of the data, alter that, and then use the regular
view.

Thanks for any help,
-Alex

P.S. If anyone is interested in why I want to do this:

I am writing some functions to simulate quantum channels and qubits and
so forth. The array is a 2^N by 2^N matrix which represents a operator
on the N qubits. The matrix has basis vectors

|0,0,0,...,0>; |0,0,0...,1>; and so on.

If I want to make a controlled-not on the jth qubit with the ith as the
control the easiest thing to do is to permute the matrix so that the
ith qubit is the 1st qubit in the set of basis vectors and the jth is
the 2nd. this corresponds to mappig the tensor product space of

a on b on c on ... on i on .. on j on ... on n
to:
i on j on a on ... on n (skipping i and j in ...)

(where on is the tensor product operator)

  the permutations above represent permutations of 3 qubits:

(0,1,2,3,4,5,6,7) ---> (0,2,1,3,4,6,5,7) (a on b on c) ---> (a on c on
b)
(0,1,2,3,4,5,6,7) ---> (0,4,1,5,2,6,3,7) (a on b on c) ---> (b on c on
a)

Then I know what the matrix looks like, in terms of various subarrays
of the matrix.