source: git/kernel/preimage.cc @ 0838d7

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