Volker Braun <vbraun.name <at> gmail.com> writes:

> > sage: FiniteEnumeratedSet(GF(3))
> > sage: sum(FiniteEnumeratedSet([0,1,2]))
> > 0
> But I would rather blame the use of caching rather than equality
> testing.
> Just removing the caching here isn't that easy, FiniteEnumeratedSet really
is just a UniqueRepresentation. I'm pretty sure there are similar issues in
other UniqueRepresentations...

For one thing it illustrates that FiniteEnumeratedSet (due to being a
full-blown parent and hence having UniqueRepresentation) is a rather
heavy-weight object.

Note that "equality" of FiniteEnumeratedSet is going to be a bit funny when
construction from arguments starts to use an equivalence test more strict
than "==": It means that we can have two enumerated sets

V = FiniteEnumeratedSet(GF(3))
W = FiniteEnumeratedSet([0,1,2])

such that

all( any(v==w for w in W) for v in V) and
all( any(v==w for v in V) for w in W) and
not( V == W )

(having UniqueRepresentation and not EqualityById would be horrible)

> Really, caching ought to apply a stricter comparison that our "== after
coercion". IMHO we should require that the parents match before coercion,
that is, use (parent(x), x) as cache dictionary key. Otherwise there will
always be cases where an incorrectly primed cache will give you wrong
answers. Not to mention the impossibility to test a cached_function/method
that it does not depend on the previous inputs.

And since the arguments get processed already in order to get hashed, it
would probably be quite doable to process them such that SageElement
instances get replaced by (elt.parent(), elt), or perhaps better: if objects
provide a "_cache_key_" method, use its value.

-- 
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 post to this group, send email to sage-devel@googlegroups.com.
Visit this group at http://groups.google.com/group/sage-devel.
For more options, visit https://groups.google.com/d/optout.

Reply via email to