Macros | Functions
bigintmat.cc File Reference
#include <misc/auxiliary.h>
#include "bigintmat.h"
#include <misc/intvec.h>
#include "rmodulon.h"
#include <math.h>
#include <string.h>

Go to the source code of this file.

Macros

#define swap(_i, _j)
 
#define MIN(a, b)   (a < b ? a : b)
 
#define MAX(a, b)   (a > b ? a : b)
 

Functions

static coeffs numbercoeffs (number n, coeffs c)
 create Z/nA of type n_Zn More...
 
bool operator== (const bigintmat &lhr, const bigintmat &rhr)
 
bool operator!= (const bigintmat &lhr, const bigintmat &rhr)
 
bigintmatbimAdd (bigintmat *a, bigintmat *b)
 Matrix-Add/-Sub/-Mult so oder mit operator+/-/* ? : NULL as a result means an error (non-compatible matrices?) More...
 
bigintmatbimAdd (bigintmat *a, int b)
 
bigintmatbimSub (bigintmat *a, bigintmat *b)
 
bigintmatbimSub (bigintmat *a, int b)
 
bigintmatbimMult (bigintmat *a, bigintmat *b)
 
bigintmatbimMult (bigintmat *a, int b)
 
bigintmatbimMult (bigintmat *a, number b, const coeffs cf)
 
intvecbim2iv (bigintmat *b)
 
bigintmativ2bim (intvec *b, const coeffs C)
 
bigintmatbimCopy (const bigintmat *b)
 same as copy constructor - apart from it being able to accept NULL as input More...
 
static int intArrSum (int *a, int length)
 
static int findLongest (int *a, int length)
 
static int getShorter (int *a, int l, int j, int cols, int rows)
 
bigintmatbimChangeCoeff (bigintmat *a, coeffs cnew)
 Liefert Kopier von Matrix a zurück, mit coeffs cnew statt den ursprünglichen. More...
 
void bimMult (bigintmat *a, bigintmat *b, bigintmat *c)
 Multipliziert Matrix a und b und speichert Ergebnis in c. More...
 
static void reduce_mod_howell (bigintmat *A, bigintmat *b, bigintmat *eps, bigintmat *x)
 
static bigintmatprependIdentity (bigintmat *A)
 
static number bimFarey (bigintmat *A, number N, bigintmat *L)
 
static number solveAx_dixon (bigintmat *A, bigintmat *B, bigintmat *x, bigintmat *kern)
 
static number solveAx_howell (bigintmat *A, bigintmat *b, bigintmat *x, bigintmat *kern)
 
number solveAx (bigintmat *A, bigintmat *b, bigintmat *x)
 solve Ax=b*d. x needs to be pre-allocated to the same number of columns as b. the minimal denominator d is returned. Currently available for Z, Q and Z/nZ (and possibly for all fields: d=1 there) Beware that the internal functions can find the kernel as well - but the interface is lacking. More...
 
void diagonalForm (bigintmat *A, bigintmat **S, bigintmat **T)
 
int kernbase (bigintmat *a, bigintmat *c, number p, coeffs q)
 a basis for the nullspace of a mod p: only used internally in Round2. Don't use it. More...
 
bool nCoeffs_are_equal (coeffs r, coeffs s)
 

Macro Definition Documentation

#define MAX (   a,
  b 
)    (a > b ? a : b)
#define MIN (   a,
  b 
)    (a < b ? a : b)
#define swap (   _i,
  _j 
)
Value:
int __i = (_i), __j=(_j); \
number c = v[__i]; \
v[__i] = v[__j]; \
v[__j] = c \
const Variable & v
< [in] a sqrfree bivariate poly
Definition: facBivar.h:37

Function Documentation

intvec* bim2iv ( bigintmat b)

Definition at line 339 of file bigintmat.cc.

340 {
341  intvec * iv = new intvec(b->rows(), b->cols(), 0);
342  for (int i=0; i<(b->rows())*(b->cols()); i++)
343  (*iv)[i] = n_Int((*b)[i], b->basecoeffs()); // Geht das so?
344  return iv;
345 }
Definition: intvec.h:16
static FORCE_INLINE long n_Int(number &n, const coeffs r)
conversion of n to an int; 0 if not possible in Z/pZ: the representing int lying in (-p/2 ...
Definition: coeffs.h:546
int i
Definition: cfEzgcd.cc:123
int cols() const
Definition: bigintmat.h:128
int rows() const
Definition: bigintmat.h:129
coeffs basecoeffs() const
Definition: bigintmat.h:130
bigintmat* bimAdd ( bigintmat a,
bigintmat b 
)

Matrix-Add/-Sub/-Mult so oder mit operator+/-/* ? : NULL as a result means an error (non-compatible matrices?)

Definition at line 178 of file bigintmat.cc.

179 {
180  if (a->cols() != b->cols()) return NULL;
181  if (a->rows() != b->rows()) return NULL;
182  if (a->basecoeffs() != b->basecoeffs()) { return NULL; }
183 
184  const coeffs basecoeffs = a->basecoeffs();
185 
186  int i;
187 
188  bigintmat * bim = new bigintmat(a->rows(), a->cols(), basecoeffs);
189 
190  for (i=a->rows()*a->cols()-1;i>=0; i--)
191  bim->rawset(i, n_Add((*a)[i], (*b)[i], basecoeffs), basecoeffs);
192 
193  return bim;
194 }
Matrices of numbers.
Definition: bigintmat.h:32
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:180
The main handler for Singular numbers which are suitable for Singular polynomials.
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:653
int i
Definition: cfEzgcd.cc:123
int cols() const
Definition: bigintmat.h:128
int rows() const
Definition: bigintmat.h:129
#define NULL
Definition: omList.c:10
coeffs basecoeffs() const
Definition: bigintmat.h:130
bigintmat* bimAdd ( bigintmat a,
int  b 
)

Definition at line 195 of file bigintmat.cc.

196 {
197 
198  const int mn = a->rows()*a->cols();
199 
200  const coeffs basecoeffs = a->basecoeffs();
201  number bb=n_Init(b,basecoeffs);
202 
203  int i;
204 
205  bigintmat * bim = new bigintmat(a->rows(),a->cols() , basecoeffs);
206 
207  for (i=0; i<mn; i++)
208  bim->rawset(i, n_Add((*a)[i], bb, basecoeffs), basecoeffs);
209 
210  n_Delete(&bb,basecoeffs);
211  return bim;
212 }
Matrices of numbers.
Definition: bigintmat.h:32
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:537
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:180
The main handler for Singular numbers which are suitable for Singular polynomials.
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:653
int i
Definition: cfEzgcd.cc:123
int cols() const
Definition: bigintmat.h:128
int rows() const
Definition: bigintmat.h:129
coeffs basecoeffs() const
Definition: bigintmat.h:130
static FORCE_INLINE void n_Delete(number *p, const coeffs r)
delete 'p'
Definition: coeffs.h:455
const poly b
Definition: syzextra.cc:213
bigintmat* bimChangeCoeff ( bigintmat a,
coeffs  cnew 
)

Liefert Kopier von Matrix a zurück, mit coeffs cnew statt den ursprünglichen.

Definition at line 1688 of file bigintmat.cc.

1689 {
1690  coeffs cold = a->basecoeffs();
1691  bigintmat *b = new bigintmat(a->rows(), a->cols(), cnew);
1692  // Erzeugt Karte von alten coeffs nach neuen
1693  nMapFunc f = n_SetMap(cold, cnew);
1694  number t1;
1695  number t2;
1696  // apply map to all entries.
1697  for (int i=1; i<=a->rows(); i++)
1698  {
1699  for (int j=1; j<=a->cols(); j++)
1700  {
1701  t1 = a->get(i, j);
1702  t2 = f(t1, cold, cnew);
1703  b->set(i, j, t2);
1704  n_Delete(&t1, cold);
1705  n_Delete(&t2, cnew);
1706  }
1707  }
1708  return b;
1709 }
Matrices of numbers.
Definition: bigintmat.h:32
f
Definition: cfModGcd.cc:4022
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:91
int j
Definition: myNF.cc:70
The main handler for Singular numbers which are suitable for Singular polynomials.
number(* nMapFunc)(number a, const coeffs src, const coeffs dst)
maps "a", which lives in src, into dst
Definition: coeffs.h:71
int i
Definition: cfEzgcd.cc:123
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:718
int cols() const
Definition: bigintmat.h:128
int rows() const
Definition: bigintmat.h:129
coeffs basecoeffs() const
Definition: bigintmat.h:130
static FORCE_INLINE void n_Delete(number *p, const coeffs r)
delete 'p'
Definition: coeffs.h:455
const poly b
Definition: syzextra.cc:213
number get(int i, int j) const
get a copy of an entry. NOTE: starts at [1,1]
Definition: bigintmat.cc:115
bigintmat* bimCopy ( const bigintmat b)

same as copy constructor - apart from it being able to accept NULL as input

Definition at line 403 of file bigintmat.cc.

404 {
405  if (b == NULL)
406  return NULL;
407 
408  return new bigintmat(b);
409 }
Matrices of numbers.
Definition: bigintmat.h:32
#define NULL
Definition: omList.c:10
static number bimFarey ( bigintmat A,
number  N,
bigintmat L 
)
static

Definition at line 1919 of file bigintmat.cc.

1919  {
1920  coeffs Z = A->basecoeffs(),
1921  Q = nInitChar(n_Q, 0);
1922  number den = n_Init(1, Z);
1923  nMapFunc f = n_SetMap(Q, Z);
1924 
1925  for(int i=1; i<= A->rows(); i++) {
1926  for(int j=1; j<= A->cols(); j++) {
1927  number ad = n_Mult(den, A->view(i, j), Z);
1928  number re = n_IntMod(ad, N, Z);
1929  n_Delete(&ad, Z);
1930  number q = n_Farey(re, N, Z);
1931  n_Delete(&re, Z);
1932  if (!q) {
1933  n_Delete(&ad, Z);
1934  n_Delete(&den, Z);
1935  return NULL;
1936  }
1937 
1938  number d = n_GetDenom(q, Q),
1939  n = n_GetNumerator(q, Q);
1940 
1941  n_Delete(&q, Q);
1942  n_Delete(&ad, Z);
1943  number dz = f(d, Q, Z),
1944  nz = f(n, Q, Z);
1945  n_Delete(&d, Q);
1946  n_Delete(&n, Q);
1947 
1948  if (!n_IsOne(dz, Z)) {
1949  L->skalmult(dz, Z);
1950  n_InpMult(den, dz, Z);
1951 #if 0
1952  Print("den increasing to ");
1953  n_Print(den, Z);
1954  Print("\n");
1955 #endif
1956  }
1957  n_Delete(&dz, Z);
1958  L->rawset(i, j, nz);
1959  }
1960  }
1961 
1962  nKillChar(Q);
1963  Print("bimFarey worked\n");
1964 #if 0
1965  L->Print();
1966  Print("\n * 1/");
1967  n_Print(den, Z);
1968  Print("\n");
1969 #endif
1970  return den;
1971 }
number view(int i, int j) const
view an entry an entry. NOTE: starts at [1,1]
Definition: bigintmat.cc:123
static FORCE_INLINE number n_IntMod(number a, number b, const coeffs r)
for r a field, return n_Init(0,r) otherwise: n_Div(a,b,r)*b+n_IntMod(a,b,r)==a
Definition: coeffs.h:625
static FORCE_INLINE number n_GetNumerator(number &n, const coeffs r)
return the numerator of n (if elements of r are by nature not fractional, result is n) ...
Definition: coeffs.h:607
#define Print
Definition: emacs.cc:83
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:638
static FORCE_INLINE BOOLEAN n_IsOne(number n, const coeffs r)
TRUE iff 'n' represents the one element.
Definition: coeffs.h:468
f
Definition: cfModGcd.cc:4022
rational (GMP) numbers
Definition: coeffs.h:30
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:537
const CanonicalForm CFMap CFMap int &both_non_zero int n
Definition: cfEzgcd.cc:52
#define Q
Definition: sirandom.c:25
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:180
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:633
const CanonicalForm CFMap CFMap & N
Definition: cfEzgcd.cc:49
int j
Definition: myNF.cc:70
The main handler for Singular numbers which are suitable for Singular polynomials.
number(* nMapFunc)(number a, const coeffs src, const coeffs dst)
maps "a", which lives in src, into dst
Definition: coeffs.h:71
bool skalmult(number b, coeffs c)
Multipliziert zur Matrix den Skalar b hinzu.
Definition: bigintmat.cc:904
int i
Definition: cfEzgcd.cc:123
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:718
int cols() const
Definition: bigintmat.h:128
void Print()
IO: simply prints the matrix to the current output (screen?)
Definition: bigintmat.cc:438
static FORCE_INLINE number n_Farey(number a, number b, const coeffs r)
Definition: coeffs.h:783
int rows() const
Definition: bigintmat.h:129
#define NULL
Definition: omList.c:10
CanonicalForm den(const CanonicalForm &f)
coeffs basecoeffs() const
Definition: bigintmat.h:130
static FORCE_INLINE number n_GetDenom(number &n, const coeffs r)
return the denominator of n (if elements of r are by nature not fractional, result is 1) ...
Definition: coeffs.h:602
static FORCE_INLINE void n_Delete(number *p, const coeffs r)
delete 'p'
Definition: coeffs.h:455
void nKillChar(coeffs r)
undo all initialisations
Definition: numbers.cc:477
void n_Print(number &a, const coeffs r)
print a number (BEWARE of string buffers!) mostly for debugging
Definition: numbers.cc:538
coeffs nInitChar(n_coeffType t, void *parameter)
one-time initialisations for new coeffs in case of an error return NULL
Definition: numbers.cc:316
bigintmat* bimMult ( bigintmat a,
bigintmat b 
)

Definition at line 251 of file bigintmat.cc.

252 {
253  const int ca = a->cols();
254  const int cb = b->cols();
255 
256  const int ra = a->rows();
257  const int rb = b->rows();
258 
259  if (ca != rb)
260  {
261 #ifndef SING_NDEBUG
262  Werror("wrong bigintmat sizes at multiplication a * b: acols: %d != brows: %d\n", ca, rb);
263 #endif
264  return NULL;
265  }
266 
267  assume (ca == rb);
268 
269  if (a->basecoeffs() != b->basecoeffs()) { return NULL; }
270 
271  const coeffs basecoeffs = a->basecoeffs();
272 
273  int i, j, k;
274 
275  number sum;
276 
277  bigintmat * bim = new bigintmat(ra, cb, basecoeffs);
278 
279  for (i=1; i<=ra; i++)
280  for (j=1; j<=cb; j++)
281  {
282  sum = n_Init(0, basecoeffs);
283 
284  for (k=1; k<=ca; k++)
285  {
286  number prod = n_Mult( BIMATELEM(*a, i, k), BIMATELEM(*b, k, j), basecoeffs);
287 
288  number sum2 = n_Add(sum, prod, basecoeffs); // no inplace add :(
289 
290  n_Delete(&sum, basecoeffs); n_Delete(&prod, basecoeffs);
291 
292  sum = sum2;
293  }
294  bim->rawset(i, j, sum, basecoeffs);
295  }
296  return bim;
297 }
Matrices of numbers.
Definition: bigintmat.h:32
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:537
int k
Definition: cfEzgcd.cc:93
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:180
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:633
int j
Definition: myNF.cc:70
#define assume(x)
Definition: mod2.h:405
The main handler for Singular numbers which are suitable for Singular polynomials.
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:653
int i
Definition: cfEzgcd.cc:123
int cols() const
Definition: bigintmat.h:128
#define BIMATELEM(M, I, J)
Definition: bigintmat.h:117
int rows() const
Definition: bigintmat.h:129
#define NULL
Definition: omList.c:10
fq_nmod_poly_t prod
Definition: facHensel.cc:95
coeffs basecoeffs() const
Definition: bigintmat.h:130
static FORCE_INLINE void n_Delete(number *p, const coeffs r)
delete 'p'
Definition: coeffs.h:455
void Werror(const char *fmt,...)
Definition: reporter.cc:199
bigintmat* bimMult ( bigintmat a,
int  b 
)

Definition at line 299 of file bigintmat.cc.

300 {
301 
302  const int mn = a->rows()*a->cols();
303 
304  const coeffs basecoeffs = a->basecoeffs();
305  number bb=n_Init(b,basecoeffs);
306 
307  int i;
308 
309  bigintmat * bim = new bigintmat(a->rows(),a->cols() , basecoeffs);
310 
311  for (i=0; i<mn; i++)
312  bim->rawset(i, n_Mult((*a)[i], bb, basecoeffs), basecoeffs);
313 
314  n_Delete(&bb,basecoeffs);
315  return bim;
316 }
Matrices of numbers.
Definition: bigintmat.h:32
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:537
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:180
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:633
The main handler for Singular numbers which are suitable for Singular polynomials.
int i
Definition: cfEzgcd.cc:123
int cols() const
Definition: bigintmat.h:128
int rows() const
Definition: bigintmat.h:129
coeffs basecoeffs() const
Definition: bigintmat.h:130
static FORCE_INLINE void n_Delete(number *p, const coeffs r)
delete 'p'
Definition: coeffs.h:455
const poly b
Definition: syzextra.cc:213
bigintmat* bimMult ( bigintmat a,
number  b,
const coeffs  cf 
)

Definition at line 318 of file bigintmat.cc.

319 {
320  if (cf!=a->basecoeffs()) return NULL;
321 
322  const int mn = a->rows()*a->cols();
323 
324  const coeffs basecoeffs = a->basecoeffs();
325 
326  int i;
327 
328  bigintmat * bim = new bigintmat(a->rows(),a->cols() , basecoeffs);
329 
330  for (i=0; i<mn; i++)
331  bim->rawset(i, n_Mult((*a)[i], b, basecoeffs), basecoeffs);
332 
333  return bim;
334 }
Matrices of numbers.
Definition: bigintmat.h:32
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:180
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:633
The main handler for Singular numbers which are suitable for Singular polynomials.
int i
Definition: cfEzgcd.cc:123
int cols() const
Definition: bigintmat.h:128
int rows() const
Definition: bigintmat.h:129
#define NULL
Definition: omList.c:10
coeffs basecoeffs() const
Definition: bigintmat.h:130
const poly b
Definition: syzextra.cc:213
void bimMult ( bigintmat a,
bigintmat b,
bigintmat c 
)

Multipliziert Matrix a und b und speichert Ergebnis in c.

Definition at line 1818 of file bigintmat.cc.

1819 {
1820  if (!nCoeffs_are_equal(a->basecoeffs(), b->basecoeffs())) {
1821  Werror("Error in bimMult. Coeffs do not agree!");
1822  return;
1823  }
1824  if ((a->rows() != c->rows()) || (b->cols() != c->cols()) || (a->cols() != b->rows())) {
1825  Werror("Error in bimMult. Dimensions do not agree!");
1826  return;
1827  }
1828  bigintmat *tmp = bimMult(a, b);
1829  c->copy(tmp);
1830 
1831  delete tmp;
1832 }
Matrices of numbers.
Definition: bigintmat.h:32
bigintmat * bimMult(bigintmat *a, bigintmat *b)
Definition: bigintmat.cc:251
int cols() const
Definition: bigintmat.h:128
int rows() const
Definition: bigintmat.h:129
coeffs basecoeffs() const
Definition: bigintmat.h:130
bool copy(bigintmat *b)
Kopiert Einträge von b auf Bigintmat.
Definition: bigintmat.cc:1176
void Werror(const char *fmt,...)
Definition: reporter.cc:199
bool nCoeffs_are_equal(coeffs r, coeffs s)
Definition: bigintmat.cc:2449
bigintmat* bimSub ( bigintmat a,
bigintmat b 
)

Definition at line 214 of file bigintmat.cc.

215 {
216  if (a->cols() != b->cols()) return NULL;
217  if (a->rows() != b->rows()) return NULL;
218  if (a->basecoeffs() != b->basecoeffs()) { return NULL; }
219 
220  const coeffs basecoeffs = a->basecoeffs();
221 
222  int i;
223 
224  bigintmat * bim = new bigintmat(a->rows(), a->cols(), basecoeffs);
225 
226  for (i=a->rows()*a->cols()-1;i>=0; i--)
227  bim->rawset(i, n_Sub((*a)[i], (*b)[i], basecoeffs), basecoeffs);
228 
229  return bim;
230 }
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:666
Matrices of numbers.
Definition: bigintmat.h:32
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:180
The main handler for Singular numbers which are suitable for Singular polynomials.
int i
Definition: cfEzgcd.cc:123
int cols() const
Definition: bigintmat.h:128
int rows() const
Definition: bigintmat.h:129
#define NULL
Definition: omList.c:10
coeffs basecoeffs() const
Definition: bigintmat.h:130
bigintmat* bimSub ( bigintmat a,
int  b 
)

Definition at line 232 of file bigintmat.cc.

233 {
234  const int mn = a->rows()*a->cols();
235 
236  const coeffs basecoeffs = a->basecoeffs();
237  number bb=n_Init(b,basecoeffs);
238 
239  int i;
240 
241  bigintmat * bim = new bigintmat(a->rows(),a->cols() , basecoeffs);
242 
243  for (i=0; i<mn; i++)
244  bim->rawset(i, n_Sub((*a)[i], bb, basecoeffs), basecoeffs);
245 
246  n_Delete(&bb,basecoeffs);
247  return bim;
248 }
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:666
Matrices of numbers.
Definition: bigintmat.h:32
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:537
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:180
The main handler for Singular numbers which are suitable for Singular polynomials.
int i
Definition: cfEzgcd.cc:123
int cols() const
Definition: bigintmat.h:128
int rows() const
Definition: bigintmat.h:129
coeffs basecoeffs() const
Definition: bigintmat.h:130
static FORCE_INLINE void n_Delete(number *p, const coeffs r)
delete 'p'
Definition: coeffs.h:455
const poly b
Definition: syzextra.cc:213
void diagonalForm ( bigintmat A,
bigintmat **  S,
bigintmat **  T 
)

Definition at line 2301 of file bigintmat.cc.

2302 {
2303  bigintmat * t, *s, *a=A;
2304  coeffs R = a->basecoeffs();
2305  if (T) {
2306  *T = new bigintmat(a->cols(), a->cols(), R),
2307  (*T)->one();
2308  t = new bigintmat(*T);
2309  } else {
2310  t = *T;
2311  }
2312 
2313  if (S) {
2314  *S = new bigintmat(a->rows(), a->rows(), R);
2315  (*S)->one();
2316  s = new bigintmat(*S);
2317  } else {
2318  s = *S;
2319  }
2320 
2321  int flip=0;
2322  do {
2323  bigintmat * x, *X;
2324  if (flip) {
2325  x = s;
2326  X = *S;
2327  } else {
2328  x = t;
2329  X = *T;
2330  }
2331 
2332  if (x) {
2333  x->one();
2334  bigintmat * r = new bigintmat(a->rows()+a->cols(), a->cols(), R);
2335  bigintmat * rw = new bigintmat(1, a->cols(), R);
2336  for(int i=0; i<a->cols(); i++) {
2337  x->getrow(i+1, rw);
2338  r->setrow(i+1, rw);
2339  }
2340  for (int i=0; i<a->rows(); i++) {
2341  a->getrow(i+1, rw);
2342  r->setrow(i+a->cols()+1, rw);
2343  }
2344  r->hnf();
2345  for(int i=0; i<a->cols(); i++) {
2346  r->getrow(i+1, rw);
2347  x->setrow(i+1, rw);
2348  }
2349  for(int i=0; i<a->rows(); i++) {
2350  r->getrow(i+a->cols()+1, rw);
2351  a->setrow(i+1, rw);
2352  }
2353  delete rw;
2354  delete r;
2355 
2356 #if 0
2357  Print("X: %ld\n", X);
2358  X->Print();
2359  Print("\nx: %ld\n", x);
2360  x->Print();
2361 #endif
2362  bimMult(X, x, X);
2363 #if 0
2364  Print("\n2:X: %ld %ld %ld\n", X, *S, *T);
2365  X->Print();
2366  Print("\n2:x: %ld\n", x);
2367  x->Print();
2368  Print("\n");
2369 #endif
2370  } else {
2371  a->hnf();
2372  }
2373 
2374  int diag = 1;
2375  for(int i=a->rows(); diag && i>0; i--) {
2376  for(int j=a->cols(); j>0; j--) {
2377  if ((a->rows()-i)!=(a->cols()-j) && !n_IsZero(a->view(i, j), R)) {
2378  diag = 0;
2379  break;
2380  }
2381  }
2382  }
2383 #if 0
2384  Print("Diag ? %d\n", diag);
2385  a->Print();
2386  Print("\n");
2387 #endif
2388  if (diag) break;
2389 
2390  a = a->transpose(); // leaks - I need to write inpTranspose
2391  flip = 1-flip;
2392  } while (1);
2393  if (flip)
2394  a = a->transpose();
2395 
2396  if (S) *S = (*S)->transpose();
2397  if (s) delete s;
2398  if (t) delete t;
2399  A->copy(a);
2400 }
bigintmat * transpose()
Definition: bigintmat.cc:36
number view(int i, int j) const
view an entry an entry. NOTE: starts at [1,1]
Definition: bigintmat.cc:123
const CanonicalForm int s
Definition: facAbsFact.cc:55
const poly a
Definition: syzextra.cc:212
#define Print
Definition: emacs.cc:83
void getrow(int i, bigintmat *a)
Schreibt i-te Zeile in Vektor (Matrix) a.
Definition: bigintmat.cc:779
Matrices of numbers.
Definition: bigintmat.h:32
void setrow(int i, bigintmat *m)
Setzt i-te Zeile gleich übergebenem Vektor (Matrix) m.
Definition: bigintmat.cc:839
const ring r
Definition: syzextra.cc:208
int j
Definition: myNF.cc:70
bigintmat * bimMult(bigintmat *a, bigintmat *b)
Definition: bigintmat.cc:251
The main handler for Singular numbers which are suitable for Singular polynomials.
#define A
Definition: sirandom.c:23
void hnf()
transforms INPLACE to HNF
Definition: bigintmat.cc:1560
int i
Definition: cfEzgcd.cc:123
static FORCE_INLINE BOOLEAN n_IsZero(number n, const coeffs r)
TRUE iff 'n' represents the zero element.
Definition: coeffs.h:464
int cols() const
Definition: bigintmat.h:128
void Print()
IO: simply prints the matrix to the current output (screen?)
Definition: bigintmat.cc:438
std::pair< ideal, ring > flip(const ideal I, const ring r, const gfan::ZVector interiorPoint, const gfan::ZVector facetNormal, const gfan::ZVector adjustedInteriorPoint, const gfan::ZVector adjustedFacetNormal)
Definition: flip.cc:40
int rows() const
Definition: bigintmat.h:129
coeffs basecoeffs() const
Definition: bigintmat.h:130
#define R
Definition: sirandom.c:26
bool copy(bigintmat *b)
Kopiert Einträge von b auf Bigintmat.
Definition: bigintmat.cc:1176
Variable x
Definition: cfModGcd.cc:4023
static jList * T
Definition: janet.cc:37
void one()
Macht Matrix (Falls quadratisch) zu Einheitsmatrix.
Definition: bigintmat.cc:1236
static int findLongest ( int a,
int  length 
)
static

Definition at line 533 of file bigintmat.cc.

534 {
535  int l = 0;
536  int index;
537  for (int i=0; i<length; i++)
538  {
539  if (a[i] > l)
540  {
541  l = a[i];
542  index = i;
543  }
544  }
545  return index;
546 }
const poly a
Definition: syzextra.cc:212
int i
Definition: cfEzgcd.cc:123
static int index(p_Length length, p_Ord ord)
Definition: p_Procs_Impl.h:597
int l
Definition: cfEzgcd.cc:94
static int getShorter ( int a,
int  l,
int  j,
int  cols,
int  rows 
)
static

Definition at line 548 of file bigintmat.cc.

549 {
550  int sndlong = 0;
551  int min;
552  for (int i=0; i<rows; i++)
553  {
554  int index = cols*i+j;
555  if ((a[index] > sndlong) && (a[index] < l))
556  {
557  min = floor(log10((double)cols))+floor(log10((double)rows))+5;
558  if ((a[index] < min) && (min < l))
559  sndlong = min;
560  else
561  sndlong = a[index];
562  }
563  }
564  if (sndlong == 0)
565  {
566  min = floor(log10((double)cols))+floor(log10((double)rows))+5;
567  if (min < l)
568  sndlong = min;
569  else
570  sndlong = 1;
571  }
572  return sndlong;
573 }
const poly a
Definition: syzextra.cc:212
static int min(int a, int b)
Definition: fast_mult.cc:268
int j
Definition: myNF.cc:70
int i
Definition: cfEzgcd.cc:123
static int index(p_Length length, p_Ord ord)
Definition: p_Procs_Impl.h:597
int l
Definition: cfEzgcd.cc:94
static int intArrSum ( int a,
int  length 
)
static

Definition at line 525 of file bigintmat.cc.

526 {
527  int sum = 0;
528  for (int i=0; i<length; i++)
529  sum += a[i];
530  return sum;
531 }
const poly a
Definition: syzextra.cc:212
int i
Definition: cfEzgcd.cc:123
bigintmat* iv2bim ( intvec b,
const coeffs  C 
)

Definition at line 347 of file bigintmat.cc.

348 {
349  const int l = (b->rows())*(b->cols());
350  bigintmat * bim = new bigintmat(b->rows(), b->cols(), C);
351 
352  for (int i=0; i < l; i++)
353  bim->rawset(i, n_Init((*b)[i], C), C);
354 
355  return bim;
356 }
Matrices of numbers.
Definition: bigintmat.h:32
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:537
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:180
int i
Definition: cfEzgcd.cc:123
int cols() const
Definition: intvec.h:86
int rows() const
Definition: intvec.h:87
int l
Definition: cfEzgcd.cc:94
int kernbase ( bigintmat a,
bigintmat c,
number  p,
coeffs  q 
)

a basis for the nullspace of a mod p: only used internally in Round2. Don't use it.

Definition at line 2405 of file bigintmat.cc.

2405  {
2406 #if 0
2407  Print("Kernel of ");
2408  a->Print();
2409  Print(" modulo ");
2410  n_Print(p, q);
2411  Print("\n");
2412 #endif
2413 
2414  coeffs coe = numbercoeffs(p, q);
2415  bigintmat *m = bimChangeCoeff(a, coe), *U, *V;
2416  diagonalForm(m, &U, &V);
2417 #if 0
2418  Print("\ndiag form: ");
2419  m->Print();
2420  Print("\nU:\n");
2421  U->Print();
2422  Print("\nV:\n");
2423  V->Print();
2424  Print("\n");
2425 #endif
2426 
2427  int rg = 0;
2428 #undef MIN
2429 #define MIN(a,b) (a < b ? a : b)
2430  for(rg=0; rg<MIN(m->rows(), m->cols()) && !n_IsZero(m->view(m->rows()-rg,m->cols()-rg), coe); rg++);
2431 
2432 #undef MAX
2433 #define MAX(a,b) (a > b ? a : b)
2434  bigintmat * k = new bigintmat(m->cols(), m->rows(), coe);
2435  for(int i=0; i<rg; i++) {
2436  number A = n_Ann(m->view(m->rows()-i, m->cols()-i), coe);
2437  k->set(m->cols()-i, i+1, A);
2438  n_Delete(&A, coe);
2439  }
2440  for(int i=rg; i<m->cols(); i++) {
2441  k->set(m->cols()-i, i+1-rg, n_Init(1, coe));
2442  }
2443  bimMult(V, k, k);
2444  c->copy(bimChangeCoeff(k, q));
2445  return c->cols();
2446 }
number view(int i, int j) const
view an entry an entry. NOTE: starts at [1,1]
Definition: bigintmat.cc:123
#define Print
Definition: emacs.cc:83
return P p
Definition: myNF.cc:203
Matrices of numbers.
Definition: bigintmat.h:32
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:537
int k
Definition: cfEzgcd.cc:93
#define MIN(a, b)
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:698
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:91
static coeffs numbercoeffs(number n, coeffs c)
create Z/nA of type n_Zn
Definition: bigintmat.cc:21
bigintmat * bimMult(bigintmat *a, bigintmat *b)
Definition: bigintmat.cc:251
The main handler for Singular numbers which are suitable for Singular polynomials.
#define A
Definition: sirandom.c:23
int m
Definition: cfEzgcd.cc:119
int i
Definition: cfEzgcd.cc:123
static FORCE_INLINE BOOLEAN n_IsZero(number n, const coeffs r)
TRUE iff 'n' represents the zero element.
Definition: coeffs.h:464
bigintmat * bimChangeCoeff(bigintmat *a, coeffs cnew)
Liefert Kopier von Matrix a zurück, mit coeffs cnew statt den ursprünglichen.
Definition: bigintmat.cc:1688
int cols() const
Definition: bigintmat.h:128
void diagonalForm(bigintmat *A, bigintmat **S, bigintmat **T)
Definition: bigintmat.cc:2301
void Print()
IO: simply prints the matrix to the current output (screen?)
Definition: bigintmat.cc:438
int rows() const
Definition: bigintmat.h:129
bool copy(bigintmat *b)
Kopiert Einträge von b auf Bigintmat.
Definition: bigintmat.cc:1176
static FORCE_INLINE void n_Delete(number *p, const coeffs r)
delete 'p'
Definition: coeffs.h:455
void n_Print(number &a, const coeffs r)
print a number (BEWARE of string buffers!) mostly for debugging
Definition: numbers.cc:538
bool nCoeffs_are_equal ( coeffs  r,
coeffs  s 
)

Definition at line 2449 of file bigintmat.cc.

2449  {
2450  if ((r == NULL) || (s == NULL))
2451  return false;
2452  if ((getCoeffType(r)==n_Z) && (getCoeffType(s)==n_Z))
2453  return true;
2454  if ((getCoeffType(r)==n_Zp) && (getCoeffType(s)==n_Zp)) {
2455  if (r->ch == s->ch)
2456  return true;
2457  else
2458  return false;
2459  }
2460  // n_Zn stimmt wahrscheinlich noch nicht
2461  if ((getCoeffType(r)==n_Zn) && (getCoeffType(s)==n_Zn)) {
2462  if (r->ch == s->ch)
2463  return true;
2464  else
2465  return false;
2466  }
2467  if ((getCoeffType(r)==n_Q) && (getCoeffType(s)==n_Q))
2468  return true;
2469  // FALL n_Zn FEHLT NOCH!
2470  //if ((getCoeffType(r)==n_Zn) && (getCoeffType(s)==n_Zn))
2471  return false;
2472 }
only used if HAVE_RINGS is defined: ?
Definition: coeffs.h:42
rational (GMP) numbers
Definition: coeffs.h:30
{p < 2^31}
Definition: coeffs.h:29
only used if HAVE_RINGS is defined: ?
Definition: coeffs.h:41
static FORCE_INLINE n_coeffType getCoeffType(const coeffs r)
Returns the type of coeffs domain.
Definition: coeffs.h:421
#define NULL
Definition: omList.c:10
static coeffs numbercoeffs ( number  n,
coeffs  c 
)
static

create Z/nA of type n_Zn

Definition at line 21 of file bigintmat.cc.

22 {
23  mpz_t p;
24  number2mpz(n, c, p);
25  ZnmInfo *pp = new ZnmInfo;
26  pp->base = p;
27  pp->exp = 1;
28  coeffs nc = nInitChar(n_Zn, (void*)pp);
29  mpz_clear(p);
30  delete pp;
31  return nc;
32 }
mpz_ptr base
Definition: rmodulon.h:18
only used if HAVE_RINGS is defined: ?
Definition: coeffs.h:42
return P p
Definition: myNF.cc:203
const CanonicalForm CFMap CFMap int &both_non_zero int n
Definition: cfEzgcd.cc:52
poly pp
Definition: myNF.cc:296
static FORCE_INLINE void number2mpz(number n, coeffs c, mpz_t m)
Definition: coeffs.h:986
The main handler for Singular numbers which are suitable for Singular polynomials.
unsigned long exp
Definition: rmodulon.h:18
coeffs nInitChar(n_coeffType t, void *parameter)
one-time initialisations for new coeffs in case of an error return NULL
Definition: numbers.cc:316
bool operator!= ( const bigintmat lhr,
const bigintmat rhr 
)

Definition at line 172 of file bigintmat.cc.

173 {
174  return !(lhr==rhr);
175 }
bool operator== ( const bigintmat lhr,
const bigintmat rhr 
)

Definition at line 155 of file bigintmat.cc.

156 {
157  if (&lhr == &rhr) { return true; }
158  if (lhr.cols() != rhr.cols()) { return false; }
159  if (lhr.rows() != rhr.rows()) { return false; }
160  if (lhr.basecoeffs() != rhr.basecoeffs()) { return false; }
161 
162  const int l = (lhr.rows())*(lhr.cols());
163 
164  for (int i=0; i < l; i++)
165  {
166  if (!n_Equal(lhr[i], rhr[i], lhr.basecoeffs())) { return false; }
167  }
168 
169  return true;
170 }
int i
Definition: cfEzgcd.cc:123
int cols() const
Definition: bigintmat.h:128
int rows() const
Definition: bigintmat.h:129
coeffs basecoeffs() const
Definition: bigintmat.h:130
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
int l
Definition: cfEzgcd.cc:94
static bigintmat* prependIdentity ( bigintmat A)
static

Definition at line 1907 of file bigintmat.cc.

1908 {
1909  coeffs R = A->basecoeffs();
1910  bigintmat *m = new bigintmat(A->rows()+A->cols(), A->cols(), R);
1911  m->copySubmatInto(A, 1, 1, A->rows(), A->cols(), A->cols()+1, 1);
1912  number one = n_Init(1, R);
1913  for(int i=1; i<= A->cols(); i++)
1914  m->set(i,i,one);
1915  n_Delete(&one, R);
1916  return m;
1917 }
Matrices of numbers.
Definition: bigintmat.h:32
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:537
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:91
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:1202
The main handler for Singular numbers which are suitable for Singular polynomials.
int m
Definition: cfEzgcd.cc:119
int i
Definition: cfEzgcd.cc:123
int cols() const
Definition: bigintmat.h:128
int rows() const
Definition: bigintmat.h:129
coeffs basecoeffs() const
Definition: bigintmat.h:130
#define R
Definition: sirandom.c:26
static FORCE_INLINE void n_Delete(number *p, const coeffs r)
delete 'p'
Definition: coeffs.h:455
static void reduce_mod_howell ( bigintmat A,
bigintmat b,
bigintmat eps,
bigintmat x 
)
static

Definition at line 1834 of file bigintmat.cc.

1834  {
1835  //write b = Ax + eps where eps is "small" in the sense of bounded by the
1836  //pivot entries in H. H does not need to be Howell (or HNF) but need
1837  //to be triagonal in the same direction.
1838  //b can have multiple columns.
1839 #if 0
1840  Print("reduce_mod_howell: A:\n");
1841  A->Print();
1842  Print("\nb:\n");
1843  b->Print();
1844 #endif
1845 
1846  coeffs R = A->basecoeffs();
1847  assume(x->basecoeffs() == R);
1848  assume(b->basecoeffs() == R);
1849  assume(eps->basecoeffs() == R);
1850  if (!A->cols()) {
1851  x->zero();
1852  eps->copy(b);
1853 
1854 #if 0
1855  Print("\nx:\n");
1856  x->Print();
1857  Print("\neps:\n");
1858  eps->Print();
1859  Print("\n****************************************\n");
1860 #endif
1861  return;
1862  }
1863 
1864  bigintmat * B = new bigintmat(b->rows(), 1, R);
1865  for(int i=1; i<= b->cols(); i++) {
1866  int A_col = A->cols();
1867  b->getcol(i, B);
1868  for(int j = B->rows(); j>0; j--) {
1869  number Ai = A->view(A->rows() - B->rows() + j, A_col);
1870  if (n_IsZero(Ai, R) &&
1871  n_IsZero(B->view(j, 1), R)) {
1872  continue; //all is fine: 0*x = 0
1873  } else if (n_IsZero(B->view(j, 1), R)) {
1874  x->rawset(x->rows() - B->rows() + j, i, n_Init(0, R));
1875  A_col--;
1876  } else if (n_IsZero(Ai, R)) {
1877  A_col--;
1878  } else {
1879  // "solve" ax=b, possibly enlarging d
1880  number Bj = B->view(j, 1);
1881  number q = n_Div(Bj, Ai, R);
1882  x->rawset(x->rows() - B->rows() + j, i, q);
1883  for(int k=j; k>B->rows() - A->rows(); k--) {
1884  //B[k] = B[k] - x[k]A[k][j]
1885  number s = n_Mult(q, A->view(A->rows() - B->rows() + k, A_col), R);
1886  B->rawset(k, 1, n_Sub(B->view(k, 1), s, R));
1887  n_Delete(&s, R);
1888  }
1889  A_col--;
1890  }
1891  if (!A_col) {
1892  break;
1893  }
1894  }
1895  eps->setcol(i, B);
1896  }
1897  delete B;
1898 #if 0
1899  Print("\nx:\n");
1900  x->Print();
1901  Print("\neps:\n");
1902  eps->Print();
1903  Print("\n****************************************\n");
1904 #endif
1905 }
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:666
number view(int i, int j) const
view an entry an entry. NOTE: starts at [1,1]
Definition: bigintmat.cc:123
const CanonicalForm int s
Definition: facAbsFact.cc:55
#define Print
Definition: emacs.cc:83
Matrices of numbers.
Definition: bigintmat.h:32
void setcol(int j, bigintmat *m)
Setzt j-te Spalte gleich übergebenem Vektor (Matrix) m.
Definition: bigintmat.cc:810
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:537
void zero()
Setzt alle Einträge auf 0.
Definition: bigintmat.cc:1254
int k
Definition: cfEzgcd.cc:93
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:180
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:633
int j
Definition: myNF.cc:70
#define assume(x)
Definition: mod2.h:405
The main handler for Singular numbers which are suitable for Singular polynomials.
int i
Definition: cfEzgcd.cc:123
static FORCE_INLINE BOOLEAN n_IsZero(number n, const coeffs r)
TRUE iff 'n' represents the zero element.
Definition: coeffs.h:464
int cols() const
Definition: bigintmat.h:128
void Print()
IO: simply prints the matrix to the current output (screen?)
Definition: bigintmat.cc:438
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...
Definition: bigintmat.cc:741
int rows() const
Definition: bigintmat.h:129
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:613
b *CanonicalForm B
Definition: facBivar.cc:51
coeffs basecoeffs() const
Definition: bigintmat.h:130
#define R
Definition: sirandom.c:26
bool copy(bigintmat *b)
Kopiert Einträge von b auf Bigintmat.
Definition: bigintmat.cc:1176
static FORCE_INLINE void n_Delete(number *p, const coeffs r)
delete 'p'
Definition: coeffs.h:455
number solveAx ( bigintmat A,
bigintmat b,
bigintmat x 
)

solve Ax=b*d. x needs to be pre-allocated to the same number of columns as b. the minimal denominator d is returned. Currently available for Z, Q and Z/nZ (and possibly for all fields: d=1 there) Beware that the internal functions can find the kernel as well - but the interface is lacking.

Definition at line 2263 of file bigintmat.cc.

2263  {
2264 #if 0
2265  Print("Solve Ax=b for A=\n");
2266  A->Print();
2267  Print("\nb = \n");
2268  b->Print();
2269  Print("\nx = \n");
2270  x->Print();
2271  Print("\n");
2272 #endif
2273 
2274  coeffs R = A->basecoeffs();
2275  assume (R == b->basecoeffs());
2276  assume (R == x->basecoeffs());
2277  assume ((x->cols() == b->cols()) && (x->rows() == A->cols()) && (A->rows() == b->rows()));
2278 
2279  switch (getCoeffType(R)) {
2280  case n_Z:
2281  return solveAx_dixon(A, b, x, NULL);
2282  case n_Zn:
2283  case n_Znm:
2284  case n_Z2m:
2285  return solveAx_howell(A, b, x, NULL);
2286  case n_Zp:
2287  case n_Q:
2288  case n_GF:
2289  case n_algExt:
2290  case n_transExt:
2291  Warn("have field, should use Gauss or better");
2292  default:
2293  if (R->cfXExtGcd && R->cfAnn) { //assume it's Euclidean
2294  return solveAx_howell(A, b, x, NULL);
2295  }
2296  Werror("have no solve algorithm");
2297  }
2298  return NULL;
2299 }
static number solveAx_dixon(bigintmat *A, bigintmat *B, bigintmat *x, bigintmat *kern)
Definition: bigintmat.cc:1973
#define Print
Definition: emacs.cc:83
only used if HAVE_RINGS is defined: ?
Definition: coeffs.h:42
only used if HAVE_RINGS is defined: ?
Definition: coeffs.h:44
used for all transcendental extensions, i.e., the top-most extension in an extension tower is transce...
Definition: coeffs.h:37
rational (GMP) numbers
Definition: coeffs.h:30
{p < 2^31}
Definition: coeffs.h:29
only used if HAVE_RINGS is defined: ?
Definition: coeffs.h:43
#define assume(x)
Definition: mod2.h:405
The main handler for Singular numbers which are suitable for Singular polynomials.
only used if HAVE_RINGS is defined: ?
Definition: coeffs.h:41
static number solveAx_howell(bigintmat *A, bigintmat *b, bigintmat *x, bigintmat *kern)
Definition: bigintmat.cc:2150
int cols() const
Definition: bigintmat.h:128
static FORCE_INLINE n_coeffType getCoeffType(const coeffs r)
Returns the type of coeffs domain.
Definition: coeffs.h:421
void Print()
IO: simply prints the matrix to the current output (screen?)
Definition: bigintmat.cc:438
int rows() const
Definition: bigintmat.h:129
#define NULL
Definition: omList.c:10
{p^n < 2^16}
Definition: coeffs.h:32
used for all algebraic extensions, i.e., the top-most extension in an extension tower is algebraic ...
Definition: coeffs.h:34
coeffs basecoeffs() const
Definition: bigintmat.h:130
#define R
Definition: sirandom.c:26
void Werror(const char *fmt,...)
Definition: reporter.cc:199
#define Warn
Definition: emacs.cc:80
static number solveAx_dixon ( bigintmat A,
bigintmat B,
bigintmat x,
bigintmat kern 
)
static

Definition at line 1973 of file bigintmat.cc.

1973  {
1974  coeffs R = A->basecoeffs();
1975 
1976  assume(getCoeffType(R) == n_Z);
1977 
1978  number p = n_Init(536870909, R); // PreviousPrime(2^29); not clever
1979  coeffs Rp = numbercoeffs(p, R); // R/pR
1980  bigintmat *Ap = bimChangeCoeff(A, Rp),
1981  *m = prependIdentity(Ap),
1982  *Tp, *Hp;
1983  delete Ap;
1984 
1985  m->howell();
1986  Hp = new bigintmat(A->rows(), A->cols(), Rp);
1987  Hp->copySubmatInto(m, A->cols()+1, 1, A->rows(), A->cols(), 1, 1);
1988  Tp = new bigintmat(A->cols(), A->cols(), Rp);
1989  Tp->copySubmatInto(m, 1, 1, A->cols(), A->cols(), 1, 1);
1990 
1991  int i, j;
1992 
1993  for(i=1; i<= A->cols(); i++) {
1994  for(j=m->rows(); j>A->cols(); j--) {
1995  if (!n_IsZero(m->view(j, i), Rp)) break;
1996  }
1997  if (j>A->cols()) break;
1998  }
1999 // Print("Found nullity (kern dim) of %d\n", i-1);
2000  bigintmat * kp = new bigintmat(A->cols(), i-1, Rp);
2001  kp->copySubmatInto(Tp, 1, 1, A->cols(), i-1, 1, 1);
2002  kp->howell();
2003 
2004  delete m;
2005 
2006  //Hp is the mod-p howell form
2007  //Tp the transformation, mod p
2008  //kp a basis for the kernel, in howell form, mod p
2009 
2010  bigintmat * eps_p = new bigintmat(B->rows(), B->cols(), Rp),
2011  * x_p = new bigintmat(A->cols(), B->cols(), Rp),
2012  * fps_p = new bigintmat(kp->cols(), B->cols(), Rp);
2013 
2014  //initial solution
2015 
2016  number zero = n_Init(0, R);
2017  x->skalmult(zero, R);
2018  n_Delete(&zero, R);
2019 
2020  bigintmat * b = new bigintmat(B);
2021  number pp = n_Init(1, R);
2022  i = 1;
2023  do {
2024  bigintmat * b_p = bimChangeCoeff(b, Rp), * s;
2025  bigintmat * t1, *t2;
2026  reduce_mod_howell(Hp, b_p, eps_p, x_p);
2027  delete b_p;
2028  if (!eps_p->isZero()) {
2029  Print("no solution, since no modular solution\n");
2030 
2031  delete eps_p;
2032  delete x_p;
2033  delete Hp;
2034  delete kp;
2035  delete Tp;
2036  delete b;
2037  n_Delete(&pp, R);
2038  n_Delete(&p, R);
2039  nKillChar(Rp);
2040 
2041  return NULL;
2042  }
2043  t1 = bimMult(Tp, x_p);
2044  delete x_p;
2045  x_p = t1;
2046  reduce_mod_howell(kp, x_p, x_p, fps_p); //we're not all interested in fps_p
2047  s = bimChangeCoeff(x_p, R);
2048  t1 = bimMult(A, s);
2049  t2 = bimSub(b, t1);
2050  t2->skaldiv(p);
2051  delete b;
2052  delete t1;
2053  b = t2;
2054  s->skalmult(pp, R);
2055  t1 = bimAdd(x, s);
2056  delete s;
2057  x->swapMatrix(t1);
2058  delete t1;
2059 
2060  if(kern && i==1) {
2061  bigintmat * ker = bimChangeCoeff(kp, R);
2062  t1 = bimMult(A, ker);
2063  t1->skaldiv(p);
2064  t1->skalmult(n_Init(-1, R), R);
2065  b->appendCol(t1);
2066  delete t1;
2067  x->appendCol(ker);
2068  delete ker;
2069  x_p->extendCols(kp->cols());
2070  eps_p->extendCols(kp->cols());
2071  fps_p->extendCols(kp->cols());
2072  }
2073 
2074  n_InpMult(pp, p, R);
2075 
2076  if (b->isZero()) {
2077  //exact solution found, stop
2078  delete eps_p;
2079  delete fps_p;
2080  delete x_p;
2081  delete Hp;
2082  delete kp;
2083  delete Tp;
2084  delete b;
2085  n_Delete(&pp, R);
2086  n_Delete(&p, R);
2087  nKillChar(Rp);
2088 
2089  return n_Init(1, R);
2090  } else {
2091  bigintmat *y = new bigintmat(x->rows(), x->cols(), R);
2092  number d = bimFarey(x, pp, y);
2093  if (d) {
2094  bigintmat *c = bimMult(A, y);
2095  bigintmat *bd = new bigintmat(B);
2096  bd->skalmult(d, R);
2097  if (kern) {
2098  bd->extendCols(kp->cols());
2099  }
2100  if (*c == *bd) {
2101  x->swapMatrix(y);
2102  delete y;
2103  delete c;
2104  if (kern) {
2105  y = new bigintmat(x->rows(), B->cols(), R);
2106  c = new bigintmat(x->rows(), kp->cols(), R);
2107  x->splitcol(y, c);
2108  x->swapMatrix(y);
2109  delete y;
2110  kern->swapMatrix(c);
2111  delete c;
2112  }
2113 
2114  delete bd;
2115 
2116  delete eps_p;
2117  delete fps_p;
2118  delete x_p;
2119  delete Hp;
2120  delete kp;
2121  delete Tp;
2122  delete b;
2123  n_Delete(&pp, R);
2124  n_Delete(&p, R);
2125  nKillChar(Rp);
2126 
2127  return d;
2128  }
2129  delete c;
2130  delete bd;
2131  n_Delete(&d, R);
2132  }
2133  delete y;
2134  }
2135  i++;
2136  } while (1);
2137  delete eps_p;
2138  delete fps_p;
2139  delete x_p;
2140  delete Hp;
2141  delete kp;
2142  delete Tp;
2143  n_Delete(&pp, R);
2144  n_Delete(&p, R);
2145  nKillChar(Rp);
2146  return NULL;
2147 }
void skaldiv(number b)
Macht Ganzzahldivision aller Matrixeinträge mit b.
Definition: bigintmat.cc:1739
void splitcol(bigintmat *a, bigintmat *b)
... linken ... rechten ...
Definition: bigintmat.cc:1105
const CanonicalForm int s
Definition: facAbsFact.cc:55
const CanonicalForm int const CFList const Variable & y
Definition: facAbsFact.cc:57
#define Print
Definition: emacs.cc:83
bigintmat * bimSub(bigintmat *a, bigintmat *b)
Definition: bigintmat.cc:214
static bigintmat * prependIdentity(bigintmat *A)
Definition: bigintmat.cc:1907
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:638
return P p
Definition: myNF.cc:203
Matrices of numbers.
Definition: bigintmat.h:32
void appendCol(bigintmat *a)
horizontally join the matrices, m <- m|a
Definition: bigintmat.cc:1032
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:537
bigintmat * bimAdd(bigintmat *a, bigintmat *b)
Matrix-Add/-Sub/-Mult so oder mit operator+/-/* ? : NULL as a result means an error (non-compatible m...
Definition: bigintmat.cc:178
poly pp
Definition: myNF.cc:296
static coeffs numbercoeffs(number n, coeffs c)
create Z/nA of type n_Zn
Definition: bigintmat.cc:21
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:1202
int j
Definition: myNF.cc:70
bigintmat * bimMult(bigintmat *a, bigintmat *b)
Definition: bigintmat.cc:251
static number bimFarey(bigintmat *A, number N, bigintmat *L)
Definition: bigintmat.cc:1919
static void reduce_mod_howell(bigintmat *A, bigintmat *b, bigintmat *eps, bigintmat *x)
Definition: bigintmat.cc:1834
void extendCols(int i)
append i zero-columns to the matrix
Definition: bigintmat.cc:1027
#define assume(x)
Definition: mod2.h:405
void swapMatrix(bigintmat *a)
Definition: bigintmat.cc:1466
The main handler for Singular numbers which are suitable for Singular polynomials.
bool skalmult(number b, coeffs c)
Multipliziert zur Matrix den Skalar b hinzu.
Definition: bigintmat.cc:904
int m
Definition: cfEzgcd.cc:119
only used if HAVE_RINGS is defined: ?
Definition: coeffs.h:41
int i
Definition: cfEzgcd.cc:123
static FORCE_INLINE BOOLEAN n_IsZero(number n, const coeffs r)
TRUE iff 'n' represents the zero element.
Definition: coeffs.h:464
bigintmat * bimChangeCoeff(bigintmat *a, coeffs cnew)
Liefert Kopier von Matrix a zurück, mit coeffs cnew statt den ursprünglichen.
Definition: bigintmat.cc:1688
int cols() const
Definition: bigintmat.h:128
static FORCE_INLINE n_coeffType getCoeffType(const coeffs r)
Returns the type of coeffs domain.
Definition: coeffs.h:421
int rows() const
Definition: bigintmat.h:129
#define NULL
Definition: omList.c:10
coeffs basecoeffs() const
Definition: bigintmat.h:130
#define R
Definition: sirandom.c:26
static FORCE_INLINE void n_Delete(number *p, const coeffs r)
delete 'p'
Definition: coeffs.h:455
int isZero()
Definition: bigintmat.cc:1264
const poly b
Definition: syzextra.cc:213
void howell()
dito, but Howell form (only different for zero-divsors)
Definition: bigintmat.cc:1485
void nKillChar(coeffs r)
undo all initialisations
Definition: numbers.cc:477
static number solveAx_howell ( bigintmat A,
bigintmat b,
bigintmat x,
bigintmat kern 
)
static

Definition at line 2150 of file bigintmat.cc.

2150  {
2151  // try to solve Ax=b, more precisely, find
2152  // number d
2153  // bigintmat x
2154  // sth. Ax=db
2155  // where d is small-ish (divides the determinant of A if this makes sense)
2156  // return 0 if there is no solution.
2157  //
2158  // if kern is non-NULL, return a basis for the kernel
2159 
2160  //Algo: we do row-howell (triangular matrix). The idea is
2161  // Ax = b <=> AT T^-1x = b
2162  // y := T^-1 x, solve AT y = b
2163  // and return Ty.
2164  //Howell does not compute the trafo, hence we need to cheat:
2165  //B := (I_n | A^t)^t, then the top part of the Howell form of
2166  //B will give a useful trafo
2167  //Then we can find x by back-substitution and lcm/gcd to find the denominator
2168  //The defining property of Howell makes this work.
2169 
2170  coeffs R = A->basecoeffs();
2171  bigintmat *m = prependIdentity(A);
2172  m->howell(); // since m contains the identity, we'll have A->cols()
2173  // many cols.
2174  number den = n_Init(1, R);
2175 
2176  bigintmat * B = new bigintmat(A->rows(), 1, R);
2177  for(int i=1; i<= b->cols(); i++) {
2178  int A_col = A->cols();
2179  b->getcol(i, B);
2180  B->skalmult(den, R);
2181  for(int j = B->rows(); j>0; j--) {
2182  number Ai = m->view(m->rows()-B->rows() + j, A_col);
2183  if (n_IsZero(Ai, R) &&
2184  n_IsZero(B->view(j, 1), R)) {
2185  continue; //all is fine: 0*x = 0
2186  } else if (n_IsZero(B->view(j, 1), R)) {
2187  x->rawset(x->rows() - B->rows() + j, i, n_Init(0, R));
2188  A_col--;
2189  } else if (n_IsZero(Ai, R)) {
2190  delete m;
2191  delete B;
2192  n_Delete(&den, R);
2193  return 0;
2194  } else {
2195  // solve ax=db, possibly enlarging d
2196  // so x = db/a
2197  number Bj = B->view(j, 1);
2198  number g = n_Gcd(Bj, Ai, R);
2199  number xi;
2200  if (n_Equal(Ai, g, R)) { //good: den stable!
2201  xi = n_Div(Bj, Ai, R);
2202  } else { //den <- den * (a/g), so old sol. needs to be adjusted
2203  number inc_d = n_Div(Ai, g, R);
2204  n_InpMult(den, inc_d, R);
2205  x->skalmult(inc_d, R);
2206  B->skalmult(inc_d, R);
2207  xi = n_Div(Bj, g, R);
2208  n_Delete(&inc_d, R);
2209  } //now for the back-substitution:
2210  x->rawset(x->rows() - B->rows() + j, i, xi);
2211  for(int k=j; k>0; k--) {
2212  //B[k] = B[k] - x[k]A[k][j]
2213  number s = n_Mult(xi, m->view(m->rows()-B->rows() + k, A_col), R);
2214  B->rawset(k, 1, n_Sub(B->view(k, 1), s, R));
2215  n_Delete(&s, R);
2216  }
2217  n_Delete(&g, R);
2218  A_col--;
2219  }
2220  if (!A_col) {
2221  if (B->isZero()) break;
2222  else {
2223  delete m;
2224  delete B;
2225  n_Delete(&den, R);
2226  return 0;
2227  }
2228  }
2229  }
2230  }
2231  delete B;
2232  bigintmat *T = new bigintmat(A->cols(), A->cols(), R);
2233  T->copySubmatInto(m, 1, 1, A->cols(), A->cols(), 1, 1);
2234  if (kern) {
2235  int i, j;
2236  for(i=1; i<= A->cols(); i++) {
2237  for(j=m->rows(); j>A->cols(); j--) {
2238  if (!n_IsZero(m->view(j, i), R)) break;
2239  }
2240  if (j>A->cols()) break;
2241  }
2242  Print("Found nullity (kern dim) of %d\n", i-1);
2243  bigintmat * ker = new bigintmat(A->rows(), i-1, R);
2244  ker->copySubmatInto(T, 1, 1, A->rows(), i-1, 1, 1);
2245  kern->swapMatrix(ker);
2246  delete ker;
2247  }
2248  delete m;
2249  bigintmat * y = bimMult(T, x);
2250  x->swapMatrix(y);
2251  delete y;
2252  x->simplifyContentDen(&den);
2253 #if 0
2254  Print("sol = 1/");
2255  n_Print(den, R);
2256  Print(" *\n");
2257  x->Print();
2258  Print("\n");
2259 #endif
2260  return den;
2261 }
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:666
number view(int i, int j) const
view an entry an entry. NOTE: starts at [1,1]
Definition: bigintmat.cc:123
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:683
const CanonicalForm int s
Definition: facAbsFact.cc:55
const CanonicalForm int const CFList const Variable & y
Definition: facAbsFact.cc:57
#define Print
Definition: emacs.cc:83
static bigintmat * prependIdentity(bigintmat *A)
Definition: bigintmat.cc:1907
void simplifyContentDen(number *den)
ensures that Gcd(den, content)=1 < enden hier wieder
Definition: bigintmat.cc:2486
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:638
Matrices of numbers.
Definition: bigintmat.h:32
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:537
g
Definition: cfModGcd.cc:4031
int k
Definition: cfEzgcd.cc:93
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:180
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:633
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:1202
int j
Definition: myNF.cc:70
bigintmat * bimMult(bigintmat *a, bigintmat *b)
Definition: bigintmat.cc:251
void swapMatrix(bigintmat *a)
Definition: bigintmat.cc:1466
The main handler for Singular numbers which are suitable for Singular polynomials.
bool skalmult(number b, coeffs c)
Multipliziert zur Matrix den Skalar b hinzu.
Definition: bigintmat.cc:904
int m
Definition: cfEzgcd.cc:119
int i
Definition: cfEzgcd.cc:123
static FORCE_INLINE BOOLEAN n_IsZero(number n, const coeffs r)
TRUE iff 'n' represents the zero element.
Definition: coeffs.h:464
int cols() const
Definition: bigintmat.h:128
void Print()
IO: simply prints the matrix to the current output (screen?)
Definition: bigintmat.cc:438
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...
Definition: bigintmat.cc:741
int rows() const
Definition: bigintmat.h:129
CanonicalForm den(const CanonicalForm &f)
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:613
b *CanonicalForm B
Definition: facBivar.cc:51
coeffs basecoeffs() const
Definition: bigintmat.h:130
#define R
Definition: sirandom.c:26
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
static FORCE_INLINE void n_Delete(number *p, const coeffs r)
delete 'p'
Definition: coeffs.h:455
static jList * T
Definition: janet.cc:37
int isZero()
Definition: bigintmat.cc:1264
void howell()
dito, but Howell form (only different for zero-divsors)
Definition: bigintmat.cc:1485
void n_Print(number &a, const coeffs r)
print a number (BEWARE of string buffers!) mostly for debugging
Definition: numbers.cc:538