My Project
Loading...
Searching...
No Matches
Data Structures | Functions
matpol.cc File Reference
#include "misc/auxiliary.h"
#include "misc/mylimits.h"
#include "misc/intvec.h"
#include "coeffs/numbers.h"
#include "reporter/reporter.h"
#include "monomials/ring.h"
#include "monomials/p_polys.h"
#include "simpleideals.h"
#include "matpol.h"
#include "prCopy.h"
#include "clapsing.h"
#include "sparsmat.h"

Go to the source code of this file.

Data Structures

class  row_col_weight
 
class  mp_permmatrix
 

Functions

static poly mp_Exdiv (poly m, poly d, poly vars, const ring)
 
static poly mp_Select (poly fro, poly what, const ring)
 
static poly mp_SelectId (ideal I, poly what, const ring R)
 
matrix mpNew (int r, int c)
 create a r x c zero-matrix More...
 
matrix mp_Copy (matrix a, const ring r)
 copies matrix a (from ring r to r) More...
 
matrix mp_Copy (const matrix a, const ring rSrc, const ring rDst)
 copies matrix a from rSrc into rDst More...
 
matrix mp_InitP (int r, int c, poly p, const ring R)
 make it a p * unit matrix More...
 
matrix mp_InitI (int r, int c, int v, const ring R)
 make it a v * unit matrix More...
 
matrix mp_MultI (matrix a, long f, const ring R)
 c = f*a More...
 
matrix mp_MultP (matrix a, poly p, const ring R)
 multiply a matrix 'a' by a poly 'p', destroy the args More...
 
matrix pMultMp (poly p, matrix a, const ring R)
 
matrix mp_Add (matrix a, matrix b, const ring R)
 
matrix mp_Sub (matrix a, matrix b, const ring R)
 
matrix mp_Mult (matrix a, matrix b, const ring R)
 
matrix mp_Transp (matrix a, const ring R)
 
poly mp_Trace (matrix a, const ring R)
 
poly TraceOfProd (matrix a, matrix b, int n, const ring R)
 
matrix mp_Coeffs (ideal I, int var, const ring R)
 corresponds to Maple's coeffs: var has to be the number of a variable More...
 
void mp_Monomials (matrix c, int r, int var, matrix m, const ring R)
 
matrix mp_CoeffProc (poly f, poly vars, const ring R)
 
matrix mp_CoeffProcId (ideal I, poly vars, const ring R)
 
void mp_Coef2 (poly v, poly mon, matrix *c, matrix *m, const ring R)
 corresponds to Macauley's coef: the exponent vector of vars has to contain the variables, eg 'xy'; then the poly f is searched for monomials in x and y, these monimials are written to the first row of the matrix co. the second row of co contains the respective factors in f. Thus f = sum co[1,i]*co[2,i], i = 1..cols, rows equals 2. More...
 
int mp_Compare (matrix a, matrix b, const ring R)
 
BOOLEAN mp_Equal (matrix a, matrix b, const ring R)
 
static poly p_Insert (poly p1, poly p2, const ring R)
 
static void mp_PartClean (matrix a, int lr, int lc, const ring R)
 
BOOLEAN mp_IsDiagUnit (matrix U, const ring R)
 
void iiWriteMatrix (matrix im, const char *n, int dim, const ring r, int spaces)
 set spaces to zero by default More...
 
char * iiStringMatrix (matrix im, int dim, const ring r, char ch)
 
void mp_Delete (matrix *a, const ring r)
 
static float mp_PolyWeight (poly p, const ring r)
 
static void mpReplace (int j, int n, int &sign, int *perm)
 
static int mp_PivBar (matrix a, int lr, int lc, const ring r)
 
static void mpSwapRow (matrix a, int pos, int lr, int lc)
 
static int mp_PrepareRow (matrix a, int lr, int lc, const ring R)
 
static int mp_PivRow (matrix a, int lr, int lc, const ring r)
 
static void mpSwapCol (matrix a, int pos, int lr, int lc)
 
static int mp_PreparePiv (matrix a, int lr, int lc, const ring r)
 
static void mp_ElimBar (matrix a0, matrix re, poly div, int lr, int lc, const ring R)
 
void mp_MinorToResult (ideal result, int &elems, matrix a, int r, int c, ideal R, const ring)
 entries of a are minors and go to result (only if not in R) More...
 
static void mpFinalClean (matrix a)
 
void mp_RecMin (int ar, ideal result, int &elems, matrix a, int lr, int lc, poly barDiv, ideal R, const ring r)
 produces recursively the ideal of all arxar-minors of a More...
 
poly mp_DetBareiss (matrix a, const ring r)
 returns the determinant of the matrix m; uses Bareiss algorithm More...
 
matrix mp_Wedge (matrix a, int ar, const ring R)
 
static ideal sm_MultAndShift (poly f, ideal B, int s, const ring r)
 
static void sm_AddSubMat (ideal res, ideal sm, int col, const ring r)
 
ideal sm_Tensor (ideal A, ideal B, const ring r)
 
ideal sm_Add (ideal a, ideal b, const ring R)
 
ideal sm_Sub (ideal a, ideal b, const ring R)
 
ideal sm_Mult (ideal a, ideal b, const ring R)
 
ideal sm_Flatten (ideal a, const ring R)
 
ideal sm_UnFlatten (ideal a, int col, const ring R)
 
poly sm_Trace (ideal a, const ring R)
 
int sm_Compare (ideal a, ideal b, const ring R)
 
BOOLEAN sm_Equal (ideal a, ideal b, const ring R)
 
static matrix mu (matrix A, const ring R)
 
poly mp_DetMu (matrix A, const ring R)
 
DetVariant mp_GetAlgorithmDet (matrix m, const ring r)
 
DetVariant mp_GetAlgorithmDet (const char *s)
 
poly mp_Det (matrix a, const ring r, DetVariant d)
 
poly sm_Det (ideal a, const ring r, DetVariant d)
 

Function Documentation

◆ iiStringMatrix()

char * iiStringMatrix ( matrix  im,
int  dim,
const ring  r,
char  ch 
)

Definition at line 848 of file matpol.cc.

849{
850 int i,ii = MATROWS(im);
851 int j,jj = MATCOLS(im);
852 poly *pp = im->m;
853 char ch_s[2];
854 ch_s[0]=ch;
855 ch_s[1]='\0';
856
857 StringSetS("");
858
859 for (i=0; i<ii; i++)
860 {
861 for (j=0; j<jj; j++)
862 {
863 p_String0(*pp++, r);
864 StringAppendS(ch_s);
865 if (dim > 1) StringAppendS("\n");
866 }
867 }
868 char *s=StringEndS();
869 s[strlen(s)- (dim > 1 ? 2 : 1)]='\0';
870 return s;
871}
CanonicalForm FACTORY_PUBLIC pp(const CanonicalForm &)
CanonicalForm pp ( const CanonicalForm & f )
Definition: cf_gcd.cc:676
int i
Definition: cfEzgcd.cc:132
poly * m
Definition: matpol.h:18
const CanonicalForm int s
Definition: facAbsFact.cc:51
int j
Definition: facHensel.cc:110
#define MATROWS(i)
Definition: matpol.h:26
#define MATCOLS(i)
Definition: matpol.h:27
void p_String0(poly p, ring lmRing, ring tailRing)
print p according to ShortOut in lmRing & tailRing
Definition: polys0.cc:223
void StringSetS(const char *st)
Definition: reporter.cc:128
void StringAppendS(const char *st)
Definition: reporter.cc:107
char * StringEndS()
Definition: reporter.cc:151
int dim(ideal I, ring r)

◆ iiWriteMatrix()

void iiWriteMatrix ( matrix  im,
const char *  n,
int  dim,
const ring  r,
int  spaces 
)

set spaces to zero by default

Definition at line 827 of file matpol.cc.

828{
829 int i,ii = MATROWS(im)-1;
830 int j,jj = MATCOLS(im)-1;
831 poly *pp = im->m;
832
833 for (i=0; i<=ii; i++)
834 {
835 for (j=0; j<=jj; j++)
836 {
837 if (spaces>0)
838 Print("%-*.*s",spaces,spaces," ");
839 if (dim == 2) Print("%s[%u,%u]=",n,i+1,j+1);
840 else if (dim == 1) Print("%s[%u]=",n,j+1);
841 else if (dim == 0) Print("%s=",n);
842 if ((i<ii)||(j<jj)) p_Write(*pp++, r);
843 else p_Write0(*pp, r);
844 }
845 }
846}
#define Print
Definition: emacs.cc:80
void p_Write(poly p, ring lmRing, ring tailRing)
Definition: polys0.cc:342
void p_Write0(poly p, ring lmRing, ring tailRing)
Definition: polys0.cc:332

◆ mp_Add()

matrix mp_Add ( matrix  a,
matrix  b,
const ring  R 
)

Definition at line 172 of file matpol.cc.

173{
174 int k, n = a->nrows, m = a->ncols;
175 if ((n != b->nrows) || (m != b->ncols))
176 {
177/*
178* Werror("cannot add %dx%d matrix and %dx%d matrix",
179* m,n,b->cols(),b->rows());
180*/
181 return NULL;
182 }
183 matrix c = mpNew(n,m);
184 for (k=m*n-1; k>=0; k--)
185 c->m[k] = p_Add_q(p_Copy(a->m[k], R), p_Copy(b->m[k], R), R);
186 return c;
187}
int m
Definition: cfEzgcd.cc:128
int k
Definition: cfEzgcd.cc:99
CanonicalForm b
Definition: cfModGcd.cc:4103
int nrows
Definition: matpol.h:20
int ncols
Definition: matpol.h:21
matrix mpNew(int r, int c)
create a r x c zero-matrix
Definition: matpol.cc:37
#define NULL
Definition: omList.c:12
static poly p_Add_q(poly p, poly q, const ring r)
Definition: p_polys.h:934
static poly p_Copy(poly p, const ring r)
returns a copy of p
Definition: p_polys.h:844
#define R
Definition: sirandom.c:27

◆ mp_Coef2()

void mp_Coef2 ( poly  v,
poly  mon,
matrix c,
matrix m,
const ring  R 
)

corresponds to Macauley's coef: the exponent vector of vars has to contain the variables, eg 'xy'; then the poly f is searched for monomials in x and y, these monimials are written to the first row of the matrix co. the second row of co contains the respective factors in f. Thus f = sum co[1,i]*co[2,i], i = 1..cols, rows equals 2.

Definition at line 574 of file matpol.cc.

575{
576 poly* s;
577 poly p;
578 int sl,i,j;
579 int l=0;
580 poly sel=mp_Select(v,mon, R);
581
582 p_Vec2Polys(sel,&s,&sl, R);
583 for (i=0; i<sl; i++)
584 l=si_max(l,pLength(s[i]));
585 *c=mpNew(sl,l);
586 *m=mpNew(sl,l);
587 poly h;
588 int isConst;
589 for (j=1; j<=sl;j++)
590 {
591 p=s[j-1];
592 if (p_IsConstant(p, R)) /*p != NULL */
593 {
594 isConst=-1;
595 i=l;
596 }
597 else
598 {
599 isConst=1;
600 i=1;
601 }
602 while(p!=NULL)
603 {
604 h = p_Head(p, R);
605 MATELEM(*m,j,i) = h;
606 i+=isConst;
607 p = p->next;
608 }
609 }
610 while (v!=NULL)
611 {
612 i = 1;
613 j = __p_GetComp(v, R);
614 loop
615 {
616 poly mp=MATELEM(*m,j,i);
617 if (mp!=NULL)
618 {
619 h = mp_Exdiv(v, mp /*MATELEM(*m,j,i)*/, mp, R);
620 if (h!=NULL)
621 {
622 p_SetComp(h,0, R);
623 MATELEM(*c,j,i) = p_Add_q(MATELEM(*c,j,i), h, R);
624 break;
625 }
626 }
627 if (i < l)
628 i++;
629 else
630 break;
631 }
632 v = v->next;
633 }
634}
static int si_max(const int a, const int b)
Definition: auxiliary.h:124
int l
Definition: cfEzgcd.cc:100
int p
Definition: cfModGcd.cc:4078
Variable next() const
Definition: variable.h:52
const Variable & v
< [in] a sqrfree bivariate poly
Definition: facBivar.h:39
STATIC_VAR Poly * h
Definition: janet.cc:971
static poly mp_Exdiv(poly m, poly d, poly vars, const ring)
Definition: matpol.cc:554
static poly mp_Select(poly fro, poly what, const ring)
Definition: matpol.cc:741
#define MATELEM(mat, i, j)
1-based access to matrix
Definition: matpol.h:29
#define __p_GetComp(p, r)
Definition: monomials.h:63
void p_Vec2Polys(poly v, poly **p, int *len, const ring r)
Definition: p_polys.cc:3625
static int pLength(poly a)
Definition: p_polys.h:188
static unsigned long p_SetComp(poly p, unsigned long c, ring r)
Definition: p_polys.h:245
static poly p_Head(const poly p, const ring r)
copy the (leading) term of p
Definition: p_polys.h:858
static BOOLEAN p_IsConstant(const poly p, const ring r)
Definition: p_polys.h:1962
#define loop
Definition: structs.h:75

◆ mp_CoeffProc()

matrix mp_CoeffProc ( poly  f,
poly  vars,
const ring  R 
)

Definition at line 392 of file matpol.cc.

393{
394 assume(vars!=NULL);
395 poly sel, h;
396 int l, i;
397 int pos_of_1 = -1;
398 matrix co;
399
400 if (f==NULL)
401 {
402 co = mpNew(2, 1);
403 MATELEM(co,1,1) = p_One(R);
404 //MATELEM(co,2,1) = NULL;
405 return co;
406 }
407 sel = mp_Select(f, vars, R);
408 l = pLength(sel);
409 co = mpNew(2, l);
410
412 {
413 for (i=l; i>=1; i--)
414 {
415 h = sel;
416 pIter(sel);
417 pNext(h)=NULL;
418 MATELEM(co,1,i) = h;
419 //MATELEM(co,2,i) = NULL;
420 if (p_IsConstant(h, R)) pos_of_1 = i;
421 }
422 }
423 else
424 {
425 for (i=1; i<=l; i++)
426 {
427 h = sel;
428 pIter(sel);
429 pNext(h)=NULL;
430 MATELEM(co,1,i) = h;
431 //MATELEM(co,2,i) = NULL;
432 if (p_IsConstant(h, R)) pos_of_1 = i;
433 }
434 }
435 while (f!=NULL)
436 {
437 i = 1;
438 loop
439 {
440 if (i!=pos_of_1)
441 {
442 h = mp_Exdiv(f, MATELEM(co,1,i),vars, R);
443 if (h!=NULL)
444 {
445 MATELEM(co,2,i) = p_Add_q(MATELEM(co,2,i), h, R);
446 break;
447 }
448 }
449 if (i == l)
450 {
451 // check monom 1 last:
452 if (pos_of_1 != -1)
453 {
454 h = mp_Exdiv(f, MATELEM(co,1,pos_of_1),vars, R);
455 if (h!=NULL)
456 {
457 MATELEM(co,2,pos_of_1) = p_Add_q(MATELEM(co,2,pos_of_1), h, R);
458 }
459 }
460 break;
461 }
462 i ++;
463 }
464 pIter(f);
465 }
466 return co;
467}
FILE * f
Definition: checklibs.c:9
#define assume(x)
Definition: mod2.h:389
#define pIter(p)
Definition: monomials.h:37
#define pNext(p)
Definition: monomials.h:36
poly p_One(const ring r)
Definition: p_polys.cc:1313
BOOLEAN rHasLocalOrMixedOrdering(const ring r)
Definition: ring.h:760

◆ mp_CoeffProcId()

matrix mp_CoeffProcId ( ideal  I,
poly  vars,
const ring  R 
)

Definition at line 469 of file matpol.cc.

470{
471 assume(vars!=NULL);
472 poly sel, h;
473 int l, i;
474 int pos_of_1 = -1;
475 matrix co;
476
477 if (idIs0(I))
478 {
479 co = mpNew(IDELEMS(I)+1,1);
480 MATELEM(co,1,1) = p_One(R);
481 return co;
482 }
483 sel = mp_SelectId(I, vars, R);
484 l = pLength(sel);
485 co = mpNew(IDELEMS(I)+1, l);
486
488 {
489 for (i=l; i>=1; i--)
490 {
491 h = sel;
492 pIter(sel);
493 pNext(h)=NULL;
494 MATELEM(co,1,i) = h;
495 //MATELEM(co,2,i) = NULL;
496 if (p_IsConstant(h, R)) pos_of_1 = i;
497 }
498 }
499 else
500 {
501 for (i=1; i<=l; i++)
502 {
503 h = sel;
504 pIter(sel);
505 pNext(h)=NULL;
506 MATELEM(co,1,i) = h;
507 //MATELEM(co,2,i) = NULL;
508 if (p_IsConstant(h, R)) pos_of_1 = i;
509 }
510 }
511 for(int j=0;j<IDELEMS(I);j++)
512 {
513 poly f=I->m[j];
514 while (f!=NULL)
515 {
516 i = 1;
517 loop
518 {
519 if (i!=pos_of_1)
520 {
521 h = mp_Exdiv(f, MATELEM(co,1,i),vars, R);
522 if (h!=NULL)
523 {
524 MATELEM(co,j+2,i) = p_Add_q(MATELEM(co,j+2,i), h, R);
525 break;
526 }
527 }
528 if (i == l)
529 {
530 // check monom 1 last:
531 if (pos_of_1 != -1)
532 {
533 h = mp_Exdiv(f, MATELEM(co,1,pos_of_1),vars, R);
534 if (h!=NULL)
535 {
536 MATELEM(co,j+2,pos_of_1) = p_Add_q(MATELEM(co,j+2,pos_of_1), h, R);
537 }
538 }
539 break;
540 }
541 i ++;
542 }
543 pIter(f);
544 }
545 }
546 return co;
547}
BOOLEAN idIs0(ideal h)
returns true if h is the zero ideal
static poly mp_SelectId(ideal I, poly what, const ring R)
Definition: matpol.cc:759
#define IDELEMS(i)
Definition: simpleideals.h:23

◆ mp_Coeffs()

matrix mp_Coeffs ( ideal  I,
int  var,
const ring  R 
)

corresponds to Maple's coeffs: var has to be the number of a variable

Definition at line 306 of file matpol.cc.

307{
308 poly h,f;
309 int l, i, c, m=0;
310 /* look for maximal power m of x_var in I */
311 for (i=IDELEMS(I)-1; i>=0; i--)
312 {
313 f=I->m[i];
314 while (f!=NULL)
315 {
316 l=p_GetExp(f,var, R);
317 if (l>m) m=l;
318 pIter(f);
319 }
320 }
321 matrix co=mpNew((m+1)*I->rank,IDELEMS(I));
322 /* divide each monomial by a power of x_var,
323 * remember the power in l and the component in c*/
324 for (i=IDELEMS(I)-1; i>=0; i--)
325 {
326 f=I->m[i];
327 I->m[i]=NULL;
328 while (f!=NULL)
329 {
330 l=p_GetExp(f,var, R);
331 p_SetExp(f,var,0, R);
332 c=si_max((int)p_GetComp(f, R),1);
333 p_SetComp(f,0, R);
334 p_Setm(f, R);
335 /* now add the resulting monomial to co*/
336 h=pNext(f);
337 pNext(f)=NULL;
338 //MATELEM(co,c*(m+1)-l,i+1)
339 // =p_Add_q(MATELEM(co,c*(m+1)-l,i+1),f, R);
340 MATELEM(co,(c-1)*(m+1)+l+1,i+1)
341 =p_Add_q(MATELEM(co,(c-1)*(m+1)+l+1,i+1),f, R);
342 /* iterate f*/
343 f=h;
344 }
345 }
346 id_Delete(&I, R);
347 return co;
348}
#define p_GetComp(p, r)
Definition: monomials.h:64
static unsigned long p_SetExp(poly p, const unsigned long e, const unsigned long iBitmask, const int VarOffset)
set a single variable exponent @Note: VarOffset encodes the position in p->exp
Definition: p_polys.h:486
static void p_Setm(poly p, const ring r)
Definition: p_polys.h:231
static long p_GetExp(const poly p, const unsigned long iBitmask, const int VarOffset)
get a single variable exponent @Note: the integer VarOffset encodes:
Definition: p_polys.h:467
void id_Delete(ideal *h, ring r)
deletes an ideal/module/matrix

◆ mp_Compare()

int mp_Compare ( matrix  a,
matrix  b,
const ring  R 
)

Definition at line 636 of file matpol.cc.

637{
638 if (MATCOLS(a)<MATCOLS(b)) return -1;
639 else if (MATCOLS(a)>MATCOLS(b)) return 1;
640 if (MATROWS(a)<MATROWS(b)) return -1;
641 else if (MATROWS(a)<MATROWS(b)) return 1;
642
643 unsigned ii=MATCOLS(a)*MATROWS(a)-1;
644 unsigned j=0;
645 int r=0;
646 while (j<=ii)
647 {
648 r=p_Compare(a->m[j],b->m[j],R);
649 if (r!=0) return r;
650 j++;
651 }
652 return r;
653}
int p_Compare(const poly a, const poly b, const ring R)
Definition: p_polys.cc:4849

◆ mp_Copy() [1/2]

matrix mp_Copy ( const matrix  a,
const ring  rSrc,
const ring  rDst 
)

copies matrix a from rSrc into rDst

Definition at line 78 of file matpol.cc.

79{
80 id_Test((ideal)a, rSrc);
81
82 poly t;
83 int i, m=MATROWS(a), n=MATCOLS(a);
84
85 matrix b = mpNew(m, n);
86
87 for (i=m*n-1; i>=0; i--)
88 {
89 t = a->m[i];
90 if (t!=NULL)
91 {
92 b->m[i] = prCopyR_NoSort(t, rSrc, rDst);
93 p_Normalize(b->m[i], rDst);
94 }
95 }
96 b->rank=a->rank;
97
98 id_Test((ideal)b, rDst);
99
100 return b;
101}
long rank
Definition: matpol.h:19
void p_Normalize(poly p, const ring r)
Definition: p_polys.cc:3813
poly prCopyR_NoSort(poly p, ring src_r, ring dest_r)
Definition: prCopy.cc:77
#define id_Test(A, lR)
Definition: simpleideals.h:87

◆ mp_Copy() [2/2]

matrix mp_Copy ( matrix  a,
const ring  r 
)

copies matrix a (from ring r to r)

Definition at line 57 of file matpol.cc.

58{
59 id_Test((ideal)a, r);
60 poly t;
61 int m=MATROWS(a), n=MATCOLS(a);
62 matrix b = mpNew(m, n);
63
64 for (long i=(long)m*(long)n-1; i>=0; i--)
65 {
66 t = a->m[i];
67 if (t!=NULL)
68 {
69 p_Normalize(t, r);
70 b->m[i] = p_Copy(t, r);
71 }
72 }
73 b->rank=a->rank;
74 return b;
75}

◆ mp_Delete()

void mp_Delete ( matrix a,
const ring  r 
)

Definition at line 873 of file matpol.cc.

874{
875 id_Delete((ideal *) a, r);
876}

◆ mp_Det()

poly mp_Det ( matrix  a,
const ring  r,
DetVariant  d 
)

Definition at line 2136 of file matpol.cc.

2137{
2138 if ((MATCOLS(a)==0)
2139 && (MATROWS(a)==0))
2140 return p_One(r);
2141 if (d==DetDefault) d=mp_GetAlgorithmDet(a,r);
2142 switch (d)
2143 {
2144 case DetBareiss: return mp_DetBareiss(a,r);
2145 case DetMu: return mp_DetMu(a,r);
2146 case DetFactory: return singclap_det(a,r);
2147 case DetSBareiss:
2148 {
2149 ideal I=id_Matrix2Module(mp_Copy(a, r),r);
2150 poly p=sm_CallDet(I, r);
2151 id_Delete(&I, r);
2152 return p;
2153 }
2154 default:
2155 WerrorS("unknown algorithm for det");
2156 return NULL;
2157 }
2158}
poly singclap_det(const matrix m, const ring s)
Definition: clapsing.cc:1757
void WerrorS(const char *s)
Definition: feFopen.cc:24
DetVariant mp_GetAlgorithmDet(matrix m, const ring r)
Definition: matpol.cc:2105
matrix mp_Copy(matrix a, const ring r)
copies matrix a (from ring r to r)
Definition: matpol.cc:57
poly mp_DetMu(matrix A, const ring R)
Definition: matpol.cc:2063
poly mp_DetBareiss(matrix a, const ring r)
returns the determinant of the matrix m; uses Bareiss algorithm
Definition: matpol.cc:1669
@ DetFactory
Definition: matpol.h:40
@ DetBareiss
Definition: matpol.h:37
@ DetDefault
Definition: matpol.h:36
@ DetSBareiss
Definition: matpol.h:38
@ DetMu
Definition: matpol.h:39
ideal id_Matrix2Module(matrix mat, const ring R)
converts mat to module, destroys mat
poly sm_CallDet(ideal I, const ring R)
Definition: sparsmat.cc:302

◆ mp_DetBareiss()

poly mp_DetBareiss ( matrix  a,
const ring  r 
)

returns the determinant of the matrix m; uses Bareiss algorithm

Definition at line 1669 of file matpol.cc.

1670{
1671 int s;
1672 poly div, res;
1673 if (MATROWS(a) != MATCOLS(a))
1674 {
1675 Werror("det of %d x %d matrix",MATROWS(a),MATCOLS(a));
1676 return NULL;
1677 }
1678 matrix c = mp_Copy(a,r);
1679 mp_permmatrix *Bareiss = new mp_permmatrix(c,r);
1680 row_col_weight w(Bareiss->mpGetRdim(), Bareiss->mpGetCdim());
1681
1682 /* Bareiss */
1683 div = NULL;
1684 while(Bareiss->mpPivotBareiss(&w))
1685 {
1686 Bareiss->mpElimBareiss(div);
1687 div = Bareiss->mpGetElem(Bareiss->mpGetRdim(), Bareiss->mpGetCdim());
1688 }
1689 Bareiss->mpRowReorder();
1690 Bareiss->mpColReorder();
1691 Bareiss->mpSaveArray();
1692 s = Bareiss->mpGetSign();
1693 delete Bareiss;
1694
1695 /* result */
1696 res = MATELEM(c,1,1);
1697 MATELEM(c,1,1) = NULL;
1698 id_Delete((ideal *)&c,r);
1699 if (s < 0)
1700 res = p_Neg(res,r);
1701 return res;
1702}
CF_NO_INLINE FACTORY_PUBLIC CanonicalForm div(const CanonicalForm &, const CanonicalForm &)
int mpGetCdim()
Definition: matpol.cc:942
void mpRowReorder()
Definition: matpol.cc:1112
poly mpGetElem(int, int)
Definition: matpol.cc:1229
void mpColReorder()
Definition: matpol.cc:1091
void mpSaveArray()
Definition: matpol.cc:945
void mpElimBareiss(poly)
Definition: matpol.cc:1237
int mpPivotBareiss(row_col_weight *)
Definition: matpol.cc:1152
int mpGetRdim()
Definition: matpol.cc:941
int mpGetSign()
Definition: matpol.cc:943
CanonicalForm res
Definition: facAbsFact.cc:60
const CanonicalForm & w
Definition: facAbsFact.cc:51
static poly p_Neg(poly p, const ring r)
Definition: p_polys.h:1105
void Werror(const char *fmt,...)
Definition: reporter.cc:189

◆ mp_DetMu()

poly mp_DetMu ( matrix  A,
const ring  R 
)

Definition at line 2063 of file matpol.cc.

2064{
2065 int n=MATROWS(A);
2066 assume(MATCOLS(A)==n);
2067 /*
2068 * Intput:
2069 * int n: Dimension der Matrix
2070 * int A: n*n Matrix
2071 *
2072 * Berechnet n-1 mal: X = mu(X)*A
2073 *
2074 * Output: det(A)
2075 */
2076
2077 //speichere A ab:
2078 matrix workA=mp_Copy(A,R);
2079
2080 // berechen X = mu(X)*A
2081 matrix X;
2082 for (int i = n-1; i >0; i--)
2083 {
2084 X=mu(workA,R);
2085 id_Delete((ideal*)&workA,R);
2086 workA=mp_Mult(X,A,R);
2087 id_Delete((ideal*)&X,R);
2088 }
2089
2090 // berrechne det(A)
2091 poly res;
2092 if (n%2 == 0)
2093 {
2094 res=p_Neg(MATELEM0(workA,0,0),R);
2095 }
2096 else
2097 {
2098 res=MATELEM0(workA,0,0);
2099 }
2100 MATELEM0(workA,0,0)=NULL;
2101 id_Delete((ideal*)&workA,R);
2102 return res;
2103}
static matrix mu(matrix A, const ring R)
Definition: matpol.cc:2025
matrix mp_Mult(matrix a, matrix b, const ring R)
Definition: matpol.cc:206
#define MATELEM0(mat, i, j)
0-based access to matrix
Definition: matpol.h:31
#define A
Definition: sirandom.c:24

◆ mp_ElimBar()

static void mp_ElimBar ( matrix  a0,
matrix  re,
poly  div,
int  lr,
int  lc,
const ring  R 
)
static

Definition at line 1442 of file matpol.cc.

1443{
1444 int r=lr-1, c=lc-1;
1445 poly *b = a0->m, *x = re->m;
1446 poly piv, elim, q1, *ap, *a, *q;
1447 int i, j;
1448
1449 ap = &b[r*a0->ncols];
1450 piv = ap[c];
1451 for(j=c-1; j>=0; j--)
1452 if (ap[j] != NULL) ap[j] = p_Neg(ap[j],R);
1453 for(i=r-1; i>=0; i--)
1454 {
1455 a = &b[i*a0->ncols];
1456 q = &x[i*re->ncols];
1457 if (a[c] != NULL)
1458 {
1459 elim = a[c];
1460 for (j=c-1; j>=0; j--)
1461 {
1462 q1 = NULL;
1463 if (a[j] != NULL)
1464 {
1465 q1 = sm_MultDiv(a[j], piv, div,R);
1466 if (ap[j] != NULL)
1467 {
1468 poly q2 = sm_MultDiv(ap[j], elim, div, R);
1469 q1 = p_Add_q(q1,q2,R);
1470 }
1471 }
1472 else if (ap[j] != NULL)
1473 q1 = sm_MultDiv(ap[j], elim, div, R);
1474 if (q1 != NULL)
1475 {
1476 if (div)
1477 sm_SpecialPolyDiv(q1, div,R);
1478 q[j] = q1;
1479 }
1480 }
1481 }
1482 else
1483 {
1484 for (j=c-1; j>=0; j--)
1485 {
1486 if (a[j] != NULL)
1487 {
1488 q1 = sm_MultDiv(a[j], piv, div, R);
1489 if (div)
1490 sm_SpecialPolyDiv(q1, div, R);
1491 q[j] = q1;
1492 }
1493 }
1494 }
1495 }
1496}
CanonicalForm lc(const CanonicalForm &f)
Variable x
Definition: cfModGcd.cc:4082
Definition: ap.h:40
poly sm_MultDiv(poly a, poly b, const poly c, const ring R)
Definition: sparsmat.cc:1759
void sm_SpecialPolyDiv(poly a, poly b, const ring R)
Definition: sparsmat.cc:1840

◆ mp_Equal()

BOOLEAN mp_Equal ( matrix  a,
matrix  b,
const ring  R 
)

Definition at line 655 of file matpol.cc.

656{
657 if ((MATCOLS(a)!=MATCOLS(b)) || (MATROWS(a)!=MATROWS(b)))
658 return FALSE;
659 int i=MATCOLS(a)*MATROWS(a)-1;
660 while (i>=0)
661 {
662 if (a->m[i]==NULL)
663 {
664 if (b->m[i]!=NULL) return FALSE;
665 }
666 else if (b->m[i]==NULL) return FALSE;
667 else if (p_Cmp(a->m[i],b->m[i], R)!=0) return FALSE;
668 i--;
669 }
670 i=MATCOLS(a)*MATROWS(a)-1;
671 while (i>=0)
672 {
673 if(!p_EqualPolys(a->m[i],b->m[i], R)) return FALSE;
674 i--;
675 }
676 return TRUE;
677}
#define TRUE
Definition: auxiliary.h:100
#define FALSE
Definition: auxiliary.h:96
BOOLEAN p_EqualPolys(poly p1, poly p2, const ring r)
Definition: p_polys.cc:4512
static int p_Cmp(poly p1, poly p2, ring r)
Definition: p_polys.h:1725

◆ mp_Exdiv()

static poly mp_Exdiv ( poly  m,
poly  d,
poly  vars,
const ring  R 
)
static

Definition at line 554 of file matpol.cc.

555{
556 int i;
557 poly h = p_Head(m, R);
558 for (i=1; i<=rVar(R); i++)
559 {
560 if (p_GetExp(vars,i, R) > 0)
561 {
562 if (p_GetExp(d,i, R) != p_GetExp(h,i, R))
563 {
564 p_Delete(&h, R);
565 return NULL;
566 }
567 p_SetExp(h,i,0, R);
568 }
569 }
570 p_Setm(h, R);
571 return h;
572}
static void p_Delete(poly *p, const ring r)
Definition: p_polys.h:899
static short rVar(const ring r)
#define rVar(r) (r->N)
Definition: ring.h:592

◆ mp_GetAlgorithmDet() [1/2]

DetVariant mp_GetAlgorithmDet ( const char *  s)

Definition at line 2125 of file matpol.cc.

2126{
2127 if (strcmp(s,"Bareiss")==0) return DetBareiss;
2128 if (strcmp(s,"SBareiss")==0) return DetSBareiss;
2129 if (strcmp(s,"Mu")==0) return DetMu;
2130 if (strcmp(s,"Factory")==0) return DetFactory;
2131 WarnS("unknown method for det");
2132 return DetDefault;
2133}
#define WarnS
Definition: emacs.cc:78

◆ mp_GetAlgorithmDet() [2/2]

DetVariant mp_GetAlgorithmDet ( matrix  m,
const ring  r 
)

Definition at line 2105 of file matpol.cc.

2106{
2107 if (MATROWS(m)+2*r->N>20+5*rField_is_Zp(r)) return DetMu;
2108 if (MATROWS(m)<10+5*rField_is_Zp(r)) return DetSBareiss;
2109 BOOLEAN isConst=TRUE;
2110 int s=0;
2111 for(int i=MATCOLS(m)*MATROWS(m)-1;i>=0;i--)
2112 {
2113 poly p=m->m[i];
2114 if (p!=NULL)
2115 {
2116 if(!p_IsConstant(p,r)) isConst=FALSE;
2117 s++;
2118 }
2119 }
2120 if (isConst && rField_is_Q(r)) return DetFactory;
2121 if (s*2<MATCOLS(m)*MATROWS(m)) // few entries
2122 return DetSBareiss;
2123 return DetMu;
2124}
int BOOLEAN
Definition: auxiliary.h:87
static BOOLEAN rField_is_Zp(const ring r)
Definition: ring.h:500
static BOOLEAN rField_is_Q(const ring r)
Definition: ring.h:506

◆ mp_InitI()

matrix mp_InitI ( int  r,
int  c,
int  v,
const ring  R 
)

make it a v * unit matrix

Definition at line 122 of file matpol.cc.

123{
124 return mp_InitP(r, c, p_ISet(v, R), R);
125}
matrix mp_InitP(int r, int c, poly p, const ring R)
make it a p * unit matrix
Definition: matpol.cc:106
poly p_ISet(long i, const ring r)
returns the poly representing the integer i
Definition: p_polys.cc:1297

◆ mp_InitP()

matrix mp_InitP ( int  r,
int  c,
poly  p,
const ring  R 
)

make it a p * unit matrix

Definition at line 106 of file matpol.cc.

107{
108 matrix rc = mpNew(r,c);
109 int i=si_min(r,c), n = c*(i-1)+i-1, inc = c+1;
110
111 p_Normalize(p, R);
112 while (n>0)
113 {
114 rc->m[n] = p_Copy(p, R);
115 n -= inc;
116 }
117 rc->m[0]=p;
118 return rc;
119}
static int si_min(const int a, const int b)
Definition: auxiliary.h:125

◆ mp_IsDiagUnit()

BOOLEAN mp_IsDiagUnit ( matrix  U,
const ring  R 
)

Definition at line 809 of file matpol.cc.

810{
811 if(MATROWS(U)!=MATCOLS(U))
812 return FALSE;
813 for(int i=MATCOLS(U);i>=1;i--)
814 {
815 for(int j=MATCOLS(U); j>=1; j--)
816 {
817 if (i==j)
818 {
819 if (!p_IsUnit(MATELEM(U,i,i), R)) return FALSE;
820 }
821 else if (MATELEM(U,i,j)!=NULL) return FALSE;
822 }
823 }
824 return TRUE;
825}
static BOOLEAN p_IsUnit(const poly p, const ring r)
Definition: p_polys.h:1989

◆ mp_MinorToResult()

void mp_MinorToResult ( ideal  result,
int &  elems,
matrix  a,
int  r,
int  c,
ideal  R,
const  ring 
)

entries of a are minors and go to result (only if not in R)

Definition at line 1500 of file matpol.cc.

1502{
1503 poly *q1;
1504 int e=IDELEMS(result);
1505 int i,j;
1506
1507 if (R != NULL)
1508 {
1509 for (i=r-1;i>=0;i--)
1510 {
1511 q1 = &(a->m)[i*a->ncols];
1512 //for (j=c-1;j>=0;j--)
1513 //{
1514 // if (q1[j]!=NULL) q1[j] = kNF(R,currRing->qideal,q1[j]);
1515 //}
1516 }
1517 }
1518 for (i=r-1;i>=0;i--)
1519 {
1520 q1 = &(a->m)[i*a->ncols];
1521 for (j=c-1;j>=0;j--)
1522 {
1523 if (q1[j]!=NULL)
1524 {
1525 if (elems>=e)
1526 {
1527 pEnlargeSet(&(result->m),e,e);
1528 e += e;
1529 IDELEMS(result) =e;
1530 }
1531 result->m[elems] = q1[j];
1532 q1[j] = NULL;
1533 elems++;
1534 }
1535 }
1536 }
1537}
return result
Definition: facAbsBiFact.cc:75
for(j=0;j< factors.length();j++)
Definition: facHensel.cc:129
void pEnlargeSet(poly **p, int l, int increment)
Definition: p_polys.cc:3696

◆ mp_Monomials()

void mp_Monomials ( matrix  c,
int  r,
int  var,
matrix  m,
const ring  R 
)

Definition at line 355 of file matpol.cc.

356{
357 /* clear contents of m*/
358 int k,l;
359 for (k=MATROWS(m);k>0;k--)
360 {
361 for(l=MATCOLS(m);l>0;l--)
362 {
363 p_Delete(&MATELEM(m,k,l), R);
364 }
365 }
366 omfreeSize((ADDRESS)m->m,MATROWS(m)*MATCOLS(m)*sizeof(poly));
367 /* allocate monoms in the right size r x MATROWS(c)*/
368 m->m=(poly*)omAlloc0(r*MATROWS(c)*sizeof(poly));
369 MATROWS(m)=r;
370 MATCOLS(m)=MATROWS(c);
371 m->rank=r;
372 /* the maximal power p of x_var: MATCOLS(m)=r*(p+1) */
373 int p=MATCOLS(m)/r-1;
374 /* fill in the powers of x_var=h*/
375 poly h=p_One(R);
376 for(k=r;k>0; k--)
377 {
378 MATELEM(m,k,k*(p+1))=p_One(R);
379 }
380 for(l=p;l>=0; l--)
381 {
382 p_SetExp(h,var,p-l, R);
383 p_Setm(h, R);
384 for(k=r;k>0; k--)
385 {
386 MATELEM(m,k,k*(p+1)-l)=p_Copy(h, R);
387 }
388 }
389 p_Delete(&h, R);
390}
void * ADDRESS
Definition: auxiliary.h:119
#define omAlloc0(size)
Definition: omAllocDecl.h:211
#define omfreeSize(addr, size)
Definition: omAllocDecl.h:236

◆ mp_Mult()

matrix mp_Mult ( matrix  a,
matrix  b,
const ring  R 
)

Definition at line 206 of file matpol.cc.

207{
208 int i, j, k;
209 int m = MATROWS(a);
210 int p = MATCOLS(a);
211 int q = MATCOLS(b);
212
213 if (p!=MATROWS(b))
214 {
215/*
216* Werror("cannot multiply %dx%d matrix and %dx%d matrix",
217* m,p,b->rows(),q);
218*/
219 return NULL;
220 }
221 matrix c = mpNew(m,q);
222
223 for (i=0; i<m; i++)
224 {
225 for (k=0; k<p; k++)
226 {
227 poly aik;
228 if ((aik=MATELEM0(a,i,k))!=NULL)
229 {
230 for (j=0; j<q; j++)
231 {
232 poly bkj;
233 if ((bkj=MATELEM0(b,k,j))!=NULL)
234 {
235 poly *cij=&(MATELEM0(c,i,j));
236 poly s = pp_Mult_qq(aik /*MATELEM0(a,i,k)*/, bkj/*MATELEM0(b,k,j)*/, R);
237 (*cij)/*MATELEM0(c,i,j)*/ = p_Add_q((*cij) /*MATELEM0(c,i,j)*/ ,s, R);
238 }
239 }
240 }
241 }
242 }
243 for(i=m*q-1;i>=0;i--) p_Normalize(c->m[i], R);
244 return c;
245}
static poly pp_Mult_qq(poly p, poly q, const ring r)
Definition: p_polys.h:1149

◆ mp_MultI()

matrix mp_MultI ( matrix  a,
long  f,
const ring  R 
)

c = f*a

Definition at line 128 of file matpol.cc.

129{
130 int k, n = a->nrows, m = a->ncols;
131 poly p = p_ISet(f, R);
132 matrix c = mpNew(n,m);
133
134 for (k=m*n-1; k>0; k--)
135 c->m[k] = pp_Mult_qq(a->m[k], p, R);
136 c->m[0] = p_Mult_q(p_Copy(a->m[0], R), p, R);
137 return c;
138}
static poly p_Mult_q(poly p, poly q, const ring r)
Definition: p_polys.h:1112

◆ mp_MultP()

matrix mp_MultP ( matrix  a,
poly  p,
const ring  R 
)

multiply a matrix 'a' by a poly 'p', destroy the args

Definition at line 141 of file matpol.cc.

142{
143 int k, n = a->nrows, m = a->ncols;
144
145 p_Normalize(p, R);
146 for (k=m*n-1; k>0; k--)
147 {
148 if (a->m[k]!=NULL)
149 a->m[k] = p_Mult_q(a->m[k], p_Copy(p, R), R);
150 }
151 a->m[0] = p_Mult_q(a->m[0], p, R);
152 return a;
153}

◆ mp_PartClean()

static void mp_PartClean ( matrix  a,
int  lr,
int  lc,
const ring  R 
)
static

Definition at line 797 of file matpol.cc.

798{
799 poly *q1;
800 int i,j;
801
802 for (i=lr-1;i>=0;i--)
803 {
804 q1 = &(a->m)[i*a->ncols];
805 for (j=lc-1;j>=0;j--) if(q1[j]) p_Delete(&q1[j], R);
806 }
807}

◆ mp_PivBar()

static int mp_PivBar ( matrix  a,
int  lr,
int  lc,
const ring  r 
)
static

Definition at line 1327 of file matpol.cc.

1328{
1329 float f1, f2;
1330 poly *q1;
1331 int i,j,io;
1332
1333 io = -1;
1334 f1 = 1.0e30;
1335 for (i=lr-1;i>=0;i--)
1336 {
1337 q1 = &(a->m)[i*a->ncols];
1338 f2 = 0.0;
1339 for (j=lc-1;j>=0;j--)
1340 {
1341 if (q1[j]!=NULL)
1342 f2 += mp_PolyWeight(q1[j],r);
1343 }
1344 if ((f2!=0.0) && (f2<f1))
1345 {
1346 f1 = f2;
1347 io = i;
1348 }
1349 }
1350 if (io<0) return 0;
1351 else return io+1;
1352}
static float mp_PolyWeight(poly p, const ring r)
Definition: matpol.cc:1295

◆ mp_PivRow()

static int mp_PivRow ( matrix  a,
int  lr,
int  lc,
const ring  r 
)
static

Definition at line 1387 of file matpol.cc.

1388{
1389 float f1, f2;
1390 poly *q1;
1391 int j,jo;
1392
1393 jo = -1;
1394 f1 = 1.0e30;
1395 q1 = &(a->m)[(lr-1)*a->ncols];
1396 for (j=lc-1;j>=0;j--)
1397 {
1398 if (q1[j]!=NULL)
1399 {
1400 f2 = mp_PolyWeight(q1[j],r);
1401 if (f2<f1)
1402 {
1403 f1 = f2;
1404 jo = j;
1405 }
1406 }
1407 }
1408 if (jo<0) return 0;
1409 else return jo+1;
1410}

◆ mp_PolyWeight()

static float mp_PolyWeight ( poly  p,
const ring  r 
)
static

Definition at line 1295 of file matpol.cc.

1296{
1297 int i;
1298 float res;
1299
1300 if (pNext(p) == NULL)
1301 {
1302 res = (float)n_Size(pGetCoeff(p),r->cf);
1303 for (i=r->N;i>0;i--)
1304 {
1305 if(p_GetExp(p,i,r)!=0)
1306 {
1307 res += 2.0;
1308 break;
1309 }
1310 }
1311 }
1312 else
1313 {
1314 res = 0.0;
1315 do
1316 {
1317 res += (float)n_Size(pGetCoeff(p),r->cf)+2.0;
1318 pIter(p);
1319 }
1320 while (p);
1321 }
1322 return res;
1323}
static FORCE_INLINE int n_Size(number n, const coeffs r)
return a non-negative measure for the complexity of n; return 0 only when n represents zero; (used fo...
Definition: coeffs.h:567
static number & pGetCoeff(poly p)
return an alias to the leading coefficient of p assumes that p != NULL NOTE: not copy
Definition: monomials.h:44

◆ mp_PreparePiv()

static int mp_PreparePiv ( matrix  a,
int  lr,
int  lc,
const ring  r 
)
static

Definition at line 1432 of file matpol.cc.

1433{
1434 int c;
1435
1436 c = mp_PivRow(a, lr, lc,r);
1437 if(c==0) return 0;
1438 if(c<lc) mpSwapCol(a, c, lr, lc);
1439 return 1;
1440}
static int mp_PivRow(matrix a, int lr, int lc, const ring r)
Definition: matpol.cc:1387
static void mpSwapCol(matrix a, int pos, int lr, int lc)
Definition: matpol.cc:1412

◆ mp_PrepareRow()

static int mp_PrepareRow ( matrix  a,
int  lr,
int  lc,
const ring  R 
)
static

Definition at line 1374 of file matpol.cc.

1375{
1376 int r;
1377
1378 r = mp_PivBar(a,lr,lc,R);
1379 if(r==0) return 0;
1380 if(r<lr) mpSwapRow(a, r, lr, lc);
1381 return 1;
1382}
static int mp_PivBar(matrix a, int lr, int lc, const ring r)
Definition: matpol.cc:1327
static void mpSwapRow(matrix a, int pos, int lr, int lc)
Definition: matpol.cc:1354

◆ mp_RecMin()

void mp_RecMin ( int  ar,
ideal  result,
int &  elems,
matrix  a,
int  lr,
int  lc,
poly  barDiv,
ideal  R,
const ring  r 
)

produces recursively the ideal of all arxar-minors of a

for minors with Bareiss

Definition at line 1596 of file matpol.cc.

1598{
1599 int k;
1600 int kr=lr-1,kc=lc-1;
1601 matrix nextLevel=mpNew(kr,kc);
1602
1603 loop
1604 {
1605/*--- look for an optimal row and bring it to last position ------------*/
1606 if(mp_PrepareRow(a,lr,lc,r)==0) break;
1607/*--- now take all pivots from the last row ------------*/
1608 k = lc;
1609 loop
1610 {
1611 if(mp_PreparePiv(a,lr,k,r)==0) break;
1612 mp_ElimBar(a,nextLevel,barDiv,lr,k,r);
1613 k--;
1614 if (ar>1)
1615 {
1616 mp_RecMin(ar-1,result,elems,nextLevel,kr,k,a->m[kr*a->ncols+k],R,r);
1617 mp_PartClean(nextLevel,kr,k, r);
1618 }
1619 else mp_MinorToResult(result,elems,nextLevel,kr,k,R,r);
1620 if (ar>k-1) break;
1621 }
1622 if (ar>=kr) break;
1623/*--- now we have to take out the last row...------------*/
1624 lr = kr;
1625 kr--;
1626 }
1627 mpFinalClean(nextLevel);
1628}
static void mp_PartClean(matrix a, int lr, int lc, const ring R)
Definition: matpol.cc:797
static int mp_PrepareRow(matrix a, int lr, int lc, const ring R)
Definition: matpol.cc:1374
static void mpFinalClean(matrix a)
Definition: matpol.cc:1588
static void mp_ElimBar(matrix a0, matrix re, poly div, int lr, int lc, const ring R)
Definition: matpol.cc:1442
static int mp_PreparePiv(matrix a, int lr, int lc, const ring r)
Definition: matpol.cc:1432
void mp_MinorToResult(ideal result, int &elems, matrix a, int r, int c, ideal R, const ring)
entries of a are minors and go to result (only if not in R)
Definition: matpol.cc:1500
void mp_RecMin(int ar, ideal result, int &elems, matrix a, int lr, int lc, poly barDiv, ideal R, const ring r)
produces recursively the ideal of all arxar-minors of a
Definition: matpol.cc:1596

◆ mp_Select()

static poly mp_Select ( poly  fro,
poly  what,
const ring  R 
)
static

Definition at line 741 of file matpol.cc.

742{
743 int i;
744 poly h, res;
745 res = NULL;
746 while (fro!=NULL)
747 {
748 h = p_One(R);
749 for (i=1; i<=rVar(R); i++)
750 p_SetExp(h,i, p_GetExp(fro,i, R) * p_GetExp(what, i, R), R);
751 p_SetComp(h, p_GetComp(fro, R), R);
752 p_Setm(h, R);
753 res = p_Insert(h, res, R);
754 fro = fro->next;
755 }
756 return res;
757}
static poly p_Insert(poly p1, poly p2, const ring R)
Definition: matpol.cc:683

◆ mp_SelectId()

static poly mp_SelectId ( ideal  I,
poly  what,
const ring  R 
)
static

Definition at line 759 of file matpol.cc.

760{
761 int i;
762 poly h, res;
763 res = NULL;
764 for(int j=0;j<IDELEMS(I);j++)
765 {
766 poly fro=I->m[j];
767 while (fro!=NULL)
768 {
769 h = p_One(R);
770 for (i=1; i<=rVar(R); i++)
771 p_SetExp(h,i, p_GetExp(fro,i, R) * p_GetExp(what, i, R), R);
772 p_SetComp(h, p_GetComp(fro, R), R);
773 p_Setm(h, R);
774 res = p_Insert(h, res, R);
775 fro = fro->next;
776 }
777 }
778 return res;
779}

◆ mp_Sub()

matrix mp_Sub ( matrix  a,
matrix  b,
const ring  R 
)

Definition at line 189 of file matpol.cc.

190{
191 int k, n = a->nrows, m = a->ncols;
192 if ((n != b->nrows) || (m != b->ncols))
193 {
194/*
195* Werror("cannot sub %dx%d matrix and %dx%d matrix",
196* m,n,b->cols(),b->rows());
197*/
198 return NULL;
199 }
200 matrix c = mpNew(n,m);
201 for (k=m*n-1; k>=0; k--)
202 c->m[k] = p_Sub(p_Copy(a->m[k], R), p_Copy(b->m[k], R), R);
203 return c;
204}
poly p_Sub(poly p1, poly p2, const ring r)
Definition: p_polys.cc:1990

◆ mp_Trace()

poly mp_Trace ( matrix  a,
const ring  R 
)

Definition at line 268 of file matpol.cc.

269{
270 int i;
271 int n = (MATCOLS(a)<MATROWS(a)) ? MATCOLS(a) : MATROWS(a);
272 poly t = NULL;
273
274 for (i=1; i<=n; i++)
275 t = p_Add_q(t, p_Copy(MATELEM(a,i,i), R), R);
276 return t;
277}

◆ mp_Transp()

matrix mp_Transp ( matrix  a,
const ring  R 
)

Definition at line 247 of file matpol.cc.

248{
249 int i, j, r = MATROWS(a), c = MATCOLS(a);
250 poly *p;
251 matrix b = mpNew(c,r);
252
253 p = b->m;
254 for (i=0; i<c; i++)
255 {
256 for (j=0; j<r; j++)
257 {
258 if (a->m[j*c+i]!=NULL) *p = p_Copy(a->m[j*c+i], R);
259 p++;
260 }
261 }
262 return b;
263}

◆ mp_Wedge()

matrix mp_Wedge ( matrix  a,
int  ar,
const ring  R 
)

Definition at line 1744 of file matpol.cc.

1745{
1746 int i,j,k,l;
1747 int *rowchoise,*colchoise;
1748 BOOLEAN rowch,colch;
1749 matrix result;
1750 matrix tmp;
1751 poly p;
1752
1753 i = binom(a->nrows,ar);
1754 j = binom(a->ncols,ar);
1755
1756 rowchoise=(int *)omAlloc(ar*sizeof(int));
1757 colchoise=(int *)omAlloc(ar*sizeof(int));
1758 result = mpNew(i,j);
1759 tmp = mpNew(ar,ar);
1760 l = 1; /* k,l:the index in result*/
1761 idInitChoise(ar,1,a->nrows,&rowch,rowchoise);
1762 while (!rowch)
1763 {
1764 k=1;
1765 idInitChoise(ar,1,a->ncols,&colch,colchoise);
1766 while (!colch)
1767 {
1768 for (i=1; i<=ar; i++)
1769 {
1770 for (j=1; j<=ar; j++)
1771 {
1772 MATELEM(tmp,i,j) = MATELEM(a,rowchoise[i-1],colchoise[j-1]);
1773 }
1774 }
1775 p = mp_DetBareiss(tmp, R);
1776 if ((k+l) & 1) p=p_Neg(p, R);
1777 MATELEM(result,l,k) = p;
1778 k++;
1779 idGetNextChoise(ar,a->ncols,&colch,colchoise);
1780 }
1781 idGetNextChoise(ar,a->nrows,&rowch,rowchoise);
1782 l++;
1783 }
1784
1785 /*delete the matrix tmp*/
1786 for (i=1; i<=ar; i++)
1787 {
1788 for (j=1; j<=ar; j++) MATELEM(tmp,i,j) = NULL;
1789 }
1790 id_Delete((ideal *) &tmp, R);
1791 return (result);
1792}
int binom(int n, int r)
void idGetNextChoise(int r, int end, BOOLEAN *endch, int *choise)
void idInitChoise(int r, int beg, int end, BOOLEAN *endch, int *choise)
#define omAlloc(size)
Definition: omAllocDecl.h:210

◆ mpFinalClean()

static void mpFinalClean ( matrix  a)
static

Definition at line 1588 of file matpol.cc.

1589{
1590 omFreeSize((ADDRESS)a->m,a->nrows*a->ncols*sizeof(poly));
1592}
#define omFreeSize(addr, size)
Definition: omAllocDecl.h:260
#define omFreeBin(addr, bin)
Definition: omAllocDecl.h:259
VAR omBin sip_sideal_bin
Definition: simpleideals.cc:27

◆ mpNew()

matrix mpNew ( int  r,
int  c 
)

create a r x c zero-matrix

Definition at line 37 of file matpol.cc.

38{
40 rc->nrows = r;
41 rc->ncols = c;
42 rc->rank = r;
43 if ((c != 0)&&(r!=0))
44 {
45 size_t s=((size_t)r)*((size_t)c)*sizeof(poly);
46 rc->m = (poly*)omAlloc0(s);
47 //if (rc->m==NULL)
48 //{
49 // Werror("internal error: creating matrix[%d][%d]",r,c);
50 // return NULL;
51 //}
52 }
53 return rc;
54}
ip_smatrix * matrix
Definition: matpol.h:43
#define omAllocBin(bin)
Definition: omAllocDecl.h:205

◆ mpReplace()

static void mpReplace ( int  j,
int  n,
int &  sign,
int *  perm 
)
static

Definition at line 1137 of file matpol.cc.

1138{
1139 int k;
1140
1141 if (j != n)
1142 {
1143 k = perm[n];
1144 perm[n] = perm[j];
1145 perm[j] = k;
1146 sign = -sign;
1147 }
1148}
static int sign(int x)
Definition: ring.cc:3427

◆ mpSwapCol()

static void mpSwapCol ( matrix  a,
int  pos,
int  lr,
int  lc 
)
static

Definition at line 1412 of file matpol.cc.

1413{
1414 poly sw;
1415 int j;
1416 poly* a2 = a->m;
1417 poly* a1 = &a2[pos-1];
1418
1419 a2 = &a2[lc-1];
1420 for (j=a->ncols*(lr-1); j>=0; j-=a->ncols)
1421 {
1422 sw = a1[j];
1423 a1[j] = a2[j];
1424 a2[j] = sw;
1425 }
1426}

◆ mpSwapRow()

static void mpSwapRow ( matrix  a,
int  pos,
int  lr,
int  lc 
)
static

Definition at line 1354 of file matpol.cc.

1355{
1356 poly sw;
1357 int j;
1358 poly* a2 = a->m;
1359 poly* a1 = &a2[a->ncols*(pos-1)];
1360
1361 a2 = &a2[a->ncols*(lr-1)];
1362 for (j=lc-1; j>=0; j--)
1363 {
1364 sw = a1[j];
1365 a1[j] = a2[j];
1366 a2[j] = sw;
1367 }
1368}

◆ mu()

static matrix mu ( matrix  A,
const ring  R 
)
static

Definition at line 2025 of file matpol.cc.

2026{
2027 int n=MATROWS(A);
2028 assume(MATCOLS(A)==n);
2029 /* Die Funktion erstellt die Matrix mu
2030 *
2031 * Input:
2032 * int n: Dimension der Matrix
2033 * int A: Matrix der Groesse n*n
2034 * int X: Speicherplatz fuer Output
2035 *
2036 * In der Matrix X speichert man die Matrix mu
2037 */
2038
2039 // X als n*n Null-Matrix initalisieren
2040 matrix X=mpNew(n,n);
2041
2042 // Diagonaleintraege von X berrechnen
2043 poly sum = NULL;
2044 for (int i = n-1; i >= 0; i--)
2045 {
2046 MATELEM0(X,i,i) = p_Copy(sum,R);
2047 sum=p_Sub(sum,p_Copy(MATELEM0(A,i,i),R),R);
2048 }
2049 p_Delete(&sum,R);
2050
2051 // Eintraege aus dem oberen Dreieck von A nach X uebertragen
2052 for (int i = n-1; i >=0; i--)
2053 {
2054 for (int j = i+1; j < n; j++)
2055 {
2056 MATELEM0(X,i,j)=p_Copy(MATELEM0(A,i,j),R);
2057 }
2058 }
2059 return X;
2060}

◆ p_Insert()

static poly p_Insert ( poly  p1,
poly  p2,
const ring  R 
)
static

Definition at line 683 of file matpol.cc.

684{
685 poly a1, p, a2, a;
686 int c;
687
688 if (p1==NULL) return p2;
689 if (p2==NULL) return p1;
690 a1 = p1;
691 a2 = p2;
692 a = p = p_One(R);
693 loop
694 {
695 c = p_Cmp(a1, a2, R);
696 if (c == 1)
697 {
698 a = pNext(a) = a1;
699 pIter(a1);
700 if (a1==NULL)
701 {
702 pNext(a) = a2;
703 break;
704 }
705 }
706 else if (c == -1)
707 {
708 a = pNext(a) = a2;
709 pIter(a2);
710 if (a2==NULL)
711 {
712 pNext(a) = a1;
713 break;
714 }
715 }
716 else
717 {
718 p_LmDelete(&a2, R);
719 a = pNext(a) = a1;
720 pIter(a1);
721 if (a1==NULL)
722 {
723 pNext(a) = a2;
724 break;
725 }
726 else if (a2==NULL)
727 {
728 pNext(a) = a1;
729 break;
730 }
731 }
732 }
733 p_LmDelete(&p, R);
734 return p;
735}
static void p_LmDelete(poly p, const ring r)
Definition: p_polys.h:721

◆ pMultMp()

matrix pMultMp ( poly  p,
matrix  a,
const ring  R 
)

Definition at line 158 of file matpol.cc.

159{
160 int k, n = a->nrows, m = a->ncols;
161
162 p_Normalize(p, R);
163 for (k=m*n-1; k>0; k--)
164 {
165 if (a->m[k]!=NULL)
166 a->m[k] = p_Mult_q(p_Copy(p, R), a->m[k], R);
167 }
168 a->m[0] = p_Mult_q(p, a->m[0], R);
169 return a;
170}

◆ sm_Add()

ideal sm_Add ( ideal  a,
ideal  b,
const ring  R 
)

Definition at line 1864 of file matpol.cc.

1865{
1866 assume(IDELEMS(a)==IDELEMS(b));
1867 assume(a->rank==b->rank);
1868 ideal c=idInit(IDELEMS(a),a->rank);
1869 for (int k=IDELEMS(a)-1; k>=0; k--)
1870 c->m[k] = p_Add_q(p_Copy(a->m[k], R), p_Copy(b->m[k], R), R);
1871 return c;
1872}
ideal idInit(int idsize, int rank)
initialise an ideal / module
Definition: simpleideals.cc:35

◆ sm_AddSubMat()

static void sm_AddSubMat ( ideal  res,
ideal  sm,
int  col,
const ring  r 
)
static

Definition at line 1815 of file matpol.cc.

1816{
1817 for(int i=0;i<IDELEMS(sm);i++)
1818 {
1819 res->m[col+i]=p_Add_q(res->m[col+i],sm->m[i],r);
1820 sm->m[i]=NULL;
1821 }
1822}

◆ sm_Compare()

int sm_Compare ( ideal  a,
ideal  b,
const ring  R 
)

Definition at line 1977 of file matpol.cc.

1978{
1979 if (IDELEMS(a)<IDELEMS(b)) return -1;
1980 else if (IDELEMS(a)>IDELEMS(b)) return 1;
1981 if ((a->rank)<(b->rank)) return -1;
1982 else if ((a->rank)<(b->rank)) return 1;
1983
1984 unsigned ii=IDELEMS(a)-1;
1985 unsigned j=0;
1986 int r=0;
1987 while (j<=ii)
1988 {
1989 r=p_Compare(a->m[j],b->m[j],R);
1990 if (r!=0) return r;
1991 j++;
1992 }
1993 return r;
1994}

◆ sm_Det()

poly sm_Det ( ideal  a,
const ring  r,
DetVariant  d 
)

Definition at line 2160 of file matpol.cc.

2161{
2162 if ((MATCOLS(a)==0)
2163 && (MATROWS(a)==0))
2164 return p_One(r);
2165 if (d==DetDefault) d=mp_GetAlgorithmDet((matrix)a,r);
2166 if (d==DetSBareiss) return sm_CallDet(a,r);
2168 poly p=mp_Det(m,r,d);
2169 id_Delete((ideal *)&m,r);
2170 return p;
2171}
ideal id_Copy(ideal h1, const ring r)
copy an ideal
poly mp_Det(matrix a, const ring r, DetVariant d)
Definition: matpol.cc:2136
matrix id_Module2Matrix(ideal mod, const ring R)

◆ sm_Equal()

BOOLEAN sm_Equal ( ideal  a,
ideal  b,
const ring  R 
)

Definition at line 1996 of file matpol.cc.

1997{
1998 if ((a->rank!=b->rank) || (IDELEMS(a)!=IDELEMS(b)))
1999 return FALSE;
2000 int i=IDELEMS(a)-1;
2001 while (i>=0)
2002 {
2003 if (a->m[i]==NULL)
2004 {
2005 if (b->m[i]!=NULL) return FALSE;
2006 }
2007 else if (b->m[i]==NULL) return FALSE;
2008 else if (p_Cmp(a->m[i],b->m[i], R)!=0) return FALSE;
2009 i--;
2010 }
2011 i=IDELEMS(a)-1;
2012 while (i>=0)
2013 {
2014 if(!p_EqualPolys(a->m[i],b->m[i], R)) return FALSE;
2015 i--;
2016 }
2017 return TRUE;
2018}

◆ sm_Flatten()

ideal sm_Flatten ( ideal  a,
const ring  R 
)

Definition at line 1919 of file matpol.cc.

1920{
1921 if (IDELEMS(a)==0) return id_Copy(a,R);
1922 ideal res=idInit(1,IDELEMS(a)*a->rank);
1923 for(int i=0;i<IDELEMS(a);i++)
1924 {
1925 if(a->m[i]!=NULL)
1926 {
1927 poly p=p_Copy(a->m[i],R);
1928 if (i==0) res->m[0]=p;
1929 else
1930 {
1931 p_Shift(&p,i*a->rank,R);
1932 res->m[0]=p_Add_q(res->m[0],p,R);
1933 }
1934 }
1935 }
1936 return res;
1937}
void p_Shift(poly *p, int i, const ring r)
shifts components of the vector p by i
Definition: p_polys.cc:4706

◆ sm_Mult()

ideal sm_Mult ( ideal  a,
ideal  b,
const ring  R 
)

Definition at line 1884 of file matpol.cc.

1885{
1886 int i, j, k;
1887 int m = a->rank;
1888 int p = IDELEMS(a);
1889 int q = IDELEMS(b);
1890
1891 assume (IDELEMS(a)==b->rank);
1892 ideal c = idInit(q,m);
1893
1894 for (i=0; i<m; i++)
1895 {
1896 for (k=0; k<p; k++)
1897 {
1898 poly aik;
1899 if ((aik=SMATELEM(a,i,k,R))!=NULL)
1900 {
1901 for (j=0; j<q; j++)
1902 {
1903 poly bkj=SMATELEM(b,k,j,R);
1904 if (bkj!=NULL)
1905 {
1906 poly s = p_Mult_q(p_Copy(aik,R) /*SMATELEM(a,i,k)*/, bkj/*SMATELEM(b,k,j)*/, R);
1907 if (s!=NULL) p_SetComp(s,i+1,R);
1908 c->m[j]=p_Add_q(c->m[j],s, R);
1909 }
1910 }
1911 p_Delete(&aik,R);
1912 }
1913 }
1914 }
1915 for(i=q-1;i>=0;i--) p_Normalize(c->m[i], R);
1916 return c;
1917}
#define SMATELEM(A, i, j, R)
Definition: matpol.h:123

◆ sm_MultAndShift()

static ideal sm_MultAndShift ( poly  f,
ideal  B,
int  s,
const ring  r 
)
static

Definition at line 1796 of file matpol.cc.

1797{
1798 assume(f!=NULL);
1799 ideal res=idInit(IDELEMS(B),B->rank+s);
1800 int q=IDELEMS(B); // p x q
1801 for(int j=0;j<q;j++)
1802 {
1803 poly h=pp_Mult_qq(f,B->m[j],r);
1804 if (h!=NULL)
1805 {
1806 if (s>0) p_Shift(&h,s,r);
1807 res->m[j]=h;
1808 }
1809 }
1810 p_Delete(&f,r);
1811 return res;
1812}
b *CanonicalForm B
Definition: facBivar.cc:52

◆ sm_Sub()

ideal sm_Sub ( ideal  a,
ideal  b,
const ring  R 
)

Definition at line 1874 of file matpol.cc.

1875{
1876 assume(IDELEMS(a)==IDELEMS(b));
1877 assume(a->rank==b->rank);
1878 ideal c=idInit(IDELEMS(a),a->rank);
1879 for (int k=IDELEMS(a)-1; k>=0; k--)
1880 c->m[k] = p_Sub(p_Copy(a->m[k], R), p_Copy(b->m[k], R), R);
1881 return c;
1882}

◆ sm_Tensor()

ideal sm_Tensor ( ideal  A,
ideal  B,
const ring  r 
)

Definition at line 1824 of file matpol.cc.

1825{
1826 // size of the result m*p x n*q
1827 int n=IDELEMS(A); // m x n
1828 int m=A->rank;
1829 int q=IDELEMS(B); // p x q
1830 int p=B->rank;
1831 ideal res=idInit(n*q,m*p);
1832 poly *a=(poly*)omAlloc(m*sizeof(poly));
1833 for(int i=0; i<n; i++)
1834 {
1835 memset(a,0,m*sizeof(poly));
1836 p_Vec2Array(A->m[i],a,m,r);
1837 for(int j=0;j<m;j++)
1838 {
1839 if (a[j]!=NULL)
1840 {
1841 ideal sm=sm_MultAndShift(a[j], // A_i_j
1842 B,
1843 j*p, // shift j*p down
1844 r);
1845 sm_AddSubMat(res,sm,i*q,r); // add this columns to col i*q ff
1846 id_Delete(&sm,r); // delete the now empty ideal
1847 }
1848 }
1849 }
1850 omFreeSize(a,m*sizeof(poly));
1851 return res;
1852}
static ideal sm_MultAndShift(poly f, ideal B, int s, const ring r)
Definition: matpol.cc:1796
static void sm_AddSubMat(ideal res, ideal sm, int col, const ring r)
Definition: matpol.cc:1815
void p_Vec2Array(poly v, poly *p, int len, const ring r)
vector to already allocated array (len>=p_MaxComp(v,r))
Definition: p_polys.cc:3595

◆ sm_Trace()

poly sm_Trace ( ideal  a,
const ring  R 
)

Definition at line 1966 of file matpol.cc.

1967{
1968 int i;
1969 int n = (IDELEMS(a)<a->rank) ? IDELEMS(a) : a->rank;
1970 poly t = NULL;
1971
1972 for (i=0; i<=n; i++)
1973 t = p_Add_q(t, p_Copy(SMATELEM(a,i,i,R), R), R);
1974 return t;
1975}

◆ sm_UnFlatten()

ideal sm_UnFlatten ( ideal  a,
int  col,
const ring  R 
)

Definition at line 1939 of file matpol.cc.

1940{
1941 if ((IDELEMS(a)!=1)
1942 ||((a->rank % col)!=0))
1943 {
1944 Werror("wrong format: %d x %d for unflatten",(int)a->rank,IDELEMS(a));
1945 return NULL;
1946 }
1947 int row=a->rank/col;
1948 ideal res=idInit(col,row);
1949 poly p=a->m[0];
1950 while(p!=NULL)
1951 {
1952 poly h=p_Head(p,R);
1953 int comp=p_GetComp(h,R);
1954 int c=(comp-1)/row;
1955 int r=comp%row; if (r==0) r=row;
1956 p_SetComp(h,r,R); p_SetmComp(h,R);
1957 res->m[c]=p_Add_q(res->m[c],h,R);
1958 pIter(p);
1959 }
1960 return res;
1961}
int comp(const CanonicalForm &A, const CanonicalForm &B)
compare polynomials
#define p_SetmComp
Definition: p_polys.h:242

◆ TraceOfProd()

poly TraceOfProd ( matrix  a,
matrix  b,
int  n,
const ring  R 
)

Definition at line 282 of file matpol.cc.

283{
284 int i, j;
285 poly p, t = NULL;
286
287 for (i=1; i<=n; i++)
288 {
289 for (j=1; j<=n; j++)
290 {
291 p = pp_Mult_qq(MATELEM(a,i,j), MATELEM(b,j,i), R);
292 t = p_Add_q(t, p, R);
293 }
294 }
295 return t;
296}