Changeset 186df6 in git


Ignore:
Timestamp:
Oct 26, 2012, 11:30:17 AM (11 years ago)
Author:
Oleksandr Motsak <motsak@…>
Branches:
(u'spielwiese', 'fe61d9c35bf7c61f2b6cbf1b56e25e2f08d536cc')
Children:
18ccf2907a4a103e379cecf364131e83e3aebab55c890683760ed725b5c0bb38871a3459d5f5ff2b
Parents:
1130ffcea9f0651b2cb15d5f7ea1758fc8cf75aa7061c1e376e43786ea799c82620a0bbed1dc5dd3
Message:
Merge pull request #199 from mmklee/flintinterface_sw

Flintinterface sw
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • Tst/Manual/extgcd.res.gz.uu

    r1130ffc r186df6  
    1 begin 640 extgcd.res.gz
    2 M'XL("&4I<DX``V5X=&=C9"YR97,`34\]"\(P%-SS*Q[%H;%I:=+$P6`&<2F(
     1begin 644 extgcd.res.gz
     2M'XL(")Y5BE```V5X=&=C9"YR97,`34\]"\(P%-SS*Q[%H;%I:=+$P6`&<2F(
    33M2]V*B!^E!$J1-F+\]R:MA"[O#N[N'5>=#^4)`*B"8[F'R(PFZ_0]DN#85??:
    44MQ%@BCZ`4--:TCV?6-Y]L-#>#JG^:*7=F,6:<T-QE:GK9(J^AFLTL=;28J0C1
  • Tst/Manual/extgcd.stat

    r1130ffc r186df6  
    1 1 >> tst_memory_0 :: 1316104113:3132- exportiert :3-1-3:ix86-Linux:mamawutz:173460
    2 1 >> tst_memory_1 :: 1316104113:3132- exportiert :3-1-3:ix86-Linux:mamawutz:667360
    3 1 >> tst_memory_2 :: 1316104113:3132- exportiert :3-1-3:ix86-Linux:mamawutz:700144
    4 1 >> tst_timer_1 :: 1316104113:3132- exportiert :3-1-3:ix86-Linux:mamawutz:12
     11 >> tst_memory_0 :: 1351243166:3150:3-1-5:ix86-Linux:mamawutz:172148
     21 >> tst_memory_1 :: 1351243166:3150:3-1-5:ix86-Linux:mamawutz:2239256
     31 >> tst_memory_2 :: 1351243166:3150:3-1-5:ix86-Linux:mamawutz:2272040
     41 >> tst_timer_1 :: 1351243166:3150:3-1-5:ix86-Linux:mamawutz:3
  • Tst/Old/m61si.res.gz.uu

    r1130ffc r186df6  
    1 begin 640 m61si.res.gz
    2 M'XL("(T/CDP``VTV,7-I+G)E<P`+#G'Q]%-04#"T`Q*I%27IR2D:1CK&FM9<
     1begin 644 m61si.res.gz
     2M'XL("!026U```VTV,7-I+G)E<P`+#G'Q]%-04#"T`Q*I%27IR2D:1CK&FM9<
    33MT8:Q5EP@&:YH(PA+%\@TA@D&0S4:@3069>:E*Q39&NAH5.A4:NKD%%C#Y8V1
    4 M#-:H,-*N,-;4`M*Z0%H'S#<%\T'B2)8:59AJ&U68P*T&*=#&9KV)G8*/IY."
    5 B4DEQB5Y.9I*2-9`17UR26%):K&&H::W"!0`(VD/WX0``````
     4M#-:H,-*N,-;4`M*Z0%H'S#<%\T'B2)96F&I7F,`M-M0W`JH`D2`"X0@@&V:-
     5IB9V"CZ>3@E))<8E>3F:2DC60$5]<DEA26JQAJ&FMP@4`.W-4^>D`````
    66`
    77end
  • Tst/Old/m61si.stat

    r1130ffc r186df6  
    1 1 >> tst_memory_0 :: 1284378480:3115- 13145 :3-1-1:ix86-Linux:mamawutz:170784 1292524760:3120- 13145 :3-1-2:ix86-Linux:mamawutz:171048
    2 1 >> tst_memory_1 :: 1284378480:3115- 13145 :3-1-1:ix86-Linux:mamawutz:667288 1292524760:3120- 13145 :3-1-2:ix86-Linux:mamawutz:667336
    3 1 >> tst_memory_2 :: 1284378480:3115- 13145 :3-1-1:ix86-Linux:mamawutz:700072 1292524760:3120- 13145 :3-1-2:ix86-Linux:mamawutz:700120
    4 1 >> tst_timer_1 :: 1284378480:3115- 13145 :3-1-1:ix86-Linux:mamawutz:3 1292524760:3120- 13145 :3-1-2:ix86-Linux:mamawutz:4
     11 >> tst_memory_0 :: 1348145684:3150:3-1-5:ix86-Linux:mamawutz:171000
     21 >> tst_memory_1 :: 1348145684:3150:3-1-5:ix86-Linux:mamawutz:2239256
     31 >> tst_memory_2 :: 1348145684:3150:3-1-5:ix86-Linux:mamawutz:2272040
     41 >> tst_timer_1 :: 1348145684:3150:3-1-5:ix86-Linux:mamawutz:2
  • factory/FLINTconvert.cc

    r1130ffc r186df6  
    3636#define __GMP_BITS_PER_MP_LIMB GMP_LIMB_BITS
    3737#endif
    38 #include <fmpz.h>
    39 #include <fmpq.h>
    40 #include <fmpz_poly.h>
    41 #include <fmpz_mod_poly.h>
    42 #include <nmod_poly.h>
    43 #include <fmpq_poly.h>
     38#include <flint/fmpz.h>
     39#include <flint/fmpq.h>
     40#include <flint/fmpz_poly.h>
     41#include <flint/fmpz_mod_poly.h>
     42#include <flint/nmod_poly.h>
     43#include <flint/fmpq_poly.h>
     44#include <flint/nmod_mat.h>
     45#include <flint/fmpz_mat.h>
    4446#ifdef __cplusplus
    4547}
     
    270272  long i;
    271273
    272   for (i = 0; i < fac->num_factors; i++)
    273     result.append (CFFactor (convertnmod_poly_t2FacCF ((nmod_poly_t &)fac->factors[i],x),
    274                              fac->exponents[i]));
     274  for (i = 0; i < fac->num; i++)
     275    result.append (CFFactor (convertnmod_poly_t2FacCF ((nmod_poly_t &)fac->p[i],x),
     276                             fac->exp[i]));
    275277  return result;
    276278}
     
    299301}
    300302
    301 #endif
    302 
    303 
     303void convertFacCFMatrix2Fmpz_mat_t (fmpz_mat_t M, CFMatrix &m)
     304{
     305  fmpz_mat_init (M, (long) m.rows(), (long) m.columns());
     306
     307  int i,j;
     308  for(i=m.rows();i>0;i--)
     309  {
     310    for(j=m.columns();j>0;j--)
     311    {
     312      convertCF2Fmpz (fmpz_mat_entry (M,i-1,j-1), m(i,j));
     313    }
     314  }
     315}
     316CFMatrix* convertFmpz_mat_t2FacCFMatrix(fmpz_mat_t m)
     317{
     318  CFMatrix *res=new CFMatrix(fmpz_mat_nrows (m),fmpz_mat_ncols (m));
     319  int i,j;
     320  for(i=res->rows();i>0;i--)
     321  {
     322    for(j=res->columns();j>0;j--)
     323    {
     324      (*res)(i,j)=convertFmpz2CF(fmpz_mat_entry (m,i-1,j-1));
     325    }
     326  }
     327  return res;
     328}
     329
     330void convertFacCFMatrix2nmod_mat_t (nmod_mat_t M, CFMatrix &m)
     331{
     332  nmod_mat_init (M, (long) m.rows(), (long) m.columns(), getCharacteristic());
     333
     334  bool save_sym_ff= isOn (SW_SYMMETRIC_FF);
     335  if (save_sym_ff) Off (SW_SYMMETRIC_FF);
     336  int i,j;
     337  for(i=m.rows();i>0;i--)
     338  {
     339    for(j=m.columns();j>0;j--)
     340    {
     341      if(!(m(i,j)).isImm()) printf("convertFacCFMatrix2FLINTmat_zz_p: not imm.\n");
     342      nmod_mat_entry (M,i-1,j-1)= (m(i,j)).intval();
     343    }
     344  }
     345  if (save_sym_ff) On (SW_SYMMETRIC_FF);
     346}
     347
     348CFMatrix* convertNmod_mat_t2FacCFMatrix(nmod_mat_t m)
     349{
     350  CFMatrix *res=new CFMatrix(nmod_mat_nrows (m), nmod_mat_ncols (m));
     351  int i,j;
     352  for(i=res->rows();i>0;i--)
     353  {
     354    for(j=res->columns();j>0;j--)
     355    {
     356      (*res)(i,j)=CanonicalForm((long) nmod_mat_entry (m, i-1, j-1));
     357    }
     358  }
     359  return res;
     360}
     361
     362#endif
     363
     364
  • factory/FLINTconvert.h

    r1130ffc r186df6  
    2727#define __GMP_BITS_PER_MP_LIMB GMP_LIMB_BITS
    2828#endif
    29 #include <fmpz.h>
    30 #include <fmpq.h>
    31 #include <fmpz_poly.h>
    32 #include <fmpz_mod_poly.h>
    33 #include <fmpq_poly.h>
    34 #include <nmod_poly.h>
     29#include <flint/fmpz.h>
     30#include <flint/fmpq.h>
     31#include <flint/fmpz_poly.h>
     32#include <flint/fmpz_mod_poly.h>
     33#include <flint/fmpq_poly.h>
     34#include <flint/nmod_poly.h>
     35#include <flint/nmod_mat.h>
     36#include <flint/fmpz_mat.h>
    3537#ifdef __cplusplus
    3638}
     
    132134                             );
    133135
     136/// conversion of a factory matrix over Z to a fmpz_mat_t
     137void convertFacCFMatrix2Fmpz_mat_t (fmpz_mat_t M, ///<[in,out] fmpz_mat_t
     138                                    CFMatrix &m   ///<[in] matrix over Z
     139                                   );
     140
     141/// conversion of a FLINT matrix over Z to a factory matrix
     142CFMatrix* convertFmpz_mat_t2FacCFMatrix(fmpz_mat_t m ///<[in] fmpz_mat_t
     143                                       );
     144
     145/// conversion of a factory matrix over Z/p to a nmod_mat_t
     146void convertFacCFMatrix2nmod_mat_t (nmod_mat_t M, ///<[in,out] nmod_mat_t
     147                                    CFMatrix &m   ///<[in] matrix over Z/p
     148                                   );
     149
     150/// conversion of a FLINT matrix over Z/p to a factory matrix
     151CFMatrix* convertNmod_mat_t2FacCFMatrix(nmod_mat_t m ///<[in] nmod_mat_t
     152                                       );
     153
    134154#endif
    135155#endif
  • factory/algext.cc

    r1130ffc r186df6  
    2929#ifdef HAVE_NTL
    3030#include "NTLconvert.h"
     31#endif
     32
     33#ifdef HAVE_FLINT
     34#include "FLINTconvert.h"
    3135#endif
    3236
     
    637641    {
    638642      if (c.isZero()) return abs (f);
     643#ifdef HAVE_FLINT
     644      fmpz_poly_t FLINTf, FLINTc;
     645      convertFacCF2Fmpz_poly_t (FLINTf, f);
     646      convertFacCF2Fmpz_poly_t (FLINTc, c);
     647      fmpz_poly_gcd (FLINTc, FLINTc, FLINTf);
     648      CanonicalForm result;
     649      if (f.inCoeffDomain())
     650        result= convertFmpz_poly_t2FacCF (FLINTc, f.mvar());
     651      else
     652        result= convertFmpz_poly_t2FacCF (FLINTc, c.mvar());
     653      fmpz_poly_clear (FLINTc);
     654      fmpz_poly_clear (FLINTf);
     655      return result;
     656#else
    639657      ZZX NTLf= convertFacCF2NTLZZX (f);
    640658      ZZX NTLc= convertFacCF2NTLZZX (c);
     
    644662      else
    645663        return convertNTLZZX2CF(NTLc,c.mvar());
     664#endif
    646665    }
    647666    else
  • factory/cfModResultant.cc

    r1130ffc r186df6  
    2626#endif
    2727
     28#ifdef HAVE_FLINT
     29#include "FLINTconvert.h"
     30#endif
     31
    2832//TODO arrange by bound= deg (F,xlevel)*deg (G,i)+deg (G,xlevel)*deg (F, i)
    2933static inline
     
    242246    return 0;
    243247
     248#ifdef HAVE_FLINT
     249  nmod_poly_t FLINTF, FLINTG;
     250  convertFacCF2nmod_poly_t (FLINTF, F);
     251  convertFacCF2nmod_poly_t (FLINTG, G);
     252  mp_limb_t FLINTresult= nmod_poly_resultant (FLINTF, FLINTG);
     253  nmod_poly_clear (FLINTF);
     254  nmod_poly_clear (FLINTG);
     255  return CanonicalForm ((long) FLINTresult);
     256#else
    244257  zz_pBak bak;
    245258  bak.save();
     
    252265  bak.restore();
    253266  return CanonicalForm (to_long (rep (NTLResult)));
     267#endif
    254268#else
    255269  return resultant (F, G, F.mvar());
  • factory/cf_gcd.cc

    r1130ffc r186df6  
    2626#include "NTLconvert.h"
    2727bool isPurePoly(const CanonicalForm & );
     28#ifndef HAVE_FLINT
    2829static CanonicalForm gcd_univar_ntl0( const CanonicalForm &, const CanonicalForm & );
    2930static CanonicalForm gcd_univar_ntlp( const CanonicalForm &, const CanonicalForm & );
     31#endif
    3032#endif
    3133
     
    307309  }
    308310#ifdef HAVE_NTL
     311#ifdef HAVE_FLINT
     312  if (( getCharacteristic() > 0 ) && (CFFactory::gettype() != GaloisFieldDomain)
     313  &&  (f.level()==g.level()) && isPurePoly(f) && isPurePoly(g))
     314  {
     315    nmod_poly_t F1, G1, A, B, R;
     316    convertFacCF2nmod_poly_t (F1, f);
     317    convertFacCF2nmod_poly_t (G1, g);
     318    nmod_poly_init (R, getCharacteristic());
     319    nmod_poly_init (A, getCharacteristic());
     320    nmod_poly_init (B, getCharacteristic());
     321    nmod_poly_xgcd (R, A, B, F1, G1);
     322    a= convertnmod_poly_t2FacCF (A, f.mvar());
     323    b= convertnmod_poly_t2FacCF (B, f.mvar());
     324    CanonicalForm r= convertnmod_poly_t2FacCF (R, f.mvar());
     325    nmod_poly_clear (F1);
     326    nmod_poly_clear (G1);
     327    nmod_poly_clear (A);
     328    nmod_poly_clear (B);
     329    nmod_poly_clear (R);
     330    return r;
     331  }
     332#else
    309333  if (isOn(SW_USE_NTL_GCD_P) && ( getCharacteristic() > 0 ) && (CFFactory::gettype() != GaloisFieldDomain)
    310334  &&  (f.level()==g.level()) && isPurePoly(f) && isPurePoly(g))
     
    347371    #endif
    348372  }
     373#endif
     374#ifdef HAVE_FLINT
     375  if (( getCharacteristic() ==0) && (f.level()==g.level())
     376       && isPurePoly(f) && isPurePoly(g))
     377  {
     378    fmpq_poly_t F1, G1;
     379    convertFacCF2Fmpq_poly_t (F1, f);
     380    convertFacCF2Fmpq_poly_t (G1, g);
     381    fmpq_poly_t R, A, B;
     382    fmpq_poly_init (R);
     383    fmpq_poly_init (A);
     384    fmpq_poly_init (B);
     385    fmpq_poly_xgcd (R, A, B, F1, G1);
     386    a= convertFmpq_poly_t2FacCF (A, f.mvar());
     387    b= convertFmpq_poly_t2FacCF (B, f.mvar());
     388    CanonicalForm r= convertFmpq_poly_t2FacCF (R, f.mvar());
     389    fmpq_poly_clear (F1);
     390    fmpq_poly_clear (G1);
     391    fmpq_poly_clear (A);
     392    fmpq_poly_clear (B);
     393    fmpq_poly_clear (R);
     394    return r;
     395  }
     396#else
    349397  if (isOn(SW_USE_NTL_GCD_0) && ( getCharacteristic() ==0)
    350398  && (f.level()==g.level()) && isPurePoly(f) && isPurePoly(g))
     
    378426      CanonicalForm rr=convertZZ2CF(RR);
    379427      ASSERT (!rr.isZero(), "NTL:XGCD failed");
    380       r*=rr;
    381       if ( r.sign() < 0 ) { r= -r; a= -a; b= -b; }
     428      a /= rr;
     429      b /= rr;
    382430      return r;
    383431    }
    384432  }
     433#endif
    385434#endif
    386435  // may contain bug in the co-factors, see track 107
     
    669718    if ( pi.isUnivariate() && pi1.isUnivariate() )
    670719    {
    671 /*#ifdef HAVE_FLINT
     720#ifdef HAVE_FLINT
    672721        if (isPurePoly(pi) && isPurePoly(pi1) )
    673722            return gcd_univar_flint0(pi, pi1 ) * C;
    674 #else*/
     723#else
    675724#ifdef HAVE_NTL
    676725        if ( isOn(SW_USE_NTL_GCD_0) && isPurePoly(pi) && isPurePoly(pi1) )
    677726            return gcd_univar_ntl0(pi, pi1 ) * C;
    678727#endif
    679 //#endif
     728#endif
    680729        return gcd_poly_univar0( pi, pi1, true ) * C;
    681730    }
     
    9931042
    9941043#ifdef HAVE_NTL
    995 
     1044#ifndef HAVE_FLINT
    9961045static CanonicalForm
    9971046gcd_univar_ntl0( const CanonicalForm & F, const CanonicalForm & G )
     
    10351084  #endif
    10361085}
    1037 
     1086#endif
    10381087#endif
    10391088
  • factory/cf_gcd_smallp.cc

    r1130ffc r186df6  
    3939#ifdef HAVE_NTL
    4040#include <NTLconvert.h>
     41#endif
     42
     43#ifdef HAVE_FLINT
     44#include "FLINTconvert.h"
    4145#endif
    4246
     
    19811985  for (int i= 0; i < L.size(); i++, j++)
    19821986    (*N) (j, M.columns() + 1)= L[i];
     1987#ifdef HAVE_FLINT
     1988  nmod_mat_t FLINTN;
     1989  convertFacCFMatrix2nmod_mat_t (FLINTN, *N);
     1990  long* dummy= new long [M.rows()];
     1991  for (int i= 0; i < M.rows(); i++)
     1992    dummy[i]= 0;
     1993  long rk= nmod_mat_rref (dummy, FLINTN);
     1994
     1995  N= convertNmod_mat_t2FacCFMatrix (FLINTN);
     1996  nmod_mat_clear (FLINTN);
     1997  delete dummy;
     1998#else
    19831999  int p= getCharacteristic ();
    19842000  zz_p::init (p);
     
    19872003
    19882004  N= convertNTLmat_zz_p2FacCFMatrix (*NTLN);
     2005#endif
    19892006
    19902007  L= CFArray (M.rows());
     
    20422059  for (int i= 0; i < L.size(); i++, j++)
    20432060    (*N) (j, M.columns() + 1)= L[i];
     2061
     2062#ifdef HAVE_FLINT
     2063  nmod_mat_t FLINTN;
     2064  convertFacCFMatrix2nmod_mat_t (FLINTN, *N);
     2065  long* dummy= new long [M.rows()];
     2066  for (int i= 0; i < M.rows(); i++)
     2067    dummy[i]= 0;
     2068  long rk= nmod_mat_rref (dummy, FLINTN);
     2069#else
    20442070  int p= getCharacteristic ();
    20452071  zz_p::init (p);
    20462072  mat_zz_p *NTLN= convertFacCFMatrix2NTLmat_zz_p(*N);
    20472073  long rk= gauss (*NTLN);
     2074#endif
    20482075  if (rk != M.columns())
    20492076  {
     2077#ifdef HAVE_FLINT
     2078    nmod_mat_clear (FLINTN);
     2079    delete dummy;
     2080#endif
    20502081    delete N;
    20512082    return CFArray();
    20522083  }
     2084#ifdef HAVE_FLINT
     2085  N= convertNmod_mat_t2FacCFMatrix (FLINTN);
     2086  nmod_mat_clear (FLINTN);
     2087  delete dummy;
     2088#else
    20532089  N= convertNTLmat_zz_p2FacCFMatrix (*NTLN);
    2054 
     2090#endif
    20552091  CFArray A= readOffSolution (*N, rk);
    20562092
  • factory/facFqBivar.cc

    r1130ffc r186df6  
    12801280}
    12811281
     1282#ifdef HAVE_FLINT
     1283long isReduced (const nmod_mat_t M)
     1284{
     1285  long i, j, nonZero;
     1286  for (i = 1; i <= nmod_mat_nrows(M); i++)
     1287  {
     1288    nonZero= 0;
     1289    for (j = 1; j <= nmod_mat_ncols (M); j++)
     1290    {
     1291      if (!(nmod_mat_entry (M, i-1, j-1)==0))
     1292        nonZero++;
     1293    }
     1294    if (nonZero != 1)
     1295      return 0;
     1296  }
     1297  return 1;
     1298}
     1299#endif
     1300
    12821301long isReduced (const mat_zz_pE& M)
    12831302{
     
    13201339  return result;
    13211340}
     1341
     1342#ifdef HAVE_FLINT
     1343int * extractZeroOneVecs (const nmod_mat_t M)
     1344{
     1345  long i, j;
     1346  bool nonZeroOne= false;
     1347  int * result= new int [nmod_mat_ncols (M)];
     1348  for (i = 0; i < nmod_mat_ncols (M); i++)
     1349  {
     1350    for (j = 0; j < nmod_mat_nrows (M); j++)
     1351    {
     1352      if (!((nmod_mat_entry (M, j, i) == 1) || (nmod_mat_entry (M, j,i) == 0)))
     1353      {
     1354        nonZeroOne= true;
     1355        break;
     1356      }
     1357    }
     1358    if (!nonZeroOne)
     1359      result [i]= 1;
     1360    else
     1361      result [i]= 0;
     1362    nonZeroOne= false;
     1363  }
     1364  return result;
     1365}
     1366#endif
    13221367
    13231368int * extractZeroOneVecs (const mat_zz_pE& M)
     
    14981543  }
    14991544}
     1545
     1546#ifdef HAVE_FLINT
     1547void
     1548reconstructionTry (CFList& reconstructedFactors, CanonicalForm& F, const CFList&
     1549                   factors, const int liftBound, int& factorsFound, int*&
     1550                   factorsFoundIndex, nmod_mat_t N, bool beenInThres
     1551                  )
     1552{
     1553  Variable y= Variable (2);
     1554  Variable x= Variable (1);
     1555  CanonicalForm yToL= power (y, liftBound);
     1556  if (factors.length() == 2)
     1557  {
     1558    CanonicalForm tmp1, tmp2, tmp3;
     1559    tmp1= factors.getFirst();
     1560    tmp2= factors.getLast();
     1561    tmp1 *= LC (F, x);
     1562    tmp1= mod (tmp1, yToL);
     1563    tmp1 /= content (tmp1, x);
     1564    tmp2 *= LC (F, x);
     1565    tmp2= mod (tmp2, yToL);
     1566    tmp2 /= content (tmp2, x);
     1567    tmp3 = tmp1*tmp2;
     1568    if (tmp3/Lc (tmp3) == F/Lc (F))
     1569    {
     1570      factorsFound++;
     1571      F= 1;
     1572      reconstructedFactors.append (tmp1);
     1573      reconstructedFactors.append (tmp2);
     1574      return;
     1575    }
     1576  }
     1577  CanonicalForm quot, buf;
     1578  CFListIterator iter;
     1579  for (long i= 0; i < nmod_mat_ncols (N); i++)
     1580  {
     1581    if (factorsFoundIndex [i] == 1)
     1582      continue;
     1583    iter= factors;
     1584    if (beenInThres)
     1585    {
     1586      int count= 0;
     1587      while (count < i)
     1588      {
     1589        count++;
     1590        iter++;
     1591      }
     1592      buf= iter.getItem();
     1593    }
     1594    else
     1595    {
     1596      buf= 1;
     1597      for (long j= 0; j < nmod_mat_nrows (N); j++, iter++)
     1598      {
     1599        if (!(nmod_mat_entry (N, j, i) == 0))
     1600          buf= mulMod2 (buf, iter.getItem(), yToL);
     1601      }
     1602    }
     1603    buf *= LC (F, x);
     1604    buf= mod (buf, yToL);
     1605    buf /= content (buf, x);
     1606    if (fdivides (buf, F, quot))
     1607    {
     1608      factorsFoundIndex[i]= 1;
     1609      factorsFound++;
     1610      F= quot;
     1611      F /= Lc (F);
     1612      reconstructedFactors.append (buf);
     1613    }
     1614    if (degree (F) <= 0)
     1615      return;
     1616    if (factorsFound + 1 == nmod_mat_ncols (N))
     1617    {
     1618      reconstructedFactors.append (F);
     1619      return;
     1620    }
     1621  }
     1622}
     1623#endif
    15001624
    15011625CFList
     
    16801804}
    16811805
     1806#ifdef HAVE_FLINT
     1807CFList
     1808extReconstruction (CanonicalForm& G, CFList& factors, int* zeroOneVecs, int
     1809                   precision, const nmod_mat_t N, const ExtensionInfo& info,
     1810                   const CanonicalForm& evaluation
     1811                  )
     1812{
     1813  Variable y= Variable (2);
     1814  Variable x= Variable (1);
     1815  Variable alpha= info.getAlpha();
     1816  Variable beta= info.getBeta();
     1817  int k= info.getGFDegree();
     1818  CanonicalForm gamma= info.getGamma();
     1819  CanonicalForm delta= info.getDelta();
     1820  CanonicalForm F= G;
     1821  CanonicalForm yToL= power (y, precision);
     1822  CFList result;
     1823  CFList bufFactors= factors;
     1824  CFList factorsConsidered;
     1825  CanonicalForm buf2, quot, buf;
     1826  CFListIterator iter;
     1827  for (long i= 0; i < nmod_mat_ncols(N); i++)
     1828  {
     1829    if (zeroOneVecs [i] == 0)
     1830      continue;
     1831    iter= factors;
     1832    buf= 1;
     1833    factorsConsidered= CFList();
     1834    for (long j= 0; j < nmod_mat_ncols(N); j++, iter++)
     1835    {
     1836      if (!(nmod_mat_entry (N, j, i) == 0))
     1837      {
     1838        factorsConsidered.append (iter.getItem());
     1839        buf= mulMod2 (buf, iter.getItem(), yToL);
     1840      }
     1841    }
     1842    buf *= LC (F, x);
     1843    buf= mod (buf, yToL);
     1844    buf /= content (buf, x);
     1845    buf2= buf (y-evaluation, y);
     1846    if (!k && beta == x)
     1847    {
     1848      if (degree (buf2, alpha) < 1)
     1849      {
     1850        if (fdivides (buf, F, quot))
     1851        {
     1852          F= quot;
     1853          F /= Lc (F);
     1854          result.append (buf2);
     1855          bufFactors= Difference (bufFactors, factorsConsidered);
     1856        }
     1857      }
     1858    }
     1859    else
     1860    {
     1861      CFList source, dest;
     1862
     1863      if (!isInExtension (buf2, gamma, k, delta, source, dest))
     1864      {
     1865        if (fdivides (buf, F, quot))
     1866        {
     1867          F= quot;
     1868          F /= Lc (F);
     1869          result.append (buf2);
     1870          bufFactors= Difference (bufFactors, factorsConsidered);
     1871        }
     1872      }
     1873    }
     1874    if (degree (F) <= 0)
     1875    {
     1876      G= F;
     1877      factors= bufFactors;
     1878      return result;
     1879    }
     1880  }
     1881  G= F;
     1882  factors= bufFactors;
     1883  return result;
     1884}
     1885#endif
     1886
    16821887CFList
    16831888reconstruction (CanonicalForm& G, CFList& factors, int* zeroOneVecs,
     
    17291934  return result;
    17301935}
     1936
     1937#ifdef HAVE_FLINT
     1938CFList
     1939reconstruction (CanonicalForm& G, CFList& factors, int* zeroOneVecs,
     1940                int precision, const nmod_mat_t N)
     1941{
     1942  Variable y= Variable (2);
     1943  Variable x= Variable (1);
     1944  CanonicalForm F= G;
     1945  CanonicalForm yToL= power (y, precision);
     1946  CanonicalForm quot, buf;
     1947  CFList result;
     1948  CFList bufFactors= factors;
     1949  CFList factorsConsidered;
     1950  CFListIterator iter;
     1951  for (long i= 0; i < nmod_mat_ncols (N); i++)
     1952  {
     1953    if (zeroOneVecs [i] == 0)
     1954      continue;
     1955    iter= factors;
     1956    buf= 1;
     1957    factorsConsidered= CFList();
     1958    for (long j= 0; j < nmod_mat_nrows (N); j++, iter++)
     1959    {
     1960      if (!(nmod_mat_entry (N, j, i) == 0))
     1961      {
     1962        factorsConsidered.append (iter.getItem());
     1963        buf= mulMod2 (buf, iter.getItem(), yToL);
     1964      }
     1965    }
     1966    buf *= LC (F, x);
     1967    buf= mod (buf, yToL);
     1968    buf /= content (buf, x);
     1969    if (fdivides (buf, F, quot))
     1970    {
     1971      F= quot;
     1972      F /= Lc (F);
     1973      result.append (buf);
     1974      bufFactors= Difference (bufFactors, factorsConsidered);
     1975    }
     1976    if (degree (F) <= 0)
     1977    {
     1978      G= F;
     1979      factors= bufFactors;
     1980      return result;
     1981    }
     1982  }
     1983  G= F;
     1984  factors= bufFactors;
     1985  return result;
     1986}
     1987#endif
    17311988
    17321989void
     
    18572114  }
    18582115}
     2116
     2117#ifdef HAVE_FLINT
     2118void
     2119extReconstructionTry (CFList& reconstructedFactors, CanonicalForm& F, const
     2120                      CFList& factors, const int liftBound, int& factorsFound,
     2121                      int*& factorsFoundIndex, nmod_mat_t N, bool beenInThres,
     2122                      const ExtensionInfo& info, const CanonicalForm& evaluation
     2123                     )
     2124{
     2125  Variable y= Variable (2);
     2126  Variable x= Variable (1);
     2127  Variable alpha= info.getAlpha();
     2128  Variable beta= info.getBeta();
     2129  int k= info.getGFDegree();
     2130  CanonicalForm gamma= info.getGamma();
     2131  CanonicalForm delta= info.getDelta();
     2132  CanonicalForm yToL= power (y, liftBound);
     2133  CFList source, dest;
     2134  if (factors.length() == 2)
     2135  {
     2136    CanonicalForm tmp1, tmp2, tmp3;
     2137    tmp1= factors.getFirst();
     2138    tmp2= factors.getLast();
     2139    tmp1 *= LC (F, x);
     2140    tmp1= mod (tmp1, yToL);
     2141    tmp1 /= content (tmp1, x);
     2142    tmp2 *= LC (F, x);
     2143    tmp2= mod (tmp2, yToL);
     2144    tmp2 /= content (tmp2, x);
     2145    tmp3 = tmp1*tmp2;
     2146    if (tmp3/Lc (tmp3) == F/Lc (F))
     2147    {
     2148      tmp1= tmp1 (y - evaluation, y);
     2149      tmp2= tmp2 (y - evaluation, y);
     2150      if (!k && beta == x && degree (tmp2, alpha) < 1 &&
     2151          degree (tmp1, alpha) < 1)
     2152      {
     2153        factorsFound++;
     2154        F= 1;
     2155        tmp1= mapDown (tmp1, info, source, dest);
     2156        tmp2= mapDown (tmp2, info, source, dest);
     2157        reconstructedFactors.append (tmp1);
     2158        reconstructedFactors.append (tmp2);
     2159        return;
     2160      }
     2161      else if (!isInExtension (tmp2, gamma, k, delta, source, dest) &&
     2162               !isInExtension (tmp1, gamma, k, delta, source, dest))
     2163      {
     2164        factorsFound++;
     2165        F= 1;
     2166        tmp1= mapDown (tmp1, info, source, dest);
     2167        tmp2= mapDown (tmp2, info, source, dest);
     2168        reconstructedFactors.append (tmp1);
     2169        reconstructedFactors.append (tmp2);
     2170        return;
     2171      }
     2172    }
     2173  }
     2174  CanonicalForm quot, buf, buf2;
     2175  CFListIterator iter;
     2176  for (long i= 0; i < nmod_mat_ncols (N); i++)
     2177  {
     2178    if (factorsFoundIndex [i] == 1)
     2179      continue;
     2180    iter= factors;
     2181    if (beenInThres)
     2182    {
     2183      int count= 0;
     2184      while (count < i)
     2185      {
     2186        count++;
     2187        iter++;
     2188      }
     2189      buf= iter.getItem();
     2190    }
     2191    else
     2192    {
     2193      buf= 1;
     2194      for (long j= 0; j < nmod_mat_nrows (N); j++, iter++)
     2195      {
     2196        if (!(nmod_mat_entry (N, j, i) == 0))
     2197          buf= mulMod2 (buf, iter.getItem(), yToL);
     2198      }
     2199    }
     2200    buf *= LC (F, x);
     2201    buf= mod (buf, yToL);
     2202    buf /= content (buf, x);
     2203    buf2= buf (y - evaluation, y);
     2204    if (!k && beta == x)
     2205    {
     2206      if (degree (buf2, alpha) < 1)
     2207      {
     2208        if (fdivides (buf, F, quot))
     2209        {
     2210          factorsFoundIndex[i]= 1;
     2211          factorsFound++;
     2212          F= quot;
     2213          F /= Lc (F);
     2214          buf2= mapDown (buf2, info, source, dest);
     2215          reconstructedFactors.append (buf2);
     2216        }
     2217      }
     2218    }
     2219    else
     2220    {
     2221      if (!isInExtension (buf2, gamma, k, delta, source, dest))
     2222      {
     2223        if (fdivides (buf, F, quot))
     2224        {
     2225          factorsFoundIndex[i]= 1;
     2226          factorsFound++;
     2227          F= quot;
     2228          F /= Lc (F);
     2229          buf2= mapDown (buf2, info, source, dest);
     2230          reconstructedFactors.append (buf2);
     2231        }
     2232      }
     2233    }
     2234    if (degree (F) <= 0)
     2235      return;
     2236    if (factorsFound + 1 == nmod_mat_nrows (N))
     2237    {
     2238      CanonicalForm tmp= F (y - evaluation, y);
     2239      tmp= mapDown (tmp, info, source, dest);
     2240      reconstructedFactors.append (tmp);
     2241      return;
     2242    }
     2243  }
     2244}
     2245#endif
    18592246
    18602247//over Fp
     
    19652352  return l;
    19662353}
     2354
     2355#ifdef HAVE_FLINT
     2356int
     2357liftAndComputeLattice (const CanonicalForm& F, int* bounds, int sizeBounds, int
     2358                       start, int liftBound, int minBound, CFList& factors,
     2359                       nmod_mat_t FLINTN, CFList& diophant, CFMatrix& M,CFArray&
     2360                       Pi, CFArray& bufQ, bool& irreducible
     2361                      )
     2362{
     2363  CanonicalForm LCF= LC (F, 1);
     2364  CFArray *A= new CFArray [factors.length() - 1];
     2365  bool wasInBounds= false;
     2366  bool hitBound= false;
     2367  int l= (minBound+1)*2;
     2368  int stepSize= 2;
     2369  int oldL= l/2;
     2370  bool reduced= false;
     2371  long rank;
     2372  nmod_mat_t FLINTK, FLINTC, null;
     2373  CFMatrix C;
     2374  CFArray buf;
     2375  CFListIterator j;
     2376  CanonicalForm truncF;
     2377  Variable y= F.mvar();
     2378  while (l <= liftBound)
     2379  {
     2380    if (start)
     2381    {
     2382      henselLiftResume12 (F, factors, start, l, Pi, diophant, M);
     2383      start= 0;
     2384    }
     2385    else
     2386    {
     2387      if (wasInBounds)
     2388        henselLiftResume12 (F, factors, oldL, l, Pi, diophant, M);
     2389      else
     2390        henselLift12 (F, factors, l, Pi, diophant, M);
     2391    }
     2392
     2393    factors.insert (LCF);
     2394    j= factors;
     2395    j++;
     2396
     2397    truncF= mod (F, power (y, l));
     2398    for (int i= 0; i < factors.length() - 1; i++, j++)
     2399    {
     2400      if (!wasInBounds)
     2401        A[i]= logarithmicDerivative (truncF, j.getItem(), l, bufQ[i]);
     2402      else
     2403        A[i]= logarithmicDerivative (truncF, j.getItem(), l, oldL, bufQ[i],
     2404                                     bufQ[i]);
     2405    }
     2406
     2407    for (int i= 0; i < sizeBounds; i++)
     2408    {
     2409      if (bounds [i] + 1 <= l/2)
     2410      {
     2411        wasInBounds= true;
     2412        int k= tmin (bounds [i] + 1, l/2);
     2413        C= CFMatrix (l - k, factors.length() - 1);
     2414        for (int ii= 0; ii < factors.length() - 1; ii++)
     2415        {
     2416          if (A[ii].size() - 1 >= i)
     2417          {
     2418            buf= getCoeffs (A[ii] [i], k);
     2419            writeInMatrix (C, buf, ii + 1, 0);
     2420          }
     2421        }
     2422
     2423        convertFacCFMatrix2nmod_mat_t (FLINTC, C);
     2424        nmod_mat_init (FLINTK, nmod_mat_nrows (FLINTC), nmod_mat_ncols (FLINTN),
     2425                       getCharacteristic());
     2426        nmod_mat_mul (FLINTK, FLINTC, FLINTN);
     2427        nmod_mat_init (null, nmod_mat_ncols (FLINTK), nmod_mat_ncols (FLINTK),
     2428                       getCharacteristic());
     2429        rank= nmod_mat_nullspace (null, FLINTK);
     2430        nmod_mat_clear (FLINTK);
     2431        nmod_mat_window_init (FLINTK, null, 0, 0, nmod_mat_nrows(null), rank);
     2432        nmod_mat_clear (FLINTC);
     2433        nmod_mat_init_set (FLINTC, FLINTN);
     2434        nmod_mat_clear (FLINTN);
     2435        nmod_mat_init (FLINTN, nmod_mat_nrows (FLINTC), nmod_mat_ncols (FLINTK),
     2436                       getCharacteristic());
     2437        nmod_mat_mul (FLINTN, FLINTC, FLINTK); //no aliasing allowed!!
     2438
     2439        nmod_mat_clear (FLINTC);
     2440        nmod_mat_window_clear (FLINTK);
     2441        nmod_mat_clear (null);
     2442        if (nmod_mat_ncols (FLINTN) == 1)
     2443        {
     2444          irreducible= true;
     2445          break;
     2446        }
     2447        if (isReduced (FLINTN) && l > (minBound+1)*2)
     2448        {
     2449          reduced= true;
     2450          break;
     2451        }
     2452      }
     2453    }
     2454
     2455    if (irreducible)
     2456      break;
     2457    if (reduced)
     2458      break;
     2459    oldL= l;
     2460    l += stepSize;
     2461    stepSize *= 2;
     2462    if (l > liftBound)
     2463    {
     2464      if (!hitBound)
     2465      {
     2466        l= liftBound;
     2467        hitBound= true;
     2468      }
     2469      else
     2470        break;
     2471    }
     2472  }
     2473  delete [] A;
     2474  return l;
     2475}
     2476#endif
    19672477
    19682478//over field extension
     
    21452655}
    21462656
     2657/*#ifdef HAVE_FLINT
     2658//over field extension
     2659int
     2660extLiftAndComputeLattice (const CanonicalForm& F, int* bounds, int sizeBounds,
     2661                          int liftBound, int minBound, int start, CFList&
     2662                          factors, nmod_mat_t FLINTN, CFList& diophant,
     2663                          CFMatrix& M, CFArray& Pi, CFArray& bufQ, bool&
     2664                          irreducible, const CanonicalForm& evaluation, const
     2665                          ExtensionInfo& info, CFList& source, CFList& dest
     2666                         )
     2667{
     2668  bool GF= (CFFactory::gettype()==GaloisFieldDomain);
     2669  CanonicalForm LCF= LC (F, 1);
     2670  CFArray *A= new CFArray [factors.length() - 1];
     2671  bool wasInBounds= false;
     2672  bool hitBound= false;
     2673  int degMipo;
     2674  Variable alpha;
     2675  alpha= info.getAlpha();
     2676  degMipo= degree (getMipo (alpha));
     2677
     2678  Variable gamma= info.getBeta();
     2679  CanonicalForm primElemAlpha= info.getGamma();
     2680  CanonicalForm imPrimElemAlpha= info.getDelta();
     2681
     2682  int stepSize= 2;
     2683  int l= ((minBound+1)/degMipo+1)*2;
     2684  l= tmax (l, 2);
     2685  if (start > l)
     2686    l= start;
     2687  int oldL= l/2;
     2688  bool reduced= false;
     2689  Variable y= F.mvar();
     2690  Variable x= Variable (1);
     2691  CanonicalForm powX, imBasis, truncF;
     2692  CFMatrix Mat, C;
     2693  CFArray buf;
     2694  CFIterator iter;
     2695  long rank;
     2696  nmod_mat_t FLINTMat, FLINTMatInv, FLINTC, FLINTK, null;
     2697  CFListIterator j;
     2698  while (l <= liftBound)
     2699  {
     2700    if (start)
     2701    {
     2702      henselLiftResume12 (F, factors, start, l, Pi, diophant, M);
     2703      start= 0;
     2704    }
     2705    else
     2706    {
     2707      if (wasInBounds)
     2708        henselLiftResume12 (F, factors, oldL, l, Pi, diophant, M);
     2709      else
     2710        henselLift12 (F, factors, l, Pi, diophant, M);
     2711    }
     2712
     2713    factors.insert (LCF);
     2714
     2715    if (GF)
     2716      setCharacteristic (getCharacteristic());
     2717
     2718    powX= power (y-gamma, l);
     2719    Mat= CFMatrix (l*degMipo, l*degMipo);
     2720    for (int i= 0; i < l*degMipo; i++)
     2721    {
     2722      imBasis= mod (power (y, i), powX);
     2723      imBasis= imBasis (power (y, degMipo), y);
     2724      imBasis= imBasis (y, gamma);
     2725      iter= imBasis;
     2726      for (; iter.hasTerms(); iter++)
     2727        Mat (iter.exp()+ 1, i+1)= iter.coeff();
     2728    }
     2729
     2730    convertFacCFMatrix2nmod_mat_t (FLINTMat, Mat);
     2731    nmod_mat_init (FLINTMatInv, nmod_mat_nrows (FLINTMat),
     2732                   nmod_mat_nrows (FLINTMat), getCharacteristic());
     2733    nmod_mat_inv (FLINTMatInv, FLINTMat);
     2734
     2735    if (GF)
     2736      setCharacteristic (getCharacteristic(), degMipo, info.getGFName());
     2737
     2738    j= factors;
     2739    j++;
     2740
     2741    truncF= mod (F, power (y, l));
     2742    for (int i= 0; i < factors.length() - 1; i++, j++)
     2743    {
     2744      if (!wasInBounds)
     2745        A[i]= logarithmicDerivative (truncF, j.getItem(), l, bufQ[i]);
     2746      else
     2747        A[i]= logarithmicDerivative (truncF, j.getItem(), l, oldL, bufQ[i],
     2748                                     bufQ[i]);
     2749    }
     2750
     2751    for (int i= 0; i < sizeBounds; i++)
     2752    {
     2753      if (bounds [i] + 1 <= (l/2)*degMipo)
     2754      {
     2755        wasInBounds= true;
     2756        int k= tmin (bounds [i] + 1, (l/2)*degMipo);
     2757        C= CFMatrix (l*degMipo - k, factors.length() - 1);
     2758
     2759        for (int ii= 0; ii < factors.length() - 1; ii++)
     2760        {
     2761          if (A[ii].size() - 1 >= i)
     2762          {
     2763            if (GF)
     2764            {
     2765              A [ii] [i]= A [ii] [i] (y-evaluation, y);
     2766              setCharacteristic (getCharacteristic());
     2767              A[ii] [i]= GF2FalphaRep (A[ii] [i], alpha);
     2768              if (alpha != gamma)
     2769                A [ii] [i]= mapDown (A[ii] [i], imPrimElemAlpha, primElemAlpha,
     2770                                     gamma, source, dest
     2771                                    );
     2772              buf= getCoeffs (A[ii] [i], k, l, degMipo, gamma, 0, FLINTMatInv); //TODO
     2773            }
     2774            else
     2775            {
     2776              A [ii] [i]= A [ii] [i] (y-evaluation, y);
     2777              if (alpha != gamma)
     2778                A[ii] [i]= mapDown (A[ii] [i], imPrimElemAlpha, primElemAlpha,
     2779                                    gamma, source, dest
     2780                                   );
     2781              buf= getCoeffs (A[ii] [i], k, l, degMipo, gamma, 0, FLINTMatInv); //TODO
     2782            }
     2783            writeInMatrix (C, buf, ii + 1, 0);
     2784          }
     2785          if (GF)
     2786            setCharacteristic (getCharacteristic(), degMipo, info.getGFName());
     2787        }
     2788
     2789        if (GF)
     2790          setCharacteristic(getCharacteristic());
     2791
     2792        convertFacCFMatrix2nmod_mat_t (FLINTC, C);
     2793        nmod_mat_init (FLINTK, nmod_mat_nrows (FLINTC), nmod_mat_ncols (FLINTN),
     2794                       getCharacteristic());
     2795        nmod_mat_mul (FLINTK, FLINTC, FLINTN);
     2796        nmod_mat_init (null, nmod_mat_ncols (FLINTK), nmod_mat_ncols (FLINTK),
     2797                       getCharacteristic());
     2798        rank= nmod_mat_nullspace (null, FLINTK);
     2799        nmod_mat_clear (FLINTK);
     2800        nmod_mat_window_init (FLINTK, null, 0, 0, nmod_mat_nrows(null), rank);
     2801        nmod_mat_clear (FLINTC);
     2802        nmod_mat_init_set (FLINTC, FLINTN);
     2803        nmod_mat_clear (FLINTN);
     2804        nmod_mat_init (FLINTN, nmod_mat_nrows (FLINTC), nmod_mat_ncols (FLINTK),
     2805                       getCharacteristic());
     2806        nmod_mat_mul (FLINTN, FLINTC, FLINTK); //no aliasing allowed!!
     2807
     2808        nmod_mat_clear (FLINTC);
     2809        nmod_mat_window_clear (FLINTK);
     2810        nmod_mat_clear (null);
     2811
     2812        if (GF)
     2813          setCharacteristic (getCharacteristic(), degMipo, info.getGFName());
     2814
     2815        if (nmod_mat_ncols (FLINTN) == 1)
     2816        {
     2817          irreducible= true;
     2818          break;
     2819        }
     2820        if (isReduced (FLINTN))
     2821        {
     2822          reduced= true;
     2823          break;
     2824        }
     2825      }
     2826    }
     2827
     2828    nmod_mat_clear (FLINTMat);
     2829    nmod_mat_clear (FLINTMatInv);
     2830
     2831    if (nmod_mat_ncols (FLINTN) == 1)
     2832    {
     2833      irreducible= true;
     2834      break;
     2835    }
     2836    if (reduced)
     2837      break;
     2838    oldL= l;
     2839    l += stepSize;
     2840    stepSize *= 2;
     2841    if (l > liftBound)
     2842    {
     2843      if (!hitBound)
     2844      {
     2845        l= liftBound;
     2846        hitBound= true;
     2847      }
     2848      else
     2849        break;
     2850    }
     2851  }
     2852  delete [] A;
     2853  return l;
     2854}
     2855#endif*/
     2856
    21472857// over Fq
    21482858int
     
    22632973}
    22642974
     2975#ifdef HAVE_FLINT
     2976int
     2977liftAndComputeLatticeFq2Fp (const CanonicalForm& F, int* bounds, int sizeBounds,
     2978                            int start, int liftBound, int minBound, CFList&
     2979                            factors, nmod_mat_t FLINTN, CFList& diophant,
     2980                            CFMatrix& M, CFArray& Pi, CFArray& bufQ, bool&
     2981                            irreducible, const Variable& alpha
     2982                           )
     2983#else
    22652984int
    22662985liftAndComputeLatticeFq2Fp (const CanonicalForm& F, int* bounds, int sizeBounds,
     
    22702989                            const Variable& alpha
    22712990                           )
     2991#endif
    22722992{
    22732993  CanonicalForm LCF= LC (F, 1);
     
    22833003  CFMatrix C;
    22843004  CFArray buf;
     3005#ifdef HAVE_FLINT
     3006  long rank;
     3007  nmod_mat_t FLINTC, FLINTK, null;
     3008#else
    22853009  mat_zz_p* NTLC, NTLK;
     3010#endif
    22863011  Variable y= F.mvar();
    22873012  CanonicalForm truncF;
     
    23363061        }
    23373062
     3063#ifdef HAVE_FLINT
     3064        convertFacCFMatrix2nmod_mat_t (FLINTC, C);
     3065        nmod_mat_init (FLINTK, nmod_mat_nrows (FLINTC), nmod_mat_ncols (FLINTN),
     3066                       getCharacteristic());
     3067        nmod_mat_mul (FLINTK, FLINTC, FLINTN);
     3068        nmod_mat_init (null, nmod_mat_ncols (FLINTK), nmod_mat_ncols (FLINTK),
     3069                       getCharacteristic());
     3070        rank= nmod_mat_nullspace (null, FLINTK);
     3071        nmod_mat_clear (FLINTK);
     3072        nmod_mat_window_init (FLINTK, null, 0, 0, nmod_mat_nrows(null), rank);
     3073        nmod_mat_clear (FLINTC);
     3074        nmod_mat_init_set (FLINTC, FLINTN);
     3075        nmod_mat_clear (FLINTN);
     3076        nmod_mat_init (FLINTN, nmod_mat_nrows (FLINTC), nmod_mat_ncols (FLINTK),
     3077                       getCharacteristic());
     3078        nmod_mat_mul (FLINTN, FLINTC, FLINTK); //no aliasing allowed!!
     3079
     3080        nmod_mat_clear (FLINTC);
     3081        nmod_mat_window_clear (FLINTK);
     3082        nmod_mat_clear (null);
     3083#else
    23383084        NTLC= convertFacCFMatrix2NTLmat_zz_p(C);
    23393085        NTLK= (*NTLC)*NTLN;
     
    23423088        transpose (NTLK, NTLK);
    23433089        NTLN *= NTLK;
    2344 
     3090#endif
     3091
     3092#ifdef HAVE_FLINT
     3093        if (nmod_mat_nrows (FLINTN) == 1)
     3094#else
    23453095        if (NTLN.NumCols() == 1)
     3096#endif
    23463097        {
    23473098          irreducible= true;
    23483099          break;
    23493100        }
     3101#ifdef HAVE_FLINT
     3102        if (isReduced (FLINTN) && l > (minBound+1)*2)
     3103#else
    23503104        if (isReduced (NTLN) && l > (minBound+1)*2)
     3105#endif
    23513106        {
    23523107          reduced= true;
     
    23563111    }
    23573112
     3113#ifdef HAVE_FLINT
     3114    if (nmod_mat_ncols (FLINTN) == 1)
     3115#else
    23583116    if (NTLN.NumCols() == 1)
     3117#endif
    23593118    {
    23603119      irreducible= true;
     
    23983157  CFArray * A= new CFArray [factors.length()];
    23993158  CFArray bufQ= CFArray (factors.length());
     3159#ifdef HAVE_FLINT
     3160  nmod_mat_t FLINTN;
     3161  nmod_mat_init (FLINTN,factors.length(),factors.length(), getCharacteristic());
     3162  for (long i=factors.length()-1; i >= 0; i--)
     3163    nmod_mat_entry (FLINTN, i, i)= 1;
     3164#else
    24003165  mat_zz_p NTLN;
    24013166  ident (NTLN, factors.length());
     3167#endif
    24023168  int minBound= bounds[0];
    24033169  for (int i= 1; i < d; i++)
     
    24143180  CFMatrix C;
    24153181  CFArray buf;
     3182#ifdef HAVE_FLINT
     3183  long rank;
     3184  nmod_mat_t FLINTC, FLINTK, null;
     3185#else
    24163186  mat_zz_p* NTLC, NTLK;
     3187#endif
    24173188  Variable y= F.mvar();
    24183189  CanonicalForm truncF;
     
    24483219          }
    24493220        }
     3221#ifdef HAVE_FLINT
     3222        convertFacCFMatrix2nmod_mat_t (FLINTC, C);
     3223        nmod_mat_init (FLINTK, nmod_mat_nrows (FLINTC), nmod_mat_ncols (FLINTN),
     3224                       getCharacteristic());
     3225        nmod_mat_mul (FLINTK, FLINTC, FLINTN);
     3226        nmod_mat_init (null, nmod_mat_ncols (FLINTK), nmod_mat_ncols (FLINTK),
     3227                       getCharacteristic());
     3228        rank= nmod_mat_nullspace (null, FLINTK);
     3229        nmod_mat_clear (FLINTK);
     3230        nmod_mat_window_init (FLINTK, null, 0, 0, nmod_mat_nrows(null), rank);
     3231        nmod_mat_clear (FLINTC);
     3232        nmod_mat_init_set (FLINTC, FLINTN);
     3233        nmod_mat_clear (FLINTN);
     3234        nmod_mat_init (FLINTN, nmod_mat_nrows (FLINTC), nmod_mat_ncols (FLINTK),
     3235                       getCharacteristic());
     3236        nmod_mat_mul (FLINTN, FLINTC, FLINTK); //no aliasing allowed!!
     3237
     3238        nmod_mat_clear (FLINTC);
     3239        nmod_mat_window_clear (FLINTK);
     3240        nmod_mat_clear (null);
     3241#else
    24503242        NTLC= convertFacCFMatrix2NTLmat_zz_p(C);
    24513243        NTLK= (*NTLC)*NTLN;
     
    24543246        transpose (NTLK, NTLK);
    24553247        NTLN *= NTLK;
     3248#endif
     3249#ifdef HAVE_FLINT
     3250        if (nmod_mat_ncols (FLINTN) == 1)
     3251        {
     3252          nmod_mat_clear (FLINTN);
     3253#else
    24563254        if (NTLN.NumCols() == 1)
    24573255        {
     3256#endif
    24583257          delete [] A;
    24593258          delete [] bounds;
     
    24653264    }
    24663265
     3266#ifdef HAVE_FLINT
     3267    if (nmod_mat_ncols (FLINTN) < oldNumCols - factorsFound)
     3268    {
     3269      if (isReduced (FLINTN))
     3270      {
     3271        int * factorsFoundIndex= new int [nmod_mat_ncols (FLINTN)];
     3272        for (long i= 0; i < nmod_mat_ncols (FLINTN); i++)
     3273#else
    24673274    if (NTLN.NumCols() < oldNumCols - factorsFound)
    24683275    {
     
    24713278        int * factorsFoundIndex= new int [NTLN.NumCols()];
    24723279        for (long i= 0; i < NTLN.NumCols(); i++)
     3280#endif
    24733281          factorsFoundIndex[i]= 0;
    24743282        int factorsFound2= 0;
    24753283        CFList result;
    24763284        CanonicalForm bufF= F;
     3285#ifdef HAVE_FLINT
     3286        reconstructionTry (result, bufF, factors, degree (F) + 1, factorsFound2,
     3287                           factorsFoundIndex, FLINTN, false
     3288                          );
     3289        if (result.length() == nmod_mat_ncols (FLINTN))
     3290        {
     3291          nmod_mat_clear (FLINTN);
     3292#else
    24773293        reconstructionTry (result, bufF, factors, degree (F) + 1, factorsFound2,
    24783294                           factorsFoundIndex, NTLN, false
     
    24803296        if (result.length() == NTLN.NumCols())
    24813297        {
     3298#endif
    24823299          delete [] factorsFoundIndex;
    24833300          delete [] A;
     
    24913308      {
    24923309        CanonicalForm bufF= F;
     3310#ifdef HAVE_FLINT
     3311        int * zeroOne= extractZeroOneVecs (FLINTN);
     3312        CFList result= reconstruction (bufF,factors,zeroOne,precision,FLINTN);
     3313        nmod_mat_clear (FLINTN);
     3314#else
    24933315        int * zeroOne= extractZeroOneVecs (NTLN);
    24943316        CFList result= reconstruction (bufF, factors, zeroOne, precision, NTLN);
     3317#endif
    24953318        F= bufF;
    24963319        delete [] zeroOne;
     
    25143337    }
    25153338  }
     3339#ifdef HAVE_FLINT
     3340  nmod_mat_clear (FLINTN);
     3341#endif
    25163342  delete [] bounds;
    25173343  delete [] A;
     
    30033829  CFArray * A= new CFArray [factors.length()];
    30043830  CFArray bufQ= CFArray (factors.length());
     3831#ifdef HAVE_FLINT
     3832  nmod_mat_t FLINTN;
     3833  nmod_mat_init (FLINTN,factors.length(),factors.length(), getCharacteristic());
     3834  for (long i=factors.length()-1; i >= 0; i--)
     3835    nmod_mat_entry (FLINTN, i, i)= 1;
     3836#else
    30053837  mat_zz_p NTLN;
    30063838  ident (NTLN, factors.length());
     3839#endif
    30073840  int minBound= bounds[0];
    30083841  for (int i= 1; i < d; i++)
     
    30183851  CFListIterator j;
    30193852  CFMatrix C;
     3853#ifdef HAVE_FLINT
     3854  long rank;
     3855  nmod_mat_t FLINTC, FLINTK, null;
     3856#else
    30203857  mat_zz_p* NTLC, NTLK;
     3858#endif
    30213859  CFArray buf;
    30223860  Variable y= F.mvar();
     
    30533891          }
    30543892        }
     3893#ifdef HAVE_FLINT
     3894        convertFacCFMatrix2nmod_mat_t (FLINTC, C);
     3895        nmod_mat_init (FLINTK, nmod_mat_nrows (FLINTC), nmod_mat_ncols (FLINTN),
     3896                       getCharacteristic());
     3897        nmod_mat_mul (FLINTK, FLINTC, FLINTN);
     3898        nmod_mat_init (null, nmod_mat_ncols (FLINTK), nmod_mat_ncols (FLINTK),
     3899                       getCharacteristic());
     3900        rank= nmod_mat_nullspace (null, FLINTK);
     3901        nmod_mat_clear (FLINTK);
     3902        nmod_mat_window_init (FLINTK, null, 0, 0, nmod_mat_nrows(null), rank);
     3903        nmod_mat_clear (FLINTC);
     3904        nmod_mat_init_set (FLINTC, FLINTN);
     3905        nmod_mat_clear (FLINTN);
     3906        nmod_mat_init (FLINTN, nmod_mat_nrows (FLINTC), nmod_mat_ncols (FLINTK),
     3907                       getCharacteristic());
     3908        nmod_mat_mul (FLINTN, FLINTC, FLINTK); //no aliasing allowed!!
     3909
     3910        nmod_mat_clear (FLINTC);
     3911        nmod_mat_window_clear (FLINTK);
     3912        nmod_mat_clear (null);
     3913#else
    30553914        NTLC= convertFacCFMatrix2NTLmat_zz_p(C);
    30563915        NTLK= (*NTLC)*NTLN;
     
    30593918        transpose (NTLK, NTLK);
    30603919        NTLN *= NTLK;
     3920#endif
     3921#ifdef HAVE_FLINT
     3922        if (nmod_mat_ncols (FLINTN) == 1)
     3923        {
     3924          nmod_mat_clear (FLINTN);
     3925#else
    30613926        if (NTLN.NumCols() == 1)
    30623927        {
     3928#endif
    30633929          delete [] A;
    30643930          delete [] bounds;
     
    30703936    }
    30713937
     3938#ifdef HAVE_FLINT
     3939    if (nmod_mat_ncols (FLINTN) < oldNumCols - factorsFound)
     3940    {
     3941      if (isReduced (FLINTN))
     3942      {
     3943        int * factorsFoundIndex= new int [nmod_mat_ncols (FLINTN)];
     3944        for (long i= 0; i < nmod_mat_ncols (FLINTN); i++)
     3945#else
    30723946    if (NTLN.NumCols() < oldNumCols - factorsFound)
    30733947    {
     
    30763950        int * factorsFoundIndex= new int [NTLN.NumCols()];
    30773951        for (long i= 0; i < NTLN.NumCols(); i++)
     3952#endif
    30783953          factorsFoundIndex[i]= 0;
    30793954        int factorsFound2= 0;
    30803955        CFList result;
    30813956        CanonicalForm bufF= F;
     3957#ifdef HAVE_FLINT
     3958        reconstructionTry (result, bufF, factors, degree (F) + 1, factorsFound2,
     3959                           factorsFoundIndex, FLINTN, false
     3960                          );
     3961        if (result.length() == nmod_mat_ncols (FLINTN))
     3962        {
     3963          nmod_mat_clear (FLINTN);
     3964#else
    30823965        reconstructionTry (result, bufF, factors, degree (F) + 1, factorsFound2,
    30833966                           factorsFoundIndex, NTLN, false
     
    30853968        if (result.length() == NTLN.NumCols())
    30863969        {
     3970#endif
    30873971          delete [] factorsFoundIndex;
    30883972          delete [] A;
     
    30963980      {
    30973981        CanonicalForm bufF= F;
     3982#ifdef HAVE_FLINT
     3983        int * zeroOne= extractZeroOneVecs (FLINTN);
     3984        CFList result= reconstruction (bufF,factors,zeroOne,precision,FLINTN);
     3985        nmod_mat_clear (FLINTN);
     3986#else
    30983987        int * zeroOne= extractZeroOneVecs (NTLN);
    30993988        CFList result= reconstruction (bufF, factors, zeroOne, precision, NTLN);
     3989#endif
    31003990        F= bufF;
    31013991        delete [] zeroOne;
     
    31194009    }
    31204010  }
     4011#ifdef HAVE_FLINT
     4012  nmod_mat_clear (FLINTN);
     4013#endif
    31214014  delete [] bounds;
    31224015  delete [] A;
     
    31244017}
    31254018
     4019#ifdef HAVE_FLINT
     4020CFList
     4021increasePrecision (CanonicalForm& F, CFList& factors, int oldL, int
     4022                   l, int d, int* bounds, CFArray& bufQ, nmod_mat_t FLINTN
     4023                  )
     4024#else
    31264025CFList
    31274026increasePrecision (CanonicalForm& F, CFList& factors, int oldL, int
    31284027                   l, int d, int* bounds, CFArray& bufQ, mat_zz_p& NTLN
    31294028                  )
     4029#endif
    31304030{
    31314031  CFList result= CFList();
     
    31334033  int oldL2= oldL/2;
    31344034  bool hitBound= false;
     4035#ifdef HAVE_FLINT
     4036  if (nmod_mat_nrows (FLINTN) != factors.length()) //refined factors
     4037  {
     4038    nmod_mat_clear (FLINTN);
     4039    nmod_mat_init(FLINTN,factors.length(),factors.length(),getCharacteristic());
     4040    for (long i=factors.length()-1; i >= 0; i--)
     4041      nmod_mat_entry (FLINTN, i, i)= 1;
     4042    bufQ= CFArray (factors.length());
     4043  }
     4044#else
    31354045  if (NTLN.NumRows() != factors.length()) //refined factors
    31364046  {
     
    31384048    bufQ= CFArray (factors.length());
    31394049  }
     4050#endif
    31404051  bool useOldQs= false;
    31414052  CFListIterator j;
    31424053  CFMatrix C;
    31434054  CFArray buf;
     4055#ifdef HAVE_FLINT
     4056  long rank;
     4057  nmod_mat_t FLINTC, FLINTK, null;
     4058#else
    31444059  mat_zz_p* NTLC, NTLK;
     4060#endif
    31454061  CanonicalForm bufF, truncF;
    31464062  CFList bufUniFactors;
     
    31784094          }
    31794095        }
     4096#ifdef HAVE_FLINT
     4097        convertFacCFMatrix2nmod_mat_t (FLINTC, C);
     4098        nmod_mat_init (FLINTK, nmod_mat_nrows (FLINTC), nmod_mat_ncols (FLINTN),
     4099                       getCharacteristic());
     4100        nmod_mat_mul (FLINTK, FLINTC, FLINTN);
     4101        nmod_mat_init (null, nmod_mat_ncols (FLINTK), nmod_mat_ncols (FLINTK),
     4102                       getCharacteristic());
     4103        rank= nmod_mat_nullspace (null, FLINTK);
     4104        nmod_mat_clear (FLINTK);
     4105        nmod_mat_window_init (FLINTK, null, 0, 0, nmod_mat_nrows(null), rank);
     4106        nmod_mat_clear (FLINTC);
     4107        nmod_mat_init_set (FLINTC, FLINTN);
     4108        nmod_mat_clear (FLINTN);
     4109        nmod_mat_init (FLINTN, nmod_mat_nrows (FLINTC), nmod_mat_ncols (FLINTK),
     4110                       getCharacteristic());
     4111        nmod_mat_mul (FLINTN, FLINTC, FLINTK); //no aliasing allowed!!
     4112
     4113        nmod_mat_clear (FLINTC);
     4114        nmod_mat_window_clear (FLINTK);
     4115        nmod_mat_clear (null);
     4116#else
    31804117        NTLC= convertFacCFMatrix2NTLmat_zz_p(C);
    31814118        NTLK= (*NTLC)*NTLN;
     
    31844121        transpose (NTLK, NTLK);
    31854122        NTLN *= NTLK;
     4123#endif
     4124#ifdef HAVE_FLINT
     4125        if (nmod_mat_ncols (FLINTN) == 1)
     4126#else
    31864127        if (NTLN.NumCols() == 1)
     4128#endif
    31874129        {
    31884130          delete [] A;
     
    31914133      }
    31924134    }
     4135#ifdef HAVE_FLINT
     4136    if (nmod_mat_ncols (FLINTN) == 1)
     4137#else
    31934138    if (NTLN.NumCols() == 1)
     4139#endif
    31944140    {
    31954141      delete [] A;
     
    31974143    }
    31984144    int * zeroOneVecs;
     4145#ifdef HAVE_FLINT
     4146    zeroOneVecs= extractZeroOneVecs (FLINTN);
     4147#else
    31994148    zeroOneVecs= extractZeroOneVecs (NTLN);
     4149#endif
    32004150    bufF= F;
    32014151    bufUniFactors= factors;
     4152#ifdef HAVE_FLINT
     4153    result= reconstruction (bufF, bufUniFactors, zeroOneVecs, oldL, FLINTN);
     4154#else
    32024155    result= reconstruction (bufF, bufUniFactors, zeroOneVecs, oldL, NTLN);
     4156#endif
    32034157    delete [] zeroOneVecs;
    32044158    if (degree (bufF) + 1 + degree (LC (bufF, 1)) < oldL && result.length() > 0)
     
    35014455}
    35024456
     4457#ifdef HAVE_FLINT
     4458CFList
     4459increasePrecisionFq2Fp (CanonicalForm& F, CFList& factors, int oldL, int l,
     4460                        int d, int* bounds, CFArray& bufQ, nmod_mat_t FLINTN,
     4461                        const Variable& alpha
     4462                       )
     4463#else
    35034464CFList
    35044465increasePrecisionFq2Fp (CanonicalForm& F, CFList& factors, int oldL, int l,
     
    35064467                        const Variable& alpha
    35074468                       )
     4469#endif
    35084470{
    35094471  CFList result= CFList();
     
    35134475  bool hitBound= false;
    35144476  bool useOldQs= false;
     4477#ifdef HAVE_FLINT
     4478  if (nmod_mat_nrows (FLINTN) != factors.length()) //refined factors
     4479  {
     4480    nmod_mat_clear (FLINTN);
     4481    nmod_mat_init(FLINTN,factors.length(),factors.length(),getCharacteristic());
     4482    for (long i=factors.length()-1; i >= 0; i--)
     4483      nmod_mat_entry (FLINTN, i, i)= 1;
     4484  }
     4485#else
    35154486  if (NTLN.NumRows() != factors.length()) //refined factors
    35164487    ident (NTLN, factors.length());
     4488#endif
    35174489  CFListIterator j;
    35184490  CFMatrix C;
    35194491  CFArray buf;
     4492#ifdef HAVE_FLINT
     4493  long rank;
     4494  nmod_mat_t FLINTC, FLINTK, null;
     4495#else
    35204496  mat_zz_p* NTLC, NTLK;
     4497#endif
    35214498  CanonicalForm bufF, truncF;
    35224499  CFList bufUniFactors;
     
    35544531          }
    35554532        }
     4533#ifdef HAVE_FLINT
     4534        convertFacCFMatrix2nmod_mat_t (FLINTC, C);
     4535        nmod_mat_init (FLINTK, nmod_mat_nrows (FLINTC), nmod_mat_ncols (FLINTN),
     4536                       getCharacteristic());
     4537        nmod_mat_mul (FLINTK, FLINTC, FLINTN);
     4538        nmod_mat_init (null, nmod_mat_ncols (FLINTK), nmod_mat_ncols (FLINTK),
     4539                       getCharacteristic());
     4540        rank= nmod_mat_nullspace (null, FLINTK);
     4541        nmod_mat_clear (FLINTK);
     4542        nmod_mat_window_init (FLINTK, null, 0, 0, nmod_mat_nrows(null), rank);
     4543        nmod_mat_clear (FLINTC);
     4544        nmod_mat_init_set (FLINTC, FLINTN);
     4545        nmod_mat_clear (FLINTN);
     4546        nmod_mat_init (FLINTN, nmod_mat_nrows (FLINTC), nmod_mat_ncols (FLINTK),
     4547                       getCharacteristic());
     4548        nmod_mat_mul (FLINTN, FLINTC, FLINTK); //no aliasing allowed!!
     4549
     4550        nmod_mat_clear (FLINTC);
     4551        nmod_mat_window_clear (FLINTK);
     4552        nmod_mat_clear (null);
     4553#else
    35564554        NTLC= convertFacCFMatrix2NTLmat_zz_p(C);
    35574555        NTLK= (*NTLC)*NTLN;
     
    35604558        transpose (NTLK, NTLK);
    35614559        NTLN *= NTLK;
     4560#endif
     4561#ifdef HAVE_FLINT
     4562        if (nmod_mat_ncols (FLINTN) == 1)
     4563#else
    35624564        if (NTLN.NumCols() == 1)
     4565#endif
    35634566        {
    35644567          delete [] A;
     
    35694572
    35704573    int * zeroOneVecs;
     4574#ifdef HAVE_FLINT
     4575    zeroOneVecs= extractZeroOneVecs (FLINTN);
     4576#else
    35714577    zeroOneVecs= extractZeroOneVecs (NTLN);
     4578#endif
    35724579
    35734580    bufF= F;
    35744581    bufUniFactors= factors;
     4582#ifdef HAVE_FLINT
     4583    result= reconstruction (bufF, bufUniFactors, zeroOneVecs, oldL, FLINTN);
     4584#else
    35754585    result= reconstruction (bufF, bufUniFactors, zeroOneVecs, oldL, NTLN);
     4586#endif
    35764587    delete [] zeroOneVecs;
    35774588    if (degree (bufF) + 1 + degree (LC (bufF, 1)) < l && result.length() > 0)
     
    36014612}
    36024613
     4614#ifdef HAVE_FLINT
     4615CFList
     4616furtherLiftingAndIncreasePrecision (CanonicalForm& F, CFList&
     4617                                    factors, int l, int liftBound, int d, int*
     4618                                    bounds, nmod_mat_t FLINTN, CFList& diophant,
     4619                                    CFMatrix& M, CFArray& Pi, CFArray& bufQ
     4620                                   )
     4621#else
    36034622CFList
    36044623furtherLiftingAndIncreasePrecision (CanonicalForm& F, CFList&
     
    36074626                                    CFMatrix& M, CFArray& Pi, CFArray& bufQ
    36084627                                   )
     4628#endif
    36094629{
    36104630  CanonicalForm LCF= LC (F, 1);
     
    36184638  int stepSize= 8; //TODO choose better step size?
    36194639  l += tmax (tmin (8, degree (F) + 1 + degree (LC (F, 1))-l), 2);
     4640#ifdef HAVE_FLINT
     4641  if (nmod_mat_nrows (FLINTN) != factors.length()) //refined factors
     4642  {
     4643    nmod_mat_clear (FLINTN);
     4644    nmod_mat_init(FLINTN,factors.length(),factors.length(),getCharacteristic());
     4645    for (long i=factors.length()-1; i >= 0; i--)
     4646      nmod_mat_entry (FLINTN, i, i)= 1;
     4647  }
     4648#else
    36204649  if (NTLN.NumRows() != factors.length()) //refined factors
    36214650    ident (NTLN, factors.length());
     4651#endif
    36224652  CFListIterator j;
    36234653  CFMatrix C;
    36244654  CFArray buf;
     4655#ifdef HAVE_FLINT
     4656  long rank;
     4657  nmod_mat_t FLINTC, FLINTK, null;
     4658#else
    36254659  mat_zz_p* NTLC, NTLK;
     4660#endif
    36264661  CanonicalForm bufF, truncF;
    36274662  Variable y= F.mvar();
     
    36594694          }
    36604695        }
     4696#ifdef HAVE_FLINT
     4697        convertFacCFMatrix2nmod_mat_t (FLINTC, C);
     4698        nmod_mat_init (FLINTK, nmod_mat_nrows (FLINTC), nmod_mat_ncols (FLINTN),
     4699                       getCharacteristic());
     4700        nmod_mat_mul (FLINTK, FLINTC, FLINTN);
     4701        nmod_mat_init (null, nmod_mat_ncols (FLINTK), nmod_mat_ncols (FLINTK),
     4702                       getCharacteristic());
     4703        rank= nmod_mat_nullspace (null, FLINTK);
     4704        nmod_mat_clear (FLINTK);
     4705        nmod_mat_window_init (FLINTK, null, 0, 0, nmod_mat_nrows(null), rank);
     4706        nmod_mat_clear (FLINTC);
     4707        nmod_mat_init_set (FLINTC, FLINTN);
     4708        nmod_mat_clear (FLINTN);
     4709        nmod_mat_init (FLINTN, nmod_mat_nrows (FLINTC), nmod_mat_ncols (FLINTK),
     4710                       getCharacteristic());
     4711        nmod_mat_mul (FLINTN, FLINTC, FLINTK); //no aliasing allowed!!
     4712
     4713        nmod_mat_clear (FLINTC);
     4714        nmod_mat_window_clear (FLINTK);
     4715        nmod_mat_clear (null);
     4716#else
    36614717        NTLC= convertFacCFMatrix2NTLmat_zz_p(C);
    36624718        NTLK= (*NTLC)*NTLN;
     
    36654721        transpose (NTLK, NTLK);
    36664722        NTLN *= NTLK;
     4723#endif
     4724#ifdef HAVE_FLINT
     4725        if (nmod_mat_ncols (FLINTN) == 1)
     4726#else
    36674727        if (NTLN.NumCols() == 1)
     4728#endif
    36684729        {
    36694730          irreducible= true;
     
    36734734    }
    36744735
     4736#ifdef HAVE_FLINT
     4737    if (nmod_mat_ncols (FLINTN) == 1)
     4738#else
    36754739    if (NTLN.NumCols() == 1)
     4740#endif
    36764741    {
    36774742      irreducible= true;
     
    36794744    }
    36804745
     4746#ifdef HAVE_FLINT
     4747    int * zeroOneVecs= extractZeroOneVecs (FLINTN);
     4748#else
    36814749    int * zeroOneVecs= extractZeroOneVecs (NTLN);
     4750#endif
    36824751    bufF= F;
     4752#ifdef HAVE_FLINT
     4753    result= reconstruction (bufF, bufFactors, zeroOneVecs, l, FLINTN);
     4754#else
    36834755    result= reconstruction (bufF, bufFactors, zeroOneVecs, l, NTLN);
     4756#endif
    36844757    delete [] zeroOneVecs;
    36854758    if (result.length() > 0 && degree (bufF) + 1 + degree (LC (bufF, 1)) <= l)
     
    36914764    }
    36924765
     4766#ifdef HAVE_FLINT
     4767    if (isReduced (FLINTN))
     4768#else
    36934769    if (isReduced (NTLN))
     4770#endif
    36944771    {
    36954772      int factorsFound= 0;
    36964773      bufF= F;
     4774#ifdef HAVE_FLINT
     4775      int* factorsFoundIndex= new int [nmod_mat_ncols (FLINTN)];
     4776      for (long i= 0; i < nmod_mat_ncols (FLINTN); i++)
     4777#else
    36974778      int* factorsFoundIndex= new int [NTLN.NumCols()];
    36984779      for (long i= 0; i < NTLN.NumCols(); i++)
     4780#endif
    36994781        factorsFoundIndex[i]= 0;
     4782#ifdef HAVE_FLINT
     4783      if (l < liftBound)
     4784        reconstructionTry (result, bufF, bufFactors, l, factorsFound,
     4785                           factorsFoundIndex, FLINTN, false
     4786                          );
     4787      else
     4788        reconstructionTry (result, bufF, bufFactors, degree (bufF) + 1 +
     4789                           degree (LCF), factorsFound, factorsFoundIndex,
     4790                           FLINTN, false
     4791                          );
     4792
     4793      if (nmod_mat_ncols (FLINTN) == result.length())
     4794#else
    37004795      if (l < liftBound)
    37014796        reconstructionTry (result, bufF, bufFactors, l, factorsFound,
     
    37094804
    37104805      if (NTLN.NumCols() == result.length())
     4806#endif
    37114807      {
    37124808        delete [] A;
     
    40805176}
    40815177
     5178#ifdef HAVE_FLINT
     5179CFList
     5180furtherLiftingAndIncreasePrecisionFq2Fp (CanonicalForm& F, CFList& factors, int
     5181                                         l, int liftBound, int d, int* bounds,
     5182                                         nmod_mat_t FLINTN, CFList& diophant,
     5183                                         CFMatrix& M, CFArray& Pi, CFArray& bufQ,
     5184                                         const Variable& alpha
     5185                                        )
     5186#else
    40825187CFList
    40835188furtherLiftingAndIncreasePrecisionFq2Fp (CanonicalForm& F, CFList& factors, int
     
    40875192                                         const Variable& alpha
    40885193                                        )
     5194#endif
    40895195{
    40905196  CanonicalForm LCF= LC (F, 1);
     
    40995205  int stepSize= 8; //TODO choose better step size?
    41005206  l += tmax (tmin (8, degree (F) + 1 + degree (LC (F, 1))-l), 2);
     5207#ifdef HAVE_FLINT
     5208  if (nmod_mat_nrows (FLINTN) != factors.length()) //refined factors
     5209  {
     5210    nmod_mat_clear (FLINTN);
     5211    nmod_mat_init(FLINTN,factors.length(),factors.length(),getCharacteristic());
     5212    for (long i=factors.length()-1; i >= 0; i--)
     5213      nmod_mat_entry (FLINTN, i, i)= 1;
     5214  }
     5215#else
    41015216  if (NTLN.NumRows() != factors.length()) //refined factors
    41025217    ident (NTLN, factors.length());
     5218#endif
    41035219  CFListIterator j;
    41045220  CFMatrix C;
     5221#ifdef HAVE_FLINT
     5222  long rank;
     5223  nmod_mat_t FLINTC, FLINTK, null;
     5224#else
    41055225  mat_zz_p* NTLC, NTLK;
     5226#endif
    41065227  CanonicalForm bufF, truncF;
    41075228  Variable y= F.mvar();
     
    41385259          }
    41395260        }
     5261#ifdef HAVE_FLINT
     5262        convertFacCFMatrix2nmod_mat_t (FLINTC, C);
     5263        nmod_mat_init (FLINTK, nmod_mat_nrows (FLINTC), nmod_mat_ncols (FLINTN),
     5264                       getCharacteristic());
     5265        nmod_mat_mul (FLINTK, FLINTC, FLINTN);
     5266        nmod_mat_init (null, nmod_mat_ncols (FLINTK), nmod_mat_ncols (FLINTK),
     5267                       getCharacteristic());
     5268        rank= nmod_mat_nullspace (null, FLINTK);
     5269        nmod_mat_clear (FLINTK);
     5270        nmod_mat_window_init (FLINTK, null, 0, 0, nmod_mat_nrows(null), rank);
     5271        nmod_mat_clear (FLINTC);
     5272        nmod_mat_init_set (FLINTC, FLINTN);
     5273        nmod_mat_clear (FLINTN);
     5274        nmod_mat_init (FLINTN, nmod_mat_nrows (FLINTC), nmod_mat_ncols (FLINTK),
     5275                       getCharacteristic());
     5276        nmod_mat_mul (FLINTN, FLINTC, FLINTK); //no aliasing allowed!!
     5277
     5278        nmod_mat_clear (FLINTC);
     5279        nmod_mat_window_clear (FLINTK);
     5280        nmod_mat_clear (null);
     5281#else
    41405282        NTLC= convertFacCFMatrix2NTLmat_zz_p(C);
    41415283        NTLK= (*NTLC)*NTLN;
     
    41445286        transpose (NTLK, NTLK);
    41455287        NTLN *= NTLK;
     5288#endif
     5289#ifdef HAVE_FLINT
     5290        if (nmod_mat_ncols (FLINTN) == 1)
     5291#else
    41465292        if (NTLN.NumCols() == 1)
     5293#endif
    41475294        {
    41485295          irreducible= true;
     
    41515298      }
    41525299    }
     5300#ifdef HAVE_FLINT
     5301    if (nmod_mat_ncols (FLINTN) == 1)
     5302#else
    41535303    if (NTLN.NumCols() == 1)
     5304#endif
    41545305    {
    41555306      irreducible= true;
     
    41575308    }
    41585309
     5310#ifdef HAVE_FLINT
     5311    int * zeroOneVecs= extractZeroOneVecs (FLINTN);
     5312#else
    41595313    int * zeroOneVecs= extractZeroOneVecs (NTLN);
     5314#endif
    41605315    CanonicalForm bufF= F;
     5316#ifdef HAVE_FLINT
     5317    result= reconstruction (bufF, bufFactors, zeroOneVecs, l, FLINTN);
     5318#else
    41615319    result= reconstruction (bufF, bufFactors, zeroOneVecs, l, NTLN);
     5320#endif
    41625321    delete [] zeroOneVecs;
    41635322    if (result.length() > 0 && degree (bufF) + 1 + degree (LC (bufF, 1)) <= l)
     
    41695328    }
    41705329
     5330#ifdef HAVE_FLINT
     5331    if (isReduced (FLINTN))
     5332#else
    41715333    if (isReduced (NTLN))
     5334#endif
    41725335    {
    41735336      int factorsFound= 0;
    41745337      bufF= F;
     5338#ifdef HAVE_FLINT
     5339      int* factorsFoundIndex= new int [nmod_mat_ncols (FLINTN)];
     5340      for (long i= 0; i < nmod_mat_ncols (FLINTN); i++)
     5341#else
    41755342      int* factorsFoundIndex= new int [NTLN.NumCols()];
    41765343      for (long i= 0; i < NTLN.NumCols(); i++)
     5344#endif
    41775345        factorsFoundIndex[i]= 0;
     5346#ifdef HAVE_FLINT
     5347      if (l < degree (bufF) + 1 + degree (LCF))
     5348        reconstructionTry (result, bufF, bufFactors, l, factorsFound,
     5349                           factorsFoundIndex, FLINTN, false
     5350                          );
     5351      else
     5352        reconstructionTry (result, bufF, bufFactors, degree (bufF) + 1 +
     5353                           degree (LCF), factorsFound, factorsFoundIndex,
     5354                           FLINTN, false
     5355                          );
     5356      if (nmod_mat_ncols (FLINTN) == result.length())
     5357#else
    41785358      if (l < degree (bufF) + 1 + degree (LCF))
    41795359        reconstructionTry (result, bufF, bufFactors, l, factorsFound,
     
    41865366                          );
    41875367      if (NTLN.NumCols() == result.length())
     5368#endif
    41885369      {
    41895370        delete [] A;
     
    42485429}
    42495430
     5431#ifdef HAVE_FLINT
     5432void
     5433refineAndRestartLift (const CanonicalForm& F, const nmod_mat_t FLINTN, int
     5434                      liftBound, int l, CFList& factors, CFMatrix& M, CFArray&
     5435                      Pi, CFList& diophant
     5436                     )
     5437{
     5438  CFList bufFactors;
     5439  Variable y= Variable (2);
     5440  CanonicalForm LCF= LC (F, 1);
     5441  CFListIterator iter;
     5442  CanonicalForm buf;
     5443  for (long i= 0; i < nmod_mat_ncols (FLINTN); i++)
     5444  {
     5445    iter= factors;
     5446    buf= 1;
     5447    for (long j= 0; j < nmod_mat_nrows (FLINTN); j++, iter++)
     5448    {
     5449      if (!(nmod_mat_entry (FLINTN,j,i) == 0))
     5450        buf= mulNTL (buf, mod (iter.getItem(), y));
     5451    }
     5452    bufFactors.append (buf);
     5453  }
     5454  factors= bufFactors;
     5455  M= CFMatrix (liftBound, factors.length());
     5456  Pi= CFArray();
     5457  diophant= CFList();
     5458  factors.insert (LCF);
     5459  henselLift12 (F, factors, l, Pi, diophant, M);
     5460}
     5461#endif
     5462
    42505463void
    42515464refineAndRestartLift (const CanonicalForm& F, const mat_zz_pE& NTLN, int
     
    42785491}
    42795492
     5493#ifdef HAVE_FLINT
     5494CFList
     5495earlyReconstructionAndLifting (const CanonicalForm& F, const nmod_mat_t N,
     5496                               CanonicalForm& bufF, CFList& factors, int& l,
     5497                               int& factorsFound, bool beenInThres, CFMatrix& M,
     5498                               CFArray& Pi, CFList& diophant, bool symmetric,
     5499                               const CanonicalForm& evaluation
     5500                              )
     5501#else
    42805502CFList
    42815503earlyReconstructionAndLifting (const CanonicalForm& F, const mat_zz_p& N,
     5504                               CanonicalForm& bufF, CFList& factors, int& l,
     5505                               int& factorsFound, bool beenInThres, CFMatrix& M,
     5506                               CFArray& Pi, CFList& diophant, bool symmetric,
     5507                               const CanonicalForm& evaluation
     5508                              )
     5509#endif
     5510{
     5511  int sizeOfLiftPre;
     5512  int * liftPre= getLiftPrecisions (F, sizeOfLiftPre, degree (LC (F, 1), 2));
     5513
     5514  Variable y= F.mvar();
     5515  factorsFound= 0;
     5516  CanonicalForm LCF= LC (F, 1);
     5517  CFList result;
     5518  int smallFactorDeg= tmin (11, liftPre [sizeOfLiftPre- 1] + 1);
     5519#ifdef HAVE_FLINT
     5520  nmod_mat_t FLINTN;
     5521  nmod_mat_init_set (FLINTN, N);
     5522  int * factorsFoundIndex= new int [nmod_mat_ncols (FLINTN)];
     5523  for (long i= 0; i < nmod_mat_ncols (FLINTN); i++)
     5524#else
     5525  mat_zz_p NTLN= N;
     5526  int * factorsFoundIndex= new int [NTLN.NumCols()];
     5527  for (long i= 0; i < NTLN.NumCols(); i++)
     5528#endif
     5529    factorsFoundIndex [i]= 0;
     5530
     5531  if (degree (F) + 1 > smallFactorDeg)
     5532  {
     5533    if (l < smallFactorDeg)
     5534    {
     5535      factors.insert (LCF);
     5536      henselLiftResume12 (F, factors, l, smallFactorDeg, Pi, diophant, M);
     5537      l= smallFactorDeg;
     5538    }
     5539#ifdef HAVE_FLINT
     5540    reconstructionTry (result, bufF, factors, smallFactorDeg, factorsFound,
     5541                       factorsFoundIndex, FLINTN, beenInThres
     5542                      );
     5543    if (result.length() == nmod_mat_ncols (FLINTN))
     5544    {
     5545      nmod_mat_clear (FLINTN);
     5546#else
     5547    reconstructionTry (result, bufF, factors, smallFactorDeg, factorsFound,
     5548                       factorsFoundIndex, NTLN, beenInThres
     5549                      );
     5550    if (result.length() == NTLN.NumCols())
     5551    {
     5552#endif
     5553      delete [] liftPre;
     5554      delete [] factorsFoundIndex;
     5555      return result;
     5556    }
     5557  }
     5558
     5559  int i= sizeOfLiftPre - 1;
     5560  int dummy= 1;
     5561  if (sizeOfLiftPre > 1 && sizeOfLiftPre < 30)
     5562  {
     5563    while (i > 0)
     5564    {
     5565      if (l < liftPre[i-1] + 1)
     5566      {
     5567        factors.insert (LCF);
     5568        henselLiftResume12 (F, factors, l, liftPre[i-1] + 1, Pi, diophant, M);
     5569        l= liftPre[i-1] + 1;
     5570      }
     5571      else
     5572      {
     5573        i--;
     5574        if (i != 0)
     5575          continue;
     5576      }
     5577#ifdef HAVE_FLINT
     5578      reconstructionTry (result, bufF, factors, l, factorsFound,
     5579                         factorsFoundIndex, FLINTN, beenInThres
     5580                        );
     5581      if (result.length() == nmod_mat_ncols (FLINTN))
     5582      {
     5583        nmod_mat_clear (FLINTN);
     5584#else
     5585      reconstructionTry (result, bufF, factors, l, factorsFound,
     5586                         factorsFoundIndex, NTLN, beenInThres
     5587                        );
     5588      if (result.length() == NTLN.NumCols())
     5589      {
     5590#endif
     5591        delete [] liftPre;
     5592        delete [] factorsFoundIndex;
     5593        return result;
     5594      }
     5595      i--;
     5596    }
     5597  }
     5598  else
     5599  {
     5600    i= 1;
     5601    while ((degree (F,y)/4)*i + 4 <= smallFactorDeg)
     5602      i++;
     5603    while (i < 5)
     5604    {
     5605      dummy= tmin (degree (F,y)+1, (degree (F,y)/4)*i+4);
     5606      if (l < dummy)
     5607      {
     5608        factors.insert (LCF);
     5609        henselLiftResume12 (F, factors, l, dummy, Pi, diophant, M);
     5610        l= dummy;
     5611        if (i == 1 && degree (F)%4==0 && symmetric && factors.length() == 2 &&
     5612            LC (F,1).inCoeffDomain() &&
     5613           (degree (factors.getFirst(), 1) == degree (factors.getLast(),1)))
     5614        {
     5615          Variable x= Variable (1);
     5616          CanonicalForm g, h, gg, hh, multiplier1, multiplier2, check1, check2;
     5617          int m= degree (F)/4+1;
     5618          g= factors.getFirst();
     5619          h= factors.getLast();
     5620          g= mod (g, power (y,m));
     5621          h= mod (h, power (y,m));
     5622          g= g (y-evaluation, y);
     5623          h= h (y-evaluation, y);
     5624          gg= mod (swapvar (g,x,y),power (x,m));
     5625          gg= gg (y + evaluation, y);
     5626          multiplier1= factors.getLast()[m-1][0]/gg[m-1][0];
     5627          gg= div (gg, power (y,m));
     5628          gg= gg*power (y,m);
     5629          hh= mod (swapvar (h,x,y),power (x,m));
     5630          hh= hh (y + evaluation, y);
     5631          multiplier2= factors.getFirst()[m-1][0]/hh[m-1][0];
     5632          hh= div (hh, power (y,m));
     5633          hh= hh*power (y,m);
     5634          gg= multiplier1*gg+mod (factors.getLast(), power (y,m));
     5635          hh= multiplier2*hh+mod (factors.getFirst(), power (y,m));
     5636          check1= gg (y-evaluation,y);
     5637          check2= hh (y-evaluation,y);
     5638          check1= swapvar (check1, x, y);
     5639          if (check1/Lc (check1) == check2/Lc (check2))
     5640          {
     5641#ifdef HAVE_FLINT
     5642            nmod_mat_clear (FLINTN);
     5643#endif
     5644            result.append (gg);
     5645            result.append (hh);
     5646            delete [] liftPre;
     5647            delete [] factorsFoundIndex;
     5648            return result;
     5649          }
     5650        }
     5651      }
     5652      else
     5653      {
     5654        i++;
     5655        if (i < 5)
     5656          continue;
     5657      }
     5658#ifdef HAVE_FLINT
     5659      reconstructionTry (result, bufF, factors, l, factorsFound,
     5660                         factorsFoundIndex, FLINTN, beenInThres
     5661                        );
     5662      if (result.length() == nmod_mat_ncols (FLINTN))
     5663      {
     5664        nmod_mat_clear (FLINTN);
     5665#else
     5666      reconstructionTry (result, bufF, factors, l, factorsFound,
     5667                         factorsFoundIndex, NTLN, beenInThres
     5668                        );
     5669      if (result.length() == NTLN.NumCols())
     5670      {
     5671#endif
     5672        delete [] liftPre;
     5673        delete [] factorsFoundIndex;
     5674        return result;
     5675      }
     5676      i++;
     5677    }
     5678  }
     5679
     5680#ifdef HAVE_FLINT
     5681  nmod_mat_clear (FLINTN);
     5682#endif
     5683  delete [] liftPre;
     5684  delete [] factorsFoundIndex;
     5685  return result;
     5686}
     5687
     5688CFList
     5689earlyReconstructionAndLifting (const CanonicalForm& F, const mat_zz_pE& N,
    42825690                               CanonicalForm& bufF, CFList& factors, int& l,
    42835691                               int& factorsFound, bool beenInThres, CFMatrix& M,
     
    42885696  int sizeOfLiftPre;
    42895697  int * liftPre= getLiftPrecisions (F, sizeOfLiftPre, degree (LC (F, 1), 2));
    4290 
    42915698  Variable y= F.mvar();
    42925699  factorsFound= 0;
    42935700  CanonicalForm LCF= LC (F, 1);
    42945701  CFList result;
    4295   int smallFactorDeg= tmin (11, liftPre [sizeOfLiftPre- 1] + 1);
    4296   mat_zz_p NTLN= N;
     5702  int smallFactorDeg= 11;
     5703  mat_zz_pE NTLN= N;
    42975704  int * factorsFoundIndex= new int [NTLN.NumCols()];
    42985705  for (long i= 0; i < NTLN.NumCols(); i++)
     
    44235830}
    44245831
    4425 CFList
    4426 earlyReconstructionAndLifting (const CanonicalForm& F, const mat_zz_pE& N,
    4427                                CanonicalForm& bufF, CFList& factors, int& l,
    4428                                int& factorsFound, bool beenInThres, CFMatrix& M,
    4429                                CFArray& Pi, CFList& diophant, bool symmetric,
    4430                                const CanonicalForm& evaluation
    4431                               )
    4432 {
    4433   int sizeOfLiftPre;
    4434   int * liftPre= getLiftPrecisions (F, sizeOfLiftPre, degree (LC (F, 1), 2));
    4435   Variable y= F.mvar();
    4436   factorsFound= 0;
    4437   CanonicalForm LCF= LC (F, 1);
    4438   CFList result;
    4439   int smallFactorDeg= 11;
    4440   mat_zz_pE NTLN= N;
    4441   int * factorsFoundIndex= new int [NTLN.NumCols()];
    4442   for (long i= 0; i < NTLN.NumCols(); i++)
    4443     factorsFoundIndex [i]= 0;
    4444 
    4445   if (degree (F) + 1 > smallFactorDeg)
    4446   {
    4447     if (l < smallFactorDeg)
    4448     {
    4449       factors.insert (LCF);
    4450       henselLiftResume12 (F, factors, l, smallFactorDeg, Pi, diophant, M);
    4451       l= smallFactorDeg;
    4452     }
    4453     reconstructionTry (result, bufF, factors, smallFactorDeg, factorsFound,
    4454                        factorsFoundIndex, NTLN, beenInThres
    4455                       );
    4456     if (result.length() == NTLN.NumCols())
    4457     {
    4458       delete [] liftPre;
    4459       delete [] factorsFoundIndex;
    4460       return result;
    4461     }
    4462   }
    4463 
    4464   int i= sizeOfLiftPre - 1;
    4465   int dummy= 1;
    4466   if (sizeOfLiftPre > 1 && sizeOfLiftPre < 30)
    4467   {
    4468     while (i > 0)
    4469     {
    4470       if (l < liftPre[i-1] + 1)
    4471       {
    4472         factors.insert (LCF);
    4473         henselLiftResume12 (F, factors, l, liftPre[i-1] + 1, Pi, diophant, M);
    4474         l= liftPre[i-1] + 1;
    4475       }
    4476       else
    4477       {
    4478         i--;
    4479         if (i != 0)
    4480           continue;
    4481       }
    4482       reconstructionTry (result, bufF, factors, l, factorsFound,
    4483                          factorsFoundIndex, NTLN, beenInThres
    4484                         );
    4485       if (result.length() == NTLN.NumCols())
    4486       {
    4487         delete [] liftPre;
    4488         delete [] factorsFoundIndex;
    4489         return result;
    4490       }
    4491       i--;
    4492     }
    4493   }
    4494   else
    4495   {
    4496     i= 1;
    4497     while ((degree (F,y)/4)*i + 4 <= smallFactorDeg)
    4498       i++;
    4499     while (i < 5)
    4500     {
    4501       dummy= tmin (degree (F,y)+1, (degree (F,y)/4)*i+4);
    4502       if (l < dummy)
    4503       {
    4504         factors.insert (LCF);
    4505         henselLiftResume12 (F, factors, l, dummy, Pi, diophant, M);
    4506         l= dummy;
    4507         if (i == 1 && degree (F)%4==0 && symmetric && factors.length() == 2 &&
    4508             LC (F,1).inCoeffDomain() &&
    4509            (degree (factors.getFirst(), 1) == degree (factors.getLast(),1)))
    4510         {
    4511           Variable x= Variable (1);
    4512           CanonicalForm g, h, gg, hh, multiplier1, multiplier2, check1, check2;
    4513           int m= degree (F)/4+1;
    4514           g= factors.getFirst();
    4515           h= factors.getLast();
    4516           g= mod (g, power (y,m));
    4517           h= mod (h, power (y,m));
    4518           g= g (y-evaluation, y);
    4519           h= h (y-evaluation, y);
    4520           gg= mod (swapvar (g,x,y),power (x,m));
    4521           gg= gg (y + evaluation, y);
    4522           multiplier1= factors.getLast()[m-1][0]/gg[m-1][0];
    4523           gg= div (gg, power (y,m));
    4524           gg= gg*power (y,m);
    4525           hh= mod (swapvar (h,x,y),power (x,m));
    4526           hh= hh (y + evaluation, y);
    4527           multiplier2= factors.getFirst()[m-1][0]/hh[m-1][0];
    4528           hh= div (hh, power (y,m));
    4529           hh= hh*power (y,m);
    4530           gg= multiplier1*gg+mod (factors.getLast(), power (y,m));
    4531           hh= multiplier2*hh+mod (factors.getFirst(), power (y,m));
    4532           check1= gg (y-evaluation,y);
    4533           check2= hh (y-evaluation,y);
    4534           check1= swapvar (check1, x, y);
    4535           if (check1/Lc (check1) == check2/Lc (check2))
    4536           {
    4537             result.append (gg);
    4538             result.append (hh);
    4539             delete [] liftPre;
    4540             delete [] factorsFoundIndex;
    4541             return result;
    4542           }
    4543         }
    4544       }
    4545       else
    4546       {
    4547         i++;
    4548         if (i < 5)
    4549           continue;
    4550       }
    4551       reconstructionTry (result, bufF, factors, l, factorsFound,
    4552                          factorsFoundIndex, NTLN, beenInThres
    4553                         );
    4554       if (result.length() == NTLN.NumCols())
    4555       {
    4556         delete [] liftPre;
    4557         delete [] factorsFoundIndex;
    4558         return result;
    4559       }
    4560       i++;
    4561     }
    4562   }
    4563 
    4564   delete [] liftPre;
    4565   delete [] factorsFoundIndex;
    4566   return result;
    4567 }
    4568 
    45695832//over field extension
    45705833CFList
     
    48926155  int l= 1;
    48936156
     6157#ifdef HAVE_FLINT
     6158  nmod_mat_t FLINTN;
     6159#else
    48946160  zz_p::init (getCharacteristic());
    48956161  mat_zz_p NTLN;
     6162#endif
     6163
    48966164  if (alpha.level() != 1)
    48976165  {
     
    49016169  mat_zz_pE NTLNe;
    49026170  if (alpha.level() == 1)
     6171  {
     6172#ifdef HAVE_FLINT
     6173    nmod_mat_init (FLINTN, bufUniFactors.length()-1, bufUniFactors.length()-1, getCharacteristic());
     6174    for (long i= bufUniFactors.length()-2; i >= 0; i--)
     6175      nmod_mat_entry (FLINTN, i, i)= 1;
     6176#else
    49036177    ident (NTLN, bufUniFactors.length() - 1);
     6178#endif
     6179  }
    49046180  else
    49056181  {
    49066182    if (reduceFq2Fp)
     6183#ifdef HAVE_FLINT
     6184    {
     6185      nmod_mat_init (FLINTN, bufUniFactors.length()-1, bufUniFactors.length()-1, getCharacteristic());
     6186      for (long i= bufUniFactors.length()-2; i >= 0; i--)
     6187        nmod_mat_entry (FLINTN, i, i)= 1;
     6188    }
     6189#else
    49076190      ident (NTLN, bufUniFactors.length() - 1);
     6191#endif
    49086192    else
    49096193      ident (NTLNe, bufUniFactors.length() - 1);
     
    49186202    if (alpha.level() == 1)
    49196203      oldL= liftAndComputeLattice (F, bounds, d, start, liftBound, minBound,
     6204#ifdef HAVE_FLINT
     6205                                   bufUniFactors, FLINTN, diophant, M, Pi, bufQ,
     6206#else
    49206207                                   bufUniFactors, NTLN, diophant, M, Pi, bufQ,
     6208#endif
    49216209                                   irreducible
    49226210                                  );
     
    49256213      if (reduceFq2Fp)
    49266214        oldL= liftAndComputeLatticeFq2Fp (F, bounds, d, start, liftBound,
     6215#ifdef HAVE_FLINT
     6216                                          minBound, bufUniFactors, FLINTN,
     6217#else
    49276218                                          minBound, bufUniFactors, NTLN,
     6219#endif
    49286220                                          diophant, M, Pi, bufQ, irreducible,
    49296221                                          alpha
     
    49396231  {
    49406232    if (alpha.level() == 1)
     6233    {
    49416234      oldL= liftAndComputeLattice (F, bounds, d, minBound + 1, liftBound,
     6235#ifdef HAVE_FLINT
     6236                                   minBound, bufUniFactors, FLINTN, diophant, M,
     6237#else
    49426238                                   minBound, bufUniFactors, NTLN, diophant, M,
     6239#endif
    49436240                                   Pi, bufQ, irreducible
    49446241                                  );
     6242    }
    49456243    else
    49466244    {
     
    49486246        oldL= liftAndComputeLatticeFq2Fp (F, bounds, d, minBound + 1,
    49496247                                          liftBound, minBound, bufUniFactors,
     6248#ifdef HAVE_FLINT
     6249                                          FLINTN, diophant, M, Pi, bufQ,
     6250#else
    49506251                                          NTLN, diophant, M, Pi, bufQ,
     6252#endif
    49516253                                          irreducible, alpha
    49526254                                         );
     
    49626264  if (oldL > liftBound)
    49636265  {
     6266#ifdef HAVE_FLINT
     6267    nmod_mat_clear (FLINTN);
     6268#endif
    49646269    delete [] bounds;
    49656270    return Union (smallFactors,
     
    49746279  if (irreducible)
    49756280  {
     6281#ifdef HAVE_FLINT
     6282    nmod_mat_clear (FLINTN);
     6283#endif
    49766284    delete [] bounds;
    49776285    return Union (CFList (F), smallFactors);
     
    49866294    if (alpha.level() == 1 || (alpha.level() != 1 && reduceFq2Fp))
    49876295    {
     6296#ifdef HAVE_FLINT
     6297      factorsFoundIndex= new int [nmod_mat_ncols (FLINTN)];
     6298      for (long i= 0; i < nmod_mat_ncols (FLINTN); i++)
     6299#else
    49886300      factorsFoundIndex= new int [NTLN.NumCols()];
    49896301      for (long i= 0; i < NTLN.NumCols(); i++)
     6302#endif
    49906303        factorsFoundIndex[i]= 0;
    49916304    }
     
    50006313    if (alpha.level() == 1 || (alpha.level() != 1 && reduceFq2Fp))
    50016314      reconstructionTry (result, bufF, bufUniFactors, degree (F) + 1,
     6315#ifdef HAVE_FLINT
     6316                         factorsFound, factorsFoundIndex, FLINTN, false
     6317#else
    50026318                         factorsFound, factorsFoundIndex, NTLN, false
     6319#endif
    50036320                        );
    50046321    else
     
    50086325    if (alpha.level() == 1 || (alpha.level() != 1 && reduceFq2Fp))
    50096326    {
     6327#ifdef HAVE_FLINT
     6328      if (result.length() == nmod_mat_ncols (FLINTN))
     6329      {
     6330        nmod_mat_clear (FLINTN);
     6331#else
    50106332      if (result.length() == NTLN.NumCols())
    50116333      {
     6334#endif
    50126335        delete [] factorsFoundIndex;
    50136336        delete [] bounds;
     
    50196342      if (result.length() == NTLNe.NumCols())
    50206343      {
     6344#ifdef HAVE_FLINT
     6345        nmod_mat_clear (FLINTN);
     6346#endif
    50216347        delete [] factorsFoundIndex;
    50226348        delete [] bounds;
     
    50316357    if (alpha.level() == 1 || (alpha.level() != 1 && reduceFq2Fp))
    50326358    {
     6359#ifdef HAVE_FLINT
     6360      factorsFoundIndex= new int [nmod_mat_ncols (FLINTN)];
     6361      for (long i= 0; i < nmod_mat_ncols (FLINTN); i++)
     6362#else
    50336363      factorsFoundIndex= new int [NTLN.NumCols()];
    50346364      for (long i= 0; i < NTLN.NumCols(); i++)
     6365#endif
    50356366        factorsFoundIndex[i]= 0;
    50366367    }
     
    50456376    if (alpha.level() == 1 || (alpha.level() != 1 && reduceFq2Fp))
    50466377      reconstructionTry (result, bufF, bufUniFactors, degree (F) + 1 + degree
     6378#ifdef HAVE_FLINT
     6379                         (LCF), factorsFound, factorsFoundIndex, FLINTN, false
     6380#else
    50476381                         (LCF), factorsFound, factorsFoundIndex, NTLN, false
     6382#endif
    50486383                        );
    50496384    else
     
    50536388    if (alpha.level() == 1 || (alpha.level() != 1 && reduceFq2Fp))
    50546389    {
     6390#ifdef HAVE_FLINT
     6391      if (result.length() == nmod_mat_ncols(FLINTN))
     6392      {
     6393        nmod_mat_clear (FLINTN);
     6394#else
    50556395      if (result.length() == NTLN.NumCols())
    50566396      {
     6397#endif
    50576398        delete [] factorsFoundIndex;
    50586399        delete [] bounds;
     
    50646405      if (result.length() == NTLNe.NumCols())
    50656406      {
     6407#ifdef HAVE_FLINT
     6408        nmod_mat_clear (FLINTN);
     6409#endif
    50666410        delete [] factorsFoundIndex;
    50676411        delete [] bounds;
     
    50796423    if (alpha.level() == 1 || (alpha.level() != 1 && reduceFq2Fp))
    50806424    {
     6425#ifdef HAVE_FLINT
     6426      if (nmod_mat_ncols (FLINTN) < bufUniFactors.length())
     6427      {
     6428        refineAndRestartLift (F, FLINTN, liftBound, l, bufUniFactors, M, Pi,
     6429#else
    50816430      if (NTLN.NumCols() < bufUniFactors.length())
    50826431      {
    50836432        refineAndRestartLift (F, NTLN, liftBound, l, bufUniFactors, M, Pi,
     6433#endif
    50846434                              diophant
    50856435                             );
     
    51036453  if (alpha.level() == 1 || (alpha.level() != 1 && reduceFq2Fp))
    51046454  {
     6455#ifdef HAVE_FLINT
     6456    result= earlyReconstructionAndLifting (F, FLINTN, bufF, bufUniFactors, l,
     6457#else
    51056458    result= earlyReconstructionAndLifting (F, NTLN, bufF, bufUniFactors, l,
     6459#endif
    51066460                                           factorsFound, beenInThres, M, Pi,
    51076461                                           diophant, symmetric, evaluation
    51086462                                          );
    51096463
     6464#ifdef HAVE_FLINT
     6465    if (result.length() == nmod_mat_ncols (FLINTN))
     6466    {
     6467      nmod_mat_clear (FLINTN);
     6468#else
    51106469    if (result.length() == NTLN.NumCols())
    51116470    {
     6471#endif
    51126472      delete [] bounds;
    51136473      return Union (result, smallFactors);
     
    51236483    if (result.length() == NTLNe.NumCols())
    51246484    {
     6485#ifdef HAVE_FLINT
     6486      nmod_mat_clear (FLINTN);
     6487#endif
    51256488      delete [] bounds;
    51266489      return Union (result, smallFactors);
     
    51576520      if (alpha.level() == 1 || (alpha.level() != 1 && reduceFq2Fp))
    51586521      {
     6522#ifdef HAVE_FLINT
     6523        numCols= nmod_mat_ncols (FLINTN);
     6524        numRows= nmod_mat_nrows (FLINTN);
     6525        zeroOne= extractZeroOneVecs (FLINTN);
     6526#else
    51596527        numCols= NTLN.NumCols();
    51606528        numRows= NTLN.NumRows();
    51616529        zeroOne= extractZeroOneVecs (NTLN);
     6530#endif
    51626531      }
    51636532      else
     
    51836552          if (alpha.level() == 1 || (alpha.level() != 1 && reduceFq2Fp))
    51846553          {
     6554#ifdef HAVE_FLINT
     6555            if (!(nmod_mat_entry (FLINTN, j,i) == 0))
     6556#else
    51856557            if (!IsZero (NTLN (j + 1,i + 1)))
     6558#endif
    51866559            {
    51876560              factorsConsidered.append (iter.getItem());
     
    52206593    if (alpha.level() == 1)
    52216594    {
     6595#ifdef HAVE_FLINT
     6596      oldNumCols= nmod_mat_ncols (FLINTN);
     6597#else
    52226598      oldNumCols= NTLN.NumCols();
     6599#endif
    52236600      resultBufF= increasePrecision (bufF, bufUniFactors, factorsFound,
    52246601                                     oldNumCols, oldL, l
     
    52296606      if (reduceFq2Fp)
    52306607      {
     6608#ifdef HAVE_FLINT
     6609        oldNumCols= nmod_mat_ncols (FLINTN);
     6610#else
    52316611        oldNumCols= NTLN.NumCols();
     6612#endif
    52326613
    52336614        resultBufF= increasePrecisionFq2Fp (bufF, bufUniFactors, factorsFound,
     
    52476628    if (bufUniFactors.isEmpty() || degree (bufF) <= 0)
    52486629    {
     6630#ifdef HAVE_FLINT
     6631      nmod_mat_clear (FLINTN);
     6632#endif
    52496633      delete [] bounds;
    52506634      result= Union (resultBufF, result);
     
    52636647    if (degs.getLength() == 1 || bufUniFactors.length() == 1)
    52646648    {
     6649#ifdef HAVE_FLINT
     6650      nmod_mat_clear (FLINTN);
     6651#endif
    52656652      result.append (bufF);
    52666653      return result;
    52676654    }
     6655#ifdef HAVE_FLINT
     6656    nmod_mat_clear (FLINTN);
     6657#endif
    52686658    return Union (result, henselLiftAndLatticeRecombi (bufF, bufUniFactors,
    52696659                                                       alpha, degs, symmetric,
     
    52786668    {
    52796669        result=increasePrecision (F, bufUniFactors, oldL, l, d, bounds, bufQ,
     6670#ifdef HAVE_FLINT
     6671                                  FLINTN
     6672#else
    52806673                                  NTLN
     6674#endif
    52816675                                 );
    52826676    }
     
    52866680      {
    52876681          result=increasePrecisionFq2Fp (F, bufUniFactors, oldL, l, d, bounds,
     6682#ifdef HAVE_FLINT
     6683                                         bufQ, FLINTN, alpha
     6684#else
    52886685                                         bufQ, NTLN, alpha
     6686#endif
    52896687                                        );
    52906688      }
     
    52986696    if (alpha.level() == 1 || (alpha.level() != 1 && reduceFq2Fp))
    52996697    {
     6698#ifdef HAVE_FLINT
     6699      if (result.length()== nmod_mat_ncols (FLINTN))
     6700      {
     6701        nmod_mat_clear (FLINTN);
     6702#else
    53006703      if (result.length()== NTLN.NumCols())
    53016704      {
     6705#endif
    53026706        delete [] bounds;
    53036707        result= Union (result, smallFactors);
     
    53096713      if (result.length()== NTLNe.NumCols())
    53106714      {
     6715#ifdef HAVE_FLINT
     6716        nmod_mat_clear (FLINTN);
     6717#endif
    53116718        delete [] bounds;
    53126719        result= Union (result, smallFactors);
     
    53196726      if (alpha.level() == 1)
    53206727        result= furtherLiftingAndIncreasePrecision (F,bufUniFactors, l,
     6728#ifdef HAVE_FLINT
     6729                                                    liftBound,d,bounds,FLINTN,
     6730#else
    53216731                                                    liftBound, d, bounds, NTLN,
     6732#endif
    53226733                                                    diophant, M, Pi, bufQ
    53236734                                                   );
     
    53276738          result= furtherLiftingAndIncreasePrecisionFq2Fp (F,bufUniFactors, l,
    53286739                                                           liftBound, d, bounds,
     6740#ifdef HAVE_FLINT
     6741                                                           FLINTN, diophant, M,
     6742#else
    53296743                                                           NTLN, diophant, M,
     6744#endif
    53306745                                                           Pi, bufQ, alpha
    53316746                                                          );
     
    53406755      if (alpha.level() == 1 || (alpha.level() != 1 && reduceFq2Fp))
    53416756      {
     6757#ifdef HAVE_FLINT
     6758        if (result.length() == nmod_mat_ncols (FLINTN))
     6759        {
     6760          nmod_mat_clear (FLINTN);
     6761#else
    53426762        if (result.length() == NTLN.NumCols())
    53436763        {
     6764#endif
    53446765          delete [] bounds;
    53456766          result= Union (result, smallFactors);
     
    53516772        if (result.length() == NTLNe.NumCols())
    53526773        {
     6774#ifdef HAVE_FLINT
     6775          nmod_mat_clear (FLINTN);
     6776#endif
    53536777          delete [] bounds;
    53546778          result= Union (result, smallFactors);
     
    53676791  delete [] bounds;
    53686792  bounds= computeBounds (F, d, isIrreducible);
     6793#ifdef HAVE_FLINT
     6794  nmod_mat_clear (FLINTN);
     6795#endif
    53696796  if (isIrreducible)
    53706797  {
  • m4/flint-check.m4

    r1130ffc r186df6  
    4848for FLINT_HOME in ${FLINT_HOME_PATH}
    4949 do     
    50 if test -r "$FLINT_HOME/include/fmpz.h"; then
     50if test -r "$FLINT_HOME/include/flint/fmpz.h"; then
    5151
    5252        if test "x$FLINT_HOME" != "x/usr"; then
    53                 FLINT_CFLAGS="-I${FLINT_HOME}/include"
     53                FLINT_CFLAGS="-I${FLINT_HOME}/include/flint"
    5454                FLINT_LIBS="-L${FLINT_HOME}/lib -lflint -lmpfr -lmpir"
    5555        else
Note: See TracChangeset for help on using the changeset viewer.