[GAP Forum] binary arithmetic

Stephen Linton steve.linton at st-andrews.ac.uk
Fri Oct 31 09:24:36 GMT 2014


Dear GAP Forum,

On 24 Oct 2014, at 14:43, Luca Giuzzi <luca.giuzzi at gmail.com> wrote:

> Dear Forum,
> I have been working with some elements defined over a large finite
> field (K=GF(2^20), actually) and I have a few questions.
> 
> 1) does there exist a "proper" way to obtain a vector representation
> (any representation is fine) for elements of K over the ground field?
> I have successfully used the idiom x![1] for x in K, but I suspect
> that this is more of an implementation detail than what is supposed to
> be used.


The “proper" way is to make a basis of the field (considered as a vector space) and
then ask for the coefficients of an element with respect to this basis:

gap> k := GF(2,20);
GF(2^20)
gap> z := Random(k);
1+z+z2+z4+z5+z6+z7+z8+z11+z14+z15+z16+z17+z18
gap> b := Basis(k);
CanonicalBasis( GF(2^20) )
gap> Coefficients(b,z);
<an immutable GF2 vector of length 20>
gap> 



> 
> 2) In any case ended up working with sets of vectors of GF(2)^20. I
> would have liked to be able to represent each vector as an integer
> (this is easy) and to implement the sum of any two of them as a xor
> between their representatives. I have not been able to find a xor
> operation being exposed (not even in the cvec package). Am I missing
> something?
> [actually, I ended up writing an external program to perform the
> checks I was interested in]

The addition operation for compressed vectors over GF(2) reduces to bitwise xor behind 
the scenes, although there will still be some overhead associated with method selection, 
dereferencing the objects to find the bits to xor, etc.

Adding bitwise operations for integers has been on our wish list for a while, though. I also notice that there is 
no xor operation for Blists (lists of Booleans, represented as bit lists) which seems like an oversight.

	Steve


> 
> With many thanks and kind regards,
> lg
> 
> _______________________________________________
> Forum mailing list
> Forum at mail.gap-system.org
> http://mail.gap-system.org/mailman/listinfo/forum




More information about the Forum mailing list