Hi William,
> > On Thu, Dec 18, 2008 at 08:40:37AM +0200, Jan Groenewald wrote:
> >> In this worksheet:
> >> http://users.aims.ac.za/~jan/type_of_variable.sws
> >> The type of a symbolic variable multiplied by a
> >> rational matrix does not return a rational matrix,
> >> but a sage.modules.free_module_element.FreeModuleElement_generic_dense,
> >> interfering with further calculations. A strange workaround
> >> is to mutiply by an identify matrix. (This exercise is intended
> >> for students to do some brute force experimentation and investigation,
> >> which becomes slow at higher dimensions.)
> >> Is this a bug or intended?
On Thu, Dec 18, 2008 at 12:03:02PM -0800, William Stein wrote:
> I doubt anybody is planning to answer your email so far, since it is
> too challenging to figure out what you're asking. It might be better
> also to paste some code into your email message showing a little Sage
> session and asking a question about it. For example, are you possibly
> complaining that the data type in the output of the last line below is
> Matrix_symbolic_dense?
Apologies. Why is v*t not the same type as v below?
sage: A=matrix([[1,2],[2,1]]);A
[1 2]
[2 1]
sage: eig=A.eigenvectors_right();eig
[(3, [
(1, 1)
], 1), (-1, [
(1, -1)
], 1)]
sage: v=eig[0][1][0];v
(1, 1)
sage: var('t')
t
sage: type(v)
<type 'sage.modules.vector_rational_dense.Vector_rational_dense'>
sage: type(v*t)
<type 'sage.modules.free_module_element.FreeModuleElement_generic_dense'>
For instance, I want to subtract v*t from A*v which is not
possible in sage.
I think this would have worked if v*t was of the type
sage.modules.vector_rational_dense.Vector_rational_dense
just like v. I think it should be that type?
sage: A*v-v*t
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
/var/autofs/misc/home/jan/<ipython console> in <module>()
/usr/local/src/sage-3.2/local/lib/python2.5/site-packages/sage/structure/element.so
in sage.structure.element.ModuleElement.__sub__
(sage/structure/element.c:6073)()
/usr/local/src/sage-3.2/local/lib/python2.5/site-packages/sage/structure/coerce.so
in sage.structure.coerce.CoercionModel_cache_maps.bin_op
(sage/structure/coerce.c:5805)()
TypeError: unsupported operand parent(s) for '-': 'Vector space of dimension
2 over Rational Field' and 'Vector space of degree 2 and dimension 1 over
Symbolic Ring
User basis matrix:
[1 1]'
A workaround we are using in the meantime:
sage: A*v-v*identity_matrix(2)*t
(3 - t, 3 - t)
I still don't get it though, the v*identity_matrix(2)*t has the same type as
v*t, why
does that even work as a workaround?
sage: type(v*t)
<type 'sage.modules.free_module_element.FreeModuleElement_generic_dense'>
sage: type(v*identity_matrix(2)*t)
<type 'sage.modules.free_module_element.FreeModuleElement_generic_dense'>
sage: type(A*v)
<type 'sage.modules.vector_rational_dense.Vector_rational_dense'>
sage: type(A*v-v*identity_matrix(2)*t)
<type 'sage.modules.free_module_element.FreeModuleElement_generic_dense'>
I hope that is clearer.
regards,
Jan
--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to [email protected]
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
-~----------~----~----~----~------~----~------~--~---