My Project
Loading...
Searching...
No Matches
gen_maps.h File Reference

Go to the source code of this file.

Functions

ideal maMapIdeal (const ideal map_id, const ring map_r, const ideal image_id, const ring image_r, const nMapFunc nMap)
 polynomial map for ideals/module/matrix map_id: the ideal to map map_r: the base ring for map_id image_id: the image of the variables image_r: the base ring for image_id nMap: map for coefficients
poly maMapPoly (const poly map_p, const ring map_r, const ideal image_id, const ring image_r, const nMapFunc nMap)
 polynomial map for poly (vector) map_p: the poly (vector) to map map_r: the base ring for map_p image_id: the image of the variables image_r: the base ring for image_id nMap: map for coefficients
poly p_SubstPoly (poly p, int var, poly image, const ring preimage_r, const ring image_r, const nMapFunc nMap, matrix cache=NULL)
ideal id_SubstPoly (ideal id, int var, poly image, const ring preimage_r, const ring image_r, const nMapFunc nMap)
number maEvalAt (const poly p, const number *pt, const ring r)
 evaluate the polynomial p at the pt given by the array pt

Function Documentation

◆ id_SubstPoly()

ideal id_SubstPoly ( ideal id,
int var,
poly image,
const ring preimage_r,
const ring image_r,
const nMapFunc nMap )

Definition at line 78 of file subst_maps.cc.

79{
80 matrix cache=mpNew(preimage_r->N,maMaxDeg_Ma(id, preimage_r));
81 int k=MATROWS((matrix)id)*MATCOLS((matrix)id);
82 ideal res=(ideal)mpNew(MATROWS((matrix)id),MATCOLS((matrix)id));
83 res->rank = id->rank;
84 for(k--;k>=0;k--)
85 {
86 res->m[k]=p_SubstPoly(id->m[k],var,image,preimage_r,image_r,nMap,cache);
87 }
88 id_Delete((ideal*)&cache,image_r);
89 return res;
90}
int k
Definition cfEzgcd.cc:99
poly * m
Definition matpol.h:18
CanonicalForm res
Definition facAbsFact.cc:60
int maMaxDeg_Ma(ideal a, ring preimage_r)
Definition maps.cc:352
matrix mpNew(int r, int c)
create a r x c zero-matrix
Definition matpol.cc:37
ip_smatrix * matrix
Definition matpol.h:43
#define MATROWS(i)
Definition matpol.h:26
#define MATCOLS(i)
Definition matpol.h:27
void id_Delete(ideal *h, ring r)
deletes an ideal/module/matrix
poly p_SubstPoly(poly p, int var, poly image, const ring preimage_r, const ring image_r, const nMapFunc nMap, matrix cache)
Definition subst_maps.cc:46

◆ maEvalAt()

number maEvalAt ( const poly p,
const number * pt,
const ring r )

evaluate the polynomial p at the pt given by the array pt

Definition at line 174 of file gen_maps.cc.

175{
176 ideal map=idInit(r->N,1);
177 for(int i=r->N-1;i>=0;i--)
178 {
179 map->m[i]=p_NSet(n_Copy(pt[i],r->cf),r);
180 }
181 poly v=maMapPoly(p,r,map,r,ndCopyMap);
182 id_Delete(&map,r);
183 number vv;
184 if (v==NULL)
185 vv=n_Init(0,r->cf);
186 else
187 {
188 vv=pGetCoeff(v);
189 p_LmFree(&v,r);
190 }
191 return vv;
192}
int i
Definition cfEzgcd.cc:132
int p
Definition cfModGcd.cc:4086
CanonicalForm map(const CanonicalForm &primElem, const Variable &alpha, const CanonicalForm &F, const Variable &beta)
map from to such that is mapped onto
static FORCE_INLINE number n_Copy(number n, const coeffs r)
return a copy of 'n'
Definition coeffs.h:457
number ndCopyMap(number a, const coeffs src, const coeffs dst)
Definition numbers.cc:293
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
const Variable & v
< [in] a sqrfree bivariate poly
Definition facBivar.h:39
poly maMapPoly(const poly map_p, const ring map_r, const ideal image_id, const ring image_r, const nMapFunc nMap)
polynomial map for poly (vector) map_p: the poly (vector) to map map_r: the base ring for map_p image...
Definition gen_maps.cc:166
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 NULL
Definition omList.c:12
poly p_NSet(number n, const ring r)
returns the poly representing the number n, destroys n
Definition p_polys.cc:1474
static void p_LmFree(poly p, ring)
Definition p_polys.h:685
ideal idInit(int idsize, int rank)
initialise an ideal / module

◆ maMapIdeal()

ideal maMapIdeal ( const ideal map_id,
const ring map_r,
const ideal image_id,
const ring image_r,
const nMapFunc nMap )

polynomial map for ideals/module/matrix map_id: the ideal to map map_r: the base ring for map_id image_id: the image of the variables image_r: the base ring for image_id nMap: map for coefficients

Definition at line 88 of file gen_maps.cc.

89{
90 // handle special cases
91 if (IDELEMS(map_id)<=0)
92 return idInit(0,map_id->rank);
93 if(!rIsNCRing(image_r))
94 {
95 // heuristic:
96 // is the map a permutation ?
97 matrix m=ma_ApplyPermForMap((matrix)map_id,preimage_r,image_id,image_r,nMap);
98 if (m!=NULL)
99 {
100 if (TEST_OPT_PROT) PrintS("map is a permutation\n");
101 return (ideal)m;
102 }
103 // ----------------------------------------------------------
104 // is it a substitution of one variable ?
105 {
106 poly p;
107 int var;
108 find_subst_for_map(preimage_r,image_r,image_id,var,p);
109 if (var!=0)
110 {
111 if (TEST_OPT_PROT) PrintS("map is a substitution\n");
112 return id_SubstPoly(map_id,var,p,preimage_r,image_r,nMap);
113 }
114 }
115 // ----------------------------------------------------------
116 // long polys in the image ?: possibility of many common subexpressions
117 if ((nMap==ndCopyMap) /* and !rIsPluralRing(image_r) */
118 && (map_id->nrows==1) /* i.e. only for ideal/map */
119 && (map_id->rank==1))
120 {
121 int sz=IDELEMS(image_id);
122 int sz_l=0;
123 int i;
124 int sz_source=0;
125 for(i=IDELEMS(map_id)-1;i>=0;i--)
126 {
127 sz_source+=pLength(map_id->m[i]);
128 }
129 for(i=IDELEMS(image_id)-1;i>=0;i--)
130 {
131 sz_l+=pLength(image_id->m[i]);
132 }
133 // few, but complex terms: sz_l/sz large, or few variables,
134 // or sz_source small
135 //printf("avg term len map:%d,N=%d, avg.image len:%d, im.len:%d\n",sz_l/sz,sz,sz_source/IDELEMS(image_id),sz_source);
136 if ((sz_l > sz*5)||(sz<5)||(sz_source<100))
137 {
138 if (TEST_OPT_PROT) PrintS("map via common subexpressions\n");
139 return fast_map_common_subexp(map_id, preimage_r, image_id, image_r);
140 }
141 }
142 }
143 // ----------------------------------------------------------
144 // otherwise: try the generic method (generic map with cache)
145 if (TEST_OPT_PROT) PrintS("map with cache\n");
146 int C=((matrix)map_id)->cols();
147 int R=((matrix)map_id)->rows();
148 matrix m=mpNew(R,C);
149 int N = preimage_r->N;
150 matrix cache=mpNew(N,maMaxDeg_Ma(map_id,preimage_r));
151 int i;
152 for (i=R*C-1;i>=0;i--)
153 {
154 if (map_id->m[i]!=NULL)
155 {
156 m->m[i]=maEval((map)image_id, map_id->m[i], preimage_r, nMap, (ideal)cache, image_r);
157 p_Test(m->m[i],image_r);
158 }
159 }
160 idDelete((ideal *)&cache);
161 ideal ii=(ideal)m;
162 ii->rank=((ideal)map_id)->rank;
163 return (ideal)m;
164}
const CanonicalForm CFMap CFMap & N
Definition cfEzgcd.cc:56
int m
Definition cfEzgcd.cc:128
ideal fast_map_common_subexp(const ideal map_id, const ring map_r, const ideal image_id, const ring image_r)
Definition fast_maps.cc:354
matrix ma_ApplyPermForMap(const matrix to_map, const ring preimage_r, const ideal image, const ring image_r, const nMapFunc nMap)
helper function for maMapIdeal mapping ideal/matrix/module for the case of a permutation: maps the id...
Definition find_perm.cc:69
static void find_subst_for_map(const ring preimage_r, const ring image_r, const ideal image, int &var, poly &p)
Definition gen_maps.cc:16
ideal id_SubstPoly(ideal id, int var, poly image, const ring preimage_r, const ring image_r, const nMapFunc nMap)
Definition subst_maps.cc:78
#define idDelete(H)
delete an ideal
Definition ideals.h:29
poly maEval(map theMap, poly p, ring preimage_r, nMapFunc nMap, ideal s, const ring dst_r)
Definition maps.cc:117
#define TEST_OPT_PROT
Definition options.h:105
static int pLength(poly a)
Definition p_polys.h:190
#define p_Test(p, r)
Definition p_polys.h:161
void PrintS(const char *s)
Definition reporter.cc:288
static BOOLEAN rIsNCRing(const ring r)
Definition ring.h:427
#define IDELEMS(i)
#define R
Definition sirandom.c:27

◆ maMapPoly()

poly maMapPoly ( const poly map_p,
const ring map_r,
const ideal image_id,
const ring image_r,
const nMapFunc nMap )

polynomial map for poly (vector) map_p: the poly (vector) to map map_r: the base ring for map_p image_id: the image of the variables image_r: the base ring for image_id nMap: map for coefficients

Definition at line 166 of file gen_maps.cc.

167{
168 matrix s=mpNew(map_r->N,maMaxDeg_P(map_p, map_r));
169 poly p=maEval((map)image_id, map_p, map_r, nMap, (ideal)s, image_r);
170 id_Delete((ideal*)&s,image_r);
171 return p;
172}
const CanonicalForm int s
Definition facAbsFact.cc:51
int maMaxDeg_P(poly p, ring preimage_r)
Definition maps.cc:390

◆ p_SubstPoly()

poly p_SubstPoly ( poly p,
int var,
poly image,
const ring preimage_r,
const ring image_r,
const nMapFunc nMap,
matrix cache = NULL )

Definition at line 46 of file subst_maps.cc.

47{
48 if (p==NULL) return NULL;
49
50 if (rIsNCRing(image_r))
51 {
52 if((image_r!=preimage_r)
53 ||(preimage_r!=currRing))
54 {
55 WerrorS("not implemented");
56 return NULL;
57 }
58 return pSubst(pCopy(p),var,image);
59 }
60 matrix org_cache=cache;
61 if (cache==NULL) cache=mpNew(preimage_r->N,maMaxDeg_P(p, preimage_r));
62
63 poly result = NULL;
64 sBucket_pt bucket = sBucketCreate(image_r);
65 while (p != NULL)
66 {
67 poly q=p_SubstMon(p,var,image,preimage_r,image_r,nMap,cache);
68 pIter(p);
69 if (q!=NULL) sBucket_Add_p(bucket,q,pLength(q));
70 }
71 int l_dummy;
72 sBucketDestroyAdd(bucket, &result, &l_dummy);
73 /*if no cache was passed,it is a local cache: */
74 if (org_cache==NULL) id_Delete((ideal*)&cache,image_r);
75 return result;
76}
return result
void WerrorS(const char *s)
Definition feFopen.cc:24
#define pIter(p)
Definition monomials.h:37
VAR ring currRing
Widely used global variable which specifies the current polynomial ring for Singular interpreter and ...
Definition polys.cc:13
#define pSubst(p, n, e)
Definition polys.h:366
#define pCopy(p)
return a copy of the poly
Definition polys.h:186
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
static poly p_SubstMon(poly p, int var, poly image, const ring preimage_r, const ring image_r, const nMapFunc nMap, matrix cache)
Definition subst_maps.cc:8