source: git/kernel/preimage.cc @ 1c94e4

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