Functions
cf_irred.cc File Reference
#include "config.h"
#include "cf_assert.h"
#include "cf_defs.h"
#include "canonicalform.h"
#include "cf_algorithm.h"
#include "cf_random.h"
#include "NTLconvert.h"

Go to the source code of this file.

Functions

static bool is_irreducible (const CanonicalForm &f)
 
CanonicalForm find_irreducible (int deg, CFRandom &gen, const Variable &x)
 generate a random irreducible polynomial in x of degree deg More...
 
CanonicalForm randomIrredpoly (int i, const Variable &x)
 computes a random monic irreducible univariate polynomial in x over Fp of degree i via NTL More...
 

Function Documentation

◆ find_irreducible()

CanonicalForm find_irreducible ( int  deg,
CFRandom gen,
const Variable x 
)

generate a random irreducible polynomial in x of degree deg

Warning
this is done in the most naive way, i.e. a random is generated and then factorized

Definition at line 26 of file cf_irred.cc.

27 {
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 }
CanonicalForm power(const CanonicalForm &f, int n)
exponentiation
factory's main class
Definition: canonicalform.h:75
virtual CanonicalForm generate() const
Definition: cf_random.h:24
int i
Definition: cfEzgcd.cc:123
static bool is_irreducible(const CanonicalForm &f)
Definition: cf_irred.cc:19
Variable x
Definition: cfModGcd.cc:4023
return result
Definition: facAbsBiFact.cc:76

◆ is_irreducible()

static bool is_irreducible ( const CanonicalForm f)
static

Definition at line 19 of file cf_irred.cc.

20 {
21  CFFList F = factorize( f );
22  return F.length() == 1 && F.getFirst().exp() == 1;
23 }
T getFirst() const
Definition: ftmpl_list.cc:279
CFFList factorize(const CanonicalForm &f, bool issqrfree=false)
factorization over or
Definition: cf_factor.cc:390
FILE * f
Definition: checklibs.c:9
int length() const
Definition: ftmpl_list.cc:273

◆ randomIrredpoly()

CanonicalForm randomIrredpoly ( int  i,
const Variable x 
)

computes a random monic irreducible univariate polynomial in x over Fp of degree i via NTL

Definition at line 42 of file cf_irred.cc.

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 }
return P p
Definition: myNF.cc:203
factory's main class
Definition: canonicalform.h:75
CanonicalForm convertNTLzzpX2CF(const zz_pX &poly, const Variable &x)
Definition: NTLconvert.cc:251
int getCharacteristic()
Definition: cf_char.cc:51
int i
Definition: cfEzgcd.cc:123
Variable x
Definition: cfModGcd.cc:4023
long fac_NTL_char
Definition: NTLconvert.cc:44