src/bdd/cudd/cuddApa.c File Reference

#include "util_hack.h"
#include "cuddInt.h"
Include dependency graph for cuddApa.c:

Go to the source code of this file.

Functions

static DdApaNumber
cuddApaCountMintermAux 
ARGS ((DdNode *node, int digits, DdApaNumber max, DdApaNumber min, st_table *table))
static enum st_retval
cuddApaStCountfree 
ARGS ((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)
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)

Variables

static char rcsid[] DD_UNUSED = "$Id: cuddApa.c,v 1.1.1.1 2003/02/24 22:23:51 wjiang Exp $"
static DdNodebackground
static DdNodezero

Function Documentation

static enum st_retval cuddApaStCountfree ARGS ( (char *key, char *value, char *arg)   )  [static]
static DdApaNumber cuddApaCountMintermAux ARGS ( (DdNode *node, int digits, DdApaNumber max, DdApaNumber min, st_table *table)   )  [static]

AutomaticStart

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 168 of file cuddApa.c.

00173 {
00174     int i;
00175     DdApaDoubleDigit partial = 0;
00176 
00177     for (i = digits - 1; i >= 0; i--) {
00178         partial = a[i] + b[i] + DD_MSDIGIT(partial);
00179         sum[i] = (DdApaDigit) DD_LSDIGIT(partial);
00180     }
00181     return(DD_MSDIGIT(partial));
00182 
00183 } /* end of Cudd_ApaAdd */

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 396 of file cuddApa.c.

00401 {
00402     int i;
00403     int firstNZ, secondNZ;
00404 
00405     /* Find first non-zero in both numbers. */
00406     for (firstNZ = 0; firstNZ < digitsFirst; firstNZ++)
00407         if (first[firstNZ] != 0) break;
00408     for (secondNZ = 0; secondNZ < digitsSecond; secondNZ++)
00409         if (second[secondNZ] != 0) break;
00410     if (digitsFirst - firstNZ > digitsSecond - secondNZ) return(1);
00411     else if (digitsFirst - firstNZ < digitsSecond - secondNZ) return(-1);
00412     for (i = 0; i < digitsFirst - firstNZ; i++) {
00413         if (first[firstNZ + i] > second[secondNZ + i]) return(1);
00414         else if (first[firstNZ + i] < second[secondNZ + i]) return(-1);
00415     }
00416     return(0);
00417 
00418 } /* 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 436 of file cuddApa.c.

00443 {
00444     int result;
00445     DdApaNumber first, second;
00446     unsigned int firstRem, secondRem;
00447 
00448     first = Cudd_NewApaNumber(digitsFirst);
00449     firstRem = Cudd_ApaIntDivision(digitsFirst,firstNum,firstDen,first);
00450     second = Cudd_NewApaNumber(digitsSecond);
00451     secondRem = Cudd_ApaIntDivision(digitsSecond,secondNum,secondDen,second);
00452     result = Cudd_ApaCompare(digitsFirst,first,digitsSecond,second);
00453     if (result == 0) {
00454         if ((double)firstRem/firstDen > (double)secondRem/secondDen)
00455             return(1);
00456         else if ((double)firstRem/firstDen < (double)secondRem/secondDen)
00457             return(-1);
00458     }
00459     return(result);
00460 
00461 } /* end of Cudd_ApaCompareRatios */

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 141 of file cuddApa.c.

00145 {
00146     int i;
00147 
00148     for (i = 0; i < digits; i++) {
00149         dest[i] = source[i];
00150     }
00151 
00152 } /* 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 629 of file cuddApa.c.

00634 {
00635     DdApaNumber max, min;
00636     st_table    *table;
00637     DdApaNumber i,count;        
00638 
00639     background = manager->background;
00640     zero = Cudd_Not(manager->one);
00641 
00642     *digits = Cudd_ApaNumberOfDigits(nvars+1);
00643     max = Cudd_NewApaNumber(*digits);
00644     if (max == NULL) {
00645         return(NULL);
00646     }
00647     Cudd_ApaPowerOfTwo(*digits,max,nvars);
00648     min = Cudd_NewApaNumber(*digits);
00649     if (min == NULL) {
00650         FREE(max);
00651         return(NULL);
00652     }
00653     Cudd_ApaSetToLiteral(*digits,min,0);
00654     table = st_init_table(st_ptrcmp,st_ptrhash);
00655     if (table == NULL) {
00656         FREE(max);
00657         FREE(min);
00658         return(NULL);
00659     }
00660     i = cuddApaCountMintermAux(Cudd_Regular(node),*digits,max,min,table);
00661     if (i == NULL) {
00662         FREE(max);
00663         FREE(min);
00664         st_foreach(table, cuddApaStCountfree, NULL);
00665         st_free_table(table);
00666         return(NULL);
00667     }
00668     count = Cudd_NewApaNumber(*digits);
00669     if (count == NULL) {
00670         FREE(max);
00671         FREE(min);
00672         st_foreach(table, cuddApaStCountfree, NULL);
00673         st_free_table(table);
00674         if (Cudd_Regular(node)->ref == 1) FREE(i);
00675         return(NULL);
00676     }
00677     if (Cudd_IsComplement(node)) {
00678         (void) Cudd_ApaSubtract(*digits,max,i,count);
00679     } else {
00680         Cudd_ApaCopy(*digits,i,count);
00681     }
00682     FREE(max);
00683     FREE(min);
00684     st_foreach(table, cuddApaStCountfree, NULL);
00685     st_free_table(table);
00686     if (Cudd_Regular(node)->ref == 1) FREE(i);
00687     return(count);
00688 
00689 } /* end of Cudd_ApaCountMinterm */

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 271 of file cuddApa.c.

00276 {
00277     int i;
00278     double partial;
00279     unsigned int remainder = 0;
00280     double ddiv = (double) divisor;
00281 
00282     for (i = 0; i < digits; i++) {
00283         partial = (double) remainder * DD_APA_BASE + dividend[i];
00284         quotient[i] = (DdApaDigit) (partial / ddiv);
00285         remainder = (unsigned int) (partial - ((double)quotient[i] * ddiv));
00286     }
00287 
00288     return(remainder);
00289 
00290 } /* end of Cudd_ApaIntDivision */

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 94 of file cuddApa.c.

00096 {
00097     int digits;
00098 
00099     digits = binaryDigits / DD_APA_BITS;
00100     if ((digits * DD_APA_BITS) != binaryDigits)
00101         digits++;
00102     return(digits);
00103 
00104 } /* end of Cudd_ApaNumberOfDigits */

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 364 of file cuddApa.c.

00368 {
00369     int i;
00370     int index;
00371 
00372     for (i = 0; i < digits; i++)
00373         number[i] = 0;
00374     i = digits - 1 - power / DD_APA_BITS;
00375     if (i < 0) return;
00376     index = power & (DD_APA_BITS - 1);
00377     number[i] = 1 << index;
00378 
00379 } /* end of Cudd_ApaPowerOfTwo */

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 507 of file cuddApa.c.

00511 {
00512     int i, result;
00513     DdApaDigit remainder;
00514     DdApaNumber work;
00515     unsigned char *decimal;
00516     int leadingzero;
00517     int decimalDigits = (int) (digits * log10((double) DD_APA_BASE)) + 1;
00518     
00519     work = Cudd_NewApaNumber(digits);
00520     if (work == NULL)
00521         return(0);
00522     decimal = ALLOC(unsigned char, decimalDigits);
00523     if (decimal == NULL) {
00524         FREE(work);
00525         return(0);
00526     }
00527     Cudd_ApaCopy(digits,number,work);
00528     for (i = decimalDigits - 1; i >= 0; i--) {
00529         remainder = Cudd_ApaShortDivision(digits,work,(DdApaDigit) 10,work);
00530         decimal[i] = remainder;
00531     }
00532     FREE(work);
00533 
00534     leadingzero = 1;
00535     for (i = 0; i < decimalDigits; i++) {
00536         leadingzero = leadingzero && (decimal[i] == 0);
00537         if ((!leadingzero) || (i == (decimalDigits - 1))) {
00538             result = fprintf(fp,"%1d",decimal[i]);
00539             if (result == EOF) {
00540                 FREE(decimal);
00541                 return(0);
00542             }
00543         }
00544     }
00545     FREE(decimal);
00546     return(1);
00547 
00548 } /* end of Cudd_ApaPrintDecimal */

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 783 of file cuddApa.c.

00788 {
00789     int digits;
00790     int result;
00791     DdApaNumber count,density;
00792     unsigned int size, remainder, fractional;
00793 
00794     count = Cudd_ApaCountMinterm(dd,node,nvars,&digits);
00795     if (count == NULL)
00796         return(0);
00797     size = Cudd_DagSize(node);
00798     density = Cudd_NewApaNumber(digits);
00799     remainder = Cudd_ApaIntDivision(digits,count,size,density);
00800     result = Cudd_ApaPrintDecimal(fp,digits,density);
00801     FREE(count);
00802     FREE(density);
00803     fractional = (unsigned int)((double)remainder / size * 1000000);
00804     if (fprintf(fp,".%u\n", fractional) == EOF) {
00805         return(0);
00806     }
00807     return(result);
00808 
00809 } /* end of Cudd_ApaPrintDensity */

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 564 of file cuddApa.c.

00569 {
00570     int i, first, last, result;
00571     DdApaDigit remainder;
00572     DdApaNumber work;
00573     unsigned char *decimal;
00574     int decimalDigits = (int) (digits * log10((double) DD_APA_BASE)) + 1;
00575     
00576     work = Cudd_NewApaNumber(digits);
00577     if (work == NULL)
00578         return(0);
00579     decimal = ALLOC(unsigned char, decimalDigits);
00580     if (decimal == NULL) {
00581         FREE(work);
00582         return(0);
00583     }
00584     Cudd_ApaCopy(digits,number,work);
00585     first = decimalDigits - 1;
00586     for (i = decimalDigits - 1; i >= 0; i--) {
00587         remainder = Cudd_ApaShortDivision(digits,work,(DdApaDigit) 10,work);
00588         decimal[i] = remainder;
00589         if (remainder != 0) first = i; /* keep track of MS non-zero */
00590     }
00591     FREE(work);
00592     last = ddMin(first + precision, decimalDigits);
00593 
00594     for (i = first; i < last; i++) {
00595         result = fprintf(fp,"%s%1d",i == first+1 ? "." : "", decimal[i]);
00596         if (result == EOF) {
00597             FREE(decimal);
00598             return(0);
00599         }
00600     }
00601     FREE(decimal);
00602     result = fprintf(fp,"e+%d",decimalDigits - first - 1);
00603     if (result == EOF) {
00604         return(0);
00605     }
00606     return(1);
00607 
00608 } /* end of Cudd_ApaPrintExponential */

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 477 of file cuddApa.c.

00481 {
00482     int i, result;
00483 
00484     for (i = 0; i < digits; i++) {
00485         result = fprintf(fp,DD_APA_HEXPRINT,number[i]);
00486         if (result == EOF)
00487             return(0);
00488     }
00489     return(1);
00490 
00491 } /* end of Cudd_ApaPrintHex */

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 706 of file cuddApa.c.

00711 {
00712     int digits;
00713     int result;
00714     DdApaNumber count;
00715 
00716     count = Cudd_ApaCountMinterm(dd,node,nvars,&digits);
00717     if (count == NULL)
00718         return(0);
00719     result = Cudd_ApaPrintDecimal(fp,digits,count);
00720     FREE(count);
00721     if (fprintf(fp,"\n") == EOF) {
00722         return(0);
00723     }
00724     return(result);
00725 
00726 } /* end of Cudd_ApaPrintMinterm */

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 745 of file cuddApa.c.

00751 {
00752     int digits;
00753     int result;
00754     DdApaNumber count;
00755 
00756     count = Cudd_ApaCountMinterm(dd,node,nvars,&digits);
00757     if (count == NULL)
00758         return(0);
00759     result = Cudd_ApaPrintExponential(fp,digits,count,precision);
00760     FREE(count);
00761     if (fprintf(fp,"\n") == EOF) {
00762         return(0);
00763     }
00764     return(result);
00765 
00766 } /* end of Cudd_ApaPrintMintermExp */

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 336 of file cuddApa.c.

00340 {
00341     int i;
00342 
00343     for (i = 0; i < digits - 1; i++)
00344         number[i] = 0;
00345     number[digits - 1] = literal;
00346 
00347 } /* 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 308 of file cuddApa.c.

00313 {
00314     int i;
00315 
00316     for (i = digits - 1; i > 0; i--) {
00317         b[i] = (a[i] >> 1) | ((a[i-1] & 1) << (DD_APA_BITS - 1));
00318     }
00319     b[0] = (a[0] >> 1) | (in << (DD_APA_BITS - 1));
00320 
00321 } /* end of Cudd_ApaShiftRight */

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 230 of file cuddApa.c.

00235 {
00236     int i;
00237     DdApaDigit remainder;
00238     DdApaDoubleDigit partial;
00239 
00240     remainder = 0;
00241     for (i = 0; i < digits; i++) {
00242         partial = remainder * DD_APA_BASE + dividend[i];
00243         quotient[i] = (DdApaDigit) (partial/(DdApaDoubleDigit)divisor);
00244         remainder = (DdApaDigit) (partial % divisor);
00245     }
00246 
00247     return(remainder);
00248 
00249 } /* end of Cudd_ApaShortDivision */

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 200 of file cuddApa.c.

00205 {
00206     int i;
00207     DdApaDoubleDigit partial = DD_APA_BASE;
00208 
00209     for (i = digits - 1; i >= 0; i--) {
00210         partial = a[i] - b[i] + DD_MSDIGIT(partial) + DD_APA_MASK;
00211         diff[i] = (DdApaDigit) DD_LSDIGIT(partial);
00212     }
00213     return(DD_MSDIGIT(partial) - 1);
00214 
00215 } /* end of Cudd_ApaSubtract */

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 121 of file cuddApa.c.

00123 {
00124     return(ALLOC(DdApaDigit, digits));
00125 
00126 } /* end of Cudd_NewApaNumber */

static DdApaNumber cuddApaCountMintermAux ( DdNode node,
int  digits,
DdApaNumber  max,
DdApaNumber  min,
st_table table 
) [static]

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 844 of file cuddApa.c.

00850 {
00851     DdNode      *Nt, *Ne;
00852     DdApaNumber mint, mint1, mint2;
00853     DdApaDigit  carryout;
00854 
00855     if (cuddIsConstant(node)) {
00856         if (node == background || node == zero) {
00857             return(min);
00858         } else {
00859             return(max);
00860         }
00861     }
00862     if (node->ref > 1 && st_lookup(table, (char *)node, (char **)&mint)) {
00863         return(mint);
00864     }
00865 
00866     Nt = cuddT(node); Ne = cuddE(node);
00867 
00868     mint1 = cuddApaCountMintermAux(Nt,  digits, max, min, table);
00869     if (mint1 == NULL) return(NULL);
00870     mint2 = cuddApaCountMintermAux(Cudd_Regular(Ne), digits, max, min, table);
00871     if (mint2 == NULL) {
00872         if (Nt->ref == 1) FREE(mint1);
00873         return(NULL);
00874     }
00875     mint = Cudd_NewApaNumber(digits);
00876     if (mint == NULL) {
00877         if (Nt->ref == 1) FREE(mint1);
00878         if (Cudd_Regular(Ne)->ref == 1) FREE(mint2);
00879         return(NULL);
00880     }
00881     if (Cudd_IsComplement(Ne)) {
00882         (void) Cudd_ApaSubtract(digits,max,mint2,mint);
00883         carryout = Cudd_ApaAdd(digits,mint1,mint,mint);
00884     } else {
00885         carryout = Cudd_ApaAdd(digits,mint1,mint2,mint);
00886     }
00887     Cudd_ApaShiftRight(digits,carryout,mint,mint);
00888     /* If the refernce count of a child is 1, its minterm count
00889     ** hasn't been stored in table.  Therefore, it must be explicitly
00890     ** freed here. */
00891     if (Nt->ref == 1) FREE(mint1);
00892     if (Cudd_Regular(Ne)->ref == 1) FREE(mint2);
00893     
00894     if (node->ref > 1) {
00895         if (st_insert(table, (char *)node, (char *)mint) == ST_OUT_OF_MEM) {
00896             FREE(mint);
00897             return(NULL);
00898         }
00899     }
00900     return(mint);
00901 
00902 } /* end of cuddApaCountMintermAux */

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 917 of file cuddApa.c.

00921 {
00922     DdApaNumber d;
00923 
00924     d = (DdApaNumber) value;
00925     FREE(d);
00926     return(ST_CONTINUE);
00927 
00928 } /* end of cuddApaStCountfree */


Variable Documentation

DdNode* background [static]

Definition at line 54 of file cuddApa.c.

char rcsid [] DD_UNUSED = "$Id: cuddApa.c,v 1.1.1.1 2003/02/24 22:23:51 wjiang Exp $" [static]

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

FileName [cuddApa.c]

PackageName [cudd]

Synopsis [Arbitrary precision arithmetic functions.]

Description [External procedures included in this module:

Internal procedures included in this module:

  • ()

Static procedures included in this module:

  • ()

]

Author [Fabio Somenzi]

Copyright [This file was created at the University of Colorado at Boulder. The University of Colorado at Boulder makes no warranty about the suitability of this software for any purpose. It is presented on an AS IS basis.]

Definition at line 51 of file cuddApa.c.

DdNode * zero [static]

Definition at line 54 of file cuddApa.c.


Generated on Tue Jan 5 12:18:52 2010 for abc70930 by  doxygen 1.6.1