beginfig(1) def porteAND(expr a) = ((halfcircle scaled 16mm) -- cycle) rotated -90 shifted (-8mm,0) shifted a enddef ; def porteNOR(expr a) = begingroup save $ ; pair $ ; $ = a shifted (-2mm,0) ; ${up}..{left}($ shifted (-8mm,8mm)) &($ shifted (-8mm,8mm)){dir -5}..($ shifted (-3mm,0)){down}..{dir 185}($ shifted (-8mm,-8mm)) &($ shifted (-8mm,-8mm)){right}..{up}$ &(${down}..($ shifted (1mm,-1mm)){right}..($ shifted (2mm,0)){up}..($ shifted (1mm,1mm)){left}..cycle) endgroup enddef ; def point(expr a) = draw a withpen pencircle scaled 4bp enddef ; z0 = (0,0) ; x1 = x0 ; x2 = x3 ; y2 = y0 - 4mm ; y3 = y1 + 4mm ; x2 - x0 = 7cm ; y0 - y1 = 5cm ; path p[] ; p0 = porteAND(z0) ; p1 = porteAND(z1) ; p2 = porteNOR(z2) ; p3 = porteNOR(z3) ; draw p0 ; draw p1 ; draw p2 ; draw p3 ; draw ((-2cm,0)--(0,0)) shifted (z0 + (-8mm,4mm)) ; draw ((-2cm,0)--(0,0)) shifted (z1 + (-8mm,-4mm)) ; label.lft(btex $S$ etex,z0 + (-28mm,4mm)) ; label.lft(btex $R$ etex,z1 + (-28mm,-4mm)) ; draw ((-28mm,0)--(-14mm,0)) shifted 1/2[z0,z1] ; point((-14mm,0) shifted 1/2[z0,z1]) ; label.lft(btex $T$ etex,1/2[z0,z1] + (-28mm,0)) ; draw ((-8mm,-4mm)--(-14mm,-4mm)--(-14mm,-46mm)--(-8mm,-46mm)) shifted z0 ; draw ((0,0)--(2cm,0)) shifted z2 ; draw ((0,0)--(2cm,0)) shifted z3 ; label.rt(btex $(\bar Q)$ etex,z2 + (2cm,0)) ; label.rt(btex $Q$ etex,z3 + (2cm,0)) ; point(z2 + (2mm,0)) ; point(z3 + (2mm,0)) ; x4 = x5 = x6 = x7 = x2 - 14mm ; x8 = x9 = x2 + 2mm ; y4 = y2 - 4mm ; y7 = y3 + 4mm ; y5 = y8 ; y6 = y9 ; y8=1/3[y2,y3] ; y9 = 2/3[y2,y3] ; draw (z2 + (2mm,0))--z8--z6--z7--(z3 + (-2mm, 4mm)) cutafter (reverse p3) ; draw (z3 + (2mm,0))--z9--z5--z4--(z2 + (-2mm,-4mm)) cutafter p2 ; draw z0--(z2 + (-2mm, 4mm)) cutafter (reverse p2) ; draw z1--(z3 + (-2mm,-4mm)) cutafter p3 ; draw (z0 + (-20mm, 12mm))--(z1 + (-20mm,-12mm))--(z3 + (8mm,-16mm))--(z2 + (8mm,16mm))--cycle dashed evenly ; endfig ; end