60 pS->iVarUsed = nShared;
67 pS->pPosOutput = pS->pOutput;
72 *pS->pPosOutput++ = *pBeg++;
76 *pS->pPosOutput++ = c;
81 pS->pPosStore[pS->iVarUsed] = pS->pStore[pS->iVarUsed];
82 if (c) *pS->pPosStore[pS->iVarUsed]++ = c;
83 return pS->iVarUsed++;
88 *pS->pPosStore[New]++ = *pBeg++;
92 *pS->pPosStore[New]++ = c;
96 if (c) *pS->pPosStore[New]++ = c;
97 *pS->pPosStore[New]++ = 0;
111 if ( pS->pStore[i][0] )
112 printf(
"%c = %s\n",
'a' + i, pS->pStore[i] );
128 if ( fCompl && pDsd[0] ==
'!' )
131 pRes[0] = (fCompl ? (char)((
int)pDsd[0] ^ 1) : pDsd[0]), pRes[1] = 0;
133 sprintf( pRes,
"%s%s", fCompl ?
"!" :
"", pDsd );
150 for ( i = 0; pDsd[i]; i++ )
153 if ( pDsd[i] ==
'<' && pDsd[pMatches[i]+1] ==
'{' )
155 if ( (pDsd[i] >=
'A' && pDsd[i] <=
'F') || (pDsd[i] >=
'0' && pDsd[i] <=
'9') )
156 while ( (pDsd[i] >=
'A' && pDsd[i] <=
'F') || (pDsd[i] >=
'0' && pDsd[i] <=
'9') )
159 if ( pDsd[i] >=
'a' && pDsd[i] <=
'z' )
160 pDsd[i] =
'a' + pMap[ pDsd[i] -
'a' ];
167 for ( i = 0; pDsd[i]; i++ )
170 if ( pDsd[i] ==
'(' || pDsd[i] ==
'[' || pDsd[i] ==
'<' || pDsd[i] ==
'{' )
171 pNested[nNested++] = i;
172 else if ( pDsd[i] ==
')' || pDsd[i] ==
']' || pDsd[i] ==
'>' || pDsd[i] ==
'}' )
173 pMatches[pNested[--nNested]] = i;
181 for ( i = 0; pDsd[i]; i++ )
184 if ( pDsd[i] ==
'<' && pDsd[pMatches[i]+1] ==
'{' )
186 if ( (pDsd[i] >=
'A' && pDsd[i] <=
'F') || (pDsd[i] >=
'0' && pDsd[i] <=
'9') )
187 while ( (pDsd[i] >=
'A' && pDsd[i] <=
'F') || (pDsd[i] >=
'0' && pDsd[i] <=
'9') )
190 if ( !(pDsd[i] >=
'a' && pDsd[i] <=
'z') )
194 pPres[pDsd[i]-
'a'] |= Mask;
201 Counter += (pPres[i] == Mask);
213 int i,
Counter = 0, Counter2 = nShared;
216 if ( pVarPres[i] == 0 )
218 if ( pVarPres[i] == 3 )
225 assert( pVarPres[i] == 1 || pVarPres[i] == 2 );
226 pOld2New[i] = Counter2;
227 pNew2Old[Counter2] = i;
236 char * pBegin = pRes;
237 for ( i = 0; pDsd[i]; i++ )
240 if ( pDsd[i] ==
'<' && pDsd[pMatches[i]+1] ==
'{' )
242 assert( pDsd[pMatches[i]] ==
'>' );
243 for ( ; i <= pMatches[i]; i++ )
246 if ( (pDsd[i] >=
'A' && pDsd[i] <=
'F') || (pDsd[i] >=
'0' && pDsd[i] <=
'9') )
247 while ( (pDsd[i] >=
'A' && pDsd[i] <=
'F') || (pDsd[i] >=
'0' && pDsd[i] <=
'9') )
250 if ( !(pDsd[i] >=
'a' && pDsd[i] <=
'z') || (pDsd[i] -
'a' < nShared) )
257 for ( pDef = pS->pStore[pDsd[i]-
'a']; *pDef; pDef++ )
280 for ( i = 0; p[i]; i++ )
281 if ( !(p[i] ==
'(' || p[i] ==
'[' || p[i] ==
'<' || p[i] ==
'{' || (p[i] >=
'a' && p[i] <=
'z')) )
283 else if ( pStatus[i] >= 0 )
284 printf(
"%d", pStatus[i] );
297 pStatus[*p - pStr] = -1;
300 while ( (**p >=
'A' && **p <=
'F') || (**p >=
'0' && **p <=
'9') )
302 pStatus[*p - pStr] = -1;
307 char * q = pStr + pMatches[ *p - pStr ];
312 for ( ; pTemp < q+1; pTemp++ )
313 pStatus[pTemp - pStr] = -1;
316 if ( **p >=
'a' && **p <=
'z' )
317 return pStatus[*p - pStr] = (**p -
'a' < nShared) ? 0 : 3;
318 if ( **p ==
'(' || **p ==
'[' || **p ==
'<' || **p ==
'{' )
320 int Status, nPure = 0,
nTotal = 0;
322 char * q = pStr + pMatches[ *p - pStr ];
323 assert( *q == **p + 1 + (**p !=
'(') );
324 for ( (*p)++; *p < q; (*p)++ )
327 nPure += (Status == 3);
334 else if ( nPure == 1 )
336 else if ( nPure <
nTotal )
338 else if ( nPure ==
nTotal )
341 return (pStatus[pOld - pStr] = Status);
366 while ( (*pBeg >=
'A' && *pBeg <=
'F') || (*pBeg >=
'0' && *pBeg <=
'9') )
370 char * q = pStr + pMatches[pBeg - pStr];
374 return pStatus[pBeg - pStr];
387 while ( (**p >=
'A' && **p <=
'F') || (**p >=
'0' && **p <=
'9') )
395 char * q = pStr + pMatches[ *p - pStr ];
401 for ( ; pTemp < q+1; pTemp++ )
405 if ( **p >=
'a' && **p <=
'z' )
411 if ( **p ==
'(' || **p ==
'[' || **p ==
'<' || **p ==
'{' )
413 int New, StatusFan, Status = pStatus[*p - pStr];
414 char * pBeg, * q = pStr + pMatches[ *p - pStr ];
415 assert( *q == **p + 1 + (**p !=
'(') );
426 for ( (*p)++; *p < q; (*p)++ )
439 if ( Status == 1 || **p ==
'<' || **p ==
'{' )
442 for ( (*p)++; *p < q; (*p)++ )
452 if ( StatusFan == 3 )
467 for ( (*p)++; *p < q; (*p)++ )
473 if ( StatusFan != 3 )
481 if ( StatusFan == 3 )
524 while ( (**p >=
'A' && **p <=
'F') || (**p >=
'0' && **p <=
'9') )
528 char * q = pStr + pMatches[*p - pStr];
532 if ( **p >=
'a' && **p <=
'z' )
534 if ( **p ==
'(' || **p ==
'[' || **p ==
'<' || **p ==
'{' )
536 char * q = pStr + pMatches[ *p - pStr ];
537 assert( *q == **p + 1 + (**p !=
'(') );
538 for ( (*p)++; *p < q; (*p)++ )
540 int fCompl = (**p ==
'!');
541 char * pBeg = fCompl ? *p + 1 : *
p;
543 if ( (!fCompl && *pBeg ==
'(' && *q ==
')') || (*pBeg ==
'[' && *q ==
']') )
545 assert( **p ==
')' || **p ==
']' );
556 char * q, *
p = pDsd;
560 for ( q = p; *
p; p++ )
563 if ( *p ==
'!' && *(q-1) ==
'!' && p != q )
587 char *
Dau_DsdMerge(
char * pDsd0i,
int * pPerm0,
char * pDsd1i,
int * pPerm1,
int fCompl0,
int fCompl1,
int nVars )
603 int nVarsShared, nVarsTotal;
605 word * pTruth, * pt = NULL, * pt0 = NULL, * pt1 = NULL;
614 printf(
"\nAfter copying:\n" );
616 printf(
"%s\n", pDsd0 );
618 printf(
"%s\n", pDsd1 );
641 printf(
"After replacement:\n" );
643 printf(
"%s\n", pDsd0 );
645 printf(
"%s\n", pDsd1 );
662 if ( nVarsShared == 0 )
664 sprintf( pRes,
"(%s%s)", pDsd0, pDsd1 );
666 printf(
"Disjoint:\n" );
668 printf(
"%s\n", pRes );
674 printf(
"Normalized:\n" );
676 printf(
"%s\n", pRes );
691 printf(
"Individual status:\n" );
701 strcpy( pDsd0, pS->pOutput );
703 printf(
"Substitutions:\n" );
705 printf(
"%s\n", pDsd0 );
710 strcpy( pDsd1, pS->pOutput );
712 printf(
"%s\n", pDsd1 );
718 sprintf( pS->pOutput,
"(%s%s)", pDsd0, pDsd1 );
728 strcpy( pRes, pS->pOutput );
732 printf(
"Decomposition:\n" );
734 printf(
"%s\n", pS->pOutput );
739 printf(
"Inlining:\n" );
741 printf(
"%s\n", pRes );
747 printf(
"Replaced:\n" );
749 printf(
"%s\n", pRes );
752 printf(
"Normalized:\n" );
754 printf(
"%s\n", pRes );
760 printf(
"Dau_DsdMerge(): Verification failed!\n" );
780 char * pStr =
"[!(a[be])!(c!df)]";
799 char * pStr1 =
"(!(ab)de)";
800 char * pStr2 =
"(!(ac)f)";
813 pRes =
Dau_DsdMerge( pStr1, Perm0, pStr2, Perm0, 0, 0, 6 );
char pStore[DAU_MAX_VAR][DAU_MAX_STR]
static int Dau_DsdMergeFindShared(char *pDsd0, char *pDsd1, int *pMatches0, int *pMatches1, int *pVarPres)
static void Dau_DsdMergeStoreClean(Dau_Sto_t *pS, int nShared)
void Dau_DsdRemoveBraces(char *pDsd, int *pMatches)
void Dau_DsdMergeSubstitute_rec(Dau_Sto_t *pS, char *pStr, char **p, int *pMatches, int *pStatus, int fWrite)
char * pPosStore[DAU_MAX_VAR]
static int Dau_DsdMergeCountShared(int *pPres, int Mask)
static void Dau_DsdMergeStoreAddToDef(Dau_Sto_t *pS, int New, char *pBeg, char *pEnd)
char pOutput[DAU_MAX_STR]
static void Dau_DsdMergeVarPres(char *pDsd, int *pMatches, int *pPres, int Mask)
static void Dau_DsdMergeSubstitute(Dau_Sto_t *pS, char *pDsd, int *pMatches, int *pStatus)
static void Dau_DsdMergePrintWithStatus(char *p, int *pStatus)
static int Dau_DsdMergeGetStatus(char *pBeg, char *pStr, int *pMatches, int *pStatus)
typedefABC_NAMESPACE_IMPL_START struct Dau_Sto_t_ Dau_Sto_t
DECLARATIONS ///.
int Dau_DsdDecompose(word *pTruth, int nVarsInit, int fSplitPrime, int fWriteTruth, char *pRes)
word * Dau_DsdToTruth(char *p, int nVars)
char * Dau_DsdMerge(char *pDsd0i, int *pPerm0, char *pDsd1i, int *pPerm1, int fCompl0, int fCompl1, int nVars)
DECLARATIONS ///.
static void Dau_DsdMergeStorePrintDefs(Dau_Sto_t *pS)
static int Dau_DsdIsConst(char *p)
MACRO DEFINITIONS ///.
static abctime Abc_Clock()
static void Dau_DsdMergeInlineDefinitions(char *pDsd, int *pMatches, Dau_Sto_t *pS, char *pRes, int nShared)
void Dau_DsdRemoveBraces_rec(char *pStr, char **p, int *pMatches)
static void Dau_DsdMergeStoreCleanOutput(Dau_Sto_t *pS)
word Dau_Dsd6ToTruth(char *p)
static int Dau_DsdMergeCreateMaps(int *pVarPres, int nShared, int *pOld2New, int *pNew2Old)
int Dau_DsdMergeStatus_rec(char *pStr, char **p, int *pMatches, int nShared, int *pStatus)
static void Abc_TtCopy(word *pOut, word *pIn, int nWords, int fCompl)
void Dau_DsdNormalize(char *p)
#define DAU_MAX_VAR
INCLUDES ///.
static void Dau_DsdMergeReplace(char *pDsd, int *pMatches, int *pMap)
static void Dau_DsdMergeStoreAddToOutput(Dau_Sto_t *pS, char *pBeg, char *pEnd)
unsigned __int64 word
DECLARATIONS ///.
#define ABC_NAMESPACE_IMPL_END
static int Dau_DsdMergeStoreStartDef(Dau_Sto_t *pS, char c)
#define ABC_NAMESPACE_IMPL_START
static int Dau_DsdIsConst1(char *p)
static int Abc_TtWordNum(int nVars)
static void Dau_DsdMergeMatches(char *pDsd, int *pMatches)
static int Abc_TtEqual(word *pIn1, word *pIn2, int nWords)
static void Dau_DsdMergeCopy(char *pDsd, int fCompl, char *pRes)
static void Dau_DsdMergeStoreStopDef(Dau_Sto_t *pS, int New, char c)
static int Dau_DsdMergeStatus(char *pDsd, int *pMatches, int nShared, int *pStatus)
static int Dau_DsdIsConst0(char *p)
static void Dau_DsdMergeStoreAddToDefChar(Dau_Sto_t *pS, int New, char c)
static void Abc_TtAnd(word *pOut, word *pIn1, word *pIn2, int nWords, int fCompl)
static void Dau_DsdMergeStoreAddToOutputChar(Dau_Sto_t *pS, char c)
static char Dau_DsdMergeStoreCreateDef(Dau_Sto_t *pS, char *pBeg, char *pEnd)
int nTotal
DECLARATIONS ///.