Loading...
Searching...
No Matches
cf_irred.cc
Go to the documentation of this file.
/* emacs edit mode for this file is -*- C++ -*- */
#include "config.h"
#include "cf_assert.h"
#include "cf_defs.h"
#include "canonicalform.h"
#include "cf_algorithm.h"
#include "cf_random.h"
#ifdef HAVE_NTL
#include "NTLconvert.h"
#endif
#ifdef HAVE_FLINT
#include "FLINTconvert.h"
#endif
#if defined(HAVE_NTL) || defined(HAVE_FLINT)
/// computes a random monic irreducible univariate polynomial in x over Fp of
/// degree i via NTL/FLINT
CanonicalForm
randomIrredpoly (int i, const Variable & x)
{
int p= getCharacteristic();
#ifdef HAVE_FLINT
nmod_poly_t Irredpoly;
nmod_poly_init(Irredpoly,p);
nmod_poly_randtest_monic_irreducible(Irredpoly, FLINTrandom, i+1);
CanonicalForm CFirredpoly=convertnmod_poly_t2FacCF(Irredpoly,x);
nmod_poly_clear(Irredpoly);
#elif defined(HAVE_NTL)
if (fac_NTL_char != p)
{
fac_NTL_char= p;
zz_p::init (p);
}
zz_pX NTLirredpoly;
BuildIrred (NTLirredpoly, i);
CanonicalForm CFirredpoly= convertNTLzzpX2CF (NTLirredpoly, x);
#else
factoryError("NTL/FLINT missing: randomIrredpoly");
#endif
return CFirredpoly;
}
#else
static bool
is_irreducible ( const CanonicalForm & f )
{
CFFList F = factorize( f );
return F.length() == 1 && F.getFirst().exp() == 1;
}
CanonicalForm
find_irreducible ( int deg, CFRandom & gen, const Variable & x )
{
CanonicalForm result;
int i;
do {
result = power( x, deg );
for ( i = deg-1; i >= 0; i-- )
result += gen.generate() * power( x, i );
} while ( ! is_irreducible( result ) );
return result;
}
#endif
convertnmod_poly_t2FacCF
CanonicalForm convertnmod_poly_t2FacCF(const nmod_poly_t poly, const Variable &x)
conversion of a FLINT poly over Z/p to CanonicalForm
Definition FLINTconvert.cc:208
FLINTconvert.h
This file defines functions for conversion to FLINT (www.flintlib.org) and back.
convertNTLzzpX2CF
CanonicalForm convertNTLzzpX2CF(const zz_pX &poly, const Variable &x)
Definition NTLconvert.cc:255
fac_NTL_char
VAR long fac_NTL_char
Definition NTLconvert.cc:46
NTLconvert.h
Conversion to and from NTL.
power
CanonicalForm power(const CanonicalForm &f, int n)
exponentiation
Definition canonicalform.cc:1896
canonicalform.h
Header for factory's main class CanonicalForm.
CFFList
List< CFFactor > CFFList
Definition canonicalform.h:393
getCharacteristic
int FACTORY_PUBLIC getCharacteristic()
Definition cf_char.cc:70
i
int i
Definition cfEzgcd.cc:132
x
Variable x
Definition cfModGcd.cc:4090
p
int p
Definition cfModGcd.cc:4086
cf_algorithm.h
declarations of higher level algorithms.
factorize
CFFList FACTORY_PUBLIC factorize(const CanonicalForm &f, bool issqrfree=false)
factorization over or
Definition cf_factor.cc:409
cf_assert.h
assertions for Factory
cf_defs.h
factory switches.
randomIrredpoly
CanonicalForm randomIrredpoly(int i, const Variable &x)
computes a random monic irreducible univariate polynomial in x over Fp of degree i via NTL/FLINT
Definition cf_irred.cc:26
find_irreducible
CanonicalForm find_irreducible(int deg, CFRandom &gen, const Variable &x)
generate a random irreducible polynomial in x of degree deg
FLINTrandom
GLOBAL_VAR flint_rand_t FLINTrandom
Definition cf_random.cc:23
cf_random.h
generate random integers, random elements of finite fields
factoryError
VAR void(* factoryError)(const char *s)
Definition cf_util.cc:80
f
FILE * f
Definition checklibs.c:9
CFRandom
virtual class for random element generation
Definition cf_random.h:21
CFRandom::generate
virtual CanonicalForm generate() const
Definition cf_random.h:24
CanonicalForm
factory's main class
Definition canonicalform.h:86
Factor::exp
int exp() const
Definition ftmpl_factor.h:31
List::getFirst
T getFirst() const
Definition ftmpl_list.cc:279
List::length
int length() const
Definition ftmpl_list.cc:273
Variable
factory's class for variables
Definition factory.h:127
result
return result
Definition facAbsBiFact.cc:76
nmod_poly_init
nmod_poly_init(FLINTmipo, getCharacteristic())
nmod_poly_clear
nmod_poly_clear(FLINTmipo)