source: git/kernel/preimage.cc @ a82c308

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