source: git/libpolys/polys/monomials/preimage.cc @ e432a0

fieker-DuValspielwiese
Last change on this file since e432a0 was 89abbe0, checked in by Oleksandr Motsak <motsak@…>, 13 years ago
FIX: preimage of a map needs a GB -> separated into preimage.cc
  • Property mode set to 100644
File size: 2.7 KB
Line 
1// ideal maGetPreimage(ring theImageRing, map theMap,ideal id);
2
3/*2
4*returns the preimage of id under theMap,
5*if id is empty or zero the kernel is computed
6* (assumes) that both ring have the same coeff.field
7*/
8ideal maGetPreimage(ring theImageRing, map theMap, ideal id, const ring dst_r)
9{
10  ring sourcering = dst_r;
11
12#ifdef HAVE_PLURAL
13  if (rIsPluralRing(theImageRing))
14  {
15    if ((rIsPluralRing(sourcering)) && (ncRingType(sourcering)!=nc_comm)) 
16    {
17      Werror("Sorry, not yet implemented for noncomm. rings");
18      return NULL;
19    }
20  }
21#endif
22 
23  int i,j;
24  poly p,pp,q;
25  ideal temp1;
26  ideal temp2;
27
28  int imagepvariables = rVar(theImageRing);
29  int N = rVar(dst_r)+imagepvariables;
30
31  ring tmpR;
32  if (rSumInternal(theImageRing,sourcering,tmpR,FALSE,TRUE)!=1)
33  {
34     WerrorS("error in rSumInternal");
35     return NULL;
36  }
37
38  if (n_SetMap(theImageRing->cf,dst_r->cf) != ndCopyMap)
39  {
40    Werror("Coefficient fields/rings must be equal");
41    return NULL;
42  }
43
44  if (id==NULL)
45    j = 0;
46  else
47    j = IDELEMS(id);
48  int j0=j;
49  if (theImageRing->qideal!=NULL) j+=IDELEMS(theImageRing->qideal);
50  temp1 = idInit(sourcering->N+j,1);
51  for (i=0;i<sourcering->N;i++)
52  {
53    q = p_ISet(-1,tmpR);
54    p_SetExp(q,i+1+imagepvariables,1,tmpR);
55    p_Setm(q,tmpR);
56    if ((i<IDELEMS(theMap)) && (theMap->m[i]!=NULL))
57    {
58      p = p_SortMerge(
59        pChangeSizeOfPoly(theImageRing,theMap->m[i],1,imagepvariables,tmpR),
60        tmpR);
61      p=p_Add_q(p,q,tmpR);
62    }
63    else
64    {
65      p = q;
66    }
67    temp1->m[i] = p;
68  }
69  idTest(temp1);
70  for (i=sourcering->N;i<sourcering->N+j0;i++)
71  {
72    temp1->m[i] = p_SortMerge(pChangeSizeOfPoly(theImageRing,
73                         id->m[i-sourcering->N],1,imagepvariables,tmpR),tmpR);
74  }
75  for (i=sourcering->N+j0;i<sourcering->N+j;i++)
76  {
77    temp1->m[i] = p_SortMerge(pChangeSizeOfPoly(theImageRing,
78                              theImageRing->qideal->m[i-sourcering->N-j0],
79                              1,imagepvariables,tmpR),tmpR);
80  }
81  // we ignore here homogenity - may be changed later:
82  temp2 = kStd(temp1,NULL,isNotHomog,NULL);
83  id_Delete(&temp1,tmpR);
84  for (i=0;i<IDELEMS(temp2);i++)
85  {
86    if (pLowVar(temp2->m[i])<imagepvariables) p_Delete(&(temp2->m[i]),tmpR);
87  }
88
89  // let's get back to the original ring
90  //rChangeCurrRing(sourcering);
91  temp1 = idInit(5,1);
92  j = 0;
93  for (i=0;i<IDELEMS(temp2);i++)
94  {
95    p = temp2->m[i];
96    if (p!=NULL)
97    {
98      q = p_SortMerge(pChangeSizeOfPoly(tmpR, p,imagepvariables+1,N),sourcering);
99      if (j>=IDELEMS(temp1))
100      {
101        pEnlargeSet(&(temp1->m),IDELEMS(temp1),5);
102        IDELEMS(temp1)+=5;
103      }
104      temp1->m[j] = q;
105      j++;
106    }
107  }
108  id_Delete(&temp2, tmpR);
109  idSkipZeroes(temp1);
110  rKill(tmpR);
111  return temp1;
112}
113
Note: See TracBrowser for help on using the repository browser.