My Project
Loading...
Searching...
No Matches
bigintmat Class Reference

Matrices of numbers. More...

#include <coeffs/bigintmat.h>

Public Member Functions

 bigintmat ()
 
bigintmattranspose ()
 
void inpTranspose ()
 transpose in place
 
 bigintmat (int r, int c, const coeffs n)
 constructor: the r times c zero-matrix. Beware that the creation of a large zero matrix is expensive in terms of time and memory.
 
 bigintmat (const bigintmat *m)
 copy constructor
 
number & operator[] (int i)
 dubious: 1-dim access to 2-dim array. Entries are read row by row.
 
const number & operator[] (int i) const
 
void operator*= (int intop)
 UEberladener *=-Operator (fuer int und bigint) Frage hier: *= verwenden oder lieber = und * einzeln? problem: what about non-commuting rings. Is this from left or right?
 
void inpMult (number bintop, const coeffs C=NULL)
 inplace version of skalar mult. CHANGES input.
 
int length ()
 
int cols () const
 
int rows () const
 
coeffs basecoeffs () const
 
 ~bigintmat ()
 canonical destructor.
 
int index (int r, int c) const
 helper function to map from 2-dim coordinates, starting by 1 to 1-dim coordinate, starting by 0
 
number get (int i, int j) const
 get a copy of an entry. NOTE: starts at [1,1]
 
number view (int i, int j) const
 view an entry an entry. NOTE: starts at [1,1]
 
number get (int i) const
 get a copy of an entry. NOTE: starts at [0]
 
number view (int i) const
 view an entry. NOTE: starts at [0]
 
void set (int i, int j, number n, const coeffs C=NULL)
 replace an entry with a copy (delete old + copy new!). NOTE: starts at [1,1]
 
void set (int i, number n, const coeffs C=NULL)
 replace an entry with a copy (delete old + copy new!). NOTE: starts at [0]
 
void rawset (int i, number n, const coeffs C=NULL)
 replace an entry with the given number n (only delete old). NOTE: starts at [0]. Should be named set_transfer
 
void rawset (int i, int j, number n, const coeffs C=NULL)
 as above, but the 2-dim version
 
char * String ()
 IO: String returns a singular string containing the matrix, needs freeing afterwards.
 
void Write ()
 IO: writes the matrix into the current internal string buffer which must be started/ allocated before (e.g. StringSetS)
 
void Print ()
 IO: simply prints the matrix to the current output (screen?)
 
char * StringAsPrinted ()
 Returns a string as it would have been printed in the interpreter.
 
void pprint (int maxwid)
 
int compare (const bigintmat *op) const
 
int * getwid (int maxwid)
 
void swap (int i, int j)
 swap columns i and j
 
void swaprow (int i, int j)
 swap rows i and j
 
int findnonzero (int i)
 find index of 1st non-zero entry in row i
 
int findcolnonzero (int j)
 find index of 1st non-zero entry in column j
 
void getcol (int j, bigintmat *a)
 copies the j-th column into the matrix a - which needs to be pre-allocated with the correct size.
 
void getColRange (int j, int no, bigintmat *a)
 copies the no-columns staring by j (so j...j+no-1) into the pre-allocated a
 
void getrow (int i, bigintmat *a)
 Schreibt i-te Zeile in Vektor (Matrix) a.
 
void setcol (int j, bigintmat *m)
 Setzt j-te Spalte gleich übergebenem Vektor (Matrix) m.
 
void setrow (int i, bigintmat *m)
 Setzt i-te Zeile gleich übergebenem Vektor (Matrix) m.
 
void appendCol (bigintmat *a)
 horizontally join the matrices, m <- m|a
 
void extendCols (int i)
 append i zero-columns to the matrix
 
bool add (bigintmat *b)
 Addiert zur Matrix die Matrix b dazu. Return false => an error occurred.
 
bool sub (bigintmat *b)
 Subtrahiert ...
 
bool skalmult (number b, coeffs c)
 Multipliziert zur Matrix den Skalar b hinzu.
 
bool addcol (int i, int j, number a, coeffs c)
 addiert a-faches der j-ten Spalte zur i-ten dazu
 
bool addrow (int i, int j, number a, coeffs c)
 ... Zeile ...
 
void colskalmult (int i, number a, coeffs c)
 Multipliziert zur i-ten Spalte den Skalar a hinzu.
 
void rowskalmult (int i, number a, coeffs c)
 ... Zeile ...
 
void coltransform (int i, int j, number a, number b, number c, number d)
 transforms cols (i,j) using the 2x2 matrix ((a,b)(c,d)) (hopefully)
 
void concatrow (bigintmat *a, bigintmat *b)
 Fügt zwei Matrixen untereinander/nebeneinander in gegebene Matrix ein, bzw spaltet gegebenen Matrix auf.
 
void concatcol (bigintmat *a, bigintmat *b)
 
void splitrow (bigintmat *a, bigintmat *b)
 Speichert in Matrix a den oberen, in b den unteren Teil der Matrix, vorausgesetzt die Dimensionen stimmen überein.
 
void splitcol (bigintmat *a, bigintmat *b)
 ... linken ... rechten ...
 
void splitcol (bigintmat *a, int i)
 Speichert die ersten i Spalten als Teilmatrix in a.
 
void splitrow (bigintmat *a, int i)
 ... Zeilen ...
 
bool copy (bigintmat *b)
 Kopiert Einträge von b auf Bigintmat.
 
void copySubmatInto (bigintmat *, int sr, int sc, int nr, int nc, int tr, int tc)
 copy the submatrix of b, staring at (a,b) having n rows, m cols into the given matrix at pos. (c,d) needs c+n, d+m <= rows, cols a+n, b+m <= b.rows(), b.cols()
 
void one ()
 Macht Matrix (Falls quadratisch) zu Einheitsmatrix.
 
int isOne ()
 is matrix is identity
 
void zero ()
 Setzt alle Einträge auf 0.
 
int isZero ()
 
int colIsZero (int i)
 
bigintmatelim (int i, int j)
 Liefert Streichungsmatrix (i-te Zeile und j-te Spalte gestrichen) zurück.
 
number pseudoinv (bigintmat *a)
 Speichert in Matrix a die Pseudoinverse, liefert den Nenner zurück.
 
number trace ()
 the trace ....
 
number det ()
 det (via LaPlace in general, hnf for euc. rings)
 
number hnfdet ()
 det via HNF Primzahlen als long long int, müssen noch in number umgewandelt werden?
 
void hnf ()
 transforms INPLACE to HNF
 
void howell ()
 dito, but Howell form (only different for zero-divsors)
 
void swapMatrix (bigintmat *a)
 
bigintmatmodhnf (number p, coeffs c)
 computes HNF(this | p*I)
 
bigintmatmodgauss (number p, coeffs c)
 
void skaldiv (number b)
 Macht Ganzzahldivision aller Matrixeinträge mit b.
 
void colskaldiv (int j, number b)
 Macht Ganzzahldivision aller j-ten Spalteneinträge mit b.
 
void mod (number p)
 Reduziert komplette Matrix modulo p.
 
bigintmatinpmod (number p, coeffs c)
 Liefert Kopie der Matrix zurück, allerdings im Ring Z modulo p.
 
number content ()
 the content, the gcd of all entries. Only makes sense for Euclidean rings (or possibly constructive PIR)
 
void simplifyContentDen (number *den)
 ensures that Gcd(den, content)=1 enden hier wieder
 

Private Attributes

coeffs m_coeffs
 
number * v
 
int row
 
int col
 

Detailed Description

Matrices of numbers.

Matrices are stored as 1-dim c-arrays but interpreted 2-dim as matrices. Both modes of addressing are supported, note however, that the 1-dim addressing starts at 0, the 2-dim at 1.

Matrices are meant to represent column modules, thus the default operations are always by column.

While basic operations are supported over any ring (coeff), some more advanced ones require more special rings: eg. echelon forms, solving of linear equations is only effective over principal ideal or even Euclidean rings.

Be careful with the get/set/view/rawset functions to understand which arguments are copied/ deleted or only assigned.

@Note: no reference counting here!

Definition at line 50 of file bigintmat.h.

Constructor & Destructor Documentation

◆ bigintmat() [1/3]

bigintmat::bigintmat ( )
inline

Definition at line 59 of file bigintmat.h.

59: m_coeffs(NULL), v(NULL), row(1), col(0){}
coeffs m_coeffs
Definition bigintmat.h:53
number * v
Definition bigintmat.h:54
#define NULL
Definition omList.c:12

◆ bigintmat() [2/3]

bigintmat::bigintmat ( int r,
int c,
const coeffs n )
inline

constructor: the r times c zero-matrix. Beware that the creation of a large zero matrix is expensive in terms of time and memory.

Definition at line 69 of file bigintmat.h.

69 : m_coeffs(n), v(NULL), row(r), col(c)
70 {
71 assume (rows() >= 0);
72 assume (cols() >= 0);
73
74 const int l = r*c;
75
76 if (l>0) /*(r>0) && (c>0) */
77 {
78 v = (number *)omAlloc(sizeof(number)*l);
79
80 assume (basecoeffs() != NULL);
81 for (int i = l - 1; i>=0; i--)
82 {
83 v[i] = n_Init(0, basecoeffs());
84 }
85 }
86 }
int l
Definition cfEzgcd.cc:100
int i
Definition cfEzgcd.cc:132
int cols() const
Definition bigintmat.h:144
int rows() const
Definition bigintmat.h:145
coeffs basecoeffs() const
Definition bigintmat.h:146
static FORCE_INLINE number n_Init(long i, const coeffs r)
a number representing i in the given coeff field/ring r
Definition coeffs.h:539
#define assume(x)
Definition mod2.h:387
#define omAlloc(size)

◆ bigintmat() [3/3]

bigintmat::bigintmat ( const bigintmat * m)
inline

copy constructor

Definition at line 89 of file bigintmat.h.

89 : m_coeffs(m->basecoeffs()), v(NULL), row(m->rows()), col(m->cols())
90 {
91 const int l = row*col;
92
93 if (l > 0)
94 {
95 assume (rows() > 0);
96 assume (cols() > 0);
97
98 assume (m->v != NULL);
99
100 v = (number *)omAlloc(sizeof(number)*row*col);
101
102 assume (basecoeffs() != NULL);
103
104 for (int i = l-1; i>=0; i--)
105 {
106 v[i] = n_Copy((*m)[i], basecoeffs());
107 }
108 }
109 }
int m
Definition cfEzgcd.cc:128
static FORCE_INLINE number n_Copy(number n, const coeffs r)
return a copy of 'n'
Definition coeffs.h:455

◆ ~bigintmat()

bigintmat::~bigintmat ( )
inline

canonical destructor.

Definition at line 149 of file bigintmat.h.

150 {
151 if (v!=NULL)
152 {
153 for (int i=row*col-1;i>=0; i--) { n_Delete(&(v[i]), basecoeffs()); }
154 omFreeSize((ADDRESS)v, sizeof(number)*row*col);
155 v=NULL;
156 }
157 }
void * ADDRESS
Definition auxiliary.h:119
static FORCE_INLINE void n_Delete(number *p, const coeffs r)
delete 'p'
Definition coeffs.h:459
#define omFreeSize(addr, size)

Member Function Documentation

◆ add()

bool bigintmat::add ( bigintmat * b)

Addiert zur Matrix die Matrix b dazu. Return false => an error occurred.

Definition at line 888 of file bigintmat.cc.

889{
890 if ((b->rows() != row) || (b->cols() != col))
891 {
892 WerrorS("Error in bigintmat::add. Dimensions do not agree!");
893 return false;
894 }
895 if (!nCoeffs_are_equal(basecoeffs(), b->basecoeffs()))
896 {
897 WerrorS("Error in bigintmat::add. coeffs do not agree!");
898 return false;
899 }
900 for (int i=1; i<=row; i++)
901 {
902 for (int j=1; j<=col; j++)
903 {
904 rawset(i, j, n_Add(b->view(i,j), view(i,j), basecoeffs()));
905 }
906 }
907 return true;
908}
bool nCoeffs_are_equal(coeffs r, coeffs s)
CanonicalForm b
Definition cfModGcd.cc:4111
number view(int i, int j) const
view an entry an entry. NOTE: starts at [1,1]
Definition bigintmat.cc:125
void rawset(int i, number n, const coeffs C=NULL)
replace an entry with the given number n (only delete old). NOTE: starts at [0]. Should be named set_...
Definition bigintmat.h:196
static FORCE_INLINE number n_Add(number a, number b, const coeffs r)
return the sum of 'a' and 'b', i.e., a+b
Definition coeffs.h:651
int j
Definition facHensel.cc:110
void WerrorS(const char *s)
Definition feFopen.cc:24

◆ addcol()

bool bigintmat::addcol ( int i,
int j,
number a,
coeffs c )

addiert a-faches der j-ten Spalte zur i-ten dazu

Definition at line 953 of file bigintmat.cc.

954{
955 if ((i>col) || (j>col) || (i<1) || (j<1))
956 {
957 WerrorS("Error in addcol: Index out of range!");
958 return false;
959 }
960 if (!nCoeffs_are_equal(c, basecoeffs()))
961 {
962 WerrorS("Error in addcol: coeffs do not agree!");
963 return false;
964 }
965 number t1, t2, t3;
966 for (int k=1; k<=row; k++)
967 {
968 t1 = view(k, j);
969 t2 = view(k, i);
970 t3 = n_Mult(t1, a, basecoeffs());
971 n_InpAdd(t3, t2, basecoeffs());
972 rawset(k, i, t3);
973 }
974 return true;
975}
int k
Definition cfEzgcd.cc:99
static FORCE_INLINE number n_Mult(number a, number b, const coeffs r)
return the product of 'a' and 'b', i.e., a*b
Definition coeffs.h:637
static FORCE_INLINE void n_InpAdd(number &a, number b, const coeffs r)
addition of 'a' and 'b'; replacement of 'a' by the sum a+b
Definition coeffs.h:647

◆ addrow()

bool bigintmat::addrow ( int i,
int j,
number a,
coeffs c )

... Zeile ...

Definition at line 977 of file bigintmat.cc.

978{
979 if ((i>row) || (j>row) || (i<1) || (j<1))
980 {
981 WerrorS("Error in addrow: Index out of range!");
982 return false;
983 }
984 if (!nCoeffs_are_equal(c, basecoeffs()))
985 {
986 WerrorS("Error in addrow: coeffs do not agree!");
987 return false;
988 }
989 number t1, t2, t3;
990 for (int k=1; k<=col; k++)
991 {
992 t1 = view(j, k);
993 t2 = view(i, k);
994 t3 = n_Mult(t1, a, basecoeffs());
995 n_InpAdd(t3, t2, basecoeffs());
996 rawset(i, k, t3);
997 }
998 return true;
999}

◆ appendCol()

void bigintmat::appendCol ( bigintmat * a)

horizontally join the matrices, m <- m|a

Definition at line 1077 of file bigintmat.cc.

1078{
1079 coeffs R = basecoeffs();
1080 int ay = a->cols();
1081 int ax = a->rows();
1082 assume(row == ax);
1083
1085
1086 bigintmat * tmp = new bigintmat(rows(), cols() + ay, R);
1087 tmp->concatcol(this, a);
1088 this->swapMatrix(tmp);
1089 delete tmp;
1090}
void swapMatrix(bigintmat *a)
void concatcol(bigintmat *a, bigintmat *b)
#define R
Definition sirandom.c:27

◆ basecoeffs()

coeffs bigintmat::basecoeffs ( ) const
inline

Definition at line 146 of file bigintmat.h.

146{ return m_coeffs; }

◆ colIsZero()

int bigintmat::colIsZero ( int i)

Definition at line 1571 of file bigintmat.cc.

1572{
1573 coeffs R = basecoeffs();
1574 for(int i=1; i<=rows(); i++)
1575 if (!n_IsZero(view(i, j), R)) return FALSE;
1576 return TRUE;
1577}
#define TRUE
Definition auxiliary.h:100
#define FALSE
Definition auxiliary.h:96
static FORCE_INLINE BOOLEAN n_IsZero(number n, const coeffs r)
TRUE iff 'n' represents the zero element.
Definition coeffs.h:468

◆ cols()

int bigintmat::cols ( ) const
inline

Definition at line 144 of file bigintmat.h.

144{ return col; }

◆ colskaldiv()

void bigintmat::colskaldiv ( int j,
number b )

Macht Ganzzahldivision aller j-ten Spalteneinträge mit b.

Definition at line 1865 of file bigintmat.cc.

1866{
1867 number tmp1, tmp2;
1868 for (int i=1; i<=row; i++)
1869 {
1870 tmp1 = view(i, j);
1871 tmp2 = n_Div(tmp1, b, basecoeffs());
1872 rawset(i, j, tmp2);
1873 }
1874}
static FORCE_INLINE number n_Div(number a, number b, const coeffs r)
return the quotient of 'a' and 'b', i.e., a/b; raises an error if 'b' is not invertible in r exceptio...
Definition coeffs.h:616
CFList tmp1
Definition facFqBivar.cc:75
CFList tmp2
Definition facFqBivar.cc:75

◆ colskalmult()

void bigintmat::colskalmult ( int i,
number a,
coeffs c )

Multipliziert zur i-ten Spalte den Skalar a hinzu.

Definition at line 1001 of file bigintmat.cc.

1002{
1003 if ((i>=1) && (i<=col) && (nCoeffs_are_equal(c, basecoeffs())))
1004 {
1005 number t, tmult;
1006 for (int j=1; j<=row; j++)
1007 {
1008 t = view(j, i);
1009 tmult = n_Mult(a, t, basecoeffs());
1010 rawset(j, i, tmult);
1011 }
1012 }
1013 else
1014 WerrorS("Error in colskalmult");
1015}

◆ coltransform()

void bigintmat::coltransform ( int i,
int j,
number a,
number b,
number c,
number d )

transforms cols (i,j) using the 2x2 matrix ((a,b)(c,d)) (hopefully)

Definition at line 1878 of file bigintmat.cc.

1879{
1880 number tmp1, tmp2, tmp3, tmp4;
1881 for (int i=1; i<=row; i++)
1882 {
1883 tmp1 = get(i, j);
1884 tmp2 = get(i, k);
1885 tmp3 = n_Mult(tmp1, a, basecoeffs());
1886 tmp4 = n_Mult(tmp2, b, basecoeffs());
1887 n_InpAdd(tmp3, tmp4, basecoeffs());
1888 n_Delete(&tmp4, basecoeffs());
1889
1890 n_InpMult(tmp1, c, basecoeffs());
1891 n_InpMult(tmp2, d, basecoeffs());
1894
1895 set(i, j, tmp3);
1896 set(i, k, tmp1);
1898 n_Delete(&tmp3, basecoeffs());
1899 }
1900}
number get(int i, int j) const
get a copy of an entry. NOTE: starts at [1,1]
Definition bigintmat.cc:117
void set(int i, int j, number n, const coeffs C=NULL)
replace an entry with a copy (delete old + copy new!). NOTE: starts at [1,1]
Definition bigintmat.cc:93
static FORCE_INLINE void n_InpMult(number &a, number b, const coeffs r)
multiplication of 'a' and 'b'; replacement of 'a' by the product a*b
Definition coeffs.h:642

◆ compare()

int bigintmat::compare ( const bigintmat * op) const

Definition at line 360 of file bigintmat.cc.

361{
362 assume (basecoeffs() == op->basecoeffs() );
363
364#ifndef SING_NDEBUG
365 if (basecoeffs() != op->basecoeffs() )
366 WerrorS("wrong bigintmat comparison: different basecoeffs!\n");
367#endif
368
369 if ((col!=1) ||(op->cols()!=1))
370 {
371 if((col!=op->cols())
372 || (row!=op->rows()))
373 return -2;
374 }
375
376 int i;
377 for (i=0; i<si_min(row*col,op->rows()*op->cols()); i++)
378 {
379 if ( n_Greater(v[i], (*op)[i], basecoeffs()) )
380 return 1;
381 else if (! n_Equal(v[i], (*op)[i], basecoeffs()))
382 return -1;
383 }
384
385 for (; i<row; i++)
386 {
387 if ( n_GreaterZero(v[i], basecoeffs()) )
388 return 1;
389 else if (! n_IsZero(v[i], basecoeffs()) )
390 return -1;
391 }
392 for (; i<op->rows(); i++)
393 {
394 if ( n_GreaterZero((*op)[i], basecoeffs()) )
395 return -1;
396 else if (! n_IsZero((*op)[i], basecoeffs()) )
397 return 1;
398 }
399 return 0;
400}
static int si_min(const int a, const int b)
Definition auxiliary.h:125
static FORCE_INLINE BOOLEAN n_GreaterZero(number n, const coeffs r)
ordered fields: TRUE iff 'n' is positive; in Z/pZ: TRUE iff 0 < m <= roundedBelow(p/2),...
Definition coeffs.h:498
static FORCE_INLINE BOOLEAN n_Greater(number a, number b, const coeffs r)
ordered fields: TRUE iff 'a' is larger than 'b'; in Z/pZ: TRUE iff la > lb, where la and lb are the l...
Definition coeffs.h:515
static FORCE_INLINE BOOLEAN n_Equal(number a, number b, const coeffs r)
TRUE iff 'a' and 'b' represent the same number; they may have different representations.
Definition coeffs.h:464

◆ concatcol()

void bigintmat::concatcol ( bigintmat * a,
bigintmat * b )

Definition at line 1092 of file bigintmat.cc.

1092 {
1093 int ay = a->cols();
1094 int ax = a->rows();
1095 int by = b->cols();
1096 int bx = b->rows();
1097 number tmp;
1098
1099 assume(row==ax && row == bx && ay+by ==col);
1100
1102
1103 for (int i=1; i<=ax; i++)
1104 {
1105 for (int j=1; j<=ay; j++)
1106 {
1107 tmp = a->view(i,j);
1108 set(i, j, tmp);
1109 }
1110 }
1111 for (int i=1; i<=bx; i++)
1112 {
1113 for (int j=1; j<=by; j++)
1114 {
1115 tmp = b->view(i,j);
1116 set(i, j+ay, tmp);
1117 }
1118 }
1119}

◆ concatrow()

void bigintmat::concatrow ( bigintmat * a,
bigintmat * b )

Fügt zwei Matrixen untereinander/nebeneinander in gegebene Matrix ein, bzw spaltet gegebenen Matrix auf.

Definition at line 1033 of file bigintmat.cc.

1034{
1035 int ay = a->cols();
1036 int ax = a->rows();
1037 int by = b->cols();
1038 int bx = b->rows();
1039 number tmp;
1040 if (!((col == ay) && (col == by) && (ax+bx == row)))
1041 {
1042 WerrorS("Error in concatrow. Dimensions must agree!");
1043 return;
1044 }
1045 if (!(nCoeffs_are_equal(a->basecoeffs(), basecoeffs()) && nCoeffs_are_equal(b->basecoeffs(), basecoeffs())))
1046 {
1047 WerrorS("Error in concatrow. coeffs do not agree!");
1048 return;
1049 }
1050 for (int i=1; i<=ax; i++)
1051 {
1052 for (int j=1; j<=ay; j++)
1053 {
1054 tmp = a->get(i,j);
1055 set(i, j, tmp);
1056 n_Delete(&tmp, basecoeffs());
1057 }
1058 }
1059 for (int i=1; i<=bx; i++)
1060 {
1061 for (int j=1; j<=by; j++)
1062 {
1063 tmp = b->get(i,j);
1064 set(i+ax, j, tmp);
1065 n_Delete(&tmp, basecoeffs());
1066 }
1067 }
1068}

◆ content()

number bigintmat::content ( )

the content, the gcd of all entries. Only makes sense for Euclidean rings (or possibly constructive PIR)

Definition at line 2658 of file bigintmat.cc.

2659{
2660 coeffs r = basecoeffs();
2661 number g = get(1,1), h;
2662 int n=rows()*cols();
2663 for(int i=1; i<n && !n_IsOne(g, r); i++)
2664 {
2665 h = n_Gcd(g, view(i), r);
2666 n_Delete(&g, r);
2667 g=h;
2668 }
2669 return g;
2670}
g
Definition cfModGcd.cc:4098
static FORCE_INLINE number n_Gcd(number a, number b, const coeffs r)
in Z: return the gcd of 'a' and 'b' in Z/nZ, Z/2^kZ: computed as in the case Z in Z/pZ,...
Definition coeffs.h:665
static FORCE_INLINE BOOLEAN n_IsOne(number n, const coeffs r)
TRUE iff 'n' represents the one element.
Definition coeffs.h:472
STATIC_VAR Poly * h
Definition janet.cc:971

◆ copy()

bool bigintmat::copy ( bigintmat * b)

Kopiert Einträge von b auf Bigintmat.

Definition at line 1253 of file bigintmat.cc.

1254{
1255 if ((b->rows() != row) || (b->cols() != col))
1256 {
1257 WerrorS("Error in bigintmat::copy. Dimensions do not agree!");
1258 return false;
1259 }
1260 if (!nCoeffs_are_equal(basecoeffs(), b->basecoeffs()))
1261 {
1262 WerrorS("Error in bigintmat::copy. coeffs do not agree!");
1263 return false;
1264 }
1265 number t1;
1266 for (int i=1; i<=row; i++)
1267 {
1268 for (int j=1; j<=col; j++)
1269 {
1270 t1 = b->view(i, j);
1271 set(i, j, t1);
1272 }
1273 }
1274 return true;
1275}

◆ copySubmatInto()

void bigintmat::copySubmatInto ( bigintmat * B,
int sr,
int sc,
int nr,
int nc,
int tr,
int tc )

copy the submatrix of b, staring at (a,b) having n rows, m cols into the given matrix at pos. (c,d) needs c+n, d+m <= rows, cols a+n, b+m <= b.rows(), b.cols()

Definition at line 1281 of file bigintmat.cc.

1282{
1283 number t1;
1284 for (int i=1; i<=n; i++)
1285 {
1286 for (int j=1; j<=m; j++)
1287 {
1288 t1 = B->view(a+i-1, b+j-1);
1289 set(c+i-1, d+j-1, t1);
1290 }
1291 }
1292}
b *CanonicalForm B
Definition facBivar.cc:52

◆ det()

number bigintmat::det ( )

det (via LaPlace in general, hnf for euc. rings)

Definition at line 1506 of file bigintmat.cc.

1507{
1508 assume (row==col);
1509
1510 if (col == 1)
1511 return get(1, 1);
1512 // should work as well in Z/pZ of type n_Zp?
1513 // relies on XExtGcd and the other euc. functions.
1515 return hnfdet();
1516 }
1517 number sum = n_Init(0, basecoeffs());
1518 number t1, t2, t3, t4;
1519 bigintmat *b;
1520 for (int i=1; i<=row; i++) {
1521 b = elim(i, 1);
1522 t1 = get(i, 1);
1523 t2 = b->det();
1524 t3 = n_Mult(t1, t2, basecoeffs());
1525 t4 = n_Copy(sum, basecoeffs());
1526 n_Delete(&sum, basecoeffs());
1527 if ((i+1)>>1<<1==(i+1))
1528 sum = n_Add(t4, t3, basecoeffs());
1529 else
1530 sum = n_Sub(t4, t3, basecoeffs());
1531 n_Delete(&t1, basecoeffs());
1532 n_Delete(&t2, basecoeffs());
1533 n_Delete(&t3, basecoeffs());
1534 n_Delete(&t4, basecoeffs());
1535 }
1536 return sum;
1537}
number hnfdet()
det via HNF Primzahlen als long long int, müssen noch in number umgewandelt werden?
bigintmat * elim(int i, int j)
Liefert Streichungsmatrix (i-te Zeile und j-te Spalte gestrichen) zurück.
@ n_Zn
only used if HAVE_RINGS is defined
Definition coeffs.h:44
@ n_Z
only used if HAVE_RINGS is defined
Definition coeffs.h:43
static FORCE_INLINE number n_Sub(number a, number b, const coeffs r)
return the difference of 'a' and 'b', i.e., a-b
Definition coeffs.h:656
static FORCE_INLINE n_coeffType getCoeffType(const coeffs r)
Returns the type of coeffs domain.
Definition coeffs.h:429

◆ elim()

bigintmat * bigintmat::elim ( int i,
int j )

Liefert Streichungsmatrix (i-te Zeile und j-te Spalte gestrichen) zurück.

Definition at line 1375 of file bigintmat.cc.

1376{
1377 if ((i<=0) || (i>row) || (j<=0) || (j>col))
1378 return NULL;
1379 int cx, cy;
1380 cx=1;
1381 cy=1;
1382 number t;
1383 bigintmat *b = new bigintmat(row-1, col-1, basecoeffs());
1384 for (int k=1; k<=row; k++) {
1385 if (k!=i)
1386 {
1387 cy=1;
1388 for (int l=1; l<=col; l++)
1389 {
1390 if (l!=j)
1391 {
1392 t = get(k, l);
1393 b->set(cx, cy, t);
1394 n_Delete(&t, basecoeffs());
1395 cy++;
1396 }
1397 }
1398 cx++;
1399 }
1400 }
1401 return b;
1402}

◆ extendCols()

void bigintmat::extendCols ( int i)

append i zero-columns to the matrix

Definition at line 1070 of file bigintmat.cc.

1071{
1072 bigintmat * tmp = new bigintmat(rows(), i, basecoeffs());
1073 appendCol(tmp);
1074 delete tmp;
1075}
void appendCol(bigintmat *a)
horizontally join the matrices, m <- m|a

◆ findcolnonzero()

int bigintmat::findcolnonzero ( int j)

find index of 1st non-zero entry in column j

Definition at line 729 of file bigintmat.cc.

730{
731 for (int i=row; i>=1; i--)
732 {
733 if (!n_IsZero(view(i,j), basecoeffs()))
734 {
735 return i;
736 }
737 }
738 return 0;
739}

◆ findnonzero()

int bigintmat::findnonzero ( int i)

find index of 1st non-zero entry in row i

Definition at line 717 of file bigintmat.cc.

718{
719 for (int j=1; j<=col; j++)
720 {
721 if (!n_IsZero(view(i,j), basecoeffs()))
722 {
723 return j;
724 }
725 }
726 return 0;
727}

◆ get() [1/2]

number bigintmat::get ( int i) const

get a copy of an entry. NOTE: starts at [0]

Definition at line 101 of file bigintmat.cc.

102{
103 assume (i >= 0);
104 assume (i<rows()*cols());
105
106 return n_Copy(v[i], basecoeffs());
107}

◆ get() [2/2]

number bigintmat::get ( int i,
int j ) const

get a copy of an entry. NOTE: starts at [1,1]

Definition at line 117 of file bigintmat.cc.

118{
119 assume (i > 0 && j > 0);
120 assume (i <= rows() && j <= cols());
121
122 return get(index(i, j));
123}
int index(int r, int c) const
helper function to map from 2-dim coordinates, starting by 1 to 1-dim coordinate, starting by 0
Definition bigintmat.h:161

◆ getcol()

void bigintmat::getcol ( int j,
bigintmat * a )

copies the j-th column into the matrix a - which needs to be pre-allocated with the correct size.

Definition at line 741 of file bigintmat.cc.

742{
743 assume((j<=col) && (j>=1));
744 if (((a->rows() != row) || (a->cols() != 1)) && ((a->rows() != 1) || (a->cols() != row)))
745 {
746 assume(0);
747 WerrorS("Error in getcol. Dimensions must agree!");
748 return;
749 }
751 {
753 number t1, t2;
754 for (int i=1; i<=row;i++)
755 {
756 t1 = get(i,j);
757 t2 = f(t1, basecoeffs(), a->basecoeffs());
758 a->set(i-1,t1);
759 n_Delete(&t1, basecoeffs());
760 n_Delete(&t2, a->basecoeffs());
761 }
762 return;
763 }
764 number t1;
765 for (int i=1; i<=row;i++)
766 {
767 t1 = view(i,j);
768 a->set(i-1,t1);
769 }
770}
FILE * f
Definition checklibs.c:9
static FORCE_INLINE nMapFunc n_SetMap(const coeffs src, const coeffs dst)
set the mapping function pointers for translating numbers from src to dst
Definition coeffs.h:701
number(* nMapFunc)(number a, const coeffs src, const coeffs dst)
maps "a", which lives in src, into dst
Definition coeffs.h:80

◆ getColRange()

void bigintmat::getColRange ( int j,
int no,
bigintmat * a )

copies the no-columns staring by j (so j...j+no-1) into the pre-allocated a

Definition at line 772 of file bigintmat.cc.

773{
774 number t1;
775 for(int ii=0; ii< no; ii++)
776 {
777 for (int i=1; i<=row;i++)
778 {
779 t1 = view(i, ii+j);
780 a->set(i, ii+1, t1);
781 }
782 }
783}

◆ getrow()

void bigintmat::getrow ( int i,
bigintmat * a )

Schreibt i-te Zeile in Vektor (Matrix) a.

Definition at line 785 of file bigintmat.cc.

786{
787 if ((i>row) || (i<1))
788 {
789 WerrorS("Error in getrow: Index out of range!");
790 return;
791 }
792 if (((a->rows() != 1) || (a->cols() != col)) && ((a->rows() != col) || (a->cols() != 1)))
793 {
794 WerrorS("Error in getrow. Dimensions must agree!");
795 return;
796 }
798 {
800 number t1, t2;
801 for (int j=1; j<=col;j++)
802 {
803 t1 = get(i,j);
804 t2 = f(t1, basecoeffs(), a->basecoeffs());
805 a->set(j-1,t2);
806 n_Delete(&t1, basecoeffs());
807 n_Delete(&t2, a->basecoeffs());
808 }
809 return;
810 }
811 number t1;
812 for (int j=1; j<=col;j++)
813 {
814 t1 = get(i,j);
815 a->set(j-1,t1);
816 n_Delete(&t1, basecoeffs());
817 }
818}

◆ getwid()

int * bigintmat::getwid ( int maxwid)

Definition at line 574 of file bigintmat.cc.

575{
576 int const c = /*2**/(col-1)+1;
577 int * wv = (int*)omAlloc(sizeof(int)*col*row);
578 int * cwv = (int*)omAlloc(sizeof(int)*col);
579 for (int j=0; j<col; j++)
580 {
581 cwv[j] = 0;
582 for (int i=0; i<row; i++)
583 {
584 StringSetS("");
585 n_Write(v[col*i+j], basecoeffs());
586 char * tmp = StringEndS();
587 const int _nl = strlen(tmp);
588 wv[col*i+j] = _nl;
589 if (_nl > cwv[j]) cwv[j]=_nl;
590 omFree(tmp);
591 }
592 }
593
594 // Groesse verkleinern, bis < maxwid
595 if (intArrSum(cwv, col)+c > maxwid)
596 {
597 int j = findLongest(cwv, col);
598 cwv[j] = getShorter(wv, cwv[j], j, col, row);
599 }
600 omFree(wv);
601 return cwv;
602}
static int intArrSum(int *a, int length)
Definition bigintmat.cc:523
static int findLongest(int *a, int length)
Definition bigintmat.cc:531
static int getShorter(int *a, int l, int j, int cols, int rows)
Definition bigintmat.cc:546
static FORCE_INLINE void n_Write(number n, const coeffs r, const BOOLEAN bShortOut=TRUE)
Definition coeffs.h:592
#define omFree(addr)
void StringSetS(const char *st)
Definition reporter.cc:128
char * StringEndS()
Definition reporter.cc:151

◆ hnf()

void bigintmat::hnf ( )

transforms INPLACE to HNF

Definition at line 1654 of file bigintmat.cc.

1655{
1656 // Laufen von unten nach oben und von links nach rechts
1657 // CF: TODO: for n_Z: write a recursive version. This one will
1658 // have exponential blow-up. Look at Michianchio
1659 // Alternatively, do p-adic det and modular method
1660
1661#if 0
1662 char * s;
1663 ::PrintS("mat over Z is \n");
1664 ::Print("%s\n", s = nCoeffString(basecoeffs()));
1665 omFree(s);
1666 Print();
1667 ::Print("\n(%d x %d)\n", rows(), cols());
1668#endif
1669
1670 int i = rows();
1671 int j = cols();
1672 number q = n_Init(0, basecoeffs());
1673 number one = n_Init(1, basecoeffs());
1674 number minusone = n_Init(-1, basecoeffs());
1675 number tmp1 = n_Init(0, basecoeffs());
1676 number tmp2 = n_Init(0, basecoeffs());
1677 number co1, co2, co3, co4;
1678 number ggt = n_Init(0, basecoeffs());
1679
1680 while ((i>0) && (j>0))
1681 {
1682 // Falls erstes Nicht-Null-Element in Zeile i nicht existiert, oder hinter Spalte j vorkommt, gehe in nächste Zeile
1683 if ((findnonzero(i)==0) || (findnonzero(i)>j))
1684 {
1685 i--;
1686 }
1687 else
1688 {
1689 // Laufe von links nach rechts durch die Zeile:
1690 for (int l=1; l<=j-1; l++)
1691 {
1693 tmp1 = get(i, l);
1694 // Falls Eintrag (im folgenden x genannt) gleich 0, gehe eine Spalte weiter. Ansonsten...
1695 if (!n_IsZero(tmp1, basecoeffs()))
1696 {
1698 tmp2 = get(i, l+1);
1699 // Falls Eintrag (i.f. y g.) rechts daneben gleich 0, tausche beide Spalten, sonst...
1700 if (!n_IsZero(tmp2, basecoeffs()))
1701 {
1702 n_Delete(&ggt, basecoeffs());
1703 ggt = n_XExtGcd(tmp1, tmp2, &co1, &co2, &co3, &co4, basecoeffs());
1704 // Falls x=ggT(x, y), tausche die beiden Spalten und ziehe die (neue) rechte Spalte so häufig von der linken ab, dass an der ehemaligen Stelle von x nun eine 0 steht. Dazu:
1705 if (n_Equal(tmp1, ggt, basecoeffs()))
1706 {
1707 swap(l, l+1);
1708 n_Delete(&q, basecoeffs());
1709 q = n_Div(tmp2, ggt, basecoeffs());
1710 q = n_InpNeg(q, basecoeffs());
1711 // Dann addiere das -q-fache der (neuen) rechten Spalte zur linken dazu. Damit erhalten wir die gewünschte 0
1712
1713 addcol(l, l+1, q, basecoeffs());
1714 n_Delete(&q, basecoeffs());
1715 }
1716 else if (n_Equal(tmp1, minusone, basecoeffs()))
1717 {
1718 // Falls x=-1, so ist x=-ggt(x, y). Dann gehe wie oben vor, multipliziere aber zuerst die neue rechte Spalte (die mit x) mit -1
1719 // Die Berechnung von q (=y/ggt) entfällt, da ggt=1
1720 swap(l, l+1);
1721 colskalmult(l+1, minusone, basecoeffs());
1723 addcol(l, l+1, tmp2, basecoeffs());
1724 }
1725 else
1726 {
1727 // CF: use the 2x2 matrix (co1, co2)(co3, co4) to
1728 // get the gcd in position and the 0 in the other:
1729#ifdef CF_DEB
1730 ::PrintS("applying trafo\n");
1731 StringSetS("");
1732 n_Write(co1, basecoeffs()); StringAppendS("\t");
1733 n_Write(co2, basecoeffs()); StringAppendS("\t");
1734 n_Write(co3, basecoeffs()); StringAppendS("\t");
1735 n_Write(co4, basecoeffs()); StringAppendS("\t");
1736 ::Print("%s\nfor l=%d\n", StringEndS(), l);
1737 {char * s = String();
1738 ::Print("to %s\n", s);omFree(s);};
1739#endif
1740 coltransform(l, l+1, co3, co4, co1, co2);
1741#ifdef CF_DEB
1742 {char * s = String();
1743 ::Print("gives %s\n", s);}
1744#endif
1745 }
1746 n_Delete(&co1, basecoeffs());
1747 n_Delete(&co2, basecoeffs());
1748 n_Delete(&co3, basecoeffs());
1749 n_Delete(&co4, basecoeffs());
1750 }
1751 else
1752 {
1753 swap(l, l+1);
1754 }
1755 // Dann betrachte die vormals rechte Spalte als neue linke, und die rechts daneben als neue rechte.
1756 }
1757 }
1758
1759 // normalize by units:
1760 if (!n_IsZero(view(i, j), basecoeffs()))
1761 {
1762 number u = n_GetUnit(view(i, j), basecoeffs());
1763 if (!n_IsOne(u, basecoeffs()))
1764 {
1765 colskaldiv(j, u);
1766 }
1767 n_Delete(&u, basecoeffs());
1768 }
1769 // Zum Schluss mache alle Einträge rechts vom Diagonalelement betragsmäßig kleiner als dieses
1770 for (int l=j+1; l<=col; l++)
1771 {
1772 n_Delete(&q, basecoeffs());
1773 q = n_QuotRem(view(i, l), view(i, j), NULL, basecoeffs());
1774 q = n_InpNeg(q, basecoeffs());
1775 addcol(l, j, q, basecoeffs());
1776 }
1777 i--;
1778 j--;
1779 // Dann betrachte die Zeile darüber und gehe dort wie vorher vor
1780 }
1781 }
1782 n_Delete(&q, basecoeffs());
1785 n_Delete(&ggt, basecoeffs());
1786 n_Delete(&one, basecoeffs());
1787 n_Delete(&minusone, basecoeffs());
1788
1789#if 0
1790 ::PrintS("hnf over Z is \n");
1791 Print();
1792 ::Print("\n(%d x %d)\n", rows(), cols());
1793#endif
1794}
#define swap(_i, _j)
void Print()
IO: simply prints the matrix to the current output (screen?)
Definition bigintmat.cc:437
void colskaldiv(int j, number b)
Macht Ganzzahldivision aller j-ten Spalteneinträge mit b.
void coltransform(int i, int j, number a, number b, number c, number d)
transforms cols (i,j) using the 2x2 matrix ((a,b)(c,d)) (hopefully)
bool addcol(int i, int j, number a, coeffs c)
addiert a-faches der j-ten Spalte zur i-ten dazu
Definition bigintmat.cc:953
int findnonzero(int i)
find index of 1st non-zero entry in row i
Definition bigintmat.cc:717
void colskalmult(int i, number a, coeffs c)
Multipliziert zur i-ten Spalte den Skalar a hinzu.
void one()
Macht Matrix (Falls quadratisch) zu Einheitsmatrix.
char * String()
IO: String returns a singular string containing the matrix, needs freeing afterwards.
Definition bigintmat.cc:430
static FORCE_INLINE number n_QuotRem(number a, number b, number *q, const coeffs r)
Definition coeffs.h:682
static FORCE_INLINE char * nCoeffString(const coeffs cf)
TODO: make it a virtual method of coeffs, together with: Decompose & Compose, rParameter & rPar.
Definition coeffs.h:952
static FORCE_INLINE number n_InpNeg(number n, const coeffs r)
in-place negation of n MUST BE USED: n = n_InpNeg(n) (no copy is returned)
Definition coeffs.h:558
static FORCE_INLINE number n_GetUnit(number n, const coeffs r)
in Z: 1 in Z/kZ (where k is not a prime): largest divisor of n (taken in Z) that is co-prime with k i...
Definition coeffs.h:535
static FORCE_INLINE number n_XExtGcd(number a, number b, number *s, number *t, number *u, number *v, const coeffs r)
Definition coeffs.h:674
const CanonicalForm int s
Definition facAbsFact.cc:51
void StringAppendS(const char *st)
Definition reporter.cc:107
void PrintS(const char *s)
Definition reporter.cc:284

◆ hnfdet()

number bigintmat::hnfdet ( )

det via HNF Primzahlen als long long int, müssen noch in number umgewandelt werden?

Definition at line 1539 of file bigintmat.cc.

1540{
1541 assume (col == row);
1542
1543 if (col == 1)
1544 return get(1, 1);
1545 bigintmat *m = new bigintmat(this);
1546 m->hnf();
1547 number prod = n_Init(1, basecoeffs());
1548 number temp, temp2;
1549 for (int i=1; i<=col; i++) {
1550 temp = m->get(i, i);
1551 temp2 = n_Mult(temp, prod, basecoeffs());
1553 prod = temp2;
1554 n_Delete(&temp, basecoeffs());
1555 }
1556 delete m;
1557 return prod;
1558}
fq_nmod_poly_t prod
Definition facHensel.cc:100

◆ howell()

void bigintmat::howell ( )

dito, but Howell form (only different for zero-divsors)

Definition at line 1579 of file bigintmat.cc.

1580{
1581 coeffs R = basecoeffs();
1582 hnf(); // as a starting point...
1583 if (getCoeffType(R)== n_Z) return; //wrong, need to prune!
1584
1585 int n = cols(), m = rows(), i, j, k;
1586
1587 //make sure, the matrix has enough space. We need no rows+1 columns.
1588 //The resulting Howell form will be pruned to be at most square.
1589 bigintmat * t = new bigintmat(m, m+1, R);
1590 t->copySubmatInto(this, 1, n>m ? n-m+1 : 1, m, n>m ? m : n, 1, n>m ? 2 : m+2-n );
1591 swapMatrix(t);
1592 delete t;
1593 for(i=1; i<= cols(); i++) {
1594 if (!colIsZero(i)) break;
1595 }
1596 assume (i>1);
1597 if (i>cols()) {
1598 t = new bigintmat(rows(), 0, R);
1599 swapMatrix(t);
1600 delete t;
1601 return; // zero matrix found, clearly normal.
1602 }
1603
1604 int last_zero_col = i-1;
1605 for (int c = cols(); c>0; c--) {
1606 for(i=rows(); i>0; i--) {
1607 if (!n_IsZero(view(i, c), R)) break;
1608 }
1609 if (i==0) break; // matrix SHOULD be zero from here on
1610 number a = n_Ann(view(i, c), R);
1611 addcol(last_zero_col, c, a, R);
1612 n_Delete(&a, R);
1613 for(j = c-1; j>last_zero_col; j--) {
1614 for(k=rows(); k>0; k--) {
1615 if (!n_IsZero(view(k, j), R)) break;
1616 if (!n_IsZero(view(k, last_zero_col), R)) break;
1617 }
1618 if (k==0) break;
1619 if (!n_IsZero(view(k, last_zero_col), R)) {
1620 number gcd, co1, co2, co3, co4;
1621 gcd = n_XExtGcd(view(k, last_zero_col), view(k, j), &co1, &co2, &co3, &co4, R);
1622 if (n_Equal(gcd, view(k, j), R)) {
1623 number q = n_Div(view(k, last_zero_col), gcd, R);
1624 q = n_InpNeg(q, R);
1625 addcol(last_zero_col, j, q, R);
1626 n_Delete(&q, R);
1627 } else if (n_Equal(gcd, view(k, last_zero_col), R)) {
1628 swap(last_zero_col, k);
1629 number q = n_Div(view(k, last_zero_col), gcd, R);
1630 q = n_InpNeg(q, R);
1631 addcol(last_zero_col, j, q, R);
1632 n_Delete(&q, R);
1633 } else {
1634 coltransform(last_zero_col, j, co3, co4, co1, co2);
1635 }
1636 n_Delete(&gcd, R);
1637 n_Delete(&co1, R);
1638 n_Delete(&co2, R);
1639 n_Delete(&co3, R);
1640 n_Delete(&co4, R);
1641 }
1642 }
1643 for(k=rows(); k>0; k--) {
1644 if (!n_IsZero(view(k, last_zero_col), R)) break;
1645 }
1646 if (k) last_zero_col--;
1647 }
1648 t = new bigintmat(rows(), cols()-last_zero_col, R);
1649 t->copySubmatInto(this, 1, last_zero_col+1, rows(), cols()-last_zero_col, 1, 1);
1650 swapMatrix(t);
1651 delete t;
1652}
void hnf()
transforms INPLACE to HNF
int colIsZero(int i)
void copySubmatInto(bigintmat *, int sr, int sc, int nr, int nc, int tr, int tc)
copy the submatrix of b, staring at (a,b) having n rows, m cols into the given matrix at pos....
static FORCE_INLINE number n_Ann(number a, const coeffs r)
if r is a ring with zero divisors, return an annihilator!=0 of b otherwise return NULL
Definition coeffs.h:680
int gcd(int a, int b)

◆ index()

int bigintmat::index ( int r,
int c ) const
inline

helper function to map from 2-dim coordinates, starting by 1 to 1-dim coordinate, starting by 0

Definition at line 161 of file bigintmat.h.

162 {
163 assume (rows() >= 0 && cols() >= 0);
164
165 assume (r > 0 && c > 0);
166 assume (r <= rows() && c <= cols());
167
168 const int index = ((r-1)*cols() + (c-1));
169
170 assume (index >= 0 && index < rows() * cols());
171 return index;
172 }

◆ inpmod()

bigintmat * bigintmat::inpmod ( number p,
coeffs c )

Liefert Kopie der Matrix zurück, allerdings im Ring Z modulo p.

◆ inpMult()

void bigintmat::inpMult ( number bintop,
const coeffs C = NULL )

inplace version of skalar mult. CHANGES input.

Definition at line 143 of file bigintmat.cc.

144{
145 assume (C == NULL || C == basecoeffs());
146
147 const int l = rows() * cols();
148
149 for (int i=0; i < l; i++)
150 n_InpMult(v[i], bintop, basecoeffs());
151}

◆ inpTranspose()

void bigintmat::inpTranspose ( )

transpose in place

Definition at line 48 of file bigintmat.cc.

49{
50 int n = row,
51 m = col,
52 nm = n<m?n : m; // the min, describing the square part of the matrix
53 //CF: this is not optimal, but so far, it seems to work
54
55#define swap(_i, _j) \
56 int __i = (_i), __j=(_j); \
57 number c = v[__i]; \
58 v[__i] = v[__j]; \
59 v[__j] = c \
60
61 for (int i=0; i< nm; i++)
62 for (int j=i+1; j< nm; j++)
63 {
64 swap(i*m+j, j*n+i);
65 }
66 if (n<m)
67 for (int i=nm; i<m; i++)
68 for(int j=0; j<n; j++)
69 {
70 swap(j*n+i, i*m+j);
71 }
72 if (n>m)
73 for (int i=nm; i<n; i++)
74 for(int j=0; j<m; j++)
75 {
76 swap(i*m+j, j*n+i);
77 }
78#undef swap
79 row = m;
80 col = n;
81}

◆ isOne()

int bigintmat::isOne ( )

is matrix is identity

Definition at line 1294 of file bigintmat.cc.

1295{
1296 coeffs r = basecoeffs();
1297 if (row==col)
1298 {
1299 for (int i=1; i<=row; i++)
1300 {
1301 for (int j=1; j<=col; j++)
1302 {
1303 if (i==j)
1304 {
1305 if (!n_IsOne(view(i, j), r))
1306 return 0;
1307 }
1308 else
1309 {
1310 if (!n_IsZero(view(i,j), r))
1311 return 0;
1312 }
1313 }
1314 }
1315 }
1316 return 1;
1317}

◆ isZero()

int bigintmat::isZero ( )

Definition at line 1357 of file bigintmat.cc.

1358{
1359 for (int i=1; i<=row; i++) {
1360 for (int j=1; j<=col; j++) {
1361 if (!n_IsZero(view(i,j), basecoeffs()))
1362 return FALSE;
1363 }
1364 }
1365 return TRUE;
1366}

◆ length()

int bigintmat::length ( )
inline

Definition at line 143 of file bigintmat.h.

143{ return col*row; }

◆ mod()

void bigintmat::mod ( number p)

Reduziert komplette Matrix modulo p.

Definition at line 1905 of file bigintmat.cc.

1906{
1907 // produce the matrix in Z/pZ
1908 number tmp1, tmp2;
1909 for (int i=1; i<=row; i++)
1910 {
1911 for (int j=1; j<=col; j++)
1912 {
1913 tmp1 = get(i, j);
1914 tmp2 = n_IntMod(tmp1, p, basecoeffs());
1916 set(i, j, tmp2);
1917 }
1918 }
1919}
int p
Definition cfModGcd.cc:4086
static FORCE_INLINE number n_IntMod(number a, number b, const coeffs r)
for r a field, return n_Init(0,r) always: n_Div(a,b,r)*b+n_IntMod(a,b,r)==a n_IntMod(a,...
Definition coeffs.h:629

◆ modgauss()

bigintmat * bigintmat::modgauss ( number p,
coeffs c )

◆ modhnf()

bigintmat * bigintmat::modhnf ( number p,
coeffs c )

computes HNF(this | p*I)

Definition at line 1823 of file bigintmat.cc.

1824{
1825 coeffs Rp = numbercoeffs(p, R); // R/pR
1826 bigintmat *m = bimChangeCoeff(this, Rp);
1827 m->howell();
1828 bigintmat *a = bimChangeCoeff(m, R);
1829 delete m;
1830 bigintmat *C = new bigintmat(rows(), rows(), R);
1831 int piv = rows(), i = a->cols();
1832 while (piv)
1833 {
1834 if (!i || n_IsZero(a->view(piv, i), R))
1835 {
1836 C->set(piv, piv, p, R);
1837 }
1838 else
1839 {
1840 C->copySubmatInto(a, 1, i, rows(), 1, 1, piv);
1841 i--;
1842 }
1843 piv--;
1844 }
1845 delete a;
1846 return C;
1847}
static coeffs numbercoeffs(number n, coeffs c)
create Z/nA of type n_Zn
Definition bigintmat.cc:20
bigintmat * bimChangeCoeff(bigintmat *a, coeffs cnew)
Liefert Kopier von Matrix a zurück, mit coeffs cnew statt den ursprünglichen.

◆ one()

void bigintmat::one ( )

Macht Matrix (Falls quadratisch) zu Einheitsmatrix.

Definition at line 1319 of file bigintmat.cc.

1320{
1321 if (row==col)
1322 {
1323 number one = n_Init(1, basecoeffs()),
1324 zero = n_Init(0, basecoeffs());
1325 for (int i=1; i<=row; i++)
1326 {
1327 for (int j=1; j<=col; j++)
1328 {
1329 if (i==j)
1330 {
1331 set(i, j, one);
1332 }
1333 else
1334 {
1335 set(i, j, zero);
1336 }
1337 }
1338 }
1339 n_Delete(&one, basecoeffs());
1341 }
1342}
void zero()
Setzt alle Einträge auf 0.

◆ operator*=()

void bigintmat::operator*= ( int intop)

UEberladener *=-Operator (fuer int und bigint) Frage hier: *= verwenden oder lieber = und * einzeln? problem: what about non-commuting rings. Is this from left or right?

Definition at line 134 of file bigintmat.cc.

135{
136 number iop = n_Init(intop, basecoeffs());
137
138 inpMult(iop, basecoeffs());
139
140 n_Delete(&iop, basecoeffs());
141}
void inpMult(number bintop, const coeffs C=NULL)
inplace version of skalar mult. CHANGES input.
Definition bigintmat.cc:143

◆ operator[]() [1/2]

number & bigintmat::operator[] ( int i)
inline

dubious: 1-dim access to 2-dim array. Entries are read row by row.

Definition at line 111 of file bigintmat.h.

112 {
113#ifndef SING_NDEBUG
114 if((i<0)||(i>=row*col))
115 {
116 Werror("wrong bigintmat index:%d\n",i);
117 }
118 assume ( !((i<0)||(i>=row*col)) );
119#endif
120 return v[i]; // Hier sollte imho kein nlCopy rein...
121 }
void Werror(const char *fmt,...)
Definition reporter.cc:189

◆ operator[]() [2/2]

const number & bigintmat::operator[] ( int i) const
inline

Definition at line 122 of file bigintmat.h.

123 {
124#ifndef SING_NDEBUG
125 if((i<0)||(i>=row*col))
126 {
127 Werror("wrong bigintmat index:%d\n",i);
128 }
129 assume ( !((i<0)||(i>=row*col)) );
130#endif
131 return v[i];
132 }

◆ pprint()

void bigintmat::pprint ( int maxwid)

Definition at line 604 of file bigintmat.cc.

605{
606 if ((col==0) || (row==0))
607 PrintS("");
608 else
609 {
610 int * colwid = getwid(maxwid);
611 char * ps;
612 int slength = 0;
613 for (int j=0; j<col; j++)
614 slength += colwid[j]*row;
615 slength += col*row+row;
616 ps = (char*) omAlloc0(sizeof(char)*(slength));
617 int pos = 0;
618 for (int i=0; i<col*row; i++)
619 {
620 StringSetS("");
621 n_Write(v[i], basecoeffs());
622 char * ts = StringEndS();
623 const int _nl = strlen(ts);
624 int cj = i%col;
625 if (_nl > colwid[cj])
626 {
627 StringSetS("");
628 int ci = i/col;
629 StringAppend("[%d,%d]", ci+1, cj+1);
630 char * ph = StringEndS();
631 int phl = strlen(ph);
632 if (phl > colwid[cj])
633 {
634 for (int j=0; j<colwid[cj]-1; j++)
635 ps[pos+j] = ' ';
636 ps[pos+colwid[cj]-1] = '*';
637 }
638 else
639 {
640 for (int j=0; j<colwid[cj]-phl; j++)
641 ps[pos+j] = ' ';
642 for (int j=0; j<phl; j++)
643 ps[pos+colwid[cj]-phl+j] = ph[j];
644 }
645 omFree(ph);
646 }
647 else // Mit Leerzeichen auffüllen und zahl reinschreiben
648 {
649 for (int j=0; j<colwid[cj]-_nl; j++)
650 ps[pos+j] = ' ';
651 for (int j=0; j<_nl; j++)
652 ps[pos+colwid[cj]-_nl+j] = ts[j];
653 }
654 // ", " und (evtl) "\n" einfügen
655 if ((i+1)%col == 0)
656 {
657 if (i != col*row-1)
658 {
659 ps[pos+colwid[cj]] = ',';
660 ps[pos+colwid[cj]+1] = '\n';
661 pos += colwid[cj]+2;
662 }
663 }
664 else
665 {
666 ps[pos+colwid[cj]] = ',';
667 pos += colwid[cj]+1;
668 }
669
670 omFree(ts); // Hier ts zerstören
671 }
672 PrintS(ps);
673 omFree(ps);
674 }
675}
int * getwid(int maxwid)
Definition bigintmat.cc:574
#define StringAppend
Definition emacs.cc:79
#define omAlloc0(size)

◆ Print()

void bigintmat::Print ( )

IO: simply prints the matrix to the current output (screen?)

Definition at line 437 of file bigintmat.cc.

438{
439 char * s = String();
440 PrintS(s);
441 omFree(s);
442}

◆ pseudoinv()

number bigintmat::pseudoinv ( bigintmat * a)

Speichert in Matrix a die Pseudoinverse, liefert den Nenner zurück.

Definition at line 1409 of file bigintmat.cc.

1409 {
1410
1411 // Falls Matrix über reellen Zahlen nicht invertierbar, breche ab
1412 assume((a->rows() == row) && (a->rows() == a->cols()) && (row == col));
1413
1414 number det = this->det(); //computes the HNF, so should e reused.
1415 if ((n_IsZero(det, basecoeffs())))
1416 return det;
1417
1418 // Hänge Einheitsmatrix über Matrix und wendet HNF an. An Stelle der Einheitsmatrix steht im Ergebnis die Transformationsmatrix dazu
1419 a->one();
1420 bigintmat *m = new bigintmat(2*row, col, basecoeffs());
1421 m->concatrow(a,this);
1422 m->hnf();
1423 // Arbeite weiterhin mit der zusammengehängten Matrix
1424 // Laufe durch die Diagonalelemente, und multipliziere jede Spalte rechts davon damit, speichere aber den alten Eintrag der Spalte, temp, der in der Zeile des Diagonalelements liegt, zwischen. Dann addiere das -temp-Fache der Diagonalspalte zur entsprechenenden Spalte rechts davon. Dadurch entsteht überall rechts der Diagonalen eine 0
1425 number diag;
1426 number temp, ttemp;
1427 for (int i=1; i<=col; i++) {
1428 diag = m->get(row+i, i);
1429 for (int j=i+1; j<=col; j++) {
1430 temp = m->get(row+i, j);
1431 m->colskalmult(j, diag, basecoeffs());
1432 temp = n_InpNeg(temp, basecoeffs());
1433 m->addcol(j, i, temp, basecoeffs());
1434 n_Delete(&temp, basecoeffs());
1435 }
1436 n_Delete(&diag, basecoeffs());
1437 }
1438 // Falls wir nicht modulo n arbeiten, können wir die Spalten durch den ggT teilen, um die Einträge kleiner zu bekommen
1439 // Bei Z/n sparen wir uns das, da es hier sinnlos ist
1440 number g;
1441 number gcd;
1442 for (int j=1; j<=col; j++) {
1443 g = n_Init(0, basecoeffs());
1444 for (int i=1; i<=2*row; i++) {
1445 temp = m->get(i,j);
1446 gcd = n_Gcd(g, temp, basecoeffs());
1447 n_Delete(&g, basecoeffs());
1448 n_Delete(&temp, basecoeffs());
1449 g = n_Copy(gcd, basecoeffs());
1450 n_Delete(&gcd, basecoeffs());
1451 }
1452 if (!(n_IsOne(g, basecoeffs())))
1453 m->colskaldiv(j, g);
1454 n_Delete(&g, basecoeffs());
1455 }
1456
1457 // Nun müssen die Diagonalelemente durch Spaltenmultiplikation gleich gesett werden. Bei Z können wir mit dem kgV arbeiten, bei Z/n bringen wir jedes Diagonalelement auf 1 (wir arbeiten immer mit n = Primzahl. Für n != Primzahl muss noch an anderen Stellen etwas geändert werden)
1458
1459 g = n_Init(0, basecoeffs());
1460 number prod = n_Init(1, basecoeffs());
1461 for (int i=1; i<=col; i++) {
1462 gcd = n_Gcd(g, m->get(row+i, i), basecoeffs());
1463 n_Delete(&g, basecoeffs());
1464 g = n_Copy(gcd, basecoeffs());
1465 n_Delete(&gcd, basecoeffs());
1466 ttemp = n_Copy(prod, basecoeffs());
1467 temp = m->get(row+i, i);
1469 prod = n_Mult(ttemp, temp, basecoeffs());
1470 n_Delete(&ttemp, basecoeffs());
1471 n_Delete(&temp, basecoeffs());
1472 }
1473 number lcm;
1474 lcm = n_Div(prod, g, basecoeffs());
1475 for (int j=1; j<=col; j++) {
1476 ttemp = m->get(row+j,j);
1477 temp = n_QuotRem(lcm, ttemp, NULL, basecoeffs());
1478 m->colskalmult(j, temp, basecoeffs());
1479 n_Delete(&ttemp, basecoeffs());
1480 n_Delete(&temp, basecoeffs());
1481 }
1482 n_Delete(&lcm, basecoeffs());
1484
1485 number divisor = m->get(row+1, 1);
1486 m->splitrow(a, 1);
1487 delete m;
1488 n_Delete(&det, basecoeffs());
1489 return divisor;
1490}
number det()
det (via LaPlace in general, hnf for euc. rings)
int lcm(unsigned long *l, unsigned long *a, unsigned long *b, unsigned long p, int dega, int degb)
Definition minpoly.cc:709

◆ rawset() [1/2]

void bigintmat::rawset ( int i,
int j,
number n,
const coeffs C = NULL )
inline

as above, but the 2-dim version

Definition at line 216 of file bigintmat.h.

217 {
218 rawset( index(i,j), n, C);
219 }

◆ rawset() [2/2]

void bigintmat::rawset ( int i,
number n,
const coeffs C = NULL )
inline

replace an entry with the given number n (only delete old). NOTE: starts at [0]. Should be named set_transfer

Definition at line 196 of file bigintmat.h.

197 {
198 assume (C == NULL || C == basecoeffs());
199 assume (i >= 0);
200 const int l = rows() * cols();
201 assume (i<l);
202
203 if (i < l)
204 {
205 n_Delete(&(v[i]), basecoeffs()); v[i] = n;
206 }
207#ifndef SING_NDEBUG
208 else
209 {
210 Werror("wrong bigintmat index:%d\n",i);
211 }
212#endif
213 }

◆ rows()

int bigintmat::rows ( ) const
inline

Definition at line 145 of file bigintmat.h.

145{ return row; }

◆ rowskalmult()

void bigintmat::rowskalmult ( int i,
number a,
coeffs c )

... Zeile ...

Definition at line 1017 of file bigintmat.cc.

1018{
1019 if ((i>=1) && (i<=row) && (nCoeffs_are_equal(c, basecoeffs())))
1020 {
1021 number t, tmult;
1022 for (int j=1; j<=col; j++)
1023 {
1024 t = view(i, j);
1025 tmult = n_Mult(a, t, basecoeffs());
1026 rawset(i, j, tmult);
1027 }
1028 }
1029 else
1030 WerrorS("Error in rowskalmult");
1031}

◆ set() [1/2]

void bigintmat::set ( int i,
int j,
number n,
const coeffs C = NULL )

replace an entry with a copy (delete old + copy new!). NOTE: starts at [1,1]

Definition at line 93 of file bigintmat.cc.

94{
95 assume (C == NULL || C == basecoeffs());
96 assume (i > 0 && j > 0);
97 assume (i <= rows() && j <= cols());
98 set(index(i, j), n, C);
99}

◆ set() [2/2]

void bigintmat::set ( int i,
number n,
const coeffs C = NULL )

replace an entry with a copy (delete old + copy new!). NOTE: starts at [0]

Definition at line 85 of file bigintmat.cc.

86{
87 assume (C == NULL || C == basecoeffs());
88
90}

◆ setcol()

void bigintmat::setcol ( int j,
bigintmat * m )

Setzt j-te Spalte gleich übergebenem Vektor (Matrix) m.

Definition at line 820 of file bigintmat.cc.

821{
822 if ((j>col) || (j<1))
823 {
824 WerrorS("Error in setcol: Index out of range!");
825 return;
826 }
827 if (((m->rows() != row) || (m->cols() != 1)) && ((m->rows() != 1) || (m->cols() != row)))
828 {
829 WerrorS("Error in setcol. Dimensions must agree!");
830 return;
831 }
832 if (!nCoeffs_are_equal(basecoeffs(), m->basecoeffs()))
833 {
834 nMapFunc f = n_SetMap(m->basecoeffs(), basecoeffs());
835 number t1,t2;
836 for (int i=1; i<=row; i++)
837 {
838 t1 = m->get(i-1);
839 t2 = f(t1, m->basecoeffs(),basecoeffs());
840 set(i, j, t2);
841 n_Delete(&t2, basecoeffs());
842 n_Delete(&t1, m->basecoeffs());
843 }
844 return;
845 }
846 number t1;
847 for (int i=1; i<=row; i++)
848 {
849 t1 = m->view(i-1);
850 set(i, j, t1);
851 }
852}

◆ setrow()

void bigintmat::setrow ( int i,
bigintmat * m )

Setzt i-te Zeile gleich übergebenem Vektor (Matrix) m.

Definition at line 854 of file bigintmat.cc.

855{
856 if ((j>row) || (j<1))
857 {
858 WerrorS("Error in setrow: Index out of range!");
859 return;
860 }
861 if (((m->rows() != 1) || (m->cols() != col)) && ((m->rows() != col) || (m->cols() != 1)))
862 {
863 WerrorS("Error in setrow. Dimensions must agree!");
864 return;
865 }
866 if (!nCoeffs_are_equal(basecoeffs(), m->basecoeffs()))
867 {
868 nMapFunc f = n_SetMap(m->basecoeffs(), basecoeffs());
869 number tmp1,tmp2;
870 for (int i=1; i<=col; i++)
871 {
872 tmp1 = m->get(i-1);
873 tmp2 = f(tmp1, m->basecoeffs(),basecoeffs());
874 set(j, i, tmp2);
876 n_Delete(&tmp1, m->basecoeffs());
877 }
878 return;
879 }
880 number tmp;
881 for (int i=1; i<=col; i++)
882 {
883 tmp = m->view(i-1);
884 set(j, i, tmp);
885 }
886}

◆ simplifyContentDen()

void bigintmat::simplifyContentDen ( number * den)

ensures that Gcd(den, content)=1 enden hier wieder

Definition at line 2671 of file bigintmat.cc.

2672{
2673 coeffs r = basecoeffs();
2674 number g = n_Copy(*d, r), h;
2675 int n=rows()*cols();
2676 for(int i=0; i<n && !n_IsOne(g, r); i++)
2677 {
2678 h = n_Gcd(g, view(i), r);
2679 n_Delete(&g, r);
2680 g=h;
2681 }
2682 *d = n_Div(*d, g, r);
2683 if (!n_IsOne(g, r))
2684 skaldiv(g);
2685}
void skaldiv(number b)
Macht Ganzzahldivision aller Matrixeinträge mit b.

◆ skaldiv()

void bigintmat::skaldiv ( number b)

Macht Ganzzahldivision aller Matrixeinträge mit b.

Definition at line 1850 of file bigintmat.cc.

1851{
1852 number tmp1, tmp2;
1853 for (int i=1; i<=row; i++)
1854 {
1855 for (int j=1; j<=col; j++)
1856 {
1857 tmp1 = view(i, j);
1858 tmp2 = n_Div(tmp1, b, basecoeffs());
1859 rawset(i, j, tmp2);
1860 }
1861 }
1862}

◆ skalmult()

bool bigintmat::skalmult ( number b,
coeffs c )

Multipliziert zur Matrix den Skalar b hinzu.

Definition at line 932 of file bigintmat.cc.

933{
934 if (!nCoeffs_are_equal(c, basecoeffs()))
935 {
936 WerrorS("Wrong coeffs\n");
937 return false;
938 }
939 number t1, t2;
940 if ( n_IsOne(b,c)) return true;
941 for (int i=1; i<=row; i++)
942 {
943 for (int j=1; j<=col; j++)
944 {
945 t1 = view(i, j);
946 t2 = n_Mult(t1, b, basecoeffs());
947 rawset(i, j, t2);
948 }
949 }
950 return true;
951}

◆ splitcol() [1/2]

void bigintmat::splitcol ( bigintmat * a,
bigintmat * b )

... linken ... rechten ...

Definition at line 1163 of file bigintmat.cc.

1164{
1165 int ay = a->cols();
1166 int ax = a->rows();
1167 int by = b->cols();
1168 int bx = b->rows();
1169 number tmp;
1170 if (!((row == ax) && (row == bx)))
1171 {
1172 WerrorS("Error in splitcol. Dimensions must agree!");
1173 }
1174 else if (!(ay+by == col))
1175 {
1176 WerrorS("Error in splitcol. Dimensions must agree!");
1177 }
1178 else if (!(nCoeffs_are_equal(a->basecoeffs(), basecoeffs()) && nCoeffs_are_equal(b->basecoeffs(), basecoeffs())))
1179 {
1180 WerrorS("Error in splitcol. coeffs do not agree!");
1181 }
1182 else
1183 {
1184 for (int i=1; i<=ax; i++)
1185 {
1186 for (int j=1; j<=ay; j++)
1187 {
1188 tmp = view(i,j);
1189 a->set(i,j,tmp);
1190 }
1191 }
1192 for (int i=1; i<=bx; i++)
1193 {
1194 for (int j=1; j<=by; j++)
1195 {
1196 tmp = view(i,j+ay);
1197 b->set(i,j,tmp);
1198 }
1199 }
1200 }
1201}

◆ splitcol() [2/2]

void bigintmat::splitcol ( bigintmat * a,
int i )

Speichert die ersten i Spalten als Teilmatrix in a.

Definition at line 1203 of file bigintmat.cc.

1204{
1205 number tmp;
1206 if ((a->rows() != row) || (a->cols()+i-1 > col) || (i<1))
1207 {
1208 WerrorS("Error in splitcol. Dimensions must agree!");
1209 return;
1210 }
1211 if (!(nCoeffs_are_equal(a->basecoeffs(), basecoeffs())))
1212 {
1213 WerrorS("Error in splitcol. coeffs do not agree!");
1214 return;
1215 }
1216 int width = a->cols();
1217 for (int j=1; j<=width; j++)
1218 {
1219 for (int k=1; k<=row; k++)
1220 {
1221 tmp = get(k, j+i-1);
1222 a->set(k, j, tmp);
1223 n_Delete(&tmp, basecoeffs());
1224 }
1225 }
1226}

◆ splitrow() [1/2]

void bigintmat::splitrow ( bigintmat * a,
bigintmat * b )

Speichert in Matrix a den oberen, in b den unteren Teil der Matrix, vorausgesetzt die Dimensionen stimmen überein.

Definition at line 1121 of file bigintmat.cc.

1122{
1123 int ay = a->cols();
1124 int ax = a->rows();
1125 int by = b->cols();
1126 int bx = b->rows();
1127 number tmp;
1128 if (!(ax + bx == row))
1129 {
1130 WerrorS("Error in splitrow. Dimensions must agree!");
1131 }
1132 else if (!((col == ay) && (col == by)))
1133 {
1134 WerrorS("Error in splitrow. Dimensions must agree!");
1135 }
1136 else if (!(nCoeffs_are_equal(a->basecoeffs(), basecoeffs()) && nCoeffs_are_equal(b->basecoeffs(), basecoeffs())))
1137 {
1138 WerrorS("Error in splitrow. coeffs do not agree!");
1139 }
1140 else
1141 {
1142 for(int i = 1; i<=ax; i++)
1143 {
1144 for(int j = 1; j<=ay;j++)
1145 {
1146 tmp = get(i,j);
1147 a->set(i,j,tmp);
1148 n_Delete(&tmp, basecoeffs());
1149 }
1150 }
1151 for (int i =1; i<=bx; i++)
1152 {
1153 for (int j=1;j<=col;j++)
1154 {
1155 tmp = get(i+ax, j);
1156 b->set(i,j,tmp);
1157 n_Delete(&tmp, basecoeffs());
1158 }
1159 }
1160 }
1161}

◆ splitrow() [2/2]

void bigintmat::splitrow ( bigintmat * a,
int i )

... Zeilen ...

Definition at line 1228 of file bigintmat.cc.

1229{
1230 number tmp;
1231 if ((a->cols() != col) || (a->rows()+i-1 > row) || (i<1))
1232 {
1233 WerrorS("Error in Marco-splitrow");
1234 return;
1235 }
1236
1237 if (!(nCoeffs_are_equal(a->basecoeffs(), basecoeffs())))
1238 {
1239 WerrorS("Error in splitrow. coeffs do not agree!");
1240 return;
1241 }
1242 int height = a->rows();
1243 for (int j=1; j<=height; j++)
1244 {
1245 for (int k=1; k<=col; k++)
1246 {
1247 tmp = view(j+i-1, k);
1248 a->set(j, k, tmp);
1249 }
1250 }
1251}

◆ String()

char * bigintmat::String ( )

IO: String returns a singular string containing the matrix, needs freeing afterwards.

Definition at line 430 of file bigintmat.cc.

431{
432 StringSetS("");
433 Write();
434 return StringEndS();
435}
void Write()
IO: writes the matrix into the current internal string buffer which must be started/ allocated before...
Definition bigintmat.cc:411

◆ StringAsPrinted()

char * bigintmat::StringAsPrinted ( )

Returns a string as it would have been printed in the interpreter.

Used e.g. in print functions of various blackbox types.

Definition at line 445 of file bigintmat.cc.

446{
447 if ((col==0) || (row==0))
448 return NULL;
449 else
450 {
451 int * colwid = getwid(80);
452 if (colwid == NULL)
453 {
454 WerrorS("not enough space to print bigintmat");
455 WerrorS("try string(...) for a unformatted output");
456 return NULL;
457 }
458 char * ps;
459 int slength = 0;
460 for (int j=0; j<col; j++)
461 slength += colwid[j]*row;
462 slength += col*row+row;
463 ps = (char*) omAlloc0(sizeof(char)*(slength));
464 int pos = 0;
465 for (int i=0; i<col*row; i++)
466 {
467 StringSetS("");
468 n_Write(v[i], basecoeffs());
469 char * ts = StringEndS();
470 const int _nl = strlen(ts);
471 int cj = i%col;
472 if (_nl > colwid[cj])
473 {
474 StringSetS("");
475 int ci = i/col;
476 StringAppend("[%d,%d]", ci+1, cj+1);
477 char * ph = StringEndS();
478 int phl = strlen(ph);
479 if (phl > colwid[cj])
480 {
481 for (int j=0; j<colwid[cj]-1; j++)
482 ps[pos+j] = ' ';
483 ps[pos+colwid[cj]-1] = '*';
484 }
485 else
486 {
487 for (int j=0; j<colwid[cj]-phl; j++)
488 ps[pos+j] = ' ';
489 for (int j=0; j<phl; j++)
490 ps[pos+colwid[cj]-phl+j] = ph[j];
491 }
492 omFree(ph);
493 }
494 else // Mit Leerzeichen auffüllen und zahl reinschreiben
495 {
496 for (int j=0; j<(colwid[cj]-_nl); j++)
497 ps[pos+j] = ' ';
498 for (int j=0; j<_nl; j++)
499 ps[pos+colwid[cj]-_nl+j] = ts[j];
500 }
501 // ", " und (evtl) "\n" einfügen
502 if ((i+1)%col == 0)
503 {
504 if (i != col*row-1)
505 {
506 ps[pos+colwid[cj]] = ',';
507 ps[pos+colwid[cj]+1] = '\n';
508 pos += colwid[cj]+2;
509 }
510 }
511 else
512 {
513 ps[pos+colwid[cj]] = ',';
514 pos += colwid[cj]+1;
515 }
516 omFree(ts); // Hier ts zerstören
517 }
518 return(ps);
519 // omFree(ps);
520}
521}

◆ sub()

bool bigintmat::sub ( bigintmat * b)

Subtrahiert ...

Definition at line 910 of file bigintmat.cc.

911{
912 if ((b->rows() != row) || (b->cols() != col))
913 {
914 WerrorS("Error in bigintmat::sub. Dimensions do not agree!");
915 return false;
916 }
917 if (!nCoeffs_are_equal(basecoeffs(), b->basecoeffs()))
918 {
919 WerrorS("Error in bigintmat::sub. coeffs do not agree!");
920 return false;
921 }
922 for (int i=1; i<=row; i++)
923 {
924 for (int j=1; j<=col; j++)
925 {
926 rawset(i, j, n_Sub(view(i,j), b->view(i,j), basecoeffs()));
927 }
928 }
929 return true;
930}

◆ swap()

void bigintmat::swap ( int i,
int j )

swap columns i and j

Definition at line 679 of file bigintmat.cc.

680{
681 if ((i <= col) && (j <= col) && (i>0) && (j>0))
682 {
683 number tmp;
684 number t;
685 for (int k=1; k<=row; k++)
686 {
687 tmp = get(k, i);
688 t = view(k, j);
689 set(k, i, t);
690 set(k, j, tmp);
691 n_Delete(&tmp, basecoeffs());
692 }
693 }
694 else
695 WerrorS("Error in swap");
696}

◆ swapMatrix()

void bigintmat::swapMatrix ( bigintmat * a)

Definition at line 1560 of file bigintmat.cc.

1561{
1562 int n = rows(), m = cols();
1563 row = a->rows();
1564 col = a->cols();
1565 number * V = v;
1566 v = a->v;
1567 a->v = V;
1568 a->row = n;
1569 a->col = m;
1570}

◆ swaprow()

void bigintmat::swaprow ( int i,
int j )

swap rows i and j

Definition at line 698 of file bigintmat.cc.

699{
700 if ((i <= row) && (j <= row) && (i>0) && (j>0))
701 {
702 number tmp;
703 number t;
704 for (int k=1; k<=col; k++)
705 {
706 tmp = get(i, k);
707 t = view(j, k);
708 set(i, k, t);
709 set(j, k, tmp);
710 n_Delete(&tmp, basecoeffs());
711 }
712 }
713 else
714 WerrorS("Error in swaprow");
715}

◆ trace()

number bigintmat::trace ( )

the trace ....

Definition at line 1492 of file bigintmat.cc.

1493{
1494 assume (col == row);
1495 number t = get(1,1),
1496 h;
1497 coeffs r = basecoeffs();
1498 for(int i=2; i<= col; i++) {
1499 h = n_Add(t, view(i,i), r);
1500 n_Delete(&t, r);
1501 t = h;
1502 }
1503 return t;
1504}

◆ transpose()

bigintmat * bigintmat::transpose ( )

Definition at line 35 of file bigintmat.cc.

36{
37 bigintmat * t = new bigintmat(col, row, basecoeffs());
38 for (int i=1; i<=row; i++)
39 {
40 for (int j=1; j<=col; j++)
41 {
42 t->set(j, i, BIMATELEM(*this,i,j));
43 }
44 }
45 return t;
46}
#define BIMATELEM(M, I, J)
Definition bigintmat.h:133

◆ view() [1/2]

number bigintmat::view ( int i) const

view an entry. NOTE: starts at [0]

Definition at line 109 of file bigintmat.cc.

110{
111 assume (i >= 0);
112 assume (i<rows()*cols());
113
114 return v[i];
115}

◆ view() [2/2]

number bigintmat::view ( int i,
int j ) const

view an entry an entry. NOTE: starts at [1,1]

Definition at line 125 of file bigintmat.cc.

126{
127 assume (i >= 0 && j >= 0);
128 assume (i <= rows() && j <= cols());
129
130 return view(index(i, j));
131}

◆ Write()

void bigintmat::Write ( )

IO: writes the matrix into the current internal string buffer which must be started/ allocated before (e.g. StringSetS)

Definition at line 411 of file bigintmat.cc.

412{
413 int n = cols(), m=rows();
414
415 for(int i=1; i<= m; i++)
416 {
417 for(int j=1; j< n; j++)
418 {
419 n_Write(v[(i-1)*n+j-1], basecoeffs());
420 StringAppendS(", ");
421 }
422 if (n) n_Write(v[i*n-1], basecoeffs());
423 if (i<m)
424 {
425 StringAppendS(", ");
426 }
427 }
428}

◆ zero()

void bigintmat::zero ( )

Setzt alle Einträge auf 0.

Definition at line 1344 of file bigintmat.cc.

1345{
1346 number tmp = n_Init(0, basecoeffs());
1347 for (int i=1; i<=row; i++)
1348 {
1349 for (int j=1; j<=col; j++)
1350 {
1351 set(i, j, tmp);
1352 }
1353 }
1354 n_Delete(&tmp,basecoeffs());
1355}

Field Documentation

◆ col

int bigintmat::col
private

Definition at line 56 of file bigintmat.h.

◆ m_coeffs

coeffs bigintmat::m_coeffs
private

Definition at line 53 of file bigintmat.h.

◆ row

int bigintmat::row
private

Definition at line 55 of file bigintmat.h.

◆ v

number* bigintmat::v
private

Definition at line 54 of file bigintmat.h.


The documentation for this class was generated from the following files: