abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
cuddApa.c File Reference
#include "misc/util/util_hack.h"
#include "cuddInt.h"

Go to the source code of this file.

Functions

static DdApaNumber cuddApaCountMintermAux (DdNode *node, int digits, DdApaNumber max, DdApaNumber min, st__table *table)
 
static enum st__retval cuddApaStCountfree (char *key, char *value, char *arg)
 
int Cudd_ApaNumberOfDigits (int binaryDigits)
 
DdApaNumber Cudd_NewApaNumber (int digits)
 
void Cudd_ApaCopy (int digits, DdApaNumber source, DdApaNumber dest)
 
DdApaDigit Cudd_ApaAdd (int digits, DdApaNumber a, DdApaNumber b, DdApaNumber sum)
 
DdApaDigit Cudd_ApaSubtract (int digits, DdApaNumber a, DdApaNumber b, DdApaNumber diff)
 
DdApaDigit Cudd_ApaShortDivision (int digits, DdApaNumber dividend, DdApaDigit divisor, DdApaNumber quotient)
 
unsigned int Cudd_ApaIntDivision (int digits, DdApaNumber dividend, unsigned int divisor, DdApaNumber quotient)
 
void Cudd_ApaShiftRight (int digits, DdApaDigit in, DdApaNumber a, DdApaNumber b)
 
void Cudd_ApaSetToLiteral (int digits, DdApaNumber number, DdApaDigit literal)
 
void Cudd_ApaPowerOfTwo (int digits, DdApaNumber number, int power)
 
int Cudd_ApaCompare (int digitsFirst, DdApaNumber first, int digitsSecond, DdApaNumber second)
 
int Cudd_ApaCompareRatios (int digitsFirst, DdApaNumber firstNum, unsigned int firstDen, int digitsSecond, DdApaNumber secondNum, unsigned int secondDen)
 
int Cudd_ApaPrintHex (FILE *fp, int digits, DdApaNumber number)
 
int Cudd_ApaPrintDecimal (FILE *fp, int digits, DdApaNumber number)
 
int Cudd_ApaPrintExponential (FILE *fp, int digits, DdApaNumber number, int precision)
 
DdApaNumber Cudd_ApaCountMinterm (DdManager *manager, DdNode *node, int nvars, int *digits)
 
int Cudd_ApaPrintMinterm (FILE *fp, DdManager *dd, DdNode *node, int nvars)
 
int Cudd_ApaPrintMintermExp (FILE *fp, DdManager *dd, DdNode *node, int nvars, int precision)
 
int Cudd_ApaPrintDensity (FILE *fp, DdManager *dd, DdNode *node, int nvars)
 

Variables

static
ABC_NAMESPACE_IMPL_START char
rcsid[] 
DD_UNUSED = "$Id: cuddApa.c,v 1.19 2009/03/08 01:27:50 fabio Exp $"
 
static DdNodebackground
 
static DdNodezero
 

Function Documentation

DdApaDigit Cudd_ApaAdd ( int  digits,
DdApaNumber  a,
DdApaNumber  b,
DdApaNumber  sum 
)

Function********************************************************************

Synopsis [Adds two arbitrary precision integers.]

Description [Adds two arbitrary precision integers. Returns the carry out of the most significant digit.]

SideEffects [The result of the sum is stored in parameter sum.]

SeeAlso []

Definition at line 221 of file cuddApa.c.

226 {
227  int i;
228  DdApaDoubleDigit partial = 0;
229 
230  for (i = digits - 1; i >= 0; i--) {
231  partial = a[i] + b[i] + DD_MSDIGIT(partial);
232  sum[i] = (DdApaDigit) DD_LSDIGIT(partial);
233  }
234  return((DdApaDigit) DD_MSDIGIT(partial));
235 
236 } /* end of Cudd_ApaAdd */
unsigned short int DdApaDigit
Definition: cudd.h:303
unsigned int DdApaDoubleDigit
Definition: cudd.h:304
#define DD_LSDIGIT(x)
Definition: cuddInt.h:995
#define DD_MSDIGIT(x)
Definition: cuddInt.h:1010
int Cudd_ApaCompare ( int  digitsFirst,
DdApaNumber  first,
int  digitsSecond,
DdApaNumber  second 
)

Function********************************************************************

Synopsis [Compares two arbitrary precision integers.]

Description [Compares two arbitrary precision integers. Returns 1 if the first number is larger; 0 if they are equal; -1 if the second number is larger.]

SideEffects [None]

SeeAlso []

Definition at line 449 of file cuddApa.c.

454 {
455  int i;
456  int firstNZ, secondNZ;
457 
458  /* Find first non-zero in both numbers. */
459  for (firstNZ = 0; firstNZ < digitsFirst; firstNZ++)
460  if (first[firstNZ] != 0) break;
461  for (secondNZ = 0; secondNZ < digitsSecond; secondNZ++)
462  if (second[secondNZ] != 0) break;
463  if (digitsFirst - firstNZ > digitsSecond - secondNZ) return(1);
464  else if (digitsFirst - firstNZ < digitsSecond - secondNZ) return(-1);
465  for (i = 0; i < digitsFirst - firstNZ; i++) {
466  if (first[firstNZ + i] > second[secondNZ + i]) return(1);
467  else if (first[firstNZ + i] < second[secondNZ + i]) return(-1);
468  }
469  return(0);
470 
471 } /* end of Cudd_ApaCompare */
int Cudd_ApaCompareRatios ( int  digitsFirst,
DdApaNumber  firstNum,
unsigned int  firstDen,
int  digitsSecond,
DdApaNumber  secondNum,
unsigned int  secondDen 
)

Function********************************************************************

Synopsis [Compares the ratios of two arbitrary precision integers to two unsigned ints.]

Description [Compares the ratios of two arbitrary precision integers to two unsigned ints. Returns 1 if the first number is larger; 0 if they are equal; -1 if the second number is larger.]

SideEffects [None]

SeeAlso []

Definition at line 489 of file cuddApa.c.

496 {
497  int result;
498  DdApaNumber first, second;
499  unsigned int firstRem, secondRem;
500 
501  first = Cudd_NewApaNumber(digitsFirst);
502  firstRem = Cudd_ApaIntDivision(digitsFirst,firstNum,firstDen,first);
503  second = Cudd_NewApaNumber(digitsSecond);
504  secondRem = Cudd_ApaIntDivision(digitsSecond,secondNum,secondDen,second);
505  result = Cudd_ApaCompare(digitsFirst,first,digitsSecond,second);
506  ABC_FREE(first);
507  ABC_FREE(second);
508  if (result == 0) {
509  if ((double)firstRem/firstDen > (double)secondRem/secondDen)
510  return(1);
511  else if ((double)firstRem/firstDen < (double)secondRem/secondDen)
512  return(-1);
513  }
514  return(result);
515 
516 } /* end of Cudd_ApaCompareRatios */
int Cudd_ApaCompare(int digitsFirst, DdApaNumber first, int digitsSecond, DdApaNumber second)
Definition: cuddApa.c:449
DdApaDigit * DdApaNumber
Definition: cudd.h:306
unsigned int Cudd_ApaIntDivision(int digits, DdApaNumber dividend, unsigned int divisor, DdApaNumber quotient)
Definition: cuddApa.c:324
#define ABC_FREE(obj)
Definition: abc_global.h:232
DdApaNumber Cudd_NewApaNumber(int digits)
Definition: cuddApa.c:174
static int result
Definition: cuddGenetic.c:125
void Cudd_ApaCopy ( int  digits,
DdApaNumber  source,
DdApaNumber  dest 
)

Function********************************************************************

Synopsis [Makes a copy of an arbitrary precision integer.]

Description [Makes a copy of an arbitrary precision integer.]

SideEffects [Changes parameter dest.]

SeeAlso []

Definition at line 194 of file cuddApa.c.

198 {
199  int i;
200 
201  for (i = 0; i < digits; i++) {
202  dest[i] = source[i];
203  }
204 
205 } /* end of Cudd_ApaCopy */
DdApaNumber Cudd_ApaCountMinterm ( DdManager manager,
DdNode node,
int  nvars,
int *  digits 
)

Function********************************************************************

Synopsis [Counts the number of minterms of a DD.]

Description [Counts the number of minterms of a DD. The function is assumed to depend on nvars variables. The minterm count is represented as an arbitrary precision unsigned integer, to allow for any number of variables CUDD supports. Returns a pointer to the array representing the number of minterms of the function rooted at node if successful; NULL otherwise.]

SideEffects [The number of digits of the result is returned in parameter digits.]

SeeAlso [Cudd_CountMinterm]

Definition at line 684 of file cuddApa.c.

689 {
690  DdApaNumber max, min;
691  st__table *table;
692  DdApaNumber i,count;
693 
694  background = manager->background;
695  zero = Cudd_Not(manager->one);
696 
697  *digits = Cudd_ApaNumberOfDigits(nvars+1);
698  max = Cudd_NewApaNumber(*digits);
699  if (max == NULL) {
700  return(NULL);
701  }
702  Cudd_ApaPowerOfTwo(*digits,max,nvars);
703  min = Cudd_NewApaNumber(*digits);
704  if (min == NULL) {
705  ABC_FREE(max);
706  return(NULL);
707  }
708  Cudd_ApaSetToLiteral(*digits,min,0);
710  if (table == NULL) {
711  ABC_FREE(max);
712  ABC_FREE(min);
713  return(NULL);
714  }
715  i = cuddApaCountMintermAux(Cudd_Regular(node),*digits,max,min,table);
716  if (i == NULL) {
717  ABC_FREE(max);
718  ABC_FREE(min);
719  st__foreach(table, cuddApaStCountfree, NULL);
720  st__free_table(table);
721  return(NULL);
722  }
723  count = Cudd_NewApaNumber(*digits);
724  if (count == NULL) {
725  ABC_FREE(max);
726  ABC_FREE(min);
727  st__foreach(table, cuddApaStCountfree, NULL);
728  st__free_table(table);
729  if (Cudd_Regular(node)->ref == 1) ABC_FREE(i);
730  return(NULL);
731  }
732  if (Cudd_IsComplement(node)) {
733  (void) Cudd_ApaSubtract(*digits,max,i,count);
734  } else {
735  Cudd_ApaCopy(*digits,i,count);
736  }
737  ABC_FREE(max);
738  ABC_FREE(min);
739  st__foreach(table, cuddApaStCountfree, NULL);
740  st__free_table(table);
741  if (Cudd_Regular(node)->ref == 1) ABC_FREE(i);
742  return(count);
743 
744 } /* end of Cudd_ApaCountMinterm */
void st__free_table(st__table *table)
Definition: st.c:81
#define Cudd_Not(node)
Definition: cudd.h:367
#define Cudd_Regular(node)
Definition: cudd.h:397
int st__ptrcmp(const char *, const char *)
Definition: st.c:480
static DdNode * background
Definition: cuddApa.c:100
int Cudd_ApaNumberOfDigits(int binaryDigits)
Definition: cuddApa.c:147
void Cudd_ApaSetToLiteral(int digits, DdApaNumber number, DdApaDigit literal)
Definition: cuddApa.c:389
void Cudd_ApaCopy(int digits, DdApaNumber source, DdApaNumber dest)
Definition: cuddApa.c:194
st__table * st__init_table(st__compare_func_type compare, st__hash_func_type hash)
Definition: st.c:72
#define Cudd_IsComplement(node)
Definition: cudd.h:425
Definition: st.h:52
static double max
Definition: cuddSubsetHB.c:134
DdApaDigit Cudd_ApaSubtract(int digits, DdApaNumber a, DdApaNumber b, DdApaNumber diff)
Definition: cuddApa.c:253
int st__foreach(st__table *table, enum st__retval(*func)(char *, char *, char *), char *arg)
Definition: st.c:421
DdApaDigit * DdApaNumber
Definition: cudd.h:306
#define ABC_FREE(obj)
Definition: abc_global.h:232
DdNode * one
Definition: cuddInt.h:345
DdApaNumber Cudd_NewApaNumber(int digits)
Definition: cuddApa.c:174
void Cudd_ApaPowerOfTwo(int digits, DdApaNumber number, int power)
Definition: cuddApa.c:417
static enum st__retval cuddApaStCountfree(char *key, char *value, char *arg)
Definition: cuddApa.c:972
int st__ptrhash(const char *, int)
Definition: st.c:468
static DdNode * zero
Definition: cuddApa.c:100
static DdApaNumber cuddApaCountMintermAux(DdNode *node, int digits, DdApaNumber max, DdApaNumber min, st__table *table)
Definition: cuddApa.c:899
DdNode * background
Definition: cuddInt.h:349
unsigned int Cudd_ApaIntDivision ( int  digits,
DdApaNumber  dividend,
unsigned int  divisor,
DdApaNumber  quotient 
)

Function********************************************************************

Synopsis [Divides an arbitrary precision integer by an integer.]

Description [Divides an arbitrary precision integer by a 32-bit unsigned integer. Returns the remainder of the division. This procedure relies on the assumption that the number of bits of a DdApaDigit plus the number of bits of an unsigned int is less the number of bits of the mantissa of a double. This guarantees that the product of a DdApaDigit and an unsigned int can be represented without loss of precision by a double. On machines where this assumption is not satisfied, this procedure will malfunction.]

SideEffects [The quotient is returned in parameter quotient.]

SeeAlso [Cudd_ApaShortDivision]

Definition at line 324 of file cuddApa.c.

329 {
330  int i;
331  double partial;
332  unsigned int remainder = 0;
333  double ddiv = (double) divisor;
334 
335  for (i = 0; i < digits; i++) {
336  partial = (double) remainder * DD_APA_BASE + dividend[i];
337  quotient[i] = (DdApaDigit) (partial / ddiv);
338  remainder = (unsigned int) (partial - ((double)quotient[i] * ddiv));
339  }
340 
341  return(remainder);
342 
343 } /* end of Cudd_ApaIntDivision */
unsigned short int DdApaDigit
Definition: cudd.h:303
#define DD_APA_BASE
Definition: cudd.h:130
int Cudd_ApaNumberOfDigits ( int  binaryDigits)

AutomaticEnd Function********************************************************************

Synopsis [Finds the number of digits for an arbitrary precision integer.]

Description [Finds the number of digits for an arbitrary precision integer given the maximum number of binary digits. The number of binary digits should be positive. Returns the number of digits if successful; 0 otherwise.]

SideEffects [None]

SeeAlso []

Definition at line 147 of file cuddApa.c.

149 {
150  int digits;
151 
152  digits = binaryDigits / DD_APA_BITS;
153  if ((digits * DD_APA_BITS) != binaryDigits)
154  digits++;
155  return(digits);
156 
157 } /* end of Cudd_ApaNumberOfDigits */
#define DD_APA_BITS
Definition: cudd.h:129
void Cudd_ApaPowerOfTwo ( int  digits,
DdApaNumber  number,
int  power 
)

Function********************************************************************

Synopsis [Sets an arbitrary precision integer to a power of two.]

Description [Sets an arbitrary precision integer to a power of two. If the power of two is too large to be represented, the number is set to 0.]

SideEffects [The result is returned in parameter number.]

SeeAlso []

Definition at line 417 of file cuddApa.c.

421 {
422  int i;
423  int index;
424 
425  for (i = 0; i < digits; i++)
426  number[i] = 0;
427  i = digits - 1 - power / DD_APA_BITS;
428  if (i < 0) return;
429  index = power & (DD_APA_BITS - 1);
430  number[i] = 1 << index;
431 
432 } /* end of Cudd_ApaPowerOfTwo */
#define DD_APA_BITS
Definition: cudd.h:129
int Cudd_ApaPrintDecimal ( FILE *  fp,
int  digits,
DdApaNumber  number 
)

Function********************************************************************

Synopsis [Prints an arbitrary precision integer in decimal format.]

Description [Prints an arbitrary precision integer in decimal format. Returns 1 if successful; 0 otherwise.]

SideEffects [None]

SeeAlso [Cudd_ApaPrintHex Cudd_ApaPrintExponential]

Definition at line 562 of file cuddApa.c.

566 {
567  int i, result;
568  DdApaDigit remainder;
569  DdApaNumber work;
570  unsigned char *decimal;
571  int leadingzero;
572  int decimalDigits = (int) (digits * log10((double) DD_APA_BASE)) + 1;
573 
574  work = Cudd_NewApaNumber(digits);
575  if (work == NULL)
576  return(0);
577  decimal = ABC_ALLOC(unsigned char, decimalDigits);
578  if (decimal == NULL) {
579  ABC_FREE(work);
580  return(0);
581  }
582  Cudd_ApaCopy(digits,number,work);
583  for (i = decimalDigits - 1; i >= 0; i--) {
584  remainder = Cudd_ApaShortDivision(digits,work,(DdApaDigit) 10,work);
585  decimal[i] = (unsigned char) remainder;
586  }
587  ABC_FREE(work);
588 
589  leadingzero = 1;
590  for (i = 0; i < decimalDigits; i++) {
591  leadingzero = leadingzero && (decimal[i] == 0);
592  if ((!leadingzero) || (i == (decimalDigits - 1))) {
593  result = fprintf(fp,"%1d",decimal[i]);
594  if (result == EOF) {
595  ABC_FREE(decimal);
596  return(0);
597  }
598  }
599  }
600  ABC_FREE(decimal);
601  return(1);
602 
603 } /* end of Cudd_ApaPrintDecimal */
#define ABC_ALLOC(type, num)
Definition: abc_global.h:229
unsigned short int DdApaDigit
Definition: cudd.h:303
void Cudd_ApaCopy(int digits, DdApaNumber source, DdApaNumber dest)
Definition: cuddApa.c:194
#define DD_APA_BASE
Definition: cudd.h:130
DdApaDigit Cudd_ApaShortDivision(int digits, DdApaNumber dividend, DdApaDigit divisor, DdApaNumber quotient)
Definition: cuddApa.c:283
DdApaDigit * DdApaNumber
Definition: cudd.h:306
#define ABC_FREE(obj)
Definition: abc_global.h:232
DdApaNumber Cudd_NewApaNumber(int digits)
Definition: cuddApa.c:174
static int result
Definition: cuddGenetic.c:125
int Cudd_ApaPrintDensity ( FILE *  fp,
DdManager dd,
DdNode node,
int  nvars 
)

Function********************************************************************

Synopsis [Prints the density of a BDD or ADD using arbitrary precision arithmetic.]

Description [Prints the density of a BDD or ADD using arbitrary precision arithmetic. Returns 1 if successful; 0 otherwise.]

SideEffects [None]

SeeAlso []

Definition at line 838 of file cuddApa.c.

843 {
844  int digits;
845  int result;
846  DdApaNumber count,density;
847  unsigned int size, remainder, fractional;
848 
849  count = Cudd_ApaCountMinterm(dd,node,nvars,&digits);
850  if (count == NULL)
851  return(0);
852  size = Cudd_DagSize(node);
853  density = Cudd_NewApaNumber(digits);
854  remainder = Cudd_ApaIntDivision(digits,count,size,density);
855  result = Cudd_ApaPrintDecimal(fp,digits,density);
856  ABC_FREE(count);
857  ABC_FREE(density);
858  fractional = (unsigned int)((double)remainder / size * 1000000);
859  if (fprintf(fp,".%u\n", fractional) == EOF) {
860  return(0);
861  }
862  return(result);
863 
864 } /* end of Cudd_ApaPrintDensity */
DdApaNumber Cudd_ApaCountMinterm(DdManager *manager, DdNode *node, int nvars, int *digits)
Definition: cuddApa.c:684
static int size
Definition: cuddSign.c:86
DdApaDigit * DdApaNumber
Definition: cudd.h:306
unsigned int Cudd_ApaIntDivision(int digits, DdApaNumber dividend, unsigned int divisor, DdApaNumber quotient)
Definition: cuddApa.c:324
#define ABC_FREE(obj)
Definition: abc_global.h:232
int Cudd_ApaPrintDecimal(FILE *fp, int digits, DdApaNumber number)
Definition: cuddApa.c:562
DdApaNumber Cudd_NewApaNumber(int digits)
Definition: cuddApa.c:174
static int result
Definition: cuddGenetic.c:125
int Cudd_DagSize(DdNode *node)
Definition: cuddUtil.c:442
int Cudd_ApaPrintExponential ( FILE *  fp,
int  digits,
DdApaNumber  number,
int  precision 
)

Function********************************************************************

Synopsis [Prints an arbitrary precision integer in exponential format.]

Description [Prints an arbitrary precision integer in exponential format. Returns 1 if successful; 0 otherwise.]

SideEffects [None]

SeeAlso [Cudd_ApaPrintHex Cudd_ApaPrintDecimal]

Definition at line 619 of file cuddApa.c.

624 {
625  int i, first, last, result;
626  DdApaDigit remainder;
627  DdApaNumber work;
628  unsigned char *decimal;
629  int decimalDigits = (int) (digits * log10((double) DD_APA_BASE)) + 1;
630 
631  work = Cudd_NewApaNumber(digits);
632  if (work == NULL)
633  return(0);
634  decimal = ABC_ALLOC(unsigned char, decimalDigits);
635  if (decimal == NULL) {
636  ABC_FREE(work);
637  return(0);
638  }
639  Cudd_ApaCopy(digits,number,work);
640  first = decimalDigits - 1;
641  for (i = decimalDigits - 1; i >= 0; i--) {
642  remainder = Cudd_ApaShortDivision(digits,work,(DdApaDigit) 10,work);
643  decimal[i] = (unsigned char) remainder;
644  if (remainder != 0) first = i; /* keep track of MS non-zero */
645  }
646  ABC_FREE(work);
647  last = ddMin(first + precision, decimalDigits);
648 
649  for (i = first; i < last; i++) {
650  result = fprintf(fp,"%s%1d",i == first+1 ? "." : "", decimal[i]);
651  if (result == EOF) {
652  ABC_FREE(decimal);
653  return(0);
654  }
655  }
656  ABC_FREE(decimal);
657  result = fprintf(fp,"e+%d",decimalDigits - first - 1);
658  if (result == EOF) {
659  return(0);
660  }
661  return(1);
662 
663 } /* end of Cudd_ApaPrintExponential */
#define ABC_ALLOC(type, num)
Definition: abc_global.h:229
unsigned short int DdApaDigit
Definition: cudd.h:303
void Cudd_ApaCopy(int digits, DdApaNumber source, DdApaNumber dest)
Definition: cuddApa.c:194
#define DD_APA_BASE
Definition: cudd.h:130
DdApaDigit Cudd_ApaShortDivision(int digits, DdApaNumber dividend, DdApaDigit divisor, DdApaNumber quotient)
Definition: cuddApa.c:283
#define ddMin(x, y)
Definition: cuddInt.h:818
DdApaDigit * DdApaNumber
Definition: cudd.h:306
#define ABC_FREE(obj)
Definition: abc_global.h:232
DdApaNumber Cudd_NewApaNumber(int digits)
Definition: cuddApa.c:174
static int result
Definition: cuddGenetic.c:125
int Cudd_ApaPrintHex ( FILE *  fp,
int  digits,
DdApaNumber  number 
)

Function********************************************************************

Synopsis [Prints an arbitrary precision integer in hexadecimal format.]

Description [Prints an arbitrary precision integer in hexadecimal format. Returns 1 if successful; 0 otherwise.]

SideEffects [None]

SeeAlso [Cudd_ApaPrintDecimal Cudd_ApaPrintExponential]

Definition at line 532 of file cuddApa.c.

536 {
537  int i, result;
538 
539  for (i = 0; i < digits; i++) {
540  result = fprintf(fp,DD_APA_HEXPRINT,number[i]);
541  if (result == EOF)
542  return(0);
543  }
544  return(1);
545 
546 } /* end of Cudd_ApaPrintHex */
#define DD_APA_HEXPRINT
Definition: cudd.h:131
static int result
Definition: cuddGenetic.c:125
int Cudd_ApaPrintMinterm ( FILE *  fp,
DdManager dd,
DdNode node,
int  nvars 
)

Function********************************************************************

Synopsis [Prints the number of minterms of a BDD or ADD using arbitrary precision arithmetic.]

Description [Prints the number of minterms of a BDD or ADD using arbitrary precision arithmetic. Returns 1 if successful; 0 otherwise.]

SideEffects [None]

SeeAlso [Cudd_ApaPrintMintermExp]

Definition at line 761 of file cuddApa.c.

766 {
767  int digits;
768  int result;
769  DdApaNumber count;
770 
771  count = Cudd_ApaCountMinterm(dd,node,nvars,&digits);
772  if (count == NULL)
773  return(0);
774  result = Cudd_ApaPrintDecimal(fp,digits,count);
775  ABC_FREE(count);
776  if (fprintf(fp,"\n") == EOF) {
777  return(0);
778  }
779  return(result);
780 
781 } /* end of Cudd_ApaPrintMinterm */
DdApaNumber Cudd_ApaCountMinterm(DdManager *manager, DdNode *node, int nvars, int *digits)
Definition: cuddApa.c:684
DdApaDigit * DdApaNumber
Definition: cudd.h:306
#define ABC_FREE(obj)
Definition: abc_global.h:232
int Cudd_ApaPrintDecimal(FILE *fp, int digits, DdApaNumber number)
Definition: cuddApa.c:562
static int result
Definition: cuddGenetic.c:125
int Cudd_ApaPrintMintermExp ( FILE *  fp,
DdManager dd,
DdNode node,
int  nvars,
int  precision 
)

Function********************************************************************

Synopsis [Prints the number of minterms of a BDD or ADD in exponential format using arbitrary precision arithmetic.]

Description [Prints the number of minterms of a BDD or ADD in exponential format using arbitrary precision arithmetic. Parameter precision controls the number of signficant digits printed. Returns 1 if successful; 0 otherwise.]

SideEffects [None]

SeeAlso [Cudd_ApaPrintMinterm]

Definition at line 800 of file cuddApa.c.

806 {
807  int digits;
808  int result;
809  DdApaNumber count;
810 
811  count = Cudd_ApaCountMinterm(dd,node,nvars,&digits);
812  if (count == NULL)
813  return(0);
814  result = Cudd_ApaPrintExponential(fp,digits,count,precision);
815  ABC_FREE(count);
816  if (fprintf(fp,"\n") == EOF) {
817  return(0);
818  }
819  return(result);
820 
821 } /* end of Cudd_ApaPrintMintermExp */
DdApaNumber Cudd_ApaCountMinterm(DdManager *manager, DdNode *node, int nvars, int *digits)
Definition: cuddApa.c:684
DdApaDigit * DdApaNumber
Definition: cudd.h:306
#define ABC_FREE(obj)
Definition: abc_global.h:232
static int result
Definition: cuddGenetic.c:125
int Cudd_ApaPrintExponential(FILE *fp, int digits, DdApaNumber number, int precision)
Definition: cuddApa.c:619
void Cudd_ApaSetToLiteral ( int  digits,
DdApaNumber  number,
DdApaDigit  literal 
)

Function********************************************************************

Synopsis [Sets an arbitrary precision integer to a one-digit literal.]

Description [Sets an arbitrary precision integer to a one-digit literal.]

SideEffects [The result is returned in parameter number.]

SeeAlso []

Definition at line 389 of file cuddApa.c.

393 {
394  int i;
395 
396  for (i = 0; i < digits - 1; i++)
397  number[i] = 0;
398  number[digits - 1] = literal;
399 
400 } /* end of Cudd_ApaSetToLiteral */
void Cudd_ApaShiftRight ( int  digits,
DdApaDigit  in,
DdApaNumber  a,
DdApaNumber  b 
)

Function********************************************************************

Synopsis [Shifts right an arbitrary precision integer by one binary place.]

Description [Shifts right an arbitrary precision integer by one binary place. The most significant binary digit of the result is taken from parameter in.]

SideEffects [The result is returned in parameter b.]

SeeAlso []

Definition at line 361 of file cuddApa.c.

366 {
367  int i;
368 
369  for (i = digits - 1; i > 0; i--) {
370  b[i] = (a[i] >> 1) | ((a[i-1] & 1) << (DD_APA_BITS - 1));
371  }
372  b[0] = (a[0] >> 1) | (in << (DD_APA_BITS - 1));
373 
374 } /* end of Cudd_ApaShiftRight */
#define DD_APA_BITS
Definition: cudd.h:129
DdApaDigit Cudd_ApaShortDivision ( int  digits,
DdApaNumber  dividend,
DdApaDigit  divisor,
DdApaNumber  quotient 
)

Function********************************************************************

Synopsis [Divides an arbitrary precision integer by a digit.]

Description [Divides an arbitrary precision integer by a digit.]

SideEffects [The quotient is returned in parameter quotient.]

SeeAlso []

Definition at line 283 of file cuddApa.c.

288 {
289  int i;
290  DdApaDigit remainder;
291  DdApaDoubleDigit partial;
292 
293  remainder = 0;
294  for (i = 0; i < digits; i++) {
295  partial = remainder * DD_APA_BASE + dividend[i];
296  quotient[i] = (DdApaDigit) (partial/(DdApaDoubleDigit)divisor);
297  remainder = (DdApaDigit) (partial % divisor);
298  }
299 
300  return(remainder);
301 
302 } /* end of Cudd_ApaShortDivision */
unsigned short int DdApaDigit
Definition: cudd.h:303
#define DD_APA_BASE
Definition: cudd.h:130
unsigned int DdApaDoubleDigit
Definition: cudd.h:304
DdApaDigit Cudd_ApaSubtract ( int  digits,
DdApaNumber  a,
DdApaNumber  b,
DdApaNumber  diff 
)

Function********************************************************************

Synopsis [Subtracts two arbitrary precision integers.]

Description [Subtracts two arbitrary precision integers. Returns the borrow out of the most significant digit.]

SideEffects [The result of the subtraction is stored in parameter diff.]

SeeAlso []

Definition at line 253 of file cuddApa.c.

258 {
259  int i;
260  DdApaDoubleDigit partial = DD_APA_BASE;
261 
262  for (i = digits - 1; i >= 0; i--) {
263  partial = DD_MSDIGIT(partial) + DD_APA_MASK + a[i] - b[i];
264  diff[i] = (DdApaDigit) DD_LSDIGIT(partial);
265  }
266  return((DdApaDigit) DD_MSDIGIT(partial) - 1);
267 
268 } /* end of Cudd_ApaSubtract */
unsigned short int DdApaDigit
Definition: cudd.h:303
#define DD_APA_BASE
Definition: cudd.h:130
unsigned int DdApaDoubleDigit
Definition: cudd.h:304
#define DD_LSDIGIT(x)
Definition: cuddInt.h:995
#define DD_MSDIGIT(x)
Definition: cuddInt.h:1010
#define DD_APA_MASK
Definition: cudd.h:133
DdApaNumber Cudd_NewApaNumber ( int  digits)

Function********************************************************************

Synopsis [Allocates memory for an arbitrary precision integer.]

Description [Allocates memory for an arbitrary precision integer. Returns a pointer to the allocated memory if successful; NULL otherwise.]

SideEffects [None]

SeeAlso []

Definition at line 174 of file cuddApa.c.

176 {
177  return(ABC_ALLOC(DdApaDigit, digits));
178 
179 } /* end of Cudd_NewApaNumber */
#define ABC_ALLOC(type, num)
Definition: abc_global.h:229
unsigned short int DdApaDigit
Definition: cudd.h:303
static DdApaNumber cuddApaCountMintermAux ( DdNode node,
int  digits,
DdApaNumber  max,
DdApaNumber  min,
st__table table 
)
static

AutomaticStart

Function********************************************************************

Synopsis [Performs the recursive step of Cudd_ApaCountMinterm.]

Description [Performs the recursive step of Cudd_ApaCountMinterm. It is based on the following identity. Let |f| be the number of minterms of f. Then: <xmp> |f| = (|f0|+|f1|)/2 </xmp> where f0 and f1 are the two cofactors of f. Uses the identity |f'| = max - |f|. The procedure expects the argument "node" to be a regular pointer, and guarantees this condition is met in the recursive calls. For efficiency, the result of a call is cached only if the node has a reference count greater than 1. Returns the number of minterms of the function rooted at node.]

SideEffects [None]

Definition at line 899 of file cuddApa.c.

905 {
906  DdNode *Nt, *Ne;
907  DdApaNumber mint, mint1, mint2;
908  DdApaDigit carryout;
909 
910  if (cuddIsConstant(node)) {
911  if (node == background || node == zero) {
912  return(min);
913  } else {
914  return(max);
915  }
916  }
917  if (node->ref > 1 && st__lookup(table, (const char *)node, (char **)&mint)) {
918  return(mint);
919  }
920 
921  Nt = cuddT(node); Ne = cuddE(node);
922 
923  mint1 = cuddApaCountMintermAux(Nt, digits, max, min, table);
924  if (mint1 == NULL) return(NULL);
925  mint2 = cuddApaCountMintermAux(Cudd_Regular(Ne), digits, max, min, table);
926  if (mint2 == NULL) {
927  if (Nt->ref == 1) ABC_FREE(mint1);
928  return(NULL);
929  }
930  mint = Cudd_NewApaNumber(digits);
931  if (mint == NULL) {
932  if (Nt->ref == 1) ABC_FREE(mint1);
933  if (Cudd_Regular(Ne)->ref == 1) ABC_FREE(mint2);
934  return(NULL);
935  }
936  if (Cudd_IsComplement(Ne)) {
937  (void) Cudd_ApaSubtract(digits,max,mint2,mint);
938  carryout = Cudd_ApaAdd(digits,mint1,mint,mint);
939  } else {
940  carryout = Cudd_ApaAdd(digits,mint1,mint2,mint);
941  }
942  Cudd_ApaShiftRight(digits,carryout,mint,mint);
943  /* If the refernce count of a child is 1, its minterm count
944  ** hasn't been stored in table. Therefore, it must be explicitly
945  ** freed here. */
946  if (Nt->ref == 1) ABC_FREE(mint1);
947  if (Cudd_Regular(Ne)->ref == 1) ABC_FREE(mint2);
948 
949  if (node->ref > 1) {
950  if ( st__insert(table, (char *)node, (char *)mint) == st__OUT_OF_MEM) {
951  ABC_FREE(mint);
952  return(NULL);
953  }
954  }
955  return(mint);
956 
957 } /* end of cuddApaCountMintermAux */
DdHalfWord ref
Definition: cudd.h:280
Definition: cudd.h:278
int st__insert(st__table *table, const char *key, char *value)
Definition: st.c:171
#define Cudd_Regular(node)
Definition: cudd.h:397
DdApaDigit Cudd_ApaAdd(int digits, DdApaNumber a, DdApaNumber b, DdApaNumber sum)
Definition: cuddApa.c:221
static DdNode * background
Definition: cuddApa.c:100
unsigned short int DdApaDigit
Definition: cudd.h:303
#define Cudd_IsComplement(node)
Definition: cudd.h:425
#define cuddIsConstant(node)
Definition: cuddInt.h:620
static double max
Definition: cuddSubsetHB.c:134
DdApaDigit Cudd_ApaSubtract(int digits, DdApaNumber a, DdApaNumber b, DdApaNumber diff)
Definition: cuddApa.c:253
#define cuddT(node)
Definition: cuddInt.h:636
#define st__OUT_OF_MEM
Definition: st.h:113
DdApaDigit * DdApaNumber
Definition: cudd.h:306
int st__lookup(st__table *table, const char *key, char **value)
Definition: st.c:114
void Cudd_ApaShiftRight(int digits, DdApaDigit in, DdApaNumber a, DdApaNumber b)
Definition: cuddApa.c:361
#define ABC_FREE(obj)
Definition: abc_global.h:232
DdApaNumber Cudd_NewApaNumber(int digits)
Definition: cuddApa.c:174
#define cuddE(node)
Definition: cuddInt.h:652
static DdNode * zero
Definition: cuddApa.c:100
static DdApaNumber cuddApaCountMintermAux(DdNode *node, int digits, DdApaNumber max, DdApaNumber min, st__table *table)
Definition: cuddApa.c:899
static enum st__retval cuddApaStCountfree ( char *  key,
char *  value,
char *  arg 
)
static

Function********************************************************************

Synopsis [Frees the memory used to store the minterm counts recorded in the visited table.]

Description [Frees the memory used to store the minterm counts recorded in the visited table. Returns st__CONTINUE.]

SideEffects [None]

Definition at line 972 of file cuddApa.c.

976 {
977  DdApaNumber d;
978 
979  d = (DdApaNumber) value;
980  ABC_FREE(d);
981  return( st__CONTINUE);
982 
983 } /* end of cuddApaStCountfree */
DdApaDigit * DdApaNumber
Definition: cudd.h:306
#define ABC_FREE(obj)
Definition: abc_global.h:232
int value

Variable Documentation

DdNode* background
static

Definition at line 100 of file cuddApa.c.

ABC_NAMESPACE_IMPL_START char rcsid [] DD_UNUSED = "$Id: cuddApa.c,v 1.19 2009/03/08 01:27:50 fabio Exp $"
static

CFile***********************************************************************

FileName [cuddApa.c]

PackageName [cudd]

Synopsis [Arbitrary precision arithmetic functions.]

Description [External procedures included in this module:

Static procedures included in this module:

]

Author [Fabio Somenzi]

Copyright [Copyright (c) 1995-2004, Regents of the University of Colorado

All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

Neither the name of the University of Colorado nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.]

Definition at line 97 of file cuddApa.c.

DdNode * zero
static

Definition at line 100 of file cuddApa.c.