#12514: default behavior of matrix([...]).eigenvectors_right() should be sane
------------------------------+---------------------------------------------
   Reporter:  ppurka          |          Owner:  jason, was         
       Type:  defect          |         Status:  new                
   Priority:  major           |      Milestone:  sage-5.0           
  Component:  linear algebra  |       Keywords:  matrix eigenvectors
Work_issues:                  |       Upstream:  N/A                
   Reviewer:                  |         Author:                     
     Merged:                  |   Dependencies:                     
------------------------------+---------------------------------------------

Old description:

> I think the default behavior of `eigenvectors_right()` should be sane.
> Current behavior varies wildly.
>
> 1. For example this fails:
> {{{
> sage: matrix([ [2, 1], [1, 2.0]]).eigenvectors_right()
> ---------------------------------------------------------------------------
> NotImplementedError                       Traceback (most recent call
> last)
>
> /home/punarbasu/Installations/sage-5.0.beta2/devel/sagenb-github/<ipython
> console> in <module>()
>
> /home/punarbasu/Installations/sage-5.0.beta2/local/lib/python2.7/site-
> packages/sage/matrix/matrix2.so in
> sage.matrix.matrix2.Matrix.eigenvectors_right
> (sage/matrix/matrix2.c:27925)()
>
> /home/punarbasu/Installations/sage-5.0.beta2/local/lib/python2.7/site-
> packages/sage/matrix/matrix2.so in
> sage.matrix.matrix2.Matrix.eigenvectors_left
> (sage/matrix/matrix2.c:27260)()
>
> /home/punarbasu/Installations/sage-5.0.beta2/local/lib/python2.7/site-
> packages/sage/matrix/matrix2.so in
> sage.matrix.matrix2.Matrix.eigenspaces_left
> (sage/matrix/matrix2.c:24126)()
>
> NotImplementedError: eigenspaces cannot be computed reliably for inexact
> rings such as Real Field with 53 bits of precision,
> consult numerical or symbolic matrix classes for other options
> }}}
>
> 2. This also fails but with a different error:
> {{{
> sage: matrix( [ [1.0, 0], [0.1, 2.0] ] ).right_eigenvector()
> ---------------------------------------------------------------------------
> AttributeError                            Traceback (most recent call
> last)
>
> /home/punarbasu/Installations/sage-5.0.beta2/devel/sagenb-github/<ipython
> console> in <module>()
>
> /home/punarbasu/Installations/sage-5.0.beta2/local/lib/python2.7/site-
> packages/sage/structure/element.so in
> sage.structure.element.Element.__getattr__
> (sage/structure/element.c:2921)()
>
> /home/punarbasu/Installations/sage-5.0.beta2/local/lib/python2.7/site-
> packages/sage/structure/parent.so in
> sage.structure.parent.getattr_from_other_class
> (sage/structure/parent.c:3302)()
>
> AttributeError: 'sage.matrix.matrix_generic_dense.Matrix_generic_dense'
> object has no attribute 'right_eigenvector'
> }}}
>
> 3. Using RDF gives a sane output:
> {{{
> sage: matrix(RDF, [ [2, 1], [1, 2]]).eigenvectors_right()
> [(3.0, [(0.707106781187, 0.707106781187)], 1), (1.0, [(-0.707106781187,
> 0.707106781187)], 1)]
> }}}
>
> 4. But not using RDF in this case gives an output that appears "broken":
> {{{
> sage: matrix([ [2, 1], [1, 2]]).eigenvectors_right()
> [(3, [
> (1, 1)
> ], 1), (1, [
> (1, -1)
> ], 1)]
> }}}
>
> In my opinion, by default all matrices should be made to belong to RDF or
> CDF if the field is not specified, so that most of the functionality can
> be availed.
>
> The output in the last example appears "broken" because at some stage
> this function is called with '''cr=True''', and this inserts a carriage
> return after every eigenvector:
> {{{
> Sequence(vecs, universe=V, check = False, immutable=True, cr=True)
> }}}

New description:

 I think the default behavior of `eigenvectors_right()` should be sane.
 Current behavior varies wildly.

 1. For example this fails:
 {{{
 sage: matrix([ [2, 1], [1, 2.0]]).eigenvectors_right()
 ---------------------------------------------------------------------------
 NotImplementedError                       Traceback (most recent call
 last)

 /home/punarbasu/Installations/sage-5.0.beta2/devel/sagenb-github/<ipython
 console> in <module>()

 /home/punarbasu/Installations/sage-5.0.beta2/local/lib/python2.7/site-
 packages/sage/matrix/matrix2.so in
 sage.matrix.matrix2.Matrix.eigenvectors_right
 (sage/matrix/matrix2.c:27925)()

 /home/punarbasu/Installations/sage-5.0.beta2/local/lib/python2.7/site-
 packages/sage/matrix/matrix2.so in
 sage.matrix.matrix2.Matrix.eigenvectors_left
 (sage/matrix/matrix2.c:27260)()

 /home/punarbasu/Installations/sage-5.0.beta2/local/lib/python2.7/site-
 packages/sage/matrix/matrix2.so in
 sage.matrix.matrix2.Matrix.eigenspaces_left
 (sage/matrix/matrix2.c:24126)()

 NotImplementedError: eigenspaces cannot be computed reliably for inexact
 rings such as Real Field with 53 bits of precision,
 consult numerical or symbolic matrix classes for other options
 }}}

 2. ''[Neglect this case. It is a typo. Keeping it here so that the
 references from the comments below make sense]'' This also fails but with
 a different error:
 {{{
 sage: matrix( [ [1.0, 0], [0.1, 2.0] ] ).right_eigenvector()
 ---------------------------------------------------------------------------
 AttributeError                            Traceback (most recent call
 last)

 /home/punarbasu/Installations/sage-5.0.beta2/devel/sagenb-github/<ipython
 console> in <module>()

 /home/punarbasu/Installations/sage-5.0.beta2/local/lib/python2.7/site-
 packages/sage/structure/element.so in
 sage.structure.element.Element.__getattr__
 (sage/structure/element.c:2921)()

 /home/punarbasu/Installations/sage-5.0.beta2/local/lib/python2.7/site-
 packages/sage/structure/parent.so in
 sage.structure.parent.getattr_from_other_class
 (sage/structure/parent.c:3302)()

 AttributeError: 'sage.matrix.matrix_generic_dense.Matrix_generic_dense'
 object has no attribute 'right_eigenvector'
 }}}

 3. Using RDF gives a sane output:
 {{{
 sage: matrix(RDF, [ [2, 1], [1, 2]]).eigenvectors_right()
 [(3.0, [(0.707106781187, 0.707106781187)], 1), (1.0, [(-0.707106781187,
 0.707106781187)], 1)]
 }}}

 4. But not using RDF in this case gives an output that appears "broken":
 {{{
 sage: matrix([ [2, 1], [1, 2]]).eigenvectors_right()
 [(3, [
 (1, 1)
 ], 1), (1, [
 (1, -1)
 ], 1)]
 }}}

 In my opinion, by default all matrices should be made to belong to RDF or
 CDF if the field is not specified, so that most of the functionality can
 be availed.

 The output in the last example appears "broken" because at some stage this
 function is called with '''cr=True''', and this inserts a carriage return
 after every eigenvector:
 {{{
 Sequence(vecs, universe=V, check = False, immutable=True, cr=True)
 }}}

--

Comment(by ppurka):

 Indeed, (2) was a typo (now I! How quaint of me to have missed that. I
 will put a message on sage-devel regarding (4). Regarding (1) there are
 two things that could be done to improve the default behavior:

 1. Simply use RDF/CDF by default.

 2. Enclose the code in a `try` statement (which first uses whatever is the
 default) and return the computations from RDF (if the numbers are not
 complex) if the `NotImplementedError` exception occurs.

-- 
Ticket URL: <http://trac.sagemath.org/sage_trac/ticket/12514#comment:2>
Sage <http://www.sagemath.org>
Sage: Creating a Viable Open Source Alternative to Magma, Maple, Mathematica, 
and MATLAB

-- 
You received this message because you are subscribed to the Google Groups 
"sage-trac" group.
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-trac?hl=en.

Reply via email to