1 | /**************************************** |
---|
2 | * Computer Algebra System SINGULAR * |
---|
3 | ****************************************/ |
---|
4 | |
---|
5 | /* $Id$ */ |
---|
6 | |
---|
7 | /*************************************************************** |
---|
8 | * |
---|
9 | * File: mpsr_PutPoly.cc |
---|
10 | * Purpose: rotines which put polys and polynomials (i.e. ring) annotations |
---|
11 | * Author: Olaf Bachmann (10/95) |
---|
12 | * |
---|
13 | * Change History (most recent first): |
---|
14 | * o 1/97 obachman |
---|
15 | * Updated routines to MP and MPP v1.1 |
---|
16 | * |
---|
17 | ***************************************************************/ |
---|
18 | #include "config.h" |
---|
19 | #include <kernel/mod2.h> |
---|
20 | |
---|
21 | #ifdef HAVE_MPSR |
---|
22 | |
---|
23 | #include <Singular/mpsr_Put.h> |
---|
24 | #include <Singular/mpsr_Tok.h> |
---|
25 | //#include "kernel/longalg.h" |
---|
26 | #include <omalloc/omalloc.h> |
---|
27 | #include <polys/monomials/ring.h> |
---|
28 | #include <kernel/polys.h> |
---|
29 | //#include "ipid.h" |
---|
30 | |
---|
31 | #ifdef PARI_BIGINT_TEST |
---|
32 | #include <Singular/MP_PariBigInt.h> |
---|
33 | MP_Status_t MP_MyPutApIntPacket(MP_Link_pt link, MP_ApInt_t mp_apint, |
---|
34 | MP_NumAnnot_t num_annots) |
---|
35 | { |
---|
36 | GEN pnum = _gmp_to_pari((mpz_ptr) mp_apint); |
---|
37 | return MP_PutApIntPacket(link, (MP_ApInt_t) pnum, num_annots); |
---|
38 | } |
---|
39 | |
---|
40 | #else |
---|
41 | |
---|
42 | #define MP_MyPutApIntPacket MP_PutApIntPacket |
---|
43 | |
---|
44 | #endif |
---|
45 | |
---|
46 | /*************************************************************** |
---|
47 | * |
---|
48 | * global variable definitions |
---|
49 | * |
---|
50 | ***************************************************************/ |
---|
51 | |
---|
52 | static mpsr_Status_t (*PutCoeff)(MP_Link_pt link, number x); |
---|
53 | static mpsr_Status_t (*PutAlgAlgNumber)(MP_Link_pt link, number x); |
---|
54 | static MP_Uint32_t gNalgvars = 0; |
---|
55 | static MP_Sint32_t gNvars = 0; |
---|
56 | static ring CurrPutRing = NULL; |
---|
57 | |
---|
58 | MP_Sint32_t *gTa = NULL; |
---|
59 | MP_Sint32_t gTa_Length = 0; |
---|
60 | |
---|
61 | /*************************************************************** |
---|
62 | * |
---|
63 | * prototype declarations |
---|
64 | * |
---|
65 | ***************************************************************/ |
---|
66 | static void SetPutFuncs(ring r); |
---|
67 | static mpsr_Status_t PutModuloNumber(MP_Link_pt link, number a); |
---|
68 | static mpsr_Status_t PutFloatNumber(MP_Link_pt link, number a); |
---|
69 | static mpsr_Status_t PutRationalNumber(MP_Link_pt link, number a); |
---|
70 | static mpsr_Status_t PutAlgPoly(MP_Link_pt link, napoly a, ring ar); |
---|
71 | static mpsr_Status_t PutAlgNumber(MP_Link_pt link, number a); |
---|
72 | |
---|
73 | static mpsr_Status_t PutVarNamesAnnot(MP_Link_pt link, ring r); |
---|
74 | static mpsr_Status_t PutVarNumberAnnot(MP_Link_pt link, ring r, BOOLEAN mv); |
---|
75 | static mpsr_Status_t PutOrderingAnnot(MP_Link_pt link, ring r, BOOLEAN mv); |
---|
76 | static mpsr_Status_t PutSimpleOrdering(MP_Link_pt link, ring r, short index); |
---|
77 | static mpsr_Status_t PutProtoTypeAnnot(MP_Link_pt link, ring r, BOOLEAN mv); |
---|
78 | static mpsr_Status_t PutMinPolyAnnot(MP_Link_pt link, ring r); |
---|
79 | static mpsr_Status_t PutDefRelsAnnot(MP_Link_pt link, ring r); |
---|
80 | |
---|
81 | |
---|
82 | /*************************************************************** |
---|
83 | * |
---|
84 | * Setting the global Put Functions |
---|
85 | * |
---|
86 | ***************************************************************/ |
---|
87 | static void SetPutFuncs(ring r) |
---|
88 | { |
---|
89 | CurrPutRing = r; |
---|
90 | // first, we set the PutNumber function |
---|
91 | gNvars = r->N; |
---|
92 | mpsr_InitTempArray(gNvars+1); |
---|
93 | |
---|
94 | if (rField_is_Q(r)) |
---|
95 | // rational numbers |
---|
96 | PutCoeff= PutRationalNumber; |
---|
97 | else if (rField_is_Zp(r) || rField_is_GF(r)) |
---|
98 | // Form our point of view, ModuloP numbers and numbers from |
---|
99 | // GF(p,n) are the same, here. They only differ in the annots |
---|
100 | PutCoeff = PutModuloNumber; |
---|
101 | else if (rField_is_R(r)) |
---|
102 | PutCoeff = PutFloatNumber; |
---|
103 | else |
---|
104 | { |
---|
105 | // now we come to algebraic numbers |
---|
106 | gNalgvars = rPar(r); |
---|
107 | mpsr_InitTempArray(gNalgvars); |
---|
108 | PutCoeff = PutAlgNumber; |
---|
109 | if (rField_is_Zp_a(r)) |
---|
110 | // first, Z/p(a) |
---|
111 | PutAlgAlgNumber = PutModuloNumber; |
---|
112 | else |
---|
113 | PutAlgAlgNumber = PutRationalNumber; |
---|
114 | } |
---|
115 | } |
---|
116 | |
---|
117 | |
---|
118 | |
---|
119 | /*************************************************************** |
---|
120 | * |
---|
121 | * modulo numbers (i.e. char p, or p^n) |
---|
122 | * |
---|
123 | ***************************************************************/ |
---|
124 | // we always put modulo numbers without a header, since |
---|
125 | // we have type-spec this before |
---|
126 | static mpsr_Status_t PutModuloNumber(MP_Link_pt link, number a) |
---|
127 | { |
---|
128 | mp_return(IMP_PutUint32(link, (MP_Uint32_t) a)); |
---|
129 | } |
---|
130 | |
---|
131 | static mpsr_Status_t PutFloatNumber(MP_Link_pt link, number a) |
---|
132 | { |
---|
133 | mp_return(IMP_PutReal32(link , Number_2_Real32(a))); |
---|
134 | } |
---|
135 | |
---|
136 | /*************************************************************** |
---|
137 | * |
---|
138 | * rational (i.e. char 0) numbers |
---|
139 | * |
---|
140 | ***************************************************************/ |
---|
141 | // This supposes that number is of char 0, i.e. a rational number |
---|
142 | static mpsr_Status_t PutRationalNumber(MP_Link_pt link, number a) |
---|
143 | { |
---|
144 | // Check for case number == NULL == 0 |
---|
145 | if (a == NULL) |
---|
146 | mp_return( MP_PutSint32Packet(link, 0, 0)); |
---|
147 | |
---|
148 | // check for SR_INT type |
---|
149 | if (SR_HDL(a) & SR_INT) |
---|
150 | mp_return( MP_PutSint32Packet(link, SR_TO_INT(a), 0)); |
---|
151 | |
---|
152 | // check for single GMP integer |
---|
153 | if ((a->s) == 3) |
---|
154 | mp_return(MP_MyPutApIntPacket(link, (MP_ApInt_t) &(a->z), 0)); |
---|
155 | |
---|
156 | // Now we have a fraction |
---|
157 | // normalize, if necessary |
---|
158 | // if ((a->s) == 0) |
---|
159 | // { |
---|
160 | // // nlNormalize(a); |
---|
161 | // return PutRationalNumber(link, a); |
---|
162 | // } |
---|
163 | |
---|
164 | // send number itself |
---|
165 | mp_failr(MP_PutCommonOperatorPacket(link, |
---|
166 | MP_BasicDict, |
---|
167 | MP_CopBasicDiv, |
---|
168 | 0, |
---|
169 | 2)); |
---|
170 | // and now sent nominator and denominator |
---|
171 | mp_failr(MP_MyPutApIntPacket(link, (MP_ApInt_t) &(a->z), 0)); |
---|
172 | mp_return(MP_MyPutApIntPacket(link, (MP_ApInt_t) &(a->n), 0)); |
---|
173 | } |
---|
174 | |
---|
175 | /*************************************************************** |
---|
176 | * |
---|
177 | * Algebraic Numbers (a la Singular) |
---|
178 | * |
---|
179 | ***************************************************************/ |
---|
180 | static inline MP_Uint32_t GetPlength(napoly a) |
---|
181 | { |
---|
182 | MP_Uint32_t i = napLength(a); |
---|
183 | return i; |
---|
184 | } |
---|
185 | |
---|
186 | static mpsr_Status_t PutAlgNumber(MP_Link_pt link, number a) |
---|
187 | { |
---|
188 | lnumber b; |
---|
189 | |
---|
190 | if (a == NULL) |
---|
191 | mp_return(IMP_PutUint32(link, 0)); |
---|
192 | |
---|
193 | b = (lnumber) a; |
---|
194 | if ((b->n) == NULL) // NULL means there is only one number |
---|
195 | { |
---|
196 | // hence, we use the first case of the union |
---|
197 | mp_failr(IMP_PutUint32(link, 1)); |
---|
198 | mp_failr(IMP_PutUint32(link, GetPlength(b->z))); |
---|
199 | return PutAlgPoly(link, b->z, CurrPutRing->extRing); |
---|
200 | } |
---|
201 | else |
---|
202 | { |
---|
203 | // we use the 2nd case of the union |
---|
204 | mp_failr(IMP_PutUint32(link, 2)); |
---|
205 | mp_failr(IMP_PutUint32(link, GetPlength(b->z))); |
---|
206 | failr(PutAlgPoly(link, b->z, CurrPutRing->extRing)); |
---|
207 | mp_failr(IMP_PutUint32(link, GetPlength(b->n))); |
---|
208 | return PutAlgPoly(link, b->n, CurrPutRing->extRing); |
---|
209 | } |
---|
210 | } |
---|
211 | |
---|
212 | // this is very similar to putting a Poly |
---|
213 | static mpsr_Status_t PutAlgPoly(MP_Link_pt link, napoly a, ring ar) |
---|
214 | { |
---|
215 | unsigned int i; |
---|
216 | int *exp; |
---|
217 | |
---|
218 | if (gNalgvars > 1) |
---|
219 | while (a != NULL) |
---|
220 | { |
---|
221 | failr(PutAlgAlgNumber(link, napGetCoeff(a))); |
---|
222 | for (i=0; i<gNalgvars; i++) |
---|
223 | gTa[i] = p_GetExp((poly)a,i+1,ar); |
---|
224 | mp_failr(IMP_PutSint32Vector(link, gTa, gNalgvars)); |
---|
225 | pIter(a); |
---|
226 | } |
---|
227 | else |
---|
228 | { |
---|
229 | while (a != NULL) |
---|
230 | { |
---|
231 | failr(PutAlgAlgNumber(link, napGetCoeff(a))); |
---|
232 | IMP_PutSint32(link, (MP_Sint32_t) p_GetExp((poly)a,1,ar)); |
---|
233 | pIter(a); |
---|
234 | } |
---|
235 | } |
---|
236 | return mpsr_Success; |
---|
237 | } |
---|
238 | |
---|
239 | /*************************************************************** |
---|
240 | * |
---|
241 | * Putting polys |
---|
242 | * |
---|
243 | ***************************************************************/ |
---|
244 | mpsr_Status_t mpsr_PutPolyData(MP_Link_pt link, poly p, ring cring) |
---|
245 | { |
---|
246 | //if (cring != CurrPutRing) |
---|
247 | SetPutFuncs(cring); |
---|
248 | |
---|
249 | #ifdef MPSR_DEBUG |
---|
250 | if (currRing == cring) |
---|
251 | pTest(p); |
---|
252 | #endif |
---|
253 | |
---|
254 | if (gNvars > 1) |
---|
255 | { |
---|
256 | short i; |
---|
257 | MP_Sint32_t *ta1 = &(gTa[1]); |
---|
258 | |
---|
259 | while (p != NULL) |
---|
260 | { |
---|
261 | failr(PutCoeff(link, pGetCoeff(p))); |
---|
262 | for (i=1; i<=gNvars; i++) |
---|
263 | gTa[i] = (MP_Sint32_t) pGetExp(p, i); |
---|
264 | mp_failr(IMP_PutSint32Vector(link, ta1, gNvars)); |
---|
265 | pIter(p); |
---|
266 | } |
---|
267 | } |
---|
268 | else |
---|
269 | while (p != NULL) |
---|
270 | { |
---|
271 | failr(PutCoeff(link, pGetCoeff(p))); |
---|
272 | IMP_PutSint32(link, (MP_Sint32_t) pGetExp(p,1)); |
---|
273 | pIter(p); |
---|
274 | } |
---|
275 | return mpsr_Success; |
---|
276 | } |
---|
277 | |
---|
278 | mpsr_Status_t mpsr_PutPolyVectorData(MP_Link_pt link, poly p, ring cring) |
---|
279 | { |
---|
280 | short i, n1; |
---|
281 | |
---|
282 | if (cring != CurrPutRing) |
---|
283 | SetPutFuncs(cring); |
---|
284 | |
---|
285 | if (gNvars > 1) |
---|
286 | { |
---|
287 | short i, n1= gNvars + 1; |
---|
288 | while (p != NULL) |
---|
289 | { |
---|
290 | failr(PutCoeff(link, pGetCoeff(p))); |
---|
291 | gTa[0] = pGetComp(p); |
---|
292 | for (i=1; i< n1; i++) |
---|
293 | gTa[i] = (MP_Sint32_t) pGetExp(p,i); |
---|
294 | mp_failr(IMP_PutSint32Vector(link, gTa, n1)); |
---|
295 | pIter(p); |
---|
296 | } |
---|
297 | } |
---|
298 | else |
---|
299 | while (p != NULL) |
---|
300 | { |
---|
301 | failr(PutCoeff(link, pGetCoeff(p))); |
---|
302 | IMP_PutSint32(link, (MP_Sint32_t) pGetComp(p)); |
---|
303 | IMP_PutSint32(link, (MP_Sint32_t) pGetExp(p,1)); |
---|
304 | pIter(p); |
---|
305 | } |
---|
306 | return mpsr_Success; |
---|
307 | } |
---|
308 | |
---|
309 | /*************************************************************** |
---|
310 | * |
---|
311 | * The putting annotation buisness |
---|
312 | * |
---|
313 | ***************************************************************/ |
---|
314 | int mpsr_GetNumOfRingAnnots(ring r, BOOLEAN mv) |
---|
315 | { |
---|
316 | short annots = 4; |
---|
317 | |
---|
318 | if (mv) annots++; |
---|
319 | if (r->qideal != NULL) annots++; |
---|
320 | // we sent the minpoly with the coefficient ring |
---|
321 | if ((r->minpoly != NULL) && (r->parameter == NULL)) annots++; |
---|
322 | |
---|
323 | return annots; |
---|
324 | } |
---|
325 | |
---|
326 | mpsr_Status_t mpsr_PutRingAnnots(MP_Link_pt link, ring r, BOOLEAN mv) |
---|
327 | { |
---|
328 | failr(PutProtoTypeAnnot(link,r, mv)); |
---|
329 | failr(PutVarNumberAnnot(link, r, mv)); |
---|
330 | failr(PutVarNamesAnnot(link,r)); |
---|
331 | failr(PutOrderingAnnot(link,r, mv)); |
---|
332 | |
---|
333 | if (mv) |
---|
334 | mp_failr(MP_PutAnnotationPacket(link, |
---|
335 | MP_PolyDict, |
---|
336 | MP_AnnotPolyModuleVector, |
---|
337 | MP_AnnotRequired)); |
---|
338 | // Hmm .. this is not according to a "proper" Singular ring, |
---|
339 | // but to be used in a recursive call of mpsr_PutRingAnnots |
---|
340 | if (r->minpoly != NULL && r->parameter == NULL && r->ch > 0) |
---|
341 | failr(PutMinPolyAnnot(link,r)); |
---|
342 | |
---|
343 | if (r->qideal != NULL) |
---|
344 | return PutDefRelsAnnot(link, r); |
---|
345 | |
---|
346 | return mpsr_Success; |
---|
347 | } |
---|
348 | |
---|
349 | static mpsr_Status_t PutProtoTypeAnnot(MP_Link_pt link, ring r, |
---|
350 | BOOLEAN mv) |
---|
351 | { |
---|
352 | // each element of the poly is a |
---|
353 | mp_failr(MP_PutAnnotationPacket(link, |
---|
354 | MP_ProtoDict, |
---|
355 | MP_AnnotProtoPrototype, |
---|
356 | MP_AnnotReqValNode)); |
---|
357 | // Monom represented as a struct of 2 elements |
---|
358 | mp_failr(MP_PutCommonOperatorPacket(link, |
---|
359 | MP_ProtoDict, |
---|
360 | MP_CopProtoStruct, |
---|
361 | 0, |
---|
362 | 2)); |
---|
363 | |
---|
364 | // First element is the coefficient |
---|
365 | if (rField_is_Q(r)) |
---|
366 | { |
---|
367 | // rational numbers |
---|
368 | mp_failr(MP_PutCommonMetaTypePacket(link, |
---|
369 | MP_NumberDict, |
---|
370 | MP_CmtNumberRational, |
---|
371 | 1)); |
---|
372 | // are always normalized (and made that way, if necessary) |
---|
373 | mp_failr(MP_PutAnnotationPacket(link, |
---|
374 | MP_NumberDict, |
---|
375 | MP_AnnotNumberIsNormalized, |
---|
376 | 0)); |
---|
377 | } |
---|
378 | else if (rField_is_Zp(r) || rField_is_GF(r)) |
---|
379 | { |
---|
380 | // modulo p numbers |
---|
381 | // are communicated as IMP_Uint32's |
---|
382 | mp_failr(MP_PutCommonMetaTypePacket(link, |
---|
383 | MP_ProtoDict, |
---|
384 | MP_CmtProtoIMP_Uint32, |
---|
385 | 1)); |
---|
386 | // but are taken as modulo numbers |
---|
387 | mp_failr(MP_PutAnnotationPacket(link, |
---|
388 | MP_NumberDict, |
---|
389 | MP_AnnotNumberModulos, |
---|
390 | MP_AnnotValuated)); |
---|
391 | // with Modulo |
---|
392 | mp_failr(MP_PutUint32Packet(link, rInternalChar(r), 1)); |
---|
393 | if (r->parameter == NULL) |
---|
394 | { |
---|
395 | // which is (in our case) always a prime number |
---|
396 | mp_failr(MP_PutAnnotationPacket(link, |
---|
397 | MP_NumberDict, |
---|
398 | MP_AnnotNumberIsPrime, |
---|
399 | 0)); |
---|
400 | } |
---|
401 | else |
---|
402 | { |
---|
403 | mp_failr(MP_PutAnnotationPacket(link, |
---|
404 | MP_SingularDict, |
---|
405 | MP_AnnotSingularGalois, |
---|
406 | MP_AnnotValuated)); |
---|
407 | mp_failr(MP_PutStringPacket(link, r->parameter[0], 0)); |
---|
408 | } |
---|
409 | } |
---|
410 | else if (rField_is_R(r)) |
---|
411 | { |
---|
412 | // floats |
---|
413 | mp_failr(MP_PutCommonMetaTypePacket(link, |
---|
414 | MP_ProtoDict, |
---|
415 | MP_CmtProtoIMP_Real32, |
---|
416 | 0)); |
---|
417 | } |
---|
418 | else |
---|
419 | { |
---|
420 | // alg numbers |
---|
421 | // create temporary ring for describing the coeeficient domain |
---|
422 | ring alg_r = r->extRing; |
---|
423 | alg_r->minpoly = r->minpoly; |
---|
424 | |
---|
425 | // Algebraic numbers are |
---|
426 | // a fraction of two Dense Dist Polys |
---|
427 | mp_failr(MP_PutCommonMetaOperatorPacket(link, |
---|
428 | MP_BasicDict, |
---|
429 | MP_CopBasicDiv, |
---|
430 | 1, |
---|
431 | 0)); |
---|
432 | mp_failr(MP_PutAnnotationPacket(link, |
---|
433 | MP_ProtoDict, |
---|
434 | MP_AnnotProtoPrototype, |
---|
435 | MP_AnnotReqValNode)); |
---|
436 | mp_failr(MP_PutCommonMetaOperatorPacket(link, |
---|
437 | MP_PolyDict, |
---|
438 | MP_CopPolyDenseDistPoly, |
---|
439 | mpsr_GetNumOfRingAnnots(alg_r, 0), |
---|
440 | 0)); |
---|
441 | failr(mpsr_PutRingAnnots(link, alg_r, 0)); |
---|
442 | |
---|
443 | // destroy temporary ring |
---|
444 | alg_r->minpoly = NULL; |
---|
445 | } |
---|
446 | |
---|
447 | // second element is the exponent vector |
---|
448 | mp_failr(MP_PutCommonMetaOperatorPacket(link, |
---|
449 | MP_ProtoDict, |
---|
450 | MP_CopProtoArray, |
---|
451 | 1, |
---|
452 | (mv ? r->N + 1 : r->N))); |
---|
453 | mp_failr(MP_PutAnnotationPacket(link, |
---|
454 | MP_ProtoDict, |
---|
455 | MP_AnnotProtoPrototype, |
---|
456 | MP_AnnotReqValNode)); |
---|
457 | mp_return(MP_PutCommonMetaTypePacket(link, |
---|
458 | MP_ProtoDict, |
---|
459 | MP_CmtProtoIMP_Sint32, |
---|
460 | 0)); |
---|
461 | } |
---|
462 | |
---|
463 | |
---|
464 | static mpsr_Status_t PutVarNamesAnnot(MP_Link_pt link, ring r) |
---|
465 | { |
---|
466 | // first, we put the annot packet, with flags (1, 0, 1, 0) |
---|
467 | mp_failr(MP_PutAnnotationPacket(link, |
---|
468 | MP_PolyDict, |
---|
469 | MP_AnnotPolyVarNames, |
---|
470 | MP_AnnotValuated)); |
---|
471 | // now, the varnames follow |
---|
472 | if ((r->N) == 1) |
---|
473 | { |
---|
474 | // only 1 varname |
---|
475 | mp_return(MP_PutIdentifierPacket(link, MP_SingularDict, *(r->names), 0)); |
---|
476 | } |
---|
477 | else |
---|
478 | { |
---|
479 | // more than one varname |
---|
480 | char **names = r->names; |
---|
481 | int i, n = r->N; |
---|
482 | |
---|
483 | mp_failr(MP_PutCommonOperatorPacket(link, |
---|
484 | MP_ProtoDict, |
---|
485 | MP_CopProtoArray, |
---|
486 | 1, |
---|
487 | r->N)); |
---|
488 | mp_failr(MP_PutAnnotationPacket(link, |
---|
489 | MP_ProtoDict, |
---|
490 | MP_AnnotProtoPrototype, |
---|
491 | MP_AnnotReqValNode)); |
---|
492 | |
---|
493 | mp_failr(MP_PutCommonMetaTypePacket(link, |
---|
494 | MP_ProtoDict, |
---|
495 | MP_CmtProtoIMP_Identifier, |
---|
496 | 0)); |
---|
497 | for (i=0; i<n; i++) |
---|
498 | mp_failr(IMP_PutString(link, names[i])); |
---|
499 | |
---|
500 | return mpsr_Success; |
---|
501 | } |
---|
502 | } |
---|
503 | |
---|
504 | static mpsr_Status_t PutVarNumberAnnot(MP_Link_pt link, ring r, BOOLEAN mv) |
---|
505 | { |
---|
506 | mp_failr(MP_PutAnnotationPacket(link, |
---|
507 | MP_PolyDict, |
---|
508 | MP_AnnotPolyVarNumber, |
---|
509 | MP_AnnotValuated)); |
---|
510 | mp_return(MP_PutUint32Packet(link, (mv ? r->N + 1 : r->N), 0)); |
---|
511 | } |
---|
512 | |
---|
513 | |
---|
514 | static mpsr_Status_t PutOrderingAnnot(MP_Link_pt link, ring r, BOOLEAN mv) |
---|
515 | { |
---|
516 | int index = 0, nblocks = 0; |
---|
517 | int *order = r->order; |
---|
518 | |
---|
519 | mp_failr(MP_PutAnnotationPacket(link, |
---|
520 | MP_PolyDict, |
---|
521 | MP_AnnotPolyOrdering, |
---|
522 | MP_AnnotValuated)); |
---|
523 | |
---|
524 | // let's see whether we have a simple ordering to sent |
---|
525 | if ((mv == 0) && (order[1] == ringorder_no)) |
---|
526 | { |
---|
527 | // ring does not contain a component entry: |
---|
528 | return PutSimpleOrdering(link, r, 0); |
---|
529 | } |
---|
530 | if ((mv == 0) && (order[2] == ringorder_no)) |
---|
531 | { |
---|
532 | if (order[1] == ringorder_C || order[1] == ringorder_c) |
---|
533 | index = 0; |
---|
534 | else |
---|
535 | index = 1; |
---|
536 | |
---|
537 | return PutSimpleOrdering(link, r, index); |
---|
538 | } |
---|
539 | |
---|
540 | // No -- so we are dealing with a product ordering |
---|
541 | // First, let's find out how many blocks there are |
---|
542 | while (order[nblocks] != ringorder_no) nblocks++; |
---|
543 | // if we deal with a non-vector, we are not going to sent |
---|
544 | // the vector ordering |
---|
545 | mp_failr(MP_PutCommonOperatorPacket(link, |
---|
546 | MP_BasicDict, |
---|
547 | MP_CopBasicList, |
---|
548 | 0, |
---|
549 | (mv ? nblocks : nblocks - 1))); |
---|
550 | |
---|
551 | for (index = 0; index < nblocks; index ++) |
---|
552 | // Do not sent vector ordering, if we are sending pure polys |
---|
553 | if (! (mv == 0 && (order[index] == ringorder_C || |
---|
554 | order[index] == ringorder_c))) |
---|
555 | { |
---|
556 | // a product ordering is sent as triple |
---|
557 | mp_failr(MP_PutCommonOperatorPacket(link, |
---|
558 | MP_BasicDict, |
---|
559 | MP_CopBasicList, |
---|
560 | 0, |
---|
561 | 3)); |
---|
562 | // first element is the simple ordering |
---|
563 | failr(PutSimpleOrdering(link, r, index)); |
---|
564 | // second and third for covered variables |
---|
565 | mp_failr(MP_PutUint32Packet(link, (MP_Uint32_t) r->block0[index], 0)); |
---|
566 | mp_failr(MP_PutUint32Packet(link, (MP_Uint32_t) r->block1[index], 0)); |
---|
567 | } |
---|
568 | |
---|
569 | return mpsr_Success; |
---|
570 | } |
---|
571 | |
---|
572 | |
---|
573 | static mpsr_Status_t PutSimpleOrdering(MP_Link_pt link, ring r, short index) |
---|
574 | { |
---|
575 | MP_Uint32_t vlength = 0, i; |
---|
576 | |
---|
577 | // find out the length of the weight-vector |
---|
578 | if (r->wvhdl && r->wvhdl[index] != NULL) |
---|
579 | vlength = r->block1[index] - r->block0[index] + 1; |
---|
580 | |
---|
581 | mp_failr(MP_PutCommonConstantPacket(link, |
---|
582 | MP_PolyDict, |
---|
583 | mpsr_ord2mp(r->order[index]), |
---|
584 | (vlength == 0 ? 0 : 1))); |
---|
585 | |
---|
586 | if (vlength == 0) return mpsr_Success; |
---|
587 | |
---|
588 | // deal with the weights |
---|
589 | mp_failr(MP_PutAnnotationPacket(link, |
---|
590 | MP_PolyDict, |
---|
591 | MP_AnnotPolyWeights, |
---|
592 | MP_AnnotValuated)); |
---|
593 | if (r->order[index] == ringorder_M) |
---|
594 | { |
---|
595 | // put the matrix header |
---|
596 | mp_failr(MP_PutCommonOperatorPacket(link, |
---|
597 | MP_MatrixDict, |
---|
598 | MP_CopMatrixDenseMatrix, |
---|
599 | 2, |
---|
600 | vlength*vlength)); |
---|
601 | mp_failr(MP_PutAnnotationPacket(link, |
---|
602 | MP_ProtoDict, |
---|
603 | MP_AnnotProtoPrototype, |
---|
604 | MP_AnnotReqValNode)); |
---|
605 | mp_failr(MP_PutCommonMetaTypePacket(link, |
---|
606 | MP_ProtoDict, |
---|
607 | MP_CmtProtoIMP_Sint32, |
---|
608 | 0)); |
---|
609 | mp_failr(MP_PutAnnotationPacket(link, |
---|
610 | MP_MatrixDict, |
---|
611 | MP_AnnotMatrixDimension, |
---|
612 | MP_AnnotReqValNode)); |
---|
613 | mp_failr(MP_PutCommonOperatorPacket(link, |
---|
614 | MP_BasicDict, |
---|
615 | MP_CopBasicList, |
---|
616 | 0, 2)); |
---|
617 | mp_failr(MP_PutSint32Packet(link, (MP_Sint32_t) vlength, 0)); |
---|
618 | mp_failr(MP_PutSint32Packet(link, (MP_Sint32_t) vlength, 0)); |
---|
619 | vlength *= vlength; |
---|
620 | } |
---|
621 | else |
---|
622 | { |
---|
623 | // vector header |
---|
624 | mp_failr(MP_PutCommonOperatorPacket(link, |
---|
625 | MP_MatrixDict, |
---|
626 | MP_CopMatrixDenseVector, |
---|
627 | 1, |
---|
628 | vlength)); |
---|
629 | mp_failr(MP_PutAnnotationPacket(link, |
---|
630 | MP_ProtoDict, |
---|
631 | MP_AnnotProtoPrototype, |
---|
632 | MP_AnnotReqValNode)); |
---|
633 | mp_failr(MP_PutCommonMetaTypePacket(link, |
---|
634 | MP_ProtoDict, |
---|
635 | MP_CmtProtoIMP_Sint32, |
---|
636 | 0)); |
---|
637 | } |
---|
638 | |
---|
639 | // weights are all what remains |
---|
640 | for (i=0; i<vlength; i++) |
---|
641 | mp_failr(IMP_PutSint32(link, (MP_Sint32_t) r->wvhdl[index][i])); |
---|
642 | |
---|
643 | return mpsr_Success; |
---|
644 | } |
---|
645 | |
---|
646 | static mpsr_Status_t PutMinPolyAnnot(MP_Link_pt link, ring r) |
---|
647 | { |
---|
648 | mpsr_assume(r->minpoly != NULL && r->ch > 0 && r->parameter == NULL); |
---|
649 | |
---|
650 | number minpoly = r->minpoly; |
---|
651 | r->minpoly = 0; |
---|
652 | |
---|
653 | mp_failr(MP_PutAnnotationPacket(link, |
---|
654 | MP_PolyDict, |
---|
655 | MP_AnnotPolyDefRel, |
---|
656 | MP_AnnotValuated)); |
---|
657 | mp_failr(MP_PutCommonOperatorPacket(link, |
---|
658 | MP_PolyDict, |
---|
659 | MP_CopPolyDenseDistPoly, |
---|
660 | 5, |
---|
661 | GetPlength( ((lnumber) minpoly)->z))); |
---|
662 | failr(PutProtoTypeAnnot(link, r, 0)); |
---|
663 | failr(PutVarNamesAnnot(link, r)); |
---|
664 | failr(PutVarNumberAnnot(link, r,0)); |
---|
665 | failr(PutOrderingAnnot(link, r, 0)); |
---|
666 | mp_failr(MP_PutAnnotationPacket(link, |
---|
667 | MP_PolyDict, |
---|
668 | MP_AnnotPolyIrreducible, |
---|
669 | 0)); |
---|
670 | |
---|
671 | // need to set PutAlgAlgnumber and gNalgVars |
---|
672 | CurrPutRing = r; |
---|
673 | if (rField_is_Zp(r) || rField_is_GF(r)) |
---|
674 | PutAlgAlgNumber = PutModuloNumber; |
---|
675 | else |
---|
676 | PutAlgAlgNumber = PutRationalNumber; |
---|
677 | gNalgvars = r->N; |
---|
678 | |
---|
679 | r->minpoly = minpoly; |
---|
680 | return PutAlgPoly(link, ((lnumber) minpoly)->z, r); |
---|
681 | } |
---|
682 | |
---|
683 | |
---|
684 | static mpsr_Status_t PutDefRelsAnnot(MP_Link_pt link, ring r) |
---|
685 | { |
---|
686 | int i, idn; |
---|
687 | ideal id; |
---|
688 | |
---|
689 | id = r->qideal; |
---|
690 | r->qideal = NULL; |
---|
691 | |
---|
692 | mp_failr(MP_PutAnnotationPacket(link, |
---|
693 | MP_PolyDict, |
---|
694 | MP_AnnotPolyDefRel, |
---|
695 | MP_AnnotValuated)); |
---|
696 | failr(mpsr_PutIdeal(link, id, r)); |
---|
697 | r->qideal = id; |
---|
698 | return mpsr_Success; |
---|
699 | } |
---|
700 | |
---|
701 | #endif |
---|