Hi Vincent, I'm sorry for my long answer. I am not a native speaker, so, it is difficult for me to be concise in English.
On 2012-08-16, Vincent Delecroix <20100.delecr...@gmail.com> wrote: > This default behavior is very badly suited. In parallel to my second > mail, I found the more striking example ... I disagree. In mathematics, == is transitive. But I believe it is impossible to keep == transitive in a complex computer algebra system. Of course one must make sure that "a==b and b==c implies a==c", provided that a, b and c belong to the same parent. However, we talk here about comparing elements in *different* parents. If a and b belong to different parents, I believe that "a==b" is not a mathematically rigid statement any more. In particular, you can't expect transitivity. Nevertheless "a==b" must still give an answer (raising an error is no option, by Python convention), and of course the answer should still be as useful as possible. In order to be useful, it must still be reflexive and symmetric, but transitivity only needs to hold "to a reasonable extent". And I believe that basing "a==b" on coercion *is* reasonable. > I definitely think that "Zmod(5)(3) in ZZ" should return False. > Remarks that it is true as a subset as Zmod(5)(3) is the set of > integers equal to 3 mod 5. The first ingredient for "Zmod(5)(3) in ZZ" being true is that there is a *canonical* ring homomorphism (used for coercion) from ZZ to Zmod(5). The second ingredient is that someone has decided that a conversion (which is not a coercion!!!) from Zmod(5) to ZZ is very useful and should be available. Let phi:ZZ->Zmod(5) the coercion homomorphism and psi:Zmod(5)->ZZ the conversion map. psi is not a homomorphism and can thus not be a coercion. But it is a section for phi, and I think it *is* reasonable to use it for conversion. Let a be in ZZ and b be in Zmod(5). If you ask a==b, even though a and b belong to different mathematical structures, then I think the best one can do is to map a and b to a canonical mathematical structure by homomorphisms. In general, the "canonical mathematical structure" will be determined by a pushout construction. Here, it is easier: There is a canonical homomorphism from ZZ to Zmod(5). Hence, Sage will compare a and b there, via the coercion homomorphism: a==b is the same as phi(a)==b. Since psi is a section, psi(b)==b holds for all b in Zmod(5). If one accepts psi as a conversion map, I think it is reasonable to accept "b in ZZ" for all b in Zmod(5) -- as long as one is aware that the embedding of Zmod(5) in ZZ is not structure preserving! Of course, there will be applications in which that kind of comparison is too coarse. But if you want to compare elements of distinct parents then it is your own risk that your notion of "reasonable" is different from Sages implementation of "reasonable". >In other words "3 in Zmod(5)(3)" should > returns True but it returns an error. Zmod(5)(3) is by default considered as an element of a ring, not as a coset. Hence, of cource "3 in Zmod(5)(3)" returns an error. If you want a coset, i.e., if you want a non-default behaviour, then you need to do so explicitly. > It is easy to create an embedding into ZZ and modify the __contains__ > method. Then many things work well. > > Note that P is a facade and hence it is normal that its elements have > a parent different from P. But is there a canonical way to tell that a > Parent is a subset of another Parent? During initialisation of a parent, one can use the method register_embedding (defined for sage.structure.parent.Parent) to declare a canonical embedding. That embedding will be used as a coercion map. Best regards, Simon -- You received this message because you are subscribed to the Google Groups "sage-combinat-devel" group. To post to this group, send email to sage-combinat-devel@googlegroups.com. To unsubscribe from this group, send email to sage-combinat-devel+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sage-combinat-devel?hl=en.