/**************************************** * Computer Algebra System SINGULAR * ****************************************/ /* $Id: maps_ip.cc,v 1.8 2005-04-29 16:04:36 Singular Exp $ */ /* * ABSTRACT - the mapping of polynomials to other rings */ #include "mod2.h" #include "tok.h" #include "febase.h" #include "polys.h" #include "numbers.h" #include "ring.h" #include "ideals.h" #include "matpol.h" #include "omalloc.h" #include "kstd1.h" #include "longalg.h" #include "lists.h" #include "maps.h" #include "maps_ip.h" #include "prCopy.h" // define this if you want to use the fast_map routine for mapping ideals #define FAST_MAP #ifdef FAST_MAP #include "fast_maps.h" #endif /*2 * maps the expression w to res, * switch what: MAP_CMD: use theMap for mapping, N for preimage ring * //FETCH_CMD: use pOrdPoly for mapping * IMAP_CMD: use perm for mapping, N for preimage ring * default: map only poly-structures, * use perm and par_perm, N and P, */ BOOLEAN maApplyFetch(int what,map theMap,leftv res, leftv w, ring preimage_r, int *perm, int *par_perm, int P, nMapFunc nMap) { int i; int N = preimage_r->N; //Print("N=%d what=%s ",N,Tok2Cmdname(what)); //if (perm!=NULL) for(i=1;i<=N;i++) Print("%d -> %d ",i,perm[i]); //PrintS("\n"); //Print("P=%d ",P); //if (par_perm!=NULL) for(i=0;i
%d ",i,par_perm[i]);
//PrintS("\n");
void *data=w->Data();
res->rtyp = w->rtyp;
switch (w->rtyp)
{
case NUMBER_CMD:
if (P!=0)
{
res->data=(void *)naPermNumber((number)data,par_perm,P, preimage_r);
res->rtyp=POLY_CMD;
if (currRing->minpoly!=NULL)
res->data=(void *)pMinPolyNormalize((poly)res->data);
pTest((poly) res->data);
}
else
{
res->data=(void *)nMap((number)data);
if (currRing->minpoly!=NULL)
{
number a=(number)res->data;
nNormalize(a);
res->data=(void *)a;
}
#ifdef LDEBUG
nTest((number) res->data);
#endif
}
break;
case POLY_CMD:
case VECTOR_CMD:
if ((what==FETCH_CMD)&& (nMap==nCopy))
res->data=(void *)prCopyR( (poly)data, preimage_r);
else
if ((what==IMAP_CMD) || ((what==FETCH_CMD) /* && (nMap!=nCopy)*/))
res->data=(void *)pPermPoly((poly)data,perm,preimage_r,nMap,par_perm,P);
else /*if (what==MAP_CMD)*/
{
matrix s=mpNew(N,maMaxDeg_P((poly)data, preimage_r));
res->data=(void *)maEval(theMap,(poly)data,preimage_r,nMap,s);
idDelete((ideal *)&s);
}
if (currRing->minpoly!=NULL)
res->data=(void *)pMinPolyNormalize((poly)res->data);
pTest((poly)res->data);
break;
case MODUL_CMD:
case MATRIX_CMD:
case IDEAL_CMD:
case MAP_CMD:
{
int C=((matrix)data)->cols();
int R;
if (w->rtyp==MAP_CMD) R=1;
else R=((matrix)data)->rows();
matrix m=mpNew(R,C);
char *tmpR=NULL;
if(w->rtyp==MAP_CMD)
{
tmpR=((map)data)->preimage;
((matrix)data)->rank=((matrix)data)->rows();
}
if ((what==FETCH_CMD)&& (nMap==nCopy))
{
for (i=R*C-1;i>=0;i--)
{
m->m[i]=prCopyR(((ideal)data)->m[i], preimage_r);
pTest(m->m[i]);
}
}
else
if ((what==IMAP_CMD) || ((what==FETCH_CMD) /* && (nMap!=nCopy)*/))
{
for (i=R*C-1;i>=0;i--)
{
m->m[i]=pPermPoly(((ideal)data)->m[i],perm,preimage_r,nMap,par_perm,P);
pTest(m->m[i]);
}
}
else /* if(what==MAP_CMD) */
{
matrix s=mpNew(N,maMaxDeg_Ma((ideal)data,preimage_r));
for (i=R*C-1;i>=0;i--)
{
m->m[i]=maEval(theMap,((ideal)data)->m[i],preimage_r,nMap,s);
pTest(m->m[i]);
}
idDelete((ideal *)&s);
}
if (currRing->minpoly!=NULL)
{
for (i=R*C-1;i>=0;i--)
{
m->m[i]=pMinPolyNormalize(m->m[i]);
pTest(m->m[i]);
}
}
if(w->rtyp==MAP_CMD)
{
((map)data)->preimage=tmpR;
((map)m)->preimage=omStrDup(tmpR);
}
else
{
m->rank=((matrix)data)->rank;
}
res->data=(char *)m;
idTest((ideal) m);
break;
}
case LIST_CMD:
{
lists l=(lists)data;
lists ml=(lists)omAllocBin(slists_bin);
ml->Init(l->nr+1);
for(i=0;i<=l->nr;i++)
{
if (((l->m[i].rtyp>BEGIN_RING)&&(l->m[i].rtyp