Loading...
Searching...
No Matches
cf_factory.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 "cf_factory.h"
#include "canonicalform.h"
#include "int_cf.h"
#include "int_int.h"
#include "int_rat.h"
#include "int_poly.h"
#include "int_pp.h"
#include "imm.h"
/// For optimizing if-branches
#ifdef __GNUC__
#define LIKELY(expression) (__builtin_expect(!!(expression), 1))
#define UNLIKELY(expression) (__builtin_expect(!!(expression), 0))
#else
#define LIKELY(expression) (expression)
#define UNLIKELY(expression) (expression)
#endif
int CFFactory::currenttype = IntegerDomain;
InternalCF *
CFFactory::basic ( long value )
{
switch(currenttype)
{
case IntegerDomain:
if (LIKELY( value >= MINIMMEDIATE && value <= MAXIMMEDIATE ))
return int2imm( value );
else
return new InternalInteger( value );
// else if ( currenttype == RationalDomain )
// if ( value >= MINIMMEDIATE && value <= MAXIMMEDIATE )
// return int2imm( value );
// else
// return new InternalRational( value );
case FiniteFieldDomain:
return int2imm_p( ff_norm( value ) );
case GaloisFieldDomain:
return int2imm_gf( gf_int2gf( value ) );
#ifndef HAVE_NTL
case PrimePowerDomain:
return new InternalPrimePower( value );
#endif
default: {
ASSERT( 0, "illegal basic domain!" );
return 0;
}
}
}
InternalCF *
CFFactory::basic ( int value )
{
switch(currenttype)
{
case IntegerDomain:
#if SIZEOF_LONG == 8
return int2imm( value );
#else
if (LIKELY( value >= MINIMMEDIATE && value <= MAXIMMEDIATE ))
return int2imm( value );
else
return new InternalInteger( value );
#endif
case RationalDomain:
#if SIZEOF_LONG == 8
return int2imm( value );
#else
if (LIKELY( value >= MINIMMEDIATE && value <= MAXIMMEDIATE ))
return int2imm( value );
else
return new InternalRational( value );
#endif
case FiniteFieldDomain:
return int2imm_p( ff_norm( value ) );
case GaloisFieldDomain:
return int2imm_gf( gf_int2gf( value ) );
#ifndef HAVE_NTL
case PrimePowerDomain:
return new InternalPrimePower( value );
#endif
default: {
ASSERT( 0, "illegal basic domain!" );
return 0;
}
}
}
InternalCF *
CFFactory::basic ( int type, long value )
{
if ( type == IntegerDomain )
if (LIKELY( value >= MINIMMEDIATE && value <= MAXIMMEDIATE ))
return int2imm( value );
else
return new InternalInteger( value );
// else if ( type == RationalDomain )
// if ( value >= MINIMMEDIATE && value <= MAXIMMEDIATE )
// return int2imm( value );
// else
// return new InternalRational( value );
else if ( type == FiniteFieldDomain )
return int2imm_p( ff_norm( value ) );
else if ( type == GaloisFieldDomain )
return int2imm_gf( gf_int2gf( value ) );
else {
ASSERT1( 0, "illegal basic domain (type = %d)!", type );
return 0;
}
}
InternalCF *
CFFactory::basic ( const char * str )
{
if ( currenttype == IntegerDomain ) {
InternalInteger * dummy = new InternalInteger( str );
if ( dummy->is_imm() ) {
InternalCF * res = int2imm( dummy->intval() );
delete dummy;
return res;
}
else
return dummy;
}
// else if ( currenttype == RationalDomain ) {
// InternalRational * dummy = new InternalRational( str );
// if ( dummy->is_imm() ) {
// InternalCF * res = int2imm( dummy->intval() );
// delete dummy;
// return res;
// }
// else
// return dummy;
// }
else if ( currenttype == FiniteFieldDomain ) {
InternalInteger * dummy = new InternalInteger( str );
InternalCF * res = int2imm_p( dummy->intmod( ff_prime ) );
delete dummy;
return res;
}
else if ( currenttype == GaloisFieldDomain ) {
InternalInteger * dummy = new InternalInteger( str );
InternalCF * res = int2imm_gf( gf_int2gf( dummy->intmod( ff_prime ) ) );
delete dummy;
return res;
}
else {
ASSERT( 0, "illegal basic domain!" );
return 0;
}
}
InternalCF *
CFFactory::basic ( const char * str, int base )
{
if ( currenttype == IntegerDomain ) {
InternalInteger * dummy = new InternalInteger( str, base );
if ( dummy->is_imm() ) {
InternalCF * res = int2imm( dummy->intval() );
delete dummy;
return res;
}
else
return dummy;
}
// else if ( currenttype == RationalDomain ) {
// InternalRational * dummy = new InternalRational( str );
// if ( dummy->is_imm() ) {
// InternalCF * res = int2imm( dummy->intval() );
// delete dummy;
// return res;
// }
// else
// return dummy;
// }
else if ( currenttype == FiniteFieldDomain ) {
InternalInteger * dummy = new InternalInteger( str, base );
InternalCF * res = int2imm_p( dummy->intmod( ff_prime ) );
delete dummy;
return res;
}
else if ( currenttype == GaloisFieldDomain ) {
InternalInteger * dummy = new InternalInteger( str, base );
InternalCF * res = int2imm_gf( gf_int2gf( dummy->intmod( ff_prime ) ) );
delete dummy;
return res;
}
else {
ASSERT( 0, "illegal basic domain!" );
return 0;
}
}
InternalCF *
CFFactory::basic ( int type, const char * const str )
{
if ( type == IntegerDomain ) {
InternalInteger * dummy = new InternalInteger( str );
if ( dummy->is_imm() ) {
InternalCF * res = int2imm( dummy->intval() );
delete dummy;
return res;
}
else
return dummy;
}
// else if ( type == RationalDomain ) {
// InternalRational * dummy = new InternalRational( str );
// if ( dummy->is_imm() ) {
// InternalCF * res = int2imm( dummy->intval() );
// delete dummy;
// return res;
// }
// else
// return dummy;
// }
else if ( type == FiniteFieldDomain ) {
InternalInteger * dummy = new InternalInteger( str );
InternalCF * res = int2imm( dummy->intmod( ff_prime ) );
delete dummy;
return res;
}
else if ( type == GaloisFieldDomain ) {
InternalInteger * dummy = new InternalInteger( str );
InternalCF * res = int2imm_gf( gf_int2gf( dummy->intmod( ff_prime ) ) );
delete dummy;
return res;
}
else {
ASSERT( 0, "illegal basic domain!" );
return 0;
}
}
InternalCF *
CFFactory::basic ( int type, long value, bool nonimm )
{
if ( nonimm )
if ( type == IntegerDomain )
return new InternalInteger( value );
else if ( type == RationalDomain )
return new InternalRational( value );
else {
ASSERT( 0, "illegal basic domain!" );
return 0;
}
else
return CFFactory::basic( type, value );
}
InternalCF *
CFFactory::basic ( const mpz_ptr num )
{
ASSERT (currenttype == IntegerDomain, "Integer domain expected");
return new InternalInteger( num );
}
InternalCF *
CFFactory::rational ( long num, long den )
{
InternalRational * res = new InternalRational( num, den );
return res->normalize_myself();
}
InternalCF *
CFFactory::rational ( const mpz_ptr num, const mpz_ptr den, bool normalize )
{
if ( normalize ) {
InternalRational * result = new InternalRational( num, den );
return result->normalize_myself();
}
else
return new InternalRational( num, den );
}
InternalCF *
CFFactory::poly ( const Variable & v, int exp, const CanonicalForm & c )
{
if ( v.level() == LEVELBASE )
return c.getval();
else
return new InternalPoly( v, exp, c );
}
InternalCF *
CFFactory::poly ( const Variable & v, int exp )
{
if ( v.level() == LEVELBASE )
return CFFactory::basic( 1L );
else
return new InternalPoly( v, exp, 1 );
}
void getmpi ( InternalCF * value, mpz_t mpi)
{
ASSERT( ! is_imm( value ) && (value->levelcoeff() == IntegerDomain || value->levelcoeff() == PrimePowerDomain), "illegal operation" );
mpz_init_set (mpi, ((InternalInteger*)value)->thempi);
}
LIKELY
#define LIKELY(X)
Definition auxiliary.h:404
canonicalform.h
Header for factory's main class CanonicalForm.
is_imm
int is_imm(const InternalCF *const ptr)
Definition canonicalform.h:65
num
CanonicalForm num(const CanonicalForm &f)
Definition canonicalform.h:337
den
CanonicalForm den(const CanonicalForm &f)
Definition canonicalform.h:340
cf_assert.h
assertions for Factory
ASSERT1
#define ASSERT1(expression, message, parameter1)
Definition cf_assert.h:101
ASSERT
#define ASSERT(expression, message)
Definition cf_assert.h:99
cf_defs.h
factory switches.
LEVELBASE
#define LEVELBASE
Definition cf_defs.h:25
PrimePowerDomain
#define PrimePowerDomain
Definition cf_defs.h:17
FiniteFieldDomain
#define FiniteFieldDomain
Definition cf_defs.h:19
RationalDomain
#define RationalDomain
Definition cf_defs.h:20
IntegerDomain
#define IntegerDomain
Definition cf_defs.h:21
GaloisFieldDomain
#define GaloisFieldDomain
Definition cf_defs.h:18
getmpi
void getmpi(InternalCF *value, mpz_t mpi)
Definition cf_factory.cc:303
cf_factory.h
Interface to generate InternalCF's over various domains from intrinsic types or mpz_t's.
CFFactory::basic
static InternalCF * basic(int value)
Definition cf_factory.cc:61
CFFactory::poly
static InternalCF * poly(const Variable &v, int exp, const CanonicalForm &c)
Definition cf_factory.cc:286
CFFactory::rational
static InternalCF * rational(long num, long den)
Definition cf_factory.cc:268
CFFactory::currenttype
static int currenttype
Definition cf_factory.h:26
CanonicalForm
factory's main class
Definition canonicalform.h:86
CanonicalForm::getval
InternalCF * getval() const
Definition canonicalform.cc:34
InternalCF
virtual class for internal CanonicalForm's
Definition int_cf.h:47
InternalCF::InternalCF
InternalCF()
Definition int_cf.h:55
InternalCF::levelcoeff
virtual int levelcoeff() const
Definition int_cf.h:68
InternalInteger
factory's class for integers
Definition int_int.h:56
InternalInteger::thempi
mpz_t thempi
Definition int_int.h:58
InternalInteger::InternalInteger
InternalInteger()
Definition int_int.h:85
InternalInteger::intval
long intval() const
Definition int_int.cc:506
InternalInteger::is_imm
bool is_imm() const
Definition int_int.cc:41
InternalInteger::intmod
int intmod(int p) const
Definition int_int.cc:511
InternalPoly
factory's class for polynomials
Definition int_poly.h:71
InternalPrimePower
Definition int_pp.h:27
InternalRational
factory's class for rationals
Definition int_rat.h:55
Variable
factory's class for variables
Definition factory.h:127
result
return result
Definition facAbsBiFact.cc:76
res
CanonicalForm res
Definition facAbsFact.cc:60
v
const Variable & v
< [in] a sqrfree bivariate poly
Definition facBivar.h:39
ff_prime
VAR int ff_prime
Definition ffops.cc:23
ff_norm
int ff_norm(const int a)
Definition ffops.h:39
gf_int2gf
int gf_int2gf(int i)
Definition gfops.h:65
imm.h
operations on immediates, that is elements of F_p, GF, Z, Q that fit into intrinsic int,...
MAXIMMEDIATE
const long MAXIMMEDIATE
Definition imm.h:55
int2imm_p
InternalCF * int2imm_p(long i)
Definition imm.h:101
MINIMMEDIATE
const long MINIMMEDIATE
Definition imm.h:54
int2imm_gf
InternalCF * int2imm_gf(long i)
Definition imm.h:106
int2imm
static InternalCF * int2imm(long i)
Definition imm.h:75
int_cf.h
Factory's internal CanonicalForm's.
int_int.h
Factory's internal integers.
int_poly.h
Factory's internal polynomials.
int_pp.h
int_rat.h
Factory's internal rationals.
exp
gmp_float exp(const gmp_float &a)
Definition mpr_complex.cc:349
normalize
static poly normalize(poly next_p, ideal add_generators, syStrategy syzstr, int *g_l, int *p_l, int crit_comp)
Definition syz3.cc:1027