[2f5b71] | 1 | /**************************************** |
---|
| 2 | * Computer Algebra System SINGULAR * |
---|
| 3 | ****************************************/ |
---|
| 4 | /* |
---|
| 5 | * ABSTRACT - the mapping of polynomials to other rings |
---|
| 6 | */ |
---|
[696bde] | 7 | #define TRANSEXT_PRIVATES |
---|
[2f5b71] | 8 | |
---|
[a4b31c] | 9 | #include "kernel/mod2.h" |
---|
[9f7665] | 10 | |
---|
[a4b31c] | 11 | #include "coeffs/numbers.h" |
---|
| 12 | #include "coeffs/coeffs.h" |
---|
[9f7665] | 13 | |
---|
[a4b31c] | 14 | #include "polys/monomials/ring.h" |
---|
| 15 | #include "polys/monomials/maps.h" |
---|
| 16 | #include "polys/matpol.h" |
---|
| 17 | #include "polys/prCopy.h" |
---|
| 18 | #include "polys/ext_fields/transext.h" |
---|
[9f7665] | 19 | |
---|
[a4b31c] | 20 | //#include "polys/ext_fields/longtrans.h" |
---|
| 21 | // #include "kernel/longalg.h" |
---|
[cf4154] | 22 | |
---|
[a4b31c] | 23 | #include "misc/options.h" |
---|
| 24 | #include "kernel/GBEngine/kstd1.h" |
---|
| 25 | #include "kernel/maps/gen_maps.h" |
---|
[cf4154] | 26 | |
---|
[5c71ae1] | 27 | #include "maps_ip.h" |
---|
| 28 | #include "ipid.h" |
---|
| 29 | |
---|
| 30 | |
---|
[cf4154] | 31 | #include "lists.h" |
---|
| 32 | #include "tok.h" |
---|
| 33 | |
---|
[5c71ae1] | 34 | /* debug output: Tok2Cmdname in maApplyFetch*/ |
---|
[83a1714] | 35 | #include "ipshell.h" |
---|
[5c71ae1] | 36 | |
---|
[2f5b71] | 37 | /*2 |
---|
| 38 | * maps the expression w to res, |
---|
| 39 | * switch what: MAP_CMD: use theMap for mapping, N for preimage ring |
---|
| 40 | * //FETCH_CMD: use pOrdPoly for mapping |
---|
| 41 | * IMAP_CMD: use perm for mapping, N for preimage ring |
---|
| 42 | * default: map only poly-structures, |
---|
| 43 | * use perm and par_perm, N and P, |
---|
| 44 | */ |
---|
| 45 | BOOLEAN maApplyFetch(int what,map theMap,leftv res, leftv w, ring preimage_r, |
---|
| 46 | int *perm, int *par_perm, int P, nMapFunc nMap) |
---|
| 47 | { |
---|
[a934fb3] | 48 | BOOLEAN use_mult=FALSE; |
---|
| 49 | #ifdef HAVE_PLURAL |
---|
| 50 | if ((what==IMAP_CMD) |
---|
| 51 | && rIsPluralRing(currRing) |
---|
| 52 | && rIsPluralRing(preimage_r)) |
---|
| 53 | { |
---|
| 54 | assume(perm!=NULL); |
---|
| 55 | int i=1; |
---|
[ad2a016] | 56 | while((i<preimage_r->N)&&(perm[i]==0)) i++; |
---|
| 57 | if (i<preimage_r->N) |
---|
[a934fb3] | 58 | { |
---|
| 59 | int prev_nonnull=i; |
---|
| 60 | i++; |
---|
[ad2a016] | 61 | for(;i<=preimage_r->N;i++) |
---|
[a934fb3] | 62 | { |
---|
| 63 | if (perm[prev_nonnull] > perm[i]) |
---|
| 64 | { |
---|
[e552b7] | 65 | if (TEST_V_ALLWARN) |
---|
| 66 | { |
---|
[ad2a016] | 67 | Warn("imap not usable for permuting variables, use map (%s <-> %s)", preimage_r->names[prev_nonnull-1],preimage_r->names[i-1]); |
---|
[e552b7] | 68 | } |
---|
[a934fb3] | 69 | use_mult=TRUE; |
---|
[e552b7] | 70 | break; |
---|
[a934fb3] | 71 | } |
---|
| 72 | else |
---|
| 73 | prev_nonnull=i; |
---|
| 74 | } |
---|
| 75 | } |
---|
| 76 | } |
---|
| 77 | #endif |
---|
[2f5b71] | 78 | int i; |
---|
| 79 | int N = preimage_r->N; |
---|
[83a1714] | 80 | #if 0 |
---|
| 81 | Print("N=%d what=%s ",N,Tok2Cmdname(what)); |
---|
| 82 | if (perm!=NULL) for(i=1;i<=N;i++) Print("%d -> %d ",i,perm[i]); |
---|
| 83 | PrintS("\n"); |
---|
| 84 | Print("P=%d ",P); |
---|
| 85 | if (par_perm!=NULL) for(i=0;i<P;i++) Print("%d -> %d ",i,par_perm[i]); |
---|
| 86 | PrintS("\n"); |
---|
| 87 | #endif |
---|
| 88 | |
---|
[2f5b71] | 89 | void *data=w->Data(); |
---|
| 90 | res->rtyp = w->rtyp; |
---|
| 91 | switch (w->rtyp) |
---|
| 92 | { |
---|
| 93 | case NUMBER_CMD: |
---|
| 94 | if (P!=0) |
---|
| 95 | { |
---|
[83a1714] | 96 | // poly n_PermNumber(const number z, const int *par_perm, const int OldPar, const ring src, const ring dst); |
---|
| 97 | res->data= (void *) n_PermNumber((number)data, par_perm, P, preimage_r, currRing); |
---|
[2f5b71] | 98 | res->rtyp=POLY_CMD; |
---|
[616e34] | 99 | if (nCoeff_is_algExt(currRing->cf)) |
---|
[3b1d9a] | 100 | res->data=(void *)p_MinPolyNormalize((poly)res->data, currRing); |
---|
[9d68fd] | 101 | pTest((poly) res->data); |
---|
[2f5b71] | 102 | } |
---|
| 103 | else |
---|
| 104 | { |
---|
[9d68fd] | 105 | assume( nMap != NULL ); |
---|
| 106 | number a = nMap((number)data, preimage_r->cf, currRing->cf); |
---|
[4470e25] | 107 | if (nCoeff_is_Extension(currRing->cf)) |
---|
[2f5b71] | 108 | { |
---|
[616e34] | 109 | n_Normalize(a, currRing->cf); |
---|
[83a1714] | 110 | /* |
---|
| 111 | number a = (number)res->data; |
---|
[9d68fd] | 112 | number one = nInit(1); |
---|
[83a1714] | 113 | number product = nMult(a, one ); |
---|
[9d68fd] | 114 | nDelete(&one); |
---|
| 115 | nDelete(&a); |
---|
[ca0d043] | 116 | res->data=(void *)product; |
---|
[83a1714] | 117 | */ |
---|
[2f5b71] | 118 | } |
---|
| 119 | #ifdef LDEBUG |
---|
[83a1714] | 120 | n_Test(a, currRing->cf); |
---|
[2f5b71] | 121 | #endif |
---|
[83a1714] | 122 | res->data=(void *)a; |
---|
| 123 | |
---|
[2f5b71] | 124 | } |
---|
| 125 | break; |
---|
[9ae5a3] | 126 | case BUCKET_CMD: |
---|
[c3b7d1e] | 127 | if ( |
---|
| 128 | (what==FETCH_CMD) && (preimage_r->cf==currRing->cf) |
---|
| 129 | #ifdef HAVE_SHIFTBBA |
---|
| 130 | && !rIsLPRing(currRing) |
---|
| 131 | #endif |
---|
| 132 | ) |
---|
[9ae5a3] | 133 | res->data=(void *)prCopyR(sBucketPeek((sBucket_pt)data), preimage_r, currRing); |
---|
| 134 | else |
---|
| 135 | if ( (what==IMAP_CMD) || /*(*/ (what==FETCH_CMD) /*)*/) /* && (nMap!=nCopy)*/ |
---|
| 136 | res->data=(void *)p_PermPoly(sBucketPeek((sBucket_pt)data),perm,preimage_r,currRing, nMap,par_perm,P,use_mult); |
---|
| 137 | else /*if (what==MAP_CMD)*/ |
---|
| 138 | { |
---|
[e552b7] | 139 | res->data=(void*)maMapPoly(sBucketPeek((sBucket_pt)data),preimage_r,(ideal)theMap,currRing,nMap); |
---|
[9ae5a3] | 140 | } |
---|
| 141 | if (nCoeff_is_Extension(currRing->cf)) |
---|
| 142 | res->data=(void *)p_MinPolyNormalize(sBucketPeek((sBucket_pt)data), currRing); |
---|
| 143 | break; |
---|
[2f5b71] | 144 | case POLY_CMD: |
---|
| 145 | case VECTOR_CMD: |
---|
[c3b7d1e] | 146 | if ( |
---|
| 147 | (what==FETCH_CMD) && (preimage_r->cf==currRing->cf) |
---|
| 148 | #ifdef HAVE_SHIFTBBA |
---|
| 149 | && !rIsLPRing(currRing) |
---|
| 150 | #endif |
---|
| 151 | ) |
---|
[3b1d9a] | 152 | res->data=(void *)prCopyR( (poly)data, preimage_r, currRing); |
---|
[2f5b71] | 153 | else |
---|
[638c230] | 154 | if ( (what==IMAP_CMD) || /*(*/ (what==FETCH_CMD) /*)*/) /* && (nMap!=nCopy)*/ |
---|
[a934fb3] | 155 | res->data=(void *)p_PermPoly((poly)data,perm,preimage_r,currRing, nMap,par_perm,P,use_mult); |
---|
[2f5b71] | 156 | else /*if (what==MAP_CMD)*/ |
---|
| 157 | { |
---|
[9d68fd] | 158 | p_Test((poly)data,preimage_r); |
---|
[e552b7] | 159 | res->data=(void*)maMapPoly((poly)data,preimage_r,(ideal)theMap,currRing,nMap); |
---|
[2f5b71] | 160 | } |
---|
[3b1d9a] | 161 | if (nCoeff_is_Extension(currRing->cf)) |
---|
| 162 | res->data=(void *)p_MinPolyNormalize((poly)res->data, currRing); |
---|
[2f5b71] | 163 | pTest((poly)res->data); |
---|
| 164 | break; |
---|
| 165 | case MODUL_CMD: |
---|
| 166 | case MATRIX_CMD: |
---|
| 167 | case IDEAL_CMD: |
---|
| 168 | case MAP_CMD: |
---|
| 169 | { |
---|
| 170 | int C=((matrix)data)->cols(); |
---|
| 171 | int R; |
---|
| 172 | if (w->rtyp==MAP_CMD) R=1; |
---|
| 173 | else R=((matrix)data)->rows(); |
---|
| 174 | matrix m=mpNew(R,C); |
---|
| 175 | char *tmpR=NULL; |
---|
| 176 | if(w->rtyp==MAP_CMD) |
---|
| 177 | { |
---|
| 178 | tmpR=((map)data)->preimage; |
---|
| 179 | ((matrix)data)->rank=((matrix)data)->rows(); |
---|
| 180 | } |
---|
[c3b7d1e] | 181 | if ( |
---|
| 182 | (what==FETCH_CMD) && (preimage_r->cf == currRing->cf) |
---|
| 183 | #ifdef HAVE_SHIFTBBA |
---|
| 184 | && !rIsLPRing(currRing) |
---|
| 185 | #endif |
---|
| 186 | ) |
---|
[2f5b71] | 187 | { |
---|
| 188 | for (i=R*C-1;i>=0;i--) |
---|
| 189 | { |
---|
[3b1d9a] | 190 | m->m[i]=prCopyR(((ideal)data)->m[i], preimage_r, currRing); |
---|
[2f5b71] | 191 | pTest(m->m[i]); |
---|
| 192 | } |
---|
| 193 | } |
---|
[f34cd44] | 194 | else if ((what==IMAP_CMD) || (what==FETCH_CMD)) |
---|
[2f5b71] | 195 | { |
---|
| 196 | for (i=R*C-1;i>=0;i--) |
---|
| 197 | { |
---|
[3b1d9a] | 198 | m->m[i]=p_PermPoly(((ideal)data)->m[i],perm,preimage_r,currRing, |
---|
[a934fb3] | 199 | nMap,par_perm,P,use_mult); |
---|
[2f5b71] | 200 | pTest(m->m[i]); |
---|
| 201 | } |
---|
| 202 | } |
---|
[f34cd44] | 203 | else /* (what==MAP_CMD) */ |
---|
[2f5b71] | 204 | { |
---|
[f34cd44] | 205 | assume(what==MAP_CMD); |
---|
[2f5b71] | 206 | matrix s=mpNew(N,maMaxDeg_Ma((ideal)data,preimage_r)); |
---|
| 207 | for (i=R*C-1;i>=0;i--) |
---|
| 208 | { |
---|
[5c71ae1] | 209 | m->m[i]=maEval(theMap, ((ideal)data)->m[i], preimage_r, nMap, (ideal)s, currRing); |
---|
[2f5b71] | 210 | pTest(m->m[i]); |
---|
| 211 | } |
---|
| 212 | idDelete((ideal *)&s); |
---|
| 213 | } |
---|
| 214 | if(w->rtyp==MAP_CMD) |
---|
| 215 | { |
---|
| 216 | ((map)data)->preimage=tmpR; |
---|
| 217 | ((map)m)->preimage=omStrDup(tmpR); |
---|
| 218 | } |
---|
| 219 | else |
---|
| 220 | { |
---|
| 221 | m->rank=((matrix)data)->rank; |
---|
| 222 | } |
---|
| 223 | res->data=(char *)m; |
---|
| 224 | idTest((ideal) m); |
---|
| 225 | break; |
---|
| 226 | } |
---|
| 227 | |
---|
| 228 | case LIST_CMD: |
---|
| 229 | { |
---|
| 230 | lists l=(lists)data; |
---|
| 231 | lists ml=(lists)omAllocBin(slists_bin); |
---|
| 232 | ml->Init(l->nr+1); |
---|
| 233 | for(i=0;i<=l->nr;i++) |
---|
| 234 | { |
---|
| 235 | if (((l->m[i].rtyp>BEGIN_RING)&&(l->m[i].rtyp<END_RING)) |
---|
| 236 | ||(l->m[i].rtyp==LIST_CMD)) |
---|
| 237 | { |
---|
| 238 | if (maApplyFetch(what,theMap,&ml->m[i],&l->m[i], |
---|
| 239 | preimage_r,perm,par_perm,P,nMap)) |
---|
| 240 | { |
---|
| 241 | ml->Clean(); |
---|
| 242 | omFreeBin((ADDRESS)ml, slists_bin); |
---|
| 243 | res->rtyp=0; |
---|
| 244 | return TRUE; |
---|
| 245 | } |
---|
| 246 | } |
---|
| 247 | else |
---|
| 248 | { |
---|
| 249 | ml->m[i].Copy(&l->m[i]); |
---|
| 250 | } |
---|
| 251 | } |
---|
| 252 | res->data=(char *)ml; |
---|
| 253 | break; |
---|
| 254 | } |
---|
| 255 | default: |
---|
| 256 | { |
---|
| 257 | return TRUE; |
---|
| 258 | } |
---|
| 259 | } |
---|
| 260 | return FALSE; |
---|
| 261 | } |
---|
| 262 | |
---|
| 263 | /*2 |
---|
| 264 | * substitutes the parameter par (from 1..N) by image, |
---|
| 265 | * does not destroy p and image |
---|
| 266 | */ |
---|
| 267 | poly pSubstPar(poly p, int par, poly image) |
---|
| 268 | { |
---|
[f769fd0] | 269 | const ring R = currRing->cf->extRing; |
---|
[95eb6d] | 270 | ideal theMapI = idInit(rPar(currRing),1); |
---|
[f769fd0] | 271 | nMapFunc nMap = n_SetMap(R->cf, currRing->cf); |
---|
[2f5b71] | 272 | int i; |
---|
[95eb6d] | 273 | for(i = rPar(currRing);i>0;i--) |
---|
[2f5b71] | 274 | { |
---|
[e92b07] | 275 | if (i != par) |
---|
| 276 | theMapI->m[i-1]= p_NSet(n_Param(i, currRing), currRing); |
---|
[2f5b71] | 277 | else |
---|
[e92b07] | 278 | theMapI->m[i-1] = p_Copy(image, currRing); |
---|
[9d68fd] | 279 | p_Test(theMapI->m[i-1],currRing); |
---|
[2f5b71] | 280 | } |
---|
[9d68fd] | 281 | //iiWriteMatrix((matrix)theMapI,"map:",1,currRing,0); |
---|
[2f5b71] | 282 | |
---|
| 283 | map theMap=(map)theMapI; |
---|
| 284 | theMap->preimage=NULL; |
---|
| 285 | |
---|
| 286 | leftv v=(leftv)omAllocBin(sleftv_bin); |
---|
| 287 | sleftv tmpW; |
---|
| 288 | poly res=NULL; |
---|
[e92b07] | 289 | |
---|
[9d68fd] | 290 | p_Normalize(p,currRing); |
---|
[638c230] | 291 | if (currRing->cf->rep==n_rep_rat_fct ) |
---|
[2f5b71] | 292 | { |
---|
[638c230] | 293 | while (p!=NULL) |
---|
[9d68fd] | 294 | { |
---|
[638c230] | 295 | memset(v,0,sizeof(sleftv)); |
---|
[696bde] | 296 | |
---|
[06abb07] | 297 | number d = n_GetDenom(pGetCoeff(p), currRing->cf); |
---|
[6105f4f] | 298 | p_Test((poly)NUM((fraction)d), R); |
---|
[638c230] | 299 | |
---|
| 300 | if ( n_IsOne (d, currRing->cf) ) |
---|
[e243f1d] | 301 | { |
---|
[06abb07] | 302 | n_Delete(&d, currRing->cf); d = NULL; |
---|
[e243f1d] | 303 | } |
---|
[616e34] | 304 | else if (!p_IsConstant((poly)NUM((fraction)d), R)) |
---|
[638c230] | 305 | { |
---|
| 306 | WarnS("ignoring denominators of coefficients..."); |
---|
[06abb07] | 307 | n_Delete(&d, currRing->cf); d = NULL; |
---|
[638c230] | 308 | } |
---|
| 309 | |
---|
[06abb07] | 310 | number num = n_GetNumerator(pGetCoeff(p), currRing->cf); |
---|
[638c230] | 311 | memset(&tmpW,0,sizeof(sleftv)); |
---|
| 312 | tmpW.rtyp = POLY_CMD; |
---|
[6105f4f] | 313 | p_Test((poly)NUM((fraction)num), R); |
---|
[e243f1d] | 314 | |
---|
[6105f4f] | 315 | tmpW.data = NUM ((fraction)num); // a copy of this poly will be used |
---|
[696bde] | 316 | |
---|
[6105f4f] | 317 | p_Normalize(NUM((fraction)num),R); |
---|
[e243f1d] | 318 | if (maApplyFetch(MAP_CMD,theMap,v,&tmpW,R,NULL,NULL,0,nMap)) |
---|
| 319 | { |
---|
| 320 | WerrorS("map failed"); |
---|
| 321 | v->data=NULL; |
---|
| 322 | } |
---|
[06abb07] | 323 | n_Delete(&num, currRing->cf); |
---|
[638c230] | 324 | //TODO check for memory leaks |
---|
| 325 | poly pp = pHead(p); |
---|
| 326 | //PrintS("map:");pWrite(pp); |
---|
| 327 | if( d != NULL ) |
---|
| 328 | { |
---|
| 329 | pSetCoeff(pp, n_Invers(d, currRing->cf)); |
---|
[06abb07] | 330 | n_Delete(&d, currRing->cf); // d = NULL; |
---|
[638c230] | 331 | } |
---|
| 332 | else |
---|
| 333 | pSetCoeff(pp, nInit(1)); |
---|
| 334 | |
---|
| 335 | //PrintS("->");pWrite((poly)(v->data)); |
---|
| 336 | poly ppp = pMult((poly)(v->data),pp); |
---|
| 337 | //PrintS("->");pWrite(ppp); |
---|
| 338 | res=pAdd(res,ppp); |
---|
| 339 | pIter(p); |
---|
[e243f1d] | 340 | } |
---|
[638c230] | 341 | } |
---|
| 342 | else if (currRing->cf->rep==n_rep_poly ) |
---|
| 343 | { |
---|
| 344 | while (p!=NULL) |
---|
[f769fd0] | 345 | { |
---|
[638c230] | 346 | memset(v,0,sizeof(sleftv)); |
---|
| 347 | |
---|
[06abb07] | 348 | number num = n_GetNumerator(pGetCoeff(p), currRing->cf); |
---|
[638c230] | 349 | memset(&tmpW,0,sizeof(sleftv)); |
---|
| 350 | tmpW.rtyp = POLY_CMD; |
---|
[eb55f8a] | 351 | p_Test((poly)num, R); |
---|
[f769fd0] | 352 | |
---|
[638c230] | 353 | |
---|
| 354 | p_Normalize((poly)num,R); |
---|
| 355 | if (num==NULL) num=(number)R->qideal->m[0]; |
---|
| 356 | tmpW.data = num; // a copy of this poly will be used |
---|
| 357 | if (maApplyFetch(MAP_CMD,theMap,v,&tmpW,R,NULL,NULL,0,nMap)) |
---|
| 358 | { |
---|
| 359 | WerrorS("map failed"); |
---|
| 360 | v->data=NULL; |
---|
| 361 | } |
---|
[06abb07] | 362 | if (num!=(number)R->qideal->m[0]) n_Delete(&num, currRing->cf); |
---|
[638c230] | 363 | //TODO check for memory leaks |
---|
| 364 | poly pp = pHead(p); |
---|
| 365 | //PrintS("map:");pWrite(pp); |
---|
[06abb07] | 366 | pSetCoeff(pp,n_Init(1,currRing->cf)); |
---|
[638c230] | 367 | //PrintS("cf->");pWrite((poly)(v->data)); |
---|
| 368 | poly ppp = pMult((poly)(v->data),pp); |
---|
| 369 | //PrintS("->");pWrite(ppp); |
---|
| 370 | res=pAdd(res,ppp); |
---|
| 371 | pIter(p); |
---|
| 372 | } |
---|
| 373 | } |
---|
| 374 | else |
---|
| 375 | { |
---|
| 376 | WerrorS("cannot apply subst for these coeffcients"); |
---|
[2f5b71] | 377 | } |
---|
| 378 | idDelete((ideal *)(&theMap)); |
---|
| 379 | omFreeBin((ADDRESS)v, sleftv_bin); |
---|
| 380 | return res; |
---|
| 381 | } |
---|
| 382 | |
---|
| 383 | /*2 |
---|
[5bdabc] | 384 | * substitute the n-th parameter by the poly e in id |
---|
[2f5b71] | 385 | * does not destroy id and e |
---|
| 386 | */ |
---|
| 387 | ideal idSubstPar(ideal id, int n, poly e) |
---|
| 388 | { |
---|
| 389 | int k=MATROWS((matrix)id)*MATCOLS((matrix)id); |
---|
| 390 | ideal res=(ideal)mpNew(MATROWS((matrix)id),MATCOLS((matrix)id)); |
---|
| 391 | |
---|
| 392 | res->rank = id->rank; |
---|
| 393 | for(k--;k>=0;k--) |
---|
| 394 | { |
---|
| 395 | res->m[k]=pSubstPar(id->m[k],n,e); |
---|
| 396 | } |
---|
| 397 | return res; |
---|
| 398 | } |
---|
| 399 | |
---|
| 400 | /*2 |
---|
| 401 | * substitutes the variable var (from 1..N) by image, |
---|
| 402 | * does not destroy p and image |
---|
| 403 | */ |
---|
| 404 | poly pSubstPoly(poly p, int var, poly image) |
---|
| 405 | { |
---|
[509ea41] | 406 | if (p==NULL) return NULL; |
---|
[5bdabc] | 407 | #ifdef HAVE_PLURAL |
---|
[e1f17c] | 408 | if (rIsPluralRing(currRing)) |
---|
| 409 | { |
---|
| 410 | return pSubst(pCopy(p),var,image); |
---|
| 411 | } |
---|
[95585d3] | 412 | #endif |
---|
| 413 | #ifdef HAVE_SHIFTBBA |
---|
| 414 | if (rIsLPRing(currRing)) |
---|
| 415 | { |
---|
| 416 | return pSubst(pCopy(p),var,image); |
---|
| 417 | } |
---|
[5bdabc] | 418 | #endif |
---|
[832330] | 419 | return p_SubstPoly(p,var,image,currRing,currRing,ndCopyMap); |
---|
[2f5b71] | 420 | } |
---|
| 421 | |
---|
| 422 | /*2 |
---|
| 423 | * substitute the n-th variable by the poly e in id |
---|
| 424 | * does not destroy id and e |
---|
| 425 | */ |
---|
| 426 | ideal idSubstPoly(ideal id, int n, poly e) |
---|
| 427 | { |
---|
| 428 | |
---|
[e4611fa] | 429 | #ifdef HAVE_PLURAL |
---|
| 430 | if (rIsPluralRing(currRing)) |
---|
[2f5b71] | 431 | { |
---|
[e4611fa] | 432 | int k=MATROWS((matrix)id)*MATCOLS((matrix)id); |
---|
| 433 | ideal res=(ideal)mpNew(MATROWS((matrix)id),MATCOLS((matrix)id)); |
---|
| 434 | res->rank = id->rank; |
---|
| 435 | for(k--;k>=0;k--) |
---|
| 436 | { |
---|
| 437 | res->m[k]=pSubst(pCopy(id->m[k]),n,e); |
---|
| 438 | } |
---|
| 439 | return res; |
---|
[2f5b71] | 440 | } |
---|
[95585d3] | 441 | #endif |
---|
| 442 | #ifdef HAVE_SHIFTBBA |
---|
| 443 | if (rIsLPRing(currRing)) |
---|
| 444 | { |
---|
| 445 | int k=MATROWS((matrix)id)*MATCOLS((matrix)id); |
---|
| 446 | ideal res=(ideal)mpNew(MATROWS((matrix)id),MATCOLS((matrix)id)); |
---|
| 447 | res->rank = id->rank; |
---|
| 448 | for(k--;k>=0;k--) |
---|
| 449 | { |
---|
| 450 | res->m[k]=pSubst(pCopy(id->m[k]),n,e); |
---|
| 451 | } |
---|
| 452 | return res; |
---|
| 453 | } |
---|
[e4611fa] | 454 | #endif |
---|
[832330] | 455 | return id_SubstPoly(id,n,e,currRing,currRing,ndCopyMap); |
---|
[2f5b71] | 456 | } |
---|