=================================================================== RCS file: /home/cvs/OpenXM/src/kan96xx/Kan/output.c,v retrieving revision 1.1.1.1 retrieving revision 1.7 diff -u -p -r1.1.1.1 -r1.7 --- OpenXM/src/kan96xx/Kan/output.c 1999/10/08 02:12:01 1.1.1.1 +++ OpenXM/src/kan96xx/Kan/output.c 2011/10/05 05:46:14 1.7 @@ -1,4 +1,8 @@ +/* $OpenXM: OpenXM/src/kan96xx/Kan/output.c,v 1.6 2006/12/21 05:29:49 takayama Exp $ */ #include +#include +#include +#include #include "datatype.h" #include "stackm.h" #include "extern.h" @@ -16,8 +20,8 @@ struct outputQueue { static void putstr(char *s,struct outputQueue *oq); static void putstr(s,oq) -char *s; -struct outputQueue *oq; + char *s; + struct outputQueue *oq; { int i; char **tmp; @@ -50,11 +54,13 @@ struct outputQueue *oq; #define multStr(c) (c==' '?" ":(c=='\0'?"":"*")) char *POLYToString(f,multSym,brace) -POLY f; -int multSym; -int brace; + POLY f; + int multSym; + int brace; { extern int Wrap; + extern int UseDsmall; + extern int COutput; int i,j,jj,fi; int printed = 0; int vi; /* index for variables */ @@ -83,7 +89,9 @@ int brace; printed = 1; xnames = dnames = (char **)NULL; }else{ - ringp = f->m->ringp; xnames = f->m->ringp->x; dnames = f->m->ringp->D; + ringp = f->m->ringp; xnames = f->m->ringp->x; + if (UseDsmall) dnames = f->m->ringp->Dsmall; + else dnames = f->m->ringp->D; n = ringp->n; xout = ringp->outputOrder; } @@ -92,30 +100,30 @@ int brace; /*print coefficient*/ if (fi == 0) { if (isConstant(f)) { - putstr(coeffToString(f->coeffp),&oq); + putstr(coeffToString(f->coeffp),&oq); }else if (isOne(f->coeffp)) { - /* do nothing */ + /* do nothing */ }else if (isMinusOne(f->coeffp)) { - putstr("-",&oq); + putstr("-",&oq); }else{ - putstr(coeffToString(f->coeffp),&oq); - putstr(multStr(multSym),&oq); + putstr(coeffToString(f->coeffp),&oq); + putstr(multStr(multSym),&oq); } }else{ if (isConstant(f)) { - if (isNegative(f->coeffp)) { - putstr(coeffToString(f->coeffp),&oq); - }else{ - putstr("+",&oq); - putstr(coeffToString(f->coeffp),&oq); - } + if (isNegative(f->coeffp)) { + putstr(coeffToString(f->coeffp),&oq); + }else{ + putstr("+",&oq); + putstr(coeffToString(f->coeffp),&oq); + } } else if (isOne(f->coeffp)) { - putstr("+",&oq); + putstr("+",&oq); }else if (isMinusOne(f->coeffp)) { - putstr("-",&oq); + putstr("-",&oq); }else{ - if (!isNegative(f->coeffp)) putstr("+",&oq); - putstr(coeffToString(f->coeffp),&oq); + if (!isNegative(f->coeffp)) putstr("+",&oq); + putstr(coeffToString(f->coeffp),&oq); putstr(multStr(multSym),&oq); } } @@ -124,34 +132,67 @@ int brace; for (jj=0; jjm->e[j].x) { - vi++; - if (vi != 1) putstr(multStr(multSym),&oq); - putstr(xnames[j],&oq); - if (f->m->e[j].x >= 2) { - putstr("^",&oq); - putstr(intToString(f->m->e[j].x),&oq); - }else if (f->m->e[j].x < 0) { - putstr("^(",&oq); - putstr(intToString(f->m->e[j].x),&oq); - putstr(")",&oq); - } - } + if (COutput) { + if (f->m->e[j].x) { + vi++; + if (vi != 1) putstr(multStr(multSym),&oq); + if (f->m->e[j].x == 1) { + putstr(xnames[j],&oq); + } else { + putstr("sm1power(",&oq); + putstr(xnames[j],&oq); + putstr(",",&oq); + putstr(intToString(f->m->e[j].x),&oq); + putstr(")",&oq); + } + } + }else{ + if (f->m->e[j].x) { + vi++; + if (vi != 1) putstr(multStr(multSym),&oq); + putstr(xnames[j],&oq); + if (f->m->e[j].x >= 2) { + putstr("^",&oq); + putstr(intToString(f->m->e[j].x),&oq); + }else if (f->m->e[j].x < 0) { + putstr("^(",&oq); + putstr(intToString(f->m->e[j].x),&oq); + putstr(")",&oq); + } + } + } }else { - j = j-n; - if (f->m->e[j].D) { - vi++; - if (vi != 1) putstr(multStr(multSym),&oq); - putstr(dnames[j],&oq); - if (f->m->e[j].D >= 2) { - putstr("^",&oq); - putstr(intToString(f->m->e[j].D),&oq); - }else if (f->m->e[j].D < 0) { - putstr("^(",&oq); - putstr(intToString(f->m->e[j].D),&oq); - putstr(")",&oq); - } - } + if (COutput) { + j = j-n; + if (f->m->e[j].D) { + vi++; + if (vi != 1) putstr(multStr(multSym),&oq); + if (f->m->e[j].D == 1) { + putstr(dnames[j],&oq); + }else { + if (f->m->e[j].D) putstr("sm1power(",&oq); + putstr(dnames[j],&oq); + putstr(",",&oq); + putstr(intToString(f->m->e[j].D),&oq); + putstr(")",&oq); + } + } + }else{ + j = j-n; + if (f->m->e[j].D) { + vi++; + if (vi != 1) putstr(multStr(multSym),&oq); + putstr(dnames[j],&oq); + if (f->m->e[j].D >= 2) { + putstr("^",&oq); + putstr(intToString(f->m->e[j].D),&oq); + }else if (f->m->e[j].D < 0) { + putstr("^(",&oq); + putstr(intToString(f->m->e[j].D),&oq); + putstr(")",&oq); + } + } + } } } fi++; @@ -182,14 +223,14 @@ int brace; } char *KPOLYToString(f) -POLY f; + POLY f; { extern int OutputStyle; return(POLYToString(f,OutputStyle,0)); } isOne(c) -struct coeff *c; + struct coeff *c; { switch(c->tag) { case INTEGER: @@ -207,7 +248,7 @@ struct coeff *c; } } isMinusOne(c) -struct coeff *c; + struct coeff *c; { switch(c->tag) { case INTEGER: @@ -225,7 +266,7 @@ struct coeff *c; } isNegative(c) -struct coeff *c; + struct coeff *c; { switch(c->tag) { case INTEGER: @@ -244,7 +285,7 @@ struct coeff *c; } isConstant(f) -POLY f; + POLY f; { int i; int n; @@ -256,9 +297,34 @@ POLY f; return(1); } +int isConstantAll(POLY f) +{ + int i; + int n; + if (f == POLYNULL) return(1); + while (f != POLYNULL) { + if (!isConstant(f)) return 0; + f = f->next; + } + return 1; +} + void errorOutput(s) -char *s; + char *s; { fprintf(stderr,"Error(output.c):%s\n",s); exit(15); +} + +char **makeDsmall(char **dvars,int n) { + char **ans; + int i; + ans = (char **) sGC_malloc(sizeof(char *)*(n+1)); + for (i=0; i