My Project
Loading...
Searching...
No Matches
flintcf_Qrat.cc
Go to the documentation of this file.
1/****************************************
2* Computer Algebra System SINGULAR *
3****************************************/
4/*
5* ABSTRACT: flint: rational functions over Q (using fmpq_mpoly)
6*/
7#include <ctype.h> /* isdigit*/
8#include <string.h> /* strncat*/
9
10#include "misc/auxiliary.h"
11
12#include "coeffs/coeffs.h"
13
14#ifdef HAVE_FLINT
15#include "flint/flint.h"
16#if __FLINT_RELEASE >= 20503
17#include "factory/factory.h"
18
19#include "coeffs/numbers.h"
20#include "coeffs/longrat.h"
21#include "coeffs/flintcf_Qrat.h"
22#include "polys/flint_mpoly.h"
23#ifdef QA_DEBUG
24#define TRANSEXT_PRIVATES
27#endif
28
29typedef fmpq_rat_struct *fmpq_rat_ptr;
30typedef fmpq_mpoly_struct *fmpq_mpoly_ptr;
31typedef fmpq_mpoly_ctx_struct *fmpq_ctx_ptr;
32typedef fmpz *fmpz_ptr;
33typedef fmpq_rat_data_struct *data_ptr;
34
35/******************************************************************************
36* Helper functions
37******************************************************************************/
38
39/*2
40* extracts a long integer from s, returns the rest
41*/
42static char * nlEatLong(char *s, fmpz_ptr i)
43{
44 const char * start = s;
45
46 while (*s >= '0' && *s <= '9') s++;
47 if (*s == '\0')
48 {
49 fmpz_set_str(i, start, 10);
50 }
51 else
52 {
53 char c = *s;
54 *s = '\0';
55 fmpz_set_str(i, start, 10);
56 *s = c;
57 }
58 return s;
59}
60
61static void fmpq_rat_init(fmpq_rat_ptr a, const coeffs r)
62{
63 fmpq_mpoly_init(a->num, ((data_ptr)r->data)->ctx);
64 fmpq_mpoly_init(a->den, ((data_ptr)r->data)->ctx);
65}
66
67static void fmpq_rat_clear(fmpq_rat_ptr a, const coeffs r)
68{
69 fmpq_mpoly_clear(a->num, ((data_ptr)r->data)->ctx);
70 fmpq_mpoly_clear(a->den, ((data_ptr)r->data)->ctx);
71}
72
73static void fmpq_rat_canonicalise(fmpq_rat_ptr a, const coeffs /*r*/)
74{
75 fmpz_t n, d;
76 fmpz_init(n);
77 fmpz_init(d);
78 fmpz_gcd(n, fmpq_numref(a->num->content), fmpq_numref(a->den->content));
79 fmpz_lcm(d, fmpq_denref(a->num->content), fmpq_denref(a->den->content));
80 if (!fmpz_is_one(d))
81 {
82 fmpq_mul_fmpz(a->num->content, a->num->content, d);
83 fmpq_mul_fmpz(a->den->content, a->den->content, d);
84 }
85 if (!fmpz_is_one(n))
86 {
87 fmpq_div_fmpz(a->num->content, a->num->content, n);
88 fmpq_div_fmpz(a->den->content, a->den->content, n);
89 }
90 fmpz_clear(n);
91 fmpz_clear(d);
92}
93
94/******************************************************************************
95* Main interface
96******************************************************************************/
97
98static BOOLEAN CoeffIsEqual(const coeffs c, n_coeffType n, void * parameter)
99{
100 if (c->type == n)
101 {
102 const QaInfo *par=(QaInfo*)parameter;
103 if (par->N != c->iNumberOfParameters) return FALSE;
104 // compare parameter names
105 for(int i=0;i<par->N;i++)
106 {
107 if (strcmp(par->names[i],c->pParameterNames[i])!=0) return FALSE;
108 }
109 return TRUE;
110 }
111 return FALSE;
112}
113
114static number Mult(number a, number b, const coeffs c)
115{
116 n_Test(a,c);
117 n_Test(b,c);
118 fmpq_rat_ptr res = (fmpq_rat_ptr) omAlloc(sizeof(fmpq_rat_struct));
119 fmpq_rat_init(res, c);
120 const fmpq_rat_ptr x = (fmpq_rat_ptr) a;
121 const fmpq_rat_ptr y = (fmpq_rat_ptr) b;
122 const fmpq_ctx_ptr ctx = (fmpq_ctx_ptr) ((data_ptr)c->data)->ctx;
123 if (fmpq_mpoly_equal(x->den, y->den, ctx)) /* denominators equal */
124 {
125 fmpq_mpoly_mul(res->num, x->num, y->num, ctx);
126 fmpq_mpoly_mul(res->den, x->den, y->den, ctx);
127 }
128 else if (fmpq_mpoly_is_one(x->den, ctx)) /* first denominator 1 */
129 {
130 fmpq_mpoly_t gd;
131 fmpq_mpoly_init(gd, ctx);
132 fmpq_mpoly_gcd(gd, x->num, y->den, ctx);
133 if (fmpq_mpoly_is_one(gd, ctx))
134 {
135 fmpq_mpoly_mul(res->num, x->num, y->num, ctx);
136 fmpq_mpoly_set(res->den, y->den, ctx);
137 }
138 else
139 {
140 fmpq_mpoly_div(res->num, x->num, gd, ctx);
141 fmpq_mpoly_mul(res->num, res->num, y->num, ctx);
142 fmpq_mpoly_div(res->den, y->den, gd, ctx);
143 }
144 fmpq_mpoly_clear(gd, ctx);
145 }
146 else if (fmpq_mpoly_is_one(y->den, ctx)) /* second denominator 1 */
147 {
148 fmpq_mpoly_t gd;
149 fmpq_mpoly_init(gd, ctx);
150 fmpq_mpoly_gcd(gd, y->num, x->den, ctx);
151 if (fmpq_mpoly_is_one(gd, ctx))
152 {
153 fmpq_mpoly_mul(res->num, x->num, y->num, ctx);
154 fmpq_mpoly_set(res->den, x->den, ctx);
155 }
156 else
157 {
158 fmpq_mpoly_div(res->num, y->num, gd, ctx);
159 fmpq_mpoly_mul(res->num, res->num, x->num, ctx);
160 fmpq_mpoly_div(res->den, x->den, gd, ctx);
161 }
162 fmpq_mpoly_clear(gd, ctx);
163 }
164 else /* general case */
165 {
166 fmpq_mpoly_t g1, g2;
167 fmpq_mpoly_ptr n1, n2, d1, d2;
168 fmpq_mpoly_init(g1, ctx);
169 fmpq_mpoly_init(g2, ctx);
170 fmpq_mpoly_gcd(g1, x->num, y->den, ctx);
171 fmpq_mpoly_gcd(g2, y->num, x->den, ctx);
172 n1 = x->num; d2 = y->den;
173 d1 = x->den; n2 = y->num;
174 if (!fmpq_mpoly_is_one(g1, ctx))
175 {
176 fmpq_mpoly_div(res->num, x->num, g1, ctx);
177 fmpq_mpoly_div(g1, y->den, g1, ctx);
178 n1 = res->num; d2 = g1;
179 }
180 if (!fmpq_mpoly_is_one(g2, ctx))
181 {
182 fmpq_mpoly_div(res->den, y->num, g2, ctx);
183 fmpq_mpoly_div(g2, x->den, g2, ctx);
184 n2 = res->den; d1 = g2;
185 }
186 fmpq_mpoly_mul(res->num, n1, n2, ctx);
187 fmpq_mpoly_mul(res->den, d1, d2, ctx);
188 fmpq_mpoly_clear(g1, ctx);
189 fmpq_mpoly_clear(g2, ctx);
190 }
191 fmpq_rat_canonicalise(res, c);
192 #ifdef QA_DEBUG
193 res->p=n_Mult(x->p,y->p, ((data_ptr)c->data)->C);
194 #endif
195 n_Test((number)res, c);
196 return (number) res;
197}
198
199static number Sub(number a, number b, const coeffs c)
200{
201 fmpq_rat_ptr res = (fmpq_rat_ptr) omAlloc(sizeof(fmpq_rat_struct));
202 fmpq_rat_init(res, c);
203 const fmpq_rat_ptr x = (fmpq_rat_ptr) a;
204 const fmpq_rat_ptr y = (fmpq_rat_ptr) b;
205 const fmpq_ctx_ptr ctx = (fmpq_ctx_ptr) ((data_ptr)c->data)->ctx;
206 if (fmpq_mpoly_equal(x->den, y->den, ctx)) /* denominators equal */
207 {
208 fmpq_mpoly_sub(res->num, x->num, y->num, ctx);
209 if (fmpq_mpoly_is_zero(res->num, ctx))
210 {
211 fmpq_mpoly_one(res->den, ctx);
212 n_Test((number)res,c);
213 return (number)res;
214 }
215 else
216 if (fmpq_mpoly_is_one(x->den, ctx))
217 {
218 fmpq_mpoly_set(res->den, x->den, ctx);
219 n_Test((number)res,c);
220 return (number)res;
221 }
222 else
223 {
224 fmpq_mpoly_t gd;
225 fmpq_mpoly_init(gd, ctx);
226 fmpq_mpoly_gcd(gd, res->num, x->den, ctx);
227 if (fmpq_mpoly_is_one(gd, ctx))
228 {
229 fmpq_mpoly_set(res->den, x->den, ctx);
230 }
231 else
232 {
233 fmpq_mpoly_div(res->den, x->den, gd, ctx);
234 fmpq_mpoly_div(res->num, res->num, gd, ctx);
235 }
236 fmpq_mpoly_clear(gd, ctx);
237 }
238 }
239 else if (fmpq_mpoly_is_one(x->den, ctx)) /* first denominator 1 */
240 {
241 fmpq_mpoly_mul(res->num, x->num, y->den, ctx);
242 fmpq_mpoly_sub(res->num, res->num, y->num, ctx);
243 if (fmpq_mpoly_is_zero(res->num, ctx))
244 {
245 fmpq_mpoly_one(res->den, ctx);
246 n_Test((number)res,c);
247 return (number)res;
248 }
249 else
250 {
251 fmpq_mpoly_set(res->den, y->den, ctx);
252 }
253 }
254 else if (fmpq_mpoly_is_one(y->den, ctx)) /* second denominator 1 */
255 {
256 fmpq_mpoly_mul(res->num, y->num, x->den, ctx);
257 fmpq_mpoly_sub(res->num, x->num, res->num, ctx);
258 if (fmpq_mpoly_is_zero(res->num,ctx))
259 {
260 fmpq_mpoly_one(res->den, ctx);
261 n_Test((number)res,c);
262 return (number)res;
263 }
264 else
265 {
266 fmpq_mpoly_set(res->den, x->den, ctx);
267 }
268 }
269 else /* general case */
270 {
271 fmpq_mpoly_t gd;
272 fmpq_mpoly_init(gd, ctx);
273 fmpq_mpoly_gcd(gd, x->den, y->den, ctx);
274 if (fmpq_mpoly_is_one(gd, ctx))
275 {
276 fmpq_mpoly_mul(res->num, x->num, y->den, ctx);
277 fmpq_mpoly_mul(gd, y->num, x->den, ctx);
278 fmpq_mpoly_sub(res->num, res->num, gd, ctx);
279 if (fmpq_mpoly_is_zero(res->num,ctx))
280 {
281 fmpq_mpoly_one(res->den, ctx);
282 n_Test((number)res,c);
283 return (number)res;
284 }
285 else
286 {
287 fmpq_mpoly_mul(res->den, x->den, y->den, ctx);
288 }
289 }
290 else
291 {
292 fmpq_mpoly_t q2;
293 fmpq_mpoly_init(q2, ctx);
294 fmpq_mpoly_div(res->den, x->den, gd, ctx);
295 fmpq_mpoly_div(q2, y->den, gd, ctx);
296 fmpq_mpoly_mul(res->num, q2, x->num, ctx);
297 fmpq_mpoly_mul(res->den, res->den, y->num, ctx);
298 fmpq_mpoly_sub(res->num, res->num, res->den, ctx);
299 fmpq_mpoly_gcd(res->den, res->num, gd, ctx);
300 if (fmpq_mpoly_is_one(res->den, ctx))
301 {
302 fmpq_mpoly_mul(res->den, q2, x->den, ctx);
303 }
304 else
305 {
306 fmpq_mpoly_div(res->num, res->num, res->den, ctx);
307 fmpq_mpoly_div(gd, x->den, res->den, ctx);
308 fmpq_mpoly_mul(res->den, gd, q2, ctx);
309 }
310 fmpq_mpoly_clear(q2, ctx);
311 }
312 fmpq_mpoly_clear(gd, ctx);
313 }
314 #ifdef QA_DEBUG
315 res->p=n_Sub(x->p,y->p, ((data_ptr)c->data)->C);
316 #endif
317 n_Test((number)res, c);
318 return (number) res;
319}
320
321static number Add(number a, number b, const coeffs c)
322{
323 fmpq_rat_ptr res = (fmpq_rat_ptr) omAlloc(sizeof(fmpq_rat_struct));
324 fmpq_rat_init(res, c);
325 const fmpq_rat_ptr x = (fmpq_rat_ptr) a;
326 const fmpq_rat_ptr y = (fmpq_rat_ptr) b;
327 const fmpq_ctx_ptr ctx = (fmpq_ctx_ptr) ((data_ptr)c->data)->ctx;
328 if (fmpq_mpoly_equal(x->den, y->den, ctx)) /* denominators equal */
329 {
330 fmpq_mpoly_add(res->num, x->num, y->num, ctx);
331 if (fmpq_mpoly_is_zero(res->num, ctx))
332 {
333 fmpq_mpoly_one(res->den, ctx);
334 n_Test((number)res,c);
335 return (number)res;
336 }
337 else
338 if (fmpq_mpoly_is_one(x->den, ctx))
339 {
340 fmpq_mpoly_set(res->den, x->den, ctx);
341 n_Test((number)res,c);
342 return (number)res;
343 }
344 else
345 {
346 fmpq_mpoly_t gd;
347 fmpq_mpoly_init(gd, ctx);
348 fmpq_mpoly_gcd(gd, res->num, x->den, ctx);
349 if (fmpq_mpoly_is_one(gd, ctx))
350 {
351 fmpq_mpoly_set(res->den, x->den, ctx);
352 }
353 else
354 {
355 fmpq_mpoly_div(res->den, x->den, gd, ctx);
356 fmpq_mpoly_div(res->num, res->num, gd, ctx);
357 }
358 fmpq_mpoly_clear(gd, ctx);
359 }
360 }
361 else if (fmpq_mpoly_is_one(x->den, ctx)) /* first denominator 1 */
362 {
363 fmpq_mpoly_mul(res->num, x->num, y->den, ctx);
364 fmpq_mpoly_add(res->num, res->num, y->num, ctx);
365 if (fmpq_mpoly_is_zero(res->num, ctx))
366 {
367 fmpq_mpoly_one(res->den, ctx);
368 n_Test((number)res,c);
369 return (number)res;
370 }
371 else
372 {
373 fmpq_mpoly_set(res->den, y->den, ctx);
374 }
375 }
376 else if (fmpq_mpoly_is_one(y->den, ctx)) /* second denominator 1 */
377 {
378 fmpq_mpoly_mul(res->num, y->num, x->den, ctx);
379 fmpq_mpoly_add(res->num, x->num, res->num, ctx);
380 if (fmpq_mpoly_is_zero(res->num, ctx))
381 {
382 fmpq_mpoly_one(res->den, ctx);
383 n_Test((number)res,c);
384 return (number)res;
385 }
386 else
387 {
388 fmpq_mpoly_set(res->den, x->den, ctx);
389 }
390 }
391 else /* general case */
392 {
393 fmpq_mpoly_t gd;
394 fmpq_mpoly_init(gd, ctx);
395 fmpq_mpoly_gcd(gd, x->den, y->den, ctx);
396 if (fmpq_mpoly_is_one(gd, ctx))
397 {
398 fmpq_mpoly_mul(res->num, x->num, y->den, ctx);
399 fmpq_mpoly_mul(gd, y->num, x->den, ctx);
400 fmpq_mpoly_add(res->num, res->num, gd, ctx);
401 if (fmpq_mpoly_is_zero(res->num,ctx))
402 {
403 fmpq_mpoly_one(res->den, ctx);
404 n_Test((number)res,c);
405 return (number)res;
406 }
407 else
408 {
409 fmpq_mpoly_mul(res->den, x->den, y->den, ctx);
410 }
411 }
412 else
413 {
414 fmpq_mpoly_t q2;
415 fmpq_mpoly_init(q2, ctx);
416 fmpq_mpoly_div(res->den, x->den, gd, ctx);
417 fmpq_mpoly_div(q2, y->den, gd, ctx);
418 fmpq_mpoly_mul(res->num, q2, x->num, ctx);
419 fmpq_mpoly_mul(res->den, res->den, y->num, ctx);
420 fmpq_mpoly_add(res->num, res->num, res->den, ctx);
421 fmpq_mpoly_gcd(res->den, res->num, gd, ctx);
422 if (fmpq_mpoly_is_one(res->den, ctx))
423 {
424 fmpq_mpoly_mul(res->den, q2, x->den, ctx);
425 }
426 else
427 {
428 fmpq_mpoly_div(res->num, res->num, res->den, ctx);
429 fmpq_mpoly_div(gd, x->den, res->den, ctx);
430 fmpq_mpoly_mul(res->den, gd, q2, ctx);
431 }
432 fmpq_mpoly_clear(q2, ctx);
433 }
434 fmpq_mpoly_clear(gd, ctx);
435 }
436 #ifdef QA_DEBUG
437 res->p=n_Add(x->p,y->p, ((data_ptr)c->data)->C);
438 #endif
439 n_Test((number)res, c);
440 return (number) res;
441}
442
443static number Div(number a, number b, const coeffs c)
444{
445 const fmpq_rat_ptr x = (fmpq_rat_ptr) a;
446 const fmpq_rat_ptr y = (fmpq_rat_ptr) b;
447 const fmpq_ctx_ptr ctx = (fmpq_ctx_ptr) ((data_ptr)c->data)->ctx;
448 fmpq_rat_ptr res = (fmpq_rat_ptr) omAlloc(sizeof(fmpq_rat_struct));
449 fmpq_rat_init(res, c);
450 if (fmpq_mpoly_is_zero(y->num, ctx))
451 {
453 return (number)res;
454 }
455 if (fmpq_mpoly_equal(x->den, y->num, ctx)) /* denominators equal */
456 {
457 fmpq_mpoly_mul(res->num, x->num, y->den, ctx);
458 fmpq_mpoly_mul(res->den, x->den, y->num, ctx);
459 }
460 else if (fmpq_mpoly_is_one(x->den, ctx)) /* first denominator 1 */
461 {
462 fmpq_mpoly_t gd;
463 fmpq_mpoly_init(gd, ctx);
464 fmpq_mpoly_gcd(gd, x->num, y->num, ctx);
465 if (fmpq_mpoly_is_one(gd, ctx))
466 {
467 fmpq_mpoly_mul(res->num, x->num, y->den, ctx);
468 fmpq_mpoly_set(res->den, y->num, ctx);
469 }
470 else
471 {
472 fmpq_mpoly_div(res->num, x->num, gd, ctx);
473 fmpq_mpoly_mul(res->num, res->num, y->den, ctx);
474 fmpq_mpoly_div(res->den, y->num, gd, ctx);
475 }
476 fmpq_mpoly_clear(gd, ctx);
477 }
478 else if (fmpq_mpoly_is_one(y->num, ctx)) /* second denominator 1 */
479 {
480 fmpq_mpoly_t gd;
481 fmpq_mpoly_init(gd, ctx);
482 fmpq_mpoly_gcd(gd, y->den, x->den, ctx);
483 if (fmpq_mpoly_is_one(gd, ctx))
484 {
485 fmpq_mpoly_mul(res->num, y->den, x->num, ctx);
486 fmpq_mpoly_set(res->den, x->den, ctx);
487 }
488 else
489 {
490 fmpq_mpoly_div(res->num, y->den, gd, ctx);
491 fmpq_mpoly_mul(res->num, res->num, x->num, ctx);
492 fmpq_mpoly_div(res->den, x->den, gd, ctx);
493 }
494 fmpq_mpoly_clear(gd, ctx);
495 }
496 else /* general case */
497 {
498 fmpq_mpoly_t g1, g2;
499 fmpq_mpoly_ptr n1, n2, d1, d2;
500 fmpq_mpoly_init(g1, ctx);
501 fmpq_mpoly_init(g2, ctx);
502 fmpq_mpoly_gcd(g1, x->num, y->num, ctx);
503 fmpq_mpoly_gcd(g2, y->den, x->den, ctx);
504 n1 = x->num; d2 = y->num;
505 d1 = x->den; n2 = y->den;
506 if (!fmpq_mpoly_is_one(g1, ctx))
507 {
508 fmpq_mpoly_div(res->num, x->num, g1, ctx);
509 fmpq_mpoly_div(g1, y->num, g1, ctx);
510 n1 = res->num; d2 = g1;
511 }
512 if (!fmpq_mpoly_is_one(g2, ctx))
513 {
514 fmpq_mpoly_div(res->den, y->den, g2, ctx);
515 fmpq_mpoly_div(g2, x->den, g2, ctx);
516 n2 = res->den; d1 = g2;
517 }
518 fmpq_mpoly_mul(res->num, n1, n2, ctx);
519 fmpq_mpoly_mul(res->den, d1, d2, ctx);
520 fmpq_mpoly_clear(g1, ctx);
521 fmpq_mpoly_clear(g2, ctx);
522 }
523 fmpq_rat_canonicalise(res, c);
524 #ifdef QA_DEBUG
525 res->p=n_Div(x->p,y->p, ((data_ptr)c->data)->C);
526 #endif
527 n_Test((number)res, c);
528 return (number) res;
529}
530
531static number ExactDiv(number a, number b, const coeffs c)
532{
533 const fmpq_rat_ptr x = (fmpq_rat_ptr) a;
534 const fmpq_rat_ptr y = (fmpq_rat_ptr) b;
535 const fmpq_ctx_ptr ctx = (fmpq_ctx_ptr) ((data_ptr)c->data)->ctx;
536 fmpq_rat_ptr res = (fmpq_rat_ptr) omAlloc(sizeof(fmpq_rat_struct));
537 fmpq_rat_init(res, c);
538 if (fmpq_mpoly_is_zero(y->num, ctx))
539 {
541 return (number)res;
542 }
543 fmpq_mpoly_div(res->num, x->num, y->num, ctx);
544 assume(fmpq_mpoly_is_one(x->den, ctx));
545 assume(fmpq_mpoly_is_one(y->den, ctx));
546 #ifdef QA_DEBUG
547 res->p=n_ExactDiv(x->p,y->p, ((data_ptr)c->data)->C);
548 #endif
549 n_Test((number)res,c);
550 return (number) res;
551}
552
553// static number IntMod(number a, number b, const coeffs c);
554// {
555// }
556
557static number Init(long i, const coeffs c)
558{
559 fmpq_rat_ptr res = (fmpq_rat_ptr) omAlloc(sizeof(fmpq_rat_struct));
560 const fmpq_ctx_ptr ctx = (fmpq_ctx_ptr) ((data_ptr)c->data)->ctx;
561 fmpq_rat_init(res, c);
562 fmpq_mpoly_set_si(res->num, (slong) i, ctx);
563 fmpq_mpoly_set_si(res->den, (slong) 1, ctx);
564 #ifdef QA_DEBUG
565 res->p=n_Init(i, ((data_ptr)c->data)->C);
566 #endif
567 n_Test((number)res,c);
568 return (number) res;
569}
570
571static number InitMPZ(mpz_t i, const coeffs c)
572{
573 fmpq_rat_ptr res = (fmpq_rat_ptr) omAlloc(sizeof(fmpq_rat_struct));
574 const fmpq_ctx_ptr ctx = (fmpq_ctx_ptr) ((data_ptr)c->data)->ctx;
575 fmpz_t t;
576 fmpz_init(t);
577 fmpz_set_mpz(t, i);
578 fmpq_rat_init(res, c);
579 fmpq_mpoly_set_fmpz(res->num, t, ctx);
580 fmpq_mpoly_set_si(res->den, (slong) 1, ctx);
581 fmpz_clear(t);
582 #ifdef QA_DEBUG
583 res->p=n_InitMPZ(i, ((data_ptr)c->data)->C);
584 #endif
585 n_Test((number)res,c);
586 return (number) res;
587}
588
589static int Size(number n, const coeffs c)
590{
591 const fmpq_rat_ptr x = (fmpq_rat_ptr) n;
592 const fmpq_ctx_ptr ctx = (fmpq_ctx_ptr) ((data_ptr)c->data)->ctx;
593 if (fmpq_mpoly_is_zero(x->num, ctx))
594 return 0;
595 unsigned long len=fmpq_mpoly_length(x->num, ctx) +
596 fmpq_mpoly_length(x->den, ctx)-fmpq_mpoly_is_one(x->den, ctx);
597 unsigned long numDegree=fmpq_mpoly_total_degree_si(x->num, ctx);
598 unsigned long denDegree=fmpq_mpoly_total_degree_si(x->den, ctx);
599 unsigned long t= ((numDegree + denDegree)*(numDegree + denDegree) + 1) * len;
600 if (t>INT_MAX) return INT_MAX;
601 else return (int)t;
602}
603
604static long Int(number &n, const coeffs c)
605{
606 const fmpq_rat_ptr x = (fmpq_rat_ptr) n;
607 const fmpq_ctx_ptr ctx = (fmpq_ctx_ptr) ((data_ptr)c->data)->ctx;
608 if (fmpq_mpoly_is_fmpq(x->den, ctx) && fmpq_mpoly_is_fmpq(x->num, ctx))
609 {
610 long nl = 0;
611 fmpq_t r;
612 fmpq_init(r);
613 fmpq_div(r, x->num->content, x->den->content);
614 if (fmpz_is_one(fmpq_denref(r)))
615 {
616 if (fmpz_fits_si(fmpq_numref(r)))
617 nl = fmpz_get_si(fmpq_numref(r));
618 }
619 fmpq_clear(r);
620 return nl;
621 }
622 return 0;
623}
624
625static void MPZ(mpz_t result, number &n, const coeffs c)
626{
627 mpz_init(result);
628 const fmpq_rat_ptr x = (fmpq_rat_ptr) n;
629 const fmpq_ctx_ptr ctx = (fmpq_ctx_ptr) ((data_ptr)c->data)->ctx;
630 if (fmpq_mpoly_is_fmpq(x->den, ctx) && fmpq_mpoly_is_fmpq(x->num, ctx))
631 {
632 fmpq_t r;
633 fmpq_init(r);
634 fmpq_div(r, x->num->content, x->den->content);
635 if (fmpz_is_one(fmpq_denref(r)))
636 {
637 fmpz_get_mpz(result, fmpq_numref(r));
638 }
639 fmpq_clear(r);
640 }
641}
642
643static number Neg(number a, const coeffs c)
644{
645 const fmpq_rat_ptr x = (fmpq_rat_ptr) a;
646 const fmpq_ctx_ptr ctx = (fmpq_ctx_ptr) ((data_ptr)c->data)->ctx;
647 fmpq_mpoly_neg(x->num, x->num, ctx);
648 #ifdef QA_DEBUG
649 x->p=n_InpNeg(x->p, ((data_ptr)c->data)->C);
650 #endif
651 n_Test((number)a, c);
652 return a;
653}
654
655static number Invers(number a, const coeffs c)
656{
657 const fmpq_rat_ptr x = (fmpq_rat_ptr) a;
658 const fmpq_ctx_ptr ctx = (fmpq_ctx_ptr) ((data_ptr)c->data)->ctx;
659 if (fmpq_mpoly_is_zero(x->num, ctx))
660 {
662 return NULL;
663 }
664 else
665 {
666 fmpq_rat_ptr res = (fmpq_rat_ptr) omAlloc(sizeof(fmpq_rat_struct));
667 fmpq_rat_init(res, c);
668 fmpq_mpoly_set(res->num, x->den, ctx);
669 fmpq_mpoly_set(res->den, x->num, ctx);
670 #ifdef QA_DEBUG
671 res->p=n_Invers(x->p, ((data_ptr)c->data)->C);
672 #endif
673 n_Test((number)res, c);
674 return (number) res;
675 }
676}
677
678static number Copy(number a, const coeffs c)
679{
680 fmpq_rat_ptr res = (fmpq_rat_ptr) omAlloc(sizeof(fmpq_rat_struct));
681 fmpq_rat_init(res, c);
682 const fmpq_rat_ptr x = (fmpq_rat_ptr) a;
683 const fmpq_ctx_ptr ctx = (fmpq_ctx_ptr) ((data_ptr)c->data)->ctx;
684 fmpq_mpoly_set(res->num, x->num, ctx);
685 fmpq_mpoly_set(res->den, x->den, ctx);
686 #ifdef QA_DEBUG
687 res->p=n_Copy(x->p, ((data_ptr)c->data)->C);
688 #endif
689 n_Test((number)res, c);
690 return (number) res;
691}
692
693//static number RePart(number a, const coeffs c)
694//{
695//}
696
697//static number ImPart(number a, const coeffs c)
698//{
699//}
700
701static BOOLEAN IsOne(number a, const coeffs c)
702{
703 if (a==NULL) return FALSE;
704 const fmpq_rat_ptr x = (fmpq_rat_ptr) a;
705 const fmpq_ctx_ptr ctx = (fmpq_ctx_ptr) ((data_ptr)c->data)->ctx;
706 if (!fmpq_mpoly_is_fmpq(x->num, ctx))
707 return FALSE;
708 if (!fmpq_mpoly_is_fmpq(x->den, ctx))
709 return FALSE;
710 return fmpq_equal(x->num->content, x->den->content);
711}
712
713static BOOLEAN IsZero(number a, const coeffs c)
714{
715 const fmpq_rat_ptr x = (fmpq_rat_ptr) a;
716 const fmpq_ctx_ptr ctx = (fmpq_ctx_ptr) ((data_ptr)c->data)->ctx;
717 return fmpq_mpoly_is_zero(x->num, ctx);
718}
719
720static void WriteLong(number a, const coeffs c)
721{
722 if (a==NULL)
723 {
724 StringAppendS("o");
725 return;
726 }
727 n_Test(a,c);
728 const fmpq_rat_ptr x = (fmpq_rat_ptr) a;
729 const fmpq_ctx_ptr ctx = (fmpq_ctx_ptr) ((data_ptr)c->data)->ctx;
730 if (fmpq_mpoly_is_zero(x->den, ctx))
731 {
732 StringAppendS("?/o");
733 return;
734 }
735 fmpz_t t;
736 long int i, j, k, nmax_i, dmax_i, max_digits;
737 fmpq_rat_canonicalise(x, c);
738 if (fmpq_mpoly_is_zero(x->num, ctx))
739 StringAppendS("0");
740 else
741 {
742 BOOLEAN num_is_const = fmpq_mpoly_is_fmpq(x->num, ctx);
743 BOOLEAN den_is_const = fmpq_mpoly_is_fmpq(x->den, ctx);
744 BOOLEAN need_times;
745 fmpq_mpoly_struct * znum = x->num;
746 fmpq_mpoly_struct * zden = x->den;
747 slong nvars = fmpq_mpoly_ctx_nvars(ctx);
748 fmpz_init(t);
749 nmax_i = 0;
750 dmax_i = 0;
751 for (i = 1; i < fmpq_mpoly_length(znum, ctx); i++)
752 {
753 if (fmpz_cmpabs(fmpq_mpoly_zpoly_term_coeff_ref(znum, i, ctx),
754 fmpq_mpoly_zpoly_term_coeff_ref(znum, nmax_i, ctx)) > 0)
755 {
756 nmax_i = i;
757 }
758 }
759 for (i = 1; i < fmpq_mpoly_length(zden, ctx); i++)
760 {
761 if (fmpz_cmpabs(fmpq_mpoly_zpoly_term_coeff_ref(zden, i, ctx),
762 fmpq_mpoly_zpoly_term_coeff_ref(zden, dmax_i, ctx)) > 0)
763 {
764 dmax_i = i;
765 }
766 }
767 if (fmpz_cmpabs(fmpq_mpoly_zpoly_term_coeff_ref(znum, nmax_i, ctx),
768 fmpq_mpoly_zpoly_term_coeff_ref(zden, dmax_i, ctx)) > 0)
769 {
770 fmpz_mul(t, fmpq_numref(x->num->content),
771 fmpq_mpoly_zpoly_term_coeff_ref(znum, nmax_i, ctx));
772 max_digits = fmpz_sizeinbase(t, 10);
773 }
774 else
775 {
776 fmpz_mul(t, fmpq_numref(x->den->content),
777 fmpq_mpoly_zpoly_term_coeff_ref(zden, dmax_i, ctx));
778 max_digits =fmpz_sizeinbase(t, 10);
779 }
780 char *s = (char*) omAlloc(max_digits + 5);
781 if (!num_is_const)
782 StringAppendS("(");
783 if (fmpq_mpoly_is_one(x->num, ctx))
784 StringAppendS("1");
785 else
786 {
787 for (i = 0; i < fmpq_mpoly_length(x->num, ctx); i++)
788 {
789 need_times = TRUE;
790 fmpz_mul(t, fmpq_mpoly_zpoly_term_coeff_ref(znum, i, ctx),
791 fmpq_numref(x->num->content));
792 if (i != 0 && fmpz_sgn(t) > 0)
793 StringAppendS("+");
794 BOOLEAN need_1=FALSE;
795 if (!fmpz_is_one(t))
796 {
797 fmpz_get_str(s, 10, t);
798 {
799 int l=strlen(s);
800 while((l>0)&&(!isdigit(s[l]))) l--;
801 s[l+1]='\0';
802 }
803 if (strcmp(s,"-1")==0)
804 {
805 StringAppendS("-");
806 need_1 = TRUE;
807 need_times = FALSE;
808 }
809 else
811 }
812 else
813 {
814 need_1 = TRUE;
815 need_times = FALSE;
816 }
817 for (j = 0; j < c->iNumberOfParameters; j++)
818 {
819 k = fmpq_mpoly_get_term_var_exp_ui(x->num, i, j, ctx);
820 if (k != 0)
821 {
822 need_1 = FALSE;
823 if (need_times)
824 StringAppendS("*");
825 if (k != 1)
826 StringAppend("%s^%d", c->pParameterNames[j], k);
827 else
828 StringAppendS(c->pParameterNames[j]);
829 need_times = TRUE;
830 }
831 }
832 if (need_1) StringAppendS("1");
833 }
834 }
835 if (!num_is_const)
836 StringAppendS(")");
837 if (!fmpq_mpoly_is_one(x->den, ctx))
838 {
839 BOOLEAN closing_paren=FALSE;
840 StringAppendS("/");
841 if (!den_is_const)
842 {
843 StringAppendS("(");
844 closing_paren = TRUE;
845 }
846 for (i = 0; i < fmpq_mpoly_length(x->den, ctx); i++)
847 {
848 need_times = TRUE;
849 fmpz_mul(t, fmpq_mpoly_zpoly_term_coeff_ref(zden, i, ctx),
850 fmpq_numref(x->den->content));
851 if (i == 0)
852 {
853 if ((fmpz_sgn(t) < 0) && den_is_const)
854 {
855 StringAppendS("(");
856 closing_paren = TRUE;
857 }
858 }
859 else if (fmpz_sgn(t) > 0)
860 StringAppendS("+");
861 if (!fmpz_is_one(t))
862 {
863 fmpz_get_str(s, 10, t);
864 {
865 int l=strlen(s);
866 while((l>0)&&(!isdigit(s[l]))) l--;
867 s[l+1]='\0';
868 }
870 }
871 else
872 {
873 need_times = FALSE;
874 }
875 for (j = 0; j < nvars; j++)
876 {
877 k = fmpq_mpoly_get_term_var_exp_ui(x->den, i, j, ctx);
878 if (k != 0)
879 {
880 if (need_times)
881 StringAppendS("*");
882 if (k != 1)
883 StringAppend("%s^%d", c->pParameterNames[j], k);
884 else
885 StringAppendS(c->pParameterNames[j]);
886 need_times = TRUE;
887 }
888 }
889 }
890 if (closing_paren)
891 StringAppendS(")");
892 }
893 fmpz_clear(t);
894 omFree(s);
895 }
896}
897
898static void WriteShort(number a, const coeffs c)
899{
900 const fmpq_rat_ptr x = (fmpq_rat_ptr) a;
901 const fmpq_ctx_ptr ctx = (fmpq_ctx_ptr) ((data_ptr)c->data)->ctx;
902 fmpz_t t;
903 char *s;
904 long int i, j, k, nmax_i, dmax_i, max_digits;
905 fmpq_rat_canonicalise(x, c);
906 if (fmpq_mpoly_is_zero(x->num, ctx))
907 StringAppendS("0");
908 else
909 {
910 BOOLEAN num_is_const = fmpq_mpoly_is_fmpq(x->num, ctx);
911 BOOLEAN den_is_const = fmpq_mpoly_is_fmpq(x->den, ctx);
912 fmpq_mpoly_struct * znum = x->num;
913 fmpq_mpoly_struct * zden = x->den;
914 slong nvars = fmpq_mpoly_ctx_nvars(ctx);
915 fmpz_init(t);
916 nmax_i = 0;
917 dmax_i = 0;
918 for (i = 1; i < fmpq_mpoly_length(znum, ctx); i++)
919 {
920 if (fmpz_cmpabs(fmpq_mpoly_zpoly_term_coeff_ref(znum, i, ctx),
921 fmpq_mpoly_zpoly_term_coeff_ref(znum, nmax_i, ctx)) > 0)
922 {
923 nmax_i = i;
924 }
925 }
926 for (i = 1; i < fmpq_mpoly_length(zden, ctx); i++)
927 {
928 if (fmpz_cmpabs(fmpq_mpoly_zpoly_term_coeff_ref(zden, i, ctx),
929 fmpq_mpoly_zpoly_term_coeff_ref(zden, dmax_i, ctx)) > 0)
930 {
931 dmax_i = i;
932 }
933 }
934 if (fmpz_cmpabs(fmpq_mpoly_zpoly_term_coeff_ref(znum, nmax_i, ctx),
935 fmpq_mpoly_zpoly_term_coeff_ref(zden, dmax_i, ctx)) > 0)
936 {
937 fmpz_mul(t, fmpq_numref(x->num->content),
938 fmpq_mpoly_zpoly_term_coeff_ref(znum, nmax_i, ctx));
939 max_digits = fmpz_sizeinbase(t, 10);
940 } else
941 {
942 fmpz_mul(t, fmpq_numref(x->den->content),
943 fmpq_mpoly_zpoly_term_coeff_ref(zden, dmax_i, ctx));
944 max_digits = fmpz_sizeinbase(t, 10);
945 }
946 s = (char*) omAlloc(max_digits + 2);
947 if (!num_is_const)
948 StringAppendS("(");
949 if (fmpq_mpoly_is_one(x->num, ctx))
950 StringAppendS("1");
951 else
952 {
953 for (i = 0; i < fmpq_mpoly_length(x->num, ctx); i++)
954 {
955 fmpz_mul(t, fmpq_mpoly_zpoly_term_coeff_ref(znum, i, ctx),
956 fmpq_numref(x->num->content));
957 if (i != 0 && fmpz_sgn(t) > 0)
958 StringAppendS("+");
959 if (!fmpz_is_one(t))
960 {
961 fmpz_get_str(s, 10, t);
963 }
964 for (j = 0; j < nvars; j++)
965 {
966 k = fmpq_mpoly_get_term_var_exp_ui(x->num, i, j, ctx);
967 if (k != 0)
968 {
969 if (k != 1)
970 StringAppend("%s%d", c->pParameterNames[j], k);
971 else
972 StringAppendS(c->pParameterNames[j]);
973 }
974 }
975 }
976 }
977 if (!num_is_const)
978 StringAppendS(")");
979 if (!fmpq_mpoly_is_one(x->den, ctx))
980 {
981 StringAppendS("/");
982 if (!den_is_const)
983 StringAppendS("(");
984 for (i = 0; i < fmpq_mpoly_length(x->den, ctx); i++)
985 {
986 fmpz_mul(t, fmpq_mpoly_zpoly_term_coeff_ref(zden, i, ctx),
987 fmpq_numref(x->den->content));
988 if (i != 0 && fmpz_sgn(t) > 0)
989 StringAppendS("+");
990 if (!fmpz_is_one(t))
991 {
992 fmpz_get_str(s, 10, t);
994 }
995 for (j = 0; j < nvars; j++)
996 {
997 k = fmpq_mpoly_get_term_var_exp_ui(x->num, i, j, ctx);
998 if (k != 0)
999 {
1000 if (k != 1)
1001 StringAppend("%s%d", c->pParameterNames[j], k);
1002 else
1003 StringAppendS(c->pParameterNames[j]);
1004 }
1005 }
1006 }
1007 if (!den_is_const)
1008 StringAppendS(")");
1009 }
1010 fmpz_clear(t);
1011 }
1012}
1013
1014static const char* Read(const char * st, number * a, const coeffs c)
1015{
1016 // we only read "monomials" (i.e. [-][digits][parameter]),
1017 // everything else (+,*,^,()) is left to the singular interpreter
1018 long int j;
1019 char *s = (char *) st;
1020 const fmpq_ctx_ptr ctx = (fmpq_ctx_ptr) ((data_ptr)c->data)->ctx;
1021 slong nvars = fmpq_mpoly_ctx_nvars(ctx);
1022 *a = (number) omAlloc(sizeof(fmpq_rat_struct));
1023 fmpq_rat_init((fmpq_rat_ptr)(*a), c);
1024 BOOLEAN neg = FALSE;
1025 if (*s=='-')
1026 {
1027 neg = TRUE;
1028 s++;
1029 }
1030 if (isdigit(*s))
1031 {
1032 fmpz_t z;
1033 fmpz_init(z);
1034 s = nlEatLong((char *) s, z);
1035 fmpq_mpoly_set_fmpz(((fmpq_rat_ptr)(*a))->num, z, ctx);
1036 fmpq_mpoly_one(((fmpq_rat_ptr)(*a))->den, ctx);
1037 if (*s == '/')
1038 {
1039 s++;
1040 s = nlEatLong((char *) s, z);
1041 fmpq_mpoly_scalar_div_fmpz(((fmpq_rat_ptr)(*a))->num,
1042 ((fmpq_rat_ptr)(*a))->num, z, ctx);
1043 }
1044 fmpz_clear(z);
1045 }
1046 else
1047 {
1049 for (j = 0; j < nvars; j++)
1050 {
1051 if (strncmp(s, c->pParameterNames[j],
1052 strlen(c->pParameterNames[j])) == 0)
1053 {
1054 found=TRUE;
1055 fmpq_mpoly_gen(((fmpq_rat_ptr)(*a))->num, j, ctx);
1056 s += strlen(c->pParameterNames[j]);
1057 if (isdigit(*s))
1058 {
1059 int i = 1;
1060 s = nEati(s, &i, 0);
1061 if (i != 1)
1062 {
1063 fmpq_mpoly_pow_ui(((fmpq_rat_ptr)(*a))->num,
1064 ((fmpq_rat_ptr)(*a))->num, (long int) i, ctx);
1065 }
1066 }
1067 }
1068 }
1069 if (!found) fmpq_mpoly_one(((fmpq_rat_ptr)(*a))->num, ctx);
1070 fmpq_mpoly_one(((fmpq_rat_ptr)(*a))->den, ctx);
1071 }
1072 if (neg)
1073 fmpq_mpoly_neg(((fmpq_rat_ptr)(*a))->num, ((fmpq_rat_ptr)(*a))->num, ctx);
1074 #ifdef QA_DEBUG
1075 poly pp=convFlintMPSingP(((fmpq_rat_ptr)(*a))->num,ctx,((data_ptr)c->data)->C->extRing);
1076 fraction f=(fraction)n_Init(1,((data_ptr)c->data)->C); /*leak*/
1077 NUM(f)=pp;
1078 ((fmpq_rat_ptr)(*a))->p=(number)f;
1079 #endif
1080 n_Test((*a),c);
1081 return s;
1082}
1083
1084static BOOLEAN Greater(number a, number b, const coeffs c)
1085{
1086 return Size(a, c) > Size(b, c);
1087}
1088
1089static void Delete(number * a, const coeffs c)
1090{
1091 if ((*a) != NULL)
1092 {
1093 const fmpq_rat_ptr x = (fmpq_rat_ptr) *a;
1094 fmpq_rat_clear(x, c);
1095 #ifdef QA_DEBUG
1096 n_Delete(&(x->p),((data_ptr)c->data)->C);
1097 #endif
1098 omFree(*a);
1099 *a = NULL;
1100 }
1101}
1102
1103static BOOLEAN Equal(number a, number b, const coeffs c)
1104{
1105 const fmpq_rat_ptr x = (fmpq_rat_ptr) a;
1106 const fmpq_rat_ptr y = (fmpq_rat_ptr) b;
1107 const fmpq_ctx_ptr ctx = (fmpq_ctx_ptr) ((data_ptr)c->data)->ctx;
1108 if (!fmpz_mpoly_equal(x->num->zpoly, y->num->zpoly, ctx->zctx))
1109 {
1110 return FALSE;
1111 }
1112 if (!fmpz_mpoly_equal(x->den->zpoly, y->den->zpoly, ctx->zctx))
1113 {
1114 return FALSE;
1115 }
1116 fmpz_t t1, t2;
1117 fmpz_init(t1);
1118 fmpz_init(t2);
1119 fmpz_mul(t1, fmpq_numref(x->num->content), fmpq_denref(x->den->content));
1120 fmpz_mul(t1, t1, fmpq_denref(y->num->content));
1121 fmpz_mul(t1, t1, fmpq_numref(y->den->content));
1122 fmpz_mul(t2, fmpq_numref(y->num->content), fmpq_denref(y->den->content));
1123 fmpz_mul(t2, t2, fmpq_denref(x->num->content));
1124 fmpz_mul(t2, t2, fmpq_numref(x->den->content));
1125 int eq = fmpz_equal(t1, t2);
1126 fmpz_clear(t1);
1127 fmpz_clear(t2);
1128 return eq;
1129}
1130
1131static BOOLEAN IsMOne(number a, const coeffs c)
1132{
1133 if (a==NULL) return FALSE;
1134 fmpq_t content;
1135 const fmpq_rat_ptr x = (fmpq_rat_ptr) a;
1136 const fmpq_ctx_ptr ctx = (fmpq_ctx_ptr) ((data_ptr)c->data)->ctx;
1137 if (!fmpq_mpoly_is_fmpq(x->num, ctx))
1138 return FALSE;
1139 if (!fmpq_mpoly_is_fmpq(x->den, ctx))
1140 return FALSE;
1141 fmpq_init(content);
1142 fmpq_neg(content, x->num->content);
1143 int eq = fmpq_equal(content, x->den->content);
1144 fmpq_clear(content);
1145 return eq;
1146}
1147
1148static BOOLEAN GreaterZero(number, const coeffs)
1149{
1150 return TRUE; /* everything in parens for now so need + sign */
1151}
1152
1153static void Power(number a, int i, number * result, const coeffs c)
1154{
1155 *result= (number) omAlloc(sizeof(fmpq_rat_struct));
1156 fmpq_rat_init((fmpq_rat_ptr) (*result), c);
1157 const fmpq_rat_ptr x = (fmpq_rat_ptr) a;
1158 const fmpq_ctx_ptr ctx = (fmpq_ctx_ptr) ((data_ptr)c->data)->ctx;
1159 fmpq_mpoly_pow_ui(((fmpq_rat_ptr)(*result))->num, x->num, (slong) i, ctx);
1160 fmpq_mpoly_pow_ui(((fmpq_rat_ptr)(*result))->den, x->den, (slong) i, ctx);
1161}
1162
1163static number GetDenom(number &n, const coeffs c)
1164{
1165 const fmpq_rat_ptr x = (fmpq_rat_ptr) n;
1166 const fmpq_ctx_ptr ctx = (fmpq_ctx_ptr) ((data_ptr)c->data)->ctx;
1167 fmpq_rat_ptr res = (fmpq_rat_ptr) omAlloc(sizeof(fmpq_rat_struct));
1168 fmpq_rat_init(res, c);
1169 fmpq_mpoly_set(res->num, x->den, ctx);
1170 fmpq_mpoly_one(res->den, ctx);
1171 return (number) res;
1172}
1173
1174static number GetNumerator(number &n, const coeffs c)
1175{
1176 const fmpq_rat_ptr x = (fmpq_rat_ptr) n;
1177 const fmpq_ctx_ptr ctx = (fmpq_ctx_ptr) ((data_ptr)c->data)->ctx;
1178 fmpq_rat_ptr res = (fmpq_rat_ptr) omAlloc(sizeof(fmpq_rat_struct));
1179 fmpq_rat_init(res, c);
1180 fmpq_mpoly_set(res->num, x->num, ctx);
1181 fmpq_mpoly_one(res->den, ctx);
1182 return (number) res;
1183}
1184
1185static number ExtGcd(number /*a*/, number /*b*/, number* /*s*/, number* /*t*/, const coeffs /*c*/)
1186{
1187 WerrorS("not a Euclidean ring: ExtGcd");
1188 return NULL;
1189}
1190
1191static number Lcm(number /*a*/, number /*b*/, const coeffs /*c*/)
1192{
1193 WerrorS("not yet: Lcm");
1194 return NULL;
1195}
1196
1197static number Q2Frac(number a, const coeffs /*src*/, const coeffs dst)
1198{
1199 number res;
1200 if (SR_HDL(a) & SR_INT)
1201 {
1202 res=Init(SR_TO_INT(a),dst);
1203 n_Test(res,dst);
1204 }
1205 else if (a->s==3)
1206 {
1207 res=InitMPZ(a->z,dst);
1208 n_Test(res,dst);
1209 }
1210 else
1211 {
1212 number z=InitMPZ(a->z,dst);
1213 number n=InitMPZ(a->n,dst);
1214 res=Div(z,n,dst);
1215 Delete(&z,dst);
1216 Delete(&n,dst);
1217 n_Test(res,dst);
1218 return res;
1219 }
1220 return res;
1221}
1222
1223static number Z2Frac(number a, const coeffs /*src*/, const coeffs dst)
1224{
1225 return InitMPZ((mpz_ptr)a,dst);
1226}
1227
1228static number Zp2Frac(number a, const coeffs src, const coeffs dst)
1229{
1230 return Init(n_Int(a,src),dst);
1231}
1232
1233static nMapFunc SetMap(const coeffs src, const coeffs dst)
1234{
1235 if (src == dst) return ndCopyMap;
1236 if (nCoeff_is_Q_or_BI(src) && (src->rep==n_rep_gap_rat)) /*Q, coeffs_BIGINT */
1237 return Q2Frac;
1238 if(src->rep==n_rep_gap_gmp) /*Z */
1239 return Z2Frac;
1240 if(nCoeff_is_Zp(src))
1241 return Zp2Frac;
1242
1243 return NULL;
1244}
1245
1246//static void InpMult(number &a, number b, const coeffs c)
1247//{
1248//}
1249
1250//static void InpAdd(number &a, number b, const coeffs c)
1251//{
1252//}
1253
1254#if 0
1255static number Init_bigint(number i, const coeffs dummy, const coeffs dst)
1256{
1257 const fmpq_ctx_ptr ctx = (fmpq_ctx_ptr) ((data_ptr)(dst->data))->ctx;
1258 fmpq_rat_ptr res = (fmpq_rat_ptr) omAlloc(sizeof(fmpq_rat_struct));
1259 fmpz_t f;
1260 fmpq_rat_init(res, dst);
1261 if (SR_HDL(i) & SR_INT)
1262 {
1263 fmpq_mpoly_set_si(res->num, SR_TO_INT(i), ctx);
1264 }
1265 else
1266 {
1267 fmpz_init(f);
1268 fmpz_set_mpz(f, i->z);
1269 fmpq_mpoly_set_fmpz(res->num, f, ctx);
1270 fmpz_clear(f);
1271 }
1272 fmpq_mpoly_set_si(res->den, 1, ctx);
1273 return (number) res;
1274}
1275#endif
1276
1277#if 0
1278static number Farey(number p, number n, const coeffs c)
1279{
1280 WerrorS("not yet: Farey");
1281 return NULL;
1282}
1283#endif
1284
1285#if 0
1286static number ChineseRemainder(number *x, number *q, int rl,
1287 BOOLEAN sym, CFArray &inv_cache, const coeffs c)
1288{
1289 WerrorS("not yet: ChineseRemainder");
1290 return NULL;
1291}
1292#endif
1293
1294static int ParDeg(number a, const coeffs c)
1295{
1296 const fmpq_rat_ptr x = (fmpq_rat_ptr) a;
1297 const fmpq_ctx_ptr ctx = (fmpq_ctx_ptr) ((data_ptr)c->data)->ctx;
1298 return (int) (fmpq_mpoly_total_degree_si(x->num, ctx) -
1299 fmpq_mpoly_total_degree_si(x->den, ctx));
1300}
1301
1302static number Parameter(const int i, const coeffs c)
1303{
1304 const fmpq_ctx_ptr ctx = (fmpq_ctx_ptr) ((data_ptr)c->data)->ctx;
1305 fmpq_rat_ptr res = (fmpq_rat_ptr) omAlloc(sizeof(fmpq_rat_struct));
1306 fmpq_rat_init(res, c);
1307 fmpq_mpoly_gen(res->num, (slong) i, ctx);
1308 fmpq_mpoly_one(res->den, ctx);
1309 return (number) res;
1310}
1311
1312static number SubringGcd(number a, number b, const coeffs c)
1313{
1314 fmpq_rat_ptr res = (fmpq_rat_ptr) omAlloc(sizeof(fmpq_rat_struct));
1315 fmpq_rat_init(res, c);
1316 const fmpq_rat_ptr x = (fmpq_rat_ptr) a;
1317 const fmpq_rat_ptr y = (fmpq_rat_ptr) b;
1318 const fmpq_ctx_ptr ctx = (fmpq_ctx_ptr) ((data_ptr)c->data)->ctx;
1319 fmpq_mpoly_gcd(res->num, x->num, y->num, ctx);
1320 // handle content:
1321 fmpz_t cont;
1322 fmpz_init(cont);
1323 fmpz_gcd(cont, fmpq_numref(x->num->content), fmpq_numref(y->num->content));
1324 if (!fmpz_is_one(cont))
1325 {
1326 fmpq_mul_fmpz(res->num->content, res->num->content, cont);
1327 }
1328 fmpz_gcd(cont, fmpq_denref(x->num->content), fmpq_denref(y->num->content));
1329 if (!fmpz_is_one(cont))
1330 {
1331 fmpq_div_fmpz(res->num->content, res->num->content, cont);
1332 }
1333 fmpz_clear(cont);
1334 fmpq_mpoly_one(res->den, ctx);
1335 fmpq_rat_canonicalise(res, c);
1336 #ifdef QA_DEBUG
1337 res->p=n_SubringGcd(x->p,y->p, ((data_ptr)c->data)->C);
1338 #endif
1339 n_Test((number)res, c);
1340 return (number) res;
1341}
1342
1343static number NormalizeHelper(number a, number b, const coeffs c)
1344{
1345 fmpq_rat_ptr res = (fmpq_rat_ptr) omAlloc(sizeof(fmpq_rat_struct));
1346 fmpq_rat_init(res, c);
1347 const fmpq_rat_ptr x = (fmpq_rat_ptr) a;
1348 const fmpq_rat_ptr y = (fmpq_rat_ptr) b;
1349 const fmpq_ctx_ptr ctx = (fmpq_ctx_ptr) ((data_ptr)c->data)->ctx;
1350 fmpq_mpoly_t gd;
1351 fmpq_mpoly_init(gd,ctx);
1352 fmpq_mpoly_one(gd,ctx); // value for gd, if fmpq_mpoly_gcd fails
1353 fmpq_mpoly_gcd(gd, x->num, y->den, ctx);
1354 fmpq_mpoly_mul(res->num, x->num, y->den, ctx);
1355 if (!fmpq_mpoly_is_one(gd, ctx))// &&(!fmpq_mpoly_is_zero(gd, ctx)))
1356 fmpq_mpoly_div(res->num, res->num, gd, ctx);
1357 fmpq_mpoly_one(res->den, ctx);
1358 #ifdef QA_DEBUG
1359 res->p=n_NormalizeHelper(x->p,y->p, ((data_ptr)c->data)->C);
1360 #endif
1361 n_Test((number)res, c);
1362 return (number) res;
1363}
1364
1365#if 0
1366static void WriteFd(number a, const ssiInfo *d, const coeffs c)
1367{
1368 // format: len a_len(num den) .. a_0
1369/* Currently not implemented
1370 const fmpq_ctx_ptr ctx = (fmpq_ctx_ptr) ((data_ptr)c->data)->ctx;
1371 const fmpq_rat_ptr aa = (fmpq_rat_ptr) a;
1372 int l = fmpq_mpoly_length(aa->num, ctx);
1373 fprintf(d->f_write, "%d ", l);
1374 mpq_t m;
1375 mpq_init(m);
1376 mpz_t num, den;
1377 mpz_init(num);
1378 mpz_init(den);
1379 for(int i = l; i >= 0; i--)
1380 {
1381 fmpq_mpoly_get_coeff_mpq(m, aa->num, i);
1382 mpq_get_num(num, m);
1383 mpq_get_den(den, m);
1384 mpz_out_str(d->f_write, SSI_BASE, num);
1385 fputc(' ', d->f_write);
1386 mpz_out_str(d->f_write, SSI_BASE, den);
1387 fputc(' ', d->f_write);
1388 }
1389 mpz_clear(den);
1390 mpz_clear(num);
1391 mpq_clear(m);
1392*/
1393}
1394#endif
1395
1396#if 0
1397static number ReadFd(const ssiInfo *d, const coeffs c)
1398{
1399 // format: len a_len .. a_0
1400/* Currently not implemented
1401 fmpq_mpoly_ptr aa = (fmpq_mpoly_ptr) omAlloc(sizeof(fmpq_mpoly_t));
1402 fmpq_mpoly_init(aa);
1403 int l = s_readint(d->f_read);
1404 mpz_t nm;
1405 mpz_init(nm);
1406 mpq_t m;
1407 mpq_init(m);
1408 for (int i = l; i >= 0; i--)
1409 {
1410 s_readmpz_base(d->f_read, nm, SSI_BASE);
1411 mpq_set_num(m, nm);
1412 s_readmpz_base(d->f_read, nm, SSI_BASE);
1413 mpq_set_den(m, nm);
1414 fmpq_mpoly_set_coeff_mpq(aa, i, m);
1415 }
1416 mpz_clear(nm);
1417 mpq_clear(m);
1418 return (number)aa;
1419*/
1420 return NULL;
1421}
1422#endif
1423
1424// cfClearContent
1425
1426// cfClearDenominators
1427
1428#if 0
1429static number ConvFactoryNSingN(const CanonicalForm n, const coeffs c)
1430{
1431 WerrorS("not yet: ConvFactoryNSingN");
1432 return NULL;
1433}
1434#endif
1435
1436#if 0
1437static CanonicalForm ConvSingNFactoryN(number n, BOOLEAN setChar, const coeffs c)
1438{
1439 WerrorS("not yet: ConvSingNFactoryN");
1440 return CanonicalForm(0);
1441}
1442#endif
1443
1444char * QratCoeffName(const coeffs c)
1445{
1446 STATIC_VAR char CoeffName_flint_Qrat[200];
1447 snprintf(CoeffName_flint_Qrat,200, "flintQQ(%s",c->pParameterNames[0]);
1448 for(int i=1; i<c->iNumberOfParameters;i++)
1449 {
1450 strncat(CoeffName_flint_Qrat,",",200-strlen(CoeffName_flint_Qrat));
1451 strncat(CoeffName_flint_Qrat,c->pParameterNames[i],200-strlen(CoeffName_flint_Qrat));
1452 }
1453 strncat(CoeffName_flint_Qrat,")",200-strlen(CoeffName_flint_Qrat));
1454 return (char*) CoeffName_flint_Qrat;
1455
1456}
1457
1459{
1460 const char start[] = "flintQ(";
1461 const int start_len = strlen(start);
1462 if (strncmp(s, start, start_len) == 0)
1463 {
1464 s += start_len;
1465 // count ,
1466 char *p=s;
1467 int N=0;
1468 loop
1469 {
1470 while((*p!=',')&&(*p!=')')&&(*p!='\0')) p++;
1471 if (*p==',') { p++; N++;}
1472 else if (*p==')') { p++; N++; break;}
1473 else if (*p=='\0') { break;}
1474 }
1475 // get names
1476 char *names[N];
1477 int i=0;
1478 p=s;
1479 loop
1480 {
1481 while((*p!=',')&&(*p!=')')&&(*p!='\0')) p++;
1482 if ((*p==',')||(*p=')'))
1483 {
1484 char c=*p;
1485 *p='\0';
1486 names[i]=omStrDup(s);
1487 *p=c;
1488 i++;
1489 p++;
1490 s=p;
1491 if (c==')') break;
1492 }
1493 if (*p=='\0') break;
1494 }
1495 QaInfo pp;
1496 pp.N=N;
1497 pp.names=names;
1498 coeffs cf=nInitChar(n,&pp);
1499 for(i=0;i<N;i++) omFree(names[i]);
1500 return cf;
1501 }
1502 return NULL;
1503}
1504
1505#ifdef LDEBUG
1506static BOOLEAN DBTest(number c, const char *, const int, const coeffs cf)
1507{
1508 const fmpq_rat_ptr x = (fmpq_rat_ptr) c;
1509 if (x!=NULL)
1510 {
1511 const fmpq_ctx_ptr ctx = (fmpq_ctx_ptr) ((data_ptr)cf->data)->ctx;
1512 fmpq_mpoly_assert_canonical(x->num,ctx);
1513 fmpq_mpoly_assert_canonical(x->den,ctx);
1514 if (fmpq_mpoly_is_zero(x->den, ctx))
1515 {
1516 dReportError("den.==0\n");
1517 return FALSE;
1518 }
1519 fmpz_t n, d;
1520 fmpz_init(n);
1521 fmpz_init(d);
1522 fmpz_gcd(n, fmpq_numref(x->num->content), fmpq_numref(x->den->content));
1523 fmpz_lcm(d, fmpq_denref(x->num->content), fmpq_denref(x->den->content));
1524 if (!fmpz_is_one(d))
1525 {
1526 dReportError("canon needed (1)");
1527 return TRUE;
1528 }
1529 if (!fmpz_is_one(n))
1530 {
1531 dReportError("canon needed (2)");
1532 return TRUE;
1533 }
1534 fmpz_clear(n);
1535 fmpz_clear(d);
1536 #ifdef QA_DEBUG
1537 poly pp=convFlintMPSingP(x->num,ctx,((data_ptr)cf->data)->C->extRing);
1538 fraction f=(fraction)x->p;
1539 if (f==NULL)
1540 {
1541 dReportError("x->p==NULL\n");
1542 return FALSE;
1543 }
1544 else
1545 {
1546 if (!p_EqualPolys(pp,NUM(f),((data_ptr)cf->data)->C->extRing))
1547 {
1548 p_Write(pp,((data_ptr)cf->data)->C->extRing);
1549 PrintS("num, p=");
1550 p_Write(NUM(f),((data_ptr)cf->data)->C->extRing);
1551 dReportError("num wrong.\n");
1552 return FALSE;
1553 }
1554 if (DEN(f)!=NULL)
1555 {
1556 pp=convFlintMPSingP(x->den,ctx,((data_ptr)cf->data)->C->extRing);
1557 if (!p_EqualPolys(pp,DEN(f),((data_ptr)cf->data)->C->extRing))
1558 {
1559 p_Write(pp,((data_ptr)cf->data)->C->extRing);
1560 PrintS("den, p=");
1561 p_Write(NUM(f),((data_ptr)cf->data)->C->extRing);
1562 dReportError("den wrong.\n");
1563 return FALSE;
1564 }
1565 }
1566 }
1567 #endif
1568 }
1569 return TRUE;
1570}
1571
1572#endif
1573static void KillChar(coeffs cf)
1574{
1575 for(int i=0;i<cf->iNumberOfParameters;i++)
1576 omFree((ADDRESS)(cf->pParameterNames[i]));
1577 omFreeSize(cf->pParameterNames,sizeof(char*));
1578 const fmpq_ctx_ptr ctx = (fmpq_ctx_ptr) ((data_ptr)cf->data)->ctx;
1579 fmpq_mpoly_ctx_clear(ctx);
1580 omFree(cf->data);
1581}
1582
1583BOOLEAN flintQrat_InitChar(coeffs cf, void * infoStruct)
1584{
1585 QaInfo *pp=(QaInfo*)infoStruct;
1586 cf->cfCoeffName = QratCoeffName;
1587 cf->nCoeffIsEqual = CoeffIsEqual;
1588 cf->cfKillChar = KillChar;
1589 cf->ch = 0; //char 0
1590 cf->cfMult = Mult;
1591 cf->cfSub = Sub;
1592 cf->cfAdd = Add;
1593 cf->cfDiv = Div;
1594 cf->cfExactDiv = Div; // ???
1595 cf->cfInit = Init;
1596 cf->cfInitMPZ = InitMPZ;
1597 cf->cfSize = Size;
1598 cf->cfInt = Int;
1599 cf->cfMPZ = MPZ;
1600 cf->cfInpNeg = Neg;
1601 cf->cfInvers = Invers;
1602 cf->cfCopy = Copy;
1603 cf->cfRePart = Copy;
1604 // default: cf->cfImPart = ndReturn0;
1605 cf->cfWriteLong = WriteLong;
1606 cf->cfWriteShort = WriteLong;
1607 cf->cfRead = Read;
1608 //cf->cfNormalize = Normalize;
1609
1610 //cf->cfDivComp=
1611 //cf->cfIsUnit=
1612 //cf->cfGetUnit=
1613 //cf->cfDivBy=
1614
1615 cf->cfGreater = Greater;
1616 cf->cfEqual = Equal;
1617 cf->cfIsZero = IsZero;
1618 cf->cfIsOne = IsOne;
1619 cf->cfIsMOne = IsMOne;
1620 cf->cfGreaterZero = GreaterZero;
1621
1622 cf->cfPower = Power;
1623 cf->cfGetDenom = GetDenom;
1624 cf->cfGetNumerator = GetNumerator;
1625 cf->cfExtGcd = ExtGcd;
1626 cf->cfSubringGcd = SubringGcd;
1627 cf->cfNormalizeHelper= NormalizeHelper;
1628 cf->cfLcm = Lcm;
1629 cf->cfDelete = Delete;
1630 cf->cfSetMap = SetMap;
1631 // default: cf->cfInpMult
1632 // default: cf->cfInpAdd
1633 //cf->cfFarey =Farey;
1634 //cf->cfChineseRemainder = ChineseRemainder;
1635 cf->cfParDeg = ParDeg;
1636 cf->cfParameter = Parameter;
1637 // cf->cfClearContent = ClearContent;
1638 // cf->cfClearDenominators = ClearDenominators;
1639 //cf->convFactoryNSingN = ConvFactoryNSingN;
1640 //cf->convSingNFactoryN = ConvSingNFactoryN;
1641 //cf->cfWriteFd = WriteFd;
1642 //cf->cfReadFd = ReadFd;
1643#ifdef LDEBUG
1644 cf->cfDBTest = DBTest;
1645#endif
1646
1647 cf->iNumberOfParameters = pp->N;
1648 char **pn = (char**) omAlloc0(pp->N*sizeof(char*));
1649 for(int i=0;i<pp->N;i++)
1650 {
1651 pn[i] = omStrDup(pp->names[i]);
1652 }
1653 cf->pParameterNames = (const char **) pn;
1654 cf->has_simple_Inverse = FALSE;
1655 cf->has_simple_Alloc = FALSE;
1656 cf->is_field = TRUE;
1657 cf->is_domain = TRUE;
1658
1659 fmpq_rat_data_struct *ps=(fmpq_rat_data_struct*)omAlloc(sizeof(fmpq_rat_data_struct));
1660 ps->ctx=(fmpq_mpoly_ctx_struct*)omAlloc(sizeof(fmpq_mpoly_ctx_struct));
1661 #ifdef QA_DEBUG
1662 ps->C=pp->C;
1663 #endif
1664 fmpq_mpoly_ctx_init(ps->ctx,pp->N,ORD_LEX);
1665 cf->data=ps;
1666 return FALSE;
1667}
1668#else
1670{ return TRUE; }
1671#endif
1672#else
1673BOOLEAN flintQrat_InitChar(coeffs cf, void * infoStruct)
1674{ return TRUE; }
1675#endif
All the auxiliary stuff.
int BOOLEAN
Definition auxiliary.h:88
#define TRUE
Definition auxiliary.h:101
#define FALSE
Definition auxiliary.h:97
void * ADDRESS
Definition auxiliary.h:120
CanonicalForm FACTORY_PUBLIC content(const CanonicalForm &)
CanonicalForm content ( const CanonicalForm & f ).
Definition cf_gcd.cc:603
CanonicalForm FACTORY_PUBLIC pp(const CanonicalForm &)
CanonicalForm pp ( const CanonicalForm & f ).
Definition cf_gcd.cc:676
Array< CanonicalForm > CFArray
CanonicalForm num(const CanonicalForm &f)
CanonicalForm den(const CanonicalForm &f)
const CanonicalForm CFMap CFMap & N
Definition cfEzgcd.cc:56
int l
Definition cfEzgcd.cc:100
int i
Definition cfEzgcd.cc:132
int k
Definition cfEzgcd.cc:99
Variable x
Definition cfModGcd.cc:4090
int p
Definition cfModGcd.cc:4086
CanonicalForm cf
Definition cfModGcd.cc:4091
CanonicalForm b
Definition cfModGcd.cc:4111
FILE * f
Definition checklibs.c:9
factory's main class
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
static FORCE_INLINE long n_Int(number &n, const coeffs r)
conversion of n to an int; 0 if not possible in Z/pZ: the representing int lying in (-p/2 ....
Definition coeffs.h:550
static FORCE_INLINE number n_Copy(number n, const coeffs r)
return a copy of 'n'
Definition coeffs.h:457
static FORCE_INLINE number n_NormalizeHelper(number a, number b, const coeffs r)
assume that r is a quotient field (otherwise, return 1) for arguments (a1/a2,b1/b2) return (lcm(a1,...
Definition coeffs.h:698
static FORCE_INLINE number n_Add(number a, number b, const coeffs r)
return the sum of 'a' and 'b', i.e., a+b
Definition coeffs.h:653
number ndCopyMap(number a, const coeffs src, const coeffs dst)
Definition numbers.cc:293
#define n_Test(a, r)
BOOLEAN n_Test(number a, const coeffs r).
Definition coeffs.h:715
n_coeffType
Definition coeffs.h:27
static FORCE_INLINE number n_Invers(number a, const coeffs r)
return the multiplicative inverse of 'a'; raise an error if 'a' is not invertible
Definition coeffs.h:567
static FORCE_INLINE number n_ExactDiv(number a, number b, const coeffs r)
assume that there is a canonical subring in cf and we know that division is possible for these a and ...
Definition coeffs.h:625
static FORCE_INLINE number n_InpNeg(number n, const coeffs r)
in-place negation of n MUST BE USED: n = n_InpNeg(n) (no copy is returned)
Definition coeffs.h:560
static FORCE_INLINE number n_Div(number a, number b, const coeffs r)
return the quotient of 'a' and 'b', i.e., a/b; raises an error if 'b' is not invertible in r exceptio...
Definition coeffs.h:618
coeffs nInitChar(n_coeffType t, void *parameter)
one-time initialisations for new coeffs in case of an error return NULL
Definition numbers.cc:412
static FORCE_INLINE number n_Sub(number a, number b, const coeffs r)
return the difference of 'a' and 'b', i.e., a-b
Definition coeffs.h:658
static FORCE_INLINE BOOLEAN nCoeff_is_Q_or_BI(const coeffs r)
Definition coeffs.h:827
static FORCE_INLINE void n_Delete(number *p, const coeffs r)
delete 'p'
Definition coeffs.h:461
static FORCE_INLINE number n_InitMPZ(mpz_t n, const coeffs r)
conversion of a GMP integer to number
Definition coeffs.h:545
static FORCE_INLINE BOOLEAN nCoeff_is_Zp(const coeffs r)
Definition coeffs.h:794
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
@ n_rep_gap_rat
(number), see longrat.h
Definition coeffs.h:118
@ n_rep_gap_gmp
(), see rinteger.h, new impl.
Definition coeffs.h:119
static FORCE_INLINE number n_SubringGcd(number a, number b, const coeffs r)
Definition coeffs.h:669
number(* nMapFunc)(number a, const coeffs src, const coeffs dst)
maps "a", which lives in src, into dst
Definition coeffs.h:80
static BOOLEAN gd(leftv res, leftv args)
Definition cohomo.cc:3721
#define StringAppend
Definition emacs.cc:79
return result
#define slong
const CanonicalForm int s
Definition facAbsFact.cc:51
const CanonicalForm int const CFList const Variable & y
Definition facAbsFact.cc:53
CanonicalForm res
Definition facAbsFact.cc:60
bool found
int j
Definition facHensel.cc:110
factory.h' is the user interface to Factory.
void WerrorS(const char *s)
Definition feFopen.cc:24
static number ExtGcd(number a, number b, number *s, number *t, const coeffs)
Definition flintcf_Q.cc:447
static void WriteShort(number a, const coeffs r)
Definition flintcf_Q.cc:233
static number Copy(number a, const coeffs)
Definition flintcf_Q.cc:215
static number ChineseRemainder(number *, number *, int, BOOLEAN, CFArray &, const coeffs)
Definition flintcf_Q.cc:500
static nMapFunc SetMap(const coeffs, const coeffs)
Definition flintcf_Q.cc:470
static number Farey(number, number, const coeffs)
Definition flintcf_Q.cc:495
static number GetDenom(number &n, const coeffs)
Definition flintcf_Q.cc:423
static const char * Read(const char *st, number *a, const coeffs r)
Definition flintcf_Q.cc:326
static BOOLEAN IsOne(number a, const coeffs)
Definition flintcf_Q.cc:389
static number ConvFactoryNSingN(const CanonicalForm, const coeffs)
Definition flintcf_Q.cc:591
static number InitMPZ(mpz_t i, const coeffs)
Definition flintcf_Q.cc:128
static int Size(number n, const coeffs)
Definition flintcf_Q.cc:139
static number Add(number a, number b, const coeffs)
Definition flintcf_Q.cc:71
static number Div(number a, number b, const coeffs)
Definition flintcf_Q.cc:78
static void WriteFd(number a, const ssiInfo *d, const coeffs)
Definition flintcf_Q.cc:516
fmpz * fmpz_ptr
Definition flintcf_Q.cc:26
static void Delete(number *a, const coeffs)
Definition flintcf_Q.cc:461
static number Parameter(const int, const coeffs)
Definition flintcf_Q.cc:509
static BOOLEAN DBTest(number, const char *, const int, const coeffs)
Definition flintcf_Q.cc:626
static void KillChar(coeffs cf)
Definition flintcf_Q.cc:631
static CanonicalForm ConvSingNFactoryN(number, BOOLEAN, const coeffs)
Definition flintcf_Q.cc:596
static number Init(long i, const coeffs)
Definition flintcf_Q.cc:121
static void MPZ(mpz_t result, number &n, const coeffs)
Definition flintcf_Q.cc:159
static number ReadFd(const ssiInfo *d, const coeffs)
Definition flintcf_Q.cc:561
static number ExactDiv(number a, number b, const coeffs)
Definition flintcf_Q.cc:100
static void Power(number a, int i, number *result, const coeffs)
Definition flintcf_Q.cc:416
static BOOLEAN IsMOne(number k, const coeffs)
Definition flintcf_Q.cc:393
static number Sub(number a, number b, const coeffs)
Definition flintcf_Q.cc:64
static number GetNumerator(number &n, const coeffs)
Definition flintcf_Q.cc:431
static BOOLEAN GreaterZero(number, const coeffs)
Definition flintcf_Q.cc:410
static BOOLEAN CoeffIsEqual(const coeffs r, n_coeffType n, void *)
Definition flintcf_Q.cc:49
static number Mult(number a, number b, const coeffs)
Definition flintcf_Q.cc:57
static number Invers(number a, const coeffs)
Definition flintcf_Q.cc:195
static number Lcm(number, number, const coeffs)
Definition flintcf_Q.cc:456
static int ParDeg(number x, const coeffs)
Definition flintcf_Q.cc:505
static BOOLEAN IsZero(number a, const coeffs)
Definition flintcf_Q.cc:385
static number Neg(number a, const coeffs)
Definition flintcf_Q.cc:190
static BOOLEAN Equal(number a, number b, const coeffs)
Definition flintcf_Q.cc:381
static long Int(number &n, const coeffs)
Definition flintcf_Q.cc:143
static char * nlEatLong(char *s, mpz_ptr i)
Definition flintcf_Q.cc:30
BOOLEAN flintQrat_InitChar(coeffs cf, void *infoStruct)
coeffs flintQratInitCfByName(char *s, n_coeffType n)
static number Init_bigint(number i, const coeffs dummy, const coeffs dst)
#define STATIC_VAR
Definition globaldefs.h:7
static bool Greater(mono_type m1, mono_type m2)
#define SR_INT
Definition longrat.h:67
#define SR_TO_INT(SR)
Definition longrat.h:69
#define assume(x)
Definition mod2.h:389
int dReportError(const char *fmt,...)
Definition dError.cc:44
The main handler for Singular numbers which are suitable for Singular polynomials.
char * nEati(char *s, int *i, int m)
divide by the first (leading) number and return it, i.e. make monic
Definition numbers.cc:672
const char *const nDivBy0
Definition numbers.h:90
#define omStrDup(s)
#define omFreeSize(addr, size)
#define omAlloc(size)
#define omFree(addr)
#define omAlloc0(size)
#define NULL
Definition omList.c:12
BOOLEAN p_EqualPolys(poly p1, poly p2, const ring r)
Definition p_polys.cc:4679
void p_Write(poly p, ring lmRing, ring tailRing)
Definition polys0.cc:342
#define NUM
Definition readcf.cc:180
void StringAppendS(const char *st)
Definition reporter.cc:107
void PrintS(const char *s)
Definition reporter.cc:288
#define loop
Definition structs.h:71
#define SR_HDL(A)
Definition tgb.cc:35