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