source: git/kernel/preimage.cc @ 7b9b8e5

spielwiese
Last change on this file since 7b9b8e5 was 7b9b8e5, checked in by Hans Schoenemann <hannes@…>, 8 years ago
fix: Werror -> WerrorS if possible
  • Property mode set to 100644
File size: 4.3 KB
Line 
1
2#include <kernel/mod2.h>
3
4#include <omalloc/omalloc.h>
5#include <misc/auxiliary.h>
6#include <misc/options.h>
7#include <misc/intvec.h>
8
9#include <kernel/polys.h>
10#include <polys/monomials/ring.h>
11
12
13#include <kernel/ideals.h>
14#include <kernel/GBEngine/kstd1.h>
15#include <kernel/GBEngine/khstd.h>
16
17#include <kernel/GBEngine/kutil.h>
18
19
20#ifdef HAVE_PLURAL
21#include <polys/nc/nc.h>
22#endif
23
24/*2
25*shifts the variables between minvar and maxvar of p  \in p_ring to the
26*first maxvar-minvar+1 variables in the actual ring
27*be carefull: there is no range check for the variables of p
28*/
29static poly pChangeSizeOfPoly(ring p_ring, poly p,int minvar,int maxvar, const ring dst_r)
30{
31  int i;
32  poly result = NULL,resultWorkP;
33  number n;
34
35  if (p==NULL) return result;
36  else result = p_Init(dst_r);
37  resultWorkP = result;
38  while (p!=NULL)
39  {
40    for (i=minvar;i<=maxvar;i++)
41      p_SetExp(resultWorkP,i-minvar+1,p_GetExp(p,i,p_ring),dst_r);
42    p_SetComp(resultWorkP,p_GetComp(p,p_ring),dst_r);
43    n=n_Copy(pGetCoeff(p),dst_r->cf);
44    p_SetCoeff(resultWorkP,n,dst_r);
45    p_Setm(resultWorkP,dst_r);
46    pIter(p);
47    if (p!=NULL)
48    {
49      pNext(resultWorkP) = p_Init(dst_r);
50      pIter(resultWorkP);
51    }
52  }
53  return result;
54}
55
56
57
58/*2
59*returns the preimage of id under theMap,
60*if id is empty or zero the kernel is computed
61* (assumes) that both ring have the same coeff.field
62*/
63ideal maGetPreimage(ring theImageRing, map theMap, ideal id, const ring dst_r)
64{
65  ring sourcering = dst_r;
66
67#ifdef HAVE_PLURAL
68  if (rIsPluralRing(theImageRing))
69  {
70    if ((rIsPluralRing(sourcering)) && (ncRingType(sourcering)!=nc_comm))
71    {
72      WerrorS("Sorry, not yet implemented for noncomm. rings");
73      return NULL;
74    }
75  }
76#endif
77
78  int i,j;
79  poly p,/*pp,*/q;
80  ideal temp1;
81  ideal temp2;
82
83  int imagepvariables = rVar(theImageRing);
84  int N = rVar(dst_r)+imagepvariables;
85
86  ring tmpR;
87  if (rSumInternal(theImageRing,sourcering,tmpR,FALSE,2)!=1)
88  {
89     WerrorS("error in rSumInternal");
90     return NULL;
91  }
92
93  assume(n_SetMap(theImageRing->cf, dst_r->cf) == ndCopyMap);
94
95  if (theImageRing->cf != dst_r->cf)
96  {
97    /// TODO: there might be extreme cases where this doesn't hold...
98    WerrorS("Coefficient fields/rings must be equal");
99    return NULL;
100  }
101
102  const ring save_ring = currRing; if (currRing!=tmpR) rChangeCurrRing(tmpR); // due to kStd
103
104  if (id==NULL)
105    j = 0;
106  else
107    j = IDELEMS(id);
108  int j0=j;
109  if (theImageRing->qideal!=NULL) j+=IDELEMS(theImageRing->qideal);
110  temp1 = idInit(sourcering->N+j,1);
111  for (i=0;i<sourcering->N;i++)
112  {
113    q = p_ISet(-1,tmpR);
114    p_SetExp(q,i+1+imagepvariables,1,tmpR);
115    p_Setm(q,tmpR);
116    if ((i<IDELEMS(theMap)) && (theMap->m[i]!=NULL))
117    {
118      p = p_SortMerge(
119                      pChangeSizeOfPoly(theImageRing, theMap->m[i], 1, imagepvariables, tmpR),
120                      tmpR);
121      p=p_Add_q(p,q,tmpR);
122    }
123    else
124    {
125      p = q;
126    }
127    temp1->m[i] = p;
128  }
129  id_Test(temp1, tmpR);
130  for (i=sourcering->N;i<sourcering->N+j0;i++)
131  {
132    temp1->m[i] = p_SortMerge(
133                              pChangeSizeOfPoly(theImageRing, id->m[i-sourcering->N], 1, imagepvariables, tmpR),
134                              tmpR);
135  }
136  for (i=sourcering->N+j0;i<sourcering->N+j;i++)
137  {
138    temp1->m[i] = p_SortMerge(
139                              pChangeSizeOfPoly(theImageRing, theImageRing->qideal->m[i-sourcering->N-j0], 1, imagepvariables, tmpR),
140                              tmpR);
141  }
142  // we ignore here homogenity - may be changed later:
143
144  temp2 = kStd(temp1,NULL,isNotHomog,NULL);
145
146  id_Delete(&temp1,tmpR);
147  for (i=0;i<IDELEMS(temp2);i++)
148  {
149    if (p_LowVar(temp2->m[i], currRing)<imagepvariables) p_Delete(&(temp2->m[i]),tmpR);
150  }
151
152  // let's get back to the original ring
153  //rChangeCurrRing(sourcering);
154  temp1 = idInit(5,1);
155  j = 0;
156  for (i=0;i<IDELEMS(temp2);i++)
157  {
158    p = temp2->m[i];
159    if (p!=NULL)
160    {
161      q = p_SortMerge(
162                      pChangeSizeOfPoly(tmpR, p, imagepvariables+1, N, sourcering),
163                      sourcering);
164      if (j>=IDELEMS(temp1))
165      {
166        pEnlargeSet(&(temp1->m),IDELEMS(temp1),5);
167        IDELEMS(temp1)+=5;
168      }
169      temp1->m[j] = q;
170      j++;
171    }
172  }
173  id_Delete(&temp2, tmpR);
174  idSkipZeroes(temp1);
175
176  if (currRing!=save_ring) rChangeCurrRing(save_ring);
177
178  rDelete(tmpR);
179  return temp1;
180}
181
Note: See TracBrowser for help on using the repository browser.