65 K
get(
int,
int )
const;
66 void set(
int,
int,
const K& );
74 int rank(
void )
const;
75 int solve( K**,
int* );
80 K
add_rows(
int,
int,
const K&,
const K& );
90 void test_row(
int )
const;
91 void test_col(
int )
const;
110 if( a != (K*)
NULL && rows > 0 && cols > 0 )
delete [] a;
129 #ifdef KMATRIX_IOSTREAM
130 cerr <<
"void KMatrix::copy_new( int k )";
131 cerr <<
": no memory left ..." << endl;
133 fprintf( stderr,
"void KMatrix::copy_new( int k )" );
134 fprintf( stderr,
": no memory left ...\n" );
149 #ifdef KMATRIX_IOSTREAM
150 cerr <<
"void KMatrix::copy_new( int k )";
151 cerr <<
": k < 0 ..." << endl;
153 fprintf( stderr,
"void KMatrix::copy_new( int k )" );
154 fprintf( stderr,
": k < 0 ...\n" );
184 for( r=0; r<n; a[r++]=(K)0 );
186 for( r=0; r<rows; r++ )
211 if(
m.a == (K*)
NULL )
222 for(
int i=0;
i<n;
i++ )
263 for(
int i=0;
i<n;
i++ )
295 #ifdef KMATRIX_IOSTREAM
296 cerr <<
"KMatrix<K>::test_row( " << r <<
" )" << endl;
297 cerr <<
" rows = " << rows << endl;
298 cerr <<
" exiting...." << endl;
300 fprintf( stderr,
"KMatrix<K>::test_row( %d )\n",r );
301 fprintf( stderr,
" rows = %d\n",rows );
302 fprintf( stderr,
" exiting....\n" );
316 #ifdef KMATRIX_IOSTREAM
317 cerr <<
"KMatrix<K>::test_col( " << c <<
" )" << endl;
318 cerr <<
" cols = " << cols << endl;
319 cerr <<
" exiting...." << endl;
321 fprintf( stderr,
"KMatrix<K>::test_col( %d )\n",c );
322 fprintf( stderr,
" cols = %d\n",cols );
323 fprintf( stderr,
" exiting....\n" );
379 if( r1 == r2 )
return 1;
383 for(
int c=0; c<cols; c++ )
386 a[r1*cols+c] = a[r2*cols+c];
408 for(
int i=0;
i<cols;
i++,i_src++ )
424 int src,
int dest,
const K &factor_src,
const K &factor_dest )
432 int i_src = src*cols;
433 int i_dest = dest*cols;
435 for(
i=0;
i<cols;
i++,i_src++,i_dest++ )
437 a[i_dest] = a[i_src]*factor_src + a[i_dest]*factor_dest;
456 for(
int c=0; c<cols; c++ )
458 if( a[r*cols+c] != (K)0 )
return FALSE;
476 for(
int r=0; r<rows; r++ )
478 if( a[r*cols+c] != (K)0 )
return FALSE;
500 for( r=r0; r<rows && a[r*cols+c]==(K)0; r++ );
510 double val = a[r*cols+c].complexity( );
511 double val_new = 0.0;
516 if( a[r*cols+c] != (K)0 &&
517 ( val_new = a[r*cols+c].complexity( ) ) < val )
538 K
g =
gcd( &(a[r*cols]),cols );
540 for(
int c=0; c<cols; c++ )
561 for( r=0; r<rows; r++ )
563 set_row_primitive( r );
569 for( c=0; c<cols && rank<rows; c++ )
571 if( ( r = column_pivot( rank,c )) >= 0 )
575 for( r=rank+1; r<rows; r++ )
577 if( a[r*cols+c] != (K)0 )
579 g =
gcd( a[r*cols+c],a[rank*cols+c] );
580 add_rows( rank,r,-a[r*cols+c]/
g,a[rank*cols+c]/
g );
581 set_row_primitive( r );
609 for( r=0; r<rows; r++ )
611 set_row_primitive( r );
619 for( c=0; c<cols && rank < rows; c++ )
621 if( ( r = column_pivot( rank,c )) >= 0 )
625 for( r=0; r<rank; r++ )
627 if( a[r*cols+c] != (K)0 )
629 g =
gcd( a[r*cols+c],a[rank*cols+c] );
630 add_rows( rank,r,-a[r*cols+c]/
g,a[rank*cols+c]/
g );
631 set_row_primitive( r );
635 for( r=rank+1; r<rows; r++ )
637 if( a[r*cols+c] != (K)0 )
639 g =
gcd( a[r*cols+c],a[rank*cols+c] );
640 add_rows( rank,r,-a[r*cols+c]/
g,a[rank*cols+c]/
g );
641 set_row_primitive( r );
656 *solution =
new K[cols-1];
659 for( c=0; c<cols-1; c++ )
661 (*solution)[c] = (K)0;
664 for( r=0; r<rows; r++ )
666 for( c=0; c<cols && a[r*cols+c] == (K)0; c++ );
670 (*solution)[c] = ((K)a[(r+1)*cols-1])/a[r*cols+c];
680 *solution = (K*)
NULL;
709 void print_rational( ostream &
s,
int digits,
const K &n )
711 unsigned int num = digits - n.length( );
713 for(
unsigned int i=0;
i <
num;
i++ )
715 #ifdef KMATRIX_IOSTREAM
718 fprintf( stdout,
" " );
728 int i,r,c,digits=0,tmp;
730 for(
i=0;
i<
m.rows*
m.cols;
i++ )
732 tmp =
m.a[
i].length( );
734 if( tmp > digits ) digits = tmp;
737 for( r=0; r<
m.rows; r++ )
741 #ifdef KMATRIX_IOSTREAM
744 fprintf( stdout,
"<" );
749 #ifdef KMATRIX_IOSTREAM
752 fprintf( stdout,
"/" );
755 else if( r ==
m.rows - 1 )
757 #ifdef KMATRIX_IOSTREAM
760 fprintf( stdout,
"\\" );
765 #ifdef KMATRIX_IOSTREAM
768 fprintf( stdout,
"|" );
772 for( c=0; c<
m.cols; c++ )
774 #ifdef KMATRIX_IOSTREAM
777 fprintf( stdout,
" " );
780 print_rational(
s,digits,
m.a[r*
m.cols+c] );
785 #ifdef KMATRIX_IOSTREAM
788 fprintf( stdout,
" >" );
793 #ifdef KMATRIX_IOSTREAM
796 fprintf( stdout,
" \\\n" );
799 else if( r ==
m.rows - 1 )
801 #ifdef KMATRIX_IOSTREAM
804 fprintf( stdout,
" /" );
809 #ifdef KMATRIX_IOSTREAM
812 fprintf( stdout,
" |\n" );
840 if( is_quadratic( ) )
844 for( r=1; r<rows; r++ )
848 if( a[r*cols+c] != a[c*cols+r] )
869 if( !is_quadratic( ) )
884 for( r=0; r<dummy.
rows; r++ )
892 for( c=0; c<cols && rank<dummy.
rows; c++ )
898 for( r=rank+1; r<dummy.
rows; r++ )
900 if( dummy.
a[r*cols+c] != (K)0 )
902 g =
gcd( dummy.
a[r*cols+c],dummy.
a[rank*cols+c] );
904 frank = -dummy.
a[r*cols+c]/
g;
905 fr = dummy.
a[rank*cols+c]/
g;
907 det /= dummy.
add_rows( rank,r,frank,fr );
915 if( rank != dummy.
rows )
920 for( r=0; r<dummy.
rows; r++ )
922 det *= dummy.
a[r*cols+r];
void set(int, int, const K &)
int column_pivot(int, int) const
int is_symmetric(void) const
K multiply_row(int, const K &)
K add_rows(int, int, const K &, const K &)
int column_is_zero(int) const
K determinant(void) const
int row_is_zero(int) const
void copy_shallow(KMatrix &)
int is_quadratic(void) const
void copy_deep(const KMatrix &)
const CanonicalForm int s
void copy_deep(spectrum &spec, lists l)
bool pivot(const matrix aMat, const int r1, const int r2, const int c1, const int c2, int *bestR, int *bestC, const ring R)
This code computes a score for each non-zero matrix entry in aMat[r1..r2, c1..c2].
ostream & operator<<(ostream &s, const spectrum &spec)