%% 
%%  The LaTeX Graphics Companion, 2ed (first printing May 2007)
%% 
%%  Example 7-4-17 on page 490.
%% 
%%  Copyright (C) 2007 Michel Goossens, Frank Mittelbach, Denis Roegel, Sebastian Rahtz, Herbert Vo\ss 
%% 
%%  It may be distributed and/or modified under the conditions
%%  of the LaTeX Project Public License, either version 1.3
%%  of this license or (at your option) any later version.
%% 
%%  See http://www.latex-project.org/lppl.txt for details.
%% 

\documentclass{ttctexa}
\pagestyle{empty}
\setcounter{page}{6}
\setlength\textwidth{207.83385pt}
\StartShownPreambleCommands
\usepackage[graph,curve,arc]{xy}
\newgraphescape{N}[1]{!{\save-/4mm/-/4pt/;p+/4mm/:
  (-1,1);(-1,-1)**@{-} ?(.25)="N#1a" ?(.75)="N#1b",
  (-1,1);(0,1)**@{-} ; (0,-1),{\ellipse_{}} ; (-1,-1)**@{-},
  (0,0);(1,0)**{}*!E\cir<2pt>{}!C-E="N#1"\restore \POS"N#1"}}
\newgraphescape{I}[1]{!{\save-/4mm/-/2pt/;p+/4mm/:
  (-1,1);(-1,-1)**@{-} ?="I#1a",  (-1,1);(.667,0)**@{-};(-1,-1)**@{-},
  (0,0);**{}*!E\cir<2pt>{}!C-E="I#1"\restore \POS"I#1"}}
\newgraphescape{B}{!{*=0@{*}}}
\newgraphescape{R}{!{;p+/r4mm/**{};}}
\newgraphescape{p}[2]{[#1!{"#2";p+/^/}]}
\newcommand\circuit[1]{\xygraph{~{0;<10mm,0mm>:<0mm,9mm>::0}#1}}
\StopShownPreambleCommands
\begin{document}
\[\begin{array}{c}
\circuit{  []!R!N1 ("N1a"([l]x - ?), "N1b"([l]y - ?))
 [r]!I2 ("N1" - "I2a") - [r]{x\land y}}\\
\circuit{  []x
 [rrr]!R!I1 ("I1a"("x" - ?))
  [drr]!R!N1 ("I1" -`r[d]`"N1a""N1a", "N1b"!plx y - "N1b")
 "I1"[dddd]!R!I2 ("I2a"[l]!puy!B - `d"I2a""I2a")
  "N1"[dd]!R!N2 ("I1a"[l(.5)]!pux!B -`d"N2a""N2a", "I2" -`r[u]`"N2b""N2b")
   [urr]!R!N3 ("N1" -`r[d]`"N3a""N3a", "N2" -`r[u]`"N3b""N3b")
   - [r]{x\mathrel{\textrm{xor}}y}}
\end{array}\]
\end{document}
