Related:
https://trac.sagemath.org/ticket/29101
(Refined protocol for _element_constructor_ in element classes with 
mutability)

On Thursday, August 5, 2021 at 4:25:08 PM UTC-7 Nils Bruin wrote:

>
> Hi all,
>
> I am fully aware of why vectors *can* be mutable and that having them 
> start out life mutable makes sense (since you cannot really change an 
> immutable vector back to mutable), but there is a scenario where it's super 
> annoying. I ran into this recently in an actual practical piece of code. I 
> won't bore you with the details. This is the setup:
>
> V = VectorSpace(GF(2),6)
> D = dict()
>
> I end up using elements of V as keys into the dictionary [in this case, 
> theta characteristics, which are naturally indexed by such vectors]. I end 
> up doing arithmetic with these indices, so I end up with expressions such 
> as:
>
> W = V.subspace([V.1,V.2,V.3])
>
> sum( D[v0+w] for w in W)
>
> except that that doesn't work, because v0+w ends up being a fresh vector 
> and hence is mutable; so not hashable.
>
> One can work around it with a little helper function
>
> def imm(v):
>     v.set_immutable()
>     return v
>
> and then one can write:
>
> sum( D[imm(v0+w)] for w in W)
>
> it's just super annoying to have to do that everywhere, and of course one 
> ends up getting an error message each time before actually putting this in 
> place.
>
> So perhaps for convenience in interactive use, it would be useful to have
>
> VectorSpace(R,n,immutable_vectors=True)
>
> or something similar. It's particularly for these kinds of situations 
> where one wants to use *vectors*, not tuples, for indexing, because one 
> WANTS the vector arithmetic. It's not for high-performance scenarios (that 
> vectors in other situations definitely need to be able to accommodate).
>
> Ideas?
>

-- 
You received this message because you are subscribed to the Google Groups 
"sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-devel+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sage-devel/34a1125e-ff85-4d67-8156-f52d363ddc35n%40googlegroups.com.

Reply via email to