preimage.cc
Go to the documentation of this file.
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 */
27 static 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_SetCoeff0(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 */
61 ideal 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 
static poly p_SortMerge(poly p, const ring r, BOOLEAN revert=FALSE)
Definition: p_polys.h:1175
CanonicalForm map(const CanonicalForm &primElem, const Variable &alpha, const CanonicalForm &F, const Variable &beta)
map from to such that is mapped onto
Definition: cf_map_ext.cc:400
int j
Definition: facHensel.cc:105
int rSumInternal(ring r1, ring r2, ring &sum, BOOLEAN vartest, BOOLEAN dp_dp)
returns -1 for not compatible, 1 for compatible (and sum) dp_dp:0: block ordering, 1: dp,dp, 2: aa(...),dp vartest: check for name conflicts
Definition: ring.cc:726
#define FALSE
Definition: auxiliary.h:94
Compatiblity layer for legacy polynomial operations (over currRing)
number ndCopyMap(number a, const coeffs aRing, const coeffs r)
Definition: numbers.cc:251
#define id_Test(A, lR)
Definition: simpleideals.h:80
static unsigned long p_SetComp(poly p, unsigned long c, ring r)
Definition: p_polys.h:247
#define p_GetComp(p, r)
Definition: monomials.h:71
static short rVar(const ring r)
#define rVar(r) (r->N)
Definition: ring.h:583
void id_Delete(ideal *h, ring r)
deletes an ideal/module/matrix
ideal kStd(ideal F, ideal Q, tHomog h, intvec **w, intvec *hilb, int syzComp, int newIdeal, intvec *vw, s_poly_proc_t sp)
Definition: kstd1.cc:2096
void WerrorS(const char *s)
Definition: feFopen.cc:24
static number & pGetCoeff(poly p)
return an alias to the leading coefficient of p assumes that p != NULL NOTE: not copy ...
Definition: monomials.h:51
Definition: nc.h:17
#define pIter(p)
Definition: monomials.h:44
const CanonicalForm CFMap CFMap & N
Definition: cfEzgcd.cc:48
static long p_GetExp(const poly p, const unsigned long iBitmask, const int VarOffset)
get a single variable exponent : the integer VarOffset encodes:
Definition: p_polys.h:469
#define assume(x)
Definition: mod2.h:390
static BOOLEAN rIsPluralRing(const ring r)
we must always have this test!
Definition: ring.h:404
int i
Definition: cfEzgcd.cc:125
static poly pChangeSizeOfPoly(ring p_ring, poly p, int minvar, int maxvar, const ring dst_r)
Definition: preimage.cc:27
int p_LowVar(poly p, const ring r)
the minimal index of used variables - 1
Definition: p_polys.cc:4564
#define IDELEMS(i)
Definition: simpleideals.h:24
static FORCE_INLINE nMapFunc n_SetMap(const coeffs src, const coeffs dst)
set the mapping function pointers for translating numbers from src to dst
Definition: coeffs.h:722
void idSkipZeroes(ideal ide)
gives an ideal/module the minimal possible size
void rChangeCurrRing(ring r)
Definition: polys.cc:15
static void p_Delete(poly *p, const ring r)
Definition: p_polys.h:857
ideal idInit(int idsize, int rank)
initialise an ideal / module
Definition: simpleideals.cc:37
static unsigned long p_SetExp(poly p, const unsigned long e, const unsigned long iBitmask, const int VarOffset)
set a single variable exponent : VarOffset encodes the position in p->exp
Definition: p_polys.h:488
#define NULL
Definition: omList.c:10
void pEnlargeSet(poly **p, int l, int increment)
Definition: p_polys.cc:3633
static FORCE_INLINE number n_Copy(number n, const coeffs r)
return a copy of &#39;n&#39;
Definition: coeffs.h:452
void rDelete(ring r)
unconditionally deletes fields in r
Definition: ring.cc:439
#define pNext(p)
Definition: monomials.h:43
ring currRing
Widely used global variable which specifies the current polynomial ring for Singular interpreter and ...
Definition: polys.cc:13
static void p_Setm(poly p, const ring r)
Definition: p_polys.h:233
static nc_type & ncRingType(nc_struct *p)
Definition: nc.h:167
ideal maGetPreimage(ring theImageRing, map theMap, ideal id, const ring dst_r)
Definition: preimage.cc:61
#define p_SetCoeff0(p, n, r)
Definition: monomials.h:67
int p
Definition: cfModGcd.cc:4019
static poly p_Add_q(poly p, poly q, const ring r)
Definition: p_polys.h:892
static poly p_Init(const ring r, omBin bin)
Definition: p_polys.h:1266
poly p_ISet(long i, const ring r)
returns the poly representing the integer i
Definition: p_polys.cc:1289
return result
Definition: facAbsBiFact.cc:76