| version 1.2, 2000/01/16 07:55:40 |
version 1.3, 2001/05/04 01:06:25 |
|
|
| /* $OpenXM$ */ |
/* $OpenXM: OpenXM/src/kan96xx/Kan/poly2.c,v 1.2 2000/01/16 07:55:40 takayama Exp $ */ |
| #include <stdio.h> |
#include <stdio.h> |
| #include "datatype.h" |
#include "datatype.h" |
| #include "stackm.h" |
#include "stackm.h" |
|
|
| static POLY mapZmonom(POLY f,struct ring *ringp); |
static POLY mapZmonom(POLY f,struct ring *ringp); |
| |
|
| POLY ppAdd(f,g) |
POLY ppAdd(f,g) |
| POLY f; POLY g; /* The result is read only. */ |
POLY f; POLY g; /* The result is read only. */ |
| { |
{ |
| POLY node; |
POLY node; |
| struct listPoly nod; |
struct listPoly nod; |
| Line 33 POLY f; POLY g; /* The result is read only. */ |
|
| Line 33 POLY f; POLY g; /* The result is read only. */ |
|
| h = h->next; |
h = h->next; |
| f = f->next; |
f = f->next; |
| if (f == POLYNULL) { |
if (f == POLYNULL) { |
| h->next = g; |
h->next = g; |
| return(node->next); |
return(node->next); |
| } |
} |
| break; |
break; |
| case 0: /* f < g */ |
case 0: /* f < g */ |
| Line 42 POLY f; POLY g; /* The result is read only. */ |
|
| Line 42 POLY f; POLY g; /* The result is read only. */ |
|
| h = h->next; |
h = h->next; |
| g = g->next; |
g = g->next; |
| if (g == POLYNULL) { |
if (g == POLYNULL) { |
| h->next = f; |
h->next = f; |
| return(node->next); |
return(node->next); |
| } |
} |
| break; |
break; |
| case 2:/* f == g */ |
case 2:/* f == g */ |
| c = coeffCopy(f->coeffp); |
c = coeffCopy(f->coeffp); |
| Cadd(c,c,g->coeffp); |
Cadd(c,c,g->coeffp); |
| if (!isZero(c)) { |
if (!isZero(c)) { |
| h->next = newCell(c,f->m); |
h->next = newCell(c,f->m); |
| h = h->next; |
h = h->next; |
| f = f->next; |
f = f->next; |
| g = g->next; |
g = g->next; |
| if (f == POLYNULL) { |
if (f == POLYNULL) { |
| h->next = g; |
h->next = g; |
| return(node->next); |
return(node->next); |
| } |
} |
| if (g == POLYNULL) { |
if (g == POLYNULL) { |
| h->next = f; |
h->next = f; |
| return(node->next); |
return(node->next); |
| } |
} |
| }else{ |
}else{ |
| f = f->next; |
f = f->next; |
| g = g->next; |
g = g->next; |
| if (f == POLYNULL) { |
if (f == POLYNULL) { |
| h->next = g; |
h->next = g; |
| return(node->next); |
return(node->next); |
| } |
} |
| if (g == POLYNULL) { |
if (g == POLYNULL) { |
| h->next = f; |
h->next = f; |
| return(node->next); |
return(node->next); |
| } |
} |
| } |
} |
| break; |
break; |
| default: |
default: |
| Line 84 POLY f; POLY g; /* The result is read only. */ |
|
| Line 84 POLY f; POLY g; /* The result is read only. */ |
|
| } |
} |
| |
|
| POLY ppSub(f,g) |
POLY ppSub(f,g) |
| POLY f; POLY g; /* The result is read only. */ |
POLY f; POLY g; /* The result is read only. */ |
| { |
{ |
| POLY h; |
POLY h; |
| struct coeff *c; |
struct coeff *c; |
| Line 99 POLY f; POLY g; /* The result is read only. */ |
|
| Line 99 POLY f; POLY g; /* The result is read only. */ |
|
| |
|
| |
|
| POLY cpMult(c,f) |
POLY cpMult(c,f) |
| struct coeff *c; |
struct coeff *c; |
| POLY f; |
POLY f; |
| { |
{ |
| POLY node; |
POLY node; |
| struct listPoly nod; |
struct listPoly nod; |
|
|
| } |
} |
| |
|
| MONOMIAL monomialAdd_poly(m,m2) |
MONOMIAL monomialAdd_poly(m,m2) |
| MONOMIAL m,m2; |
MONOMIAL m,m2; |
| { |
{ |
| extern int Msize; |
extern int Msize; |
| MONOMIAL f; |
MONOMIAL f; |
|
|
| |
|
| /* Note that mpMult_poly is called from mmLarger_tower! */ |
/* Note that mpMult_poly is called from mmLarger_tower! */ |
| POLY mpMult_poly(f,g) |
POLY mpMult_poly(f,g) |
| POLY f; |
POLY f; |
| POLY g; |
POLY g; |
| { |
{ |
| POLY node; |
POLY node; |
| struct listPoly nod; |
struct listPoly nod; |
|
|
| } |
} |
| |
|
| POLY ppMult_old(f,g) |
POLY ppMult_old(f,g) |
| POLY f,g; |
POLY f,g; |
| { |
{ |
| POLY r; |
POLY r; |
| POLY tmp; |
POLY tmp; |
|
|
| } |
} |
| |
|
| POLY ppAddv(f,g) |
POLY ppAddv(f,g) |
| POLY f; POLY g; /* It breaks f and g. Use it just after calling mpMult() */ |
POLY f; POLY g; /* It breaks f and g. Use it just after calling mpMult() */ |
| { |
{ |
| POLY node; |
POLY node; |
| struct listPoly nod; |
struct listPoly nod; |
| Line 215 POLY f; POLY g; /* It breaks f and g. Use it just aft |
|
| Line 215 POLY f; POLY g; /* It breaks f and g. Use it just aft |
|
| h->next = f; |
h->next = f; |
| h = h->next; f = f->next;; |
h = h->next; f = f->next;; |
| if (f == POLYNULL) { |
if (f == POLYNULL) { |
| h->next = g; |
h->next = g; |
| return(node->next); |
return(node->next); |
| } |
} |
| break; |
break; |
| case 0: /* f < g */ |
case 0: /* f < g */ |
| h->next = g; |
h->next = g; |
| h = h->next; g = g->next; |
h = h->next; g = g->next; |
| if (g == POLYNULL) { |
if (g == POLYNULL) { |
| h->next = f; |
h->next = f; |
| return(node->next); |
return(node->next); |
| } |
} |
| break; |
break; |
| case 2:/* f == g */ |
case 2:/* f == g */ |
| c = f->coeffp; |
c = f->coeffp; |
| Cadd(c,c,g->coeffp); |
Cadd(c,c,g->coeffp); |
| if (!isZero(c)) { |
if (!isZero(c)) { |
| h->next = f; |
h->next = f; |
| h = h->next; f = f->next;; |
h = h->next; f = f->next;; |
| g = g->next; |
g = g->next; |
| if (f == POLYNULL) { |
if (f == POLYNULL) { |
| h->next = g; |
h->next = g; |
| return(node->next); |
return(node->next); |
| } |
} |
| if (g == POLYNULL) { |
if (g == POLYNULL) { |
| h->next = f; |
h->next = f; |
| return(node->next); |
return(node->next); |
| } |
} |
| }else{ |
}else{ |
| f = f->next; |
f = f->next; |
| g = g->next; |
g = g->next; |
| if (f == POLYNULL) { |
if (f == POLYNULL) { |
| h->next = g; |
h->next = g; |
| return(node->next); |
return(node->next); |
| } |
} |
| if (g == POLYNULL) { |
if (g == POLYNULL) { |
| h->next = f; |
h->next = f; |
| return(node->next); |
return(node->next); |
| } |
} |
| } |
} |
| break; |
break; |
| default: |
default: |
| Line 264 POLY f; POLY g; /* It breaks f and g. Use it just aft |
|
| Line 264 POLY f; POLY g; /* It breaks f and g. Use it just aft |
|
| } |
} |
| |
|
| POLY pPower(f,k) |
POLY pPower(f,k) |
| POLY f; |
POLY f; |
| int k; |
int k; |
| { |
{ |
| POLY r; |
POLY r; |
| int i,n; |
int i,n; |
|
|
| } |
} |
| |
|
| POLY pPower_poly(f,k) |
POLY pPower_poly(f,k) |
| POLY f; |
POLY f; |
| int k; |
int k; |
| { |
{ |
| POLY r; |
POLY r; |
| int i,n; |
int i,n; |
|
|
| } |
} |
| |
|
| POLY modulop_trash(f,ringp) |
POLY modulop_trash(f,ringp) |
| POLY f; |
POLY f; |
| struct ring *ringp; |
struct ring *ringp; |
| { |
{ |
| int p; |
int p; |
| POLY h; |
POLY h; |
| Line 382 struct ring *ringp; |
|
| Line 382 struct ring *ringp; |
|
| mpz_mod_ui(c,f->coeffp->val.bigp,(unsigned long int)p); |
mpz_mod_ui(c,f->coeffp->val.bigp,(unsigned long int)p); |
| cc = (int) mpz_get_si(c); |
cc = (int) mpz_get_si(c); |
| if (cc != 0) { |
if (cc != 0) { |
| h->next = newCell(newCoeff(),monomialCopy(f->m)); |
h->next = newCell(newCoeff(),monomialCopy(f->m)); |
| h = h->next; |
h = h->next; |
| h->m->ringp = ringp; |
h->m->ringp = ringp; |
| h->coeffp->tag = INTEGER; |
h->coeffp->tag = INTEGER; |
| h->coeffp->p = p; |
h->coeffp->p = p; |
| h->coeffp->val.i = cc; |
h->coeffp->val.i = cc; |
| } |
} |
| f = f->next; |
f = f->next; |
| } |
} |
| Line 404 struct ring *ringp; |
|
| Line 404 struct ring *ringp; |
|
| } |
} |
| |
|
| POLY modulop(f,ringp) |
POLY modulop(f,ringp) |
| POLY f; |
POLY f; |
| struct ring *ringp; |
struct ring *ringp; |
| /* Z[x] ---> R[x] where R=Z, Z/Zp, ringp->next. */ |
/* Z[x] ---> R[x] where R=Z, Z/Zp, ringp->next. */ |
| { |
{ |
| int p; |
int p; |
| POLY h; |
POLY h; |
| Line 447 struct ring *ringp; |
|
| Line 447 struct ring *ringp; |
|
| mpz_mod_ui(c,f->coeffp->val.bigp,(unsigned long int)p); |
mpz_mod_ui(c,f->coeffp->val.bigp,(unsigned long int)p); |
| cc = (int) mpz_get_si(c); |
cc = (int) mpz_get_si(c); |
| if (cc != 0) { |
if (cc != 0) { |
| h->next = newCell(newCoeff(),monomialCopy(f->m)); |
h->next = newCell(newCoeff(),monomialCopy(f->m)); |
| h = h->next; |
h = h->next; |
| h->m->ringp = ringp; |
h->m->ringp = ringp; |
| h->coeffp->tag = INTEGER; |
h->coeffp->tag = INTEGER; |
| h->coeffp->p = p; |
h->coeffp->p = p; |
| h->coeffp->val.i = cc; |
h->coeffp->val.i = cc; |
| } |
} |
| f = f->next; |
f = f->next; |
| } |
} |
| Line 471 struct ring *ringp; |
|
| Line 471 struct ring *ringp; |
|
| } |
} |
| |
|
| POLY modulopZ(f,pcoeff) |
POLY modulopZ(f,pcoeff) |
| POLY f; |
POLY f; |
| struct coeff *pcoeff; |
struct coeff *pcoeff; |
| /* Z[x] ---> Z[x] , f ---> f mod pcoeff*/ |
/* Z[x] ---> Z[x] , f ---> f mod pcoeff*/ |
| { |
{ |
| int p; |
int p; |
| POLY h; |
POLY h; |
| Line 535 struct coeff *pcoeff; |
|
| Line 535 struct coeff *pcoeff; |
|
| } |
} |
| |
|
| struct pairOfPOLY quotientByNumber(f,pcoeff) |
struct pairOfPOLY quotientByNumber(f,pcoeff) |
| POLY f; |
POLY f; |
| struct coeff *pcoeff; |
struct coeff *pcoeff; |
| /* Z[x] ---> Z[x],Z[x] , f = first*pcoeff + second */ |
/* Z[x] ---> Z[x],Z[x] , f = first*pcoeff + second */ |
| { |
{ |
| int p; |
int p; |
| POLY h; |
POLY h; |
| Line 631 struct coeff *pcoeff; |
|
| Line 631 struct coeff *pcoeff; |
|
| |
|
| |
|
| POLY modulo0(f,ringp) |
POLY modulo0(f,ringp) |
| POLY f; |
POLY f; |
| struct ring *ringp; |
struct ring *ringp; |
| { |
{ |
| int p; |
int p; |
| POLY h; |
POLY h; |
| Line 650 struct ring *ringp; |
|
| Line 650 struct ring *ringp; |
|
| node = pcmCopy(f); |
node = pcmCopy(f); |
| f = node; |
f = node; |
| while (f != POLYNULL) { |
while (f != POLYNULL) { |
| f->m->ringp = ringp; /* Touch the monomial "ringp" field. */ |
f->m->ringp = ringp; /* Touch the monomial "ringp" field. */ |
| f = f->next; |
f = f->next; |
| } |
} |
| return(node); |
return(node); |
| } |
} |
| Line 692 struct ring *ringp; |
|
| Line 692 struct ring *ringp; |
|
| |
|
| |
|
| struct object test(ob) /* test3 */ |
struct object test(ob) /* test3 */ |
| struct object ob; |
struct object ob; |
| { |
{ |
| struct object rob; |
struct object rob; |
| int k; |
int k; |
| Line 714 struct object ob; |
|
| Line 714 struct object ob; |
|
| for (i=k; i>=0; i--) { |
for (i=k; i>=0; i--) { |
| f0->next = bxx(BiiPower(-k,i),0,i,CurrentRingp); |
f0->next = bxx(BiiPower(-k,i),0,i,CurrentRingp); |
| if (f0->next != POLYNULL) { |
if (f0->next != POLYNULL) { |
| f0 = f0->next; |
f0 = f0->next; |
| } |
} |
| } |
} |
| f0 = addNode->next; |
f0 = addNode->next; |
| Line 726 struct object ob; |
|
| Line 726 struct object ob; |
|
| for (i=k; i>=0; i--) { |
for (i=k; i>=0; i--) { |
| f1->next = bxx(BiiPower(k,i),0,i,CurrentRingp); |
f1->next = bxx(BiiPower(k,i),0,i,CurrentRingp); |
| if (f1->next != POLYNULL) { |
if (f1->next != POLYNULL) { |
| f1 = f1->next; |
f1 = f1->next; |
| } |
} |
| } |
} |
| f1 = addNode->next; |
f1 = addNode->next; |
| Line 746 struct object ob; |
|
| Line 746 struct object ob; |
|
| |
|
| |
|
| int pLength(f) |
int pLength(f) |
| POLY f; |
POLY f; |
| { |
{ |
| int c=0; |
int c=0; |
| if (f ISZERO) return(0); |
if (f ISZERO) return(0); |
|
|
| |
|
| |
|
| POLY ppAddv2(f,g,top,nexttop) |
POLY ppAddv2(f,g,top,nexttop) |
| POLY f; POLY g; /* It breaks f and g. Use it just after calling mpMult() */ |
POLY f; POLY g; /* It breaks f and g. Use it just after calling mpMult() */ |
| POLY top; |
POLY top; |
| POLY *nexttop; |
POLY *nexttop; |
| /* top is the starting address in the list f. |
/* top is the starting address in the list f. |
| if top == POLYNULL, start from f. |
if top == POLYNULL, start from f. |
| |
|
| *nexttop == 0 |
*nexttop == 0 |
| == g |
== g |
| == h or 0 |
== h or 0 |
| |
|
| It must be called as r = ppAddv2(r,g,...); |
It must be called as r = ppAddv2(r,g,...); |
| */ |
*/ |
| { |
{ |
| POLY node; |
POLY node; |
|
|
| if (top != POLYNULL) { |
if (top != POLYNULL) { |
| while (f != top) { |
while (f != top) { |
| if (f == POLYNULL) { |
if (f == POLYNULL) { |
| fprintf(stderr,"\nppAddv2(): Internal error.\n");fflush(stderr); |
fprintf(stderr,"\nppAddv2(): Internal error.\n");fflush(stderr); |
| fprintf(stderr,"f = %s\n",POLYToString(f0,'*',0)); |
fprintf(stderr,"f = %s\n",POLYToString(f0,'*',0)); |
| fprintf(stderr,"g = %s\n",POLYToString(g0,'*',0)); |
fprintf(stderr,"g = %s\n",POLYToString(g0,'*',0)); |
| fprintf(stderr,"top=%s\n",POLYToString(top,'*',0)); |
fprintf(stderr,"top=%s\n",POLYToString(top,'*',0)); |
| errorPoly("ppAddv2(). Internal error=1."); |
errorPoly("ppAddv2(). Internal error=1."); |
| } |
} |
| h->next = f; |
h->next = f; |
| h = h->next; |
h = h->next; |
|
|
| h->next = f; |
h->next = f; |
| h = h->next; f = f->next;; |
h = h->next; f = f->next;; |
| if (f == POLYNULL) { |
if (f == POLYNULL) { |
| h->next = g; |
h->next = g; |
| return(node->next); |
return(node->next); |
| } |
} |
| break; |
break; |
| case 0: /* f < g */ |
case 0: /* f < g */ |
| h->next = g; |
h->next = g; |
| h = h->next; g = g->next; |
h = h->next; g = g->next; |
| if (g == POLYNULL) { |
if (g == POLYNULL) { |
| h->next = f; |
h->next = f; |
| return(node->next); |
return(node->next); |
| } |
} |
| break; |
break; |
| case 2:/* f == g */ |
case 2:/* f == g */ |
| c = g->coeffp; |
c = g->coeffp; |
| Cadd(c,f->coeffp,c); |
Cadd(c,f->coeffp,c); |
| if (!isZero(c)) { |
if (!isZero(c)) { |
| h->next = g; |
h->next = g; |
| h = h->next; |
h = h->next; |
| f = f->next;; |
f = f->next;; |
| g = g->next; |
g = g->next; |
| if (f == POLYNULL) { |
if (f == POLYNULL) { |
| h->next = g; |
h->next = g; |
| return(node->next); |
return(node->next); |
| } |
} |
| if (g == POLYNULL) { |
if (g == POLYNULL) { |
| h->next = f; |
h->next = f; |
| return(node->next); |
return(node->next); |
| } |
} |
| }else{ |
}else{ |
| if (g == g0) { |
if (g == g0) { |
| if (h != node) { |
if (h != node) { |
| *nexttop = h; |
*nexttop = h; |
| }else{ |
}else{ |
| *nexttop = POLYNULL; |
*nexttop = POLYNULL; |
| } |
} |
| } |
} |
| |
|
| f = f->next; |
f = f->next; |
| g = g->next; |
g = g->next; |
| |
|
| if (f == POLYNULL) { |
if (f == POLYNULL) { |
| h->next = g; |
h->next = g; |
| return(node->next); |
return(node->next); |
| } |
} |
| if (g == POLYNULL) { |
if (g == POLYNULL) { |
| h->next = f; |
h->next = f; |
| return(node->next); |
return(node->next); |
| } |
} |
| } |
} |
| break; |
break; |
| default: |
default: |
|
|
| } |
} |
| |
|
| POLY ppMult(f,g) |
POLY ppMult(f,g) |
| POLY f,g; |
POLY f,g; |
| { |
{ |
| POLY r; |
POLY r; |
| POLY tmp; |
POLY tmp; |
|
|
| } |
} |
| |
|
| POLY ppMult_poly(f,g) |
POLY ppMult_poly(f,g) |
| POLY f,g; |
POLY f,g; |
| { |
{ |
| POLY r; |
POLY r; |
| POLY tmp; |
POLY tmp; |
|
|
| } |
} |
| |
|
| POLY mapZmonom(f,ringp) |
POLY mapZmonom(f,ringp) |
| POLY f; /* assumes monomial. f \in Z[x] */ |
POLY f; /* assumes monomial. f \in Z[x] */ |
| struct ring *ringp; /* R[x] */ |
struct ring *ringp; /* R[x] */ |
| { |
{ |
| struct ring *nextRing; |
struct ring *nextRing; |
| struct ring nextRing0; |
struct ring nextRing0; |