14#include "flint/flint.h"
15#if __FLINT_RELEASE >= 20503
16#include "factory/factory.h"
23#define TRANSEXT_PRIVATES
28typedef fmpq_rat_struct *fmpq_rat_ptr;
29typedef fmpq_mpoly_struct *fmpq_mpoly_ptr;
30typedef fmpq_mpoly_ctx_struct *fmpq_ctx_ptr;
32typedef fmpq_rat_data_struct *data_ptr;
43 const char * start =
s;
45 while (*
s >=
'0' && *
s <=
'9')
s++;
48 fmpz_set_str(
i, start, 10);
54 fmpz_set_str(
i, start, 10);
60static void fmpq_rat_init(fmpq_rat_ptr a,
const coeffs r)
62 fmpq_mpoly_init(a->num, ((data_ptr)r->data)->ctx);
63 fmpq_mpoly_init(a->den, ((data_ptr)r->data)->ctx);
66static void fmpq_rat_clear(fmpq_rat_ptr a,
const coeffs r)
68 fmpq_mpoly_clear(a->num, ((data_ptr)r->data)->ctx);
69 fmpq_mpoly_clear(a->den, ((data_ptr)r->data)->ctx);
72static void fmpq_rat_canonicalise(fmpq_rat_ptr a,
const coeffs r)
77 fmpz_gcd(n, fmpq_numref(a->num->content), fmpq_numref(a->den->content));
78 fmpz_lcm(d, fmpq_denref(a->num->content), fmpq_denref(a->den->content));
81 fmpq_mul_fmpz(a->num->content, a->num->content, d);
82 fmpq_mul_fmpz(a->den->content, a->den->content, d);
86 fmpq_div_fmpz(a->num->content, a->num->content, n);
87 fmpq_div_fmpz(a->den->content, a->den->content, n);
101 const fmpq_ctx_ptr ctx = (fmpq_ctx_ptr) ((data_ptr)c->data)->ctx;
102 const QaInfo *par=(QaInfo*)parameter;
103 if (par->N != c->iNumberOfParameters)
return FALSE;
105 for(
int i=0;
i<par->N;
i++)
107 if (strcmp(par->names[
i],c->pParameterNames[
i])!=0)
return FALSE;
114static number
Mult(number a, number
b,
const coeffs 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))
128 else if (fmpq_mpoly_is_one(
x->den, ctx))
131 fmpq_mpoly_init(
gd, ctx);
132 fmpq_mpoly_gcd(
gd,
x->num,
y->
den, ctx);
133 if (fmpq_mpoly_is_one(
gd, ctx))
140 fmpq_mpoly_div(
res->
num,
x->num,
gd, ctx);
144 fmpq_mpoly_clear(
gd, ctx);
146 else if (fmpq_mpoly_is_one(
y->
den, ctx))
149 fmpq_mpoly_init(
gd, ctx);
150 fmpq_mpoly_gcd(
gd,
y->
num,
x->den, ctx);
151 if (fmpq_mpoly_is_one(
gd, ctx))
154 fmpq_mpoly_set(
res->
den,
x->den, ctx);
160 fmpq_mpoly_div(
res->
den,
x->den,
gd, ctx);
162 fmpq_mpoly_clear(
gd, ctx);
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))
176 fmpq_mpoly_div(
res->
num,
x->num, g1, ctx);
177 fmpq_mpoly_div(g1,
y->
den, g1, ctx);
180 if (!fmpq_mpoly_is_one(g2, ctx))
183 fmpq_mpoly_div(g2,
x->den, g2, ctx);
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);
191 fmpq_rat_canonicalise(
res, c);
199static number
Sub(number a, number
b,
const coeffs c)
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))
209 if (fmpq_mpoly_is_zero(
res->
num, ctx))
211 fmpq_mpoly_one(
res->
den, ctx);
216 if (fmpq_mpoly_is_one(
x->den, ctx))
218 fmpq_mpoly_set(
res->
den,
x->den, ctx);
225 fmpq_mpoly_init(
gd, ctx);
226 fmpq_mpoly_gcd(
gd,
res->
num,
x->den, ctx);
227 if (fmpq_mpoly_is_one(
gd, ctx))
229 fmpq_mpoly_set(
res->
den,
x->den, ctx);
233 fmpq_mpoly_div(
res->
den,
x->den,
gd, ctx);
236 fmpq_mpoly_clear(
gd, ctx);
239 else if (fmpq_mpoly_is_one(
x->den, ctx))
243 if (fmpq_mpoly_is_zero(
res->
num, ctx))
245 fmpq_mpoly_one(
res->
den, ctx);
254 else if (fmpq_mpoly_is_one(
y->
den, ctx))
258 if (fmpq_mpoly_is_zero(
res->
num,ctx))
260 fmpq_mpoly_one(
res->
den, ctx);
266 fmpq_mpoly_set(
res->
den,
x->den, ctx);
272 fmpq_mpoly_init(
gd, ctx);
273 fmpq_mpoly_gcd(
gd,
x->den,
y->
den, ctx);
274 if (fmpq_mpoly_is_one(
gd, ctx))
277 fmpq_mpoly_mul(
gd,
y->
num,
x->den, ctx);
279 if (fmpq_mpoly_is_zero(
res->
num,ctx))
281 fmpq_mpoly_one(
res->
den, ctx);
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);
300 if (fmpq_mpoly_is_one(
res->
den, ctx))
302 fmpq_mpoly_mul(
res->
den, q2,
x->den, ctx);
307 fmpq_mpoly_div(
gd,
x->den,
res->
den, ctx);
308 fmpq_mpoly_mul(
res->
den,
gd, q2, ctx);
310 fmpq_mpoly_clear(q2, ctx);
312 fmpq_mpoly_clear(
gd, ctx);
315 res->p=
n_Sub(
x->p,
y->p, ((data_ptr)c->data)->C);
321static number
Add(number a, number
b,
const coeffs c)
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))
331 if (fmpq_mpoly_is_zero(
res->
num, ctx))
333 fmpq_mpoly_one(
res->
den, ctx);
338 if (fmpq_mpoly_is_one(
x->den, ctx))
340 fmpq_mpoly_set(
res->
den,
x->den, ctx);
347 fmpq_mpoly_init(
gd, ctx);
348 fmpq_mpoly_gcd(
gd,
res->
num,
x->den, ctx);
349 if (fmpq_mpoly_is_one(
gd, ctx))
351 fmpq_mpoly_set(
res->
den,
x->den, ctx);
355 fmpq_mpoly_div(
res->
den,
x->den,
gd, ctx);
358 fmpq_mpoly_clear(
gd, ctx);
361 else if (fmpq_mpoly_is_one(
x->den, ctx))
365 if (fmpq_mpoly_is_zero(
res->
num, ctx))
367 fmpq_mpoly_one(
res->
den, ctx);
376 else if (fmpq_mpoly_is_one(
y->
den, ctx))
380 if (fmpq_mpoly_is_zero(
res->
num, ctx))
382 fmpq_mpoly_one(
res->
den, ctx);
388 fmpq_mpoly_set(
res->
den,
x->den, ctx);
394 fmpq_mpoly_init(
gd, ctx);
395 fmpq_mpoly_gcd(
gd,
x->den,
y->
den, ctx);
396 if (fmpq_mpoly_is_one(
gd, ctx))
399 fmpq_mpoly_mul(
gd,
y->
num,
x->den, ctx);
401 if (fmpq_mpoly_is_zero(
res->
num,ctx))
403 fmpq_mpoly_one(
res->
den, ctx);
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);
422 if (fmpq_mpoly_is_one(
res->
den, ctx))
424 fmpq_mpoly_mul(
res->
den, q2,
x->den, ctx);
429 fmpq_mpoly_div(
gd,
x->den,
res->
den, ctx);
430 fmpq_mpoly_mul(
res->
den,
gd, q2, ctx);
432 fmpq_mpoly_clear(q2, ctx);
434 fmpq_mpoly_clear(
gd, ctx);
437 res->p=
n_Add(
x->p,
y->p, ((data_ptr)c->data)->C);
443static number
Div(number a, number
b,
const coeffs c)
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))
455 if (fmpq_mpoly_equal(
x->den,
y->
num, ctx))
460 else if (fmpq_mpoly_is_one(
x->den, ctx))
463 fmpq_mpoly_init(
gd, ctx);
464 fmpq_mpoly_gcd(
gd,
x->num,
y->
num, ctx);
465 if (fmpq_mpoly_is_one(
gd, ctx))
472 fmpq_mpoly_div(
res->
num,
x->num,
gd, ctx);
476 fmpq_mpoly_clear(
gd, ctx);
478 else if (fmpq_mpoly_is_one(
y->
num, ctx))
481 fmpq_mpoly_init(
gd, ctx);
482 fmpq_mpoly_gcd(
gd,
y->
den,
x->den, ctx);
483 if (fmpq_mpoly_is_one(
gd, ctx))
486 fmpq_mpoly_set(
res->
den,
x->den, ctx);
492 fmpq_mpoly_div(
res->
den,
x->den,
gd, ctx);
494 fmpq_mpoly_clear(
gd, ctx);
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))
508 fmpq_mpoly_div(
res->
num,
x->num, g1, ctx);
509 fmpq_mpoly_div(g1,
y->
num, g1, ctx);
512 if (!fmpq_mpoly_is_one(g2, ctx))
515 fmpq_mpoly_div(g2,
x->den, g2, ctx);
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);
523 fmpq_rat_canonicalise(
res, c);
525 res->p=
n_Div(
x->p,
y->p, ((data_ptr)c->data)->C);
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))
544 assume(fmpq_mpoly_is_one(
x->den, ctx));
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);
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;
578 fmpq_rat_init(
res, c);
579 fmpq_mpoly_set_fmpz(
res->
num, t, ctx);
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))
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;
604static long Int(number &n,
const coeffs c)
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))
613 fmpq_div(r,
x->num->content,
x->den->content);
614 if (fmpz_is_one(fmpq_denref(r)))
616 if (fmpz_fits_si(fmpq_numref(r)))
617 nl = fmpz_get_si(fmpq_numref(r));
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))
635 fmpq_div(r,
x->num->content,
x->den->content);
636 if (fmpz_is_one(fmpq_denref(r)))
638 fmpz_get_mpz(
result, fmpq_numref(r));
644static number
Neg(number a,
const coeffs c)
646 const fmpq_rat_ptr
x = (fmpq_rat_ptr) a;
647 const fmpq_ctx_ptr ctx = (fmpq_ctx_ptr) ((data_ptr)c->data)->ctx;
648 fmpq_mpoly_neg(
x->num,
x->num, ctx);
658 const fmpq_rat_ptr
x = (fmpq_rat_ptr) a;
659 const fmpq_ctx_ptr ctx = (fmpq_ctx_ptr) ((data_ptr)c->data)->ctx;
660 if (fmpq_mpoly_is_zero(
x->num, ctx))
667 fmpq_rat_ptr
res = (fmpq_rat_ptr)
omAlloc(
sizeof(fmpq_rat_struct));
668 fmpq_rat_init(
res, c);
669 fmpq_mpoly_set(
res->
num,
x->den, ctx);
670 fmpq_mpoly_set(
res->
den,
x->num, ctx);
681 fmpq_rat_ptr
res = (fmpq_rat_ptr)
omAlloc(
sizeof(fmpq_rat_struct));
682 fmpq_rat_init(
res, c);
683 const fmpq_rat_ptr
x = (fmpq_rat_ptr) a;
684 const fmpq_ctx_ptr ctx = (fmpq_ctx_ptr) ((data_ptr)c->data)->ctx;
685 fmpq_mpoly_set(
res->
num,
x->num, ctx);
686 fmpq_mpoly_set(
res->
den,
x->den, ctx);
705 const fmpq_rat_ptr
x = (fmpq_rat_ptr) a;
706 const fmpq_ctx_ptr ctx = (fmpq_ctx_ptr) ((data_ptr)c->data)->ctx;
707 if (!fmpq_mpoly_is_fmpq(
x->num, ctx))
709 if (!fmpq_mpoly_is_fmpq(
x->den, ctx))
711 return fmpq_equal(
x->num->content,
x->den->content);
716 const fmpq_rat_ptr
x = (fmpq_rat_ptr) a;
717 const fmpq_ctx_ptr ctx = (fmpq_ctx_ptr) ((data_ptr)c->data)->ctx;
718 return fmpq_mpoly_is_zero(
x->num, ctx);
721static void WriteLong(number a,
const coeffs c)
729 const fmpq_rat_ptr
x = (fmpq_rat_ptr) a;
730 const fmpq_ctx_ptr ctx = (fmpq_ctx_ptr) ((data_ptr)c->data)->ctx;
731 if (fmpq_mpoly_is_zero(
x->den, ctx))
737 long int i,
j,
k, nmax_i, dmax_i, max_digits;
738 fmpq_rat_canonicalise(
x, c);
739 if (fmpq_mpoly_is_zero(
x->num, ctx))
743 BOOLEAN num_is_const = fmpq_mpoly_is_fmpq(
x->num, ctx);
744 BOOLEAN den_is_const = fmpq_mpoly_is_fmpq(
x->den, ctx);
746 fmpq_mpoly_struct * znum =
x->num;
747 fmpq_mpoly_struct * zden =
x->den;
748 slong nvars = fmpq_mpoly_ctx_nvars(ctx);
752 for (
i = 1;
i < fmpq_mpoly_length(znum, ctx);
i++)
754 if (fmpz_cmpabs(fmpq_mpoly_zpoly_term_coeff_ref(znum,
i, ctx),
755 fmpq_mpoly_zpoly_term_coeff_ref(znum, nmax_i, ctx)) > 0)
760 for (
i = 1;
i < fmpq_mpoly_length(zden, ctx);
i++)
762 if (fmpz_cmpabs(fmpq_mpoly_zpoly_term_coeff_ref(zden,
i, ctx),
763 fmpq_mpoly_zpoly_term_coeff_ref(zden, dmax_i, ctx)) > 0)
768 if (fmpz_cmpabs(fmpq_mpoly_zpoly_term_coeff_ref(znum, nmax_i, ctx),
769 fmpq_mpoly_zpoly_term_coeff_ref(zden, dmax_i, ctx)) > 0)
771 fmpz_mul(t, fmpq_numref(
x->num->content),
772 fmpq_mpoly_zpoly_term_coeff_ref(znum, nmax_i, ctx));
773 max_digits = fmpz_sizeinbase(t, 10);
777 fmpz_mul(t, fmpq_numref(
x->den->content),
778 fmpq_mpoly_zpoly_term_coeff_ref(zden, dmax_i, ctx));
779 max_digits =fmpz_sizeinbase(t, 10);
781 char *
s = (
char*)
omAlloc(max_digits + 5);
784 if (fmpq_mpoly_is_one(
x->num, ctx))
788 for (
i = 0;
i < fmpq_mpoly_length(
x->num, ctx);
i++)
791 fmpz_mul(t, fmpq_mpoly_zpoly_term_coeff_ref(znum,
i, ctx),
792 fmpq_numref(
x->num->content));
793 if (
i != 0 && fmpz_sgn(t) > 0)
798 fmpz_get_str(
s, 10, t);
801 while((
l>0)&&(!isdigit(
s[
l])))
l--;
804 if (strcmp(
s,
"-1")==0)
818 for (
j = 0;
j < c->iNumberOfParameters;
j++)
820 k = fmpq_mpoly_get_term_var_exp_ui(
x->num,
i,
j, ctx);
838 if (!fmpq_mpoly_is_one(
x->den, ctx))
845 closing_paren =
TRUE;
847 for (
i = 0;
i < fmpq_mpoly_length(
x->den, ctx);
i++)
850 fmpz_mul(t, fmpq_mpoly_zpoly_term_coeff_ref(zden,
i, ctx),
851 fmpq_numref(
x->den->content));
854 if ((fmpz_sgn(t) < 0) && den_is_const)
857 closing_paren =
TRUE;
860 else if (fmpz_sgn(t) > 0)
864 fmpz_get_str(
s, 10, t);
867 while((
l>0)&&(!isdigit(
s[
l])))
l--;
876 for (
j = 0;
j < nvars;
j++)
878 k = fmpq_mpoly_get_term_var_exp_ui(
x->den,
i,
j, ctx);
901 const fmpq_rat_ptr
x = (fmpq_rat_ptr) a;
902 const fmpq_ctx_ptr ctx = (fmpq_ctx_ptr) ((data_ptr)c->data)->ctx;
905 long int i,
j,
k, nmax_i, dmax_i, max_digits;
906 fmpq_rat_canonicalise(
x, c);
907 if (fmpq_mpoly_is_zero(
x->num, ctx))
911 BOOLEAN num_is_const = fmpq_mpoly_is_fmpq(
x->num, ctx);
912 BOOLEAN den_is_const = fmpq_mpoly_is_fmpq(
x->den, ctx);
913 fmpq_mpoly_struct * znum =
x->num;
914 fmpq_mpoly_struct * zden =
x->den;
915 slong nvars = fmpq_mpoly_ctx_nvars(ctx);
919 for (
i = 1;
i < fmpq_mpoly_length(znum, ctx);
i++)
921 if (fmpz_cmpabs(fmpq_mpoly_zpoly_term_coeff_ref(znum,
i, ctx),
922 fmpq_mpoly_zpoly_term_coeff_ref(znum, nmax_i, ctx)) > 0)
927 for (
i = 1;
i < fmpq_mpoly_length(zden, ctx);
i++)
929 if (fmpz_cmpabs(fmpq_mpoly_zpoly_term_coeff_ref(zden,
i, ctx),
930 fmpq_mpoly_zpoly_term_coeff_ref(zden, dmax_i, ctx)) > 0)
935 if (fmpz_cmpabs(fmpq_mpoly_zpoly_term_coeff_ref(znum, nmax_i, ctx),
936 fmpq_mpoly_zpoly_term_coeff_ref(zden, dmax_i, ctx)) > 0)
938 fmpz_mul(t, fmpq_numref(
x->num->content),
939 fmpq_mpoly_zpoly_term_coeff_ref(znum, nmax_i, ctx));
940 max_digits = fmpz_sizeinbase(t, 10);
943 fmpz_mul(t, fmpq_numref(
x->den->content),
944 fmpq_mpoly_zpoly_term_coeff_ref(zden, dmax_i, ctx));
945 max_digits = fmpz_sizeinbase(t, 10);
947 s = (
char*)
omAlloc(max_digits + 2);
950 if (fmpq_mpoly_is_one(
x->num, ctx))
954 for (
i = 0;
i < fmpq_mpoly_length(
x->num, ctx);
i++)
956 fmpz_mul(t, fmpq_mpoly_zpoly_term_coeff_ref(znum,
i, ctx),
957 fmpq_numref(
x->num->content));
958 if (
i != 0 && fmpz_sgn(t) > 0)
962 fmpz_get_str(
s, 10, t);
965 for (
j = 0;
j < nvars;
j++)
967 k = fmpq_mpoly_get_term_var_exp_ui(
x->num,
i,
j, ctx);
980 if (!fmpq_mpoly_is_one(
x->den, ctx))
985 for (
i = 0;
i < fmpq_mpoly_length(
x->den, ctx);
i++)
987 fmpz_mul(t, fmpq_mpoly_zpoly_term_coeff_ref(zden,
i, ctx),
988 fmpq_numref(
x->den->content));
989 if (
i != 0 && fmpz_sgn(t) > 0)
993 fmpz_get_str(
s, 10, t);
996 for (
j = 0;
j < nvars;
j++)
998 k = fmpq_mpoly_get_term_var_exp_ui(
x->num,
i,
j, ctx);
1015static const char*
Read(
const char * st, number * a,
const coeffs c)
1020 char *
s = (
char *) st;
1021 const fmpq_ctx_ptr ctx = (fmpq_ctx_ptr) ((data_ptr)c->data)->ctx;
1022 slong nvars = fmpq_mpoly_ctx_nvars(ctx);
1023 *a = (number)
omAlloc(
sizeof(fmpq_rat_struct));
1024 fmpq_rat_init((fmpq_rat_ptr)(*a), c);
1036 fmpq_mpoly_set_fmpz(((fmpq_rat_ptr)(*a))->
num, z, ctx);
1037 fmpq_mpoly_one(((fmpq_rat_ptr)(*a))->
den, ctx);
1042 fmpq_mpoly_scalar_div_fmpz(((fmpq_rat_ptr)(*a))->
num,
1043 ((fmpq_rat_ptr)(*a))->
num, z, ctx);
1050 for (
j = 0;
j < nvars;
j++)
1052 if (strncmp(
s, c->pParameterNames[
j],
1053 strlen(c->pParameterNames[
j])) == 0)
1056 fmpq_mpoly_gen(((fmpq_rat_ptr)(*a))->
num,
j, ctx);
1057 s += strlen(c->pParameterNames[
j]);
1064 fmpq_mpoly_pow_ui(((fmpq_rat_ptr)(*a))->
num,
1065 ((fmpq_rat_ptr)(*a))->
num, (
long int)
i, ctx);
1070 if (!
found) fmpq_mpoly_one(((fmpq_rat_ptr)(*a))->
num, ctx);
1071 fmpq_mpoly_one(((fmpq_rat_ptr)(*a))->
den, ctx);
1074 fmpq_mpoly_neg(((fmpq_rat_ptr)(*a))->
num, ((fmpq_rat_ptr)(*a))->
num, ctx);
1076 poly
pp=convFlintMPSingP(((fmpq_rat_ptr)(*a))->
num,ctx,((data_ptr)c->data)->C->extRing);
1077 fraction
f=(fraction)
n_Init(1,((data_ptr)c->data)->C);
1079 ((fmpq_rat_ptr)(*a))->
p=(number)
f;
1094 const fmpq_rat_ptr
x = (fmpq_rat_ptr) *a;
1095 fmpq_rat_clear(
x, c);
1097 n_Delete(&(
x->p),((data_ptr)c->data)->C);
1106 const fmpq_rat_ptr
x = (fmpq_rat_ptr) a;
1107 const fmpq_rat_ptr
y = (fmpq_rat_ptr)
b;
1108 const fmpq_ctx_ptr ctx = (fmpq_ctx_ptr) ((data_ptr)c->data)->ctx;
1109 if (!fmpz_mpoly_equal(
x->num->zpoly,
y->
num->zpoly, ctx->zctx))
1113 if (!fmpz_mpoly_equal(
x->den->zpoly,
y->
den->zpoly, ctx->zctx))
1120 fmpz_mul(t1, fmpq_numref(
x->num->content), fmpq_denref(
x->den->content));
1121 fmpz_mul(t1, t1, fmpq_denref(
y->
num->content));
1122 fmpz_mul(t1, t1, fmpq_numref(
y->
den->content));
1123 fmpz_mul(t2, fmpq_numref(
y->
num->content), fmpq_denref(
y->
den->content));
1124 fmpz_mul(t2, t2, fmpq_denref(
x->num->content));
1125 fmpz_mul(t2, t2, fmpq_numref(
x->den->content));
1126 int eq = fmpz_equal(t1, t2);
1136 const fmpq_rat_ptr
x = (fmpq_rat_ptr) a;
1137 const fmpq_ctx_ptr ctx = (fmpq_ctx_ptr) ((data_ptr)c->data)->ctx;
1138 if (!fmpq_mpoly_is_fmpq(
x->num, ctx))
1140 if (!fmpq_mpoly_is_fmpq(
x->den, ctx))
1143 fmpq_neg(
content,
x->num->content);
1144 int eq = fmpq_equal(
content,
x->den->content);
1157 fmpq_rat_init((fmpq_rat_ptr) (*
result), c);
1158 const fmpq_rat_ptr
x = (fmpq_rat_ptr) a;
1159 const fmpq_ctx_ptr ctx = (fmpq_ctx_ptr) ((data_ptr)c->data)->ctx;
1166 const fmpq_rat_ptr
x = (fmpq_rat_ptr) n;
1167 const fmpq_ctx_ptr ctx = (fmpq_ctx_ptr) ((data_ptr)c->data)->ctx;
1168 fmpq_rat_ptr
res = (fmpq_rat_ptr)
omAlloc(
sizeof(fmpq_rat_struct));
1169 fmpq_rat_init(
res, c);
1170 fmpq_mpoly_set(
res->
num,
x->den, ctx);
1171 fmpq_mpoly_one(
res->
den, ctx);
1172 return (number)
res;
1177 const fmpq_rat_ptr
x = (fmpq_rat_ptr) n;
1178 const fmpq_ctx_ptr ctx = (fmpq_ctx_ptr) ((data_ptr)c->data)->ctx;
1179 fmpq_rat_ptr
res = (fmpq_rat_ptr)
omAlloc(
sizeof(fmpq_rat_struct));
1180 fmpq_rat_init(
res, c);
1181 fmpq_mpoly_set(
res->
num,
x->num, ctx);
1182 fmpq_mpoly_one(
res->
den, ctx);
1183 return (number)
res;
1186static number
ExtGcd(number a, number
b, number *
s, number *t,
const coeffs c)
1188 WerrorS(
"not a Euclidean ring: ExtGcd");
1192static number
Lcm(number a, number
b,
const coeffs c)
1198static number Q2Frac(number a,
const coeffs src,
const coeffs dst)
1224static number Z2Frac(number a,
const coeffs src,
const coeffs dst)
1226 return InitMPZ((mpz_ptr)a,dst);
1229static number Zp2Frac(number a,
const coeffs src,
const coeffs dst)
1258 const fmpq_ctx_ptr ctx = (fmpq_ctx_ptr) ((data_ptr)(dst->data))->ctx;
1259 fmpq_rat_ptr
res = (fmpq_rat_ptr)
omAlloc(
sizeof(fmpq_rat_struct));
1261 fmpq_rat_init(
res, dst);
1269 fmpz_set_mpz(
f,
i->z);
1270 fmpq_mpoly_set_fmpz(
res->
num,
f, ctx);
1273 fmpq_mpoly_set_si(
res->
den, 1, ctx);
1274 return (number)
res;
1290 WerrorS(
"not yet: ChineseRemainder");
1297 const fmpq_rat_ptr
x = (fmpq_rat_ptr) a;
1298 const fmpq_ctx_ptr ctx = (fmpq_ctx_ptr) ((data_ptr)c->data)->ctx;
1299 return (
int) (fmpq_mpoly_total_degree_si(
x->num, ctx) -
1300 fmpq_mpoly_total_degree_si(
x->den, ctx));
1305 const fmpq_ctx_ptr ctx = (fmpq_ctx_ptr) ((data_ptr)c->data)->ctx;
1306 fmpq_rat_ptr
res = (fmpq_rat_ptr)
omAlloc(
sizeof(fmpq_rat_struct));
1307 fmpq_rat_init(
res, c);
1309 fmpq_mpoly_one(
res->
den, ctx);
1310 return (number)
res;
1313static number SubringGcd(number a, number
b,
const coeffs c)
1315 fmpq_rat_ptr
res = (fmpq_rat_ptr)
omAlloc(
sizeof(fmpq_rat_struct));
1316 fmpq_rat_init(
res, c);
1317 const fmpq_rat_ptr
x = (fmpq_rat_ptr) a;
1318 const fmpq_rat_ptr
y = (fmpq_rat_ptr)
b;
1319 const fmpq_ctx_ptr ctx = (fmpq_ctx_ptr) ((data_ptr)c->data)->ctx;
1324 fmpz_gcd(cont, fmpq_numref(
x->num->content), fmpq_numref(
y->
num->content));
1325 if (!fmpz_is_one(cont))
1327 fmpq_mul_fmpz(
res->
num->content,
res->
num->content, cont);
1329 fmpz_gcd(cont, fmpq_denref(
x->num->content), fmpq_denref(
y->
num->content));
1330 if (!fmpz_is_one(cont))
1332 fmpq_div_fmpz(
res->
num->content,
res->
num->content, cont);
1335 fmpq_mpoly_one(
res->
den, ctx);
1336 fmpq_rat_canonicalise(
res, c);
1341 return (number)
res;
1344static number NormalizeHelper(number a, number
b,
const coeffs c)
1346 fmpq_rat_ptr
res = (fmpq_rat_ptr)
omAlloc(
sizeof(fmpq_rat_struct));
1347 fmpq_rat_init(
res, c);
1348 const fmpq_rat_ptr
x = (fmpq_rat_ptr) a;
1349 const fmpq_rat_ptr
y = (fmpq_rat_ptr)
b;
1350 const fmpq_ctx_ptr ctx = (fmpq_ctx_ptr) ((data_ptr)c->data)->ctx;
1352 fmpq_mpoly_init(
gd,ctx);
1353 fmpq_mpoly_one(
gd,ctx);
1354 fmpq_mpoly_gcd(
gd,
x->num,
y->
den, ctx);
1356 if (!fmpq_mpoly_is_one(
gd, ctx))
1358 fmpq_mpoly_one(
res->
den, ctx);
1363 return (number)
res;
1432 WerrorS(
"not yet: ConvFactoryNSingN");
1440 WerrorS(
"not yet: ConvSingNFactoryN");
1445char * QratCoeffName(
const coeffs c)
1448 sprintf(CoeffName_flint_Qrat,
"flintQQ(%s",c->pParameterNames[0]);
1449 for(
int i=1;
i<c->iNumberOfParameters;
i++)
1451 strcat(CoeffName_flint_Qrat,
",");
1452 strcat(CoeffName_flint_Qrat,c->pParameterNames[
i]);
1454 strcat(CoeffName_flint_Qrat,
")");
1455 return (
char*) CoeffName_flint_Qrat;
1461 const char start[] =
"flintQ(";
1462 const int start_len = strlen(start);
1463 if (strncmp(
s, start, start_len) == 0)
1471 while((*
p!=
',')&&(*
p!=
')')&&(*
p!=
'\0'))
p++;
1472 if (*
p==
',') {
p++;
N++;}
1473 else if (*
p==
')') {
p++;
N++;
break;}
1474 else if (*
p==
'\0') {
break;}
1482 while((*
p!=
',')&&(*
p!=
')')&&(*
p!=
'\0'))
p++;
1483 if ((*
p==
',')||(*
p=
')'))
1494 if (*
p==
'\0')
break;
1509 const fmpq_rat_ptr
x = (fmpq_rat_ptr) c;
1516 const fmpq_ctx_ptr ctx = (fmpq_ctx_ptr) ((data_ptr)
cf->data)->ctx;
1517 fmpq_mpoly_assert_canonical(
x->num,ctx);
1518 fmpq_mpoly_assert_canonical(
x->den,ctx);
1519 if (fmpq_mpoly_is_zero(
x->den, ctx))
1527 fmpz_gcd(n, fmpq_numref(
x->num->content), fmpq_numref(
x->den->content));
1528 fmpz_lcm(d, fmpq_denref(
x->num->content), fmpq_denref(
x->den->content));
1529 if (!fmpz_is_one(d))
1534 if (!fmpz_is_one(n))
1542 poly
pp=convFlintMPSingP(
x->num,ctx,((data_ptr)
cf->data)->C->extRing);
1543 fraction
f=(fraction)
x->p;
1555 p_Write(NUM(
f),((data_ptr)
cf->data)->C->extRing);
1561 pp=convFlintMPSingP(
x->den,ctx,((data_ptr)
cf->data)->C->extRing);
1566 p_Write(NUM(
f),((data_ptr)
cf->data)->C->extRing);
1579 for(
int i=0;
i<
cf->iNumberOfParameters;
i++)
1582 const fmpq_ctx_ptr ctx = (fmpq_ctx_ptr) ((data_ptr)
cf->data)->ctx;
1583 fmpq_mpoly_ctx_clear(ctx);
1589 QaInfo *
pp=(QaInfo*)infoStruct;
1590 cf->cfCoeffName = QratCoeffName;
1598 cf->cfExactDiv =
Div;
1609 cf->cfWriteLong = WriteLong;
1610 cf->cfWriteShort = WriteLong;
1630 cf->cfSubringGcd = SubringGcd;
1631 cf->cfNormalizeHelper= NormalizeHelper;
1651 cf->iNumberOfParameters =
pp->N;
1652 char **pn = (
char**)
omAlloc0(
pp->N*
sizeof(
char*));
1653 for(
int i=0;
i<
pp->N;
i++)
1657 cf->pParameterNames = (
const char **) pn;
1658 cf->has_simple_Inverse =
FALSE;
1663 fmpq_rat_data_struct *ps=(fmpq_rat_data_struct*)
omAlloc(
sizeof(fmpq_rat_data_struct));
1664 ps->ctx=(fmpq_mpoly_ctx_struct*)
omAlloc(
sizeof(fmpq_mpoly_ctx_struct));
1668 fmpq_mpoly_ctx_init(ps->ctx,
pp->N,ORD_LEX);
const CanonicalForm CFMap CFMap & N
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
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 ....
static FORCE_INLINE number n_Copy(number n, const coeffs r)
return a copy of 'n'
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,...
static FORCE_INLINE number n_Add(number a, number b, const coeffs r)
return the sum of 'a' and 'b', i.e., a+b
number ndCopyMap(number a, const coeffs src, const coeffs dst)
#define n_Test(a, r)
BOOLEAN n_Test(number a, const coeffs r)
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
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 ...
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)
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...
coeffs nInitChar(n_coeffType t, void *parameter)
one-time initialisations for new coeffs in case of an error return NULL
static FORCE_INLINE number n_Sub(number a, number b, const coeffs r)
return the difference of 'a' and 'b', i.e., a-b
static FORCE_INLINE BOOLEAN nCoeff_is_Q_or_BI(const coeffs r)
static FORCE_INLINE void n_Delete(number *p, const coeffs r)
delete 'p'
static FORCE_INLINE number n_InitMPZ(mpz_t n, const coeffs r)
conversion of a GMP integer to number
static FORCE_INLINE BOOLEAN nCoeff_is_Zp(const coeffs r)
static FORCE_INLINE number n_Init(long i, const coeffs r)
a number representing i in the given coeff field/ring r
@ n_rep_gap_rat
(number), see longrat.h
@ n_rep_gap_gmp
(), see rinteger.h, new impl.
static FORCE_INLINE number n_SubringGcd(number a, number b, const coeffs r)
number(* nMapFunc)(number a, const coeffs src, const coeffs dst)
maps "a", which lives in src, into dst
static BOOLEAN gd(leftv res, leftv args)
const CanonicalForm int s
const CanonicalForm int const CFList const Variable & y
void WerrorS(const char *s)
if(!FE_OPT_NO_SHELL_FLAG)(void) system(sys)
static number ExtGcd(number a, number b, number *s, number *t, const coeffs)
static void WriteShort(number a, const coeffs r)
static number Copy(number a, const coeffs)
static number ChineseRemainder(number *, number *, int, BOOLEAN, CFArray &, const coeffs)
static nMapFunc SetMap(const coeffs, const coeffs)
static number Farey(number, number, const coeffs)
static number GetDenom(number &n, const coeffs)
static const char * Read(const char *st, number *a, const coeffs r)
static BOOLEAN IsOne(number a, const coeffs)
static number ConvFactoryNSingN(const CanonicalForm, const coeffs)
static number InitMPZ(mpz_t i, const coeffs)
static int Size(number n, const coeffs)
static number Add(number a, number b, const coeffs)
static number Div(number a, number b, const coeffs)
static void WriteFd(number a, const ssiInfo *d, const coeffs)
static void Delete(number *a, const coeffs)
static number Parameter(const int, const coeffs)
static BOOLEAN DBTest(number, const char *, const int, const coeffs)
static void KillChar(coeffs cf)
static CanonicalForm ConvSingNFactoryN(number, BOOLEAN, const coeffs)
static number Init(long i, const coeffs)
static void MPZ(mpz_t result, number &n, const coeffs)
static number ReadFd(const ssiInfo *d, const coeffs)
static number ExactDiv(number a, number b, const coeffs)
static void Power(number a, int i, number *result, const coeffs)
static BOOLEAN IsMOne(number k, const coeffs)
static number Sub(number a, number b, const coeffs)
static number GetNumerator(number &n, const coeffs)
static BOOLEAN GreaterZero(number, const coeffs)
static BOOLEAN CoeffIsEqual(const coeffs r, n_coeffType n, void *)
static number Mult(number a, number b, const coeffs)
static number Invers(number a, const coeffs)
static number Lcm(number, number, const coeffs)
static int ParDeg(number x, const coeffs)
static BOOLEAN IsZero(number a, const coeffs)
static number Neg(number a, const coeffs)
static BOOLEAN Equal(number a, number b, const coeffs)
static long Int(number &n, const coeffs)
static char * nlEatLong(char *s, mpz_ptr i)
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)
static bool Greater(mono_type m1, mono_type m2)
int dReportError(const char *fmt,...)
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
const char *const nDivBy0
#define omFreeSize(addr, size)
BOOLEAN p_EqualPolys(poly p1, poly p2, const ring r)
void p_Write(poly p, ring lmRing, ring tailRing)
void StringAppendS(const char *st)
void PrintS(const char *s)