Changeset fc25d7 in git


Ignore:
Timestamp:
Dec 16, 2013, 2:40:30 PM (9 years ago)
Author:
Martin Lee <martinlee84@…>
Branches:
(u'jengelh-datetime', 'ceac47cbc86fe4a15902392bdbb9bd2ae0ea02c6')(u'spielwiese', 'a800fe4b3e9d37a38c5a10cc0ae9dfa0c15a4ee6')
Children:
1f4ed35293648146e81ceb849bb6dbba0771e8b3
Parents:
7c0d57dd4602fd556a785a238d95da87fbba50de
git-author:
Martin Lee <martinlee84@web.de>2013-12-16 14:40:30+01:00
git-committer:
Martin Lee <martinlee84@web.de>2014-01-20 16:45:03+01:00
Message:
chg: added new conversion for polys over Fq (requires FLINT at least 2.4)

Conflicts:

	factory/FLINTconvert.cc
Location:
factory
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • factory/FLINTconvert.cc

    r7c0d57d rfc25d7  
    4646#include <flint/nmod_mat.h>
    4747#include <flint/fmpz_mat.h>
     48#if (__FLINT_VERSION_MINOR >= 4)
     49#include <flint/fq.h>
     50#include <flint/fq_poly.h>
     51#include <flint/fq_nmod.h>
     52#include <flint/fq_nmod_poly.h>
     53#include <flint/fq_nmod_mat.h>
     54#endif
    4855#ifdef __cplusplus
    4956}
     
    7380}
    7481
    75 CanonicalForm convertFmpz2CF (fmpz_t coefficient)
     82CanonicalForm convertFmpz2CF (const fmpz_t coefficient)
    7683{
    7784  if (fmpz_cmp_si (coefficient, MINIMMEDIATE) >= 0 &&
     
    9198}
    9299
    93 CanonicalForm convertFmpz_poly_t2FacCF (fmpz_poly_t poly, const Variable& x)
     100CanonicalForm
     101convertFmpz_poly_t2FacCF (const fmpz_poly_t poly, const Variable& x)
    94102{
    95103  CanonicalForm result= 0;
     
    104112}
    105113
    106 void convertFacCF2nmod_poly_t (nmod_poly_t result, const CanonicalForm& f)
     114void
     115convertFacCF2nmod_poly_t (nmod_poly_t result, const CanonicalForm& f)
    107116{
    108117  bool save_sym_ff= isOn (SW_SYMMETRIC_FF);
     
    125134}
    126135
    127 CanonicalForm convertnmod_poly_t2FacCF (nmod_poly_t poly, const Variable& x)
     136CanonicalForm
     137convertnmod_poly_t2FacCF (const nmod_poly_t poly, const Variable& x)
    128138{
    129139  CanonicalForm result= 0;
     
    188198}
    189199
    190 CanonicalForm convertFmpq_poly_t2FacCF (fmpq_poly_t p, const Variable& x)
     200CanonicalForm
     201convertFmpq_poly_t2FacCF (const fmpq_poly_t p, const Variable& x)
    191202{
    192203  CanonicalForm result= 0;
     
    226237
    227238CFFList
    228 convertFLINTnmod_poly_factor2FacCFFList (nmod_poly_factor_t fac,
    229                                           mp_limb_t leadingCoeff,
     239convertFLINTnmod_poly_factor2FacCFFList (const nmod_poly_factor_t fac,
     240                                          const mp_limb_t leadingCoeff,
    230241                                          const Variable& x
    231242                                         )
     
    238249
    239250  for (i = 0; i < fac->num; i++)
    240     result.append (CFFactor (convertnmod_poly_t2FacCF ((nmod_poly_t &)fac->p[i],x),
     251    result.append (CFFactor (convertnmod_poly_t2FacCF (
     252                             (nmod_poly_t &)fac->p[i],x),
    241253                             fac->exp[i]));
    242254  return result;
    243255}
     256
     257#if __FLINT_VERSION_MINOR >= 4
     258CFFList
     259convertFLINTFq_nmod_poly_factor2FacCFFList (const fq_nmod_poly_factor_t fac,
     260                                       const Variable& x, const Variable& alpha,
     261                                       const fq_nmod_ctx_t fq_con
     262                                         )
     263{
     264  CFFList result;
     265
     266  long i;
     267
     268  for (i = 0; i < fac->num; i++)
     269    result.append (CFFactor (convertFq_nmod_poly_t2FacCF (
     270                             (fq_nmod_poly_t &)fac->poly[i], x, alpha, fq_con),
     271                             fac->exp[i]));
     272  return result;
     273}
     274#endif
    244275
    245276void
     
    255286
    256287CanonicalForm
    257 convertFmpz_mod_poly_t2FacCF (fmpz_mod_poly_t poly, const Variable& x,
     288convertFmpz_mod_poly_t2FacCF (const fmpz_mod_poly_t poly, const Variable& x,
    258289                              const modpk& b)
    259290{
     
    266297}
    267298
    268 void convertFacCFMatrix2Fmpz_mat_t (fmpz_mat_t M, CFMatrix &m)
     299#if __FLINT_VERSION_MINOR >= 4
     300void
     301convertFacCF2Fq_nmod_t (fq_nmod_t result, const CanonicalForm& f,
     302                        const fq_nmod_ctx_t ctx)
     303{
     304  bool save_sym_ff= isOn (SW_SYMMETRIC_FF);
     305  if (save_sym_ff) Off (SW_SYMMETRIC_FF);
     306  for (CFIterator i= f; i.hasTerms(); i++)
     307  {
     308    CanonicalForm c= i.coeff();
     309    if (!c.isImm()) c=c.mapinto(); //c%= getCharacteristic();
     310    if (!c.isImm())
     311    {  //This case will never happen if the characteristic is in fact a prime
     312       // number, since all coefficients are represented as immediates
     313       printf("convertFacCF2Fq_nmod_t: coefficient not immediate!, char=%d\n",
     314              getCharacteristic());
     315    }
     316    else
     317    {
     318      STICKYASSERT (i.exp() <= fq_nmod_ctx_degree(ctx), "convertFacCF2Fq_nmod_t: element is not reduced");
     319      nmod_poly_set_coeff_ui (result, i.exp(), c.intval());
     320    }
     321  }
     322  if (save_sym_ff) On (SW_SYMMETRIC_FF);
     323}
     324
     325CanonicalForm
     326convertFq_nmod_t2FacCF (const fq_nmod_t poly, const Variable& alpha)
     327{
     328  return convertnmod_poly_t2FacCF (poly, alpha);
     329}
     330
     331void
     332convertFacCF2Fq_t (fq_t result, const CanonicalForm& f, const fq_ctx_t ctx)
     333{
     334  fmpz_poly_init2 (result, fq_ctx_degree(ctx));
     335  ASSERT (degree (f) < fq_ctx_degree (ctx), "input is not reduced");
     336  _fmpz_poly_set_length(result, degree(f)+1);
     337  for (CFIterator i= f; i.hasTerms(); i++)
     338    convertCF2Fmpz (fmpz_poly_get_coeff_ptr(result, i.exp()), i.coeff());
     339  _fmpz_vec_scalar_mod_fmpz (result->coeffs, result->coeffs, degree (f) + 1,
     340                             &ctx->p);
     341  _fmpz_poly_normalise (result);
     342}
     343
     344CanonicalForm
     345convertFq_t2FacCF (const fq_t poly, const Variable& alpha)
     346{
     347  return convertFmpz_poly_t2FacCF (poly, alpha);
     348}
     349
     350void
     351convertFacCF2Fq_poly_t (fq_poly_t result, const CanonicalForm& f,
     352                        const fq_ctx_t ctx)
     353{
     354  fq_poly_init2 (result, degree (f)+1, ctx);
     355  _fq_poly_set_length (result, degree (f) + 1, ctx);
     356  fmpz_poly_t buf;
     357  for (CFIterator i= f; i.hasTerms(); i++)
     358  {
     359    convertFacCF2Fmpz_poly_t (buf, i.coeff());
     360    _fmpz_vec_scalar_mod_fmpz (buf->coeffs, buf->coeffs, degree (i.coeff()) + 1,
     361                               &ctx->p);
     362    _fmpz_poly_normalise (buf);
     363    fq_poly_set_coeff (result, i.exp(), buf, ctx);
     364    fmpz_poly_clear (buf);
     365  }
     366}
     367
     368void
     369convertFacCF2Fq_nmod_poly_t (fq_nmod_poly_t result, const CanonicalForm& f,
     370                             const fq_nmod_ctx_t ctx)
     371{
     372  fq_nmod_poly_init2 (result, degree (f)+1, ctx);
     373  _fq_nmod_poly_set_length (result, degree (f) + 1, ctx);
     374  fq_nmod_t buf;
     375  fq_nmod_init2 (buf, ctx);
     376  for (CFIterator i= f; i.hasTerms(); i++)
     377  {
     378    convertFacCF2Fq_nmod_t (buf, i.coeff(), ctx);
     379    fq_nmod_poly_set_coeff (result, i.exp(), buf, ctx);
     380    fq_nmod_zero (buf, ctx);
     381  }
     382  fq_nmod_clear (buf, ctx);
     383}
     384
     385CanonicalForm
     386convertFq_poly_t2FacCF (const fq_poly_t p, const Variable& x,
     387                        const Variable& alpha, const fq_ctx_t ctx)
     388{
     389  CanonicalForm result= 0;
     390  fq_t coeff;
     391  long n= fq_poly_length (p, ctx);
     392  fq_init2 (coeff, ctx);
     393  for (long i= 0; i < n; i++)
     394  {
     395    fq_poly_get_coeff (coeff, p, i, ctx);
     396    if (fq_is_zero (coeff, ctx))
     397      continue;
     398    result += convertFq_t2FacCF (coeff, alpha)*power (x, i);
     399    fq_zero (coeff, ctx);
     400  }
     401  fq_clear (coeff, ctx);
     402
     403  return result;
     404}
     405
     406CanonicalForm
     407convertFq_nmod_poly_t2FacCF (const fq_nmod_poly_t p, const Variable& x,
     408                             const Variable& alpha, const fq_nmod_ctx_t ctx)
     409{
     410  CanonicalForm result= 0;
     411  fq_nmod_t coeff;
     412  long n= fq_nmod_poly_length (p, ctx);
     413  fq_nmod_init2 (coeff, ctx);
     414  for (long i= 0; i < n; i++)
     415  {
     416    fq_nmod_poly_get_coeff (coeff, p, i, ctx);
     417    if (fq_nmod_is_zero (coeff, ctx))
     418      continue;
     419    result += convertFq_nmod_t2FacCF (coeff, alpha)*power (x, i);
     420    fq_nmod_zero (coeff, ctx);
     421  }
     422  fq_nmod_clear (coeff, ctx);
     423
     424  return result;
     425}
     426#endif
     427
     428void convertFacCFMatrix2Fmpz_mat_t (fmpz_mat_t M, const CFMatrix &m)
    269429{
    270430  fmpz_mat_init (M, (long) m.rows(), (long) m.columns());
     
    279439  }
    280440}
    281 CFMatrix* convertFmpz_mat_t2FacCFMatrix(fmpz_mat_t m)
     441CFMatrix* convertFmpz_mat_t2FacCFMatrix(const fmpz_mat_t m)
    282442{
    283443  CFMatrix *res=new CFMatrix(fmpz_mat_nrows (m),fmpz_mat_ncols (m));
     
    293453}
    294454
    295 void convertFacCFMatrix2nmod_mat_t (nmod_mat_t M, CFMatrix &m)
     455void convertFacCFMatrix2nmod_mat_t (nmod_mat_t M, const CFMatrix &m)
    296456{
    297457  nmod_mat_init (M, (long) m.rows(), (long) m.columns(), getCharacteristic());
     
    311471}
    312472
    313 CFMatrix* convertNmod_mat_t2FacCFMatrix(nmod_mat_t m)
     473CFMatrix* convertNmod_mat_t2FacCFMatrix(const nmod_mat_t m)
    314474{
    315475  CFMatrix *res=new CFMatrix(nmod_mat_nrows (m), nmod_mat_ncols (m));
     
    325485}
    326486
    327 #endif
    328 
    329 
     487#if __FLINT_VERSION_MINOR >= 4
     488void
     489convertFacCFMatrix2Fq_nmod_mat_t (fq_nmod_mat_t M,
     490                                  const fq_nmod_ctx_t fq_con, const CFMatrix &m)
     491{
     492  fq_nmod_mat_init (M, (long) m.rows(), (long) m.columns(), fq_con);
     493  int i,j;
     494  for(i=m.rows();i>0;i--)
     495  {
     496    for(j=m.columns();j>0;j--)
     497    {
     498      convertFacCF2nmod_poly_t (M->rows[i-1]+j-1, m (i,j));
     499    }
     500  }
     501}
     502
     503CFMatrix*
     504convertFq_nmod_mat_t2FacCFMatrix(const fq_nmod_mat_t m,
     505                                 const fq_nmod_ctx_t& fq_con,
     506                                 const Variable& alpha)
     507{
     508  CFMatrix *res=new CFMatrix(fq_nmod_mat_nrows (m, fq_con),
     509                             fq_nmod_mat_ncols (m, fq_con));
     510  int i,j;
     511  for(i=res->rows();i>0;i--)
     512  {
     513    for(j=res->columns();j>0;j--)
     514    {
     515      (*res)(i,j)=convertFq_nmod_t2FacCF (fq_nmod_mat_entry (m, i-1, j-1),
     516                                          alpha);
     517    }
     518  }
     519  return res;
     520}
     521#endif
     522
     523#endif
     524
     525
  • factory/FLINTconvert.h

    r7c0d57d rfc25d7  
    3535#include <flint/nmod_mat.h>
    3636#include <flint/fmpz_mat.h>
     37#if (__FLINT_VERSION_MINOR >= 4)
     38#include <flint/fq.h>
     39#include <flint/fq_poly.h>
     40#include <flint/fq_nmod.h>
     41#include <flint/fq_nmod_poly.h>
     42#include <flint/fq_nmod_mat.h>
     43#endif
    3744#ifdef __cplusplus
    3845}
     
    5764/// conversion of a FLINT integer to CanonicalForm
    5865CanonicalForm
    59 convertFmpz2CF (fmpz_t coefficient ///< [in] a FLINT integer
     66convertFmpz2CF (const fmpz_t coefficient ///< [in] a FLINT integer
    6067               );
    6168
    6269/// conversion of a FLINT poly over Z to CanonicalForm
    6370CanonicalForm
    64 convertFmpz_poly_t2FacCF (fmpz_poly_t poly, ///< [in] an fmpz_poly_t
     71convertFmpz_poly_t2FacCF (const fmpz_poly_t poly, ///< [in] an fmpz_poly_t
    6572                          const Variable& x ///< [in] variable the result should
    6673                                            ///< have
     
    7784/// conversion of a FLINT poly over Z/p to CanonicalForm
    7885CanonicalForm
    79 convertnmod_poly_t2FacCF (nmod_poly_t poly, ///< [in] a nmod_poly_t
     86convertnmod_poly_t2FacCF (const nmod_poly_t poly, ///< [in] a nmod_poly_t
    8087                          const Variable& x ///< [in] variable the result should
    8188                                            ///< have
     
    98105/// conversion of a FLINT poly over Q to CanonicalForm
    99106CanonicalForm
    100 convertFmpq_poly_t2FacCF (fmpq_poly_t p,    ///< [in] an fmpq_poly_t
     107convertFmpq_poly_t2FacCF (const fmpq_poly_t p,    ///< [in] an fmpq_poly_t
    101108                          const Variable& x ///< [in] variable the result should
    102109                                            ///< have
     
    107114CFFList
    108115convertFLINTnmod_poly_factor2FacCFFList (
    109                    nmod_poly_factor_t fac, ///< [in] a nmod_poly_factor_t
    110                    mp_limb_t leadingCoeff, ///< [in] leading coefficient
     116                   const nmod_poly_factor_t fac, ///< [in] a nmod_poly_factor_t
     117                   const mp_limb_t leadingCoeff, ///< [in] leading coefficient
    111118                   const Variable& x       ///< [in] variable the result should
    112119                                           ///< have
     
    127134CanonicalForm
    128135convertFmpz_mod_poly_t2FacCF (
    129                           fmpz_mod_poly_t poly, ///< [in] fmpz_mod_poly_t
     136                          const fmpz_mod_poly_t poly, ///< [in] fmpz_mod_poly_t
    130137                          const Variable& x,    ///< [in] variable the result
    131138                                                ///< should have
     
    134141                             );
    135142
     143#if __FLINT_VERSION_MINOR >= 4
     144/// conversion of a FLINT element of F_q to a CanonicalForm with alg. variable
     145/// alpha
     146CanonicalForm
     147convertFq_nmod_t2FacCF (const fq_nmod_t poly, ///< [in] fq_nmod_t
     148                        const Variable& alpha ///< [in] algebraic variable
     149                       );
     150
     151/// conversion of a FLINT element of F_q with non-word size p to a CanonicalForm
     152/// with alg. variable alpha
     153CanonicalForm
     154convertFq_t2FacCF (const fq_t poly,      ///< [in] fq_t
     155                   const Variable& alpha ///< [in] algebraic variable
     156                  );
     157
     158/// conversion of a factory element of F_q to a FLINT fq_nmod_t, does not do any
     159/// memory allocation for poly
     160void
     161convertFacCF2Fq_nmod_t (fq_nmod_t result,       ///< [in,out] fq_nmod_t
     162                        const CanonicalForm& f, ///< [in] element of Fq
     163                        const fq_nmod_ctx_t ctx ///< [in] Fq context
     164                       );
     165
     166/// conversion of a factory element of F_q (for non-word size p) to a FLINT fq_t
     167void
     168convertFacCF2Fq_t (fq_t result,            ///< [in,out] fq_t
     169                   const CanonicalForm& f, ///< [in] element of Fq
     170                   const fq_ctx_t ctx      ///< [in] Fq context
     171                  );
     172
     173/// conversion of a factory univariate poly over F_q (for non-word size p) to a
     174/// FLINT fq_poly_t
     175void
     176convertFacCF2Fq_poly_t (fq_poly_t result,      ///< [in,out] fq_poly_t
     177                        const CanonicalForm& f,///< [in] univariate poly over Fq
     178                        const fq_ctx_t ctx     ///< [in] Fq context
     179                       );
     180
     181/// conversion of a factory univariate poly over F_q to a FLINT fq_nmod_poly_t
     182void
     183convertFacCF2Fq_nmod_poly_t (fq_nmod_poly_t result, ///< [in,out] fq_nmod_poly_t
     184                             const CanonicalForm& f,///< [in] univariate poly
     185                                                    ///< over Fq
     186                             const fq_nmod_ctx_t ctx///< [in] Fq context
     187                            );
     188
     189/// conversion of a FLINT poly over Fq (for non-word size p) to a CanonicalForm
     190/// with alg. variable alpha and polynomial variable x
     191CanonicalForm
     192convertFq_poly_t2FacCF (const fq_poly_t p,     ///< [in] fq_poly_t
     193                        const Variable& x,     ///< [in] polynomial variable
     194                        const Variable& alpha, ///< [in] algebraic variable
     195                        const fq_ctx_t ctx     ///< [in] Fq context
     196                       );
     197
     198/// conversion of a FLINT poly over Fq to a CanonicalForm with alg. variable
     199/// alpha and polynomial variable x
     200CanonicalForm
     201convertFq_nmod_poly_t2FacCF (const fq_nmod_poly_t p, ///< [in] fq_nmod_poly_t
     202                             const Variable& x,      ///< [in] polynomial var.
     203                             const Variable& alpha,  ///< [in] algebraic var.
     204                             const fq_nmod_ctx_t ctx ///< [in] Fq context
     205                            );
     206#endif
     207
    136208/// conversion of a factory matrix over Z to a fmpz_mat_t
    137 void convertFacCFMatrix2Fmpz_mat_t (fmpz_mat_t M, ///<[in,out] fmpz_mat_t
    138                                     CFMatrix &m   ///<[in] matrix over Z
     209void convertFacCFMatrix2Fmpz_mat_t (fmpz_mat_t M,      ///<[in,out] fmpz_mat_t
     210                                    const CFMatrix &m  ///<[in] matrix over Z
    139211                                   );
    140212
    141213/// conversion of a FLINT matrix over Z to a factory matrix
    142 CFMatrix* convertFmpz_mat_t2FacCFMatrix(fmpz_mat_t m ///<[in] fmpz_mat_t
     214CFMatrix* convertFmpz_mat_t2FacCFMatrix(const fmpz_mat_t m ///<[in] fmpz_mat_t
    143215                                       );
    144216
    145217/// conversion of a factory matrix over Z/p to a nmod_mat_t
    146 void convertFacCFMatrix2nmod_mat_t (nmod_mat_t M, ///<[in,out] nmod_mat_t
    147                                     CFMatrix &m  ///<[in] matrix over Z/p
     218void convertFacCFMatrix2nmod_mat_t (nmod_mat_t M,     ///<[in,out] nmod_mat_t
     219                                    const CFMatrix &m ///<[in] matrix over Z/p
    148220                                   );
    149221
    150222/// conversion of a FLINT matrix over Z/p to a factory matrix
    151 CFMatrix* convertNmod_mat_t2FacCFMatrix(nmod_mat_t m ///<[in] nmod_mat_t
     223CFMatrix* convertNmod_mat_t2FacCFMatrix(const nmod_mat_t m ///<[in] nmod_mat_t
    152224                                       );
    153225
    154 #endif
    155 #endif
     226#if __FLINT_VERSION_MINOR >= 4
     227/// conversion of a FLINT matrix over F_q to a factory matrix
     228CFMatrix*
     229convertFq_nmod_mat_t2FacCFMatrix(const fq_nmod_mat_t m,       ///< [in] fq_nmod_mat_t
     230                                 const fq_nmod_ctx_t& fq_con, ///< [in] Fq context
     231                                 const Variable& alpha ///< [in] algebraic variable
     232                                );
     233
     234/// conversion of a factory matrix over F_q to a fq_nmod_mat_t
     235void
     236convertFacCFMatrix2Fq_nmod_mat_t (fq_nmod_mat_t M,            ///< [in, out] fq_nmod_mat_t
     237                                  const fq_nmod_ctx_t fq_con, ///< [in] Fq context
     238                                  const CFMatrix &m           ///< [in] matrix over Fq
     239                                 );
     240
     241/// conversion of a FLINT factorization over Fq (for word size p) to a
     242/// CFFList
     243CFFList
     244convertFLINTFq_nmod_poly_factor2FacCFFList (const fq_nmod_poly_factor_t fac, ///< [in] fq_nmod_poly_factor_t
     245                                          const Variable& x,     ///< [in] polynomial variable
     246                                          const Variable& alpha, ///< [in] algebraic variable
     247                                          const fq_nmod_ctx_t fq_con ///< [in] Fq context
     248                                           );
     249#endif
     250
     251
     252#endif
     253#endif
Note: See TracChangeset for help on using the changeset viewer.