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.

1549 lines
35 KiB

3 months ago
  1. /**
  2. @file
  3. @ingroup cudd
  4. @brief Functions to manipulate covers represented as ZDDs.
  5. @author In-Ho Moon
  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. /** \endcond */
  56. /*---------------------------------------------------------------------------*/
  57. /* Definition of exported functions */
  58. /*---------------------------------------------------------------------------*/
  59. /**
  60. @brief Computes the product of two covers represented by ZDDs.
  61. @details The result is also a %ZDD. The covers on which
  62. Cudd_zddProduct operates use two %ZDD variables for each function
  63. variable (one %ZDD variable for each literal of the variable). Those
  64. two %ZDD variables should be adjacent in the order.
  65. @return a pointer to the result if successful; NULL otherwise.
  66. @sideeffect None
  67. @see Cudd_zddUnateProduct
  68. */
  69. DdNode *
  70. Cudd_zddProduct(
  71. DdManager * dd,
  72. DdNode * f,
  73. DdNode * g)
  74. {
  75. DdNode *res;
  76. do {
  77. dd->reordered = 0;
  78. res = cuddZddProduct(dd, f, g);
  79. } while (dd->reordered == 1);
  80. if (dd->errorCode == CUDD_TIMEOUT_EXPIRED && dd->timeoutHandler) {
  81. dd->timeoutHandler(dd, dd->tohArg);
  82. }
  83. return(res);
  84. } /* end of Cudd_zddProduct */
  85. /**
  86. @brief Computes the product of two unate covers represented as ZDDs.
  87. @details Unate covers use one %ZDD variable for each %BDD
  88. variable.
  89. @return a pointer to the result if successful; NULL otherwise.
  90. @sideeffect None
  91. @see Cudd_zddProduct
  92. */
  93. DdNode *
  94. Cudd_zddUnateProduct(
  95. DdManager * dd,
  96. DdNode * f,
  97. DdNode * g)
  98. {
  99. DdNode *res;
  100. do {
  101. dd->reordered = 0;
  102. res = cuddZddUnateProduct(dd, f, g);
  103. } while (dd->reordered == 1);
  104. if (dd->errorCode == CUDD_TIMEOUT_EXPIRED && dd->timeoutHandler) {
  105. dd->timeoutHandler(dd, dd->tohArg);
  106. }
  107. return(res);
  108. } /* end of Cudd_zddUnateProduct */
  109. /**
  110. @brief Applies weak division to two covers.
  111. @details Applies weak division to two ZDDs representing two covers.
  112. The result of weak division depends on the variable order. The
  113. covers on which Cudd_zddWeakDiv operates use two %ZDD variables for
  114. each function variable (one %ZDD variable for each literal of the
  115. variable). Those two %ZDD variables should be adjacent in the order.
  116. @return a pointer to the %ZDD representing the result if successful;
  117. NULL otherwise.
  118. @sideeffect None
  119. @see Cudd_zddDivide
  120. */
  121. DdNode *
  122. Cudd_zddWeakDiv(
  123. DdManager * dd,
  124. DdNode * f,
  125. DdNode * g)
  126. {
  127. DdNode *res;
  128. do {
  129. dd->reordered = 0;
  130. res = cuddZddWeakDiv(dd, f, g);
  131. } while (dd->reordered == 1);
  132. if (dd->errorCode == CUDD_TIMEOUT_EXPIRED && dd->timeoutHandler) {
  133. dd->timeoutHandler(dd, dd->tohArg);
  134. }
  135. return(res);
  136. } /* end of Cudd_zddWeakDiv */
  137. /**
  138. @brief Computes the quotient of two unate covers.
  139. @details Computes the quotient of two unate covers represented by
  140. ZDDs. Unate covers use one %ZDD variable for each %BDD variable.
  141. @return a pointer to the resulting %ZDD if successful; NULL
  142. otherwise.
  143. @sideeffect None
  144. @see Cudd_zddWeakDiv
  145. */
  146. DdNode *
  147. Cudd_zddDivide(
  148. DdManager * dd,
  149. DdNode * f,
  150. DdNode * g)
  151. {
  152. DdNode *res;
  153. do {
  154. dd->reordered = 0;
  155. res = cuddZddDivide(dd, f, g);
  156. } while (dd->reordered == 1);
  157. if (dd->errorCode == CUDD_TIMEOUT_EXPIRED && dd->timeoutHandler) {
  158. dd->timeoutHandler(dd, dd->tohArg);
  159. }
  160. return(res);
  161. } /* end of Cudd_zddDivide */
  162. /**
  163. @brief Modified version of Cudd_zddWeakDiv.
  164. @details This function may disappear in future releases.
  165. @sideeffect None
  166. @see Cudd_zddWeakDiv
  167. */
  168. DdNode *
  169. Cudd_zddWeakDivF(
  170. DdManager * dd,
  171. DdNode * f,
  172. DdNode * g)
  173. {
  174. DdNode *res;
  175. do {
  176. dd->reordered = 0;
  177. res = cuddZddWeakDivF(dd, f, g);
  178. } while (dd->reordered == 1);
  179. if (dd->errorCode == CUDD_TIMEOUT_EXPIRED && dd->timeoutHandler) {
  180. dd->timeoutHandler(dd, dd->tohArg);
  181. }
  182. return(res);
  183. } /* end of Cudd_zddWeakDivF */
  184. /**
  185. @brief Modified version of Cudd_zddDivide.
  186. @details This function may disappear in future releases.
  187. @sideeffect None
  188. */
  189. DdNode *
  190. Cudd_zddDivideF(
  191. DdManager * dd,
  192. DdNode * f,
  193. DdNode * g)
  194. {
  195. DdNode *res;
  196. do {
  197. dd->reordered = 0;
  198. res = cuddZddDivideF(dd, f, g);
  199. } while (dd->reordered == 1);
  200. if (dd->errorCode == CUDD_TIMEOUT_EXPIRED && dd->timeoutHandler) {
  201. dd->timeoutHandler(dd, dd->tohArg);
  202. }
  203. return(res);
  204. } /* end of Cudd_zddDivideF */
  205. /**
  206. @brief Computes a complement cover for a %ZDD node.
  207. @details For lack of a better method, we first extract the function
  208. %BDD from the %ZDD cover, then make the complement of the %ZDD cover
  209. from the complement of the %BDD node by using ISOP. The result
  210. depends on current variable order.
  211. @return a pointer to the resulting cover if successful; NULL
  212. otherwise.
  213. @sideeffect The result depends on current variable order.
  214. */
  215. DdNode *
  216. Cudd_zddComplement(
  217. DdManager *dd,
  218. DdNode *node)
  219. {
  220. DdNode *b, *isop, *zdd_I;
  221. /* Check cache */
  222. zdd_I = cuddCacheLookup1Zdd(dd, cuddZddComplement, node);
  223. if (zdd_I)
  224. return(zdd_I);
  225. b = Cudd_MakeBddFromZddCover(dd, node);
  226. if (!b)
  227. return(NULL);
  228. Cudd_Ref(b);
  229. isop = Cudd_zddIsop(dd, Cudd_Not(b), Cudd_Not(b), &zdd_I);
  230. if (!isop) {
  231. Cudd_RecursiveDeref(dd, b);
  232. return(NULL);
  233. }
  234. Cudd_Ref(isop);
  235. Cudd_Ref(zdd_I);
  236. Cudd_RecursiveDeref(dd, b);
  237. Cudd_RecursiveDeref(dd, isop);
  238. cuddCacheInsert1(dd, cuddZddComplement, node, zdd_I);
  239. Cudd_Deref(zdd_I);
  240. return(zdd_I);
  241. } /* end of Cudd_zddComplement */
  242. /*---------------------------------------------------------------------------*/
  243. /* Definition of internal functions */
  244. /*---------------------------------------------------------------------------*/
  245. /**
  246. @brief Performs the recursive step of Cudd_zddProduct.
  247. @sideeffect None
  248. @see Cudd_zddProduct
  249. */
  250. DdNode *
  251. cuddZddProduct(
  252. DdManager * dd,
  253. DdNode * f,
  254. DdNode * g)
  255. {
  256. int v;
  257. int top_f, top_g;
  258. DdNode *tmp, *term1, *term2, *term3;
  259. DdNode *f0, *f1, *fd, *g0, *g1, *gd;
  260. DdNode *R0, *R1, *Rd, *N0, *N1;
  261. DdNode *r;
  262. DdNode *one = DD_ONE(dd);
  263. DdNode *zero = DD_ZERO(dd);
  264. int flag;
  265. int pv, nv;
  266. statLine(dd);
  267. if (f == zero || g == zero)
  268. return(zero);
  269. if (f == one)
  270. return(g);
  271. if (g == one)
  272. return(f);
  273. top_f = dd->permZ[f->index];
  274. top_g = dd->permZ[g->index];
  275. if (top_f > top_g)
  276. return(cuddZddProduct(dd, g, f));
  277. /* Check cache */
  278. r = cuddCacheLookup2Zdd(dd, cuddZddProduct, f, g);
  279. if (r)
  280. return(r);
  281. v = (int) f->index; /* either yi or zi */
  282. flag = cuddZddGetCofactors3(dd, f, v, &f1, &f0, &fd);
  283. if (flag == 1)
  284. return(NULL);
  285. Cudd_Ref(f1);
  286. Cudd_Ref(f0);
  287. Cudd_Ref(fd);
  288. flag = cuddZddGetCofactors3(dd, g, v, &g1, &g0, &gd);
  289. if (flag == 1) {
  290. Cudd_RecursiveDerefZdd(dd, f1);
  291. Cudd_RecursiveDerefZdd(dd, f0);
  292. Cudd_RecursiveDerefZdd(dd, fd);
  293. return(NULL);
  294. }
  295. Cudd_Ref(g1);
  296. Cudd_Ref(g0);
  297. Cudd_Ref(gd);
  298. pv = cuddZddGetPosVarIndex(dd, v);
  299. nv = cuddZddGetNegVarIndex(dd, v);
  300. Rd = cuddZddProduct(dd, fd, gd);
  301. if (Rd == NULL) {
  302. Cudd_RecursiveDerefZdd(dd, f1);
  303. Cudd_RecursiveDerefZdd(dd, f0);
  304. Cudd_RecursiveDerefZdd(dd, fd);
  305. Cudd_RecursiveDerefZdd(dd, g1);
  306. Cudd_RecursiveDerefZdd(dd, g0);
  307. Cudd_RecursiveDerefZdd(dd, gd);
  308. return(NULL);
  309. }
  310. Cudd_Ref(Rd);
  311. term1 = cuddZddProduct(dd, f0, g0);
  312. if (term1 == NULL) {
  313. Cudd_RecursiveDerefZdd(dd, f1);
  314. Cudd_RecursiveDerefZdd(dd, f0);
  315. Cudd_RecursiveDerefZdd(dd, fd);
  316. Cudd_RecursiveDerefZdd(dd, g1);
  317. Cudd_RecursiveDerefZdd(dd, g0);
  318. Cudd_RecursiveDerefZdd(dd, gd);
  319. Cudd_RecursiveDerefZdd(dd, Rd);
  320. return(NULL);
  321. }
  322. Cudd_Ref(term1);
  323. term2 = cuddZddProduct(dd, f0, gd);
  324. if (term2 == NULL) {
  325. Cudd_RecursiveDerefZdd(dd, f1);
  326. Cudd_RecursiveDerefZdd(dd, f0);
  327. Cudd_RecursiveDerefZdd(dd, fd);
  328. Cudd_RecursiveDerefZdd(dd, g1);
  329. Cudd_RecursiveDerefZdd(dd, g0);
  330. Cudd_RecursiveDerefZdd(dd, gd);
  331. Cudd_RecursiveDerefZdd(dd, Rd);
  332. Cudd_RecursiveDerefZdd(dd, term1);
  333. return(NULL);
  334. }
  335. Cudd_Ref(term2);
  336. term3 = cuddZddProduct(dd, fd, g0);
  337. if (term3 == NULL) {
  338. Cudd_RecursiveDerefZdd(dd, f1);
  339. Cudd_RecursiveDerefZdd(dd, f0);
  340. Cudd_RecursiveDerefZdd(dd, fd);
  341. Cudd_RecursiveDerefZdd(dd, g1);
  342. Cudd_RecursiveDerefZdd(dd, g0);
  343. Cudd_RecursiveDerefZdd(dd, gd);
  344. Cudd_RecursiveDerefZdd(dd, Rd);
  345. Cudd_RecursiveDerefZdd(dd, term1);
  346. Cudd_RecursiveDerefZdd(dd, term2);
  347. return(NULL);
  348. }
  349. Cudd_Ref(term3);
  350. Cudd_RecursiveDerefZdd(dd, f0);
  351. Cudd_RecursiveDerefZdd(dd, g0);
  352. tmp = cuddZddUnion(dd, term1, term2);
  353. if (tmp == NULL) {
  354. Cudd_RecursiveDerefZdd(dd, f1);
  355. Cudd_RecursiveDerefZdd(dd, fd);
  356. Cudd_RecursiveDerefZdd(dd, g1);
  357. Cudd_RecursiveDerefZdd(dd, gd);
  358. Cudd_RecursiveDerefZdd(dd, Rd);
  359. Cudd_RecursiveDerefZdd(dd, term1);
  360. Cudd_RecursiveDerefZdd(dd, term2);
  361. Cudd_RecursiveDerefZdd(dd, term3);
  362. return(NULL);
  363. }
  364. Cudd_Ref(tmp);
  365. Cudd_RecursiveDerefZdd(dd, term1);
  366. Cudd_RecursiveDerefZdd(dd, term2);
  367. R0 = cuddZddUnion(dd, tmp, term3);
  368. if (R0 == NULL) {
  369. Cudd_RecursiveDerefZdd(dd, f1);
  370. Cudd_RecursiveDerefZdd(dd, fd);
  371. Cudd_RecursiveDerefZdd(dd, g1);
  372. Cudd_RecursiveDerefZdd(dd, gd);
  373. Cudd_RecursiveDerefZdd(dd, Rd);
  374. Cudd_RecursiveDerefZdd(dd, term3);
  375. Cudd_RecursiveDerefZdd(dd, tmp);
  376. return(NULL);
  377. }
  378. Cudd_Ref(R0);
  379. Cudd_RecursiveDerefZdd(dd, tmp);
  380. Cudd_RecursiveDerefZdd(dd, term3);
  381. N0 = cuddZddGetNode(dd, nv, R0, Rd); /* nv = zi */
  382. if (N0 == NULL) {
  383. Cudd_RecursiveDerefZdd(dd, f1);
  384. Cudd_RecursiveDerefZdd(dd, fd);
  385. Cudd_RecursiveDerefZdd(dd, g1);
  386. Cudd_RecursiveDerefZdd(dd, gd);
  387. Cudd_RecursiveDerefZdd(dd, Rd);
  388. Cudd_RecursiveDerefZdd(dd, R0);
  389. return(NULL);
  390. }
  391. Cudd_Ref(N0);
  392. Cudd_RecursiveDerefZdd(dd, R0);
  393. Cudd_RecursiveDerefZdd(dd, Rd);
  394. term1 = cuddZddProduct(dd, f1, g1);
  395. if (term1 == NULL) {
  396. Cudd_RecursiveDerefZdd(dd, f1);
  397. Cudd_RecursiveDerefZdd(dd, fd);
  398. Cudd_RecursiveDerefZdd(dd, g1);
  399. Cudd_RecursiveDerefZdd(dd, gd);
  400. Cudd_RecursiveDerefZdd(dd, N0);
  401. return(NULL);
  402. }
  403. Cudd_Ref(term1);
  404. term2 = cuddZddProduct(dd, f1, gd);
  405. if (term2 == NULL) {
  406. Cudd_RecursiveDerefZdd(dd, f1);
  407. Cudd_RecursiveDerefZdd(dd, fd);
  408. Cudd_RecursiveDerefZdd(dd, g1);
  409. Cudd_RecursiveDerefZdd(dd, gd);
  410. Cudd_RecursiveDerefZdd(dd, N0);
  411. Cudd_RecursiveDerefZdd(dd, term1);
  412. return(NULL);
  413. }
  414. Cudd_Ref(term2);
  415. term3 = cuddZddProduct(dd, fd, g1);
  416. if (term3 == NULL) {
  417. Cudd_RecursiveDerefZdd(dd, f1);
  418. Cudd_RecursiveDerefZdd(dd, fd);
  419. Cudd_RecursiveDerefZdd(dd, g1);
  420. Cudd_RecursiveDerefZdd(dd, gd);
  421. Cudd_RecursiveDerefZdd(dd, N0);
  422. Cudd_RecursiveDerefZdd(dd, term1);
  423. Cudd_RecursiveDerefZdd(dd, term2);
  424. return(NULL);
  425. }
  426. Cudd_Ref(term3);
  427. Cudd_RecursiveDerefZdd(dd, f1);
  428. Cudd_RecursiveDerefZdd(dd, g1);
  429. Cudd_RecursiveDerefZdd(dd, fd);
  430. Cudd_RecursiveDerefZdd(dd, gd);
  431. tmp = cuddZddUnion(dd, term1, term2);
  432. if (tmp == NULL) {
  433. Cudd_RecursiveDerefZdd(dd, N0);
  434. Cudd_RecursiveDerefZdd(dd, term1);
  435. Cudd_RecursiveDerefZdd(dd, term2);
  436. Cudd_RecursiveDerefZdd(dd, term3);
  437. return(NULL);
  438. }
  439. Cudd_Ref(tmp);
  440. Cudd_RecursiveDerefZdd(dd, term1);
  441. Cudd_RecursiveDerefZdd(dd, term2);
  442. R1 = cuddZddUnion(dd, tmp, term3);
  443. if (R1 == NULL) {
  444. Cudd_RecursiveDerefZdd(dd, N0);
  445. Cudd_RecursiveDerefZdd(dd, term3);
  446. Cudd_RecursiveDerefZdd(dd, tmp);
  447. return(NULL);
  448. }
  449. Cudd_Ref(R1);
  450. Cudd_RecursiveDerefZdd(dd, tmp);
  451. Cudd_RecursiveDerefZdd(dd, term3);
  452. N1 = cuddZddGetNode(dd, pv, R1, N0); /* pv = yi */
  453. if (N1 == NULL) {
  454. Cudd_RecursiveDerefZdd(dd, N0);
  455. Cudd_RecursiveDerefZdd(dd, R1);
  456. return(NULL);
  457. }
  458. Cudd_Ref(N1);
  459. Cudd_RecursiveDerefZdd(dd, R1);
  460. Cudd_RecursiveDerefZdd(dd, N0);
  461. cuddCacheInsert2(dd, cuddZddProduct, f, g, N1);
  462. Cudd_Deref(N1);
  463. return(N1);
  464. } /* end of cuddZddProduct */
  465. /**
  466. @brief Performs the recursive step of Cudd_zddUnateProduct.
  467. @sideeffect None
  468. @see Cudd_zddUnateProduct
  469. */
  470. DdNode *
  471. cuddZddUnateProduct(
  472. DdManager * dd,
  473. DdNode * f,
  474. DdNode * g)
  475. {
  476. int v;
  477. int top_f, top_g;
  478. DdNode *term1, *term2, *term3, *term4;
  479. DdNode *sum1, *sum2;
  480. DdNode *f0, *f1, *g0, *g1;
  481. DdNode *r;
  482. DdNode *one = DD_ONE(dd);
  483. DdNode *zero = DD_ZERO(dd);
  484. int flag;
  485. statLine(dd);
  486. if (f == zero || g == zero)
  487. return(zero);
  488. if (f == one)
  489. return(g);
  490. if (g == one)
  491. return(f);
  492. top_f = dd->permZ[f->index];
  493. top_g = dd->permZ[g->index];
  494. if (top_f > top_g)
  495. return(cuddZddUnateProduct(dd, g, f));
  496. /* Check cache */
  497. r = cuddCacheLookup2Zdd(dd, cuddZddUnateProduct, f, g);
  498. if (r)
  499. return(r);
  500. v = (int) f->index; /* either yi or zi */
  501. flag = cuddZddGetCofactors2(dd, f, v, &f1, &f0);
  502. if (flag == 1)
  503. return(NULL);
  504. Cudd_Ref(f1);
  505. Cudd_Ref(f0);
  506. flag = cuddZddGetCofactors2(dd, g, v, &g1, &g0);
  507. if (flag == 1) {
  508. Cudd_RecursiveDerefZdd(dd, f1);
  509. Cudd_RecursiveDerefZdd(dd, f0);
  510. return(NULL);
  511. }
  512. Cudd_Ref(g1);
  513. Cudd_Ref(g0);
  514. term1 = cuddZddUnateProduct(dd, f1, g1);
  515. if (term1 == NULL) {
  516. Cudd_RecursiveDerefZdd(dd, f1);
  517. Cudd_RecursiveDerefZdd(dd, f0);
  518. Cudd_RecursiveDerefZdd(dd, g1);
  519. Cudd_RecursiveDerefZdd(dd, g0);
  520. return(NULL);
  521. }
  522. Cudd_Ref(term1);
  523. term2 = cuddZddUnateProduct(dd, f1, g0);
  524. if (term2 == NULL) {
  525. Cudd_RecursiveDerefZdd(dd, f1);
  526. Cudd_RecursiveDerefZdd(dd, f0);
  527. Cudd_RecursiveDerefZdd(dd, g1);
  528. Cudd_RecursiveDerefZdd(dd, g0);
  529. Cudd_RecursiveDerefZdd(dd, term1);
  530. return(NULL);
  531. }
  532. Cudd_Ref(term2);
  533. term3 = cuddZddUnateProduct(dd, f0, g1);
  534. if (term3 == NULL) {
  535. Cudd_RecursiveDerefZdd(dd, f1);
  536. Cudd_RecursiveDerefZdd(dd, f0);
  537. Cudd_RecursiveDerefZdd(dd, g1);
  538. Cudd_RecursiveDerefZdd(dd, g0);
  539. Cudd_RecursiveDerefZdd(dd, term1);
  540. Cudd_RecursiveDerefZdd(dd, term2);
  541. return(NULL);
  542. }
  543. Cudd_Ref(term3);
  544. term4 = cuddZddUnateProduct(dd, f0, g0);
  545. if (term4 == NULL) {
  546. Cudd_RecursiveDerefZdd(dd, f1);
  547. Cudd_RecursiveDerefZdd(dd, f0);
  548. Cudd_RecursiveDerefZdd(dd, g1);
  549. Cudd_RecursiveDerefZdd(dd, g0);
  550. Cudd_RecursiveDerefZdd(dd, term1);
  551. Cudd_RecursiveDerefZdd(dd, term2);
  552. Cudd_RecursiveDerefZdd(dd, term3);
  553. return(NULL);
  554. }
  555. Cudd_Ref(term4);
  556. Cudd_RecursiveDerefZdd(dd, f1);
  557. Cudd_RecursiveDerefZdd(dd, f0);
  558. Cudd_RecursiveDerefZdd(dd, g1);
  559. Cudd_RecursiveDerefZdd(dd, g0);
  560. sum1 = cuddZddUnion(dd, term1, term2);
  561. if (sum1 == NULL) {
  562. Cudd_RecursiveDerefZdd(dd, term1);
  563. Cudd_RecursiveDerefZdd(dd, term2);
  564. Cudd_RecursiveDerefZdd(dd, term3);
  565. Cudd_RecursiveDerefZdd(dd, term4);
  566. return(NULL);
  567. }
  568. Cudd_Ref(sum1);
  569. Cudd_RecursiveDerefZdd(dd, term1);
  570. Cudd_RecursiveDerefZdd(dd, term2);
  571. sum2 = cuddZddUnion(dd, sum1, term3);
  572. if (sum2 == NULL) {
  573. Cudd_RecursiveDerefZdd(dd, term3);
  574. Cudd_RecursiveDerefZdd(dd, term4);
  575. Cudd_RecursiveDerefZdd(dd, sum1);
  576. return(NULL);
  577. }
  578. Cudd_Ref(sum2);
  579. Cudd_RecursiveDerefZdd(dd, sum1);
  580. Cudd_RecursiveDerefZdd(dd, term3);
  581. r = cuddZddGetNode(dd, v, sum2, term4);
  582. if (r == NULL) {
  583. Cudd_RecursiveDerefZdd(dd, term4);
  584. Cudd_RecursiveDerefZdd(dd, sum2);
  585. return(NULL);
  586. }
  587. Cudd_Ref(r);
  588. Cudd_RecursiveDerefZdd(dd, sum2);
  589. Cudd_RecursiveDerefZdd(dd, term4);
  590. cuddCacheInsert2(dd, cuddZddUnateProduct, f, g, r);
  591. Cudd_Deref(r);
  592. return(r);
  593. } /* end of cuddZddUnateProduct */
  594. /**
  595. @brief Performs the recursive step of Cudd_zddWeakDiv.
  596. @sideeffect None
  597. @see Cudd_zddWeakDiv
  598. */
  599. DdNode *
  600. cuddZddWeakDiv(
  601. DdManager * dd,
  602. DdNode * f,
  603. DdNode * g)
  604. {
  605. int v;
  606. DdNode *one = DD_ONE(dd);
  607. DdNode *zero = DD_ZERO(dd);
  608. DdNode *f0, *f1, *fd, *g0, *g1, *gd;
  609. DdNode *q, *tmp;
  610. DdNode *r;
  611. int flag;
  612. statLine(dd);
  613. if (g == one)
  614. return(f);
  615. if (f == zero || f == one)
  616. return(zero);
  617. if (f == g)
  618. return(one);
  619. /* Check cache. */
  620. r = cuddCacheLookup2Zdd(dd, cuddZddWeakDiv, f, g);
  621. if (r)
  622. return(r);
  623. v = (int) g->index;
  624. flag = cuddZddGetCofactors3(dd, f, v, &f1, &f0, &fd);
  625. if (flag == 1)
  626. return(NULL);
  627. Cudd_Ref(f1);
  628. Cudd_Ref(f0);
  629. Cudd_Ref(fd);
  630. flag = cuddZddGetCofactors3(dd, g, v, &g1, &g0, &gd);
  631. if (flag == 1) {
  632. Cudd_RecursiveDerefZdd(dd, f1);
  633. Cudd_RecursiveDerefZdd(dd, f0);
  634. Cudd_RecursiveDerefZdd(dd, fd);
  635. return(NULL);
  636. }
  637. Cudd_Ref(g1);
  638. Cudd_Ref(g0);
  639. Cudd_Ref(gd);
  640. q = g;
  641. if (g0 != zero) {
  642. q = cuddZddWeakDiv(dd, f0, g0);
  643. if (q == NULL) {
  644. Cudd_RecursiveDerefZdd(dd, f1);
  645. Cudd_RecursiveDerefZdd(dd, f0);
  646. Cudd_RecursiveDerefZdd(dd, fd);
  647. Cudd_RecursiveDerefZdd(dd, g1);
  648. Cudd_RecursiveDerefZdd(dd, g0);
  649. Cudd_RecursiveDerefZdd(dd, gd);
  650. return(NULL);
  651. }
  652. Cudd_Ref(q);
  653. }
  654. else
  655. Cudd_Ref(q);
  656. Cudd_RecursiveDerefZdd(dd, f0);
  657. Cudd_RecursiveDerefZdd(dd, g0);
  658. if (q == zero) {
  659. Cudd_RecursiveDerefZdd(dd, f1);
  660. Cudd_RecursiveDerefZdd(dd, g1);
  661. Cudd_RecursiveDerefZdd(dd, fd);
  662. Cudd_RecursiveDerefZdd(dd, gd);
  663. cuddCacheInsert2(dd, cuddZddWeakDiv, f, g, zero);
  664. Cudd_Deref(q);
  665. return(zero);
  666. }
  667. if (g1 != zero) {
  668. Cudd_RecursiveDerefZdd(dd, q);
  669. tmp = cuddZddWeakDiv(dd, f1, g1);
  670. if (tmp == NULL) {
  671. Cudd_RecursiveDerefZdd(dd, f1);
  672. Cudd_RecursiveDerefZdd(dd, g1);
  673. Cudd_RecursiveDerefZdd(dd, fd);
  674. Cudd_RecursiveDerefZdd(dd, gd);
  675. return(NULL);
  676. }
  677. Cudd_Ref(tmp);
  678. Cudd_RecursiveDerefZdd(dd, f1);
  679. Cudd_RecursiveDerefZdd(dd, g1);
  680. if (q == g)
  681. q = tmp;
  682. else {
  683. q = cuddZddIntersect(dd, q, tmp);
  684. if (q == NULL) {
  685. Cudd_RecursiveDerefZdd(dd, fd);
  686. Cudd_RecursiveDerefZdd(dd, gd);
  687. return(NULL);
  688. }
  689. Cudd_Ref(q);
  690. Cudd_RecursiveDerefZdd(dd, tmp);
  691. }
  692. }
  693. else {
  694. Cudd_RecursiveDerefZdd(dd, f1);
  695. Cudd_RecursiveDerefZdd(dd, g1);
  696. }
  697. if (q == zero) {
  698. Cudd_RecursiveDerefZdd(dd, fd);
  699. Cudd_RecursiveDerefZdd(dd, gd);
  700. cuddCacheInsert2(dd, cuddZddWeakDiv, f, g, zero);
  701. Cudd_Deref(q);
  702. return(zero);
  703. }
  704. if (gd != zero) {
  705. Cudd_RecursiveDerefZdd(dd, q);
  706. tmp = cuddZddWeakDiv(dd, fd, gd);
  707. if (tmp == NULL) {
  708. Cudd_RecursiveDerefZdd(dd, fd);
  709. Cudd_RecursiveDerefZdd(dd, gd);
  710. return(NULL);
  711. }
  712. Cudd_Ref(tmp);
  713. Cudd_RecursiveDerefZdd(dd, fd);
  714. Cudd_RecursiveDerefZdd(dd, gd);
  715. if (q == g)
  716. q = tmp;
  717. else {
  718. q = cuddZddIntersect(dd, q, tmp);
  719. if (q == NULL) {
  720. Cudd_RecursiveDerefZdd(dd, tmp);
  721. return(NULL);
  722. }
  723. Cudd_Ref(q);
  724. Cudd_RecursiveDerefZdd(dd, tmp);
  725. }
  726. }
  727. else {
  728. Cudd_RecursiveDerefZdd(dd, fd);
  729. Cudd_RecursiveDerefZdd(dd, gd);
  730. }
  731. cuddCacheInsert2(dd, cuddZddWeakDiv, f, g, q);
  732. Cudd_Deref(q);
  733. return(q);
  734. } /* end of cuddZddWeakDiv */
  735. /**
  736. @brief Performs the recursive step of Cudd_zddWeakDivF.
  737. @sideeffect None
  738. @see Cudd_zddWeakDivF
  739. */
  740. DdNode *
  741. cuddZddWeakDivF(
  742. DdManager * dd,
  743. DdNode * f,
  744. DdNode * g)
  745. {
  746. int v;
  747. int top_f, top_g, vf, vg;
  748. DdNode *one = DD_ONE(dd);
  749. DdNode *zero = DD_ZERO(dd);
  750. DdNode *f0, *f1, *fd, *g0, *g1, *gd;
  751. DdNode *q, *tmp;
  752. DdNode *r;
  753. DdNode *term1, *term0, *termd;
  754. int flag;
  755. int pv, nv;
  756. statLine(dd);
  757. if (g == one)
  758. return(f);
  759. if (f == zero || f == one)
  760. return(zero);
  761. if (f == g)
  762. return(one);
  763. /* Check cache. */
  764. r = cuddCacheLookup2Zdd(dd, cuddZddWeakDivF, f, g);
  765. if (r)
  766. return(r);
  767. top_f = dd->permZ[f->index];
  768. top_g = dd->permZ[g->index];
  769. vf = top_f >> 1;
  770. vg = top_g >> 1;
  771. v = ddMin(top_f, top_g);
  772. if (v == top_f && vf < vg) {
  773. v = (int) f->index;
  774. flag = cuddZddGetCofactors3(dd, f, v, &f1, &f0, &fd);
  775. if (flag == 1)
  776. return(NULL);
  777. Cudd_Ref(f1);
  778. Cudd_Ref(f0);
  779. Cudd_Ref(fd);
  780. pv = cuddZddGetPosVarIndex(dd, v);
  781. nv = cuddZddGetNegVarIndex(dd, v);
  782. term1 = cuddZddWeakDivF(dd, f1, g);
  783. if (term1 == NULL) {
  784. Cudd_RecursiveDerefZdd(dd, f1);
  785. Cudd_RecursiveDerefZdd(dd, f0);
  786. Cudd_RecursiveDerefZdd(dd, fd);
  787. return(NULL);
  788. }
  789. Cudd_Ref(term1);
  790. Cudd_RecursiveDerefZdd(dd, f1);
  791. term0 = cuddZddWeakDivF(dd, f0, g);
  792. if (term0 == NULL) {
  793. Cudd_RecursiveDerefZdd(dd, f0);
  794. Cudd_RecursiveDerefZdd(dd, fd);
  795. Cudd_RecursiveDerefZdd(dd, term1);
  796. return(NULL);
  797. }
  798. Cudd_Ref(term0);
  799. Cudd_RecursiveDerefZdd(dd, f0);
  800. termd = cuddZddWeakDivF(dd, fd, g);
  801. if (termd == NULL) {
  802. Cudd_RecursiveDerefZdd(dd, fd);
  803. Cudd_RecursiveDerefZdd(dd, term1);
  804. Cudd_RecursiveDerefZdd(dd, term0);
  805. return(NULL);
  806. }
  807. Cudd_Ref(termd);
  808. Cudd_RecursiveDerefZdd(dd, fd);
  809. tmp = cuddZddGetNode(dd, nv, term0, termd); /* nv = zi */
  810. if (tmp == NULL) {
  811. Cudd_RecursiveDerefZdd(dd, term1);
  812. Cudd_RecursiveDerefZdd(dd, term0);
  813. Cudd_RecursiveDerefZdd(dd, termd);
  814. return(NULL);
  815. }
  816. Cudd_Ref(tmp);
  817. Cudd_RecursiveDerefZdd(dd, term0);
  818. Cudd_RecursiveDerefZdd(dd, termd);
  819. q = cuddZddGetNode(dd, pv, term1, tmp); /* pv = yi */
  820. if (q == NULL) {
  821. Cudd_RecursiveDerefZdd(dd, term1);
  822. Cudd_RecursiveDerefZdd(dd, tmp);
  823. return(NULL);
  824. }
  825. Cudd_Ref(q);
  826. Cudd_RecursiveDerefZdd(dd, term1);
  827. Cudd_RecursiveDerefZdd(dd, tmp);
  828. cuddCacheInsert2(dd, cuddZddWeakDivF, f, g, q);
  829. Cudd_Deref(q);
  830. return(q);
  831. }
  832. if (v == top_f)
  833. v = (int) f->index;
  834. else
  835. v = (int) g->index;
  836. flag = cuddZddGetCofactors3(dd, f, v, &f1, &f0, &fd);
  837. if (flag == 1)
  838. return(NULL);
  839. Cudd_Ref(f1);
  840. Cudd_Ref(f0);
  841. Cudd_Ref(fd);
  842. flag = cuddZddGetCofactors3(dd, g, v, &g1, &g0, &gd);
  843. if (flag == 1) {
  844. Cudd_RecursiveDerefZdd(dd, f1);
  845. Cudd_RecursiveDerefZdd(dd, f0);
  846. Cudd_RecursiveDerefZdd(dd, fd);
  847. return(NULL);
  848. }
  849. Cudd_Ref(g1);
  850. Cudd_Ref(g0);
  851. Cudd_Ref(gd);
  852. q = g;
  853. if (g0 != zero) {
  854. q = cuddZddWeakDivF(dd, f0, g0);
  855. if (q == NULL) {
  856. Cudd_RecursiveDerefZdd(dd, f1);
  857. Cudd_RecursiveDerefZdd(dd, f0);
  858. Cudd_RecursiveDerefZdd(dd, fd);
  859. Cudd_RecursiveDerefZdd(dd, g1);
  860. Cudd_RecursiveDerefZdd(dd, g0);
  861. Cudd_RecursiveDerefZdd(dd, gd);
  862. return(NULL);
  863. }
  864. Cudd_Ref(q);
  865. }
  866. else
  867. Cudd_Ref(q);
  868. Cudd_RecursiveDerefZdd(dd, f0);
  869. Cudd_RecursiveDerefZdd(dd, g0);
  870. if (q == zero) {
  871. Cudd_RecursiveDerefZdd(dd, f1);
  872. Cudd_RecursiveDerefZdd(dd, g1);
  873. Cudd_RecursiveDerefZdd(dd, fd);
  874. Cudd_RecursiveDerefZdd(dd, gd);
  875. cuddCacheInsert2(dd, cuddZddWeakDivF, f, g, zero);
  876. Cudd_Deref(q);
  877. return(zero);
  878. }
  879. if (g1 != zero) {
  880. Cudd_RecursiveDerefZdd(dd, q);
  881. tmp = cuddZddWeakDivF(dd, f1, g1);
  882. if (tmp == NULL) {
  883. Cudd_RecursiveDerefZdd(dd, f1);
  884. Cudd_RecursiveDerefZdd(dd, g1);
  885. Cudd_RecursiveDerefZdd(dd, fd);
  886. Cudd_RecursiveDerefZdd(dd, gd);
  887. return(NULL);
  888. }
  889. Cudd_Ref(tmp);
  890. Cudd_RecursiveDerefZdd(dd, f1);
  891. Cudd_RecursiveDerefZdd(dd, g1);
  892. if (q == g)
  893. q = tmp;
  894. else {
  895. q = cuddZddIntersect(dd, q, tmp);
  896. if (q == NULL) {
  897. Cudd_RecursiveDerefZdd(dd, fd);
  898. Cudd_RecursiveDerefZdd(dd, gd);
  899. return(NULL);
  900. }
  901. Cudd_Ref(q);
  902. Cudd_RecursiveDerefZdd(dd, tmp);
  903. }
  904. }
  905. else {
  906. Cudd_RecursiveDerefZdd(dd, f1);
  907. Cudd_RecursiveDerefZdd(dd, g1);
  908. }
  909. if (q == zero) {
  910. Cudd_RecursiveDerefZdd(dd, fd);
  911. Cudd_RecursiveDerefZdd(dd, gd);
  912. cuddCacheInsert2(dd, cuddZddWeakDivF, f, g, zero);
  913. Cudd_Deref(q);
  914. return(zero);
  915. }
  916. if (gd != zero) {
  917. Cudd_RecursiveDerefZdd(dd, q);
  918. tmp = cuddZddWeakDivF(dd, fd, gd);
  919. if (tmp == NULL) {
  920. Cudd_RecursiveDerefZdd(dd, fd);
  921. Cudd_RecursiveDerefZdd(dd, gd);
  922. return(NULL);
  923. }
  924. Cudd_Ref(tmp);
  925. Cudd_RecursiveDerefZdd(dd, fd);
  926. Cudd_RecursiveDerefZdd(dd, gd);
  927. if (q == g)
  928. q = tmp;
  929. else {
  930. q = cuddZddIntersect(dd, q, tmp);
  931. if (q == NULL) {
  932. Cudd_RecursiveDerefZdd(dd, tmp);
  933. return(NULL);
  934. }
  935. Cudd_Ref(q);
  936. Cudd_RecursiveDerefZdd(dd, tmp);
  937. }
  938. }
  939. else {
  940. Cudd_RecursiveDerefZdd(dd, fd);
  941. Cudd_RecursiveDerefZdd(dd, gd);
  942. }
  943. cuddCacheInsert2(dd, cuddZddWeakDivF, f, g, q);
  944. Cudd_Deref(q);
  945. return(q);
  946. } /* end of cuddZddWeakDivF */
  947. /**
  948. @brief Performs the recursive step of Cudd_zddDivide.
  949. @sideeffect None
  950. @see Cudd_zddDivide
  951. */
  952. DdNode *
  953. cuddZddDivide(
  954. DdManager * dd,
  955. DdNode * f,
  956. DdNode * g)
  957. {
  958. int v;
  959. DdNode *one = DD_ONE(dd);
  960. DdNode *zero = DD_ZERO(dd);
  961. DdNode *f0, *f1, *g0, *g1;
  962. DdNode *q, *r, *tmp;
  963. int flag;
  964. statLine(dd);
  965. if (g == one)
  966. return(f);
  967. if (f == zero || f == one)
  968. return(zero);
  969. if (f == g)
  970. return(one);
  971. /* Check cache. */
  972. r = cuddCacheLookup2Zdd(dd, cuddZddDivide, f, g);
  973. if (r)
  974. return(r);
  975. v = (int) g->index;
  976. flag = cuddZddGetCofactors2(dd, f, v, &f1, &f0);
  977. if (flag == 1)
  978. return(NULL);
  979. Cudd_Ref(f1);
  980. Cudd_Ref(f0);
  981. flag = cuddZddGetCofactors2(dd, g, v, &g1, &g0); /* g1 != zero */
  982. if (flag == 1) {
  983. Cudd_RecursiveDerefZdd(dd, f1);
  984. Cudd_RecursiveDerefZdd(dd, f0);
  985. return(NULL);
  986. }
  987. Cudd_Ref(g1);
  988. Cudd_Ref(g0);
  989. r = cuddZddDivide(dd, f1, g1);
  990. if (r == NULL) {
  991. Cudd_RecursiveDerefZdd(dd, f1);
  992. Cudd_RecursiveDerefZdd(dd, f0);
  993. Cudd_RecursiveDerefZdd(dd, g1);
  994. Cudd_RecursiveDerefZdd(dd, g0);
  995. return(NULL);
  996. }
  997. Cudd_Ref(r);
  998. if (r != zero && g0 != zero) {
  999. tmp = r;
  1000. q = cuddZddDivide(dd, f0, g0);
  1001. if (q == NULL) {
  1002. Cudd_RecursiveDerefZdd(dd, f1);
  1003. Cudd_RecursiveDerefZdd(dd, f0);
  1004. Cudd_RecursiveDerefZdd(dd, g1);
  1005. Cudd_RecursiveDerefZdd(dd, g0);
  1006. return(NULL);
  1007. }
  1008. Cudd_Ref(q);
  1009. r = cuddZddIntersect(dd, r, q);
  1010. if (r == NULL) {
  1011. Cudd_RecursiveDerefZdd(dd, f1);
  1012. Cudd_RecursiveDerefZdd(dd, f0);
  1013. Cudd_RecursiveDerefZdd(dd, g1);
  1014. Cudd_RecursiveDerefZdd(dd, g0);
  1015. Cudd_RecursiveDerefZdd(dd, q);
  1016. return(NULL);
  1017. }
  1018. Cudd_Ref(r);
  1019. Cudd_RecursiveDerefZdd(dd, q);
  1020. Cudd_RecursiveDerefZdd(dd, tmp);
  1021. }
  1022. Cudd_RecursiveDerefZdd(dd, f1);
  1023. Cudd_RecursiveDerefZdd(dd, f0);
  1024. Cudd_RecursiveDerefZdd(dd, g1);
  1025. Cudd_RecursiveDerefZdd(dd, g0);
  1026. cuddCacheInsert2(dd, cuddZddDivide, f, g, r);
  1027. Cudd_Deref(r);
  1028. return(r);
  1029. } /* end of cuddZddDivide */
  1030. /**
  1031. @brief Performs the recursive step of Cudd_zddDivideF.
  1032. @sideeffect None
  1033. @see Cudd_zddDivideF
  1034. */
  1035. DdNode *
  1036. cuddZddDivideF(
  1037. DdManager * dd,
  1038. DdNode * f,
  1039. DdNode * g)
  1040. {
  1041. int v;
  1042. DdNode *one = DD_ONE(dd);
  1043. DdNode *zero = DD_ZERO(dd);
  1044. DdNode *f0, *f1, *g0, *g1;
  1045. DdNode *q, *r, *tmp;
  1046. int flag;
  1047. statLine(dd);
  1048. if (g == one)
  1049. return(f);
  1050. if (f == zero || f == one)
  1051. return(zero);
  1052. if (f == g)
  1053. return(one);
  1054. /* Check cache. */
  1055. r = cuddCacheLookup2Zdd(dd, cuddZddDivideF, f, g);
  1056. if (r)
  1057. return(r);
  1058. v = (int) g->index;
  1059. flag = cuddZddGetCofactors2(dd, f, v, &f1, &f0);
  1060. if (flag == 1)
  1061. return(NULL);
  1062. Cudd_Ref(f1);
  1063. Cudd_Ref(f0);
  1064. flag = cuddZddGetCofactors2(dd, g, v, &g1, &g0); /* g1 != zero */
  1065. if (flag == 1) {
  1066. Cudd_RecursiveDerefZdd(dd, f1);
  1067. Cudd_RecursiveDerefZdd(dd, f0);
  1068. return(NULL);
  1069. }
  1070. Cudd_Ref(g1);
  1071. Cudd_Ref(g0);
  1072. r = cuddZddDivideF(dd, f1, g1);
  1073. if (r == NULL) {
  1074. Cudd_RecursiveDerefZdd(dd, f1);
  1075. Cudd_RecursiveDerefZdd(dd, f0);
  1076. Cudd_RecursiveDerefZdd(dd, g1);
  1077. Cudd_RecursiveDerefZdd(dd, g0);
  1078. return(NULL);
  1079. }
  1080. Cudd_Ref(r);
  1081. if (r != zero && g0 != zero) {
  1082. tmp = r;
  1083. q = cuddZddDivideF(dd, f0, g0);
  1084. if (q == NULL) {
  1085. Cudd_RecursiveDerefZdd(dd, f1);
  1086. Cudd_RecursiveDerefZdd(dd, f0);
  1087. Cudd_RecursiveDerefZdd(dd, g1);
  1088. Cudd_RecursiveDerefZdd(dd, g0);
  1089. return(NULL);
  1090. }
  1091. Cudd_Ref(q);
  1092. r = cuddZddIntersect(dd, r, q);
  1093. if (r == NULL) {
  1094. Cudd_RecursiveDerefZdd(dd, f1);
  1095. Cudd_RecursiveDerefZdd(dd, f0);
  1096. Cudd_RecursiveDerefZdd(dd, g1);
  1097. Cudd_RecursiveDerefZdd(dd, g0);
  1098. Cudd_RecursiveDerefZdd(dd, q);
  1099. return(NULL);
  1100. }
  1101. Cudd_Ref(r);
  1102. Cudd_RecursiveDerefZdd(dd, q);
  1103. Cudd_RecursiveDerefZdd(dd, tmp);
  1104. }
  1105. Cudd_RecursiveDerefZdd(dd, f1);
  1106. Cudd_RecursiveDerefZdd(dd, f0);
  1107. Cudd_RecursiveDerefZdd(dd, g1);
  1108. Cudd_RecursiveDerefZdd(dd, g0);
  1109. cuddCacheInsert2(dd, cuddZddDivideF, f, g, r);
  1110. Cudd_Deref(r);
  1111. return(r);
  1112. } /* end of cuddZddDivideF */
  1113. /**
  1114. @brief Computes the three-way decomposition of f w.r.t. v.
  1115. @details Computes the three-way decomposition of function f
  1116. (represented by a %ZDD) with respect to variable v.
  1117. @return 0 if successful; 1 otherwise.
  1118. @sideeffect The results are returned in f1, f0, and fd.
  1119. @see cuddZddGetCofactors2
  1120. */
  1121. int
  1122. cuddZddGetCofactors3(
  1123. DdManager * dd,
  1124. DdNode * f,
  1125. int v,
  1126. DdNode ** f1,
  1127. DdNode ** f0,
  1128. DdNode ** fd)
  1129. {
  1130. DdNode *pc, *nc;
  1131. DdNode *zero = DD_ZERO(dd);
  1132. int top, hv, ht, pv, nv;
  1133. int level;
  1134. top = dd->permZ[f->index];
  1135. level = dd->permZ[v];
  1136. hv = level >> 1;
  1137. ht = top >> 1;
  1138. if (hv < ht) {
  1139. *f1 = zero;
  1140. *f0 = zero;
  1141. *fd = f;
  1142. }
  1143. else {
  1144. pv = cuddZddGetPosVarIndex(dd, v);
  1145. nv = cuddZddGetNegVarIndex(dd, v);
  1146. /* not to create intermediate ZDD node */
  1147. if (cuddZddGetPosVarLevel(dd, v) < cuddZddGetNegVarLevel(dd, v)) {
  1148. pc = cuddZddSubset1(dd, f, pv);
  1149. if (pc == NULL)
  1150. return(1);
  1151. Cudd_Ref(pc);
  1152. nc = cuddZddSubset0(dd, f, pv);
  1153. if (nc == NULL) {
  1154. Cudd_RecursiveDerefZdd(dd, pc);
  1155. return(1);
  1156. }
  1157. Cudd_Ref(nc);
  1158. *f1 = cuddZddSubset0(dd, pc, nv);
  1159. if (*f1 == NULL) {
  1160. Cudd_RecursiveDerefZdd(dd, pc);
  1161. Cudd_RecursiveDerefZdd(dd, nc);
  1162. return(1);
  1163. }
  1164. Cudd_Ref(*f1);
  1165. *f0 = cuddZddSubset1(dd, nc, nv);
  1166. if (*f0 == NULL) {
  1167. Cudd_RecursiveDerefZdd(dd, pc);
  1168. Cudd_RecursiveDerefZdd(dd, nc);
  1169. Cudd_RecursiveDerefZdd(dd, *f1);
  1170. return(1);
  1171. }
  1172. Cudd_Ref(*f0);
  1173. *fd = cuddZddSubset0(dd, nc, nv);
  1174. if (*fd == NULL) {
  1175. Cudd_RecursiveDerefZdd(dd, pc);
  1176. Cudd_RecursiveDerefZdd(dd, nc);
  1177. Cudd_RecursiveDerefZdd(dd, *f1);
  1178. Cudd_RecursiveDerefZdd(dd, *f0);
  1179. return(1);
  1180. }
  1181. Cudd_Ref(*fd);
  1182. } else {
  1183. pc = cuddZddSubset1(dd, f, nv);
  1184. if (pc == NULL)
  1185. return(1);
  1186. Cudd_Ref(pc);
  1187. nc = cuddZddSubset0(dd, f, nv);
  1188. if (nc == NULL) {
  1189. Cudd_RecursiveDerefZdd(dd, pc);
  1190. return(1);
  1191. }
  1192. Cudd_Ref(nc);
  1193. *f0 = cuddZddSubset0(dd, pc, pv);
  1194. if (*f0 == NULL) {
  1195. Cudd_RecursiveDerefZdd(dd, pc);
  1196. Cudd_RecursiveDerefZdd(dd, nc);
  1197. return(1);
  1198. }
  1199. Cudd_Ref(*f0);
  1200. *f1 = cuddZddSubset1(dd, nc, pv);
  1201. if (*f1 == NULL) {
  1202. Cudd_RecursiveDerefZdd(dd, pc);
  1203. Cudd_RecursiveDerefZdd(dd, nc);
  1204. Cudd_RecursiveDerefZdd(dd, *f0);
  1205. return(1);
  1206. }
  1207. Cudd_Ref(*f1);
  1208. *fd = cuddZddSubset0(dd, nc, pv);
  1209. if (*fd == NULL) {
  1210. Cudd_RecursiveDerefZdd(dd, pc);
  1211. Cudd_RecursiveDerefZdd(dd, nc);
  1212. Cudd_RecursiveDerefZdd(dd, *f1);
  1213. Cudd_RecursiveDerefZdd(dd, *f0);
  1214. return(1);
  1215. }
  1216. Cudd_Ref(*fd);
  1217. }
  1218. Cudd_RecursiveDerefZdd(dd, pc);
  1219. Cudd_RecursiveDerefZdd(dd, nc);
  1220. Cudd_Deref(*f1);
  1221. Cudd_Deref(*f0);
  1222. Cudd_Deref(*fd);
  1223. }
  1224. return(0);
  1225. } /* end of cuddZddGetCofactors3 */
  1226. /**
  1227. @brief Computes the two-way decomposition of f w.r.t. v.
  1228. @sideeffect The results are returned in f1 and f0.
  1229. @see cuddZddGetCofactors3
  1230. */
  1231. int
  1232. cuddZddGetCofactors2(
  1233. DdManager * dd,
  1234. DdNode * f,
  1235. int v,
  1236. DdNode ** f1,
  1237. DdNode ** f0)
  1238. {
  1239. *f1 = cuddZddSubset1(dd, f, v);
  1240. if (*f1 == NULL)
  1241. return(1);
  1242. *f0 = cuddZddSubset0(dd, f, v);
  1243. if (*f0 == NULL) {
  1244. Cudd_RecursiveDerefZdd(dd, *f1);
  1245. return(1);
  1246. }
  1247. return(0);
  1248. } /* end of cuddZddGetCofactors2 */
  1249. /**
  1250. @brief Computes a complement of a %ZDD node.
  1251. @details So far, since we couldn't find a direct way to get the
  1252. complement of a %ZDD cover, we first convert a %ZDD cover to a %BDD,
  1253. then make the complement of the %ZDD cover from the complement of the
  1254. %BDD node by using ISOP. The result depends on current variable order.
  1255. */
  1256. DdNode *
  1257. cuddZddComplement(
  1258. DdManager * dd,
  1259. DdNode *node)
  1260. {
  1261. DdNode *b, *isop, *zdd_I;
  1262. /* Check cache */
  1263. zdd_I = cuddCacheLookup1Zdd(dd, cuddZddComplement, node);
  1264. if (zdd_I)
  1265. return(zdd_I);
  1266. b = cuddMakeBddFromZddCover(dd, node);
  1267. if (!b)
  1268. return(NULL);
  1269. cuddRef(b);
  1270. isop = cuddZddIsop(dd, Cudd_Not(b), Cudd_Not(b), &zdd_I);
  1271. if (!isop) {
  1272. Cudd_RecursiveDeref(dd, b);
  1273. return(NULL);
  1274. }
  1275. cuddRef(isop);
  1276. cuddRef(zdd_I);
  1277. Cudd_RecursiveDeref(dd, b);
  1278. Cudd_RecursiveDeref(dd, isop);
  1279. cuddCacheInsert1(dd, cuddZddComplement, node, zdd_I);
  1280. cuddDeref(zdd_I);
  1281. return(zdd_I);
  1282. } /* end of cuddZddComplement */
  1283. /**
  1284. @brief Returns the index of positive %ZDD variable.
  1285. */
  1286. int
  1287. cuddZddGetPosVarIndex(
  1288. DdManager * dd,
  1289. int index)
  1290. {
  1291. (void) dd; /* avoid warning */
  1292. int pv = index & ~0x1;
  1293. return(pv);
  1294. } /* end of cuddZddGetPosVarIndex */
  1295. /**
  1296. @brief Returns the index of negative %ZDD variable.
  1297. */
  1298. int
  1299. cuddZddGetNegVarIndex(
  1300. DdManager * dd,
  1301. int index)
  1302. {
  1303. (void) dd; /* avoid warning */
  1304. int nv = index | 0x1;
  1305. return(nv);
  1306. } /* end of cuddZddGetPosVarIndex */
  1307. /**
  1308. @brief Returns the level of positive %ZDD variable.
  1309. */
  1310. int
  1311. cuddZddGetPosVarLevel(
  1312. DdManager * dd,
  1313. int index)
  1314. {
  1315. int pv = cuddZddGetPosVarIndex(dd, index);
  1316. return(dd->permZ[pv]);
  1317. } /* end of cuddZddGetPosVarLevel */
  1318. /**
  1319. @brief Returns the level of negative %ZDD variable.
  1320. */
  1321. int
  1322. cuddZddGetNegVarLevel(
  1323. DdManager * dd,
  1324. int index)
  1325. {
  1326. int nv = cuddZddGetNegVarIndex(dd, index);
  1327. return(dd->permZ[nv]);
  1328. } /* end of cuddZddGetNegVarLevel */