source: git/kernel/preimage.cc @ 5ca9328

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