On Oct 14, 2008, at 2:02 PM, Martin Rubey wrote:

> Robert Bradshaw <[EMAIL PROTECTED]> writes:
>
>> On Oct 14, 2008, at 1:33 PM, Martin Rubey wrote:
>>
>>>
>>> I believe I understood now:
>>>
>>> sage: ?parent
>>> Type:           function
>>> <snip>
>>>         Return x.parent() if defined, or type(x) if not.
>>>
>>> I wonder why this is a function, and not a method of Parent?
>>
>> Typically one uses the parent() function when one has an element
>> (such as an integer) and wants it's Parent. This is why it's not an
>> element of the Parent.
>
> Hm, I do not understand that.  Why wouldn't one want to use 5.parent 
> (), for
> example?  (The method notation together with tab completion is  
> really nice...)
> Well, I suppose that some people prefer usual functional notation.

Yes, the method notation + tab completion is very nice and usually  
prefered. The reason one would want to use parent() however is  
because not everything has a parent method. For example, int(1).parent 
() would fail with an attribute error. The parent function always  
succeeds, giving something reasonable if the object in question  
doesn't have such a method.

Often functional notation is just handier for really common things,  
e.g. writing sin(pi/5) rather than (pi/5).sin().

>> The docstring should have some better examples, e.g.
>>
>> sage: parent(5)
>> Integer Ring
>> sage: parent(1/2)
>> Rational Field
>> sage: parent(1.5)
>> Real Field with 53 bits of precision
>
> Well, actually, I find the current docstring OK, it answered my  
> question, at
> least partially.  OK, maybe some more examples wouldn't hurt.
>
> But what I really do not understand is why Parent doesn't implement  
> a parent
> method...



>>> (Am I right that all Sage parents inherit from Parent?  Would be  
>>> great to
>>> know this)
>>
>> Yes, that is correct.
>
> OK, great.
>
>>> Set_object inherits from Set_generic, and does not define a  
>>> parent method,
>>> for whatever reason, maybe because the elements of the set need  
>>> not have a
>>> common type.
>>>
>>> I just saw on
>>> http://trac.sagemath.org/sage_trac/attachment/ticket/2314/
>>> coerce_2_sets.patch
>>>
>>> a patch to primes.py, which, in particular, makes Primes inherit  
>>> from a new
>>> class Subset instead of Set_generic.  I guess this adresses the  
>>> issue.
>>>
>>> It would be wonderful to hear either of "yes, correct", or "no,  
>>> you are
>>> mistaken".
>
>> I'm not sure exactly what your question is,
>
> The question was, why does
>
> parent(Primes()) give an answer, while Primes().parent() yields an  
> error.
>
>> but sets don't really have a parent,
>
> well, they do:
>
> sage: parent(Set([1,2,3])) <class
> 'sage.sets.set.Set_object_enumerated'>
>
> ;-)
>
> I think it's ok to have things without parent, but I do not  
> understand yet, why
> x.f() and f(x) are designed differently in some cases.  One case I  
> stepped into
> was parent, the other was Mod.

Here it's a question of context. The method mod(a,b) is a constructor  
for an element of Z/mZ, a.mod(b) means "divide and take the remainder  
(as an integer)"

>> as the set of all sets is not a category.
>
> Äh?  You don't mean category in the mathematical sense here, do you?
> http://en.wikipedia.org/wiki/Category_of_sets

Yes, I meant in the sense that the class of all sets can't be an  
object in a category. I think the confusion here is as to what a  
parent actually is. A parent is an Object in a concrete category,  
i.e. it contains Elements. This is why the notion of the "parent of a  
Parent" is a bit strange. Because Python (justifiably) doesn't force  
all objects to have categorically-theoretical underpinnings, we use  
the type (or, internally "the set of all objects of type X") as a  
pseudo-parent to be able to reason with (e.g. for coercion).

> Does Sage have it's own notion of category, just as FriCAS?

Yes, though it's not as heavily used (yet, it's becoming more so).

- Robert
--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sage-support
URLs: http://www.sagemath.org
-~----------~----~----~----~------~----~------~--~---

Reply via email to