My Project  UNKNOWN_GIT_VERSION
Macros | Functions | Variables
imm.h File Reference

operations on immediates, that is elements of F_p, GF, Z, Q that fit into intrinsic int, long More...

#include <stdint.h>
#include <iostream>
#include "cf_assert.h"
#include "cf_defs.h"
#include "cf_globals.h"
#include "ffops.h"
#include "gfops.h"
#include "cf_factory.h"
#include "canonicalform.h"
#include "int_cf.h"

Go to the source code of this file.

Macros

#define OSTREAM   std::ostream
 

Functions

static long imm2int (const InternalCF *const imm)
 
static InternalCFint2imm (long i)
 
InternalCFint2imm_p (long i)
 
InternalCFint2imm_gf (long i)
 
int imm_isone (const InternalCF *const ptr)
 
int imm_isone_p (const InternalCF *const ptr)
 
int imm_isone_gf (const InternalCF *const ptr)
 
int imm_iszero (const InternalCF *const ptr)
 
int imm_iszero_p (const InternalCF *const ptr)
 
int imm_iszero_gf (const InternalCF *const ptr)
 
long imm_intval (const InternalCF *const op)
 
int imm_sign (const InternalCF *const op)
 imm_sign() - return sign of immediate object. More...
 
int imm_cmp (const InternalCF *const lhs, const InternalCF *const rhs)
 imm_cmp(), imm_cmp_p(), imm_cmp_gf() - compare immediate objects. More...
 
int imm_cmp_p (const InternalCF *const lhs, const InternalCF *const rhs)
 
int imm_cmp_gf (const InternalCF *const lhs, const InternalCF *const rhs)
 
InternalCFimm_add (const InternalCF *const lhs, const InternalCF *const rhs)
 
InternalCFimm_add_p (const InternalCF *const lhs, const InternalCF *const rhs)
 
InternalCFimm_add_gf (const InternalCF *const lhs, const InternalCF *const rhs)
 
InternalCFimm_sub (const InternalCF *const lhs, const InternalCF *const rhs)
 
InternalCFimm_sub_p (const InternalCF *const lhs, const InternalCF *const rhs)
 
InternalCFimm_sub_gf (const InternalCF *const lhs, const InternalCF *const rhs)
 
InternalCFimm_mul (InternalCF *lhs, InternalCF *rhs)
 
InternalCFimm_mul_p (const InternalCF *const lhs, const InternalCF *const rhs)
 
InternalCFimm_mul_gf (const InternalCF *const lhs, const InternalCF *const rhs)
 
InternalCFimm_div (const InternalCF *const lhs, const InternalCF *const rhs)
 
InternalCFimm_divrat (const InternalCF *const lhs, const InternalCF *const rhs)
 
InternalCFimm_div_p (const InternalCF *const lhs, const InternalCF *const rhs)
 
InternalCFimm_div_gf (const InternalCF *const lhs, const InternalCF *const rhs)
 
InternalCFimm_mod (const InternalCF *const lhs, const InternalCF *const rhs)
 
InternalCFimm_mod_p (const InternalCF *const, const InternalCF *const)
 
InternalCFimm_mod_gf (const InternalCF *const, const InternalCF *const)
 
void imm_divrem (const InternalCF *const lhs, const InternalCF *const rhs, InternalCF *&q, InternalCF *&r)
 
void imm_divrem_p (const InternalCF *const lhs, const InternalCF *const rhs, InternalCF *&q, InternalCF *&r)
 
void imm_divrem_gf (const InternalCF *const lhs, const InternalCF *const rhs, InternalCF *&q, InternalCF *&r)
 
InternalCFimm_neg (const InternalCF *const op)
 
InternalCFimm_neg_p (const InternalCF *const op)
 
InternalCFimm_neg_gf (const InternalCF *const op)
 
void imm_print (OSTREAM &os, const InternalCF *const op, const char *const str)
 

Variables

const long INTMARK = 1
 
const long FFMARK = 2
 
const long GFMARK = 3
 
const long MINIMMEDIATE = -(1L<<60)+2L
 
const long MAXIMMEDIATE = (1L<<60)-2L
 
const FACTORY_INT64 MINIMMEDIATELL = -268435454LL
 
const FACTORY_INT64 MAXIMMEDIATELL = 268435454LL
 

Detailed Description

operations on immediates, that is elements of F_p, GF, Z, Q that fit into intrinsic int, long

Definition in file imm.h.

Macro Definition Documentation

◆ OSTREAM

#define OSTREAM   std::ostream

Definition at line 20 of file imm.h.

Function Documentation

◆ imm2int()

static long imm2int ( const InternalCF *const  imm)
inlinestatic

Definition at line 70 of file imm.h.

71 {
72  return ((intptr_t)imm) >> 2;
73 }

◆ imm_add()

InternalCF* imm_add ( const InternalCF *const  lhs,
const InternalCF *const  rhs 
)
inline

Definition at line 269 of file imm.h.

270 {
271  long result = imm2int( lhs ) + imm2int( rhs );
272  if ( ( result > MAXIMMEDIATE ) || ( result < MINIMMEDIATE ) )
273  return CFFactory::basic( result );
274  else
275  return int2imm( result );
276 }
static InternalCF * basic(long value)
Definition: cf_factory.cc:30
return result
Definition: facAbsBiFact.cc:76
static long imm2int(const InternalCF *const imm)
Definition: imm.h:70
const long MAXIMMEDIATE
Definition: imm.h:55
static InternalCF * int2imm(long i)
Definition: imm.h:75
const long MINIMMEDIATE
Definition: imm.h:54

◆ imm_add_gf()

InternalCF* imm_add_gf ( const InternalCF *const  lhs,
const InternalCF *const  rhs 
)
inline

Definition at line 283 of file imm.h.

284 {
285  return int2imm_gf( gf_add( imm2int( lhs ), imm2int( rhs ) ) );
286 }
int gf_add(int a, int b)
Definition: gfops.h:133
InternalCF * int2imm_gf(long i)
Definition: imm.h:106

◆ imm_add_p()

InternalCF* imm_add_p ( const InternalCF *const  lhs,
const InternalCF *const  rhs 
)
inline

Definition at line 278 of file imm.h.

279 {
280  return int2imm_p( ff_add( imm2int( lhs ), imm2int( rhs ) ) );
281 }
int ff_add(const int a, const int b)
Definition: ffops.h:97
InternalCF * int2imm_p(long i)
Definition: imm.h:101

◆ imm_cmp()

int imm_cmp ( const InternalCF *const  lhs,
const InternalCF *const  rhs 
)
inline

imm_cmp(), imm_cmp_p(), imm_cmp_gf() - compare immediate objects.

For immediate integers, it is clear how this should be done. For objects from finite fields, it is not clear since they are not ordered fields. However, since we want to have a total well order on polynomials we have to define a total well order on all coefficients, too. We decided to use simply the order on the representation as `int's of such objects.

See also
CanonicalForm::operator <(), CanonicalForm::operator ==()

Definition at line 234 of file imm.h.

235 {
236  if ( imm2int( lhs ) == imm2int( rhs ) )
237  return 0;
238  else if ( imm2int( lhs ) > imm2int( rhs ) )
239  return 1;
240  else
241  return -1;
242 }

◆ imm_cmp_gf()

int imm_cmp_gf ( const InternalCF *const  lhs,
const InternalCF *const  rhs 
)
inline

Definition at line 256 of file imm.h.

257 {
258  if ( imm2int( lhs ) == imm2int( rhs ) )
259  return 0;
260  // check is done in this way because zero should be minimal
261  else if ( imm2int( lhs ) > imm2int( rhs ) )
262  return -1;
263  else
264  return 1;
265 }

◆ imm_cmp_p()

int imm_cmp_p ( const InternalCF *const  lhs,
const InternalCF *const  rhs 
)
inline

Definition at line 245 of file imm.h.

246 {
247  if ( imm2int( lhs ) == imm2int( rhs ) )
248  return 0;
249  else if ( imm2int( lhs ) > imm2int( rhs ) )
250  return 1;
251  else
252  return -1;
253 }

◆ imm_div()

InternalCF* imm_div ( const InternalCF *const  lhs,
const InternalCF *const  rhs 
)
inline

Definition at line 356 of file imm.h.

357 {
358  long a = imm2int( lhs );
359  long b = imm2int( rhs );
360  if ( a > 0 )
361  return int2imm( a / b );
362  else if ( b > 0 )
363  return int2imm( -((b-a-1)/b) );
364  else
365  return int2imm( (-a-b-1)/(-b) );
366 }
CanonicalForm b
Definition: cfModGcd.cc:4044

◆ imm_div_gf()

InternalCF* imm_div_gf ( const InternalCF *const  lhs,
const InternalCF *const  rhs 
)
inline

Definition at line 389 of file imm.h.

390 {
391  return int2imm_gf( gf_div( imm2int( lhs ), imm2int( rhs ) ) );
392 }
int gf_div(int a, int b)
Definition: gfops.h:185

◆ imm_div_p()

InternalCF* imm_div_p ( const InternalCF *const  lhs,
const InternalCF *const  rhs 
)
inline

Definition at line 384 of file imm.h.

385 {
386  return int2imm_p( ff_div( imm2int( lhs ), imm2int( rhs ) ) );
387 }
int ff_div(const int a, const int b)
Definition: ffops.h:163

◆ imm_divrat()

InternalCF* imm_divrat ( const InternalCF *const  lhs,
const InternalCF *const  rhs 
)
inline

Definition at line 368 of file imm.h.

369 {
371  return CFFactory::rational( imm2int( lhs ), imm2int( rhs ) );
372  else {
373  long a = imm2int( lhs );
374  long b = imm2int( rhs );
375  if ( a > 0 )
376  return int2imm( a / b );
377  else if ( b > 0 )
378  return int2imm( -((b-a-1)/b) );
379  else
380  return int2imm( (-a-b-1)/(-b) );
381  }
382 }
static const int SW_RATIONAL
set to 1 for computations over Q
Definition: cf_defs.h:28
CFSwitches cf_glob_switches
CFSwitches cf_glob_switches;.
Definition: cf_switches.cc:41
static InternalCF * rational(long num, long den)
Definition: cf_factory.cc:225
bool isOn(int s) const
check if 's' is on
Definition: cf_switches.h:55

◆ imm_divrem()

void imm_divrem ( const InternalCF *const  lhs,
const InternalCF *const  rhs,
InternalCF *&  q,
InternalCF *&  r 
)
inline

Definition at line 428 of file imm.h.

429 {
430  if ( cf_glob_switches.isOn( SW_RATIONAL ) ) {
431  q = imm_divrat( lhs, rhs );
432  r = CFFactory::basic( 0L );
433  }
434  else {
435  q = imm_div( lhs, rhs );
436  r = imm_mod( lhs, rhs );
437  }
438 }
InternalCF * imm_div(const InternalCF *const lhs, const InternalCF *const rhs)
Definition: imm.h:356
InternalCF * imm_divrat(const InternalCF *const lhs, const InternalCF *const rhs)
Definition: imm.h:368
InternalCF * imm_mod(const InternalCF *const lhs, const InternalCF *const rhs)
Definition: imm.h:394

◆ imm_divrem_gf()

void imm_divrem_gf ( const InternalCF *const  lhs,
const InternalCF *const  rhs,
InternalCF *&  q,
InternalCF *&  r 
)
inline

Definition at line 446 of file imm.h.

447 {
448  q = int2imm_gf( gf_div( imm2int( lhs ), imm2int( rhs ) ) );
449  r = int2imm_gf( gf_q );
450 }
int gf_q
Definition: gfops.cc:47

◆ imm_divrem_p()

void imm_divrem_p ( const InternalCF *const  lhs,
const InternalCF *const  rhs,
InternalCF *&  q,
InternalCF *&  r 
)
inline

Definition at line 440 of file imm.h.

441 {
442  q = int2imm_p( ff_div( imm2int( lhs ), imm2int( rhs ) ) );
443  r = int2imm_p( 0 );
444 }

◆ imm_intval()

long imm_intval ( const InternalCF *const  op)
inline

Definition at line 164 of file imm.h.

165 {
166  if ( is_imm( op ) == FFMARK )
168  return ff_symmetric( imm2int( op ) );
169  else
170  return imm2int( op );
171  else if ( is_imm( op ) == GFMARK ) {
172  ASSERT( gf_isff( imm2int( op ) ), "invalid conversion" );
174  return ff_symmetric( gf_gf2ff( imm2int( op ) ) );
175  else
176  return gf_gf2ff( imm2int( op ) );
177  }
178  else
179  return imm2int( op );
180 }
int is_imm(const InternalCF *const ptr)
Definition: canonicalform.h:62
#define ASSERT(expression, message)
Definition: cf_assert.h:99
static const int SW_SYMMETRIC_FF
set to 1 for symmetric representation over F_q
Definition: cf_defs.h:30
long gf_gf2ff(long a)
Definition: gfops.cc:226
bool gf_isff(long a)
Definition: gfops.cc:270
int ff_symmetric(const int a)
Definition: ffops.h:67
const long FFMARK
Definition: imm.h:38
const long GFMARK
Definition: imm.h:39

◆ imm_isone()

int imm_isone ( const InternalCF *const  ptr)
inline

Definition at line 124 of file imm.h.

125 {
126  return imm2int( ptr ) == 1;
127 }

◆ imm_isone_gf()

int imm_isone_gf ( const InternalCF *const  ptr)
inline

Definition at line 136 of file imm.h.

137 {
138  return gf_isone( imm2int( ptr ) );
139 }
bool gf_isone(int a)
Definition: gfops.h:53

◆ imm_isone_p()

int imm_isone_p ( const InternalCF *const  ptr)
inline

Definition at line 130 of file imm.h.

131 {
132  return imm2int( ptr ) == 1;
133 }

◆ imm_iszero()

int imm_iszero ( const InternalCF *const  ptr)
inline

Definition at line 145 of file imm.h.

146 {
147  return imm2int( ptr ) == 0;
148 }

◆ imm_iszero_gf()

int imm_iszero_gf ( const InternalCF *const  ptr)
inline

Definition at line 157 of file imm.h.

158 {
159  return gf_iszero( imm2int( ptr ) );
160 }
bool gf_iszero(int a)
Definition: gfops.h:43

◆ imm_iszero_p()

int imm_iszero_p ( const InternalCF *const  ptr)
inline

Definition at line 151 of file imm.h.

152 {
153  return imm2int( ptr ) == 0;
154 }

◆ imm_mod()

InternalCF* imm_mod ( const InternalCF *const  lhs,
const InternalCF *const  rhs 
)
inline

Definition at line 394 of file imm.h.

395 {
397  return int2imm( 0 );
398  else {
399  long a = imm2int( lhs );
400  long b = imm2int( rhs );
401  if ( a > 0 )
402  if ( b > 0 )
403  return int2imm( a % b );
404  else
405  return int2imm( a % (-b) );
406  else
407  if ( b > 0 ) {
408  long r = (-a) % b;
409  return int2imm( (r==0) ? r : b-r );
410  }
411  else {
412  long r = (-a) % (-b);
413  return int2imm( (r==0) ? r : -b-r );
414  }
415  }
416 }

◆ imm_mod_gf()

InternalCF* imm_mod_gf ( const InternalCF * const  ,
const InternalCF * const   
)
inline

Definition at line 423 of file imm.h.

424 {
425  return int2imm_gf( gf_q );
426 }

◆ imm_mod_p()

InternalCF* imm_mod_p ( const InternalCF * const  ,
const InternalCF * const   
)
inline

Definition at line 418 of file imm.h.

419 {
420  return int2imm_p( 0 );
421 }

◆ imm_mul()

InternalCF* imm_mul ( InternalCF lhs,
InternalCF rhs 
)
inline

Definition at line 308 of file imm.h.

309 {
310  long a = imm2int( lhs );
311  long b = imm2int( rhs );
312  int sa= 1;
313  unsigned FACTORY_INT64 aa, bb;
314  if (a < 0)
315  {
316  sa= -1;
317  aa= (unsigned FACTORY_INT64) (-a);
318  }
319  else
320  aa= (unsigned FACTORY_INT64) a;
321  if (b < 0)
322  {
323  sa= -sa;
324  bb= (unsigned FACTORY_INT64) (-b);
325  }
326  else
327  bb= (unsigned FACTORY_INT64) b;
328  unsigned FACTORY_INT64 result = aa*bb;
329  #if SIZEOF_LONG == 4
330  if (result>(unsigned FACTORY_INT64)MAXIMMEDIATE)
331  {
333  return res->mulcoeff( rhs );
334  }
335  #else
336  if ( ( a!=0L ) && ((result/aa!=bb) || (result>(unsigned FACTORY_INT64) MAXIMMEDIATE) ))
337  {
339  return res->mulcoeff( rhs );
340  }
341  #endif
342  else
343  return int2imm( sa*result );
344 }
#define IntegerDomain
Definition: cf_defs.h:25
virtual class for internal CanonicalForm's
Definition: int_cf.h:47
CanonicalForm res
Definition: facAbsFact.cc:64
#define FACTORY_INT64
Definition: ffops.h:24

◆ imm_mul_gf()

InternalCF* imm_mul_gf ( const InternalCF *const  lhs,
const InternalCF *const  rhs 
)
inline

Definition at line 351 of file imm.h.

352 {
353  return int2imm_gf( gf_mul( imm2int( lhs ), imm2int( rhs ) ) );
354 }
int gf_mul(int a, int b)
Definition: gfops.h:163

◆ imm_mul_p()

InternalCF* imm_mul_p ( const InternalCF *const  lhs,
const InternalCF *const  rhs 
)
inline

Definition at line 346 of file imm.h.

347 {
348  return int2imm_p( ff_mul( imm2int( lhs ), imm2int( rhs ) ) );
349 }
int ff_mul(const int a, const int b)
Definition: ffops.h:139

◆ imm_neg()

InternalCF* imm_neg ( const InternalCF *const  op)
inline

Definition at line 455 of file imm.h.

456 {
457  return int2imm( -imm2int( op ) );
458 }

◆ imm_neg_gf()

InternalCF* imm_neg_gf ( const InternalCF *const  op)
inline

Definition at line 467 of file imm.h.

468 {
469  return int2imm_gf( gf_neg( imm2int( op ) ) );
470 }
int gf_neg(int a)
Definition: gfops.h:123

◆ imm_neg_p()

InternalCF* imm_neg_p ( const InternalCF *const  op)
inline

Definition at line 461 of file imm.h.

462 {
463  return int2imm_p( ff_neg( imm2int( op ) ) );
464 }
int ff_neg(const int a)
Definition: ffops.h:126

◆ imm_print()

void imm_print ( OSTREAM os,
const InternalCF *const  op,
const char *const  str 
)
inline

Definition at line 476 of file imm.h.

477 {
478  if ( is_imm( op ) == FFMARK )
480  os << ff_symmetric( imm2int( op ) ) << str;
481  else
482  os << imm2int( op ) << str;
483  else if ( is_imm( op ) == GFMARK ) {
484  gf_print( os, imm2int( op ) );
485  os << str;
486  }
487  else
488  os << imm2int( op ) << str;
489 }
void gf_print(OSTREAM &os, int a)
Definition: gfops.h:207

◆ imm_sign()

int imm_sign ( const InternalCF *const  op)
inline

imm_sign() - return sign of immediate object.

If CO is an immediate integer, the sign is defined as usual. If CO is an element of FF(p) and SW_SYMMETRIC_FF is on the sign of CO is the sign of the symmetric representation of CO. If CO is in GF(q) or in FF(p) and SW_SYMMETRIC_FF is off, the sign of CO is zero iff CO is zero, otherwise the sign is one.

See also
CanonicalForm::sign(), gf_sign()

Definition at line 197 of file imm.h.

198 {
199  if ( is_imm( op ) == FFMARK )
200  if ( imm2int( op ) == 0 )
201  return 0;
202  else if ( cf_glob_switches.isOn( SW_SYMMETRIC_FF ) )
203  if ( ff_symmetric( imm2int( op ) ) > 0 )
204  return 1;
205  else
206  return -1;
207  else
208  return 1;
209  else if ( is_imm( op ) == GFMARK )
210  return gf_sign( imm2int( op ) );
211  else if ( imm2int( op ) == 0 )
212  return 0;
213  else if ( imm2int( op ) > 0 )
214  return 1;
215  else
216  return -1;
217 }
int gf_sign(int a)
Definition: gfops.h:113

◆ imm_sub()

InternalCF* imm_sub ( const InternalCF *const  lhs,
const InternalCF *const  rhs 
)
inline

Definition at line 288 of file imm.h.

289 {
290  long result = imm2int( lhs ) - imm2int( rhs );
291  if ( ( result > MAXIMMEDIATE ) || ( result < MINIMMEDIATE ) )
292  return CFFactory::basic( result );
293  else
294  return int2imm( result );
295 }

◆ imm_sub_gf()

InternalCF* imm_sub_gf ( const InternalCF *const  lhs,
const InternalCF *const  rhs 
)
inline

Definition at line 302 of file imm.h.

303 {
304  return int2imm_gf( gf_sub( imm2int( lhs ), imm2int( rhs ) ) );
305 }
int gf_sub(int a, int b)
Definition: gfops.h:158

◆ imm_sub_p()

InternalCF* imm_sub_p ( const InternalCF *const  lhs,
const InternalCF *const  rhs 
)
inline

Definition at line 297 of file imm.h.

298 {
299  return int2imm_p( ff_sub( imm2int( lhs ), imm2int( rhs ) ) );
300 }
int ff_sub(const int a, const int b)
Definition: ffops.h:112

◆ int2imm()

static InternalCF* int2imm ( long  i)
inlinestatic

Definition at line 75 of file imm.h.

76 {
77  return (InternalCF*)((i << 2) | INTMARK );
78 }
int i
Definition: cfEzgcd.cc:125
const long INTMARK
Definition: imm.h:37

◆ int2imm_gf()

InternalCF* int2imm_gf ( long  i)
inline

Definition at line 106 of file imm.h.

107 {
108  return (InternalCF*)((i << 2) | GFMARK );
109 }

◆ int2imm_p()

InternalCF* int2imm_p ( long  i)
inline

Definition at line 101 of file imm.h.

102 {
103  return (InternalCF*)((i << 2) | FFMARK );
104 }

Variable Documentation

◆ FFMARK

const long FFMARK = 2

Definition at line 38 of file imm.h.

◆ GFMARK

const long GFMARK = 3

Definition at line 39 of file imm.h.

◆ INTMARK

const long INTMARK = 1

Definition at line 37 of file imm.h.

◆ MAXIMMEDIATE

const long MAXIMMEDIATE = (1L<<60)-2L

Definition at line 55 of file imm.h.

◆ MAXIMMEDIATELL

const FACTORY_INT64 MAXIMMEDIATELL = 268435454LL

Definition at line 63 of file imm.h.

◆ MINIMMEDIATE

const long MINIMMEDIATE = -(1L<<60)+2L

Definition at line 54 of file imm.h.

◆ MINIMMEDIATELL

const FACTORY_INT64 MINIMMEDIATELL = -268435454LL

Definition at line 62 of file imm.h.