source: git/factory/cf_irred.cc @ 517ffa

fieker-DuValspielwiese
Last change on this file since 517ffa was f4365f, checked in by Martin Lee <martinlee84@…>, 10 years ago
fix: compilation without NTL
  • Property mode set to 100644
File size: 1.1 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
18static bool
19is_irreducible ( const CanonicalForm & f )
20{
21    CFFList F = factorize( f );
22    return F.length() == 1 && F.getFirst().exp() == 1;
23}
24
25CanonicalForm
26find_irreducible ( int deg, CFRandom & gen, const Variable & x )
27{
28    CanonicalForm result;
29    int i;
30    do {
31        result = power( x, deg );
32        for ( i = deg-1; i >= 0; i-- )
33            result += gen.generate() * power( x, i );
34    } while ( ! is_irreducible( result ) );
35    return result;
36}
37
38#ifdef HAVE_NTL
39/// computes a random monic irreducible univariate polynomial in x over Fp of
40/// degree i via NTL
41CanonicalForm
42randomIrredpoly (int i, const Variable & x)
43{
44  int p= getCharacteristic();
45  if (fac_NTL_char != p)
46  {
47    fac_NTL_char= p;
48    zz_p::init (p);
49  }
50  zz_pX NTLirredpoly;
51  CanonicalForm CFirredpoly;
52  BuildIrred (NTLirredpoly, i);
53  CFirredpoly= convertNTLzzpX2CF (NTLirredpoly, x);
54  return CFirredpoly;
55}
56#endif
Note: See TracBrowser for help on using the repository browser.