A Tutology Checker loosely relted to Stålmrck s Algorithm y Mrtin Richrds mr@cl.cm.c.uk http://www.cl.cm.c.uk/users/mr/ University Computer Lortory New Museum Site Pemroke Street Cmridge, CB2 3QG Mrtin Richrds 1 Tlk 13/Mr/98
Introduction Consider the propositionl expression: (( ) c) ( ( ) c) The corresponding tree is: nd imp or eqv c not c eqv Mrtin Richrds 2 Tlk 13/Mr/98
Lel Edges Invent vrile nmes for the unlelled edges: t6 t2 nd t5 t1 imp t4 or eqv c not c t3 eqv Mrtin Richrds 3 Tlk 13/Mr/98
Set Root to Zero Set the root vrile to zero (flse) nd see if this leds to n inconsistency. 0 t2 nd t5 t1 imp t4 or eqv c not c t3 eqv Mrtin Richrds 4 Tlk 13/Mr/98
Set of Terms The tree corresponds to the following set of terms. 0 t2 t1 nd imp eqv t2 t5 t1 c t5 t4 t3 or not eqv t4 c t3 Mrtin Richrds 5 Tlk 13/Mr/98
Inference Rules The terms re modified nd possily eliminted y the ppliction of inference rules which sometimes yield vrile mpping informtion. Mpping informtion Vrile mpping informtion is set of items of the form: or where x = 0 x = 1 x = y x = ȳ x nd y re vriles. Mrtin Richrds 6 Tlk 13/Mr/98
0 t2 t1 nd imp eqv t2 t5 t1 c t5 t4 t3 or not eqv t4 c t3 Mpping: t 4 = t 3 0 t2 t1 nd imp eqv t2 t5 t1 c t5 t3 imp eqv t3 c Mrtin Richrds 7 Tlk 13/Mr/98
0 t2 t1 nd imp eqv t2 t5 t1 c t5 t3 imp eqv t3 c Mpping: t 4 = t 3, t 3 = t 1 0 t2 t1 nd imp eqv t2 t5 t1 c t5 imp t1 c Mrtin Richrds 8 Tlk 13/Mr/98
0 t2 t1 nd imp eqv t2 t5 t1 c t5 imp t1 c Mpping: t 4 = t 3, t 3 = t 1, t 5 = t 2 0 t2 t1 nd imp eqv t2 t2 t1 c Mrtin Richrds 9 Tlk 13/Mr/98
0 t2 t1 nd imp eqv t2 t2 t1 c Mpping: t 4 = t 3, t 3 = t 1, t 5 = t 2, t 2 = 0 0 t1 imp eqv t1 c Mrtin Richrds 10 Tlk 13/Mr/98
0 t1 imp eqv t1 c Mpping: t 4 = t 3, t 3 = t 1, t 5 = t 2, t 2 = 0, t 1 = 1, c = 0 1 eqv Mrtin Richrds 11 Tlk 13/Mr/98
1 eqv Mpping: t 4 = t 3, t 3 = t 1, t 5 = t 2, t 2 = 0, t 1 = 1, c = 0, = There re now no terms left. An inconsistency hs not een found, so the originl expression ws not tutology. These direct derivtions cn e done in liner time. Mrtin Richrds 12 Tlk 13/Mr/98
Unfortuntely We cnnot, in generl, expect direct derivtions to solve the prolem, (since tutology checking hs exponentil cost). If we pply the technique to: (( ) ( ) ( ) we otin: 0 0 0 nor gt lt 0 nd Mrtin Richrds 13 Tlk 13/Mr/98
We cn esily see tht 0 0 0 nor gt lt 0 nd hs no solution since first term implies: = 01, 10, 11 second term implies: = 00, 01, 11 third term implies: = 00, 10, 11 fourth term implies: = 00, 01, 10 Mrtin Richrds 14 Tlk 13/Mr/98
The Dilemm Rule 1. Select vrile, v i, sy, tht hs not yet een ssigned vlue. 2. Set it to 0 nd 1 in turn nd pply the direct inferences until convergence, yielding vrile mppings M 0 nd M 1, respectively. 3. If oth settings led to inconsistencies then the terms cnnot e stisfied. 4. If just one setting leds to n inconsistency, return the other mpping. 5. If neither setting leds to n inconsistency, return the intesection of M 0 nd M 1, i.e. the set of mpping items tht occur in oth M 0 nd M 1. 6. Repet for ll other vriles. Mrtin Richrds 15 Tlk 13/Mr/98
7. Repet the process using pirs of vriles, v i v j, setting them to ll possile vlues (00, 01, 10 nd 11), tking the intersection of the four mppings produced. 8. Repet similrly with ll sets of 3, 4,... n vriles until either no terms remin or n inconsistency is found. When the lgorithm is considering k vriles, it is sid to e t recursion depth k. Hopefully, the prolem will e solved efore the recursion depth gets too lrge. The prolem will certinly e solved t recursion depth n, if not efore. Any strtegy to reduce the recursion depth is vlule. Mrtin Richrds 16 Tlk 13/Mr/98
Mpping Intersection Suppose M 0 ={v 1 = 0, v 2 = 1, v 2 = v 4, v 5 = v 6 } nd M 1 ={v 1 = 0, v 2 = 0, v 3 = v 5, v 5 = v 6 } then the intersection is {v 1 = 0, v 5 = v 6 } Mrtin Richrds 17 Tlk 13/Mr/98
Using Tridic Reltions The terms so fr considered represent the reltion etween the opernds nd result of dydic Boolen opertors. For exmple, x nd y z sys tht the only vlid settings of xyz re: 000, 001, 010 or 111 There re just 16 dydic Boolen opertors, ut there re 256 reltions over 3 Boolen vriles. We extend Ståmrck s Algorithm to use such reltions in the term set. Mrtin Richrds 18 Tlk 13/Mr/98
Eight Bit Representtion The reltion R(x, y, z) cn e represented using it pttern of length 8, s follows: x 1 1 1 1 0 0 0 0 y 1 1 0 0 1 1 0 0 z 1 0 1 0 1 0 1 0 c d e f g h The its h = 1 000ɛR g = 1 001ɛR f = 1 010ɛR e = 1 011ɛR d = 1 100ɛR c = 1 101ɛR = 1 110ɛR = 1 111ɛR Mrtin Richrds 19 Tlk 13/Mr/98
Nottion We will use Rcdefgh to identify the reltion with it pttern cdefgh. The terms in the previous exmple: 0 0 0 nor gt lt 0 nd cn e written s: R00011110(0,, ) R01001011(0,, ) R00101101(0,, ) R10000111(0,, ) Mrtin Richrds 20 Tlk 13/Mr/98
New Inferences Mny more inference rules re now ville. We cn, for instnce, comine R00101101(0,, ) nd R10000111(0,, ) to yield R00000101(0,, ). Reltion Triplets R00101101 101 011 010 000 R10000111 111 010 001 000 R00000101 010 000 Mrtin Richrds 21 Tlk 13/Mr/98
Derivtion The terms in the previous exmple re: R00011110(0,, ) R01001011(0,, ) R00101101(0,, ) R10000111(0,, ) Comining terms 3 nd 4 gives: R00011110(0,, ) R01001011(0,, ) R00000101(0,, ) Comining terms 2 nd 3 gives: R00011110(0,, ) R00000001(0,, ) Comining these two terms gives: R00000000(0,, ) This is term tht cnnot e stisfied, so n inconsistency hs een found. Mrtin Richrds 22 Tlk 13/Mr/98
Oservtions Hving 256 reltions my seem to e disdvntge, ut there re compenstions. As we hve seen, the recursion depth my e reduced. Terms cn e put into cnonicl form to llow esy elimintion of equivlent terms. Mny more inferences re possile. Inferences cn e done y tle lookup or y simple it pttern opertions. Mrtin Richrds 23 Tlk 13/Mr/98
Cnoniclistion A term cn e put into cnonicl form y the following steps: 1. Replce R(x, y, z) y R (0, y, z), if the reltion does not depend on x. For exmple, replce R10111011(x, y, z) y R00001011(0, y, z), since the upper nd lower 4 its of R re equl. 2. Replce R(x, y, y) y the equivlent R (x, y, 0). For exmple, replce R00110101(x, y, y) y R00010001(x, y, 0), i.e. msk R with R10011001. 3. Replce R(1, y, z) y the equivlent R (0, y, z). For exmple, replce R00110101(1, y, z) y R00000011(0, y, z), i.e. right shift y 4. Mrtin Richrds 24 Tlk 13/Mr/98
4. Replce R(0, y, z) y the equivlent R (0, y, z). For exmple, replce R00110101(0, y, z) y R00000101(0, y, z), i.e. msk R with R00001111. 5. Do the ove trnsformtions for ll permuttions of (x, y, z). 6. Return R(x, y, z) with the vriles (x, y, z) in dictionry order. The resulting cnonicl term will hve one of the following forms: Rcdefgh(x, y, z) R0000cd(0, y, z) R000000(0, 0, z) R0000000(0, 0, 0) Mrtin Richrds 25 Tlk 13/Mr/98
Deducing Mppings Given term Rcdefgh(x, y, z), we my e le to deduce new mpping informtion. For instnce, if cd = 0000 then x = 0. By similr mens, we cn deduce whether x = 1, x = y or x = ȳ. Term Deduction R0000efgh(x, y, z) x = 0 Rcd0000 (x, y, z) x = 1 R00de00h(x, y, z) R0c00fg0 (x, y, z)... There re 12 such mppings. x = y x = ȳ They cn e deduced y simple msking opertions or y tle lookup. Mrtin Richrds 26 Tlk 13/Mr/98
Pirwise Inferences As we hve lredy seen, if we hve two terms R(x, y, z) nd S(x, y, z) referring to the sme vriles, then they cn e replced y the single term (R S)(x, y, z). Mrtin Richrds 27 Tlk 13/Mr/98
Pirwise Inferences If we hve two terms R(, x, y) nd S(, x, y) with two vriles in common then we cn sometimes simplify R nd/or S, nd we cn sometimes deduce reltion etween nd. For exmple, T erm T riplets R01010011(, x, y) 110 100 001 000 R10101100(, x, y) 111 101 011 010 The first disllows the pttern xy = 11 nd the second disllows xy = 00, so, tken together we cn deduce: R01000010(, x, y) 110 001 R00100100(, x, y) 101 010 Mrtin Richrds 28 Tlk 13/Mr/98
Pirwise Inferences R01000010(, x, y) 110 001 R00100100(, x, y) 101 010 From these we cn deduce informtion out, nmely =, nd tken seprtely the terms llow us to deduce new informtion out xy, (nmely: = x = ȳ), nd xy (nmely: = x = ȳ). All these deductions cn e mde esily y mens of itwise opertions on the reltion it ptterns. Another inference rule pplies to pir of terms of the form R(x, 0, z) nd S(0, y, z), replcing them y T (x, y, z). Agin, the it pttern representtion of T is esily clculted from R nd S. Mrtin Richrds 29 Tlk 13/Mr/98
Using Lrger Reltions We hve seen how the mechnism works with reltions over three Boolen vriles. Wht out reltions over 4, 5,... n vriles? The length of the reltion it pttern is 2 n nd the numer of vrile mpping items is n(n + 1). When n = 4, 16-its re required to represent the reltion nd there re 20 mpping items. When n = 8, the reltion tkes eight 32-it word to represent, which is typiclly equl to the spce require to represent the eight vriles. Such term cn thus e represented in 16 32-it words. A term over 6 vriles would require 8 words. n = 8 is proly good compromise. Mrtin Richrds 30 Tlk 13/Mr/98
Nottion We will use Rn to denote the set of terms contining generl reltions over n vriles. A typicl element of Rn is R(v 1,... v n ). BinOp is the suset of R3 in which ll terms re restricted to reltions corresponding to the 16 dydic Boolen opertors. Ståmrck s vrile mpping cn e thought of s the suset (EqNe) of R2, restricted to 12 of the 16 possile reltions over 2 Boolens. The four tht re omitted involve impliction, possily comined with negtion. We will cll this suset of R2: Imp. Mrtin Richrds 31 Tlk 13/Mr/98
R2 Reltions Reltion xy Pirs Condition R0000 F lse R0001 00 x = 0 y = 0 R0010 01 x = 0 y = 1 R0011 01 00 x = 0 R0100 10 x = 1 y = 0 R0101 10 00 y = 0 R0110 10 01 x = ȳ R0111 10 01 00 x ȳ R1000 11 x = 1 y = 1 R1001 11 00 x = y R1010 11 01 y = 1 R1011 11 01 00 x y R1100 11 10 x = 1 R1101 11 10 00 x ȳ R1110 11 10 01 x y R1111 11 10 01 00 T rue Mrtin Richrds 32 Tlk 13/Mr/98
R2 If circulr chin of implictions cn e found in R2 then either ll the vrile in the chin re equl or n inconsistency is present. For exmple: x y, ȳ z, z x = x = y = z x y, ȳ z, z x = Inconsistent Such deductions should e mde s soon s they re detectle. Elements of EqN e correspond to renming, nd cn e removed s soon s the renming is done. We re thus left with n R2 structure contining only terms from Imp tht contin no cycles nd we need n efficient lgorithm to detect cycles when new items re dded (to either Imp or EqNe). It is well known tht R2 cn e solved in liner time. Mrtin Richrds 33 Tlk 13/Mr/98
PERM R(v 1, v 2,..., v n ) = R (v i, v j,..., v k ) where i, j,...k is permuttion of 1, 2,..., n Exmple R10110110(x, y, z) 111 101 100 010 001 = R10110110(x, z, y) 111 110 100 010 001 Mrtin Richrds 34 Tlk 13/Mr/98
UNDUP R(v 1, v 1, v 3,..., v n ) = R (v 1, 0, v 3,..., v n ) Exmple R10110110(x, x, y) 111 101 100 010 001 = R00100010(x, 0, y) 101 001 By comining PERM nd UNDUP, ll repeted vriles in term cn e removed. Mrtin Richrds 35 Tlk 13/Mr/98
ELIMVAR R(v 1, v 2,..., v n ) = R (0, v 2,..., v n ) if v 1 is not used in ny other term Exmple R00110110(x, y, z) 101 100 010 001 = R00000111(0, y, z) 010 001 000 Mrtin Richrds 36 Tlk 13/Mr/98
INDEP R(v 1, v 2,..., v n ) = R (0, v 2,..., v n ) if the truth of this term does not depend on the vlue of v 1 Exmple R01100110(x, y, z) 110 101 010 001 = R00000110(0, y, z) 010 001 Mrtin Richrds 37 Tlk 13/Mr/98
ONE R(1, v 2,..., v n ) = R (0, v 2,..., v n ) Exmple R01100101(1, y, z) 110 101 010 000 = R00000110(0, y, z) 010 001 Mrtin Richrds 38 Tlk 13/Mr/98
ZERO R(0, v 2,..., v n ) = R (0, v 2,..., v n ) Exmple R01100101(x, y, z) 110 101 010 000 = R00000101(0, y, z) 010 000 Mrtin Richrds 39 Tlk 13/Mr/98
UNIT R(v 1, v 2,..., v n ) = S(v i, v j ) Exmple R01001111(x, y, z) 110 011 010 001 000 = R1011(x, y) 11 01 00 Mrtin Richrds 40 Tlk 13/Mr/98
PAIR2 s(, ) R(v 1, v 2,..., v n ) = R (v 1, v 2,..., v n ) Exmple R1011(x, y) 11 01 00 R01111001(x, y, z) 110 101 100 011 000 = R01001001(x, y, z) 110 011 000 Mrtin Richrds 41 Tlk 13/Mr/98
PAIRGEN R(v 1, v 2,..., v n ) S(w 1, w 2,..., w n ) = T (v i, w j ) Exmple R01101011(, y, z) 111 110 011 001 000 R01110011(, y, z) 110 101 100 001 000 = R1011(, ) 11 01 00 Mrtin Richrds 42 Tlk 13/Mr/98
PAIRSIMP R(v 1, v 2,..., v n ) S(w 1, w 2,..., w n ) = R (v 1, v 2,..., v n ) S (w 1, w 2,..., w n ) Exmple R01101011(, y, z) 111 110 011 001 000 R01110011(, y, z) 110 101 100 001 000 = R01101011(, y, z) 110 001 000 R01110011(, y, z) 110 101 100 001 000 Mrtin Richrds 43 Tlk 13/Mr/98
PAIRCOMB R(v 1, 0,..., v n ) S(0, v 2,..., v n ) = T (v 1, v 2,..., v n ) Exmple R0000110000001010(, 0, y, z) 1011 1010 0011 0001 R0000000011100001(0,, y, z) 0111 0110 0101 0000 = R1100000000101000(,, y, z) 1111 1110 0101 0011 Mrtin Richrds 44 Tlk 13/Mr/98
FACTOR R(v 1,..., v i, v i+1,..., v n ) = S(0,..., 0, v 0,..., v i ) T (0,..., 0, v i+1,..., v n ) if the given reltion cn e prtitioned into two reltions over independent sets of vriles. This is only useful when n > 5. It increses the pplicility of PAIRCOMB. Mrtin Richrds 45 Tlk 13/Mr/98
Finl Remrks This pproch reduces the numer of terms, the numer of vriles, nd the depth nd fnout of the recursion. This pproch increses the numer of inference rules nd simplifies their ppliction. Multi-vrite reltions llow the representtion of higher level properties of circuit. Another form of dilemm rule is possile. Pick rndom reltion over n vriles R11011100(x, y, z), sy, nd its complement R00100011(x, y, z), nd use these s the lterntives in the dilemm rule. This is more useful when n > 3. Mrtin Richrds 46 Tlk 13/Mr/98
Lst Thought If multi-vrite reltions re good ide, it might e worth using reltions over 16 or perhps 32 vriles, representing the reltions y OBDDs insted of it ptterns. Mrtin Richrds 47 Tlk 13/Mr/98
Anlogy Mrtin Richrds 48 Tlk 13/Mr/98