📄 cuddaddapply.c
字号:
/**CFile*********************************************************************** FileName [cuddAddApply.c] PackageName [cudd] Synopsis [Apply functions for ADDs and their operators.] Description [External procedures included in this module: <ul> <li> Cudd_addApply() <li> Cudd_addMonadicApply() <li> Cudd_addPlus() <li> Cudd_addTimes() <li> Cudd_addThreshold() <li> Cudd_addSetNZ() <li> Cudd_addDivide() <li> Cudd_addMinus() <li> Cudd_addMinimum() <li> Cudd_addMaximum() <li> Cudd_addOneZeroMaximum() <li> Cudd_addDiff() <li> Cudd_addAgreement() <li> Cudd_addOr() <li> Cudd_addNand() <li> Cudd_addNor() <li> Cudd_addXor() <li> Cudd_addXnor() </ul> Internal procedures included in this module: <ul> <li> cuddAddApplyRecur() <li> cuddAddMonadicApplyRecur() </ul>] 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.]******************************************************************************/#include "util.h"#include "cuddInt.h"/*---------------------------------------------------------------------------*//* Constant declarations *//*---------------------------------------------------------------------------*//*---------------------------------------------------------------------------*//* Stucture declarations *//*---------------------------------------------------------------------------*//*---------------------------------------------------------------------------*//* Type declarations *//*---------------------------------------------------------------------------*//*---------------------------------------------------------------------------*//* Variable declarations *//*---------------------------------------------------------------------------*/#ifndef lintstatic char rcsid[] DD_UNUSED = "$Id: cuddAddApply.c,v 1.1.1.1 2003/02/24 22:23:50 wjiang Exp $";#endif/*---------------------------------------------------------------------------*//* Macro declarations *//*---------------------------------------------------------------------------*//**AutomaticStart*************************************************************//*---------------------------------------------------------------------------*//* Static function prototypes *//*---------------------------------------------------------------------------*//**AutomaticEnd***************************************************************//*---------------------------------------------------------------------------*//* Definition of exported functions *//*---------------------------------------------------------------------------*//**Function******************************************************************** Synopsis [Applies op to the corresponding discriminants of f and g.] Description [Applies op to the corresponding discriminants of f and g. Returns a pointer to the result if succssful; NULL otherwise.] SideEffects [None] SeeAlso [Cudd_addMonadicApply Cudd_addPlus Cudd_addTimes Cudd_addThreshold Cudd_addSetNZ Cudd_addDivide Cudd_addMinus Cudd_addMinimum Cudd_addMaximum Cudd_addOneZeroMaximum Cudd_addDiff Cudd_addAgreement Cudd_addOr Cudd_addNand Cudd_addNor Cudd_addXor Cudd_addXnor]******************************************************************************/DdNode *Cudd_addApply( DdManager * dd, DdNode * (*op)(DdManager *, DdNode **, DdNode **), DdNode * f, DdNode * g){ DdNode *res; do { dd->reordered = 0; res = cuddAddApplyRecur(dd,op,f,g); } while (dd->reordered == 1); return(res);} /* end of Cudd_addApply *//**Function******************************************************************** Synopsis [Integer and floating point addition.] Description [Integer and floating point addition. Returns NULL if not a terminal case; f+g otherwise.] SideEffects [None] SeeAlso [Cudd_addApply]******************************************************************************/DdNode *Cudd_addPlus( DdManager * dd, DdNode ** f, DdNode ** g){ DdNode *res; DdNode *F, *G; CUDD_VALUE_TYPE value; F = *f; G = *g; if (F == DD_ZERO(dd)) return(G); if (G == DD_ZERO(dd)) return(F); if (cuddIsConstant(F) && cuddIsConstant(G)) { value = cuddV(F)+cuddV(G); res = cuddUniqueConst(dd,value); return(res); } if (F > G) { /* swap f and g */ *f = G; *g = F; } return(NULL);} /* end of Cudd_addPlus *//**Function******************************************************************** Synopsis [Integer and floating point multiplication.] Description [Integer and floating point multiplication. Returns NULL if not a terminal case; f * g otherwise. This function can be used also to take the AND of two 0-1 ADDs.] SideEffects [None] SeeAlso [Cudd_addApply]******************************************************************************/DdNode *Cudd_addTimes( DdManager * dd, DdNode ** f, DdNode ** g){ DdNode *res; DdNode *F, *G; CUDD_VALUE_TYPE value; F = *f; G = *g; if (F == DD_ZERO(dd) || G == DD_ZERO(dd)) return(DD_ZERO(dd)); if (F == DD_ONE(dd)) return(G); if (G == DD_ONE(dd)) return(F); if (cuddIsConstant(F) && cuddIsConstant(G)) { value = cuddV(F)*cuddV(G); res = cuddUniqueConst(dd,value); return(res); } if (F > G) { /* swap f and g */ *f = G; *g = F; } return(NULL);} /* end of Cudd_addTimes *//**Function******************************************************************** Synopsis [f if f>=g; 0 if f<g.] Description [Threshold operator for Apply (f if f >=g; 0 if f<g). Returns NULL if not a terminal case; f op g otherwise.] SideEffects [None] SeeAlso [Cudd_addApply]******************************************************************************/DdNode *Cudd_addThreshold( DdManager * dd, DdNode ** f, DdNode ** g){ DdNode *F, *G; F = *f; G = *g; if (F == G || F == DD_PLUS_INFINITY(dd)) return(F); if (cuddIsConstant(F) && cuddIsConstant(G)) { if (cuddV(F) >= cuddV(G)) { return(F); } else { return(DD_ZERO(dd)); } } return(NULL);} /* end of Cudd_addThreshold *//**Function******************************************************************** Synopsis [This operator sets f to the value of g wherever g != 0.] Description [This operator sets f to the value of g wherever g != 0. Returns NULL if not a terminal case; f op g otherwise.] SideEffects [None] SeeAlso [Cudd_addApply]******************************************************************************/DdNode *Cudd_addSetNZ( DdManager * dd, DdNode ** f, DdNode ** g){ DdNode *F, *G; F = *f; G = *g; if (F == G) return(F); if (F == DD_ZERO(dd)) return(G); if (G == DD_ZERO(dd)) return(F); if (cuddIsConstant(G)) return(G); return(NULL);} /* end of Cudd_addSetNZ *//**Function******************************************************************** Synopsis [Integer and floating point division.] Description [Integer and floating point division. Returns NULL if not a terminal case; f / g otherwise.] SideEffects [None] SeeAlso [Cudd_addApply]******************************************************************************/DdNode *Cudd_addDivide( DdManager * dd, DdNode ** f, DdNode ** g){ DdNode *res; DdNode *F, *G; CUDD_VALUE_TYPE value; F = *f; G = *g; /* We would like to use F == G -> F/G == 1, but F and G may ** contain zeroes. */ if (F == DD_ZERO(dd)) return(DD_ZERO(dd)); if (G == DD_ONE(dd)) return(F); if (cuddIsConstant(F) && cuddIsConstant(G)) { value = cuddV(F)/cuddV(G); res = cuddUniqueConst(dd,value); return(res); } return(NULL);} /* end of Cudd_addDivide *//**Function******************************************************************** Synopsis [Integer and floating point subtraction.] Description [Integer and floating point subtraction. Returns NULL if not a terminal case; f - g otherwise.] SideEffects [None] SeeAlso [Cudd_addApply]******************************************************************************/DdNode *Cudd_addMinus( DdManager * dd, DdNode ** f, DdNode ** g){ DdNode *res; DdNode *F, *G; CUDD_VALUE_TYPE value; F = *f; G = *g; if (F == G) return(DD_ZERO(dd)); if (F == DD_ZERO(dd)) return(cuddAddNegateRecur(dd,G)); if (G == DD_ZERO(dd)) return(F); if (cuddIsConstant(F) && cuddIsConstant(G)) { value = cuddV(F)-cuddV(G); res = cuddUniqueConst(dd,value); return(res); } return(NULL);} /* end of Cudd_addMinus *//**Function******************************************************************** Synopsis [Integer and floating point min.] Description [Integer and floating point min for Cudd_addApply. Returns NULL if not a terminal case; min(f,g) otherwise.] SideEffects [None] SeeAlso [Cudd_addApply]******************************************************************************/DdNode *Cudd_addMinimum( DdManager * dd, DdNode ** f, DdNode ** g){ DdNode *F, *G; F = *f; G = *g; if (F == DD_PLUS_INFINITY(dd)) return(G); if (G == DD_PLUS_INFINITY(dd)) return(F); if (F == G) return(F);#if 0 /* These special cases probably do not pay off. */ if (F == DD_MINUS_INFINITY(dd)) return(F); if (G == DD_MINUS_INFINITY(dd)) return(G);#endif if (cuddIsConstant(F) && cuddIsConstant(G)) { if (cuddV(F) <= cuddV(G)) { return(F); } else { return(G); } } if (F > G) { /* swap f and g */ *f = G; *g = F; } return(NULL);} /* end of Cudd_addMinimum *//**Function******************************************************************** Synopsis [Integer and floating point max.] Description [Integer and floating point max for Cudd_addApply. Returns NULL if not a terminal case; max(f,g) otherwise.] SideEffects [None] SeeAlso [Cudd_addApply]******************************************************************************/DdNode *Cudd_addMaximum( DdManager * dd, DdNode ** f, DdNode ** g){ DdNode *F, *G; F = *f; G = *g; if (F == G) return(F); if (F == DD_MINUS_INFINITY(dd)) return(G); if (G == DD_MINUS_INFINITY(dd)) return(F);#if 0 /* These special cases probably do not pay off. */ if (F == DD_PLUS_INFINITY(dd)) return(F); if (G == DD_PLUS_INFINITY(dd)) return(G);#endif if (cuddIsConstant(F) && cuddIsConstant(G)) { if (cuddV(F) >= cuddV(G)) { return(F); } else { return(G); } } if (F > G) { /* swap f and g */ *f = G; *g = F; } return(NULL);} /* end of Cudd_addMaximum *//**Function******************************************************************** Synopsis [Returns 1 if f > g and 0 otherwise.] Description [Returns 1 if f > g and 0 otherwise. Used in conjunction with Cudd_addApply. Returns NULL if not a terminal case.] SideEffects [None] SeeAlso [Cudd_addApply]******************************************************************************/DdNode *Cudd_addOneZeroMaximum( DdManager * dd, DdNode ** f, DdNode ** g){ if (*f == *g) return(DD_ZERO(dd)); if (*g == DD_PLUS_INFINITY(dd)) return DD_ZERO(dd); if (cuddIsConstant(*f) && cuddIsConstant(*g)) { if (cuddV(*f) > cuddV(*g)) { return(DD_ONE(dd)); } else { return(DD_ZERO(dd)); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -