2 * substitutes the parameter par (from 1..N) by image, * does not destroy p and image */
| 263 | * does not destroy p and image |
| 264 | */ |
| 265 | poly pSubstPar(poly p, int par, poly image) |
| 266 | { |
| 267 | const ring R = currRing->cf->extRing; |
| 268 | ideal theMapI = idInit(rPar(currRing),1); |
| 269 | nMapFunc nMap = n_SetMap(R->cf, currRing->cf); |
| 270 | int i; |
| 271 | for(i = rPar(currRing);i>0;i--) |
| 272 | { |
| 273 | if (i != par) |
| 274 | theMapI->m[i-1]= p_NSet(n_Param(i, currRing), currRing); |
| 275 | else |
| 276 | theMapI->m[i-1] = p_Copy(image, currRing); |
| 277 | p_Test(theMapI->m[i-1],currRing); |
| 278 | } |
| 279 | //iiWriteMatrix((matrix)theMapI,"map:",1,currRing,0); |
| 280 | |
| 281 | map theMap=(map)theMapI; |
| 282 | theMap->preimage=NULL; |
| 283 | |
| 284 | leftv v=(leftv)omAllocBin(sleftv_bin); |
| 285 | sleftv tmpW; |
| 286 | poly res=NULL; |
| 287 | |
| 288 | p_Normalize(p,currRing); |
| 289 | if (currRing->cf->rep==n_rep_rat_fct ) |
| 290 | { |
| 291 | while (p!=NULL) |
| 292 | { |
| 293 | memset(v,0,sizeof(sleftv)); |
| 294 | |
| 295 | number d = n_GetDenom(pGetCoeff(p), currRing->cf); |
| 296 | p_Test((poly)NUM((fraction)d), R); |
| 297 | |
| 298 | if ( n_IsOne (d, currRing->cf) ) |
| 299 | { |
| 300 | n_Delete(&d, currRing->cf); d = NULL; |
| 301 | } |
| 302 | else if (!p_IsConstant((poly)NUM((fraction)d), R)) |
| 303 | { |
| 304 | WarnS("ignoring denominators of coefficients..."); |
| 305 | n_Delete(&d, currRing->cf); d = NULL; |
| 306 | } |
| 307 | |
| 308 | number num = n_GetNumerator(pGetCoeff(p), currRing->cf); |
| 309 | memset(&tmpW,0,sizeof(sleftv)); |
| 310 | tmpW.rtyp = POLY_CMD; |
| 311 | p_Test((poly)NUM((fraction)num), R); |
| 312 | |
| 313 | tmpW.data = NUM ((fraction)num); // a copy of this poly will be used |
| 314 | |
| 315 | p_Normalize(NUM((fraction)num),R); |
| 316 | if (maApplyFetch(MAP_CMD,theMap,v,&tmpW,R,NULL,NULL,0,nMap)) |
| 317 | { |
| 318 | WerrorS("map failed"); |
| 319 | v->data=NULL; |
| 320 | } |
| 321 | n_Delete(&num, currRing->cf); |
| 322 | //TODO check for memory leaks |
no test coverage detected