version 1.9, 2003/08/21 12:28:58 |
version 1.15, 2005/06/16 05:07:23 |
|
|
/* $OpenXM: OpenXM/src/kan96xx/Kan/poly4.c,v 1.8 2003/08/19 08:02:10 takayama Exp $ */ |
/* $OpenXM: OpenXM/src/kan96xx/Kan/poly4.c,v 1.14 2004/07/29 08:13:42 takayama Exp $ */ |
#include <stdio.h> |
#include <stdio.h> |
#include "datatype.h" |
#include "datatype.h" |
#include "stackm.h" |
#include "stackm.h" |
|
|
static void shell(int v[],int n); |
static void shell(int v[],int n); |
static int degreeOfPrincipalPart(POLY f); |
static int degreeOfPrincipalPart(POLY f); |
static int degreeOfInitW(POLY f,int w[]); |
static int degreeOfInitW(POLY f,int w[]); |
|
static int degreeOfInitWS(POLY f,int w[],int s[]); |
|
static int dDegree(POLY f); |
|
static POLY dHomogenize(POLY f); |
|
|
|
|
static void shell(v,n) |
static void shell(v,n) |
int v[]; |
int v[]; |
int n; |
int n; |
Line 39 struct matrixOfPOLY *parts(f,v) |
|
Line 41 struct matrixOfPOLY *parts(f,v) |
|
int *ev; |
int *ev; |
struct object *evList; |
struct object *evList; |
struct object *list; |
struct object *list; |
struct object ob; |
struct object ob = OINIT; |
POLY ans; |
POLY ans; |
POLY h; |
POLY h; |
extern struct ring *CurrentRingp; |
extern struct ring *CurrentRingp; |
Line 126 struct object parts2(f,v) |
|
Line 128 struct object parts2(f,v) |
|
int *ev; |
int *ev; |
struct object *evList; |
struct object *evList; |
struct object *list; |
struct object *list; |
struct object ob; |
struct object ob = OINIT; |
POLY ans; |
POLY ans; |
POLY h; |
POLY h; |
POLY ft; |
POLY ft; |
struct object ob1,ob2,rob; |
struct object ob1 = OINIT; |
|
struct object ob2 = OINIT; |
|
struct object rob = OINIT; |
|
|
|
|
if (f ISZERO || v ISZERO) { |
if (f ISZERO || v ISZERO) { |
Line 305 POLY homogenize(f) |
|
Line 309 POLY homogenize(f) |
|
POLY t; |
POLY t; |
int maxg; |
int maxg; |
int flag,d; |
int flag,d; |
|
extern int Homogenize; |
|
|
if (f == ZERO) return(f); |
if (f == ZERO) return(f); |
|
if (Homogenize == 3) { /* double homogenization Dx x = x Dx + h H */ |
|
return dHomogenize(f); |
|
} |
t = f; maxg = (*grade)(f); flag = 0; |
t = f; maxg = (*grade)(f); flag = 0; |
while (t != POLYNULL) { |
while (t != POLYNULL) { |
d = (*grade)(t); |
d = (*grade)(t); |
Line 374 int isHomogenized_vec(f) |
|
Line 382 int isHomogenized_vec(f) |
|
return(1); |
return(1); |
} |
} |
|
|
|
static POLY dHomogenize(f) |
|
POLY f; |
|
{ |
|
POLY t; |
|
int maxg, maxdg; |
|
int flag,d,dd,neg; |
|
|
|
if (f == ZERO) return(f); |
|
|
|
t = f; |
|
maxg = (*grade)(f); |
|
while (t != POLYNULL) { |
|
dd = (*grade)(t); |
|
if (maxg < dd) maxg = dd; |
|
t = t->next; |
|
} |
|
/* fprintf(stderr,"maxg=%d\n",maxg); */ |
|
|
|
t = f; |
|
maxdg = dDegree(f); |
|
while (t != POLYNULL) { |
|
dd = dDegree(t); |
|
if (maxdg < dd) maxdg = dd; |
|
t = t->next; |
|
} |
|
/* fprintf(stderr,"maxdg=%d\n",maxdg); */ |
|
|
|
t = f; |
|
flag = 0; |
|
while (t != POLYNULL) { |
|
d = (*grade)(t); |
|
if (d != maxg) flag = 1; |
|
if (d > maxg) { |
|
maxg = d; |
|
} |
|
d = dDegree(f); |
|
if (d > maxdg) { |
|
maxdg = d; |
|
} |
|
t = t->next; |
|
} |
|
if (flag == 0) return(f); |
|
|
|
t = f; neg = 0; |
|
while (t != POLYNULL) { |
|
d = (*grade)(t); |
|
dd = dDegree(t); |
|
if (maxg-d-(maxdg-dd) < neg) { |
|
neg = maxg-d-(maxdg-dd); |
|
} |
|
t = t->next; |
|
} |
|
neg = -neg; |
|
|
|
f = pmCopy(f); /* You can rewrite the monomial parts */ |
|
t = f; |
|
while (t != POLYNULL) { |
|
d = (*grade)(t); |
|
dd = dDegree(t); |
|
t->m->e[0].D += maxdg-dd; /* h */ |
|
t->m->e[0].x += maxg-d-(maxdg-dd)+neg; /* Multiply H */ |
|
/* example Dx^2+Dx+x */ |
|
t = t->next; |
|
} |
|
return(f); |
|
} |
|
|
static int degreeOfPrincipalPart(f) |
static int degreeOfPrincipalPart(f) |
POLY f; |
POLY f; |
{ |
{ |
Line 387 static int degreeOfPrincipalPart(f) |
|
Line 461 static int degreeOfPrincipalPart(f) |
|
} |
} |
return(dd); |
return(dd); |
} |
} |
|
|
|
static int dDegree(f) |
|
POLY f; |
|
{ |
|
int nn,i,dd,m; |
|
if (f ISZERO) return(0); |
|
nn = f->m->ringp->nn; dd = 0; |
|
m = f->m->ringp->m; |
|
for (i=m; i<nn; i++) { |
|
dd += f->m->e[i].D; |
|
} |
|
return(dd); |
|
} |
|
|
POLY POLYToPrincipalPart(f) |
POLY POLYToPrincipalPart(f) |
POLY f; |
POLY f; |
Line 437 POLY POLYToInitW(f,w) |
|
Line 524 POLY POLYToInitW(f,w) |
|
POLY f; |
POLY f; |
int w[]; /* weight vector */ |
int w[]; /* weight vector */ |
{ |
{ |
POLY node; |
|
struct listPoly nod; |
|
POLY h; |
POLY h; |
POLY g; |
POLY g; |
int maxd; |
int maxd; |
int dd; |
int dd; |
node = &nod; node->next = POLYNULL; h = node; |
h = POLYNULL; |
|
|
|
/*printf("1:%s\n",POLYToString(f,'*',1));*/ |
if (f ISZERO) return(f); |
if (f ISZERO) return(f); |
maxd = degreeOfInitW(f,w); |
maxd = degreeOfInitW(f,w); |
g = pCopy(f); /* shallow copy */ |
g = f; |
while (!(f ISZERO)) { |
while (!(f ISZERO)) { |
dd = degreeOfInitW(f,w); |
dd = degreeOfInitW(f,w); |
if (dd > maxd) maxd = dd; |
if (dd > maxd) maxd = dd; |
Line 456 POLY POLYToInitW(f,w) |
|
Line 542 POLY POLYToInitW(f,w) |
|
while (!(g ISZERO)) { |
while (!(g ISZERO)) { |
dd = degreeOfInitW(g,w); |
dd = degreeOfInitW(g,w); |
if (dd == maxd) { |
if (dd == maxd) { |
h->next = g; |
h = ppAdd(h,newCell(g->coeffp,g->m)); /* it might be slow. */ |
h = h->next; |
|
} |
} |
g = g->next; |
g = g->next; |
} |
} |
h->next = POLYNULL; |
/*printf("2:%s\n",POLYToString(h,'*',1));*/ |
return(node->next); |
return(h); |
} |
} |
|
|
|
static int degreeOfInitWS(f,w,s) |
|
POLY f; |
|
int w[]; |
|
int s[]; |
|
{ |
|
int n,i,dd; |
|
if (f ISZERO) { |
|
errorPoly("degreeOfInitWS(0,w) "); |
|
} |
|
if (s == (int *) NULL) return degreeOfInitW(f,w); |
|
n = f->m->ringp->n; dd = 0; |
|
for (i=0; i<n-1; i++) { |
|
dd += (f->m->e[i].D)*w[n+i]; |
|
dd += (f->m->e[i].x)*w[i]; |
|
} |
|
dd += s[(f->m->e[n-1].x)]; |
|
return(dd); |
|
} |
|
|
|
POLY POLYToInitWS(f,w,s) |
|
POLY f; |
|
int w[]; /* weight vector */ |
|
int s[]; /* shift vector */ |
|
{ |
|
POLY h; |
|
POLY g; |
|
int maxd; |
|
int dd; |
|
h = POLYNULL; |
|
|
|
/*printf("1s:%s\n",POLYToString(f,'*',1));*/ |
|
if (f ISZERO) return(f); |
|
maxd = degreeOfInitWS(f,w,s); |
|
g = f; |
|
while (!(f ISZERO)) { |
|
dd = degreeOfInitWS(f,w,s); |
|
if (dd > maxd) maxd = dd; |
|
f = f->next; |
|
} |
|
while (!(g ISZERO)) { |
|
dd = degreeOfInitWS(g,w,s); |
|
if (dd == maxd) { |
|
h = ppAdd(h,newCell(g->coeffp,g->m)); /* it might be slow. */ |
|
} |
|
g = g->next; |
|
} |
|
/*printf("2s:%s\n",POLYToString(h,'*',1));*/ |
|
return(h); |
|
} |
|
|
|
int ordWsAll(f,w,s) |
|
POLY f; |
|
int w[]; /* weight vector */ |
|
int s[]; /* shift vector */ |
|
{ |
|
int maxd; |
|
int dd; |
|
|
|
if (f ISZERO) errorPoly("ordWsAll(0,w,s) "); |
|
maxd = degreeOfInitWS(f,w,s); |
|
while (!(f ISZERO)) { |
|
dd = degreeOfInitWS(f,w,s); |
|
if (dd > maxd) maxd = dd; |
|
f = f->next; |
|
} |
|
return maxd; |
|
} |
|
|
|
|
/* |
/* |
1.The substitution "ringp->multiplication = ...." is allowed only in |
1.The substitution "ringp->multiplication = ...." is allowed only in |
KsetUpRing(), so the check in KswitchFunction is not necessary. |
KsetUpRing(), so the check in KswitchFunction is not necessary. |
Line 559 POLY goDeHomogenizeS(POLY f) { |
|
Line 712 POLY goDeHomogenizeS(POLY f) { |
|
cp = f->coeffp; |
cp = f->coeffp; |
if (cp->tag == POLY_COEFF) { |
if (cp->tag == POLY_COEFF) { |
t = goDeHomogenizeS((cp->val).f); |
t = goDeHomogenizeS((cp->val).f); |
nc = newCell(polyToCoeff(t,f->m->ringp),f->m); |
nc = newCell(polyToCoeff(t,f->m->ringp),monomialCopy(f->m)); |
ans = ppAddv(ans,nc); |
ans = ppAddv(ans,nc); |
f = f->next; |
f = f->next; |
}else{ |
}else{ |
Line 633 POLY goHomogenize(POLY f,int u[],int v[],int ds[],int |
|
Line 786 POLY goHomogenize(POLY f,int u[],int v[],int ds[],int |
|
message = 1; |
message = 1; |
if (f == POLYNULL) return(POLYNULL); |
if (f == POLYNULL) return(POLYNULL); |
rp = f->m->ringp; |
rp = f->m->ringp; |
|
/* |
if ((rp->degreeShiftSize == 0) && (dssize > 0)) { |
if ((rp->degreeShiftSize == 0) && (dssize > 0)) { |
warningPoly("You are trying to homogenize a polynomial with degree shift. However, the polynomial belongs to the ring without degreeShift option. It may cause a trouble in comparison in free module.\n"); |
warningPoly("You are trying to homogenize a polynomial with degree shift. However, the polynomial belongs to the ring without degreeShift option. It may cause a trouble in comparison in free module.\n"); |
} |
} |
|
*/ |
node = &nod; |
node = &nod; |
node->next = POLYNULL; |
node->next = POLYNULL; |
lastf = POLYNULL; |
lastf = POLYNULL; |
Line 687 POLY goHomogenize(POLY f,int u[],int v[],int ds[],int |
|
Line 842 POLY goHomogenize(POLY f,int u[],int v[],int ds[],int |
|
h = node->next; |
h = node->next; |
/*go-debug printf("m=%d, mp=%d\n",m,mp); */ |
/*go-debug printf("m=%d, mp=%d\n",m,mp); */ |
while (h != POLYNULL) { |
while (h != POLYNULL) { |
/*go-debug printf("Old: h=%d, s=%d\n",h->m->e[0].D,h->m->e[0].x); */ |
/*go-debug printf("Old: h=%d, s=%d\n",h->m->e[0].D,h->m->e[0].x); */ |
if (!onlyS) h->m->e[0].D += m; /* h */ |
if (!onlyS) h->m->e[0].D += m; /* h */ |
h->m->e[0].x += -mp; /* H, s*/ |
h->m->e[0].x += -mp; /* H, s*/ |
/*go-debug printf("New: h=%d, s=%d\n",h->m->e[0].D,h->m->e[0].x); */ |
/*go-debug printf("New: h=%d, s=%d\n",h->m->e[0].D,h->m->e[0].x); */ |