Integer representation for Finite field

717 views
Skip to first unread message

mahm....@gmail.com

unread,
Mar 22, 2017, 5:26:36 PM3/22/17
to sage-support
In my program , I am gonna be feeding integers as arguments from command line to a sage script that deals with finite fields.
I need to convert these ints to their corresponding finite field representation.
for example, 
in a GF(2^8) : int(3) => a+1 in GF

I read the manual and I found this method of Givaro fields implementation
integer_representation(
it does  the opposite 
for example 
sage: k(a+1).integer_representation()
3
it seems that sage is aware about mapping GF to int representation, 
so is there a way to execute my request ?

Nils Bruin

unread,
Mar 22, 2017, 5:53:14 PM3/22/17
to sage-support

sage: k([ZZ(u) for u in reversed(list(6.binary()))])
a^2 + a

mahm....@gmail.com

unread,
Mar 22, 2017, 6:19:14 PM3/22/17
to sage-support
Oh , didn't know this piece of info.
This thing took me time more than it would have if I implemented it myself, and I was intending to xD 
What I get from your answer is that if I put binary list inside k it returns the field.
sage: k([0,1,1])  # where most significant bit is on the right
a^2 + a

thank you very much, I most probably would have never known this by my own, didn't see it any where in the docs.
May be I just don't look good enough

Nils Bruin

unread,
Mar 22, 2017, 6:58:47 PM3/22/17
to sage-support
It's a reasonable thing to try if you think of elements in k as represented by polynomials in a. A polynomial in sage can be constructed by calling the polynomial ring with the list of coefficients. It's sort-of documented in GF(2^8)._element_constructor:

   Free module elements over "prime_subfield()" are interpreted
   'little endian':

      sage: k = GF(2**8, 'a')
      sage: e = k.vector_space().gen(1); e
      (0, 1, 0, 0, 0, 0, 0, 0)
      sage: k(e)
      a

but as you can see the constructor is a bit more liberal than just that. It's "discoverable" in the sense that it's reasonable to hope that it works once you know how sage works, but it doesn't seem to be documented literally.

As to the fact that you need to look at the binary representation: Both integers and polynomials over GF(2) are naturally represented as bitstrings. The indentification of these is what underlies Givaro's "integer_representation".
Reply all
Reply to author
Forward
0 new messages