source: git/factory/cf_irred.cc @ f5c2fcf

fieker-DuValspielwiese
Last change on this file since f5c2fcf was 03c742, checked in by Hans Schoenemann <hannes@…>, 4 years ago
factory: BuildIrred, FLINT/NTL seperation
  • Property mode set to 100644
File size: 1.5 KB
Line 
1/* emacs edit mode for this file is -*- C++ -*- */
2
3
4#include "config.h"
5
6
7#include "cf_assert.h"
8
9#include "cf_defs.h"
10#include "canonicalform.h"
11#include "cf_algorithm.h"
12#include "cf_random.h"
13
14#ifdef HAVE_NTL
15#include "NTLconvert.h"
16#endif
17
18#ifdef HAVE_FLINT
19#include "FLINTconvert.h"
20#endif
21
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 {
35        result = power( x, deg );
36        for ( i = deg-1; i >= 0; i-- )
37            result += gen.generate() * power( x, i );
38    } while ( ! is_irreducible( result ) );
39    return result;
40}
41
42#if defined(HAVE_NTL) || defined(HAVE_FLINT)
43/// computes a random monic irreducible univariate polynomial in x over Fp of
44/// degree i via NTL/FLINT
45CanonicalForm
46randomIrredpoly (int i, const Variable & x)
47{
48  int p= getCharacteristic();
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)
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);
63  CanonicalForm CFirredpoly= convertNTLzzpX2CF (NTLirredpoly, x);
64  #endif
65  return CFirredpoly;
66}
67#endif
Note: See TracBrowser for help on using the repository browser.