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.

1381 lines
42 KiB

  1. /**
  2. @file
  3. @ingroup cudd
  4. @brief Quantification functions for ADDs.
  5. @author Fabio Somenzi
  6. @copyright@parblock
  7. Copyright (c) 1995-2015, Regents of the University of Colorado
  8. All rights reserved.
  9. Redistribution and use in source and binary forms, with or without
  10. modification, are permitted provided that the following conditions
  11. are met:
  12. Redistributions of source code must retain the above copyright
  13. notice, this list of conditions and the following disclaimer.
  14. Redistributions in binary form must reproduce the above copyright
  15. notice, this list of conditions and the following disclaimer in the
  16. documentation and/or other materials provided with the distribution.
  17. Neither the name of the University of Colorado nor the names of its
  18. contributors may be used to endorse or promote products derived from
  19. this software without specific prior written permission.
  20. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  21. "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  22. LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  23. FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  24. COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  25. INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  26. BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  27. LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  28. CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  29. LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  30. ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  31. POSSIBILITY OF SUCH DAMAGE.
  32. @endparblock
  33. */
  34. #include "util.h"
  35. #include "cuddInt.h"
  36. /*---------------------------------------------------------------------------*/
  37. /* Constant declarations */
  38. /*---------------------------------------------------------------------------*/
  39. /*---------------------------------------------------------------------------*/
  40. /* Stucture declarations */
  41. /*---------------------------------------------------------------------------*/
  42. /*---------------------------------------------------------------------------*/
  43. /* Type declarations */
  44. /*---------------------------------------------------------------------------*/
  45. /*---------------------------------------------------------------------------*/
  46. /* Variable declarations */
  47. /*---------------------------------------------------------------------------*/
  48. /*---------------------------------------------------------------------------*/
  49. /* Macro declarations */
  50. /*---------------------------------------------------------------------------*/
  51. /** \cond */
  52. /*---------------------------------------------------------------------------*/
  53. /* Static function prototypes */
  54. /*---------------------------------------------------------------------------*/
  55. static int addCheckPositiveCube (DdManager *manager, DdNode *cube);
  56. /** \endcond */
  57. /*---------------------------------------------------------------------------*/
  58. /* Definition of exported functions */
  59. /*---------------------------------------------------------------------------*/
  60. /**
  61. @brief Existentially Abstracts all the variables in cube from f.
  62. @details Abstracts all the variables in cube from f by summing
  63. over all possible values taken by the variables.
  64. @return the abstracted %ADD.
  65. @sideeffect None
  66. @see Cudd_addUnivAbstract Cudd_bddExistAbstract
  67. Cudd_addOrAbstract
  68. */
  69. DdNode *
  70. Cudd_addExistAbstract(
  71. DdManager * manager,
  72. DdNode * f,
  73. DdNode * cube)
  74. {
  75. DdNode *res;
  76. if (addCheckPositiveCube(manager, cube) == 0) {
  77. (void) fprintf(manager->err,"Error: Can only abstract cubes");
  78. return(NULL);
  79. }
  80. do {
  81. manager->reordered = 0;
  82. res = cuddAddExistAbstractRecur(manager, f, cube);
  83. } while (manager->reordered == 1);
  84. if (manager->errorCode == CUDD_TIMEOUT_EXPIRED && manager->timeoutHandler) {
  85. manager->timeoutHandler(manager, manager->tohArg);
  86. }
  87. return(res);
  88. } /* end of Cudd_addExistAbstract */
  89. /**
  90. @brief Universally Abstracts all the variables in cube from f.
  91. @details Abstracts all the variables in cube from f by taking
  92. the product over all possible values taken by the variable.
  93. @return the abstracted %ADD if successful; NULL otherwise.
  94. @sideeffect None
  95. @see Cudd_addExistAbstract Cudd_bddUnivAbstract
  96. Cudd_addOrAbstract
  97. */
  98. DdNode *
  99. Cudd_addUnivAbstract(
  100. DdManager * manager,
  101. DdNode * f,
  102. DdNode * cube)
  103. {
  104. DdNode *res;
  105. if (addCheckPositiveCube(manager, cube) == 0) {
  106. (void) fprintf(manager->err,"Error: Can only abstract cubes");
  107. return(NULL);
  108. }
  109. do {
  110. manager->reordered = 0;
  111. res = cuddAddUnivAbstractRecur(manager, f, cube);
  112. } while (manager->reordered == 1);
  113. if (manager->errorCode == CUDD_TIMEOUT_EXPIRED && manager->timeoutHandler) {
  114. manager->timeoutHandler(manager, manager->tohArg);
  115. }
  116. return(res);
  117. } /* end of Cudd_addUnivAbstract */
  118. /**
  119. @brief Disjunctively abstracts all the variables in cube from the
  120. 0-1 %ADD f.
  121. @details Abstracts all the variables in cube from the 0-1 %ADD f
  122. by taking the disjunction over all possible values taken by the
  123. variables.
  124. @return the abstracted %ADD if successful; NULL otherwise.
  125. @sideeffect None
  126. @see Cudd_addUnivAbstract Cudd_addExistAbstract
  127. */
  128. DdNode *
  129. Cudd_addOrAbstract(
  130. DdManager * manager,
  131. DdNode * f,
  132. DdNode * cube)
  133. {
  134. DdNode *res;
  135. if (addCheckPositiveCube(manager, cube) == 0) {
  136. (void) fprintf(manager->err,"Error: Can only abstract cubes");
  137. return(NULL);
  138. }
  139. do {
  140. manager->reordered = 0;
  141. res = cuddAddOrAbstractRecur(manager, f, cube);
  142. } while (manager->reordered == 1);
  143. if (manager->errorCode == CUDD_TIMEOUT_EXPIRED && manager->timeoutHandler) {
  144. manager->timeoutHandler(manager, manager->tohArg);
  145. }
  146. return(res);
  147. } /* end of Cudd_addOrAbstract */
  148. /**Function********************************************************************
  149. Synopsis [Abstracts all the variables in cube from the
  150. ADD f by taking the minimum.]
  151. Description [Abstracts all the variables in cube from the ADD f
  152. by taking the minimum over all possible values taken by the
  153. variables. Returns the abstracted ADD if successful; NULL
  154. otherwise.]
  155. SideEffects [None]
  156. SeeAlso [Cudd_addUnivAbstract Cudd_addExistAbstract]
  157. Note: Added by Dave Parker 14/6/99
  158. ******************************************************************************/
  159. DdNode *
  160. Cudd_addMinAbstract(
  161. DdManager * manager,
  162. DdNode * f,
  163. DdNode * cube)
  164. {
  165. DdNode *res;
  166. if (addCheckPositiveCube(manager, cube) == 0) {
  167. (void) fprintf(manager->err,"Error: Can only abstract cubes");
  168. return(NULL);
  169. }
  170. do {
  171. manager->reordered = 0;
  172. res = cuddAddMinAbstractRecur(manager, f, cube);
  173. } while (manager->reordered == 1);
  174. return(res);
  175. } /* end of Cudd_addMinAbstract */
  176. /**Function********************************************************************
  177. Synopsis [Abstracts all the variables in cube from the
  178. ADD f by taking the minimum.]
  179. Description [Abstracts all the variables in cube from the ADD f
  180. by taking the minimum over all possible values taken by the
  181. variables. Returns the abstracted ADD if successful; NULL
  182. otherwise.]
  183. SideEffects [None]
  184. SeeAlso [Cudd_addUnivAbstract Cudd_addExistAbstract]
  185. Note: Added by Christian Dehnert 24/08/2016
  186. ******************************************************************************/
  187. DdNode *
  188. Cudd_addMinExcept0Abstract(
  189. DdManager * manager,
  190. DdNode * f,
  191. DdNode * cube)
  192. {
  193. DdNode *res;
  194. if (addCheckPositiveCube(manager, cube) == 0) {
  195. (void) fprintf(manager->err,"Error: Can only abstract cubes");
  196. return(NULL);
  197. }
  198. do {
  199. manager->reordered = 0;
  200. res = cuddAddMinExcept0AbstractRecur(manager, f, cube);
  201. } while (manager->reordered == 1);
  202. return(res);
  203. } /* end of Cudd_addMinExcept0Abstract */
  204. /**Function********************************************************************
  205. Synopsis [Abstracts all the variables in cube from the
  206. ADD f by taking the maximum.]
  207. Description [Abstracts all the variables in cube from the ADD f
  208. by taking the maximum over all possible values taken by the
  209. variables. Returns the abstracted ADD if successful; NULL
  210. otherwise.]
  211. SideEffects [None]
  212. SeeAlso [Cudd_addUnivAbstract Cudd_addExistAbstract]
  213. Note: Added by Dave Parker 14/6/99
  214. ******************************************************************************/
  215. DdNode *
  216. Cudd_addMaxAbstract(
  217. DdManager * manager,
  218. DdNode * f,
  219. DdNode * cube)
  220. {
  221. DdNode *res;
  222. if (addCheckPositiveCube(manager, cube) == 0) {
  223. (void) fprintf(manager->err,"Error: Can only abstract cubes");
  224. return(NULL);
  225. }
  226. do {
  227. manager->reordered = 0;
  228. res = cuddAddMaxAbstractRecur(manager, f, cube);
  229. } while (manager->reordered == 1);
  230. return(res);
  231. } /* end of Cudd_addMaxAbstract */
  232. /**Function********************************************************************
  233. Synopsis [Just like Cudd_addMinAbstract, but instead of abstracting the
  234. variables in the given cube, picks a unique representative that realizes th
  235. minimal function value.]
  236. Description [Returns the resulting ADD if successful; NULL otherwise.]
  237. SideEffects [None]
  238. SeeAlso [Cudd_addMaxAbstractRepresentative]
  239. Note: Added by Christian Dehnert 8/5/14
  240. ******************************************************************************/
  241. DdNode *
  242. Cudd_addMinAbstractRepresentative(
  243. DdManager * manager,
  244. DdNode * f,
  245. DdNode * cube)
  246. {
  247. DdNode *res;
  248. if (addCheckPositiveCube(manager, cube) == 0) {
  249. (void) fprintf(manager->err,"Error: Can only abstract cubes");
  250. return(NULL);
  251. }
  252. do {
  253. manager->reordered = 0;
  254. res = cuddAddMinAbstractRepresentativeRecur(manager, f, cube);
  255. } while (manager->reordered == 1);
  256. return(res);
  257. } /* end of Cudd_addMinRepresentative */
  258. /**Function********************************************************************
  259. Synopsis [Just like Cudd_addMaxAbstract, but instead of abstracting the
  260. variables in the given cube, picks a unique representative that realizes th
  261. maximal function value.]
  262. Description [Returns the resulting ADD if successful; NULL otherwise.]
  263. SideEffects [None]
  264. SeeAlso [Cudd_addMinAbstractRepresentative]
  265. Note: Added by Christian Dehnert 8/5/14
  266. ******************************************************************************/
  267. DdNode *
  268. Cudd_addMaxAbstractRepresentative(
  269. DdManager * manager,
  270. DdNode * f,
  271. DdNode * cube)
  272. {
  273. DdNode *res;
  274. if (addCheckPositiveCube(manager, cube) == 0) {
  275. (void) fprintf(manager->err,"Error: Can only abstract cubes");
  276. return(NULL);
  277. }
  278. do {
  279. manager->reordered = 0;
  280. res = cuddAddMaxAbstractRepresentativeRecur(manager, f, cube);
  281. } while (manager->reordered == 1);
  282. return(res);
  283. } /* end of Cudd_addMaxRepresentative */
  284. /*---------------------------------------------------------------------------*/
  285. /* Definition of internal functions */
  286. /*---------------------------------------------------------------------------*/
  287. /**
  288. @brief Performs the recursive step of Cudd_addExistAbstract.
  289. @details Returns the %ADD obtained by abstracting the variables of
  290. cube from f, if successful; NULL otherwise.
  291. @sideeffect None
  292. */
  293. DdNode *
  294. cuddAddExistAbstractRecur(
  295. DdManager * manager,
  296. DdNode * f,
  297. DdNode * cube)
  298. {
  299. DdNode *T, *E, *res, *res1, *res2, *zero;
  300. statLine(manager);
  301. zero = DD_ZERO(manager);
  302. /* Cube is guaranteed to be a cube at this point. */
  303. if (f == zero || cuddIsConstant(cube)) {
  304. return(f);
  305. }
  306. /* Abstract a variable that does not appear in f => multiply by 2. */
  307. if (cuddI(manager,f->index) > cuddI(manager,cube->index)) {
  308. res1 = cuddAddExistAbstractRecur(manager, f, cuddT(cube));
  309. if (res1 == NULL) return(NULL);
  310. cuddRef(res1);
  311. /* Use the "internal" procedure to be alerted in case of
  312. ** dynamic reordering. If dynamic reordering occurs, we
  313. ** have to abort the entire abstraction.
  314. */
  315. res = cuddAddApplyRecur(manager,Cudd_addPlus,res1,res1);
  316. if (res == NULL) {
  317. Cudd_RecursiveDeref(manager,res1);
  318. return(NULL);
  319. }
  320. cuddRef(res);
  321. Cudd_RecursiveDeref(manager,res1);
  322. cuddDeref(res);
  323. return(res);
  324. }
  325. if ((res = cuddCacheLookup2(manager, Cudd_addExistAbstract, f, cube)) != NULL) {
  326. return(res);
  327. }
  328. checkWhetherToGiveUp(manager);
  329. T = cuddT(f);
  330. E = cuddE(f);
  331. /* If the two indices are the same, so are their levels. */
  332. if (f->index == cube->index) {
  333. res1 = cuddAddExistAbstractRecur(manager, T, cuddT(cube));
  334. if (res1 == NULL) return(NULL);
  335. cuddRef(res1);
  336. res2 = cuddAddExistAbstractRecur(manager, E, cuddT(cube));
  337. if (res2 == NULL) {
  338. Cudd_RecursiveDeref(manager,res1);
  339. return(NULL);
  340. }
  341. cuddRef(res2);
  342. res = cuddAddApplyRecur(manager, Cudd_addPlus, res1, res2);
  343. if (res == NULL) {
  344. Cudd_RecursiveDeref(manager,res1);
  345. Cudd_RecursiveDeref(manager,res2);
  346. return(NULL);
  347. }
  348. cuddRef(res);
  349. Cudd_RecursiveDeref(manager,res1);
  350. Cudd_RecursiveDeref(manager,res2);
  351. cuddCacheInsert2(manager, Cudd_addExistAbstract, f, cube, res);
  352. cuddDeref(res);
  353. return(res);
  354. } else { /* if (cuddI(manager,f->index) < cuddI(manager,cube->index)) */
  355. res1 = cuddAddExistAbstractRecur(manager, T, cube);
  356. if (res1 == NULL) return(NULL);
  357. cuddRef(res1);
  358. res2 = cuddAddExistAbstractRecur(manager, E, cube);
  359. if (res2 == NULL) {
  360. Cudd_RecursiveDeref(manager,res1);
  361. return(NULL);
  362. }
  363. cuddRef(res2);
  364. res = (res1 == res2) ? res1 :
  365. cuddUniqueInter(manager, (int) f->index, res1, res2);
  366. if (res == NULL) {
  367. Cudd_RecursiveDeref(manager,res1);
  368. Cudd_RecursiveDeref(manager,res2);
  369. return(NULL);
  370. }
  371. cuddDeref(res1);
  372. cuddDeref(res2);
  373. cuddCacheInsert2(manager, Cudd_addExistAbstract, f, cube, res);
  374. return(res);
  375. }
  376. } /* end of cuddAddExistAbstractRecur */
  377. /**
  378. @brief Performs the recursive step of Cudd_addUnivAbstract.
  379. @return the %ADD obtained by abstracting the variables of cube from
  380. f, if successful; NULL otherwise.
  381. @sideeffect None
  382. */
  383. DdNode *
  384. cuddAddUnivAbstractRecur(
  385. DdManager * manager,
  386. DdNode * f,
  387. DdNode * cube)
  388. {
  389. DdNode *T, *E, *res, *res1, *res2, *one, *zero;
  390. statLine(manager);
  391. one = DD_ONE(manager);
  392. zero = DD_ZERO(manager);
  393. /* Cube is guaranteed to be a cube at this point.
  394. ** zero and one are the only constatnts c such that c*c=c.
  395. */
  396. if (f == zero || f == one || cube == one) {
  397. return(f);
  398. }
  399. /* Abstract a variable that does not appear in f. */
  400. if (cuddI(manager,f->index) > cuddI(manager,cube->index)) {
  401. res1 = cuddAddUnivAbstractRecur(manager, f, cuddT(cube));
  402. if (res1 == NULL) return(NULL);
  403. cuddRef(res1);
  404. /* Use the "internal" procedure to be alerted in case of
  405. ** dynamic reordering. If dynamic reordering occurs, we
  406. ** have to abort the entire abstraction.
  407. */
  408. res = cuddAddApplyRecur(manager, Cudd_addTimes, res1, res1);
  409. if (res == NULL) {
  410. Cudd_RecursiveDeref(manager,res1);
  411. return(NULL);
  412. }
  413. cuddRef(res);
  414. Cudd_RecursiveDeref(manager,res1);
  415. cuddDeref(res);
  416. return(res);
  417. }
  418. if ((res = cuddCacheLookup2(manager, Cudd_addUnivAbstract, f, cube)) != NULL) {
  419. return(res);
  420. }
  421. checkWhetherToGiveUp(manager);
  422. T = cuddT(f);
  423. E = cuddE(f);
  424. /* If the two indices are the same, so are their levels. */
  425. if (f->index == cube->index) {
  426. res1 = cuddAddUnivAbstractRecur(manager, T, cuddT(cube));
  427. if (res1 == NULL) return(NULL);
  428. cuddRef(res1);
  429. res2 = cuddAddUnivAbstractRecur(manager, E, cuddT(cube));
  430. if (res2 == NULL) {
  431. Cudd_RecursiveDeref(manager,res1);
  432. return(NULL);
  433. }
  434. cuddRef(res2);
  435. res = cuddAddApplyRecur(manager, Cudd_addTimes, res1, res2);
  436. if (res == NULL) {
  437. Cudd_RecursiveDeref(manager,res1);
  438. Cudd_RecursiveDeref(manager,res2);
  439. return(NULL);
  440. }
  441. cuddRef(res);
  442. Cudd_RecursiveDeref(manager,res1);
  443. Cudd_RecursiveDeref(manager,res2);
  444. cuddCacheInsert2(manager, Cudd_addUnivAbstract, f, cube, res);
  445. cuddDeref(res);
  446. return(res);
  447. } else { /* if (cuddI(manager,f->index) < cuddI(manager,cube->index)) */
  448. res1 = cuddAddUnivAbstractRecur(manager, T, cube);
  449. if (res1 == NULL) return(NULL);
  450. cuddRef(res1);
  451. res2 = cuddAddUnivAbstractRecur(manager, E, cube);
  452. if (res2 == NULL) {
  453. Cudd_RecursiveDeref(manager,res1);
  454. return(NULL);
  455. }
  456. cuddRef(res2);
  457. res = (res1 == res2) ? res1 :
  458. cuddUniqueInter(manager, (int) f->index, res1, res2);
  459. if (res == NULL) {
  460. Cudd_RecursiveDeref(manager,res1);
  461. Cudd_RecursiveDeref(manager,res2);
  462. return(NULL);
  463. }
  464. cuddDeref(res1);
  465. cuddDeref(res2);
  466. cuddCacheInsert2(manager, Cudd_addUnivAbstract, f, cube, res);
  467. return(res);
  468. }
  469. } /* end of cuddAddUnivAbstractRecur */
  470. /**
  471. @brief Performs the recursive step of Cudd_addOrAbstract.
  472. @return the %ADD obtained by abstracting the variables of cube from
  473. f, if successful; NULL otherwise.
  474. @sideeffect None
  475. */
  476. DdNode *
  477. cuddAddOrAbstractRecur(
  478. DdManager * manager,
  479. DdNode * f,
  480. DdNode * cube)
  481. {
  482. DdNode *T, *E, *res, *res1, *res2, *one;
  483. statLine(manager);
  484. one = DD_ONE(manager);
  485. /* Cube is guaranteed to be a cube at this point. */
  486. if (cuddIsConstant(f) || cube == one) {
  487. return(f);
  488. }
  489. /* Abstract a variable that does not appear in f. */
  490. if (cuddI(manager,f->index) > cuddI(manager,cube->index)) {
  491. res = cuddAddOrAbstractRecur(manager, f, cuddT(cube));
  492. return(res);
  493. }
  494. if ((res = cuddCacheLookup2(manager, Cudd_addOrAbstract, f, cube)) != NULL) {
  495. return(res);
  496. }
  497. checkWhetherToGiveUp(manager);
  498. T = cuddT(f);
  499. E = cuddE(f);
  500. /* If the two indices are the same, so are their levels. */
  501. if (f->index == cube->index) {
  502. res1 = cuddAddOrAbstractRecur(manager, T, cuddT(cube));
  503. if (res1 == NULL) return(NULL);
  504. cuddRef(res1);
  505. if (res1 != one) {
  506. res2 = cuddAddOrAbstractRecur(manager, E, cuddT(cube));
  507. if (res2 == NULL) {
  508. Cudd_RecursiveDeref(manager,res1);
  509. return(NULL);
  510. }
  511. cuddRef(res2);
  512. res = cuddAddApplyRecur(manager, Cudd_addOr, res1, res2);
  513. if (res == NULL) {
  514. Cudd_RecursiveDeref(manager,res1);
  515. Cudd_RecursiveDeref(manager,res2);
  516. return(NULL);
  517. }
  518. cuddRef(res);
  519. Cudd_RecursiveDeref(manager,res1);
  520. Cudd_RecursiveDeref(manager,res2);
  521. } else {
  522. res = res1;
  523. }
  524. cuddCacheInsert2(manager, Cudd_addOrAbstract, f, cube, res);
  525. cuddDeref(res);
  526. return(res);
  527. } else { /* if (cuddI(manager,f->index) < cuddI(manager,cube->index)) */
  528. res1 = cuddAddOrAbstractRecur(manager, T, cube);
  529. if (res1 == NULL) return(NULL);
  530. cuddRef(res1);
  531. res2 = cuddAddOrAbstractRecur(manager, E, cube);
  532. if (res2 == NULL) {
  533. Cudd_RecursiveDeref(manager,res1);
  534. return(NULL);
  535. }
  536. cuddRef(res2);
  537. res = (res1 == res2) ? res1 :
  538. cuddUniqueInter(manager, (int) f->index, res1, res2);
  539. if (res == NULL) {
  540. Cudd_RecursiveDeref(manager,res1);
  541. Cudd_RecursiveDeref(manager,res2);
  542. return(NULL);
  543. }
  544. cuddDeref(res1);
  545. cuddDeref(res2);
  546. cuddCacheInsert2(manager, Cudd_addOrAbstract, f, cube, res);
  547. return(res);
  548. }
  549. } /* end of cuddAddOrAbstractRecur */
  550. /**Function********************************************************************
  551. Synopsis [Performs the recursive step of Cudd_addMinAbstract.]
  552. Description [Performs the recursive step of Cudd_addMinAbstract.
  553. Returns the ADD obtained by abstracting the variables of cube from f,
  554. if successful; NULL otherwise.]
  555. SideEffects [None]
  556. SeeAlso []
  557. ******************************************************************************/
  558. DdNode *
  559. cuddAddMinAbstractRecur(
  560. DdManager * manager,
  561. DdNode * f,
  562. DdNode * cube)
  563. {
  564. DdNode *T, *E, *res, *res1, *res2, *zero;
  565. zero = DD_ZERO(manager);
  566. /* Cube is guaranteed to be a cube at this point. */
  567. if (f == zero || cuddIsConstant(cube)) {
  568. return(f);
  569. }
  570. /* Abstract a variable that does not appear in f. */
  571. if (cuddI(manager,f->index) > cuddI(manager,cube->index)) {
  572. res = cuddAddMinAbstractRecur(manager, f, cuddT(cube));
  573. return(res);
  574. }
  575. if ((res = cuddCacheLookup2(manager, Cudd_addMinAbstract, f, cube)) != NULL) {
  576. return(res);
  577. }
  578. T = cuddT(f);
  579. E = cuddE(f);
  580. /* If the two indices are the same, so are their levels. */
  581. if (f->index == cube->index) {
  582. res1 = cuddAddMinAbstractRecur(manager, T, cuddT(cube));
  583. if (res1 == NULL) return(NULL);
  584. cuddRef(res1);
  585. res2 = cuddAddMinAbstractRecur(manager, E, cuddT(cube));
  586. if (res2 == NULL) {
  587. Cudd_RecursiveDeref(manager,res1);
  588. return(NULL);
  589. }
  590. cuddRef(res2);
  591. res = cuddAddApplyRecur(manager, Cudd_addMinimum, res1, res2);
  592. if (res == NULL) {
  593. Cudd_RecursiveDeref(manager,res1);
  594. Cudd_RecursiveDeref(manager,res2);
  595. return(NULL);
  596. }
  597. cuddRef(res);
  598. Cudd_RecursiveDeref(manager,res1);
  599. Cudd_RecursiveDeref(manager,res2);
  600. cuddCacheInsert2(manager, Cudd_addMinAbstract, f, cube, res);
  601. cuddDeref(res);
  602. return(res);
  603. }
  604. else { /* if (cuddI(manager,f->index) < cuddI(manager,cube->index)) */
  605. res1 = cuddAddMinAbstractRecur(manager, T, cube);
  606. if (res1 == NULL) return(NULL);
  607. cuddRef(res1);
  608. res2 = cuddAddMinAbstractRecur(manager, E, cube);
  609. if (res2 == NULL) {
  610. Cudd_RecursiveDeref(manager,res1);
  611. return(NULL);
  612. }
  613. cuddRef(res2);
  614. res = (res1 == res2) ? res1 :
  615. cuddUniqueInter(manager, (int) f->index, res1, res2);
  616. if (res == NULL) {
  617. Cudd_RecursiveDeref(manager,res1);
  618. Cudd_RecursiveDeref(manager,res2);
  619. return(NULL);
  620. }
  621. cuddDeref(res1);
  622. cuddDeref(res2);
  623. cuddCacheInsert2(manager, Cudd_addMinAbstract, f, cube, res);
  624. return(res);
  625. }
  626. } /* end of cuddAddMinAbstractRecur */
  627. /**Function********************************************************************
  628. Synopsis [Performs the recursive step of Cudd_addMinAbstract.]
  629. Description [Performs the recursive step of Cudd_addMinAbstract.
  630. Returns the ADD obtained by abstracting the variables of cube from f,
  631. if successful; NULL otherwise.]
  632. SideEffects [None]
  633. SeeAlso []
  634. added 24/08/2016 by Christian Dehnert
  635. ******************************************************************************/
  636. DdNode *
  637. cuddAddMinExcept0AbstractRecur(
  638. DdManager * manager,
  639. DdNode * f,
  640. DdNode * cube)
  641. {
  642. DdNode *T, *E, *res, *res1, *res2, *zero;
  643. zero = DD_ZERO(manager);
  644. /* Cube is guaranteed to be a cube at this point. */
  645. if (f == zero || cuddIsConstant(cube)) {
  646. return(f);
  647. }
  648. /* Abstract a variable that does not appear in f. */
  649. if (cuddI(manager,f->index) > cuddI(manager,cube->index)) {
  650. res = cuddAddMinAbstractRecur(manager, f, cuddT(cube));
  651. return(res);
  652. }
  653. if ((res = cuddCacheLookup2(manager, Cudd_addMinAbstract, f, cube)) != NULL) {
  654. return(res);
  655. }
  656. T = cuddT(f);
  657. E = cuddE(f);
  658. /* If the two indices are the same, so are their levels. */
  659. if (f->index == cube->index) {
  660. res1 = cuddAddMinAbstractRecur(manager, T, cuddT(cube));
  661. if (res1 == NULL) return(NULL);
  662. cuddRef(res1);
  663. res2 = cuddAddMinAbstractRecur(manager, E, cuddT(cube));
  664. if (res2 == NULL) {
  665. Cudd_RecursiveDeref(manager,res1);
  666. return(NULL);
  667. }
  668. cuddRef(res2);
  669. res = cuddAddApplyRecur(manager, Cudd_addMinimumExcept0, res1, res2);
  670. if (res == NULL) {
  671. Cudd_RecursiveDeref(manager,res1);
  672. Cudd_RecursiveDeref(manager,res2);
  673. return(NULL);
  674. }
  675. cuddRef(res);
  676. Cudd_RecursiveDeref(manager,res1);
  677. Cudd_RecursiveDeref(manager,res2);
  678. cuddCacheInsert2(manager, Cudd_addMinAbstract, f, cube, res);
  679. cuddDeref(res);
  680. return(res);
  681. }
  682. else { /* if (cuddI(manager,f->index) < cuddI(manager,cube->index)) */
  683. res1 = cuddAddMinAbstractRecur(manager, T, cube);
  684. if (res1 == NULL) return(NULL);
  685. cuddRef(res1);
  686. res2 = cuddAddMinAbstractRecur(manager, E, cube);
  687. if (res2 == NULL) {
  688. Cudd_RecursiveDeref(manager,res1);
  689. return(NULL);
  690. }
  691. cuddRef(res2);
  692. res = (res1 == res2) ? res1 :
  693. cuddUniqueInter(manager, (int) f->index, res1, res2);
  694. if (res == NULL) {
  695. Cudd_RecursiveDeref(manager,res1);
  696. Cudd_RecursiveDeref(manager,res2);
  697. return(NULL);
  698. }
  699. cuddDeref(res1);
  700. cuddDeref(res2);
  701. cuddCacheInsert2(manager, Cudd_addMinAbstract, f, cube, res);
  702. return(res);
  703. }
  704. } /* end of cuddAddMinAbstractRecur */
  705. /**Function********************************************************************
  706. Synopsis [Performs the recursive step of Cudd_addMaxAbstract.]
  707. Description [Performs the recursive step of Cudd_addMaxAbstract.
  708. Returns the ADD obtained by abstracting the variables of cube from f,
  709. if successful; NULL otherwise.]
  710. SideEffects [None]
  711. SeeAlso []
  712. ******************************************************************************/
  713. DdNode *
  714. cuddAddMaxAbstractRecur(
  715. DdManager * manager,
  716. DdNode * f,
  717. DdNode * cube)
  718. {
  719. DdNode *T, *E, *res, *res1, *res2, *zero;
  720. zero = DD_ZERO(manager);
  721. /* Cube is guaranteed to be a cube at this point. */
  722. if (f == zero || cuddIsConstant(cube)) {
  723. return(f);
  724. }
  725. /* Abstract a variable that does not appear in f. */
  726. if (cuddI(manager,f->index) > cuddI(manager,cube->index)) {
  727. res = cuddAddMaxAbstractRecur(manager, f, cuddT(cube));
  728. return(res);
  729. }
  730. if ((res = cuddCacheLookup2(manager, Cudd_addMaxAbstract, f, cube)) != NULL) {
  731. return(res);
  732. }
  733. T = cuddT(f);
  734. E = cuddE(f);
  735. /* If the two indices are the same, so are their levels. */
  736. if (f->index == cube->index) {
  737. res1 = cuddAddMaxAbstractRecur(manager, T, cuddT(cube));
  738. if (res1 == NULL) return(NULL);
  739. cuddRef(res1);
  740. res2 = cuddAddMaxAbstractRecur(manager, E, cuddT(cube));
  741. if (res2 == NULL) {
  742. Cudd_RecursiveDeref(manager,res1);
  743. return(NULL);
  744. }
  745. cuddRef(res2);
  746. res = cuddAddApplyRecur(manager, Cudd_addMaximum, res1, res2);
  747. if (res == NULL) {
  748. Cudd_RecursiveDeref(manager,res1);
  749. Cudd_RecursiveDeref(manager,res2);
  750. return(NULL);
  751. }
  752. cuddRef(res);
  753. Cudd_RecursiveDeref(manager,res1);
  754. Cudd_RecursiveDeref(manager,res2);
  755. cuddCacheInsert2(manager, Cudd_addMaxAbstract, f, cube, res);
  756. cuddDeref(res);
  757. return(res);
  758. }
  759. else { /* if (cuddI(manager,f->index) < cuddI(manager,cube->index)) */
  760. res1 = cuddAddMaxAbstractRecur(manager, T, cube);
  761. if (res1 == NULL) return(NULL);
  762. cuddRef(res1);
  763. res2 = cuddAddMaxAbstractRecur(manager, E, cube);
  764. if (res2 == NULL) {
  765. Cudd_RecursiveDeref(manager,res1);
  766. return(NULL);
  767. }
  768. cuddRef(res2);
  769. res = (res1 == res2) ? res1 :
  770. cuddUniqueInter(manager, (int) f->index, res1, res2);
  771. if (res == NULL) {
  772. Cudd_RecursiveDeref(manager,res1);
  773. Cudd_RecursiveDeref(manager,res2);
  774. return(NULL);
  775. }
  776. cuddDeref(res1);
  777. cuddDeref(res2);
  778. cuddCacheInsert2(manager, Cudd_addMaxAbstract, f, cube, res);
  779. return(res);
  780. }
  781. } /* end of cuddAddMaxAbstractRecur */
  782. /*---------------------------------------------------------------------------*/
  783. /* Definition of static functions */
  784. /*---------------------------------------------------------------------------*/
  785. /**Function********************************************************************
  786. Synopsis [Performs the recursive step of Cudd_addMinAbstractRepresentative.]
  787. Description [Performs the recursive step of Cudd_addMinAbstractRepresentative.
  788. Returns the ADD obtained by picking a representative over the variables in
  789. the given cube for all other valuations. Returns the resulting ADD if successful;
  790. NULL otherwise.]
  791. SideEffects [None]
  792. SeeAlso []
  793. ******************************************************************************/
  794. DdNode *
  795. cuddAddMinAbstractRepresentativeRecur(
  796. DdManager * manager,
  797. DdNode * f,
  798. DdNode * cube)
  799. {
  800. DdNode *T, *E, *res, *res1, *res2, *zero, *one, *logicalZero, *res1Inf, *res2Inf, *left, *right, *tmp, *tmp2;
  801. zero = DD_ZERO(manager);
  802. one = DD_ONE(manager);
  803. logicalZero = Cudd_Not(one);
  804. /* Cube is guaranteed to be a cube at this point. */
  805. if (cuddIsConstant(cube)) {
  806. return one;
  807. }
  808. if (cuddIsConstant(f)) {
  809. res = cuddAddMinAbstractRepresentativeRecur(manager, f, cuddT(cube));
  810. if (res == NULL) {
  811. return(NULL);
  812. }
  813. cuddRef(res);
  814. // We build in the negation ourselves.
  815. res1 = cuddUniqueInter(manager, (int) cube->index, one, Cudd_Not(res));
  816. if (res1 == NULL) {
  817. Cudd_IterDerefBdd(manager,res);
  818. return(NULL);
  819. }
  820. res1 = Cudd_Not(res1);
  821. cuddDeref(res);
  822. return(res1);
  823. }
  824. if ((res = cuddCacheLookup2(manager, Cudd_addMinAbstractRepresentative, f, cube)) != NULL) {
  825. return(res);
  826. }
  827. /* Abstract a variable that does not appear in f. */
  828. if (cuddI(manager,f->index) > cuddI(manager,cube->index)) {
  829. res = cuddAddMinAbstractRepresentativeRecur(manager, f, cuddT(cube));
  830. if (res == NULL) {
  831. return(NULL);
  832. }
  833. // Fill in the missing variables to make representative unique.
  834. cuddRef(res);
  835. // We build in the negation ourselves.
  836. res1 = cuddUniqueInter(manager, (int) cube->index, one, Cudd_Not(res));
  837. if (res1 == NULL) {
  838. Cudd_IterDerefBdd(manager,res);
  839. return(NULL);
  840. }
  841. res1 = Cudd_Not(res1);
  842. cuddDeref(res);
  843. return(res1);
  844. }
  845. E = cuddE(f);
  846. T = cuddT(f);
  847. /* If the two indices are the same, so are their levels. */
  848. if (f->index == cube->index) {
  849. res1 = cuddAddMinAbstractRepresentativeRecur(manager, E, cuddT(cube));
  850. if (res1 == NULL) {
  851. return(NULL);
  852. }
  853. cuddRef(res1);
  854. res2 = cuddAddMinAbstractRepresentativeRecur(manager, T, cuddT(cube));
  855. if (res2 == NULL) {
  856. Cudd_IterDerefBdd(manager, res1);
  857. return(NULL);
  858. }
  859. cuddRef(res2);
  860. left = cuddAddMinAbstractRecur(manager, E, cuddT(cube));
  861. if (left == NULL) {
  862. Cudd_IterDerefBdd(manager, res1);
  863. Cudd_IterDerefBdd(manager, res2);
  864. return(NULL);
  865. }
  866. cuddRef(left);
  867. right = cuddAddMinAbstractRecur(manager, T, cuddT(cube));
  868. if (right == NULL) {
  869. Cudd_IterDerefBdd(manager, res1);
  870. Cudd_IterDerefBdd(manager, res2);
  871. Cudd_RecursiveDeref(manager, left);
  872. return(NULL);
  873. }
  874. cuddRef(right);
  875. tmp = cuddAddToBddApplyRecur(manager, Cudd_addToBddLessThanEquals, left, right);
  876. if (tmp == NULL) {
  877. Cudd_IterDerefBdd(manager,res1);
  878. Cudd_IterDerefBdd(manager,res2);
  879. Cudd_RecursiveDeref(manager,left);
  880. Cudd_RecursiveDeref(manager,right);
  881. return(NULL);
  882. }
  883. cuddRef(tmp);
  884. Cudd_RecursiveDeref(manager, left);
  885. Cudd_RecursiveDeref(manager, right);
  886. res1Inf = cuddBddIteRecur(manager, tmp, res1, logicalZero);
  887. if (res1Inf == NULL) {
  888. Cudd_IterDerefBdd(manager,res1);
  889. Cudd_IterDerefBdd(manager,res2);
  890. Cudd_IterDerefBdd(manager,tmp);
  891. return(NULL);
  892. }
  893. cuddRef(res1Inf);
  894. Cudd_IterDerefBdd(manager,res1);
  895. res2Inf = cuddBddIteRecur(manager, tmp, logicalZero, res2);
  896. Cudd_IterDerefBdd(manager,tmp);
  897. if (res2Inf == NULL) {
  898. Cudd_IterDerefBdd(manager,res2);
  899. Cudd_IterDerefBdd(manager,res1Inf);
  900. return(NULL);
  901. }
  902. cuddRef(res2Inf);
  903. Cudd_IterDerefBdd(manager,res2);
  904. int compl = (res1Inf == res2Inf) ? 1 : Cudd_IsComplement(res2Inf);
  905. res = (res1Inf == res2Inf) ? cuddUniqueInter(manager, (int) f->index, one, Cudd_Not(res1Inf)) : cuddUniqueInter(manager, (int) f->index, Cudd_Regular(res2Inf), compl ? Cudd_Not(res1Inf) : res1Inf);
  906. if (res == NULL) {
  907. Cudd_IterDerefBdd(manager,res1Inf);
  908. Cudd_IterDerefBdd(manager,res2Inf);
  909. return(NULL);
  910. }
  911. if (compl) {
  912. res = Cudd_Not(res);
  913. }
  914. cuddRef(res);
  915. cuddDeref(res1Inf);
  916. cuddDeref(res2Inf);
  917. cuddCacheInsert2(manager, Cudd_addMinAbstractRepresentative, f, cube, res);
  918. cuddDeref(res);
  919. return(res);
  920. }
  921. else { /* if (cuddI(manager,f->index) < cuddI(manager,cube->index)) */
  922. res1 = cuddAddMinAbstractRepresentativeRecur(manager, E, cube);
  923. if (res1 == NULL) return(NULL);
  924. cuddRef(res1);
  925. res2 = cuddAddMinAbstractRepresentativeRecur(manager, T, cube);
  926. if (res2 == NULL) {
  927. Cudd_IterDerefBdd(manager,res1);
  928. return(NULL);
  929. }
  930. cuddRef(res2);
  931. int compl = (res1 == res2) ? 0 : Cudd_IsComplement(res2);
  932. res = (res1 == res2) ? res1 : cuddUniqueInter(manager, (int) f->index, Cudd_Regular(res2), compl ? Cudd_Not(res1) : res1);
  933. if (res == NULL) {
  934. Cudd_IterDerefBdd(manager,res1);
  935. Cudd_IterDerefBdd(manager,res2);
  936. return(NULL);
  937. }
  938. if (compl) {
  939. res = Cudd_Not(res);
  940. }
  941. cuddDeref(res1);
  942. cuddDeref(res2);
  943. cuddCacheInsert2(manager, Cudd_addMinAbstractRepresentative, f, cube, res);
  944. return(res);
  945. }
  946. } /* end of cuddAddMinAbstractRepresentativeRecur */
  947. /**Function********************************************************************
  948. Synopsis [Performs the recursive step of Cudd_addMaxAbstractRepresentative.]
  949. Description [Performs the recursive step of Cudd_addMaxAbstractRepresentative.
  950. Returns the ADD obtained by picking a representative over the variables in
  951. the given cube for all other valuations. Returns the resulting ADD if successful;
  952. NULL otherwise.]
  953. SideEffects [None]
  954. SeeAlso []
  955. ******************************************************************************/
  956. DdNode *
  957. cuddAddMaxAbstractRepresentativeRecur(
  958. DdManager * manager,
  959. DdNode * f,
  960. DdNode * cube)
  961. {
  962. DdNode *T, *E, *res, *res1, *res2, *zero, *one, *logicalZero, *res1Inf, *res2Inf, *left, *right, *tmp, *tmp2;
  963. zero = DD_ZERO(manager);
  964. one = DD_ONE(manager);
  965. logicalZero = Cudd_Not(one);
  966. /* Cube is guaranteed to be a cube at this point. */
  967. if (cuddIsConstant(cube)) {
  968. return one;
  969. }
  970. if (cuddIsConstant(f)) {
  971. res = cuddAddMaxAbstractRepresentativeRecur(manager, f, cuddT(cube));
  972. if (res == NULL) {
  973. return(NULL);
  974. }
  975. cuddRef(res);
  976. // We build in the negation ourselves.
  977. res1 = cuddUniqueInter(manager, (int) cube->index, one, Cudd_Not(res));
  978. if (res1 == NULL) {
  979. Cudd_IterDerefBdd(manager,res);
  980. return(NULL);
  981. }
  982. res1 = Cudd_Not(res1);
  983. cuddDeref(res);
  984. return(res1);
  985. }
  986. if ((res = cuddCacheLookup2(manager, Cudd_addMaxAbstractRepresentative, f, cube)) != NULL) {
  987. return(res);
  988. }
  989. /* Abstract a variable that does not appear in f. */
  990. if (cuddI(manager,f->index) > cuddI(manager,cube->index)) {
  991. res = cuddAddMaxAbstractRepresentativeRecur(manager, f, cuddT(cube));
  992. if (res == NULL) {
  993. return(NULL);
  994. }
  995. // Fill in the missing variables to make representative unique.
  996. cuddRef(res);
  997. res1 = cuddUniqueInter(manager, (int) cube->index, one, Cudd_Not(res));
  998. if (res1 == NULL) {
  999. Cudd_IterDerefBdd(manager, res);
  1000. return(NULL);
  1001. }
  1002. res1 = Cudd_Not(res1);
  1003. Cudd_IterDerefBdd(manager,res);
  1004. return(res1);
  1005. }
  1006. E = cuddE(f);
  1007. T = cuddT(f);
  1008. /* If the two indices are the same, so are their levels. */
  1009. if (f->index == cube->index) {
  1010. res1 = cuddAddMaxAbstractRepresentativeRecur(manager, E, cuddT(cube));
  1011. if (res1 == NULL) {
  1012. return(NULL);
  1013. }
  1014. cuddRef(res1);
  1015. res2 = cuddAddMaxAbstractRepresentativeRecur(manager, T, cuddT(cube));
  1016. if (res2 == NULL) {
  1017. Cudd_IterDerefBdd(manager, res1);
  1018. return(NULL);
  1019. }
  1020. cuddRef(res2);
  1021. left = cuddAddMaxAbstractRecur(manager, E, cuddT(cube));
  1022. if (left == NULL) {
  1023. Cudd_IterDerefBdd(manager, res1);
  1024. Cudd_IterDerefBdd(manager, res2);
  1025. return(NULL);
  1026. }
  1027. cuddRef(left);
  1028. right = cuddAddMaxAbstractRecur(manager, T, cuddT(cube));
  1029. if (right == NULL) {
  1030. Cudd_IterDerefBdd(manager, res1);
  1031. Cudd_IterDerefBdd(manager, res2);
  1032. Cudd_RecursiveDeref(manager, left);
  1033. return(NULL);
  1034. }
  1035. cuddRef(right);
  1036. tmp = cuddAddToBddApplyRecur(manager, Cudd_addToBddGreaterThanEquals, left, right);
  1037. if (tmp == NULL) {
  1038. Cudd_IterDerefBdd(manager,res1);
  1039. Cudd_IterDerefBdd(manager,res2);
  1040. Cudd_RecursiveDeref(manager,left);
  1041. Cudd_RecursiveDeref(manager,right);
  1042. return(NULL);
  1043. }
  1044. cuddRef(tmp);
  1045. Cudd_RecursiveDeref(manager, left);
  1046. Cudd_RecursiveDeref(manager, right);
  1047. cuddRef(zero);
  1048. res1Inf = cuddBddIteRecur(manager, tmp, res1, logicalZero);
  1049. if (res1Inf == NULL) {
  1050. Cudd_IterDerefBdd(manager,res1);
  1051. Cudd_IterDerefBdd(manager,res2);
  1052. Cudd_IterDerefBdd(manager,tmp);
  1053. cuddDeref(zero);
  1054. return(NULL);
  1055. }
  1056. cuddRef(res1Inf);
  1057. Cudd_IterDerefBdd(manager,res1);
  1058. cuddRef(zero);
  1059. res2Inf = cuddBddIteRecur(manager, tmp, logicalZero, res2);
  1060. if (res2Inf == NULL) {
  1061. Cudd_IterDerefBdd(manager,res2);
  1062. Cudd_IterDerefBdd(manager,res1Inf);
  1063. Cudd_IterDerefBdd(manager,tmp);
  1064. return(NULL);
  1065. }
  1066. cuddRef(res2Inf);
  1067. Cudd_IterDerefBdd(manager,res2);
  1068. Cudd_IterDerefBdd(manager,tmp);
  1069. int compl = (res1Inf == res2Inf) ? 1 : Cudd_IsComplement(res2Inf);
  1070. res = (res1Inf == res2Inf) ? cuddUniqueInter(manager, (int) f->index, one, Cudd_Not(res1Inf)) : cuddUniqueInter(manager, (int) f->index, Cudd_Regular(res2Inf), compl ? Cudd_Not(res1Inf) : res1Inf);
  1071. if (res == NULL) {
  1072. Cudd_IterDerefBdd(manager,res1Inf);
  1073. Cudd_IterDerefBdd(manager,res2Inf);
  1074. return(NULL);
  1075. }
  1076. if (compl) {
  1077. res = Cudd_Not(res);
  1078. }
  1079. cuddRef(res);
  1080. Cudd_IterDerefBdd(manager,res1Inf);
  1081. Cudd_IterDerefBdd(manager,res2Inf);
  1082. cuddCacheInsert2(manager, Cudd_addMaxAbstractRepresentative, f, cube, res);
  1083. cuddDeref(res);
  1084. return(res);
  1085. }
  1086. else { /* if (cuddI(manager,f->index) < cuddI(manager,cube->index)) */
  1087. res1 = cuddAddMaxAbstractRepresentativeRecur(manager, E, cube);
  1088. if (res1 == NULL) return(NULL);
  1089. cuddRef(res1);
  1090. res2 = cuddAddMaxAbstractRepresentativeRecur(manager, T, cube);
  1091. if (res2 == NULL) {
  1092. Cudd_IterDerefBdd(manager,res1);
  1093. return(NULL);
  1094. }
  1095. cuddRef(res2);
  1096. int compl = (res1 == res2) ? 0 : Cudd_IsComplement(res2);
  1097. res = (res1 == res2) ? res1 : cuddUniqueInter(manager, (int) f->index, Cudd_Regular(res2), compl ? Cudd_Not(res1) : res1);
  1098. if (res == NULL) {
  1099. Cudd_IterDerefBdd(manager,res1);
  1100. Cudd_IterDerefBdd(manager,res2);
  1101. return(NULL);
  1102. }
  1103. if (compl) {
  1104. res = Cudd_Not(res);
  1105. }
  1106. cuddDeref(res1);
  1107. cuddDeref(res2);
  1108. cuddCacheInsert2(manager, Cudd_addMaxAbstractRepresentative, f, cube, res);
  1109. return(res);
  1110. }
  1111. } /* end of cuddAddMaxAbstractRepresentativeRecur */
  1112. /*---------------------------------------------------------------------------*/
  1113. /* Definition of static functions */
  1114. /*---------------------------------------------------------------------------*/
  1115. /**
  1116. @brief Checks whether cube is an %ADD representing the product
  1117. of positive literals.
  1118. @return 1 in case of success; 0 otherwise.
  1119. @sideeffect None
  1120. */
  1121. static int
  1122. addCheckPositiveCube(
  1123. DdManager * manager,
  1124. DdNode * cube)
  1125. {
  1126. if (Cudd_IsComplement(cube)) return(0);
  1127. if (cube == DD_ONE(manager)) return(1);
  1128. if (cuddIsConstant(cube)) return(0);
  1129. if (cuddE(cube) == DD_ZERO(manager)) {
  1130. return(addCheckPositiveCube(manager, cuddT(cube)));
  1131. }
  1132. return(0);
  1133. } /* end of addCheckPositiveCube */