My Project
Loading...
Searching...
No Matches
prCopy.cc
Go to the documentation of this file.
1/****************************************
2* Computer Algebra System SINGULAR *
3****************************************/
4/*
5* ABSTRACT - implementation of functions for Copy/Move/Delete for Polys
6*/
7
8
9#include "misc/auxiliary.h"
10
13#include "coeffs/numbers.h"
15#include "polys/simpleideals.h"
16
17static inline void
18prCopyEvector(poly dest, ring dest_r, poly src, ring src_r,int max)
19{
20 //memset(dest->exp,0,dest_r->ExpL_Size*sizeof(long));
21 int i;
22 for (i=max; i>0; i--)
23 {
24 p_SetExp(dest, i, p_GetExp( src, i,src_r), dest_r);
25 }
26 if (rRing_has_Comp(dest_r) && rRing_has_Comp(src_r))
27 p_SetComp(dest, p_GetComp( src,src_r), dest_r);
28 p_Setm(dest, dest_r);
29}
30
31#include "polys/prCopy.inc"
32
33/////////////////////////////////////////////////////////////////////////
34poly prCopyR(poly p, ring src_r, ring dest_r)
35{
36 poly res;
37 if (rField_has_simple_Alloc(dest_r))
38 res = pr_Copy_NoREqual_NSimple_Sort(p, src_r, dest_r);
39 else
40 res = pr_Copy_NoREqual_NoNSimple_Sort(p, src_r, dest_r);
41 p_Test(res, dest_r);
42 return res;
43}
44
45poly prMapR(poly src, nMapFunc nMap, ring src_r, ring dest_r)
46{
47 if (src==NULL) return NULL;
48 int _min = si_min(dest_r->N, src_r->N);
49
50 spolyrec dest_s;
51
52 poly dest = &dest_s;
53
54 poly prev;
55 while (src != NULL)
56 {
57 pNext(dest) = (poly) p_Init(dest_r);
58 prev = dest;
59 pIter(dest);
60
61 pSetCoeff0(dest, nMap(pGetCoeff(src),src_r->cf,dest_r->cf));
62 prCopyEvector(dest, dest_r, src, src_r, _min);
63 if (n_IsZero(pGetCoeff(dest),dest_r->cf))
64 {
65 p_LmDelete(&pNext(prev),dest_r);
66 dest=prev;
67 }
68 pIter(src);
69 }
70 pNext(dest) = NULL;
71 dest = pNext(&dest_s);
72 dest=p_SortAdd(dest, dest_r);
73 p_Test(dest, dest_r);
74 return dest;
75}
76
77poly prCopyR_NoSort(poly p, ring src_r, ring dest_r)
78{
79 poly res;
80 if (rField_has_simple_Alloc(dest_r))
81 res = pr_Copy_NoREqual_NSimple_NoSort(p, src_r, dest_r);
82 else
83 res = pr_Copy_NoREqual_NoNSimple_NoSort(p, src_r, dest_r);
84 p_Test(res, dest_r);
85 return res;
86}
87
88/////////////////////////////////////////////////////////////////////////
89// prMove
90poly prMoveR(poly &p, ring src_r, ring dest_r)
91{
92 poly res;
93 if (rField_has_simple_Alloc(dest_r))
94 res = pr_Move_NoREqual_NSimple_Sort(p, src_r, dest_r);
95 else
96 res = pr_Move_NoREqual_NoNSimple_Sort(p, src_r, dest_r);
97 p_Test(res, dest_r);
98 return res;
99}
100
101poly prMoveR_NoSort(poly &p, ring src_r, ring dest_r)
102{
103 poly res;
104 if (rField_has_simple_Alloc(dest_r))
105 res = pr_Move_NoREqual_NSimple_NoSort(p, src_r, dest_r);
106 else
107 res = pr_Move_NoREqual_NoNSimple_NoSort(p, src_r, dest_r);
108 p_Test(res, dest_r);
109 return res;
110}
111
112poly prShallowCopyR_NoSort(poly p, ring r, ring dest_r)
113{
114 return pr_Copy_NoREqual_NSimple_NoSort(p, r, dest_r);
115}
116
117poly prShallowCopyR(poly p, ring r, ring dest_r)
118{
119 return pr_Copy_NoREqual_NSimple_Sort(p, r, dest_r);
120}
121
122/////////////////////////////////////////////////////////////////////////
123// prHead
124typedef poly (*prCopyProc_t)(poly &src_p, ring src_r, ring dest_r);
125
126poly prHeadR(poly p, ring src_r, ring dest_r, prCopyProc_t prproc)
127{
128 if (p == NULL) return NULL;
129 poly tail, head, q = p;
130 tail = pNext(p);
131 pNext(p) = NULL;
132 head = prproc(q, src_r, dest_r);
133 pNext(p) = tail;
134
135 p_Test(p, src_r);
136 p_Test(head, dest_r);
137
138 return head;
139}
140
141poly prHeadR(poly p, ring src_r, ring dest_r)
142{
143 prCopyProc_t prproc;
144 if (rField_has_simple_Alloc(dest_r))
145 prproc = pr_Copy_NoREqual_NSimple_NoSort;
146 else
147 prproc = pr_Copy_NoREqual_NoNSimple_NoSort;
148
149 const poly res = prHeadR(p, src_r, dest_r, prproc);
150 p_Test(res, dest_r);
151 return res;
152}
153
154/////////////////////////////////////////////////////////////////////////
155/// Copy leading terms of id[i] via prHeeadR into dest_r
156ideal idrHeadR(ideal id, ring r, ring dest_r)
157{
158 if (id == NULL) return NULL;
159
160 prCopyProc_t prproc = pr_Copy_NoREqual_NoNSimple_NoSort;
161 if (rField_has_simple_Alloc(dest_r))
162 prproc = pr_Copy_NoREqual_NSimple_NoSort;
163
164 const int N = IDELEMS(id);
165 ideal res = idInit(N, id->rank);
166
167 for (int i = N - 1; i >= 0; i--)
168 res->m[i] = prHeadR(id->m[i], r, dest_r, prproc); // !!!
169
170 return res;
171}
172
173
174static inline ideal
175idrCopy(ideal id, ring src_r, ring dest_r, prCopyProc_t prproc)
176{
177 if (id == NULL) return NULL;
178 assume(src_r->cf==dest_r->cf);
179 poly p;
180 ideal res = idInit(IDELEMS(id), id->rank);
181 int i;
182
183 for (i=IDELEMS(id)-1; i>=0; i--)
184 {
185 p = id->m[i];
186 res->m[i] = prproc(p, src_r, dest_r);
187 p_Test(res->m[i], dest_r);
188 }
189 return res;
190}
191
192ideal idrCopyR(ideal id, ring src_r, ring dest_r)
193{
194 assume(src_r->cf==dest_r->cf);
195 ideal res;
196 prCopyProc_t prproc;
197 if (rField_has_simple_Alloc(dest_r))
198 prproc = pr_Copy_NoREqual_NSimple_Sort;
199 else
200 prproc = pr_Copy_NoREqual_NoNSimple_Sort;
201 res = idrCopy(id, src_r, dest_r, prproc);
202 return res;
203}
204
205ideal idrCopyR_NoSort(ideal id, ring src_r, ring dest_r)
206{
207 assume(src_r->cf==dest_r->cf);
208 ideal res;
209 prCopyProc_t prproc;
210 if (rField_has_simple_Alloc(dest_r))
211 prproc = pr_Copy_NoREqual_NSimple_NoSort;
212 else
213 prproc = pr_Copy_NoREqual_NoNSimple_NoSort;
214 res = idrCopy(id, src_r, dest_r, prproc);
215 return res;
216}
217
218/////////////////////////////////////////////////////////////////////////
219// idrShallowCopy
220ideal idrShallowCopyR(ideal id, ring src_r, ring dest_r)
221{
222 return idrCopy(id, src_r, dest_r, pr_Copy_NoREqual_NSimple_Sort);
223}
224
225ideal idrShallowCopyR_NoSort(ideal id, ring src_r, ring dest_r)
226{
227 return idrCopy(id, src_r, dest_r, pr_Copy_NoREqual_NSimple_NoSort);
228}
229
230/////////////////////////////////////////////////////////////////////////
231// idrMove
232static inline ideal
233idrMove(ideal &id, ring src_r, ring dest_r, prCopyProc_t prproc)
234{
235 assume(src_r->cf==dest_r->cf);
236 assume( prproc != NULL );
237
238 if (id == NULL) return NULL;
239
240 ideal res = id; id = NULL;
241
242 for (int i = IDELEMS(res) - 1; i >= 0; i--)
243 res->m[i] = prproc(res->m[i], src_r, dest_r);
244
245 return res;
246}
247
248ideal idrMoveR(ideal &id, ring src_r, ring dest_r)
249{
250 assume(src_r->cf==dest_r->cf);
251 prCopyProc_t prproc;
252 ideal res;
253 if (rField_has_simple_Alloc(dest_r))
254 prproc = pr_Move_NoREqual_NSimple_Sort;
255 else
256 prproc = pr_Move_NoREqual_NoNSimple_Sort;
257 res = idrMove(id, src_r, dest_r, prproc);
258 return res;
259}
260
261ideal idrMoveR_NoSort(ideal &id, ring src_r, ring dest_r)
262{
263 assume(src_r->cf==dest_r->cf);
264 prCopyProc_t prproc;
265 ideal res;
266 if (rField_has_simple_Alloc(dest_r))
267 prproc = pr_Move_NoREqual_NSimple_NoSort;
268 else
269 prproc = pr_Move_NoREqual_NoNSimple_NoSort;
270 res = idrMove(id, src_r, dest_r, prproc);
271 return res;
272}
273
274
All the auxiliary stuff.
static int si_min(const int a, const int b)
Definition: auxiliary.h:125
CanonicalForm head(const CanonicalForm &f)
const CanonicalForm CFMap CFMap & N
Definition: cfEzgcd.cc:56
int i
Definition: cfEzgcd.cc:132
int p
Definition: cfModGcd.cc:4078
static FORCE_INLINE BOOLEAN n_IsZero(number n, const coeffs r)
TRUE iff 'n' represents the zero element.
Definition: coeffs.h:461
number(* nMapFunc)(number a, const coeffs src, const coeffs dst)
maps "a", which lives in src, into dst
Definition: coeffs.h:73
CanonicalForm res
Definition: facAbsFact.cc:60
static int max(int a, int b)
Definition: fast_mult.cc:264
#define assume(x)
Definition: mod2.h:389
#define p_GetComp(p, r)
Definition: monomials.h:64
#define pIter(p)
Definition: monomials.h:37
#define pNext(p)
Definition: monomials.h:36
#define pSetCoeff0(p, n)
Definition: monomials.h:59
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 rRing_has_Comp(r)
Definition: monomials.h:266
#define NULL
Definition: omList.c:12
static void p_LmDelete(poly p, const ring r)
Definition: p_polys.h:721
static unsigned long p_SetExp(poly p, const unsigned long e, const unsigned long iBitmask, const int VarOffset)
set a single variable exponent @Note: VarOffset encodes the position in p->exp
Definition: p_polys.h:486
static unsigned long p_SetComp(poly p, unsigned long c, ring r)
Definition: p_polys.h:245
static void p_Setm(poly p, const ring r)
Definition: p_polys.h:231
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:467
static poly p_Init(const ring r, omBin bin)
Definition: p_polys.h:1318
static poly p_SortAdd(poly p, const ring r, BOOLEAN revert=FALSE)
Definition: p_polys.h:1217
#define p_Test(p, r)
Definition: p_polys.h:159
poly prMoveR(poly &p, ring src_r, ring dest_r)
Definition: prCopy.cc:90
ideal idrMoveR(ideal &id, ring src_r, ring dest_r)
Definition: prCopy.cc:248
poly prHeadR(poly p, ring src_r, ring dest_r, prCopyProc_t prproc)
Definition: prCopy.cc:126
poly prMapR(poly src, nMapFunc nMap, ring src_r, ring dest_r)
Definition: prCopy.cc:45
static void prCopyEvector(poly dest, ring dest_r, poly src, ring src_r, int max)
Definition: prCopy.cc:18
ideal idrShallowCopyR_NoSort(ideal id, ring src_r, ring dest_r)
Definition: prCopy.cc:225
poly prCopyR(poly p, ring src_r, ring dest_r)
Definition: prCopy.cc:34
ideal idrCopyR(ideal id, ring src_r, ring dest_r)
Definition: prCopy.cc:192
poly prShallowCopyR(poly p, ring r, ring dest_r)
Definition: prCopy.cc:117
ideal idrMoveR_NoSort(ideal &id, ring src_r, ring dest_r)
Definition: prCopy.cc:261
static ideal idrMove(ideal &id, ring src_r, ring dest_r, prCopyProc_t prproc)
Definition: prCopy.cc:233
static ideal idrCopy(ideal id, ring src_r, ring dest_r, prCopyProc_t prproc)
Definition: prCopy.cc:175
poly prMoveR_NoSort(poly &p, ring src_r, ring dest_r)
Definition: prCopy.cc:101
poly prCopyR_NoSort(poly p, ring src_r, ring dest_r)
Definition: prCopy.cc:77
ideal idrCopyR_NoSort(ideal id, ring src_r, ring dest_r)
Definition: prCopy.cc:205
ideal idrHeadR(ideal id, ring r, ring dest_r)
Copy leading terms of id[i] via prHeeadR into dest_r.
Definition: prCopy.cc:156
ideal idrShallowCopyR(ideal id, ring src_r, ring dest_r)
Definition: prCopy.cc:220
poly(* prCopyProc_t)(poly &src_p, ring src_r, ring dest_r)
Definition: prCopy.cc:124
poly prShallowCopyR_NoSort(poly p, ring r, ring dest_r)
Definition: prCopy.cc:112
static BOOLEAN rField_has_simple_Alloc(const ring r)
Z/p, GF(p,n), R: nCopy, nNew, nDelete are dummies.
Definition: ring.h:552
ideal idInit(int idsize, int rank)
initialise an ideal / module
Definition: simpleideals.cc:35
#define IDELEMS(i)
Definition: simpleideals.h:23