Dear Bruce, dear graph fans,
On Sat, May 15, 2010 at 02:46:14PM -0700, Bruce wrote:
> I am continuing a discussion in a new post.
> The issue is that if we take a class such as graphs the instances
> are mutable. It would be useful to have a version which was
> immutable and therefore hashable. For example, we could then use
> CombinatorialFreeModule to construct formal linear combinations.
> Nicolas has pointed out that:
> In any cases, with Sage 4.4.1, you can actually cheat around this, and
> pretend that your graph is immutable:
>
> sage: G = DiGraph(4)
> sage: hash(G)
> ------------------------------------------------------------
> Traceback (most recent call last):
> ...
> TypeError: graphs are mutable, and thus not hashable
>
> sage: G._immutable = True
> sage: hash(G)
> -236023159
>
> This is *dangerous*, so use with all due care. But maybe this can be
> sufficient as a workaround for you until a proper mutability
> management is implemented for graphs.
>
> Is the right way to deal with this (and other similar problems) to
> have a new class frozengraph
> but the types that the data is built up from is changed so that lists,
> sequences, etc. are converted
> to tuples and dictionaries are converted first to sets and then
> frozensets?
See what's done e.g. with matrices:
sage: m = matrix([[1,2],[1,2]])
sage: m.set_immutable?
as well as the mutability section in:
http://www.sagemath.org/doc/developer/coding_in_python.html
(Florent: you may want to throw in this discussion a link to the
"clone" feature)
In any cases, this is a fairly technical issue (not in itself, but
because it involves a large body of code), so the details of the
design should be left to the people in charge of the graph
library. Hence, the best way is to open a ticket (please ask for help
for that if needed). I am also forwarding this discussion to sage-devel.
Best,
Nicolas
--
Nicolas M. ThiƩry "Isil" <[email protected]>
http://Nicolas.Thiery.name/
--
You received this message because you are subscribed to the Google Groups
"sage-combinat-devel" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/sage-combinat-devel?hl=en.