source: git/factory/cf_irred.cc @ 03c742

spielwiese
Last change on this file since 03c742 was 03c742, checked in by Hans Schoenemann <hannes@…>, 3 years ago
factory: BuildIrred, FLINT/NTL seperation
  • Property mode set to 100644
File size: 1.5 KB
RevLine 
[493c477]1/* emacs edit mode for this file is -*- C++ -*- */
[2dd068]2
[9f7665]3
[e4fe2b]4#include "config.h"
[9f7665]5
[ab4548f]6
[650f2d8]7#include "cf_assert.h"
[ab4548f]8
[2dd068]9#include "cf_defs.h"
10#include "canonicalform.h"
[f58e95]11#include "cf_algorithm.h"
[2dd068]12#include "cf_random.h"
13
[eed963]14#ifdef HAVE_NTL
15#include "NTLconvert.h"
16#endif
17
[03c742]18#ifdef HAVE_FLINT
19#include "FLINTconvert.h"
20#endif
21
[2dd068]22static bool
23is_irreducible ( const CanonicalForm & f )
24{
25    CFFList F = factorize( f );
26    return F.length() == 1 && F.getFirst().exp() == 1;
27}
28
29CanonicalForm
30find_irreducible ( int deg, CFRandom & gen, const Variable & x )
31{
32    CanonicalForm result;
33    int i;
34    do {
[806c18]35        result = power( x, deg );
36        for ( i = deg-1; i >= 0; i-- )
37            result += gen.generate() * power( x, i );
[2dd068]38    } while ( ! is_irreducible( result ) );
39    return result;
40}
[eed963]41
[03c742]42#if defined(HAVE_NTL) || defined(HAVE_FLINT)
[eed963]43/// computes a random monic irreducible univariate polynomial in x over Fp of
[03c742]44/// degree i via NTL/FLINT
[eed963]45CanonicalForm
46randomIrredpoly (int i, const Variable & x)
47{
48  int p= getCharacteristic();
[03c742]49  #ifdef HAVE_FLINT
50  nmod_poly_t Irredpoly;
51  nmod_poly_init(Irredpoly,p);
52  nmod_poly_randtest_monic_irreducible(Irredpoly, FLINTrandom, i+1);
53  CanonicalForm CFirredpoly=convertnmod_poly_t2FacCF(Irredpoly,Variable(1));
54  nmod_poly_clear(Irredpoly);
55  #elif defined(HAVE_NTL)
[eed963]56  if (fac_NTL_char != p)
57  {
58    fac_NTL_char= p;
59    zz_p::init (p);
60  }
61  zz_pX NTLirredpoly;
62  BuildIrred (NTLirredpoly, i);
[03c742]63  CanonicalForm CFirredpoly= convertNTLzzpX2CF (NTLirredpoly, x);
64  #endif
[eed963]65  return CFirredpoly;
66}
[f4365f]67#endif
Note: See TracBrowser for help on using the repository browser.