\documentclass[11pt]{article}
\usepackage{palatino}
\usepackage{amsmath}
\usepackage{pdflscape}
\usepackage[margin=2cm]{geometry}
\begin{document}

\title{Prettyprinting Intermediate Computations from a Bytecode}
\maketitle

\noindent Reference: \textit{Functional programming languages Part II: abstract machines, Xavier Leroy, INRIA Rocquencourt, MPRI 2-4-2, 2007}

\section{Programs}

Programs are defined like this. Variable accesses have been converted to deBruijn indices when the program was converted from an OCaml one.

{\small\begin{verbatim}
type op = Add | Sub | Mul | Div

type prog =
  Int of int
| Bool of bool
| Var of int
| Eq of prog * prog
| Op of prog * op * prog
| Apply of prog * prog
| Lambda of prog
| Let of prog * prog
| If of prog * prog * prog\end{verbatim}}

\noindent For example, the OCaml program

\medskip
\noindent\texttt{let x = 5 in if x = 4 then 1 else (fun x -> x + 1) 2}
\medskip

\noindent may be represented as:

\medskip
{\small
\begin{verbatim}Let(Int 5,
    If(Eq(Var 1, Int 4),
       Int 1,
       Apply(Lambda(Op(Var 1, Add, Int 1), Int 2))))\end{verbatim}}

\section{Compilation Scheme}

The abstract machine instructions are as followed (Leroy plus BOOL, IF, EQ)

\medskip

\noindent
EMPTY\\
INT(integer)\\
BOOL(boolean)\\
OP(op)\\
EQ\\
ACCESS(integer)\\
CLOSURE(instructions)\\
LET\\
ENDLET\\
APPLY\\
RETURN\\
IF
\medskip

\noindent Here is the compilation scheme, again extended from Leroy:

\begin{align*}
\mathcal{C}(\texttt{Int}(i)) &= \text{INT}(i)\\
\mathcal{C}(\texttt{Bool}(b)) &= \text{BOOL}(b)\\
\mathcal{C}(\texttt{Op}(a, \oplus, b)) &= \mathcal{C}(a); \mathcal{C}(b); \text{OP}(\oplus)\\
\mathcal{C}(\texttt{Eq}(a, b)) &= \mathcal{C}(a); \mathcal{C}(b); \text{EQ}\\
\mathcal{C}(\texttt{Var}(n)) &= \text{ACCESS}(n)\\
\mathcal{C}(\texttt{Lambda}(a)) &= \text{CLOSURE}(\mathcal{C}(a); \text{RETURN})\\
\mathcal{C}(\texttt{Let}(a, b)) &= \mathcal{C}(a); \text{LET}; \mathcal{C}(b); \text{ENDLET}\\
\mathcal{C}(\texttt{Apply}(a, b)) &= \mathcal{C}(a); \mathcal{C}(b); \text{APPLY}\\
\mathcal{C}(\texttt{If}(a, b, c)) &= \mathcal{C}(\texttt{Lambda}(b)); \mathcal{C}(\texttt{Lambda}(c)); \mathcal{C}(a); \text{IF}
\end{align*}

\noindent So our example

\medskip
\noindent\texttt{let x = 5 in if x = 4 then 1 else (fun x -> x + 1) 2}
\medskip

\noindent compiles to (including an EMPTY at the end):

\medskip

\noindent INT 5\\
LET\\
CLOSURE\\
\phantom{\ \ }\ INT 1\\
\phantom{\ \ }\ RETURN\\
CLOSURE\\
\phantom{\ \ } CLOSURE\\
\phantom{\ \ \ \ } ACCESS 1\\
\phantom{\ \ \ \ } INT 1\\
\phantom{\ \ \ \ } OP +\\
\phantom{\ \ \ \ } RETURN\\
\phantom{\ \ } INT 2\\
\phantom{\ \ } APPLY\\
\phantom{\ \ } RETURN\\
ACCESS 1\\
INT 4\\
EQ\\
BRANCH\\
ENDLET\\
EMPTY

\medskip

\section{Evaluation Scheme}

Here is the evaluation scheme $\mathcal{E}$, again extended from Leroy.

\bigskip

\begin{tabular}{l|l|l||l|l|l}
\multicolumn{3}{c}{Machine state before}&\multicolumn{3}{c}{Machine state after}                       \\
Code                    & Env   & Stack                          & Code   & Env    & Stack             \\
$\text{INT}(i);c$       & $e$   & $s$                            & $c$    & $e$    & $i.s$             \\
$\text{BOOL}(b);c$      & $e$   & $s$                            & $c$    & $e$    & $b.s$             \\
$\text{OP}(\oplus);c$   & $e$   & $i.i'.s$                       & $c$    & $e$    & $\oplus(i, i').s$ \\
$\text{EQ};c$           & $e$   & $i.i'.s$                       & $c$    & $e$    & $(i = i').s$      \\
$\text{ACCESS}(n);c$    & $e$   & $s$                            & $c$    & $e$    & $e(n).s$          \\
$\text{CLOSURE}(c');c$  & $e$   & $s$                            & $c$    & $e$    & $c'[e].s$         \\
$\text{LET};c$          & $e$   & $v.s$                          & $c$    & $v.e$  & $s$               \\
$\text{ENDLET};c$       & $v.e$ & $s$                            & $c$    & $e$    & $s$               \\
$\text{APPLY;c}$        & $e$   & $v.c'[e'].s$                   & $c'$   & $v.e'$ & $c.e.s$           \\
$\text{RETURN;c}$       & $e$   & $v.c'.e'.s$                    & $c'$   & $e'$   & $v.s$             \\
$\text{IF;c}$           & $e$   & $\textsf{T}.c'[e'].c''[e''].s$ & $c'$   & $e'$   & $c[e].s$          \\
$\text{IF;c}$           & $e$   & $\textsf{F}.c'[e'].c''[e''].s$ & $c''$  & $e''$  & $c[e].s$          \\
\end{tabular}

\bigskip

\noindent The final result is at the top of the stack when the code is EMPTY.

\section{Decompilation Scheme}

We need to be able to decompile:

\begin{itemize}
\item Any program which has been compiled by the compilation scheme above.
\item Certain incomplete evaluations under the evaluation scheme above. That is to say, given $(c, s)$ we can decompile a program which represents the evaluation at that stage. We need not be able to decompile arbitrary $(c, e, s)$ triples.
\end{itemize}

\noindent  We add names to \texttt{VarAccess}, \texttt{Lambda} and \texttt{Let}:

\begin{verbatim}
type prog =
  Int of int
| Bool of bool
| VarAccess of name * int
| Eq of prog * prog
| Op of prog * op * prog
| Apply of prog * prog
| Lambda of name * prog
| Let of name * prog * prog
| If of prog * prog * prog\end{verbatim}

\noindent Similarly, we add names to the ACCESS, CLOSURE and LET instructions (not required for evaluation, but only for decompilation).

\bigskip

\noindent
EMPTY\\
INT(integer)\\
BOOL(boolean)\\\
OP(op)\\
EQ\\
ACCESS(name, integer)\\
CLOSURE(name, instructions)\\
LET(name)\\
ENDLET\\
APPLY\\
RETURN\\
IF
\medskip

\noindent Decompilation is performed by going through the instructions in order, holding a stack a little like the evaluation stack, but which may also contain decompiled program fragments -- the empty stack is written $\{\}$. When we have gone through all the instructions, the final program is at the top of the stack. We do not need the environment, since we are not running the code, just decompiling it.

\begin{align*}
\mathcal{D}(\text{EMPTY}, v.s) &= v\\
\mathcal{D}(\text{INT}(i); c, s) &= \mathcal{D}(c, \texttt{Int}(i).s)\\
\mathcal{D}(\text{BOOL}(i); c, s) &= \mathcal{D}(c, \texttt{Bool}(b).s)\\
\mathcal{D}(\text{OP}(\oplus); c, i.i'.s) &= \mathcal{D}(c, \texttt{Op}(i, \oplus, i').s) \\
\mathcal{D}(\text{EQ}; c, i.i'.s) &= \mathcal{D}(c, \texttt{Eq}(i, i').s)\\
\mathcal{D}(\text{ACCESS}(n, l); c, s) &= \mathcal{D}(c, \texttt{VarAccess}(n, l).s)\\
\mathcal{D}(\text{CLOSURE}(n, c'); c, s) &= \mathcal{D}(c, c'[n, \{\}].s)\\
\mathcal{D}(\text{LET}(n); c, v.s) &= \texttt{Let}(n, v, \mathcal{D}(c, s))\\
\mathcal{D}(\text{ENDLET}; c, s) &= \mathcal{D}(c, s)\\
\mathcal{D}(\text{APPLY}; c, v.c'[n, e'].s) &= \texttt{Apply}(\texttt{Lambda(n}, \mathcal{D}(c', \{\}\texttt{))}, v)\\
\mathcal{D}(\text{RETURN}; c, v.c'.e'.s) &= \mathcal{D}(c', v.s)\\
\mathcal{D}(\text{RETURN}; c, s) &= \mathcal{D}(c, s)\\
\mathcal{D}(\text{IF}; c, e.c'[e'].c''[e''].s) &= \mathcal{D}(c, \texttt{If}(e, \mathcal{D}(c', s), \mathcal{D}(c'', s)).s)
\end{align*}

\noindent This decompiler works for:

\begin{itemize}
\item Any program-stack pair (P, \{\}) where P was compiled by $\mathcal{C}$ above.
\item program,stack pair (P, S) which is an intermediate state of the evaluation procedure $\mathcal{E}$ (minus the environment) where P begins with OP or APPLY.
\end{itemize}

\noindent Our example program decompiles properly from bytecode.

\section{Worked examples}

The following pages contain a worked example of the compilation $\mathcal{C}$, the evaluation $\mathcal{E}$, and full-program and partial-evaluation invocations of the decompiler $\mathcal{D}$.

\begin{landscape}

\noindent Compilation under $\mathcal{C}$:

\bigskip

{\small

\noindent$\mathcal{C}$(\texttt{Let(Int 5, If(Eq(Var 1, Int 4), Int 1, Apply(Lambda(Op(Var 1, Add, Int 1), Int 2))))})

\smallskip
\noindent Rule $\mathcal{C}$-\texttt{Let}
\smallskip

\noindent $\mathcal{C}$(\texttt{Int 5}); LET; $\mathcal{C}$(\texttt{If(Eq(Var 1, Int 4), Int 1, Apply(Lambda(Op(Var 1, Add, Int 1), Int 2)))}); ENDLET

\smallskip
\noindent Rule $\mathcal{C}$-\texttt{Int}
\smallskip

\noindent INT 5; LET; $\mathcal{C}$(\texttt{If(Eq(Var 1, Int 4), Int 1, Apply(Lambda(Op(Var 1, Add, Int 1), Int 2)))}); ENDLET

\smallskip
\noindent Rule $\mathcal{C}$-\texttt{If}
\smallskip

\noindent INT 5; LET; $\mathcal{C}$(\texttt{Lambda (Int 1)}); $\mathcal{C}$(\texttt{Lambda(Apply(Lambda(Op(Var 1, Add, Int 1), Int 2)))}); $\mathcal{C}$(\texttt{Eq(Var 1, Int 4)}); IF; ENDLET

\smallskip
\noindent Rule $\mathcal{C}$-\texttt{Eq} then Rule $\mathcal{C}$-\texttt{Eq} then Rule $\mathcal{C}$-\texttt{Eq}
\smallskip

\noindent INT 5; LET; $\mathcal{C}$(\texttt{Lambda (Int 1)}); $\mathcal{C}$(\texttt{Lambda(Apply(Lambda(Op(Var 1, Add, Int 1), Int 2)))}); ACCESS 1; INT 4; EQ; IF; ENDLET

\smallskip
\noindent Rule $\mathcal{C}$-\texttt{Lambda} then Rule $\mathcal{C}$-\texttt{Int}
\smallskip

\noindent INT 5; LET; CLOSURE [INT 1; RETURN]; $\mathcal{C}$(\texttt{Lambda(Apply(Lambda(Op(Var 1, Add, Int 1), Int 2)))}); ACCESS 1; INT 4; EQ; IF; ENDLET

\smallskip
\noindent Rule $\mathcal{C}$-\texttt{Lambda}
\smallskip

\noindent INT 5; LET; CLOSURE [INT 1; RETURN]; CLOSURE [$\mathcal{C}$(\texttt{Apply(Lambda(Op(Var 1, Add, Int 1), Int 2))}); RETURN]; ACCESS 1; INT 4; EQ; IF; ENDLET

\smallskip
\noindent Rule $\mathcal{C}$-\texttt{Apply}
\smallskip

\noindent INT 5; LET; CLOSURE [INT 1; RETURN]; CLOSURE [$\mathcal{C}$(\texttt{Lambda(Op(Var 1, Add, Int 1))}; $\mathcal{C}$(\texttt{Int 2}); APPLY; RETURN]; ACCESS 1; INT 4; EQ; IF; ENDLET

\smallskip
\noindent Rule $\mathcal{C}$-\texttt{Int} then Rule $\mathcal{C}$-\texttt{Lambda} then Rule $\mathcal{C}$-\texttt{Op} then Rule $\mathcal{C}$-\texttt{Var} then Rule $\mathcal{C}$-\texttt{Int}
\smallskip

\noindent INT 5; LET; CLOSURE [INT 1; RETURN]; CLOSURE [CLOSURE [ACCESS 1; INT 1; OP +; RETURN]; INT 2; APPLY; RETURN]; ACCESS 1; INT 4; EQ; IF; ENDLET

}

\newpage

\noindent Evaluation under $\mathcal{E}$. Stacks and environments are written \{items\}, and a closure on the stack is written [instructions]\{environment\}. Environments may be put on the stack.

\bigskip

{\small
\begin{tabular}{l||p{9.5cm}|l|p{9.5cm}}
& \multicolumn{3}{c}{Machine state after}                       \\
Instruction & Code      & Env   & Stack\\
   -        & INT 5; LET; CLOSURE [INT 1; RETURN]; CLOSURE [CLOSURE [ACCESS 1; INT 1; OP +; RETURN]; INT 2; APPLY; RETURN]; ACCESS 1; INT 4; EQ; IF; ENDLET & \{\}  & \{\}\\

INT & LET; CLOSURE [INT 1; RETURN]; CLOSURE [CLOSURE [ACCESS 1; INT 1; OP +; RETURN]; INT 2; APPLY; RETURN]; ACCESS 1; INT 4; EQ; IF; ENDLET& \{\}   & \{5\}\\

LET & CLOSURE [INT 1; RETURN]; CLOSURE [CLOSURE [ACCESS 1; INT 1; OP +; RETURN]; INT 2; APPLY; RETURN]; ACCESS 1; INT 4; EQ; IF; ENDLET & \{5\}   & \{\}\\

CLOSURE & CLOSURE [CLOSURE [ACCESS 1; INT 1; OP +; RETURN]; INT 2; APPLY; RETURN]; ACCESS 1; INT 4; EQ; IF; ENDLET & \{5\}   & \{[INT 1; RETURN]\{5\}\}\\

CLOSURE & ACCESS 1; INT 4; EQ; IF; ENDLET & \{5\} & \{[CLOSURE [ACCESS 1; INT 1; OP +; RETURN]\{5\}; INT 2; APPLY; RETURN]; [INT 1; RETURN]\{5\}\}\\

ACCESS & INT 4; EQ; IF; ENDLET & \{5\}   & \{5; [CLOSURE [ACCESS 1; INT 1; OP +; RETURN]\{5\}; INT 2; APPLY; RETURN]; [INT 1; RETURN]\{5\}\}\\

INT & EQ; IF; ENDLET & \{5\}   & \{4; 5; [CLOSURE [ACCESS 1; INT 1; OP +; RETURN]\{5\}; INT 2; APPLY; RETURN]; [INT 1; RETURN]\{5\}\}\\

EQ & IF; ENDLET & \{5\}   & \{false; [CLOSURE [ACCESS 1; INT 1; OP +; RETURN]\{5\}; INT 2; APPLY; RETURN]; [INT 1; RETURN]\{5\}\}\\

IF & CLOSURE [ACCESS 1; INT 1; OP +; RETURN]; INT 2; APPLY; RETURN & \{5\} & \{[ENDLET]; \{5\}\}\\

CLOSURE & INT 2; APPLY; RETURN & \{5\} & \{[ACCESS 1; INT 1; OP +; RETURN]\{5\}; [ENDLET]; \{5\}\}\\

INT & APPLY; RETURN & \{5\} & \{2; [ACCESS 1; INT 1; OP +; RETURN]\{5\}; [ENDLET]; \{5\}\}\\

APPLY & ACCESS 1; INT 1; OP +; RETURN & \{2; 5\} & \{[RETURN]; \{5\}; [ENDLET]; \{5\}\}\\

ACCESS & INT 1; OP +; RETURN & \{2; 5\} & \{2; [RETURN]; \{5\}; [ENDLET]; \{5\}\}\\

INT & OP +; RETURN & \{2; 5\} & \{1; 2; [RETURN]; \{5\}; [ENDLET]; \{5\}\}\\

OP & RETURN & \{2; 5\} & \{3; [RETURN]; \{5\}; [ENDLET]; \{5\}\}\\

RETURN & EMPTY & \{2; 5\} & \{3; [RETURN]; \{5\}; [ENDLET]; \{5\}\}\\

RETURN & EMPTY & \{5\} & \{3; [ENDLET]; \{5\}\}\\

ENDLET & EMPTY & \{\} & \{3\}\\
EMPTY
\end{tabular}
}

\newpage

{\small

\noindent Decompilation under $\mathcal{D}$ of a program compiled under $\mathcal{C}$, with an empty stack to begin, since the program is unexecuted.

\bigskip

\noindent $\mathcal{D}$(INT 5; LET x; CLOSURE [INT 1; RETURN]; CLOSURE [CLOSURE [ACCESS (x, 1); INT 1; OP +; RETURN]; INT 2; APPLY; RETURN]; ACCESS (x, 1); INT 4; EQ; IF; ENDLET, \{\})

\smallskip
\noindent Rule $\mathcal{D}$-CONST
\smallskip

\noindent $\mathcal{D}$(LET x; CLOSURE [INT 1; RETURN]; CLOSURE [CLOSURE [ACCESS (x, 1); INT 1; OP +; RETURN]; INT 2; APPLY; RETURN]; ACCESS (x, 1); INT 4; EQ; IF; ENDLET, \{\texttt{Int 5}\})

\smallskip
\noindent Rule $\mathcal{D}$-LET
\smallskip

\noindent \texttt{Let(x, }\texttt{Int 5}, $\mathcal{D}$(CLOSURE [INT 1; RETURN]; CLOSURE [CLOSURE [ACCESS (x, 1); INT 1; OP +; RETURN]; INT 2; APPLY; RETURN]; ACCESS (x, 1); INT 4; EQ; IF; ENDLET, \{\})\texttt{)}

\smallskip
\noindent Rule $\mathcal{D}$-CLOSURE
\smallskip

\noindent \texttt{Let(x, }\texttt{Int 5}, $\mathcal{D}$(CLOSURE [CLOSURE [ACCESS (x, 1); INT 1; OP +; RETURN]; INT 2; APPLY; RETURN]; ACCESS (x, 1); INT 4; EQ; IF; ENDLET, \{CLOSURE [INT 1; RETURN]\})\texttt{)}

\smallskip
\noindent Rule $\mathcal{D}$-CLOSURE
\smallskip

\noindent \texttt{Let(x, }\texttt{Int 5}, $\mathcal{D}$(ACCESS (x, 1); INT 4; EQ; IF; ENDLET, \{ CLOSURE [ACCESS (x, 1); INT 1; OP +; RETURN; INT 2; APPLY; RETURN]; CLOSURE [INT 1; RETURN]\})\texttt{)}

\smallskip
\noindent Rule $\mathcal{D}$-ACCESS
\smallskip

\noindent \texttt{Let(x, }\texttt{Int 5}, $\mathcal{D}$(INT 4; EQ; IF; ENDLET, \{\texttt{VarAccess(x, 1)}; CLOSURE [ACCESS (x, 1); INT 1; OP +; RETURN; INT 2; APPLY; RETURN]; CLOSURE [INT 1; RETURN]\})\texttt{)}

\smallskip
\noindent Rule $\mathcal{D}$-INT
\smallskip

\noindent \texttt{Let(x, }\texttt{Int 5}, $\mathcal{D}$(EQ; IF; ENDLET, \{\texttt{Int 4}; \texttt{VarAccess(x, 1)}; CLOSURE [ACCESS (x, 1); INT 1; OP +; RETURN]; INT 2; APPLY; RETURN; CLOSURE [INT 1; RETURN]\})\texttt{)}

\smallskip
\noindent Rule $\mathcal{D}$-EQ
\smallskip

\noindent \texttt{Let(x, }\texttt{Int 5}, $\mathcal{D}$(IF; ENDLET, \{\texttt{Eq(VarAccess (x, 1), Int 4)};  CLOSURE [ACCESS (x, 1); INT 1; OP +; RETURN]; INT 2; APPLY; RETURN; CLOSURE [INT 1; RETURN]\})\texttt{)}

\smallskip
\noindent Rule $\mathcal{D}$-IF
\smallskip

\noindent \texttt{Let(x, }\texttt{Int 5}, $\mathcal{D}$(ENDLET, \{\texttt{If(Eq(VarAccess (x, 1), Int 4)}, $\mathcal{D}$(CLOSURE [ACCESS (x, 1); INT 1; OP +; RETURN]; INT 2; APPLY; RETURN, \{\}), $\mathcal{D}$(CLOSURE [INT 1; RETURN], \{\})\texttt{)}

\smallskip
\noindent Rule $\mathcal{D}$-ENDLET
\smallskip

\noindent \texttt{Let(x, Int 5, If(Eq(VarAccess (x, 1), Int 4)}, $\mathcal{D}$(CLOSURE [ACCESS (x, 1); INT 1; OP +; RETURN]; INT 2; APPLY; RETURN, \{\}), $\mathcal{D}$(CLOSURE [INT 1; RETURN], \{\})\texttt{)}

\smallskip
\noindent Rule $\mathcal{D}$-CLOSURE then $\mathcal{D}$-INT then $\mathcal{D}$-RETURN
\smallskip

\noindent \texttt{Let(x, Int 5, If(Eq(VarAccess (x, 1), Int 4)}, $\mathcal{D}$(CLOSURE [ACCESS (x, 1); INT 1; OP +; RETURN]; INT 2; APPLY; RETURN, \{\}), \texttt{Int 1})\texttt{)}

\smallskip
\noindent Rule $\mathcal{D}$-CLOSURE
\smallskip

\noindent \texttt{Let(x, Int 5, If(Eq(VarAccess (x, 1), Int 4)}, $\mathcal{D}$(INT 2; APPLY; RETURN, \{CLOSURE [ACCESS (x, 1); INT 1; OP +; RETURN]\}), \texttt{Int 1})\texttt{)}

\smallskip
\noindent Rule $\mathcal{D}$-INT
\smallskip

\noindent \texttt{Let(x, Int 5, If(Eq(VarAccess (x, 1), Int 4)}, $\mathcal{D}$(APPLY; RETURN, \{\texttt{Int 2}; CLOSURE [ACCESS (x, 1); INT 1; OP +; RETURN]\}), \texttt{Int 1})\texttt{)}

\smallskip
\noindent Rule $\mathcal{D}$-APPLY
\smallskip

\noindent \texttt{Let(x, Int 5, If(Eq(VarAccess (x, 1), Int 4)}, \ \texttt{Apply(}$\mathcal{D}$(ACCESS (x, 1); INT 1; OP +; RETURN, \{\}), \texttt{Int 2)}, \texttt{Int 1})\texttt{)}

\smallskip
\noindent Rule $\mathcal{D}$-ACCESS then $\mathcal{D}$-INT then $\mathcal{D}$-OP then $\mathcal{D}$-RETURN
\smallskip

\noindent \texttt{Let(x, Int 5, If(Eq(VarAccess (x, 1), Int 4)}, \ \texttt{Apply(Lambda(Op(Var 1, Add, Int 1)), \texttt{Int 2)}, \texttt{Int 1})\texttt{)}}

}

\newpage

{\small

\noindent Decompilation under $\mathcal{D}$ of a program compiled under $\mathcal{C}$ and partially evaluated with $\mathcal{D}$.

\bigskip

\noindent $\mathcal{D}$(IF; ENDLET, {false; [CLOSURE [ACCESS(x, 1); INT 1; OP +; RETURN]; INT 2; APPLY; RETURN]; [INT 1; RETURN]})

\smallskip
\noindent Rule $\mathcal{D}$-IF
\smallskip

\noindent $\mathcal{D}$(ENDLET, \texttt{If (false,} $\mathcal{D}$([INT 1; RETURN], \{\})) $\mathcal{D}$([CLOSURE [ACCESS(x, 1); INT 1; OP +: RETURN]; INT 2; APPLY; RETURN], \{\}), \{\})

\smallskip
\noindent Rule $\mathcal{D}$-ENDLET
\smallskip

\noindent \texttt{If (Bool false,} $\mathcal{D}$([INT 1; RETURN], \{\}), $\mathcal{D}$([CLOSURE [ACCESS(x, 1); INT 1; OP +: RETURN]; INT 2; APPLY; RETURN]\{\}), \texttt{)}

\smallskip
\noindent Rule $\mathcal{D}$-INT then $\mathcal{D}$-RETURN
\smallskip

\noindent \texttt{If (Bool false,} \texttt{Int 1}, $\mathcal{D}$([CLOSURE [ACCESS(x, 1); INT 1; OP +: RETURN]; INT 2; APPLY; RETURN]\{\}),\texttt{)}

\smallskip
\noindent Rule $\mathcal{D}$-CLOSURE
\smallskip

\noindent \texttt{If (Bool false,} \texttt{Int 1}, $\mathcal{D}$([INT 2; APPLY; RETURN], \{[ACCESS(x, 1); INT 1; OP +: RETURN]\})\texttt{)}

\smallskip
\noindent Rule $\mathcal{D}$-INT
\smallskip

\noindent \texttt{If (Bool false,} \texttt{Int 1}, $\mathcal{D}$([APPLY; RETURN], \{\texttt{Int 2}; [ACCESS(x, 1); INT 1; OP +: RETURN]\})\texttt{)}

\smallskip
\noindent Rule $\mathcal{D}$-APPLY
\smallskip

\noindent \texttt{If (Bool false,}, \texttt{Int 1}, \texttt{Apply (Lambda(x, }$\mathcal{D}$(ACCESS(x, 1); INT 1; OP +: RETURN, \{\}), \texttt{Int 2))}\texttt{)}

\smallskip
\noindent Rule $\mathcal{D}$-ACCESS
\smallskip

\noindent \texttt{If (Bool false,} \texttt{Int 1}, \texttt{Apply (Lambda(x, }$\mathcal{D}$(INT 1; OP +; RETURN, \{\texttt{VarAccess(x, 1)}\}), \texttt{Int 2))}\texttt{)}

\smallskip
\noindent Rule $\mathcal{D}$-INT
\smallskip

\noindent \texttt{If (Bool false,} \texttt{Int 1}, \texttt{Apply (Lambda(x, }$\mathcal{D}$(OP +; RETURN, \{\texttt{Int 1; VarAccess(x, 1)}\}), \texttt{Int 2))}\texttt{)}

\smallskip
\noindent Rule $\mathcal{D}$-OP
\smallskip

\noindent \texttt{If (Bool false,} \texttt{Int 1}, \texttt{Apply (Lambda(x, }$\mathcal{D}$(RETURN, \{\texttt{Op(VarAccess(x, 1), Add, Int 1)}\}), \texttt{Int 2))}\texttt{)}

\smallskip
\noindent Rule $\mathcal{D}$-RETURN
\smallskip

\noindent \texttt{If (Bool false,} \texttt{Int 1}, \texttt{Apply (Lambda(x, Op(VarAccess(x, 1), Add, Int 1)}, \texttt{Int 2))}\texttt{)}

\bigskip

\noindent This is the program \texttt{if false then 1 else (fun x -> x + 1) 2}, as required.

}\end{landscape}

\end{document}


\section{Introduction}

% --------------------------------------------------------------------------------------------------------------
\begin{frame}
\frametitle{Pagerank}
\begin{figure}
	\centering
	\includegraphics[width=0.8\textwidth]{pagerank1.png}
	\caption{PageRank example 1 \cite{prsigner}}
\end{figure}
\begin{itemize}
  \item A page has a high PageRank $R$ if
  \begin{itemize}
    \item there are many pages linking to it
    \item or, if there are some pages with a high PageRank
linking to it
  \end{itemize}
\end{itemize}
\end{frame}
% --------------------------------------------------------------------------------------------------------------

% --------------------------------------------------------------------------------------------------------------
\begin{frame}
\frametitle{PageRank}

\begin{minipage}[l]{0.5\textwidth}
\textbf{$$
R(P_i)= \sum_{P_j \in B_i}\frac{R(P_j)}{L_j}
$$}
\begin{itemize}
  \item where
  \begin{itemize}
    \item $B_i$ is the set of pages that link to page $P_i$
    \item $L_j$ is the number of outgoing links for page $P_j$
linking to it
  \end{itemize}
\end{itemize}
\end{minipage}
\begin{minipage}[l]{0.49\textwidth}
\begin{figure}
	\centering
	\includegraphics[width=\textwidth]{pagerank2.png}
	\caption{PageRank example 2 \cite{prsigner}}
\end{figure}
\end{minipage}

\end{frame}
% --------------------------------------------------------------------------------------------------------------

% --------------------------------------------------------------------------------------------------------------
\begin{frame}
\begin{figure}
	\centering
	\includegraphics[width=0.65\textwidth]{squirrel.png}
	\caption*{\cite{squirrel}}
\end{figure}
\end{frame}
% --------------------------------------------------------------------------------------------------------------

% --------------------------------------------------------------------------------------------------------------
\begin{frame}
\frametitle{Apache Flink}
\begin{itemize}
\item Open source framework for distributed Big Data Analytics
\item Exploits:
	\begin{itemize}
	\item data streaming
	\item in-memory processing
	\item iteration operators
	\end{itemize}
to improve performance
\item Formerly Stratosphere (Flink means agile)
\item Developed here at TU Berlin
\end{itemize}
\end{frame}
% --------------------------------------------------------------------------------------------------------------

% --------------------------------------------------------------------------------------------------------------
\begin{frame}
\begin{figure}
	\centering
	\includegraphics[width=0.9\textwidth]{repetition.jpg}
	\caption*{\cite{repetition}}
\end{figure}
\end{frame}
% --------------------------------------------------------------------------------------------------------------

% --------------------------------------------------------------------------------------------------------------
\begin{frame}
\frametitle{Apache Flink: 2 possible setups}

\begin{minipage}[l]{0.5\textwidth}
\begin{figure}
	\centering
	\includegraphics[width=0.9\textwidth]{pomxml.png}
	\caption{Maven}
\end{figure}
\end{minipage}
\begin{minipage}[l]{0.49\textwidth}
\begin{figure}
	\centering
	\includegraphics[width=\textwidth]{dashboard.png}
	\caption{Binary version (self compiled)}
\end{figure}
\end{minipage}
\end{frame}
% --------------------------------------------------------------------------------------------------------------

\begin{frame}
\frametitle{Demo}
\begin{figure}
	\centering
	\includegraphics[width=0.9\textwidth]{job.png}
	\caption{Visualisation of a Flink job}
\end{figure}
\end{frame}

% --------------------------------------------------------------------------------------------------------------
\begin{frame}
\frametitle{Apache Flink: Gelly}

\begin{figure}
	\centering
	\includegraphics[width=\textwidth]{gelly.png}
	\caption{Gelly}
\end{figure}

\end{frame}
% --------------------------------------------------------------------------------------------------------------

% --------------------------------------------------------------------------------------------------------------
\begin{frame}
\frametitle{Apache Flink: Gelly}
\begin{itemize}
\item Large-scale graph processing API
\item On top of Flink's Java API
\item Off-the shelf library methods (e.g. PageRank)
\item Iterative algorithms
\end{itemize}

\end{frame}
% --------------------------------------------------------------------------------------------------------------


\documentclass[12pt,letter,notitlepage]{article}
\usepackage{url,graphicx,bm,latexsym,amsmath,amssymb,comment,diagbox}
\pagestyle{plain}
\textwidth 6in
\textheight 9in
\topmargin -0.75in
\oddsidemargin 0.25in

%-----------------------
\begin{document}

\title{Perceived Randomness: Pseudo-Random Number Generators \& Human Interpretation}

\author{Kyle Carson \\
\url{kylecarson@cs.ucsb.edu} \\
Department of Computer Science \\
University of California Santa Barbara
}

\date{June 17, 2017}

\maketitle % \thispagestyle{plain} \thispagestyle{empty}

\begin{abstract}
Random number generators represent a core building block within cryptography, in some cases forming the basis of software and hardware encryption. While true randomness requires specially designed hardware, many software implementations, known "pseudo-random" or "deterministic" number generators, exist. From efficiency of computation to the level of precision, these software-implemented algorithms differ along many vectors. In applied cryptography and beyond, there exist instances where humans directly interacting with the results of these generators may interpret them with their own concept of what is considered random. In this paper, we compare various DRNGs in terms of multiple quality metrics. As an additional exercise, we analyze the shortcomings of these algorithms against human interpretation, and design a method which introduces various types of biasing to these generators with the intent of improving the "perceived randomness".
\end{abstract}

\section{Introduction}

While many deterministic number generators, or "DRNGs", share a basis in modular arithmetic of primes, the finer details of their implementation tend to play a crucial role in their overall performance. Contrary to "true" random number generators which are designed at the hardware level around some source of classical or quantum physical entropy, the randomness of DRNGs is backed by certain assumptions about the complexity or irreversible nature of the building blocks used to form the algorithms.

For a DRNG algorithm to be considered for all intents and purposes cryptographically secure, there exists a general set of properties and behaviors that need to be met. The algorithm should take some k-bit input as a seed, preferably from a source of true randomness, and should output some n-bit random value. Some part of this output should then contribute to the seeding of the next call to the algorithm, in a way that produces a statistically uniform distribution of random values over multiple calls. Of important note here is that, for a given seed, successive calls to a DRNG algorithm will produce some statics stream of values. That is, if one were to make successive calls again to the algorithm with the same initial seed as before, the stream of values produced will be exactly the same as before.

Some tests used to quantify the algorithms include the polynomial-time statistical test, which holds if no polynomial-time approach can distinguish the statistical difference of randomness between a DRNG and a truly random generator with probability greater than 0.5. Another test, the next-bit test, holds true if for the first m-bits of some output O, the m+1 bit cannot be predicted with statistical probability greater than 0.5. Following the basic model for structuring the algorithm and passing these tests quantifies a DRNG algorithm as cryptographically secure.

\section{DRNGs}

To attain a more applied understanding of these algorithms as described above, we've implemented seven different approaches including LCG, BBS, RSA, MSRSA, RAB, PG, and NR. Below we discuss the general principles for each algorithm, and anything of interest regarding each algorithms' actual implementation. All of the code was written in C, and can be found at \url{https://github.com/carsonkk/drngs}.

\subsection{LCG}

Linear Congruential Generator is a simple deterministic algorithm based on modular arithmetic of the previous output to produce the next output:
\[x_{\text{i+1}} = a * x_i + b ({\text{mod n}})\]
Depending on the values used to seed the algorithm, a sequence of some static window size is formed, such that once all of the values in the window have been produced, the sequence will wrap back around and repeat itself. There's many different options for what values to set the multiplicative and adder factors too depending on the application, however going by ANSI standard we set $a = 1103515245, b = 12345, n = 0x80000000$.

\subsection{BBS}

Blum-Blum-Shub is based on the following equation, where the modulus value is the multiplication of two large primes:
\[x_{\text{i+1}} = x_i^2 ({\text{mod n}})\]
\[n = p*q\]
Some important properties must hold for the algorithm to behave as desired, including the seed value and n being co-prime and the primes $p, q$ should both be congruent to $3{\text{mod 4}}$. The actual output of the single pass is used to seed the next pass, however the only information used from an output towards the generated value is a singular bit of the output. Common bit outputs include even parity, odd parity, and the least significant bit. Therefore to actually generate a value, one must define some desired level of precision and run the algorithm that many times to fully form a generated value.

This pattern of using a single bit and doing multiple passes for some level of precision is quite common, and ends up being used in all of the following algorithms

\subsection{RAB}

The Rabin algorithm is a modified form of the the BBS algorithm:
\[x'_{\text{i+1}} = x_i^2 ({\text{mod n}})\]
\[x_{\text{i+1}} = (x'_{\text{i+1}} < n/2) \text{ ? } x'_{\text{i+1}} \text{ : } n - x'_{\text{i+1}}\]
\[n = p*q\]

\subsection{RSA}

RSA like many of these algorithms is based on the factoring problem, using a much more involved series of equations to generate its asymmetric results:
\[x_{\text{i+1}} = x_i^e ({\text{mod n}})\]
\[e \in [2,\phi-1] {\text{ with }} gcd(e,\phi) = 1\]
\[\phi = (p-1)*(q-1)\]
\[n = p*q\]

\subsection{MSRSA}

A modified version of RSA, in this case referred to as Micali-Schnorr RSA, improves the overall efficiency of traditional RSA. Simply speaking, this is done by extracting more bits from each exponentiation, making modifications to both the range for the exponent $e$ and how the bits for both successive seeding and output are chosen.

\subsection{PG}

The Power Generator algorithm derives its strength from using primitive elements of a set for a given primes to perform modular exponentiation. Due to how expensive it is to compute primitive elements for significantly large primes, we pre-computed a set of primes and associated primitives and used them to drive the algorithm. While this greatly increased the efficiency of the computation, a less than desirable result of this was a significant limit on the range of values that could be generated, particularly when using smaller primes. A better approach would be to invest the computational power to generate primitives for large primes and index them for future use, however this would take a non-trivial amount of time to complete.
\[x_{\text{i+1}} = g^{x_i} ({\text{mod p}})\]

\subsection{NR}

The Naor-Reingold algorithm is similar to the Blum-Blum-Shub algorithm in that tis complexity is dependent upon the inability of an attacker to factor large prime integers. It uses a few building blocks of its own for it's computation, including a binary vectoring function, a modular product function, and a integer vector comparison function. The binary vectoring function ($bin_k(u)$) takes two integer parameters, $k$ and $u$, and translates the $k$-least-significant-bits of $u$ into a binary vector array. If $u$ has less bits than the value of $k$, the vector array's most-significant-bits are padded with 0's. The modular product function ($dot$) takes two binary vectors of the same length and takes the summation of the products of each bit from the two vectors, applying a modulus of 2 to the result. Finally the vector comparison function ($f(A,b)$) takes two vector parameters, $A$ which is of integers and length $2k$, and b which is a binary vector of length $k$. The values in $A$ are in pairs, where the first value is relevant if the corresponding bit in $b$ is 0, or the second value is relevant if the bit is 1. Thus the function selects each of the relevant integers from $A$ using $b$, then returns their summation. These functions are then used in the actual computation of the generated value:
\[b = {\text{bin}}_k(i)\]
\[u = f(A,b)\]
\[v = g^u ({\text{mod n}})\]
\[x_{\text{i+1}} = x_i {\text{ dot }} {\text{bin}}_{2k}(v)\]

\section{Testing}

\subsection{Setup}

The test setup for measuring the quality of each algorithm was based on two inter-related metrics: CPU cycles and real-world time of execution. To somewhat normalize the precision between each algorithm, each one's random function call uses the same methodology as LCG in which the upper-order magnitude of bits is used when returning the actual output. The experiment was performed multiple times, varying the number of successive calls made to each algorithm as outlined below in Table 1 and Table 2.

\begin{table}
\centering
\begin{tabular}{|l||*{7}{c|}}\hline
\backslashbox{Algo}{Calls}
&\makebox[3em]{10}&\makebox[3em]{25}&\makebox[3em]{100}&\makebox[3em]{250}
&\makebox[3em]{10000}&\makebox[3em]{100000}&\makebox[3em]{1000000}\\\hline\hline
LCG&0.0&0.0&0.0&0.0&0.0&0.001&0.012\\\hline
BBS&0.0&0.0&0.0&0.0&0.006&0.064&0.468\\\hline
RAB&0.0&0.0&0.0&0.0&0.008&0.077&0.524\\\hline
RSA&2.53&6.242&26.536&70.27&-&-&-\\\hline
MSRSA&0.0&0.0&0.0&0.0&0.051&0.275&2.432\\\hline
PG&0.0&0.0&0.0&0.0&0.033&0.276&2.206\\\hline
NR&4.89&28.934&444.311&504.85&-&-&-\\\hline
\end{tabular}
\caption{\label{tab:table-name}Algorithm speed in terms of real-world computation time (seconds)}
\end{table}

\begin{table}
\centering
\begin{tabular}{|l||*{7}{c|}}\hline
\backslashbox{Algo}{Calls}
&\makebox[3em]{10}&\makebox[3em]{25}&\makebox[3em]{100}&\makebox[3em]{250}
&\makebox[3em]{10000}&\makebox[3em]{100000}&\makebox[3em]{1000000}\\\hline\hline
LCG&1&1&2&3&100&1126&21486\\\hline
BBS&4&11&41&105&6750&60364&453863\\\hline
RAB&6&14&53&132&8616&68644&538605\\\hline
RSA&2044421&7107596&25926498&66659430&-&-&-\\\hline
MSRSA&41&32&243&607&37529&287388&2544693\\\hline
PG&29&55&214&533&37895&283791&2154358\\\hline
NR&4177409&27015995&416989667&2652261381&-&-&-\\\hline
\end{tabular}
\caption{\label{tab:table-name}Algorithm speed in terms of CPU cycles}
\end{table}

\subsection{Results}

From the data above we can see a massive disparity in the performance of RSA and NR compared to the rest of the algorithms. RSA's inefficiency in the case is do to the large size of $e$ as a result of the values used to seed the algorithm, requiring each pass to loop a non-trivial number of times. MSRSA avoids this by using a commonly agreed upon static value of $e$, greatly reducing the runtime. The results of PG are also a bit skewed, as it uses a relatively small index of prime/primitive pairs, where the primes themselves are quite small. This becomes more evident when using the $print$ test in the repository and observing the values output by each algorithm side-by-side, as the resolution of PG's output is noticeably more limited.

\section{BRAND}

While each of the aforementioned algorithms strives to produce a uniformly distributed set of seemingly random variables, they tend to have some shortcomings when used in applications. The range of values they produce are often limited to some {[}$0, RAND\_MAX${)}, which may be problematic in that both the desired range size may too big or too small, or the min and max values themselves aren't ideal. If a user wants to use one of these algorithms in an applied manner for a range they control, a naive solution is often something along the lines of:
\[val = min + rand() \% (max - min)\]
The problem with this is it introduces a statistically detectable bias when the modulus doesn't perfectly divide into the $RAND\_MAX$ of the $rand()$ function.

As a solution to this, we provide $brand$, a set of wrapper functions around C's implementation of $rand()$, which is fundamentally based upon LCG. With this library, the default $min$ and $max$ for the range of random values is still $0$ and $RAND\_MAX$, however now the user can set the limits of the range, then use the wrapper functions to generate a statistically uniform distribution of random variables within the given range.

The standard flow for using $brand$ is to first seed C's built in $rand()$ function however you like; typically this is done through a call to $srand(time(NULL))$. Next, the user can use $brand$'s limit setting functions $bsetn()$, $bsetx()$, and $bsetnx()$ to define the desired range. Next the user simply calls $brand()$ as many times as they want to get the desired value, and finally when they're done using the library call $bcln()$ to clean up dynamically allocated memory. An additional function $brandd()$ is also available, which uses $brand()$ internally to generate a random value in the range {[}$0.0,1.0${)}, with the resolution of the result controlled by the limits set.

With this we now have a well functioning RNG library based on LCG in which we can control the range, but now we want to add one more piece of functionality. When it comes to human perception of randomness, people tend to apply their own biases to what they perceive as random, sometimes without even realizing it. A prime example of this is the "shuffle" button in any sort of music or media software. The expectation when listening to a library of music with the shuffle button enabled is that the software will cycle through the music and select the order to play songs in at random. If, for example, a user has a library of 1,000 songs being shuffled, and the RNG function happens to select the same song twice back to back before playing any other song, the user will likely be annoyed by hearing a repeat, breaking their biased perception of "randomness".

Thus $brand$ has an additional wrapper function, $brandus()$, that aims to produce a uniquely random stream of values for a given range. For a given range of size $N$, it achieves this by allocating an array of length $N$ and setting each value of the array to be the corresponding value in the range. It then generates a random value within the range, removing the minimum offset, and uses that as an index into the array to find the value to return. With that value saved, it then shifts all values beyond the output value down in the array, effectively removing it from the set of available values, and decreases the maximum range value by one. Some performance implications of this include the cache array must be $O(N)$, an $O(1)$ lookup time as the random value generated is just an index, and a $(N/2)$ average update time factor.

While this works great for smaller ranges and always ensures a unique stream of random values for $N$ passes on a range of size $N$, it has two shortcomings. The first being that, when all $N$ values have been generated, it's behavior is that it will reset the values in the array and begin a new unique stream. This is fine, except that say in our previous example song 1000 plays at the very end in the first full pass, and the very beginning in the second full pass, then we'll have two back-to-back instances of the same object and will have again broken our notion of "perceived randomness". The second shortcoming is the memory footprint of this method. For any non-trivial range of values, the method will take up a substantial amount of memory as it needs to index every single value (at least initially).

Some potential future work for this cached indexing approach could include an alternative cache method which only caches the most recent $X$ amount of values out of the total $N$ range, where $X << N$. Some potential issues with this include lookup failures and having to do multiple retries, however these could likely be mitigated by [placing a strict limit on the size of the local cache relative to the overall size of the range.

\section{Conclusion}

DRNGs can vary widely in both the approaches they take to achieve cryptographic security and statistical randomness, and the actual performance that comes as a result. Some are much more specialized, such as RSA for asymmetric key encryption, while others are much more broad in their applications, like LCG. Beyond the algorithms themselves, ensuring statistical uniformity in a random distribution where the range or uniqueness of a value matters is surprisingly non-trivial to implement, however in applications that interface directly with users or use cases such as procedural generation, these properties can be invaluable.

\end{document}


\documentclass[a4paper]{article}
\usepackage{amsmath,amssymb,amsthm,tikz,parskip,lplfitch}
\usetikzlibrary{decorations.text,trees,positioning}

\title{Semantic Tableaux}
\author{Blat Blatnik}
\date{July, 2020}

\begin{document}
\maketitle

\tikzset{%
	l/.style={%
		baseline, level distance = 2em
	}
}

\section{First Order Logic (FOL)}
\begin{center}
	\renewcommand{\arraystretch}{2.5}
	\begin{tabular}{cc}
		\multicolumn{2}{c}{
		 	\begin{tikzpicture}[l]
		 	\node {$\lnot\lnot$ A}
		 	[->]
		 	child {node[below]{A}};
		 	\end{tikzpicture}
		}
		\\
		\begin{tikzpicture}[l]
			\node {A $\land$ B}
			[->]
			child {node[below,align=center]{A\\[4]B}};
		\end{tikzpicture}
		&
		\begin{tikzpicture}[l]
			\node {$\lnot$(A $\land$ B)}
			[->]
			child {node[below]{$\lnot$A}}
			child {node[below]{$\lnot$B}};
		\end{tikzpicture}
		\\
		\begin{tikzpicture}[l]
			\node {A $\lor$ B}
			[->]
			child {node[below]{A}}
			child {node[below]{B}};
		\end{tikzpicture}
		&
		\begin{tikzpicture}[l]
			\node {$\lnot$(A $\lor$ B)}
			[->]
			child {node[below,align=center]{$\lnot$A\\[4]$\lnot$B}};
		\end{tikzpicture}
		\\
		\begin{tikzpicture}[l]
			\node {A $\supset$ B}
			[->]
			child {node[below]{$\lnot$A}}
			child {node[below]{B}};
		\end{tikzpicture}
		&
		\begin{tikzpicture}[l]
			\node {$\lnot$(A $\supset$ B)}
			[->]
			child {node[below,align=center]{A\\[4]$\lnot$B}};
		\end{tikzpicture}
		\\
		\begin{tikzpicture}[l]
			\node {A $\equiv$ B}
			[->]
			child {node[below,align=center]{A\\[4]B}}
			child {node[below,align=center]{$\lnot$A\\[4]$\lnot$B}};
		\end{tikzpicture}
		&
		\begin{tikzpicture}[l]
			\node {$\lnot$(A $\equiv$ B)}
			[->]
			child {node[below,align=center]{$\lnot$A\\[4]B}}
			child {node[below,align=center]{A\\[4]$\lnot$B}};
		\end{tikzpicture}
		\\
	\end{tabular}
\end{center}

\vspace{2.0em}
\textbf{Closure condition}: A branch of closes if it contains both A and $\lnot$A.

\textbf{Counter-model procedure}: Take any open branch, if P occurs at any node in the branch, assign it 1, and if $\lnot$P occurs on any node, assign it 0.

\textbf{Designated values}: $1$

\pagebreak

\section{First Degree Entailment (FDE)}
\begin{center}
	\renewcommand{\arraystretch}{2.5}
	\begin{tabular}{cccc}
		\multicolumn{2}{c}{
			\begin{tikzpicture}[l]
				\node {$\lnot\lnot$ A, +}
				[->]
				child {node[below]{A, +}};
			\end{tikzpicture}
		}
		&
		\multicolumn{2}{c}{
			\begin{tikzpicture}[l]
			\node {$\lnot\lnot$ A, --}
			[->]
			child {node[below]{A, --}};
			\end{tikzpicture}
		}
		\\
		\begin{tikzpicture}[l]
			\node {A $\land$ B, +}
			[->]
			child {node[below,align=center]{A, +\\[4]B, +}};
		\end{tikzpicture}
		&
		\begin{tikzpicture}[l]
			\node {$\lnot$(A $\land$ B), +}
			[->]
			child {node[below]{$\lnot$A, +}}
			child {node[below]{$\lnot$B, +}};
		\end{tikzpicture}
		&
		\begin{tikzpicture}[l]
			\node {A $\land$ B, --}
			[->]
			child {node[below]{A, --}}
			child {node[below]{B, --}};
		\end{tikzpicture}
		&
		\begin{tikzpicture}[l]
			\node {$\lnot$(A $\land$ B), --}
			[->]
			child {node[below]{$\lnot$A, --}}
			child {node[below]{$\lnot$B, --}};
		\end{tikzpicture}
		\\
		\begin{tikzpicture}[l]
			\node {A $\lor$ B, +}
			[->]
			child {node[below]{A, +}}
			child {node[below]{B, +}};
		\end{tikzpicture}
		&
		\begin{tikzpicture}[l]
			\node {$\lnot$(A $\lor$ B), +}
			[->]
			child {node[below,align=center]{$\lnot$A, +\\[4]$\lnot$B, +}};
		\end{tikzpicture}
		&
		\begin{tikzpicture}[l]
			\node {A $\lor$ B, --}
			[->]
			child {node[below,align=center]{A, --\\[4]B, --}};
		\end{tikzpicture}
		&
		\begin{tikzpicture}[l]
			\node {$\lnot$(A $\lor$ B), --}
			[->]
			child {node[below,align=center]{$\lnot$A, --\\[4]$\lnot$B, --}};
		\end{tikzpicture}
	\end{tabular}
\end{center}

\vspace{3em}
\textbf{Closure condition}: A branch closes if it contains both A, + and A, --.

\textbf{Counter-model procedure}: Take any open branch, if P, + occurs at any node in the branch assign it P$\rho$1, and if $\lnot$P, + occurs on any node, assign it P$\rho$0.

\textbf{Truth table}:
\begin{center}
	\renewcommand{\arraystretch}{1.2}
	\begin{tabular}{|c|c|}
		\hline
		$\lnot$ & \\\hline
		$0$ & $1$ \\
		$n$ & $n$ \\
		$b$ & $b$ \\
		$1$ & $0$ \\\hline
	\end{tabular}
	\quad
	\begin{tabular}{|c|cccc|}
		\hline
		$\land$ & $0$ & $n$ & $b$ & $1$ \\\hline
		$0$ & $0$ & $0$ & $0$ & $0$ \\
		$n$ & $0$ & $n$ & $0$ & $n$ \\
		$b$ & $0$ & $0$ & $b$ & $b$ \\
		$1$ & $0$ & $n$ & $b$ & $1$ \\\hline
	\end{tabular}
	\quad
	\begin{tabular}{|c|cccc|}
		\hline
		$\lor$ & $0$ & $n$ & $b$ & $1$ \\\hline
		$0$ & $0$ & $n$ & $b$ & $1$ \\
		$n$ & $n$ & $n$ & $1$ & $1$ \\
		$b$ & $b$ & $1$ & $b$ & $1$ \\
		$1$ & $1$ & $1$ & $1$ & $1$ \\\hline
	\end{tabular}
\end{center}

\textbf{Designated values}: $1, b$

\pagebreak

\section{Kleene 3-valued logic (K$_3$)}
\begin{center}
	\renewcommand{\arraystretch}{2.5}
	\begin{tabular}{cccc}
		\multicolumn{2}{c}{
			\begin{tikzpicture}[l]
				\node {$\lnot\lnot$ A, +}
				[->]
				child {node[below]{A, +}};
			\end{tikzpicture}
		}
		&
		\multicolumn{2}{c}{
			\begin{tikzpicture}[l]
				\node {$\lnot\lnot$ A, --}
				[->]
				child {node[below]{A, --}};
			\end{tikzpicture}
		}
		\\
		\begin{tikzpicture}[l]
			\node {A $\land$ B, +}
			[->]
			child {node[below,align=center]{A, +\\[4]B, +}};
		\end{tikzpicture}
		&
		\begin{tikzpicture}[l]
			\node {$\lnot$(A $\land$ B), +}
			[->]
			child {node[below]{$\lnot$A, +}}
			child {node[below]{$\lnot$B, +}};
		\end{tikzpicture}
		&
		\begin{tikzpicture}[l]
			\node {A $\land$ B, --}
			[->]
			child {node[below]{A, --}}
			child {node[below]{B, --}};
		\end{tikzpicture}
		&
		\begin{tikzpicture}[l]
			\node {$\lnot$(A $\land$ B), --}
			[->]
			child {node[below]{$\lnot$A, --}}
			child {node[below]{$\lnot$B, --}};
		\end{tikzpicture}
		\\
		\begin{tikzpicture}[l]
			\node {A $\lor$ B, +}
			[->]
			child {node[below]{A, +}}
			child {node[below]{B, +}};
		\end{tikzpicture}
		&
		\begin{tikzpicture}[l]
			\node {$\lnot$(A $\lor$ B), +}
			[->]
			child {node[below,align=center]{$\lnot$A, +\\[4]$\lnot$B, +}};
		\end{tikzpicture}
		&
		\begin{tikzpicture}[l]
			\node {A $\lor$ B, --}
			[->]
			child {node[below,align=center]{A, --\\[4]B, --}};
		\end{tikzpicture}
		&
		\begin{tikzpicture}[l]
			\node {$\lnot$(A $\lor$ B), --}
			[->]
			child {node[below,align=center]{$\lnot$A, --\\[4]$\lnot$B, --}};
		\end{tikzpicture}
		\\
		\begin{tikzpicture}[l]
			\node {A $\supset$ B, +}
			[->]
			child {node[below]{$\lnot$A, +}}
			child {node[below]{B, +}};
		\end{tikzpicture}
		&
		\begin{tikzpicture}[l]
			\node {$\lnot$(A $\supset$ B), +}
			[->]
			child {node[below,align=center]{A, +\\[4]$\lnot$B, +}};
		\end{tikzpicture}
		&
		\begin{tikzpicture}[l]
			\node {A $\supset$ B, --}
			[->]
			child {node[below,align=center]{$\lnot$A, --\\[4]B, --}};
		\end{tikzpicture}
		&
		\begin{tikzpicture}[l]
			\node {$\lnot$(A $\supset$ B), --}
			[->]
			child {node[below,align=center]{A, --\\[4]$\lnot$B, --}};
		\end{tikzpicture}
	\end{tabular}
\end{center}

\vspace{3em}
\textbf{Closure condition}: A branch closes if it contains both A, + and A, -- or both A, + and $\lnot$A, +.

\textbf{Counter-model procedure}: Take any open branch, if P, + occurs at any node in the branch assign it P$\rho$1, and if $\lnot$P, + occurs on any node, assign it P$\rho$0.

\textbf{Truth table}:
\begin{center}
	\renewcommand{\arraystretch}{1.2}
	\begin{tabular}{|c|c|}
		\hline
		$\lnot$ & \\\hline
		$0$ & $1$ \\
		$i$ & $i$ \\
		$1$ & $0$ \\\hline
	\end{tabular}
	\quad
	\begin{tabular}{|c|ccc|}
		\hline
		$\land$ & $0$ & $i$ & $1$ \\\hline
		$0$ & $0$ & $0$ & $0$ \\
		$i$ & $0$ & $i$ & $i$ \\
		$1$ & $0$ & $i$ & $1$ \\\hline
	\end{tabular}
	\quad
	\begin{tabular}{|c|ccc|}
		\hline
		$\lor$ & $0$ & $i$ & $1$ \\\hline
		$0$ & $0$ & $i$ & $1$ \\
		$i$ & $i$ & $i$ & $1$ \\
		$1$ & $1$ & $1$ & $1$ \\\hline
	\end{tabular}
	\quad
	\begin{tabular}{|c|ccc|}
		\hline
		$\supset$ & $0$ & $i$ & $1$ \\\hline
		$0$ & $1$ & $1$ & $1$ \\
		$i$ & $i$ & $i$ & $1$ \\
		$1$ & $0$ & $i$ & $1$ \\\hline
	\end{tabular}
\end{center}

\textbf{Designated values}: $1$

\pagebreak

\section{{\L}ukasiewicz 3-valued logic (\L$_3$)}
\begin{center}
	\renewcommand{\arraystretch}{2.5}
	\begin{tabular}{cccc}
		\multicolumn{2}{c}{
			\begin{tikzpicture}[l]
				\node {$\lnot\lnot$ A, +}
				[->]
				child {node[below]{A, +}};
			\end{tikzpicture}
		}
		&
		\multicolumn{2}{c}{
			\begin{tikzpicture}[l]
				\node {$\lnot\lnot$ A, --}
				[->]
				child {node[below]{A, --}};
			\end{tikzpicture}
		}
		\\
		\begin{tikzpicture}[l]
			\node {A $\land$ B, +}
			[->]
			child {node[below,align=center]{A, +\\[4]B, +}};
		\end{tikzpicture}
		&
		\begin{tikzpicture}[l]
			\node {$\lnot$(A $\land$ B), +}
			[->]
			child {node[below]{$\lnot$A, +}}
			child {node[below]{$\lnot$B, +}};
		\end{tikzpicture}
		&
		\begin{tikzpicture}[l]
			\node {A $\land$ B, --}
			[->]
			child {node[below]{A, --}}
			child {node[below]{B, --}};
		\end{tikzpicture}
		&
		\begin{tikzpicture}[l]
			\node {$\lnot$(A $\land$ B), --}
			[->]
			child {node[below]{$\lnot$A, --}}
			child {node[below]{$\lnot$B, --}};
		\end{tikzpicture}
		\\
		\begin{tikzpicture}[l]
			\node {A $\lor$ B, +}
			[->]
			child {node[below]{A, +}}
			child {node[below]{B, +}};
		\end{tikzpicture}
		&
		\begin{tikzpicture}[l]
			\node {$\lnot$(A $\lor$ B), +}
			[->]
			child {node[below,align=center]{$\lnot$A, +\\[4]$\lnot$B, +}};
		\end{tikzpicture}
		&
		\begin{tikzpicture}[l]
			\node {A $\lor$ B, --}
			[->]
			child {node[below,align=center]{A, --\\[4]B, --}};
		\end{tikzpicture}
		&
		\begin{tikzpicture}[l]
			\node {$\lnot$(A $\lor$ B), --}
			[->]
			child {node[below,align=center]{$\lnot$A, --\\[4]$\lnot$B, --}};
		\end{tikzpicture}
		\\
		\begin{tikzpicture}[l]
			\node {A $\supset$ B, +}
			[->]
			child {node[below]{$\lnot$A, +}}
			child {node[below]{B, +}}
			child {node[below,align=center]{A $\lor$ $\lnot$A, -\\[4]B $\lor$ $\lnot$B, -}};
		\end{tikzpicture}
		&
		\begin{tikzpicture}[l]
			\node {$\lnot$(A $\supset$ B), +}
			[->]
			child {node[below,align=center]{A, +\\[4]$\lnot$B, +}};
		\end{tikzpicture}
		&
		\begin{tikzpicture}[l]
			\node {A $\supset$ B, --}
			[->]
			child {node[below,align=center]{A, +\\[4]B, --}}
			child {node[below,align=center]{$\lnot$A, --\\[4]$\lnot$B, +}};
		\end{tikzpicture}
		&
		\begin{tikzpicture}[l]
			\node {$\lnot$(A $\supset$ B), --}
			[->]
			child {node[below]{A, --}}
			child {node[below]{$\lnot$B, --}};
		\end{tikzpicture}
		\\
	\end{tabular}
\end{center}

\vspace{3em}
\textbf{Closure condition}: A branch closes if it contains both A, + and A, -- or both A, + and $\lnot$A, +.

\textbf{Counter-model procedure}: Take any open branch, if P, + occurs at any node in the branch assign it P$\rho$1, and if $\lnot$P, + occurs on any node, assign it P$\rho$0.

\textbf{Designated values}: $1$

\textbf{Truth table}:
\begin{center}
	\renewcommand{\arraystretch}{1.2}
	\begin{tabular}{|c|c|}
		\hline
		$\lnot$ & \\\hline
		$0$ & $1$ \\
		$i$ & $i$ \\
		$1$ & $0$ \\\hline
	\end{tabular}
	\quad
	\begin{tabular}{|c|ccc|}
		\hline
		$\land$ & $0$ & $i$ & $1$ \\\hline
		$0$ & $0$ & $0$ & $0$ \\
		$i$ & $0$ & $i$ & $i$ \\
		$1$ & $0$ & $i$ & $1$ \\\hline
	\end{tabular}
	\quad
	\begin{tabular}{|c|ccc|}
		\hline
		$\lor$ & $0$ & $i$ & $1$ \\\hline
		$0$ & $0$ & $i$ & $1$ \\
		$i$ & $i$ & $i$ & $1$ \\
		$1$ & $1$ & $1$ & $1$ \\\hline
	\end{tabular}
	\quad
	\begin{tabular}{|c|ccc|}
		\hline
		$\supset$ & $0$ & $i$ & $1$ \\\hline
		$0$ & $1$ & $1$ & $1$ \\
		$i$ & $i$ & $1$ & $1$ \\
		$1$ & $0$ & $i$ & $1$ \\\hline
	\end{tabular}
\end{center}

\pagebreak

\section{Logic of Paradox (LP)}
\begin{center}
	\renewcommand{\arraystretch}{2.5}
	\begin{tabular}{cccc}
		\multicolumn{2}{c}{
			\begin{tikzpicture}[l]
				\node {$\lnot\lnot$ A, +}
				[->]
				child {node[below]{A, +}};
			\end{tikzpicture}
		}
		&
		\multicolumn{2}{c}{
			\begin{tikzpicture}[l]
				\node {$\lnot\lnot$ A, --}
				[->]
				child {node[below]{A, --}};
			\end{tikzpicture}
		}
		\\
		\begin{tikzpicture}[l]
			\node {A $\land$ B, +}
			[->]
			child {node[below,align=center]{A, +\\[4]B, +}};
		\end{tikzpicture}
		&
		\begin{tikzpicture}[l]
			\node {$\lnot$(A $\land$ B), +}
			[->]
			child {node[below]{$\lnot$A, +}}
			child {node[below]{$\lnot$B, +}};
		\end{tikzpicture}
		&
		\begin{tikzpicture}[l]
			\node {A $\land$ B, --}
			[->]
			child {node[below]{A, --}}
			child {node[below]{B, --}};
		\end{tikzpicture}
		&
		\begin{tikzpicture}[l]
			\node {$\lnot$(A $\land$ B), --}
			[->]
			child {node[below]{$\lnot$A, --}}
			child {node[below]{$\lnot$B, --}};
		\end{tikzpicture}
		\\
		\begin{tikzpicture}[l]
			\node {A $\lor$ B, +}
			[->]
			child {node[below]{A, +}}
			child {node[below]{B, +}};
		\end{tikzpicture}
		&
		\begin{tikzpicture}[l]
			\node {$\lnot$(A $\lor$ B), +}
			[->]
			child {node[below,align=center]{$\lnot$A, +\\[4]$\lnot$B, +}};
		\end{tikzpicture}
		&
		\begin{tikzpicture}[l]
			\node {A $\lor$ B, --}
			[->]
			child {node[below,align=center]{A, --\\[4]B, --}};
		\end{tikzpicture}
		&
		\begin{tikzpicture}[l]
			\node {$\lnot$(A $\lor$ B), --}
			[->]
			child {node[below,align=center]{$\lnot$A, --\\[4]$\lnot$B, --}};
		\end{tikzpicture}
		\\
		\begin{tikzpicture}[l]
			\node {A $\supset$ B, +}
			[->]
			child {node[below]{$\lnot$A, +}}
			child {node[below]{B, +}};
		\end{tikzpicture}
		&
		\begin{tikzpicture}[l]
			\node {$\lnot$(A $\supset$ B), +}
			[->]
			child {node[below,align=center]{A, +\\[4]$\lnot$B, +}};
		\end{tikzpicture}
		&
		\begin{tikzpicture}[l]
			\node {A $\supset$ B, --}
			[->]
			child {node[below,align=center]{$\lnot$A, --\\[4]B, --}};
		\end{tikzpicture}
		&
		\begin{tikzpicture}[l]
			\node {$\lnot$(A $\supset$ B), --}
			[->]
			child {node[below,align=center]{A, --\\[4]$\lnot$B, --}};
		\end{tikzpicture}
		\\
	\end{tabular}
\end{center}

\vspace{3em}
\textbf{Closure condition}: A branch closes if it contains both A, + and A, -- or both A, -- and $\lnot$A, --.

\textbf{Counter-model procedure}: Take any open branch, if P, -- \emph{does not} occur on any node of the branch assign it P$\rho$1, and if $\lnot$P, -- \emph{does not} occur on any node, assign it P$\rho$0.

\textbf{Designated values}: $1, i$

\textbf{Truth table}:
\begin{center}
	\renewcommand{\arraystretch}{1.2}
	\begin{tabular}{|c|c|}
		\hline
		$\lnot$ & \\\hline
		$0$ & $1$ \\
		$i$ & $i$ \\
		$1$ & $0$ \\\hline
	\end{tabular}
	\quad
	\begin{tabular}{|c|ccc|}
		\hline
		$\land$ & $0$ & $i$ & $1$ \\\hline
		$0$ & $0$ & $0$ & $0$ \\
		$i$ & $0$ & $i$ & $i$ \\
		$1$ & $0$ & $i$ & $1$ \\\hline
	\end{tabular}
	\quad
	\begin{tabular}{|c|ccc|}
		\hline
		$\lor$ & $0$ & $i$ & $1$ \\\hline
		$0$ & $0$ & $i$ & $1$ \\
		$i$ & $i$ & $i$ & $1$ \\
		$1$ & $1$ & $1$ & $1$ \\\hline
	\end{tabular}
	\quad
	\begin{tabular}{|c|ccc|}
		\hline
		$\supset$ & $0$ & $i$ & $1$ \\\hline
		$0$ & $1$ & $1$ & $1$ \\
		$i$ & $i$ & $i$ & $1$ \\
		$1$ & $0$ & $i$ & $1$ \\\hline
	\end{tabular}
\end{center}

\pagebreak

\section{Mix 3-valued logic (RM$_3$)}
\begin{center}
	\renewcommand{\arraystretch}{2.5}
	\begin{tabular}{cccc}
		\multicolumn{2}{c}{
			\begin{tikzpicture}[l]
				\node {$\lnot\lnot$ A, +}
				[->]
				child {node[below]{A, +}};
			\end{tikzpicture}
		}
		&
		\multicolumn{2}{c}{
			\begin{tikzpicture}[l]
				\node {$\lnot\lnot$ A, --}
				[->]
				child {node[below]{A, --}};
			\end{tikzpicture}
		}
		\\
		\begin{tikzpicture}[l]
			\node {A $\land$ B, +}
			[->]
			child {node[below,align=center]{A, +\\[4]B, +}};
		\end{tikzpicture}
		&
		\begin{tikzpicture}[l]
			\node {$\lnot$(A $\land$ B), +}
			[->]
			child {node[below]{$\lnot$A, +}}
			child {node[below]{$\lnot$B, +}};
		\end{tikzpicture}
		&
		\begin{tikzpicture}[l]
			\node {A $\land$ B, --}
			[->]
			child {node[below]{A, --}}
			child {node[below]{B, --}};
		\end{tikzpicture}
		&
		\begin{tikzpicture}[l]
			\node {$\lnot$(A $\land$ B), --}
			[->]
			child {node[below]{$\lnot$A, --}}
			child {node[below]{$\lnot$B, --}};
		\end{tikzpicture}
		\\
		\begin{tikzpicture}[l]
			\node {A $\lor$ B, +}
			[->]
			child {node[below]{A, +}}
			child {node[below]{B, +}};
		\end{tikzpicture}
		&
		\begin{tikzpicture}[l]
			\node {$\lnot$(A $\lor$ B), +}
			[->]
			child {node[below,align=center]{$\lnot$A, +\\[4]$\lnot$B, +}};
		\end{tikzpicture}
		&
		\begin{tikzpicture}[l]
			\node {A $\lor$ B, --}
			[->]
			child {node[below,align=center]{A, --\\[4]B, --}};
		\end{tikzpicture}
		&
		\begin{tikzpicture}[l]
			\node {$\lnot$(A $\lor$ B), --}
			[->]
			child {node[below,align=center]{$\lnot$A, --\\[4]$\lnot$B, --}};
		\end{tikzpicture}
		\\
		\begin{tikzpicture}[l]
			\node {A $\supset$ B, +}
			[->]
			child {node[below]{A, --}}
			child {node[below]{$\lnot$B, --}}
			child {node[below,align=center]{A $\land$ $\lnot$A, +\\[4]B $\land$ $\lnot$B, +}};
		\end{tikzpicture}
		&
		\begin{tikzpicture}[l]
			\node {$\lnot$(A $\supset$ B), +}
			[->]
			child {node[below,align=center]{A, +\\[4]$\lnot$B, +}};
		\end{tikzpicture}
		&
		\begin{tikzpicture}[l]
			\node {A $\supset$ B, --}
			[->]
			child {node[below,align=center]{A, +\\[4]B, --}}
			child {node[below,align=center]{$\lnot$A, --\\[4]$\lnot$B, +}};
		\end{tikzpicture}
		&
		\begin{tikzpicture}[l]
			\node {$\lnot$(A $\supset$ B), --}
			[->]
			child {node[below]{A, --}}
			child {node[below]{$\lnot$B, --}};
		\end{tikzpicture}
		\\
	\end{tabular}
\end{center}

\vspace{3em}
\textbf{Closure condition}: A branch closes if it contains both A, + and A, -- or both A, -- and $\lnot$A, --.

\textbf{Counter-model procedure}: Take any open branch, if P, -- \emph{does not} occur on any node of the branch assign it P$\rho$1, and if $\lnot$P, -- \emph{does not} occur on any node, assign it P$\rho$0.

\textbf{Designated values}: $1, i$

\textbf{Truth table}:
\begin{center}
	\renewcommand{\arraystretch}{1.2}
	\begin{tabular}{|c|c|}
		\hline
		$\lnot$ & \\\hline
		$0$ & $1$ \\
		$i$ & $i$ \\
		$1$ & $0$ \\\hline
	\end{tabular}
	\quad
	\begin{tabular}{|c|ccc|}
		\hline
		$\land$ & $0$ & $i$ & $1$ \\\hline
		$0$ & $0$ & $0$ & $0$ \\
		$i$ & $0$ & $i$ & $i$ \\
		$1$ & $0$ & $i$ & $1$ \\\hline
	\end{tabular}
	\quad
	\begin{tabular}{|c|ccc|}
		\hline
		$\lor$ & $0$ & $i$ & $1$ \\\hline
		$0$ & $0$ & $i$ & $1$ \\
		$i$ & $i$ & $i$ & $1$ \\
		$1$ & $1$ & $1$ & $1$ \\\hline
	\end{tabular}
	\quad
	\begin{tabular}{|c|ccc|}
		\hline
		$\supset$ & $0$ & $i$ & $1$ \\\hline
		$0$ & $1$ & $1$ & $1$ \\
		$i$ & $0$ & $i$ & $1$ \\
		$1$ & $0$ & $0$ & $1$ \\\hline
	\end{tabular}
\end{center}

\pagebreak

\section{Basic Modal Logic}
\begin{center}
	\renewcommand{\arraystretch}{2.5}
	\begin{tabular}{cccc}
		\multicolumn{4}{c}{
			\begin{tikzpicture}[l]
				\node {$\lnot\lnot$ A, $i$}
				[->]
				child {node[below]{A, $i$}};
			\end{tikzpicture}
		}
		\\
		\begin{tikzpicture}[l]
			\node {A $\land$ B, $i$}
			[->]
			child {node[below,align=center]{A, $i$\\[4] B, $i$}};
		\end{tikzpicture}
		&
		\begin{tikzpicture}[l]
			\node {$\lnot$(A $\land$ B), $i$}
			[->]
			child {node[below]{$\lnot$A, $i$}}
			child {node[below]{$\lnot$B, $i$}};
		\end{tikzpicture}
		&
		\begin{tikzpicture}[l]
			\node {A $\lor$ B, $i$}
			[->]
			child {node[below]{A, $i$}}
			child {node[below]{B, $i$}};
		\end{tikzpicture}
		&
		\begin{tikzpicture}[l]
			\node {$\lnot$(A $\lor$ B), $i$}
			[->]
			child {node[below,align=center]{$\lnot$A, $i$\\[4] $\lnot$B, $i$}};
		\end{tikzpicture}
		\\
		\begin{tikzpicture}[l]
			\node {A $\supset$ B, $i$}
			[->]
			child {node[below]{$\lnot$A, $i$}}
			child {node[below]{B, $i$}};
		\end{tikzpicture}
		&
		\begin{tikzpicture}[l]
			\node {$\lnot$(A $\supset$ B), $i$}
			[->]
			child {node[below,align=center]{A, $i$\\[4] $\lnot$B, $i$}};
		\end{tikzpicture}
		&
		\begin{tikzpicture}[l]
			\node {A $\equiv$ B, $i$}
			[->]
			child {node[below,align=center]{A, $i$\\[4] B, $i$}}
			child {node[below,align=center]{$\lnot$A, $i$\\[4] $\lnot$B, $i$}};
		\end{tikzpicture}
		&
		\begin{tikzpicture}[l]
			\node {$\lnot$(A $\equiv$ B), $i$}
			[->]
			child {node[below,align=center]{$\lnot$A, $i$\\[4] B, $i$}}
			child {node[below,align=center]{A, $i$\\[4] $\lnot$B, $i$}};
		\end{tikzpicture}
		\\
		\begin{tikzpicture}[l]
			\node[align=center] {$\Box$ A, $i$\\[4]$i$ r $j$}
			[->]
			child {node[below,align=center]{A, $j$\\[4](every $j$)}};
		\end{tikzpicture}
		&
		\begin{tikzpicture}[l]
			\node {$\lnot \Box$ A, $i$}
			[->]
			child {node[below]{$\Diamond \lnot$ A, $i$}};
		\end{tikzpicture}
		&
		\begin{tikzpicture}[l]
			\node {$\Diamond$ A, $i$}
			[->]
			child {node[below,align=center]{$i$ r $j$\\[4] A, $j$\\[4](new $j$)}};
		\end{tikzpicture}
		&
		\begin{tikzpicture}[l]
			\node {$\lnot \Diamond$ A, $i$}
			[->]
			child {node[below]{$\Box \lnot$ A, $i$}};
		\end{tikzpicture}
	\end{tabular}
\end{center}

\vspace{2.5em}
\textbf{Closure condition}: A branch of closes if it for some $i$, A, $i$ and $\lnot$ A, $i$ occur on the same branch.

\textbf{Counter-model procedure}: For each $i$ that occurs the word $w_i$ exists. If $i$ r $j$ occurs on the branch then $w_i$ R $w_j$. If P, $i$ occurs on the branch then $v_{w_i}$(P) = 1, if $\lnot$ P, i occurs on the branch then $v_{w_i}$(P) = 0.

\textbf{Extensions}
\begin{description}
	\item[$\rho$] reflexivity: for all $w$, $wRw$
	\item[$\sigma$] symmetry: for all $w_1$, $w_2$, if $w_1Rw_2$, then $w_2Rw_1$
	\item[$\tau$] transitivity: for all $w_1$, $w_2$, $w_3$, if $w_1Rw_2$ and $w_2Rw_3$, then $w_1Rw_3$
	\item[$\eta$] extendability: for all $w_1$, there is a $w_2$ such that $w_1Rw_2$
\end{description}

\section{Tense Logic}
\begin{center}
	\renewcommand{\arraystretch}{2.5}
	\begin{tabular}{cccc}
		\multicolumn{4}{c}{
			\begin{tikzpicture}[l]
				\node {$\lnot\lnot$ A, $i$}
				[->]
				child {node[below]{A, $i$}};
			\end{tikzpicture}
		}
		\\
		\begin{tikzpicture}[l]
			\node {A $\land$ B, $i$}
			[->]
			child {node[below,align=center]{A, $i$ \\[4] B, $i$}};
		\end{tikzpicture}
		&
		\begin{tikzpicture}[l]
			\node {$\lnot$(A $\land$ B), $i$}
			[->]
			child {node[below]{$\lnot$A, $i$}}
			child {node[below]{$\lnot$B, $i$}};
		\end{tikzpicture}
		&
		\begin{tikzpicture}[l]
			\node {A $\lor$ B, $i$}
			[->]
			child {node[below]{A, $i$}}
			child {node[below]{B, $i$}};
		\end{tikzpicture}
		&
		\begin{tikzpicture}[l]
			\node {$\lnot$(A $\lor$ B), $i$}
			[->]
			child {node[below,align=center]{$\lnot$A, $i$\\[4] $\lnot$B, $i$}};
		\end{tikzpicture}
		\\
		\begin{tikzpicture}[l]
			\node {A $\supset$ B, $i$}
			[->]
			child {node[below]{$\lnot$A, $i$}}
			child {node[below]{B, $i$}};
		\end{tikzpicture}
		&
		\begin{tikzpicture}[l]
			\node {$\lnot$(A $\supset$ B), $i$}
			[->]
			child {node[below,align=center]{A, $i$\\[4] $\lnot$B, $i$}};
		\end{tikzpicture}
		&
		\begin{tikzpicture}[l]
			\node {A $\equiv$ B, $i$}
			[->]
			child {node[below,align=center]{A, $i$\\[4] B, $i$}}
			child {node[below,align=center]{$\lnot$A, $i$\\[4] $\lnot$B, $i$}};
		\end{tikzpicture}
		&
		\begin{tikzpicture}[l]
			\node {$\lnot$(A $\equiv$ B), $i$}
			[->]
			child {node[below,align=center]{$\lnot$A, $i$\\[4] B, $i$}}
			child {node[below,align=center]{A, $i$\\[4] $\lnot$B, $i$}};
		\end{tikzpicture}
		\\
		\begin{tikzpicture}[l]
			\node[align=center] {[F]A, $i$\\[4]$i$ r $j$}
			[->]
			child {node[below,align=center]{A, $j$\\[4](every $j$)}};
		\end{tikzpicture}
		&
		\begin{tikzpicture}[l]
			\node {$\lnot$[F]A, $i$}
			[->]
			child {node[below]{$\langle$F$\rangle$$\lnot$ A, $i$}};
		\end{tikzpicture}
		&
		\begin{tikzpicture}[l]
			\node {$\langle$F$\rangle$A, $i$}
			[->]
			child {node[below,align=center]{$i$ r $j$\\[4] A, $j$\\[4] (new $j$)}};
		\end{tikzpicture}
		&
		\begin{tikzpicture}[l]
			\node {$\lnot$$\langle$F$\rangle$A, $i$}
			[->]
			child {node[below]{[F]$\lnot$ A, $i$}};
		\end{tikzpicture}
		\\
		\begin{tikzpicture}[l]
			\node[align=center] {[P]A, $i$\\[4]$j$ r $i$}
			[->]
			child {node[below,align=center]{A, $j$\\[4] (every $j$)}};
			\end{tikzpicture}
		&
		\begin{tikzpicture}[l]
			\node {$\lnot$[P]A, $i$}
			[->]
			child {node[below]{$\langle$P$\rangle$$\lnot$ A, $i$}};
		\end{tikzpicture}
		&
		\begin{tikzpicture}[l]
			\node {$\langle$P$\rangle$A, $i$}
			[->]
			child {node[below,align=center]{$j$ r $i$\\[4] A, $j$\\[4] (new $j$)}};
		\end{tikzpicture}
		&
		\begin{tikzpicture}[l]
			\node {$\lnot$$\langle$P$\rangle$A, $i$}
			[->]
			child {node[below]{[P]$\lnot$ A, $i$}};
		\end{tikzpicture}
	\end{tabular}
\end{center}

\vspace{3em}
\textbf{Closure condition}: A branch of closes if it for some $i$, A, $i$ and $\lnot$ A, $i$ occur on the same branch.

\textbf{Counter-model procedure}: For each $i$ that occurs the word $w_i$ exists. If $i$ r $j$ occurs on the branch then $w_i$ R $w_j$. If P, $i$ occurs on the branch then $v_{w_i}$(P) = 1, if $\lnot$ P, i occurs on the branch then $v_{w_i}$(P) = 0. If there are lines of the form $i = j$, $j = k$, $...$, we only chose one of them, like $i$, and ignore the others.

\textbf{Extensions}
\begin{description}
	\item[$\delta$] denseness: if $iRj$ then for some $k$, $iRk$ and $kRj$
	\item[$\phi$] forward convergence: if $iRj$ and $iRk$ then $jRk$ or $j = k$ or $kRj$
	\item[$\beta$] backward convergence: if $jRi$ and $kRi$ then $jRk$ or $j = k$ or $kRj$
\end{description}

\pagebreak

\section{First Order Modal Logic}

\begin{center}
	\renewcommand{\arraystretch}{2.5}
	\begin{tabular}{cccc}
				\multicolumn{4}{c}{
			\begin{tikzpicture}[l]
			\node {$\lnot\lnot$ A, $i$}
			[->]
			child {node[below]{A, $i$}};
			\end{tikzpicture}
		}
		\\
		\begin{tikzpicture}[l]
		\node {A $\land$ B, $i$}
		[->]
		child {node[below,align=center]{A, $i$\\[4] B, $i$}};
		\end{tikzpicture}
		&
		\begin{tikzpicture}[l]
		\node {$\lnot$(A $\land$ B), $i$}
		[->]
		child {node[below]{$\lnot$A, $i$}}
		child {node[below]{$\lnot$B, $i$}};
		\end{tikzpicture}
		&
		\begin{tikzpicture}[l]
		\node {A $\lor$ B, $i$}
		[->]
		child {node[below]{A, $i$}}
		child {node[below]{B, $i$}};
		\end{tikzpicture}
		&
		\begin{tikzpicture}[l]
		\node {$\lnot$(A $\lor$ B), $i$}
		[->]
		child {node[below,align=center]{$\lnot$A, $i$\\[4] $\lnot$B, $i$}};
		\end{tikzpicture}
		\\
		\begin{tikzpicture}[l]
		\node {A $\supset$ B, $i$}
		[->]
		child {node[below]{$\lnot$A, $i$}}
		child {node[below]{B, $i$}};
		\end{tikzpicture}
		&
		\begin{tikzpicture}[l]
		\node {$\lnot$(A $\supset$ B), $i$}
		[->]
		child {node[below,align=center]{A, $i$\\[4] $\lnot$B, $i$}};
		\end{tikzpicture}
		&
		\begin{tikzpicture}[l]
		\node {A $\equiv$ B, $i$}
		[->]
		child {node[below,align=center]{A, $i$\\[4] B, $i$}}
		child {node[below,align=center]{$\lnot$A, $i$\\[4] $\lnot$B, $i$}};
		\end{tikzpicture}
		&
		\begin{tikzpicture}[l]
		\node {$\lnot$(A $\equiv$ B), $i$}
		[->]
		child {node[below,align=center]{$\lnot$A, $i$\\[4] B, $i$}}
		child {node[below,align=center]{A, $i$\\[4] $\lnot$B, $i$}};
		\end{tikzpicture}
		\\
		\begin{tikzpicture}[l]
		\node[align=center] {$\Box$ A, $i$\\[4]$i$ r $j$}
		[->]
		child {node[below,align=center]{A, $j$\\[4](every $j$)}};
		\end{tikzpicture}
		&
		\begin{tikzpicture}[l]
		\node {$\lnot \Box$ A, $i$}
		[->]
		child {node[below]{$\Diamond \lnot$ A, $i$}};
		\end{tikzpicture}
		&
		\begin{tikzpicture}[l]
		\node {$\Diamond$ A, $i$}
		[->]
		child {node[below,align=center]{$i$ r $j$\\[4] A, $j$\\[4](new $j$)}};
		\end{tikzpicture}
		&
		\begin{tikzpicture}[l]
		\node {$\lnot \Diamond$ A, $i$}
		[->]
		child {node[below]{$\Box \lnot$ A, $i$}};
		\end{tikzpicture}
		\\
		\multicolumn{4}{c}{\textbf{Variable Domain}}
		\\
		\begin{tikzpicture}[l]
		\node {$\forall x$ A, $i$}
		[->]
		child {node[below]{$A_x(a)$, $i$}}
		child {node[below,align=center]{$\lnot$ $\mathfrak{E}a$, $i$\\[4](old $a$ if possible)}};
		\end{tikzpicture}
		&
		\begin{tikzpicture}[l]
		\node {$\lnot \forall x$ A, $i$}
		[->]
		child {node[below]{$\exists x$ $\lnot$A, $i$}};
		\end{tikzpicture}
		&
		\begin{tikzpicture}[l]
		\node {$\exists x$ A, $i$}
		[->]
		child {node[align=center,below]{$\mathfrak{E}a$, $i$\\[4]$A_x(a)$, $i$\\[4](new $a$)}};
		\end{tikzpicture}
		&
		\begin{tikzpicture}[l]
		\node {$\lnot \exists x$ A, $i$}
		[->]
		child {node[below]{$\forall x$ $\lnot$A, $i$}};
		\end{tikzpicture}
		\\
		\multicolumn{4}{c}{\textbf{Constant Domain}}
		\\
		\begin{tikzpicture}[l]
		\node {$\forall x$ A, $i$}
		[->]
		child {node[align=center, below]{$A_x(a)$, $i$\\[4](old $a$ if possible)}};
		\end{tikzpicture}
		&
		\begin{tikzpicture}[l]
		\node {$\lnot \forall x$ A, $i$}
		[->]
		child {node[below]{$\exists x$ $\lnot$A, $i$}};
		\end{tikzpicture}
		&
		\begin{tikzpicture}[l]
		\node {$\exists x$ A, $i$}
		[->]
		child {node[align=center, below]{$A_x(a)$, $i$\\[4](new $a$)}};
		\end{tikzpicture}
		&
		\begin{tikzpicture}[l]
		\node {$\lnot \exists x$ A, $i$}
		[->]
		child {node[below]{$\forall x$ $\lnot$A, $i$}};
		\end{tikzpicture}
	\end{tabular}
\end{center}

\textbf{Counter-models}:
Need to define:
\begin{itemize}
	\item which objects exist in which worlds: e.g. $D(w_1) = \lbrace \partial_a, \partial_b \rbrace$
	\item which predicates hold for which objects: e.g. $v_{w_1}(P) = \lbrace \partial_c \rbrace$
\end{itemize}

\pagebreak

\section{Fuzzy Logic}

\begin{align*}
	\lnot x   &= 1 - x\\
	x \land y &= \min(x, y)\\
	x \lor y  &= \max(x, y)\\
	x \lif y  &= \min(1, 1 - x + y)
\end{align*}

\textbf{Designated values}:
$A \models_{\textrm{\L}_{0.5}}$ if $v(A) \geq 0.5$ then $v(B) \geq 0.5$\\
Special case: \L$_{\aleph}$ - the only designated value is 1.

\section{Default Logic}

\[
	\beta = \frac{\phi : \psi_1, ..., \psi_n}{\chi}
	\textrm{ \quad for example \quad }
	\frac{bird(X) : flies(X)}{flies(X)}
\]

where:
\begin{description}
	\item $pre(\delta) = \phi$ (the prerequisites of $\delta$)
	\item $just(\delta) = \lbrace \psi_1, ..., \psi_n \rbrace$ (the justification of $\delta$)
	\item $cons(\delta) = \chi$ (the consequence of $\delta$)
\end{description}

\subsection{Processes}

\begin{description}
	\item $\prod = (\delta_0, \delta_1, ...)$ \quad can also be empty: $()$
	\item $Th(X) = $ all formulas that can be deduced from $X$.
	\item $In(\prod) = Th(M)$, where $M = W \cup \lbrace\, cons(\delta) \;|\; \delta \in \prod \,\rbrace$
	\item $Out(\prod) = Th(N)$, where $N = \lbrace\, \lnot just(\delta) \;|\; \delta \in \prod \,\rbrace$
	\item $\prod$ is \emph{closed} iff every $\delta \in D$ that is applicable to $In(\prod)$ is also in $\prod$.
	\item $\prod$ is \emph{successful} iff $In(\prod) \cap Out(\prod) = \emptyset$
	\item[Extensions] A set of formulas $E$ is an extension of the default theory $T$ iff there is some closed and successful process $\prod$ of $T$ such that $E = In(\prod)$
	\item[Skeptical consequence] $(W, D) \vdash_s \phi$ iff $\phi$ is in all extensions of $(W, D)$.
	\item[Credulous consequence] $(W, D) \vdash_c \phi$ iff $\phi$ is in at least one extension of $(W, D)$.
\end{description}

\section{Soundness and Completeness}

\subsection{Propositional Logic}

$\Sigma \models A$ iff for all valuations $v$, for all $B \in \Sigma$, $v(B) = 1$, then $v(A) = 1$.

$\Sigma \vdash A$ iff there is a closed tree whose initial list comprises the members of $\Sigma$ and the negation of $A$.

\begin{description}
	\item[Faithful] A valuation $v$ is \emph{faithful} to branch $b$ iff for every formula $D$ that occurs on $b$, $v(D) = 1$.
	\item[Induced] A valuation $v$ is \emph{induced} by branch $b$, iff for every propositional parameter $p$ that occurs on $b$, $v(p) = 1$ iff $p$ is a node on $b$, and $v(p) = 0$ iff $\lnot p$ is a node on $b$.
	\item[Soundness lemma] If $v$ is \emph{faithful} to a branch $b$, and a tableau rule is applied to $b$, then $v$ is faithful to at least \emph{one} of of the branches generated by the application of the rule.
	\item[Completeness lemma] If branch $b$ is \emph{complete} and \emph{open}, and if $v$ is the valuation \emph{induced} by $b$, then for all formulas $D$: if $D$ is on $b$, then $v(D) = 1$, and if $\lnot D$ is on $b$, then $v(D) = 0$.
\end{description}

\subsection{Modal Logic}

Basic modal logic, extensions $K_{\rho}$, $K_{\sigma}$, $K_{\tau}$, $K_{\eta}$, and any combination of extensions are all sound \emph{and} complete.

$\Sigma \models A$ iff for all valuations $v$, for all $B \in \Sigma$, $v(B) = 1$, then $v(A) = 1$.

$\Sigma \vdash A$ iff there is a closed tree whose initial list comprises the members of $\Sigma$ and the negation of $A$.

\begin{description}

	\item[Faithful] An interpretation $I = \langle W, R, v \rangle$ is \emph{faithful} to branch $b$ iff there is a map $f$ from $\mathbb{N}$ to $W$ such that:
	\begin{itemize}
		\item For every node $D, i$ on $b$, $D$ is true at world $f(i)$ in $I$.
		\item If $i$ r $j$ is on $b$, then $f(i)Rf(j)$ is in $R$.
	\end{itemize}

	\item[Induced]  If branch $b$ is \emph{complete} and \emph{open}, $I = \langle W, R, v \rangle$ is \emph{induced} by $b$ iff:
	\begin{itemize}
		\item $W$ = the set of all worlds $w_i$ such that $i$ appears on b.
		\item $w_iRw_j$ iff $i$ r $j$ occurs on b.
		\item If $p, i$ occurs on $b$, then $v_{w_i}(p) = 1$, and if $\lnot p, i$ occurs on  $b$, then $v_{w_i}(p) = 0$.
	\end{itemize}

	\item[Soundness lemma] If $I = \langle W, R, v \rangle$ is \emph{faithful} to branch $b$, and a tableau rule is applied to $b$, then $I$ is faithful to at least \emph{one} of of the branches generated by the application of the rule.

	\item[Completeness lemma] If branch $b$ is \emph{complete} and \emph{open}, and $I = \langle W, R, v \rangle$ is \emph{induced} by $b$, then for all formulas $D$ and for all $i$: if $D, i$ is on $b$, then $v_{w_i}(D) = 1$, and if $\lnot D, i$ is on $b$, then $v_{w_i}(D) = 0$.
\end{description}

\end{document}


\documentclass[fleqn, 10pt, twocolumn]{SelfArx}
\usepackage[english]{babel}
\usepackage[utf8]{inputenc}

\setlength{\columnsep}{0.55cm} % Distance between the two columns of text
\setlength{\fboxrule}{0.75pt} % Width of the border around the abstract

\usepackage[version=4]{mhchem}

\usepackage{fancyhdr}
\usepackage{here}
\usepackage{relsize}

\usepackage[locale=DE,output-decimal-marker={.}]{siunitx}
\usepackage{amsmath}
\sisetup{separate-uncertainty, per-mode=fraction,}
\usepackage{tikz}
\usepackage{pgfplots,pgfplotstable}
\usetikzlibrary{external}
\tikzexternalize[prefix=tikz/]

\usepackage{hyperref}

\pagestyle{fancy}
\fancyhf{}
\lhead{Felix Wechsler}
\rhead{Topic 3 \textit{Photonic crystal fibers}}
\definecolor{color1}{RGB}{0,0,90} % Color of the article title and sections
\definecolor{color2}{RGB}{0,20,20} % Color of the boxes behind the abstract and headings

\usepackage[%
  backend=biber,
  url=false,
  %style=alphabetic,
  % citestyle=authoryear,
  citestyle=numeric,
  maxnames=1,
  minnames=1,
  maxbibnames=99,
  giveninits,
  uniquename=init]{biblatex}
\DeclareSourcemap{
  \maps[datatype=bibtex]{
    \map{
      \step[fieldset=issn, null]
    }
  }
}
\DeclareSourcemap{
  \maps[datatype=bibtex]{
    \map{
      \step[fieldset=doi, null]
    }
  }
}
\DeclareSourcemap{
  \maps[datatype=bibtex]{
    \map{
      \step[fieldset=isbn, null]
    }
  }
}

\addbibresource{references.bib}
\usepackage[symbol]{footmisc}
\renewcommand{\thefootnote}{\fnsymbol{footnote}}

\begin{document}%
\begin{center}
\colorbox{color2!10}{\large\relscale{1.13}\textcolor{color1}{\sffamily\bfseries Entrance Exam for MPSP Applicants}}
\end{center}
    \textit{Third harmonics can be generated by pumping Ti:sapphire laser femtosecond pulses into an Ar-filled hollow-core photonics crystal fiber (HC-PCF) \cite{Nold2010}.
        In this work\footnote{For more details about the numerical calculations see this GitHub repository \url{https://git.io/JtHKW}} we discuss several aspects of their generation and analysis.}

    \section{Derivation of Effective Refractive Index}
    The effective refractive index of the generated modes within the HC-PCF can by approximated by:
    \begin{align}
        n^{mn}(\lambda, p) = \sqrt{n^2_{\text{Ar}}(\lambda, p ) - \frac{u_{mn}^2}{k_0^2 a^2}}
        \label{eq1}
    \end{align}
    where $k_0=2\pi/\lambda$ is the wave number, $\lambda$ is the vacuum wavelength, $p_0$ and $p$ are a reference and the present pressure, respectively. $a$ is the
    effective radius of the fiber. $u_{mn}$ is the $n$th zero of a $m$th order Bessel function of the first kind. Since the fiber used in \cite{Nold2010} has a hexagonal core, \eqref{eq1} is only an approximation.
    \eqref{eq1} originates from two principles: a $\lambda$ dependent refractive index and an effective refractive index due to the present mode in a circular fiber.
    Firstly, we discuss the overall structure of the equation coming from the mode formed within the fiber. The field in the fiber is generated by a laser pulse. Once the laser is launched, Maxwell's equation and hence the Helmholtz equation have to be valid.
    % \begin{align}
    %     \left(\nabla^2 + k(\omega)\right) \mathbf E = 0
    %     \label{eq:helmholtz}
    % \end{align}
    It is known that the Helmholtz equation within a fiber with circular cross section is solved by Bessel functions \cite{Nickelson2019}.
    Numerically, a Finite Difference Mode Solver can be used to obtain the eigenvectors $\mathbf E$ representing the field and the eigenvalues $k^{mn}$ representing the wave number for more complex shapes. The analytical solution for cylindrical symmetries is
    \begin{align}
        k^{mn} = \sqrt{(n k_0)^2 - \left( \frac{u_{mn}}{a}\right)^2}
    \end{align}
    where $n$ is the refractive index of the medium.
    From the wave number we obtain the effective refractive index
    \begin{align}
        n^{mn} = \sqrt{n^2 - \left( \frac{u_{mn}}{a k_0}\right)^2}.
        \label{eq:mode}
    \end{align}
    Secondly, we can now introduce a wavelength and a pressure dependency to the equation. To describe the $\lambda$ dependency, several empirical approaches are possible.
    In the case of noble gases, the following Sellmeier equation turned out to be convenient \cite{Borzsonyi2008}
    \begin{align}
       n^2(\lambda, p_0)  = 1 + \frac{T_0}{T} \left(\frac{B_1}{1- (\lambda_1/\lambda)^2} + \frac{B_2}{1- (\lambda_2/\lambda)^2}  \right)
        \label{eq:wvl}
    \end{align}
    where $B_{1/2}$ and $\lambda_{1/2}$ are fitting parameters being gas specific.
    Furthermore, from the Lorentz-Lorenz theory
    we know that there is a linear relation between the squared refractive index and the pressure $p$ \cite{Borzsonyi2008}.
    Knowing $n^2(p_0) \sim p_0$ it is straightforward to see that
    \begin{align}
        n_{\text{Ar}}^2(\lambda, p) = \frac{p}{p_0} n^2(\lambda, p_0)
        \label{eq:p}
    \end{align}
    and therefore by measuring the Sellmeier parameters for a pressure $p_0$ we can plug Equation \ref{eq:wvl}, \ref{eq:p} into \ref{eq:mode} to obtain \eqref{eq1}.
    By introducing a first order Taylor approximation of $\sqrt{1+x} \approx 1 + \frac{x}{2}$, we can further simplify to obtain the equation below.
    \begin{align}
        n^{mn}(\lambda, p) \approx 1 + n^2(\lambda, p_0) \frac{p}{2p_0} -  \frac{u_{mn}^2}{2 k_0^2 a^2}
        \label{eq1a}
    \end{align}

    \section{Phase Matching}
    In third harmonics generation, two fundamental conditions need to hold: energy and momentum conservation.
    In the wave picture, momentum conservation is a phase matching condition and can be in the fiber mode expressed as
    \begin{align}
        \mathbf{k}^{mn} = 3 \cdot \mathbf k^{11}
    \end{align}
    and hence
    \begin{align}
        n^{11}(\lambda, p) - n^{mn}(\lambda / 3, p)= 0
        \label{eq:pm}
    \end{align}
    where $mn$ is the generated third harmonic mode and $11$ the pump mode.
    The left hand side of \eqref{eq:pm} can be visualized to find all possible solutions.
    We believe\footnote{Despite \citeauthor{Travers2011} state differently \cite{Travers2011}, we could only reproduce the results of \citeauthor{Nold2010} by decrementing $m$. This decrementation is mentioned by \citeauthor{Marcatili1964} \cite{Marcatili1964}.} that the hybrid mode $\text{HE}_{mn}$ corresponds to Bessel coefficients $u_{(m-1)n}$.
    Accordingly, $\text{HE}_{11}$ has the Bessel coefficients $u_{01}$.
    \begin{figure}[h]
        \centering
        \begin{tikzpicture}
            \begin{axis}[
                xmin = 400, xmax = 1000,
                ymin = -5, ymax = 7.5,
                ytick = {-2.5, 0, ..., 7.5},
                height=5.5cm, width=8cm,
                xlabel = {$\lambda$ in \si{\nano\meter}},
                ylabel = {$(n^{11}(\lambda, p) - n^{mn}(\lambda/3, p)) \cdot 10^4$},
                legend pos = {north west},
                legend entries = {$\ce{Ar}-\text{HE}_{11}$, $\ce{Ar}-\text{HE}_{12}$, $\ce{Ar}-\text{HE}_{13}$, $\ce{Ar}-\text{HE}_{23}$, $\ce{Ar}-\text{HE}_{33}$}
                ]
                \draw[dashed] (axis cs:0,0) -- (axis cs:1200, 0);
                \draw[dashed] (axis cs:800,10) -- (axis cs:800, -10);
                \node at (axis cs:860, 5) {\footnotesize pump $\lambda$};
                \addplot[color=blue]
                    table[x index = 0, y index = 1]{../data/argon.txt};
                \addplot[color=red]
                    table[x index = 0, y index = 2]{../data/argon.txt};
                \addplot[color=green]
                    table[x index = 0, y index = 3]{../data/argon.txt};
                \addplot[color=orange]
                    table[x index = 0, y index = 4]{../data/argon.txt};
                \addplot[color=black!50!white]
                    table[x index = 0, y index = 5]{../data/argon.txt};
                \addplot[color=blue, dotted]
                    table[x index = 0, y index = 1]{../data/argon_low_pressure.txt};
            \end{axis}
        \end{tikzpicture}
        \caption{Refractive index difference of \ce{Ar} for different \text{HE} modes and $\text{HE}_{11}$ at $T=\SI{293}{\kelvin}$, $p=\SI{5000}{\milli\bar}$.}
        \label{plt:pm}
    \end{figure}
    From \autoref{plt:pm} it follows that intra-modal phase matching ($mn = 11$) is not possible since the $\text{HE}_{11}$ curve does not reach values where the refractive index difference is approximately 0.
    Even, at a low pressure of $p=\SI{100}{\milli\bar}$ the dotted blue line does not reach 0.
    Also mathematically it is clear that \eqref{eq:pm} cannot be solved for intra-modal phase matching because the only variable is $\lambda$ and since $n(\lambda)$ is a monotonic decreasing function, there is no solution for $\lambda$ and $\lambda/3$.
    However, $\text{HE}_{13}$ has a solution to the phase matching condition identifiable at $\lambda=\SI{800}{\nano\meter}$.
    Mathematically, $\lambda/3$ leads to a decrease in \eqref{eq:pm} which is then compensated by an increase of $u_{03}>u_{01}$.\\
    Instead of using \ce{Ar}-filled HC-PCF, third harmonics can be generated with \ce{Kr} as well.
    Using the Sellmeier coefficients for \ce{Kr}, we apply the phase matching condition to
    solve for the required pressure.
    \begin{figure}[h]
        \centering
        \begin{tikzpicture}
            \begin{axis}[
                xmin = 0, xmax = 9,
                ymin = -3, ymax = 5.5,
                ytick = {-2, 0, 2, 4, 6},
                height=5.5cm, width=8cm,
                xlabel = {$p$ in \si{\bar}},
                ylabel = {$(n^{11}(\lambda, p) - n^{mn}(\lambda/3, p)) \cdot 10^4$ },
                legend pos = {north west},
                legend entries = {$\ce{Kr}-\text{HE}_{13}$, $\ce{Kr}-\text{HE}_{23}$, $\ce{Kr}-\text{HE}_{33}$}
                ]
                \draw[dashed] (axis cs:0,0) -- (axis cs:12, 0);
                \addplot[color=blue]
                    table[x index = 0, y index = 1]{../data/krypton.txt};
                \addplot[color=red]
                    table[x index = 0, y index = 2]{../data/krypton.txt};
                \addplot[color=green]
                    table[x index = 0, y index = 3]{../data/krypton.txt};
            \end{axis}
        \end{tikzpicture}
        \caption{Refractive index difference of \ce{Kr} for different \text{HE} modes and $\text{HE}_{11}$ at $T=\SI{293}{\kelvin}$,  $\lambda=\SI{800}{\nano\meter}$.}
        \label{plt:pressure}
    \end{figure}
    In \autoref{plt:pressure} we can see that for $p^{13}=\SI{2.4}{\bar}$, $p^{23}=\SI{5.3}{\bar}$ and $p^{33}=\SI{8.5}{\bar}$ the phase matching is fulfilled.
\section{\ce{Xe}-filled HC-PCF}
    \autoref{plt:pmxenon} shows the refractive index difference for a \ce{Xe}-filled HC-PCF\footnote{Note, there is a typo in \cite{Borzsonyi2008}. $C_1$ should be \SI{12.75e-3}{\micro\meter\squared} instead of \SI{12.75e-6}{\micro\meter\squared}. See \url{https://refractiveindex.info/?shelf=main&book=Xe&page=Borzsonyi}}.
    \begin{figure}[h]
        \centering
        \begin{tikzpicture}
            \begin{axis}[
                xmin = 400, xmax = 1000,
                ymin = -5, ymax = 7.5,
                ytick = {-2.5, 0, ..., 7.5},
                height=5.5cm, width=8cm,
                xlabel = {$\lambda$ in \si{\nano\meter}},
                ylabel = {$(n^{11}(\lambda, p) - n^{mn}(\lambda/3, p)) \cdot 10^4$},
                legend pos = {north west},
                legend entries = {$\ce{Xe}-\text{HE}_{11}$, $\ce{Xe}-\text{HE}_{12}$,$\ce{Xe}-\text{HE}_{13}$, $\ce{Xe}-\text{HE}_{23}$, $\ce{Xe}-\text{HE}_{33}$}
                ]
                \draw[dashed] (axis cs:0,0) -- (axis cs:1200, 0);
                \draw[dashed] (axis cs:800,10) -- (axis cs:800, -10);
                \node at (axis cs:860, 5) {\footnotesize pump $\lambda$};
                \addplot[color=blue]
                    table[x index = 0, y index = 1]{../data/xenon.txt};
                \addplot[color=red]
                    table[x index = 0, y index = 2]{../data/xenon.txt};
                \addplot[color=green]
                    table[x index = 0, y index = 3]{../data/xenon.txt};
                \addplot[color=orange]
                    table[x index = 0, y index = 4]{../data/xenon.txt};
                \addplot[color=black!50!white]
                    table[x index = 0, y index = 5]{../data/xenon.txt};
            \end{axis}
        \end{tikzpicture}
        \caption{Refractive index difference of \ce{Xe} for different \text{HE} modes and $\text{HE}_{11}$ at $T=\SI{293}{\kelvin}$, $p=\SI{960}{\milli\bar}$.}
        \label{plt:pmxenon}
    \end{figure}
    It follows that third harmonic generation is possible for \ce{Xe} at lower pressures but even higher harmonics have been observed in \ce{Xe}
    \cite{Heckl2009}. Among the investigated noble gases, \ce{Xe} has the lowest absolute pressure and \ce{Ar} the highest required for third harmonic generation.
    The reason for the lower pressure is that \ce{Xe} has the largest dispersion \cite{Borzsonyi2008} leading to a smaller $p$ needed to compensate for the larger $u_{mn}$ in \eqref{eq:pm}.
    Consequently \ce{Ar} shows the lowest dispersion.
    It is worth to mention that the opportunity to use different gases enhances the use in practical applications of higher harmonics generation with HC-PCFs.
    \ce{Xe} and \ce{Ar} allow to vary the presssure by almost one order of magnitude but still generating third harmonics. Also, the linear pressure dependency in the phase matching condition
    allows to fine-tune efficiently for certain higher order modes.
    Furthermore, combining \eqref{eq1a} together with the ideal gas law, gas-filled HC-PCFs are robust against temperature induced pressure variations. For moderate gas chamber dimensions temperature changes due to absorption of radiation are negligible \cite{Serebryannikov2004}.
    In conclusion, noble gas-filled HC-PCFs allow for setups to be small, nonhazardous and insensitive to environmental changes and are therefore
    suitable candidates for generation of light in UV or EUV regimes.
    It can be conjectured, that other noble gases like Helium and Neon are also promising candidates since their Sellmeier coefficients are in the same order of magnitudes and the physical properties of noble gases are similar.

    \printbibliography

\end{document}