source: git/kernel/preimage.cc @ b1b525

fieker-DuValspielwiese
Last change on this file since b1b525 was e6cdad, checked in by Hans Schoenemann <hannes@…>, 6 years ago
use xalloc if omalloc is disabled
  • Property mode set to 100644
File size: 4.2 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  assume(n_SetMap(theImageRing->cf, dst_r->cf) == ndCopyMap);
91
92  if (theImageRing->cf != dst_r->cf)
93  {
94    /// TODO: there might be extreme cases where this doesn't hold...
95    WerrorS("Coefficient fields/rings must be equal");
96    return NULL;
97  }
98
99  const ring save_ring = currRing; if (currRing!=tmpR) rChangeCurrRing(tmpR); // due to kStd
100
101  if (id==NULL)
102    j = 0;
103  else
104    j = IDELEMS(id);
105  int j0=j;
106  if (theImageRing->qideal!=NULL) j+=IDELEMS(theImageRing->qideal);
107  temp1 = idInit(sourcering->N+j,1);
108  for (i=0;i<sourcering->N;i++)
109  {
110    q = p_ISet(-1,tmpR);
111    p_SetExp(q,i+1+imagepvariables,1,tmpR);
112    p_Setm(q,tmpR);
113    if ((i<IDELEMS(theMap)) && (theMap->m[i]!=NULL))
114    {
115      p = p_SortMerge(
116                      pChangeSizeOfPoly(theImageRing, theMap->m[i], 1, imagepvariables, tmpR),
117                      tmpR);
118      p=p_Add_q(p,q,tmpR);
119    }
120    else
121    {
122      p = q;
123    }
124    temp1->m[i] = p;
125  }
126  id_Test(temp1, tmpR);
127  for (i=sourcering->N;i<sourcering->N+j0;i++)
128  {
129    temp1->m[i] = p_SortMerge(
130                              pChangeSizeOfPoly(theImageRing, id->m[i-sourcering->N], 1, imagepvariables, tmpR),
131                              tmpR);
132  }
133  for (i=sourcering->N+j0;i<sourcering->N+j;i++)
134  {
135    temp1->m[i] = p_SortMerge(
136                              pChangeSizeOfPoly(theImageRing, theImageRing->qideal->m[i-sourcering->N-j0], 1, imagepvariables, tmpR),
137                              tmpR);
138  }
139  // we ignore here homogenity - may be changed later:
140
141  temp2 = kStd(temp1,NULL,isNotHomog,NULL);
142
143  id_Delete(&temp1,tmpR);
144  for (i=0;i<IDELEMS(temp2);i++)
145  {
146    if (p_LowVar(temp2->m[i], currRing)<imagepvariables) p_Delete(&(temp2->m[i]),tmpR);
147  }
148
149  // let's get back to the original ring
150  //rChangeCurrRing(sourcering);
151  temp1 = idInit(5,1);
152  j = 0;
153  for (i=0;i<IDELEMS(temp2);i++)
154  {
155    p = temp2->m[i];
156    if (p!=NULL)
157    {
158      q = p_SortMerge(
159                      pChangeSizeOfPoly(tmpR, p, imagepvariables+1, N, sourcering),
160                      sourcering);
161      if (j>=IDELEMS(temp1))
162      {
163        pEnlargeSet(&(temp1->m),IDELEMS(temp1),5);
164        IDELEMS(temp1)+=5;
165      }
166      temp1->m[j] = q;
167      j++;
168    }
169  }
170  id_Delete(&temp2, tmpR);
171  idSkipZeroes(temp1);
172
173  if (currRing!=save_ring) rChangeCurrRing(save_ring);
174
175  rDelete(tmpR);
176  return temp1;
177}
178
Note: See TracBrowser for help on using the repository browser.