Debian Codegraph @

texmf-dist/doc/latex/qworld/qworld_en.tex

raw
1 \documentclass{article}
2 \usepackage[a4paper, textwidth=150mm]{geometry}
3
4 \usepackage{qworld}
5
6 \usepackage{bookmark}
7 \usepackage{fontspec}
8 \usepackage{pdfpages}
9
10 \usepackage{amsmath}
11 \usepackage{amssymb}
12 \usepackage{amsfonts}
13 \usepackage{mathtools}
14
15 \usepackage{ascmac}
16 \usepackage{fancybox}
17 \usepackage{float}
18
19 \usepackage{bbm}
20 \usepackage{mathrsfs}
21
22 \usepackage{changelog}
23
24 \usepackage{framed}
25 \newenvironment{longshadowbox}{%
26 \def\FrameCommand{\fboxsep=\FrameSep \shadowbox}%
27 \MakeFramed {\FrameRestore}}%
28 {\endMakeFramed}
29
30 \usepackage{url}
31 \usepackage{hyperref}
32 \hypersetup{colorlinks=true, linkcolor=blue}
33
34 \usepackage{iitem}
35
36 \usepackage{xspace}
37 \newcommand{\qworldname}{\texttt{QWorld}\xspace}
38 \newcommand{\tikzname}{Ti\emph{k}Z\xspace}
39 \newcommand{\texlivename}{\TeX{} \textsf{Live}\xspace}
40
41 \setcounter{tocdepth}{3}
42
43 \usepackage[most]{tcolorbox}
44 \newtcblisting{mybox}[2][]{
45 colback=red!5!white,
46 colframe=red!75!black,
47 fonttitle=\bfseries,
48 title=#2,
49 #1
50 }
51
52 \tcbset
53 {
54 codeinfo/.style=
55 {
56 colframe=cyan!90,
57 coltitle=cyan!60,
58 colbacktitle=black,
59 fonttitle=\small\sffamily\bfseries,
60 fontupper=\small,
61 fontlower=\small
62 },
63 exampletitleinfo/.style 2 args=
64 {
65 codeinfo,
66 title={Example \thetcbcounter : #1},
67 label={#2}
68 },
69 failurecodeinfo/.style=
70 {
71 colframe=red!90,
72 coltitle=red!60,
73 colbacktitle=black,
74 fonttitle=\small\sffamily\bfseries,
75 fontupper=\small,
76 fontlower=\small
77 },
78 failureexampletitleinfo/.style 2 args=
79 {
80 failurecodeinfo,
81 title={Failure Example \thetcbcounter : #1},
82 label={#2}
83 }
84 }
85 \newtcblisting{texexp}[1]
86 {
87 codeinfo,
88 #1
89 }
90 \newtcblisting[auto counter,number within=section]{codebox}[3][center lower,listing side text,righthand width=3.5cm,bicolor,colbacklower=white]
91 {
92 exampletitleinfo={#2}{#3},
93 breakable,
94 #1
95 }
96
97 \newtcblisting[use counter from=codebox,number within=section]{CODEBOX}[3][center lower,bicolor,colbacklower=white]
98 {
99 exampletitleinfo={#2}{#3},
100 breakable,
101 #1
102 }
103 \newtcolorbox[use counter from=codebox]{codeboxspec}[3][]
104 {
105 exampletitleinfo={#2}{#3},
106 breakable,
107 #1
108 }
109
110 \newtcblisting{texfexp}[1]
111 {
112 failurecodeinfo,
113 #1
114 }
115 \newtcblisting[auto counter,number within=section]{fcodebox}[3][center lower,listing side text,righthand width=3.5cm,bicolor,colbacklower=white]
116 {
117 failureexampletitleinfo={#2}{#3},
118 breakable,
119 #1
120 }
121
122 \newtcblisting[use counter from=fcodebox,number within=section]{FCODEBOX}[3][center lower,bicolor,colbacklower=white]
123 {
124 failureexampletitleinfo={#2}{#3},
125 breakable,
126 #1
127 }
128 \newtcolorbox[use counter from=fcodebox]{fcodeboxspec}[3][]
129 {
130 failureexampletitleinfo={#2}{#3},
131 breakable,
132 #1
133 }
134 \usepackage{xcolor}
135 \NewDocumentCommand{\showcmd}{O{\textbackslash} m O{black}}{%
136 \leavevmode%
137 \ifthenelse{\equal{#3}{new}}{%
138 \textcolor{green!50!black}{\texttt{#1#2}}%
139 }{%
140 \ifthenelse{\equal{#3}{old}}{%
141 \textcolor{red}{\texttt{#1#2}}%
142 }{%
143 \textcolor{#3}{\texttt{#1#2}}%
144 }%
145 }%
146 }
147
148 \begin{document}
149
150 % \title{
151 % \Huge\textbf{The QWorld Package}\\[4pt]
152 % \scriptsize\texttt{Version 1.1.1} \\[4pt]
153 % }
154 % \author{
155 % \textbf{Niina Ryota} \\[4pt]
156 % }
157 % \date{\today}
158 % \maketitle
159
160 \begin{titlepage}
161 \centering
162 \vspace*{2.5cm}
163
164 % パッケージ名とバージョン
165 {\Huge\bfseries The QWorld Package\par}
166 \vspace{1ex}
167
168 % {\large A \LaTeX{} package for diagrammatic reasoning\\
169 % in monoidal categories and categorical quantum mechanics\par}
170
171 {\large A \LaTeX{} package for drawing string diagrams\par in monoidal categories and quantum theory\par}
172 \vspace{2ex}
173
174 {\normalsize\ttfamily v1.1.2\par}
175
176 \vspace{3cm}
177
178 % 著者情報
179 {\large\bfseries Niina Ryota\par}
180 \vspace{1ex}
181 \href{[email protected]}
182 {\normalsize\ttfamily [email protected]}
183
184 \vfill
185
186 % 日付
187 {\today}
188 \end{titlepage}
189
190 \begin{abstract}
191 \qworldname is a \LaTeX\ package designed for efficiently rendering complex graphical calculus in monoidal categories.
192 In particular, it supports the typesetting of diagrammatic languages in category theory, quantum theory, and related fields, where diagrammatic reasoning plays a crucial role.
193 \end{abstract}
194
195 \tableofcontents
196 \section{Introduction}
197 This document aims to provide a step-by-step guide to installing and using the \qworldname package, from basic commands to advanced applications.
198 \qworldname is a \LaTeX\ package specifically designed for the typesetting of diagrammatic languages, offering an intuitive command set for describing diagrams related to monoidal categories, Frobenius structures, braiding, Hopf algebras, symmetries, dualities, pivotal structures, and dagger categories using \tikzname\cite{tikz-manual}.
199 \section{Basic Usage}
200 \subsection{Fundamental Elements}
201 The following are the most fundamental commands in the \qworldname package, forming the basis for drawing diagrams:
202 \begin{itemize}
203 \item \showcmd{q}: A canvas for placing diagram elements.
204 \item \showcmd{qbox}: Draws a box\(\q[scale=0.5]{\qbox}\).
205 \item \showcmd{qwire}: Draws a wire\(\q[scale=0.5]{\qwire}\).
206 \item \showcmd{qcirc}: Compositon.
207 \end{itemize}
208 These commands are used within the canvas environment, denoted by \verb|\q{...}|.
209 For example, writing \verb|\q{\qbox}| results in the rendering of a box\(\q[scale=0.5]{\qbox}\).\par
210 To compose \(\q[scale=0.5]{\qbox}\)and\(\q[scale=0.5]{\qbox}\), use \verb|\qcirc|.
211 This is analogous to function composition in mathematics, such as \(g\circ f\) (\verb|\(g\circ f\)|).
212 \begin{codebox}{}{Ex:78129738917}
213 \q{ \qbox \qcirc \qbox }
214 \end{codebox}
215 Additionally, placing multiple \verb|\qbox| commands in sequence results in boxes\(\q[scale=0.5]{\qbox}\)being arranged horizontally:
216 \begin{codebox}{}{boxs2}
217 \q{ \qbox \qbox \qbox }
218 \end{codebox}
219 It is also possible to compose multiple boxes using\verb|\qcirc|:
220 \begin{codebox}{}{boxsbr}
221 \q
222 {
223 \qbox \qbox \qbox
224 \qcirc
225 \qbox \qbox \qbox
226 }
227 \end{codebox}
228 Note that \verb|\n| is synonymous with\verb|\qcirc|
229 \begin{codebox}{}{boxsn}
230 \q
231 {
232 \qbox \qbox \qbox \n
233 \qbox \qbox \qbox
234 }
235 \end{codebox}
236 \begin{codebox}{}{ex:hopflink}
237 \q{
238 \qcaprev \qcap \n
239 \qwire \qbraid \qwire \n
240 \qwire \qbraid \qwire \n
241 \qcup \qcuprev
242 }
243 \end{codebox}
244 \begin{itemize}
245 \item \verb|\qcaprev| draws \(\q[scale=0.6]{\qcaprev}\).
246 \item \verb|\qcap| draws \(\q[scale=0.6]{\qcap}\).
247 \item \verb|\qwire| draws \(\q[scale=0.5]{\qwire}\).
248 \item \verb|\qbraid| draws \(\q[scale=0.5]{\qbraid}\).
249 \item \verb|\qcup| draws\(\q[scale=0.6]{\qcup}\).
250 \item \verb|\qcuprev| draws \(\q[scale=0.6]{\qcuprev}\).
251 \end{itemize}
252 As a whole, the elements are arranged in the diagram according to the order in which the commands are written.\par
253 \subsection{Mathematical Mode}
254 When writing equations that include diagrammatic language, use the mathematical mode.
255 \begin{CODEBOX}{}{IntroEx}
256 \[
257 \operatorname{Tr}\left(\q{\qbraid\qcirc\qbraid}\right)
258 =\q{
259 \qcap \qcap \n
260 \qwire \qbraidinv \qwire \n
261 \qwire \qbraidinv \qwire \n
262 \qcuprev \qcuprev
263 }
264 \]
265 \end{CODEBOX}
266
267 \subsection{Installation}
268 The style file for the \qworldname package, \showcmd[]{qworld.sty}, is available for download from the following \href{https://ctan.org/pkg/qworld}{CTAN} page:
269 \begin{center}
270 \url{https://ctan.org/pkg/qworld}
271 \end{center}
272 To use it, place the file in your \TeX\ package directory and include the following line in the preamble:
273 \begin{verbatim}
274 \usepackage{qworld}
275 \end{verbatim}
276 If your \TeX\ distribution includes \qworldname, you may also install it using a package manager such as \showcmd[]{tlmgr} or \showcmd[]{MiKTeX Console}.
277
278 \paragraph{Dependencies}
279 The package depends on the following:
280 \begin{itemize}
281 \item \tikzname, with the following libraries:
282 \iitem \showcmd[]{cd}
283 \iitem \showcmd[]{positioning}
284 \iitem \showcmd[]{arrows}
285 \iitem \showcmd[]{arrows.meta}
286 \iitem \showcmd[]{calc}
287 \iitem \showcmd[]{intersections}
288 \iitem \showcmd[]{shapes.symbols}
289 \iitem \showcmd[]{shapes.geometric}
290 \iitem \showcmd[]{shapes.misc}
291 \iitem \showcmd[]{decorations.pathreplacing}
292 \iitem \showcmd[]{decorations.markings}
293 \iitem \showcmd[]{decorations.pathmorphing}
294 \item \showcmd[]{pgffor}
295 \item \showcmd[]{ifthen}
296 \item \showcmd[]{xparse}
297 \item \showcmd[]{xfp}
298 \item \showcmd[]{xstring}
299 \end{itemize}
300 These dependencies are included by default in the \texlivename distribution, so no additional setup is required.
301 \section{Basic Customization}
302 This section explains how to customize commands in the \qworldname package.
303
304 \subsection{Identification Number}
305 All commands placed within \verb|\q{...}| are automatically assigned unique identification numbers based on their execution order.
306 For example, in the previous example \ref{boxsn}, each \verb|\qbox| is numbered as follows:
307 \[\q{\qloop[2]{\qloop[3]{\qbox[show id={true}]}\n}}\]
308 For more details, see Section \ref{subsec:show id} on page \pageref{subsec:show id}.
309 \subsection{Bounding Box}
310 \[
311 \q{
312 \qcaprev \qcap \n
313 \qwire \qbraid \qwire \n
314 \qwire \qbraid \qwire \n
315 \qcup \qcuprev
316 \qbb[red][1,2]
317 \bbsymbol{Measure}
318 \bbsymbol[W]{Output}[left]
319 \bbsymbol[NW]{Computation}[above left]
320 \bbsymbol[NE]{Physics}[above right]
321 \qbb[yellow][3,5,6,8]
322 \bbsymbol{Braid}
323 \bbsymbol[W]{Compute}[left]
324 \qbb[cyan][9,10]
325 \bbsymbol{Create}
326 \bbsymbol[W]{Initialize}[left]
327 }
328 \]
329
330 Each element has an associated bounding box. The following are examples:
331 \begin{itemize}
332 \item The bounding box of\q{\qcaprev}is visualized as\q{\qcaprev\qbball}.
333 \item The bounding box of\q{\qbraid}is visualized as\q{\qbraid\qbball}.
334 \item The bounding box of\q{\qwire}is visualized as\q{\qwire\qbball}.
335 \item The bounding box of\q{\qcuprev}is visualized as\q{\qcuprev\qbball}.
336 \end{itemize}
337 The following commands are available for visualizing bounding boxes and placing text near them:
338 \begin{itemize}
339 \item Visualization
340 \iitem \showcmd{qbb}: Displays the bounding box of a specific element.
341 \iitem \showcmd{qbball}: Displays the bounding boxes of all elements at once.
342 \iitem \showcmd{qBBall}: Displays the bounding box surrounding the entire canvas.
343 \item Placing text
344 \iitem \showcmd{bbsymbol}: Places text within a bounding box.
345 \end{itemize}
346 \begin{verbatim}
347 \qbb[<color>][<ID list>]
348 \end{verbatim}
349 \begin{itemize}
350 \item First argument (optional): Specifies the color. If omitted, no color is applied.
351 \item Second argument: Specifies a list of element IDs to display their bounding boxes.
352 \end{itemize}
353 \begin{codebox}{}{Ex:78129738920}
354 \q{\qbox\qbb[1]}
355 \end{codebox}
356 \begin{codebox}{}{ex:781297389270454}
357 \q{
358 \qcaprev \qcap \n
359 \qwire \qbraid \qwire \n
360 \qwire \qbraid \qwire \n
361 \qcup \qcuprev
362 \qbb[4,7]
363 }
364 \end{codebox}
365 \begin{CODEBOX}{}{Ex:78129738921}
366 \q{\qbox\qbox\qbox\qbox\qbox\qbox\qbb[yellow][2,...,5]}
367 \end{CODEBOX}
368 \begin{codebox}{}{Ex:74839722}
369 \q
370 {
371 \qbox\qbox\qbox\n
372 \qbox\qbox\qbox
373 \qbb[green][2,5]
374 }
375 \end{codebox}
376 \begin{codebox}{}{Ex:78129738918}
377 \q{
378 \qcaprev \qcap \n
379 \qwire \qbraid \qwire \n
380 \qwire \qbraid \qwire \n
381 \qcup \qcuprev
382 \qbb[blue][4,7]
383 }
384 \end{codebox}
385 \begin{verbatim}
386 \qbball[<color>]
387 \end{verbatim}
388 \begin{itemize}
389 \item Displays multiple bounding boxes at once (even for a single element).
390 \item Ensures that the bounding boxes of different elements are properly aligned without overlap.
391 \item The \qworldname package \textbf{minimizes the need for tedious manual coordinate adjustments} in diagram drawing.
392 \end{itemize}
393 \begin{codebox}[center lower,listing side text,righthand width=5cm,bicolor,colbacklower=white]{}{Ex:781297389270511}
394 \q{
395 \qcaprev \qcap \n
396 \qwire \qbraid \qwire \n
397 \qwire \qbraid \qwire \n
398 \qcup \qcuprev
399 \qbball
400 }
401 \end{codebox}
402
403 \begin{verbatim}
404 \qBBall[<color>]
405 \end{verbatim}
406 \begin{itemize}
407 \item Displays the bounding box surrounding all elements within the canvas.
408 \end{itemize}
409 \begin{codebox}[center lower,listing side text,righthand width=5cm,bicolor,colbacklower=white]{}{Ex:78129738916}
410 \q{
411 \qcaprev \qcap \n
412 \qwire \qbraid \qwire \n
413 \qwire \qbraid \qwire \n
414 \qcup \qcuprev
415 \qBBall
416 }
417 \end{codebox}
418 \begin{verbatim}
419 \bbsymbol[<direction>]{<text>}[<options>]
420 \end{verbatim}
421 \begin{itemize}
422 \item First argument (optional): Specifies placement direction. Options:
423 \iitem \showcmd[]{N} (North), \showcmd[]{S} (South), \showcmd[]{E} (East), \showcmd[]{W} (West),
424 \iitem \showcmd[]{NW} (Northwest), \showcmd[]{NE} (Northeast), \showcmd[]{SE} (Southeast), \showcmd[]{SW} (Southwest),
425 \iitem \showcmd[]{C} (Center).
426 \iitem Default: \showcmd[]{E} (East).
427 \item Second argument: Specifies the text to be placed.
428 \item Third argument (optional): Adjusts position (e.g., \showcmd[]{above}, \showcmd[]{below}, \showcmd[]{left}, \showcmd[]{right}).
429 \iitem Default: \showcmd[]{right}.
430 \end{itemize}
431 \begin{CODEBOX}{}{Ex:bbsymbol}
432 \q[scale=5]{
433 \qbox
434 \qbb[1]
435 \bbsymbol{East (Default)}
436 \bbsymbol[W]{West}[left]
437 \bbsymbol[N]{North}[above]
438 \bbsymbol[S]{South}[below]
439 \bbsymbol[NE]{NorthEast}[above right]
440 \bbsymbol[NW]{NorthWest}[above left]
441 \bbsymbol[SE]{SouthWest}[below right]
442 \bbsymbol[SW]{SouthEast}[below left]
443 \bbsymbol[C]{Center}[]
444 }
445 \end{CODEBOX}
446 \begin{CODEBOX}{}{Ex:78129738915}
447 \q
448 {
449 \qcaprev \qcap \n
450 \qwire \qbraid \qwire \n
451 \qwire \qbraid \qwire \n
452 \qcup \qcuprev
453 \qbb[red][1,2]
454 \bbsymbol{Measure}
455 \bbsymbol[W]{Output}[left]
456 \bbsymbol[NW]{Computation}[above left]
457 \bbsymbol[NE]{Physics}[above right]
458 \qbb[yellow][3,5,6,8]
459 \bbsymbol{Braid}
460 \bbsymbol[W]{Compute}[left]
461 \qbb[cyan][9,10]
462 \bbsymbol{Create}
463 \bbsymbol[W]{Initialize}[left]
464 }
465 \end{CODEBOX}
466
467 \subsection{Box Customization}
468 \label{subsec:boxcustomization}
469 Keys can be used to adjust the number and arrangement of the box’s boundary lines.
470 For example, the following boxes can be drawn:
471 \begin{itemize}
472 \item \(\q[scale=0.5]{\qbox[p=20,hlen=3]}\)
473 \item \(\q[scale=0.5]{\qbox[p=10,N={1,2,3,8,9,10},S={4,5,6,7},hlen=3]}\)
474 \end{itemize}
475 These keys are applicable to many elements other than wires.
476 The main keys are as follows:
477 \begin{itemize}
478 \item \showcmd[]{n}
479 \iitem The number of points on the north edge of the box\(\q[scale=0.5]{\qbox[p=2, P={}]}\)where wires\(\q[scale=0.31]{\qwire}\)can be generated (these points will be referred to as \showcmd[]{n} terminals).
480 \iitem For example, if \showcmd[]{n=3}, three points can be placed at equal intervals on the north edge of the box.
481 \iitem The default value is \showcmd[]{n=1}.
482 \iitem The point obtained by vertically moving an \showcmd[]{n} terminal to the northernmost position is called an \showcmd[]{N} terminal.
483 \iitem Both \showcmd[]{n} terminals and \showcmd[]{N} terminals are indexed as \(1,2,...\) from the west (left).
484 \iitem Generating a wire from the \(i\)-th \showcmd[]{n} terminal means connecting the \(i\)-th \showcmd[]{n} terminal and the \(i\)-th \showcmd[]{N} terminal with a line segment.
485 \item \showcmd[]{N}
486 \iitem The set of indices of the \showcmd[]{n} terminals from which wires are actually generated.
487 \iitem For example, if \showcmd[]{n=3} and \showcmd[]{N=\{2\}}, a wire can be generated from the \(2\)nd of the three \showcmd[]{n} terminals.
488 \iitem If \showcmd[]{n} is unspecified and \showcmd[]{N} is specified, \showcmd[]{n} is automatically set to \(\showcmd[]{n}\coloneq\max\showcmd[]{N}\).
489 \iitem If \showcmd[]{N} is unspecified and \showcmd[]{n} is specified, \showcmd[]{N} is automatically set to \(\showcmd[]{N}\coloneq\{1,...,\showcmd[]{n}\}\).
490 \iitem The northernmost end of a wire actually generated from an \showcmd[]{n} terminal is called the output point, or \showcmd[]{O} terminal.
491 \item \showcmd[]{s}
492 \iitem The number of points on the south edge of the box where wires can be generated (these points will be referred to as \showcmd[]{s} terminals).
493 \iitem For example, if \showcmd[]{s=4}, four points can be placed at equal intervals on the south edge of the box.
494 \iitem The default value is \showcmd[]{s=1}.
495 \iitem The point obtained by vertically moving an \showcmd[]{s} terminal to the southernmost position is called an \showcmd[]{S} terminal.
496 \iitem Both \showcmd[]{s} terminals and \showcmd[]{S} terminals are indexed as \(1,2,...\) from the west (left).
497 \iitem Generating a wire from the \(i\)-th \showcmd[]{s} terminal means connecting the \(i\)-th \showcmd[]{s} terminal and the \(i\)-th \showcmd[]{S} terminal with a line segment.
498 \item \showcmd[]{S}
499 \iitem The set of indices of the \showcmd[]{s} terminals from which wires are actually generated.
500 \iitem For example, if \showcmd[]{s=4} and \showcmd[]{S=\{1,4\}}, wires can be generated from the 1st and 4th of the four \showcmd[]{s} terminals.
501 \iitem If \showcmd[]{s} is unspecified and \showcmd[]{S} is specified, \showcmd[]{s} is automatically set to \(\showcmd[]{s}\coloneq\max\showcmd[]{S}\).
502 \iitem If \showcmd[]{S} is unspecified and \showcmd[]{s} is specified, \showcmd[]{S} is automatically set to \(\showcmd[]{S}\coloneq\{1,...,\showcmd[]{s}\}\).
503 \iitem The southernmost end of a wire actually generated from an \showcmd[]{s} terminal is called the input point, or \showcmd[]{I} terminal.
504 \item \showcmd[]{hlen}
505 \iitem The horizontal length of the bounding box.
506 \iitem For example, if \showcmd[]{hlen=2}, the horizontal length of the bounding box becomes \showcmd[]{2}.
507 \iitem With one exception, the distance between the westernmost wire and the bounding box's boundary, and the distance between the easternmost wire and the bounding box's boundary, are both \(\fpeval{0.5}\).
508 \iitem When \showcmd[]{hlen} is unspecified, the \showcmd[]{n} terminals and \showcmd[]{s} terminals are arranged with an interval of \(1\).
509 \iitem When \showcmd[]{hlen} is specified, the \showcmd[]{n} terminals and \showcmd[]{s} terminals are arranged at equal intervals in a section of length \(\showcmd[]{hlen}-1\). The spacing depends on \showcmd[]{hlen} and the number of terminals.
510 \iiitem If there is only one terminal, it is placed at the center of the section. In this case, if \(\showcmd[]{hlen}>1\), the distance between the westernmost wire and the bounding box's boundary, and the distance between the easternmost wire and the bounding box's boundary, are both \(\frac{\showcmd[]{hlen}}{2}>\fpeval{0.5}\).
511 \item \showcmd[]{vlen}
512 \iitem The vertical length (height) of the bounding box.
513 \iitem The default value is \showcmd[]{vlen=1}.
514 \item \showcmd[]{id}
515 \iitem The identifier of the box.
516 \iitem For example, if \showcmd[]{id=ID}, the following names are automatically assigned to the various points:
517 \iiitem The \(i\)-th \showcmd[]{n} terminal (counting from the west): (n-\(i\)-ID).
518 \iiitem The \(i\)-th \showcmd[]{s} terminal: (s-\(i\)-ID).
519 \iiitem The point obtained by vertically moving the \(i\)-th \showcmd[]{n} terminal to the north edge of the box: (N-\(i\)-ID).
520 \iiitem The point obtained by vertically moving the \(i\)-th \showcmd[]{s} terminal to the south edge of the box: (S-\(i\)-ID).
521 \iiitem The northwest corner of the bounding box: (NW-ID)
522 \iiitem The northeast corner of the bounding box: (NE-ID)
523 \iiitem The southwest corner of the bounding box: (SW-ID)
524 \iiitem The southeast corner of the bounding box: (SE-ID)
525 \iiitem The northernmost point of the bounding box: (N-ID)
526 \iiitem The southernmost point of the bounding box: (S-ID)
527 \iiitem The westernmost point of the bounding box: (W-ID)
528 \iiitem The easternmost point of the bounding box: (E-ID)
529 \iiitem The center of the bounding box: (C-ID)
530 \iiitem The northwest corner of the box: (nw-ID)
531 \iiitem The northeast corner of the box: (ne-ID)
532 \iiitem The southwest corner of the box: (sw-ID)
533 \iiitem The southeast corner of the box: (se-ID)
534 \iiitem The northernmost point of the box: (n-ID)
535 \iiitem The southernmost point of the box: (s-ID)
536 \iiitem The westernmost point of the box: (w-ID)
537 \iiitem The easternmost point of the box: (e-ID)
538 \iiitem The \(i\)-th output point: (O-\(i\)-ID)
539 \iiitem The \(i\)-th input point: (I-\(i\)-ID)
540 \iitem Regardless of whether it is specified, each command placed inside \showcmd{q\{...\}} is assigned an identification number. Replacing the ID part with that number refers to the same point. See section \ref{subsec:show id} for details.
541 \item \showcmd[]{p}, \showcmd[]{P}
542 \iitem For a positive integer \showcmd[]{k}, \showcmd[]{p=k} means \showcmd[]{n=k} and \showcmd[]{s=k}.
543 \iitem For a finite set of positive integers \showcmd[]{K}, \showcmd[]{P=K} means \showcmd[]{N=K} and \showcmd[]{S=K}.
544 \item \showcmd[]{name}
545 \iitem With \showcmd[]{name=<text>}, \text{<text>} is placed at the center of the box.
546 \end{itemize}
547 \begin{CODEBOX}{}{ex:boxpoints}
548 \def\pradius{0.4pt}
549 \q[scale=4]
550 {
551 \qbox
552 [
553 n=3,N={2},
554 s=4,S={1,4},
555 hlen=2,
556 vlen=2,
557 id={ID},
558 name={C-ID}
559 ]\n
560 \qbb[ID]
561 \node [above] at (NE-ID) {NE-ID};
562 \node [above] at (NW-ID) {NW-ID};
563 \node [below] at (SE-ID) {SE-ID};
564 \node [below] at (SW-ID) {SW-ID};
565 \fill (NE-ID) circle (\pradius);
566 \fill (NW-ID) circle (\pradius);
567 \fill (SE-ID) circle (\pradius);
568 \fill (SW-ID) circle (\pradius);
569 \node [above] at (ne-ID) {ne-ID};
570 \node [above] at (nw-ID) {nw-ID};
571 \node [below] at (se-ID) {se-ID};
572 \node [below] at (sw-ID) {sw-ID};
573 \fill (ne-ID) circle (\pradius);
574 \fill (nw-ID) circle (\pradius);
575 \fill (se-ID) circle (\pradius);
576 \fill (sw-ID) circle (\pradius);
577 \foreach\i in {1,...,3}
578 {
579 \symboln[\i]{n-\i-ID}[below]
580 \fill (n-\i-ID) circle (\pradius);
581 \symbolN[\i]{N-\i-ID}
582 \fill (N-\i-ID) circle (\pradius);
583 }
584 \foreach\i in {1,...,4}
585 {
586 \symbols[\i]{s-\i-ID}[above]
587 \fill (s-\i-ID) circle (\pradius);
588 \symbolS[\i]{S-\i-ID}[below]
589 \fill (S-\i-ID) circle (\pradius);
590 }
591 \draw[line width=0.2pt] (NW-ID)
592 to [bend left=60] node [fill=white, midway] {hlen} (NE-ID);
593 \draw[line width=0.2pt] (NW-ID)
594 to [bend right=60] node [fill=white, midway] {vlen} (SW-ID);
595 \draw [red, <->] (C-ID -| W-ID)
596 -- node [midway, auto, font=\footnotesize] {0.5} (C-ID -| S-1-ID);
597 \draw [red, <->] (C-ID -| S-4-ID)
598 -- node [midway, auto, font=\footnotesize] {0.5} (C-ID -| E-ID);
599 \qwire[arrowtype={loosely dotted}, dom={s-1-ID}, cod={n-1-ID}]
600 \qwire[arrowtype={loosely dotted}, dom={s-4-ID}, cod={n-3-ID}]
601 \node (O1prime) at ([shift={(0.25,0.25)}]O-1-ID){O-1-ID};
602 \draw[->,red] (O1prime) to ([shift={(0.05,0.05)}]O-1-ID);
603 \node (I1prime) at ([shift={(0.5,-0.5)}]I-1-ID){I-1-ID};
604 \node (I2prime) at ([shift={(0.5,-0.5)}]I-2-ID) {I-2-ID};
605 \draw[->,red](I1prime) to ([shift={(0.05,-0.05)}]I-1-ID);
606 \draw[->,red](I2prime) to ([shift={(0.05,-0.05)}]I-2-ID);
607 }
608 \end{CODEBOX}
609 The \verb|\qwire| \verb|arrowtype| key, as well as the \verb|dom| and \verb|cod| keys, are explained in section \ref{subsec:wirecustomization} on page \pageref{subsec:wirecustomization}.
610
611 \paragraph{Label (\showcmd{symbol})}
612 \begin{verbatim}
613 \symbolI[<number>]{<label>}[<options>]
614 \end{verbatim}
615 For example, \verb|\symbolI[2]{text}[below right, id=ID]| places the label "text" at the bottom right of the second input point (I-2-ID) of \verb|\q{\qbox[p=3, id=ID]}| (\(\q[scale=0.5]{\qbox[p=3, id=ID]}\)).
616 When no number or options are specified, the default values \(1\), below, and \verb|id=<previous>| are applied, respectively.
617 Other label display commands include:
618 \begin{verbatim}
619 \symbolS[<number>]{<label>}[<options>]
620 \end{verbatim}
621 \begin{verbatim}
622 \symbols[<number>]{<label>}[<options>]
623 \end{verbatim}
624 \begin{verbatim}
625 \symbolO[<number>]{<label>}[<options>]
626 \end{verbatim}
627 \begin{verbatim}
628 \symbolN[<number>]{<label>}[<options>]
629 \end{verbatim}
630 \begin{verbatim}
631 \symboln[<number>]{<label>}[<options>]
632 \end{verbatim}
633 \verb|\symbolS| and \verb|\symbols| place the label \textless label\textgreater at points (S-\(i\)-ID) and (s-\(i\)-ID), respectively.
634 The default number \(i\) is \(1\), and the default option is below.
635 \verb|\symbolO|, \verb|\symbolN|, and \verb|\symboln| place the label \textless label\textgreater at points (O-\(i\)-ID), (N-\(i\)-ID), and (n-\(i\)-ID), respectively.
636 The default number \(i\) is \(1\), and the default option is above.
637 \begin{codebox}[center lower,listing side text,righthand width=5cm,bicolor,colbacklower=white]{}{Ex:78129738911}
638 \q{
639 \qbox[p=5, S={1,4,5}, id=ID]
640 \symbolO{A}
641 \symbolN[3]{B}
642 \symboln[5]{C}[below left]
643 \symbolS[2]{D}
644 \symbols[3]{E}
645 \symbolI[2]{F}
646 \symbolI[3]{G}[below right]
647 }
648 \end{codebox}
649 \begin{CODEBOX}{}{Ex:78129738910}
650 \q{
651 \qbox[p=10,N={1,2,5,6,9,10}, id=ID]
652 \foreach\i in {1,...,10}
653 {
654 \symbolI[\i]{\(x_{\i}\)}
655 }
656 \foreach\j in {1,...,6}
657 {
658 \symbolO[\j]{\(y_{\j}\)}
659 }
660 }
661 \end{CODEBOX}
662
663 \subsection{Repetition}
664 \label{subsec:forloop}
665 \begin{verbatim}
666 \qloop[<number of repetitions>]{<command>}
667 \end{verbatim}
668 By using the \verb|\qloop| command, you can repeat a command the specified number of times:
669 \begin{CODEBOX}{}{Ex:78129738905}
670 \q{ \qloop[10]{\qbox} }
671 \end{CODEBOX}
672 The \verb|\qloop| command can also be used outside of \verb|\q|:
673 \begin{codebox}[listing side text,righthand width=5.5cm,bicolor,colbacklower=white]{}{Ex:781297389220930}
674 \qloop[30]{I AM BOB}
675 \end{codebox}
676
677 \subsection{Displaying Identification Numbers}
678 \label{subsec:show id}
679 Commands inside \verb|\q{...}| are automatically assigned identification numbers.
680 If \showcmd[]{show id=true} is specified, those identification numbers will be displayed.
681 \begin{CODEBOX}{}{Ex:78129738903}
682 \q{
683 \qbox[show id={true}] \qbox[show id={true}] \qbox[show id={true}]\n
684 \qbox[show id={true}] \qbox[show id={true}] \qbox[show id={true}]
685 }
686 \end{CODEBOX}
687 \begin{CODEBOX}{}{Ex:78129738902}
688 \q{
689 \qloop[10]
690 {
691 \qloop[10]
692 {
693 \qbox[show id={true}]
694 }\n
695 }\n
696 }
697 \end{CODEBOX}
698
699 \subsection{Color}
700 You can specify colors for the boxes:
701 \begin{itemize}
702 \item \showcmd[]{color}
703 \iitem The color inside the box, for example, \showcmd[]{color=green} will produce \q[scale=0.75]{\qbox[color={green}]}.
704 \item \showcmd[]{frame color}
705 \iitem The color of the box's frame, for example, \showcmd[]{frame color=cyan} will produce \q[scale=0.75]{\qbox[frame color={cyan}]}.
706 \item \showcmd[]{morphism color}
707 \iitem The color of the morphisms inside the box, for example, \showcmd[]{morphism color=red} will produce \q[scale=0.75]{\qbox[morphism color={red}, name={\(f\)}]}.
708 \end{itemize}
709 \begin{CODEBOX}{}{Ex:74839759}
710 \q[scale={\fpeval{pi}}]{
711 \qbox
712 [
713 name={\textbf{Q-WORLD}},
714 color=red,
715 frame color={green!50!black},
716 morphism color=yellow
717 ]
718 }
719 \end{CODEBOX}
720
721 \paragraph{\showcmd[]{N}, \showcmd[]{S}, Arithmetic Sequence}
722 \qworldname loads the \showcmd[]{pgffor} package, so the shorthand notation using \verb|...| can be used for lists:
723 \begin{itemize}
724 \item \(1,...,10\): An arithmetic sequence with a common difference of \(1\)
725 \item \(1,3,...,11\): An arithmetic sequence based on the first two terms with a common difference
726 \end{itemize}
727 \begin{CODEBOX}{}{Ex:74839758}
728 \q{
729 \qbox[N={1,...,10}, S={1,3,...,11}]
730 }
731 \end{CODEBOX}
732 \begin{CODEBOX}{}{Ex:74839757}
733 \q{
734 \qbox[N={1,...,4,6,8,...,20}, S={1,...,20}, hlen=10]
735 }
736 \end{CODEBOX}
737 \begin{CODEBOX}{}{Ex:74839756}
738 \q{
739 \qbox[N={1,...,4,7,10,...,19,20,21,...,25}, S={1,...,25}, hlen=10]
740 }
741 \end{CODEBOX}
742 \subsection{Relative Coordinates}
743 This is a command for specifying the position of elements relative to a given point.
744 Note that \(x\) and \(y\) do not have to be integers; expressions evaluable by \verb|\fpeval|,
745 such as \verb|2^1.5|, \verb|cos(pi)|, and \verb|sprt(2)|, are valid.
746 \begin{itemize}
747 \item \showcmd{qmv[\(x\),\(y\)]}
748 \iitem Translates by (\(x\), \(y\)).
749 \iitem The default is \(x=y=0\).
750 \item \showcmd{n[\(y\)]}
751 \iitem Moves vertically by \(y\) (\(Y\mapsto Y-y\)), and sets the X coordinate to \(0\).
752 \iitem The default is \(y=1\) , which behaves like a line break.
753 \item \showcmd{qspace[\(x\)]}
754 \iitem Moves Horizontally by \(x\).
755 \iitem The default is \(x=1\), which behaves like the spacebar.
756 \iitem This is equivalent to \showcmd{qmv[\(x\),0]}.
757 \item \showcmd{qreset[\(x\),\(y\)]}
758 \iitem Moves to the point (\(x\),\(y\)).
759 \end{itemize}
760 \[\q[scale=2.35]{
761 \fill[blue] (qworldat) circle (1pt);
762 \coordinate (I) at (qworldat);
763 \qbox
764 \fill[blue] (qworldat) circle (1pt);
765 \coordinate (II) at (qworldat);
766 \n
767 \fill[blue] (qworldat) circle (1pt);
768 \coordinate (III) at (qworldat);
769 \qspace
770 \fill[blue] (qworldat) circle (1pt);
771 \coordinate (IV) at (qworldat);
772 \qspace[0.5]
773 \fill[blue] (qworldat) circle (1pt);
774 \coordinate (V) at (qworldat);
775 \n[2]
776 \fill[blue] (qworldat) circle (1pt);
777 \coordinate (VI) at (qworldat);
778 \qmv[-2,-1]
779 \fill[blue] (qworldat) circle (1pt);
780 \coordinate (VII) at (qworldat);
781 \n
782 \fill[blue] (qworldat) circle (1pt);
783 \coordinate (VIII) at (qworldat);
784 \qspace[-3]
785 \fill[blue] (qworldat) circle (1pt);
786 \coordinate (IX) at (qworldat);
787 \qreset
788 \fill[blue] (qworldat) circle (1pt);
789 \coordinate (X) at (qworldat);
790 \qreset[-2,1]
791 \fill[blue] (qworldat) circle (1pt);
792 \coordinate (XI) at (qworldat);
793 \qbball
794 \qwireup[dom={I}, cod={II},
795 label={Auto-update}, label side={below},
796 label at={midway}, color=cyan]
797 \qwireup[dom={II},cod={III},
798 label={\showcmd{n}},
799 label side={below}, color=cyan]
800 \qwireup[dom={III},cod={IV},
801 label={\showcmd{qspace}},
802 label side={below}, color=cyan]
803 \qwireup[dom={IV},cod={V},
804 label={\showcmd{qspace[0.5]}},
805 label at={at end}, label side={above}, color=cyan]
806 \qwireup[dom={V},cod={VI},
807 label={\showcmd{n[2]}},color=cyan]
808 \qwireup[dom={VI},cod={VII},
809 label={\showcmd{qmv[-2,-1]}},color=cyan]
810 \qwireup[dom={VII},cod={VIII},
811 label={\showcmd{n}},color=cyan]
812 \qwireup[dom={VIII},cod={IX},
813 label={\showcmd{qspace[-3]}},
814 label side={below},color=cyan]
815 \qwireup[dom={IX},cod={X},
816 label={\showcmd{qreset}},
817 label side=left, color=cyan]
818 \qwireup[dom={X},cod={XI},
819 label={\showcmd{qreset[-2,1]}},
820 label side=left,
821 label at={near start}, color=cyan]
822 \draw[help lines] (-4,-6) grid (2,2);
823 }\]
824
825 \subsection{Absolute Coordinates}
826 By using the \showcmd[]{at} key, positions can be specified with absolute coordinates.
827 \verb|\q{\qbox[at={2,3}]}| is equivalent to \verb|\q{\qreset[2,3]\qbox}|.
828 \begin{CODEBOX}{Absolute Coordinates}{Ex:74839754}
829 \q{
830 \coordinate (a) at (0,{\fpeval{2*sqrt(3)}});
831 \qbox[at=a]
832 \qbox[at={-2,0}]
833 \qbox[at={2,0}]
834 \fill[red] (a) circle (2pt);
835 \fill[red] (-2,0) circle (2pt);
836 \fill[red] (2,0) circle (2pt);
837 \node[below left] at (a) {a};
838 \node[below left] at (-2,0) {(-2,0)};
839 \node[below left] at (2,0) {(2,0)};
840 }
841 \end{CODEBOX}
842 The \TeX\ language is Turing complete\footnote{For example, the ability to simulate a Turing machine is demonstrated in the example from LiteratePrograms\cite{literateprograms}. Additionally, an article on Overleaf introduces a method to compute Fibonacci numbers using \TeX, illustrating the practical utility of its Turing completeness \cite{overleaf}}.
843 In other words, every algorithm that exists in the world can be expressed in \TeX.
844 Physical simulations (such as weather forecasting or chemical reaction prediction),
845 economic simulations (such as investment strategies),
846 and even artificial intelligence learning algorithms (such as image recognition or natural language processing)------\par
847 all of these can be implemented in \TeX.\par
848 However, how many people would actually want to do that?
849 I for one, wouldn't want to write even a sorting algorithm in \TeX.
850 That's like trying to create Super Mario in spreadsheet.\par
851 However, there is a twist.\par
852 I had a ``revelation''\footnote{Original source: On January 20, 2011, an algorithm called "Sleep Sort" was posted on the anonymous message board 4chan \cite{geniussorting, gfxhatena}. This algorithm uses a \showcmd[]{Bash} script to execute each input value as a thread asynchronously, sorting the list by the timing of each thread’s completion (the specified "sleep" time).}.
853 And with the \showcmd[]{at} key, I created a sorting algorithm.
854 \begin{codebox}{}{Ex:genius}
855 \newcommand{\AtSort}[1][1]{
856 \q{
857 \foreach \i in {#1}
858 {
859 \qbox[name={\i}, at={0, -\i}]\n
860 }
861 }
862 }
863 \AtSort[4,1,3,-1,6,2]
864 \end{codebox}
865 It works. Indeed, it works.\par
866 But there is one problem.
867 \textbf{If the list contains elements with large absolute values, the output will overflow the page}.
868 \subsection{Wire Customization}
869 \label{subsec:wirecustomization}
870 \[
871 \q{
872 \def\maxi{11}
873 \foreach \i in {0,...,\maxi}
874 {
875 \qwireup[dom={0,0}, cod={{\fpeval{\i*360/(\maxi+1)}}:3}]
876 \node at ({\fpeval{\i*360/(\maxi+1)}}:3.6) {\showcmd[]{cod}\i};
877 }
878 }
879 \]
880 Among the keys of the box \(\q[scale=0.5]{\qbox}\) introduced in section \ref{subsec:boxcustomization}, \showcmd[]{id} and \showcmd[]{vlen} are also valid for wires.
881 The basic keys specific to wires are as follows:
882 \begin{itemize}
883 \item \showcmd[]{dom}: input point.
884 \item \showcmd[]{cod}: output point.
885 \iitem Default value is the position obtained by moving \showcmd[]{dom} \(1\) unit vertically to the north.
886 \item \showcmd[]{label}: Label for the wire.
887 \item \showcmd[]{label at}: Position of the label on the wire.
888 \iitem The default is midway.
889 \item \showcmd[]{label side}: Relationship between the label and the wire.
890 \iitem The default is right.
891 \end{itemize}
892 \begin{codebox}{}{ex:781297389260951}
893 \q{
894 \qbox[n=3,hlen=1.5]
895 \qbox[at={1,2}, s=2, hlen=1.5]
896 \qbox[at={-1,4}, s=2, hlen=1.5]
897 \qwire[dom={N-1-1}, cod={S-1-3}]
898 \qwire[dom={N-2-1}, cod={S-1-2}]
899 \qwire[dom={N-3-1}, cod={S-2-2}]
900 \qwire[dom={N-1-2}, cod={S-2-3}]
901 }
902 \end{codebox}
903 \begin{CODEBOX}{}{ex:193477432894112213}
904 \q{
905 \def\maxi{11}
906 \foreach \i in {0,...,\maxi}
907 {
908 \qwireup[dom={0,0}, cod={{\fpeval{\i*360/(\maxi+1)}}:2}]
909 \node at ({\fpeval{\i*360/(\maxi+1)}}:2.5) {\texttt{cod} \i};
910 }
911 }
912 \end{CODEBOX}
913 The bounding box of the wire \q[scale=0.6]{\qwire} is the same as that of \q[scale=0.5]{\qbox}:
914 \begin{codebox}{}{ex:781297389220926}
915 \q{
916 \qwire\qbox\qwire\n
917 \qbox\qwire\qbox
918 \qbball
919 }
920 \end{codebox}
921 The bounding box of the wire matches that of a box with \showcmd[]{dom} as the input point and \showcmd[]{cod} as the output point:
922 \begin{itemize}
923 \item \(\q[scale=0.5]{\qwire}\) and \(\q[scale=0.5]{\qbox}\)
924 \item \(\q[scale=0.5]{\qwire[dom={0,0},cod={1,1}]}\) and \(\q[scale=0.5]{\qbox[p=2,S={1},N={2}]}\)
925 \end{itemize}
926
927 \begin{CODEBOX}{}{Ex:78129738909}
928 \q[scale=3]{
929 \coordinate (A) at (0,0);
930 \coordinate (B) at (2,3);
931 \qwire[dom=A, cod={1,1}, label={wire1}, label side={left}]
932 \qwire[dom={1,1}, cod=B, label={wire2}, label at={near end}]
933 \node[fill=red, circle] at (A) {A};
934 \node[fill=green, circle] at (B) {B};
935 \node[fill=yellow, circle] at (1,1) {(1,1)};
936 \qbball
937 }
938 \end{CODEBOX}
939
940 \begin{CODEBOX}{}{Ex:78129738901}
941 \q{
942 \qloop[5]{
943 \qloop[10]{
944 \qbox[show id={true}]
945 }\n
946 }\n
947 \qspace[3]\qbox[s=2,show id={true},id={ego1}]\n\n
948 \qspace[6]\qbox[n=2,show id={true},id={ego2}]\n\n
949 \qloop[5]{
950 \qloop[10]{
951 \qbox[show id={true}]
952 }\n
953 }
954 \qwire[dom={O-1-55},cod={I-1-51}]
955 \qwire[dom={O-1-60},cod={I-1-52}]
956 \qwire[dom={O-1-51},cod={I-1-45}]
957 \qwire[dom={O-1-52},cod={I-2-51}]
958 \qwire[dom={O-2-52},cod={I-1-48}]
959 }
960 \end{CODEBOX}
961
962 \paragraph{arrowtype}
963 The wire style is specified using the \showcmd[]{arrowtype} key.
964 \begin{codebox}[center lower,listing side text,righthand width=5cm,bicolor,colbacklower=white]{}{wirearrowtype}
965 \q{
966 \qwire[arrowtype=dotted]
967 \qwire[arrowtype=dashed]
968 \qwire[arrowtype={dash dot}]
969 \qwire[arrowtype={dash dot dot}]
970 \qwire[arrowtype={densely dotted}]
971 \qwire[arrowtype={loosely dotted}]
972 }
973 \end{codebox}
974
975 \begin{codebox}[center lower,listing side text,righthand width=5cm,bicolor,colbacklower=white]{}{boxarrowtype}
976 \q{
977 \qbox[dom arrowtype={dotted}]
978 \qbox[cod arrowtype={dotted}]
979 \qbox[arrowtype={dotted}]
980 }
981 \end{codebox}
982
983 \begin{codebox}[center lower,listing side text,righthand width=5cm,bicolor,colbacklower=white]{}{spiderarrowtype}
984 \q{
985 \qspider[dom arrowtype={dotted}]
986 \qspider[cod arrowtype={dotted}]
987 \qspider[arrowtype={dotted}]
988 }
989 \end{codebox}
990
991 \subsection{Canvas}
992 \begin{verbatim}
993 \q[option]
994 {
995 command 1
996 command 2
997 ...
998 }
999 \end{verbatim}
1000 The entire diagram can be transformed useing canvas options.
1001 \begin{codebox}{}{Ex:74839753}
1002 \q[scale=2,rotate=30]{\qbox}
1003 \end{codebox}
1004 It is also possible to \textbf{slant} the canvas.
1005 \begin{CODEBOX}{}{Ex:74839752}
1006 \def\anglerot{-55}
1007 \tikzset
1008 {
1009 my slant style/.style={
1010 yslant=-cot(\anglerot),
1011 xscale=sin(-\anglerot)
1012 }
1013 }
1014 \q[my slant style]
1015 {
1016 \qcaprev\qcap\n
1017 \qwire\qbraidinv\qwiredown\n
1018 \qwiredown\qbraidinv\qwire\n
1019 \qcup\qcuprev
1020 \qBBall
1021 }
1022 \end{CODEBOX}
1023 \begin{CODEBOX}{}{Ex:74839751}
1024 \def\anglerot{-60}
1025 \tikzset
1026 {
1027 my slant style/.style={
1028 yslant=-cot(\anglerot),
1029 xscale=sin(-\anglerot)
1030 }
1031 }
1032 \[
1033 \q[my slant style]{
1034 \qbraid\qwire\n
1035 \qwire\qbraid\n
1036 \qbraid\qwire
1037 }=\q[my slant style]{
1038 \qbraid\qwire\n
1039 \qwire\qwire\qwire\n
1040 \qbraid[num R=2]
1041 \qbb[red][1]
1042 \qbb[cyan][6]
1043 }=\q[my slant style]{
1044 \qbraid[ num R=2]\n
1045 \qwire\qwire\qwire\n
1046 \qwire\qbraid
1047 \qbb[red][6]
1048 \qbb[cyan][1]
1049 }=\q[my slant style]{
1050 \qwire\qbraid\n
1051 \qbraid\qwire\n
1052 \qwire\qbraid
1053 }
1054 \]
1055 \end{CODEBOX}
1056
1057 \section{Monoidal Categories and \qworldname}
1058 In this section, we explore how to typeset graphical calculus using the \qworldname package, examining its different applications and practical usage.\par
1059 While \qworldname can handle diagrams independently, it is often beneficial to combine it with packages like \showcmd[]{amsmath}, \showcmd[]{amssymb}, and \showcmd[]{mathtools} for more flexible mathematical expressions.
1060 This section demonstrates how to typeset actual graphical calculus in \TeX\ while introducing the functionalities of \qworldname.\par
1061 To reproduce the examples in this section, please ensure that the following packages are loaded:
1062 \begin{verbatim}
1063 \usepackage{amsmath, amssymb, mathtools}
1064 \usepackage{qworld}
1065 \end{verbatim}
1066 \subsection{Category}
1067 \begin{codebox}{Domain}{ex:dom2}
1068 \[
1069 \operatorname{dom}\left(
1070 \q{
1071 \qbox[name={\(f\)}]
1072 \symbolI{\(x\)}
1073 \symbolO{\(y\)}
1074 }
1075 \right)=\q{\qwire[label={\(x\)}]}
1076 \]
1077 \end{codebox}
1078 \begin{codebox}{Codomain}{ex:cod2}
1079 \[
1080 \operatorname{cod}\left(
1081 \q{
1082 \qbox[name={\(f\)}]
1083 \symbolI{\(x\)}
1084 \symbolO{\(y\)}
1085 }
1086 \right)=\q{\qwire[label={\(y\)}]}
1087 \]
1088 \end{codebox}
1089
1090 \begin{codebox}{(Vertical) Compositon}{def:composite}
1091 \[
1092 \q{
1093 \qbox[name={\(f\)}]\qcirc\qbox[name={\(g\)}]
1094 }=\q{\qbox[name={\(f\circ g\)}]}
1095 \]
1096 \end{codebox}
1097 \begin{CODEBOX}{Associativity}{Ex:74839750}
1098 \[
1099 \forall\q{\qbox[name={\(h\)}] \symbolI{\(z\)} \symbolO{\(w\)}}
1100 \forall\q{\qbox[name={\(g\)}] \symbolI{\(y\)} \symbolO{\(z\)}}
1101 \forall\q{\qbox[name={\(f\)}] \symbolI{\(x\)} \symbolO{\(y\)}}
1102 \q{
1103 \qbox[name={\(h\)}]\qcirc\qbox[name={\(g\)}]\qcirc\qbox[name={\(f\)}]
1104 \qbb[2,3]
1105 }
1106 =
1107 \q{
1108 \qbox[name={\(h\)}]\qcirc\qbox[name={\(g\)}]\qcirc\qbox[name={\(f\)}]
1109 \qbb[1,2]
1110 }
1111 \]
1112 \end{CODEBOX}
1113 \begin{CODEBOX}{Identity Law}{IdentityLaw}
1114 \begin{equation}
1115 \label{law:identity}
1116 \forall\q
1117 {
1118 \qbox[name={\(f\)}]
1119 \symbolS{\(x\)}
1120 \symbolN{\(y\)}
1121 }\colon
1122 \q{
1123 \qwire[label={\(y\)}]\n
1124 \qbox[name={\(f\)}]
1125 }=\q{
1126 \qbox[name={\(f\)}]
1127 }=\q{
1128 \qbox[name={\(f\)}]\n
1129 \qwire[label={\(x\)}]
1130 }
1131 \end{equation}
1132 \end{CODEBOX}
1133 \subsubsection{Object Information and Color}
1134 \label{subsubsec:objectcolor}
1135 In categorical string diagrammatics, identity morphism are typically represented as simple wires.
1136 To make it visually evident which object an identity morphism corresponds to, a method has been introduced that assigns a \textbf{distinct color to each object}.
1137 This allows object information to be encoded directly on the wire, providing intuitive visual cues for distinguishing between objects-especially in diagrams composed entirely of curved structures.
1138 \par
1139 The theoretical foundation of this approach lies in the categorical fact that \textbf{every morphism has a uniquely defined domain and codomain object}.
1140 Since this structure is intrinsic to any category, representing objects diagrammatically via the visual attribute of ``color'' is fully justified.
1141 \par
1142 In diagrams involving braidings (see Section \ref{subsubsec:braid:color}, page \pageref{subsubsec:braid:color}) or duality structures (see Section \ref{subsubsec:duality:color}, page \pageref{subsubsec:duality:color}),
1143 color serves as an effective aid in supporting accurate interpretation.
1144 \par
1145 From this perspective, an object may be regarded as something that manifests as a color decorating a wire.
1146 The following example illustrates how the domain and codomain colors of morphisms contribute to visually validating the composability of morphisms:
1147 \begin{CODEBOX}[bicolor,colbacklower=white]{}{objectcolor}
1148 \(\operatorname{dom}\) is a function that identifies the domain color
1149 \(\q{\qwire[color=red]}\)
1150 of the morphism
1151 \(\q{\qbox[name={\(f\)}, dom color=red, cod color=cyan]}\),
1152 and \(\operatorname{cod}\) similarly identifies the codomain color
1153 \(\q{\qwire[color=cyan]}\).\par
1154 On the page, the codomain color of
1155 \(\q{\qbox[name={\(f\)}, dom color=purple, cod color=teal]}\)
1156 and the domain color of
1157 \(\q{\qbox[name={\(g\)}, dom color=teal, cod color=orange]}\)
1158 are explicitly shown to be the same via color matching.
1159 Only when this condition holds is the vertical composition
1160 \[
1161 \q{
1162 \qbox[name={\(g\)}, dom color=teal, cod color=orange]
1163 \n
1164 \qbox[name={\(f\)}, dom color=purple, cod color=teal]
1165 }
1166 \]
1167 accepted as a type-consistent operation.
1168 \end{CODEBOX}
1169 \subsection{Monoidal Category}
1170 \begin{CODEBOX}{Tensor Product, Horizontal (Parallel) Compositon}{monoidalproduct}
1171 \[
1172 \q
1173 {
1174 \qbox[name={\(f\)}] \qbox[name={\(g\)}]
1175 \symbolO{\(Y_1\)}[id=1] \symbolO{\(Y_2\)}
1176 \symbolI{\(X_1\)}[id=1] \symbolI{\(X_2\)}
1177 }
1178 =\q
1179 {
1180 \qbox[name={\(f\otimes g\)}, p=2]
1181 \symbolO{\(Y_1\)} \symbolO[2]{\(Y_2\)}
1182 \symbolI{\(X_1\)} \symbolI[2]{\(X_2\)}
1183 }
1184 =\q
1185 {
1186 \qbox[name={\(f\otimes g\)}]
1187 \symbolO{\(Y_1\otimes Y_2\)}
1188 \symbolI{\(X_1\otimes X_2\)}
1189 }
1190 \]
1191 \end{CODEBOX}
1192 \subsubsection{Interchange Law}
1193 \begin{CODEBOX}{Interchange Law (Covariant Functoriality of \(\bigotimes\))}{InterchangeLaw}
1194 \begin{equation}
1195 \label{law:interchange}
1196 \q
1197 {
1198 \qbox[name={\(f_2\)}]\qbox[name={\(g_2\)}]\n
1199 \qbox[name={\(f_1\)}]\qbox[name={\(g_1\)}]
1200 \qbb[1,2]
1201 \qbb[3,4]
1202 }
1203 =\q
1204 {
1205 \qbox[name={\(f_2\)}]\qbox[name={\(g_2\)}]\n
1206 \qbox[name={\(f_1\)}]\qbox[name={\(g_1\)}]
1207 \qbb[2,4]
1208 \qbb[1,3]
1209 }
1210 \end{equation}
1211 \end{CODEBOX}
1212
1213 \begin{CODEBOX}{Unit Object}{Ex:74839744}
1214 \begin{gather}
1215 \q{ \qwire[arrowtype=dotted]}
1216 =\q{ \qunitob \qbball }\\
1217 \q{ \qunitob \qbox[name={\(f\)}] \qbball }
1218 =\q{ \qbox[name={\(f\)}] }
1219 =\q{ \qbox[name={\(f\)}] \qunitob \qbball }\label{cond:unitob}
1220 \end{gather}
1221 \end{CODEBOX}
1222 \begin{CODEBOX}{}{Ex:74839743}
1223 \[
1224 \q{\qunitob\qbball}
1225 =\q{\qloop[2]{\qunitob}\qbball}
1226 =\q{\qloop[3]{\qunitob}\qbball}
1227 =\cdots
1228 \]
1229 \end{CODEBOX}
1230
1231 \subsection{Special Boxes}
1232
1233 \begin{itemize}
1234 \item \showcmd{qstate}: \(\q[scale=0.5]{\qstate}\) (Zero Input).
1235 \item \showcmd{qeffect}: \(\q[scale=0.5]{\qeffect}\) (Zero Output).
1236 \item \showcmd{qscalar}: \(\q[scale=0.5]{\qscalar}\) (Zero Input, Zero Output).
1237 \item \showcmd{qasym}: \(\q[scale=0.5]{\qasym}\) (Asymmetric Box).
1238 \item \showcmd{qtrans}: \(\q[scale=0.5]{\qtrans}\) (Transpose Box). Section \ref{subsubsec:transpose} on page \pageref{subsubsec:transpose}.
1239 \item \showcmd{qadj}: \(\q[scale=0.5]{\qadj}\) (Adjoint Box). Section \ref{subsubsec:adjoint} on page \pageref{subsubsec:adjoint}.
1240 \item \showcmd{qconj}: \(\q[scale=0.5]{\qconj}\) (Conjugate Box). Section \ref{subsubsec:conj} on page \pageref{subsubsec:conj}.
1241 \end{itemize}
1242 \subsubsection{Zero Input}
1243 \label{subsubsec:zeroinput}
1244 \begin{codebox}{}{def:state}
1245 \q{\qstate}
1246 \end{codebox}
1247 \subsubsection{Zero Output}
1248 \label{subsubsec:zerooutput}
1249 \begin{codebox}{}{def:effect}
1250 \q{\qeffect}
1251 \end{codebox}
1252 \subsubsection{Zero Input, Zero Output}
1253 \label{subsubsec:zeroinputoutput}
1254 \begin{codebox}{}{def:scalar}
1255 \q{\qscalar}
1256 \end{codebox}
1257 \paragraph{\(\q[scale=0.4]{\qeffect\qstate\qwire[dom={O-1-2}, cod={1,2}]\qwire[dom={1,-1}, cod={I-1-1}]}=\q[scale=0.4]{\qwire[vlen=0.5]\n\qstate\n\qeffect\n[0.5]\qwire[vlen=0.5]}=\q[scale=0.4]{\qstate\qeffect\qwire[dom={O-1-1}, cod={1,2}]\qwire[dom={1,-1}, cod={I-1-2}]}\)}
1258 \begin{CODEBOX}{}{coherence:unitor}
1259 \[
1260 \q{
1261 \qeffect\qstate
1262 \qwire[dom={O-1-2}, cod={1,2}]
1263 \qwire[dom={1,-1}, cod={I-1-1}]
1264 }=\q{
1265 \qwire[arrowtype=dotted]\qwire\n
1266 \qeffect\qstate\n
1267 \qwire\qwire[arrowtype=dotted]
1268 }\stackrel{\text{(\ref{law:interchange}, \ref{law:identity})}}{=}\q{
1269 \qwire[arrowtype=dotted]\qstate\n
1270 \qeffect\qwire[arrowtype=dotted]
1271 }\stackrel{\text{(\ref{law:interchange}, \ref{cond:unitob})}}{=}\q{\qstate\n\qeffect}
1272 \]
1273 \end{CODEBOX}
1274 \begin{CODEBOX}{Matrix Representation}{matrixrepre}
1275 \begin{align*}
1276 \q{\qbox[name={\(f\)}]}
1277 &=\sum\limits_{i,j}
1278 \left(
1279 \q{
1280 \qeffect[name={\(w_j^{\dagger}\)}]\n
1281 \qbox[name={\(f\)}]\n
1282 \qstate[name={\(v_i\)}]\n
1283 }\q{
1284 \qstate[name={\(w_j\)}]\n
1285 \qeffect[name={\(v_i^{\dagger}\)}]
1286 }
1287 \right)
1288 =\sum\limits_{i,j}\left(
1289 \q{
1290 \qscalar[name={\(w_j^{\dagger}\circ f\circ v_i\)}]
1291 }
1292 \q{
1293 \qstate[name={\(w_j\)}]\n
1294 \qeffect[name={\(v_i^{\dagger}\)}]
1295 }
1296 \right)\\
1297 &=\begin{pmatrix}
1298 \q{\qscalar[name={\(w_1^{\dagger}\circ f\circ v_1\)}]}&&\cdots&&\q{\qscalar[name={\(w_1^{\dagger}\circ f\circ v_{m}\)}]}\\
1299 &\ddots&&&\\
1300 \vdots& &\q{\qscalar[name={\(w_j^{\dagger}\circ f\circ v_i\)}]}& &\vdots\\
1301 &&&\ddots&\\
1302 \q{\qscalar[name={\(w_n^{\dagger}\circ f\circ v_1\)}]}&&\cdots&&\q{\qscalar[name={\(w_n^{\dagger}\circ f\circ v_m\)}]}
1303 \end{pmatrix}
1304 \end{align*}
1305 \end{CODEBOX}
1306
1307 \subsection{Monoid Object}
1308 \label{subsec:monoid}
1309 \begin{itemize}
1310 \item \showcmd{qmul}: \(\q[scale=0.5]{\qmul}\)
1311 \iitem \showcmd[]{hlen=2}: \(\q[scale=0.5]{\qmul[hlen=2]}\)
1312 \item \showcmd{qcomul}: \(\q[scale=0.5]{\qcomul}\)
1313 \iitem \showcmd[]{hlen=2}: \(\q[scale=0.5]{\qcomul[hlen=2]}\)
1314 \item \showcmd{qunit}: \(\q[scale=0.5]{\qunit}\)
1315 \item \showcmd{qcounit}: \(\q[scale=0.5]{\qcounit}\)
1316 \item \showcmd{qspider}: \(\q[scale=0.5]{\qspider}\)
1317 \end{itemize}
1318
1319 \begin{CODEBOX}{Associativity}{AssociateLaw}
1320 \begin{equation}
1321 \label{law:associate}
1322 \q{
1323 \qspace[0.5]\qmul[hlen=2]\n
1324 \qmul[hlen=2]\qspace[-0.5]\qwire
1325 }=\q{
1326 \qmul[hlen=2]\n
1327 \qwire\qspace[-0.5]\qmul[hlen=2]
1328 }
1329 \end{equation}
1330 \end{CODEBOX}
1331 \begin{CODEBOX}{Unitality}{UnitLaw}
1332 \begin{equation}
1333 \label{law:unit}
1334 \q{
1335 \qmul[hlen=2]\n
1336 \qwire\qunit
1337 }=\q{\qwire[vlen=2]}
1338 =\q{
1339 \qmul[hlen=2]\n
1340 \qunit\qwire
1341 }
1342 \end{equation}
1343 \end{CODEBOX}
1344 \begin{CODEBOX}{Coassociativity}{CoassociateLaw}
1345 \begin{equation}
1346 \label{law:coassociate}
1347 \q{
1348 \qcomul[hlen=2]\qspace[-0.5]\qwire\n
1349 \qspace[0.5]\qcomul[hlen=2]
1350 }
1351 =\q{
1352 \qwire\qspace[-0.5]\qcomul[hlen=2]\n
1353 \qcomul[hlen=2]
1354 }
1355 \end{equation}
1356 \end{CODEBOX}
1357 \begin{CODEBOX}{Counitality}{CounitLaw}
1358 \begin{equation}
1359 \label{law:counit}
1360 \q{
1361 \qcounit\qwire\n
1362 \qcomul[hlen=2]
1363 }
1364 =\q{\qwire[vlen=2]}
1365 =\q{
1366 \qwire\qcounit\n
1367 \qcomul[hlen=2]
1368 }
1369 \end{equation}
1370 \end{CODEBOX}
1371
1372 \subsubsection{Frobenius Law}
1373 \begin{FCODEBOX}{Frobenius Law}{FrobeniusLaw}
1374 \[
1375 \q{
1376 \qwire\qmul[color=black]\n
1377 \qcomul\qwire
1378 }=\q{
1379 \qcomul\n
1380 \qmul[color=black]
1381 }=\q{
1382 \qmul[color=black]\qwire\n
1383 \qwire\qcomul
1384 }
1385 \]
1386 \end{FCODEBOX}
1387 Although it is mentioned as a ``Failure Example'', in reality, the Frobenius law is accurately described.
1388 Rather, since the spacing between all the wires is maintained as integer values, adjustment during vertical composition becomes easier, and in some cases, no adjustment may be necessary.
1389 This is merely a matter of preference.
1390 The default drawing results of \verb|\qmul| and \verb|\qcomul|, which are \q[scale=0.5]{\qmul} and \q[scale=0.5]{\qcomul}, are remnants of the default drawing results of \verb|\qbox[s=2]| and \verb|\qbox[n=2]|, which are \q[scale=0.5]{\qbox[s=2]} and \q[scale=0.5]{\qbox[n=2]}.
1391 For adjustments in such cases, the adjustment key \verb|hlen| is available:
1392 \begin{CODEBOX}{Frobenius Law}{FrobeniusLaw2}
1393 \[
1394 \q{
1395 \qwire\qmul[hlen=2,color=black]\n
1396 \qcomul[hlen=2]\qwire
1397 }=\q{
1398 \qcomul[hlen=2]\n
1399 \qmul[hlen=2,color=black]
1400 }=\q{
1401 \qmul[hlen=2,color=black]\qwire\n
1402 \qwire\qcomul[hlen=2]
1403 }
1404 \]
1405 \end{CODEBOX}
1406 The command \verb|\qspider| is the same as \verb|\qbox|, except that the nodes are circles rather than boxes.
1407 \begin{codebox}{}{spider781297389240521}
1408 \[\q{\qspider}\]
1409 \[\q{\qspider[n=0]}\]
1410 \[\q{\qspider[n=0,s=4]}\]
1411 \[\q{\qspider[n=2,s=4]}\]
1412 \[\q{\qspider[N={1,4},s=4]}\]
1413 \[\q{\qspider[N={2,3},s=4]}\]
1414 \[\q{\qspider[p=3,N={2},S={1,3}]}\]
1415 \[\q{\qspider[p=3,N={2},S={1,3},hlen=2]}\]
1416 \[\q{\qspider[n=1,s=2,hlen=2]}\]
1417 \end{codebox}
1418
1419 \begin{CODEBOX}{}{spider781297389270738}
1420 \[
1421 \q{
1422 \qspider[n=2, s=4, hlen=4]\qwire\qwire\n
1423 \qwire\qwire\qspider[n=4, s=2, hlen=4]
1424 }=\q{\qspider[p=4]}\]
1425 \end{CODEBOX}
1426
1427 \subsection{Braiding}
1428 \label{subsec:braidedcategory}
1429 \begin{itemize}
1430 \item \showcmd{qbraid}: \(\q[scale=0.5]{\qbraid}\)
1431 \item \showcmd{qbraidinv}: \(\q[scale=0.5]{\qbraidinv}\)
1432 \item \showcmd{qsym}: \(\q[scale=0.5]{\qsym}\)
1433 \end{itemize}
1434
1435 \paragraph{\showcmd[]{num L} and \showcmd[]{num R}}
1436
1437 For the commands \verb|\qbraid|, \verb|\qbraidinv|, and \verb|\qsym|, \showcmd[]{num L} specifies the number of wires on the left side, and \showcmd[]{num R} specifies the number of wires on the right side.
1438 For example, specifies \showcmd[]{num L=3} and \showcmd[]{num R=2} will result in the diagram \q{\qbraid[num L=3, num R=2]}.
1439 The default value for both is \(1\).
1440
1441 \begin{CODEBOX}{Hexagon Equations}{hexagon}
1442 \begin{equation}
1443 \label{eq:hexagon}
1444 \q
1445 {
1446 \qbraid[num R=2,,hlen=2,vlen=2]
1447 }=\q
1448 {
1449 \qwire\qbraid\n
1450 \qbraid\qwire
1451 }
1452 \qquad
1453 \q
1454 {
1455 \qbraid[num L=2,,hlen=2,vlen=2]
1456 }
1457 =\q
1458 {
1459 \qbraid\qwire\n
1460 \qwire\qbraid
1461 }
1462 \end{equation}
1463 \end{CODEBOX}
1464 \paragraph{\({\q[scale=0.5]{\qbraid}}^{-1}=\q[scale=0.5]{\qbraidinv}\)}
1465 \begin{CODEBOX}{}{braidisom2}
1466 \begin{equation}
1467 \label{eq:inverse:braid}
1468 \q
1469 {
1470 \qbraidinv\n
1471 \qbraid
1472 }
1473 =\q
1474 {
1475 \qwire[vlen=2]\qwire[vlen=2]
1476 }
1477 \qquad
1478 \q
1479 {
1480 \qbraid\n
1481 \qbraidinv
1482 }
1483 =\q
1484 {
1485 \qwire[vlen=2]\qwire[vlen=2]
1486 }
1487 \end{equation}
1488 \end{CODEBOX}
1489 \begin{CODEBOX}{Naturality of the Braid (Being a Natural Transformation)}{braidnatural}
1490 \begin{equation}
1491 \label{cond:naturality:braid}
1492 \q
1493 {
1494 \qbraid\n
1495 \qbox[name={\(f\)}]\qbox[name={\(g\)}]
1496 }
1497 =\q
1498 {
1499 \qbox[name={\(g\)}]\qbox[name={\(f\)}]\n
1500 \qbraid
1501 }
1502 \qquad
1503 \q
1504 {
1505 \qbraidinv\n
1506 \qbox[name={\(f\)}]\qbox[name={\(g\)}]
1507 }
1508 =\q
1509 {
1510 \qbox[name={\(g\)}]\qbox[name={\(f\)}]\n
1511 \qbraidinv
1512 }
1513 \end{equation}
1514 \end{CODEBOX}
1515
1516 For the commands \verb|\qbraid|, \verb|\qbraidinv|, and \verb|\qasym|, specifying \showcmd[]{num R=0} results in a dashed line for the right wire, as shown in \q[scale=0.65]{\qbraid[num R=0]}.
1517 Similarly, specifying \showcmd[]{num L=0} results in a dashed line for the left wire, as shown in \q[scale=0.65]{\qbraid[num L=0]}.
1518 This is due to representing the unit object as an empty diagrams, i.e., a diagram with \(0\) wires.
1519 \begin{CODEBOX}{}{stateeffect3dimbraid}
1520 \begin{gather}
1521 \q{
1522 \qwire\qstate\n
1523 \qwire
1524 }
1525 =\q{
1526 \qwire\qstate\n
1527 \qbraid[num L=0]
1528 }\stackrel{\text{(\ref{cond:naturality:braid})}}{=}\q{
1529 \qbraid\n
1530 \qstate\qwire
1531 }\label{iso:u:state}\\
1532 \q{
1533 \qunitob\qwire\n
1534 \qeffect\qwire
1535 }
1536 =\q{
1537 \qbraid[num L=0]\n
1538 \qeffect\qwire
1539 }\stackrel{\text{(\ref{cond:naturality:braid})}}{=}\q{
1540 \qwire\qeffect\n
1541 \qbraid
1542 }\label{iso:u:effect}
1543 \end{gather}
1544 \end{CODEBOX}
1545 \begin{CODEBOX}{}{iso:spatial:scalar}
1546 \begin{equation}
1547 \label{iso:spatial}
1548 \q{\qscalar\qmv[0,-1]\qwire[vlen=3]}
1549 =\q{\qbraid[num L=0]\n\qscalar\qmv[0,-1]\qwire[vlen=2]}
1550 \stackrel{\text{(\ref{cond:naturality:braid})}}{=}
1551 \q{\qwire[vlen=2]\qscalar\n\qbraid[num L=0]}
1552 =\q{\qscalar\qmv[-2,-1]\qwire[vlen=3]}
1553 \end{equation}
1554 \end{CODEBOX}
1555 \begin{CODEBOX}{}{iso:spatial:state.effect}
1556 \[
1557 \q{\qscalar\qmv[0,-1]\qwire[vlen=3]}
1558 =\q{\qeffect\n\qstate\qmv[0,-0.5]\qwire[vlen=3]}
1559 \stackrel{\text{(\ref{iso:u:effect})}}{=}
1560 \q{\qwire\qeffect\n\qbraid\n\qstate\qwire}
1561 \stackrel{\text{(\ref{iso:u:state})}}{=}
1562 \q{\qeffect\n\qstate\qmv[-2,-0.5]\qwire[vlen=3]}
1563 =\q{\qscalar\qmv[-2,-1]\qwire[vlen=3]}
1564 \]
1565 \end{CODEBOX}
1566 \paragraph{\(\q[scale=0.5]{\qbraid\qwire\n\qwire\qstate[n=2]}=\q[scale=0.5]{\qwire\qbraidinv\n\qstate[n=2]\qwire}\)}
1567 \begin{CODEBOX}{}{dashedbraid}
1568 \begin{align}
1569 \q
1570 {
1571 \qbraid\qwire\n
1572 \qwire\qstate[n=2]
1573 }&=\q
1574 {
1575 \qbraid\qwire\n
1576 \qwire\qstate[n=2]\n\n
1577 \qbraidinv[num L=0,vlen=2,hlen=2.5]
1578 }
1579 \stackrel{\text{(\ref{cond:naturality:braid})}}{=}\q
1580 {
1581 \qbraid\qwire\n\n
1582 \qbraidinv[num L=2,vlen=2]\n
1583 \qstate[n=2]\qwire\n
1584 \qspace[0.5]\qwire[arrowtype={densely dotted}]\qspace[0.5]\qwire
1585 }\\
1586 &=\q
1587 {
1588 \qbraid\qwire\n\n
1589 \qbraidinv[num L=2,vlen=2]\n
1590 \qstate[n=2]\qwire\n
1591 \qspace[2]\qwire
1592 \qbb[green][3]
1593 }\stackrel{\text{(\ref{eq:hexagon})}}{=}\q
1594 {
1595 \qbraid\qwire\n
1596 \qbraidinv\qwire\n
1597 \qwire\qbraidinv\n
1598 \qstate[n=2]\qwire\n
1599 \qspace[2]\qwire
1600 \qbb[green][3,...,6]
1601 }\\
1602 &=\q
1603 {
1604 \qbraid\qwire\n
1605 \qbraidinv\qwire\n
1606 \qwire\qbraidinv\n
1607 \qstate[n=2]\qwire\n
1608 \qspace[2]\qwire
1609 \qbb[orange][1,3]
1610 }
1611 \stackrel{\text{(\ref{eq:inverse:braid})}}{=}\q
1612 {
1613 \qloop[2]{\qloop[3]{\qwire}\n}
1614 \qwire\qbraidinv\n
1615 \qstate[n=2]\qwire\n
1616 \qspace[2]\qwire
1617 \qbb[orange][1,2,4,5]
1618 }
1619 \end{align}
1620 \end{CODEBOX}
1621
1622 \begin{CODEBOX}{Yang-Baxer Equation}{YangBaxer}
1623 \[
1624 \q{
1625 \qbraid\qwire\n
1626 \qwire\qbraid\n
1627 \qbraid\qwire
1628 }=\q{
1629 \qwire\qbraid\n
1630 \qbraid\qwire\n
1631 \qwire\qbraid
1632 }
1633 \]
1634 \end{CODEBOX}
1635
1636 \begin{codebox}[center lower,listing side text,righthand width=5cm,bicolor,colbacklower=white]{Commutativity}{def:cmt}
1637 \begin{equation}
1638 \label{cond:cmt}
1639 \q{\qmul[hlen=2]}=\q{\qmul[hlen=2]\n\qbraid}
1640 \end{equation}
1641 \end{codebox}
1642 \begin{codebox}[center lower,listing side text,righthand width=5cm,bicolor,colbacklower=white]{Cocommutativity}{def:ccmt}
1643 \begin{equation}
1644 \label{cond:ccmt}
1645 \q{\qcomul[hlen=2]}=\q{\qbraid\n\qcomul[hlen=2]}
1646 \end{equation}
1647 \end{codebox}
1648 \subsubsection{Bialgebra}
1649 \begin{CODEBOX}{Bialgebra Law}{law:bialgebra}
1650 \begin{gather}
1651 \q{\qcomul[hlen=2]\qcirc\qmul[hlen=2, color=black]}
1652 =\q{
1653 \qmul[hlen=2, color=black]\qmul[hlen=2, color=black]\n
1654 \qwire\qbraid\qwire\n\qcomul[hlen=2]\qcomul[hlen=2]
1655 }\\
1656 \q{\qspace[0.5]\qcounit\qcirc\qmul[hlen=2, color=black]}
1657 =\q{\qcounit\qcounit}\\
1658 \q{\qcomul[hlen=2]\qcirc\qspace[0.5]\qunit[color=black]}
1659 =\q{\qunit[color=black]\qunit[color=black]}\\
1660 \q{\qcounit\n\qunit[color=black]}
1661 =\q{\qunitob}
1662 \end{gather}
1663 \end{CODEBOX}
1664 \subsubsection{Hopf Algebra}
1665 \begin{CODEBOX}{Antipode and Hopf Algebra}{law:hopf}
1666 \begin{equation}
1667 \q{
1668 \qmul[hlen=2, color=black]\n
1669 \qwire\qbox[name={\(s\)}]\n
1670 \qcomul[hlen=2]
1671 }
1672 =\q{\qunit[color=black]\qcirc\qcounit}
1673 =\q{
1674 \qmul[hlen=2, color=black]\n
1675 \qbox[name={\(s\)}]\qwire\n
1676 \qcomul[hlen=2]
1677 }
1678 \end{equation}
1679 \end{CODEBOX}
1680 \subsubsection{Balanced Structure}
1681 \label{subsubsec:balancedcategory}
1682 \begin{CODEBOX}{Twist}{def:twist}
1683 \begin{gather}
1684 \q{
1685 \qbox[name={\(\theta_{X\otimes Y}\)}, p=2]
1686 \symbolI{\(X\)}\symbolI[2]{\(Y\)}
1687 \symbolO{\(X\)}\symbolO[2]{\(Y\)}
1688 }
1689 =\q{
1690 \qbox[name={\(\theta_X\)}]\qbox[name={\(\theta_Y\)}]\n
1691 \qbraid\n\qbraid
1692 }\label{cond:twist}\\
1693 \q{\qbox[name={\(\theta_I\)}]}=\q{\qunitob}\label{cond:i:twist}\\
1694 \forall\q{\qbox[name={\(f\)}]}\colon
1695 \q{
1696 \qbox[name={\(\theta_{\operatorname{cod}(f)}\)}, hlen=1.5]\n
1697 \qbox[name={\(f\)}, hlen=1.5]
1698 }=\q{
1699 \qbox[name={\(f\)}, hlen=1.5]\n
1700 \qbox[name={\(\theta_{\operatorname{dom}(f)}\)}, hlen=1.5]
1701 }\label{cond:naturality:twist}
1702 \end{gather}
1703 \end{CODEBOX}
1704 \subsubsection{Color}
1705 \label{subsubsec:braid:color}
1706 \begin{codebox}[center lower,listing side text,righthand width=5cm,bicolor,colbacklower=white]{Symmetry}{defeq:sym}
1707 \begin{equation}
1708 \label{cond:symmetry}
1709 \q
1710 {
1711 \qbraid[L color=cyan, R color=red]\n
1712 \qbraid[L color=red, R color=cyan]
1713 }
1714 =\q{\qwire[color=red, vlen=2]\qwire[color=cyan, vlen=2]}
1715 \end{equation}
1716 \end{codebox}
1717
1718 \begin{CODEBOX}{}{wowsym}
1719 \[\q{\qbraid[L color=red, R color=cyan]}
1720 =\left(\q{\qbraid[L color=cyan, R color=red]}\right)^{-1}
1721 =\q{\qbraidinv[L color=red, R color=cyan]}\]
1722 \end{CODEBOX}
1723 \begin{codebox}{Symmetry}{def:sym}
1724 \q{\qsym}
1725 \end{codebox}
1726
1727 \subsection{Duality}
1728 \label{subsubsec:duality}
1729 \begin{itemize}
1730 \item \showcmd{qcap}: \(\q[scale=0.6]{\qcap}\)
1731 \item \showcmd{qcup}: \(\q[scale=0.6]{\qcup}\)
1732 \item \showcmd{qcaprev}: \(\q[scale=0.6]{\qcaprev}\)
1733 \item \showcmd{qcuprev}: \(\q[scale=0.6]{\qcuprev}\)
1734 \end{itemize}
1735
1736 \begin{CODEBOX}{Snake Equations}{Snake}
1737 \begin{equation}
1738 \label{eq:snake}
1739 \q{
1740 \qcap\qwireup\n
1741 \qwireup\qcup
1742 }
1743 =\q{
1744 \qwireup[vlen=2]
1745 }
1746 \qquad\land\qquad
1747 \q{
1748 \qwiredown\qcap\n
1749 \qcup\qwiredown
1750 }
1751 =\q{
1752 \qwiredown[vlen=2]
1753 }
1754 \end{equation}
1755 \end{CODEBOX}
1756
1757 \subsubsection{Transpose Box}
1758 \label{subsubsec:transpose}
1759 \begin{CODEBOX}{Transpose}{Transpose}
1760 \[
1761 \left(\q{\qwire\n\qasym[name={\(f\)}]\n\qwire}\right)^T
1762 =\q{
1763 \qwire\n
1764 \qtrans[name={\(f\)}]\n
1765 \qwire
1766 }\coloneq\q{
1767 \qwire\qcap\n
1768 \qwire\qasym[name={\(f\)}]\qwire\n
1769 \qcup\qwire
1770 }
1771 \]
1772 \end{CODEBOX}
1773
1774 \begin{CODEBOX}{}{ex:193477432894021826}
1775 \begin{equation}
1776 \label{eq:wirerev}
1777 \left(\q{\qwireup}\right)^T=\q{\qwiredown}
1778 \end{equation}
1779 \end{CODEBOX}
1780
1781 \begin{CODEBOX}{Sliding}{Sliding}
1782 \begin{equation}
1783 \label{eq:sliding}
1784 \q{
1785 \qcap \n
1786 \qasym \qwire
1787 }
1788 =\q
1789 {
1790 \qcap \n
1791 \qwire \qtrans
1792 }\qquad
1793 \q
1794 {
1795 \qwire\qasym \n
1796 \qcup
1797 }
1798 =\q
1799 {
1800 \qtrans \qwire \n
1801 \qcup
1802 }
1803 \end{equation}
1804 \end{CODEBOX}
1805
1806 \begin{CODEBOX}{}{MapStateDuality}
1807 \begin{equation}
1808 \begin{array}{rccc}
1809 \operatorname{NAME}\colon & \operatorname{Hom}(X,Y)
1810 & \to & \operatorname{Hom}(I,X^T\otimes Y)\\
1811 & \rotatebox{90}{\(\in\)} && \rotatebox{90}{\(\in\)}\\
1812 & \q{
1813 \qasym
1814 \symbolI{\(X\)}
1815 \symbolO{\(Y\)}
1816 } & \mapsto
1817 & \q{
1818 \qwire[label={\(X^T\)}, label at={at end}, label side={above}] \qasym \n
1819 \qcup
1820 \symbolO{\(Y\)}[id=2]
1821 }
1822 \end{array}
1823 \end{equation}
1824 \end{CODEBOX}
1825
1826 \begin{CODEBOX}{}{MapEffectDuality}
1827 \begin{equation}
1828 \begin{array}{rccc}
1829 \operatorname{CONAME}\colon & \operatorname{Hom}(X,Y)
1830 & \to & \operatorname{Hom}(X\otimes Y^T,I)\\
1831 & \rotatebox{90}{\(\in\)}&&\rotatebox{90}{\(\in\)}\\
1832 & \q{
1833 \qasym
1834 \symbolI{\(X\)}
1835 \symbolO{\(Y\)}
1836 } & \mapsto
1837 & \q{
1838 \qcap \n
1839 \qasym \qwire[label={\(Y^T\)}, label at={at start}, label side={below}]
1840 \symbolI{\(X\)}[id=2]
1841 }
1842 \end{array}
1843 \end{equation}
1844 \end{CODEBOX}
1845
1846 \subsubsection{No Cloning Theorem}
1847 \label{subsubsec:nocopy}
1848 \begin{CODEBOX}{Uniform Copying}{def:copy}
1849 \begin{gather}
1850 \q{
1851 \qwire\qbraid\qwire\n
1852 \qcomul[hlen=2, name={\(\operatorname{copy}_X\)}]\qcomul[hlen=2, name={\(\operatorname{copy}_Y\)}]
1853 \symbolI{\(X\)}[id=4]\symbolI{\(Y\)}[id=5]
1854 \symbolO{\(X\)}[id=1]\symbolO{\(Y\)}[id=2]
1855 \symbolO[2]{\(X\)}[id=2]\symbolO{\(Y\)}[id=3]
1856 }=\q{
1857 \qcomul[hlen=3, vlen=2, name={\(\operatorname{copy}_{X\otimes Y}\)}]\symbolI{\(X\otimes Y\)}
1858 \symbolO{\(X\otimes Y\)}\symbolO[2]{\(X\otimes Y\)}
1859 }\label{cond:copy}\\
1860 \forall\q{\qbox[name={\(f\)}]\symbolI{\(X\)}\symbolO{\(Y\)}}\colon
1861 \q{
1862 \qbox[name={\(f\)}]\qbox[name={\(f\)}]\n
1863 \qcomul[hlen=2, name={\(\operatorname{copy}_X\)}]
1864 }=\q{
1865 \qcomul[hlen=2, name={\(\operatorname{copy}_Y\)}]\n
1866 \qspace[0.5]\qbox[name={\(f\)}]
1867 }\label{cond:morcopy}\\
1868 \q{
1869 \qcomul[hlen=2, name={\(\operatorname{copy}_I\)}]\symbolI{\(I\)}
1870 \symbolO{\(I\)}\symbolO[2]{\(I\)}
1871 }=\q{\qunitob}\label{cond:i:copy}
1872 \end{gather}
1873 \end{CODEBOX}
1874
1875 \begin{CODEBOX}{Copyable State}{def:copyablestate}
1876 \[
1877 \q{
1878 \qcomul[hlen=2, name={\(\operatorname{copy}\)}]\n
1879 \qspace[0.5]\qstate[name={\(a\)}]
1880 }=\q{
1881 \qstate[name={\(a\)}]\qstate[name={\(a\)}]
1882 }
1883 \]
1884 \end{CODEBOX}
1885 \begin{CODEBOX}{}{len:copycupcup}
1886 \begin{align*}
1887 \q{\qcup\qcup}&\stackrel{\text{(\ref{cond:i:copy})}}{=}
1888 \q{
1889 \qcup\qcup\n\qmv[0.5,0.4]
1890 \qcomul[
1891 dom arrowtype=dotted,
1892 cod arrowtype=dotted,
1893 hlen=3,
1894 name={\(\operatorname{copy}\)}
1895 ]
1896 }\stackrel{\text{(\ref{cond:morcopy})}}{=}
1897 \q{
1898 \qspider[
1899 name={\(\operatorname{copy}\)},
1900 N={1,2,4,5},
1901 s=2,
1902 hlen=2
1903 ]\n\qcup
1904 }\\
1905 &\stackrel{\text{(\ref{cond:copy})}}{=}\q[scale=0.6]{
1906 \qwire\qbraid\qwire\n
1907 \qloop[4]{\qwire}\n
1908 \qcomul[hlen=2, name={\(\operatorname{copy}\)}]\qcomul[hlen=2]\n
1909 \qspace[0.5]\qcup[hlen=3]
1910 \qbb[red][4,8]
1911 }\stackrel{\text{(\ref{cond:ccmt})}}{=}\q[scale=0.6]{
1912 \qwire\qbraid\qwire\n
1913 \qbraidinv\qwire\qwire\n
1914 \qcomul[hlen=2]\qcomul[hlen=2]\n
1915 \qspace[0.5]\qcup[hlen=3]
1916 \qbb[red][4,7]
1917 }\\
1918 &=\q[scale=0.6]{
1919 \qwire\qbraid\qwire\n
1920 \qbraidinv\qwire\qwire\n[2]
1921 \qloop[4]{\qwire[vlen=2]}\n
1922 \qloop[2]{\qcomul[hlen=2, name={\(\operatorname{copy}\)}]}\n
1923 \qspace[0.5]\qcup[hlen=3]
1924 \qbb[blue][8,9]
1925 }
1926 \stackrel{\text{(\ref{eq:inverse:braid})}}{=}
1927 \q[scale=0.6]{
1928 \qwire\qbraid\qwire\n
1929 \qbraidinv\qwire\qwire\n
1930 \qwire\qbraidinv\qwire\n
1931 \qwire\qbraid\qwire\n
1932 \qloop[2]{\qcomul[hlen=2, name={\(\operatorname{copy}\)}]}\n
1933 \qspace[0.5]\qcup[hlen=3]
1934 \qbb[blue][8,11]
1935 }\\
1936 &=\q[xscale=0.6, yscale=0.5]{
1937 \qwire\qbraid\qwire\n
1938 \qbraidinv\qwire\qwire\n
1939 \qwire\qbraidinv\qwire\n
1940 \qwire\qbraid\qwire\n
1941 \qloop[2]{\qcomul[hlen=2, name={\(\operatorname{copy}\)}]}\n
1942 \qspace[0.5]\qcup[hlen=3]
1943 \qbb[yellow][10,14,15]
1944 }\stackrel{\text{(\ref{cond:copy}, \ref{cond:morcopy}, \ref{cond:i:copy})}}{=}
1945 \q[scale=0.6]{
1946 \qwire\qbraid\qwire\n
1947 \qbraidinv\qwire\qwire\n
1948 \qwire\qbraidinv\qwire\n
1949 \qcup\qcup
1950 \qbb[yellow][10,11]
1951 }\\
1952 &=\q{
1953 \qwire\qbraid\qwire\n
1954 \qcup[n=4]
1955 }
1956 \end{align*}
1957 \end{CODEBOX}
1958 \begin{CODEBOX}{}{len:copybraid}
1959 \begin{align*}
1960 \q{
1961 \qbraid
1962 \symbolI{\(X\)}\symbolO{\(X\)}
1963 \symbolI[2]{\(X\)}\symbolO[2]{\(X\)}
1964 }&\stackrel{\text{(\ref{eq:snake})}}{=}\q[scale=0.5]{
1965 \qwire\qspace[2]\qcap\qwire\n
1966 \qbraid[hlen=4]\qwire\qwire\n
1967 \qwire\qcap\qwire\qcup\n
1968 \qwire\qwire\qcup
1969 \qbb[blue][1,5]
1970 }=\q[scale=0.5]{
1971 \qcap[hlen=4]\qwire\n
1972 \qwire\qspace[2]\qbraidinv\n
1973 \qwire\qcap\qwire\qwire\qwire[vlen=3]\n
1974 \qwire\qwire\qcup\qcup
1975 \qbb[blue][1,4]
1976 \qbb[yellow][12,13]
1977 }\\
1978 &\stackrel{\text{Example \ref{len:copycupcup}}}{=}\q[scale=0.5]{
1979 \qcap[hlen=4]\qwire\n
1980 \qwire\qspace[2]\qbraidinv\n
1981 \qwire\qcap\qwire\qwire\qwire[vlen=3]\n
1982 \qwire\qwire\qwire\qbraid\qwire\n
1983 \qwire\qwire\qcup[n=4]
1984 \qbb[yellow][12,14,17]
1985 }=\q[scale=0.5]{
1986 \qcap[s=4]\qwire\n
1987 \qloop[3]{\qwire}\qbraidinv\n
1988 \qloop[3]{\qwire}\qbraid\qwire[vlen=3]\n
1989 \qwire\qwire\qcup[n=4]
1990 \qbb[green][6,10]
1991 }\\
1992 &\stackrel{\text{(\ref{eq:inverse:braid})}}{=}\q[scale=0.5]{
1993 \qcap[s=4]\qwire\qwire\n[2]
1994 \qloop[6]{\qwire[vlen=2]}\n
1995 \qwire\qwire\qcup[n=4]
1996 \qbb[green][7,8]
1997 }\stackrel{\text{(\ref{eq:snake})}}{=}\q{
1998 \qwire\qwire
1999 \symbolI{\(X\)}[id=1]\symbolO{\(X\)}[id=1]
2000 \symbolI{\(X\)}\symbolO{\(X\)}
2001 }
2002 \end{align*}
2003 \end{CODEBOX}
2004
2005 \begin{CODEBOX}{No Cloning Theorem}{thm:nocopy}
2006 \begin{align*}
2007 \q{
2008 \qasym[name={\(f\)}]
2009 \symbolI{\(X\)}\symbolO{\(X\)}
2010 }&\stackrel{\text{(\ref{eq:snake})}}{=}
2011 \q{
2012 \qcap\qasym[name={\(f\)}]\n
2013 \qwire\qcup
2014 }\stackrel{\text{(\ref{eq:inverse:braid})}}{=}\q{
2015 \qcap\qasym[name={\(f\)}]\n
2016 \qwire\qbraidinv\n
2017 \qwire\qbraid\n
2018 \qwire\qcup
2019 }\\
2020 &\stackrel{\text{(\ref{cond:naturality:braid})}}{=}\q{
2021 \qcap\qwire\n
2022 \qwire\qbraidinv\n
2023 \qwire\qasym[name={\(f\)}]\qwire\n
2024 \qwire\qbraid\n
2025 \qwire\qcup
2026 \qbb[red][1,4]
2027 }=\q{
2028 \qwire\qcap\n
2029 \qbraid\qwire\n
2030 \qwire\qasym[name={\(f\)}]\qwire\n
2031 \qwire\qbraid\n
2032 \qwire\qcup
2033 \qbb[red][1,4]
2034 }\\
2035 &=\q{
2036 \qwire\qcap\n
2037 \qbraid\qwire\n
2038 \qwire\qasym[name={\(f\)}]\qwire\n
2039 \qwire\qbraid\n
2040 \qwire\qcup
2041 \qbb[blue][3]
2042 }\stackrel{\text{Example \ref{len:copybraid}}}{=}\q{
2043 \qwire\qcap\n
2044 \qwire\qwire\qwire\n
2045 \qwire\qasym[name={\(f\)}]\qwire\n
2046 \qwire\qbraid\n
2047 \qwire\qcup
2048 \qbb[blue][3,4]
2049 }
2050 \end{align*}
2051 \end{CODEBOX}
2052 \subsection{Pivotal Category}
2053 \label{subsec:pivotal}
2054 \begin{CODEBOX}{}{struct:Pivotal}
2055 \begin{equation}
2056 \label{cond:naturality:pivotal}
2057 \forall\q{\qasym[name={\(f\)}]\symbolI{\(X\)}\symbolO{\(Y\)}}\colon
2058 \q[scale=0.5]{
2059 \qwire\qcap[s=4]\n
2060 \qwire\qwire\qasym[name={\(f\)}]\qwire\qwire\n
2061 \qcup[n=4]\qwire\qmv[-1,-1]\qasym[name={\(\pi_X\)}]
2062 }=\q{
2063 \qasym[name={\(\pi_Y\)}]\n
2064 \qasym[name={\(f\)}]
2065 }
2066 \end{equation}
2067 \end{CODEBOX}
2068 \begin{CODEBOX}{}{dualrev}
2069 \begin{equation}
2070 \label{def:dualrev}
2071 \q{
2072 \qcaprev\n
2073 \symbolI{\(X^T\)}\symbolI[2]{\(X\)}
2074 }\coloneq\q
2075 {
2076 \qcap \n
2077 \qwire \qwireupup \n
2078 \qwire \qasym[name={\(\pi_x\)}] \n
2079 }\qquad\q{
2080 \qcuprev
2081 \symbolO{\(X\)}\symbolO[2]{\(X^T\)}
2082 }\coloneq\q
2083 {
2084 \qasym[name={\(\pi_X^{-1}\)}]\qwire\n
2085 \qwireupup\qwire\n
2086 \qcup
2087 }
2088 \end{equation}
2089 \end{CODEBOX}
2090 \begin{CODEBOX}{}{revSliding}
2091 \begin{equation}
2092 \label{eq:sliding:rev}
2093 \q{
2094 \qcaprev\n
2095 \qtrans\qwire\n
2096 }=\q{
2097 \qcaprev\n
2098 \qwire\qasym
2099 }\qquad\q{
2100 \qwire\qtrans\n
2101 \qcuprev
2102 }=\q{
2103 \qasym\qwire\n
2104 \qcuprev
2105 }
2106 \end{equation}
2107 \end{CODEBOX}
2108 \begin{CODEBOX}{}{corr:pivotal:twist}
2109 \begin{gather}
2110 \q{
2111 \qwireuu[label={\(X^{**}\)}]\n
2112 \qasym[name={\(\pi_X\)}]\n
2113 \qwireup[label={\(X\)}]
2114 }=\q{
2115 \qwireuu[label={\(X^{**}\)}]\qcap\n
2116 \qbraid\qwired[label={\(X^T\)}]\n
2117 \qasym[name={\(\theta_X^{-1}\)}]\qcuprev\n
2118 \qwireup[label={\(X\)}]
2119 }\label{twist:pivotal}\\
2120 \q{
2121 \qwireup[label={\(X\)}]\n
2122 \qasym[name={\(\theta_X\)}]\n
2123 \qwireup[label={\(X\)}]
2124 }=\q{
2125 \qwireup[label={\(X\)}]\n
2126 \qasym[name={\(\pi_X^{-1}\)}]\n
2127 \qwireuu[label={\(X^{**}\)}]\qcap\n
2128 \qbraid\qwired[label={\(X^T\)}]\n
2129 \qwire[label={\(X\)}]\qcuprev
2130 }\label{pivotal:twist}
2131 \end{gather}
2132 \end{CODEBOX}
2133 \begin{CODEBOX}{}{ex193477432894100303}
2134 \begin{align*}
2135 \q{\qasym[name={\(\theta_X\)}]}
2136 &=\q{
2137 \qwireu[label={\(X\)}]\qcap\n
2138 \qbraid\qwired\n
2139 \qwireu[label={\(X\)}]\qcuprev
2140 }&\q{\qasym[name={\(\theta_X^{-1}\)}]}
2141 &=\q{
2142 \qcaprev\qwireu[label={\(X\)}]\n
2143 \qwired\qbraidinv\n
2144 \qcup\qwireu[label={\(X\)}]
2145 }\\
2146 \q{\qtrans[name={\(\theta_X\)}]}
2147 &=\q{
2148 \qcap\qwired[label={\(X^T\)}]\n
2149 \qwireu\qbraid\n
2150 \qcuprev\qwired[label={\(X^T\)}]
2151 }&\q{\qtrans[name={\(\theta_X^{-1}\)}]}
2152 &=\q{
2153 \qwired[label={\(X^T\)}]\qcaprev\n
2154 \qbraidinv\qwireu\n
2155 \qwired[label={\(X^T\)}]\qcup
2156 }
2157 \end{align*}
2158 \end{CODEBOX}
2159 \begin{CODEBOX}{Ribbon Category}{code:def:ribboncategory}
2160 \begin{equation}
2161 \label{def:ribboncategory}
2162 \q{
2163 \qwired\qcaprev\n
2164 \qbraid\qwireu\n
2165 \qwired\qcup
2166 }=\q{
2167 \qcap\qwired\n
2168 \qwireu\qbraid\n
2169 \qcuprev\qwired
2170 }
2171 \end{equation}
2172 \end{CODEBOX}
2173
2174 \subsubsection{Trace}
2175 \label{subsubsec:trace}
2176 \begin{CODEBOX}{Trace}{Trdef}
2177 \[
2178 \begin{array}{rccc}
2179 \operatorname{Tr}\colon & \operatorname{Hom}(X,X) & \to &\operatorname{Hom}(I,I)\\
2180 &\rotatebox{90}{\(\in\)}&&\rotatebox{90}{\(\in\)}\\
2181 &\q{
2182 \qasym[name={\(f\)}]
2183 } & \mapsto & \q{
2184 \qcap\n
2185 \qasym[name={\(f\)}]\qwire\n
2186 \qcuprev
2187 }
2188 \end{array}
2189 \]
2190 \end{CODEBOX}
2191 \begin{CODEBOX}{Commutativity of the Trace}{Cotr}
2192 \begin{equation}
2193 \label{cmt:trace}
2194 \operatorname{Tr}\left(\q{
2195 \qasym[name={\(g\)}]\n
2196 \qasym[name={\(f\)}]
2197 }\right)
2198 =\q{
2199 \qcap\n
2200 \qasym[name={\(g\)}]\qwire\n
2201 \qasym[name={\(f\)}]\qwire\n
2202 \qcuprev
2203 }
2204 \stackrel{\text{(\ref{eq:sliding})}}{=}\q{
2205 \qcap\n
2206 \qasym[name={\(f\)}]\qtrans[name={\(g\)}]\n
2207 \qcuprev
2208 }\stackrel{\text{(\ref{eq:sliding:rev})}}{=}\q{
2209 \qcap\n
2210 \qasym[name={\(f\)}]\qwire\n
2211 \qasym[name={\(g\)}]\qwire\n
2212 \qcuprev
2213 }=\operatorname{Tr}\left(\q{
2214 \qasym[name={\(f\)}]\n
2215 \qasym[name={\(g\)}]
2216 }\right)
2217 \end{equation}
2218 \end{CODEBOX}
2219 \begin{CODEBOX}{Dimension}{def:dim}
2220 \[
2221 \q{\qscalar[name={\(\operatorname{dim}(X)\)}]}
2222 \coloneq\q{\qscalar[name={\(\operatorname{Tr}(\operatorname{id}_X)\)}]}
2223 =\q{\qcap\n\qcuprev}
2224 \]
2225 \end{CODEBOX}
2226 \subsubsection{Compact Category}
2227 \label{subsubsec:compact}
2228 \begin{CODEBOX}{Compact Category}{Def:compact}
2229 \begin{equation}
2230 \label{def:compact}
2231 \q{\qasym[name={\(\pi_X\)}]}=\q{
2232 \qwireuu[label={\(X^{TT}\)}]\qcap\n
2233 \qsym\qwired[label={\(X^T\)}]\n
2234 \qwire[label={\(X\)}]\qcuprev
2235 }
2236 \end{equation}
2237 \end{CODEBOX}
2238
2239 \subsubsection{Color}
2240 \label{subsubsec:duality:color}
2241 \begin{CODEBOX}{}{Ex:coloredhopflink}
2242 \begin{equation}
2243 \label{eq:tr:hopf}
2244 \operatorname{Tr}\left(
2245 \q{
2246 \qbraid[L color=blue, R color=orange]\n
2247 \qbraid[L color=orange, R color=blue]}
2248 \right)
2249 =\q{
2250 \qcap[hlen=4, frame color=orange]\n
2251 \qwire[color=orange]\qcap[frame color=blue]\n
2252 \qbraid[L color=blue, R color=orange]\n
2253 \qbraid[L color=orange, R color=blue
2254 ]\qwiredown[vlen=2, color=blue]\n
2255 \qwire[color=orange]
2256 \qcuprev[frame color=blue]
2257 \qwiredown[vlen=4, color=orange]\n
2258 \qcuprev[hlen=4, frame color=orange]
2259 }=\q{
2260 \qcap[frame color=blue]
2261 \qcap[frame color=orange]\n
2262 \qspace
2263 \qbraidinv[L color=orange, R color=blue]\n
2264 \qwireup[vlen=2, color=blue]
2265 \qbraidinv[L color=blue, R color=orange]
2266 \qwiredown[vlen=2, color=orange]\n
2267 \qcuprev[frame color=blue]
2268 \qcuprev[frame color=orange]
2269 }
2270 \end{equation}
2271 \end{CODEBOX}
2272
2273 \subsection{Dagger}
2274 \label{subsec:dagger}
2275 \subsubsection{Adjoint Box}
2276 \label{subsubsec:adjoint}
2277 \begin{CODEBOX}{Adjoint}{def:adj}
2278 \begin{gather}
2279 \left(
2280 \q{
2281 \qasym[name={\(f\)}]
2282 \symbolI{\(X\)}\symbolO{\(Y\)}
2283 }
2284 \right)^{\dagger}
2285 \coloneq
2286 \q{
2287 \qadj[name={\(f\)}]
2288 \symbolI{\(Y\)}\symbolO{\(X\)}
2289 }\\
2290 \left(\q{\qasym[name={\(f\)}]}\right)^{\dagger\dagger}
2291 =\left(\q{\qadj[name={\(f\)}]}\right)^{\dagger}
2292 =\q{\qasym[name={\(f\)}]}\\
2293 \left(\q{\qwire}\right)^{\dagger}=\q{\qwire}\\
2294 \q{
2295 \qadj[name={\(f\)}]\n
2296 \qadj[name={\(g\)}]
2297 }=\q{
2298 \qadj[name={\(g\circ f\)}]
2299 }
2300 \end{gather}
2301 \end{CODEBOX}
2302 \subsubsection{Conjugate Box}
2303 \label{subsubsec:conj}
2304 \begin{CODEBOX}{}{prep:conj}
2305 \begin{align*}
2306 \left(\q{\qadj}\right)^T
2307 &=\q{
2308 \qwire\qcap\n
2309 \qwire\qadj\qwire\n
2310 \qcup\qwire
2311 }=\q{
2312 \qcaprev\qwire\n
2313 \qwire\qadj\qwire\n
2314 \qwire\qcuprev
2315 }=\left(
2316 \q{
2317 \qwire\qcap\n
2318 \qwire\qasym\qwire\n
2319 \qcup\qwire
2320 }
2321 \right)^{\dagger}=\left(\q{\qtrans}\right)^{\dagger}
2322 \end{align*}
2323 \end{CODEBOX}
2324 \section{List of Primitive Diagrams}
2325 \label{sec:fcommands}
2326 \begin{tcbraster}[raster columns=4,raster equal height=rows,fonttitle=\bfseries,
2327 colframe=cyan!90,coltitle=cyan!50,colbacktitle=black,
2328 subtitle style={boxrule=0.4pt,
2329 colback=black!70}
2330 ]
2331 \begin{tcolorbox}[adjusted title={\showcmd{qwire}[cyan]}]
2332 \[\q{\qwire}\]
2333 \end{tcolorbox}
2334 \begin{tcolorbox}[adjusted title={\showcmd{qbox}[cyan]}]
2335 \[
2336 \q{
2337 \qbox
2338 }
2339 \]
2340 \end{tcolorbox}
2341 \begin{tcolorbox}[adjusted title={\showcmd{qstate}[cyan]}]
2342 \[
2343 \q{
2344 \qstate
2345 }
2346 \]
2347 \end{tcolorbox}
2348 \begin{tcolorbox}[adjusted title={\showcmd{qeffect}[cyan]}]
2349 \[
2350 \q{
2351 \qeffect
2352 }
2353 \]
2354 \end{tcolorbox}
2355 \begin{tcolorbox}[adjusted title={\showcmd{qscalar}[cyan]}]
2356 \[
2357 \q{
2358 \qscalar
2359 }
2360 \]
2361 \end{tcolorbox}
2362 \begin{tcolorbox}[adjusted title={\showcmd{qunitob}[cyan]}]
2363 \[
2364 \q{
2365 \qunitob
2366 }
2367 \]
2368 \end{tcolorbox}
2369 \begin{tcolorbox}[adjusted title={\showcmd{qmul}[cyan]}]
2370 \[
2371 \q{
2372 \qmul[hlen=2]
2373 }
2374 \]
2375 \end{tcolorbox}
2376 \begin{tcolorbox}[adjusted title={\showcmd{qcomul}[cyan]}]
2377 \[
2378 \q{
2379 \qcomul[hlen=2]
2380 }
2381 \]
2382 \end{tcolorbox}
2383 \begin{tcolorbox}[adjusted title={\showcmd{qunit}[cyan]}]
2384 \[
2385 \q{
2386 \qunit
2387 }
2388 \]
2389 \end{tcolorbox}
2390 \begin{tcolorbox}[adjusted title={\showcmd{qcounit}[cyan]}]
2391 \[
2392 \q{
2393 \qcounit
2394 }
2395 \]
2396 \end{tcolorbox}
2397 \begin{tcolorbox}[adjusted title={\showcmd{qspider}[cyan]}]
2398 \[
2399 \q{
2400 \qspider[p=4,hlen=2]
2401 }
2402 \]
2403 \end{tcolorbox}
2404 \begin{tcolorbox}[adjusted title={\showcmd{qbraid}[cyan]}]
2405 \[
2406 \q{
2407 \qbraid
2408 }
2409 \]
2410 \end{tcolorbox}
2411 \begin{tcolorbox}[adjusted title={\showcmd{qbraidinv}[cyan]}]
2412 \[
2413 \q{
2414 \qbraidinv
2415 }
2416 \]
2417 \end{tcolorbox}
2418 \begin{tcolorbox}[adjusted title={\showcmd{qsym}[cyan]}]
2419 \[
2420 \q{
2421 \qsym
2422 }
2423 \]
2424 \end{tcolorbox}
2425 \begin{tcolorbox}[adjusted title={\showcmd{qcap}[cyan]}]
2426 \[
2427 \q{
2428 \qcap
2429 }
2430 \]
2431 \end{tcolorbox}
2432 \begin{tcolorbox}[adjusted title={\showcmd{qcup}[cyan]}]
2433 \[
2434 \q{
2435 \qcup
2436 }
2437 \]
2438 \end{tcolorbox}
2439 \begin{tcolorbox}[adjusted title={\showcmd{qwireu}[cyan]}]
2440 \[\q{\qwireup}\]
2441 \end{tcolorbox}
2442 \begin{tcolorbox}[adjusted title={\showcmd{qwired}[cyan]}]
2443 \[\q{\qwiredown}\]
2444 \end{tcolorbox}
2445 \begin{tcolorbox}[adjusted title={\showcmd{qwireuu}[cyan]}]
2446 \[\q{\qwireuu}\]
2447 \end{tcolorbox}
2448 \begin{tcolorbox}[adjusted title={\showcmd{qwiredd}[cyan]}]
2449 \[\q{\qwiredd}\]
2450 \end{tcolorbox}
2451 \begin{tcolorbox}[adjusted title={\showcmd{qasym}[cyan]}]
2452 \[
2453 \q{
2454 \qasym
2455 }
2456 \]
2457 \end{tcolorbox}
2458 \begin{tcolorbox}[adjusted title={\showcmd{qtrans}[cyan]}]
2459 \[
2460 \q{
2461 \qtrans
2462 }
2463 \]
2464 \end{tcolorbox}
2465 \begin{tcolorbox}[adjusted title={\showcmd{adj}[cyan]}]
2466 \[
2467 \q{
2468 \qadj
2469 }
2470 \]
2471 \end{tcolorbox}
2472 \begin{tcolorbox}[adjusted title={\showcmd{qconj}[cyan]}]
2473 \[
2474 \q{
2475 \qconj
2476 }
2477 \]
2478 \end{tcolorbox}
2479 \begin{tcolorbox}[adjusted title={\showcmd{qcaprev}[cyan]}]
2480 \[
2481 \q{
2482 \qcaprev
2483 }
2484 \]
2485 \end{tcolorbox}
2486 \begin{tcolorbox}[adjusted title={\showcmd{qcuprev}[cyan]}]
2487 \[
2488 \q{
2489 \qcuprev
2490 }
2491 \]
2492 \end{tcolorbox}
2493 \end{tcbraster}
2494 \addcontentsline{toc}{section}{References}
2495 \begin{thebibliography}{99}
2496 \bibitem{tikz-manual}
2497 Till Tantau,
2498 \textit{The TikZ and PGF Packages Manual for Version 3.1.10},
2499 Institut für Theoretische Informatik, Universität zu Lübeck,
2500 n.d.,
2501 \url{https://github.com/pgf-tikz/pgf}
2502 (retrieved March 22, 2025).
2503 \bibitem{geniussorting}
2504 Anonymous,
2505 \textit{Genius Sorting Algorithm},
2506 4chan Programming Board,
2507 January 20, 2011,
2508 \url{https://dis.4chan.org/read/prog/1295544154}
2509 (accessed January 20, 2011; link currently inactive).
2510 \bibitem{gfxhatena}
2511 gfx,
2512 \textit{Joushiki wo kutsugaesu so-to arugorizumu! Sono na mo "sleep sort"!},
2513 Hatena Diary,
2514 May 19, 2011,
2515 \url{https://gfx.hatenadiary.org/entry/20110519/1305810786}.
2516 \bibitem{literateprograms}
2517 LiteratePrograms,
2518 \textit{Turing Machine Simulator in \LaTeX},
2519 \url{https://literateprograms.org/turing_machine_simulator__latex_.html},
2520 n.d.,
2521 retrieved March 22, 2025.
2522 \bibitem{overleaf}
2523 Overleaf,
2524 \textit{\LaTeX\ is More Powerful than You Think: Computing the Fibonacci Numbers and Turing Completeness},
2525 \url{https://www.overleaf.com/learn/latex/Articles/LaTeX_is_More_Powerful_than_you_Think_-_Computing_the_Fibonacci_Numbers_and_Turing_Completeness},
2526 n.d.,
2527 retrieved March 22, 2025.
2528 \end{thebibliography}
2529
2530 \begin{changelog}[author=Ninna Ryota, sectioncmd=\section*]
2531
2532 \shortversion{
2533 v=1.1.2, date=2025-07-28,
2534 changes={Fixed typos in the English documentation (qworld\_en.pdf) and the corresponding TeX source file (qworld\_en.tex). This change only affects the English documentation (qworld\_en.pdf) and the TeX source file (qworld\_en.tex), and does not impact the style file.}
2535 }
2536
2537 \begin{version}[v=1.1.1, date=2025-04-14]
2538 \added
2539 \item Color annotation for wires and tangles\par The \showcmd[]{frame color} attribute is now supported for CAP and CUP structures, allowing wires to express object identity through color. Additionally, BRAIDING now supports separate \showcmd[]{L color} and \showcmd[]{R color} options for independently coloring the left and right wires.
2540 \fixed
2541 \item Improved wire rendering\par The rendering of curves has been refined to produce smoother and more aesthetically coherent diagrams.
2542 \end{version}
2543
2544 \begin{version}[v=1.1.0, date=2025-04-03]
2545 \changed
2546 \item Argument structure revised for symbol commands\par The following commands were updated to support key-value-style optional arguments instead of mandatory positional arguments:
2547 \begin{itemize}
2548 \item \showcmd{symbolI}
2549 \item \showcmd{symbols}
2550 \item \showcmd{symbolS}
2551 \item \showcmd{symbolO}
2552 \item \showcmd{symboln}
2553 \item \showcmd{symbolN}
2554 \end{itemize}
2555 \begin{description}
2556 \item[Previous syntax] \showcmd{symbolI[i]\{ID\}\{text\}[position options]}[old]
2557 \item[New syntax] \showcmd{symbolI[i]\{text\}[id=ID, position options]}[new]
2558 \end{description}
2559 With this revision, the \showcmd[]{ID} parameter is now optional. In simple cases, \showcmd{symbolI\{text\}}[new] suffices. This change enables more concise and readable definitions.
2560 \added
2561 \item English documentation\par An English version of the user guide has been added.
2562 \end{version}
2563
2564 \shortversion{
2565 v=1.0.0,
2566 date=2025-04-01,
2567 changes={Initial release}
2568 }
2569
2570 \end{changelog}
2571
2572 \section*{License and Copyright}
2573
2574 This package is distributed under the \textbf{LaTeX Project Public License (LPPL)}, version 1.3c or later.
2575 For details, see \url{https://www.latex-project.org/lppl.txt}.
2576
2577 Copyright \textcopyright 2025 Niina Ryota
2578
2579 You are free to distribute and modify this package under the terms of LPPL.
2580 However, any modified versions \textbf{must not} be distributed under the original name, and the original author must be credited.
2581 \end{document}