My Project  debian-1:4.1.2-p1+ds-2
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 "misc/auxiliary.h"
9 #include "misc/options.h"
10 
11 #include "coeffs/coeffs.h"
12 #include "coeffs/numbers.h"
13 
15 #include "polys/monomials/ring.h"
16 #include "polys/simpleideals.h"
17 #include "polys/prCopy.h"
18 #include "polys/monomials/maps.h"
19 
20 #ifdef HAVE_PLURAL
21 #include "polys/nc/nc.h"
22 #endif
23 
24 // This is a very dirty way to "normalize" numbers w.r.t. a
25 // MinPoly
26 
27 #define MAX_MAP_DEG 128
28 
29 /*2
30 * copy a map
31 */
32 map maCopy(map theMap, const ring r)
33 {
34  int i;
35  map m=(map)idInit(IDELEMS(theMap),0);
36  for (i=IDELEMS(theMap)-1; i>=0; i--)
37  m->m[i] = p_Copy(theMap->m[i],r);
38  m->preimage=omStrDup(theMap->preimage);
39  return m;
40 }
41 
42 
43 /*2
44 * return the image of var(v)^pExp, where var(v) maps to p
45 */
46 poly maEvalVariable(poly p, int v,int pExp, ideal s, const ring dst_r)
47 {
48  if (pExp==1)
49  return p_Copy(p,dst_r);
50 
51  poly res;
52 
53  if((s!=NULL)&&(pExp<MAX_MAP_DEG))
54  {
55  int j=2;
56  poly p0=p;
57  // find starting point
58  if(MATELEM(s,v,1)==NULL)
59  {
60  MATELEM(s,v,1)=p_Copy(p/*theMap->m[v-1]*/,dst_r);
61  }
62  else
63  {
64  while((j<=pExp)&&(MATELEM(s,v,j)!=NULL))
65  {
66  j++;
67  }
68  p0=MATELEM(s,v,j-1);
69  }
70  // multiply
71  for(;j<=pExp;j++)
72  {
73  p0=MATELEM(s,v,j)=pp_Mult_qq(p0, p,dst_r);
74  p_Normalize(p0, dst_r);
75  }
76  res=p_Copy(p0/*MATELEM(s,v,pExp)*/,dst_r);
77  }
78  else //if ((p->next!=NULL)&&(p->next->next==NULL))
79  {
80  res=p_Power(p_Copy(p,dst_r),pExp,dst_r);
81  }
82  return res;
83 }
84 
85 static poly maEvalMonom(map theMap, poly p,ring preimage_r, ideal s,
86  nMapFunc nMap, const ring dst_r)
87 {
88  p_Test(p,preimage_r);
89  poly q=p_NSet(nMap(pGetCoeff(p),preimage_r->cf,dst_r->cf),dst_r);
90 
91  int i;
92  for(i=1;i<=preimage_r->N; i++)
93  {
94  int pExp=p_GetExp( p,i,preimage_r);
95  if (pExp != 0)
96  {
97  if (theMap->m[i-1]!=NULL)
98  {
99  poly p1=theMap->m[i-1];
100  poly pp=maEvalVariable(p1,i,pExp,s,dst_r);
101  q = p_Mult_q(q,pp,dst_r);
102  }
103  else
104  {
105  p_Delete(&q,dst_r);
106  break;
107  }
108  }
109  }
110  int modulComp = p_GetComp( p,preimage_r);
111  if (q!=NULL) p_SetCompP(q,modulComp,dst_r);
112  return q;
113 }
114 
115 poly maEval(map theMap, poly p,ring preimage_r,nMapFunc nMap, ideal s, const ring dst_r)
116 {
117  poly result = NULL;
118  int i;
119 
120 // for(i=1; i<=preimage_r->N; i++)
121 // {
122 // pTest(theMap->m[i-1]);
123 // }
124 // while (p!=NULL)
125 // {
126 // poly q=maEvalMonom(theMap,p,preimage_r,s);
127 // result = pAdd(result,q);
128 // pIter(p);
129 // }
130  if (p!=NULL)
131  {
132  int l = pLength(p)-1;
133  poly* monoms;
134  if (l>0)
135  {
136  monoms = (poly*) omAlloc(l*sizeof(poly));
137 
138  for (i=0; i<l; i++)
139  {
140  monoms[i]=maEvalMonom(theMap,p,preimage_r,s, nMap, dst_r);
141  pIter(p);
142  }
143  }
144  result=maEvalMonom(theMap,p,preimage_r,s, nMap, dst_r);
145  if (l>0)
146  {
147  for(i = l-1; i>=0; i--)
148  {
149  result=p_Add_q(result, monoms[i], dst_r);
150  }
151  omFreeSize((ADDRESS)monoms,l*sizeof(poly));
152  }
153 
154  assume(dst_r != NULL);
155  assume(dst_r->cf != NULL);
156 
157  if (nCoeff_is_algExt(dst_r->cf))
158  result = p_MinPolyNormalize(result, dst_r);
159  }
160  return result;
161 }
162 
163 void maFindPerm(char const * const * const preim_names, int preim_n, char const * const * const preim_par, int preim_p,
164  char const * const * const names, int n, char const * const * const par, int nop,
165  int * perm, int *par_perm, n_coeffType ch)
166 {
167  int i,j;
168  /* find correspondig vars */
169  for (i=0; i<preim_n; i++)
170  {
171  for(j=0; j<n; j++)
172  {
173  if (strcmp(preim_names[i],names[j])==0)
174  {
175  if (BVERBOSE(V_IMAP))
176  Print("// var %s: nr %d -> nr %d\n",preim_names[i],i+1,j+1);
177  /* var i+1 from preimage ring is var j+1 (index j+1) from image ring */
178  perm[i+1]=j+1;
179  break;
180  }
181  }
182  if ((perm[i+1]==0)&&(par!=NULL)
183  // do not consider par of Fq
184  && (ch!=n_GF))
185  {
186  for(j=0; j<nop; j++)
187  {
188  if (strcmp(preim_names[i],par[j])==0)
189  {
190  if (BVERBOSE(V_IMAP))
191  Print("// var %s: nr %d -> par %d\n",preim_names[i],i+1,j+1);
192  /* var i+1 from preimage ring is par j+1 (index j) from image ring */
193  perm[i+1]=-(j+1);
194  }
195  }
196  }
197  }
198  if (par_perm!=NULL)
199  {
200  for (i=0; i<preim_p; i++)
201  {
202  for(j=0; j<n; j++)
203  {
204  if (strcmp(preim_par[i],names[j])==0)
205  {
206  if (BVERBOSE(V_IMAP))
207  Print("// par %s: par %d -> nr %d\n",preim_par[i],i+1,j+1);
208  /*par i+1 from preimage ring is var j+1 (index j+1) from image ring*/
209  par_perm[i]=j+1;
210  break;
211  }
212  }
213  if ((par!=NULL) && (par_perm[i]==0))
214  {
215  for(j=0; j<nop; j++)
216  {
217  if (strcmp(preim_par[i],par[j])==0)
218  {
219  if (BVERBOSE(V_IMAP))
220  Print("// par %s: nr %d -> par %d\n",preim_par[i],i+1,j+1);
221  /*par i+1 from preimage ring is par j+1 (index j) from image ring */
222  par_perm[i]=-(j+1);
223  }
224  }
225  }
226  }
227  }
228 }
229 
230 #ifdef HAVE_SHIFTBBA
231 void maFindPermLP(char const * const * const preim_names, int preim_n, char const * const * const preim_par, int preim_p,
232  char const * const * const names, int n, char const * const * const par, int nop,
233  int * perm, int *par_perm, n_coeffType ch, int lV)
234 {
235  int i,j,b;
236  /* find correspondig vars */
237  for (b=0;b<preim_n/lV;b++)
238  {
239  for (i=b*lV; i<(b+1)*lV; i++)
240  {
241  int cnt=0;
242  for(j=0; j<n; j++)
243  {
244  if (strcmp(preim_names[i],names[j])==0)
245  {
246  if (cnt==b)
247  {
248  if (BVERBOSE(V_IMAP))
249  Print("// var %s: nr %d -> nr %d\n",preim_names[i],i+1,j+1);
250  /* var i+1 from preimage ring is var j+1 (index j+1) from image ring */
251  perm[i+1]=j+1;
252  break;
253  }
254  else cnt++;
255  }
256  }
257  if ((perm[i+1]==0)&&(par!=NULL)
258  // do not consider par of Fq
259  && (ch!=n_GF))
260  {
261  for(j=0; j<nop; j++)
262  {
263  if (strcmp(preim_names[i],par[j])==0)
264  {
265  if (BVERBOSE(V_IMAP))
266  Print("// var %s: nr %d -> par %d\n",preim_names[i],i+1,j+1);
267  /* var i+1 from preimage ring is par j+1 (index j) from image ring */
268  perm[i+1]=-(j+1);
269  }
270  }
271  }
272  }
273  }
274  if (par_perm!=NULL)
275  {
276  for (i=0; i<preim_p; i++)
277  {
278  for(j=0; j<n; j++)
279  {
280  if (strcmp(preim_par[i],names[j])==0)
281  {
282  if (BVERBOSE(V_IMAP))
283  Print("// par %s: par %d -> nr %d\n",preim_par[i],i+1,j+1);
284  /*par i+1 from preimage ring is var j+1 (index j+1) from image ring*/
285  par_perm[i]=j+1;
286  break;
287  }
288  }
289  if ((par!=NULL) && (par_perm[i]==0))
290  {
291  for(j=0; j<nop; j++)
292  {
293  if (strcmp(preim_par[i],par[j])==0)
294  {
295  if (BVERBOSE(V_IMAP))
296  Print("// par %s: nr %d -> par %d\n",preim_par[i],i+1,j+1);
297  /*par i+1 from preimage ring is par j+1 (index j) from image ring */
298  par_perm[i]=-(j+1);
299  }
300  }
301  }
302  }
303  }
304 }
305 #endif
306 
307 /*2
308 * embeds poly p from the subring r into the current ring
309 */
310 poly maIMap(ring r, poly p, const ring dst_r)
311 {
312  /* the simplest case:*/
313  if(r==dst_r) return p_Copy(p,dst_r);
314  nMapFunc nMap=n_SetMap(r->cf,dst_r->cf);
315  int *perm=(int *)omAlloc0((r->N+1)*sizeof(int));
316  //int *par_perm=(int *)omAlloc0(rPar(r)*sizeof(int));
317  maFindPerm(r->names, rVar(r), rParameter(r), rPar(r),
318  dst_r->names, rVar(dst_r),rParameter(dst_r), rPar(dst_r),
319  perm,NULL, dst_r->cf->type);
320  poly res=p_PermPoly(p,perm,r,dst_r, nMap /*,par_perm,rPar(r)*/);
321  omFreeSize((ADDRESS)perm,(r->N+1)*sizeof(int));
322  //omFreeSize((ADDRESS)par_perm,rPar(r)*sizeof(int));
323  return res;
324 }
325 
326 /*3
327 * find the max. degree in one variable, but not larger than MAX_MAP_DEG
328 */
329 int maMaxDeg_Ma(ideal a,ring preimage_r)
330 {
331  int i,j;
332  int N = preimage_r->N;
333  poly p;
334  int *m=(int *)omAlloc0(N*sizeof(int));
335 
336  for (i=MATROWS(a)*MATCOLS(a)-1;i>=0;i--)
337  {
338  p=a->m[i];
339  //pTest(p); // cannot test p because it is from another ring
340  while(p!=NULL)
341  {
342  for(j=N-1;j>=0;j--)
343  {
344  m[j]=si_max(m[j],(int)p_GetExp( p,j+1,preimage_r));
345  if (m[j]>=MAX_MAP_DEG)
346  {
347  i=MAX_MAP_DEG;
348  goto max_deg_fertig_id;
349  }
350  }
351  pIter(p);
352  }
353  }
354  i=m[0];
355  for(j=N-1;j>0;j--)
356  {
357  i=si_max(i,m[j]);
358  }
359 max_deg_fertig_id:
360  omFreeSize((ADDRESS)m,N*sizeof(int));
361  return i;
362 }
363 
364 /*3
365 * find the max. degree in one variable, but not larger than MAX_MAP_DEG
366 */
367 int maMaxDeg_P(poly p,ring preimage_r)
368 {
369  int i,j;
370  int N = preimage_r->N;
371  int *m=(int *)omAlloc0(N*sizeof(int));
372 
373 // pTest(p);
374  while(p!=NULL)
375  {
376  for(j=N-1;j>=0;j--)
377  {
378  m[j]=si_max(m[j],(int)p_GetExp(p,j+1,preimage_r));
379  if (m[j]>=MAX_MAP_DEG)
380  {
381  i=MAX_MAP_DEG;
382  goto max_deg_fertig_p;
383  }
384  }
385  pIter(p);
386  }
387  i=m[0];
388  for(j=N-1;j>0;j--)
389  {
390  i=si_max(i,m[j]);
391  }
392 max_deg_fertig_p:
393  omFreeSize((ADDRESS)m,N*sizeof(int));
394  return i;
395 }
396 
397 // This is a very dirty way to cancel monoms whose number equals the
398 // MinPoly
399 poly p_MinPolyNormalize(poly p, const ring r)
400 {
401  const coeffs C = r->cf;
402  number one = n_Init(1, C);
403  spolyrec rp;
404 
405  poly q = &rp;
406 
407  while (p != NULL)
408  {
409  // this returns 0, if p == MinPoly
410  number product = n_Mult(p_GetCoeff(p, r), one, C);
411  if ((product == NULL)||(n_IsZero(product, C)))
412  {
413  p_LmDelete(&p, r);
414  }
415  else
416  {
417  p_SetCoeff(p, product, r);
418  pNext(q) = p;
419  q = p;
420  p = pNext(p);
421  }
422  }
423  pNext(q) = NULL;
424  n_Delete(&one, C);
425  return rp.next;
426 }
All the auxiliary stuff.
static int si_max(const int a, const int b)
Definition: auxiliary.h:140
void * ADDRESS
Definition: auxiliary.h:135
CanonicalForm pp(const CanonicalForm &)
CanonicalForm pp ( const CanonicalForm & f )
Definition: cf_gcd.cc:248
const CanonicalForm CFMap CFMap & N
Definition: cfEzgcd.cc:49
int l
Definition: cfEzgcd.cc:93
int m
Definition: cfEzgcd.cc:121
int i
Definition: cfEzgcd.cc:125
int p
Definition: cfModGcd.cc:4019
CanonicalForm b
Definition: cfModGcd.cc:4044
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
Coefficient rings, fields and other domains suitable for Singular polynomials.
static FORCE_INLINE number n_Mult(number a, number b, const coeffs r)
return the product of 'a' and 'b', i.e., a*b
Definition: coeffs.h:636
n_coeffType
Definition: coeffs.h:28
@ n_GF
\GF{p^n < 2^16}
Definition: coeffs.h:33
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:721
static FORCE_INLINE BOOLEAN n_IsZero(number n, const coeffs r)
TRUE iff 'n' represents the zero element.
Definition: coeffs.h:464
static FORCE_INLINE void n_Delete(number *p, const coeffs r)
delete 'p'
Definition: coeffs.h:455
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:538
static FORCE_INLINE BOOLEAN nCoeff_is_algExt(const coeffs r)
TRUE iff r represents an algebraic extension field.
Definition: coeffs.h:932
number(* nMapFunc)(number a, const coeffs src, const coeffs dst)
maps "a", which lives in src, into dst
Definition: coeffs.h:73
#define Print
Definition: emacs.cc:80
return result
Definition: facAbsBiFact.cc:76
const CanonicalForm int s
Definition: facAbsFact.cc:55
CanonicalForm res
Definition: facAbsFact.cc:64
const Variable & v
< [in] a sqrfree bivariate poly
Definition: facBivar.h:37
int j
Definition: facHensel.cc:105
map maCopy(map theMap, const ring r)
Definition: maps.cc:32
poly maEval(map theMap, poly p, ring preimage_r, nMapFunc nMap, ideal s, const ring dst_r)
Definition: maps.cc:115
poly maIMap(ring r, poly p, const ring dst_r)
Definition: maps.cc:310
int maMaxDeg_P(poly p, ring preimage_r)
Definition: maps.cc:367
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:163
static poly maEvalMonom(map theMap, poly p, ring preimage_r, ideal s, nMapFunc nMap, const ring dst_r)
Definition: maps.cc:85
void maFindPermLP(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, int lV)
Definition: maps.cc:231
poly maEvalVariable(poly p, int v, int pExp, ideal s, const ring dst_r)
Definition: maps.cc:46
int maMaxDeg_Ma(ideal a, ring preimage_r)
Definition: maps.cc:329
poly p_MinPolyNormalize(poly p, const ring r)
Definition: maps.cc:399
#define MAX_MAP_DEG
Definition: maps.cc:27
#define MATELEM(mat, i, j)
1-based access to matrix
Definition: matpol.h:29
#define MATROWS(i)
Definition: matpol.h:26
#define MATCOLS(i)
Definition: matpol.h:27
#define assume(x)
Definition: mod2.h:390
#define p_GetComp(p, r)
Definition: monomials.h:64
poly next
Definition: monomials.h:24
#define pIter(p)
Definition: monomials.h:37
#define pNext(p)
Definition: monomials.h:36
static number & pGetCoeff(poly p)
return an alias to the leading coefficient of p assumes that p != NULL NOTE: not copy
Definition: monomials.h:44
#define p_GetCoeff(p, r)
Definition: monomials.h:50
The main handler for Singular numbers which are suitable for Singular polynomials.
#define omStrDup(s)
Definition: omAllocDecl.h:263
#define omFreeSize(addr, size)
Definition: omAllocDecl.h:260
#define omAlloc(size)
Definition: omAllocDecl.h:210
#define omAlloc0(size)
Definition: omAllocDecl.h:211
#define NULL
Definition: omList.c:12
#define BVERBOSE(a)
Definition: options.h:34
#define V_IMAP
Definition: options.h:52
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:4036
poly p_Power(poly p, int i, const ring r)
Definition: p_polys.cc:2172
void p_Normalize(poly p, const ring r)
Definition: p_polys.cc:3732
poly p_NSet(number n, const ring r)
returns the poly representing the number n, destroys n
Definition: p_polys.cc:1455
static poly p_Add_q(poly p, poly q, const ring r)
Definition: p_polys.h:895
static void p_LmDelete(poly p, const ring r)
Definition: p_polys.h:710
static poly p_Mult_q(poly p, poly q, const ring r)
Definition: p_polys.h:1053
static void p_SetCompP(poly p, int i, ring r)
Definition: p_polys.h:253
static number p_SetCoeff(poly p, number n, ring r)
Definition: p_polys.h:411
static long p_GetExp(const poly p, const unsigned long iBitmask, const int VarOffset)
get a single variable exponent @Note: the integer VarOffset encodes:
Definition: p_polys.h:468
static void p_Delete(poly *p, const ring r)
Definition: p_polys.h:860
static unsigned pLength(poly a)
Definition: p_polys.h:191
static poly pp_Mult_qq(poly p, poly q, const ring r)
Definition: p_polys.h:1090
static poly p_Copy(poly p, const ring r)
returns a copy of p
Definition: p_polys.h:811
#define p_Test(p, r)
Definition: p_polys.h:162
static char const ** rParameter(const ring r)
(r->cf->parameter)
Definition: ring.h:620
static int rPar(const ring r)
(r->cf->P)
Definition: ring.h:594
static short rVar(const ring r)
#define rVar(r) (r->N)
Definition: ring.h:587
ideal idInit(int idsize, int rank)
initialise an ideal / module
Definition: simpleideals.cc:35
#define IDELEMS(i)
Definition: simpleideals.h:23