version 1.2, 2000/01/16 07:55:41 |
version 1.3, 2001/05/04 01:06:25 |
|
|
/* $OpenXM$ */ |
/* $OpenXM: OpenXM/src/kan96xx/Kan/replace.c,v 1.2 2000/01/16 07:55:41 takayama Exp $ */ |
#include <stdio.h> |
#include <stdio.h> |
#include "datatype.h" |
#include "datatype.h" |
#include "extern2.h" |
#include "extern2.h" |
|
|
static int badLRule(POLY set[],int num); |
static int badLRule(POLY set[],int num); |
|
|
POLY mReplace(mm,lSideX,rSideX,sizex,lSideD,rSideD,sized,commutative) |
POLY mReplace(mm,lSideX,rSideX,sizex,lSideD,rSideD,sized,commutative) |
POLY mm; |
POLY mm; |
int lSideX[]; |
int lSideX[]; |
POLY rSideX[]; /* Rule: a=lSideX[i], x_a ---> rSideX[i] */ |
POLY rSideX[]; /* Rule: a=lSideX[i], x_a ---> rSideX[i] */ |
int sizex; |
int sizex; |
int lSideD[]; /* Rule: b=lSideD[i], D_b ---> rSideD[i] */ |
int lSideD[]; /* Rule: b=lSideD[i], D_b ---> rSideD[i] */ |
POLY rSideD[]; |
POLY rSideD[]; |
int sized; |
int sized; |
int commutative; |
int commutative; |
{ |
{ |
/* The function should be tuned by using a table. */ |
/* The function should be tuned by using a table. */ |
POLY rp; |
POLY rp; |
POLY fac; |
POLY fac; |
int i; |
int i; |
|
|
if (mp->e[i].D != 0) { |
if (mp->e[i].D != 0) { |
flag = 1; |
flag = 1; |
for (j=0; j<sized; j++) { |
for (j=0; j<sized; j++) { |
if (lSideD[j] == i) { |
if (lSideD[j] == i) { |
if (commutative) fac = pPower_poly(rSideD[j],mp->e[i].D); |
if (commutative) fac = pPower_poly(rSideD[j],mp->e[i].D); |
else fac = pPower(rSideD[j],mp->e[i].D); |
else fac = pPower(rSideD[j],mp->e[i].D); |
/* if negative, this does not work well!! */ |
/* if negative, this does not work well!! */ |
flag = 0; |
flag = 0; |
break; |
break; |
} |
} |
} |
} |
if (flag) fac = cdd(1,i,mp->e[i].D,mp->ringp); |
if (flag) fac = cdd(1,i,mp->e[i].D,mp->ringp); |
if (commutative) rp = ppMult_poly(fac,rp); |
if (commutative) rp = ppMult_poly(fac,rp); |
|
|
if (mp->e[i].x != 0) { |
if (mp->e[i].x != 0) { |
flag = 1; |
flag = 1; |
for (j=0; j<sizex; j++) { |
for (j=0; j<sizex; j++) { |
if (lSideX[j] == i) { |
if (lSideX[j] == i) { |
if (commutative) fac = pPower_poly(rSideX[j],mp->e[i].x); |
if (commutative) fac = pPower_poly(rSideX[j],mp->e[i].x); |
else fac = pPower(rSideX[j],mp->e[i].x); |
else fac = pPower(rSideX[j],mp->e[i].x); |
/* if negative, this does not work well!! */ |
/* if negative, this does not work well!! */ |
flag = 0; |
flag = 0; |
break; |
break; |
} |
} |
} |
} |
if (flag) fac = cxx(1,i,mp->e[i].x,mp->ringp); |
if (flag) fac = cxx(1,i,mp->e[i].x,mp->ringp); |
if (commutative) rp = ppMult_poly(fac,rp); |
if (commutative) rp = ppMult_poly(fac,rp); |
|
|
lRule[i] ---> rRule[i] |
lRule[i] ---> rRule[i] |
*/ |
*/ |
POLY replace(f,lRule,rRule,num) |
POLY replace(f,lRule,rRule,num) |
POLY f; |
POLY f; |
POLY lRule[]; /* lRule[i] must be x0 or ... or D{N-1} */ |
POLY lRule[]; /* lRule[i] must be x0 or ... or D{N-1} */ |
POLY rRule[]; |
POLY rRule[]; |
int num; |
int num; |
{ |
{ |
POLY rSideX[N0]; |
POLY rSideX[N0]; |
POLY rSideD[N0]; |
POLY rSideD[N0]; |
|
|
int n; |
int n; |
|
|
/***printf("f=%s\n",POLYToString(f,'*',0)); |
/***printf("f=%s\n",POLYToString(f,'*',0)); |
for (i=0; i<num; i++) { |
for (i=0; i<num; i++) { |
printf("%s --> %s\n",POLYToString(lRule[i],'*',0), |
printf("%s --> %s\n",POLYToString(lRule[i],'*',0), |
POLYToString(rRule[i],'*',0)); |
POLYToString(rRule[i],'*',0)); |
} |
} |
printf("\n"); ***/ |
printf("\n"); ***/ |
|
|
if (f ISZERO) return(ZERO); |
if (f ISZERO) return(ZERO); |
sizex = sized = 0; |
sizex = sized = 0; |
|
|
for (i=0; i<n; i++) { |
for (i=0; i<n; i++) { |
for (j=0; j<num; j++) { |
for (j=0; j<num; j++) { |
if (lRule[j]->m->e[i].x == 1) { |
if (lRule[j]->m->e[i].x == 1) { |
lSideX[sizex] = i; |
lSideX[sizex] = i; |
rSideX[sizex] = rRule[j]; |
rSideX[sizex] = rRule[j]; |
sizex++; |
sizex++; |
if (sizex >= n) { |
if (sizex >= n) { |
warningPoly(" replace(): too many x-rules . "); |
warningPoly(" replace(): too many x-rules . "); |
sizex--; |
sizex--; |
} |
} |
break; |
break; |
} |
} |
} |
} |
} |
} |
|
|
for (i=0; i<n; i++) { |
for (i=0; i<n; i++) { |
for (j=0; j<num; j++) { |
for (j=0; j<num; j++) { |
if (lRule[j]->m->e[i].D == 1) { |
if (lRule[j]->m->e[i].D == 1) { |
lSideD[sized] = i; |
lSideD[sized] = i; |
rSideD[sized] = rRule[j]; |
rSideD[sized] = rRule[j]; |
sized++; |
sized++; |
if (sized >= n) { |
if (sized >= n) { |
warningPoly(" replacen(): too many D-rules . "); |
warningPoly(" replacen(): too many D-rules . "); |
sized--; |
sized--; |
} |
} |
break; |
break; |
} |
} |
} |
} |
} |
} |
|
|
|
|
/* For the dirty trick of mpMult_difference */ |
/* For the dirty trick of mpMult_difference */ |
POLY replace_poly(f,lRule,rRule,num) |
POLY replace_poly(f,lRule,rRule,num) |
POLY f; |
POLY f; |
POLY lRule[]; /* lRule[i] must be x0 or ... or D{N-1} */ |
POLY lRule[]; /* lRule[i] must be x0 or ... or D{N-1} */ |
POLY rRule[]; |
POLY rRule[]; |
int num; |
int num; |
{ |
{ |
POLY rSideX[N0]; |
POLY rSideX[N0]; |
POLY rSideD[N0]; |
POLY rSideD[N0]; |
|
|
int n; |
int n; |
|
|
/***printf("f=%s\n",POLYToString(f,'*',0)); |
/***printf("f=%s\n",POLYToString(f,'*',0)); |
for (i=0; i<num; i++) { |
for (i=0; i<num; i++) { |
printf("%s --> %s\n",POLYToString(lRule[i],'*',0), |
printf("%s --> %s\n",POLYToString(lRule[i],'*',0), |
POLYToString(rRule[i],'*',0)); |
POLYToString(rRule[i],'*',0)); |
} |
} |
printf("\n"); ***/ |
printf("\n"); ***/ |
|
|
if (f ISZERO) return(ZERO); |
if (f ISZERO) return(ZERO); |
sizex = sized = 0; |
sizex = sized = 0; |
|
|
for (i=0; i<n; i++) { |
for (i=0; i<n; i++) { |
for (j=0; j<num; j++) { |
for (j=0; j<num; j++) { |
if (lRule[j]->m->e[i].x == 1) { |
if (lRule[j]->m->e[i].x == 1) { |
lSideX[sizex] = i; |
lSideX[sizex] = i; |
rSideX[sizex] = rRule[j]; |
rSideX[sizex] = rRule[j]; |
sizex++; |
sizex++; |
if (sizex >= n) { |
if (sizex >= n) { |
warningPoly(" replace(): too many x-rules . "); |
warningPoly(" replace(): too many x-rules . "); |
sizex--; |
sizex--; |
} |
} |
break; |
break; |
} |
} |
} |
} |
} |
} |
|
|
for (i=0; i<n; i++) { |
for (i=0; i<n; i++) { |
for (j=0; j<num; j++) { |
for (j=0; j<num; j++) { |
if (lRule[j]->m->e[i].D == 1) { |
if (lRule[j]->m->e[i].D == 1) { |
lSideD[sized] = i; |
lSideD[sized] = i; |
rSideD[sized] = rRule[j]; |
rSideD[sized] = rRule[j]; |
sized++; |
sized++; |
if (sized >= n) { |
if (sized >= n) { |
warningPoly(" replacen(): too many D-rules . "); |
warningPoly(" replacen(): too many D-rules . "); |
sized--; |
sized--; |
} |
} |
break; |
break; |
} |
} |
} |
} |
} |
} |
|
|
|
|
|
|
static int badLRule(set,num) |
static int badLRule(set,num) |
POLY set[]; |
POLY set[]; |
int num; |
int num; |
{ int i; |
{ int i; |
for (i=0; i<num; i++) { |
for (i=0; i<num; i++) { |
if (set[0] ISZERO) { |
if (set[0] ISZERO) { |
return(1); |
return(1); |
} |
} |
} |
} |
return(0); |
return(0); |
} |
} |
|
|