src/cuBdd/cuddApa.c File Reference

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

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

00222 {
00223     int i;
00224     DdApaDoubleDigit partial = 0;
00225 
00226     for (i = digits - 1; i >= 0; i--) {
00227         partial = a[i] + b[i] + DD_MSDIGIT(partial);
00228         sum[i] = (DdApaDigit) DD_LSDIGIT(partial);
00229     }
00230     return((DdApaDigit) DD_MSDIGIT(partial));
00231 
00232 } /* 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 445 of file cuddApa.c.

00450 {
00451     int i;
00452     int firstNZ, secondNZ;
00453 
00454     /* Find first non-zero in both numbers. */
00455     for (firstNZ = 0; firstNZ < digitsFirst; firstNZ++)
00456         if (first[firstNZ] != 0) break;
00457     for (secondNZ = 0; secondNZ < digitsSecond; secondNZ++)
00458         if (second[secondNZ] != 0) break;
00459     if (digitsFirst - firstNZ > digitsSecond - secondNZ) return(1);
00460     else if (digitsFirst - firstNZ < digitsSecond - secondNZ) return(-1);
00461     for (i = 0; i < digitsFirst - firstNZ; i++) {
00462         if (first[firstNZ + i] > second[secondNZ + i]) return(1);
00463         else if (first[firstNZ + i] < second[secondNZ + i]) return(-1);
00464     }
00465     return(0);
00466 
00467 } /* 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 485 of file cuddApa.c.

00492 {
00493     int result;
00494     DdApaNumber first, second;
00495     unsigned int firstRem, secondRem;
00496 
00497     first = Cudd_NewApaNumber(digitsFirst);
00498     firstRem = Cudd_ApaIntDivision(digitsFirst,firstNum,firstDen,first);
00499     second = Cudd_NewApaNumber(digitsSecond);
00500     secondRem = Cudd_ApaIntDivision(digitsSecond,secondNum,secondDen,second);
00501     result = Cudd_ApaCompare(digitsFirst,first,digitsSecond,second);
00502     FREE(first);
00503     FREE(second);
00504     if (result == 0) {
00505         if ((double)firstRem/firstDen > (double)secondRem/secondDen)
00506             return(1);
00507         else if ((double)firstRem/firstDen < (double)secondRem/secondDen)
00508             return(-1);
00509     }
00510     return(result);
00511 
00512 } /* 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 190 of file cuddApa.c.

00194 {
00195     int i;
00196 
00197     for (i = 0; i < digits; i++) {
00198         dest[i] = source[i];
00199     }
00200 
00201 } /* 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 680 of file cuddApa.c.

00685 {
00686     DdApaNumber max, min;
00687     st_table    *table;
00688     DdApaNumber i,count;
00689 
00690     background = manager->background;
00691     zero = Cudd_Not(manager->one);
00692 
00693     *digits = Cudd_ApaNumberOfDigits(nvars+1);
00694     max = Cudd_NewApaNumber(*digits);
00695     if (max == NULL) {
00696         return(NULL);
00697     }
00698     Cudd_ApaPowerOfTwo(*digits,max,nvars);
00699     min = Cudd_NewApaNumber(*digits);
00700     if (min == NULL) {
00701         FREE(max);
00702         return(NULL);
00703     }
00704     Cudd_ApaSetToLiteral(*digits,min,0);
00705     table = st_init_table(st_ptrcmp,st_ptrhash);
00706     if (table == NULL) {
00707         FREE(max);
00708         FREE(min);
00709         return(NULL);
00710     }
00711     i = cuddApaCountMintermAux(Cudd_Regular(node),*digits,max,min,table);
00712     if (i == NULL) {
00713         FREE(max);
00714         FREE(min);
00715         st_foreach(table, cuddApaStCountfree, NULL);
00716         st_free_table(table);
00717         return(NULL);
00718     }
00719     count = Cudd_NewApaNumber(*digits);
00720     if (count == NULL) {
00721         FREE(max);
00722         FREE(min);
00723         st_foreach(table, cuddApaStCountfree, NULL);
00724         st_free_table(table);
00725         if (Cudd_Regular(node)->ref == 1) FREE(i);
00726         return(NULL);
00727     }
00728     if (Cudd_IsComplement(node)) {
00729         (void) Cudd_ApaSubtract(*digits,max,i,count);
00730     } else {
00731         Cudd_ApaCopy(*digits,i,count);
00732     }
00733     FREE(max);
00734     FREE(min);
00735     st_foreach(table, cuddApaStCountfree, NULL);
00736     st_free_table(table);
00737     if (Cudd_Regular(node)->ref == 1) FREE(i);
00738     return(count);
00739 
00740 } /* 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 320 of file cuddApa.c.

00325 {
00326     int i;
00327     double partial;
00328     unsigned int remainder = 0;
00329     double ddiv = (double) divisor;
00330 
00331     for (i = 0; i < digits; i++) {
00332         partial = (double) remainder * DD_APA_BASE + dividend[i];
00333         quotient[i] = (DdApaDigit) (partial / ddiv);
00334         remainder = (unsigned int) (partial - ((double)quotient[i] * ddiv));
00335     }
00336 
00337     return(remainder);
00338 
00339 } /* 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 143 of file cuddApa.c.

00145 {
00146     int digits;
00147 
00148     digits = binaryDigits / DD_APA_BITS;
00149     if ((digits * DD_APA_BITS) != binaryDigits)
00150         digits++;
00151     return(digits);
00152 
00153 } /* 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 413 of file cuddApa.c.

00417 {
00418     int i;
00419     int index;
00420 
00421     for (i = 0; i < digits; i++)
00422         number[i] = 0;
00423     i = digits - 1 - power / DD_APA_BITS;
00424     if (i < 0) return;
00425     index = power & (DD_APA_BITS - 1);
00426     number[i] = 1 << index;
00427 
00428 } /* 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 558 of file cuddApa.c.

00562 {
00563     int i, result;
00564     DdApaDigit remainder;
00565     DdApaNumber work;
00566     unsigned char *decimal;
00567     int leadingzero;
00568     int decimalDigits = (int) (digits * log10((double) DD_APA_BASE)) + 1;
00569 
00570     work = Cudd_NewApaNumber(digits);
00571     if (work == NULL)
00572         return(0);
00573     decimal = ALLOC(unsigned char, decimalDigits);
00574     if (decimal == NULL) {
00575         FREE(work);
00576         return(0);
00577     }
00578     Cudd_ApaCopy(digits,number,work);
00579     for (i = decimalDigits - 1; i >= 0; i--) {
00580         remainder = Cudd_ApaShortDivision(digits,work,(DdApaDigit) 10,work);
00581         decimal[i] = (unsigned char) remainder;
00582     }
00583     FREE(work);
00584 
00585     leadingzero = 1;
00586     for (i = 0; i < decimalDigits; i++) {
00587         leadingzero = leadingzero && (decimal[i] == 0);
00588         if ((!leadingzero) || (i == (decimalDigits - 1))) {
00589             result = fprintf(fp,"%1d",decimal[i]);
00590             if (result == EOF) {
00591                 FREE(decimal);
00592                 return(0);
00593             }
00594         }
00595     }
00596     FREE(decimal);
00597     return(1);
00598 
00599 } /* 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 834 of file cuddApa.c.

00839 {
00840     int digits;
00841     int result;
00842     DdApaNumber count,density;
00843     unsigned int size, remainder, fractional;
00844 
00845     count = Cudd_ApaCountMinterm(dd,node,nvars,&digits);
00846     if (count == NULL)
00847         return(0);
00848     size = Cudd_DagSize(node);
00849     density = Cudd_NewApaNumber(digits);
00850     remainder = Cudd_ApaIntDivision(digits,count,size,density);
00851     result = Cudd_ApaPrintDecimal(fp,digits,density);
00852     FREE(count);
00853     FREE(density);
00854     fractional = (unsigned int)((double)remainder / size * 1000000);
00855     if (fprintf(fp,".%u\n", fractional) == EOF) {
00856         return(0);
00857     }
00858     return(result);
00859 
00860 } /* 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 615 of file cuddApa.c.

00620 {
00621     int i, first, last, result;
00622     DdApaDigit remainder;
00623     DdApaNumber work;
00624     unsigned char *decimal;
00625     int decimalDigits = (int) (digits * log10((double) DD_APA_BASE)) + 1;
00626 
00627     work = Cudd_NewApaNumber(digits);
00628     if (work == NULL)
00629         return(0);
00630     decimal = ALLOC(unsigned char, decimalDigits);
00631     if (decimal == NULL) {
00632         FREE(work);
00633         return(0);
00634     }
00635     Cudd_ApaCopy(digits,number,work);
00636     first = decimalDigits - 1;
00637     for (i = decimalDigits - 1; i >= 0; i--) {
00638         remainder = Cudd_ApaShortDivision(digits,work,(DdApaDigit) 10,work);
00639         decimal[i] = (unsigned char) remainder;
00640         if (remainder != 0) first = i; /* keep track of MS non-zero */
00641     }
00642     FREE(work);
00643     last = ddMin(first + precision, decimalDigits);
00644 
00645     for (i = first; i < last; i++) {
00646         result = fprintf(fp,"%s%1d",i == first+1 ? "." : "", decimal[i]);
00647         if (result == EOF) {
00648             FREE(decimal);
00649             return(0);
00650         }
00651     }
00652     FREE(decimal);
00653     result = fprintf(fp,"e+%d",decimalDigits - first - 1);
00654     if (result == EOF) {
00655         return(0);
00656     }
00657     return(1);
00658 
00659 } /* 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 528 of file cuddApa.c.

00532 {
00533     int i, result;
00534 
00535     for (i = 0; i < digits; i++) {
00536         result = fprintf(fp,DD_APA_HEXPRINT,number[i]);
00537         if (result == EOF)
00538             return(0);
00539     }
00540     return(1);
00541 
00542 } /* 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 757 of file cuddApa.c.

00762 {
00763     int digits;
00764     int result;
00765     DdApaNumber count;
00766 
00767     count = Cudd_ApaCountMinterm(dd,node,nvars,&digits);
00768     if (count == NULL)
00769         return(0);
00770     result = Cudd_ApaPrintDecimal(fp,digits,count);
00771     FREE(count);
00772     if (fprintf(fp,"\n") == EOF) {
00773         return(0);
00774     }
00775     return(result);
00776 
00777 } /* 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 796 of file cuddApa.c.

00802 {
00803     int digits;
00804     int result;
00805     DdApaNumber count;
00806 
00807     count = Cudd_ApaCountMinterm(dd,node,nvars,&digits);
00808     if (count == NULL)
00809         return(0);
00810     result = Cudd_ApaPrintExponential(fp,digits,count,precision);
00811     FREE(count);
00812     if (fprintf(fp,"\n") == EOF) {
00813         return(0);
00814     }
00815     return(result);
00816 
00817 } /* 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 385 of file cuddApa.c.

00389 {
00390     int i;
00391 
00392     for (i = 0; i < digits - 1; i++)
00393         number[i] = 0;
00394     number[digits - 1] = literal;
00395 
00396 } /* 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 357 of file cuddApa.c.

00362 {
00363     int i;
00364 
00365     for (i = digits - 1; i > 0; i--) {
00366         b[i] = (a[i] >> 1) | ((a[i-1] & 1) << (DD_APA_BITS - 1));
00367     }
00368     b[0] = (a[0] >> 1) | (in << (DD_APA_BITS - 1));
00369 
00370 } /* 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 279 of file cuddApa.c.

00284 {
00285     int i;
00286     DdApaDigit remainder;
00287     DdApaDoubleDigit partial;
00288 
00289     remainder = 0;
00290     for (i = 0; i < digits; i++) {
00291         partial = remainder * DD_APA_BASE + dividend[i];
00292         quotient[i] = (DdApaDigit) (partial/(DdApaDoubleDigit)divisor);
00293         remainder = (DdApaDigit) (partial % divisor);
00294     }
00295 
00296     return(remainder);
00297 
00298 } /* 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 249 of file cuddApa.c.

00254 {
00255     int i;
00256     DdApaDoubleDigit partial = DD_APA_BASE;
00257 
00258     for (i = digits - 1; i >= 0; i--) {
00259         partial = DD_MSDIGIT(partial) + DD_APA_MASK + a[i] - b[i];
00260         diff[i] = (DdApaDigit) DD_LSDIGIT(partial);
00261     }
00262     return((DdApaDigit) DD_MSDIGIT(partial) - 1);
00263 
00264 } /* 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 170 of file cuddApa.c.

00172 {
00173     return(ALLOC(DdApaDigit, digits));
00174 
00175 } /* end of Cudd_NewApaNumber */

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

00901 {
00902     DdNode      *Nt, *Ne;
00903     DdApaNumber mint, mint1, mint2;
00904     DdApaDigit  carryout;
00905 
00906     if (cuddIsConstant(node)) {
00907         if (node == background || node == zero) {
00908             return(min);
00909         } else {
00910             return(max);
00911         }
00912     }
00913     if (node->ref > 1 && st_lookup(table, node, &mint)) {
00914         return(mint);
00915     }
00916 
00917     Nt = cuddT(node); Ne = cuddE(node);
00918 
00919     mint1 = cuddApaCountMintermAux(Nt,  digits, max, min, table);
00920     if (mint1 == NULL) return(NULL);
00921     mint2 = cuddApaCountMintermAux(Cudd_Regular(Ne), digits, max, min, table);
00922     if (mint2 == NULL) {
00923         if (Nt->ref == 1) FREE(mint1);
00924         return(NULL);
00925     }
00926     mint = Cudd_NewApaNumber(digits);
00927     if (mint == NULL) {
00928         if (Nt->ref == 1) FREE(mint1);
00929         if (Cudd_Regular(Ne)->ref == 1) FREE(mint2);
00930         return(NULL);
00931     }
00932     if (Cudd_IsComplement(Ne)) {
00933         (void) Cudd_ApaSubtract(digits,max,mint2,mint);
00934         carryout = Cudd_ApaAdd(digits,mint1,mint,mint);
00935     } else {
00936         carryout = Cudd_ApaAdd(digits,mint1,mint2,mint);
00937     }
00938     Cudd_ApaShiftRight(digits,carryout,mint,mint);
00939     /* If the refernce count of a child is 1, its minterm count
00940     ** hasn't been stored in table.  Therefore, it must be explicitly
00941     ** freed here. */
00942     if (Nt->ref == 1) FREE(mint1);
00943     if (Cudd_Regular(Ne)->ref == 1) FREE(mint2);
00944 
00945     if (node->ref > 1) {
00946         if (st_insert(table, (char *)node, (char *)mint) == ST_OUT_OF_MEM) {
00947             FREE(mint);
00948             return(NULL);
00949         }
00950     }
00951     return(mint);
00952 
00953 } /* 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 968 of file cuddApa.c.

00972 {
00973     DdApaNumber d;
00974 
00975     d = (DdApaNumber) value;
00976     FREE(d);
00977     return(ST_CONTINUE);
00978 
00979 } /* end of cuddApaStCountfree */


Variable Documentation

DdNode* background [static]

Definition at line 96 of file cuddApa.c.

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

DdNode * zero [static]

Definition at line 96 of file cuddApa.c.


Generated on Tue Jan 12 13:57:18 2010 for glu-2.2 by  doxygen 1.6.1