\documentclass[12pt]{article}
\usepackage{blindtext}
\usepackage{enumerate}
\usepackage{hyperref, bookmark}
\usepackage{amsmath, amsfonts, amssymb, amsthm}
\usepackage{xcolor}

\title{Strong Separation}
% \author{---}
\date{\vspace{-2em}\today{}}

\input{macros}
\renewcommand{\Lam}[2]{\lambda#1.\, \{\!\!\{#2\}\!\!\}}

\begin{document}

\maketitle

\section*{The Calculus}
\subparagraph{Syntax}
\[\begin{array}{lll}
  \tm, \tmtwo & \ddef & \var \mid \tm\,\tmtwo \mid \Lam\var{\tm\Comma\vec\tm} \\
  n & \ddef & \Lam\var{n\Comma\vec n} \mid \var\,\vec n \\
  \\
  C & \ddef & \Box \mid C\,\tm \mid \tm\,C \\
  P & \ddef & \vec\tm \Comma \Box \Comma \vec\tm \mid \vec\tm \Comma C[\Lam\var P] \Comma \vec\tm  \\
\end{array}\]

\subparagraph{Reduction rules}
\[\begin{array}{lll}
  P[C[(\Lam\var{\tm\Comma\vec\tm})\,\tmtwo]] & \Red{}{\var\in \tm,\vec\tm} &
   P[C[\tm\Subst\var\tmtwo]\Comma \vec\tm\Subst\var\tmtwo]\\
   P[C[(\Lam\var{\tm\Comma\vec\tm})\,\tmtwo]] & \Red{}{\var\not\in\tm,\vec\tm} &
    P[C[\tm] \Comma \vec\tm\Comma\tmtwo]\\
\end{array}\]

\subparagraph{Properties}
\begin{itemize}
  \item Every term is normalizing iff it is strongly normalizing.
  \item Ogni strategia e' perpetua!
  \item \ldots
\end{itemize}

\clearpage
\section*{Separation}
% Paths:
\newcommand{\PathEmpty}{\epsilon}
\newcommand{\PathAbs}[1]{\mathtt{abs}(#1)}
\newcommand{\PathArg}[3]{\mathtt{arg}_{#2}^{#1}(#3)}
\newcommand{\PathHd}{\mathtt{hd}}

\newcommand{\GarbageOf}[1]{\operatorname{Garb}(#1)}
\newcommand{\HeadOf}[1]{\operatorname{head}(#1)}
\newcommand{\FstOf}[1]{\operatorname{fst}(#1)}
\newcommand{\DegOf}[1]{\operatorname{deg}(#1)}
\newcommand{\SubtmOf}[2]{#1\preceq #2}
\newcommand{\OfHead}[2]{#1_{{\mid}#2}}
\newcommand{\SubtmsOf}[1]{\operatorname{Sub}(#1)}
\newcommand{\Div}{\mathtt{d}}
\newcommand{\Conv}{\mathtt{c}}
\newcommand{\Const}{\mathtt{K}}
\newcommand{\NamedBoundVar}[1]{\texttt{bvar(}#1\texttt{)}}
\newcommand{\AC}[1]{{\color{violet}#1}}
\begin{itemize}
  % \item \textbf{$\boldsymbol\sigma$-separation.}
  %  \textcolor{red}{come definirlo? con le variabili? con i termini?
  %   problematico in cbv}
  %  Two terms are $\sigma$-separable iff there exists a substitution
  %   $\sigma$ such that \textcolor{red}{???}
  % \item \textbf{Semi-$\boldsymbol\sigma$-separation.}
  %  Two terms are semi-$\sigma$-separable iff there exists a substitution
  %   $\sigma$ such that -- in short -- it makes one diverge and the other one converge.
  % \item \textbf{Our subproblem:} Semi-$\sigma$-separating two (usual) $\boldsymbol\lambda$-terms
   % (in deep normal form)
   \item \textbf{Subterm:} $\SubtmOf\tm\tmtwo$ means that $\tm$ is an ($\eta/\Omega$)-subterm of $\tmtwo$.
   \item \textbf{Subterm at position $\boldsymbol\pi$:} TODO
   \item $\boldsymbol\sim_{\boldsymbol\pi}$
   \item \textbf{Distinction:} Let $\var\defeq \HeadOf D$. Let $T_{\var} \defeq \{\tm \preceq T \mid \HeadOf{\tm} = \var \}$.
  $C_{\var}$ is $D$--\emph{distinct} iff it is empty, or there exists path $\pi$ s.t.:
  \begin{itemize}
    \item \emph{effective} for $D$, cioe' $\FstOf{\pi} \leq \DegOf{D}$;
    \item $\forall \tm\in D_\var$, $\tm_\pi \neq \Omega$;
    \item $\exists \tm\in C_\var$ s.t. $\tm \not\sim_\pi D$;
    \item $\{\tm\in C_\var \mid \tm \sim_\pi D\}$ is $D$--distinct.
  \end{itemize}

\clearpage
  \item $\bullet$ $\bullet$ $\bullet$ $\bullet$ $\bullet$
  $\bullet$ $\bullet$ $\bullet$ $\bullet$ $\bullet$
  $\bullet$ $\bullet$ $\bullet$ $\bullet$ $\bullet$
  \texttt{ prove di nuove definizioni di ac:}

  \item \textbf{Set of subterms:} %$\SubtmsOf{\tm} \defeq \{ \tmtwo \mid \SubtmOf\tmtwo\tm \}$
  \[\begin{array}{ll}
    \SubtmsOf{\var} & \defeq \{\var\} \\
    \SubtmsOf{\tm\,\tmtwo} & \defeq \SubtmsOf\tm \cup \SubtmsOf\tmtwo \cup \{\tm\,\tmtwo\} \\
    \SubtmsOf{\lambda \var.\, \vec\tm} & \defeq \{\tmtwo\{\Const/\var\} \mid \tmtwo \in\SubtmsOf{\vec\tm}\} \\
  \end{array}\]
  \AC{Note: $\SubtmsOf\cdot$ replaces bound variables with $\Const$ when going under abstractions.}
  \item \textbf{Subterm at position:}
  \[\begin{array}{ll}
    \text{Paths: } \pi & ::= \PathEmpty \mid \PathHd \mid \PathArg i \var \pi \mid \PathAbs\pi
  \end{array}\]
  \AC{
   Given a path, one can retrieve from a term (if possible) the subterm at that position.

   Since the path may go through abstractions, bound variables that become free
   are renamed to variables of the form $\NamedBoundVar\pi$
   (where $\pi$ is the path in the original inert leading to the abstraction binding that variable).
  }
  % \newcommand{\GetSubtm}[2]{\operatorname{GetSubtm}(#1\texttt{;}#2)}
  \newcommand{\GetSubtm}[2]{{#1}_{#2}}
  \[\begin{array}{ll}
    \GetSubtm\tm\pi & \defeq \GetSubtm\tm{\underline\pi} \\
    \GetSubtm\tm{\rho[\underline\PathEmpty]} & \defeq \tm \\
    \GetSubtm{(x\,t_1\cdots t_n)}{\rho[\underline\PathHd]} & \defeq x \\
    \GetSubtm{(x\,t_1\cdots t_n)}{\rho[\underline{\PathArg i \var \pi}]} & \defeq
      \GetSubtm{(t_i)}{\rho[\PathArg i \var {\underline\pi}]} \mbox{(if } 1 \leq i\leq n \mbox{)} \\
    \GetSubtm{(\lambda x.\, t)}{\rho[\underline {\PathAbs \pi}]} & \defeq
     \GetSubtm\tm{\rho(\PathAbs{\underline\pi})}
     \{\var\mapsto\NamedBoundVar{\rho[\PathEmpty]}\} \\
    \GetSubtm{\tm}{\rho(\underline{\PathAbs \pi})} &
     \defeq \GetSubtm{(\lambda \var.\, \tm\,\var)}{\rho(\PathAbs {\underline\pi})} \text{ (with } x \text{ fresh) (eta)}\\
    % \Omega_-^- & \defeq \Omega \\
  \end{array}\]
  \item \textbf{Head restriction:} $\OfHead T \var \defeq \{\tm \in T \mid \HeadOf{\tm} (\defeq \tm_{\PathHd}) = \var \}$
  \item \textbf{Telescopic garbage chain:} $\{\langle\tm_1,\pi_1\rangle,\ldots,\langle\tm_n,\pi_n\rangle\}$ is a $-$ if $\forall i$:
   \[\tm_{i+1} \in \SubtmsOf{\text{garbage of } \GetSubtm{(\tm_i)}{\pi_i}}\]
  \item \textbf{Distinction:} \underline{$S$ is $\{\langle\Div_1,\pi_1\rangle,\ldots,\langle\Div_n,\pi_n\rangle\}$--distinct} iff (one of the following three):
  \begin{itemize}
    \item $\OfHead S {\HeadOf \Div}$ is empty and $n=1$
  \end{itemize}
   OR: let $\Div\defeq\Div_1$ in:
 \begin{itemize}
   \item there exists a path $\pi$ s.t.
   \item (Effective) $\pi$ is \emph{effective} for all $\Div_i$ s.t. $\HeadOf{\Div_i} = \HeadOf{\Div}$
   \item $\forall \tm\in \OfHead{\SubtmsOf{\Div_i}}{\HeadOf\Div}$, $\tm_\pi \neq \Omega$;
   \item (Useful) $\exists s\in \OfHead S{\HeadOf\Div}$ s.t. $s \not\sim_\pi \Div$;
   \item $S\setminus\{s\in \OfHead S{\HeadOf\Div} \mid s \not\sim_\pi \Div\}$ is $D$--distinct.
 \end{itemize}
 OR:
\begin{itemize}
   \item $S'$ is $\{\langle\Div_2,\pi_2\rangle,\ldots,\langle\Div_n,\pi_n\rangle\}$--distinct, where:
    \[S' \defeq S \mathrel{\cup} \SubtmsOf{\{\text{garbage of } s \text{ along } \pi_1 \mid s\in \OfHead{S}{\HeadOf\Div}\}} \]
 \end{itemize}

 \item \textbf{Semi-$\sigma$-separability: } $(\Div,\Conv)$ are semi-$\sigma$-separable
  IFF there is $\Div_1$ (an $\Omega$--approximation of a subterm of $\Div$ with
  at most one garbage, and without stuck variables)
  and a telescopic garbage chain $D\defeq\{\langle\Div_1,\pi_1\rangle,\ldots,\langle\Div_n,\pi_n\rangle\}$ s.t.
  $\SubtmsOf\Conv$ is $D$--distinct.

 \clearpage
 \item $\bullet$ $\bullet$ $\bullet$ $\bullet$ $\bullet$
 $\bullet$ $\bullet$ $\bullet$ $\bullet$ $\bullet$
 $\bullet$ $\bullet$ $\bullet$ $\bullet$ $\bullet$

 \item \textbf{Unlockable variables.}
  We use the following contexts:
  $E ::= \Box \mid E\, t \mid t\, E \mid \Lam\var{\vec t\Comma E \Comma \vec t} $.
 A variable $\var$ is \emph{unlockable} in a context $E$ if:
  \begin{itemize}
    \item it is not bound in $E$, or
    \item $E[\cdot] = E'[\vartwo\, \vec\tm \, (\Lam{\cdots\var\cdots}{\vec\tmtwo \Comma E'[\cdot]\Comma\vec\tmthree})]$
     and $\vartwo$ is unlockable in $E'$.
  \end{itemize}

  Transformation removing an unlockable variable bound at position $\pi$:
  \[\tau_{n::\pi}[\alpha] := \lambda x_1..x_n\,x.\, \alpha\,\vec x\,(\tau_\pi[x])\]

  % \textcolor{red}{For every term there exists an equivalent term with no unlockable variables}

\end{itemize}

% \clearpage
% \section*{NP-hardness}
% \newcommand{\Pacman}{\Omega}
% \newcommand{\sep}{\cdot}
% \begin{example}[Graph 3-coloring]\label{example:3col}
% Let $G=(V,E)$ be a graph, with $N \defeq |V|$.
% We encode the problem of finding a 3-coloring of $G$ in the following problem of semi-$\sigma$-separation:
%  \[\begin{array}{cl}
%  \Uparrow & x \sep t_1^1\,t_1^2\,t_1^3 \sep t_2^1\,t_2^2\,t_2^3 \sep \cdots t_n^1\,t_n^2\,t_n^3 \\
%  \\
%  \Downarrow & x \sep \Pacman\,\Pacman\,\Pacman \sep t_2^1\,t_2^2\,t_2^3 \sep \cdots t_n^1\,t_n^2\,t_n^3 \\
%  \Downarrow & x \sep t_1^1\,t_1^2\,t_1^3 \sep \Pacman\,\Pacman\,\Pacman \sep \cdots t_n^1\,t_n^2\,t_n^3 \\
%  \vdots & \vdots \\
%  \Downarrow & x \sep t_1^1\,t_1^2\,t_1^3 \sep t_2^1\,t_2^2\,t_2^3 \sep \cdots \Pacman\,\Pacman\,\Pacman \\
%  \end{array}\]
%
% Where: $\dummy$ is (probably) a variable, $\bomb\defeq \lambda\_.\,\bot$, and the $a$'s are defined as follows:
%
% \begin{itemize}
%
%  \item $\begin{array}{ll}
%   a_1^1 \defeq & \lambda\_. \, x \sep y\bomb\bomb \sep\bomb\ldots \\
%   a_1^2 \defeq & \lambda\_. \, x \sep \bomb y\bomb \sep\bomb\ldots \\
%   a_1^3 \defeq & \lambda\_. \, x \sep \bomb\bomb y \sep\bomb\ldots \\
%  \end{array}$
%
%  \item $a_2^1 \defeq \begin{cases}
%   \lambda\_.\, x \sep \bomb \dummy\dummy \sep y\bomb\bomb \cdot \bomb\ldots & \text{if } (v_1, v_2)\in E \\
%   \lambda\_.\, x \sep \dummy\dummy\dummy \sep y\bomb\bomb \cdot \bomb\ldots & \text{if } (v_1, v_2)\not\in E \\
%  \end{cases}$
%
%  \item \ldots
%
% \end{itemize}
%
% \begin{definition}[Index notation]
%  Let $t = x \sep x_1^1 x_2^1 x_3^1 \sep x_1^2 x_2^2 x_3^2 \sep \ldots \sep x_1^m x_2^m x_3^m$. Then: \[t[\,_k^j] \defeq x_k^j.\]
%  \end{definition}
%
% Let $z_0$, $z_1$, $z_2$ be variables.
%
% Define:
% \[a_k^j[\,_{k'}^{j'}]\defeq\begin{cases}
%  \bomb & \text{if } j<j' \\
%  \begin{cases}
%   \bomb & \text{if } k\neq k' \\
%   y & \text{if } k = k' \\
%  \end{cases} & \text{if } j = j' \\
%  \begin{cases}
%   \bomb & \text{if } k = k' \\
%   \dummy & \text{if } k \neq k' \\
%  \end{cases} & \text{if } (v_j,v_{j'}) \in E \\
%  \dummy & \text{if } (v_j,v_{j'}) \not\in E
% \end{cases}\]
%
% Attenzione! Le $a$ vanno protette da lambda ($\lambda\_$)!
%
% % Dimensione del problema: circa $(3\times m^2)^2$.
%
% Intuitively, if $\sigma(x)$ ``uses'' $a_j^i$, then $\sigma$ colors $v_j$ with color $i$.
%
% \begin{lemma}[Extraction of the coloring]
%  Let $\sigma$ be a substitution which is a solution for the semi-separation problem. Then for example:
%
% \begin{itemize}
%  \item $\operatorname{color}(v_1) = 2$ iff
%   \[(x \sep \Pacman\,\bomb\,\Pacman \sep \bomb\,\bomb\,\bomb \,\sep \bomb\,\bomb\,\bomb \,\sep \cdots \sep \bomb\,\bomb\,\bomb)\,\sigma \to \bot\]
%  \item $\operatorname{color}(v_2) = 3$ iff:
%   \[(x \sep \dummy\,\dummy\,\dummy \sep \Pacman\,\Pacman\,\bomb \,\sep \bomb\,\bomb\,\bomb \,\sep \cdots \sep \bomb\,\bomb\,\bomb)\,\sigma \to \bot\]
% \end{itemize}
% \end{lemma}
%
% % Where $\Pacman \equiv \lambda\_.\,\Pacman$.
%
% \end{example}
\clearpage
\section{Tentativi $\mathbf X$--separability (July, 15$^{\mathbf{th}}\div\infty$)}
\newcommand{\perm}{\pi}
\newcommand{\Perm}[2]{\pi[#1,#2]}
\newcommand{\xK}{\kappa}
\newcommand{\xN}{n}
\newcommand{\LAM}[2]{\Lambda_{#2,#1}}
\newcommand{\LAMNK}{\LAM\xN\xK}
\newcommand{\Apply}[2]{(#1\mapsto#2)}
\newcommand{\kn}{$(\kappa,n)$}
\newcommand{\knnf}{\kn{}-nf}
\newcommand{\Lams}[1]{\operatorname{lams}(#1)}
\newcommand{\Args}[1]{\operatorname{args}(#1)}
\newcommand{\Head}[1]{\operatorname{head}(#1)}
\begin{definition}[$\Lams\cdot,\Args\cdot,\Head\cdot$]
  \[\Lams{\lambda\vec\var.\,\vartwo\,\vec\tm} \defeq |\vec\var| \]
  \[\Args{\lambda\vec\var.\,\vartwo\,\vec\tm} \defeq |\vec\tm| \]
  \[\Head{\lambda\vec\var.\,\vartwo\,\vec\tm} \defeq \vartwo \]
\end{definition}

\begin{definition}[\kn{}-normal forms]
  First recall that terms in normal form have the shape
  $\lambda\vec\var.\,\vartwo\,\vec\tm$, where the terms $\vec\tm$ are in normal form too.
  
  We define inductively the set of \knnf s (for $\xK,\xN$ natural numbers):
  $\lambda\vec\var.\,\vartwo\,\vec\tm$ is a \knnf{} iff 
  $|\vec\var|\leq\xK$, $|\vec\tm|\leq\xN$, and every term in $\vec\tm$ is a \knnf{}.
\end{definition}

\begin{definition}[Permutator $\Perm\cdot\cdot$]~
  \[\Perm i j \defeq \lambda\vec\var\vartwo.\,\vartwo\, \vec\alpha\,\vec\var\,\vartwo\]
  where $\vec\var$, $\vec\alpha$ and $\vartwo$ are fresh variables,
  with $|\vec\var| = i$ and $|\vec\alpha| = j$.
\end{definition}

\begin{definition}{$\Apply\cdot\cdot$}
  We denote by $\tmtwo\Apply\var\tm$ the normal form of $\tmtwo\Subst\var\tm$ in normal form --
  if it has one.
\end{definition}

\begin{lemma}
  Let $\tm$ a \knnf, and $\Head\tm=\var$.
  If $A\leq \Args\tm$ and $B \geq \xK + A + 1$,
  let $\tmtwo\defeq\tm\Apply\var{\Perm{A}{B}}$ in:
  $\Lams\tm=\Lams\tmtwo$ and $\tmtwo\in\LAM ? ?$
\end{lemma}
\begin{proof}
  By induction on the normal form structure of $\tm$.
  Let $\tm=\lambda\vec\var.\,\vartwo\,\vec\tmtwo$:
  \begin{itemize}
    \item if $\vartwo=\var$, then
    $\tm\Apply\var\perm = \lambda\var_1\ldots\var_{???}.\,\var\,\vec\tmthree$
    \item if $\vartwo\neq\var$, then $\tm\Apply\var\perm = \lambda\vec\var.\,\vartwo\,\vec\tmthree$
    where $\vec\tmthree\defeq \vec\tmtwo\Apply\var\perm$.
    Conclude by inductive hypothesis.
  \end{itemize}
\end{proof}
\begin{corollary}
  Let $\tm \defeq \var\,f_1\cdots f_m$ a \knnf.
  If $A\leq m$ and $B \geq A + \xK$,
  then $\tm\Apply\var{\Perm{A}{B}}$ is an inert.
\end{corollary}

\begin{lemma}
  For every $\tm,\tmtwo$ be \knnf{s},
  every fresh variable $\var$,
  $\perm\defeq\Perm{i}{i+k+1}$ permutator,
  $\tm\EtaEq\tmtwo$ iff $\tm\Apply\var\perm\EtaEq\tmtwo\Apply\var\perm$.
\end{lemma}

\end{document}
