Bonsoir Eric, Primes() is using the default _element_constructor_ from the category. There is no check at all. Actually, it would make sense to add a containment test at the end of the construction. Something along
def _element_constructor_(self, data): i = super(self, X)._element_constructor_(data) if i not in self: raise AppropriateError return i Vincent 2015-02-01 18:43 UTC+01:00, Eric Gourgoulhon <egourgoul...@gmail.com>: > Hi, > > While playing with prime numbers to understand facade sets in Sage, I > noticed the following surprising behavior: > > sage: P = Primes() ; P > Set of all prime numbers: 2, 3, 5, 7, ... > sage: P.facade_for() > (Integer Ring,) > sage: P(4) > 4 > sage: P(4) in P > False > > > The culprit is _element_constructor_: > > sage: P._element_constructor_(4) > 4 > > > Actually, for any integer n, P(n) returns n. On the contratry the behavior > of PrimeNumbers_Facade (used by Sets().example("facade") is more > satisfactory: > > sage: PP = Sets().example("facade") ; PP > Set of prime numbers (facade implementation) > sage: PP.facade_for() > (Integer Ring,) > sage: PP(4) > Traceback (most recent call last): > ... > ValueError: 4 is not a prime number > sage: 4 in PP > False > > Is there any reason for the above behavior of Primes() ? (Maybe I am > missing something...) > > Eric. > > -- > 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. > -- 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.