=================================================================== RCS file: /home/cvs/OpenXM/src/kan96xx/Kan/coeff.c,v retrieving revision 1.2 retrieving revision 1.3 diff -u -p -r1.2 -r1.3 --- OpenXM/src/kan96xx/Kan/coeff.c 2000/01/16 07:55:38 1.2 +++ OpenXM/src/kan96xx/Kan/coeff.c 2001/05/04 01:06:23 1.3 @@ -1,4 +1,4 @@ -/* $OpenXM$ */ +/* $OpenXM: OpenXM/src/kan96xx/Kan/coeff.c,v 1.2 2000/01/16 07:55:38 takayama Exp $ */ #include #include "datatype.h" #include "stackm.h" @@ -18,7 +18,7 @@ static void printTag(coeffType t) } char *intToString(i) -int i; + int i; { char work[80]; char *s; @@ -30,7 +30,7 @@ int i; } char *coeffToString(cp) -struct coeff *cp; + struct coeff *cp; { char *s; switch(cp->tag) { @@ -54,8 +54,8 @@ struct coeff *cp; /* constructors */ struct coeff *intToCoeff(i,ringp) -int i; -struct ring *ringp; + int i; + struct ring *ringp; { struct coeff *c; int p; @@ -79,8 +79,8 @@ struct ring *ringp; } struct coeff *mpintToCoeff(b,ringp) -MP_INT *b; -struct ring *ringp; + MP_INT *b; + struct ring *ringp; { struct coeff *c; struct coeff *c2; @@ -103,16 +103,16 @@ struct ring *ringp; c->val.f = coeffToPoly(c2,ringp->next); return(c); /* - errorCoeff("mpintToCoeff(): mpint --> poly_coeff has not yet be supported. Returns 0."); - c->tag = POLY_COEFF; - c->val.f = ZERO; + errorCoeff("mpintToCoeff(): mpint --> poly_coeff has not yet be supported. Returns 0."); + c->tag = POLY_COEFF; + c->val.f = ZERO; */ } } struct coeff *polyToCoeff(f,ringp) -POLY f; -struct ring *ringp; + POLY f; + struct ring *ringp; { struct coeff *c; if (f ISZERO) { @@ -133,8 +133,8 @@ struct ring *ringp; /* returns -c */ struct coeff *coeffNeg(c,ringp) -struct coeff *c; -struct ring *ringp; + struct coeff *c; + struct ring *ringp; { struct coeff *r; r = intToCoeff(-1,ringp); @@ -143,7 +143,7 @@ struct ring *ringp; } int coeffToInt(cp) -struct coeff *cp; + struct coeff *cp; { POLY f; switch(cp->tag) { @@ -164,9 +164,9 @@ struct coeff *cp; } void Cadd(r,a,b) -struct coeff *r; -struct coeff *a; -struct coeff *b; + struct coeff *r; + struct coeff *a; + struct coeff *b; { int p; POLY f; @@ -175,10 +175,10 @@ struct coeff *b; r->p = p = a->p; r->val.i = ((a->val.i) + (b->val.i)) % p; }else if (a->tag == MP_INTEGER && b->tag == MP_INTEGER - && r->tag == MP_INTEGER) { + && r->tag == MP_INTEGER) { mpz_add(r->val.bigp,a->val.bigp,b->val.bigp); }else if (a->tag == POLY_COEFF && b->tag == POLY_COEFF - && r->tag == POLY_COEFF) { + && r->tag == POLY_COEFF) { f = ppAdd(a->val.f,b->val.f); r->val.f = f; }else { @@ -187,9 +187,9 @@ struct coeff *b; } void Csub(r,a,b) -struct coeff *r; -struct coeff *a; -struct coeff *b; + struct coeff *r; + struct coeff *a; + struct coeff *b; { int p; @@ -197,7 +197,7 @@ struct coeff *b; r->p = p = a->p; r->val.i = ((a->val.i) - (b->val.i)) % p; }else if (a->tag == MP_INTEGER && b->tag == MP_INTEGER - && r->tag == MP_INTEGER) { + && r->tag == MP_INTEGER) { mpz_sub(r->val.bigp,a->val.bigp,b->val.bigp); }else { warningCoeff("Csub(): The data type is not supported."); @@ -205,9 +205,9 @@ struct coeff *b; } void Cmult(r,a,b) -struct coeff *r; -struct coeff *a; -struct coeff *b; + struct coeff *r; + struct coeff *a; + struct coeff *b; { int p; POLY f; @@ -216,10 +216,10 @@ struct coeff *b; r->p = p = a->p; r->val.i = ((a->val.i) * (b->val.i)) % p; }else if (a->tag == MP_INTEGER && b->tag == MP_INTEGER - && r->tag == MP_INTEGER) { + && r->tag == MP_INTEGER) { mpz_mul(r->val.bigp,a->val.bigp,b->val.bigp); }else if (a->tag == POLY_COEFF && b->tag == POLY_COEFF - && r->tag == POLY_COEFF) { + && r->tag == POLY_COEFF) { f = ppMult(a->val.f,b->val.f); r->val.f = f; }else { @@ -232,7 +232,7 @@ struct coeff *b; } int isZero(a) -struct coeff *a; + struct coeff *a; { int r; if (a->tag == INTEGER) { @@ -252,8 +252,8 @@ struct coeff *a; } struct coeff *coeffCopy(c) -struct coeff *c; -/* Deep copy */ + struct coeff *c; + /* Deep copy */ { struct coeff *r; r = newCoeff(); @@ -281,9 +281,9 @@ struct coeff *c; } void CiiComb(r,p,q) -struct coeff *r; -int p,q; -/* r->val.bigp is read only. */ + struct coeff *r; + int p,q; + /* r->val.bigp is read only. */ { switch(r->tag) { case INTEGER: @@ -301,15 +301,15 @@ int p,q; MP_INT *BiiComb(p,q) -int p,q; -/* It returns {p \choose q} when p>=0, 0<=q<=p. - The value is read only. DON'T CHANGE IT. -p=0 0 1 -p=1 1 2 1 1 -p=2 3 4 5 1 2 1 - q=0 q=1 q=2 - [p(p+1)/2+q] -*/ + int p,q; + /* It returns {p \choose q} when p>=0, 0<=q<=p. + The value is read only. DON'T CHANGE IT. + p=0 0 1 + p=1 1 2 1 1 + p=2 3 4 5 1 2 1 + q=0 q=1 q=2 + [p(p+1)/2+q] + */ { extern MP_INT *Mp_one; int i,j; @@ -327,15 +327,15 @@ p=2 3 4 5 1 2 1 if (newTable == (MP_INT **) NULL) errorCoeff("BiiComb(): No more memory."); for (i=0; i=0 and 0<=q or - p<0 and 0<=q. - [p,q] = p*[p-1,q-1]. [p,0] = 1. - The value is read only. DON'T CHANGE IT. + /* It returns p(p-1) ... (p-q+1) = [p,q] when p>=0 and 0<=q or + p<0 and 0<=q. + [p,q] = p*[p-1,q-1]. [p,0] = 1. + The value is read only. DON'T CHANGE IT. -When p>=0, -p=0 0 1 -p=1 1 2 1 1 -p=2 3 4 5 1 2 2*1 -p=3 6 7 8 9 1 3 3*2 3*2*1, if p=0, + p=0 0 1 + p=1 1 2 1 1 + p=2 3 4 5 1 2 2*1 + p=3 6 7 8 9 1 3 3*2 3*2*1, if p=0 && p < k) return(0); @@ -553,9 +553,9 @@ int iiPoch(p,k,P) int p,k,P; /* p(p-1)...(p-k+1) */ { } void CiiPoch(r,p,q) -struct coeff *r; -int p,q; -/* r->val.bigp is read only. */ + struct coeff *r; + int p,q; + /* r->val.bigp is read only. */ { switch(r->tag) { case INTEGER: @@ -571,21 +571,21 @@ int p,q; } MP_INT *BiiPower(p,q) -int p,q; -/* It returns p^q. q must be >=0. - p^q = [p,q] = p*[p,q-1]. - The value is read only. DON'T CHANGE IT. -*/ - /* -[p,q] is indexed by table2D[p+q,q]=table1D[(p+q)(p+q+1)/2 + q]. -p+q = pq. + int p,q; + /* It returns p^q. q must be >=0. + p^q = [p,q] = p*[p,q-1]. + The value is read only. DON'T CHANGE IT. + */ + /* + [p,q] is indexed by table2D[p+q,q]=table1D[(p+q)(p+q+1)/2 + q]. + p+q = pq. -q=3 0 1 8 27 -q=2 0 1 4 9 -q=1 0 1 2 3 -q=0 1 1 1 1 - -p=0 -p=1 -p=2 -p=3 - */ + q=3 0 1 8 27 + q=2 0 1 4 9 + q=1 0 1 2 3 + q=0 1 1 1 1 + -p=0 -p=1 -p=2 -p=3 + */ { extern MP_INT *Mp_one; extern MP_INT *Mp_zero; @@ -622,22 +622,22 @@ q=0 1 1 1 1 errorCoeff("BiiPower(): No more memory."); for (i=0; i=0*/ -int P; + int k; + int s; /* k^s , s>=0*/ + int P; { int kk,r; r = 1; @@ -680,9 +680,9 @@ int P; } void CiiPower(r,p,q) -struct coeff *r; -int p,q; -/* r->val.bigp is read only. */ + struct coeff *r; + int p,q; + /* r->val.bigp is read only. */ { switch(r->tag) { case INTEGER: @@ -698,8 +698,8 @@ int p,q; } struct coeff *stringToUniversalNumber(s,flagp) -char *s; -int *flagp; + char *s; + int *flagp; { MP_INT *value; struct coeff * c; @@ -712,24 +712,24 @@ int *flagp; } struct coeff *newUniversalNumber(i) -int i; + int i; { extern struct ring *SmallRingp; - struct coeff *c; - c = intToCoeff(i,SmallRingp); - return(c); + struct coeff *c; + c = intToCoeff(i,SmallRingp); + return(c); } struct coeff *newUniversalNumber2(i) -MP_INT *i; + MP_INT *i; { extern struct ring *SmallRingp; - struct coeff *c; - c = mpintToCoeff(i,SmallRingp); - return(c); + struct coeff *c; + c = mpintToCoeff(i,SmallRingp); + return(c); } int coeffEqual(a,b) -struct coeff *a; -struct coeff *b; + struct coeff *a; + struct coeff *b; { if (a->tag == INTEGER && b->tag == INTEGER) { return((a->val.i) == (b->val.i)); @@ -744,8 +744,8 @@ struct coeff *b; } int coeffGreater(a,b) -struct coeff *a; -struct coeff *b; + struct coeff *a; + struct coeff *b; { if (a->tag == INTEGER && b->tag == INTEGER) { return((a->val.i) - (b->val.i)); @@ -760,9 +760,9 @@ struct coeff *b; } void universalNumberDiv(r,a,b) -struct coeff *r; -struct coeff *a; -struct coeff *b; + struct coeff *r; + struct coeff *a; + struct coeff *b; { if (a->tag == MP_INTEGER && b->tag == MP_INTEGER && r->tag == MP_INTEGER) { mpz_div(r->val.bigp,a->val.bigp,b->val.bigp); @@ -773,26 +773,26 @@ struct coeff *b; /* Note that it does not check if c is zero or not. cf isZero(). */ POLY coeffToPoly(c,ringp) -struct coeff *c; -struct ring *ringp; + struct coeff *c; + struct ring *ringp; { int p; - struct coeff *tc; + struct coeff *tc; - if (c->tag == INTEGER) { - tc = intToCoeff(c->val.i,ringp); - return(newCell(tc,newMonomial(ringp))); - }else if (c->tag == MP_INTEGER) { - tc = mpintToCoeff(c->val.bigp,ringp); - return(newCell(tc,newMonomial(ringp))); - } else if (c->tag == POLY_COEFF) { - return(newCell(c,newMonomial(ringp))); - }else { - warningCoeff("coeffToPoly(): The data type is not supported. Return 0."); - return(ZERO); - } + if (c->tag == INTEGER) { + tc = intToCoeff(c->val.i,ringp); + return(newCell(tc,newMonomial(ringp))); + }else if (c->tag == MP_INTEGER) { + tc = mpintToCoeff(c->val.bigp,ringp); + return(newCell(tc,newMonomial(ringp))); + } else if (c->tag == POLY_COEFF) { + return(newCell(c,newMonomial(ringp))); + }else { + warningCoeff("coeffToPoly(): The data type is not supported. Return 0."); + return(ZERO); + } } void errorCoeff(str) -char *str; + char *str; { fprintf(stderr,"Error(coeff.c): %s\n",str); fprintf(stderr,"Type in ctrl-\\");getchar(); @@ -800,7 +800,7 @@ char *str; } void warningCoeff(str) -char *str; + char *str; { fprintf(stderr,"Warning(coeff.c): %s\n",str); }