VIS

src/puresat/puresatAig.c

Go to the documentation of this file.
00001 
00048 #include "maigInt.h"
00049 #include "baig.h"
00050 #include "ntk.h"
00051 #include "puresatInt.h"
00052 /*---------------------------------------------------------------------------*/
00053 /* Constant declarations                                                     */
00054 /*---------------------------------------------------------------------------*/
00055 
00056 /*---------------------------------------------------------------------------*/
00057 /* Type declarations                                                         */
00058 /*---------------------------------------------------------------------------*/
00059 
00060 
00061 /*---------------------------------------------------------------------------*/
00062 /* Structure declarations                                                    */
00063 /*---------------------------------------------------------------------------*/
00064 
00065 
00066 /*---------------------------------------------------------------------------*/
00067 /* Variable declarations                                                     */
00068 /*---------------------------------------------------------------------------*/
00069 
00070 /*---------------------------------------------------------------------------*/
00071 /* Macro declarations                                                        */
00072 /*---------------------------------------------------------------------------*/
00073 
00076 /*---------------------------------------------------------------------------*/
00077 /* Static function prototypes                                                */
00078 /*---------------------------------------------------------------------------*/
00079 
00080 
00083 /*---------------------------------------------------------------------------*/
00084 /* Definition of exported functions                                          */
00085 /*---------------------------------------------------------------------------*/
00086 
00087 
00088 /*---------------------------------------------------------------------------*/
00089 /* Definition of internal functions                                          */
00090 /*---------------------------------------------------------------------------*/
00091 
00104 void
00105 PureSat_unconnectOutput(
00106    bAig_Manager_t *manager,
00107    bAigEdge_t from,
00108    bAigEdge_t to)
00109 {
00110    bAigEdge_t cur, *pfan, *newfan;
00111    int i, nfan,find=0;
00112 
00113   from = bAig_NonInvertedEdge(from);
00114   to = bAig_NonInvertedEdge(to);
00115 
00116   pfan = (bAigEdge_t *)fanout(from);
00117   nfan = nFanout(from);
00118   newfan = (bAigEdge_t *)malloc(sizeof(bAigEdge_t)*(nfan));
00119   for(i=0; i<nfan; i++) {
00120     cur = pfan[i];
00121     cur = cur >> 1;
00122     cur = bAig_NonInvertedEdge(cur);
00123     if(cur == to) {
00124       find = 1;
00125       memcpy(newfan, pfan, sizeof(bAigEdge_t)*i);
00126       memcpy(&(newfan[i]), &(pfan[i+1]), sizeof(bAigEdge_t)*(nfan-i-1));
00127       newfan[nfan-1] = 0;
00128 
00129       fanout(from) = (bAigEdge_t)newfan;
00130 
00131 
00132       free(pfan);
00133       nFanout(from) = nfan-1;
00134       break;
00135     }
00136   }
00137   assert(find);
00138 }
00139 
00140 
00154 void
00155 PureSat_connectOutput(
00156    bAig_Manager_t *manager,
00157    bAigEdge_t from,
00158    bAigEdge_t to,
00159    int inputIndex)
00160 {
00161   bAigEdge_t *pfan;
00162   bAigEdge_t nfan;
00163 
00164   to = bAig_NonInvertedEdge(to);
00165   pfan = (bAigEdge_t *)fanout(from);
00166   nfan = nFanout(from);
00167   if(nfan == 0) pfan = malloc((sizeof(bAigEdge_t)*2));
00168   else          pfan = realloc(pfan, sizeof(bAigEdge_t)*(nfan+2));
00169   to += bAig_IsInverted(from);
00170   to = to << 1;
00171   to += inputIndex;
00172   pfan[nfan++] = to;
00173   pfan[nfan] = 0;
00174   fanout(from) = (bAigEdge_t)pfan;
00175   nFanout(from) = nfan;
00176 }
00177 
00178 
00191 bAigEdge_t
00192 PureSat_HashTableLookup(
00193   bAig_Manager_t *manager,
00194   bAigEdge_t  node1,
00195   bAigEdge_t  node2)
00196 {
00197   bAigEdge_t key = HashTableFunction(node1, node2);
00198   bAigEdge_t node;
00199 
00200   node = manager->HashTableArray[manager->class_][key];
00201   if  (node == bAig_NULL) {
00202     return bAig_NULL;
00203   }
00204   else{
00205     while ( (rightChild(bAig_NonInvertedEdge(node)) != node2) ||
00206             (leftChild(bAig_NonInvertedEdge(node))  != node1)) {
00207 
00208       if (next(bAig_NonInvertedEdge(node)) == bAig_NULL){
00209         return(bAig_NULL);
00210       }
00211       node = next(bAig_NonInvertedEdge(node)); /* Get the next Node */
00212     } /* While loop */
00213     return(node);
00214 
00215   } /* If Then Else */
00216 
00217 } /* End of HashTableLookup() */
00218 
00219 
00232 int
00233 PureSat_HashTableAdd(
00234   bAig_Manager_t   *manager,
00235   bAigEdge_t  nodeIndexParent,
00236   bAigEdge_t  nodeIndex1,
00237   bAigEdge_t  nodeIndex2)
00238 {
00239   bAigEdge_t key = HashTableFunction(nodeIndex1, nodeIndex2);
00240   bAigEdge_t nodeIndex;
00241   bAigEdge_t node;
00242 
00243   nodeIndex = manager->HashTableArray[manager->class_][key];
00244   if  (nodeIndex == bAig_NULL) {
00245     manager->HashTableArray[manager->class_][key] = nodeIndexParent;
00246     return TRUE;
00247   }
00248   else{
00249     node = nodeIndex;
00250     nodeIndex = next(bAig_NonInvertedEdge(nodeIndex));  /* Get the Node */
00251     while (nodeIndex != bAig_NULL) {
00252       node = nodeIndex;
00253       nodeIndex = next(bAig_NonInvertedEdge(nodeIndex));
00254     }
00255     next(bAig_NonInvertedEdge(node)) = nodeIndexParent;
00256     return TRUE;
00257   }
00258 
00259 }
00260 
00261 
00262 
00275 bAigEdge_t
00276 PureSat_CreateAndNode(
00277    bAig_Manager_t  *manager,
00278    bAigEdge_t node1,
00279    bAigEdge_t node2)
00280 {
00281 
00282   bAigEdge_t varIndex;
00283   char       *name = NIL(char);
00284   char       *node1Str = util_inttostr(node1);
00285   char       *node2Str = util_inttostr(node2);
00286   long class_ = manager->class_;
00287 
00288   name = util_strcat4("Nd", node1Str,"_", node2Str);
00289   while (st_lookup(manager->SymbolTableArray[class_], name, &varIndex)){
00290     fprintf(vis_stdout, "Find redundant node at %ld %ld\n", node1, node2);
00291     name = util_strcat3(name, node1Str, node2Str);
00292   }
00293   FREE(node1Str);
00294   FREE(node2Str);
00295   varIndex = bAig_CreateNode(manager, node1, node2);
00296   if (varIndex == bAig_NULL){
00297     FREE(name);
00298     return (varIndex);
00299   }
00300   /* Insert the varaible in the Symbol Table */
00301   st_insert(manager->SymbolTableArray[class_], name, (char*) (long) varIndex);
00302   manager->nameList[bAigNodeID(varIndex)] = name;
00303 
00304   return(varIndex);
00305 
00306 }
00307 
00308 
00321 bAigEdge_t
00322 PureSat_And2(
00323    bAig_Manager_t *manager,
00324    bAigEdge_t nodeIndex1,
00325    bAigEdge_t nodeIndex2)
00326 {
00327   bAigEdge_t newNodeIndex;
00328 
00329     newNodeIndex = PureSat_CreateAndNode(manager, nodeIndex1, nodeIndex2) ;
00330 
00331     PureSat_HashTableAdd(manager, newNodeIndex, nodeIndex1, nodeIndex2);
00332     PureSat_connectOutput(manager, nodeIndex1, newNodeIndex, 0);
00333     PureSat_connectOutput(manager, nodeIndex2, newNodeIndex, 1);
00334 
00335   return newNodeIndex;
00336 
00337 }
00338 
00339 
00352 bAigEdge_t
00353 PureSat_And3(
00354            bAig_Manager_t *manager,
00355            bAigEdge_t l,
00356            bAigEdge_t r)
00357 {
00358   int caseIndex, caseSig;
00359   bAigEdge_t rl, rr;
00360 
00361   rl = leftChild(r);
00362   rr = rightChild(r);
00363 
00364   caseIndex = 0; /* (a)(b c) */
00365   if(bAigCompareNode(l, rl)) {
00366     caseIndex = 1; /* (a)(a b) */
00367   }
00368   else if(bAigCompareNode(l, rr)) {
00369     caseIndex = 2; /* (a)(b a) */
00370   }
00371 
00372   caseSig = 0;
00373   if(bAig_IsInverted(l))  caseSig += 8;
00374   if(bAig_IsInverted(rl)) caseSig += 4;
00375   if(bAig_IsInverted(rr)) caseSig += 2;
00376   if(bAig_IsInverted(r))  caseSig += 1;
00377   if(caseIndex == 0) {
00378     return(PureSat_And2(manager, l, r));
00379   }
00380   else if(caseIndex == 1) {
00381     switch(caseSig) {
00382         case 2 :
00383         case 0 :
00384         case 14 :
00385         case 12 :
00386       return(r);
00387         case 10 :
00388         case 8 :
00389         case 6 :
00390         case 4 :
00391       return(bAig_Zero);
00392         case 3 :
00393         case 1 :
00394         case 15 :
00395         case 13 :
00396       return(PureSat_And(manager, rl, bAig_Not(rr)));
00397         case 11 :
00398         case 9 :
00399         case 7 :
00400         case 5 :
00401       return(l);
00402     }
00403   }
00404   else if(caseIndex == 2) {
00405     switch(caseSig) {
00406         case 4 :
00407         case 0 :
00408         case 14 :
00409         case 10 :
00410       return(r);
00411         case 12 :
00412         case 8 :
00413         case 6 :
00414         case 2 :
00415       return(bAig_Zero);
00416         case 5 :
00417         case 1 :
00418         case 15 :
00419         case 11 :
00420       return(PureSat_And(manager, bAig_Not(rl), rr));
00421         case 13 :
00422         case 9 :
00423         case 7 :
00424         case 3 :
00425       return(l);
00426     }
00427   }
00428   return(0);
00429 }
00430 
00431 
00444 bAigEdge_t
00445 PureSat_And4(
00446            bAig_Manager_t *manager,
00447            bAigEdge_t l,
00448            bAigEdge_t r)
00449 {
00450   int caseIndex, caseSig;
00451   bAigEdge_t ll, lr, rl, rr;
00452   bAigEdge_t t1, t2;
00453 
00454   ll = leftChild(l);
00455   lr = rightChild(l);
00456   rl = leftChild(r);
00457   rr = rightChild(r);
00458 
00459   if(bAigCompareNode(l, rl) ||
00460      bAigCompareNode(l, rr)) {
00461     return(PureSat_And3(manager, l, r));
00462   }
00463   else if(bAigCompareNode(r, ll) ||
00464      bAigCompareNode(r, lr)) {
00465     return(PureSat_And3(manager, r, l));
00466   }
00467 
00468   if(ll > lr+1) bAigSwap(ll, lr);
00469   if(rl > rr+1) bAigSwap(rl, rr);
00470 
00471   caseIndex = 0; /* (a b)(c d) */
00472   if(bAigCompareNode(ll, rl)) {
00473     if(bAigCompareNode(lr, rr)) {
00474       caseIndex = 4; /* (a b) (a b) */
00475     }
00476     else {
00477       caseIndex = 1; /* (a b) (a c) */
00478       if(lr > rr+1) {
00479         bAigSwap(ll, rl);
00480         bAigSwap(lr, rr);
00481         bAigSwap(l, r);
00482       }
00483     }
00484   }
00485   else if(bAigCompareNode(lr, rl)) {
00486     caseIndex = 2; /* (b a)(a c) */
00487   }
00488   else if(bAigCompareNode(lr, rr)) {
00489     caseIndex = 3; /* (b a)(c a) */
00490     if(ll > rl+1) {
00491       bAigSwap(ll, rl);
00492       bAigSwap(lr, rr);
00493       bAigSwap(l, r);
00494     }
00495   }
00496   else if(bAigCompareNode(ll, rr)) {
00497     /* (a b)(c a)  */
00498     bAigSwap(ll, rl);
00499     bAigSwap(lr, rr);
00500     bAigSwap(l, r);
00501     caseIndex = 2; /* (c a )(a b) because of c < b */
00502   }
00503 
00504   caseSig = 0;
00505   if(bAig_IsInverted(ll)) caseSig += 32;
00506   if(bAig_IsInverted(lr)) caseSig += 16;
00507   if(bAig_IsInverted(l))  caseSig += 8;
00508   if(bAig_IsInverted(rl)) caseSig += 4;
00509   if(bAig_IsInverted(rr)) caseSig += 2;
00510   if(bAig_IsInverted(r))  caseSig += 1;
00511 
00512   if(caseIndex == 0) {
00513     return(PureSat_And2(manager, l, r));
00514   }
00515   else if(caseIndex == 1) {
00516     switch(caseSig) {
00517         case 19 :
00518         case 17 :
00519         case 3 :
00520         case 1 :
00521         case 55 :
00522         case 53 :
00523         case 39 :
00524         case 37 :
00525       t1 = PureSat_And(manager, lr, bAig_Not(rr));
00526       t2 = PureSat_And(manager, ll, t1);
00527       return(t2);
00528         case 18 :
00529         case 16 :
00530         case 2 :
00531         case 0 :
00532         case 54 :
00533         case 52 :
00534         case 38 :
00535         case 36 :
00536       t1 = PureSat_And(manager, lr, rr);
00537       t2 = PureSat_And(manager, ll, t1);
00538       return(t2);
00539         case 26 :
00540         case 24 :
00541         case 10 :
00542         case 8 :
00543         case 62 :
00544         case 60 :
00545         case 46 :
00546         case 44 :
00547       t1 = PureSat_And(manager, bAig_Not(lr), rr);
00548       t2 = PureSat_And(manager, ll, t1);
00549       return(t2);
00550         case 61 :
00551         case 27 :
00552         case 25 :
00553         case 11 :
00554         case 63 :
00555         case 47 :
00556         case 9 :
00557         case 45 :
00558       t1 = PureSat_And(manager, bAig_Not(lr), bAig_Not(rr));
00559       t2 = PureSat_Or(manager, bAig_Not(ll), t1);
00560       return(t2);
00561         case 23 :
00562         case 21 :
00563         case 7 :
00564         case 5 :
00565         case 51 :
00566         case 49 :
00567         case 35 :
00568         case 33 :
00569       return(l);
00570         case 30 :
00571         case 28 :
00572         case 14 :
00573         case 12 :
00574         case 58 :
00575         case 56 :
00576         case 42 :
00577         case 40 :
00578       return(r);
00579         case 22 :
00580         case 20 :
00581         case 6 :
00582         case 4 :
00583         case 50 :
00584         case 48 :
00585         case 34 :
00586         case 32 :
00587       return(bAig_Zero);
00588         case 31 :
00589         case 29 :
00590         case 15 :
00591         case 13 :
00592         case 59 :
00593         case 57 :
00594         case 43 :
00595         case 41 :
00596       t1 = PureSat_And2(manager, l, r);
00597       return(t1);
00598     }
00599   }
00600   else if(caseIndex == 2) {
00601     switch(caseSig) {
00602         case 35 :
00603         case 33 :
00604         case 3 :
00605         case 1 :
00606         case 55 :
00607         case 53 :
00608         case 23 :
00609         case 21 :
00610       t1 = PureSat_And(manager, lr, bAig_Not(rr));
00611       t2 = PureSat_And(manager, ll, t1);
00612       return(t2);
00613         case 34 :
00614         case 32 :
00615         case 2 :
00616         case 0 :
00617         case 54 :
00618         case 52 :
00619         case 22 :
00620         case 20 :
00621       t1 = PureSat_And(manager, lr, rr);
00622       t2 = PureSat_And(manager, ll, t1);
00623       return(t2);
00624         case 42 :
00625         case 40 :
00626         case 10 :
00627         case 8 :
00628         case 62 :
00629         case 60 :
00630         case 30 :
00631         case 28 :
00632       t1 = PureSat_And(manager, lr, rr);
00633       t2 = PureSat_And(manager, bAig_Not(ll), t1);
00634       return(t2);
00635         case 43 :
00636         case 41 :
00637         case 11 :
00638         case 9 :
00639         case 63 :
00640         case 61 :
00641         case 31 :
00642         case 29 :
00643       t1 = PureSat_And(manager, bAig_Not(ll), bAig_Not(rr));
00644       t2 = PureSat_Or(manager, bAig_Not(lr), t1);
00645       return(t2);
00646         case 39 :
00647         case 37 :
00648         case 7 :
00649         case 5 :
00650         case 51 :
00651         case 49 :
00652         case 19 :
00653         case 17 :
00654       return(l);
00655         case 46 :
00656         case 44 :
00657         case 14 :
00658         case 12 :
00659         case 58 :
00660         case 56 :
00661         case 26 :
00662         case 24 :
00663       return(r);
00664         case 38 :
00665         case 36 :
00666         case 6 :
00667         case 4 :
00668         case 50 :
00669         case 48 :
00670         case 18 :
00671         case 16 :
00672       return(bAig_Zero);
00673         case 45 :
00674         case 15 :
00675         case 13 :
00676         case 59 :
00677         case 57 :
00678         case 47 :
00679         case 27 :
00680         case 25 :
00681       t1 = PureSat_And2(manager, l, r);
00682       return(t1);
00683     }
00684   }
00685   else if(caseIndex == 3) {
00686     switch(caseSig) {
00687         case 37 :
00688         case 33 :
00689         case 5 :
00690         case 1 :
00691         case 55 :
00692         case 51 :
00693         case 23 :
00694         case 19 :
00695       t1 = PureSat_And(manager, bAig_Not(rl), lr);
00696       t2 = PureSat_And(manager, ll, t1);
00697       return(t2);
00698         case 36 :
00699         case 32 :
00700         case 4 :
00701         case 0 :
00702         case 54 :
00703         case 50 :
00704         case 22 :
00705         case 18 :
00706       t1 = PureSat_And(manager, rl, lr);
00707       t2 = PureSat_And(manager, ll, t1);
00708       return(t2);
00709         case 44 :
00710         case 40 :
00711         case 12 :
00712         case 8 :
00713         case 62 :
00714         case 58 :
00715         case 30 :
00716         case 26 :
00717       t1 = PureSat_And(manager, rl, lr);
00718       t2 = PureSat_And(manager, bAig_Not(ll), t1);
00719       return(t2);
00720         case 45 :
00721         case 41 :
00722         case 13 :
00723         case 9 :
00724         case 63 :
00725         case 59 :
00726         case 31 :
00727         case 27 :
00728       t1 = PureSat_And(manager, bAig_Not(ll), bAig_Not(rl));
00729       t2 = PureSat_Or(manager, bAig_Not(lr), t1);
00730       return(t2);
00731         case 39 :
00732         case 35 :
00733         case 7 :
00734         case 3 :
00735         case 53 :
00736         case 49 :
00737         case 21 :
00738         case 17 :
00739       return(l);
00740         case 46 :
00741         case 42 :
00742         case 14 :
00743         case 10 :
00744         case 60 :
00745         case 56 :
00746         case 28 :
00747         case 24 :
00748       return(r);
00749         case 38 :
00750         case 34 :
00751         case 6 :
00752         case 2 :
00753         case 52 :
00754         case 48 :
00755         case 20 :
00756         case 16 :
00757       return(bAig_Zero);
00758         case 47 :
00759         case 43 :
00760         case 15 :
00761         case 11 :
00762         case 61 :
00763         case 57 :
00764         case 29 :
00765         case 25 :
00766       t1 = PureSat_And2(manager, l, r);
00767       return(t1);
00768     }
00769   }
00770   else if(caseIndex == 4) {
00771     switch(caseSig) {
00772         case 22 :
00773         case 20 :
00774         case 6 :
00775         case 4 :
00776         case 50 :
00777         case 48 :
00778         case 34 :
00779         case 32 :
00780         case 2 :
00781         case 16 :
00782         case 52 :
00783         case 1 :
00784         case 8 :
00785         case 19 :
00786         case 26 :
00787         case 37 :
00788         case 44 :
00789         case 38 :
00790         case 55 :
00791         case 62 :
00792       return(bAig_Zero);
00793         case 0 :
00794         case 18 :
00795         case 36 :
00796         case 54 :
00797         case 9 :
00798         case 27 :
00799         case 45 :
00800         case 63 :
00801         case 5 :
00802         case 23 :
00803         case 33 :
00804         case 51 :
00805         case 3 :
00806         case 17 :
00807         case 49 :
00808         case 7 :
00809         case 35 :
00810         case 21 :
00811         case 39 :
00812         case 53 :
00813       return(l);
00814         case 40 :
00815         case 58 :
00816         case 12 :
00817         case 30 :
00818         case 24 :
00819         case 10 :
00820         case 14 :
00821         case 56 :
00822         case 28 :
00823         case 42 :
00824         case 60 :
00825         case 46 :
00826       return(r);
00827         case 11 :
00828         case 47 :
00829         case 25 :
00830         case 61 :
00831       return(bAig_Not(ll));
00832         case 41 :
00833         case 59 :
00834         case 13 :
00835         case 31 :
00836       return(bAig_Not(lr));
00837         case 15 :
00838       t1 = PureSat_And(manager, ll, bAig_Not(lr));
00839       t2 = PureSat_And(manager, bAig_Not(ll), lr);
00840       return(bAig_Not(PureSat_And2(manager, bAig_Not(t1), bAig_Not(t2))));
00841         case 57 :
00842       t1 = PureSat_And(manager, rl, bAig_Not(rr));
00843       t2 = PureSat_And(manager, bAig_Not(rl), rr);
00844       return(bAig_Not(PureSat_And2(manager, bAig_Not(t1), bAig_Not(t2))));
00845         case 29 :
00846       t1 = PureSat_And(manager, ll, lr);
00847       t2 = PureSat_And(manager, bAig_Not(ll), bAig_Not(lr));
00848       return((PureSat_And2(manager, bAig_Not(t1), bAig_Not(t2))));
00849         case 43 :
00850       t1 = PureSat_And(manager, rl, rr);
00851       t2 = PureSat_And(manager, bAig_Not(rl), bAig_Not(rr));
00852       return((PureSat_And2(manager, bAig_Not(t1), bAig_Not(t2))));
00853     }
00854   }
00855   return(0);
00856 }
00857 
00858 
00859 
00874 int PureSat_Test2LevelMini(bAig_Manager_t *manager,
00875                            bAigEdge_t l,
00876                            bAigEdge_t r)
00877 {
00878   int class_ = bAig_Class(l);
00879   bAigEdge_t ll,lr,rl,rr;
00880 
00881   if(!manager->test2LevelMini)
00882     return 0;
00883 
00884   if(class_!= bAig_Class(r) || class_ != manager->class_)
00885     return 0;
00886 
00887   ll = leftChild(l);
00888   if(ll!=bAig_NULL && class_!=bAig_Class(ll))
00889     return 0;
00890   lr = rightChild(l);
00891   if(lr!=bAig_NULL && class_!=bAig_Class(lr))
00892     return 0;
00893   rl = leftChild(r);
00894   if(rl!=bAig_NULL && class_!=bAig_Class(rl))
00895     return 0;
00896   rr = rightChild(r);
00897   if(rr!=bAig_NULL && class_!=bAig_Class(rr))
00898     return 0;
00899 
00900   return 1;
00901 }
00902 
00919 bAigEdge_t
00920 PureSat_And(
00921    bAig_Manager_t *manager,
00922    bAigEdge_t nodeIndex1,
00923    bAigEdge_t nodeIndex2)
00924 {
00925 
00926   bAigEdge_t newNodeIndex;
00927 
00928   nodeIndex1 = bAig_GetCanonical(manager, nodeIndex1);
00929   nodeIndex2 = bAig_GetCanonical(manager, nodeIndex2);
00930 
00931   newNodeIndex = nodeIndex1;     /* The left node has the smallest index */
00932   if (bAig_NonInvertedEdge(nodeIndex1) > bAig_NonInvertedEdge(nodeIndex2)){
00933     nodeIndex1 = nodeIndex2;
00934     nodeIndex2 = newNodeIndex;
00935   }
00936 
00937   if ( nodeIndex2 == bAig_Zero ) {
00938     return bAig_Zero;
00939   }
00940   if ( nodeIndex1 == bAig_Zero ) {
00941     return bAig_Zero;
00942   }
00943   if ( nodeIndex2 == bAig_One ) {
00944     return nodeIndex1;
00945   }
00946   if ( nodeIndex1 == bAig_One ) {
00947     return nodeIndex2;
00948   }
00949   if ( nodeIndex1 == nodeIndex2 ) {
00950     return nodeIndex1;
00951   }
00952   if ( nodeIndex1 == bAig_Not(nodeIndex2) ) {
00953     return bAig_Zero;
00954   }
00955 
00956   /* Look for the new node in the Hash table */
00957   newNodeIndex = PureSat_HashTableLookup(manager, nodeIndex1, nodeIndex2);
00958 
00959 
00960   if (newNodeIndex == bAig_NULL){
00961     if(!PureSat_Test2LevelMini(manager,nodeIndex1,nodeIndex2)){
00962       newNodeIndex = PureSat_And2(manager, nodeIndex1, nodeIndex2);
00963       return newNodeIndex;
00964     }
00965 
00966     if(bAigIsVar(manager, nodeIndex1) && bAigIsVar(manager, nodeIndex2))
00967       newNodeIndex = PureSat_And2(manager, nodeIndex1, nodeIndex2);
00968     else if(bAigIsVar(manager, nodeIndex1))
00969       newNodeIndex = PureSat_And3(manager, nodeIndex1, nodeIndex2);
00970     else if(bAigIsVar(manager, nodeIndex2))
00971       newNodeIndex = PureSat_And3(manager, nodeIndex2, nodeIndex1);
00972     else {
00973       newNodeIndex = PureSat_And4(manager, nodeIndex1, nodeIndex2);
00974     }
00975   }
00976 
00977   return newNodeIndex;
00978 
00979 }
00980 
00981 
00994 bAigEdge_t
00995 PureSat_Or(
00996    bAig_Manager_t *manager,
00997    bAigEdge_t nodeIndex1,
00998    bAigEdge_t nodeIndex2)
00999 {
01000   return ( bAig_Not(PureSat_And(manager,  bAig_Not(nodeIndex1),  bAig_Not(nodeIndex2))));
01001 }
01002 
01003 
01016 bAigEdge_t
01017 PureSat_Xor(
01018    bAig_Manager_t *manager,
01019    bAigEdge_t nodeIndex1,
01020    bAigEdge_t nodeIndex2)
01021 {
01022  return PureSat_Or(manager,
01023             PureSat_And(manager, nodeIndex1, bAig_Not(nodeIndex2)),
01024             PureSat_And(manager, bAig_Not(nodeIndex1),nodeIndex2)
01025         );
01026 }
01027 
01028 
01041 bAigEdge_t
01042 PureSat_Eq(
01043    bAig_Manager_t *manager,
01044    bAigEdge_t nodeIndex1,
01045    bAigEdge_t nodeIndex2)
01046 {
01047  return bAig_Not(
01048             PureSat_Xor(manager, nodeIndex1, nodeIndex2)
01049             );
01050 }
01051 
01052 
01065 bAigEdge_t
01066 PureSat_Then(
01067    bAig_Manager_t *manager,
01068    bAigEdge_t nodeIndex1,
01069    bAigEdge_t nodeIndex2)
01070 {
01071  return PureSat_Or(manager,
01072                 bAig_Not(nodeIndex1),
01073                 nodeIndex2);
01074 }
01075 
01076 
01077 
01091 bAigEdge_t
01092 PureSat_CreateVarNode(
01093    bAig_Manager_t  *manager,
01094    nameType_t      *name)
01095 {
01096 
01097   bAigEdge_t varIndex;
01098   int class_ = manager->class_;
01099 
01100 
01101   if (!st_lookup(manager->SymbolTableArray[class_], name, &varIndex)){
01102     varIndex = bAig_CreateNode(manager, bAig_NULL, bAig_NULL);
01103     if (varIndex == bAig_NULL){
01104       return (varIndex);
01105     }
01106     /* Insert the varaible in the Symbol Table */
01107     st_insert(manager->SymbolTableArray[class_],
01108               name, (char*) (long) varIndex);
01109     manager->nameList[bAigNodeID(varIndex)] = name;
01110     return(varIndex);
01111   }
01112   else {
01113     return (varIndex);
01114   }
01115 }