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? (coeffs in Singular are always commutative)
 
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:389
#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:120
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 889 of file bigintmat.cc.

890{
891 if ((b->rows() != row) || (b->cols() != col))
892 {
893 WerrorS("Error in bigintmat::add. Dimensions do not agree!");
894 return false;
895 }
896 if (!nCoeffs_are_equal(basecoeffs(), b->basecoeffs()))
897 {
898 WerrorS("Error in bigintmat::add. coeffs do not agree!");
899 return false;
900 }
901 for (int i=1; i<=row; i++)
902 {
903 for (int j=1; j<=col; j++)
904 {
905 rawset(i, j, n_Add(b->view(i,j), view(i,j), basecoeffs()));
906 }
907 }
908 return true;
909}
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 954 of file bigintmat.cc.

955{
956 if ((i>col) || (j>col) || (i<1) || (j<1))
957 {
958 WerrorS("Error in addcol: Index out of range!");
959 return false;
960 }
961 if (!nCoeffs_are_equal(c, basecoeffs()))
962 {
963 WerrorS("Error in addcol: coeffs do not agree!");
964 return false;
965 }
966 number t1, t2, t3;
967 for (int k=1; k<=row; k++)
968 {
969 t1 = view(k, j);
970 t2 = view(k, i);
971 t3 = n_Mult(t1, a, basecoeffs());
972 n_InpAdd(t3, t2, basecoeffs());
973 rawset(k, i, t3);
974 }
975 return true;
976}
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 978 of file bigintmat.cc.

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

◆ appendCol()

void bigintmat::appendCol ( bigintmat * a)

horizontally join the matrices, m <- m|a

Definition at line 1078 of file bigintmat.cc.

1079{
1080 coeffs R = basecoeffs();
1081 int ay = a->cols();
1082 int ax = a->rows();
1083 assume(row == ax);
1084
1086
1087 bigintmat * tmp = new bigintmat(rows(), cols() + ay, R);
1088 tmp->concatcol(this, a);
1089 this->swapMatrix(tmp);
1090 delete tmp;
1091}
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 1572 of file bigintmat.cc.

1573{
1574 coeffs R = basecoeffs();
1575 for(int i=1; i<=rows(); i++)
1576 if (!n_IsZero(view(i, j), R)) return FALSE;
1577 return TRUE;
1578}
#define TRUE
Definition auxiliary.h:101
#define FALSE
Definition auxiliary.h:97
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 1866 of file bigintmat.cc.

1867{
1868 number tmp1, tmp2;
1869 for (int i=1; i<=row; i++)
1870 {
1871 tmp1 = view(i, j);
1872 tmp2 = n_Div(tmp1, b, basecoeffs());
1873 rawset(i, j, tmp2);
1874 }
1875}
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 1002 of file bigintmat.cc.

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

◆ 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 1879 of file bigintmat.cc.

1880{
1881 number tmp1, tmp2, tmp3, tmp4;
1882 for (int i=1; i<=row; i++)
1883 {
1884 tmp1 = get(i, j);
1885 tmp2 = get(i, k);
1886 tmp3 = n_Mult(tmp1, a, basecoeffs());
1887 tmp4 = n_Mult(tmp2, b, basecoeffs());
1888 n_InpAdd(tmp3, tmp4, basecoeffs());
1889 n_Delete(&tmp4, basecoeffs());
1890
1891 n_InpMult(tmp1, c, basecoeffs());
1892 n_InpMult(tmp2, d, basecoeffs());
1895
1896 set(i, j, tmp3);
1897 set(i, k, tmp1);
1899 n_Delete(&tmp3, basecoeffs());
1900 }
1901}
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:126
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 1093 of file bigintmat.cc.

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

◆ 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 1034 of file bigintmat.cc.

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

◆ content()

number bigintmat::content ( )

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

Definition at line 2659 of file bigintmat.cc.

2660{
2661 coeffs r = basecoeffs();
2662 number g = get(1,1), h;
2663 int n=rows()*cols();
2664 for(int i=1; i<n && !n_IsOne(g, r); i++)
2665 {
2666 h = n_Gcd(g, view(i), r);
2667 n_Delete(&g, r);
2668 g=h;
2669 }
2670 return g;
2671}
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 1254 of file bigintmat.cc.

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

◆ 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 1282 of file bigintmat.cc.

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

◆ det()

number bigintmat::det ( )

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

Definition at line 1507 of file bigintmat.cc.

1508{
1509 assume (row==col);
1510
1511 if (col == 1)
1512 return get(1, 1);
1513 // should work as well in Z/pZ of type n_Zp?
1514 // relies on XExtGcd and the other euc. functions.
1516 return hnfdet();
1517 }
1518 number sum = n_Init(0, basecoeffs());
1519 number t1, t2, t3, t4;
1520 bigintmat *b;
1521 for (int i=1; i<=row; i++) {
1522 b = elim(i, 1);
1523 t1 = get(i, 1);
1524 t2 = b->det();
1525 t3 = n_Mult(t1, t2, basecoeffs());
1526 t4 = n_Copy(sum, basecoeffs());
1527 n_Delete(&sum, basecoeffs());
1528 if ((i+1)>>1<<1==(i+1))
1529 sum = n_Add(t4, t3, basecoeffs());
1530 else
1531 sum = n_Sub(t4, t3, basecoeffs());
1532 n_Delete(&t1, basecoeffs());
1533 n_Delete(&t2, basecoeffs());
1534 n_Delete(&t3, basecoeffs());
1535 n_Delete(&t4, basecoeffs());
1536 }
1537 return sum;
1538}
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 1376 of file bigintmat.cc.

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

◆ extendCols()

void bigintmat::extendCols ( int i)

append i zero-columns to the matrix

Definition at line 1071 of file bigintmat.cc.

1072{
1073 bigintmat * tmp = new bigintmat(rows(), i, basecoeffs());
1074 appendCol(tmp);
1075 delete tmp;
1076}
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 730 of file bigintmat.cc.

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

◆ findnonzero()

int bigintmat::findnonzero ( int i)

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

Definition at line 718 of file bigintmat.cc.

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

◆ 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 742 of file bigintmat.cc.

743{
744 assume((j<=col) && (j>=1));
745 if (((a->rows() != row) || (a->cols() != 1)) && ((a->rows() != 1) || (a->cols() != row)))
746 {
747 assume(0);
748 WerrorS("Error in getcol. Dimensions must agree!");
749 return;
750 }
752 {
754 number t1, t2;
755 for (int i=1; i<=row;i++)
756 {
757 t1 = get(i,j);
758 t2 = f(t1, basecoeffs(), a->basecoeffs());
759 a->set(i-1,t1);
760 n_Delete(&t1, basecoeffs());
761 n_Delete(&t2, a->basecoeffs());
762 }
763 return;
764 }
765 number t1;
766 for (int i=1; i<=row;i++)
767 {
768 t1 = view(i,j);
769 a->set(i-1,t1);
770 }
771}
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 773 of file bigintmat.cc.

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

◆ getrow()

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

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

Definition at line 786 of file bigintmat.cc.

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

◆ 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 1655 of file bigintmat.cc.

1656{
1657 // Laufen von unten nach oben und von links nach rechts
1658 // CF: TODO: for n_Z: write a recursive version. This one will
1659 // have exponential blow-up. Look at Michianchio
1660 // Alternatively, do p-adic det and modular method
1661
1662#if 0
1663 char * s;
1664 ::PrintS("mat over Z is \n");
1665 ::Print("%s\n", s = nCoeffString(basecoeffs()));
1666 omFree(s);
1667 Print();
1668 ::Print("\n(%d x %d)\n", rows(), cols());
1669#endif
1670
1671 int i = rows();
1672 int j = cols();
1673 number q = n_Init(0, basecoeffs());
1674 number one = n_Init(1, basecoeffs());
1675 number minusone = n_Init(-1, basecoeffs());
1676 number tmp1 = n_Init(0, basecoeffs());
1677 number tmp2 = n_Init(0, basecoeffs());
1678 number co1, co2, co3, co4;
1679 number ggt = n_Init(0, basecoeffs());
1680
1681 while ((i>0) && (j>0))
1682 {
1683 // Falls erstes Nicht-Null-Element in Zeile i nicht existiert, oder hinter Spalte j vorkommt, gehe in nächste Zeile
1684 if ((findnonzero(i)==0) || (findnonzero(i)>j))
1685 {
1686 i--;
1687 }
1688 else
1689 {
1690 // Laufe von links nach rechts durch die Zeile:
1691 for (int l=1; l<=j-1; l++)
1692 {
1694 tmp1 = get(i, l);
1695 // Falls Eintrag (im folgenden x genannt) gleich 0, gehe eine Spalte weiter. Ansonsten...
1696 if (!n_IsZero(tmp1, basecoeffs()))
1697 {
1699 tmp2 = get(i, l+1);
1700 // Falls Eintrag (i.f. y g.) rechts daneben gleich 0, tausche beide Spalten, sonst...
1701 if (!n_IsZero(tmp2, basecoeffs()))
1702 {
1703 n_Delete(&ggt, basecoeffs());
1704 ggt = n_XExtGcd(tmp1, tmp2, &co1, &co2, &co3, &co4, basecoeffs());
1705 // 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:
1706 if (n_Equal(tmp1, ggt, basecoeffs()))
1707 {
1708 swap(l, l+1);
1709 n_Delete(&q, basecoeffs());
1710 q = n_Div(tmp2, ggt, basecoeffs());
1711 q = n_InpNeg(q, basecoeffs());
1712 // Dann addiere das -q-fache der (neuen) rechten Spalte zur linken dazu. Damit erhalten wir die gewünschte 0
1713
1714 addcol(l, l+1, q, basecoeffs());
1715 n_Delete(&q, basecoeffs());
1716 }
1717 else if (n_Equal(tmp1, minusone, basecoeffs()))
1718 {
1719 // 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
1720 // Die Berechnung von q (=y/ggt) entfällt, da ggt=1
1721 swap(l, l+1);
1722 colskalmult(l+1, minusone, basecoeffs());
1724 addcol(l, l+1, tmp2, basecoeffs());
1725 }
1726 else
1727 {
1728 // CF: use the 2x2 matrix (co1, co2)(co3, co4) to
1729 // get the gcd in position and the 0 in the other:
1730#ifdef CF_DEB
1731 ::PrintS("applying trafo\n");
1732 StringSetS("");
1733 n_Write(co1, basecoeffs()); StringAppendS("\t");
1734 n_Write(co2, basecoeffs()); StringAppendS("\t");
1735 n_Write(co3, basecoeffs()); StringAppendS("\t");
1736 n_Write(co4, basecoeffs()); StringAppendS("\t");
1737 ::Print("%s\nfor l=%d\n", StringEndS(), l);
1738 {char * s = String();
1739 ::Print("to %s\n", s);omFree(s);};
1740#endif
1741 coltransform(l, l+1, co3, co4, co1, co2);
1742#ifdef CF_DEB
1743 {char * s = String();
1744 ::Print("gives %s\n", s);}
1745#endif
1746 }
1747 n_Delete(&co1, basecoeffs());
1748 n_Delete(&co2, basecoeffs());
1749 n_Delete(&co3, basecoeffs());
1750 n_Delete(&co4, basecoeffs());
1751 }
1752 else
1753 {
1754 swap(l, l+1);
1755 }
1756 // Dann betrachte die vormals rechte Spalte als neue linke, und die rechts daneben als neue rechte.
1757 }
1758 }
1759
1760 // normalize by units:
1761 if (!n_IsZero(view(i, j), basecoeffs()))
1762 {
1763 number u = n_GetUnit(view(i, j), basecoeffs());
1764 if (!n_IsOne(u, basecoeffs()))
1765 {
1766 colskaldiv(j, u);
1767 }
1768 n_Delete(&u, basecoeffs());
1769 }
1770 // Zum Schluss mache alle Einträge rechts vom Diagonalelement betragsmäßig kleiner als dieses
1771 for (int l=j+1; l<=col; l++)
1772 {
1773 n_Delete(&q, basecoeffs());
1774 q = n_QuotRem(view(i, l), view(i, j), NULL, basecoeffs());
1775 q = n_InpNeg(q, basecoeffs());
1776 addcol(l, j, q, basecoeffs());
1777 }
1778 i--;
1779 j--;
1780 // Dann betrachte die Zeile darüber und gehe dort wie vorher vor
1781 }
1782 }
1783 n_Delete(&q, basecoeffs());
1786 n_Delete(&ggt, basecoeffs());
1787 n_Delete(&one, basecoeffs());
1788 n_Delete(&minusone, basecoeffs());
1789
1790#if 0
1791 ::PrintS("hnf over Z is \n");
1792 Print();
1793 ::Print("\n(%d x %d)\n", rows(), cols());
1794#endif
1795}
#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:954
int findnonzero(int i)
find index of 1st non-zero entry in row i
Definition bigintmat.cc:718
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:956
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 1540 of file bigintmat.cc.

1541{
1542 assume (col == row);
1543
1544 if (col == 1)
1545 return get(1, 1);
1546 bigintmat *m = new bigintmat(this);
1547 m->hnf();
1548 number prod = n_Init(1, basecoeffs());
1549 number temp, temp2;
1550 for (int i=1; i<=col; i++) {
1551 temp = m->get(i, i);
1552 temp2 = n_Mult(temp, prod, basecoeffs());
1554 prod = temp2;
1555 n_Delete(&temp, basecoeffs());
1556 }
1557 delete m;
1558 return prod;
1559}
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 1580 of file bigintmat.cc.

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

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

◆ isZero()

int bigintmat::isZero ( )

Definition at line 1358 of file bigintmat.cc.

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

◆ 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 1906 of file bigintmat.cc.

1907{
1908 // produce the matrix in Z/pZ
1909 number tmp1, tmp2;
1910 for (int i=1; i<=row; i++)
1911 {
1912 for (int j=1; j<=col; j++)
1913 {
1914 tmp1 = get(i, j);
1915 tmp2 = n_IntMod(tmp1, p, basecoeffs());
1917 set(i, j, tmp2);
1918 }
1919 }
1920}
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 1824 of file bigintmat.cc.

1825{
1826 coeffs Rp = numbercoeffs(p, R); // R/pR
1827 bigintmat *m = bimChangeCoeff(this, Rp);
1828 m->howell();
1829 bigintmat *a = bimChangeCoeff(m, R);
1830 delete m;
1831 bigintmat *C = new bigintmat(rows(), rows(), R);
1832 int piv = rows(), i = a->cols();
1833 while (piv)
1834 {
1835 if (!i || n_IsZero(a->view(piv, i), R))
1836 {
1837 C->set(piv, piv, p, R);
1838 }
1839 else
1840 {
1841 C->copySubmatInto(a, 1, i, rows(), 1, 1, piv);
1842 i--;
1843 }
1844 piv--;
1845 }
1846 delete a;
1847 return C;
1848}
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 1320 of file bigintmat.cc.

1321{
1322 if (row==col)
1323 {
1324 number one = n_Init(1, basecoeffs()),
1325 zero = n_Init(0, basecoeffs());
1326 for (int i=1; i<=row; i++)
1327 {
1328 for (int j=1; j<=col; j++)
1329 {
1330 if (i==j)
1331 {
1332 set(i, j, one);
1333 }
1334 else
1335 {
1336 set(i, j, zero);
1337 }
1338 }
1339 }
1340 n_Delete(&one, basecoeffs());
1342 }
1343}
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? (coeffs in Singular are always commutative)

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 omFree(colwid);
675 }
676}
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 1410 of file bigintmat.cc.

1410 {
1411
1412 // Falls Matrix über reellen Zahlen nicht invertierbar, breche ab
1413 assume((a->rows() == row) && (a->rows() == a->cols()) && (row == col));
1414
1415 number det = this->det(); //computes the HNF, so should e reused.
1416 if ((n_IsZero(det, basecoeffs())))
1417 return det;
1418
1419 // Hänge Einheitsmatrix über Matrix und wendet HNF an. An Stelle der Einheitsmatrix steht im Ergebnis die Transformationsmatrix dazu
1420 a->one();
1421 bigintmat *m = new bigintmat(2*row, col, basecoeffs());
1422 m->concatrow(a,this);
1423 m->hnf();
1424 // Arbeite weiterhin mit der zusammengehängten Matrix
1425 // 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
1426 number diag;
1427 number temp, ttemp;
1428 for (int i=1; i<=col; i++) {
1429 diag = m->get(row+i, i);
1430 for (int j=i+1; j<=col; j++) {
1431 temp = m->get(row+i, j);
1432 m->colskalmult(j, diag, basecoeffs());
1433 temp = n_InpNeg(temp, basecoeffs());
1434 m->addcol(j, i, temp, basecoeffs());
1435 n_Delete(&temp, basecoeffs());
1436 }
1437 n_Delete(&diag, basecoeffs());
1438 }
1439 // Falls wir nicht modulo n arbeiten, können wir die Spalten durch den ggT teilen, um die Einträge kleiner zu bekommen
1440 // Bei Z/n sparen wir uns das, da es hier sinnlos ist
1441 number g;
1442 number gcd;
1443 for (int j=1; j<=col; j++) {
1444 g = n_Init(0, basecoeffs());
1445 for (int i=1; i<=2*row; i++) {
1446 temp = m->get(i,j);
1447 gcd = n_Gcd(g, temp, basecoeffs());
1448 n_Delete(&g, basecoeffs());
1449 n_Delete(&temp, basecoeffs());
1450 g = n_Copy(gcd, basecoeffs());
1451 n_Delete(&gcd, basecoeffs());
1452 }
1453 if (!(n_IsOne(g, basecoeffs())))
1454 m->colskaldiv(j, g);
1455 n_Delete(&g, basecoeffs());
1456 }
1457
1458 // 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)
1459
1460 g = n_Init(0, basecoeffs());
1461 number prod = n_Init(1, basecoeffs());
1462 for (int i=1; i<=col; i++) {
1463 gcd = n_Gcd(g, m->get(row+i, i), basecoeffs());
1464 n_Delete(&g, basecoeffs());
1465 g = n_Copy(gcd, basecoeffs());
1466 n_Delete(&gcd, basecoeffs());
1467 ttemp = n_Copy(prod, basecoeffs());
1468 temp = m->get(row+i, i);
1470 prod = n_Mult(ttemp, temp, basecoeffs());
1471 n_Delete(&ttemp, basecoeffs());
1472 n_Delete(&temp, basecoeffs());
1473 }
1474 number lcm;
1475 lcm = n_Div(prod, g, basecoeffs());
1476 for (int j=1; j<=col; j++) {
1477 ttemp = m->get(row+j,j);
1478 temp = n_QuotRem(lcm, ttemp, NULL, basecoeffs());
1479 m->colskalmult(j, temp, basecoeffs());
1480 n_Delete(&ttemp, basecoeffs());
1481 n_Delete(&temp, basecoeffs());
1482 }
1483 n_Delete(&lcm, basecoeffs());
1485
1486 number divisor = m->get(row+1, 1);
1487 m->splitrow(a, 1);
1488 delete m;
1489 n_Delete(&det, basecoeffs());
1490 return divisor;
1491}
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 1018 of file bigintmat.cc.

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

◆ 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 821 of file bigintmat.cc.

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

◆ setrow()

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

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

Definition at line 855 of file bigintmat.cc.

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

◆ simplifyContentDen()

void bigintmat::simplifyContentDen ( number * den)

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

Definition at line 2672 of file bigintmat.cc.

2673{
2674 coeffs r = basecoeffs();
2675 number g = n_Copy(*d, r), h;
2676 int n=rows()*cols();
2677 for(int i=0; i<n && !n_IsOne(g, r); i++)
2678 {
2679 h = n_Gcd(g, view(i), r);
2680 n_Delete(&g, r);
2681 g=h;
2682 }
2683 *d = n_Div(*d, g, r);
2684 if (!n_IsOne(g, r))
2685 skaldiv(g);
2686}
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 1851 of file bigintmat.cc.

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

◆ skalmult()

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

Multipliziert zur Matrix den Skalar b hinzu.

Definition at line 933 of file bigintmat.cc.

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

◆ splitcol() [1/2]

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

... linken ... rechten ...

Definition at line 1164 of file bigintmat.cc.

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

◆ splitcol() [2/2]

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

Speichert die ersten i Spalten als Teilmatrix in a.

Definition at line 1204 of file bigintmat.cc.

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

◆ 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 1122 of file bigintmat.cc.

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

◆ splitrow() [2/2]

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

... Zeilen ...

Definition at line 1229 of file bigintmat.cc.

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

◆ 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 911 of file bigintmat.cc.

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

◆ swap()

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

swap columns i and j

Definition at line 680 of file bigintmat.cc.

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

◆ swapMatrix()

void bigintmat::swapMatrix ( bigintmat * a)

Definition at line 1561 of file bigintmat.cc.

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

◆ swaprow()

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

swap rows i and j

Definition at line 699 of file bigintmat.cc.

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

◆ trace()

number bigintmat::trace ( )

the trace ....

Definition at line 1493 of file bigintmat.cc.

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

◆ 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 1345 of file bigintmat.cc.

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

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: