Index: factory/FLINTconvert.cc
===================================================================
--- factory/FLINTconvert.cc	(revision 7c0d57dd4602fd556a785a238d95da87fbba50de)
+++ factory/FLINTconvert.cc	(revision fc25d7148572ee90d065637f58166dac76c41c53)
@@ -46,4 +46,11 @@
 #include <flint/nmod_mat.h>
 #include <flint/fmpz_mat.h>
+#if (__FLINT_VERSION_MINOR >= 4)
+#include <flint/fq.h>
+#include <flint/fq_poly.h>
+#include <flint/fq_nmod.h>
+#include <flint/fq_nmod_poly.h>
+#include <flint/fq_nmod_mat.h>
+#endif
 #ifdef __cplusplus
 }
@@ -73,5 +80,5 @@
 }
 
-CanonicalForm convertFmpz2CF (fmpz_t coefficient)
+CanonicalForm convertFmpz2CF (const fmpz_t coefficient)
 {
   if (fmpz_cmp_si (coefficient, MINIMMEDIATE) >= 0 &&
@@ -91,5 +98,6 @@
 }
 
-CanonicalForm convertFmpz_poly_t2FacCF (fmpz_poly_t poly, const Variable& x)
+CanonicalForm
+convertFmpz_poly_t2FacCF (const fmpz_poly_t poly, const Variable& x)
 {
   CanonicalForm result= 0;
@@ -104,5 +112,6 @@
 }
 
-void convertFacCF2nmod_poly_t (nmod_poly_t result, const CanonicalForm& f)
+void
+convertFacCF2nmod_poly_t (nmod_poly_t result, const CanonicalForm& f)
 {
   bool save_sym_ff= isOn (SW_SYMMETRIC_FF);
@@ -125,5 +134,6 @@
 }
 
-CanonicalForm convertnmod_poly_t2FacCF (nmod_poly_t poly, const Variable& x)
+CanonicalForm
+convertnmod_poly_t2FacCF (const nmod_poly_t poly, const Variable& x)
 {
   CanonicalForm result= 0;
@@ -188,5 +198,6 @@
 }
 
-CanonicalForm convertFmpq_poly_t2FacCF (fmpq_poly_t p, const Variable& x)
+CanonicalForm
+convertFmpq_poly_t2FacCF (const fmpq_poly_t p, const Variable& x)
 {
   CanonicalForm result= 0;
@@ -226,6 +237,6 @@
 
 CFFList
-convertFLINTnmod_poly_factor2FacCFFList (nmod_poly_factor_t fac,
-                                          mp_limb_t leadingCoeff,
+convertFLINTnmod_poly_factor2FacCFFList (const nmod_poly_factor_t fac,
+                                          const mp_limb_t leadingCoeff,
                                           const Variable& x
                                          )
@@ -238,8 +249,28 @@
 
   for (i = 0; i < fac->num; i++)
-    result.append (CFFactor (convertnmod_poly_t2FacCF ((nmod_poly_t &)fac->p[i],x),
+    result.append (CFFactor (convertnmod_poly_t2FacCF (
+                             (nmod_poly_t &)fac->p[i],x),
                              fac->exp[i]));
   return result;
 }
+
+#if __FLINT_VERSION_MINOR >= 4
+CFFList
+convertFLINTFq_nmod_poly_factor2FacCFFList (const fq_nmod_poly_factor_t fac,
+                                       const Variable& x, const Variable& alpha,
+                                       const fq_nmod_ctx_t fq_con
+                                         )
+{
+  CFFList result;
+
+  long i;
+
+  for (i = 0; i < fac->num; i++)
+    result.append (CFFactor (convertFq_nmod_poly_t2FacCF (
+                             (fq_nmod_poly_t &)fac->poly[i], x, alpha, fq_con),
+                             fac->exp[i]));
+  return result;
+}
+#endif
 
 void
@@ -255,5 +286,5 @@
 
 CanonicalForm
-convertFmpz_mod_poly_t2FacCF (fmpz_mod_poly_t poly, const Variable& x,
+convertFmpz_mod_poly_t2FacCF (const fmpz_mod_poly_t poly, const Variable& x,
                               const modpk& b)
 {
@@ -266,5 +297,134 @@
 }
 
-void convertFacCFMatrix2Fmpz_mat_t (fmpz_mat_t M, CFMatrix &m)
+#if __FLINT_VERSION_MINOR >= 4
+void
+convertFacCF2Fq_nmod_t (fq_nmod_t result, const CanonicalForm& f,
+                        const fq_nmod_ctx_t ctx)
+{
+  bool save_sym_ff= isOn (SW_SYMMETRIC_FF);
+  if (save_sym_ff) Off (SW_SYMMETRIC_FF);
+  for (CFIterator i= f; i.hasTerms(); i++)
+  {
+    CanonicalForm c= i.coeff();
+    if (!c.isImm()) c=c.mapinto(); //c%= getCharacteristic();
+    if (!c.isImm())
+    {  //This case will never happen if the characteristic is in fact a prime
+       // number, since all coefficients are represented as immediates
+       printf("convertFacCF2Fq_nmod_t: coefficient not immediate!, char=%d\n",
+              getCharacteristic());
+    }
+    else
+    {
+      STICKYASSERT (i.exp() <= fq_nmod_ctx_degree(ctx), "convertFacCF2Fq_nmod_t: element is not reduced");
+      nmod_poly_set_coeff_ui (result, i.exp(), c.intval());
+    }
+  }
+  if (save_sym_ff) On (SW_SYMMETRIC_FF);
+}
+
+CanonicalForm
+convertFq_nmod_t2FacCF (const fq_nmod_t poly, const Variable& alpha)
+{
+  return convertnmod_poly_t2FacCF (poly, alpha);
+}
+
+void
+convertFacCF2Fq_t (fq_t result, const CanonicalForm& f, const fq_ctx_t ctx)
+{
+  fmpz_poly_init2 (result, fq_ctx_degree(ctx));
+  ASSERT (degree (f) < fq_ctx_degree (ctx), "input is not reduced");
+  _fmpz_poly_set_length(result, degree(f)+1);
+  for (CFIterator i= f; i.hasTerms(); i++)
+    convertCF2Fmpz (fmpz_poly_get_coeff_ptr(result, i.exp()), i.coeff());
+  _fmpz_vec_scalar_mod_fmpz (result->coeffs, result->coeffs, degree (f) + 1,
+                             &ctx->p);
+  _fmpz_poly_normalise (result);
+}
+
+CanonicalForm
+convertFq_t2FacCF (const fq_t poly, const Variable& alpha)
+{
+  return convertFmpz_poly_t2FacCF (poly, alpha);
+}
+
+void
+convertFacCF2Fq_poly_t (fq_poly_t result, const CanonicalForm& f,
+                        const fq_ctx_t ctx)
+{
+  fq_poly_init2 (result, degree (f)+1, ctx);
+  _fq_poly_set_length (result, degree (f) + 1, ctx);
+  fmpz_poly_t buf;
+  for (CFIterator i= f; i.hasTerms(); i++)
+  {
+    convertFacCF2Fmpz_poly_t (buf, i.coeff());
+    _fmpz_vec_scalar_mod_fmpz (buf->coeffs, buf->coeffs, degree (i.coeff()) + 1,
+                               &ctx->p);
+    _fmpz_poly_normalise (buf);
+    fq_poly_set_coeff (result, i.exp(), buf, ctx);
+    fmpz_poly_clear (buf);
+  }
+}
+
+void
+convertFacCF2Fq_nmod_poly_t (fq_nmod_poly_t result, const CanonicalForm& f,
+                             const fq_nmod_ctx_t ctx)
+{
+  fq_nmod_poly_init2 (result, degree (f)+1, ctx);
+  _fq_nmod_poly_set_length (result, degree (f) + 1, ctx);
+  fq_nmod_t buf;
+  fq_nmod_init2 (buf, ctx);
+  for (CFIterator i= f; i.hasTerms(); i++)
+  {
+    convertFacCF2Fq_nmod_t (buf, i.coeff(), ctx);
+    fq_nmod_poly_set_coeff (result, i.exp(), buf, ctx);
+    fq_nmod_zero (buf, ctx);
+  }
+  fq_nmod_clear (buf, ctx);
+}
+
+CanonicalForm
+convertFq_poly_t2FacCF (const fq_poly_t p, const Variable& x,
+                        const Variable& alpha, const fq_ctx_t ctx)
+{
+  CanonicalForm result= 0;
+  fq_t coeff;
+  long n= fq_poly_length (p, ctx);
+  fq_init2 (coeff, ctx);
+  for (long i= 0; i < n; i++)
+  {
+    fq_poly_get_coeff (coeff, p, i, ctx);
+    if (fq_is_zero (coeff, ctx))
+      continue;
+    result += convertFq_t2FacCF (coeff, alpha)*power (x, i);
+    fq_zero (coeff, ctx);
+  }
+  fq_clear (coeff, ctx);
+
+  return result;
+}
+
+CanonicalForm
+convertFq_nmod_poly_t2FacCF (const fq_nmod_poly_t p, const Variable& x,
+                             const Variable& alpha, const fq_nmod_ctx_t ctx)
+{
+  CanonicalForm result= 0;
+  fq_nmod_t coeff;
+  long n= fq_nmod_poly_length (p, ctx);
+  fq_nmod_init2 (coeff, ctx);
+  for (long i= 0; i < n; i++)
+  {
+    fq_nmod_poly_get_coeff (coeff, p, i, ctx);
+    if (fq_nmod_is_zero (coeff, ctx))
+      continue;
+    result += convertFq_nmod_t2FacCF (coeff, alpha)*power (x, i);
+    fq_nmod_zero (coeff, ctx);
+  }
+  fq_nmod_clear (coeff, ctx);
+
+  return result;
+}
+#endif
+
+void convertFacCFMatrix2Fmpz_mat_t (fmpz_mat_t M, const CFMatrix &m)
 {
   fmpz_mat_init (M, (long) m.rows(), (long) m.columns());
@@ -279,5 +439,5 @@
   }
 }
-CFMatrix* convertFmpz_mat_t2FacCFMatrix(fmpz_mat_t m)
+CFMatrix* convertFmpz_mat_t2FacCFMatrix(const fmpz_mat_t m)
 {
   CFMatrix *res=new CFMatrix(fmpz_mat_nrows (m),fmpz_mat_ncols (m));
@@ -293,5 +453,5 @@
 }
 
-void convertFacCFMatrix2nmod_mat_t (nmod_mat_t M, CFMatrix &m)
+void convertFacCFMatrix2nmod_mat_t (nmod_mat_t M, const CFMatrix &m)
 {
   nmod_mat_init (M, (long) m.rows(), (long) m.columns(), getCharacteristic());
@@ -311,5 +471,5 @@
 }
 
-CFMatrix* convertNmod_mat_t2FacCFMatrix(nmod_mat_t m)
+CFMatrix* convertNmod_mat_t2FacCFMatrix(const nmod_mat_t m)
 {
   CFMatrix *res=new CFMatrix(nmod_mat_nrows (m), nmod_mat_ncols (m));
@@ -325,5 +485,41 @@
 }
 
-#endif
-
-
+#if __FLINT_VERSION_MINOR >= 4
+void
+convertFacCFMatrix2Fq_nmod_mat_t (fq_nmod_mat_t M,
+                                  const fq_nmod_ctx_t fq_con, const CFMatrix &m)
+{
+  fq_nmod_mat_init (M, (long) m.rows(), (long) m.columns(), fq_con);
+  int i,j;
+  for(i=m.rows();i>0;i--)
+  {
+    for(j=m.columns();j>0;j--)
+    {
+      convertFacCF2nmod_poly_t (M->rows[i-1]+j-1, m (i,j));
+    }
+  }
+}
+
+CFMatrix*
+convertFq_nmod_mat_t2FacCFMatrix(const fq_nmod_mat_t m,
+                                 const fq_nmod_ctx_t& fq_con,
+                                 const Variable& alpha)
+{
+  CFMatrix *res=new CFMatrix(fq_nmod_mat_nrows (m, fq_con),
+                             fq_nmod_mat_ncols (m, fq_con));
+  int i,j;
+  for(i=res->rows();i>0;i--)
+  {
+    for(j=res->columns();j>0;j--)
+    {
+      (*res)(i,j)=convertFq_nmod_t2FacCF (fq_nmod_mat_entry (m, i-1, j-1),
+                                          alpha);
+    }
+  }
+  return res;
+}
+#endif
+
+#endif
+
+
Index: factory/FLINTconvert.h
===================================================================
--- factory/FLINTconvert.h	(revision 7c0d57dd4602fd556a785a238d95da87fbba50de)
+++ factory/FLINTconvert.h	(revision fc25d7148572ee90d065637f58166dac76c41c53)
@@ -35,4 +35,11 @@
 #include <flint/nmod_mat.h>
 #include <flint/fmpz_mat.h>
+#if (__FLINT_VERSION_MINOR >= 4)
+#include <flint/fq.h>
+#include <flint/fq_poly.h>
+#include <flint/fq_nmod.h>
+#include <flint/fq_nmod_poly.h>
+#include <flint/fq_nmod_mat.h>
+#endif
 #ifdef __cplusplus
 }
@@ -57,10 +64,10 @@
 /// conversion of a FLINT integer to CanonicalForm
 CanonicalForm
-convertFmpz2CF (fmpz_t coefficient ///< [in] a FLINT integer
+convertFmpz2CF (const fmpz_t coefficient ///< [in] a FLINT integer
                );
 
 /// conversion of a FLINT poly over Z to CanonicalForm
 CanonicalForm
-convertFmpz_poly_t2FacCF (fmpz_poly_t poly, ///< [in] an fmpz_poly_t
+convertFmpz_poly_t2FacCF (const fmpz_poly_t poly, ///< [in] an fmpz_poly_t
                           const Variable& x ///< [in] variable the result should
                                             ///< have
@@ -77,5 +84,5 @@
 /// conversion of a FLINT poly over Z/p to CanonicalForm
 CanonicalForm
-convertnmod_poly_t2FacCF (nmod_poly_t poly, ///< [in] a nmod_poly_t
+convertnmod_poly_t2FacCF (const nmod_poly_t poly, ///< [in] a nmod_poly_t
                           const Variable& x ///< [in] variable the result should
                                             ///< have
@@ -98,5 +105,5 @@
 /// conversion of a FLINT poly over Q to CanonicalForm
 CanonicalForm
-convertFmpq_poly_t2FacCF (fmpq_poly_t p,    ///< [in] an fmpq_poly_t
+convertFmpq_poly_t2FacCF (const fmpq_poly_t p,    ///< [in] an fmpq_poly_t
                           const Variable& x ///< [in] variable the result should
                                             ///< have
@@ -107,6 +114,6 @@
 CFFList
 convertFLINTnmod_poly_factor2FacCFFList (
-                   nmod_poly_factor_t fac, ///< [in] a nmod_poly_factor_t
-                   mp_limb_t leadingCoeff, ///< [in] leading coefficient
+                   const nmod_poly_factor_t fac, ///< [in] a nmod_poly_factor_t
+                   const mp_limb_t leadingCoeff, ///< [in] leading coefficient
                    const Variable& x       ///< [in] variable the result should
                                            ///< have
@@ -127,5 +134,5 @@
 CanonicalForm
 convertFmpz_mod_poly_t2FacCF (
-                          fmpz_mod_poly_t poly, ///< [in] fmpz_mod_poly_t
+                          const fmpz_mod_poly_t poly, ///< [in] fmpz_mod_poly_t
                           const Variable& x,    ///< [in] variable the result
                                                 ///< should have
@@ -134,22 +141,113 @@
                              );
 
+#if __FLINT_VERSION_MINOR >= 4
+/// conversion of a FLINT element of F_q to a CanonicalForm with alg. variable 
+/// alpha
+CanonicalForm
+convertFq_nmod_t2FacCF (const fq_nmod_t poly, ///< [in] fq_nmod_t
+                        const Variable& alpha ///< [in] algebraic variable
+                       );
+
+/// conversion of a FLINT element of F_q with non-word size p to a CanonicalForm
+/// with alg. variable alpha
+CanonicalForm
+convertFq_t2FacCF (const fq_t poly,      ///< [in] fq_t
+                   const Variable& alpha ///< [in] algebraic variable
+                  );
+
+/// conversion of a factory element of F_q to a FLINT fq_nmod_t, does not do any
+/// memory allocation for poly
+void
+convertFacCF2Fq_nmod_t (fq_nmod_t result,       ///< [in,out] fq_nmod_t
+                        const CanonicalForm& f, ///< [in] element of Fq
+                        const fq_nmod_ctx_t ctx ///< [in] Fq context
+                       );
+
+/// conversion of a factory element of F_q (for non-word size p) to a FLINT fq_t
+void
+convertFacCF2Fq_t (fq_t result,            ///< [in,out] fq_t
+                   const CanonicalForm& f, ///< [in] element of Fq
+                   const fq_ctx_t ctx      ///< [in] Fq context
+                  );
+
+/// conversion of a factory univariate poly over F_q (for non-word size p) to a
+/// FLINT fq_poly_t
+void
+convertFacCF2Fq_poly_t (fq_poly_t result,      ///< [in,out] fq_poly_t
+                        const CanonicalForm& f,///< [in] univariate poly over Fq
+                        const fq_ctx_t ctx     ///< [in] Fq context
+                       );
+
+/// conversion of a factory univariate poly over F_q to a FLINT fq_nmod_poly_t
+void
+convertFacCF2Fq_nmod_poly_t (fq_nmod_poly_t result, ///< [in,out] fq_nmod_poly_t
+                             const CanonicalForm& f,///< [in] univariate poly 
+                                                    ///< over Fq
+                             const fq_nmod_ctx_t ctx///< [in] Fq context
+                            );
+
+/// conversion of a FLINT poly over Fq (for non-word size p) to a CanonicalForm
+/// with alg. variable alpha and polynomial variable x
+CanonicalForm
+convertFq_poly_t2FacCF (const fq_poly_t p,     ///< [in] fq_poly_t
+                        const Variable& x,     ///< [in] polynomial variable
+                        const Variable& alpha, ///< [in] algebraic variable
+                        const fq_ctx_t ctx     ///< [in] Fq context
+                       );
+
+/// conversion of a FLINT poly over Fq to a CanonicalForm with alg. variable
+/// alpha and polynomial variable x
+CanonicalForm
+convertFq_nmod_poly_t2FacCF (const fq_nmod_poly_t p, ///< [in] fq_nmod_poly_t
+                             const Variable& x,      ///< [in] polynomial var.
+                             const Variable& alpha,  ///< [in] algebraic var.
+                             const fq_nmod_ctx_t ctx ///< [in] Fq context
+                            );
+#endif
+
 /// conversion of a factory matrix over Z to a fmpz_mat_t
-void convertFacCFMatrix2Fmpz_mat_t (fmpz_mat_t M, ///<[in,out] fmpz_mat_t
-                                    CFMatrix &m   ///<[in] matrix over Z
+void convertFacCFMatrix2Fmpz_mat_t (fmpz_mat_t M,      ///<[in,out] fmpz_mat_t
+                                    const CFMatrix &m  ///<[in] matrix over Z
                                    );
 
 /// conversion of a FLINT matrix over Z to a factory matrix
-CFMatrix* convertFmpz_mat_t2FacCFMatrix(fmpz_mat_t m ///<[in] fmpz_mat_t
+CFMatrix* convertFmpz_mat_t2FacCFMatrix(const fmpz_mat_t m ///<[in] fmpz_mat_t
                                        );
 
 /// conversion of a factory matrix over Z/p to a nmod_mat_t
-void convertFacCFMatrix2nmod_mat_t (nmod_mat_t M, ///<[in,out] nmod_mat_t
-                                    CFMatrix &m   ///<[in] matrix over Z/p
+void convertFacCFMatrix2nmod_mat_t (nmod_mat_t M,     ///<[in,out] nmod_mat_t
+                                    const CFMatrix &m ///<[in] matrix over Z/p
                                    );
 
 /// conversion of a FLINT matrix over Z/p to a factory matrix
-CFMatrix* convertNmod_mat_t2FacCFMatrix(nmod_mat_t m ///<[in] nmod_mat_t
+CFMatrix* convertNmod_mat_t2FacCFMatrix(const nmod_mat_t m ///<[in] nmod_mat_t
                                        );
 
-#endif
-#endif
+#if __FLINT_VERSION_MINOR >= 4
+/// conversion of a FLINT matrix over F_q to a factory matrix
+CFMatrix*
+convertFq_nmod_mat_t2FacCFMatrix(const fq_nmod_mat_t m,       ///< [in] fq_nmod_mat_t
+                                 const fq_nmod_ctx_t& fq_con, ///< [in] Fq context
+                                 const Variable& alpha ///< [in] algebraic variable
+                                );
+
+/// conversion of a factory matrix over F_q to a fq_nmod_mat_t
+void
+convertFacCFMatrix2Fq_nmod_mat_t (fq_nmod_mat_t M,            ///< [in, out] fq_nmod_mat_t
+                                  const fq_nmod_ctx_t fq_con, ///< [in] Fq context
+                                  const CFMatrix &m           ///< [in] matrix over Fq
+                                 );
+
+/// conversion of a FLINT factorization over Fq (for word size p) to a
+/// CFFList
+CFFList
+convertFLINTFq_nmod_poly_factor2FacCFFList (const fq_nmod_poly_factor_t fac, ///< [in] fq_nmod_poly_factor_t
+                                          const Variable& x,     ///< [in] polynomial variable
+                                          const Variable& alpha, ///< [in] algebraic variable
+                                          const fq_nmod_ctx_t fq_con ///< [in] Fq context
+                                           );
+#endif
+
+
+#endif
+#endif
