maps.cc
Go to the documentation of this file.
1 /****************************************
2 * Computer Algebra System SINGULAR *
3 ****************************************/
4 /*
5 * ABSTRACT - the mapping of polynomials to other rings
6 */
7 
8 #include <omalloc/omalloc.h>
9 
10 
11 
12 
13 #include <misc/auxiliary.h>
14 #include <misc/options.h>
15 
16 #include <coeffs/coeffs.h>
17 #include <coeffs/numbers.h>
18 
20 #include <polys/monomials/ring.h>
21 #include <polys/simpleideals.h>
22 #include <polys/prCopy.h>
23 // #include <polys/ext_fields/longtrans.h>
24 #include <polys/monomials/maps.h>
25 
26 #ifdef HAVE_PLURAL
27 #include <polys/nc/nc.h>
28 #endif
29 
30 // This is a very dirty way to "normalize" numbers w.r.t. a
31 // MinPoly
32 
33 #define MAX_MAP_DEG 128
34 
35 /*2
36 * copy a map
37 */
38 map maCopy(map theMap, const ring r)
39 {
40  int i;
41  map m=(map)idInit(IDELEMS(theMap),0);
42  for (i=IDELEMS(theMap)-1; i>=0; i--)
43  m->m[i] = p_Copy(theMap->m[i],r);
44  m->preimage=omStrDup(theMap->preimage);
45  return m;
46 }
47 
48 
49 /*2
50 * return the image of var(v)^pExp, where var(v) maps to p
51 */
52 poly maEvalVariable(poly p, int v,int pExp, ideal s, const ring dst_r)
53 {
54  if (pExp==1)
55  return p_Copy(p,dst_r);
56 
57  poly res;
58 
59  if((s!=NULL)&&(pExp<MAX_MAP_DEG))
60  {
61  int j=2;
62  poly p0=p;
63  // find starting point
64  if(MATELEM(s,v,1)==NULL)
65  {
66  MATELEM(s,v,1)=p_Copy(p/*theMap->m[v-1]*/,dst_r);
67  }
68  else
69  {
70  while((j<=pExp)&&(MATELEM(s,v,j)!=NULL))
71  {
72  j++;
73  }
74  p0=MATELEM(s,v,j-1);
75  }
76  // multiply
77  for(;j<=pExp;j++)
78  {
79  p0=MATELEM(s,v,j)=pp_Mult_qq(p0, p,dst_r);
80  p_Normalize(p0, dst_r);
81  }
82  res=p_Copy(p0/*MATELEM(s,v,pExp)*/,dst_r);
83  }
84  else //if ((p->next!=NULL)&&(p->next->next==NULL))
85  {
86  res=p_Power(p_Copy(p,dst_r),pExp,dst_r);
87  }
88  return res;
89 }
90 
91 static poly maEvalMonom(map theMap, poly p,ring preimage_r, ideal s,
92  nMapFunc nMap, const ring dst_r)
93 {
94  p_Test(p,preimage_r);
95  poly q=p_NSet(nMap(pGetCoeff(p),preimage_r->cf,dst_r->cf),dst_r);
96 
97  int i;
98  for(i=1;i<=preimage_r->N; i++)
99  {
100  int pExp=p_GetExp( p,i,preimage_r);
101  if (pExp != 0)
102  {
103  if (theMap->m[i-1]!=NULL)
104  {
105  poly p1=theMap->m[i-1];
106  poly pp=maEvalVariable(p1,i,pExp,s,dst_r);
107  q = p_Mult_q(q,pp,dst_r);
108  }
109  else
110  {
111  p_Delete(&q,dst_r);
112  break;
113  }
114  }
115  }
116  int modulComp = p_GetComp( p,preimage_r);
117  if (q!=NULL) p_SetCompP(q,modulComp,dst_r);
118  return q;
119 }
120 
121 poly maEval(map theMap, poly p,ring preimage_r,nMapFunc nMap, ideal s, const ring dst_r)
122 {
123  poly result = NULL;
124  int i;
125 
126 // for(i=1; i<=preimage_r->N; i++)
127 // {
128 // pTest(theMap->m[i-1]);
129 // }
130 // while (p!=NULL)
131 // {
132 // poly q=maEvalMonom(theMap,p,preimage_r,s);
133 // result = pAdd(result,q);
134 // pIter(p);
135 // }
136  if (p!=NULL)
137  {
138  int l = pLength(p)-1;
139  poly* monoms;
140  if (l>0)
141  {
142  monoms = (poly*) omAlloc(l*sizeof(poly));
143 
144  for (i=0; i<l; i++)
145  {
146  monoms[i]=maEvalMonom(theMap,p,preimage_r,s, nMap, dst_r);
147  pIter(p);
148  }
149  }
150  result=maEvalMonom(theMap,p,preimage_r,s, nMap, dst_r);
151  if (l>0)
152  {
153  for(i = l-1; i>=0; i--)
154  {
155  result=p_Add_q(result, monoms[i], dst_r);
156  }
157  omFreeSize((ADDRESS)monoms,l*sizeof(poly));
158  }
159 
160  assume(dst_r != NULL);
161  assume(dst_r->cf != NULL);
162 
163  if (nCoeff_is_algExt(dst_r->cf))
164  result = p_MinPolyNormalize(result, dst_r);
165  }
166  return result;
167 }
168 
169 void maFindPerm(char const * const * const preim_names, int preim_n, char const * const * const preim_par, int preim_p,
170  char const * const * const names, int n, char const * const * const par, int nop,
171  int * perm, int *par_perm, n_coeffType ch)
172 {
173  int i,j;
174  /* find correspondig vars */
175  for (i=0; i<preim_n; i++)
176  {
177  for(j=0; j<n; j++)
178  {
179  if (strcmp(preim_names[i],names[j])==0)
180  {
181  if (BVERBOSE(V_IMAP))
182  Print("// var %s: nr %d -> nr %d\n",preim_names[i],i+1,j+1);
183  /* var i+1 from preimage ring is var j+1 (index j+1) from image ring */
184  perm[i+1]=j+1;
185  break;
186  }
187  }
188  if ((perm[i+1]==0)&&(par!=NULL)
189  // do not consider par of Fq
190  && (ch!=n_GF))
191  {
192  for(j=0; j<nop; j++)
193  {
194  if (strcmp(preim_names[i],par[j])==0)
195  {
196  if (BVERBOSE(V_IMAP))
197  Print("// var %s: nr %d -> par %d\n",preim_names[i],i+1,j+1);
198  /* var i+1 from preimage ring is par j+1 (index j) from image ring */
199  perm[i+1]=-(j+1);
200  }
201  }
202  }
203  }
204  if (par_perm!=NULL)
205  {
206  for (i=0; i<preim_p; i++)
207  {
208  for(j=0; j<n; j++)
209  {
210  if (strcmp(preim_par[i],names[j])==0)
211  {
212  if (BVERBOSE(V_IMAP))
213  Print("// par %s: par %d -> nr %d\n",preim_par[i],i+1,j+1);
214  /*par i+1 from preimage ring is var j+1 (index j+1) from image ring*/
215  par_perm[i]=j+1;
216  break;
217  }
218  }
219  if ((par!=NULL) && (par_perm[i]==0))
220  {
221  for(j=0; j<nop; j++)
222  {
223  if (strcmp(preim_par[i],par[j])==0)
224  {
225  if (BVERBOSE(V_IMAP))
226  Print("// par %s: nr %d -> par %d\n",preim_par[i],i+1,j+1);
227  /*par i+1 from preimage ring is par j+1 (index j) from image ring */
228  par_perm[i]=-(j+1);
229  }
230  }
231  }
232  }
233  }
234 }
235 
236 /*2
237 * embeds poly p from the subring r into the current ring
238 */
239 poly maIMap(ring r, poly p, const ring dst_r)
240 {
241  /* the simplest case:*/
242  if(r==dst_r) return p_Copy(p,dst_r);
243  nMapFunc nMap=n_SetMap(r->cf,dst_r->cf);
244  int *perm=(int *)omAlloc0((r->N+1)*sizeof(int));
245  //int *par_perm=(int *)omAlloc0(rPar(r)*sizeof(int));
246  maFindPerm(r->names, rVar(r), rParameter(r), rPar(r),
247  dst_r->names, rVar(dst_r),rParameter(dst_r), rPar(dst_r),
248  perm,NULL, dst_r->cf->type);
249  poly res=p_PermPoly(p,perm,r,dst_r, nMap /*,par_perm,rPar(r)*/);
250  omFreeSize((ADDRESS)perm,(r->N+1)*sizeof(int));
251  //omFreeSize((ADDRESS)par_perm,rPar(r)*sizeof(int));
252  return res;
253 }
254 
255 /*3
256 * find the max. degree in one variable, but not larger than MAX_MAP_DEG
257 */
258 int maMaxDeg_Ma(ideal a,ring preimage_r)
259 {
260  int i,j;
261  int N = preimage_r->N;
262  poly p;
263  int *m=(int *)omAlloc0(N*sizeof(int));
264 
265  for (i=MATROWS(a)*MATCOLS(a)-1;i>=0;i--)
266  {
267  p=a->m[i];
268  //pTest(p); // cannot test p because it is from another ring
269  while(p!=NULL)
270  {
271  for(j=N-1;j>=0;j--)
272  {
273  m[j]=si_max(m[j],(int)p_GetExp( p,j+1,preimage_r));
274  if (m[j]>=MAX_MAP_DEG)
275  {
276  i=MAX_MAP_DEG;
277  goto max_deg_fertig_id;
278  }
279  }
280  pIter(p);
281  }
282  }
283  i=m[0];
284  for(j=N-1;j>0;j--)
285  {
286  i=si_max(i,m[j]);
287  }
288 max_deg_fertig_id:
289  omFreeSize((ADDRESS)m,N*sizeof(int));
290  return i;
291 }
292 
293 /*3
294 * find the max. degree in one variable, but not larger than MAX_MAP_DEG
295 */
296 int maMaxDeg_P(poly p,ring preimage_r)
297 {
298  int i,j;
299  int N = preimage_r->N;
300  int *m=(int *)omAlloc0(N*sizeof(int));
301 
302 // pTest(p);
303  while(p!=NULL)
304  {
305  for(j=N-1;j>=0;j--)
306  {
307  m[j]=si_max(m[j],(int)p_GetExp(p,j+1,preimage_r));
308  if (m[j]>=MAX_MAP_DEG)
309  {
310  i=MAX_MAP_DEG;
311  goto max_deg_fertig_p;
312  }
313  }
314  pIter(p);
315  }
316  i=m[0];
317  for(j=N-1;j>0;j--)
318  {
319  i=si_max(i,m[j]);
320  }
321 max_deg_fertig_p:
322  omFreeSize((ADDRESS)m,N*sizeof(int));
323  return i;
324 }
325 
326 // This is a very dirty way to cancel monoms whose number equals the
327 // MinPoly
329 {
330  const coeffs C = r->cf;
331  number one = n_Init(1, C);
332  spolyrec rp;
333 
334  poly q = &rp;
335 
336  while (p != NULL)
337  {
338  // this returns 0, if p == MinPoly
339  number product = n_Mult(p_GetCoeff(p, r), one, C);
340  if ((product == NULL)||(n_IsZero(product, C)))
341  {
342  p_LmDelete(&p, r);
343  }
344  else
345  {
346  p_SetCoeff(p, product, r);
347  pNext(q) = p;
348  q = p;
349  p = pNext(p);
350  }
351  }
352  pNext(q) = NULL;
353  n_Delete(&one, C);
354  return rp.next;
355 }
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
const CanonicalForm int s
Definition: facAbsFact.cc:55
const poly a
Definition: syzextra.cc:212
#define Print
Definition: emacs.cc:83
#define MAX_MAP_DEG
Definition: maps.cc:33
return P p
Definition: myNF.cc:203
poly maEvalVariable(poly p, int v, int pExp, ideal s, const ring dst_r)
Definition: maps.cc:52
static int rPar(const ring r)
(r->cf->P)
Definition: ring.h:590
poly p_NSet(number n, const ring r)
returns the poly representing the number n, destroys n
Definition: p_polys.cc:1442
#define p_GetComp(p, r)
Definition: monomials.h:72
static FORCE_INLINE number n_Init(long i, const coeffs r)
a number representing i in the given coeff field/ring r
Definition: coeffs.h:542
#define omFreeSize(addr, size)
Definition: omAllocDecl.h:260
static short rVar(const ring r)
#define rVar(r) (r->N)
Definition: ring.h:583
int maMaxDeg_Ma(ideal a, ring preimage_r)
Definition: maps.cc:258
void * ADDRESS
Definition: auxiliary.h:115
static char const ** rParameter(const ring r)
(r->cf->parameter)
Definition: ring.h:616
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
#define omAlloc(size)
Definition: omAllocDecl.h:210
static number p_SetCoeff(poly p, number n, ring r)
Definition: p_polys.h:407
static poly p_Copy(poly p, const ring r)
returns a copy of p
Definition: p_polys.h:804
poly pp
Definition: myNF.cc:296
#define pIter(p)
Definition: monomials.h:44
poly res
Definition: myNF.cc:322
static FORCE_INLINE number n_Mult(number a, number b, const coeffs r)
return the product of &#39;a&#39; and &#39;b&#39;, i.e., a*b
Definition: coeffs.h:640
const ring r
Definition: syzextra.cc:208
poly p_PermPoly(poly p, const int *perm, const ring oldRing, const ring dst, nMapFunc nMap, const int *par_perm, int OldPar, BOOLEAN use_mult)
Definition: p_polys.cc:3938
Coefficient rings, fields and other domains suitable for Singular polynomials.
static FORCE_INLINE BOOLEAN nCoeff_is_algExt(const coeffs r)
TRUE iff r represents an algebraic extension field.
Definition: coeffs.h:927
static void p_SetCompP(poly p, int i, ring r)
Definition: p_polys.h:249
const CanonicalForm CFMap CFMap & N
Definition: cfEzgcd.cc:49
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:464
int j
Definition: myNF.cc:70
#define assume(x)
Definition: mod2.h:394
The main handler for Singular numbers which are suitable for Singular polynomials.
static poly pp_Mult_qq(poly p, poly q, const ring r)
Definition: p_polys.h:1070
number(* nMapFunc)(number a, const coeffs src, const coeffs dst)
maps "a", which lives in src, into dst
Definition: coeffs.h:73
All the auxiliary stuff.
poly maIMap(ring r, poly p, const ring dst_r)
Definition: maps.cc:239
int m
Definition: cfEzgcd.cc:119
static int si_max(const int a, const int b)
Definition: auxiliary.h:120
int i
Definition: cfEzgcd.cc:123
static unsigned pLength(poly a)
Definition: p_polys.h:189
#define IDELEMS(i)
Definition: simpleideals.h:24
static FORCE_INLINE BOOLEAN n_IsZero(number n, const coeffs r)
TRUE iff &#39;n&#39; represents the zero element.
Definition: coeffs.h:468
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:725
#define p_Test(p, r)
Definition: p_polys.h:160
#define BVERBOSE(a)
Definition: options.h:33
void p_Normalize(poly p, const ring r)
Definition: p_polys.cc:3633
static void p_Delete(poly *p, const ring r)
Definition: p_polys.h:843
ideal idInit(int idsize, int rank)
initialise an ideal / module
Definition: simpleideals.cc:38
const Variable & v
< [in] a sqrfree bivariate poly
Definition: facBivar.h:37
poly p_MinPolyNormalize(poly p, const ring r)
Definition: maps.cc:328
n_coeffType
Definition: coeffs.h:27
void maFindPerm(char const *const *const preim_names, int preim_n, char const *const *const preim_par, int preim_p, char const *const *const names, int n, char const *const *const par, int nop, int *perm, int *par_perm, n_coeffType ch)
Definition: maps.cc:169
#define MATCOLS(i)
Definition: matpol.h:28
#define NULL
Definition: omList.c:10
{p^n < 2^16}
Definition: coeffs.h:33
int maMaxDeg_P(poly p, ring preimage_r)
Definition: maps.cc:296
#define pNext(p)
Definition: monomials.h:43
#define p_GetCoeff(p, r)
Definition: monomials.h:57
map maCopy(map theMap, const ring r)
Definition: maps.cc:38
static void p_LmDelete(poly p, const ring r)
Definition: p_polys.h:706
static FORCE_INLINE void n_Delete(number *p, const coeffs r)
delete &#39;p&#39;
Definition: coeffs.h:459
#define MATROWS(i)
Definition: matpol.h:27
polyrec * poly
Definition: hilb.h:10
static poly p_Add_q(poly p, poly q, const ring r)
Definition: p_polys.h:877
static poly p_Mult_q(poly p, poly q, const ring r)
Definition: p_polys.h:1020
poly p_Power(poly p, int i, const ring r)
Definition: p_polys.cc:2118
static poly maEvalMonom(map theMap, poly p, ring preimage_r, ideal s, nMapFunc nMap, const ring dst_r)
Definition: maps.cc:91
poly next
Definition: monomials.h:31
#define omAlloc0(size)
Definition: omAllocDecl.h:211
int l
Definition: cfEzgcd.cc:94
return result
Definition: facAbsBiFact.cc:76
poly maEval(map theMap, poly p, ring preimage_r, nMapFunc nMap, ideal s, const ring dst_r)
Definition: maps.cc:121
#define MATELEM(mat, i, j)
Definition: matpol.h:29
#define V_IMAP
Definition: options.h:51
#define omStrDup(s)
Definition: omAllocDecl.h:263