source: git/kernel/preimage.cc @ c6a876

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