Immutable HammingCode?

29 views
Skip to first unread message

Gerli Viikmaa

unread,
May 12, 2014, 11:12:19 AM5/12/14
to sage-s...@googlegroups.com
Hi,

Consider the following code (the field is arbitrary in this case)
sage: code = codes.HammingCode(2, GF(4,'a'))

The codewords (vectors) cannot be changed (note the absence of an error):
sage: code[0]
(0, 0, 0, 0, 0)
sage
: code[0][0] = 1
sage
: code[0]
(0, 0, 0, 0, 0)

yet they are not immutable, even when trying to set them so:
sage: code[0].is_immutable()
False
sage
: code[0].set_immutable()
sage
: code[0].is_immutable()
False

Is there any particular reason why the codewords are not immutable if they cannot be changed anyway?

If they were, using them as dictionary keys would be less of a hassle:
sage: {code[0]: "element"}
TypeError: mutable vectors are unhashable

I guess the current options are
sage: v = code[0]
sage
: v.set_immutable()
sage
: {v: "element"}
or
sage: {tuple(code[0]): "element"}
neither of which is particularly elegant.

Is there a way to set the all of the codewords as immutable?

I'm using Sage version 6.1.1 on a Linux machine.

Gerli
Message has been deleted

P Purkayastha

unread,
May 12, 2014, 1:20:57 PM5/12/14
to sage-s...@googlegroups.com
The reason why it behaves this way is because the code[0] command regenerates the codeword every time you call it. The reason for doing so is in http://trac.sagemath.org/ticket/13694

So, code[0][0]=1 is indeed changing the vector, but it is not changing the vector that is displayed by the next code[0] command. If you want a set of immutable vectors, then you can do something like this:

sage: C = codes.HammingCode(3, GF(2))
sage
: codevectors = C.list()
sage
: for c in codevectors: c.set_immutable()
sage
:
sage
: D = {c: c.hamming_weight() for c in codevectors}

P Purkayastha

unread,
May 12, 2014, 1:28:54 PM5/12/14
to sage-s...@googlegroups.com
It may not be such a bad idea to return codevectors which are immutable. I have opened http://trac.sagemath.org/ticket/16338 to discuss this.


On Monday, May 12, 2014 11:12:19 PM UTC+8, Gerli Viikmaa wrote:
Reply all
Reply to author
Forward
0 new messages