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

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