Repository: flintlib/antic (language: python)

Issue:
Compatibility with flint 2.6
In https://github.com/wbhart/antic/commit/2d6a93c1b34d545abf98f1b2d6fe85ecf281b7a9 antic was adapted to API changes in flint 2.7. In e-antic we would like to support both flint 2.6 and 2.7 to make upgrading easier.

I could add a few #ifdefs to make antic work with flint 2.6 and 2.7. Should I go ahead and create a Pull Request?


Discussion / hints:
cc @videlec 
That's fine, but please be aware that we do not intend to maintain the flint-2.6 version of flint or antic.

Fix patch:
diff --git a/.build_dependencies b/.build_dependencies
index 64c7bed5..25672199 100755
--- a/.build_dependencies
+++ b/.build_dependencies
@@ -1,27 +1,31 @@
-#! /bin/sh
+#!/bin/bash
+
+MAKE=${MAKE:=make}
+
+set -exo pipefail
 
 wget http://mpir.org/mpir-2.7.2.tar.bz2
 tar -xf mpir-2.7.2.tar.bz2
 mkdir -p local
 
-cd mpir-2.7.2
+pushd mpir-2.7.2
 ./configure ABI=$ABI --enable-gmpcompat --prefix=${LOCAL}
-${MAKE} > /dev/null 2>&1
-${MAKE} install > /dev/null 2>&1
-cd ..
+${MAKE}
+${MAKE} install
+popd
 
 wget http://www.mpfr.org/mpfr-4.0.0/mpfr-4.0.0.tar.bz2
 tar -xf mpfr-4.0.0.tar.bz2
-cd mpfr-4.0.0
+pushd mpfr-4.0.0
 ./configure ABI=$ABI --with-gmp=${LOCAL} --prefix=${LOCAL}
-${MAKE} > /dev/null 2>&1
-${MAKE} install > /dev/null 2>&1
-cd ..
+${MAKE}
+${MAKE} install
+popd
  
-git clone https://github.com/wbhart/flint2
-cd flint2
+git clone --branch $FLINT_TAG https://github.com/wbhart/flint2
+pushd flint2
 ./configure --with-mpir=${LOCAL} --with-mpfr=${LOCAL} --prefix=${LOCAL}
-${MAKE} > /dev/null 2>&1
-${MAKE} install > /dev/null 2>&1
-cd ..
+${MAKE}
+${MAKE} install
+popd
 
diff --git a/.travis.yml b/.travis.yml
index 19bb24cc..29921f35 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -6,11 +6,16 @@ addons:
     packages:
       - texinfo
 env:
-  MAKE="make -j4"
+  MAKEFLAGS=-j2
 
 os:
   - osx
   - linux
+env:
+  - FLINT_TAG: v2.6.3
+  - FLINT_TAG: v2.7.0
+  - FLINT_TAG: v2.7.1
+  - FLINT_TAG: trunk
 
 osx_image: xcode6.4
 
@@ -23,12 +28,12 @@ install:
   - while sleep 30; do echo "still alive"; done &
   - ./.build_dependencies
   - ./configure --with-mpir=${LOCAL} --with-mpfr=${LOCAL} --with-flint=${LOCAL} --prefix=${LOCAL}
-  - ${MAKE}
+  - make
   - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then otool -L libantic.dylib; fi
   - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then ldd libantic.so; fi
 
 script:
-  - ${MAKE} check
-  - ${MAKE} install
+  - make check
+  - make install
   - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then otool -L local/lib/libantic.dylib; fi
   - PREFIX=$(pwd)/local ./.check_post_install
diff --git a/nf_elem.h b/nf_elem.h
index 0c4b672c..c634a300 100644
--- a/nf_elem.h
+++ b/nf_elem.h
@@ -553,6 +553,7 @@ void nf_elem_get_nmod_poly_den(nmod_poly_t pol,
 FLINT_DLL
 void nf_elem_get_nmod_poly(nmod_poly_t pol, const nf_elem_t a, const nf_t nf);
 
+#if __FLINT_RELEASE >= 20700
 FLINT_DLL
 void _nf_elem_get_fmpz_mod_poly(fmpz_mod_poly_t pol,
                    const nf_elem_t a, const nf_t nf, const fmpz_mod_ctx_t ctx);
@@ -564,6 +565,16 @@ void nf_elem_get_fmpz_mod_poly_den(fmpz_mod_poly_t pol,
 FLINT_DLL
 void nf_elem_get_fmpz_mod_poly(fmpz_mod_poly_t pol,
                    const nf_elem_t a, const nf_t nf, const fmpz_mod_ctx_t ctx);
+#else
+FLINT_DLL
+void _nf_elem_get_fmpz_mod_poly(fmpz_mod_poly_t pol, const nf_elem_t a, const nf_t nf);
+
+FLINT_DLL
+void nf_elem_get_fmpz_mod_poly_den(fmpz_mod_poly_t pol, const nf_elem_t a, const nf_t nf, int den);
+
+FLINT_DLL
+void nf_elem_get_fmpz_mod_poly(fmpz_mod_poly_t pol, const nf_elem_t a, const nf_t nf);
+#endif
 
 /******************************************************************************
  
@@ -975,4 +986,21 @@ void nf_elem_coprime_den_signed(nf_elem_t res, const nf_elem_t a, const fmpz_t m
 }
 #endif
 
+/******************************************************************************
+
+    Helpers for compatibility with FLINT 2.6
+
+******************************************************************************/
+#if __FLINT_RELEASE >= 20700
+#define FMPZ_MOD_POLY_FIT_LENGTH(POL, N, CTX) fmpz_mod_poly_fit_length(POL, N, CTX)
+#define FMPZ_MOD(F, G, CTX, P) fmpz_mod(F, G, (CTX)->n)
+#define FMPZ_MOD_POLY_ZERO(POL, CTX) fmpz_mod_poly_zero(POL, CTX)
+#define FMPZ_MOD_POLY_SCALAR_DIV_FMPZ(RES, POL, X, CTX) fmpz_mod_poly_scalar_div_fmpz(RES, POL, X, CTX)
+#else
+#define FMPZ_MOD_POLY_FIT_LENGTH(POL, N, CTX) fmpz_mod_poly_fit_length(POL, N)
+#define FMPZ_MOD(F, G, CTX, P) fmpz_mod(F, G, P)
+#define FMPZ_MOD_POLY_ZERO(POL, CTX) fmpz_mod_poly_zero(POL)
+#define FMPZ_MOD_POLY_SCALAR_DIV_FMPZ(RES, POL, X, CTX) fmpz_mod_poly_scalar_div_fmpz(RES, POL, X)
+#endif
+
 #endif
diff --git a/nf_elem/get_fmpz_mod_poly.c b/nf_elem/get_fmpz_mod_poly.c
index a5a78a91..65c68e78 100644
--- a/nf_elem/get_fmpz_mod_poly.c
+++ b/nf_elem/get_fmpz_mod_poly.c
@@ -16,21 +16,25 @@
 
 #include "nf_elem.h"
 
+#if __FLINT_RELEASE >= 20700
 void _nf_elem_get_fmpz_mod_poly(fmpz_mod_poly_t pol, const nf_elem_t a,
                                        const nf_t nf, const fmpz_mod_ctx_t ctx)
+#else
+void _nf_elem_get_fmpz_mod_poly(fmpz_mod_poly_t pol, const nf_elem_t a, const nf_t nf)
+#endif
 {
     if (nf_elem_is_zero(a, nf))
     {
-        fmpz_mod_poly_zero(pol, ctx);
+        FMPZ_MOD_POLY_ZERO(pol, ctx);
         
         return;
     }
     if (nf->flag & NF_LINEAR)
     {
         {
-            fmpz_mod_poly_fit_length(pol, 1, ctx);
+            FMPZ_MOD_POLY_FIT_LENGTH(pol, 1, ctx);
         
-            fmpz_mod(pol->coeffs + 0, LNF_ELEM_NUMREF(a), ctx->n);
+            FMPZ_MOD(pol->coeffs + 0, LNF_ELEM_NUMREF(a), ctx, &(pol->p));
         
             _fmpz_mod_poly_set_length(pol, 1);
             _fmpz_mod_poly_normalise(pol);
@@ -38,11 +42,11 @@ void _nf_elem_get_fmpz_mod_poly(fmpz_mod_poly_t pol, const nf_elem_t a,
         }
     } else if (nf->flag & NF_QUADRATIC)
     {
-        fmpz_mod_poly_fit_length(pol, 3, ctx);
+        FMPZ_MOD_POLY_FIT_LENGTH(pol, 3, ctx);
         
-        fmpz_mod(pol->coeffs + 0, QNF_ELEM_NUMREF(a), ctx->n);
-        fmpz_mod(pol->coeffs + 1, QNF_ELEM_NUMREF(a) + 1, ctx->n);
-        fmpz_mod(pol->coeffs + 2, QNF_ELEM_NUMREF(a) + 2, ctx->n);
+        FMPZ_MOD(pol->coeffs + 0, QNF_ELEM_NUMREF(a), ctx, &(pol->p));
+        FMPZ_MOD(pol->coeffs + 1, QNF_ELEM_NUMREF(a) + 1, ctx, &(pol->p));
+        FMPZ_MOD(pol->coeffs + 2, QNF_ELEM_NUMREF(a) + 2, ctx, &(pol->p));
         
         _fmpz_mod_poly_set_length(pol, 3);
         _fmpz_mod_poly_normalise(pol);
@@ -51,33 +55,48 @@ void _nf_elem_get_fmpz_mod_poly(fmpz_mod_poly_t pol, const nf_elem_t a,
         slong len = NF_ELEM(a)->length;
         slong i;
 
-        fmpz_mod_poly_fit_length(pol, len, ctx);
+        FMPZ_MOD_POLY_FIT_LENGTH(pol, len, ctx);
         
         for (i = 0; i < len; i++)
-            fmpz_mod(pol->coeffs + i, NF_ELEM_NUMREF(a) + i, ctx->n);
+            FMPZ_MOD(pol->coeffs + i, NF_ELEM_NUMREF(a) + i, ctx, &(pol->p));
         
         _fmpz_mod_poly_set_length(pol, len);
         _fmpz_mod_poly_normalise(pol);
     }
 }
 
+#if __FLINT_RELEASE >= 20700
 void nf_elem_get_fmpz_mod_poly_den(fmpz_mod_poly_t pol, const nf_elem_t a,
                               const nf_t nf, int den, const fmpz_mod_ctx_t ctx)
+#else
+void nf_elem_get_fmpz_mod_poly_den(fmpz_mod_poly_t pol, const nf_elem_t a, const nf_t nf, int den)
+#endif
 {
+#if __FLINT_RELEASE >= 20700
     _nf_elem_get_fmpz_mod_poly(pol, a, nf, ctx);
+#else
+    _nf_elem_get_fmpz_mod_poly(pol, a, nf);
+#endif
     if (den)
     {
         if (nf->flag & NF_LINEAR)
-            fmpz_mod_poly_scalar_div_fmpz(pol, pol, LNF_ELEM_DENREF(a), ctx);
+            FMPZ_MOD_POLY_SCALAR_DIV_FMPZ(pol, pol, LNF_ELEM_DENREF(a), ctx);
         else if (nf->flag & NF_QUADRATIC)
-            fmpz_mod_poly_scalar_div_fmpz(pol, pol, QNF_ELEM_DENREF(a), ctx);
+            FMPZ_MOD_POLY_SCALAR_DIV_FMPZ(pol, pol, QNF_ELEM_DENREF(a), ctx);
         else
-            fmpz_mod_poly_scalar_div_fmpz(pol, pol, NF_ELEM_DENREF(a), ctx);
+            FMPZ_MOD_POLY_SCALAR_DIV_FMPZ(pol, pol, NF_ELEM_DENREF(a), ctx);
     }
 }
 
+#if __FLINT_RELEASE >= 20700
 void nf_elem_get_fmpz_mod_poly(fmpz_mod_poly_t pol, const nf_elem_t a,
                                        const nf_t nf, const fmpz_mod_ctx_t ctx)
 {
     nf_elem_get_fmpz_mod_poly_den(pol, a, nf, 1, ctx);
 }
+#else
+void nf_elem_get_fmpz_mod_poly(fmpz_mod_poly_t pol, const nf_elem_t a, const nf_t nf)
+{
+    nf_elem_get_fmpz_mod_poly_den(pol, a, nf, 1);
+}
+#endif


Test patch:
diff --git a/nf_elem/test/t-get_fmpz_mod_poly.c b/nf_elem/test/t-get_fmpz_mod_poly.c
index db77b14a..2c1ac9db 100644
--- a/nf_elem/test/t-get_fmpz_mod_poly.c
+++ b/nf_elem/test/t-get_fmpz_mod_poly.c
@@ -37,7 +37,9 @@ main(void)
         nf_elem_t a;
         fmpz_mod_poly_t reduced_elem;
         fmpz_t coeff, mod, reduced_coeff;
+#if __FLINT_RELEASE >= 20700
         fmpz_mod_ctx_t ctx;
+#endif
 
         fmpz_init(mod);
         fmpz_randtest_unsigned(mod, state, 2 * FLINT_BITS);
@@ -45,8 +47,12 @@ main(void)
 
         fmpz_init(coeff);
         fmpz_init(reduced_coeff);
+#if __FLINT_RELEASE >= 20700
         fmpz_mod_ctx_init(ctx, mod);
         fmpz_mod_poly_init(reduced_elem, ctx);
+#else
+        fmpz_mod_poly_init(reduced_elem, &mod);
+#endif
 
         nf_init_randtest(nf, state, 40, 200);
 
@@ -54,13 +60,21 @@ main(void)
 
         nf_elem_randtest(a, state, 200, nf);
 
+#if __FLINT_RELEASE >= 20700
         nf_elem_get_fmpz_mod_poly_den(reduced_elem, a, nf, 0, ctx);
+#else
+        nf_elem_get_fmpz_mod_poly_den(reduced_elem, a, nf, 0);
+#endif
 
         for (j = 0; j < fmpq_poly_degree(nf->pol); j++)
         {
             nf_elem_get_coeff_fmpz(coeff, a, j, nf);
             fmpz_mod(coeff, coeff, mod);
+#if __FLINT_RELEASE >= 20700
             fmpz_mod_poly_get_coeff_fmpz(reduced_coeff, reduced_elem, j, ctx);
+#else
+            fmpz_mod_poly_get_coeff_fmpz(reduced_coeff, reduced_elem, j);
+#endif
             result = fmpz_equal(reduced_coeff, coeff);
             if (!result)
             {
@@ -68,14 +82,24 @@ main(void)
                 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("a mod n = "); fmpz_mod_poly_print_pretty(reduced_elem, "x", ctx); printf("\n");
+                printf("a mod n = ");
+#if __FLINT_RELEASE >= 20700
+                fmpz_mod_poly_print_pretty(reduced_elem, "x", ctx);
+#else
+                fmpz_mod_poly_print_pretty(reduced_elem, "x");
+#endif
+                printf("\n");
                 abort();
             }
         }
 
         nf_elem_clear(a, nf);
+#if __FLINT_RELEASE >= 20700
         fmpz_mod_poly_clear(reduced_elem, ctx);
         fmpz_mod_ctx_clear(ctx);
+#else
+        fmpz_mod_poly_clear(reduced_elem);
+#endif
         fmpz_clear(coeff);
         fmpz_clear(mod);
         nf_clear(nf);
@@ -88,7 +112,9 @@ main(void)
         nf_elem_t a;
         fmpz_mod_poly_t reduced_elem;
         fmpz_t coeff, reduced_coeff, den, mod, d_mod, d_modinv;
+#if __FLINT_RELEASE >= 20700
         fmpz_mod_ctx_t ctx;
+#endif
 
         fmpz_init(coeff);
         fmpz_init(den);
@@ -101,9 +127,12 @@ main(void)
         fmpz_randtest_unsigned(mod, state, 2 * FLINT_BITS);
         fmpz_add_ui(mod, mod, 2);
 
+#if __FLINT_RELEASE >= 20700
         fmpz_mod_ctx_init(ctx, mod);
-
         fmpz_mod_poly_init(reduced_elem, ctx);
+#else
+        fmpz_mod_poly_init(reduced_elem, &mod);
+#endif
 
         nf_init_randtest(nf, state, 40, 200);
 
@@ -116,7 +145,11 @@ main(void)
             fmpz_gcd(d_mod, d_mod, mod);
         } while (!fmpz_is_one(d_mod));
 
+#if __FLINT_RELEASE >= 20700
         nf_elem_get_fmpz_mod_poly(reduced_elem, a, nf, ctx);
+#else
+        nf_elem_get_fmpz_mod_poly(reduced_elem, a, nf);
+#endif
 
         for (j = 0; j < fmpq_poly_degree(nf->pol); j++)
         {
@@ -125,14 +158,24 @@ main(void)
             fmpz_invmod(d_modinv, den, mod);
             fmpz_mul(coeff, coeff, d_modinv);
             fmpz_mod(coeff, coeff, mod);
+#if __FLINT_RELEASE >= 20700
             fmpz_mod_poly_get_coeff_fmpz(reduced_coeff, reduced_elem, j, ctx);
+#else
+            fmpz_mod_poly_get_coeff_fmpz(reduced_coeff, reduced_elem, j);
+#endif
             result = (fmpz_equal(coeff, reduced_coeff));
             if (!result)
             {
                 printf("FAIL: Reducing element with denominator\n");
                 printf("a = "); nf_elem_print_pretty(a, nf, "x"); printf("\n");
                 printf("n = "); fmpz_print(mod); flint_printf("\n");
-                printf("a mod n = "); fmpz_mod_poly_print_pretty(reduced_elem, "x", ctx); printf("\n");
+                printf("a mod n = ");
+#if __FLINT_RELEASE >= 20700
+                fmpz_mod_poly_print_pretty(reduced_elem, "x", ctx);
+#else
+                fmpz_mod_poly_print_pretty(reduced_elem, "x");
+#endif
+                printf("\n");
                 abort();
             }
         }
@@ -144,8 +187,12 @@ main(void)
         fmpz_clear(d_mod);
         fmpz_clear(d_modinv);
         nf_elem_clear(a, nf);
+#if __FLINT_RELEASE >= 20700
         fmpz_mod_poly_clear(reduced_elem, ctx);
         fmpz_mod_ctx_clear(ctx);
+#else
+        fmpz_mod_poly_clear(reduced_elem);
+#endif
         nf_clear(nf);
     }