You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

760 lines
21 KiB

  1. /**CFile***********************************************************************
  2. FileName [cuddBddAbs.c]
  3. PackageName [cudd]
  4. Synopsis [Quantification functions for BDDs.]
  5. Description [External procedures included in this module:
  6. <ul>
  7. <li> Cudd_bddExistAbstract()
  8. <li> Cudd_bddExistAbstractLimit()
  9. <li> Cudd_bddXorExistAbstract()
  10. <li> Cudd_bddUnivAbstract()
  11. <li> Cudd_bddBooleanDiff()
  12. <li> Cudd_bddVarIsDependent()
  13. </ul>
  14. Internal procedures included in this module:
  15. <ul>
  16. <li> cuddBddExistAbstractRecur()
  17. <li> cuddBddXorExistAbstractRecur()
  18. <li> cuddBddBooleanDiffRecur()
  19. </ul>
  20. Static procedures included in this module:
  21. <ul>
  22. <li> bddCheckPositiveCube()
  23. </ul>
  24. ]
  25. Author [Fabio Somenzi]
  26. Copyright [Copyright (c) 1995-2012, Regents of the University of Colorado
  27. All rights reserved.
  28. Redistribution and use in source and binary forms, with or without
  29. modification, are permitted provided that the following conditions
  30. are met:
  31. Redistributions of source code must retain the above copyright
  32. notice, this list of conditions and the following disclaimer.
  33. Redistributions in binary form must reproduce the above copyright
  34. notice, this list of conditions and the following disclaimer in the
  35. documentation and/or other materials provided with the distribution.
  36. Neither the name of the University of Colorado nor the names of its
  37. contributors may be used to endorse or promote products derived from
  38. this software without specific prior written permission.
  39. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  40. "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  41. LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  42. FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  43. COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  44. INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  45. BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  46. LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  47. CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  48. LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  49. ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  50. POSSIBILITY OF SUCH DAMAGE.]
  51. ******************************************************************************/
  52. #include "util.h"
  53. #include "cuddInt.h"
  54. /*---------------------------------------------------------------------------*/
  55. /* Constant declarations */
  56. /*---------------------------------------------------------------------------*/
  57. /*---------------------------------------------------------------------------*/
  58. /* Stucture declarations */
  59. /*---------------------------------------------------------------------------*/
  60. /*---------------------------------------------------------------------------*/
  61. /* Type declarations */
  62. /*---------------------------------------------------------------------------*/
  63. /*---------------------------------------------------------------------------*/
  64. /* Variable declarations */
  65. /*---------------------------------------------------------------------------*/
  66. #ifndef lint
  67. static char rcsid[] DD_UNUSED = "$Id: cuddBddAbs.c,v 1.28 2012/02/05 01:07:18 fabio Exp $";
  68. #endif
  69. /*---------------------------------------------------------------------------*/
  70. /* Macro declarations */
  71. /*---------------------------------------------------------------------------*/
  72. /**AutomaticStart*************************************************************/
  73. /*---------------------------------------------------------------------------*/
  74. /* Static function prototypes */
  75. /*---------------------------------------------------------------------------*/
  76. static int bddCheckPositiveCube (DdManager *manager, DdNode *cube);
  77. /**AutomaticEnd***************************************************************/
  78. /*---------------------------------------------------------------------------*/
  79. /* Definition of exported functions */
  80. /*---------------------------------------------------------------------------*/
  81. /**Function********************************************************************
  82. Synopsis [Existentially abstracts all the variables in cube from f.]
  83. Description [Existentially abstracts all the variables in cube from f.
  84. Returns the abstracted BDD if successful; NULL otherwise.]
  85. SideEffects [None]
  86. SeeAlso [Cudd_bddUnivAbstract Cudd_addExistAbstract]
  87. ******************************************************************************/
  88. DdNode *
  89. Cudd_bddExistAbstract(
  90. DdManager * manager,
  91. DdNode * f,
  92. DdNode * cube)
  93. {
  94. DdNode *res;
  95. if (bddCheckPositiveCube(manager, cube) == 0) {
  96. (void) fprintf(manager->err,
  97. "Error: Can only abstract positive cubes\n");
  98. manager->errorCode = CUDD_INVALID_ARG;
  99. return(NULL);
  100. }
  101. do {
  102. manager->reordered = 0;
  103. res = cuddBddExistAbstractRecur(manager, f, cube);
  104. } while (manager->reordered == 1);
  105. return(res);
  106. } /* end of Cudd_bddExistAbstract */
  107. /**Function********************************************************************
  108. Synopsis [Existentially abstracts all the variables in cube from f.]
  109. Description [Existentially abstracts all the variables in cube from f.
  110. Returns the abstracted BDD if successful; NULL if the intermediate
  111. result blows up or more new nodes than <code>limit</code> are
  112. required.]
  113. SideEffects [None]
  114. SeeAlso [Cudd_bddExistAbstract]
  115. ******************************************************************************/
  116. DdNode *
  117. Cudd_bddExistAbstractLimit(
  118. DdManager * manager,
  119. DdNode * f,
  120. DdNode * cube,
  121. unsigned int limit)
  122. {
  123. DdNode *res;
  124. unsigned int saveLimit = manager->maxLive;
  125. if (bddCheckPositiveCube(manager, cube) == 0) {
  126. (void) fprintf(manager->err,
  127. "Error: Can only abstract positive cubes\n");
  128. manager->errorCode = CUDD_INVALID_ARG;
  129. return(NULL);
  130. }
  131. manager->maxLive = (manager->keys - manager->dead) +
  132. (manager->keysZ - manager->deadZ) + limit;
  133. do {
  134. manager->reordered = 0;
  135. res = cuddBddExistAbstractRecur(manager, f, cube);
  136. } while (manager->reordered == 1);
  137. manager->maxLive = saveLimit;
  138. return(res);
  139. } /* end of Cudd_bddExistAbstractLimit */
  140. /**Function********************************************************************
  141. Synopsis [Takes the exclusive OR of two BDDs and simultaneously abstracts the
  142. variables in cube.]
  143. Description [Takes the exclusive OR of two BDDs and simultaneously abstracts
  144. the variables in cube. The variables are existentially abstracted. Returns a
  145. pointer to the result is successful; NULL otherwise.]
  146. SideEffects [None]
  147. SeeAlso [Cudd_bddUnivAbstract Cudd_bddExistAbstract Cudd_bddAndAbstract]
  148. ******************************************************************************/
  149. DdNode *
  150. Cudd_bddXorExistAbstract(
  151. DdManager * manager,
  152. DdNode * f,
  153. DdNode * g,
  154. DdNode * cube)
  155. {
  156. DdNode *res;
  157. if (bddCheckPositiveCube(manager, cube) == 0) {
  158. (void) fprintf(manager->err,
  159. "Error: Can only abstract positive cubes\n");
  160. manager->errorCode = CUDD_INVALID_ARG;
  161. return(NULL);
  162. }
  163. do {
  164. manager->reordered = 0;
  165. res = cuddBddXorExistAbstractRecur(manager, f, g, cube);
  166. } while (manager->reordered == 1);
  167. return(res);
  168. } /* end of Cudd_bddXorExistAbstract */
  169. /**Function********************************************************************
  170. Synopsis [Universally abstracts all the variables in cube from f.]
  171. Description [Universally abstracts all the variables in cube from f.
  172. Returns the abstracted BDD if successful; NULL otherwise.]
  173. SideEffects [None]
  174. SeeAlso [Cudd_bddExistAbstract Cudd_addUnivAbstract]
  175. ******************************************************************************/
  176. DdNode *
  177. Cudd_bddUnivAbstract(
  178. DdManager * manager,
  179. DdNode * f,
  180. DdNode * cube)
  181. {
  182. DdNode *res;
  183. if (bddCheckPositiveCube(manager, cube) == 0) {
  184. (void) fprintf(manager->err,
  185. "Error: Can only abstract positive cubes\n");
  186. manager->errorCode = CUDD_INVALID_ARG;
  187. return(NULL);
  188. }
  189. do {
  190. manager->reordered = 0;
  191. res = cuddBddExistAbstractRecur(manager, Cudd_Not(f), cube);
  192. } while (manager->reordered == 1);
  193. if (res != NULL) res = Cudd_Not(res);
  194. return(res);
  195. } /* end of Cudd_bddUnivAbstract */
  196. /**Function********************************************************************
  197. Synopsis [Computes the boolean difference of f with respect to x.]
  198. Description [Computes the boolean difference of f with respect to the
  199. variable with index x. Returns the BDD of the boolean difference if
  200. successful; NULL otherwise.]
  201. SideEffects [None]
  202. SeeAlso []
  203. ******************************************************************************/
  204. DdNode *
  205. Cudd_bddBooleanDiff(
  206. DdManager * manager,
  207. DdNode * f,
  208. int x)
  209. {
  210. DdNode *res, *var;
  211. /* If the variable is not currently in the manager, f cannot
  212. ** depend on it.
  213. */
  214. if (x >= manager->size) return(Cudd_Not(DD_ONE(manager)));
  215. var = manager->vars[x];
  216. do {
  217. manager->reordered = 0;
  218. res = cuddBddBooleanDiffRecur(manager, Cudd_Regular(f), var);
  219. } while (manager->reordered == 1);
  220. return(res);
  221. } /* end of Cudd_bddBooleanDiff */
  222. /**Function********************************************************************
  223. Synopsis [Checks whether a variable is dependent on others in a
  224. function.]
  225. Description [Checks whether a variable is dependent on others in a
  226. function. Returns 1 if the variable is dependent; 0 otherwise. No
  227. new nodes are created.]
  228. SideEffects [None]
  229. SeeAlso []
  230. ******************************************************************************/
  231. int
  232. Cudd_bddVarIsDependent(
  233. DdManager *dd, /* manager */
  234. DdNode *f, /* function */
  235. DdNode *var /* variable */)
  236. {
  237. DdNode *F, *res, *zero, *ft, *fe;
  238. unsigned topf, level;
  239. DD_CTFP cacheOp;
  240. int retval;
  241. zero = Cudd_Not(DD_ONE(dd));
  242. if (Cudd_IsConstant(f)) return(f == zero);
  243. /* From now on f is not constant. */
  244. F = Cudd_Regular(f);
  245. topf = (unsigned) dd->perm[F->index];
  246. level = (unsigned) dd->perm[var->index];
  247. /* Check terminal case. If topf > index of var, f does not depend on var.
  248. ** Therefore, var is not dependent in f. */
  249. if (topf > level) {
  250. return(0);
  251. }
  252. cacheOp = (DD_CTFP) Cudd_bddVarIsDependent;
  253. res = cuddCacheLookup2(dd,cacheOp,f,var);
  254. if (res != NULL) {
  255. return(res != zero);
  256. }
  257. /* Compute cofactors. */
  258. ft = Cudd_NotCond(cuddT(F), f != F);
  259. fe = Cudd_NotCond(cuddE(F), f != F);
  260. if (topf == level) {
  261. retval = Cudd_bddLeq(dd,ft,Cudd_Not(fe));
  262. } else {
  263. retval = Cudd_bddVarIsDependent(dd,ft,var) &&
  264. Cudd_bddVarIsDependent(dd,fe,var);
  265. }
  266. cuddCacheInsert2(dd,cacheOp,f,var,Cudd_NotCond(zero,retval));
  267. return(retval);
  268. } /* Cudd_bddVarIsDependent */
  269. /*---------------------------------------------------------------------------*/
  270. /* Definition of internal functions */
  271. /*---------------------------------------------------------------------------*/
  272. /**Function********************************************************************
  273. Synopsis [Performs the recursive steps of Cudd_bddExistAbstract.]
  274. Description [Performs the recursive steps of Cudd_bddExistAbstract.
  275. Returns the BDD obtained by abstracting the variables
  276. of cube from f if successful; NULL otherwise. It is also used by
  277. Cudd_bddUnivAbstract.]
  278. SideEffects [None]
  279. SeeAlso [Cudd_bddExistAbstract Cudd_bddUnivAbstract]
  280. ******************************************************************************/
  281. DdNode *
  282. cuddBddExistAbstractRecur(
  283. DdManager * manager,
  284. DdNode * f,
  285. DdNode * cube)
  286. {
  287. DdNode *F, *T, *E, *res, *res1, *res2, *one;
  288. statLine(manager);
  289. one = DD_ONE(manager);
  290. F = Cudd_Regular(f);
  291. /* Cube is guaranteed to be a cube at this point. */
  292. if (cube == one || F == one) {
  293. return(f);
  294. }
  295. /* From now on, f and cube are non-constant. */
  296. /* Abstract a variable that does not appear in f. */
  297. while (manager->perm[F->index] > manager->perm[cube->index]) {
  298. cube = cuddT(cube);
  299. if (cube == one) return(f);
  300. }
  301. /* Check the cache. */
  302. if (F->ref != 1 && (res = cuddCacheLookup2(manager, Cudd_bddExistAbstract, f, cube)) != NULL) {
  303. return(res);
  304. }
  305. /* Compute the cofactors of f. */
  306. T = cuddT(F); E = cuddE(F);
  307. if (f != F) {
  308. T = Cudd_Not(T); E = Cudd_Not(E);
  309. }
  310. /* If the two indices are the same, so are their levels. */
  311. if (F->index == cube->index) {
  312. if (T == one || E == one || T == Cudd_Not(E)) {
  313. return(one);
  314. }
  315. res1 = cuddBddExistAbstractRecur(manager, T, cuddT(cube));
  316. if (res1 == NULL) return(NULL);
  317. if (res1 == one) {
  318. if (F->ref != 1)
  319. cuddCacheInsert2(manager, Cudd_bddExistAbstract, f, cube, one);
  320. return(one);
  321. }
  322. cuddRef(res1);
  323. res2 = cuddBddExistAbstractRecur(manager, E, cuddT(cube));
  324. if (res2 == NULL) {
  325. Cudd_IterDerefBdd(manager,res1);
  326. return(NULL);
  327. }
  328. cuddRef(res2);
  329. res = cuddBddAndRecur(manager, Cudd_Not(res1), Cudd_Not(res2));
  330. if (res == NULL) {
  331. Cudd_IterDerefBdd(manager, res1);
  332. Cudd_IterDerefBdd(manager, res2);
  333. return(NULL);
  334. }
  335. res = Cudd_Not(res);
  336. cuddRef(res);
  337. Cudd_IterDerefBdd(manager, res1);
  338. Cudd_IterDerefBdd(manager, res2);
  339. if (F->ref != 1)
  340. cuddCacheInsert2(manager, Cudd_bddExistAbstract, f, cube, res);
  341. cuddDeref(res);
  342. return(res);
  343. } else { /* if (cuddI(manager,F->index) < cuddI(manager,cube->index)) */
  344. res1 = cuddBddExistAbstractRecur(manager, T, cube);
  345. if (res1 == NULL) return(NULL);
  346. cuddRef(res1);
  347. res2 = cuddBddExistAbstractRecur(manager, E, cube);
  348. if (res2 == NULL) {
  349. Cudd_IterDerefBdd(manager, res1);
  350. return(NULL);
  351. }
  352. cuddRef(res2);
  353. /* ITE takes care of possible complementation of res1 and of the
  354. ** case in which res1 == res2. */
  355. res = cuddBddIteRecur(manager, manager->vars[F->index], res1, res2);
  356. if (res == NULL) {
  357. Cudd_IterDerefBdd(manager, res1);
  358. Cudd_IterDerefBdd(manager, res2);
  359. return(NULL);
  360. }
  361. cuddDeref(res1);
  362. cuddDeref(res2);
  363. if (F->ref != 1)
  364. cuddCacheInsert2(manager, Cudd_bddExistAbstract, f, cube, res);
  365. return(res);
  366. }
  367. } /* end of cuddBddExistAbstractRecur */
  368. /**Function********************************************************************
  369. Synopsis [Takes the exclusive OR of two BDDs and simultaneously abstracts the
  370. variables in cube.]
  371. Description [Takes the exclusive OR of two BDDs and simultaneously abstracts
  372. the variables in cube. The variables are existentially abstracted. Returns a
  373. pointer to the result is successful; NULL otherwise.]
  374. SideEffects [None]
  375. SeeAlso [Cudd_bddAndAbstract]
  376. ******************************************************************************/
  377. DdNode *
  378. cuddBddXorExistAbstractRecur(
  379. DdManager * manager,
  380. DdNode * f,
  381. DdNode * g,
  382. DdNode * cube)
  383. {
  384. DdNode *F, *fv, *fnv, *G, *gv, *gnv;
  385. DdNode *one, *zero, *r, *t, *e, *Cube;
  386. unsigned int topf, topg, topcube, top, index;
  387. statLine(manager);
  388. one = DD_ONE(manager);
  389. zero = Cudd_Not(one);
  390. /* Terminal cases. */
  391. if (f == g) {
  392. return(zero);
  393. }
  394. if (f == Cudd_Not(g)) {
  395. return(one);
  396. }
  397. if (cube == one) {
  398. return(cuddBddXorRecur(manager, f, g));
  399. }
  400. if (f == one) {
  401. return(cuddBddExistAbstractRecur(manager, Cudd_Not(g), cube));
  402. }
  403. if (g == one) {
  404. return(cuddBddExistAbstractRecur(manager, Cudd_Not(f), cube));
  405. }
  406. if (f == zero) {
  407. return(cuddBddExistAbstractRecur(manager, g, cube));
  408. }
  409. if (g == zero) {
  410. return(cuddBddExistAbstractRecur(manager, f, cube));
  411. }
  412. /* At this point f, g, and cube are not constant. */
  413. if (f > g) { /* Try to increase cache efficiency. */
  414. DdNode *tmp = f;
  415. f = g;
  416. g = tmp;
  417. }
  418. /* Check cache. */
  419. r = cuddCacheLookup(manager, DD_BDD_XOR_EXIST_ABSTRACT_TAG, f, g, cube);
  420. if (r != NULL) {
  421. return(r);
  422. }
  423. /* Here we can skip the use of cuddI, because the operands are known
  424. ** to be non-constant.
  425. */
  426. F = Cudd_Regular(f);
  427. topf = manager->perm[F->index];
  428. G = Cudd_Regular(g);
  429. topg = manager->perm[G->index];
  430. top = ddMin(topf, topg);
  431. topcube = manager->perm[cube->index];
  432. if (topcube < top) {
  433. return(cuddBddXorExistAbstractRecur(manager, f, g, cuddT(cube)));
  434. }
  435. /* Now, topcube >= top. */
  436. if (topf == top) {
  437. index = F->index;
  438. fv = cuddT(F);
  439. fnv = cuddE(F);
  440. if (Cudd_IsComplement(f)) {
  441. fv = Cudd_Not(fv);
  442. fnv = Cudd_Not(fnv);
  443. }
  444. } else {
  445. index = G->index;
  446. fv = fnv = f;
  447. }
  448. if (topg == top) {
  449. gv = cuddT(G);
  450. gnv = cuddE(G);
  451. if (Cudd_IsComplement(g)) {
  452. gv = Cudd_Not(gv);
  453. gnv = Cudd_Not(gnv);
  454. }
  455. } else {
  456. gv = gnv = g;
  457. }
  458. if (topcube == top) {
  459. Cube = cuddT(cube);
  460. } else {
  461. Cube = cube;
  462. }
  463. t = cuddBddXorExistAbstractRecur(manager, fv, gv, Cube);
  464. if (t == NULL) return(NULL);
  465. /* Special case: 1 OR anything = 1. Hence, no need to compute
  466. ** the else branch if t is 1.
  467. */
  468. if (t == one && topcube == top) {
  469. cuddCacheInsert(manager, DD_BDD_XOR_EXIST_ABSTRACT_TAG, f, g, cube, one);
  470. return(one);
  471. }
  472. cuddRef(t);
  473. e = cuddBddXorExistAbstractRecur(manager, fnv, gnv, Cube);
  474. if (e == NULL) {
  475. Cudd_IterDerefBdd(manager, t);
  476. return(NULL);
  477. }
  478. cuddRef(e);
  479. if (topcube == top) { /* abstract */
  480. r = cuddBddAndRecur(manager, Cudd_Not(t), Cudd_Not(e));
  481. if (r == NULL) {
  482. Cudd_IterDerefBdd(manager, t);
  483. Cudd_IterDerefBdd(manager, e);
  484. return(NULL);
  485. }
  486. r = Cudd_Not(r);
  487. cuddRef(r);
  488. Cudd_IterDerefBdd(manager, t);
  489. Cudd_IterDerefBdd(manager, e);
  490. cuddDeref(r);
  491. } else if (t == e) {
  492. r = t;
  493. cuddDeref(t);
  494. cuddDeref(e);
  495. } else {
  496. if (Cudd_IsComplement(t)) {
  497. r = cuddUniqueInter(manager,(int)index,Cudd_Not(t),Cudd_Not(e));
  498. if (r == NULL) {
  499. Cudd_IterDerefBdd(manager, t);
  500. Cudd_IterDerefBdd(manager, e);
  501. return(NULL);
  502. }
  503. r = Cudd_Not(r);
  504. } else {
  505. r = cuddUniqueInter(manager,(int)index,t,e);
  506. if (r == NULL) {
  507. Cudd_IterDerefBdd(manager, t);
  508. Cudd_IterDerefBdd(manager, e);
  509. return(NULL);
  510. }
  511. }
  512. cuddDeref(e);
  513. cuddDeref(t);
  514. }
  515. cuddCacheInsert(manager, DD_BDD_XOR_EXIST_ABSTRACT_TAG, f, g, cube, r);
  516. return (r);
  517. } /* end of cuddBddXorExistAbstractRecur */
  518. /**Function********************************************************************
  519. Synopsis [Performs the recursive steps of Cudd_bddBoleanDiff.]
  520. Description [Performs the recursive steps of Cudd_bddBoleanDiff.
  521. Returns the BDD obtained by XORing the cofactors of f with respect to
  522. var if successful; NULL otherwise. Exploits the fact that dF/dx =
  523. dF'/dx.]
  524. SideEffects [None]
  525. SeeAlso []
  526. ******************************************************************************/
  527. DdNode *
  528. cuddBddBooleanDiffRecur(
  529. DdManager * manager,
  530. DdNode * f,
  531. DdNode * var)
  532. {
  533. DdNode *T, *E, *res, *res1, *res2;
  534. statLine(manager);
  535. if (cuddI(manager,f->index) > manager->perm[var->index]) {
  536. /* f does not depend on var. */
  537. return(Cudd_Not(DD_ONE(manager)));
  538. }
  539. /* From now on, f is non-constant. */
  540. /* If the two indices are the same, so are their levels. */
  541. if (f->index == var->index) {
  542. res = cuddBddXorRecur(manager, cuddT(f), cuddE(f));
  543. return(res);
  544. }
  545. /* From now on, cuddI(manager,f->index) < cuddI(manager,cube->index). */
  546. /* Check the cache. */
  547. res = cuddCacheLookup2(manager, cuddBddBooleanDiffRecur, f, var);
  548. if (res != NULL) {
  549. return(res);
  550. }
  551. /* Compute the cofactors of f. */
  552. T = cuddT(f); E = cuddE(f);
  553. res1 = cuddBddBooleanDiffRecur(manager, T, var);
  554. if (res1 == NULL) return(NULL);
  555. cuddRef(res1);
  556. res2 = cuddBddBooleanDiffRecur(manager, Cudd_Regular(E), var);
  557. if (res2 == NULL) {
  558. Cudd_IterDerefBdd(manager, res1);
  559. return(NULL);
  560. }
  561. cuddRef(res2);
  562. /* ITE takes care of possible complementation of res1 and of the
  563. ** case in which res1 == res2. */
  564. res = cuddBddIteRecur(manager, manager->vars[f->index], res1, res2);
  565. if (res == NULL) {
  566. Cudd_IterDerefBdd(manager, res1);
  567. Cudd_IterDerefBdd(manager, res2);
  568. return(NULL);
  569. }
  570. cuddDeref(res1);
  571. cuddDeref(res2);
  572. cuddCacheInsert2(manager, cuddBddBooleanDiffRecur, f, var, res);
  573. return(res);
  574. } /* end of cuddBddBooleanDiffRecur */
  575. /*---------------------------------------------------------------------------*/
  576. /* Definition of static functions */
  577. /*---------------------------------------------------------------------------*/
  578. /**Function********************************************************************
  579. Synopsis [Checks whether cube is an BDD representing the product of
  580. positive literals.]
  581. Description [Returns 1 in case of success; 0 otherwise.]
  582. SideEffects [None]
  583. ******************************************************************************/
  584. static int
  585. bddCheckPositiveCube(
  586. DdManager * manager,
  587. DdNode * cube)
  588. {
  589. if (Cudd_IsComplement(cube)) return(0);
  590. if (cube == DD_ONE(manager)) return(1);
  591. if (cuddIsConstant(cube)) return(0);
  592. if (cuddE(cube) == Cudd_Not(DD_ONE(manager))) {
  593. return(bddCheckPositiveCube(manager, cuddT(cube)));
  594. }
  595. return(0);
  596. } /* end of bddCheckPositiveCube */