On Dec 19, 2008, at 10:40 AM, Jason Grout wrote:

> Marshall Hampton wrote:
>> Something odd is happening here.  I just noticed that if we define v
>> as:
>>
>> v = vector(QQ,[1,1])
>>
>> then there are no problems, even though the type(v) is the same as in
>> your code.  I don't understand how the same type of object, with the
>> same values, would have different coercion behavior.

Coercion, or wether arithmetic even makes sense, is determined by the  
*parent* of an object, not its type. Consider the following session.

sage: a = mod(2, 5)
sage: b = mod(2, 7)
sage: type(a)
<type 'sage.rings.integer_mod.IntegerMod_int'>
sage: type(b)
<type 'sage.rings.integer_mod.IntegerMod_int'>
sage: a*b  # This doesn't makes sense, and SHOULD fail
Traceback (most recent call last):
   File "<ipython console>", line 1, in <module>
   File "element.pyx", line 1102, in  
sage.structure.element.RingElement.__mul__ (sage/structure/element.c: 
8632)
   File "coerce.pyx", line 697, in  
sage.structure.coerce.CoercionModel_cache_maps.bin_op (sage/structure/ 
coerce.c:5833)
TypeError: unsupported operand parent(s) for '*': 'Ring of integers  
modulo 5' and 'Ring of integers modulo 7'

sage: parent(a)
Ring of integers modulo 5
sage: parent(b)
Ring of integers modulo 7


> I think that the issue might be the issue in #3058:
> http://trac.sagemath.org/sage_trac/ticket/3058
>
> The problem comes up when the parent of v has a user-defined basis,
> instead of the standard basis:
>
> sage: v.parent()
>
> Vector space of degree 2 and dimension 1 over Rational Field
> User basis matrix:
> [1 1]

Yes, you hit the nail on the head. Note that (for better or for  
worse) multiplication by the identity matrix makes it forget the user- 
defined basis.

sage: A=matrix([[1,2],[2,1]])
sage: eig=A.eigenvectors_right()
sage: v=eig[0][1][0]
sage: t = var('t')
sage: I = A.parent()(1); I
[1 0]
[0 1]

sage: parent(v*t)
Vector space of degree 2 and dimension 1 over Symbolic Ring
User basis matrix:
[1 1]
sage: parent(I*v*t)
Vector space of dimension 2 over Symbolic Ring
sage: A*v - I*v*t
(3 - t, 3 - t)

- Robert


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

Reply via email to