diff options
Diffstat (limited to 'Master/texmf-dist/tex/latex/yquant/yquant-circuit.tex')
-rw-r--r-- | Master/texmf-dist/tex/latex/yquant/yquant-circuit.tex | 304 |
1 files changed, 126 insertions, 178 deletions
diff --git a/Master/texmf-dist/tex/latex/yquant/yquant-circuit.tex b/Master/texmf-dist/tex/latex/yquant/yquant-circuit.tex index 993455cbebb..2117e7f4407 100644 --- a/Master/texmf-dist/tex/latex/yquant/yquant-circuit.tex +++ b/Master/texmf-dist/tex/latex/yquant/yquant-circuit.tex @@ -1,221 +1,145 @@ % BEGIN_FOLD Drawing wires -% extends the wire of register #1. Assumes a node called yquantbox is set up, and it is a node with appropriate projections. -\protected\def\yquant@circuit@extendwire#1{% - \begingroup% - \edef\wiretype{\yquant@register@get@type{#1}}% - \dimdef\wireypos{\yquant@register@get@y{#1}}% - \tikzset{/yquant/every wire}% - \unless\ifnum\wiretype=\yquant@register@type@none{% - \csname yquant@circuit@extendwire@\wiretype\endcsname{#1}% - }\fi% - % set the wire style to have the correct \pgflinewidth available (we don't allow individual line widths for different types of wires - \tikzset{/yquant/every wire}% - \pgfpointanchor{yquantbox}{east}% - \@tempdima=\pgf@x% - \pgfpointshapexproj{yquantbox}% - {\pgfqpoint{\@tempdima} - {\dimexpr\wireypos+2\pgflinewidth\relax}}% - \edef\tmp{{(\the\pgf@x,\the\pgf@y)}}% - % For multi-qubit registers, the east anchor is not necessarily accurate. - \pgfpointshapexproj{yquantbox}{\pgfqpoint{\@tempdima}{\wireypos}}% - \edef\tmp{\tmp{(\the\pgf@x,\the\pgf@y)}}% - \pgfpointshapexproj{yquantbox} - {\pgfqpoint{\@tempdima}% - {\dimexpr\wireypos-2\pgflinewidth\relax}}% - \yquant@register@set@lastwire{#1}{\tmp{(\the\pgf@x,\the\pgf@y)}}% - \endgroup% -} - -% finishes the wire of register #1 until x position \yquant@env@end@xpos -\protected\def\yquant@circuit@endwire#1{% - \begingroup% - \edef\wiretype{\yquant@register@get@type{#1}}% - \unless\ifnum\wiretype=\yquant@register@type@none\relax% - % we don't have a yquantbox node but still want to extend the line; so just install a dummy projection - \let\pgfpointshapexproj=\yquant@circuit@endwire@xproj% - \dimdef\wireypos{\yquant@register@get@y{#1}}% - \tikzset{/yquant/every wire}% - \csname yquant@circuit@extendwire@\wiretype\endcsname{#1}% - \fi% - \endgroup% -} - -\protected\def\yquant@circuit@endwire@xproj#1#2{% - \pgf@process{% - #2% - \pgf@x=\yquant@env@end@xpos% - }% -} - -\def\yquant@circuit@extendwire@@extract(#1,#2){% - #1% -} - % a bit faster than nested \@firstoftwo/\@secondoftwo % note \@thirdofthree is defined in the latex kernel already. \long\def\@firstofthree#1#2#3{#1}% \long\def\@secondofthree#1#2#3{#2}% +\long\def\@firstoffour#1#2#3#4{#1}% +\long\def\@secondoffour#1#2#3#4{#2}% +\long\def\@thirdoffour#1#2#3#4{#3}% +\long\def\@fourthoffour#1#2#3#4{#4}% +\long\def\@thirdandfourthoffour#1#2#3#4{#3#4}% -% quantum wire -\protected\csdef{yquant@circuit@extendwire@1}#1{% - \edef\tmp{\yquant@register@get@lastwire{#1}}% - \edef\tmp{\expandafter\@secondofthree\tmp}% - \edef\lastx{\expandafter\yquant@circuit@extendwire@@extract\tmp}% - \pgfpointshapexproj{yquantbox}{\pgfqpoint{\lastx}{\wireypos}}% - \ifdim\lastx<\pgf@x% - \edef\cmd{% - \noexpand\path [/yquant/every wire, /yquant/every qubit wire] - \tmp -- (\the\pgf@x,\the\pgf@y);% - }% - \cmd% - \fi% +% extends the wire of register #1. Assumes a node called yquantbox is set up, and the \pgfshapeclippathhorzresult was set up appropriately for this node. +\protected\def\yquant@circuit@extendwire#1{% + \begingroup% + \pgfpointanchor{yquantbox}{center}% + \edef\wirexpos{\the\pgf@x}% + \yquant@register@get@typeywire{#1}\wiretype\wireypos\wirelast% + \edef\wirexprevpos{\expandafter\@firstoffour\wirelast}% + \ifnum\wiretype=\yquant@register@type@none% + % the clippings of the previous operator will for sure not be needed, but the type might be turned into an active one, so we need the last clipping. + \yquant@register@set@lastwire{#1}{% + {\wirexprevpos}{\wirexpos}{}% + {\unexpanded\expandafter{\pgfshapeclippathhorzresult}}% + }% + \else% + % append the previous `last' clipping to the old list and insert the new one + \yquant@register@set@lastwire{#1}{% + {\wirexprevpos}{\wirexpos}% + {\unexpanded\expandafter\expandafter\expandafter{% + \expandafter\@thirdandfourthoffour\wirelast% + }% + } + {\unexpanded\expandafter{\pgfshapeclippathhorzresult}}% + }% + \fi% + \endgroup% } -% classical wire -\protected\csdef{yquant@circuit@extendwire@2}#1{% - \edef\tmp{\yquant@register@get@lastwire{#1}}% - \edef\tmpa{\expandafter\@firstofthree\tmp}% - \edef\lastxa{\expandafter\yquant@circuit@extendwire@@extract\tmpa}% - \edef\tmpb{\expandafter\@thirdofthree\tmp}% - \edef\lastxb{\expandafter\yquant@circuit@extendwire@@extract\tmpb}% - \let\cmd=\empty% - \pgfpointshapexproj{yquantbox}{\pgfqpoint{\lastxa}% - {\dimexpr\wireypos+2\pgflinewidth\relax}}% - \ifdim\lastxa<\pgf@x% - \edef\cmd{% - \tmpa -- (\the\pgf@x,\the\pgf@y)% - }% - \fi% - \pgfpointshapexproj{yquantbox}{\pgfqpoint{\lastxb}% - {\dimexpr\wireypos-2\pgflinewidth\relax}}% - \ifdim\lastxb<\pgf@x% - \eappto\cmd{% - \tmpb -- (\the\pgf@x,\the\pgf@y)% - }% - \fi% - \unless\ifx\cmd\empty% - \edef\cmd{\noexpand\path [/yquant/every wire, /yquant/every cbit wire] \cmd;}% - \cmd% - \fi% +% finishes the wire of registers 1 to #1 until x position \yquant@env@end@xpos +\protected\def\yquant@circuit@endwires#1{% + \yquant@for \yquant@circuit@endwires@i := 1 to #1 { + \yquant@draw@wire\yquant@circuit@endwires@i\yquant@env@end@xpos% + }% } -% quantum-bundle -\protected\csdef{yquant@circuit@extendwire@3}#1{% - \edef\tmp{\yquant@register@get@lastwire{#1}}% - \edef\tmpa{\expandafter\@firstofthree\tmp}% - \edef\lastxa{\expandafter\yquant@circuit@extendwire@@extract\tmpa}% - \edef\tmpb{\expandafter\@secondofthree\tmp}% - \edef\lastxb{\expandafter\yquant@circuit@extendwire@@extract\tmpb}% - \edef\tmpc{\expandafter\@thirdofthree\tmp}% - \edef\lastxc{\expandafter\yquant@circuit@extendwire@@extract\tmpc}% - \let\cmd=\empty% - \pgfpointshapexproj{yquantbox}{\pgfqpoint{\lastxa}% - {\dimexpr\wireypos+2\pgflinewidth\relax}}% - \ifdim\lastxa<\pgf@x% - \edef\cmd{% - \tmpa -- (\the\pgf@x,\the\pgf@y)% - }% - \fi% - \pgfpointshapexproj{yquantbox}{\pgfqpoint{\lastxb}{\wireypos}}% - \ifdim\lastxb<\pgf@x% - \eappto\cmd{% - \tmpb -- (\the\pgf@x,\the\pgf@y)% - }% - \fi% - \pgfpointshapexproj{yquantbox}{\pgfqpoint{\lastxc}% - {\dimexpr\wireypos-2\pgflinewidth\relax}}% - \ifdim\lastxc<\pgf@x% - \eappto\cmd{% - \tmpc -- (\the\pgf@x,\the\pgf@y)% +% outputs the wire according to its previous instructions and prepares for a change in the wire style +\protected\def\yquant@circuit@flushwire#1{% + \yquant@draw@wire{#1}{}% + \begingroup% + \yquant@register@get@lastwire{#1}\wirelast% + \yquant@register@set@lastwire{#1}{% + {\expandafter\@secondoffour\wirelast}{\expandafter\@secondoffour\wirelast}{}% + {\unexpanded\expandafter\expandafter\expandafter{% + \expandafter\@fourthoffour\wirelast% + }}% }% - \fi% - \unless\ifx\cmd\empty% - \edef\cmd{\noexpand\path [/yquant/every wire, /yquant/every qubits wire] \cmd;}% - \cmd% - \fi% + \endgroup% } % END_FOLD % BEGIN_FOLD Drawing control lines -% populates a drawing macro with the current control line with style #1 at position #2. Assumes a node called yquantbox is set up, and it is a node with appropriate projections. At the first call, \yquant@circuit@extendcontrolline@cmd must be \let to \empty and \yquant@circuit@extendcontrolline@prev to \relax. +% populates a drawing macro with the current control line with style #1 at position #2. Assumes a node called yquantbox is set up, and the \pgfshapeclippathvertresult was set up appropriately for this node. At the first call, \yquant@circuit@extendcontrolline@cmd must be \let to \empty and \yquant@circuit@extendcontrolline@prev to \relax. \protected\def\yquant@circuit@extendcontrolline#1#2{% \begingroup% \tikzset{/yquant/every control line}% \expandafter% \endgroup% + \eappto\yquant@circuit@extendcontrolline@clip{% + \unexpanded\expandafter{\pgfshapeclippathvertresult}% + }% \expandafter\@tempdima\the\pgflinewidth% \ifcase#1% % no control (or to a discarded target, which we don't do) \or% % qubit + \pgfpointanchor{yquantbox}{center}% \unless\ifx\yquant@circuit@extendcontrolline@prev\relax% - \pgfpointanchor{yquantbox}{north}% - \pgfpointshapeyproj{yquantbox}{\pgf@x=#2\relax}% \eappto\yquant@circuit@extendcontrolline@cmd{% \expandafter\@secondofthree\yquant@circuit@extendcontrolline@prev% - -- (\the\pgf@x,\the\pgf@y)% + -- (#2,\the\pgf@y)% }% \fi% \yquant@circuit@extendcontrolline@store{#2}% \or% % cbit + \pgfpointanchor{yquantbox}{center}% \unless\ifx\yquant@circuit@extendcontrolline@prev\relax% - \pgfpointanchor{yquantbox}{north}% - \pgfpointshapeyproj{yquantbox}% - {\pgf@x=\dimexpr#2-2\@tempdima\relax}% \eappto\yquant@circuit@extendcontrolline@cmd{% \expandafter\@firstofthree\yquant@circuit@extendcontrolline@prev% - -- (\the\pgf@x,\the\pgf@y)% - }% - \pgfpointshapeyproj{yquantbox}% - {\pgf@x=\dimexpr#2+2\@tempdima\relax}% - \eappto\yquant@circuit@extendcontrolline@cmd{% + -- (\the\dimexpr#2-2\@tempdima\relax,\the\pgf@y)% \expandafter\@thirdofthree\yquant@circuit@extendcontrolline@prev% - -- (\the\pgf@x,\the\pgf@y)% + -- (\the\dimexpr#2+2\@tempdima\relax,\the\pgf@y)% }% \fi% \yquant@circuit@extendcontrolline@store{#2}% \or% % quantum-bundle (very unusual, but perhaps for transversal operations?) + \pgfpointanchor{yquantbox}{center}% \unless\ifx\yquant@circuit@extendcontrolline@prev\relax% - \pgfpointanchor{yquantbox}{north}% - \pgfpointshapeyproj{yquantbox}% - {\pgf@x=\dimexpr#2-2\@tempdima\relax}% \eappto\yquant@circuit@extendcontrolline@cmd{% \expandafter\@firstofthree\yquant@circuit@extendcontrolline@prev% - -- (\the\pgf@x,\the\pgf@y)% - }% - \pgfpointshapeyproj{yquantbox}% - {\pgf@x=\dimexpr#2\relax}% - \eappto\yquant@circuit@extendcontrolline@cmd{% + -- (\the\dimexpr#2-2\@tempdima\relax,\the\pgf@y)% \expandafter\@secondofthree\yquant@circuit@extendcontrolline@prev% - -- (\the\pgf@x,\the\pgf@y)% - }% - \pgfpointshapeyproj{yquantbox}% - {\pgf@x=\dimexpr#2+2\@tempdima\relax}% - \eappto\yquant@circuit@extendcontrolline@cmd{% + -- (\the\dimexpr#2\relax,\the\pgf@y)% \expandafter\@thirdofthree\yquant@circuit@extendcontrolline@prev% - -- (\the\pgf@x,\the\pgf@y)% + -- (\the\dimexpr#2+2\@tempdima\relax,\the\pgf@y)% }% \fi% \yquant@circuit@extendcontrolline@store{#2}% \else% - \PackageError{yquant.sty}{Invalid control line type `\the#1'}% + \PackageError{yquant.sty}{Invalid control line type `#1'}% {yquant encountered an internal error.}% \fi% } \protected\def\yquant@circuit@extendcontrolline@store#1{% - \pgfpointanchor{yquantbox}{south}% - \pgfpointshapeyproj{yquantbox}% - {\pgf@x=\dimexpr#1-2\@tempdima\relax}% - \edef\yquant@circuit@extendcontrolline@prev{{(\the\pgf@x,\the\pgf@y)}}% - \pgfpointshapeyproj{yquantbox}% - {\pgf@x=#1\relax}% - \eappto\yquant@circuit@extendcontrolline@prev{{(\the\pgf@x,\the\pgf@y)}}% - \pgfpointshapeyproj{yquantbox}% - {\pgf@x=\dimexpr#1+2\@tempdima\relax}% - \eappto\yquant@circuit@extendcontrolline@prev{{(\the\pgf@x,\the\pgf@y)}}% + \edef\yquant@circuit@extendcontrolline@prev{% + {(\the\dimexpr#1-2\@tempdima\relax,\the\pgf@y)}% + {(\the\dimexpr#1\relax,\the\pgf@y)}% + {(\the\dimexpr#1+2\@tempdima\relax,\the\pgf@y)}% + }% +} + +% populates a drawing macro with the multi operation connector at position #2. Assumes a node called yquantbox is set up, and the \pgfshapeclippathvertresult was set up appropriately for this node. At the first call, \yquant@circuit@extendmultiline@cmd must be \let to \empty and \yquant@circuit@extendmultiline@prev to \relax. +\protected\def\yquant@circuit@extendmultiline#1{% + \begingroup% + \tikzset{/yquant/every multi line}% + \expandafter% + \endgroup% + \eappto\yquant@circuit@extendmultiline@clip{% + \unexpanded\expandafter{\pgfshapeclippathvertresult}% + }% + \expandafter\@tempdima\the\pgflinewidth% + \pgfpointanchor{yquantbox}{center}% + \unless\ifx\yquant@circuit@extendmultiline@prev\relax% + \eappto\yquant@circuit@extendmultiline@cmd{% + \yquant@circuit@extendmultiline@prev -- (#1,\the\pgf@y)% + }% + \fi% + \edef\yquant@circuit@extendmultiline@prev{% + (\the\dimexpr#1\relax,\the\pgf@y)% + }% } % END_FOLD @@ -364,7 +288,18 @@ % BEGIN_FOLD Helpers for operator callbacks % turn a wire into a different type \def\yquant@circuit@settype#1{% - \yquant@register@set@type{#1}\yquant@circuit@settype@to% + \yquant@circuit@flushwire{#1}% + \yquant@register@set@type{#1}{\yquant@circuit@settype@to}% +} + +\protected\long\def\yquant@circuit@setstyle#1#2{% + \yquant@circuit@flushwire{#1}% + \yquant@register@set@style{#1}{#2}% +} + +\protected\long\def\yquant@circuit@addstyle#1#2{% + \yquant@circuit@flushwire{#1}% + \yquant@register@set@style{#1}{\yquant@register@get@style{#1},#2}% } % performs an alignment of all registers specified in the argument; that is, the next operation on any of the listed registers will be after the maximum position of all of them @@ -393,19 +328,20 @@ \endgroup% } -% sets the type of a list of registers -% #1: arbitrary register list -% #2: new type -\protected\def\yquant@circuit@settypes#1#2{% +% applies an action to wires a list of registers and causes them to be redrawn +% #1: action +% #2: arbitrary register list +% #3: parameter(s) +\protected\def\yquant@circuit@actonwires#1#2#3{% \begingroup% \let\tmp=\empty% \def\do##1{% % We do not extend the wire: a register that is discarded somewhere does not make % sense, only right after some application (which is supposed to already have % extended the wire appropriately). - \appto\tmp{\yquant@register@set@type{##1}#2}% + \appto\tmp{#1{##1}#3}% }% - \dolistloop{#1}% + \dolistloop{#2}% \csxappto{\yquant@prefix draw}{\tmp}% \endgroup% } @@ -434,12 +370,12 @@ {\yquant@circuit@output@do@single{##1}{#3}}% }% }% - % \dolistloop will carry out one \expandafter on the argument; but this expansion step - % is already done. If #1 starts with \yquant@register@multi, this will be expanded once - % despite \protected, so insert some expand-to-nothing token first. \csgappto{\yquant@prefix draw}{% \yquant@circuit@output@group{#2}% } + % \dolistloop will carry out one \expandafter on the argument; but this expansion step + % is already done. If #1 starts with \yquant@register@multi, this will be expanded once + % despite \protected, so insert some expand-to-nothing token first. \dolistloop{\empty#1}% \csgappto{\yquant@prefix draw}{% \yquant@circuit@output@endgroup% @@ -447,7 +383,7 @@ } \def\yquant@circuit@output@do@multi@@extract#1#2#3#4#5{% - {#2}{#3}% + {#2}{#3}{#5}% } \protected\long\def\yquant@circuit@output@group#1{% @@ -462,15 +398,27 @@ \path (\yquant@env@end@xpos, \yquant@register@get@y{#1}) node[/yquant/every output, - /yquant/every \ifcase\yquant@register@get@type{#1} qubit\or cbit\or qubits\fi\space output] {#2}; + /yquant/every \ifcase\yquant@register@get@type{#1} nobit\or qubit\or cbit\or qubits\fi\space output] {#2}; \numdef\idx{\idx+1}% } -\long\def\yquant@circuit@output@do@multi#1#2#3{% +\long\def\yquant@circuit@output@do@multi#1#2#3#4{% + % extremely similar to \yquant@draw@multiinit + \@tempdima=-.5\dimexpr\yquant@config@register@sep\relax% + \dimdef\yquant@draw@multiinit@@min{\yquant@register@get@y{#1}-\@tempdima}% + \dimdef\yquant@draw@multiinit@@max{\yquant@register@get@y{#2}+\@tempdima}% + \dimdef\yquant@draw@multiinit@@total{% + \yquant@draw@multiinit@@max-\yquant@draw@multiinit@@min% + }% + \def\pgfdecorationsegmentaspect{0}% + \let\yquant@register@multi@contiguous=\yquant@draw@multiinit@contiguous% + \let\pgfdecorationsegmentfromto=\empty% + #3% + \edef\pgfdecorationsegmentfromto{\expandafter\@gobble\pgfdecorationsegmentfromto}% \path[/yquant/every multi output] - (\yquant@env@end@xpos, \yquant@register@get@y{#1}) -- - (\yquant@env@end@xpos, \yquant@register@get@y{#2}) - node {#3};% + (\yquant@env@end@xpos, \yquant@draw@multiinit@@min) -- + (\yquant@env@end@xpos, \yquant@draw@multiinit@@max) + node {#4};% \numdef\idx{\idx+1}% } % END_FOLD
\ No newline at end of file |