My Project
Loading...
Searching...
No Matches
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)
 

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 272 of file imm.h.

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

◆ imm_add_gf()

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

Definition at line 286 of file imm.h.

287{
288 return int2imm_gf( gf_add( imm2int( lhs ), imm2int( rhs ) ) );
289}
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 281 of file imm.h.

282{
283 return int2imm_p( ff_add( imm2int( lhs ), imm2int( rhs ) ) );
284}
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 237 of file imm.h.

238{
239 if ( imm2int( lhs ) == imm2int( rhs ) )
240 return 0;
241 else if ( imm2int( lhs ) > imm2int( rhs ) )
242 return 1;
243 else
244 return -1;
245}

◆ imm_cmp_gf()

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

Definition at line 259 of file imm.h.

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

◆ imm_cmp_p()

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

Definition at line 248 of file imm.h.

249{
250 if ( imm2int( lhs ) == imm2int( rhs ) )
251 return 0;
252 else if ( imm2int( lhs ) > imm2int( rhs ) )
253 return 1;
254 else
255 return -1;
256}

◆ imm_div()

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

Definition at line 361 of file imm.h.

362{
363 long a = imm2int( lhs );
364 long b = imm2int( rhs );
365 if ( a > 0 )
366 return int2imm( a / b );
367 else if ( b > 0 )
368 return int2imm( -((b-a-1)/b) );
369 else
370 return int2imm( (-a-b-1)/(-b) );
371}
CanonicalForm b
Definition: cfModGcd.cc:4103

◆ imm_div_gf()

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

Definition at line 394 of file imm.h.

395{
396 return int2imm_gf( gf_div( imm2int( lhs ), imm2int( rhs ) ) );
397}
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 389 of file imm.h.

390{
391 return int2imm_p( ff_div( imm2int( lhs ), imm2int( rhs ) ) );
392}
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 373 of file imm.h.

374{
376 return CFFactory::rational( imm2int( lhs ), imm2int( rhs ) );
377 else {
378 long a = imm2int( lhs );
379 long b = imm2int( rhs );
380 if ( a > 0 )
381 return int2imm( a / b );
382 else if ( b > 0 )
383 return int2imm( -((b-a-1)/b) );
384 else
385 return int2imm( (-a-b-1)/(-b) );
386 }
387}
static const int SW_RATIONAL
set to 1 for computations over Q
Definition: cf_defs.h:31
INST_VAR CFSwitches cf_glob_switches
Definition: cf_switches.cc:54
static InternalCF * rational(long num, long den)
Definition: cf_factory.cc:268
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 433 of file imm.h.

434{
436 q = imm_divrat( lhs, rhs );
437 r = CFFactory::basic( 0L );
438 }
439 else {
440 q = imm_div( lhs, rhs );
441 r = imm_mod( lhs, rhs );
442 }
443}
InternalCF * imm_div(const InternalCF *const lhs, const InternalCF *const rhs)
Definition: imm.h:361
InternalCF * imm_mod(const InternalCF *const lhs, const InternalCF *const rhs)
Definition: imm.h:399
InternalCF * imm_divrat(const InternalCF *const lhs, const InternalCF *const rhs)
Definition: imm.h:373

◆ imm_divrem_gf()

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

Definition at line 451 of file imm.h.

452{
453 q = int2imm_gf( gf_div( imm2int( lhs ), imm2int( rhs ) ) );
454 r = int2imm_gf( gf_q );
455}
VAR 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 445 of file imm.h.

446{
447 q = int2imm_p( ff_div( imm2int( lhs ), imm2int( rhs ) ) );
448 r = int2imm_p( 0 );
449}

◆ 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 )
167 {
169 return ff_symmetric( imm2int( op ) );
170 else
171 return imm2int( op );
172 }
173 else if ( is_imm( op ) == GFMARK )
174 {
175 ASSERT( gf_isff( imm2int( op ) ), "invalid conversion" );
177 return ff_symmetric( gf_gf2ff( imm2int( op ) ) );
178 else
179 return gf_gf2ff( imm2int( op ) );
180 }
181 /*else*/
182 return imm2int( op );
183}
int is_imm(const InternalCF *const ptr)
Definition: canonicalform.h:65
#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:33
int ff_symmetric(const int a)
Definition: ffops.h:67
long gf_gf2ff(long a)
Definition: gfops.cc:209
bool gf_isff(long a)
Definition: gfops.cc:253
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 399 of file imm.h.

400{
402 return int2imm( 0 );
403 else {
404 long a = imm2int( lhs );
405 long b = imm2int( rhs );
406 if ( a > 0 )
407 if ( b > 0 )
408 return int2imm( a % b );
409 else
410 return int2imm( a % (-b) );
411 else
412 if ( b > 0 ) {
413 long r = (-a) % b;
414 return int2imm( (r==0) ? r : b-r );
415 }
416 else {
417 long r = (-a) % (-b);
418 return int2imm( (r==0) ? r : -b-r );
419 }
420 }
421}

◆ imm_mod_gf()

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

Definition at line 428 of file imm.h.

429{
430 return int2imm_gf( gf_q );
431}

◆ imm_mod_p()

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

Definition at line 423 of file imm.h.

424{
425 return int2imm_p( 0 );
426}

◆ imm_mul()

InternalCF * imm_mul ( InternalCF lhs,
InternalCF rhs 
)
inline

Definition at line 311 of file imm.h.

312{
313 long a = imm2int( lhs );
314 if (a == 0L)
315 return int2imm(0);
316 long b = imm2int( rhs );
317 int sa= 1;
318 unsigned FACTORY_INT64 aa, bb;
319 if (a < 0)
320 {
321 sa= -1;
322 aa= (unsigned FACTORY_INT64) (-a);
323 }
324 else
325 aa= (unsigned FACTORY_INT64) a;
326 if (b < 0)
327 {
328 sa= -sa;
329 bb= (unsigned FACTORY_INT64) (-b);
330 }
331 else
332 bb= (unsigned FACTORY_INT64) b;
333 unsigned FACTORY_INT64 result = aa*bb;
334 #if SIZEOF_LONG == 4
335 if (result>(unsigned FACTORY_INT64)MAXIMMEDIATE)
336 {
338 return res->mulcoeff( rhs );
339 }
340 #else
341 if ( ((result/aa!=bb) || (result>(unsigned FACTORY_INT64) MAXIMMEDIATE) ))
342 {
344 return res->mulcoeff( rhs );
345 }
346 #endif
347 else
348 return int2imm( sa*result );
349}
#define IntegerDomain
Definition: cf_defs.h:21
virtual class for internal CanonicalForm's
Definition: int_cf.h:47
CanonicalForm res
Definition: facAbsFact.cc:60
#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 356 of file imm.h.

357{
358 return int2imm_gf( gf_mul( imm2int( lhs ), imm2int( rhs ) ) );
359}
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 351 of file imm.h.

352{
353 return int2imm_p( ff_mul( imm2int( lhs ), imm2int( rhs ) ) );
354}
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 460 of file imm.h.

461{
462 return int2imm( -imm2int( op ) );
463}

◆ imm_neg_gf()

InternalCF * imm_neg_gf ( const InternalCF *const  op)
inline

Definition at line 472 of file imm.h.

473{
474 return int2imm_gf( gf_neg( imm2int( op ) ) );
475}
int gf_neg(int a)
Definition: gfops.h:123

◆ imm_neg_p()

InternalCF * imm_neg_p ( const InternalCF *const  op)
inline

Definition at line 466 of file imm.h.

467{
468 return int2imm_p( ff_neg( imm2int( op ) ) );
469}
int ff_neg(const int a)
Definition: ffops.h:126

◆ 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 200 of file imm.h.

201{
202 if ( is_imm( op ) == FFMARK )
203 if ( imm2int( op ) == 0 )
204 return 0;
206 if ( ff_symmetric( imm2int( op ) ) > 0 )
207 return 1;
208 else
209 return -1;
210 else
211 return 1;
212 else if ( is_imm( op ) == GFMARK )
213 return gf_sign( imm2int( op ) );
214 else if ( imm2int( op ) == 0 )
215 return 0;
216 else if ( imm2int( op ) > 0 )
217 return 1;
218 else
219 return -1;
220}
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 291 of file imm.h.

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

◆ imm_sub_gf()

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

Definition at line 305 of file imm.h.

306{
307 return int2imm_gf( gf_sub( imm2int( lhs ), imm2int( rhs ) ) );
308}
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 300 of file imm.h.

301{
302 return int2imm_p( ff_sub( imm2int( lhs ), imm2int( rhs ) ) );
303}
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:132
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.