Changeset fc25d7 in git
- Timestamp:
- Dec 16, 2013, 2:40:30 PM (9 years ago)
- 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
- Location:
- factory
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
factory/FLINTconvert.cc
r7c0d57d rfc25d7 46 46 #include <flint/nmod_mat.h> 47 47 #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 48 55 #ifdef __cplusplus 49 56 } … … 73 80 } 74 81 75 CanonicalForm convertFmpz2CF ( fmpz_t coefficient)82 CanonicalForm convertFmpz2CF (const fmpz_t coefficient) 76 83 { 77 84 if (fmpz_cmp_si (coefficient, MINIMMEDIATE) >= 0 && … … 91 98 } 92 99 93 CanonicalForm convertFmpz_poly_t2FacCF (fmpz_poly_t poly, const Variable& x) 100 CanonicalForm 101 convertFmpz_poly_t2FacCF (const fmpz_poly_t poly, const Variable& x) 94 102 { 95 103 CanonicalForm result= 0; … … 104 112 } 105 113 106 void convertFacCF2nmod_poly_t (nmod_poly_t result, const CanonicalForm& f) 114 void 115 convertFacCF2nmod_poly_t (nmod_poly_t result, const CanonicalForm& f) 107 116 { 108 117 bool save_sym_ff= isOn (SW_SYMMETRIC_FF); … … 125 134 } 126 135 127 CanonicalForm convertnmod_poly_t2FacCF (nmod_poly_t poly, const Variable& x) 136 CanonicalForm 137 convertnmod_poly_t2FacCF (const nmod_poly_t poly, const Variable& x) 128 138 { 129 139 CanonicalForm result= 0; … … 188 198 } 189 199 190 CanonicalForm convertFmpq_poly_t2FacCF (fmpq_poly_t p, const Variable& x) 200 CanonicalForm 201 convertFmpq_poly_t2FacCF (const fmpq_poly_t p, const Variable& x) 191 202 { 192 203 CanonicalForm result= 0; … … 226 237 227 238 CFFList 228 convertFLINTnmod_poly_factor2FacCFFList ( nmod_poly_factor_t fac,229 mp_limb_t leadingCoeff,239 convertFLINTnmod_poly_factor2FacCFFList (const nmod_poly_factor_t fac, 240 const mp_limb_t leadingCoeff, 230 241 const Variable& x 231 242 ) … … 238 249 239 250 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), 241 253 fac->exp[i])); 242 254 return result; 243 255 } 256 257 #if __FLINT_VERSION_MINOR >= 4 258 CFFList 259 convertFLINTFq_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 244 275 245 276 void … … 255 286 256 287 CanonicalForm 257 convertFmpz_mod_poly_t2FacCF ( fmpz_mod_poly_t poly, const Variable& x,288 convertFmpz_mod_poly_t2FacCF (const fmpz_mod_poly_t poly, const Variable& x, 258 289 const modpk& b) 259 290 { … … 266 297 } 267 298 268 void convertFacCFMatrix2Fmpz_mat_t (fmpz_mat_t M, CFMatrix &m) 299 #if __FLINT_VERSION_MINOR >= 4 300 void 301 convertFacCF2Fq_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 325 CanonicalForm 326 convertFq_nmod_t2FacCF (const fq_nmod_t poly, const Variable& alpha) 327 { 328 return convertnmod_poly_t2FacCF (poly, alpha); 329 } 330 331 void 332 convertFacCF2Fq_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 344 CanonicalForm 345 convertFq_t2FacCF (const fq_t poly, const Variable& alpha) 346 { 347 return convertFmpz_poly_t2FacCF (poly, alpha); 348 } 349 350 void 351 convertFacCF2Fq_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 368 void 369 convertFacCF2Fq_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 385 CanonicalForm 386 convertFq_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 406 CanonicalForm 407 convertFq_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 428 void convertFacCFMatrix2Fmpz_mat_t (fmpz_mat_t M, const CFMatrix &m) 269 429 { 270 430 fmpz_mat_init (M, (long) m.rows(), (long) m.columns()); … … 279 439 } 280 440 } 281 CFMatrix* convertFmpz_mat_t2FacCFMatrix( fmpz_mat_t m)441 CFMatrix* convertFmpz_mat_t2FacCFMatrix(const fmpz_mat_t m) 282 442 { 283 443 CFMatrix *res=new CFMatrix(fmpz_mat_nrows (m),fmpz_mat_ncols (m)); … … 293 453 } 294 454 295 void convertFacCFMatrix2nmod_mat_t (nmod_mat_t M, CFMatrix &m)455 void convertFacCFMatrix2nmod_mat_t (nmod_mat_t M, const CFMatrix &m) 296 456 { 297 457 nmod_mat_init (M, (long) m.rows(), (long) m.columns(), getCharacteristic()); … … 311 471 } 312 472 313 CFMatrix* convertNmod_mat_t2FacCFMatrix( nmod_mat_t m)473 CFMatrix* convertNmod_mat_t2FacCFMatrix(const nmod_mat_t m) 314 474 { 315 475 CFMatrix *res=new CFMatrix(nmod_mat_nrows (m), nmod_mat_ncols (m)); … … 325 485 } 326 486 327 #endif 328 329 487 #if __FLINT_VERSION_MINOR >= 4 488 void 489 convertFacCFMatrix2Fq_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 503 CFMatrix* 504 convertFq_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 35 35 #include <flint/nmod_mat.h> 36 36 #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 37 44 #ifdef __cplusplus 38 45 } … … 57 64 /// conversion of a FLINT integer to CanonicalForm 58 65 CanonicalForm 59 convertFmpz2CF ( fmpz_t coefficient ///< [in] a FLINT integer66 convertFmpz2CF (const fmpz_t coefficient ///< [in] a FLINT integer 60 67 ); 61 68 62 69 /// conversion of a FLINT poly over Z to CanonicalForm 63 70 CanonicalForm 64 convertFmpz_poly_t2FacCF ( fmpz_poly_t poly, ///< [in] an fmpz_poly_t71 convertFmpz_poly_t2FacCF (const fmpz_poly_t poly, ///< [in] an fmpz_poly_t 65 72 const Variable& x ///< [in] variable the result should 66 73 ///< have … … 77 84 /// conversion of a FLINT poly over Z/p to CanonicalForm 78 85 CanonicalForm 79 convertnmod_poly_t2FacCF ( nmod_poly_t poly, ///< [in] a nmod_poly_t86 convertnmod_poly_t2FacCF (const nmod_poly_t poly, ///< [in] a nmod_poly_t 80 87 const Variable& x ///< [in] variable the result should 81 88 ///< have … … 98 105 /// conversion of a FLINT poly over Q to CanonicalForm 99 106 CanonicalForm 100 convertFmpq_poly_t2FacCF ( fmpq_poly_t p, ///< [in] an fmpq_poly_t107 convertFmpq_poly_t2FacCF (const fmpq_poly_t p, ///< [in] an fmpq_poly_t 101 108 const Variable& x ///< [in] variable the result should 102 109 ///< have … … 107 114 CFFList 108 115 convertFLINTnmod_poly_factor2FacCFFList ( 109 nmod_poly_factor_t fac, ///< [in] a nmod_poly_factor_t110 mp_limb_t leadingCoeff, ///< [in] leading coefficient116 const nmod_poly_factor_t fac, ///< [in] a nmod_poly_factor_t 117 const mp_limb_t leadingCoeff, ///< [in] leading coefficient 111 118 const Variable& x ///< [in] variable the result should 112 119 ///< have … … 127 134 CanonicalForm 128 135 convertFmpz_mod_poly_t2FacCF ( 129 fmpz_mod_poly_t poly, ///< [in] fmpz_mod_poly_t136 const fmpz_mod_poly_t poly, ///< [in] fmpz_mod_poly_t 130 137 const Variable& x, ///< [in] variable the result 131 138 ///< should have … … 134 141 ); 135 142 143 #if __FLINT_VERSION_MINOR >= 4 144 /// conversion of a FLINT element of F_q to a CanonicalForm with alg. variable 145 /// alpha 146 CanonicalForm 147 convertFq_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 153 CanonicalForm 154 convertFq_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 160 void 161 convertFacCF2Fq_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 167 void 168 convertFacCF2Fq_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 175 void 176 convertFacCF2Fq_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 182 void 183 convertFacCF2Fq_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 191 CanonicalForm 192 convertFq_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 200 CanonicalForm 201 convertFq_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 136 208 /// 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_t138 CFMatrix &m///<[in] matrix over Z209 void convertFacCFMatrix2Fmpz_mat_t (fmpz_mat_t M, ///<[in,out] fmpz_mat_t 210 const CFMatrix &m ///<[in] matrix over Z 139 211 ); 140 212 141 213 /// conversion of a FLINT matrix over Z to a factory matrix 142 CFMatrix* convertFmpz_mat_t2FacCFMatrix( fmpz_mat_t m ///<[in] fmpz_mat_t214 CFMatrix* convertFmpz_mat_t2FacCFMatrix(const fmpz_mat_t m ///<[in] fmpz_mat_t 143 215 ); 144 216 145 217 /// 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_t147 CFMatrix &m///<[in] matrix over Z/p218 void convertFacCFMatrix2nmod_mat_t (nmod_mat_t M, ///<[in,out] nmod_mat_t 219 const CFMatrix &m ///<[in] matrix over Z/p 148 220 ); 149 221 150 222 /// conversion of a FLINT matrix over Z/p to a factory matrix 151 CFMatrix* convertNmod_mat_t2FacCFMatrix( nmod_mat_t m ///<[in] nmod_mat_t223 CFMatrix* convertNmod_mat_t2FacCFMatrix(const nmod_mat_t m ///<[in] nmod_mat_t 152 224 ); 153 225 154 #endif 155 #endif 226 #if __FLINT_VERSION_MINOR >= 4 227 /// conversion of a FLINT matrix over F_q to a factory matrix 228 CFMatrix* 229 convertFq_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 235 void 236 convertFacCFMatrix2Fq_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 243 CFFList 244 convertFLINTFq_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.