My Project
Public Member Functions | Private Attributes
bigintmat Class Reference

Matrices of numbers. More...

#include <coeffs/bigintmat.h>

Public Member Functions

 bigintmat ()
 
bigintmattranspose ()
 
void inpTranspose ()
 transpose in place More...
 
 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. More...
 
 bigintmat (const bigintmat *m)
 copy constructor More...
 
number & operator[] (int i)
 dubious: 1-dim access to 2-dim array. Entries are read row by row. More...
 
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? More...
 
void inpMult (number bintop, const coeffs C=NULL)
 inplace version of skalar mult. CHANGES input. More...
 
int length ()
 
int cols () const
 
int rows () const
 
coeffs basecoeffs () const
 
 ~bigintmat ()
 canonical destructor. More...
 
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 More...
 
number get (int i, int j) const
 get a copy of an entry. NOTE: starts at [1,1] More...
 
number view (int i, int j) const
 view an entry an entry. NOTE: starts at [1,1] More...
 
number get (int i) const
 get a copy of an entry. NOTE: starts at [0] More...
 
number view (int i) const
 view an entry. NOTE: starts at [0] More...
 
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] More...
 
void set (int i, number n, const coeffs C=NULL)
 replace an entry with a copy (delete old + copy new!). NOTE: starts at [0] More...
 
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 More...
 
void rawset (int i, int j, number n, const coeffs C=NULL)
 as above, but the 2-dim version More...
 
char * String ()
 IO: String returns a singular string containing the matrix, needs freeing afterwards. More...
 
void Write ()
 IO: writes the matrix into the current internal string buffer which must be started/ allocated before (e.g. StringSetS) More...
 
void Print ()
 IO: simply prints the matrix to the current output (screen?) More...
 
char * StringAsPrinted ()
 Returns a string as it would have been printed in the interpreter. More...
 
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 More...
 
void swaprow (int i, int j)
 swap rows i and j More...
 
int findnonzero (int i)
 find index of 1st non-zero entry in row i More...
 
int findcolnonzero (int j)
 find index of 1st non-zero entry in column j More...
 
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. More...
 
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 More...
 
void getrow (int i, bigintmat *a)
 Schreibt i-te Zeile in Vektor (Matrix) a. More...
 
void setcol (int j, bigintmat *m)
 Setzt j-te Spalte gleich übergebenem Vektor (Matrix) m. More...
 
void setrow (int i, bigintmat *m)
 Setzt i-te Zeile gleich übergebenem Vektor (Matrix) m. More...
 
void appendCol (bigintmat *a)
 horizontally join the matrices, m <- m|a More...
 
void extendCols (int i)
 append i zero-columns to the matrix More...
 
bool add (bigintmat *b)
 Addiert zur Matrix die Matrix b dazu. Return false => an error occurred. More...
 
bool sub (bigintmat *b)
 Subtrahiert ... More...
 
bool skalmult (number b, coeffs c)
 Multipliziert zur Matrix den Skalar b hinzu. More...
 
bool addcol (int i, int j, number a, coeffs c)
 addiert a-faches der j-ten Spalte zur i-ten dazu More...
 
bool addrow (int i, int j, number a, coeffs c)
 ... Zeile ... More...
 
void colskalmult (int i, number a, coeffs c)
 Multipliziert zur i-ten Spalte den Skalar a hinzu. More...
 
void rowskalmult (int i, number a, coeffs c)
 ... Zeile ... More...
 
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) More...
 
void concatrow (bigintmat *a, bigintmat *b)
 Fügt zwei Matrixen untereinander/nebeneinander in gegebene Matrix ein, bzw spaltet gegebenen Matrix auf. More...
 
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. More...
 
void splitcol (bigintmat *a, bigintmat *b)
 ... linken ... rechten ... More...
 
void splitcol (bigintmat *a, int i)
 Speichert die ersten i Spalten als Teilmatrix in a. More...
 
void splitrow (bigintmat *a, int i)
 ... Zeilen ... More...
 
bool copy (bigintmat *b)
 Kopiert Einträge von b auf Bigintmat. More...
 
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() More...
 
void one ()
 Macht Matrix (Falls quadratisch) zu Einheitsmatrix. More...
 
int isOne ()
 is matrix is identity More...
 
void zero ()
 Setzt alle Einträge auf 0. More...
 
int isZero ()
 
int colIsZero (int i)
 
bigintmatelim (int i, int j)
 Liefert Streichungsmatrix (i-te Zeile und j-te Spalte gestrichen) zurück. More...
 
number pseudoinv (bigintmat *a)
 Speichert in Matrix a die Pseudoinverse, liefert den Nenner zurück. More...
 
number trace ()
 the trace .... More...
 
number det ()
 det (via LaPlace in general, hnf for euc. rings) More...
 
number hnfdet ()
 det via HNF Primzahlen als long long int, müssen noch in number umgewandelt werden? More...
 
void hnf ()
 transforms INPLACE to HNF More...
 
void howell ()
 dito, but Howell form (only different for zero-divsors) More...
 
void swapMatrix (bigintmat *a)
 
bigintmatmodhnf (number p, coeffs c)
 computes HNF(this | p*I) More...
 
bigintmatmodgauss (number p, coeffs c)
 
void skaldiv (number b)
 Macht Ganzzahldivision aller Matrixeinträge mit b. More...
 
void colskaldiv (int j, number b)
 Macht Ganzzahldivision aller j-ten Spalteneinträge mit b. More...
 
void mod (number p)
 Reduziert komplette Matrix modulo p. More...
 
bigintmatinpmod (number p, coeffs c)
 Liefert Kopie der Matrix zurück, allerdings im Ring Z modulo p. More...
 
number content ()
 the content, the gcd of all entries. Only makes sense for Euclidean rings (or possibly constructive PIR) More...
 
void simplifyContentDen (number *den)
 ensures that Gcd(den, content)=1 enden hier wieder More...
 

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 adressing 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
int col
Definition: bigintmat.h:56
int row
Definition: bigintmat.h:55
#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:538
#define assume(x)
Definition: mod2.h:389
#define omAlloc(size)
Definition: omAllocDecl.h:210

◆ 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:451

◆ ~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:455
#define omFreeSize(addr, size)
Definition: omAllocDecl.h:260

Member Function Documentation

◆ add()

bool bigintmat::add ( bigintmat b)

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

Definition at line 894 of file bigintmat.cc.

895 {
896  if ((b->rows() != row) || (b->cols() != col))
897  {
898  WerrorS("Error in bigintmat::add. Dimensions do not agree!");
899  return false;
900  }
901  if (!nCoeffs_are_equal(basecoeffs(), b->basecoeffs()))
902  {
903  WerrorS("Error in bigintmat::add. coeffs do not agree!");
904  return false;
905  }
906  for (int i=1; i<=row; i++)
907  {
908  for (int j=1; j<=col; j++)
909  {
910  rawset(i, j, n_Add(b->view(i,j), view(i,j), basecoeffs()));
911  }
912  }
913  return true;
914 }
bool nCoeffs_are_equal(coeffs r, coeffs s)
Definition: bigintmat.cc:2645
CanonicalForm b
Definition: cfModGcd.cc:4103
number view(int i, int j) const
view an entry an entry. NOTE: starts at [1,1]
Definition: bigintmat.cc:127
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:650
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 959 of file bigintmat.cc.

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

◆ addrow()

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

... Zeile ...

Definition at line 983 of file bigintmat.cc.

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

◆ appendCol()

void bigintmat::appendCol ( bigintmat a)

horizontally join the matrices, m <- m|a

Definition at line 1083 of file bigintmat.cc.

1084 {
1085  coeffs R = basecoeffs();
1086  int ay = a->cols();
1087  int ax = a->rows();
1088  assume(row == ax);
1089 
1091 
1092  bigintmat * tmp = new bigintmat(rows(), cols() + ay, R);
1093  tmp->concatcol(this, a);
1094  this->swapMatrix(tmp);
1095  delete tmp;
1096 }
Matrices of numbers.
Definition: bigintmat.h:51
void swapMatrix(bigintmat *a)
Definition: bigintmat.cc:1566
void concatcol(bigintmat *a, bigintmat *b)
Definition: bigintmat.cc:1098
bigintmat()
Definition: bigintmat.h:59
The main handler for Singular numbers which are suitable for Singular polynomials.
#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 1577 of file bigintmat.cc.

1578 {
1579  coeffs R = basecoeffs();
1580  for(int i=1; i<=rows(); i++)
1581  if (!n_IsZero(view(i, j), R)) return FALSE;
1582  return TRUE;
1583 }
#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:464

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

1877 {
1878  number tmp1, tmp2;
1879  for (int i=1; i<=row; i++)
1880  {
1881  tmp1 = view(i, j);
1882  tmp2 = n_Div(tmp1, b, basecoeffs());
1883  rawset(i, j, tmp2);
1884  }
1885 }
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:615
CFList tmp1
Definition: facFqBivar.cc:72
CFList tmp2
Definition: facFqBivar.cc:72

◆ colskalmult()

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

Multipliziert zur i-ten Spalte den Skalar a hinzu.

Definition at line 1007 of file bigintmat.cc.

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

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

1890 {
1891  number tmp1, tmp2, tmp3, tmp4;
1892  for (int i=1; i<=row; i++)
1893  {
1894  tmp1 = get(i, j);
1895  tmp2 = get(i, k);
1896  tmp3 = n_Mult(tmp1, a, basecoeffs());
1897  tmp4 = n_Mult(tmp2, b, basecoeffs());
1898  n_InpAdd(tmp3, tmp4, basecoeffs());
1899  n_Delete(&tmp4, basecoeffs());
1900 
1901  n_InpMult(tmp1, c, basecoeffs());
1902  n_InpMult(tmp2, d, basecoeffs());
1904  n_Delete(&tmp2, basecoeffs());
1905 
1906  set(i, j, tmp3);
1907  set(i, k, tmp1);
1908  n_Delete(&tmp1, basecoeffs());
1909  n_Delete(&tmp3, basecoeffs());
1910  }
1911 }
number get(int i, int j) const
get a copy of an entry. NOTE: starts at [1,1]
Definition: bigintmat.cc:119
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:95
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:641

◆ compare()

int bigintmat::compare ( const bigintmat op) const

Definition at line 362 of file bigintmat.cc.

363 {
364  assume (basecoeffs() == op->basecoeffs() );
365 
366 #ifndef SING_NDEBUG
367  if (basecoeffs() != op->basecoeffs() )
368  WerrorS("wrong bigintmat comparison: different basecoeffs!\n");
369 #endif
370 
371  if ((col!=1) ||(op->cols()!=1))
372  {
373  if((col!=op->cols())
374  || (row!=op->rows()))
375  return -2;
376  }
377 
378  int i;
379  for (i=0; i<si_min(row*col,op->rows()*op->cols()); i++)
380  {
381  if ( n_Greater(v[i], (*op)[i], basecoeffs()) )
382  return 1;
383  else if (! n_Equal(v[i], (*op)[i], basecoeffs()))
384  return -1;
385  }
386 
387  for (; i<row; i++)
388  {
389  if ( n_GreaterZero(v[i], basecoeffs()) )
390  return 1;
391  else if (! n_IsZero(v[i], basecoeffs()) )
392  return -1;
393  }
394  for (; i<op->rows(); i++)
395  {
396  if ( n_GreaterZero((*op)[i], basecoeffs()) )
397  return -1;
398  else if (! n_IsZero((*op)[i], basecoeffs()) )
399  return 1;
400  }
401  return 0;
402 }
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:494
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:511
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:460

◆ concatcol()

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

Definition at line 1098 of file bigintmat.cc.

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

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

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

◆ content()

number bigintmat::content ( )

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

Definition at line 2675 of file bigintmat.cc.

2676 {
2677  coeffs r = basecoeffs();
2678  number g = get(1,1), h;
2679  int n=rows()*cols();
2680  for(int i=1; i<n && !n_IsOne(g, r); i++)
2681  {
2682  h = n_Gcd(g, view(i), r);
2683  n_Delete(&g, r);
2684  g=h;
2685  }
2686  return g;
2687 }
g
Definition: cfModGcd.cc:4090
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:664
static FORCE_INLINE BOOLEAN n_IsOne(number n, const coeffs r)
TRUE iff 'n' represents the one element.
Definition: coeffs.h:468
STATIC_VAR Poly * h
Definition: janet.cc:971

◆ copy()

bool bigintmat::copy ( bigintmat b)

Kopiert Einträge von b auf Bigintmat.

Definition at line 1259 of file bigintmat.cc.

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

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

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

◆ det()

number bigintmat::det ( )

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

Definition at line 1512 of file bigintmat.cc.

1513 {
1514  assume (row==col);
1515 
1516  if (col == 1)
1517  return get(1, 1);
1518  // should work as well in Z/pZ of type n_Zp?
1519  // relies on XExtGcd and the other euc. functinos.
1520  if ( getCoeffType(basecoeffs())== n_Z || getCoeffType(basecoeffs() )== n_Zn) {
1521  return hnfdet();
1522  }
1523  number sum = n_Init(0, basecoeffs());
1524  number t1, t2, t3, t4;
1525  bigintmat *b;
1526  for (int i=1; i<=row; i++) {
1527  b = elim(i, 1);
1528  t1 = get(i, 1);
1529  t2 = b->det();
1530  t3 = n_Mult(t1, t2, basecoeffs());
1531  t4 = n_Copy(sum, basecoeffs());
1532  n_Delete(&sum, basecoeffs());
1533  if ((i+1)>>1<<1==(i+1))
1534  sum = n_Add(t4, t3, basecoeffs());
1535  else
1536  sum = n_Sub(t4, t3, basecoeffs());
1537  n_Delete(&t1, basecoeffs());
1538  n_Delete(&t2, basecoeffs());
1539  n_Delete(&t3, basecoeffs());
1540  n_Delete(&t4, basecoeffs());
1541  }
1542  return sum;
1543 }
number hnfdet()
det via HNF Primzahlen als long long int, müssen noch in number umgewandelt werden?
Definition: bigintmat.cc:1545
bigintmat * elim(int i, int j)
Liefert Streichungsmatrix (i-te Zeile und j-te Spalte gestrichen) zurück.
Definition: bigintmat.cc:1381
@ 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:655
static FORCE_INLINE n_coeffType getCoeffType(const coeffs r)
Returns the type of coeffs domain.
Definition: coeffs.h:421

◆ elim()

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

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

Definition at line 1381 of file bigintmat.cc.

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

◆ extendCols()

void bigintmat::extendCols ( int  i)

append i zero-columns to the matrix

Definition at line 1076 of file bigintmat.cc.

1077 {
1078  bigintmat * tmp = new bigintmat(rows(), i, basecoeffs());
1079  appendCol(tmp);
1080  delete tmp;
1081 }
void appendCol(bigintmat *a)
horizontally join the matrices, m <- m|a
Definition: bigintmat.cc:1083

◆ findcolnonzero()

int bigintmat::findcolnonzero ( int  j)

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

Definition at line 735 of file bigintmat.cc.

736 {
737  for (int i=row; i>=1; i--)
738  {
739  if (!n_IsZero(view(i,j), basecoeffs()))
740  {
741  return i;
742  }
743  }
744  return 0;
745 }

◆ findnonzero()

int bigintmat::findnonzero ( int  i)

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

Definition at line 723 of file bigintmat.cc.

724 {
725  for (int j=1; j<=col; j++)
726  {
727  if (!n_IsZero(view(i,j), basecoeffs()))
728  {
729  return j;
730  }
731  }
732  return 0;
733 }

◆ get() [1/2]

number bigintmat::get ( int  i) const

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

Definition at line 103 of file bigintmat.cc.

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

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

120 {
121  assume (i > 0 && j > 0);
122  assume (i <= rows() && j <= cols());
123 
124  return get(index(i, j));
125 }
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 747 of file bigintmat.cc.

748 {
749  assume((j<=col) && (j>=1));
750  if (((a->rows() != row) || (a->cols() != 1)) && ((a->rows() != 1) || (a->cols() != row)))
751  {
752  assume(0);
753  WerrorS("Error in getcol. Dimensions must agree!");
754  return;
755  }
757  {
759  number t1, t2;
760  for (int i=1; i<=row;i++)
761  {
762  t1 = get(i,j);
763  t2 = f(t1, basecoeffs(), a->basecoeffs());
764  a->set(i-1,t1);
765  n_Delete(&t1, basecoeffs());
766  n_Delete(&t2, a->basecoeffs());
767  }
768  return;
769  }
770  number t1;
771  for (int i=1; i<=row;i++)
772  {
773  t1 = view(i,j);
774  a->set(i-1,t1);
775  }
776 }
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:700
number(* nMapFunc)(number a, const coeffs src, const coeffs dst)
maps "a", which lives in src, into dst
Definition: coeffs.h:73

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

779 {
780  number t1;
781  for(int ii=0; ii< no; ii++)
782  {
783  for (int i=1; i<=row;i++)
784  {
785  t1 = view(i, ii+j);
786  a->set(i, ii+1, t1);
787  }
788  }
789 }

◆ getrow()

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

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

Definition at line 791 of file bigintmat.cc.

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

◆ getwid()

int * bigintmat::getwid ( int  maxwid)

Definition at line 580 of file bigintmat.cc.

581 {
582  int const c = /*2**/(col-1)+1;
583  int * wv = (int*)omAlloc(sizeof(int)*col*row);
584  int * cwv = (int*)omAlloc(sizeof(int)*col);
585  for (int j=0; j<col; j++)
586  {
587  cwv[j] = 0;
588  for (int i=0; i<row; i++)
589  {
590  StringSetS("");
591  n_Write(v[col*i+j], basecoeffs());
592  char * tmp = StringEndS();
593  const int _nl = strlen(tmp);
594  wv[col*i+j] = _nl;
595  if (_nl > cwv[j]) cwv[j]=_nl;
596  omFree(tmp);
597  }
598  }
599 
600  // Groesse verkleinern, bis < maxwid
601  if (intArrSum(cwv, col)+c > maxwid)
602  {
603  int j = findLongest(cwv, col);
604  cwv[j] = getShorter(wv, cwv[j], j, col, row);
605  }
606  omFree(wv);
607  return cwv;
608 }
static int intArrSum(int *a, int length)
Definition: bigintmat.cc:529
static int findLongest(int *a, int length)
Definition: bigintmat.cc:537
static int getShorter(int *a, int l, int j, int cols, int rows)
Definition: bigintmat.cc:552
static FORCE_INLINE void n_Write(number n, const coeffs r, const BOOLEAN bShortOut=TRUE)
Definition: coeffs.h:591
#define omFree(addr)
Definition: omAllocDecl.h:261
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 1660 of file bigintmat.cc.

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

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

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

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

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

◆ inpTranspose()

void bigintmat::inpTranspose ( )

transpose in place

Definition at line 50 of file bigintmat.cc.

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

◆ isOne()

int bigintmat::isOne ( )

is matrix is identity

Definition at line 1300 of file bigintmat.cc.

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

◆ isZero()

int bigintmat::isZero ( )

Definition at line 1363 of file bigintmat.cc.

1364 {
1365  for (int i=1; i<=row; i++) {
1366  for (int j=1; j<=col; j++) {
1367  if (!n_IsZero(view(i,j), basecoeffs()))
1368  return FALSE;
1369  }
1370  }
1371  return TRUE;
1372 }

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

1917 {
1918  // produce the matrix in Z/pZ
1919  number tmp1, tmp2;
1920  for (int i=1; i<=row; i++)
1921  {
1922  for (int j=1; j<=col; j++)
1923  {
1924  tmp1 = get(i, j);
1925  tmp2 = n_IntMod(tmp1, p, basecoeffs());
1926  n_Delete(&tmp1, basecoeffs());
1927  set(i, j, tmp2);
1928  }
1929  }
1930 }
int p
Definition: cfModGcd.cc:4078
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:628

◆ modgauss()

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

◆ modhnf()

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

computes HNF(this | p*I)

Definition at line 1832 of file bigintmat.cc.

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

◆ one()

void bigintmat::one ( )

Macht Matrix (Falls quadratisch) zu Einheitsmatrix.

Definition at line 1325 of file bigintmat.cc.

1326 {
1327  if (row==col)
1328  {
1329  number one = n_Init(1, basecoeffs()),
1330  zero = n_Init(0, basecoeffs());
1331  for (int i=1; i<=row; i++)
1332  {
1333  for (int j=1; j<=col; j++)
1334  {
1335  if (i==j)
1336  {
1337  set(i, j, one);
1338  }
1339  else
1340  {
1341  set(i, j, zero);
1342  }
1343  }
1344  }
1345  n_Delete(&one, basecoeffs());
1346  n_Delete(&zero, basecoeffs());
1347  }
1348 }
void zero()
Setzt alle Einträge auf 0.
Definition: bigintmat.cc:1350

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

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

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

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

◆ Print()

void bigintmat::Print ( )

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

Definition at line 443 of file bigintmat.cc.

444 {
445  char * s = String();
446  PrintS(s);
447  omFree(s);
448 }

◆ pseudoinv()

number bigintmat::pseudoinv ( bigintmat a)

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

Definition at line 1415 of file bigintmat.cc.

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

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

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

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

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

88 {
89  assume (C == NULL || C == basecoeffs());
90 
91  rawset(i, n_Copy(n, basecoeffs()), basecoeffs());
92 }

◆ setcol()

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

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

Definition at line 826 of file bigintmat.cc.

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

◆ setrow()

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

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

Definition at line 860 of file bigintmat.cc.

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

◆ simplifyContentDen()

void bigintmat::simplifyContentDen ( number *  den)

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

Definition at line 2688 of file bigintmat.cc.

2689 {
2690  coeffs r = basecoeffs();
2691  number g = n_Copy(*d, r), h;
2692  int n=rows()*cols();
2693  for(int i=0; i<n && !n_IsOne(g, r); i++)
2694  {
2695  h = n_Gcd(g, view(i), r);
2696  n_Delete(&g, r);
2697  g=h;
2698  }
2699  *d = n_Div(*d, g, r);
2700  if (!n_IsOne(g, r))
2701  skaldiv(g);
2702 }
void skaldiv(number b)
Macht Ganzzahldivision aller Matrixeinträge mit b.
Definition: bigintmat.cc:1861

◆ skaldiv()

void bigintmat::skaldiv ( number  b)

Macht Ganzzahldivision aller Matrixeinträge mit b.

Definition at line 1861 of file bigintmat.cc.

1862 {
1863  number tmp1, tmp2;
1864  for (int i=1; i<=row; i++)
1865  {
1866  for (int j=1; j<=col; j++)
1867  {
1868  tmp1 = view(i, j);
1869  tmp2 = n_Div(tmp1, b, basecoeffs());
1870  rawset(i, j, tmp2);
1871  }
1872  }
1873 }

◆ skalmult()

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

Multipliziert zur Matrix den Skalar b hinzu.

Definition at line 938 of file bigintmat.cc.

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

◆ splitcol() [1/2]

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

... linken ... rechten ...

Definition at line 1169 of file bigintmat.cc.

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

◆ splitcol() [2/2]

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

Speichert die ersten i Spalten als Teilmatrix in a.

Definition at line 1209 of file bigintmat.cc.

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

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

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

◆ splitrow() [2/2]

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

... Zeilen ...

Definition at line 1234 of file bigintmat.cc.

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

◆ String()

char * bigintmat::String ( )

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

Definition at line 436 of file bigintmat.cc.

437 {
438  StringSetS("");
439  Write();
440  return StringEndS();
441 }
void Write()
IO: writes the matrix into the current internal string buffer which must be started/ allocated before...
Definition: bigintmat.cc:413

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

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

◆ sub()

bool bigintmat::sub ( bigintmat b)

Subtrahiert ...

Definition at line 916 of file bigintmat.cc.

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

◆ swap()

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

swap columns i and j

Definition at line 685 of file bigintmat.cc.

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

◆ swapMatrix()

void bigintmat::swapMatrix ( bigintmat a)

Definition at line 1566 of file bigintmat.cc.

1567 {
1568  int n = rows(), m = cols();
1569  row = a->rows();
1570  col = a->cols();
1571  number * V = v;
1572  v = a->v;
1573  a->v = V;
1574  a->row = n;
1575  a->col = m;
1576 }

◆ swaprow()

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

swap rows i and j

Definition at line 704 of file bigintmat.cc.

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

◆ trace()

number bigintmat::trace ( )

the trace ....

Definition at line 1498 of file bigintmat.cc.

1499 {
1500  assume (col == row);
1501  number t = get(1,1),
1502  h;
1503  coeffs r = basecoeffs();
1504  for(int i=2; i<= col; i++) {
1505  h = n_Add(t, view(i,i), r);
1506  n_Delete(&t, r);
1507  t = h;
1508  }
1509  return t;
1510 }

◆ transpose()

bigintmat * bigintmat::transpose ( )

Definition at line 37 of file bigintmat.cc.

38 {
39  bigintmat * t = new bigintmat(col, row, basecoeffs());
40  for (int i=1; i<=row; i++)
41  {
42  for (int j=1; j<=col; j++)
43  {
44  t->set(j, i, BIMATELEM(*this,i,j));
45  }
46  }
47  return t;
48 }
#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 111 of file bigintmat.cc.

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

◆ view() [2/2]

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

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

Definition at line 127 of file bigintmat.cc.

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

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

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

◆ zero()

void bigintmat::zero ( )

Setzt alle Einträge auf 0.

Definition at line 1350 of file bigintmat.cc.

1351 {
1352  number tmp = n_Init(0, basecoeffs());
1353  for (int i=1; i<=row; i++)
1354  {
1355  for (int j=1; j<=col; j++)
1356  {
1357  set(i, j, tmp);
1358  }
1359  }
1360  n_Delete(&tmp,basecoeffs());
1361 }

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: