[sage-devel] Re: trouble with linear algebra over CC and CDF

2008-04-15 Thread didier deshommes
On Fri, Apr 11, 2008 at 8:00 PM, Alex Ghitza [EMAIL PROTECTED] wrote:

  -BEGIN PGP SIGNED MESSAGE-
  Hash: SHA1

  Hi,

  There are some inconsistencies in linear algebra over fields like CDF.
  Some trouble was already reported in #2256.  The following is another issue:

  sage: M = matrix(CDF, 2, 2, [(-1 - 2*I, 5 - 6*I), (-2 - 4*I, 10 - 12*I)])
  sage: M.is_invertible()
  True
  sage: M.determinant()
  5.3290705182e-15 + 1.7763568394e-15*I
  sage: M.inverse()
  [ 1.01330991616e+15 - 2.58956978574e+15*I -5.06654958079e+14 +
  1.29478489287e+15*I]
  [ 5.62949953421e+14 + 5.62949953421e+14*I -2.81474976711e+14 -
  2.81474976711e+14*I]

  So because of roundoff errors, Sage thinks that we have an invertible
  matrix.  But the code for echelon_form knows that it's not invertible:

  sage: M.echelon_form()
  [1.0 1.4
  + 3.2*I]
  [-2.22044604925e-16 - 4.4408920985e-16*I
  ~   0]
  sage: M.rank()
  1

  This behavior is inconsistent.  Either there is enough precision to
  decide that the matrix is invertible, or there isn't.  Doing this in two
  different ways should not yield two mutually exclusive answers.

  Similar problems occur over CC.

  I hope it's clear by now that I have no idea how CDF and friends
  actually work, so I don't know what would be a good solution or even
  whether such a solution should exist.  My initial guess would be that
  finding the determinant requires more computations so there is more
  precision loss than in computing the echelon form; in that case, maybe
  over such fields we should not base is_invertible() and inverse() on
  determinant() but rather on echelon_form().

This is now #2932: http://trac.sagemath.org/sage_trac/ticket/2932:

Just looking at the value of M.rank() should be enough, I think. Also,
M.rank() seems much faster than computing the determinant:
{{{
sage: M = matrix(CDF, 2, 2, [(-1 - 2*I, 5 - 6*I), (-2 - 4*I, 10 - 12*I)])
sage: %timeit M.rank()
100 loops, best of 3: 676 ns per loop
sage: %timeit M.det()
10 loops, best of 3: 2.81 µs per loop
}}}

Timings are comparable over ZZ,QQ,RR.

didier


  Note also that this problem does not seem to occur over RR or RDF.

  Best,
  Alex


  - --
  Alexandru Ghitza
  Assistant Professor
  Department of Mathematics
  Colby College
  Waterville, ME 04901
  http://bayes.colby.edu/~ghitza/
  -BEGIN PGP SIGNATURE-
  Version: GnuPG v2.0.7 (GNU/Linux)
  Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

  iD8DBQFH//uydZTaNFFPILgRArYKAJ4r9QOJNYSSCgVzSutUW7gEfcv3uQCfd3aj
  nYV2EFH6znwShoGL7q2BjRY=
  =74HR
  -END PGP SIGNATURE-

  


--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



[sage-devel] Re: trouble with linear algebra over CC and CDF

2008-04-11 Thread Jason Grout

Alex Ghitza wrote:
 -BEGIN PGP SIGNED MESSAGE-
 Hash: SHA1
 
 Hi,
 
 There are some inconsistencies in linear algebra over fields like CDF.
 Some trouble was already reported in #2256.  The following is another issue:
 
 sage: M = matrix(CDF, 2, 2, [(-1 - 2*I, 5 - 6*I), (-2 - 4*I, 10 - 12*I)])
 sage: M.is_invertible()
 True
 sage: M.determinant()
 5.3290705182e-15 + 1.7763568394e-15*I
 sage: M.inverse()
 [ 1.01330991616e+15 - 2.58956978574e+15*I -5.06654958079e+14 +
 1.29478489287e+15*I]
 [ 5.62949953421e+14 + 5.62949953421e+14*I -2.81474976711e+14 -
 2.81474976711e+14*I]
 
 So because of roundoff errors, Sage thinks that we have an invertible
 matrix.  But the code for echelon_form knows that it's not invertible:
 
 sage: M.echelon_form()
 [1.0 1.4
 + 3.2*I]
 [-2.22044604925e-16 - 4.4408920985e-16*I
 ~   0]
 sage: M.rank()
 1
 
 This behavior is inconsistent.  Either there is enough precision to
 decide that the matrix is invertible, or there isn't.  Doing this in two
 different ways should not yield two mutually exclusive answers.
 
 Similar problems occur over CC.
 
 I hope it's clear by now that I have no idea how CDF and friends
 actually work, so I don't know what would be a good solution or even
 whether such a solution should exist.  My initial guess would be that
 finding the determinant requires more computations so there is more
 precision loss than in computing the echelon form; in that case, maybe
 over such fields we should not base is_invertible() and inverse() on
 determinant() but rather on echelon_form().
 
 Note also that this problem does not seem to occur over RR or RDF.


Do you know how Matlab and friends treat a similar case?

Should we be computing singular values and letting the user decide on a 
cut-off point for deciding if a singular value really is zero?

Jason


--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---