On Monday, 9 August 2021 at 15:54:03 UTC-7 Michael Jung wrote: > I like the idea proposed in https://trac.sagemath.org/ticket/29101 (as > posted by Matthias). Namely, introducing the option mutable=False for the > element constructor. Then your code could be rewritten to > > sum( D[V(v0+w, mutable=False)] for w in W) > > which should be fine, I guess. >
No, that is not an improvement at all. imm(v0+w) is shorter than that. Note that in my case, v0 and w are *already* elements of V, so Sage is perfectly capable of working out that their sum v0+w should lie in V again. It's just that currently V creates its new elements by default as unhashable, whereas it should be perfectly fine to use elements from a vector space as indices in a dictionary. What we need is a way to convince the parent V to create its new elements in a hashable way. An almost-solution is to define Vinf = PolynomialRing(GF(2), 'e') Its elements are by default hashable and the space V should be the GF(2)-span of [1,e,e^2,e^3,e^4,e^5]. The space W would be the GF(2)-span of [1,e,e^2]. The problem is that polynomial rings do not have a concept of subsets that are modules over their base ring, so it's difficult to write the sum: you'd have to construct the index set W explicitly by hand. Plus your vectors would print in a weird way. I think the fact that polynomial rings give an almost-but-not-quite solution is a good illustration that we're missing a part of fundamental infrastructure here: almost all arithmetic elements in sage have hashing by default; including things like real numbers, where it's probably a bad idea. It's just vector spaces and matrices where an extra action is currently always required before hashing works. It breaks an otherwise quite expressive notational system that allows python to almost read like mathematics. It may well be that it's convenient internally to have element constructors to allow for a "mutable=True/False" flag. It may even help with implementing the feature under consideration here: making sure that vector spaces have an option to produce (immediately) hashable elements as a result from arithmetic operations in that vector space. But it does not replace the need for being able to set that flag on a parent. -- 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/ad9d71e7-0392-4ee4-82a7-2f3aa9d4f12en%40googlegroups.com.