On Jan 18, 2008, at 3:44 PM, William Stein wrote:

>
>> But then for "convenience of users", division by a unit is carried  
>> out
>> in the same ring:
>>
>>> Parent(1/(1+q));
>> Power series ring in q over Rational Field
>>
>> In writing code, it becomes necessary to test the invertibility of  
>> the
>> denominator in order to know what the output type will be.
>>
>> Moreover, the conventions for power series ring are not the same for
>> p-adic rings, so writing generic code becomes difficult.
>>
>> I strongly suggest that some fixed convention exists for all rings,
>> before things become too muddled.  I prefer:
>>
>> 1/x = constructor for the ring of fractions
>
> Yes.

I think it's nice that 1/(1+q) is still a power series, but there  
should be a convention adopted here. My proposal is that division is  
a constructor for fraction fields when generic elements are non- 
units, and happens in the ring (and raises error on failure) when  
they're not. This seems to be consistent with the current status of  
Sage, and is clear-cut and (IMHO) usually does what one wants.

>> x^-1 = x.inverse() the inverse in the ring (error for non-units)
>
> I'm not so sure.
>
>> If you think SAGE should be more lenient with the notation x^-1, then
>
> I do.  Not allowing 3^(-1) seems too mean to me.
>
>> 1/x = x^-1 constructor for the ring of fractions
>> x.inverse() the inverse in the ring
>> But x.inverse() should not return an inverse if one does not exist;
>> this should be reserved for the operation on units in the ring or
>> give an error.  I really want to be able to do:
>
> I would be OK with this, but I think the name should be more  
> explicit, e.g.,
>    x.inverse_in_parent()

There is currently an inverse_of_unit command.

ZZ(-1).inverse_of_unit().parent()
Integer Ring
sage: QQ[x](2).inverse_of_unit().parent()
Univariate Polynomial Ring in x over Rational Field
sage: matrix(ZZ, 2, 2, [1,5,0,-1]).inverse_of_unit() # not  
implemented...
------------------------------------------------------------
Traceback (most recent call last):
   File "<ipython console>", line 1, in <module>
<type 'exceptions.AttributeError'>:  
'sage.matrix.matrix_integer_dense.Matrix_integer_de' object has no  
attribute 'inverse_of_unit'

It would be nice (perhaps) to have an easier way to get a unit in  
self.parent(), if one exists. E.g. the ~ operator could do this.  
(Perhaps this would be too confusing.)

>> In general I am opposed to functions returning values of different
>> types depending on the values of the arguments, unless there is some
>> overriding reason and convention in place for doing otherwise.
>
> Same here.  And in the case of exponentiation I think there is
> such an overriding reason and convention in place for doing otherwise.

Exponentiation is particularly thorny, which is why it has been  
difficult to put it into the coercion model... However, I think that  
x^(-1) != 1/x would cause a lot of confusion, as would parent(x) !=  
parent(x^n) for positive n.

- Robert


--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to sage-devel@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-devel
URLs: http://www.sagemath.org
-~----------~----~----~----~------~----~------~--~---

Reply via email to