Hi Vincent, On 2014-02-13, Vincent Delecroix <[email protected]> wrote: > Words currently do not fit well with category... (for example they do > not inherit from parent).
If it is supposed to behave like an object in a sub-category of Sets, then it is a quite severe bug not to derive it from Parent. > For your problem, a stupid strategy of the conversion mechanism in > Sage from X to Y is to ask for X an element x (via an_element()) and > then try Y(x). It makes many things annoying ! Why? The not-so-stupid strategy of the coercion framework is to create some map once, for a given pair P1, P2 of parents, such that all conversions from P1 to P2 are provided by that map. So, rather than re-creating a map for each given element of P1, a single map is used. You could easily provide a conversion map from P1 to P2, and then I think supplying _an_element_() is not needed. If the user/developer does not provide a conversion map, then some default approaches for conversion (respectively for action, in the case of a product a*b with a and b in different parents) are tried. I am sure that in the case of a*b some sanity checks are done: Sage will only choose a particular default conversion map (among several that may exist) after having tested that it does not give an error when mapping an element. Sanity checks are a not-so-stupid idea. > On the other hand, > there is no real specifications for "x in X" You are mistaken. The specification for "x in X" defaults to: x in X <=> x==X(x) If you analyse the right hand side a bit further: You need a conversion X(x) (in particular, it must not raise an error), and coercion is involved for testing equality of elements x and X(x) (which belong to different parents!). Hence, you will have "x in X" if a conversion from x into X works and if x.parent() and X canonically fit into a common parent Z (hence, you have coercions from x.parent() to Z and from X to Z). So, eventually, you have x in X if and only if x and X(x) are mapped to the same element of Z. So, that's the default. As I said, some sanity checks are done in the case of multiplication a*b. These involve trying whether the map works for some elements. By some recent ticket, the explicitly given elements a and b are taken for test, so that supplying _an_element_ is not needed any more (it used to be needed in the past). And I guess a similar story happens when testing "x in X": Coercion is involved, and sanity checks occur that require to have an element. So, what we should do, similar to the case of multiplication a*b: Use the explicitly given element x, so that x.parent().an_element() does not need to be called. That's worth a ticket. Could you open one and put me on Cc? Best regards, Simon -- 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 [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/sage-devel. For more options, visit https://groups.google.com/groups/opt_out.
