1 | /****************************************************************** |
---|
2 | * |
---|
3 | * File: MPT_PutPoly.c |
---|
4 | * Purpose: Routines which support Put side of polynomial communications |
---|
5 | * Author: Olaf Bachman (obachman@mathematik.uni-kl.de) |
---|
6 | * Created: 6/97 |
---|
7 | * |
---|
8 | ******************************************************************/ |
---|
9 | #include "MPT.h" |
---|
10 | |
---|
11 | MP_Status_t MPT_PutDDPoly(MP_Link_pt link, |
---|
12 | MPT_ExternalPoly_t poly, |
---|
13 | MPT_PutPolyFncs_pt polyfncs) |
---|
14 | { |
---|
15 | MP_Uint32_t nummonomials = polyfncs->GetNumberOfMonomials(poly); |
---|
16 | |
---|
17 | failr(MP_PutCommonOperatorPacket(link, |
---|
18 | MP_PolyDict, |
---|
19 | MP_CopPolyDenseDistPoly, |
---|
20 | 4, |
---|
21 | nummonomials)); |
---|
22 | |
---|
23 | failr(MPT_PutPolyAnnots(link, poly, polyfncs)); |
---|
24 | |
---|
25 | return MPT_PutPolyData(link, poly, nummonomials, polyfncs); |
---|
26 | } |
---|
27 | |
---|
28 | MP_Status_t MPT_PutPolyAnnots(MP_Link_pt link, |
---|
29 | MPT_ExternalPoly_t poly, |
---|
30 | MPT_PutPolyFncs_pt polyfncs) |
---|
31 | { |
---|
32 | MP_Sint32_t characteristic = polyfncs->GetCharacteristic(poly); |
---|
33 | MP_Uint32_t varnum = polyfncs->GetNumberOfVariables(poly); |
---|
34 | MP_Uint32_t i; |
---|
35 | |
---|
36 | /************************************/ |
---|
37 | /* Put the prototype annot first */ |
---|
38 | /************************************/ |
---|
39 | |
---|
40 | /* each polynomial consists of monomials */ |
---|
41 | failr(MP_PutAnnotationPacket(link, |
---|
42 | MP_ProtoDict, |
---|
43 | MP_AnnotProtoPrototype, |
---|
44 | MP_AnnotReqValTree)); |
---|
45 | |
---|
46 | /* Each monomial is a struct of two members */ |
---|
47 | failr(MP_PutCommonOperatorPacket(link, |
---|
48 | MP_ProtoDict, |
---|
49 | MP_CopProtoStruct, |
---|
50 | 0, |
---|
51 | 2)); |
---|
52 | /* First part is the coeff */ |
---|
53 | if (characteristic > 0) |
---|
54 | { |
---|
55 | /* prime characterisitc */ |
---|
56 | failr(MP_PutCommonMetaTypePacket(link, |
---|
57 | MP_ProtoDict, |
---|
58 | MP_CmtProtoIMP_Uint32, |
---|
59 | 1)); |
---|
60 | failr(MP_PutAnnotationPacket(link, |
---|
61 | MP_NumberDict, |
---|
62 | MP_AnnotNumberModulos, |
---|
63 | MP_AnnotValuated)); |
---|
64 | /* with Modulo */ |
---|
65 | failr(MP_PutUint32Packet(link, characteristic, 1)); |
---|
66 | /* which is (in our case) always a prime number */ |
---|
67 | failr(MP_PutAnnotationPacket(link, |
---|
68 | MP_NumberDict, |
---|
69 | MP_AnnotNumberIsPrime, |
---|
70 | 0)); |
---|
71 | } |
---|
72 | else |
---|
73 | { |
---|
74 | /* characteristic 0 */ |
---|
75 | failr(MP_PutCommonMetaTypePacket(link, |
---|
76 | MP_NumberDict, |
---|
77 | MP_CmtNumberRational, |
---|
78 | 1)); |
---|
79 | /* are always normalized */ |
---|
80 | failr(MP_PutAnnotationPacket(link, |
---|
81 | MP_NumberDict, |
---|
82 | MP_AnnotNumberIsNormalized, |
---|
83 | 0)); |
---|
84 | } |
---|
85 | /* Second part is the exponent vector */ |
---|
86 | failr(MP_PutCommonMetaOperatorPacket(link, |
---|
87 | MP_ProtoDict, |
---|
88 | MP_CopProtoArray, |
---|
89 | 1, |
---|
90 | varnum)); |
---|
91 | failr(MP_PutAnnotationPacket(link, |
---|
92 | MP_ProtoDict, |
---|
93 | MP_AnnotProtoPrototype, |
---|
94 | MP_AnnotReqValNode)); |
---|
95 | failr(MP_PutCommonMetaTypePacket(link, |
---|
96 | MP_ProtoDict, |
---|
97 | MP_CmtProtoIMP_Sint32, |
---|
98 | 0)); |
---|
99 | |
---|
100 | |
---|
101 | /************************************/ |
---|
102 | /* Put the varnames annot */ |
---|
103 | /************************************/ |
---|
104 | failr(MP_PutAnnotationPacket(link, |
---|
105 | MP_PolyDict, |
---|
106 | MP_AnnotPolyVarNames, |
---|
107 | MP_AnnotValuated)); |
---|
108 | /* now, the varnames follow */ |
---|
109 | failr(MP_PutCommonOperatorPacket(link, |
---|
110 | MP_ProtoDict, |
---|
111 | MP_CopProtoArray, |
---|
112 | 1, |
---|
113 | varnum)); |
---|
114 | failr(MP_PutAnnotationPacket(link, |
---|
115 | MP_ProtoDict, |
---|
116 | MP_AnnotProtoPrototype, |
---|
117 | MP_AnnotReqValNode)); |
---|
118 | |
---|
119 | failr(MP_PutCommonMetaTypePacket(link, |
---|
120 | MP_ProtoDict, |
---|
121 | MP_CmtProtoIMP_Identifier, |
---|
122 | 0)); |
---|
123 | for (i=0; i<varnum; i++) |
---|
124 | failr(IMP_PutString(link, polyfncs->GetVarName(poly, i))); |
---|
125 | |
---|
126 | |
---|
127 | /************************************/ |
---|
128 | /* Put the varnumber annot */ |
---|
129 | /************************************/ |
---|
130 | failr(MP_PutAnnotationPacket(link, |
---|
131 | MP_PolyDict, |
---|
132 | MP_AnnotPolyVarNumber, |
---|
133 | MP_AnnotValuated)); |
---|
134 | failr(MP_PutUint32Packet(link, varnum, 0)); |
---|
135 | |
---|
136 | /************************************/ |
---|
137 | /* Put the Ordering annot */ |
---|
138 | /************************************/ |
---|
139 | failr(MP_PutAnnotationPacket(link, |
---|
140 | MP_PolyDict, |
---|
141 | MP_AnnotPolyOrdering, |
---|
142 | MP_AnnotValuated)); |
---|
143 | |
---|
144 | failr(MP_PutCommonConstantPacket(link, |
---|
145 | MP_PolyDict, |
---|
146 | polyfncs->GetMonomialOrdering(poly), |
---|
147 | 0)); |
---|
148 | |
---|
149 | return MP_Success; |
---|
150 | } |
---|
151 | |
---|
152 | |
---|
153 | MP_Status_t MPT_PutPolyData(MP_Link_pt link, |
---|
154 | MPT_ExternalPoly_t poly, |
---|
155 | MP_Uint32_t nummonomials, |
---|
156 | MPT_PutPolyFncs_pt polyfncs) |
---|
157 | { |
---|
158 | MP_Uint32_t varnum = polyfncs->GetNumberOfVariables(poly), i; |
---|
159 | MP_Sint32_t |
---|
160 | *exp_vector = (MP_Sint32_t *) IMP_MemAllocFnc(varnum*sizeof(MP_Sint32_t)); |
---|
161 | |
---|
162 | for (i=0; i<nummonomials; i++) |
---|
163 | { |
---|
164 | polyfncs->PutCoeffFillExpVector(link, poly, i, varnum, exp_vector); |
---|
165 | failr(IMP_PutSint32Vector(link, exp_vector, varnum)); |
---|
166 | } |
---|
167 | |
---|
168 | IMP_MemFreeFnc(exp_vector, varnum*sizeof(MP_Sint32_t)); |
---|
169 | return MP_Success; |
---|
170 | } |
---|
171 | |
---|
172 | MP_Status_t MPT_PutDDPIdeal(MP_Link_pt link, |
---|
173 | MPT_ExternalIdeal_t ideal, |
---|
174 | MPT_PutIdealFncs_pt idealfncs) |
---|
175 | { |
---|
176 | MP_Uint32_t numpolys = idealfncs->GetNumberOfPolys(ideal), i, nummonoms; |
---|
177 | MPT_ExternalPoly_t poly; |
---|
178 | |
---|
179 | failr(MP_PutCommonOperatorPacket(link, |
---|
180 | MP_PolyDict, |
---|
181 | MP_CopPolyIdeal, |
---|
182 | 1, |
---|
183 | numpolys)); |
---|
184 | failr(MP_PutAnnotationPacket(link, |
---|
185 | MP_ProtoDict, |
---|
186 | MP_AnnotProtoPrototype, |
---|
187 | MP_AnnotReqValTree)); |
---|
188 | failr(MP_PutCommonMetaOperatorPacket(link, |
---|
189 | MP_PolyDict, |
---|
190 | MP_CopPolyDenseDistPoly, |
---|
191 | 4, |
---|
192 | 0)); |
---|
193 | |
---|
194 | failr(MPT_PutPolyAnnots(link, |
---|
195 | idealfncs->GetPoly(ideal, 0), |
---|
196 | idealfncs->polyfncs)); |
---|
197 | |
---|
198 | for (i=0; i<numpolys; i++) |
---|
199 | { |
---|
200 | poly = idealfncs->GetPoly(ideal, i); |
---|
201 | nummonoms = idealfncs->polyfncs->GetNumberOfMonomials(poly); |
---|
202 | failr(IMP_PutUint32(link, nummonoms)); |
---|
203 | failr(MPT_PutPolyData(link, |
---|
204 | poly, |
---|
205 | nummonoms, |
---|
206 | idealfncs->polyfncs)); |
---|
207 | } |
---|
208 | |
---|
209 | return MP_Success; |
---|
210 | } |
---|
211 | |
---|
212 | MP_Status_t MPT_PutDense2DMatrix(MP_Link_pt link, |
---|
213 | MPT_External2DMatrix_t matrix, |
---|
214 | MPT_Put2DMatrixFncs_pt matrixfncs) |
---|
215 | { |
---|
216 | MP_Uint32_t m, n, mn, i, j; |
---|
217 | |
---|
218 | matrixfncs->GetDimension(matrix, &m, &n); |
---|
219 | |
---|
220 | mn = m*n; |
---|
221 | |
---|
222 | failr(MP_PutCommonOperatorPacket(link, |
---|
223 | MP_MatrixDict, |
---|
224 | MP_CopMatrixDenseMatrix, |
---|
225 | (matrixfncs->PutElType != NULL ? 1 : 2), |
---|
226 | mn)); |
---|
227 | |
---|
228 | /* Put dimension annot */ |
---|
229 | failr(MP_PutAnnotationPacket(link, |
---|
230 | MP_MatrixDict, |
---|
231 | MP_AnnotMatrixDimension, |
---|
232 | MP_AnnotReqValNode)); |
---|
233 | /* which specifies the dimesnion of the matrix */ |
---|
234 | failr(MP_PutCommonOperatorPacket(link, |
---|
235 | MP_BasicDict, |
---|
236 | MP_CopBasicList, |
---|
237 | 0, 2)); |
---|
238 | failr(MP_PutUint32Packet(link, (MP_Uint32_t) m, 0)); |
---|
239 | failr(MP_PutUint32Packet(link, (MP_Uint32_t) n, 0)); |
---|
240 | |
---|
241 | /* Now put the prototype annotation, if necessary */ |
---|
242 | if (matrixfncs->PutElType != NULL) |
---|
243 | { |
---|
244 | failr(MP_PutAnnotationPacket(link, |
---|
245 | MP_ProtoDict, |
---|
246 | MP_AnnotProtoPrototype, |
---|
247 | MP_AnnotReqValNode)); |
---|
248 | failr(matrixfncs->PutElType(link, matrix)); |
---|
249 | } |
---|
250 | |
---|
251 | /* Now we are ready to Put the elements */ |
---|
252 | for (i=0; i<m; i++) |
---|
253 | for (j=0; j<m; j++) |
---|
254 | failr(matrixfncs->PutEl(link, matrix, i, j)); |
---|
255 | |
---|
256 | return MP_Success; |
---|
257 | } |
---|
258 | |
---|
259 | MP_Status_t MPT_Put2DPolyMatrix(MP_Link_pt link, |
---|
260 | MPT_External2DPolyMatrix_t matrix, |
---|
261 | MPT_Put2DPolyMatrixFncs_pt mfncs) |
---|
262 | { |
---|
263 | MP_Uint32_t m,n, i, j, nummonoms; |
---|
264 | MPT_ExternalPoly_t poly; |
---|
265 | |
---|
266 | mfncs->GetDimension(matrix, &m, &n); |
---|
267 | failr(MP_PutCommonOperatorPacket(link, |
---|
268 | MP_MatrixDict, |
---|
269 | MP_CopMatrixDenseMatrix, |
---|
270 | 2, |
---|
271 | m*n)); |
---|
272 | |
---|
273 | /* Put the prototype annot */ |
---|
274 | failr(MP_PutAnnotationPacket(link, |
---|
275 | MP_ProtoDict, |
---|
276 | MP_AnnotProtoPrototype, |
---|
277 | MP_AnnotReqValTree)); |
---|
278 | failr(MP_PutCommonMetaOperatorPacket(link, |
---|
279 | MP_PolyDict, |
---|
280 | MP_CopPolyDenseDistPoly, |
---|
281 | 4, |
---|
282 | 0)); |
---|
283 | |
---|
284 | failr(MPT_PutPolyAnnots(link, |
---|
285 | mfncs->GetPoly(matrix, 0, 0), |
---|
286 | mfncs->polyfncs)); |
---|
287 | |
---|
288 | |
---|
289 | /* Put dimension annot */ |
---|
290 | failr(MP_PutAnnotationPacket(link, |
---|
291 | MP_MatrixDict, |
---|
292 | MP_AnnotMatrixDimension, |
---|
293 | MP_AnnotReqValNode)); |
---|
294 | /* which specifies the dimesnion of the matrix */ |
---|
295 | failr(MP_PutCommonOperatorPacket(link, |
---|
296 | MP_BasicDict, |
---|
297 | MP_CopBasicList, |
---|
298 | 0, 2)); |
---|
299 | failr(MP_PutUint32Packet(link, (MP_Uint32_t) m, 0)); |
---|
300 | failr(MP_PutUint32Packet(link, (MP_Uint32_t) n, 0)); |
---|
301 | |
---|
302 | for (i=0; i<m; i++) |
---|
303 | { |
---|
304 | for (j=0; j<n; j++) |
---|
305 | { |
---|
306 | poly = mfncs->GetPoly(matrix, i, j); |
---|
307 | nummonoms = mfncs->polyfncs->GetNumberOfMonomials(poly); |
---|
308 | failr(IMP_PutUint32(link, nummonoms)); |
---|
309 | failr(MPT_PutPolyData(link, |
---|
310 | poly, |
---|
311 | nummonoms, |
---|
312 | mfncs->polyfncs)); |
---|
313 | } |
---|
314 | } |
---|
315 | |
---|
316 | return MP_Success; |
---|
317 | } |
---|
318 | |
---|
319 | |
---|
320 | |
---|