0

I am using the CAS SAGE. I have a vector v belonging GF(2). How I will be able to find the integer representation of this vector? Any example please?

 aux = random_matrix(GF(2), n,2*n)
 for i in range(2*n):
     x = ZZ(list(aux[:,i]), base=2)
Juan
  • 2,073
  • 3
  • 22
  • 37

1 Answers1

3

Assuming I understand you, you have a vector living in a space over GF(2):

sage: V = VectorSpace(GF(2), 5)
sage: V
Vector space of dimension 5 over Finite Field of size 2
sage: v = V.random_element()
sage: v
(0, 1, 0, 1, 1)

There are lots of ways to convert this to an Integer, and lots of equally valid representations. One natural one would be:

sage: i = ZZ(list(v), base=2)
sage: i
26
sage: parent(i)
Integer Ring
sage: i.digits(2)
[0, 1, 0, 1, 1]
DSM
  • 342,061
  • 65
  • 592
  • 494
  • I cann't get this. I edit my question with my code. The error is TypeError: unable to coerce to an integer – Juan Jul 02 '13 at 16:08
  • 1
    @Juan: by using `aux[:,i]`, you're getting a columnar matrix, not a vector. `print type(aux[:,i])` to convince yourself this is true. So `list(aux[:,i])` is producing something like `[(0), (1), (1), (1), (0)]` instead of what you want. IOW, you're one level too high up; you need a list of elements of GF(2), not a list of collections. Try something like `ZZ(list((aux[:,i].T)[0]), 2)`. – DSM Jul 02 '13 at 16:17
  • 1
    @Juan: `.T` is simply an abbreviation for `transpose`. – DSM Jul 02 '13 at 16:46
  • thanks, and for make the inverse. Let be a "i" a integer How I will be able to get a columnar matrix? – Juan Jul 02 '13 at 16:49