source: git/kernel/preimage.cc @ a1ef3a2

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