diff -Nru e-antic-0.1.5+ds/debian/changelog e-antic-0.1.5+ds/debian/changelog --- e-antic-0.1.5+ds/debian/changelog 2020-05-19 12:45:32.000000000 +0000 +++ e-antic-0.1.5+ds/debian/changelog 2020-08-27 15:59:03.000000000 +0000 @@ -1,3 +1,22 @@ +e-antic (0.1.5+ds-2+rpi1) bullseye-staging; urgency=medium + + * Fix build with flint 2.6.3 (Closes: 963290 ) + + Apply upstream commit 10ed02f429f75a418ee41814af2dffc8cd41101f + as debian/patches/flint-2.6.0.patch to support flint 2.6.0 + + Apply upstream commit cebabe52632013a70be321d590301e06c306a766 + as debian/patches/remove-flint-upperlimit.patch to allow builds + with newer flint versions. + + Disable debian/patches/upstream-fix-sprintf_buffer_overflow.patch + it conflicts with the flint 2.6.0 patch and according to + https://github.com/videlec/e-antic/pull/92 the issue it addresses + was fixed as part of that patch. + + Add EANTIC_FIXED_fmpq_poly_add_fmpq to libeantic.map in + upstream-libtool-version_script.patch + + Update symbols file, removed symbols do not appear to be + used by any other packages in Debian. + + -- Peter Michael Green Thu, 27 Aug 2020 15:59:03 +0000 + e-antic (0.1.5+ds-2) unstable; urgency=medium * Serious fix release, revert symbols (Closes: #960614, #960875). diff -Nru e-antic-0.1.5+ds/debian/libeantic0.symbols e-antic-0.1.5+ds/debian/libeantic0.symbols --- e-antic-0.1.5+ds/debian/libeantic0.symbols 2020-05-19 12:40:01.000000000 +0000 +++ e-antic-0.1.5+ds/debian/libeantic0.symbols 2020-08-27 15:59:03.000000000 +0000 @@ -1,8 +1,7 @@ libeantic.so.0 libeantic0 #MINVER# * Build-Depends-Package: libeantic-dev - EANTIC_FIXED_fmpq_poly_get_str_pretty@LIBEANTIC_0_1_2 0.1.2 + EANTIC_FIXED_fmpq_poly_add_fmpq@LIBEANTIC_0_1_2 0.1.5+ds-2+rpi1 LIBEANTIC_0_1_2@LIBEANTIC_0_1_2 0.1.2 - _EANTIC_FIXED_fmpq_poly_get_str_pretty@LIBEANTIC_0_1_2 0.1.2 _fmpq_poly_resultant_div@LIBEANTIC_0_1_2 0.1.2 _fmpq_vec_fprint@LIBEANTIC_0_1_2 0.1.2 _fmpq_vec_randtest_uniq_sorted@LIBEANTIC_0_1_2 0.1.2 @@ -33,7 +32,6 @@ _nf_elem_get_nmod_poly@LIBEANTIC_0_1_2 0.1.2 _nf_elem_inv@LIBEANTIC_0_1_2 0.1.2 _nf_elem_invertible_check@LIBEANTIC_0_1_2 0.1.2 - _nf_elem_mod_fmpz@LIBEANTIC_0_1_2 0.1.2 _nf_elem_mul@LIBEANTIC_0_1_2 0.1.2 _nf_elem_mul_red@LIBEANTIC_0_1_2 0.1.2 _nf_elem_norm@LIBEANTIC_0_1_2 0.1.2 @@ -114,8 +112,6 @@ nf_elem_is_one@LIBEANTIC_0_1_2 0.1.2 nf_elem_is_rational@LIBEANTIC_0_1_2 0.1.2 nf_elem_is_zero@LIBEANTIC_0_1_2 0.1.2 - nf_elem_mod_fmpz@LIBEANTIC_0_1_2 0.1.2 - nf_elem_mod_fmpz_den@LIBEANTIC_0_1_2 0.1.2 nf_elem_mul@LIBEANTIC_0_1_2 0.1.2 nf_elem_mul_gen@LIBEANTIC_0_1_2 0.1.2 nf_elem_mul_red@LIBEANTIC_0_1_2 0.1.2 diff -Nru e-antic-0.1.5+ds/debian/patches/flint-2.6.0.patch e-antic-0.1.5+ds/debian/patches/flint-2.6.0.patch --- e-antic-0.1.5+ds/debian/patches/flint-2.6.0.patch 1970-01-01 00:00:00.000000000 +0000 +++ e-antic-0.1.5+ds/debian/patches/flint-2.6.0.patch 2020-08-27 15:49:56.000000000 +0000 @@ -0,0 +1,1580 @@ +commit 10ed02f429f75a418ee41814af2dffc8cd41101f +Author: Vincent Delecroix +Date: Mon Jun 8 11:06:42 2020 +0200 + + backport #94 + +diff --git a/Makefile.am b/Makefile.am +index 026631c..cc03132 100644 +--- a/Makefile.am ++++ b/Makefile.am +@@ -36,6 +36,7 @@ libeantic_la_SOURCES += \ + poly_extra/fmpz_poly_scale_0_1_fmpq.c \ + poly_extra/fmpz_poly_squarefree_part.c \ + poly_extra/fmpq_poly_set_str_pretty.c \ ++ poly_extra/fmpq_poly_add_fmpq.c \ + poly_extra/has_real_root.c \ + poly_extra/newton_step_arb.c \ + poly_extra/num_real_roots_0_1.c \ +@@ -83,7 +84,8 @@ check_PROGRAMS += \ + poly_extra/test/t-fmpz_poly_set_str_pretty \ + poly_extra/test/t-fmpq_poly_set_str_pretty \ + poly_extra/test/t-fmpz_poly_randtest_irreducible \ +- poly_extra/test/t-fmpz_poly_isolate_real_roots ++ poly_extra/test/t-fmpz_poly_isolate_real_roots \ ++ poly_extra/test/t-fmpq_poly_add_sub_fmpq + if FLINT252 + check_PROGRAMS += \ + poly_extra/test/t-nextprime \ +@@ -128,7 +130,6 @@ libeantic_la_SOURCES += \ + nf_elem/inlines.c \ + nf_elem/inv.c \ + nf_elem/invertible_check.c \ +- nf_elem/mod_fmpz.c \ + nf_elem/mul.c \ + nf_elem/norm.c \ + nf_elem/norm_div.c \ +@@ -165,8 +166,8 @@ check_PROGRAMS += \ + nf_elem/test/t-init_clear \ + nf_elem/test/t-inv \ + nf_elem/test/t-is_rational_integer \ +- nf_elem/test/t-mod_fmpz \ + nf_elem/test/t-mul \ ++ nf_elem/test/t-mul_div_fmpq \ + nf_elem/test/t-mul_gen \ + nf_elem/test/t-norm \ + nf_elem/test/t-norm_div \ +diff --git a/e-antic/e-antic.h b/e-antic/e-antic.h +index d941baf..df841e7 100644 +--- a/e-antic/e-antic.h ++++ b/e-antic/e-antic.h +@@ -20,7 +20,7 @@ extern "C" { + + /* check flint version */ + +-#if __FLINT_RELEASE != 20502 && __FLINT_RELEASE != 20503 ++#if __FLINT_RELEASE != 20502 && __FLINT_RELEASE != 20503 && __FLINT_RELEASE != 20600 + #error FLINT 2.5.2 or 2.5.3 required + #endif + +diff --git a/e-antic/nf_elem.h b/e-antic/nf_elem.h +index 90c4007..1a49dc2 100644 +--- a/e-antic/nf_elem.h ++++ b/e-antic/nf_elem.h +@@ -55,7 +55,7 @@ typedef lnf_elem_struct lnf_elem_t[1]; + + typedef struct /* element of a quadratic number field */ + { +- fmpz num[3]; ++ fmpz num[3]; /* extra coeff for delayed reduction */ + fmpz_t den; + } qnf_elem_struct; + +@@ -321,7 +321,7 @@ char * nf_elem_get_str_pretty(const nf_elem_t a, + { + const fmpz * const den = QNF_ELEM_DENREF(a); + const fmpz * const num = QNF_ELEM_NUMREF(a); +- slong len = 2; ++ slong len = 3; + + while (len != 0 && fmpz_is_zero(num + len - 1)) + len--; +@@ -974,13 +974,10 @@ FLINT_DLL void nf_elem_rep_mat_fmpz_mat_den(fmpz_mat_t res, fmpz_t den, const nf + ******************************************************************************/ + + FLINT_DLL +-void _nf_elem_mod_fmpz(nf_elem_t res, const nf_elem_t a, const fmpz_t mod, const nf_t nf); ++void nf_elem_coprime_den(nf_elem_t res, const nf_elem_t a, const fmpz_t mod, const nf_t nf); + + FLINT_DLL +-void nf_elem_mod_fmpz_den(nf_elem_t res, const nf_elem_t a, const fmpz_t mod, const nf_t nf, int den); +- +-FLINT_DLL +-void nf_elem_mod_fmpz(nf_elem_t res, const nf_elem_t a, const fmpz_t mod, const nf_t nf); ++void nf_elem_coprime_den_signed(nf_elem_t res, const nf_elem_t a, const fmpz_t mod, const nf_t nf); + + #ifdef __cplusplus + } +diff --git a/e-antic/poly_extra.h b/e-antic/poly_extra.h +index 9338f29..b8c5ecc 100644 +--- a/e-antic/poly_extra.h ++++ b/e-antic/poly_extra.h +@@ -100,6 +100,10 @@ void arb_mul_fmpq(arb_t a, const arb_t b, const fmpq_t c, slong prec); + void arb_div_fmpq(arb_t a, const arb_t b, const fmpq_t c, slong prec); + void arb_fmpq_div(arb_t a, const fmpq_t c, const arb_t b, slong prec); + ++void EANTIC_FIXED_fmpq_poly_add_fmpq(fmpq_poly_t res, const fmpq_poly_t poly, const fmpq_t c); ++ ++#if __FLINT_RELEASE < 20600 ++ + static __inline__ + int fmpq_equal_fmpz(const fmpq_t a, const fmpz_t b) + { +@@ -196,6 +200,8 @@ void fmpq_mul_ui(fmpq_t a, const fmpq_t b, ulong c) + fmpz_clear(tmp); + } + ++#endif ++ + static __inline__ + void fmpq_div_si(fmpq_t a, const fmpq_t b, slong c) + { +@@ -256,8 +262,9 @@ void fmpz_poly_evaluate_at_one(fmpz_t res, fmpz * p, slong len) + return _fmpz_vec_sum(res, p, len); + } + ++#if __FLINT_RELEASE != 20600 + static __inline__ +-double fmpq_get_d(fmpq_t q) ++double fmpq_get_d(const fmpq_t q) + { + arb_t z; + double d; +@@ -271,6 +278,7 @@ double fmpq_get_d(fmpq_t q) + + return d; + } ++#endif + + static __inline__ + ulong EANTIC_FIXED_fmpz_vec_max_bits(const fmpz * vec, slong len) +@@ -338,14 +346,14 @@ void _fmpz_poly_num_real_roots_sturm(slong * n_neg, slong * n_pos, const fmpz * + + void fmpz_poly_product_roots_fmpq_vec(fmpz_poly_t poly, const fmpq * xs, slong n); + +-#elif __FLINT_RELEASE == 20503 ++#elif __FLINT_RELEASE == 20503 || __FLINT_RELEASE == 20600 + + #define _EANTIC_FIXED_fmpq_poly_get_str_pretty _fmpq_poly_get_str_pretty + #define EANTIC_FIXED_fmpq_poly_get_str_pretty fmpq_poly_get_str_pretty + + #else + +-#error "Invalid flint release: e-antic needs flint-2.5.2 or flint-2.5.3" ++#error "Invalid flint release: e-antic needs flint-2.5.2, flint-2.5.3 or flint-2.6.0" + + #endif + +diff --git a/nf/print.c b/nf/print.c +index a1acbcd..62265b6 100644 +--- a/nf/print.c ++++ b/nf/print.c +@@ -27,7 +27,8 @@ + + void nf_print(const nf_t nf) + { +- flint_printf("Number field with defining polynomial "); ++ flint_printf("NumberField("); + fmpq_poly_print_pretty(nf->pol, "x"); ++ flint_printf(")"); + } + +diff --git a/nf_elem/add_fmpq.c b/nf_elem/add_fmpq.c +index 5ca96cd..1c43f3b 100644 +--- a/nf_elem/add_fmpq.c ++++ b/nf_elem/add_fmpq.c +@@ -89,6 +89,6 @@ void nf_elem_add_fmpq(nf_elem_t a, const nf_elem_t b, const fmpq_t c, const nf_t + } + } else + { +- fmpq_poly_add_fmpq(NF_ELEM(a), NF_ELEM(b), c); ++ EANTIC_FIXED_fmpq_poly_add_fmpq(NF_ELEM(a), NF_ELEM(b), c); + } + } +diff --git a/nf_elem/doc/nf_elem.txt b/nf_elem/doc/nf_elem.txt +index be0feab..8b5af71 100644 +--- a/nf_elem/doc/nf_elem.txt ++++ b/nf_elem/doc/nf_elem.txt +@@ -354,25 +354,3 @@ void nf_elem_rep_mat_fmpz_mat_den(fmpz_mat_t res, fmpz_t den, const nf_elem_t a, + multiplication with $a$ with respect to the basis $1, a, \dotsc, a^{d - 1}$, + where $a$ is the generator of the number field of $d$ is its degree. + The integral matrix $M$ is primitive. +- +-******************************************************************************* +- +- Modular reduction +- +-******************************************************************************* +- +-void nf_elem_mod_fmpz_den(nf_elem_t z, const nf_elem_t a, const fmpz_t mod, const nf_t nf, int den); +- +- If \code{den == 0}, return an element $z$ with denominator $1$, such that +- the coefficients of $z - da$ are divisble by \code{mod}, where $d$ is the +- denominator of $a$. The coefficients of $z$ are reduced modulo \code{mod}. +- +- If \code{den == 1}, return an element $z$ with denominator $1$, such that +- the coefficients of $z - a$ are divisble by \code{mod}. The coefficients of +- $z$ are reduced modulo \code{mod * d}, where $d$ is the denominator of $a$. +- +-void nf_elem_mod_fmpz(nf_elem_t res, const nf_elem_t a, const fmpz_t mod, const nf_t nf); +- +- Return an element $z$ with denominator $1$ such that the coefficients of $z +- -a$ are divisible by \code{mod}. The coefficients of $z$ are reduced +- modulo \code{mod * d}, where $d$ is the denominator of $b$. +diff --git a/nf_elem/fmpq_sub.c b/nf_elem/fmpq_sub.c +index 19e81ea..b07d8ab 100644 +--- a/nf_elem/fmpq_sub.c ++++ b/nf_elem/fmpq_sub.c +@@ -59,6 +59,7 @@ void nf_elem_fmpq_sub(nf_elem_t a, const fmpq_t c, const nf_elem_t b, const nf_t + if (fmpz_equal(fmpq_denref(c), den2)) + { + fmpz_sub(num, fmpq_numref(c), num2); ++ fmpz_neg(num + 1, num2 + 1); + fmpz_set(den, den2); + } else /* slow path */ + { +@@ -69,17 +70,18 @@ void nf_elem_fmpq_sub(nf_elem_t a, const fmpq_t c, const nf_elem_t b, const nf_t + fmpz_init(g); + + nf_elem_set(a, b, nf); +- ++ + fmpz_gcd(g, fmpq_denref(c), den); + fmpz_divexact(d1, fmpq_denref(c), g); + fmpz_divexact(d2, den, g); +- ++ + fmpz_mul(num + 1, num + 1, d1); + fmpz_mul(num, num, d1); + fmpz_mul(den, den, d1); + + fmpz_submul(num, d2, fmpq_numref(c)); + fmpz_neg(num, num); ++ fmpz_neg(num + 1, num + 1); + + fmpz_clear(g); + fmpz_clear(d1); +diff --git a/nf_elem/fmpz_sub.c b/nf_elem/fmpz_sub.c +index d0b15b9..b741848 100644 +--- a/nf_elem/fmpz_sub.c ++++ b/nf_elem/fmpz_sub.c +@@ -40,17 +40,11 @@ void nf_elem_fmpz_sub(nf_elem_t a, const fmpz_t c, const nf_elem_t b, const nf_t + else if (nf->flag & NF_QUADRATIC) + { + fmpz * den = QNF_ELEM_DENREF(a); +- fmpz * num = QNF_ELEM_NUMREF(a); +- slong len = 2; ++ fmpz * num = QNF_ELEM_NUMREF(a); + +- nf_elem_set(a, b, nf); +- +- while (len != 0 && fmpz_is_zero(num + len - 1)) +- len--; +- +- fmpz_submul(num, den, c); +- fmpz_neg(num, num); +- _fmpq_poly_canonicalise(num, den, len); ++ nf_elem_neg(a, b, nf); ++ fmpz_addmul(num, den, c); ++ _fmpq_poly_canonicalise(num, den, 2); + } else + { + fmpq_poly_fmpz_sub(NF_ELEM(a), c, NF_ELEM(b)); +diff --git a/nf_elem/get_fmpz_mod_poly.c b/nf_elem/get_fmpz_mod_poly.c +index 0816eb4..7c31021 100644 +--- a/nf_elem/get_fmpz_mod_poly.c ++++ b/nf_elem/get_fmpz_mod_poly.c +@@ -43,10 +43,11 @@ void _nf_elem_get_fmpz_mod_poly(fmpz_mod_poly_t pol, const nf_elem_t a, const nf + } + } else if (nf->flag & NF_QUADRATIC) + { +- fmpz_mod_poly_fit_length(pol, 2); ++ fmpz_mod_poly_fit_length(pol, 3); + fmpz_mod(pol->coeffs + 0, QNF_ELEM_NUMREF(a), &(pol->p)); + fmpz_mod(pol->coeffs + 1, QNF_ELEM_NUMREF(a) + 1, &(pol->p)); +- _fmpz_mod_poly_set_length(pol, 2); ++ fmpz_mod(pol->coeffs + 2, QNF_ELEM_NUMREF(a) + 2, &(pol->p)); ++ _fmpz_mod_poly_set_length(pol, 3); + _fmpz_mod_poly_normalise(pol); + } else + { +diff --git a/nf_elem/mod_fmpz.c b/nf_elem/mod_fmpz.c +deleted file mode 100644 +index b6ec461..0000000 +--- a/nf_elem/mod_fmpz.c ++++ /dev/null +@@ -1,81 +0,0 @@ +-/*============================================================================= +- +- This file is part of ANTIC. +- +- FLINT is free software; you can redistribute it and/or modify +- it under the terms of the GNU General Public License as published by +- the Free Software Foundation; either version 2 of the License, or +- (at your option) any later version. +- +- FLINT is distributed in the hope that it will be useful, +- but WITHOUT ANY WARRANTY; without even the implied warranty of +- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +- GNU General Public License for more details. +- +- You should have received a copy of the GNU General Public License +- along with FLINT; if not, write to the Free Software +- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +- +-=============================================================================*/ +-/****************************************************************************** +- +- Copyright (C) 2018 Tommy Hofmann +- +-******************************************************************************/ +- +-#include "e-antic/nf_elem.h" +- +-void +-_nf_elem_mod_fmpz(nf_elem_t res, const nf_elem_t a, const fmpz_t mod, const nf_t nf) +-{ +- if (nf_elem_is_zero(a, nf)) +- { +- nf_elem_zero(res, nf); +- return; +- } +- if (nf->flag & NF_LINEAR) +- { +- fmpz_mod(LNF_ELEM_NUMREF(res), LNF_ELEM_NUMREF(a), mod); +- fmpz_one(LNF_ELEM_DENREF(res)); +- } +- else if (nf->flag & NF_QUADRATIC) +- { +- _fmpz_vec_scalar_mod_fmpz(QNF_ELEM_NUMREF(res), QNF_ELEM_NUMREF(a), 3, mod); +- fmpz_one(QNF_ELEM_DENREF(res)); +- } +- else +- { +- fmpq_poly_fit_length(NF_ELEM(res), fmpq_poly_length(NF_ELEM(a))); +- _fmpq_poly_set_length(NF_ELEM(res), fmpq_poly_length(NF_ELEM(a))); +- _fmpz_vec_scalar_mod_fmpz(NF_ELEM(res)->coeffs, NF_ELEM(a)->coeffs, fmpq_poly_length(NF_ELEM(a)), mod); +- fmpz_one(NF_ELEM_DENREF(res)); +- } +- nf_elem_canonicalise(res, nf); +-} +- +-void +-nf_elem_mod_fmpz_den(nf_elem_t res, const nf_elem_t a, const fmpz_t mod, const nf_t nf, int den) +-{ +- if (!den || nf_elem_den_is_one(a, nf)) +- { +- _nf_elem_mod_fmpz(res, a, mod, nf); +- } +- else +- { +- fmpz_t t; +- +- fmpz_init(t); +- +- nf_elem_get_den(t, a, nf); +- fmpz_mul(t, t, mod); +- +- _nf_elem_mod_fmpz(res, a, t, nf); +- +- fmpz_clear(t); +- } +-} +- +-void nf_elem_mod_fmpz(nf_elem_t res, const nf_elem_t a, const fmpz_t mod, const nf_t nf) +-{ +- nf_elem_mod_fmpz_den(res, a, mod, nf, 1); +-} +diff --git a/nf_elem/mul.c b/nf_elem/mul.c +index 17fb3ed..069e002 100644 +--- a/nf_elem/mul.c ++++ b/nf_elem/mul.c +@@ -127,8 +127,13 @@ void _nf_elem_mul_red(nf_elem_t a, const nf_elem_t b, + + _fmpz_vec_set(r, NF_ELEM_NUMREF(a), plen); + ++#if __FLINT_RELEASE == 20600 + _fmpz_poly_divrem(q, NF_ELEM_NUMREF(a), r, plen, ++ fmpq_poly_numref(nf->pol), len, 0); ++#else ++ _fmpz_poly_divrem(q, NF_ELEM_NUMREF(a), r, plen, + fmpq_poly_numref(nf->pol), len); ++#endif + + _fmpz_vec_clear(r, plen); + _fmpz_vec_clear(q, plen - len + 1); +diff --git a/nf_elem/reduce.c b/nf_elem/reduce.c +index dd84519..94914d2 100644 +--- a/nf_elem/reduce.c ++++ b/nf_elem/reduce.c +@@ -80,8 +80,13 @@ void _nf_elem_reduce(nf_elem_t a, const nf_t nf) + + _fmpz_vec_set(r, NF_ELEM_NUMREF(a), plen); + ++#if __FLINT_RELEASE == 20600 + _fmpz_poly_divrem(q, NF_ELEM_NUMREF(a), r, plen, ++ fmpq_poly_numref(nf->pol), len, 0); ++#else ++ _fmpz_poly_divrem(q, NF_ELEM_NUMREF(a), r, plen, + fmpq_poly_numref(nf->pol), len); ++#endif + + _fmpz_vec_clear(r, plen); + _fmpz_vec_clear(q, plen - len + 1); +diff --git a/nf_elem/rep_mat.c b/nf_elem/rep_mat.c +index dea81f8..4dc0d93 100644 +--- a/nf_elem/rep_mat.c ++++ b/nf_elem/rep_mat.c +@@ -66,15 +66,15 @@ void nf_elem_rep_mat(fmpq_mat_t res, const nf_elem_t a, const nf_t nf) + slong i, j; + slong d = fmpq_poly_degree(nf->pol); + ++ nf_elem_init(t, nf); ++ nf_elem_set(t, a, nf); ++ + if (NF_ELEM(a)->length == 0) + { + fmpq_mat_zero(res); + return; + } + +- nf_elem_init(t, nf); +- nf_elem_set(t, a, nf); +- + for (i = 0; i <= NF_ELEM(a)->length - 1; i ++) + { + fmpz_set(fmpq_mat_entry_num(res, 0, i), fmpq_poly_numref(NF_ELEM(a)) + i); +diff --git a/nf_elem/scalar_div_fmpq.c b/nf_elem/scalar_div_fmpq.c +index 369e8a1..624029b 100644 +--- a/nf_elem/scalar_div_fmpq.c ++++ b/nf_elem/scalar_div_fmpq.c +@@ -31,11 +31,10 @@ void nf_elem_scalar_div_fmpq(nf_elem_t a, const nf_elem_t b, + if (nf->flag & NF_LINEAR) + { + fmpz * den = LNF_ELEM_DENREF(a); +- fmpz * num = LNF_ELEM_NUMREF(a); +- const fmpz * const den2 = LNF_ELEM_DENREF(b); +- const fmpz * const num2 = LNF_ELEM_NUMREF(b); +- +- _fmpq_mul(num, den, num2, den2, fmpq_denref(c), fmpq_numref(c)); ++ fmpz * num = LNF_ELEM_NUMREF(a); ++ const fmpz * const den2 = LNF_ELEM_DENREF(b); ++ const fmpz * const num2 = LNF_ELEM_NUMREF(b); ++ _fmpq_div(num, den, num2, den2, fmpq_numref(c), fmpq_denref(c)); + } + else if (nf->flag & NF_QUADRATIC) + { +diff --git a/nf_elem/si_sub.c b/nf_elem/si_sub.c +index 75f0aff..d38f6c9 100644 +--- a/nf_elem/si_sub.c ++++ b/nf_elem/si_sub.c +@@ -32,9 +32,8 @@ void nf_elem_si_sub(nf_elem_t a, slong c, const nf_elem_t b, const nf_t nf) + fmpz * den = LNF_ELEM_DENREF(a); + fmpz * num = LNF_ELEM_NUMREF(a); + +- nf_elem_set(a, b, nf); ++ nf_elem_neg(a, b, nf); + +- fmpz_neg(num, num); + if (c >= 0) + fmpz_addmul_ui(num, den, c); + else +@@ -45,21 +44,15 @@ void nf_elem_si_sub(nf_elem_t a, slong c, const nf_elem_t b, const nf_t nf) + { + fmpz * den = QNF_ELEM_DENREF(a); + fmpz * num = QNF_ELEM_NUMREF(a); +- slong len = 2, i; + +- nf_elem_set(a, b, nf); +- +- while (len != 0 && fmpz_is_zero(num + len - 1)) +- len--; ++ nf_elem_neg(a, b, nf); + + if (c >= 0) +- fmpz_submul_ui(num, den, c); ++ fmpz_addmul_ui(num, den, c); + else +- fmpz_addmul_ui(num, den, -c); ++ fmpz_submul_ui(num, den, -c); + +- for(i=0; i<= len; i++) +- fmpz_neg(num+i, num+i); +- _fmpq_poly_canonicalise(num, den, len); ++ _fmpq_poly_canonicalise(num, den, 2); + } else + { + fmpq_poly_si_sub(NF_ELEM(a), c, NF_ELEM(b)); +diff --git a/nf_elem/test/t-add_sub_fmpq.c b/nf_elem/test/t-add_sub_fmpq.c +new file mode 100644 +index 0000000..81bceeb +--- /dev/null ++++ b/nf_elem/test/t-add_sub_fmpq.c +@@ -0,0 +1,117 @@ ++/*============================================================================= ++ ++ This file is part of FLINT. ++ ++ FLINT is free software; you can redistribute it and/or modify ++ it under the terms of the GNU General Public License as published by ++ the Free Software Foundation; either version 2 of the License, or ++ (at your option) any later version. ++ ++ FLINT is distributed in the hope that it will be useful, ++ but WITHOUT ANY WARRANTY; without even the implied warranty of ++ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ++ GNU General Public License for more details. ++ ++ You should have received a copy of the GNU General Public License ++ along with FLINT; if not, write to the Free Software ++ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA ++ ++=============================================================================*/ ++/****************************************************************************** ++ ++ Copyright (C) 2020 Vincent Delecroix ++ ++******************************************************************************/ ++ ++#include ++#include "e-antic/nf.h" ++#include "e-antic/nf_elem.h" ++ ++int ++main(void) ++{ ++ int i, result; ++ flint_rand_t state; ++ ++ flint_randinit(state); ++ ++ /* test b + c - c = b */ ++ for (i = 0; i < 100; i++) ++ { ++ nf_t nf; ++ nf_elem_t a, b, t; ++ fmpq_t c; ++ ++ nf_init_randtest(nf, state, 40, 200); ++ ++ nf_elem_init(a, nf); ++ nf_elem_init(b, nf); ++ nf_elem_init(t, nf); ++ fmpq_init(c); ++ ++ nf_elem_randtest(b, state, 200, nf); ++ fmpq_randtest(c, state, 200); ++ ++ nf_elem_add_fmpq(t, b, c, nf); ++ nf_elem_sub_fmpq(a, t, c, nf); ++ ++ if (!nf_elem_equal(a, b, nf)) ++ { ++ printf("FAIL:\n"); ++ printf("nf = "); nf_print(nf); printf("\n"); ++ printf("a = "); nf_elem_print_pretty(a, nf, "x"); printf("\n"); ++ printf("b = "); nf_elem_print_pretty(b, nf, "x"); printf("\n"); ++ printf("c = "); fmpq_print(c); printf("\n"); ++ abort(); ++ } ++ ++ nf_elem_clear(a, nf); ++ nf_elem_clear(b, nf); ++ nf_elem_clear(t, nf); ++ fmpq_clear(c); ++ ++ nf_clear(nf); ++ } ++ ++ /* test aliasing a and b */ ++ for (i = 0; i < 100; i++) ++ { ++ nf_t nf; ++ nf_elem_t a, b; ++ fmpq_t c; ++ ++ nf_init_randtest(nf, state, 40, 200); ++ ++ nf_elem_init(a, nf); ++ nf_elem_init(b, nf); ++ fmpq_init(c); ++ ++ nf_elem_randtest(b, state, 200, nf); ++ fmpq_randtest(c, state, 200); ++ ++ nf_elem_set(a, b, nf); ++ nf_elem_add_fmpq(b, b, c, nf); ++ nf_elem_sub_fmpq(b, b, c, nf); ++ ++ if (!nf_elem_equal(a, b, nf)) ++ { ++ printf("FAIL:\n"); ++ printf("(with aliasing)\n"); ++ printf("nf = "); nf_print(nf); printf("\n"); ++ printf("a = "); nf_elem_print_pretty(a, nf, "x"); printf("\n"); ++ printf("b = "); nf_elem_print_pretty(b, nf, "x"); printf("\n"); ++ printf("c = "); fmpq_print(c); printf("\n"); ++ abort(); ++ } ++ ++ nf_elem_clear(a, nf); ++ nf_elem_clear(b, nf); ++ fmpq_clear(c); ++ ++ nf_clear(nf); ++ } ++ ++ flint_randclear(state); ++ ++ return 0; ++} +diff --git a/nf_elem/test/t-mod_fmpz.c b/nf_elem/test/t-mod_fmpz.c +deleted file mode 100644 +index 5e26cf5..0000000 +--- a/nf_elem/test/t-mod_fmpz.c ++++ /dev/null +@@ -1,144 +0,0 @@ +-/*============================================================================= +- +- This file is part of ANTIC. +- +- FLINT is free software; you can redistribute it and/or modify +- it under the terms of the GNU General Public License as published by +- the Free Software Foundation; either version 2 of the License, or +- (at your option) any later version. +- +- FLINT is distributed in the hope that it will be useful, +- but WITHOUT ANY WARRANTY; without even the implied warranty of +- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +- GNU General Public License for more details. +- +- You should have received a copy of the GNU General Public License +- along with FLINT; if not, write to the Free Software +- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +- +- =============================================================================*/ +-/****************************************************************************** +- +- Copyright (C) 2018 Tommy Hofmann +- +- ******************************************************************************/ +- +-#include +-#include "e-antic/nf.h" +-#include "e-antic/nf_elem.h" +- +-int +-main(void) +-{ +- int i, result; +- flint_rand_t state; +- +- flint_printf("mod_fmpz...."); +- fflush(stdout); +- +- flint_randinit(state); +- +- for (i = 0; i < 100; i++) +- { +- slong j; +- nf_t nf; +- nf_elem_t a, b; +- fmpz_t coeff, mod, reduced_coeff; +- +- fmpz_init(mod); +- fmpz_randtest_unsigned(mod, state, 2 * FLINT_BITS); +- fmpz_add_ui(mod, mod, 2); +- +- fmpz_init(coeff); +- fmpz_init(reduced_coeff); +- +- nf_init_randtest(nf, state, 40, 200); +- +- nf_elem_init(a, nf); +- nf_elem_init(b, nf); +- +- nf_elem_randtest(a, state, 200, nf); +- +- nf_elem_mod_fmpz_den(b, a, mod, nf, 0); +- +- for (j = 0; j < nf_degree(nf); j++) +- { +- nf_elem_get_coeff_fmpz(coeff, a, j, nf); +- fmpz_mod(coeff, coeff, mod); +- nf_elem_get_coeff_fmpz(reduced_coeff, b, j, nf); +- result = fmpz_equal(reduced_coeff, coeff); +- if (!result) +- { +- printf("FAIL: Reducing without denominator\n"); +- printf("f = "); fmpq_poly_print_pretty(nf->pol, "x"); printf("\n"); +- printf("a = "); nf_elem_print_pretty(a, nf, "x"); printf("\n"); +- printf("n = "); fmpz_print(mod); printf("\n"); +- printf("b = "); nf_elem_print_pretty(b, nf, "x"); printf("\n"); +- abort(); +- } +- } +- +- nf_elem_clear(a, nf); +- nf_elem_clear(b, nf); +- fmpz_clear(coeff); +- fmpz_clear(reduced_coeff); +- fmpz_clear(mod); +- nf_clear(nf); +- } +- +- for (i = 0; i < 100; i++) +- { +- slong j; +- nf_t nf; +- nf_elem_t a, b; +- fmpz_t coeff, mod, reduced_coeff, den; +- +- fmpz_init(mod); +- fmpz_randtest_unsigned(mod, state, 2 * FLINT_BITS); +- fmpz_add_ui(mod, mod, 2); +- +- fmpz_init(coeff); +- fmpz_init(reduced_coeff); +- fmpz_init(den); +- +- nf_init_randtest(nf, state, 4, 2); +- +- nf_elem_init(a, nf); +- nf_elem_init(b, nf); +- +- nf_elem_randtest(a, state, 2, nf); +- nf_elem_get_den(den, a, nf); +- fmpz_mul(den, den, mod); +- +- nf_elem_mod_fmpz(b, a, mod, nf); +- +- for (j = 0; j < nf_degree(nf); j++) +- { +- nf_elem_get_coeff_fmpz(coeff, a, j, nf); +- fmpz_mod(coeff, coeff, den); +- nf_elem_get_coeff_fmpz(reduced_coeff, b, j, nf); +- result = fmpz_equal(reduced_coeff, coeff); +- if (!result) +- { +- printf("FAIL: Reducing without denominator\n"); +- printf("f = "); fmpq_poly_print_pretty(nf->pol, "x"); printf("\n"); +- printf("a = "); nf_elem_print_pretty(a, nf, "x"); printf("\n"); +- printf("n = "); fmpz_print(mod); printf("\n"); +- printf("b = "); nf_elem_print_pretty(b, nf, "x"); printf("\n"); +- abort(); +- } +- } +- +- nf_elem_clear(a, nf); +- nf_elem_clear(b, nf); +- fmpz_clear(coeff); +- fmpz_clear(reduced_coeff); +- fmpz_clear(mod); +- fmpz_clear(den); +- nf_clear(nf); +- } +- +- flint_randclear(state); +- flint_printf("PASS\n"); +- return 0; +-} +diff --git a/nf_elem/test/t-mul_div_fmpq.c b/nf_elem/test/t-mul_div_fmpq.c +new file mode 100644 +index 0000000..6da5099 +--- /dev/null ++++ b/nf_elem/test/t-mul_div_fmpq.c +@@ -0,0 +1,117 @@ ++/*============================================================================= ++ ++ This file is part of FLINT. ++ ++ FLINT is free software; you can redistribute it and/or modify ++ it under the terms of the GNU General Public License as published by ++ the Free Software Foundation; either version 2 of the License, or ++ (at your option) any later version. ++ ++ FLINT is distributed in the hope that it will be useful, ++ but WITHOUT ANY WARRANTY; without even the implied warranty of ++ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ++ GNU General Public License for more details. ++ ++ You should have received a copy of the GNU General Public License ++ along with FLINT; if not, write to the Free Software ++ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA ++ ++=============================================================================*/ ++/****************************************************************************** ++ ++ Copyright (C) 2020 Vincent Delecroix ++ ++******************************************************************************/ ++ ++#include ++#include "e-antic/nf.h" ++#include "e-antic/nf_elem.h" ++ ++int ++main(void) ++{ ++ int i, result; ++ flint_rand_t state; ++ ++ flint_randinit(state); ++ ++ /* test b + c - c = b */ ++ for (i = 0; i < 100; i++) ++ { ++ nf_t nf; ++ nf_elem_t a, b, t; ++ fmpq_t c; ++ ++ nf_init_randtest(nf, state, 40, 200); ++ ++ nf_elem_init(a, nf); ++ nf_elem_init(b, nf); ++ nf_elem_init(t, nf); ++ fmpq_init(c); ++ ++ nf_elem_randtest(b, state, 200, nf); ++ fmpq_randtest_not_zero(c, state, 200); ++ ++ nf_elem_scalar_mul_fmpq(t, b, c, nf); ++ nf_elem_scalar_div_fmpq(a, t, c, nf); ++ ++ if (!nf_elem_equal(a, b, nf)) ++ { ++ printf("FAIL:\n"); ++ printf("nf = "); nf_print(nf); printf("\n"); ++ printf("a = "); nf_elem_print_pretty(a, nf, "x"); printf("\n"); ++ printf("b = "); nf_elem_print_pretty(b, nf, "x"); printf("\n"); ++ printf("c = "); fmpq_print(c); printf("\n"); ++ abort(); ++ } ++ ++ nf_elem_clear(a, nf); ++ nf_elem_clear(b, nf); ++ nf_elem_clear(t, nf); ++ fmpq_clear(c); ++ ++ nf_clear(nf); ++ } ++ ++ /* test aliasing a and b */ ++ for (i = 0; i < 100; i++) ++ { ++ nf_t nf; ++ nf_elem_t a, b; ++ fmpq_t c; ++ ++ nf_init_randtest(nf, state, 40, 200); ++ ++ nf_elem_init(a, nf); ++ nf_elem_init(b, nf); ++ fmpq_init(c); ++ ++ nf_elem_randtest(b, state, 200, nf); ++ fmpq_randtest_not_zero(c, state, 200); ++ ++ nf_elem_set(a, b, nf); ++ nf_elem_scalar_mul_fmpq(b, b, c, nf); ++ nf_elem_scalar_div_fmpq(b, b, c, nf); ++ ++ if (!nf_elem_equal(a, b, nf)) ++ { ++ printf("FAIL:\n"); ++ printf("(with aliasing)\n"); ++ printf("nf = "); nf_print(nf); printf("\n"); ++ printf("a = "); nf_elem_print_pretty(a, nf, "x"); printf("\n"); ++ printf("b = "); nf_elem_print_pretty(b, nf, "x"); printf("\n"); ++ printf("c = "); fmpq_print(c); printf("\n"); ++ abort(); ++ } ++ ++ nf_elem_clear(a, nf); ++ nf_elem_clear(b, nf); ++ fmpq_clear(c); ++ ++ nf_clear(nf); ++ } ++ ++ flint_randclear(state); ++ ++ return 0; ++} +diff --git a/nf_elem/test/t-pow.c b/nf_elem/test/t-pow.c +index a4a1337..c844df3 100644 +--- a/nf_elem/test/t-pow.c ++++ b/nf_elem/test/t-pow.c +@@ -46,13 +46,13 @@ main(void) + slong exp; + + nf_init_randtest(nf, state, 40, 20); +- ++ + nf_elem_init(a, nf); + nf_elem_init(p1, nf); + nf_elem_init(p2, nf); + + nf_elem_randtest(a, state, 20, nf); +- ++ + exp = n_randint(state, 10); + + nf_elem_pow(p1, a, exp, nf); +@@ -60,7 +60,7 @@ main(void) + + for (j = 0; j < exp; j++) + nf_elem_mul(p2, p2, a, nf); +- ++ + result = (nf_elem_equal(p1, p2, nf)); + if (!result) + { +@@ -75,10 +75,10 @@ main(void) + nf_elem_clear(a, nf); + nf_elem_clear(p1, nf); + nf_elem_clear(p2, nf); +- ++ + nf_clear(nf); + } +- ++ + /* test aliasing a and res */ + for (i = 0; i < 100; i++) + { +@@ -87,19 +87,19 @@ main(void) + slong exp; + + nf_init_randtest(nf, state, 40, 20); +- ++ + nf_elem_init(a, nf); + nf_elem_init(p1, nf); + nf_elem_init(p2, nf); + + nf_elem_randtest(a, state, 20, nf); +- ++ + exp = n_randint(state, 10); + + nf_elem_pow(p1, a, exp, nf); + nf_elem_set(p2, a, nf); + nf_elem_pow(p2, p2, exp, nf); +- ++ + result = (nf_elem_equal(p1, p2, nf)); + if (!result) + { +@@ -114,10 +114,10 @@ main(void) + nf_elem_clear(a, nf); + nf_elem_clear(p1, nf); + nf_elem_clear(p2, nf); +- ++ + nf_clear(nf); + } +- ++ + flint_randclear(state); + flint_printf("PASS\n"); + return 0; +diff --git a/poly_extra/fmpq_poly_add_fmpq.c b/poly_extra/fmpq_poly_add_fmpq.c +new file mode 100644 +index 0000000..7907b43 +--- /dev/null ++++ b/poly_extra/fmpq_poly_add_fmpq.c +@@ -0,0 +1,107 @@ ++/* ++ Copyright (C) 2009 William Hart ++ ++ This file is part of FLINT. ++ ++ FLINT is free software: you can redistribute it and/or modify it under ++ the terms of the GNU Lesser General Public License (LGPL) as published ++ by the Free Software Foundation; either version 2.1 of the License, or ++ (at your option) any later version. See . ++*/ ++ ++#include ++#include ++#include ++#include ++#include ++#include ++ ++void EANTIC_FIXED_fmpq_poly_add_fmpq(fmpq_poly_t res, const fmpq_poly_t poly, const fmpq_t c) ++{ ++ fmpz_t d; ++ ++ if (poly -> length == 0) ++ { ++ fmpq_poly_set_fmpq(res, c); ++ return; ++ } ++ ++ fmpq_poly_set(res, poly); ++ ++ if (poly -> length == 1) ++ { ++ _fmpq_add(res->coeffs, res->den, poly->coeffs, poly->den, fmpq_numref(c), fmpq_denref(c)); ++ if (fmpz_is_zero(res->coeffs)) ++ res->length = 0; ++ return; ++ } ++ ++ if (fmpz_equal(res->den, fmpq_denref(c))) ++ { ++ fmpz_add(res->coeffs + 0, res->coeffs + 0, fmpq_numref(c)); ++ ++ if (!fmpz_is_one(res->den)) ++ { ++ fmpz_init(d); ++ fmpz_gcd(d, res->den, res->coeffs + 0); ++ ++ if (!fmpz_is_one(d)) ++ { ++ _fmpz_vec_content(d, res->coeffs, res->length); ++ if (!fmpz_is_one(d)) ++ { ++ fmpz_gcd(d, d, res->den); ++ _fmpz_vec_scalar_divexact_fmpz(res->coeffs, res->coeffs, res->length, d); ++ fmpz_divexact(res->den, res->den, d); ++ } ++ } ++ fmpz_clear(d); ++ } ++ return; ++ } ++ ++ fmpz_init(d); ++ fmpz_one(d); ++ ++ if (!fmpz_is_one(poly->den) && !fmpz_is_one(fmpq_denref(c))) ++ fmpz_gcd(d, poly->den, fmpq_denref(c)); ++ ++ if (fmpz_is_one(d)) ++ { ++ _fmpz_vec_scalar_mul_fmpz(res->coeffs, res->coeffs, res->length, fmpq_denref(c)); ++ fmpz_addmul(res->coeffs, fmpq_numref(c), res->den); ++ fmpz_mul(res->den, res->den, fmpq_denref(c)); ++ } ++ else ++ { ++ fmpz_t den11; ++ fmpz_t den22; ++ fmpz_t e; ++ ++ fmpz_init(den11); ++ fmpz_init(den22); ++ fmpz_init(e); ++ ++ fmpz_divexact(den11, res->den, d); ++ fmpz_divexact(den22, fmpq_denref(c), d); ++ ++ _fmpz_vec_scalar_mul_fmpz(res->coeffs, res->coeffs, res->length, den22); ++ fmpz_addmul(res->coeffs, fmpq_numref(c), den11); ++ _fmpz_vec_content(e, res->coeffs, res->length); ++ if (!fmpz_is_one(e)) ++ fmpz_gcd(e, e, d); ++ ++ if (fmpz_is_one(e)) ++ fmpz_mul(res->den, res->den, den22); ++ else ++ { ++ _fmpz_vec_scalar_divexact_fmpz(res->coeffs, res->coeffs, res->length, e); ++ fmpz_divexact(den11, res->den, e); ++ fmpz_mul(res->den, den11, den22); ++ } ++ fmpz_clear(e); ++ fmpz_clear(den11); ++ fmpz_clear(den22); ++ } ++ fmpz_clear(d); ++} +diff --git a/poly_extra/test/t-fmpq_poly_add_sub_fmpq.c b/poly_extra/test/t-fmpq_poly_add_sub_fmpq.c +new file mode 100644 +index 0000000..e4938e6 +--- /dev/null ++++ b/poly_extra/test/t-fmpq_poly_add_sub_fmpq.c +@@ -0,0 +1,105 @@ ++/*============================================================================= ++ ++ This file is part of FLINT. ++ ++ FLINT is free software; you can redistribute it and/or modify ++ it under the terms of the GNU General Public License as published by ++ the Free Software Foundation; either version 2 of the License, or ++ (at your option) any later version. ++ ++ FLINT is distributed in the hope that it will be useful, ++ but WITHOUT ANY WARRANTY; without even the implied warranty of ++ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ++ GNU General Public License for more details. ++ ++ You should have received a copy of the GNU General Public License ++ along with FLINT; if not, write to the Free Software ++ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA ++ ++=============================================================================*/ ++/****************************************************************************** ++ ++ Copyright (C) 2020 Vincent Delecroix ++ ++******************************************************************************/ ++ ++#include ++#include ++#include ++ ++int ++main(void) ++{ ++ int i; ++ flint_rand_t state; ++ ++ flint_randinit(state); ++ ++ /* test b + c - c = b */ ++ for (i = 0; i < 100; i++) ++ { ++ fmpq_poly_t a, b, t; ++ fmpq_t c; ++ ++ fmpq_poly_init(a); ++ fmpq_poly_init(b); ++ fmpq_poly_init(t); ++ fmpq_init(c); ++ ++ fmpq_poly_randtest(b, state, 10, 200); ++ fmpq_randtest(c, state, 200); ++ ++ EANTIC_FIXED_fmpq_poly_add_fmpq(t, b, c); ++ fmpq_poly_sub_fmpq(a, t, c); ++ ++ if (!fmpq_poly_equal(a, b)) ++ { ++ printf("FAIL:\n"); ++ printf("a = "); fmpq_poly_print(a); printf("\n"); ++ printf("b = "); fmpq_poly_print(b); printf("\n"); ++ printf("c = "); fmpq_print(c); printf("\n"); ++ abort(); ++ } ++ ++ fmpq_poly_clear(a); ++ fmpq_poly_clear(b); ++ fmpq_poly_clear(t); ++ fmpq_clear(c); ++ } ++ ++ /* test aliasing a and b */ ++ for (i = 0; i < 100; i++) ++ { ++ fmpq_poly_t a, b; ++ fmpq_t c; ++ ++ fmpq_poly_init(a); ++ fmpq_poly_init(b); ++ fmpq_init(c); ++ ++ fmpq_poly_randtest(b, state, 10, 200); ++ fmpq_randtest(c, state, 200); ++ ++ fmpq_poly_set(a, b); ++ EANTIC_FIXED_fmpq_poly_add_fmpq(b, b, c); ++ fmpq_poly_sub_fmpq(b, b, c); ++ ++ if (!fmpq_poly_equal(a, b)) ++ { ++ printf("FAIL:\n"); ++ printf("(with aliasing)\n"); ++ printf("a = "); fmpq_poly_print(a); printf("\n"); ++ printf("b = "); fmpq_poly_print(b); printf("\n"); ++ printf("c = "); fmpq_print(c); printf("\n"); ++ abort(); ++ } ++ ++ fmpq_poly_clear(a); ++ fmpq_poly_clear(b); ++ fmpq_clear(c); ++ } ++ ++ flint_randclear(state); ++ ++ return 0; ++} +diff --git a/renf/print.c b/renf/print.c +index 28241bf..56dd3e9 100644 +--- a/renf/print.c ++++ b/renf/print.c +@@ -13,6 +13,9 @@ + + void renf_print(const renf_t nf) + { +- nf_print(nf->nf); ++ flint_printf("NumberField("); ++ fmpq_poly_print_pretty(nf->nf->pol, "x"); ++ flint_printf(", "); + arb_print(nf->emb); ++ flint_printf(")"); + } +diff --git a/renf/refine_embedding.c b/renf/refine_embedding.c +index 1f8a7f9..336ec10 100644 +--- a/renf/refine_embedding.c ++++ b/renf/refine_embedding.c +@@ -9,13 +9,40 @@ + (at your option) any later version. See . + */ + ++#include ++#include + #include + #include + ++#ifdef HAVE_PTHREAD ++#include ++static pthread_once_t mtx_initialized; ++static pthread_mutex_t mtx; ++ ++void initialize_mtx() ++{ ++ if (pthread_mutex_init(&mtx, NULL) != 0) ++ { ++ err(1, "failed to create mutex for renf_refine_embedding()"); ++ } ++} ++#endif ++ + void renf_refine_embedding(renf_t nf, slong prec) + { +- #pragma omp critical(RENF_REFINE) ++#ifdef HAVE_PTHREAD ++ pthread_once(&mtx_initialized, initialize_mtx); ++ ++ // We need to make sure that no two threads attempt to refine the same ++ // number field embedding at the same time: if two threads were looking for ++ // different precisions, we might end up with the lower precision ++ // eventually. Also the arb_swap() would not be safe. ++ if (pthread_mutex_lock(&mtx) != 0) + { ++ err(1, "failed to lock mutex for renf_refine_embedding()"); ++ } ++#endif ++ + arb_t tmp; + slong cond; + slong comp_prec; +@@ -54,5 +81,11 @@ void renf_refine_embedding(renf_t nf, slong prec) + comp_prec = 2 * FLINT_ABS(arb_rel_accuracy_bits(nf->emb)) + cond * nf->nf->pol->length; + } + arb_clear(tmp); +- } // #pragma ++ ++#ifdef HAVE_PTHREAD ++ if (pthread_mutex_unlock(&mtx) != 0) ++ { ++ err(1, "failed to unlock mutex for renf_refine_embedding()"); ++ } ++#endif + } +diff --git a/renf_elem/get_str_pretty.c b/renf_elem/get_str_pretty.c +index a6d3aa1..623076a 100644 +--- a/renf_elem/get_str_pretty.c ++++ b/renf_elem/get_str_pretty.c +@@ -9,6 +9,7 @@ + (at your option) any later version. See . + */ + ++#include + #include + #include + +@@ -41,11 +42,40 @@ char * renf_elem_get_str_pretty(renf_elem_t a, const char * var, renf_t nf, slon + + if (flag & EANTIC_STR_D) + { +- // output of get_d +- s = flint_malloc(20 * sizeof(char)); +- sprintf(s, "%lf", renf_elem_get_d(a, nf, ARF_RND_NEAR)); ++ // Print the approximate double value of a. ++ ++ double d = renf_elem_get_d(a, nf, ARF_RND_NEAR); ++ ++ switch (isinf(d)) { ++ case -1: ++ s = flint_malloc(strlen("-inf") + 1); ++ strcpy(s, "-inf"); ++ break; ++ case 1: ++ s = flint_malloc(strlen("inf") + 1); ++ strcpy(s, "inf"); ++ break; ++ default: ++ // Since we do not like printf()'s double printing, (the output of %f ++ // is too large for big numbers, %e is hard to read for small integers, ++ // %g does not show enough digits in many cases,) we use Arb's double ++ // printing instead. ++ { ++ arb_t x; ++ arb_init(x); ++ ++ arb_set_d(x, d); ++ ++ s = arb_get_str(x, 8, ARB_STR_NO_RADIUS); ++ ++ arb_clear(x); ++ } ++ break; ++ } ++ + t = flint_realloc(t, strlen(t) + strlen(s) + 1); + strcat(t, s); ++ + flint_free(s); + } + +diff --git a/renf_elem/test/t-binop.c b/renf_elem/test/t-binop.c +index 214a1a3..037cfb0 100644 +--- a/renf_elem/test/t-binop.c ++++ b/renf_elem/test/t-binop.c +@@ -16,7 +16,7 @@ int main() + int iter; + FLINT_TEST_INIT(state); + +- for (iter = 0; iter < 100; iter++) ++ for (iter = 0; iter < 1000; iter++) + { + /* operations on two renf elements */ + renf_t nf; +@@ -28,6 +28,7 @@ int main() + + { + /* renf renf operations */ ++ fprintf(stderr, "renf renf operations\n"); + renf_elem_t a, b, c; + renf_elem_init(a, nf); + renf_elem_init(b, nf); +@@ -55,6 +56,7 @@ int main() + + { + /* renf si operations */ ++ fprintf(stderr, "renf si operations\n"); + renf_elem_t a, c; + slong b; + renf_elem_init(a, nf); +@@ -81,6 +83,7 @@ int main() + + { + /* renf ui operations */ ++ fprintf(stderr, "renf ui operations\n"); + renf_elem_t a, c; + ulong b; + renf_elem_init(a, nf); +@@ -107,6 +110,7 @@ int main() + + { + /* renf fmpz operations */ ++ fprintf(stderr, "renf fmpz operations\n"); + renf_elem_t a, c; + fmpz_t b; + +@@ -137,8 +141,10 @@ int main() + + { + /* renf fmpq operations */ ++ fprintf(stderr, "renf fmpq operations\n"); + renf_elem_t a, c; + fmpq_t b; ++ char * res; + + renf_elem_init(a, nf); + fmpq_init(b); +@@ -147,15 +153,44 @@ int main() + renf_elem_randtest(a, state, 10 + n_randint(state, 30), nf); + fmpq_randtest(b, state, 10 + n_randint(state, 30)); + ++ res = renf_elem_get_str_pretty(a, "x", nf, 10, EANTIC_STR_ALG | EANTIC_STR_ARB); ++ fprintf(stderr, " a = "); fputs(res, stderr); fprintf(stderr, "\n"); ++ flint_free(res); ++ fprintf(stderr, " b = "); fmpq_fprint(stderr, b); fprintf(stderr, "\n"); ++ fflush(stderr); ++ ++ fprintf(stderr, " add\n"); + renf_elem_add_fmpq(c, a, b, nf); ++ res = renf_elem_get_str_pretty(c, "x", nf, 10, EANTIC_STR_ALG | EANTIC_STR_ARB); ++ fprintf(stderr, " c = "); fputs(res, stderr); fprintf(stderr, "\n"); ++ flint_free(res); ++ fflush(stderr); + renf_elem_check_embedding(c, nf, 1024); ++ ++ fprintf(stderr, " sub\n"); + renf_elem_sub_fmpq(c, a, b, nf); ++ res = renf_elem_get_str_pretty(c, "x", nf, 10, EANTIC_STR_ALG | EANTIC_STR_ARB); ++ fprintf(stderr, " c = "); fputs(res, stderr); fprintf(stderr, "\n"); ++ flint_free(res); ++ fflush(stderr); + renf_elem_check_embedding(c, nf, 1024); ++ ++ fprintf(stderr, " mul\n"); + renf_elem_mul_fmpq(c, a, b, nf); ++ res = renf_elem_get_str_pretty(c, "x", nf, 10, EANTIC_STR_ALG | EANTIC_STR_ARB); ++ fprintf(stderr, " c = "); fputs(res, stderr); fprintf(stderr, "\n"); ++ flint_free(res); ++ fflush(stderr); + renf_elem_check_embedding(c, nf, 1024); ++ + if (!fmpq_is_zero(b)) + { ++ fprintf(stderr, " div\n"); + renf_elem_div_fmpq(c, a, b, nf); ++ res = renf_elem_get_str_pretty(c, "x", nf, 10, EANTIC_STR_ALG | EANTIC_STR_ARB); ++ fprintf(stderr, " c = "); fputs(res, stderr); fprintf(stderr, "\n"); ++ flint_free(res); ++ fflush(stderr); + renf_elem_check_embedding(c, nf, 1024); + } + +diff --git a/renf_elem/test/t-get_str_pretty.c b/renf_elem/test/t-get_str_pretty.c +index 516a8bd..7d88173 100644 +--- a/renf_elem/test/t-get_str_pretty.c ++++ b/renf_elem/test/t-get_str_pretty.c +@@ -20,7 +20,7 @@ int main(void) + renf_elem_t a; + fmpq_poly_t pol; + char * s; +- size_t i; ++ size_t i, j; + int flags[5] = { + EANTIC_STR_ALG, + EANTIC_STR_D, +@@ -29,10 +29,20 @@ int main(void) + EANTIC_STR_ALG | EANTIC_STR_ARB}; + char * output[5] = { + "-2/3*x+1/2", +- "-0.990712", ++ "-0.99071198", + "[-0.9907119850 +/- 1.43e-13]", +- "-2/3*x+1/2 ~ -0.990712", ++ "-2/3*x+1/2 ~ -0.99071198", + "-2/3*x+1/2 ~ [-0.9907119850 +/- 1.43e-13]"}; ++ char * shifted_output [8] = { ++ "-9.9071198", ++ "-99.071198", ++ "-990.71198", ++ "-9907.1198", ++ "-99071.198", ++ "-990711.98", ++ "-9907119.8", ++ "-9.9071198e+7", ++ }; + + FLINT_TEST_INIT(state); + +@@ -58,12 +68,47 @@ int main(void) + s = renf_elem_get_str_pretty(a, "x", nf, 10, flags[i]); + if (strcmp(s, output[i])) + { +- fprintf(stderr, "wrong output %zu\n", i); ++ fprintf(stderr, "wrong output for i=%zu; expected %s got %s\n", i, output[i], s); + return 1; + } + flint_free(s); + } + ++ /* Check that large numbers can be printed */ ++ for (j = 0; j < 1024; j++) ++ { ++ renf_elem_mul_ui(a, a, 10, nf); ++ ++ for (i = 0; i < 5; i++) { ++ s = renf_elem_get_str_pretty(a, "x", nf, 10, flags[i]); ++ ++ if (i == 0 || i == 3 || i == 4) { ++ if (strncmp(s, "-2", 2)) { ++ fprintf(stderr, "wrong output for i=%zu; expected output to start with -2 but found %s\n", i, s); ++ return 1; ++ } ++ } else if (i == 1) { ++ if (strncmp(s, "-9", 2) && strcmp(s, "-inf")) { ++ fprintf(stderr, "wrong output for i=%zu; expected output to be -inf or start with -9 but found %s\n", i, s); ++ return 1; ++ } ++ if (j < 8) { ++ if (strcmp(s, shifted_output[j])) { ++ fprintf(stderr, "wrong output for i=%zu; expected output to be %s but found %s\n", i, shifted_output[j], s); ++ return 1; ++ } ++ } ++ } else if (i == 4) { ++ if (strncmp(s, "[-9", 3)) { ++ fprintf(stderr, "wrong output for i=%zu; expected output to start with [-9 but found %s\n", i, s); ++ return 1; ++ } ++ } ++ ++ flint_free(s); ++ } ++ } ++ + renf_elem_clear(a, nf); + renf_clear(nf); + +diff --git a/renfxx/test/t-get_str.cpp b/renfxx/test/t-get_str.cpp +index ead2f0e..b6a7a49 100644 +--- a/renfxx/test/t-get_str.cpp ++++ b/renfxx/test/t-get_str.cpp +@@ -52,19 +52,19 @@ int main(void) + + { + renf_elem_class a(K, "0"); +- check_string(a, "(0 ~ 0.000000)", "0", "0.000000"); ++ check_string(a, "(0 ~ 0)", "0", "0"); + } + + { + std::string alg = "2/3"; + std::string d = "2/3"; + renf_elem_class a(K, alg); +- check_string(a, "(2/3 ~ 0.666667)", "2/3", "0.666667"); ++ check_string(a, "(2/3 ~ 0.66666667)", "2/3", "0.66666667"); + } + + { + std::string alg = "x"; +- std::string d = "1.414214"; ++ std::string d = "1.4142136"; + renf_elem_class a(K, alg); + check_string(a, "(" + alg + " ~ " + d + ")", alg, d); + } +@@ -76,24 +76,24 @@ int main(void) + + { + renf_elem_class a(K, "0"); +- check_string(a, "(0 ~ 0.000000)", "0", "0.000000"); ++ check_string(a, "(0 ~ 0)", "0", "0"); + } + + { + renf_elem_class a(K, "2/3"); +- check_string(a, "(2/3 ~ 0.666667)", "2/3", "0.666667"); ++ check_string(a, "(2/3 ~ 0.66666667)", "2/3", "0.66666667"); + } + + { + std::string alg = "x"; +- std::string d = "0.873580"; ++ std::string d = "0.87358046"; + renf_elem_class a(K, alg); + check_string(a, "(" + alg + " ~ " + d + ")", alg, d); + } + + { + std::string alg = "3/7*x-2/11"; +- std::string d = "0.192573"; ++ std::string d = "0.19257345"; + renf_elem_class a(K, alg); + check_string(a, "(" + alg + " ~ " + d + ")", alg, d); + } +diff --git a/renfxx/test/t-stream.cpp b/renfxx/test/t-stream.cpp +index c1d8923..f7bfaa0 100644 +--- a/renfxx/test/t-stream.cpp ++++ b/renfxx/test/t-stream.cpp +@@ -41,7 +41,7 @@ int main(void) + std::stringstream s; + renf_elem_class a = K1.gen(); + s << a; +- if (s.str() != "(A ~ 1.259921)") ++ if (s.str() != "(A ~ 1.2599210)") + throw std::runtime_error("wrong string, got " + s.str()); + } + diff -Nru e-antic-0.1.5+ds/debian/patches/remove-flint-upperlimit.patch e-antic-0.1.5+ds/debian/patches/remove-flint-upperlimit.patch --- e-antic-0.1.5+ds/debian/patches/remove-flint-upperlimit.patch 1970-01-01 00:00:00.000000000 +0000 +++ e-antic-0.1.5+ds/debian/patches/remove-flint-upperlimit.patch 2020-08-27 15:42:51.000000000 +0000 @@ -0,0 +1,77 @@ +commit cebabe52632013a70be321d590301e06c306a766 +Author: Winfried Bruns +Date: Thu Jul 30 12:26:28 2020 +0200 + + Allowing Flint versions >= 2.5.2 + +diff --git a/e-antic/e-antic.h b/e-antic/e-antic.h +index df841e7..02656d9 100644 +--- a/e-antic/e-antic.h ++++ b/e-antic/e-antic.h +@@ -20,8 +20,8 @@ extern "C" { + + /* check flint version */ + +-#if __FLINT_RELEASE != 20502 && __FLINT_RELEASE != 20503 && __FLINT_RELEASE != 20600 +-#error FLINT 2.5.2 or 2.5.3 required ++#if __FLINT_RELEASE < 20502 ++#error FLINT >= 2.5.2 required + #endif + + #ifdef __cplusplus +diff --git a/e-antic/poly_extra.h b/e-antic/poly_extra.h +index b8c5ecc..509930d 100644 +--- a/e-antic/poly_extra.h ++++ b/e-antic/poly_extra.h +@@ -262,7 +262,7 @@ void fmpz_poly_evaluate_at_one(fmpz_t res, fmpz * p, slong len) + return _fmpz_vec_sum(res, p, len); + } + +-#if __FLINT_RELEASE != 20600 ++#if __FLINT_RELEASE < 20600 + static __inline__ + double fmpq_get_d(const fmpq_t q) + { +@@ -346,14 +346,14 @@ void _fmpz_poly_num_real_roots_sturm(slong * n_neg, slong * n_pos, const fmpz * + + void fmpz_poly_product_roots_fmpq_vec(fmpz_poly_t poly, const fmpq * xs, slong n); + +-#elif __FLINT_RELEASE == 20503 || __FLINT_RELEASE == 20600 ++#elif __FLINT_RELEASE > 20502 + + #define _EANTIC_FIXED_fmpq_poly_get_str_pretty _fmpq_poly_get_str_pretty + #define EANTIC_FIXED_fmpq_poly_get_str_pretty fmpq_poly_get_str_pretty + + #else + +-#error "Invalid flint release: e-antic needs flint-2.5.2, flint-2.5.3 or flint-2.6.0" ++#error "Invalid flint release: e-antic needs flint >= 2.5.2" + + #endif + +diff --git a/nf_elem/mul.c b/nf_elem/mul.c +index 069e002..4b6dee6 100644 +--- a/nf_elem/mul.c ++++ b/nf_elem/mul.c +@@ -127,7 +127,7 @@ void _nf_elem_mul_red(nf_elem_t a, const nf_elem_t b, + + _fmpz_vec_set(r, NF_ELEM_NUMREF(a), plen); + +-#if __FLINT_RELEASE == 20600 ++#if __FLINT_RELEASE >= 20600 + _fmpz_poly_divrem(q, NF_ELEM_NUMREF(a), r, plen, + fmpq_poly_numref(nf->pol), len, 0); + #else +diff --git a/nf_elem/reduce.c b/nf_elem/reduce.c +index 94914d2..b3e37ac 100644 +--- a/nf_elem/reduce.c ++++ b/nf_elem/reduce.c +@@ -80,7 +80,7 @@ void _nf_elem_reduce(nf_elem_t a, const nf_t nf) + + _fmpz_vec_set(r, NF_ELEM_NUMREF(a), plen); + +-#if __FLINT_RELEASE == 20600 ++#if __FLINT_RELEASE >= 20600 + _fmpz_poly_divrem(q, NF_ELEM_NUMREF(a), r, plen, + fmpq_poly_numref(nf->pol), len, 0); + #else diff -Nru e-antic-0.1.5+ds/debian/patches/series e-antic-0.1.5+ds/debian/patches/series --- e-antic-0.1.5+ds/debian/patches/series 2020-05-04 16:14:20.000000000 +0000 +++ e-antic-0.1.5+ds/debian/patches/series 2020-08-27 15:59:03.000000000 +0000 @@ -1,4 +1,5 @@ -upstream-fix-sprintf_buffer_overflow.patch upstream-libtool-versioning.patch upstream-libtool-version_script.patch debianization.patch +flint-2.6.0.patch +remove-flint-upperlimit.patch diff -Nru e-antic-0.1.5+ds/debian/patches/upstream-libtool-version_script.patch e-antic-0.1.5+ds/debian/patches/upstream-libtool-version_script.patch --- e-antic-0.1.5+ds/debian/patches/upstream-libtool-version_script.patch 2020-05-19 10:05:26.000000000 +0000 +++ e-antic-0.1.5+ds/debian/patches/upstream-libtool-version_script.patch 2020-08-27 15:59:03.000000000 +0000 @@ -15,13 +15,19 @@ This material uses the ld-version-script.m4 script as furnished by gnulib [2]. [1] https://www.gnu.org/software/gnulib/manual/html_node/LD-Version-Scripts.html [2] https://www.gnu.org/software/gnulib/ + . + EANTIC_FIXED_fmpq_poly_add_fmpq added to script by Peter Michael Green as part + of the patching to support flint 2.6.3 Origin: vendor, Debian Forwarded: https://github.com/videlec/e-antic/pull/53 Author: Jerome Benoit -Last-Update: 2019-05-17 +Author: Peter Michael Green +Last-Update: 2020-08-27 +Index: e-antic-0.1.5+ds/libeantic.map +=================================================================== --- /dev/null -+++ b/libeantic.map ++++ e-antic-0.1.5+ds/libeantic.map @@ -0,0 +1,204 @@ +## libeantic.map -- LD version script +## @@ -223,13 +229,15 @@ +fmpz_poly_randtest_no_real_root; +_fmpz_poly_num_real_roots_sturm; +fmpz_poly_product_roots_fmpq_vec; -+ ++EANTIC_FIXED_fmpq_poly_add_fmpq; +local: *; +}; +## eos ---- a/configure.ac -+++ b/configure.ac -@@ -18,6 +18,9 @@ +Index: e-antic-0.1.5+ds/configure.ac +=================================================================== +--- e-antic-0.1.5+ds.orig/configure.ac ++++ e-antic-0.1.5+ds/configure.ac +@@ -18,6 +18,9 @@ EANTIC_AC_PKG_EANTIC_SETUP AC_PROG_LIBTOOL AC_PROG_CXX @@ -239,9 +247,11 @@ ## Test for OpenMP parallelization. AC_ARG_ENABLE([openmp], [AS_HELP_STRING([--enable-openmp@<:@=ARG@:>@], ---- a/Makefile.am -+++ b/Makefile.am -@@ -10,9 +10,17 @@ +Index: e-antic-0.1.5+ds/Makefile.am +=================================================================== +--- e-antic-0.1.5+ds.orig/Makefile.am ++++ e-antic-0.1.5+ds/Makefile.am +@@ -10,9 +10,17 @@ lib_LTLIBRARIES = libeantic.la libeantic libeantic_la_LT_INFO = -version-info $(EANTIC_LT_INFO) libeanticxx_la_LT_INFO = -version-info $(EANTIC_LT_INFO) @@ -261,8 +271,10 @@ # Linked-against libraries libeantic_la_LIBADD = @LIBS@ +Index: e-antic-0.1.5+ds/libeanticxx.map +=================================================================== --- /dev/null -+++ b/libeanticxx.map ++++ e-antic-0.1.5+ds/libeanticxx.map @@ -0,0 +1,21 @@ +## libeanticxx.map -- LD version script +##