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}
On Monday, May 12, 2014 11:12:19 PM UTC+8, Gerli Viikmaa wrote:
>
> 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
>
--
You received this message because you are subscribed to the Google Groups
"sage-support" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sage-support.
For more options, visit https://groups.google.com/d/optout.