\documentclass[]{sigplanconf}

\title{Nameless, Painless}

\authorinfo{Nicolas Pouillard}{INRIA}{Nicolas.Pouillard@inria.fr}


\conferenceinfo{ICFP'11,} {September 19--21, 2011, Tokyo, Japan.}
\CopyrightYear{2011}
\copyrightdata{978-1-4503-0865-6/11/09}


\usepackage[]{amsfonts}

\usepackage[]{amssymb}

\usepackage[]{tikz}

\usepackage[]{stmaryrd}

\usepackage[]{url}

\usepackage[pdftex,bookmarks=true,bookmarksopen=true,colorlinks=true,linkcolor=blue,citecolor=blue,urlcolor=blue]{hyperref}

\usepackage[T3,OT1]{fontenc}

\DeclareTextSymbol\textcrlambda{T3}{172}

\DeclareTextSymbolDefault\textcrlambda{T3}

\usetikzlibrary{matrix,arrows}

\usepackage[utf8x]{inputenc}


\providecommand\mathbbm{\mathbb}
\DeclareUnicodeCharacter{8718}{\ensuremath{\scriptstyle{\blacksquare}}}
\DeclareUnicodeCharacter{8759}{::}
\DeclareUnicodeCharacter{10214}{\ensuremath{\llbracket}} % ⟦
\DeclareUnicodeCharacter{10215}{\ensuremath{\rrbracket}} % ⟧
\DeclareUnicodeCharacter{10218}{\ensuremath{\langle\!\langle}} % ⟪
\DeclareUnicodeCharacter{10219}{\ensuremath{\rangle\!\rangle}} % ⟫
\DeclareUnicodeCharacter{7482}{\textsuperscript{N}}             % ᴺ
\DeclareUnicodeCharacter{7490}{\textsuperscript{W}}             % ᵂ
\DeclareUnicodeCharacter{411}{\textcrlambda}                    % ƛ
\DeclareUnicodeCharacter{738}{\textsuperscript{s}}              % ˢ
\DeclareUnicodeCharacter{955}{\ensuremath{\lambda}}             % λ
\DeclareUnicodeCharacter{183}{\ensuremath{\cdot}}               % ·
\DeclareUnicodeCharacter{7523}{\ensuremath{_{r}}}               % ᵣ
\DeclareUnicodeCharacter{8760}{\texttt{-}}                      % ∸ -}
\DeclareUnicodeCharacter{9679}{\ensuremath{\bullet}}            % ●

\begin{document}
\maketitle

\begin{abstract}
De Bruijn indices are a well  known technique for programming with names
and  binders. They  provide a  representation  that is  both simple  and
canonical.

However, programming errors tend to be really easy to make. We propose a
safer programming  interface implemented as a  library. Whereas indexing
the types of names and terms by a numerical bound is a famous technique,
we index them by worlds, a different  notion of index that is both finer
and more abstract. While being more finely typed, our approach incurs no
loss of expressiveness or efficiency.

Via parametricity  we   obtain   properties  about functions polymorphic
on worlds.  For instance,  well-typed  world-polymorphic functions  over
open λ-terms commute with any renaming of the free variables.

Our whole  development is conducted  within Agda,  from the code  of the
library,  to its  soundness proof  and the  properties of external
functions. The soundness of our  library is demonstrated via the construction
of a logical relations argument.

\end{abstract}


\category{D.3.3}{Programming Languages}{Language Constructs and Features}
                [Data types and structures; Polymorphism]
\terms{Design, Languages, Theory}
\keywords{names, binders, meta-programming, name abstraction, de Bruijn indices}


\section{Introduction\label{intro}}

%
%paragraphName: representations with names and binders in the wild
It is quite common in the programming realm to deal with the mundane
    business of data structures with  names and binders. Compilers, code
    generators,  static analysers,  theorem  provers, and  type-checkers
    have this in common. They manipulate programs, formulae, proofs, and
    types. When  seen as pieces of  data, there is a  common difficulty$:$
    the representation of variables (names and binders).%


%
%paragraphName: binders are hard
One traditional  approach is to  represent all the occurrences  of a
    bound variable  identically by using character  strings or integers.
    While being the  most obvious representation it is known  to cause a
    lot of  trouble when dealing  with operations like  substitution. In
    particular we  name it the capture-avoiding  substitution because it
    has  to rename  some variables  to avoid  accidental changes  called
    captures.%


%
%paragraphName: we focus on nameless
In  this article  we focus  on a  different kind  of representation,
    namely de Bruijn indices \cite{de-bruijn-72}. This  representation is said to be
    nameless because variables are no longer  identified by a name but a
    notion of  ``distance'' to the  binding point. De Bruijn indices are  the most
    famous nameless representation and in  the following we will use the
    term ``nameless'' as a synonym for ``de Bruijn indices''.%


%
%paragraphName: nameless advantages
The  nameless approach  solves part  of the  problem by  providing a
    canonical representation. More precisely  binding occurrences are no
    longer named (we now use  \texttt{$ \lambda ${\char `\.}} instead of \texttt{$ \lambda $x{\char `\.}}). Then bound
    variables are represented by the ``distance'' to the binding λ. This
    distance  is  the number  of  λs  to cross  in  order  to reach  the
    binding{~}λ.%


%
%paragraphName: why having a safer system?
A   major   issue  with   this   nameless   representation  is   its
    arithmetic  flavor. Indeed  properties about  names and  binders are
    turned  into  arithmetic  formulae.  The result  can  be  harder  to
    understand,  and  worse,  easier  to  get  wrong.  To  remedy  this,
    several  techniques  have  been   proposed  to  give  finer  grained
    types to these representations \cite{mcbride-mckinna-04,altenkirch-93,altenkirch-reus-99,bird-paterson-99}.  We  continue further  in  this
    direction by  providing a  safer system to  program with  a nameless
    representation.%


\subsection{Contributions}

%
%paragraphName: nameless only
In  a previous  paper \cite{pouillard-pottier-10} we  developed an
    abstract interface to program with  names and binders. The interface
    can be  both implemented  in a  named or a  nameless style.  Here by
    focusing  on  a  nameless  representation we  greatly  simplify  the
    programming interface needed to achieve our safety goals. This is at
    the expense of some loss of abstraction. However while the goals are
    less ambitious, the results are significantly more applicable since
    simpler and closer to a concrete representation.%


%
%paragraphName: better worlds
Our  previous  nameless implementation  was  relying  on the  \texttt{Fin}    approach  (described in  section  \ref{finSection}).  The notion  of
    worlds  presented  here  (in   section  \ref{napaTypesSection})  is
    significantly  more precise  than  \texttt{Fin}. However  the worlds  were
    already  abstract  to the  programmer  and  they still  are.  Indeed
    abstraction is  necessary to retain the  parametricity properties we
    want from world-polymorphic functions.%


%
%paragraphName: solid from the ground
While  a   fair  amount  of   proofs  were  already   mechanized  in
    \cite{pouillard-pottier-10}, the logical  relation argument was still
    largely on paper. Here we  not only finished these mechanized proofs
    but have every part well connected in one single setup. The code and
    proofs are  accessible online  at \cite{pouillard-11} and  we encourage
    the reader  to have a  look for  reference on technical  details and
    applications.%


\subsection{Outline of the paper}

%
%paragraphName: plan
This paper is organized as follows. In the remainder of this section
    we present several nameless  techniques to represent data structures
    with bindings.  In section \ref{defNaPa} we detail our  approach to
    the problem.  In section \ref{usingNaPa} we give some  examples and
    advanced operations. In section \ref{soundness} we develop a logical
    relation  construction which  ensures  the  soundness properties  we
    want,  and we  show  how  to exploit  these  properties on  concrete
    examples. All the construction is built in the \textsc{Agda} language, our
    system is  an \textsc{Agda}  library and  its soundness  proof is  done in
    \textsc{Agda} as well.%


\subsection{A brief introduction to \textsc{Agda} notation}

%
%paragraphName: agda types
Throughout the paper, our definitions are presented in the syntax of
    \textsc{Agda}.  In \textsc{Agda},  \texttt{Set}  (or  \texttt{Set₀}) is  the  type of  small
    types  like  \texttt{Bool},  \texttt{Maybe $ {(} $List Bool$ {)} $}, or  \texttt{$ \mathbb{{N}} $}.  \texttt{Set₁}    is  the  type  of \texttt{Set},  \texttt{Set $ \rightarrow $ Bool},  or  \texttt{$ \mathbb{{N}} $ $ \rightarrow $ Set}.
    The  function space  is written  \texttt{A $ \rightarrow $ B}, while  the dependent
    function  space  is   written  \texttt{$ {(} $x {\char `\:} A$ {)} $ $ \rightarrow $}{ }\texttt{B}$ \: $  or
    \texttt{ $ \forall $ $ {(} $x {\char `\:} A$ {)} $ $ \rightarrow $ B}.  An   implicit  parameter,   introduced  via
    \texttt{ $ \forall $\{x {\char `\:} A\} $ \rightarrow $ B},  can  be  omitted  at  a  call  site  if  its
    value  can be  inferred from  the context.  There are  shortcuts for
    introducing  multiple  arguments at  once  or  for omitting  a  type
    annotation, as in \texttt{$ \forall $\{A\} \{i j {\char `\:} A\} x $ \rightarrow $ e}. There is no specific
    sort for propositions in \textsc{Agda}, everything is in \texttt{Set ℓ} for
    some \texttt{ℓ}. The unit type is  a record type with no fields named
    \texttt{$ \top $}, it  also represents  the \texttt{True} proposition.  The empty
    type is an  (inductive) data type with no  constructors named \texttt{$ \bot $},
    it  also  represents  the \texttt{False}  proposition.  The  negation
    \texttt{$ \neg $ A} is defined as \texttt{A $ \rightarrow $ $ \bot $}.%


%
%paragraphName: agda constructors
The same name  can be used for different  data constructors. \textsc{Agda}    makes use of type annotations to resolve ambiguities.%


%
%paragraphName: agda definitions
As  in Haskell,  a definition  consists of  a type  signature and  a
    sequence of defining equations,  which may involve pattern-matching.
    The   \texttt{with}   construct  extends   a   pattern-matching-based
    definition with  new columns. An ellipsis  \emph{\texttt{{\char `\.}{\char `\.}{\char `\.}}} is used
    to elide a redundant equation prefix.%


%
%paragraphName: agda lexical syntax
\textsc{Agda} is  strict about  whitespace$:$ \texttt{x$ \leq $y} is  an identifier,
    whereas  \texttt{x $ \leq $ y}  is  an  application. This  allows  naming  a
    variable after its type (deprived  of any whitespace). We use mixfix
    declarations,  such as  \texttt{{\char `\_}$ \oplus ${\char `\_}}.  We use  some definitions  from
    \textsc{Agda}'s standard  library$:$ natural  numbers, booleans,  lists, and
    applicative functors (\texttt{pure}, \texttt{{\char `\_}$ \otimes ${\char `\_}}).%


%
%paragraphName: not self-contained
For  the  sake  of  conciseness, the  code  fragments  presented  in
    the  paper are  sometimes not  perfectly self-contained.  However, a
    complete \textsc{Agda} development is available online \cite{pouillard-11}.%


\subsection{Related work$:$ nameless representations}

%
%paragraphName: nameless representations
Various  techniques  have  been   discovered  to  build  a  nameless
    representation. We have  chosen a few of them  which gradually setup
    the stage.%


\subsubsection{\texttt{bare}$:$ The original approach}

%
%paragraphName: description of bare
We  call  this one  \texttt{bare},  because  it  solely relies  on  natural
    numbers. To  make things  more concrete  here is  an example  of its
    use  when  defining  the  untyped  λ-calculus  with  local  bindings
    (\texttt{let}). Our  naming convention is  as follows$:$ we  call \texttt{Tm}    the type of λ-terms, \texttt{V} is the data constructor for variables, \texttt{{\char `\_}}\texttt{$ \cdotp $}\texttt{{\char `\_}}  is for  the application,  \texttt{ƛ} is  for the  λ-abstraction, and
    finally \texttt{Let} is for local bindings.%


%
%comment:
%  data Tm : Set where
%    V    : (x    : ℕ)  → Tm
%    _·_  : (t u  : Tm)  → Tm
%    ƛ    : (t    : Tm)  → Tm
%    Let  : (t u  : Tm)  → Tm
%
%


~\\~\texttt{\mbox{\hspace{1em}}data\mbox{\hspace{0.50em}}Tm\mbox{\hspace{0.50em}}{\char `\:}\mbox{\hspace{0.50em}}Set\mbox{\hspace{0.50em}}where\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{2em}}V\mbox{\hspace{2em}}{\char `\:}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}x\mbox{\hspace{2em}}{\char `\:}\mbox{\hspace{0.50em}}\makebox[2.44ex][c]{$ \mathbb{{N}} $}\makebox[1.22ex][c]{$ {)} $}\mbox{\hspace{1em}}$ \rightarrow $\mbox{\hspace{0.50em}}Tm\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{2em}}\makebox[1.22ex][c]{{\char `\_}}\makebox[1.22ex][c]{$ \cdotp $}\makebox[1.22ex][c]{{\char `\_}}\mbox{\hspace{1em}}{\char `\:}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}t\mbox{\hspace{0.50em}}u\mbox{\hspace{1em}}{\char `\:}\mbox{\hspace{0.50em}}Tm\makebox[1.22ex][c]{$ {)} $}\mbox{\hspace{1em}}$ \rightarrow $\mbox{\hspace{0.50em}}Tm\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{2em}}\makebox[1.22ex][c]{ƛ}\mbox{\hspace{2em}}{\char `\:}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}t\mbox{\hspace{2em}}{\char `\:}\mbox{\hspace{0.50em}}Tm\makebox[1.22ex][c]{$ {)} $}\mbox{\hspace{1em}}$ \rightarrow $\mbox{\hspace{0.50em}}Tm\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{2em}}Let\mbox{\hspace{1em}}{\char `\:}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}t\mbox{\hspace{0.50em}}u\mbox{\hspace{1em}}{\char `\:}\mbox{\hspace{0.50em}}Tm\makebox[1.22ex][c]{$ {)} $}\mbox{\hspace{1em}}$ \rightarrow $\mbox{\hspace{0.50em}}Tm\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{1em}}}

%
%paragraphName: in bare, types are weak
From the point of view of the binding structure, it is striking that
    no difference appears between the  constructors of the data type. It
    is completely up to the  programmer to manage the scoping difference
    introduced by  \texttt{ƛ} and  \texttt{Let}. This  is even  more worrying  in the
    \texttt{Let}  case  since  we  have  no clue  of  difference  between  the
    arguments.%


%
%paragraphName: appTm in bare
Here is an example using this representation to build the λ-term for
    \texttt{$ \lambda $f{\char `\.}$ \lambda $x{\char `\.}f}{ }\texttt{x}.%


%
%comment:
%  appTm : Tm
%  appTm = ƛ (ƛ (V 1 · V 0))
%
%


~\\~\texttt{\mbox{\hspace{1em}}appTm\mbox{\hspace{0.50em}}{\char `\:}\mbox{\hspace{0.50em}}Tm\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{1em}}appTm\mbox{\hspace{0.50em}}{\char `\=}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{ƛ}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}\makebox[1.22ex][c]{ƛ}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}V\mbox{\hspace{0.50em}}1\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \cdotp $}\mbox{\hspace{0.50em}}V\mbox{\hspace{0.50em}}0\makebox[1.22ex][c]{$ {)} $}\makebox[1.22ex][c]{$ {)} $}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{1em}}}

%
%paragraphName: bare expressiveness
The  main  advantages  of  this  approach  are  its  simplicity  and
    its  expressiveness.  The  expressiveness is  almost  maximal  since
    no  restriction  is   put  on  the  usage   of  variables.  Actually
    expressiveness is really maximal only in partial languages where all
    types  are  inhabited by  a  looping  term.  Indeed the  absence  of
    restrictions  on data  can be  constraining when  receiving data  as
    argument. In  a total language  all cases  have to be  covered, even
    those we consider  as impossible. For instance  a function accepting
    only  closed terms  will  have to  provide a  return  value for  the
    variable case  anyway. Sometimes the  return type is  so constrained
    that  the type  is actually  empty  in this  case, and  so no  dummy
    value  can be  returned. However,  even  in a  partial language  the
    expressiveness is  maximal if  we are  willing to  live in  an error
    monad.%


\subsubsection{\texttt{Maybe}$:$ The nested data type approach}

%
%paragraphName: Tm in Maybe
The nested  data type approach \cite{bellegarde-94,bird-paterson-99,altenkirch-reus-99} is  a first step towards  better properties about
    the binding structure of terms. Let  us start with the definition of
    \texttt{Tm} with this approach$:$%


%
%comment:
%  data Tm (A : Set) : Set where
%    V    : (x : A)                        → Tm A
%    _·_  : (t u : Tm A)                   → Tm A
%    ƛ    : (t : Tm (Maybe A))             → Tm A
%    Let  : (t : Tm A) (u : Tm (Maybe A))  → Tm A
%
%


~\\~\texttt{\mbox{\hspace{1em}}data\mbox{\hspace{0.50em}}Tm\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}A\mbox{\hspace{0.50em}}{\char `\:}\mbox{\hspace{0.50em}}Set\makebox[1.22ex][c]{$ {)} $}\mbox{\hspace{0.50em}}{\char `\:}\mbox{\hspace{0.50em}}Set\mbox{\hspace{0.50em}}where\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{2em}}V\mbox{\hspace{2em}}{\char `\:}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}x\mbox{\hspace{0.50em}}{\char `\:}\mbox{\hspace{0.50em}}A\makebox[1.22ex][c]{$ {)} $}\mbox{\hspace{12em}}$ \rightarrow $\mbox{\hspace{0.50em}}Tm\mbox{\hspace{0.50em}}A\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{2em}}\makebox[1.22ex][c]{{\char `\_}}\makebox[1.22ex][c]{$ \cdotp $}\makebox[1.22ex][c]{{\char `\_}}\mbox{\hspace{1em}}{\char `\:}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}t\mbox{\hspace{0.50em}}u\mbox{\hspace{0.50em}}{\char `\:}\mbox{\hspace{0.50em}}Tm\mbox{\hspace{0.50em}}A\makebox[1.22ex][c]{$ {)} $}\mbox{\hspace{9.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}Tm\mbox{\hspace{0.50em}}A\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{2em}}\makebox[1.22ex][c]{ƛ}\mbox{\hspace{2em}}{\char `\:}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}t\mbox{\hspace{0.50em}}{\char `\:}\mbox{\hspace{0.50em}}Tm\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}Maybe\mbox{\hspace{0.50em}}A\makebox[1.22ex][c]{$ {)} $}\makebox[1.22ex][c]{$ {)} $}\mbox{\hspace{6.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}Tm\mbox{\hspace{0.50em}}A\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{2em}}Let\mbox{\hspace{1em}}{\char `\:}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}t\mbox{\hspace{0.50em}}{\char `\:}\mbox{\hspace{0.50em}}Tm\mbox{\hspace{0.50em}}A\makebox[1.22ex][c]{$ {)} $}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}u\mbox{\hspace{0.50em}}{\char `\:}\mbox{\hspace{0.50em}}Tm\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}Maybe\mbox{\hspace{0.50em}}A\makebox[1.22ex][c]{$ {)} $}\makebox[1.22ex][c]{$ {)} $}\mbox{\hspace{1em}}$ \rightarrow $\mbox{\hspace{0.50em}}Tm\mbox{\hspace{0.50em}}A\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{1em}}}

%
%paragraphName: explaining Tm in Maybe
There are three  points to look at. The \texttt{Tm}  type is parameterized
    by another  type called  \texttt{A}, so  we can look  at it  as a  kind of
    container. Note  also that the  variable case  \texttt{V} does not  hold a
    \texttt{$ \mathbb{{N}} $} but an \texttt{A}. Last but not least the \texttt{ƛ} case holds a term whose
    parameter is not simply an \texttt{A} but a \texttt{Maybe A}.%


%
%paragraphName: nested/non-regular
This  last point  makes  the \texttt{Tm}  type a  nested  data type,  also
    called a  non-regular type.  This has  the consequence  of requiring
    polymorphic recursion to write recursive functions on such a type.%


%
%paragraphName: adequacy of Maybe
To understand why this is  an adequate representation of λ-terms one
    has to look a bit more at the meaning of \texttt{Maybe}. If types are seen
    as sets, then \texttt{Maybe} takes a set  and returns a set with one extra
    element. So each time we cross a  \texttt{ƛ}, there is one extra element in
    the  set of  allowed variables,  exactly capturing  the fact  we are
    introducing a variable.%


%
%paragraphName: appTm in Maybe
To  see the  difference  with  the previous  approach,  here is  the
    \texttt{appTm} λ-term again$:$%


%
%comment:
%  appTm : Tm ⊥
%  appTm = ƛ (ƛ (V (just nothing) · V nothing))
%
%


~\\~\texttt{\mbox{\hspace{1em}}appTm\mbox{\hspace{0.50em}}{\char `\:}\mbox{\hspace{0.50em}}Tm\mbox{\hspace{0.50em}}$ \bot $\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{1em}}appTm\mbox{\hspace{0.50em}}{\char `\=}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{ƛ}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}\makebox[1.22ex][c]{ƛ}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}V\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}just\mbox{\hspace{0.50em}}nothing\makebox[1.22ex][c]{$ {)} $}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \cdotp $}\mbox{\hspace{0.50em}}V\mbox{\hspace{0.50em}}nothing\makebox[1.22ex][c]{$ {)} $}\makebox[1.22ex][c]{$ {)} $}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{1em}}}

%
%paragraphName: ⊥ in Maybe
Note the use of the empty type  \texttt{$ \bot $} to state the closedness of the
    \texttt{appTm} term.  Stating this kind of  properties was impossible
    to  do with  the  previous approach,  without  resorting to  logical
    properties on the side.%


\subsubsection{The \texttt{Fin} approach\label{finSection}}

%
%paragraphName: Fin approach description
Another approach already described  and used in \cite{altenkirch-93,mcbride-mckinna-04} is to  index everything (terms for  example) by a
    bound. This bound  is the maximum number of  distinct free variables
    allowed in the value. This rule  is enforced in two parts$:$ variables
    have  to be  strictly  lower  than their  bound,  and  the bound  is
    incremented by one when crossing a name abstraction (a λ-abstraction
    for instance, called \texttt{ƛ} here).%


%
%paragraphName: Fin type description
The \texttt{Fin n} type is  used for variables and represents natural
    numbers strictly lower than \texttt{n}.  The name \texttt{Fin n} comes
    from the fact that it defines finite sets of size \texttt{n}. We call
    this approach \texttt{Fin} for its use  of this type. The definition found
    in \textsc{Agda} standard library is the following$:$%


%
%comment:
%  data Fin : ℕ → Set where
%    zero : {n : ℕ} → Fin (suc n)
%    suc  : {n : ℕ} (i : Fin n) → Fin (suc n)
%
%


~\\~\texttt{\mbox{\hspace{1em}}data\mbox{\hspace{0.50em}}Fin\mbox{\hspace{0.50em}}{\char `\:}\mbox{\hspace{0.50em}}\makebox[2.44ex][c]{$ \mathbb{{N}} $}\mbox{\hspace{0.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}Set\mbox{\hspace{0.50em}}where\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{2em}}zero\mbox{\hspace{0.50em}}{\char `\:}\mbox{\hspace{0.50em}}\{n\mbox{\hspace{0.50em}}{\char `\:}\mbox{\hspace{0.50em}}\makebox[2.44ex][c]{$ \mathbb{{N}} $}\}\mbox{\hspace{0.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}Fin\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}suc\mbox{\hspace{0.50em}}n\makebox[1.22ex][c]{$ {)} $}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{2em}}suc\mbox{\hspace{1em}}{\char `\:}\mbox{\hspace{0.50em}}\{n\mbox{\hspace{0.50em}}{\char `\:}\mbox{\hspace{0.50em}}\makebox[2.44ex][c]{$ \mathbb{{N}} $}\}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}i\mbox{\hspace{0.50em}}{\char `\:}\mbox{\hspace{0.50em}}Fin\mbox{\hspace{0.50em}}n\makebox[1.22ex][c]{$ {)} $}\mbox{\hspace{0.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}Fin\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}suc\mbox{\hspace{0.50em}}n\makebox[1.22ex][c]{$ {)} $}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{1em}}}

%
%paragraphName: Tm in Fin
Given this  \texttt{Fin} type, one  can define  the \texttt{Tm} data  type using
    this approach$:$%


%
%comment:
%  data Tm n : Set where
%    V    : (x : Fin n)                  → Tm n
%    _·_  : (t u : Tm n)                 → Tm n
%    ƛ    : (t : Tm (suc n))             → Tm n
%    Let  : (t : Tm n) (u : Tm (suc n))  → Tm n
%
%


~\\~\texttt{\mbox{\hspace{1em}}data\mbox{\hspace{0.50em}}Tm\mbox{\hspace{0.50em}}n\mbox{\hspace{0.50em}}{\char `\:}\mbox{\hspace{0.50em}}Set\mbox{\hspace{0.50em}}where\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{2em}}V\mbox{\hspace{2em}}{\char `\:}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}x\mbox{\hspace{0.50em}}{\char `\:}\mbox{\hspace{0.50em}}Fin\mbox{\hspace{0.50em}}n\makebox[1.22ex][c]{$ {)} $}\mbox{\hspace{9em}}$ \rightarrow $\mbox{\hspace{0.50em}}Tm\mbox{\hspace{0.50em}}n\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{2em}}\makebox[1.22ex][c]{{\char `\_}}\makebox[1.22ex][c]{$ \cdotp $}\makebox[1.22ex][c]{{\char `\_}}\mbox{\hspace{1em}}{\char `\:}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}t\mbox{\hspace{0.50em}}u\mbox{\hspace{0.50em}}{\char `\:}\mbox{\hspace{0.50em}}Tm\mbox{\hspace{0.50em}}n\makebox[1.22ex][c]{$ {)} $}\mbox{\hspace{8.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}Tm\mbox{\hspace{0.50em}}n\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{2em}}\makebox[1.22ex][c]{ƛ}\mbox{\hspace{2em}}{\char `\:}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}t\mbox{\hspace{0.50em}}{\char `\:}\mbox{\hspace{0.50em}}Tm\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}suc\mbox{\hspace{0.50em}}n\makebox[1.22ex][c]{$ {)} $}\makebox[1.22ex][c]{$ {)} $}\mbox{\hspace{6.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}Tm\mbox{\hspace{0.50em}}n\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{2em}}Let\mbox{\hspace{1em}}{\char `\:}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}t\mbox{\hspace{0.50em}}{\char `\:}\mbox{\hspace{0.50em}}Tm\mbox{\hspace{0.50em}}n\makebox[1.22ex][c]{$ {)} $}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}u\mbox{\hspace{0.50em}}{\char `\:}\mbox{\hspace{0.50em}}Tm\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}suc\mbox{\hspace{0.50em}}n\makebox[1.22ex][c]{$ {)} $}\makebox[1.22ex][c]{$ {)} $}\mbox{\hspace{1em}}$ \rightarrow $\mbox{\hspace{0.50em}}Tm\mbox{\hspace{0.50em}}n\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{1em}}}

%
%paragraphName: Tm 0 in Fin
As the  previous approach, this representation  helps enforcing some
    wellformedness properties, for instance  \texttt{Tm 0} is the type of
    closed λ-terms.%


%
%paragraphName: appTm in Fin
Here is the \texttt{appTm} λ-term in this approach$:$%


%
%comment:
%  appTm : Tm 0
%  appTm = ƛ (ƛ (V (suc zero) · V zero))
%
%


~\\~\texttt{\mbox{\hspace{1em}}appTm\mbox{\hspace{0.50em}}{\char `\:}\mbox{\hspace{0.50em}}Tm\mbox{\hspace{0.50em}}0\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{1em}}appTm\mbox{\hspace{0.50em}}{\char `\=}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{ƛ}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}\makebox[1.22ex][c]{ƛ}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}V\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}suc\mbox{\hspace{0.50em}}zero\makebox[1.22ex][c]{$ {)} $}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \cdotp $}\mbox{\hspace{0.50em}}V\mbox{\hspace{0.50em}}zero\makebox[1.22ex][c]{$ {)} $}\makebox[1.22ex][c]{$ {)} $}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{1em}}}

%
%paragraphName: Fin/Maybe connection
We can  easily draw a link  with the \texttt{Maybe} approach.  Indeed, the
    \texttt{Fin $ {(} $suc n$ {)} $}  type  has exactly  one  more  element than  the
    \texttt{Fin n} type.  Although they are  not equivalent for  at least
    two reasons. The \texttt{Maybe} approach  can accept any type to represent
    variables.  This  makes the  structure  more  like a  container  and
    this  can be  particularly  helpful to  define  the substitution  as
    the  composition  of  \texttt{mapTm {\char `\:} $ \forall $\{A B\} $ \rightarrow $ $ {(} $A $ \rightarrow $ B$ {)} $ $ \rightarrow $ Tm A $ \rightarrow $ Tm B}    and       \texttt{joinTm {\char `\:} $ \forall $\{A\} $ \rightarrow $ Tm $ {(} $Tm A$ {)} $ $ \rightarrow $ Tm A}       as       in
    \cite{bird-paterson-99,altenkirch-reus-99}.  The  \texttt{Fin}  approach  has
    advantages as well, the representation is concrete and simpler since
    closer  to the  \texttt{bare}  approach. However  this apparent  simplicity
    comes at a cost, we will see that its concrete representation is one
    root of the problem.%


\section{\textsc{NaPa}, a safer nameless representation\label{defNaPa}}

\subsection{Motivation}

%
%paragraphName: wellformedness of terms, what about behavior of functions
While these  nameless approaches easily guarantee  wellformedness of
    terms, nothing is  said about functions manipulating  terms. How are
    the  inputs of  a  function related  to its  output?  What should  a
    function be able  to do given unknown free variables?  We claim that
    free variables  should be kept  abstract. More precisely  a function
    $ {f} $ operating on terms should commute with a renaming $ \Phi $ of
    free variables, namely  $ {f}{ }\circ{ }\Phi{ }{=}{ }{ }\Phi{ }\circ{ }{f} $. By renaming  we mean a
    permutation  of  the free  variables  (more  precisely an  injective
    function). In  fact this is  a bit  more flexible, depending  on the
    type of the function $ {f} $ this  property will be enforced or not,
    as we will see in section \ref{paramSection}.%


%
%paragraphName: catches programming errors but not a restriction
The goal is  to catch some programming errors by  having finer types
    for  the  manipulated  values  and for  the  functions  manipulating
    values.  We will  show  later  that this  is  not  a restriction  by
    itself since  the types do  not force  the programmer to  be precise
    everywhere.%


%
%paragraphName: forgot to shift?
One   common  kind   of  programming   error  with   these  nameless
    representations is  to forget to  shift the free variables  here and
    there. While these errors are already caught by the \texttt{Maybe} and the
    \texttt{Fin} approaches,  in these  approaches the programmer  is provided
    with  means to  workaround  the type  error.  In complex  situations
    making the distinction between a valid  coercion and a wrong one can
    be challenging. With  finer types, the mistakes will  result in more
    informative type errors.%


\subsection{A data definition kit}

%
%paragraphName: the idea of DataKit
The  three  previous approaches  are  closely  related. Just  a  few
    details change each  time. We can capture all of  them with a single
    abstraction$:$ a  triple (\texttt{World}, \texttt{Name}, \texttt{{\char `\_}$ \uparrow $1})  where \texttt{World} is
    the  index of  types  like  \texttt{Tm}, \texttt{Name}  is  the  type for  names
    (indexed by  worlds) as  used in the  \texttt{V} constructor,  and finally
    \texttt{{\char `\_}$ \uparrow $1} is  an operation to shift  a world by  one as used in  the \texttt{ƛ}    constructor.%


%
%paragraphName: DataKit in Agda
In \textsc{Agda},  this triple  can be  defined with  a record  type named
    \texttt{DataKit}. This  type is  made universe  polymorphic to  accept the
    nested data types approach.%


%
%comment:
%  record DataKit {ℓ} : Set (suc ℓ) where
%    constructor ⟨_,_,_⟩
%    field
%      World : Set ℓ
%      Name  : World → Set
%      _↑1   : World → World
%
%


~\\~\texttt{\mbox{\hspace{1em}}record\mbox{\hspace{0.50em}}DataKit\mbox{\hspace{0.50em}}\{\makebox[1.22ex][c]{ℓ}\}\mbox{\hspace{0.50em}}{\char `\:}\mbox{\hspace{0.50em}}Set\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}suc\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{ℓ}\makebox[1.22ex][c]{$ {)} $}\mbox{\hspace{0.50em}}where\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{2em}}constructor\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{⟨}\makebox[1.22ex][c]{{\char `\_}}{\char `\,}\makebox[1.22ex][c]{{\char `\_}}{\char `\,}\makebox[1.22ex][c]{{\char `\_}}\makebox[1.22ex][c]{⟩}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{2em}}field\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{3em}}World\mbox{\hspace{0.50em}}{\char `\:}\mbox{\hspace{0.50em}}Set\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{ℓ}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{3em}}Name\mbox{\hspace{1em}}{\char `\:}\mbox{\hspace{0.50em}}World\mbox{\hspace{0.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}Set\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{3em}}\makebox[1.22ex][c]{{\char `\_}}\makebox[1.22ex][c]{$ \uparrow $}1\mbox{\hspace{1.50em}}{\char `\:}\mbox{\hspace{0.50em}}World\mbox{\hspace{0.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}World\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{1em}}}

\begin{figure}[]
%
%comment:
%    bareKit   : DataKit
%    bareKit   = ⟨ ⊤ , λ _ → ℕ , id ⟩
%
%    maybeKit  : DataKit
%    maybeKit  = ⟨ Set , id , Maybe ⟩
%
%    finKit    : DataKit
%    finKit    = ⟨ ℕ , Fin , suc ⟩
%
%


~\\~\texttt{\mbox{\hspace{2em}}bareKit\mbox{\hspace{1.50em}}{\char `\:}\mbox{\hspace{0.50em}}DataKit\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{2em}}bareKit\mbox{\hspace{1.50em}}{\char `\=}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{⟨}\mbox{\hspace{0.50em}}$ \top $\mbox{\hspace{0.50em}}{\char `\,}\mbox{\hspace{0.50em}}$ \lambda $\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{{\char `\_}}\mbox{\hspace{0.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}\makebox[2.44ex][c]{$ \mathbb{{N}} $}\mbox{\hspace{0.50em}}{\char `\,}\mbox{\hspace{0.50em}}id\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{⟩}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{2em}}maybeKit\mbox{\hspace{1em}}{\char `\:}\mbox{\hspace{0.50em}}DataKit\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{2em}}maybeKit\mbox{\hspace{1em}}{\char `\=}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{⟨}\mbox{\hspace{0.50em}}Set\mbox{\hspace{0.50em}}{\char `\,}\mbox{\hspace{0.50em}}id\mbox{\hspace{0.50em}}{\char `\,}\mbox{\hspace{0.50em}}Maybe\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{⟩}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{2em}}finKit\mbox{\hspace{2em}}{\char `\:}\mbox{\hspace{0.50em}}DataKit\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{2em}}finKit\mbox{\hspace{2em}}{\char `\=}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{⟨}\mbox{\hspace{0.50em}}\makebox[2.44ex][c]{$ \mathbb{{N}} $}\mbox{\hspace{0.50em}}{\char `\,}\mbox{\hspace{0.50em}}Fin\mbox{\hspace{0.50em}}{\char `\,}\mbox{\hspace{0.50em}}suc\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{⟩}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{2em}}}

\caption{\texttt{DataKit}s for the three previous approaches\label{kitsF}}
\end{figure}

%
%paragraphName: kits description
The three previous approaches are summed up in figure \ref{kitsF} by
    defining their  \texttt{DataKit}. Note  that for  the \texttt{bare}  approach the
    index type is the unit type. In the \texttt{Maybe} approach the index type
    is \texttt{Set} and the type for names is directly the index so we use the
    identity function.%


%
%paragraphName: generic Tm
We can now give a single  definition of \texttt{Tm} generalizing the three
    previous ones. To this end, we  simply take a \texttt{DataKit} as argument
    and use it to define the type \texttt{Tm}.%


%
%comment:
%  module DataTm {ℓ} (kit : DataKit {ℓ}) where
%    open DataKit kit
%    data Tm α : Set ℓ where
%      V    : (x : Name α)                → Tm α
%      _·_  : (t u : Tm α)                → Tm α
%      ƛ    : (t : Tm (α ↑1))             → Tm α
%      Let  : (t : Tm α) (u : Tm (α ↑1))  → Tm α
%
%


~\\~\texttt{\mbox{\hspace{1em}}module\mbox{\hspace{0.50em}}DataTm\mbox{\hspace{0.50em}}\{\makebox[1.22ex][c]{ℓ}\}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}kit\mbox{\hspace{0.50em}}{\char `\:}\mbox{\hspace{0.50em}}DataKit\mbox{\hspace{0.50em}}\{\makebox[1.22ex][c]{ℓ}\}\makebox[1.22ex][c]{$ {)} $}\mbox{\hspace{0.50em}}where\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{2em}}open\mbox{\hspace{0.50em}}DataKit\mbox{\hspace{0.50em}}kit\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{2em}}data\mbox{\hspace{0.50em}}Tm\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \alpha $}\mbox{\hspace{0.50em}}{\char `\:}\mbox{\hspace{0.50em}}Set\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{ℓ}\mbox{\hspace{0.50em}}where\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{3em}}V\mbox{\hspace{2em}}{\char `\:}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}x\mbox{\hspace{0.50em}}{\char `\:}\mbox{\hspace{0.50em}}Name\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \alpha $}\makebox[1.22ex][c]{$ {)} $}\mbox{\hspace{8em}}$ \rightarrow $\mbox{\hspace{0.50em}}Tm\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \alpha $}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{3em}}\makebox[1.22ex][c]{{\char `\_}}\makebox[1.22ex][c]{$ \cdotp $}\makebox[1.22ex][c]{{\char `\_}}\mbox{\hspace{1em}}{\char `\:}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}t\mbox{\hspace{0.50em}}u\mbox{\hspace{0.50em}}{\char `\:}\mbox{\hspace{0.50em}}Tm\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \alpha $}\makebox[1.22ex][c]{$ {)} $}\mbox{\hspace{8em}}$ \rightarrow $\mbox{\hspace{0.50em}}Tm\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \alpha $}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{3em}}\makebox[1.22ex][c]{ƛ}\mbox{\hspace{2em}}{\char `\:}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}t\mbox{\hspace{0.50em}}{\char `\:}\mbox{\hspace{0.50em}}Tm\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}\makebox[1.22ex][c]{$ \alpha $}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \uparrow $}1\makebox[1.22ex][c]{$ {)} $}\makebox[1.22ex][c]{$ {)} $}\mbox{\hspace{6.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}Tm\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \alpha $}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{3em}}Let\mbox{\hspace{1em}}{\char `\:}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}t\mbox{\hspace{0.50em}}{\char `\:}\mbox{\hspace{0.50em}}Tm\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \alpha $}\makebox[1.22ex][c]{$ {)} $}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}u\mbox{\hspace{0.50em}}{\char `\:}\mbox{\hspace{0.50em}}Tm\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}\makebox[1.22ex][c]{$ \alpha $}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \uparrow $}1\makebox[1.22ex][c]{$ {)} $}\makebox[1.22ex][c]{$ {)} $}\mbox{\hspace{1em}}$ \rightarrow $\mbox{\hspace{0.50em}}Tm\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \alpha $}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{1em}}}

%
%paragraphName: the kit is enough
We claim  that nothing  more is  required from  the kit.  As complex
    binding  structures   can  be  defined  in   the  original  nameless
    representation (\texttt{bare}), they can also be defined using this kit. In
    particular having an empty world or making an induction over a world
    is not necessary.%


%
%paragraphName: translations between kits
Translation  between data  types using  different kits  can be  done
    modularly as we do in the \textsc{Agda} development. In any direction (any
    pair of  kits \texttt{k₁}  \texttt{k₂}) one can  define a  function of
    type \texttt{$ \forall $}{ }\texttt{\{$ \alpha $₁}{ }\texttt{$ \alpha $₂\}}{ }\texttt{$ \rightarrow $}{ }\texttt{$ {(} $Name}{ }\texttt{k₁}{ }\texttt{$ \alpha $₁}{ }\texttt{$ \rightarrow $}{ }\texttt{Name}{ }\texttt{k₂}{ }\texttt{$ \alpha $₂$ {)} $}{ }\texttt{$ \rightarrow $}{ }\texttt{Tm}{ }\texttt{k₁}{ }\texttt{$ \alpha $₁}{ }\texttt{$ \rightarrow $}{ }\texttt{Tm}{ }\texttt{k₂}{ }\texttt{$ \alpha $₂}. This  function takes  a mapping for  free variables  and lifts
    this mapping to terms.%


%
%paragraphName: initial mapping
Whereas using these  translations is fine in many  cases, when going
    from \texttt{bare} to a more precise representation, an issue arises. Since
    \textsc{Agda} is  a total language,  the initial  mapping must be  a total
    function. The \texttt{bare} approach ensuring nothing about free variables,
    one cannot  supply the initial mapping  to go to a  closed term. One
    has to  keep at least one  free variable and then  dynamically check
    for occurrences of the free variable in a second transformation.%


%
%paragraphName: will build on DataKit
We will  now build on  this \texttt{DataKit} abstraction to  introduce our
    own solution.%


\subsection{\textsc{NaPa} types\label{napaTypesSection}}

\begin{figure}[]
%
%comment:
%    World   : Set
%    ø       : World
%    _+1     : World → World
%    _↑1     : World → World
%    Name    : World → Set
%    _⊆_    : World → World → Set
%
%    napaKit : DataKit
%    napaKit = ⟨ World , Name , _↑1 ⟩
%
%


~\\~\texttt{\mbox{\hspace{2em}}World\mbox{\hspace{1.50em}}{\char `\:}\mbox{\hspace{0.50em}}Set\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{2em}}\makebox[1.22ex][c]{$ \emptyset $}\mbox{\hspace{3.50em}}{\char `\:}\mbox{\hspace{0.50em}}World\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{2em}}\makebox[1.22ex][c]{{\char `\_}}{\char `\+}1\mbox{\hspace{2.50em}}{\char `\:}\mbox{\hspace{0.50em}}World\mbox{\hspace{0.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}World\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{2em}}\makebox[1.22ex][c]{{\char `\_}}\makebox[1.22ex][c]{$ \uparrow $}1\mbox{\hspace{2.50em}}{\char `\:}\mbox{\hspace{0.50em}}World\mbox{\hspace{0.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}World\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{2em}}Name\mbox{\hspace{2em}}{\char `\:}\mbox{\hspace{0.50em}}World\mbox{\hspace{0.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}Set\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{2em}}\makebox[1.22ex][c]{{\char `\_}}\makebox[2.44ex][c]{$ \subseteq $}\makebox[1.22ex][c]{{\char `\_}}\mbox{\hspace{2em}}{\char `\:}\mbox{\hspace{0.50em}}World\mbox{\hspace{0.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}World\mbox{\hspace{0.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}Set\vphantom{$\{$}{\nopagebreak[4] \newline%
}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{2em}}napaKit\mbox{\hspace{0.50em}}{\char `\:}\mbox{\hspace{0.50em}}DataKit\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{2em}}napaKit\mbox{\hspace{0.50em}}{\char `\=}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{⟨}\mbox{\hspace{0.50em}}World\mbox{\hspace{0.50em}}{\char `\,}\mbox{\hspace{0.50em}}Name\mbox{\hspace{0.50em}}{\char `\,}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{{\char `\_}}\makebox[1.22ex][c]{$ \uparrow $}1\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{⟩}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{2em}}}

\caption{Core types of \textsc{NaPa}\label{coreTypesF}}
\end{figure}

%
%paragraphName: NaPa types description
We call our approach \textsc{NaPa} as in \textbf{Na}meless, \textbf{Pa}inless. At the level
    of  types,  \textsc{NaPa}  exposes  the  interface  shown  in  figure  \ref{coreTypesF}.  This is  a superset  of the  \texttt{DataKit}, featuring  an
    empty world, a  \texttt{{\char `\_}{\char `\+}1} operation on worlds described later  on, and a
    notion of world inclusion.%


%
%paragraphName: too much info
If we look  closely at the notion of worlds  in the \texttt{Fin} approach,
    we see  that it  gives us  too much  information. Indeed  a function
    could look at the given world (by pattern-matching or induction) and
    behave differently for some values of the world.%


%
%paragraphName: too coarse
On the  other hand, \texttt{Fin}  worlds are  too coarse$:$ a  single number
    $ \mbox{ℓ} $ is  used to  represent a set,  namely the  complete interval
    $ \mbox{{[}}{0}{ }\mbox{.}\mbox{.}{ }\mbox{ℓ}\mbox{-}{1}\mbox{{]}} $.%


%
%paragraphName: NaPa worlds
In \textsc{NaPa}, a world denotes a subset of \texttt{$ \mathbb{{N}} $} but is kept abstract (no
    pattern-matching  nor  induction). Only  the  empty  world \texttt{$ \emptyset $}  and
    two  operations  are given,  namely  \texttt{{\char `\_}{\char `\+}1}  and \texttt{{\char `\_}$ \uparrow $1}.  Semantically
    $ \alpha\mbox{ }\mbox{+}{1} $  is  defined  by  $ \mbox{\{}{x}\mbox{ }\mbox{+}\mbox{ }{1}\mbox{ }\mbox{\textbar{}}\mbox{ }{x}\mbox{ }\in\mbox{ }\alpha\mbox{\}} $  and  $ \alpha\mbox{ }\uparrow{1} $  by
    $ \mbox{\{}{0}\mbox{\}}\mbox{ }\cup\mbox{ }\mbox{(}\alpha\mbox{ }\mbox{+}{1}\mbox{)} $.%


%
%paragraphName: Worlds as List Bool
Internally we  represent worlds by  lists of Boolean  values. Having
    \texttt{true} at  the $ {n} $\textsuperscript{th} position of  the list means that  $ {n} $ is in
    the world. Here are the \textsc{Agda} definitions$:$%


%
%comment:
%  World : Set
%  World = List Bool
%
%  ø : World
%  ø = []
%
%  _+1 : World → World
%  α +1 = false ∷ α
%
%  _↑1 : World → World
%  α ↑1 = true ∷ α
%
%


~\\~\texttt{\mbox{\hspace{1em}}World\mbox{\hspace{0.50em}}{\char `\:}\mbox{\hspace{0.50em}}Set\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{1em}}World\mbox{\hspace{0.50em}}{\char `\=}\mbox{\hspace{0.50em}}List\mbox{\hspace{0.50em}}Bool\vphantom{$\{$}{\nopagebreak[4] \newline%
}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{1em}}\makebox[1.22ex][c]{$ \emptyset $}\mbox{\hspace{0.50em}}{\char `\:}\mbox{\hspace{0.50em}}World\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{1em}}\makebox[1.22ex][c]{$ \emptyset $}\mbox{\hspace{0.50em}}{\char `\=}\mbox{\hspace{0.50em}}{\char `\[}{\char `\]}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{1em}}\makebox[1.22ex][c]{{\char `\_}}{\char `\+}1\mbox{\hspace{0.50em}}{\char `\:}\mbox{\hspace{0.50em}}World\mbox{\hspace{0.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}World\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{1em}}\makebox[1.22ex][c]{$ \alpha $}\mbox{\hspace{0.50em}}{\char `\+}1\mbox{\hspace{0.50em}}{\char `\=}\mbox{\hspace{0.50em}}false\mbox{\hspace{0.50em}}∷\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \alpha $}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{1em}}\makebox[1.22ex][c]{{\char `\_}}\makebox[1.22ex][c]{$ \uparrow $}1\mbox{\hspace{0.50em}}{\char `\:}\mbox{\hspace{0.50em}}World\mbox{\hspace{0.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}World\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{1em}}\makebox[1.22ex][c]{$ \alpha $}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \uparrow $}1\mbox{\hspace{0.50em}}{\char `\=}\mbox{\hspace{0.50em}}true\mbox{\hspace{0.50em}}∷\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \alpha $}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{1em}}}

%
%paragraphName: Generalizing ↑1 and +1
These  one  step  definitions  \texttt{{\char `\_}{\char `\+}1}   and  \texttt{{\char `\_}$ \uparrow $1}  are  extended  to
    any   number   to   produce   \texttt{{\char `\_}}\texttt{{\char `\+}ᵂ}\texttt{{\char `\_}}  and   \texttt{{\char `\_}}\texttt{$ \uparrow $}\texttt{{\char `\_}}   of   type
    \texttt{World $ \rightarrow $ $ \mathbb{{N}} $ $ \rightarrow $ World}.%


%
%paragraphName: _+1, _↑1 distinction is new
To the  best of  our knowledge, making  the distinction  between two
    forms of shifting operations for  worlds has never been investigated
    in the context of representing names and binders.%


%
%paragraphName: Name implem
In \textsc{NaPa} the type for names  is a refinement of \texttt{$ \mathbb{{N}} $}, kept abstract
    by  not  exporting  its  definition.  From  a  set  point  of  view,
    inhabitants of  \texttt{Name $ \alpha $} are members  of $ \alpha $. However  we want
    worlds to form static information only  and to be able to erase them
    before  running the  programs. To  do so  we will  use a  pair of  a
    natural number  and a  proof it  belongs to its  world. Here  is the
    membership predicate and the record definition for names$:$%


%
%comment:
%  _∈_ : ℕ → World → Set
%  _      ∈ []             = ⊥
%  zero   ∈ (false ∷ _)   = ⊥
%  zero   ∈ (true  ∷ _)   = ⊤
%  suc n  ∈ (_     ∷ xs)  = n ∈ xs
%
%  record Name α : Set where
%    constructor _,_
%    field
%      name    : ℕ
%      name∈α  : name ∈ α
%
%


~\\~\texttt{\mbox{\hspace{1em}}\makebox[1.22ex][c]{{\char `\_}}\makebox[1.22ex][c]{$ \in $}\makebox[1.22ex][c]{{\char `\_}}\mbox{\hspace{0.50em}}{\char `\:}\mbox{\hspace{0.50em}}\makebox[2.44ex][c]{$ \mathbb{{N}} $}\mbox{\hspace{0.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}World\mbox{\hspace{0.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}Set\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{1em}}\makebox[1.22ex][c]{{\char `\_}}\mbox{\hspace{3em}}\makebox[1.22ex][c]{$ \in $}\mbox{\hspace{0.50em}}{\char `\[}{\char `\]}\mbox{\hspace{6.50em}}{\char `\=}\mbox{\hspace{0.50em}}$ \bot $\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{1em}}zero\mbox{\hspace{1.50em}}\makebox[1.22ex][c]{$ \in $}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}false\mbox{\hspace{0.50em}}∷\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{{\char `\_}}\makebox[1.22ex][c]{$ {)} $}\mbox{\hspace{1.50em}}{\char `\=}\mbox{\hspace{0.50em}}$ \bot $\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{1em}}zero\mbox{\hspace{1.50em}}\makebox[1.22ex][c]{$ \in $}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}true\mbox{\hspace{1em}}∷\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{{\char `\_}}\makebox[1.22ex][c]{$ {)} $}\mbox{\hspace{1.50em}}{\char `\=}\mbox{\hspace{0.50em}}$ \top $\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{1em}}suc\mbox{\hspace{0.50em}}n\mbox{\hspace{1em}}\makebox[1.22ex][c]{$ \in $}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}\makebox[1.22ex][c]{{\char `\_}}\mbox{\hspace{2.50em}}∷\mbox{\hspace{0.50em}}xs\makebox[1.22ex][c]{$ {)} $}\mbox{\hspace{1em}}{\char `\=}\mbox{\hspace{0.50em}}n\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \in $}\mbox{\hspace{0.50em}}xs\vphantom{$\{$}{\nopagebreak[4] \newline%
}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{1em}}record\mbox{\hspace{0.50em}}Name\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \alpha $}\mbox{\hspace{0.50em}}{\char `\:}\mbox{\hspace{0.50em}}Set\mbox{\hspace{0.50em}}where\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{2em}}constructor\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{{\char `\_}}{\char `\,}\makebox[1.22ex][c]{{\char `\_}}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{2em}}field\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{3em}}name\mbox{\hspace{2em}}{\char `\:}\mbox{\hspace{0.50em}}\makebox[2.44ex][c]{$ \mathbb{{N}} $}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{3em}}name\makebox[1.22ex][c]{$ \in $}\makebox[1.22ex][c]{$ \alpha $}\mbox{\hspace{1em}}{\char `\:}\mbox{\hspace{0.50em}}name\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \in $}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \alpha $}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{1em}}}

%
%paragraphName: proof-irrelevance
Thanks to  our definition  of world  membership which  is canonical,
    equality of the \texttt{name} field implies equality on whole \texttt{Name}    values. This means we get provable proof-irrelevance for the \texttt{Name}    type without requiring an additional axiom.%


\subsection{Operations on names}

\begin{figure}[]
%
%comment:
%    zeroᴺ     : ∀ {α}    → Name (α ↑1)
%    addᴺ      : ∀ {α} k  → Name α
%                         → Name (α +ᵂ k)
%    subtractᴺ : ∀ {α} k  → Name (α +ᵂ k)
%                         → Name α
%    cmpᴺ      : ∀ {α} ℓ  → Name (α ↑  ℓ)
%                         → Name (ø ↑  ℓ)
%                         ⊎ Name (α +ᵂ ℓ)
%    _==ᴺ_     : ∀ {α} (x y : Name α) → Bool
%    coerceᴺ   : ∀ {α β}  → α ⊆ β
%                         → Name α  → Name β
%    ¬Nameø   : ¬(Name ø)
%
%    syntax addᴺ      k x = x +ᴺ k
%    syntax subtractᴺ k x = x ∸ᴺ k
%    syntax cmpᴺ      ℓ x = x <ᴺ ℓ
%
%


~\\~\texttt{\mbox{\hspace{2em}}zero\makebox[0.61ex][c]{ᴺ}\mbox{\hspace{2.50em}}{\char `\:}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \forall $}\mbox{\hspace{0.50em}}\{\makebox[1.22ex][c]{$ \alpha $}\}\mbox{\hspace{1.50em}}\makebox[0.61ex][c]{ }\mbox{\hspace{0.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}Name\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}\makebox[1.22ex][c]{$ \alpha $}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \uparrow $}1\makebox[1.22ex][c]{$ {)} $}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{2em}}add\makebox[0.61ex][c]{ᴺ}\mbox{\hspace{3em}}{\char `\:}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \forall $}\mbox{\hspace{0.50em}}\{\makebox[1.22ex][c]{$ \alpha $}\}\mbox{\hspace{0.50em}}k\mbox{\hspace{0.50em}}\makebox[0.61ex][c]{ }\mbox{\hspace{0.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}Name\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \alpha $}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{12.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}Name\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}\makebox[1.22ex][c]{$ \alpha $}\mbox{\hspace{0.50em}}{\char `\+}\makebox[0.61ex][c]{ᵂ}\mbox{\hspace{0.50em}}k\makebox[1.22ex][c]{$ {)} $}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{2em}}subtract\makebox[0.61ex][c]{ᴺ}\mbox{\hspace{0.50em}}{\char `\:}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \forall $}\mbox{\hspace{0.50em}}\{\makebox[1.22ex][c]{$ \alpha $}\}\mbox{\hspace{0.50em}}k\mbox{\hspace{0.50em}}\makebox[0.61ex][c]{ }\mbox{\hspace{0.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}Name\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}\makebox[1.22ex][c]{$ \alpha $}\mbox{\hspace{0.50em}}{\char `\+}\makebox[0.61ex][c]{ᵂ}\mbox{\hspace{0.50em}}k\makebox[1.22ex][c]{$ {)} $}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{12.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}Name\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \alpha $}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{2em}}cmp\makebox[0.61ex][c]{ᴺ}\mbox{\hspace{3em}}{\char `\:}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \forall $}\mbox{\hspace{0.50em}}\{\makebox[1.22ex][c]{$ \alpha $}\}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{ℓ}\mbox{\hspace{0.50em}}\makebox[0.61ex][c]{ }\mbox{\hspace{0.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}Name\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}\makebox[1.22ex][c]{$ \alpha $}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \uparrow $}\mbox{\hspace{1em}}\makebox[1.22ex][c]{ℓ}\makebox[1.22ex][c]{$ {)} $}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{12.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}Name\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}\makebox[1.22ex][c]{$ \emptyset $}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \uparrow $}\mbox{\hspace{1em}}\makebox[1.22ex][c]{ℓ}\makebox[1.22ex][c]{$ {)} $}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{12.50em}}\makebox[2.44ex][c]{⊎}\mbox{\hspace{0.50em}}Name\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}\makebox[1.22ex][c]{$ \alpha $}\mbox{\hspace{0.50em}}{\char `\+}\makebox[0.61ex][c]{ᵂ}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{ℓ}\makebox[1.22ex][c]{$ {)} $}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{2em}}\makebox[1.22ex][c]{{\char `\_}}{\char `\=}{\char `\=}\makebox[0.61ex][c]{ᴺ}\makebox[1.22ex][c]{{\char `\_}}\mbox{\hspace{2.50em}}{\char `\:}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \forall $}\mbox{\hspace{0.50em}}\{\makebox[1.22ex][c]{$ \alpha $}\}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}x\mbox{\hspace{0.50em}}y\mbox{\hspace{0.50em}}{\char `\:}\mbox{\hspace{0.50em}}Name\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \alpha $}\makebox[1.22ex][c]{$ {)} $}\mbox{\hspace{0.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}Bool\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{2em}}coerce\makebox[0.61ex][c]{ᴺ}\mbox{\hspace{1.50em}}{\char `\:}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \forall $}\mbox{\hspace{0.50em}}\{\makebox[1.22ex][c]{$ \alpha $}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \beta $}\}\mbox{\hspace{0.50em}}\makebox[0.61ex][c]{ }\mbox{\hspace{0.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \alpha $}\mbox{\hspace{0.50em}}\makebox[2.44ex][c]{$ \subseteq $}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \beta $}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{12.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}Name\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \alpha $}\mbox{\hspace{1em}}$ \rightarrow $\mbox{\hspace{0.50em}}Name\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \beta $}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{2em}}\makebox[2.44ex][c]{$ \neg $}Name\makebox[1.22ex][c]{$ \emptyset $}\mbox{\hspace{1.50em}}{\char `\:}\mbox{\hspace{0.50em}}\makebox[2.44ex][c]{$ \neg $}\makebox[1.22ex][c]{$ {(} $}Name\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \emptyset $}\makebox[1.22ex][c]{$ {)} $}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{2em}}syntax\mbox{\hspace{0.50em}}add\makebox[0.61ex][c]{ᴺ}\mbox{\hspace{3em}}k\mbox{\hspace{0.50em}}x\mbox{\hspace{0.50em}}{\char `\=}\mbox{\hspace{0.50em}}x\mbox{\hspace{0.50em}}{\char `\+}\makebox[0.61ex][c]{ᴺ}\mbox{\hspace{0.50em}}k\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{2em}}syntax\mbox{\hspace{0.50em}}subtract\makebox[0.61ex][c]{ᴺ}\mbox{\hspace{0.50em}}k\mbox{\hspace{0.50em}}x\mbox{\hspace{0.50em}}{\char `\=}\mbox{\hspace{0.50em}}x\mbox{\hspace{0.50em}}∸\makebox[0.61ex][c]{ᴺ}\mbox{\hspace{0.50em}}k\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{2em}}syntax\mbox{\hspace{0.50em}}cmp\makebox[0.61ex][c]{ᴺ}\mbox{\hspace{3em}}\makebox[1.22ex][c]{ℓ}\mbox{\hspace{0.50em}}x\mbox{\hspace{0.50em}}{\char `\=}\mbox{\hspace{0.50em}}x\mbox{\hspace{0.50em}}{\char `\<}\makebox[0.61ex][c]{ᴺ}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{ℓ}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{2em}}}

\caption{Core operations on names\label{opsfig}}
\end{figure}

%
%paragraphName: core operations descriptions
The core operations  on names are given in figure  \ref{opsfig}. The
    simplest name  is \texttt{zeroᴺ}, it  represents 0  and lives in  any world
    shifted by one. One can add any constant to a name in any world with
    \texttt{addᴺ}, the  resulting world  clearly shows  that this  function (if
    parametric in  $ \alpha $) does exactly  its job.  One can do  the opposite
    operation with \texttt{subtractᴺ}. Thanks to its precise type this function
    is total and the inverse of  \texttt{addᴺ}. Figure \ref{opsdiag} depict the
    core operations we  have on names. Starting from  the bottom, worlds
    of  the form  \texttt{$ \emptyset $ $ \uparrow $ k} are  names which  are definitely  bound.
    There  value  is completely  known  as  stated  by arrows  with  the
    \texttt{Fin k}  type. Above we have  names that may be  bound or free
    (\texttt{Name $ {(} $$ \alpha $ $ \uparrow $ k$ {)} $}), a dynamic  test (\texttt{cmpᴺ}) can tell whether it
    is bound or  not. Above we have  names that are known  to be greater
    than  \texttt{k} (\texttt{Name $ {(} $$ \alpha $ {\char `\+}ᵂ k$ {)} $}),  apart from  that they  are
    free names. Above we have free names (\texttt{Name $ \alpha $}). On the top we
    have impossible  names since  they are  said to  belong to  an empty
    world. From them we can derive everything.%


%
%paragraphName: the comparison function
Given  any  world  $ \alpha $,  a   name  in  the  world  \texttt{$ \alpha $ $ \uparrow $ ℓ}  is
    either  strictly  lower  than  \texttt{ℓ}   (and  so  also  lives  in
    \texttt{$ \emptyset $ $ \uparrow $ ℓ}), or greater or equal to \texttt{ℓ} (thus also lives in
    \texttt{$ \alpha $ {\char `\+}ᵂ ℓ}). This is exactly what  the \texttt{cmpᴺ} function is about.
    Given a name, it  returns a disjoint sum of names  which can be read
    in  two parts.  It first  gives which  side of  the disjoint  sum it
    stands, and second it gives a refined version of the input name.%


%
%paragraphName: coerceᴺ, ==ᴺ, and ¬Nameø
The  \texttt{coerceᴺ} function  will be  described  in length  in the  next
    sub-section. The only way left to extract information from a name in
    an arbitrary world  is to compare it with another  name for equality
    with \texttt{{\char `\_}}\texttt{{\char `\=}{\char `\=}ᴺ}\texttt{{\char `\_}}. Finally \texttt{$ \neg $Name$ \emptyset $} asserts  that no name lives  in the
    empty world.  In a  total language  this is of  great use  to tackle
    impossible cases.%


\begin{figure}[]
\begin{tikzpicture}
\matrix (m) [matrix of math nodes, row sep=1em, column sep=1em, text height=1.5ex, text depth=0.25ex] { \texttt{Name $ {(} $$ \emptyset $ {\char `\+}ᵂ k$ {)} $} &  &  \\  &  &  \\ \texttt{Name $ \emptyset $} &  &  \\  &  &  \\ \texttt{Name $ \alpha $} &  &  \\  &  &  \\ \texttt{Name $ {(} $$ \alpha $ {\char `\+}ᵂ k$ {)} $} &  &  \\  &  &  \\ \texttt{Name $ {(} $$ \alpha $ $ \uparrow $ k$ {)} $} &  & \texttt{cmpᴺ} \\  &  &  \\ \texttt{Name $ {(} $$ \emptyset $ $ \uparrow $ k$ {)} $} &  & \texttt{Fin k} \\  };\path[->](m-1-1) edgenode[left]{\texttt{coerceᴺ {\char `\_}}}(m-3-1);\path[->](m-3-1) edgenode[left]{\texttt{$ \neg $Name$ \emptyset $ $ \circ $ coerceᴺ {\char `\_}}}(m-5-1);\path[->](m-5-1) edgenode[left]{\texttt{addᴺ k}}(m-7-1);\path[->](m-7-1) edgenode[right]{\texttt{subtractᴺ k}}(m-5-1);\path[->](m-9-1) edgenode[left]{}(m-9-3);\path[->](m-7-1) edgenode[left]{\texttt{coerceᴺ {\char `\_}}}(m-9-1);\path[->](m-9-3) edgenode[right]{ (\textit{if} \texttt{$ \geq $k})}(m-7-1);\path[<-](m-9-1) edgenode[left]{\texttt{coerceᴺ {\char `\_}}}(m-11-1);\path[->](m-9-3) edgenode[right]{ (\textit{if} \texttt{{\char `\<}k})}(m-11-1);\path[<->](m-11-1) edgenode[left]{}(m-11-3);
\end{tikzpicture}

\caption{Operations on names\label{opsdiag}}
\end{figure}

%
%paragraphName: NaPa vs Fin
These  primitives   are  enough  to  show   an  isomorphism  between
    \texttt{Fin n}  and \texttt{Name $ {(} $$ \emptyset $ $ \uparrow $ n$ {)} $}.  From  this, every  program
    involving  \texttt{Fin} can  be  translated into  our  system. This  means
    that  our system  does not  restrict  the programmer  more than  the
    \texttt{Fin}  approach. However  as  soon  as one  uses  finer types  than
    \texttt{Name $ {(} $$ \emptyset $ $ \uparrow $ n$ {)} $}, then  fewer ``wrong programs''  type-check and
    more properties hold as we will see later.%


\subsection{A type for world inclusion witnesses}

%
%paragraphName: why _⊆_ and coerceᴺ
Having finer types also implies being able to give more types to the
    same value. Then  cheaply moving from different types is  a must. We
    call a  function which has an  output type different from  the input
    type and behaves as the identity a coercion. To capture a great deal
    of coercions from  a world $ \alpha $ to  a world $ \beta $ we focus  on the case
    where  $ \alpha $  is included  in  $ \beta $.  In \textsc{NaPa}  a  type  \texttt{{\char `\_}}\texttt{$ \subseteq $}\texttt{{\char `\_}}  is
    introduced to  witness the  inclusion between  two worlds.  Then the
    \texttt{coerceᴺ} function turns a \texttt{ $ \alpha $ $ \subseteq $ $ \beta $ } into an identity function
    of type \texttt{Name $ \alpha $ $ \rightarrow $ Name $ \beta $}. Here  is the \texttt{coerceᴺ} function and
    its alias \texttt{{\char `\_}⟨{\char `\-}because{\char `\_}{\char `\-}⟩} which is useful  to keep the code separated from
    the typing/proof, in  particular what is between  the angle brackets
    can be safely skipped.%


%
%comment:
%coerceᴺ : ∀ {α β} → α ⊆ β → Name α → Name β
%coerceᴺ α⊆β (x , x∈α) = (x , ⊆-sound α⊆β x x∈α)
%
%infix 0 _⟨-because_-⟩
%_⟨-because_-⟩ : ∀{α β}→ Name α → α ⊆ β → Name β
%_⟨-because_-⟩ n pf = coerceᴺ pf n
%
%


~\\~\texttt{coerce\makebox[0.61ex][c]{ᴺ}\mbox{\hspace{0.50em}}{\char `\:}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \forall $}\mbox{\hspace{0.50em}}\{\makebox[1.22ex][c]{$ \alpha $}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \beta $}\}\mbox{\hspace{0.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \alpha $}\mbox{\hspace{0.50em}}\makebox[2.44ex][c]{$ \subseteq $}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \beta $}\mbox{\hspace{0.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}Name\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \alpha $}\mbox{\hspace{0.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}Name\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \beta $}\vphantom{$\{$}{\nopagebreak[4] \newline%
}coerce\makebox[0.61ex][c]{ᴺ}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \alpha $}\makebox[2.44ex][c]{$ \subseteq $}\makebox[1.22ex][c]{$ \beta $}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}x\mbox{\hspace{0.50em}}{\char `\,}\mbox{\hspace{0.50em}}x\makebox[1.22ex][c]{$ \in $}\makebox[1.22ex][c]{$ \alpha $}\makebox[1.22ex][c]{$ {)} $}\mbox{\hspace{0.50em}}{\char `\=}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}x\mbox{\hspace{0.50em}}{\char `\,}\mbox{\hspace{0.50em}}\makebox[2.44ex][c]{$ \subseteq $}{\char `\-}sound\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \alpha $}\makebox[2.44ex][c]{$ \subseteq $}\makebox[1.22ex][c]{$ \beta $}\mbox{\hspace{0.50em}}x\mbox{\hspace{0.50em}}x\makebox[1.22ex][c]{$ \in $}\makebox[1.22ex][c]{$ \alpha $}\makebox[1.22ex][c]{$ {)} $}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\vphantom{$\{$}{\nopagebreak[4] \newline%
}infix\mbox{\hspace{0.50em}}0\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{{\char `\_}}\makebox[1.22ex][c]{⟨}{\char `\-}because\makebox[1.22ex][c]{{\char `\_}}{\char `\-}\makebox[1.22ex][c]{⟩}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\makebox[1.22ex][c]{{\char `\_}}\makebox[1.22ex][c]{⟨}{\char `\-}because\makebox[1.22ex][c]{{\char `\_}}{\char `\-}\makebox[1.22ex][c]{⟩}\mbox{\hspace{0.50em}}{\char `\:}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \forall $}\{\makebox[1.22ex][c]{$ \alpha $}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \beta $}\}$ \rightarrow $\mbox{\hspace{0.50em}}Name\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \alpha $}\mbox{\hspace{0.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \alpha $}\mbox{\hspace{0.50em}}\makebox[2.44ex][c]{$ \subseteq $}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \beta $}\mbox{\hspace{0.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}Name\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \beta $}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\makebox[1.22ex][c]{{\char `\_}}\makebox[1.22ex][c]{⟨}{\char `\-}because\makebox[1.22ex][c]{{\char `\_}}{\char `\-}\makebox[1.22ex][c]{⟩}\mbox{\hspace{0.50em}}n\mbox{\hspace{0.50em}}pf\mbox{\hspace{0.50em}}{\char `\=}\mbox{\hspace{0.50em}}coerce\makebox[0.61ex][c]{ᴺ}\mbox{\hspace{0.50em}}pf\mbox{\hspace{0.50em}}n\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{1em}}}

%
%paragraphName: on emptiness and (⊆ ø)
The inclusion relation  also expresses the emptiness of  a world $ \alpha $    by  using \texttt{$ \alpha $ $ \subseteq $ $ \emptyset $}.  We  use this  definition  of emptiness  as
    opposed to an  equality with the empty world for  two reasons. First
    \texttt{$ \emptyset $} is  not the only empty  world (\texttt{$ \emptyset $ {\char `\+}1} is empty  as well).
    Second  having world  equalities would  require new  definitions and
    would be  heavy in  comparison to the  use of  inclusions. Combining
    \texttt{coerceᴺ}  and \texttt{$ \neg $Name$ \emptyset $}  turns any  contradiction on  names into  an
    inclusion problem, reusing any automation done on this side.%


%
%comment:
%  ¬Name : ∀ {α} → α ⊆ ø → ¬(Name α)
%  ¬Name α⊆ø = ¬Nameø ∘ coerceᴺ α⊆ø
%
%


~\\~\texttt{\mbox{\hspace{1em}}\makebox[2.44ex][c]{$ \neg $}Name\mbox{\hspace{0.50em}}{\char `\:}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \forall $}\mbox{\hspace{0.50em}}\{\makebox[1.22ex][c]{$ \alpha $}\}\mbox{\hspace{0.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \alpha $}\mbox{\hspace{0.50em}}\makebox[2.44ex][c]{$ \subseteq $}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \emptyset $}\mbox{\hspace{0.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}\makebox[2.44ex][c]{$ \neg $}\makebox[1.22ex][c]{$ {(} $}Name\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \alpha $}\makebox[1.22ex][c]{$ {)} $}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{1em}}\makebox[2.44ex][c]{$ \neg $}Name\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \alpha $}\makebox[2.44ex][c]{$ \subseteq $}\makebox[1.22ex][c]{$ \emptyset $}\mbox{\hspace{0.50em}}{\char `\=}\mbox{\hspace{0.50em}}\makebox[2.44ex][c]{$ \neg $}Name\makebox[1.22ex][c]{$ \emptyset $}\mbox{\hspace{0.50em}}$ \circ $\mbox{\hspace{0.50em}}coerce\makebox[0.61ex][c]{ᴺ}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \alpha $}\makebox[2.44ex][c]{$ \subseteq $}\makebox[1.22ex][c]{$ \emptyset $}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{1em}}}

\begin{figure}[]
%
%comment:
%⊆-refl  : ∀{α}→ α ⊆ α
%
%⊆-trans : ∀{α β γ}→ α ⊆ β → β ⊆ γ → α ⊆ γ
%
%⊆-ø     : ∀{α}→ ø ⊆ α
%
%⊆-ø+1   : ø +1 ⊆ ø
%
%⊆-↑1-↑1 : ∀{α β}→ α ⊆ β ↔ α ↑1 ⊆ β ↑1
%
%⊆-+1-+1 : ∀{α β}→ α ⊆ β ↔ α +1 ⊆ β +1
%
%⊆-+1-↑1 : ∀{α}→ α +1 ⊆ α ↑1
%
%


~\\~\texttt{\makebox[2.44ex][c]{$ \subseteq $}{\char `\-}refl\mbox{\hspace{1em}}{\char `\:}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \forall $}\{\makebox[1.22ex][c]{$ \alpha $}\}$ \rightarrow $\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \alpha $}\mbox{\hspace{0.50em}}\makebox[2.44ex][c]{$ \subseteq $}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \alpha $}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\makebox[2.44ex][c]{$ \subseteq $}{\char `\-}trans\mbox{\hspace{0.50em}}{\char `\:}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \forall $}\{\makebox[1.22ex][c]{$ \alpha $}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \beta $}\mbox{\hspace{0.50em}}$ \gamma $\}$ \rightarrow $\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \alpha $}\mbox{\hspace{0.50em}}\makebox[2.44ex][c]{$ \subseteq $}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \beta $}\mbox{\hspace{0.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \beta $}\mbox{\hspace{0.50em}}\makebox[2.44ex][c]{$ \subseteq $}\mbox{\hspace{0.50em}}$ \gamma $\mbox{\hspace{0.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \alpha $}\mbox{\hspace{0.50em}}\makebox[2.44ex][c]{$ \subseteq $}\mbox{\hspace{0.50em}}$ \gamma $\vphantom{$\{$}{\nopagebreak[4] \newline%
}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\makebox[2.44ex][c]{$ \subseteq $}{\char `\-}\makebox[1.22ex][c]{$ \emptyset $}\mbox{\hspace{2.50em}}{\char `\:}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \forall $}\{\makebox[1.22ex][c]{$ \alpha $}\}$ \rightarrow $\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \emptyset $}\mbox{\hspace{0.50em}}\makebox[2.44ex][c]{$ \subseteq $}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \alpha $}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\makebox[2.44ex][c]{$ \subseteq $}{\char `\-}\makebox[1.22ex][c]{$ \emptyset $}{\char `\+}1\mbox{\hspace{1.50em}}{\char `\:}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \emptyset $}\mbox{\hspace{0.50em}}{\char `\+}1\mbox{\hspace{0.50em}}\makebox[2.44ex][c]{$ \subseteq $}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \emptyset $}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\makebox[2.44ex][c]{$ \subseteq $}{\char `\-}\makebox[1.22ex][c]{$ \uparrow $}1{\char `\-}\makebox[1.22ex][c]{$ \uparrow $}1\mbox{\hspace{0.50em}}{\char `\:}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \forall $}\{\makebox[1.22ex][c]{$ \alpha $}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \beta $}\}$ \rightarrow $\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \alpha $}\mbox{\hspace{0.50em}}\makebox[2.44ex][c]{$ \subseteq $}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \beta $}\mbox{\hspace{0.50em}}$ \leftrightarrow $\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \alpha $}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \uparrow $}1\mbox{\hspace{0.50em}}\makebox[2.44ex][c]{$ \subseteq $}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \beta $}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \uparrow $}1\vphantom{$\{$}{\nopagebreak[4] \newline%
}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\makebox[2.44ex][c]{$ \subseteq $}{\char `\-}{\char `\+}1{\char `\-}{\char `\+}1\mbox{\hspace{0.50em}}{\char `\:}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \forall $}\{\makebox[1.22ex][c]{$ \alpha $}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \beta $}\}$ \rightarrow $\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \alpha $}\mbox{\hspace{0.50em}}\makebox[2.44ex][c]{$ \subseteq $}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \beta $}\mbox{\hspace{0.50em}}$ \leftrightarrow $\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \alpha $}\mbox{\hspace{0.50em}}{\char `\+}1\mbox{\hspace{0.50em}}\makebox[2.44ex][c]{$ \subseteq $}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \beta $}\mbox{\hspace{0.50em}}{\char `\+}1\vphantom{$\{$}{\nopagebreak[4] \newline%
}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\makebox[2.44ex][c]{$ \subseteq $}{\char `\-}{\char `\+}1{\char `\-}\makebox[1.22ex][c]{$ \uparrow $}1\mbox{\hspace{0.50em}}{\char `\:}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \forall $}\{\makebox[1.22ex][c]{$ \alpha $}\}$ \rightarrow $\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \alpha $}\mbox{\hspace{0.50em}}{\char `\+}1\mbox{\hspace{0.50em}}\makebox[2.44ex][c]{$ \subseteq $}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \alpha $}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \uparrow $}1\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{2em}}}

\caption{Rules for world inclusion\label{subfig}}
\end{figure}

%
%paragraphName: ⊆ rules
We  expose the  inclusion  relation with  a set  of  rules given  in
    figure  \ref{subfig}.  This states  that the  inclusion relation  is
    reflexive, transitive,  and has the  empty world as  lowest element.
    The  \texttt{$ \subseteq ${\char `\-}$ \emptyset ${\char `\+}1}  rule  states  that \texttt{$ \emptyset $ {\char `\+}1}  is  empty.  The
    inclusion is  preserved both ways  by the contexts \texttt{{\char `\_}$ \uparrow $1}  and \texttt{{\char `\_}{\char `\+}1}.
    Finally  \texttt{{\char `\_}{\char `\+}1} can  be  weakened  in \texttt{{\char `\_}$ \uparrow $1}.  This  accounts for  the
    fact  that  \texttt{$ \alpha $ $ \uparrow $1}  means  \texttt{\{0\} $ \cup $ $ {(} $$ \alpha $ {\char `\+}1$ {)} $}  and  so  is
    a  superset  of \texttt{$ \alpha $ {\char `\+}1}.  This  set  of  rules has  been  shown
    sound  according  to  a  semantic definition  of  inclusion,  namely
    \texttt{$ \forall $ x $ \rightarrow $ x $ \in $ $ \alpha $ $ \rightarrow $ x $ \in $ $ \beta $}. On top of  these base rules, we derived
    others that we omit to define here but some are used in the code.%


%
%paragraphName: ⊆-Reasoning
Sometimes  one  has  to  build complex  inclusion  witnesses.  While
    inference  would  be of  great  effect  here,  we propose  a  modest
    syntactic tool to build them, namely the \texttt{$ \subseteq ${\char `\-}Reasoning} module.
    It gives access to the transitivity \texttt{$ \subseteq ${\char `\-}trans} in a style which
    focuses more on the intermediate states of the reasoning rather than
    the steps. The  syntax is a list of worlds  interleaved by inclusion
    witnesses,  with  two \texttt{∎}  around  the  last world.  There  is
    one  example of  its  use in  the following  section.  The code  for
    \texttt{$ \subseteq ${\char `\-}Reasoning} is given  below for reference and  can be safely
    skipped.%


%
%comment:
%module ⊆-Reasoning where
%  infix  2 finally
%  infixr 2 _⊆⟨_⟩_
%
%  _⊆⟨_⟩_ : ∀ x {y z} → x ⊆ y → y ⊆ z → x ⊆ z
%  _ ⊆⟨ x⊆y ⟩ y⊆z = ⊆-trans x⊆y y⊆z
%
%  finally : ∀ x y → x ⊆ y → x ⊆ y
%  finally _ _ x⊆y = x⊆y
%
%  syntax finally x y x⊆y = x ⊆⟨ x⊆y ⟩∎ y ∎
%
%


~\\~\texttt{module\mbox{\hspace{0.50em}}\makebox[2.44ex][c]{$ \subseteq $}{\char `\-}Reasoning\mbox{\hspace{0.50em}}where\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{1em}}infix\mbox{\hspace{1em}}2\mbox{\hspace{0.50em}}finally\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{1em}}infixr\mbox{\hspace{0.50em}}2\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{{\char `\_}}\makebox[2.44ex][c]{$ \subseteq $}\makebox[1.22ex][c]{⟨}\makebox[1.22ex][c]{{\char `\_}}\makebox[1.22ex][c]{⟩}\makebox[1.22ex][c]{{\char `\_}}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{1em}}\makebox[1.22ex][c]{{\char `\_}}\makebox[2.44ex][c]{$ \subseteq $}\makebox[1.22ex][c]{⟨}\makebox[1.22ex][c]{{\char `\_}}\makebox[1.22ex][c]{⟩}\makebox[1.22ex][c]{{\char `\_}}\mbox{\hspace{0.50em}}{\char `\:}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \forall $}\mbox{\hspace{0.50em}}x\mbox{\hspace{0.50em}}\{y\mbox{\hspace{0.50em}}z\}\mbox{\hspace{0.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}x\mbox{\hspace{0.50em}}\makebox[2.44ex][c]{$ \subseteq $}\mbox{\hspace{0.50em}}y\mbox{\hspace{0.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}y\mbox{\hspace{0.50em}}\makebox[2.44ex][c]{$ \subseteq $}\mbox{\hspace{0.50em}}z\mbox{\hspace{0.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}x\mbox{\hspace{0.50em}}\makebox[2.44ex][c]{$ \subseteq $}\mbox{\hspace{0.50em}}z\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{1em}}\makebox[1.22ex][c]{{\char `\_}}\mbox{\hspace{0.50em}}\makebox[2.44ex][c]{$ \subseteq $}\makebox[1.22ex][c]{⟨}\mbox{\hspace{0.50em}}x\makebox[2.44ex][c]{$ \subseteq $}y\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{⟩}\mbox{\hspace{0.50em}}y\makebox[2.44ex][c]{$ \subseteq $}z\mbox{\hspace{0.50em}}{\char `\=}\mbox{\hspace{0.50em}}\makebox[2.44ex][c]{$ \subseteq $}{\char `\-}trans\mbox{\hspace{0.50em}}x\makebox[2.44ex][c]{$ \subseteq $}y\mbox{\hspace{0.50em}}y\makebox[2.44ex][c]{$ \subseteq $}z\vphantom{$\{$}{\nopagebreak[4] \newline%
}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{1em}}finally\mbox{\hspace{0.50em}}{\char `\:}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \forall $}\mbox{\hspace{0.50em}}x\mbox{\hspace{0.50em}}y\mbox{\hspace{0.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}x\mbox{\hspace{0.50em}}\makebox[2.44ex][c]{$ \subseteq $}\mbox{\hspace{0.50em}}y\mbox{\hspace{0.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}x\mbox{\hspace{0.50em}}\makebox[2.44ex][c]{$ \subseteq $}\mbox{\hspace{0.50em}}y\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{1em}}finally\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{{\char `\_}}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{{\char `\_}}\mbox{\hspace{0.50em}}x\makebox[2.44ex][c]{$ \subseteq $}y\mbox{\hspace{0.50em}}{\char `\=}\mbox{\hspace{0.50em}}x\makebox[2.44ex][c]{$ \subseteq $}y\vphantom{$\{$}{\nopagebreak[4] \newline%
}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{1em}}syntax\mbox{\hspace{0.50em}}finally\mbox{\hspace{0.50em}}x\mbox{\hspace{0.50em}}y\mbox{\hspace{0.50em}}x\makebox[2.44ex][c]{$ \subseteq $}y\mbox{\hspace{0.50em}}{\char `\=}\mbox{\hspace{0.50em}}x\mbox{\hspace{0.50em}}\makebox[2.44ex][c]{$ \subseteq $}\makebox[1.22ex][c]{⟨}\mbox{\hspace{0.50em}}x\makebox[2.44ex][c]{$ \subseteq $}y\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{⟩}∎\mbox{\hspace{0.50em}}y\mbox{\hspace{0.50em}}∎\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{1em}}}

\subsection{Singleton worlds!}

%
%paragraphName: singletons worlds
We said that  our worlds denote finite subsets of  \texttt{$ \mathbb{{N}} $} and are more
    precise than in the \texttt{Fin} approach. Actually they can be as precise
    as  we wish,  since  any subset  of  \texttt{$ \mathbb{{N}} $} can  be  described by  our
    operations on  worlds (\texttt{$ \emptyset $}, \texttt{{\char `\_}{\char `\+}1},  and \texttt{{\char `\_}$ \uparrow $1}). In  particular they
    can be  singleton worlds. From  singleton worlds we  build singleton
    types for names$:$%


%
%comment:
%  Worldˢ : ℕ → World
%  Worldˢ n = ø ↑1 +ᵂ n
%
%  Nameˢ : ℕ → Set
%  Nameˢ = Name ∘ Worldˢ
%
%  _ˢ : ∀ n → Nameˢ n
%  _ˢ n = zeroᴺ +ᴺ n
%
%


~\\~\texttt{\mbox{\hspace{1em}}World\makebox[0.61ex][c]{ˢ}\mbox{\hspace{0.50em}}{\char `\:}\mbox{\hspace{0.50em}}\makebox[2.44ex][c]{$ \mathbb{{N}} $}\mbox{\hspace{0.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}World\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{1em}}World\makebox[0.61ex][c]{ˢ}\mbox{\hspace{0.50em}}n\mbox{\hspace{0.50em}}{\char `\=}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \emptyset $}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \uparrow $}1\mbox{\hspace{0.50em}}{\char `\+}\makebox[0.61ex][c]{ᵂ}\mbox{\hspace{0.50em}}n\vphantom{$\{$}{\nopagebreak[4] \newline%
}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{1em}}Name\makebox[0.61ex][c]{ˢ}\mbox{\hspace{0.50em}}{\char `\:}\mbox{\hspace{0.50em}}\makebox[2.44ex][c]{$ \mathbb{{N}} $}\mbox{\hspace{0.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}Set\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{1em}}Name\makebox[0.61ex][c]{ˢ}\mbox{\hspace{0.50em}}{\char `\=}\mbox{\hspace{0.50em}}Name\mbox{\hspace{0.50em}}$ \circ $\mbox{\hspace{0.50em}}World\makebox[0.61ex][c]{ˢ}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{1em}}\makebox[1.22ex][c]{{\char `\_}}\makebox[0.61ex][c]{ˢ}\mbox{\hspace{0.50em}}{\char `\:}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \forall $}\mbox{\hspace{0.50em}}n\mbox{\hspace{0.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}Name\makebox[0.61ex][c]{ˢ}\mbox{\hspace{0.50em}}n\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{1em}}\makebox[1.22ex][c]{{\char `\_}}\makebox[0.61ex][c]{ˢ}\mbox{\hspace{0.50em}}n\mbox{\hspace{0.50em}}{\char `\=}\mbox{\hspace{0.50em}}zero\makebox[0.61ex][c]{ᴺ}\mbox{\hspace{0.50em}}{\char `\+}\makebox[0.61ex][c]{ᴺ}\mbox{\hspace{0.50em}}n\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{1em}}}

%
%paragraphName: addᴺ & subtractᴺ
Singleton worlds not only exist, they  are also preserved by our two
    updating operations, namely \texttt{addᴺ} and \texttt{subtractᴺ}.%


%
%comment:
%addˢ : ∀ {n} k → Nameˢ n → Nameˢ (k +ℕ n)
%addˢ {n} k x = addᴺ k x
%  ⟨-because ⊆-assoc-+ ⊆-refl n k −⟩
%
%subtractˢ : ∀ {n} k → Nameˢ (k +ℕ n) → Nameˢ n
%subtractˢ {n} k x = subtractᴺ k x
%  ⟨-because ⊆-assoc-+′ ⊆-refl n k -⟩
%
%


~\\~\texttt{add\makebox[0.61ex][c]{ˢ}\mbox{\hspace{0.50em}}{\char `\:}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \forall $}\mbox{\hspace{0.50em}}\{n\}\mbox{\hspace{0.50em}}k\mbox{\hspace{0.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}Name\makebox[0.61ex][c]{ˢ}\mbox{\hspace{0.50em}}n\mbox{\hspace{0.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}Name\makebox[0.61ex][c]{ˢ}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}k\mbox{\hspace{0.50em}}{\char `\+}\makebox[2.44ex][c]{$ \mathbb{{N}} $}\mbox{\hspace{0.50em}}n\makebox[1.22ex][c]{$ {)} $}\vphantom{$\{$}{\nopagebreak[4] \newline%
}add\makebox[0.61ex][c]{ˢ}\mbox{\hspace{0.50em}}\{n\}\mbox{\hspace{0.50em}}k\mbox{\hspace{0.50em}}x\mbox{\hspace{0.50em}}{\char `\=}\mbox{\hspace{0.50em}}add\makebox[0.61ex][c]{ᴺ}\mbox{\hspace{0.50em}}k\mbox{\hspace{0.50em}}x\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{1em}}\makebox[1.22ex][c]{⟨}{\char `\-}because\mbox{\hspace{0.50em}}\makebox[2.44ex][c]{$ \subseteq $}{\char `\-}assoc{\char `\-}{\char `\+}\mbox{\hspace{0.50em}}\makebox[2.44ex][c]{$ \subseteq $}{\char `\-}refl\mbox{\hspace{0.50em}}n\mbox{\hspace{0.50em}}k\mbox{\hspace{0.50em}}−\makebox[1.22ex][c]{⟩}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\vphantom{$\{$}{\nopagebreak[4] \newline%
}subtract\makebox[0.61ex][c]{ˢ}\mbox{\hspace{0.50em}}{\char `\:}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \forall $}\mbox{\hspace{0.50em}}\{n\}\mbox{\hspace{0.50em}}k\mbox{\hspace{0.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}Name\makebox[0.61ex][c]{ˢ}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}k\mbox{\hspace{0.50em}}{\char `\+}\makebox[2.44ex][c]{$ \mathbb{{N}} $}\mbox{\hspace{0.50em}}n\makebox[1.22ex][c]{$ {)} $}\mbox{\hspace{0.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}Name\makebox[0.61ex][c]{ˢ}\mbox{\hspace{0.50em}}n\vphantom{$\{$}{\nopagebreak[4] \newline%
}subtract\makebox[0.61ex][c]{ˢ}\mbox{\hspace{0.50em}}\{n\}\mbox{\hspace{0.50em}}k\mbox{\hspace{0.50em}}x\mbox{\hspace{0.50em}}{\char `\=}\mbox{\hspace{0.50em}}subtract\makebox[0.61ex][c]{ᴺ}\mbox{\hspace{0.50em}}k\mbox{\hspace{0.50em}}x\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{1em}}\makebox[1.22ex][c]{⟨}{\char `\-}because\mbox{\hspace{0.50em}}\makebox[2.44ex][c]{$ \subseteq $}{\char `\-}assoc{\char `\-}{\char `\+}′\mbox{\hspace{0.50em}}\makebox[2.44ex][c]{$ \subseteq $}{\char `\-}refl\mbox{\hspace{0.50em}}n\mbox{\hspace{0.50em}}k\mbox{\hspace{0.50em}}{\char `\-}\makebox[1.22ex][c]{⟩}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{1em}}}

\section{Using \textsc{NaPa}$:$ examples and advanced operations\label{usingNaPa}}

\subsection{Some convenience functions}

%
%paragraphName: convenience functions description
Here  are   a  few   functions  built  on   top  of   the  interface
    (without  using the  concrete  representation of  names). \texttt{sucᴺ}  is
    \texttt{addᴺ 1}  and  \texttt{sucᴺ$ \uparrow $}  is  a variant  that  includes  a
    coercion from \texttt{$ \alpha $ {\char `\+}1} to  \texttt{$ \alpha $ $ \uparrow $1}. The function \texttt{{\char `\_}ᴺ} turns
    a number $ {n} $  into a name that inhabits any  world with at least
    $ {n}{ }\mbox{+}{ }{1} $ consecutive binders.%


%
%comment:
%  sucᴺ : ∀ {α} → Name α → Name (α +1)
%  sucᴺ = addᴺ 1
%
%  sucᴺ↑ : ∀ {α} → Name α → Name (α ↑1)
%  sucᴺ↑ = coerceᴺ ⊆-+1↑1 ∘ sucᴺ
%
%  _ᴺ : ∀ {α} n → Name (α ↑ suc n)
%  _ᴺ {α} n = zeroᴺ +ᴺ n
%    ⟨-because α ↑1 +ᵂ n ⊆⟨ ⊆-+-↑ n ⟩
%              α ↑1 ↑  n ⊆⟨ ⊆-exch-↑-↑ 1 n ⟩∎
%              α ↑ suc n ∎ -⟩
%   where open ⊆-Reasoning
%
%


~\\~\texttt{\mbox{\hspace{1em}}suc\makebox[0.61ex][c]{ᴺ}\mbox{\hspace{0.50em}}{\char `\:}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \forall $}\mbox{\hspace{0.50em}}\{\makebox[1.22ex][c]{$ \alpha $}\}\mbox{\hspace{0.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}Name\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \alpha $}\mbox{\hspace{0.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}Name\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}\makebox[1.22ex][c]{$ \alpha $}\mbox{\hspace{0.50em}}{\char `\+}1\makebox[1.22ex][c]{$ {)} $}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{1em}}suc\makebox[0.61ex][c]{ᴺ}\mbox{\hspace{0.50em}}{\char `\=}\mbox{\hspace{0.50em}}add\makebox[0.61ex][c]{ᴺ}\mbox{\hspace{0.50em}}1\vphantom{$\{$}{\nopagebreak[4] \newline%
}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{1em}}suc\makebox[0.61ex][c]{ᴺ}\makebox[1.22ex][c]{$ \uparrow $}\mbox{\hspace{0.50em}}{\char `\:}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \forall $}\mbox{\hspace{0.50em}}\{\makebox[1.22ex][c]{$ \alpha $}\}\mbox{\hspace{0.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}Name\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \alpha $}\mbox{\hspace{0.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}Name\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}\makebox[1.22ex][c]{$ \alpha $}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \uparrow $}1\makebox[1.22ex][c]{$ {)} $}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{1em}}suc\makebox[0.61ex][c]{ᴺ}\makebox[1.22ex][c]{$ \uparrow $}\mbox{\hspace{0.50em}}{\char `\=}\mbox{\hspace{0.50em}}coerce\makebox[0.61ex][c]{ᴺ}\mbox{\hspace{0.50em}}\makebox[2.44ex][c]{$ \subseteq $}{\char `\-}{\char `\+}1\makebox[1.22ex][c]{$ \uparrow $}1\mbox{\hspace{0.50em}}$ \circ $\mbox{\hspace{0.50em}}suc\makebox[0.61ex][c]{ᴺ}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{1em}}\makebox[1.22ex][c]{{\char `\_}}\makebox[0.61ex][c]{ᴺ}\mbox{\hspace{0.50em}}{\char `\:}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \forall $}\mbox{\hspace{0.50em}}\{\makebox[1.22ex][c]{$ \alpha $}\}\mbox{\hspace{0.50em}}n\mbox{\hspace{0.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}Name\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}\makebox[1.22ex][c]{$ \alpha $}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \uparrow $}\mbox{\hspace{0.50em}}suc\mbox{\hspace{0.50em}}n\makebox[1.22ex][c]{$ {)} $}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{1em}}\makebox[1.22ex][c]{{\char `\_}}\makebox[0.61ex][c]{ᴺ}\mbox{\hspace{0.50em}}\{\makebox[1.22ex][c]{$ \alpha $}\}\mbox{\hspace{0.50em}}n\mbox{\hspace{0.50em}}{\char `\=}\mbox{\hspace{0.50em}}zero\makebox[0.61ex][c]{ᴺ}\mbox{\hspace{0.50em}}{\char `\+}\makebox[0.61ex][c]{ᴺ}\mbox{\hspace{0.50em}}n\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{2em}}\makebox[1.22ex][c]{⟨}{\char `\-}because\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \alpha $}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \uparrow $}1\mbox{\hspace{0.50em}}{\char `\+}\makebox[0.61ex][c]{ᵂ}\mbox{\hspace{0.50em}}n\mbox{\hspace{0.50em}}\makebox[2.44ex][c]{$ \subseteq $}\makebox[1.22ex][c]{⟨}\mbox{\hspace{0.50em}}\makebox[2.44ex][c]{$ \subseteq $}{\char `\-}{\char `\+}{\char `\-}\makebox[1.22ex][c]{$ \uparrow $}\mbox{\hspace{0.50em}}n\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{⟩}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{7em}}\makebox[1.22ex][c]{$ \alpha $}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \uparrow $}1\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \uparrow $}\mbox{\hspace{1em}}n\mbox{\hspace{0.50em}}\makebox[2.44ex][c]{$ \subseteq $}\makebox[1.22ex][c]{⟨}\mbox{\hspace{0.50em}}\makebox[2.44ex][c]{$ \subseteq $}{\char `\-}exch{\char `\-}\makebox[1.22ex][c]{$ \uparrow $}{\char `\-}\makebox[1.22ex][c]{$ \uparrow $}\mbox{\hspace{0.50em}}1\mbox{\hspace{0.50em}}n\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{⟩}∎\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{7em}}\makebox[1.22ex][c]{$ \alpha $}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \uparrow $}\mbox{\hspace{0.50em}}suc\mbox{\hspace{0.50em}}n\mbox{\hspace{0.50em}}∎\mbox{\hspace{0.50em}}{\char `\-}\makebox[1.22ex][c]{⟩}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{1.50em}}where\mbox{\hspace{0.50em}}open\mbox{\hspace{0.50em}}\makebox[2.44ex][c]{$ \subseteq $}{\char `\-}Reasoning\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{1em}}}

%
%paragraphName: ℓ-bound, ℓ-free
We call ℓ-bound,  a name bound somewhere in the  scope of ℓ binders.
    We call ℓ-free, a name free for  all ℓ binders. In other words, a de
    Bruijn index is ℓ-bound if it is  strictly less than ℓ; it is ℓ-free
    otherwise.%


%
%paragraphName: exportName
The \texttt{exportName} function  tells whether a given name  is ℓ-bound or
    ℓ-free.  In case  the name  is free,  an exported  version of  it is
    returned. This function  forms the base case  of exporting functions
    like \texttt{exportTm} explained later on.%


%
%comment:
%  -- Partial functions from A to B
%  A →? B = A → Maybe B
%
%  exportName : ∀ {α} ℓ →  Name (α ↑ ℓ)
%                       →? Name α
%  exportName ℓ x
%    with x <ᴺ ℓ
%  ...  | inj₁ _  = nothing
%  ...  | inj₂ x′ = just (x′ ∸ᴺ ℓ)
%
%


~\\~\texttt{\mbox{\hspace{1em}}{\char `\-}{\char `\-}\mbox{\hspace{0.50em}}Partial\mbox{\hspace{0.50em}}functions\mbox{\hspace{0.50em}}from\mbox{\hspace{0.50em}}A\mbox{\hspace{0.50em}}to\mbox{\hspace{0.50em}}B\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{1em}}A\mbox{\hspace{0.50em}}$ \rightarrow ${\char `\?}\mbox{\hspace{0.50em}}B\mbox{\hspace{0.50em}}{\char `\=}\mbox{\hspace{0.50em}}A\mbox{\hspace{0.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}Maybe\mbox{\hspace{0.50em}}B\vphantom{$\{$}{\nopagebreak[4] \newline%
}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{1em}}exportName\mbox{\hspace{0.50em}}{\char `\:}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \forall $}\mbox{\hspace{0.50em}}\{\makebox[1.22ex][c]{$ \alpha $}\}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{ℓ}\mbox{\hspace{0.50em}}$ \rightarrow $\mbox{\hspace{1em}}Name\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}\makebox[1.22ex][c]{$ \alpha $}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \uparrow $}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{ℓ}\makebox[1.22ex][c]{$ {)} $}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{11.50em}}$ \rightarrow ${\char `\?}\mbox{\hspace{0.50em}}Name\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \alpha $}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{1em}}exportName\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{ℓ}\mbox{\hspace{0.50em}}x\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{2em}}with\mbox{\hspace{0.50em}}x\mbox{\hspace{0.50em}}{\char `\<}\makebox[0.61ex][c]{ᴺ}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{ℓ}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{1em}}{\char `\.}{\char `\.}{\char `\.}\mbox{\hspace{1em}}{\char `\|}\mbox{\hspace{0.50em}}inj\makebox[0.61ex][c]{₁}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{{\char `\_}}\mbox{\hspace{1em}}{\char `\=}\mbox{\hspace{0.50em}}nothing\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{1em}}{\char `\.}{\char `\.}{\char `\.}\mbox{\hspace{1em}}{\char `\|}\mbox{\hspace{0.50em}}inj\makebox[0.61ex][c]{₂}\mbox{\hspace{0.50em}}x′\mbox{\hspace{0.50em}}{\char `\=}\mbox{\hspace{0.50em}}just\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}x′\mbox{\hspace{0.50em}}∸\makebox[0.61ex][c]{ᴺ}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{ℓ}\makebox[1.22ex][c]{$ {)} $}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{1em}}}

%
%paragraphName: shiftName
The  function   \texttt{shiftName ℓ k pf}  shifts  its   argument  by
    \texttt{k} if  this name is  ℓ-free, otherwise it leaves  the ℓ-bound
    name untouched.  This function makes  use of \texttt{cmpᴺ} and  coerces the
    outputs to the required type. It also perform a coercion on the fly,
    giving extra flexibility for free.%


%
%comment:
%shiftName : ∀ {α} ℓ k → (α +ᵂ k) ⊆ β
%                      → Name (α ↑ ℓ)
%                      → Name (β ↑ ℓ)
%shiftName ℓ k pf x
% with x <ᴺ ℓ
%... | inj₁ x′ = x′
%                ⟨-because pf₁ -⟩
%... | inj₂ x′ = x′ +ᴺ k
%                ⟨-because pf₂ -⟩
%  where
%  pf₁ = ⊆-cong-↑ ⊆-ø ℓ
%  pf₂ = ⊆-trans (⊆-exch-+-+ ⊆-refl ℓ k)
%                (⊆-ctx-+↑ pf ℓ)
%
%


~\\~\texttt{shiftName\mbox{\hspace{0.50em}}{\char `\:}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \forall $}\mbox{\hspace{0.50em}}\{\makebox[1.22ex][c]{$ \alpha $}\}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{ℓ}\mbox{\hspace{0.50em}}k\mbox{\hspace{0.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}\makebox[1.22ex][c]{$ \alpha $}\mbox{\hspace{0.50em}}{\char `\+}\makebox[0.61ex][c]{ᵂ}\mbox{\hspace{0.50em}}k\makebox[1.22ex][c]{$ {)} $}\mbox{\hspace{0.50em}}\makebox[2.44ex][c]{$ \subseteq $}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \beta $}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{11em}}$ \rightarrow $\mbox{\hspace{0.50em}}Name\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}\makebox[1.22ex][c]{$ \alpha $}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \uparrow $}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{ℓ}\makebox[1.22ex][c]{$ {)} $}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{11em}}$ \rightarrow $\mbox{\hspace{0.50em}}Name\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}\makebox[1.22ex][c]{$ \beta $}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \uparrow $}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{ℓ}\makebox[1.22ex][c]{$ {)} $}\vphantom{$\{$}{\nopagebreak[4] \newline%
}shiftName\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{ℓ}\mbox{\hspace{0.50em}}k\mbox{\hspace{0.50em}}pf\mbox{\hspace{0.50em}}x\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{0.50em}}with\mbox{\hspace{0.50em}}x\mbox{\hspace{0.50em}}{\char `\<}\makebox[0.61ex][c]{ᴺ}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{ℓ}\vphantom{$\{$}{\nopagebreak[4] \newline%
}{\char `\.}{\char `\.}{\char `\.}\mbox{\hspace{0.50em}}{\char `\|}\mbox{\hspace{0.50em}}inj\makebox[0.61ex][c]{₁}\mbox{\hspace{0.50em}}x′\mbox{\hspace{0.50em}}{\char `\=}\mbox{\hspace{0.50em}}x′\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{8em}}\makebox[1.22ex][c]{⟨}{\char `\-}because\mbox{\hspace{0.50em}}pf\makebox[0.61ex][c]{₁}\mbox{\hspace{0.50em}}{\char `\-}\makebox[1.22ex][c]{⟩}\vphantom{$\{$}{\nopagebreak[4] \newline%
}{\char `\.}{\char `\.}{\char `\.}\mbox{\hspace{0.50em}}{\char `\|}\mbox{\hspace{0.50em}}inj\makebox[0.61ex][c]{₂}\mbox{\hspace{0.50em}}x′\mbox{\hspace{0.50em}}{\char `\=}\mbox{\hspace{0.50em}}x′\mbox{\hspace{0.50em}}{\char `\+}\makebox[0.61ex][c]{ᴺ}\mbox{\hspace{0.50em}}k\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{8em}}\makebox[1.22ex][c]{⟨}{\char `\-}because\mbox{\hspace{0.50em}}pf\makebox[0.61ex][c]{₂}\mbox{\hspace{0.50em}}{\char `\-}\makebox[1.22ex][c]{⟩}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{1em}}where\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{1em}}pf\makebox[0.61ex][c]{₁}\mbox{\hspace{0.50em}}{\char `\=}\mbox{\hspace{0.50em}}\makebox[2.44ex][c]{$ \subseteq $}{\char `\-}cong{\char `\-}\makebox[1.22ex][c]{$ \uparrow $}\mbox{\hspace{0.50em}}\makebox[2.44ex][c]{$ \subseteq $}{\char `\-}\makebox[1.22ex][c]{$ \emptyset $}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{ℓ}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{1em}}pf\makebox[0.61ex][c]{₂}\mbox{\hspace{0.50em}}{\char `\=}\mbox{\hspace{0.50em}}\makebox[2.44ex][c]{$ \subseteq $}{\char `\-}trans\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}\makebox[2.44ex][c]{$ \subseteq $}{\char `\-}exch{\char `\-}{\char `\+}{\char `\-}{\char `\+}\mbox{\hspace{0.50em}}\makebox[2.44ex][c]{$ \subseteq $}{\char `\-}refl\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{ℓ}\mbox{\hspace{0.50em}}k\makebox[1.22ex][c]{$ {)} $}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{8em}}\makebox[0.61ex][c]{ }\makebox[1.22ex][c]{$ {(} $}\makebox[2.44ex][c]{$ \subseteq $}{\char `\-}ctx{\char `\-}{\char `\+}\makebox[1.22ex][c]{$ \uparrow $}\mbox{\hspace{0.50em}}pf\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{ℓ}\makebox[1.22ex][c]{$ {)} $}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{1em}}}

%
%paragraphName: protect↑
The  \texttt{protect$ \uparrow $}  function  shifts   a  name  transformer.  Let
    \texttt{f}  be  a   function  from  names  to   names.  The  function
    \texttt{protect$ \uparrow $ ℓ f} is  a version  of \texttt{f} that  is applicable
    under \texttt{ℓ}  binders. Let  \texttt{x} be  a name  under \texttt{ℓ}    binders.  When  \texttt{x}  is  ℓ-bound,  it  is  left  untouched  by
    \texttt{protect$ \uparrow $}.  When   \texttt{x}  is  ℓ-free,  we   can  subtract
    \texttt{ℓ} to \texttt{x}, give it to \texttt{f}, and then add \texttt{ℓ}    to get  the result.  By combining \texttt{protect$ \uparrow $}  and \texttt{addᴺ}    one obtain an alternative implementation of \texttt{shiftName} called
    \texttt{shiftName′}.  However  \texttt{shiftName}  is  more  efficient
    since it avoids to subtracting \texttt{ℓ} to add it back after adding
    \texttt{k}.%


%
%comment:
%protect↑ : ∀ {α β} ℓ
%           → (Name α → Name β)
%           → (Name (α ↑ ℓ) → Name (β ↑ ℓ))
%protect↑ ℓ f x
% with x <ᴺ ℓ
%... | inj₁ x′ = x′
%              ⟨-because ⊆-cong-↑ ⊆-ø ℓ -⟩
%... | inj₂ x′ = f (x′ ∸ᴺ ℓ) +ᴺ ℓ
%              ⟨-because ⊆-+-↑ ℓ -⟩
%
%shiftName′ : ∀ {α β} ℓ k → (α +ᵂ k) ⊆ β
%             → Name (α ↑ ℓ) → Name (β ↑ ℓ)
%shiftName′ ℓ k pf = protect↑ (coerceᴺ pf ∘ addᴺ k) ℓ
%
%


~\\~\texttt{protect\makebox[1.22ex][c]{$ \uparrow $}\mbox{\hspace{0.50em}}{\char `\:}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \forall $}\mbox{\hspace{0.50em}}\{\makebox[1.22ex][c]{$ \alpha $}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \beta $}\}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{ℓ}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{5.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}Name\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \alpha $}\mbox{\hspace{0.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}Name\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \beta $}\makebox[1.22ex][c]{$ {)} $}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{5.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}Name\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}\makebox[1.22ex][c]{$ \alpha $}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \uparrow $}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{ℓ}\makebox[1.22ex][c]{$ {)} $}\mbox{\hspace{0.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}Name\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}\makebox[1.22ex][c]{$ \beta $}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \uparrow $}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{ℓ}\makebox[1.22ex][c]{$ {)} $}\makebox[1.22ex][c]{$ {)} $}\vphantom{$\{$}{\nopagebreak[4] \newline%
}protect\makebox[1.22ex][c]{$ \uparrow $}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{ℓ}\mbox{\hspace{0.50em}}f\mbox{\hspace{0.50em}}x\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{0.50em}}with\mbox{\hspace{0.50em}}x\mbox{\hspace{0.50em}}{\char `\<}\makebox[0.61ex][c]{ᴺ}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{ℓ}\vphantom{$\{$}{\nopagebreak[4] \newline%
}{\char `\.}{\char `\.}{\char `\.}\mbox{\hspace{0.50em}}{\char `\|}\mbox{\hspace{0.50em}}inj\makebox[0.61ex][c]{₁}\mbox{\hspace{0.50em}}x′\mbox{\hspace{0.50em}}{\char `\=}\mbox{\hspace{0.50em}}x′\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{7em}}\makebox[1.22ex][c]{⟨}{\char `\-}because\mbox{\hspace{0.50em}}\makebox[2.44ex][c]{$ \subseteq $}{\char `\-}cong{\char `\-}\makebox[1.22ex][c]{$ \uparrow $}\mbox{\hspace{0.50em}}\makebox[2.44ex][c]{$ \subseteq $}{\char `\-}\makebox[1.22ex][c]{$ \emptyset $}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{ℓ}\mbox{\hspace{0.50em}}{\char `\-}\makebox[1.22ex][c]{⟩}\vphantom{$\{$}{\nopagebreak[4] \newline%
}{\char `\.}{\char `\.}{\char `\.}\mbox{\hspace{0.50em}}{\char `\|}\mbox{\hspace{0.50em}}inj\makebox[0.61ex][c]{₂}\mbox{\hspace{0.50em}}x′\mbox{\hspace{0.50em}}{\char `\=}\mbox{\hspace{0.50em}}f\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}x′\mbox{\hspace{0.50em}}∸\makebox[0.61ex][c]{ᴺ}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{ℓ}\makebox[1.22ex][c]{$ {)} $}\mbox{\hspace{0.50em}}{\char `\+}\makebox[0.61ex][c]{ᴺ}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{ℓ}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{7em}}\makebox[1.22ex][c]{⟨}{\char `\-}because\mbox{\hspace{0.50em}}\makebox[2.44ex][c]{$ \subseteq $}{\char `\-}{\char `\+}{\char `\-}\makebox[1.22ex][c]{$ \uparrow $}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{ℓ}\mbox{\hspace{0.50em}}{\char `\-}\makebox[1.22ex][c]{⟩}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\vphantom{$\{$}{\nopagebreak[4] \newline%
}shiftName′\mbox{\hspace{0.50em}}{\char `\:}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \forall $}\mbox{\hspace{0.50em}}\{\makebox[1.22ex][c]{$ \alpha $}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \beta $}\}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{ℓ}\mbox{\hspace{0.50em}}k\mbox{\hspace{0.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}\makebox[1.22ex][c]{$ \alpha $}\mbox{\hspace{0.50em}}{\char `\+}\makebox[0.61ex][c]{ᵂ}\mbox{\hspace{0.50em}}k\makebox[1.22ex][c]{$ {)} $}\mbox{\hspace{0.50em}}\makebox[2.44ex][c]{$ \subseteq $}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \beta $}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{6.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}Name\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}\makebox[1.22ex][c]{$ \alpha $}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \uparrow $}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{ℓ}\makebox[1.22ex][c]{$ {)} $}\mbox{\hspace{0.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}Name\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}\makebox[1.22ex][c]{$ \beta $}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \uparrow $}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{ℓ}\makebox[1.22ex][c]{$ {)} $}\vphantom{$\{$}{\nopagebreak[4] \newline%
}shiftName′\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{ℓ}\mbox{\hspace{0.50em}}k\mbox{\hspace{0.50em}}pf\mbox{\hspace{0.50em}}{\char `\=}\mbox{\hspace{0.50em}}protect\makebox[1.22ex][c]{$ \uparrow $}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}coerce\makebox[0.61ex][c]{ᴺ}\mbox{\hspace{0.50em}}pf\mbox{\hspace{0.50em}}$ \circ $\mbox{\hspace{0.50em}}add\makebox[0.61ex][c]{ᴺ}\mbox{\hspace{0.50em}}k\makebox[1.22ex][c]{$ {)} $}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{ℓ}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{1em}}}

\subsection{Building terms}

%
%paragraphName: bulding terms description
Building terms  in \textsc{NaPa} is as  easy as building them  in the other
    nameless approaches we have seen. The structure is exactly the same,
    and the  variables are made  of numbers  (of type \texttt{$ \mathbb{{N}} $})  using \texttt{{\char `\_}ᴺ}.
    Below  we define  the  representation of  the  identity function  as
    \texttt{idTm}, the application operator  as \texttt{appTm} and finally
    the composition function as \texttt{compTm}$:$%


%
%comment:
%idTm : ∀ {α} → Tm α
%idTm = ƛ(V (0 ᴺ))
%
%appTm : ∀ {α} → Tm α
%appTm = ƛ(ƛ(V (1 ᴺ) · V (0 ᴺ)))
%
%compTm : ∀ {α} → Tm α
%compTm = ƛ(ƛ(ƛ(V (2 ᴺ)) · (V (1 ᴺ) · V (0 ᴺ)))))
%
%


~\\~\texttt{idTm\mbox{\hspace{0.50em}}{\char `\:}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \forall $}\mbox{\hspace{0.50em}}\{\makebox[1.22ex][c]{$ \alpha $}\}\mbox{\hspace{0.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}Tm\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \alpha $}\vphantom{$\{$}{\nopagebreak[4] \newline%
}idTm\mbox{\hspace{0.50em}}{\char `\=}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{ƛ}\makebox[1.22ex][c]{$ {(} $}V\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}0\mbox{\hspace{0.50em}}\makebox[0.61ex][c]{ᴺ}\makebox[1.22ex][c]{$ {)} $}\makebox[1.22ex][c]{$ {)} $}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\vphantom{$\{$}{\nopagebreak[4] \newline%
}appTm\mbox{\hspace{0.50em}}{\char `\:}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \forall $}\mbox{\hspace{0.50em}}\{\makebox[1.22ex][c]{$ \alpha $}\}\mbox{\hspace{0.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}Tm\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \alpha $}\vphantom{$\{$}{\nopagebreak[4] \newline%
}appTm\mbox{\hspace{0.50em}}{\char `\=}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{ƛ}\makebox[1.22ex][c]{$ {(} $}\makebox[1.22ex][c]{ƛ}\makebox[1.22ex][c]{$ {(} $}V\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}1\mbox{\hspace{0.50em}}\makebox[0.61ex][c]{ᴺ}\makebox[1.22ex][c]{$ {)} $}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \cdotp $}\mbox{\hspace{0.50em}}V\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}0\mbox{\hspace{0.50em}}\makebox[0.61ex][c]{ᴺ}\makebox[1.22ex][c]{$ {)} $}\makebox[1.22ex][c]{$ {)} $}\makebox[1.22ex][c]{$ {)} $}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\vphantom{$\{$}{\nopagebreak[4] \newline%
}compTm\mbox{\hspace{0.50em}}{\char `\:}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \forall $}\mbox{\hspace{0.50em}}\{\makebox[1.22ex][c]{$ \alpha $}\}\mbox{\hspace{0.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}Tm\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \alpha $}\vphantom{$\{$}{\nopagebreak[4] \newline%
}compTm\mbox{\hspace{0.50em}}{\char `\=}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{ƛ}\makebox[1.22ex][c]{$ {(} $}\makebox[1.22ex][c]{ƛ}\makebox[1.22ex][c]{$ {(} $}\makebox[1.22ex][c]{ƛ}\makebox[1.22ex][c]{$ {(} $}V\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}2\mbox{\hspace{0.50em}}\makebox[0.61ex][c]{ᴺ}\makebox[1.22ex][c]{$ {)} $}\makebox[1.22ex][c]{$ {)} $}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \cdotp $}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}V\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}1\mbox{\hspace{0.50em}}\makebox[0.61ex][c]{ᴺ}\makebox[1.22ex][c]{$ {)} $}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \cdotp $}\mbox{\hspace{0.50em}}V\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}0\mbox{\hspace{0.50em}}\makebox[0.61ex][c]{ᴺ}\makebox[1.22ex][c]{$ {)} $}\makebox[1.22ex][c]{$ {)} $}\makebox[1.22ex][c]{$ {)} $}\makebox[1.22ex][c]{$ {)} $}\makebox[1.22ex][c]{$ {)} $}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{1em}}}

\newpage

\subsection{Computing free variables}

%
%paragraphName: fv description
Our first example  of functions over terms simply  computes the list
    of  free  variables  in  the input  term.  The  \texttt{fv}  function
    below,  while  straightforward,  has  the subtle  cases  of  binding
    constructs (\texttt{ƛ}  and \texttt{Let}). In these  cases we have to  remove the
    bound  variable  from  the  list  of free  variables  given  by  the
    recursive  call. In  this  nameless representation  this amounts  to
    removing occurrences of  $ {0} $ and subtract $ {1} $  to other name
    occurrences. This  is done  by the  function \texttt{rm₀{\char `\|}}{ }\texttt{which}{ }\texttt{calls}{ }\texttt{\{agda{\char `\|}exportName 1}  on each  element of  the list  and merges  the
    results.  Note that  forgetting to  remove the  bound variable  will
    result in  a type error. In  the same vein the  typing of \texttt{fv}    ensures  that all  returned variables  do appear  free in  the given
    term.%


%
%comment:
%  rm₀ : ∀ {α} → List (Name (α ↑1))
%              → List (Name α)
%  rm₀ [] = []
%  rm₀ (x ∷ xs) with exportName 1 x
%  ...               |  just x'  = x' ∷ rm₀ xs
%  ...               |  nothing  = rm₀ xs
%
%  fv : ∀ {α} → Tm α → List (Name α)
%  fv (V x)        = [ x ]
%  fv (fct · arg)  = fv fct ++ fv arg
%  fv (ƛ t)        = rm₀ (fv t)
%  fv (Let t u)    = fv t ++ rm₀ (fv u)
%
%


~\\~\texttt{\mbox{\hspace{1em}}rm₀\mbox{\hspace{0.50em}}{\char `\:}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \forall $}\mbox{\hspace{0.50em}}\{\makebox[1.22ex][c]{$ \alpha $}\}\mbox{\hspace{0.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}List\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}Name\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}\makebox[1.22ex][c]{$ \alpha $}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \uparrow $}1\makebox[1.22ex][c]{$ {)} $}\makebox[1.22ex][c]{$ {)} $}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{7em}}$ \rightarrow $\mbox{\hspace{0.50em}}List\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}Name\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \alpha $}\makebox[1.22ex][c]{$ {)} $}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{1em}}rm₀\mbox{\hspace{0.50em}}{\char `\[}{\char `\]}\mbox{\hspace{0.50em}}{\char `\=}\mbox{\hspace{0.50em}}{\char `\[}{\char `\]}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{1em}}rm₀\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}x\mbox{\hspace{0.50em}}∷\mbox{\hspace{0.50em}}xs\makebox[1.22ex][c]{$ {)} $}\mbox{\hspace{0.50em}}with\mbox{\hspace{0.50em}}exportName\mbox{\hspace{0.50em}}1\mbox{\hspace{0.50em}}x\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{1em}}{\char `\.}{\char `\.}{\char `\.}\mbox{\hspace{7.50em}}{\char `\|}\mbox{\hspace{1em}}just\mbox{\hspace{0.50em}}x{\char `\'}\mbox{\hspace{1em}}{\char `\=}\mbox{\hspace{0.50em}}x{\char `\'}\mbox{\hspace{0.50em}}∷\mbox{\hspace{0.50em}}rm₀\mbox{\hspace{0.50em}}xs\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{1em}}{\char `\.}{\char `\.}{\char `\.}\mbox{\hspace{7.50em}}{\char `\|}\mbox{\hspace{1em}}nothing\mbox{\hspace{1em}}{\char `\=}\mbox{\hspace{0.50em}}rm₀\mbox{\hspace{0.50em}}xs\vphantom{$\{$}{\nopagebreak[4] \newline%
}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{1em}}fv\mbox{\hspace{0.50em}}{\char `\:}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \forall $}\mbox{\hspace{0.50em}}\{\makebox[1.22ex][c]{$ \alpha $}\}\mbox{\hspace{0.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}Tm\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \alpha $}\mbox{\hspace{0.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}List\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}Name\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \alpha $}\makebox[1.22ex][c]{$ {)} $}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{1em}}fv\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}V\mbox{\hspace{0.50em}}x\makebox[1.22ex][c]{$ {)} $}\mbox{\hspace{4em}}{\char `\=}\mbox{\hspace{0.50em}}{\char `\[}\mbox{\hspace{0.50em}}x\mbox{\hspace{0.50em}}{\char `\]}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{1em}}fv\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}fct\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \cdotp $}\mbox{\hspace{0.50em}}arg\makebox[1.22ex][c]{$ {)} $}\mbox{\hspace{1em}}{\char `\=}\mbox{\hspace{0.50em}}fv\mbox{\hspace{0.50em}}fct\mbox{\hspace{0.50em}}{\char `\+}{\char `\+}\mbox{\hspace{0.50em}}fv\mbox{\hspace{0.50em}}arg\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{1em}}fv\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}\makebox[1.22ex][c]{ƛ}\mbox{\hspace{0.50em}}t\makebox[1.22ex][c]{$ {)} $}\mbox{\hspace{4em}}{\char `\=}\mbox{\hspace{0.50em}}rm₀\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}fv\mbox{\hspace{0.50em}}t\makebox[1.22ex][c]{$ {)} $}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{1em}}fv\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}Let\mbox{\hspace{0.50em}}t\mbox{\hspace{0.50em}}u\makebox[1.22ex][c]{$ {)} $}\mbox{\hspace{2em}}{\char `\=}\mbox{\hspace{0.50em}}fv\mbox{\hspace{0.50em}}t\mbox{\hspace{0.50em}}{\char `\+}{\char `\+}\mbox{\hspace{0.50em}}rm₀\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}fv\mbox{\hspace{0.50em}}u\makebox[1.22ex][c]{$ {)} $}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{1em}}}

\subsection{Generic traversal}

%
%paragraphName: TraverseTm
In  order  to  build  multiple   traversal  functions  at  once,  we
    first  define  a   generic  function  based  on   ideas  from  \cite{mcbride-paterson-08}. It  is essentially a map/subst  function where
    the  free variables  are  transformed by  a user-supplied  function.
    Moreover  a class  of effects  (an applicative  functor) is  allowed
    during the  traversal. An applicative  functor is halfway  between a
    functor and a monad. Like a monad, an applicative functor has a unit
    called  \texttt{pure}.  It  allows  to  embed any  pure  value  as  a
    potentially effectful  one. The second operation  called \texttt{{\char `\_}$ \otimes ${\char `\_}}    is an effectful  application, taking both an  effectful function and
    argument and resulting in an effectful result.%


%
%comment:
%module TraverseTm
%          {E}   (E-app  : Applicative E)
%          {α β} (trName : ∀ ℓ → Name (α ↑ ℓ)
%                              → E (Tm (β ↑ ℓ)))
%  where
%  open Applicative E-app
%
%  tr : ∀ ℓ → Tm (α ↑ ℓ) → E (Tm (β ↑ ℓ))
%  tr ℓ (V x)     = trName ℓ x
%  tr ℓ (t · u)   = pure _·_ ⊛ tr ℓ t ⊛ tr ℓ u
%  tr ℓ (ƛ t)     = pure ƛ   ⊛ tr (suc ℓ) t
%  tr ℓ (Let t u) = pure Let ⊛ tr ℓ t
%                            ⊛ tr (suc ℓ) u
%
%  trTm : Tm α → E (Tm β)
%  trTm = tr 0
%
%


~\\~\texttt{module\mbox{\hspace{0.50em}}TraverseTm\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{5em}}\{E\}\mbox{\hspace{1.50em}}\makebox[1.22ex][c]{$ {(} $}E{\char `\-}app\mbox{\hspace{1em}}{\char `\:}\mbox{\hspace{0.50em}}Applicative\mbox{\hspace{0.50em}}E\makebox[1.22ex][c]{$ {)} $}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{5em}}\{\makebox[1.22ex][c]{$ \alpha $}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \beta $}\}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}trName\mbox{\hspace{0.50em}}{\char `\:}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \forall $}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{ℓ}\mbox{\hspace{0.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}Name\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}\makebox[1.22ex][c]{$ \alpha $}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \uparrow $}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{ℓ}\makebox[1.22ex][c]{$ {)} $}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{15em}}$ \rightarrow $\mbox{\hspace{0.50em}}E\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}Tm\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}\makebox[1.22ex][c]{$ \beta $}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \uparrow $}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{ℓ}\makebox[1.22ex][c]{$ {)} $}\makebox[1.22ex][c]{$ {)} $}\makebox[1.22ex][c]{$ {)} $}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{1em}}where\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{1em}}open\mbox{\hspace{0.50em}}Applicative\mbox{\hspace{0.50em}}E{\char `\-}app\vphantom{$\{$}{\nopagebreak[4] \newline%
}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{1em}}tr\mbox{\hspace{0.50em}}{\char `\:}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \forall $}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{ℓ}\mbox{\hspace{0.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}Tm\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}\makebox[1.22ex][c]{$ \alpha $}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \uparrow $}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{ℓ}\makebox[1.22ex][c]{$ {)} $}\mbox{\hspace{0.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}E\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}Tm\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}\makebox[1.22ex][c]{$ \beta $}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \uparrow $}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{ℓ}\makebox[1.22ex][c]{$ {)} $}\makebox[1.22ex][c]{$ {)} $}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{1em}}tr\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{ℓ}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}V\mbox{\hspace{0.50em}}x\makebox[1.22ex][c]{$ {)} $}\mbox{\hspace{2.50em}}{\char `\=}\mbox{\hspace{0.50em}}trName\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{ℓ}\mbox{\hspace{0.50em}}x\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{1em}}tr\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{ℓ}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}t\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \cdotp $}\mbox{\hspace{0.50em}}u\makebox[1.22ex][c]{$ {)} $}\mbox{\hspace{1.50em}}{\char `\=}\mbox{\hspace{0.50em}}pure\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{{\char `\_}}\makebox[1.22ex][c]{$ \cdotp $}\makebox[1.22ex][c]{{\char `\_}}\mbox{\hspace{0.50em}}$ \otimes $\mbox{\hspace{0.50em}}tr\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{ℓ}\mbox{\hspace{0.50em}}t\mbox{\hspace{0.50em}}$ \otimes $\mbox{\hspace{0.50em}}tr\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{ℓ}\mbox{\hspace{0.50em}}u\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{1em}}tr\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{ℓ}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}\makebox[1.22ex][c]{ƛ}\mbox{\hspace{0.50em}}t\makebox[1.22ex][c]{$ {)} $}\mbox{\hspace{2.50em}}{\char `\=}\mbox{\hspace{0.50em}}pure\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{ƛ}\mbox{\hspace{1.50em}}$ \otimes $\mbox{\hspace{0.50em}}tr\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}suc\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{ℓ}\makebox[1.22ex][c]{$ {)} $}\mbox{\hspace{0.50em}}t\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{1em}}tr\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{ℓ}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}Let\mbox{\hspace{0.50em}}t\mbox{\hspace{0.50em}}u\makebox[1.22ex][c]{$ {)} $}\mbox{\hspace{0.50em}}{\char `\=}\mbox{\hspace{0.50em}}pure\mbox{\hspace{0.50em}}Let\mbox{\hspace{0.50em}}$ \otimes $\mbox{\hspace{0.50em}}tr\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{ℓ}\mbox{\hspace{0.50em}}t\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{14em}}$ \otimes $\mbox{\hspace{0.50em}}tr\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}suc\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{ℓ}\makebox[1.22ex][c]{$ {)} $}\mbox{\hspace{0.50em}}u\vphantom{$\{$}{\nopagebreak[4] \newline%
}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{1em}}trTm\mbox{\hspace{0.50em}}{\char `\:}\mbox{\hspace{0.50em}}Tm\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \alpha $}\mbox{\hspace{0.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}E\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}Tm\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \beta $}\makebox[1.22ex][c]{$ {)} $}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{1em}}trTm\mbox{\hspace{0.50em}}{\char `\=}\mbox{\hspace{0.50em}}tr\mbox{\hspace{0.50em}}0\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{1em}}}

%
%paragraphName: trTm′
To put  this traversal at  work we successively instantiate  some of
    its arguments. For instance you may have noticed the special case we
    made for  variables. Mapping  names to terms  will bring  us capture
    avoiding substitution almost for free.  However, in the mean time we
    build  \texttt{trTm′}  which maps  names  to  names.  It does  so  by
    applying \texttt{pure V} to the name to name function$:$%


%
%comment:
%open TraverseTm
%
%trTm′ :
%  ∀ {E} (E-app : Applicative E) {α β}
%    (trName : ∀ ℓ → Name (α ↑ ℓ)
%                  → E (Name (β ↑ ℓ)))
%  → Tm α → E (Tm β)
%trTm′ E-app trName
%  = trTm E-app (λ ℓ x → pure V ⊛ trName ℓ x)
%    where open Applicative E-app
%
%


~\\~\texttt{open\mbox{\hspace{0.50em}}TraverseTm\vphantom{$\{$}{\nopagebreak[4] \newline%
}\vphantom{$\{$}{\nopagebreak[4] \newline%
}trTm′\mbox{\hspace{0.50em}}{\char `\:}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{1em}}\makebox[1.22ex][c]{$ \forall $}\mbox{\hspace{0.50em}}\{E\}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}E{\char `\-}app\mbox{\hspace{0.50em}}{\char `\:}\mbox{\hspace{0.50em}}Applicative\mbox{\hspace{0.50em}}E\makebox[1.22ex][c]{$ {)} $}\mbox{\hspace{0.50em}}\{\makebox[1.22ex][c]{$ \alpha $}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \beta $}\}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{2em}}\makebox[1.22ex][c]{$ {(} $}trName\mbox{\hspace{0.50em}}{\char `\:}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \forall $}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{ℓ}\mbox{\hspace{0.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}Name\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}\makebox[1.22ex][c]{$ \alpha $}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \uparrow $}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{ℓ}\makebox[1.22ex][c]{$ {)} $}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{9em}}$ \rightarrow $\mbox{\hspace{0.50em}}E\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}Name\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}\makebox[1.22ex][c]{$ \beta $}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \uparrow $}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{ℓ}\makebox[1.22ex][c]{$ {)} $}\makebox[1.22ex][c]{$ {)} $}\makebox[1.22ex][c]{$ {)} $}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{1em}}$ \rightarrow $\mbox{\hspace{0.50em}}Tm\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \alpha $}\mbox{\hspace{0.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}E\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}Tm\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \beta $}\makebox[1.22ex][c]{$ {)} $}\vphantom{$\{$}{\nopagebreak[4] \newline%
}trTm′\mbox{\hspace{0.50em}}E{\char `\-}app\mbox{\hspace{0.50em}}trName\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{1em}}{\char `\=}\mbox{\hspace{0.50em}}trTm\mbox{\hspace{0.50em}}E{\char `\-}app\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}$ \lambda $\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{ℓ}\mbox{\hspace{0.50em}}x\mbox{\hspace{0.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}pure\mbox{\hspace{0.50em}}V\mbox{\hspace{0.50em}}$ \otimes $\mbox{\hspace{0.50em}}trName\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{ℓ}\mbox{\hspace{0.50em}}x\makebox[1.22ex][c]{$ {)} $}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{2em}}where\mbox{\hspace{0.50em}}open\mbox{\hspace{0.50em}}Applicative\mbox{\hspace{0.50em}}E{\char `\-}app\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{1em}}}

\paragraph{Renaming functions}

%
%paragraphName: renameTm, renameTm?
In  many functions  over terms  the handling  of variables  shares a
    common part.  Given a variable  under \texttt{ℓ} binders, we  test if
    the variable is  ℓ-bound. If so we leave it  untouched, otherwise we
    subtract  \texttt{ℓ} and  go  on a  specific  processing after  which
    we  add  \texttt{ℓ}  again  to  the free  variables  of  the  result.
    The  traversal function  is augmented  by this  processing of  bound
    variables  to build  \texttt{renameTmA}. Then  by picking  either the
    identity functor (\texttt{id{\char `\-}app}), or the  \texttt{Maybe} one we build two
    functions (a total  and a partial one) to  perform renamings, namely
    \texttt{renameTm} and \texttt{renameTm{\char `\?}}$:$%


%
%comment:
%renameTmA : ∀ {E} (E-app : Applicative E)
%              {α β} (θ : Name α → E (Name β))
%            → Tm α → E (Tm β)
%renameTmA E-app θ
%  = trTm′ E-app (protect↑A E-app θ)
%
%


~\\~\texttt{renameTmA\mbox{\hspace{0.50em}}{\char `\:}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \forall $}\mbox{\hspace{0.50em}}\{E\}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}E{\char `\-}app\mbox{\hspace{0.50em}}{\char `\:}\mbox{\hspace{0.50em}}Applicative\mbox{\hspace{0.50em}}E\makebox[1.22ex][c]{$ {)} $}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{7em}}\{\makebox[1.22ex][c]{$ \alpha $}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \beta $}\}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}$ \theta $\mbox{\hspace{0.50em}}{\char `\:}\mbox{\hspace{0.50em}}Name\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \alpha $}\mbox{\hspace{0.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}E\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}Name\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \beta $}\makebox[1.22ex][c]{$ {)} $}\makebox[1.22ex][c]{$ {)} $}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{6em}}$ \rightarrow $\mbox{\hspace{0.50em}}Tm\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \alpha $}\mbox{\hspace{0.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}E\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}Tm\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \beta $}\makebox[1.22ex][c]{$ {)} $}\vphantom{$\{$}{\nopagebreak[4] \newline%
}renameTmA\mbox{\hspace{0.50em}}E{\char `\-}app\mbox{\hspace{0.50em}}$ \theta $\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{1em}}{\char `\=}\mbox{\hspace{0.50em}}trTm′\mbox{\hspace{0.50em}}E{\char `\-}app\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}protect\makebox[1.22ex][c]{$ \uparrow $}A\mbox{\hspace{0.50em}}E{\char `\-}app\mbox{\hspace{0.50em}}$ \theta $\makebox[1.22ex][c]{$ {)} $}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{1em}}}

%
%comment:
%renameTm : ∀ {α β} → (Name α → Name β)
%                   → Tm α → Tm β
%renameTm θ = trTm′ id-app (protect↑ θ)
%-- or
%-- renameTm = renameTmA id-app
%
%


~\\~\texttt{renameTm\mbox{\hspace{0.50em}}{\char `\:}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \forall $}\mbox{\hspace{0.50em}}\{\makebox[1.22ex][c]{$ \alpha $}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \beta $}\}\mbox{\hspace{0.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}Name\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \alpha $}\mbox{\hspace{0.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}Name\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \beta $}\makebox[1.22ex][c]{$ {)} $}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{9.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}Tm\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \alpha $}\mbox{\hspace{0.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}Tm\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \beta $}\vphantom{$\{$}{\nopagebreak[4] \newline%
}renameTm\mbox{\hspace{0.50em}}$ \theta $\mbox{\hspace{0.50em}}{\char `\=}\mbox{\hspace{0.50em}}trTm′\mbox{\hspace{0.50em}}id{\char `\-}app\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}protect\makebox[1.22ex][c]{$ \uparrow $}\mbox{\hspace{0.50em}}$ \theta $\makebox[1.22ex][c]{$ {)} $}\vphantom{$\{$}{\nopagebreak[4] \newline%
}{\char `\-}{\char `\-}\mbox{\hspace{0.50em}}or\vphantom{$\{$}{\nopagebreak[4] \newline%
}{\char `\-}{\char `\-}\mbox{\hspace{0.50em}}renameTm\mbox{\hspace{0.50em}}{\char `\=}\mbox{\hspace{0.50em}}renameTmA\mbox{\hspace{0.50em}}id{\char `\-}app\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{1em}}}

%
%comment:
%renameTm? : ∀ {α β} → (Name α →? Name β)
%                    → Tm α →? Tm β
%renameTm? = renameTmA Maybe.applicative
%
%


~\\~\texttt{renameTm{\char `\?}\mbox{\hspace{0.50em}}{\char `\:}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \forall $}\mbox{\hspace{0.50em}}\{\makebox[1.22ex][c]{$ \alpha $}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \beta $}\}\mbox{\hspace{0.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}Name\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \alpha $}\mbox{\hspace{0.50em}}$ \rightarrow ${\char `\?}\mbox{\hspace{0.50em}}Name\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \beta $}\makebox[1.22ex][c]{$ {)} $}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{10em}}$ \rightarrow $\mbox{\hspace{0.50em}}Tm\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \alpha $}\mbox{\hspace{0.50em}}$ \rightarrow ${\char `\?}\mbox{\hspace{0.50em}}Tm\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \beta $}\vphantom{$\{$}{\nopagebreak[4] \newline%
}renameTm{\char `\?}\mbox{\hspace{0.50em}}{\char `\=}\mbox{\hspace{0.50em}}renameTmA\mbox{\hspace{0.50em}}Maybe{\char `\.}applicative\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{1em}}}

\paragraph{Lifting name functions}

%
%paragraphName: addTm, subtractTm
Any operation  on names can  now be  lifted to terms$:$%


%
%comment:
%addTm : ∀ {α} k → Tm α → Tm (α +ᵂ k)
%addTm = renameTm ∘ addᴺ
%
%subtractTm : ∀ {α} k → Tm (α +ᵂ k) → Tm α
%subtractTm = renameTm ∘ subtractᴺ
%
%exportTm? : ∀ {α} ℓ → Tm (α ↑ ℓ) →? Tm α
%exportTm? = renameTm? ∘ exportName
%
%


~\\~\texttt{addTm\mbox{\hspace{0.50em}}{\char `\:}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \forall $}\mbox{\hspace{0.50em}}\{\makebox[1.22ex][c]{$ \alpha $}\}\mbox{\hspace{0.50em}}k\mbox{\hspace{0.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}Tm\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \alpha $}\mbox{\hspace{0.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}Tm\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}\makebox[1.22ex][c]{$ \alpha $}\mbox{\hspace{0.50em}}{\char `\+}\makebox[0.61ex][c]{ᵂ}\mbox{\hspace{0.50em}}k\makebox[1.22ex][c]{$ {)} $}\vphantom{$\{$}{\nopagebreak[4] \newline%
}addTm\mbox{\hspace{0.50em}}{\char `\=}\mbox{\hspace{0.50em}}renameTm\mbox{\hspace{0.50em}}$ \circ $\mbox{\hspace{0.50em}}add\makebox[0.61ex][c]{ᴺ}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\vphantom{$\{$}{\nopagebreak[4] \newline%
}subtractTm\mbox{\hspace{0.50em}}{\char `\:}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \forall $}\mbox{\hspace{0.50em}}\{\makebox[1.22ex][c]{$ \alpha $}\}\mbox{\hspace{0.50em}}k\mbox{\hspace{0.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}Tm\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}\makebox[1.22ex][c]{$ \alpha $}\mbox{\hspace{0.50em}}{\char `\+}\makebox[0.61ex][c]{ᵂ}\mbox{\hspace{0.50em}}k\makebox[1.22ex][c]{$ {)} $}\mbox{\hspace{0.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}Tm\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \alpha $}\vphantom{$\{$}{\nopagebreak[4] \newline%
}subtractTm\mbox{\hspace{0.50em}}{\char `\=}\mbox{\hspace{0.50em}}renameTm\mbox{\hspace{0.50em}}$ \circ $\mbox{\hspace{0.50em}}subtract\makebox[0.61ex][c]{ᴺ}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\vphantom{$\{$}{\nopagebreak[4] \newline%
}exportTm{\char `\?}\mbox{\hspace{0.50em}}{\char `\:}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \forall $}\mbox{\hspace{0.50em}}\{\makebox[1.22ex][c]{$ \alpha $}\}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{ℓ}\mbox{\hspace{0.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}Tm\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}\makebox[1.22ex][c]{$ \alpha $}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \uparrow $}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{ℓ}\makebox[1.22ex][c]{$ {)} $}\mbox{\hspace{0.50em}}$ \rightarrow ${\char `\?}\mbox{\hspace{0.50em}}Tm\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \alpha $}\vphantom{$\{$}{\nopagebreak[4] \newline%
}exportTm{\char `\?}\mbox{\hspace{0.50em}}{\char `\=}\mbox{\hspace{0.50em}}renameTm{\char `\?}\mbox{\hspace{0.50em}}$ \circ $\mbox{\hspace{0.50em}}exportName\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{1em}}}

%
%paragraphName: coerceTm
While  \texttt{coerceᴺ} can  be  lifted to  terms in  the  same way,  using
    \texttt{trTm′}  directly  enables  to  by-pass  the  \texttt{protect$ \uparrow $}    dynamic tests and directly ``protect'' the inclusion witness with an
    appropriate inclusion rule.%


%
%comment:
%coerceTm : ∀ {α β} → α ⊆ β → Tm α → Tm β
%coerceTm pf = trTm′ id-app (coerceᴺ ∘ ⊆-cong-↑ pf)
%-- or less efficiently:
%-- coerceTm = renameTm ∘ coerceᴺ
%
%


~\\~\texttt{coerceTm\mbox{\hspace{0.50em}}{\char `\:}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \forall $}\mbox{\hspace{0.50em}}\{\makebox[1.22ex][c]{$ \alpha $}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \beta $}\}\mbox{\hspace{0.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \alpha $}\mbox{\hspace{0.50em}}\makebox[2.44ex][c]{$ \subseteq $}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \beta $}\mbox{\hspace{0.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}Tm\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \alpha $}\mbox{\hspace{0.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}Tm\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \beta $}\vphantom{$\{$}{\nopagebreak[4] \newline%
}coerceTm\mbox{\hspace{0.50em}}pf\mbox{\hspace{0.50em}}{\char `\=}\mbox{\hspace{0.50em}}trTm′\mbox{\hspace{0.50em}}id{\char `\-}app\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}coerce\makebox[0.61ex][c]{ᴺ}\mbox{\hspace{0.50em}}$ \circ $\mbox{\hspace{0.50em}}\makebox[2.44ex][c]{$ \subseteq $}{\char `\-}cong{\char `\-}\makebox[1.22ex][c]{$ \uparrow $}\mbox{\hspace{0.50em}}pf\makebox[1.22ex][c]{$ {)} $}\vphantom{$\{$}{\nopagebreak[4] \newline%
}{\char `\-}{\char `\-}\mbox{\hspace{0.50em}}or\mbox{\hspace{0.50em}}less\mbox{\hspace{0.50em}}efficiently{\char `\:}\vphantom{$\{$}{\nopagebreak[4] \newline%
}{\char `\-}{\char `\-}\mbox{\hspace{0.50em}}coerceTm\mbox{\hspace{0.50em}}{\char `\=}\mbox{\hspace{0.50em}}renameTm\mbox{\hspace{0.50em}}$ \circ $\mbox{\hspace{0.50em}}coerce\makebox[0.61ex][c]{ᴺ}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{1em}}}

%
%paragraphName: shiftTm
Lifting \texttt{addᴺ}  to terms  can be  done more  efficiently (than
    using \texttt{protect$ \uparrow $}) as well. Here  the dynamic test performed by
    \texttt{protect$ \uparrow $} is  necessary. However when  the name is  ℓ-free we
    subtract  ℓ to  add it  back  after adding  \texttt{k}. The  function
    \texttt{shiftName} avoids this extra computation, hence the following
    \texttt{shiftTm}$:$%


%
%comment:
%shiftTm : ∀ {α β} k → (α +ᵂ k)⊆ β → Tm α → Tm β
%shiftTm k p = trTm′ id-app (λ ℓ → shiftName ℓ k p)
%-- or less efficiently:
%-- shiftTm k pf = renameTm (coerceᴺ pf ∘ addᴺ k)
%
%


~\\~\texttt{shiftTm\mbox{\hspace{0.50em}}{\char `\:}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \forall $}\mbox{\hspace{0.50em}}\{\makebox[1.22ex][c]{$ \alpha $}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \beta $}\}\mbox{\hspace{0.50em}}k\mbox{\hspace{0.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}\makebox[1.22ex][c]{$ \alpha $}\mbox{\hspace{0.50em}}{\char `\+}\makebox[0.61ex][c]{ᵂ}\mbox{\hspace{0.50em}}k\makebox[1.22ex][c]{$ {)} $}\makebox[2.44ex][c]{$ \subseteq $}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \beta $}\mbox{\hspace{0.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}Tm\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \alpha $}\mbox{\hspace{0.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}Tm\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \beta $}\vphantom{$\{$}{\nopagebreak[4] \newline%
}shiftTm\mbox{\hspace{0.50em}}k\mbox{\hspace{0.50em}}p\mbox{\hspace{0.50em}}{\char `\=}\mbox{\hspace{0.50em}}trTm′\mbox{\hspace{0.50em}}id{\char `\-}app\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}$ \lambda $\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{ℓ}\mbox{\hspace{0.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}shiftName\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{ℓ}\mbox{\hspace{0.50em}}k\mbox{\hspace{0.50em}}p\makebox[1.22ex][c]{$ {)} $}\vphantom{$\{$}{\nopagebreak[4] \newline%
}{\char `\-}{\char `\-}\mbox{\hspace{0.50em}}or\mbox{\hspace{0.50em}}less\mbox{\hspace{0.50em}}efficiently{\char `\:}\vphantom{$\{$}{\nopagebreak[4] \newline%
}{\char `\-}{\char `\-}\mbox{\hspace{0.50em}}shiftTm\mbox{\hspace{0.50em}}k\mbox{\hspace{0.50em}}pf\mbox{\hspace{0.50em}}{\char `\=}\mbox{\hspace{0.50em}}renameTm\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}coerce\makebox[0.61ex][c]{ᴺ}\mbox{\hspace{0.50em}}pf\mbox{\hspace{0.50em}}$ \circ $\mbox{\hspace{0.50em}}add\makebox[0.61ex][c]{ᴺ}\mbox{\hspace{0.50em}}k\makebox[1.22ex][c]{$ {)} $}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{1em}}}

%
%paragraphName: closeTm?
A   special    case   of   \texttt{renameTm{\char `\?}}   is    the   so-called
    \texttt{closeTm{\char `\?}}. This function takes a term in any world and checks
    if the term is closed. If so, the same term is returned in the empty
    world. Otherwise the function fails by returning \texttt{nothing}$:$%


%
%comment:
%closeTm? : ∀ {α} → Tm α →? Tm ø
%closeTm? = renameTm? (const nothing)
%
%


~\\~\texttt{closeTm{\char `\?}\mbox{\hspace{0.50em}}{\char `\:}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \forall $}\mbox{\hspace{0.50em}}\{\makebox[1.22ex][c]{$ \alpha $}\}\mbox{\hspace{0.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}Tm\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \alpha $}\mbox{\hspace{0.50em}}$ \rightarrow ${\char `\?}\mbox{\hspace{0.50em}}Tm\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \emptyset $}\vphantom{$\{$}{\nopagebreak[4] \newline%
}closeTm{\char `\?}\mbox{\hspace{0.50em}}{\char `\=}\mbox{\hspace{0.50em}}renameTm{\char `\?}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}const\mbox{\hspace{0.50em}}nothing\makebox[1.22ex][c]{$ {)} $}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{1em}}}

\paragraph{Capture avoiding substitution}

%
%paragraphName: substVar
To implement  capture avoiding  substitution for  the \texttt{Tm}  type we
    solely  need a  specific \texttt{trName}  function for  \texttt{trTm}.
    Here substitutions are represented as functions from names to terms.
    The function \texttt{substVarTm} handles the case for variables. This
    function is very close to \texttt{protect$ \uparrow $} but extended to functions
    returning terms.%


%
%comment:
%substVarTm : ∀{α β} → (Name α → Tm β) →
%             ∀ ℓ → Name (α ↑ ℓ) → Tm (β ↑ ℓ)
%substVarTm f ℓ x
% with x <ᴺ ℓ
%... | inj₁ x′ = V (x′
%              ⟨-because ⊆-cong-↑ ⊆-ø ℓ -⟩)
%... | inj₂ x′ = shiftTm ℓ (⊆-+-↑ ℓ) (f (x′ ∸ᴺ ℓ))
%
%


~\\~\texttt{substVarTm\mbox{\hspace{0.50em}}{\char `\:}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \forall $}\{\makebox[1.22ex][c]{$ \alpha $}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \beta $}\}\mbox{\hspace{0.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}Name\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \alpha $}\mbox{\hspace{0.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}Tm\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \beta $}\makebox[1.22ex][c]{$ {)} $}\mbox{\hspace{0.50em}}$ \rightarrow $\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{6.50em}}\makebox[1.22ex][c]{$ \forall $}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{ℓ}\mbox{\hspace{0.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}Name\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}\makebox[1.22ex][c]{$ \alpha $}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \uparrow $}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{ℓ}\makebox[1.22ex][c]{$ {)} $}\mbox{\hspace{0.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}Tm\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}\makebox[1.22ex][c]{$ \beta $}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \uparrow $}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{ℓ}\makebox[1.22ex][c]{$ {)} $}\vphantom{$\{$}{\nopagebreak[4] \newline%
}substVarTm\mbox{\hspace{0.50em}}f\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{ℓ}\mbox{\hspace{0.50em}}x\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{0.50em}}with\mbox{\hspace{0.50em}}x\mbox{\hspace{0.50em}}{\char `\<}\makebox[0.61ex][c]{ᴺ}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{ℓ}\vphantom{$\{$}{\nopagebreak[4] \newline%
}{\char `\.}{\char `\.}{\char `\.}\mbox{\hspace{0.50em}}{\char `\|}\mbox{\hspace{0.50em}}inj\makebox[0.61ex][c]{₁}\mbox{\hspace{0.50em}}x′\mbox{\hspace{0.50em}}{\char `\=}\mbox{\hspace{0.50em}}V\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}x′\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{7em}}\makebox[1.22ex][c]{⟨}{\char `\-}because\mbox{\hspace{0.50em}}\makebox[2.44ex][c]{$ \subseteq $}{\char `\-}cong{\char `\-}\makebox[1.22ex][c]{$ \uparrow $}\mbox{\hspace{0.50em}}\makebox[2.44ex][c]{$ \subseteq $}{\char `\-}\makebox[1.22ex][c]{$ \emptyset $}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{ℓ}\mbox{\hspace{0.50em}}{\char `\-}\makebox[1.22ex][c]{⟩}\makebox[1.22ex][c]{$ {)} $}\vphantom{$\{$}{\nopagebreak[4] \newline%
}{\char `\.}{\char `\.}{\char `\.}\mbox{\hspace{0.50em}}{\char `\|}\mbox{\hspace{0.50em}}inj\makebox[0.61ex][c]{₂}\mbox{\hspace{0.50em}}x′\mbox{\hspace{0.50em}}{\char `\=}\mbox{\hspace{0.50em}}shiftTm\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{ℓ}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}\makebox[2.44ex][c]{$ \subseteq $}{\char `\-}{\char `\+}{\char `\-}\makebox[1.22ex][c]{$ \uparrow $}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{ℓ}\makebox[1.22ex][c]{$ {)} $}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}f\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}x′\mbox{\hspace{0.50em}}∸\makebox[0.61ex][c]{ᴺ}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{ℓ}\makebox[1.22ex][c]{$ {)} $}\makebox[1.22ex][c]{$ {)} $}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{1em}}}

%
%paragraphName: substTm
The main function \texttt{substTm} instantiates \texttt{trTm} with
    the identity applicative functor and \texttt{substVarTm}$:$%


%
%comment:
%substTm : ∀ {α β} → (Name α → Tm β)
%                  → Tm α → Tm β
%substTm = trTm id-app ∘ substVarTm
%
%


~\\~\texttt{substTm\mbox{\hspace{0.50em}}{\char `\:}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \forall $}\mbox{\hspace{0.50em}}\{\makebox[1.22ex][c]{$ \alpha $}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \beta $}\}\mbox{\hspace{0.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}Name\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \alpha $}\mbox{\hspace{0.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}Tm\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \beta $}\makebox[1.22ex][c]{$ {)} $}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{9em}}$ \rightarrow $\mbox{\hspace{0.50em}}Tm\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \alpha $}\mbox{\hspace{0.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}Tm\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \beta $}\vphantom{$\{$}{\nopagebreak[4] \newline%
}substTm\mbox{\hspace{0.50em}}{\char `\=}\mbox{\hspace{0.50em}}trTm\mbox{\hspace{0.50em}}id{\char `\-}app\mbox{\hspace{0.50em}}$ \circ $\mbox{\hspace{0.50em}}substVarTm\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{1em}}}

%
%paragraphName: β-red
As an illustration,  the function \texttt{$ \beta ${\char `\-}red} takes the  body of a
    λ-abstraction and  calls \texttt{substTm} with the  substitution that
    replaces 0 with a received replacement term$:$%


%
%comment:
%β-red : ∀ {α} → Tm (α ↑1) → Tm α → Tm α
%β-red {α} f a = substTm (φ ∘ exportName 1) f
%  where φ : Maybe (Name α) → Tm α
%        φ (just x) = V x
%        φ nothing  = a
%
%


~\\~\texttt{\makebox[1.22ex][c]{$ \beta $}{\char `\-}red\mbox{\hspace{0.50em}}{\char `\:}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \forall $}\mbox{\hspace{0.50em}}\{\makebox[1.22ex][c]{$ \alpha $}\}\mbox{\hspace{0.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}Tm\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}\makebox[1.22ex][c]{$ \alpha $}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \uparrow $}1\makebox[1.22ex][c]{$ {)} $}\mbox{\hspace{0.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}Tm\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \alpha $}\mbox{\hspace{0.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}Tm\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \alpha $}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\makebox[1.22ex][c]{$ \beta $}{\char `\-}red\mbox{\hspace{0.50em}}\{\makebox[1.22ex][c]{$ \alpha $}\}\mbox{\hspace{0.50em}}f\mbox{\hspace{0.50em}}a\mbox{\hspace{0.50em}}{\char `\=}\mbox{\hspace{0.50em}}substTm\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}$ \phi $\mbox{\hspace{0.50em}}$ \circ $\mbox{\hspace{0.50em}}exportName\mbox{\hspace{0.50em}}1\makebox[1.22ex][c]{$ {)} $}\mbox{\hspace{0.50em}}f\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{1em}}where\mbox{\hspace{0.50em}}$ \phi $\mbox{\hspace{0.50em}}{\char `\:}\mbox{\hspace{0.50em}}Maybe\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}Name\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \alpha $}\makebox[1.22ex][c]{$ {)} $}\mbox{\hspace{0.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}Tm\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \alpha $}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{4em}}$ \phi $\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}just\mbox{\hspace{0.50em}}x\makebox[1.22ex][c]{$ {)} $}\mbox{\hspace{0.50em}}{\char `\=}\mbox{\hspace{0.50em}}V\mbox{\hspace{0.50em}}x\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{4em}}$ \phi $\mbox{\hspace{0.50em}}nothing\mbox{\hspace{1em}}{\char `\=}\mbox{\hspace{0.50em}}a\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{1em}}}

\subsection{Deciding term $ \alpha $-equivalence}

%
%paragraphName: αEq type
Our next  example focuses  on comparison of  terms. We  first define
    \texttt{$ \alpha $Eq}, where \texttt{$ \alpha $Eq F} is  the type of functions comparing
    \texttt{F} structures.%


%
%comment:
%αEq : (F : World → Set) (α β : World) → Set
%αEq F α β = F α → F β → Bool
%
%


~\\~\texttt{\makebox[1.22ex][c]{$ \alpha $}Eq\mbox{\hspace{0.50em}}{\char `\:}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}F\mbox{\hspace{0.50em}}{\char `\:}\mbox{\hspace{0.50em}}World\mbox{\hspace{0.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}Set\makebox[1.22ex][c]{$ {)} $}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}\makebox[1.22ex][c]{$ \alpha $}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \beta $}\mbox{\hspace{0.50em}}{\char `\:}\mbox{\hspace{0.50em}}World\makebox[1.22ex][c]{$ {)} $}\mbox{\hspace{0.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}Set\vphantom{$\{$}{\nopagebreak[4] \newline%
}\makebox[1.22ex][c]{$ \alpha $}Eq\mbox{\hspace{0.50em}}F\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \alpha $}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \beta $}\mbox{\hspace{0.50em}}{\char `\=}\mbox{\hspace{0.50em}}F\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \alpha $}\mbox{\hspace{0.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}F\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \beta $}\mbox{\hspace{0.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}Bool\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{1em}}}

%
%paragraphName: αeqName
We show that all the subtle work is  done at the level of names in a
    separate and reusable function called \texttt{$ \alpha $eqName}. This function
    takes a  function that compares two  free names and builds  one that
    compares two names under \texttt{ℓ} bindings. It does so by comparing
    both of  them to{~}\texttt{ℓ}. If they  are both bound they  can be
    safely compared using \texttt{{\char `\_}}\texttt{{\char `\=}{\char `\=}ᴺ}\texttt{{\char `\_}} since they now are  of the same type.
    If  they are  both free,  they can  be compared  using the  function
    received as argument. Otherwise they are different.%


%
%comment:
%αeqName : ∀ {α β} ℓ → αEq Name α β
%                    → αEq Name (α ↑ ℓ) (β ↑ ℓ)
%αeqName ℓ Γ x y with x <ᴺ ℓ | y <ᴺ ℓ
%... | inj₁ x′ | inj₁ y′  = x′ ==ᴺ y′
%... | inj₂ x′ | inj₂ y′  = Γ (x′ ∸ᴺ ℓ) (y′ ∸ᴺ ℓ)
%... | _      | _       = false
%
%


~\\~\texttt{\makebox[1.22ex][c]{$ \alpha $}eqName\mbox{\hspace{0.50em}}{\char `\:}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \forall $}\mbox{\hspace{0.50em}}\{\makebox[1.22ex][c]{$ \alpha $}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \beta $}\}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{ℓ}\mbox{\hspace{0.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \alpha $}Eq\mbox{\hspace{0.50em}}Name\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \alpha $}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \beta $}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{10em}}$ \rightarrow $\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \alpha $}Eq\mbox{\hspace{0.50em}}Name\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}\makebox[1.22ex][c]{$ \alpha $}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \uparrow $}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{ℓ}\makebox[1.22ex][c]{$ {)} $}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}\makebox[1.22ex][c]{$ \beta $}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \uparrow $}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{ℓ}\makebox[1.22ex][c]{$ {)} $}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\makebox[1.22ex][c]{$ \alpha $}eqName\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{ℓ}\mbox{\hspace{0.50em}}$ \Gamma $\mbox{\hspace{0.50em}}x\mbox{\hspace{0.50em}}y\mbox{\hspace{0.50em}}with\mbox{\hspace{0.50em}}x\mbox{\hspace{0.50em}}{\char `\<}\makebox[0.61ex][c]{ᴺ}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{ℓ}\mbox{\hspace{0.50em}}{\char `\|}\mbox{\hspace{0.50em}}y\mbox{\hspace{0.50em}}{\char `\<}\makebox[0.61ex][c]{ᴺ}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{ℓ}\vphantom{$\{$}{\nopagebreak[4] \newline%
}{\char `\.}{\char `\.}{\char `\.}\mbox{\hspace{0.50em}}{\char `\|}\mbox{\hspace{0.50em}}inj\makebox[0.61ex][c]{₁}\mbox{\hspace{0.50em}}x′\mbox{\hspace{0.50em}}{\char `\|}\mbox{\hspace{0.50em}}inj\makebox[0.61ex][c]{₁}\mbox{\hspace{0.50em}}y′\mbox{\hspace{1em}}{\char `\=}\mbox{\hspace{0.50em}}x′\mbox{\hspace{0.50em}}{\char `\=}{\char `\=}\makebox[0.61ex][c]{ᴺ}\mbox{\hspace{0.50em}}y′\vphantom{$\{$}{\nopagebreak[4] \newline%
}{\char `\.}{\char `\.}{\char `\.}\mbox{\hspace{0.50em}}{\char `\|}\mbox{\hspace{0.50em}}inj\makebox[0.61ex][c]{₂}\mbox{\hspace{0.50em}}x′\mbox{\hspace{0.50em}}{\char `\|}\mbox{\hspace{0.50em}}inj\makebox[0.61ex][c]{₂}\mbox{\hspace{0.50em}}y′\mbox{\hspace{1em}}{\char `\=}\mbox{\hspace{0.50em}}$ \Gamma $\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}x′\mbox{\hspace{0.50em}}∸\makebox[0.61ex][c]{ᴺ}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{ℓ}\makebox[1.22ex][c]{$ {)} $}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}y′\mbox{\hspace{0.50em}}∸\makebox[0.61ex][c]{ᴺ}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{ℓ}\makebox[1.22ex][c]{$ {)} $}\vphantom{$\{$}{\nopagebreak[4] \newline%
}{\char `\.}{\char `\.}{\char `\.}\mbox{\hspace{0.50em}}{\char `\|}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{{\char `\_}}\mbox{\hspace{3em}}{\char `\|}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{{\char `\_}}\mbox{\hspace{3.50em}}{\char `\=}\mbox{\hspace{0.50em}}false\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{1em}}}

%
%paragraphName: αeqTm
The  \texttt{$ \alpha $eqTm} function  structurally  compares two  terms in  a
    simple way,  only keeping track  of the number of  traversed binders
    and calling \texttt{$ \alpha $eqName} at variables.%


%
%comment:
%αeqTm : ∀ {α β} → αEq Name α β → αEq Tm α β
%αeqTm {α} {β} Γ = go 0 where
%  go : ∀ ℓ → αEq Tm (α ↑ ℓ) (β ↑ ℓ)
%  go ℓ (V x)     (V y)     = αeqName ℓ Γ x y
%  go ℓ (t · u)   (v · w)   = go ℓ t v ∧ go ℓ u w
%  go ℓ (ƛ t)     (ƛ u)     = go (suc ℓ) t u
%  go ℓ (Let t u) (Let v w) = go ℓ t v
%                          ∧ go (suc ℓ) u w
%  go _ _ _                 = false
%
%


~\\~\texttt{\makebox[1.22ex][c]{$ \alpha $}eqTm\mbox{\hspace{0.50em}}{\char `\:}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \forall $}\mbox{\hspace{0.50em}}\{\makebox[1.22ex][c]{$ \alpha $}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \beta $}\}\mbox{\hspace{0.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \alpha $}Eq\mbox{\hspace{0.50em}}Name\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \alpha $}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \beta $}\mbox{\hspace{0.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \alpha $}Eq\mbox{\hspace{0.50em}}Tm\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \alpha $}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \beta $}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\makebox[1.22ex][c]{$ \alpha $}eqTm\mbox{\hspace{0.50em}}\{\makebox[1.22ex][c]{$ \alpha $}\}\mbox{\hspace{0.50em}}\{\makebox[1.22ex][c]{$ \beta $}\}\mbox{\hspace{0.50em}}$ \Gamma $\mbox{\hspace{0.50em}}{\char `\=}\mbox{\hspace{0.50em}}go\mbox{\hspace{0.50em}}0\mbox{\hspace{0.50em}}where\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{1em}}go\mbox{\hspace{0.50em}}{\char `\:}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \forall $}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{ℓ}\mbox{\hspace{0.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \alpha $}Eq\mbox{\hspace{0.50em}}Tm\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}\makebox[1.22ex][c]{$ \alpha $}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \uparrow $}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{ℓ}\makebox[1.22ex][c]{$ {)} $}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}\makebox[1.22ex][c]{$ \beta $}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \uparrow $}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{ℓ}\makebox[1.22ex][c]{$ {)} $}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{1em}}go\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{ℓ}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}V\mbox{\hspace{0.50em}}x\makebox[1.22ex][c]{$ {)} $}\mbox{\hspace{2.50em}}\makebox[1.22ex][c]{$ {(} $}V\mbox{\hspace{0.50em}}y\makebox[1.22ex][c]{$ {)} $}\mbox{\hspace{2.50em}}{\char `\=}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \alpha $}eqName\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{ℓ}\mbox{\hspace{0.50em}}$ \Gamma $\mbox{\hspace{0.50em}}x\mbox{\hspace{0.50em}}y\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{1em}}go\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{ℓ}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}t\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \cdotp $}\mbox{\hspace{0.50em}}u\makebox[1.22ex][c]{$ {)} $}\mbox{\hspace{1.50em}}\makebox[1.22ex][c]{$ {(} $}v\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \cdotp $}\mbox{\hspace{0.50em}}w\makebox[1.22ex][c]{$ {)} $}\mbox{\hspace{1.50em}}{\char `\=}\mbox{\hspace{0.50em}}go\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{ℓ}\mbox{\hspace{0.50em}}t\mbox{\hspace{0.50em}}v\mbox{\hspace{0.50em}}\makebox[2.44ex][c]{$ \wedge $}\mbox{\hspace{0.50em}}go\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{ℓ}\mbox{\hspace{0.50em}}u\mbox{\hspace{0.50em}}w\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{1em}}go\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{ℓ}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}\makebox[1.22ex][c]{ƛ}\mbox{\hspace{0.50em}}t\makebox[1.22ex][c]{$ {)} $}\mbox{\hspace{2.50em}}\makebox[1.22ex][c]{$ {(} $}\makebox[1.22ex][c]{ƛ}\mbox{\hspace{0.50em}}u\makebox[1.22ex][c]{$ {)} $}\mbox{\hspace{2.50em}}{\char `\=}\mbox{\hspace{0.50em}}go\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}suc\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{ℓ}\makebox[1.22ex][c]{$ {)} $}\mbox{\hspace{0.50em}}t\mbox{\hspace{0.50em}}u\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{1em}}go\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{ℓ}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}Let\mbox{\hspace{0.50em}}t\mbox{\hspace{0.50em}}u\makebox[1.22ex][c]{$ {)} $}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}Let\mbox{\hspace{0.50em}}v\mbox{\hspace{0.50em}}w\makebox[1.22ex][c]{$ {)} $}\mbox{\hspace{0.50em}}{\char `\=}\mbox{\hspace{0.50em}}go\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{ℓ}\mbox{\hspace{0.50em}}t\mbox{\hspace{0.50em}}v\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{13em}}\makebox[2.44ex][c]{$ \wedge $}\mbox{\hspace{0.50em}}go\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}suc\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{ℓ}\makebox[1.22ex][c]{$ {)} $}\mbox{\hspace{0.50em}}u\mbox{\hspace{0.50em}}w\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{1em}}go\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{{\char `\_}}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{{\char `\_}}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{{\char `\_}}\mbox{\hspace{8.50em}}{\char `\=}\mbox{\hspace{0.50em}}false\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{1em}}}

\section{Soundness using logical relations\label{soundness}}

%
%paragraphName: why using logical relations?
Since our library is written in a type-safe language, one may wonder
    what soundness properties  are to be proved. Moreover  our names are
    indexed by  worlds and  hold membership  proofs. The  functions over
    names are given  precise types and have been shown  to be type-safe.
    However we still  wish to show that our library  respects a model of
    good behavior with respect to names  and binders. Our model is based
    on  logical  relations  indexed/directed by  types.  This  technique
    \cite{bernardy-10} is independent of this work and enables to define
    a notion  of program equivalence.  We use this technique  to capture
    good behavior of  functions involving names and  binders. Using this
    technique, the set  of specific definitions is kept to  a minimum of
    one  per introduced  type (\texttt{World},  \texttt{Name}, and  \texttt{{\char `\_}}\texttt{$ \subseteq $}\texttt{{\char `\_}}).  One
    proof  per  value  introduced  has  to  be  done,  which  keeps  the
    development modular  and forward-compatible to the  addition of more
    features.%


%
%paragraphName: plan
This section is organized as follows.  First we recall the basics of
    logical relations.  Then we give  a toy  example to practice  a bit.
    Then relations  for worlds, names,  and world inclusions  are given.
    Finally  we make  use of  the construction  to obtain  free theorems
    \cite{wadler-free-89}  about  world-polymorphic  functions  over  the
    \texttt{Tm} type.%


\subsection{Recap of the framework}

%
%paragraphName: type-directed relation
A  relation is  said  to  be type-directed  when  it is  recursively
    defined on the structure of types.  Let \texttt{$ \mathcal{{R}} $} be such a type-directed
    relation, and let $ \tau $ be a type. Then, \texttt{$ \mathcal{{R}} $}$ \tau $ is a relation on values
    of type $ \tau $, namely  \texttt{$ \mathcal{{R}} $}$ \tau $ \texttt{{\char `\:} $ \tau $ $ \rightarrow $ $ \tau $ $ \rightarrow $ Set}. Recall that \texttt{Set}    is also the type of propositions in \textsc{Agda}.%


%
%paragraphName: logical
A type-directed  relation is  called ``logical''  when the  case for
    functions is  defined extensionally.  Here extensionally  means that
    two functions are  related when they produce related  results out of
    related arguments.  Let \texttt{Aᵣ} be  a relation for  the arguments
    and \texttt{Bᵣ} a relation for  results. Two functions \texttt{f₁} and
    \texttt{f₂} are  related if and only  if for every pair  of arguments
    \texttt{$ {(} $x₁{\char `\,} x₂$ {)} $} related  by \texttt{Aᵣ},  the results  \texttt{f₁ x₁}    and \texttt{f₂ x₂} are related by  \texttt{Bᵣ}. This definition can be
    given in \textsc{Agda} as well$:$%


%
%comment:
%  RelatedFunctions Aᵣ Bᵣ f₁ f₂ =
%              ∀ {x₁ x₂} → Aᵣ x₁ x₂
%                        → Bᵣ (f₁ x₁) (f₂ x₂)
%
%


~\\~\texttt{\mbox{\hspace{1em}}RelatedFunctions\mbox{\hspace{0.50em}}A\makebox[0.61ex][c]{ᵣ}\mbox{\hspace{0.50em}}B\makebox[0.61ex][c]{ᵣ}\mbox{\hspace{0.50em}}f\makebox[0.61ex][c]{₁}\mbox{\hspace{0.50em}}f\makebox[0.61ex][c]{₂}\mbox{\hspace{0.50em}}{\char `\=}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{7em}}\makebox[1.22ex][c]{$ \forall $}\mbox{\hspace{0.50em}}\{x\makebox[0.61ex][c]{₁}\mbox{\hspace{0.50em}}x\makebox[0.61ex][c]{₂}\}\mbox{\hspace{0.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}A\makebox[0.61ex][c]{ᵣ}\mbox{\hspace{0.50em}}x\makebox[0.61ex][c]{₁}\mbox{\hspace{0.50em}}x\makebox[0.61ex][c]{₂}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{12em}}$ \rightarrow $\mbox{\hspace{0.50em}}B\makebox[0.61ex][c]{ᵣ}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}f\makebox[0.61ex][c]{₁}\mbox{\hspace{0.50em}}x\makebox[0.61ex][c]{₁}\makebox[1.22ex][c]{$ {)} $}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}f\makebox[0.61ex][c]{₂}\mbox{\hspace{0.50em}}x\makebox[0.61ex][c]{₂}\makebox[1.22ex][c]{$ {)} $}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{1em}}}

%
%paragraphName: name conventions
We say that a program or a  value fits a logical relation when it is
    related to itself by the relation indexed by its type. We say that a
    logical relation is  universal if every well-typed  program fits the
    logical relation. This notion  of universality was originally coined
    by John Reynolds as  the ``Abstraction Theorem'' \cite{reynolds-83}.
    We call the ``\textsc{Agda} logical relation'' the one defined by Bernardy
    et  al.  \cite{bernardy-10} for  a  $ \mathcal{{P}{T}{S}} $  (pure type  system)  and
    naturally extended  as they  suggest to  other features  of \textsc{Agda}.
    While no  complete mechanized proof has  been done for this  we will
    consider the \textsc{Agda} logical relation as universal.%


%
%paragraphName: no universe-polymorphism
To simplify  matters, the  definitions shown  here are  not universe
    polymorphic. You  can find  universe-polymorphic definitions  in our
    complete \textsc{Agda} development \cite{pouillard-11}.%


%
%paragraphName: the universe technique
To  formally  define   a  logical  relation  indexed   by  types,  a
    common  technique  is  to  first inductively  define  the  structure
    of  types.  This   is  known  as  a  ``universe   of  codes''  \texttt{U}.
    Then  one defines  a  function  called \texttt{El}  from  codes to  types.
    Finally one  defines by  induction a function  called \texttt{⟦}\texttt{{\char `\_}}\texttt{⟧} from
    codes  to relations  on  elements  of type  described  by the  given
    code.  In \textsc{Agda}  the \texttt{⟦}\texttt{{\char `\_}}\texttt{⟧}  function has  the following  type$:$
    \texttt{$ {(} $$ \tau $ {\char `\:} U$ {)} $ $ \rightarrow $ El $ \tau $ $ \rightarrow $ El $ \tau $ $ \rightarrow $ Set}.  Because,  when  types  contain
    variables, a good deal of complexity is added to this scheme, we opt
    for a lighter scheme. We do not define \texttt{U}, \texttt{El}, and \texttt{⟦}\texttt{{\char `\_}}\texttt{⟧}.%


%
%paragraphName: ⟦Π⟧
Instead, for each type constructor $ \kappa $, we define a relation \texttt{⟦}$ \kappa $\texttt{⟧}    For  the  function  type  constructor  the  \texttt{RelatedFunctions}    definition  above  is  a  good   start.  Actually  this  is  a  fine
    definition  for  non-dependent   functions.  The  dependent  version
    of  \texttt{RelatedFunctions}, called  \texttt{⟦$ \Pi $⟧}  here, passes  the
    relation argument \texttt{Aᵣ x₁ x₂} called \texttt{xᵣ} to the relation
    for  results  \texttt{Bᵣ}. In  short  the  relation for  results  now
    depends on  the relation  for arguments. Here  is the  definition in
    \textsc{Agda}$:$%


%
%comment:
%  ⟦Π⟧ Aᵣ Bᵣ f₁ f₂ = ∀ {x₁ x₂} (xᵣ : Aᵣ x₁ x₂)
%                      → Bᵣ xᵣ (f₁ x₁) (f₂ x₂)
%
%


~\\~\texttt{\mbox{\hspace{1em}}\makebox[1.22ex][c]{⟦}$ \Pi $\makebox[1.22ex][c]{⟧}\mbox{\hspace{0.50em}}A\makebox[0.61ex][c]{ᵣ}\mbox{\hspace{0.50em}}B\makebox[0.61ex][c]{ᵣ}\mbox{\hspace{0.50em}}f\makebox[0.61ex][c]{₁}\mbox{\hspace{0.50em}}f\makebox[0.61ex][c]{₂}\mbox{\hspace{0.50em}}{\char `\=}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \forall $}\mbox{\hspace{0.50em}}\{x\makebox[0.61ex][c]{₁}\mbox{\hspace{0.50em}}x\makebox[0.61ex][c]{₂}\}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}x\makebox[0.61ex][c]{ᵣ}\mbox{\hspace{0.50em}}{\char `\:}\mbox{\hspace{0.50em}}A\makebox[0.61ex][c]{ᵣ}\mbox{\hspace{0.50em}}x\makebox[0.61ex][c]{₁}\mbox{\hspace{0.50em}}x\makebox[0.61ex][c]{₂}\makebox[1.22ex][c]{$ {)} $}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{11em}}$ \rightarrow $\mbox{\hspace{0.50em}}B\makebox[0.61ex][c]{ᵣ}\mbox{\hspace{0.50em}}x\makebox[0.61ex][c]{ᵣ}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}f\makebox[0.61ex][c]{₁}\mbox{\hspace{0.50em}}x\makebox[0.61ex][c]{₁}\makebox[1.22ex][c]{$ {)} $}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}f\makebox[0.61ex][c]{₂}\mbox{\hspace{0.50em}}x\makebox[0.61ex][c]{₂}\makebox[1.22ex][c]{$ {)} $}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{1em}}}

%
%paragraphName: ⟦→⟧, ⟦∀⟧, and ⟦Set₀⟧
Note  that this  definition  generalizes the  case of  non-dependent
    functions and  universal quantifications as well.  For non-dependent
    functions we simply provide a relation for results which ignores its
    first  argument (equivalent  to  \texttt{RelatedFunctions} and  noted
    \texttt{{\char `\_}⟦$ \rightarrow $⟧{\char `\_}} from now on). For universal quantifications, since the
    arguments are types, all we need is a relation for types (members of
    \texttt{Set₀}) themselves. Following our  convention we call this relation
    \texttt{⟦}\texttt{Set₀}\texttt{⟧}, its  definition is  the set  of relations  between its
    arguments$:$%


%
%comment:
%  ⟦Set₀⟧ : Set₀ → Set₀ → Set₁
%  ⟦Set₀⟧ A₁ A₂ = A₁ → A₂ → Set₀
%
%


~\\~\texttt{\mbox{\hspace{1em}}\makebox[1.22ex][c]{⟦}Set₀\makebox[1.22ex][c]{⟧}\mbox{\hspace{0.50em}}{\char `\:}\mbox{\hspace{0.50em}}Set₀\mbox{\hspace{0.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}Set₀\mbox{\hspace{0.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}Set\makebox[0.61ex][c]{₁}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{1em}}\makebox[1.22ex][c]{⟦}Set₀\makebox[1.22ex][c]{⟧}\mbox{\hspace{0.50em}}A\makebox[0.61ex][c]{₁}\mbox{\hspace{0.50em}}A\makebox[0.61ex][c]{₂}\mbox{\hspace{0.50em}}{\char `\=}\mbox{\hspace{0.50em}}A\makebox[0.61ex][c]{₁}\mbox{\hspace{0.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}A\makebox[0.61ex][c]{₂}\mbox{\hspace{0.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}Set₀\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{1em}}}

%
%paragraphName: ⟦_⟧ as a macro
For reference,  full definitions for  core type theory are  given in
    figure \ref{rellogfig}.  We now have all the building  blocks of the
    meta-function \texttt{⟦}\texttt{{\char `\_}}\texttt{⟧} and we will  not materialize it more here. We
    will apply the  \texttt{⟦}\texttt{{\char `\_}}\texttt{⟧} function manually. To this  end it suffices
    to  replace each  constructor $ \kappa $  by  \texttt{⟦}$ \kappa $\texttt{⟧},  each non  dependent
    arrow by  \texttt{⟦$ \rightarrow $⟧}, each  dependent arrow  \texttt{$ {(} $x {\char `\:} A$ {)} $ $ \rightarrow $ B} by
    \texttt{⟨ xᵣ ∶ ⟦ A ⟧ ⟩⟦$ \rightarrow $⟧ ⟦ B ⟧}.  By  convention  we  subscript  the
    variables by \texttt{r}. Applications are translated to applications.
    Because of dependent  types, this translation has to  be extended to
    all  terms but  we will  not  do it  here.  Finally here  are a  few
    examples of the manual use of the \texttt{⟦}\texttt{{\char `\_}}\texttt{⟧} function$:$%


%
%comment:
%  ⟦ ℕ → ℕ → Bool ⟧ =
%  ⟦ℕ⟧ ⟦→⟧ ⟦ℕ⟧ ⟦→⟧ ⟦Bool⟧ =
%  λ f₁ f₂ →
%    ∀ {x₁ x₂} (xᵣ : ⟦ℕ⟧ x₁ x₂)
%      {y₁ y₂} (yᵣ : ⟦ℕ⟧ y₁ y₂)
%    → ⟦Bool⟧ (f₁ x₁ y₁) (f₂ x₂ y₂)
%
%


~\\~\texttt{\mbox{\hspace{1em}}\makebox[1.22ex][c]{⟦}\mbox{\hspace{0.50em}}\makebox[2.44ex][c]{$ \mathbb{{N}} $}\mbox{\hspace{0.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}\makebox[2.44ex][c]{$ \mathbb{{N}} $}\mbox{\hspace{0.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}Bool\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{⟧}\mbox{\hspace{0.50em}}{\char `\=}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{1em}}\makebox[1.22ex][c]{⟦}\makebox[2.44ex][c]{$ \mathbb{{N}} $}\makebox[1.22ex][c]{⟧}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{⟦}$ \rightarrow $\makebox[1.22ex][c]{⟧}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{⟦}\makebox[2.44ex][c]{$ \mathbb{{N}} $}\makebox[1.22ex][c]{⟧}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{⟦}$ \rightarrow $\makebox[1.22ex][c]{⟧}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{⟦}Bool\makebox[1.22ex][c]{⟧}\mbox{\hspace{0.50em}}{\char `\=}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{1em}}$ \lambda $\mbox{\hspace{0.50em}}f\makebox[0.61ex][c]{₁}\mbox{\hspace{0.50em}}f\makebox[0.61ex][c]{₂}\mbox{\hspace{0.50em}}$ \rightarrow $\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{2em}}\makebox[1.22ex][c]{$ \forall $}\mbox{\hspace{0.50em}}\{x\makebox[0.61ex][c]{₁}\mbox{\hspace{0.50em}}x\makebox[0.61ex][c]{₂}\}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}x\makebox[0.61ex][c]{ᵣ}\mbox{\hspace{0.50em}}{\char `\:}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{⟦}\makebox[2.44ex][c]{$ \mathbb{{N}} $}\makebox[1.22ex][c]{⟧}\mbox{\hspace{0.50em}}x\makebox[0.61ex][c]{₁}\mbox{\hspace{0.50em}}x\makebox[0.61ex][c]{₂}\makebox[1.22ex][c]{$ {)} $}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{3em}}\{y\makebox[0.61ex][c]{₁}\mbox{\hspace{0.50em}}y\makebox[0.61ex][c]{₂}\}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}y\makebox[0.61ex][c]{ᵣ}\mbox{\hspace{0.50em}}{\char `\:}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{⟦}\makebox[2.44ex][c]{$ \mathbb{{N}} $}\makebox[1.22ex][c]{⟧}\mbox{\hspace{0.50em}}y\makebox[0.61ex][c]{₁}\mbox{\hspace{0.50em}}y\makebox[0.61ex][c]{₂}\makebox[1.22ex][c]{$ {)} $}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{2em}}$ \rightarrow $\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{⟦}Bool\makebox[1.22ex][c]{⟧}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}f\makebox[0.61ex][c]{₁}\mbox{\hspace{0.50em}}x\makebox[0.61ex][c]{₁}\mbox{\hspace{0.50em}}y\makebox[0.61ex][c]{₁}\makebox[1.22ex][c]{$ {)} $}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}f\makebox[0.61ex][c]{₂}\mbox{\hspace{0.50em}}x\makebox[0.61ex][c]{₂}\mbox{\hspace{0.50em}}y\makebox[0.61ex][c]{₂}\makebox[1.22ex][c]{$ {)} $}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{1em}}}

%
%comment:
%  ⟦ (A : Set₀) → A → A ⟧ =
%  ⟦Π⟧ ⟦Set₀⟧ (λ Aᵣ → Aᵣ ⟦→⟧ Aᵣ) =
%  λ f₁ f₂ →
%    ∀ {A₁ A₂} (Aᵣ : A₁ → A₂ → Set₀)
%      {x₁ x₂} (xᵣ : Aᵣ x₁ x₂)
%    → Aᵣ (f₁ A₁ x₁) (f₂ A₂ x₂)
%
%


~\\~\texttt{\mbox{\hspace{1em}}\makebox[1.22ex][c]{⟦}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}A\mbox{\hspace{0.50em}}{\char `\:}\mbox{\hspace{0.50em}}Set₀\makebox[1.22ex][c]{$ {)} $}\mbox{\hspace{0.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}A\mbox{\hspace{0.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}A\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{⟧}\mbox{\hspace{0.50em}}{\char `\=}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{1em}}\makebox[1.22ex][c]{⟦}$ \Pi $\makebox[1.22ex][c]{⟧}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{⟦}Set₀\makebox[1.22ex][c]{⟧}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}$ \lambda $\mbox{\hspace{0.50em}}A\makebox[0.61ex][c]{ᵣ}\mbox{\hspace{0.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}A\makebox[0.61ex][c]{ᵣ}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{⟦}$ \rightarrow $\makebox[1.22ex][c]{⟧}\mbox{\hspace{0.50em}}A\makebox[0.61ex][c]{ᵣ}\makebox[1.22ex][c]{$ {)} $}\mbox{\hspace{0.50em}}{\char `\=}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{1em}}$ \lambda $\mbox{\hspace{0.50em}}f\makebox[0.61ex][c]{₁}\mbox{\hspace{0.50em}}f\makebox[0.61ex][c]{₂}\mbox{\hspace{0.50em}}$ \rightarrow $\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{2em}}\makebox[1.22ex][c]{$ \forall $}\mbox{\hspace{0.50em}}\{A\makebox[0.61ex][c]{₁}\mbox{\hspace{0.50em}}A\makebox[0.61ex][c]{₂}\}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}A\makebox[0.61ex][c]{ᵣ}\mbox{\hspace{0.50em}}{\char `\:}\mbox{\hspace{0.50em}}A\makebox[0.61ex][c]{₁}\mbox{\hspace{0.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}A\makebox[0.61ex][c]{₂}\mbox{\hspace{0.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}Set₀\makebox[1.22ex][c]{$ {)} $}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{3em}}\{x\makebox[0.61ex][c]{₁}\mbox{\hspace{0.50em}}x\makebox[0.61ex][c]{₂}\}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}x\makebox[0.61ex][c]{ᵣ}\mbox{\hspace{0.50em}}{\char `\:}\mbox{\hspace{0.50em}}A\makebox[0.61ex][c]{ᵣ}\mbox{\hspace{0.50em}}x\makebox[0.61ex][c]{₁}\mbox{\hspace{0.50em}}x\makebox[0.61ex][c]{₂}\makebox[1.22ex][c]{$ {)} $}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{2em}}$ \rightarrow $\mbox{\hspace{0.50em}}A\makebox[0.61ex][c]{ᵣ}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}f\makebox[0.61ex][c]{₁}\mbox{\hspace{0.50em}}A\makebox[0.61ex][c]{₁}\mbox{\hspace{0.50em}}x\makebox[0.61ex][c]{₁}\makebox[1.22ex][c]{$ {)} $}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}f\makebox[0.61ex][c]{₂}\mbox{\hspace{0.50em}}A\makebox[0.61ex][c]{₂}\mbox{\hspace{0.50em}}x\makebox[0.61ex][c]{₂}\makebox[1.22ex][c]{$ {)} $}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{1em}}}

%
%comment:
%  -- Using the notation instead of ⟦Π⟧:
%  ⟦ (A : Set₀) → List A ⟧ =
%  ⟨ Aᵣ ∶ ⟦Set₀⟧ ⟩⟦→⟧ ⟦List⟧ Aᵣ =
%  λ l₁ l₂ →
%    ∀ {A₁ A₂} (Aᵣ : A₁ → A₂ → Set₀)
%    → ⟦List⟧ Aᵣ (l₁ A₁) (l₂ A₂)
%
%


~\\~\texttt{\mbox{\hspace{1em}}{\char `\-}{\char `\-}\mbox{\hspace{0.50em}}Using\mbox{\hspace{0.50em}}the\mbox{\hspace{0.50em}}notation\mbox{\hspace{0.50em}}instead\mbox{\hspace{0.50em}}of\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{⟦}$ \Pi $\makebox[1.22ex][c]{⟧}{\char `\:}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{1em}}\makebox[1.22ex][c]{⟦}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}A\mbox{\hspace{0.50em}}{\char `\:}\mbox{\hspace{0.50em}}Set₀\makebox[1.22ex][c]{$ {)} $}\mbox{\hspace{0.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}List\mbox{\hspace{0.50em}}A\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{⟧}\mbox{\hspace{0.50em}}{\char `\=}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{1em}}\makebox[1.22ex][c]{⟨}\mbox{\hspace{0.50em}}A\makebox[0.61ex][c]{ᵣ}\mbox{\hspace{0.50em}}∶\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{⟦}Set₀\makebox[1.22ex][c]{⟧}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{⟩}\makebox[1.22ex][c]{⟦}$ \rightarrow $\makebox[1.22ex][c]{⟧}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{⟦}List\makebox[1.22ex][c]{⟧}\mbox{\hspace{0.50em}}A\makebox[0.61ex][c]{ᵣ}\mbox{\hspace{0.50em}}{\char `\=}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{1em}}$ \lambda $\mbox{\hspace{0.50em}}l\makebox[0.61ex][c]{₁}\mbox{\hspace{0.50em}}l\makebox[0.61ex][c]{₂}\mbox{\hspace{0.50em}}$ \rightarrow $\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{2em}}\makebox[1.22ex][c]{$ \forall $}\mbox{\hspace{0.50em}}\{A\makebox[0.61ex][c]{₁}\mbox{\hspace{0.50em}}A\makebox[0.61ex][c]{₂}\}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}A\makebox[0.61ex][c]{ᵣ}\mbox{\hspace{0.50em}}{\char `\:}\mbox{\hspace{0.50em}}A\makebox[0.61ex][c]{₁}\mbox{\hspace{0.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}A\makebox[0.61ex][c]{₂}\mbox{\hspace{0.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}Set₀\makebox[1.22ex][c]{$ {)} $}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{2em}}$ \rightarrow $\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{⟦}List\makebox[1.22ex][c]{⟧}\mbox{\hspace{0.50em}}A\makebox[0.61ex][c]{ᵣ}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}l\makebox[0.61ex][c]{₁}\mbox{\hspace{0.50em}}A\makebox[0.61ex][c]{₁}\makebox[1.22ex][c]{$ {)} $}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}l\makebox[0.61ex][c]{₂}\mbox{\hspace{0.50em}}A\makebox[0.61ex][c]{₂}\makebox[1.22ex][c]{$ {)} $}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{1em}}}

\begin{figure*}[]
%
%comment:
%    ⟦Set₀⟧ : ∀ (A₁ A₂ : Set₀) → Set₁
%    ⟦Set₀⟧ A₁ A₂ = A₁ → A₂ → Set₀
%
%    ⟦Set₁⟧ : ∀ (A₁ A₂ : Set₁) → Set₂
%    ⟦Set₁⟧ A₁ A₂ = A₁ → A₂ → Set₁
%
%    _⟦→⟧_ : ∀ {A₁ A₂ B₁ B₂} → ⟦Set₀⟧ A₁ A₂ → ⟦Set₀⟧ B₁ B₂ → ⟦Set₀⟧ (A₁ → B₁) (A₂ → B₂)
%    Aᵣ ⟦→⟧ Bᵣ = λ f₁ f₂ → ∀ {x₁ x₂} → Aᵣ x₁ x₂ → Bᵣ (f₁ x₁) (f₂ x₂)
%
%    infixr 0 _⟦→⟧_
%
%    ⟦Π⟧ : ∀ {A₁ A₂} (Aᵣ : ⟦Set₀⟧ A₁ A₂)
%            {B₁ B₂} (Bᵣ : (Aᵣ ⟦→⟧ ⟦Set₀⟧) B₁ B₂)
%          → ((x : A₁) → B₁ x) → ((x : A₂) → B₂ x) → Set₁
%    ⟦Π⟧ Aᵣ Bᵣ = λ f₁ f₂ → ∀ {x₁ x₂} (xᵣ : Aᵣ x₁ x₂) → Bᵣ xᵣ (f₁ x₁) (f₂ x₂)
%
%    syntax ⟦Π⟧ Aᵣ (λ xᵣ → f) = ⟨ xᵣ ∶ Aᵣ ⟩⟦→⟧ f
%
%    ⟦∀⟧ : ∀ {A₁ A₂} (Aᵣ : ⟦Set₀⟧ A₁ A₂)
%            {B₁ B₂} (Bᵣ : (⟦Set₀⟧ ⟦→⟧ ⟦Set₀⟧) B₁ B₂)
%          → ⟦Set₁⟧ ({x : A₁} → B₁ x) ({x : A₂} → B₂ x)
%    ⟦∀⟧ Aᵣ Bᵣ = λ f₁ f₂ → ∀ {x₁ x₂} (xᵣ : Aᵣ x₁ x₂) → Bᵣ xᵣ (f₁ {x₁}) (f₂ {x₂})
%
%    syntax ⟦∀⟧ Aᵣ (λ xᵣ → f) = ∀⟨ xᵣ ∶ Aᵣ ⟩⟦→⟧ f
%
%


~\\~\texttt{\mbox{\hspace{2em}}\makebox[1.22ex][c]{⟦}Set₀\makebox[1.22ex][c]{⟧}\mbox{\hspace{0.50em}}{\char `\:}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \forall $}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}A\makebox[0.61ex][c]{₁}\mbox{\hspace{0.50em}}A\makebox[0.61ex][c]{₂}\mbox{\hspace{0.50em}}{\char `\:}\mbox{\hspace{0.50em}}Set₀\makebox[1.22ex][c]{$ {)} $}\mbox{\hspace{0.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}Set\makebox[0.61ex][c]{₁}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{2em}}\makebox[1.22ex][c]{⟦}Set₀\makebox[1.22ex][c]{⟧}\mbox{\hspace{0.50em}}A\makebox[0.61ex][c]{₁}\mbox{\hspace{0.50em}}A\makebox[0.61ex][c]{₂}\mbox{\hspace{0.50em}}{\char `\=}\mbox{\hspace{0.50em}}A\makebox[0.61ex][c]{₁}\mbox{\hspace{0.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}A\makebox[0.61ex][c]{₂}\mbox{\hspace{0.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}Set₀\vphantom{$\{$}{\nopagebreak[4] \newline%
}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{2em}}\makebox[1.22ex][c]{⟦}Set\makebox[0.61ex][c]{₁}\makebox[1.22ex][c]{⟧}\mbox{\hspace{0.50em}}{\char `\:}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \forall $}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}A\makebox[0.61ex][c]{₁}\mbox{\hspace{0.50em}}A\makebox[0.61ex][c]{₂}\mbox{\hspace{0.50em}}{\char `\:}\mbox{\hspace{0.50em}}Set\makebox[0.61ex][c]{₁}\makebox[1.22ex][c]{$ {)} $}\mbox{\hspace{0.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}Set\makebox[0.61ex][c]{₂}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{2em}}\makebox[1.22ex][c]{⟦}Set\makebox[0.61ex][c]{₁}\makebox[1.22ex][c]{⟧}\mbox{\hspace{0.50em}}A\makebox[0.61ex][c]{₁}\mbox{\hspace{0.50em}}A\makebox[0.61ex][c]{₂}\mbox{\hspace{0.50em}}{\char `\=}\mbox{\hspace{0.50em}}A\makebox[0.61ex][c]{₁}\mbox{\hspace{0.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}A\makebox[0.61ex][c]{₂}\mbox{\hspace{0.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}Set\makebox[0.61ex][c]{₁}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{2em}}\makebox[1.22ex][c]{{\char `\_}}\makebox[1.22ex][c]{⟦}$ \rightarrow $\makebox[1.22ex][c]{⟧}\makebox[1.22ex][c]{{\char `\_}}\mbox{\hspace{0.50em}}{\char `\:}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \forall $}\mbox{\hspace{0.50em}}\{A\makebox[0.61ex][c]{₁}\mbox{\hspace{0.50em}}A\makebox[0.61ex][c]{₂}\mbox{\hspace{0.50em}}B\makebox[0.61ex][c]{₁}\mbox{\hspace{0.50em}}B\makebox[0.61ex][c]{₂}\}\mbox{\hspace{0.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{⟦}Set₀\makebox[1.22ex][c]{⟧}\mbox{\hspace{0.50em}}A\makebox[0.61ex][c]{₁}\mbox{\hspace{0.50em}}A\makebox[0.61ex][c]{₂}\mbox{\hspace{0.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{⟦}Set₀\makebox[1.22ex][c]{⟧}\mbox{\hspace{0.50em}}B\makebox[0.61ex][c]{₁}\mbox{\hspace{0.50em}}B\makebox[0.61ex][c]{₂}\mbox{\hspace{0.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{⟦}Set₀\makebox[1.22ex][c]{⟧}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}A\makebox[0.61ex][c]{₁}\mbox{\hspace{0.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}B\makebox[0.61ex][c]{₁}\makebox[1.22ex][c]{$ {)} $}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}A\makebox[0.61ex][c]{₂}\mbox{\hspace{0.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}B\makebox[0.61ex][c]{₂}\makebox[1.22ex][c]{$ {)} $}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{2em}}A\makebox[0.61ex][c]{ᵣ}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{⟦}$ \rightarrow $\makebox[1.22ex][c]{⟧}\mbox{\hspace{0.50em}}B\makebox[0.61ex][c]{ᵣ}\mbox{\hspace{0.50em}}{\char `\=}\mbox{\hspace{0.50em}}$ \lambda $\mbox{\hspace{0.50em}}f\makebox[0.61ex][c]{₁}\mbox{\hspace{0.50em}}f\makebox[0.61ex][c]{₂}\mbox{\hspace{0.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \forall $}\mbox{\hspace{0.50em}}\{x\makebox[0.61ex][c]{₁}\mbox{\hspace{0.50em}}x\makebox[0.61ex][c]{₂}\}\mbox{\hspace{0.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}A\makebox[0.61ex][c]{ᵣ}\mbox{\hspace{0.50em}}x\makebox[0.61ex][c]{₁}\mbox{\hspace{0.50em}}x\makebox[0.61ex][c]{₂}\mbox{\hspace{0.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}B\makebox[0.61ex][c]{ᵣ}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}f\makebox[0.61ex][c]{₁}\mbox{\hspace{0.50em}}x\makebox[0.61ex][c]{₁}\makebox[1.22ex][c]{$ {)} $}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}f\makebox[0.61ex][c]{₂}\mbox{\hspace{0.50em}}x\makebox[0.61ex][c]{₂}\makebox[1.22ex][c]{$ {)} $}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{2em}}infixr\mbox{\hspace{0.50em}}0\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{{\char `\_}}\makebox[1.22ex][c]{⟦}$ \rightarrow $\makebox[1.22ex][c]{⟧}\makebox[1.22ex][c]{{\char `\_}}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{2em}}\makebox[1.22ex][c]{⟦}$ \Pi $\makebox[1.22ex][c]{⟧}\mbox{\hspace{0.50em}}{\char `\:}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \forall $}\mbox{\hspace{0.50em}}\{A\makebox[0.61ex][c]{₁}\mbox{\hspace{0.50em}}A\makebox[0.61ex][c]{₂}\}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}A\makebox[0.61ex][c]{ᵣ}\mbox{\hspace{0.50em}}{\char `\:}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{⟦}Set₀\makebox[1.22ex][c]{⟧}\mbox{\hspace{0.50em}}A\makebox[0.61ex][c]{₁}\mbox{\hspace{0.50em}}A\makebox[0.61ex][c]{₂}\makebox[1.22ex][c]{$ {)} $}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{6em}}\{B\makebox[0.61ex][c]{₁}\mbox{\hspace{0.50em}}B\makebox[0.61ex][c]{₂}\}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}B\makebox[0.61ex][c]{ᵣ}\mbox{\hspace{0.50em}}{\char `\:}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}A\makebox[0.61ex][c]{ᵣ}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{⟦}$ \rightarrow $\makebox[1.22ex][c]{⟧}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{⟦}Set₀\makebox[1.22ex][c]{⟧}\makebox[1.22ex][c]{$ {)} $}\mbox{\hspace{0.50em}}B\makebox[0.61ex][c]{₁}\mbox{\hspace{0.50em}}B\makebox[0.61ex][c]{₂}\makebox[1.22ex][c]{$ {)} $}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{5em}}$ \rightarrow $\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}\makebox[1.22ex][c]{$ {(} $}x\mbox{\hspace{0.50em}}{\char `\:}\mbox{\hspace{0.50em}}A\makebox[0.61ex][c]{₁}\makebox[1.22ex][c]{$ {)} $}\mbox{\hspace{0.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}B\makebox[0.61ex][c]{₁}\mbox{\hspace{0.50em}}x\makebox[1.22ex][c]{$ {)} $}\mbox{\hspace{0.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}\makebox[1.22ex][c]{$ {(} $}x\mbox{\hspace{0.50em}}{\char `\:}\mbox{\hspace{0.50em}}A\makebox[0.61ex][c]{₂}\makebox[1.22ex][c]{$ {)} $}\mbox{\hspace{0.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}B\makebox[0.61ex][c]{₂}\mbox{\hspace{0.50em}}x\makebox[1.22ex][c]{$ {)} $}\mbox{\hspace{0.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}Set\makebox[0.61ex][c]{₁}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{2em}}\makebox[1.22ex][c]{⟦}$ \Pi $\makebox[1.22ex][c]{⟧}\mbox{\hspace{0.50em}}A\makebox[0.61ex][c]{ᵣ}\mbox{\hspace{0.50em}}B\makebox[0.61ex][c]{ᵣ}\mbox{\hspace{0.50em}}{\char `\=}\mbox{\hspace{0.50em}}$ \lambda $\mbox{\hspace{0.50em}}f\makebox[0.61ex][c]{₁}\mbox{\hspace{0.50em}}f\makebox[0.61ex][c]{₂}\mbox{\hspace{0.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \forall $}\mbox{\hspace{0.50em}}\{x\makebox[0.61ex][c]{₁}\mbox{\hspace{0.50em}}x\makebox[0.61ex][c]{₂}\}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}x\makebox[0.61ex][c]{ᵣ}\mbox{\hspace{0.50em}}{\char `\:}\mbox{\hspace{0.50em}}A\makebox[0.61ex][c]{ᵣ}\mbox{\hspace{0.50em}}x\makebox[0.61ex][c]{₁}\mbox{\hspace{0.50em}}x\makebox[0.61ex][c]{₂}\makebox[1.22ex][c]{$ {)} $}\mbox{\hspace{0.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}B\makebox[0.61ex][c]{ᵣ}\mbox{\hspace{0.50em}}x\makebox[0.61ex][c]{ᵣ}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}f\makebox[0.61ex][c]{₁}\mbox{\hspace{0.50em}}x\makebox[0.61ex][c]{₁}\makebox[1.22ex][c]{$ {)} $}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}f\makebox[0.61ex][c]{₂}\mbox{\hspace{0.50em}}x\makebox[0.61ex][c]{₂}\makebox[1.22ex][c]{$ {)} $}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{2em}}syntax\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{⟦}$ \Pi $\makebox[1.22ex][c]{⟧}\mbox{\hspace{0.50em}}A\makebox[0.61ex][c]{ᵣ}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}$ \lambda $\mbox{\hspace{0.50em}}x\makebox[0.61ex][c]{ᵣ}\mbox{\hspace{0.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}f\makebox[1.22ex][c]{$ {)} $}\mbox{\hspace{0.50em}}{\char `\=}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{⟨}\mbox{\hspace{0.50em}}x\makebox[0.61ex][c]{ᵣ}\mbox{\hspace{0.50em}}∶\mbox{\hspace{0.50em}}A\makebox[0.61ex][c]{ᵣ}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{⟩}\makebox[1.22ex][c]{⟦}$ \rightarrow $\makebox[1.22ex][c]{⟧}\mbox{\hspace{0.50em}}f\vphantom{$\{$}{\nopagebreak[4] \newline%
}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{2em}}\makebox[1.22ex][c]{⟦}\makebox[1.22ex][c]{$ \forall $}\makebox[1.22ex][c]{⟧}\mbox{\hspace{0.50em}}{\char `\:}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \forall $}\mbox{\hspace{0.50em}}\{A\makebox[0.61ex][c]{₁}\mbox{\hspace{0.50em}}A\makebox[0.61ex][c]{₂}\}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}A\makebox[0.61ex][c]{ᵣ}\mbox{\hspace{0.50em}}{\char `\:}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{⟦}Set₀\makebox[1.22ex][c]{⟧}\mbox{\hspace{0.50em}}A\makebox[0.61ex][c]{₁}\mbox{\hspace{0.50em}}A\makebox[0.61ex][c]{₂}\makebox[1.22ex][c]{$ {)} $}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{6em}}\{B\makebox[0.61ex][c]{₁}\mbox{\hspace{0.50em}}B\makebox[0.61ex][c]{₂}\}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}B\makebox[0.61ex][c]{ᵣ}\mbox{\hspace{0.50em}}{\char `\:}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}\makebox[1.22ex][c]{⟦}Set₀\makebox[1.22ex][c]{⟧}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{⟦}$ \rightarrow $\makebox[1.22ex][c]{⟧}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{⟦}Set₀\makebox[1.22ex][c]{⟧}\makebox[1.22ex][c]{$ {)} $}\mbox{\hspace{0.50em}}B\makebox[0.61ex][c]{₁}\mbox{\hspace{0.50em}}B\makebox[0.61ex][c]{₂}\makebox[1.22ex][c]{$ {)} $}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{5em}}$ \rightarrow $\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{⟦}Set\makebox[0.61ex][c]{₁}\makebox[1.22ex][c]{⟧}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}\{x\mbox{\hspace{0.50em}}{\char `\:}\mbox{\hspace{0.50em}}A\makebox[0.61ex][c]{₁}\}\mbox{\hspace{0.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}B\makebox[0.61ex][c]{₁}\mbox{\hspace{0.50em}}x\makebox[1.22ex][c]{$ {)} $}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}\{x\mbox{\hspace{0.50em}}{\char `\:}\mbox{\hspace{0.50em}}A\makebox[0.61ex][c]{₂}\}\mbox{\hspace{0.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}B\makebox[0.61ex][c]{₂}\mbox{\hspace{0.50em}}x\makebox[1.22ex][c]{$ {)} $}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{2em}}\makebox[1.22ex][c]{⟦}\makebox[1.22ex][c]{$ \forall $}\makebox[1.22ex][c]{⟧}\mbox{\hspace{0.50em}}A\makebox[0.61ex][c]{ᵣ}\mbox{\hspace{0.50em}}B\makebox[0.61ex][c]{ᵣ}\mbox{\hspace{0.50em}}{\char `\=}\mbox{\hspace{0.50em}}$ \lambda $\mbox{\hspace{0.50em}}f\makebox[0.61ex][c]{₁}\mbox{\hspace{0.50em}}f\makebox[0.61ex][c]{₂}\mbox{\hspace{0.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \forall $}\mbox{\hspace{0.50em}}\{x\makebox[0.61ex][c]{₁}\mbox{\hspace{0.50em}}x\makebox[0.61ex][c]{₂}\}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}x\makebox[0.61ex][c]{ᵣ}\mbox{\hspace{0.50em}}{\char `\:}\mbox{\hspace{0.50em}}A\makebox[0.61ex][c]{ᵣ}\mbox{\hspace{0.50em}}x\makebox[0.61ex][c]{₁}\mbox{\hspace{0.50em}}x\makebox[0.61ex][c]{₂}\makebox[1.22ex][c]{$ {)} $}\mbox{\hspace{0.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}B\makebox[0.61ex][c]{ᵣ}\mbox{\hspace{0.50em}}x\makebox[0.61ex][c]{ᵣ}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}f\makebox[0.61ex][c]{₁}\mbox{\hspace{0.50em}}\{x\makebox[0.61ex][c]{₁}\}\makebox[1.22ex][c]{$ {)} $}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}f\makebox[0.61ex][c]{₂}\mbox{\hspace{0.50em}}\{x\makebox[0.61ex][c]{₂}\}\makebox[1.22ex][c]{$ {)} $}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{2em}}syntax\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{⟦}\makebox[1.22ex][c]{$ \forall $}\makebox[1.22ex][c]{⟧}\mbox{\hspace{0.50em}}A\makebox[0.61ex][c]{ᵣ}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}$ \lambda $\mbox{\hspace{0.50em}}x\makebox[0.61ex][c]{ᵣ}\mbox{\hspace{0.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}f\makebox[1.22ex][c]{$ {)} $}\mbox{\hspace{0.50em}}{\char `\=}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \forall $}\makebox[1.22ex][c]{⟨}\mbox{\hspace{0.50em}}x\makebox[0.61ex][c]{ᵣ}\mbox{\hspace{0.50em}}∶\mbox{\hspace{0.50em}}A\makebox[0.61ex][c]{ᵣ}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{⟩}\makebox[1.22ex][c]{⟦}$ \rightarrow $\makebox[1.22ex][c]{⟧}\mbox{\hspace{0.50em}}f\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{2em}}}

\caption{Logical relations for core types\label{rellogfig}}
\end{figure*}

%
%paragraphName: relations for data types
We now have  the definition of the \textsc{Agda} logical  relation for the
    core type theory part. It extends nicely to inductive data types and
    records.  The process  is as  follows$:$ for  each constructor  $ \kappa $ of
    type  {~}$ \tau $, declare  a new  constructor  \texttt{⟦}$ \kappa $\texttt{⟧}  whose type  is
    \texttt{⟦ $ \tau $ ⟧ $ \kappa $ $ \kappa $}.  This process  applies to  type constructors  and
    data constructors of data types, and type constructors and fields of
    record types. For reference, the logical relations for data types we
    use in this development are in figure \ref{datarelfig}.%


\begin{figure}[]
%
%comment:
%    data ⟦⊥⟧ : ⟦Set₀⟧ ⊥ ⊥ -- no constructors
%
%    data ⟦Bool⟧ : ⟦Set₀⟧ Bool Bool where
%      ⟦true⟧   : ⟦Bool⟧ true   true
%      ⟦false⟧  : ⟦Bool⟧ false  false
%
%    data ⟦ℕ⟧ : ⟦Set₀⟧ ℕ ℕ where
%      ⟦zero⟧  : ⟦ℕ⟧              zero  zero
%      ⟦suc⟧   : (⟦ℕ⟧ ⟦→⟧ ⟦ℕ⟧)  suc   suc
%
%    data _⟦⊎⟧_ {A₁ A₂ B₁ B₂} (Aᵣ : ⟦Set₀⟧ A₁ A₂)
%                            (Bᵣ : ⟦Set₀⟧ B₁ B₂) :
%                A₁ ⊎ B₁ → A₂ ⊎ B₂ → Set₀ where
%      ⟦inj₁⟧ : (Aᵣ → Aᵣ ⟦⊎⟧ Bᵣ) inj₁ inj₁
%      ⟦inj₂⟧ : (Bᵣ → Aᵣ ⟦⊎⟧ Bᵣ) inj₂ inj₂
%
%


~\\~\texttt{\mbox{\hspace{2em}}data\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{⟦}$ \bot $\makebox[1.22ex][c]{⟧}\mbox{\hspace{0.50em}}{\char `\:}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{⟦}Set₀\makebox[1.22ex][c]{⟧}\mbox{\hspace{0.50em}}$ \bot $\mbox{\hspace{0.50em}}$ \bot $\mbox{\hspace{0.50em}}{\char `\-}{\char `\-}\mbox{\hspace{0.50em}}no\mbox{\hspace{0.50em}}constructors\vphantom{$\{$}{\nopagebreak[4] \newline%
}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{2em}}data\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{⟦}Bool\makebox[1.22ex][c]{⟧}\mbox{\hspace{0.50em}}{\char `\:}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{⟦}Set₀\makebox[1.22ex][c]{⟧}\mbox{\hspace{0.50em}}Bool\mbox{\hspace{0.50em}}Bool\mbox{\hspace{0.50em}}where\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{3em}}\makebox[1.22ex][c]{⟦}true\makebox[1.22ex][c]{⟧}\mbox{\hspace{1.50em}}{\char `\:}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{⟦}Bool\makebox[1.22ex][c]{⟧}\mbox{\hspace{0.50em}}true\mbox{\hspace{1.50em}}true\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{3em}}\makebox[1.22ex][c]{⟦}false\makebox[1.22ex][c]{⟧}\mbox{\hspace{1em}}{\char `\:}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{⟦}Bool\makebox[1.22ex][c]{⟧}\mbox{\hspace{0.50em}}false\mbox{\hspace{1em}}false\vphantom{$\{$}{\nopagebreak[4] \newline%
}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{2em}}data\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{⟦}\makebox[2.44ex][c]{$ \mathbb{{N}} $}\makebox[1.22ex][c]{⟧}\mbox{\hspace{0.50em}}{\char `\:}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{⟦}Set₀\makebox[1.22ex][c]{⟧}\mbox{\hspace{0.50em}}\makebox[2.44ex][c]{$ \mathbb{{N}} $}\mbox{\hspace{0.50em}}\makebox[2.44ex][c]{$ \mathbb{{N}} $}\mbox{\hspace{0.50em}}where\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{3em}}\makebox[1.22ex][c]{⟦}zero\makebox[1.22ex][c]{⟧}\mbox{\hspace{1em}}{\char `\:}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{⟦}\makebox[2.44ex][c]{$ \mathbb{{N}} $}\makebox[1.22ex][c]{⟧}\mbox{\hspace{7em}}zero\mbox{\hspace{1em}}zero\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{3em}}\makebox[1.22ex][c]{⟦}suc\makebox[1.22ex][c]{⟧}\mbox{\hspace{1.50em}}{\char `\:}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}\makebox[1.22ex][c]{⟦}\makebox[2.44ex][c]{$ \mathbb{{N}} $}\makebox[1.22ex][c]{⟧}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{⟦}$ \rightarrow $\makebox[1.22ex][c]{⟧}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{⟦}\makebox[2.44ex][c]{$ \mathbb{{N}} $}\makebox[1.22ex][c]{⟧}\makebox[1.22ex][c]{$ {)} $}\mbox{\hspace{1em}}suc\mbox{\hspace{1.50em}}suc\vphantom{$\{$}{\nopagebreak[4] \newline%
}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{2em}}data\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{{\char `\_}}\makebox[1.22ex][c]{⟦}\makebox[2.44ex][c]{⊎}\makebox[1.22ex][c]{⟧}\makebox[1.22ex][c]{{\char `\_}}\mbox{\hspace{0.50em}}\{A\makebox[0.61ex][c]{₁}\mbox{\hspace{0.50em}}A\makebox[0.61ex][c]{₂}\mbox{\hspace{0.50em}}B\makebox[0.61ex][c]{₁}\mbox{\hspace{0.50em}}B\makebox[0.61ex][c]{₂}\}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}A\makebox[0.61ex][c]{ᵣ}\mbox{\hspace{0.50em}}{\char `\:}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{⟦}Set₀\makebox[1.22ex][c]{⟧}\mbox{\hspace{0.50em}}A\makebox[0.61ex][c]{₁}\mbox{\hspace{0.50em}}A\makebox[0.61ex][c]{₂}\makebox[1.22ex][c]{$ {)} $}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{14em}}\makebox[1.22ex][c]{$ {(} $}B\makebox[0.61ex][c]{ᵣ}\mbox{\hspace{0.50em}}{\char `\:}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{⟦}Set₀\makebox[1.22ex][c]{⟧}\mbox{\hspace{0.50em}}B\makebox[0.61ex][c]{₁}\mbox{\hspace{0.50em}}B\makebox[0.61ex][c]{₂}\makebox[1.22ex][c]{$ {)} $}\mbox{\hspace{0.50em}}{\char `\:}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{8em}}A\makebox[0.61ex][c]{₁}\mbox{\hspace{0.50em}}\makebox[2.44ex][c]{⊎}\mbox{\hspace{0.50em}}B\makebox[0.61ex][c]{₁}\mbox{\hspace{0.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}A\makebox[0.61ex][c]{₂}\mbox{\hspace{0.50em}}\makebox[2.44ex][c]{⊎}\mbox{\hspace{0.50em}}B\makebox[0.61ex][c]{₂}\mbox{\hspace{0.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}Set₀\mbox{\hspace{0.50em}}where\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{3em}}\makebox[1.22ex][c]{⟦}inj\makebox[0.61ex][c]{₁}\makebox[1.22ex][c]{⟧}\mbox{\hspace{0.50em}}{\char `\:}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}A\makebox[0.61ex][c]{ᵣ}\mbox{\hspace{0.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}A\makebox[0.61ex][c]{ᵣ}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{⟦}\makebox[2.44ex][c]{⊎}\makebox[1.22ex][c]{⟧}\mbox{\hspace{0.50em}}B\makebox[0.61ex][c]{ᵣ}\makebox[1.22ex][c]{$ {)} $}\mbox{\hspace{0.50em}}inj\makebox[0.61ex][c]{₁}\mbox{\hspace{0.50em}}inj\makebox[0.61ex][c]{₁}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{3em}}\makebox[1.22ex][c]{⟦}inj\makebox[0.61ex][c]{₂}\makebox[1.22ex][c]{⟧}\mbox{\hspace{0.50em}}{\char `\:}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}B\makebox[0.61ex][c]{ᵣ}\mbox{\hspace{0.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}A\makebox[0.61ex][c]{ᵣ}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{⟦}\makebox[2.44ex][c]{⊎}\makebox[1.22ex][c]{⟧}\mbox{\hspace{0.50em}}B\makebox[0.61ex][c]{ᵣ}\makebox[1.22ex][c]{$ {)} $}\mbox{\hspace{0.50em}}inj\makebox[0.61ex][c]{₂}\mbox{\hspace{0.50em}}inj\makebox[0.61ex][c]{₂}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{2em}}}

\caption{Logical relations for data types\label{datarelfig}}
\end{figure}

\subsection{An example$:$ booleans represented by numbers}

%
%paragraphName: describe our bool as ℕ example
We  wish to  explain how  logical relations  can help  build a  safe
    interface to an abstract type. To  do so we introduce a tiny example
    about booleans  represented using  natural numbers. We  want $ {0} $    to  represent \texttt{false}  and  any other  number  to represent  \texttt{true}.
    Therefore the boolean disjunction can be implemented using addition.
    We show  that logical relations  help build  a model, ensure  that a
    given implementation  respects this model,  and finally show  that a
    client that uses only the interface will also respect the model.%


%
%paragraphName: toy however
Note however that  this is a toy example in  several ways. There are
    no polymorphic  functions in the  interface, so no  interesting free
    theorems are  to be  expected. While  we could  prove the  safety by
    defining  a representation  predicate  in unary  style, the  logical
    relations  approach is  different. It  relies on  comparing concrete
    data as opposed to mapping  to abstract data. The unary construction
    would allow for a  simpler construction, however this oversimplifies
    the problem here and would be no longer useful for proving \textsc{NaPa}.%


%
%paragraphName: description of B implem
Our tiny implementation  of booleans using natural  numbers is given
    below.  It contains  a  type \texttt{B}  that we  want  to keep  abstract.
    It  contains  obvious  definitions  for  \texttt{true},  \texttt{false},  and  the
    disjunction \texttt{{\char `\_}}\texttt{$ \vee $}\texttt{{\char `\_}}. It intentionally  has a dubious function \texttt{is42{\char `\?}}    which breaks our still informal expectations from such a module.%


%
%comment:
%  B : Set
%  B = ℕ
%
%  false : B
%  false = 0
%
%  true : B
%  true = 1
%
%


~\\~\texttt{\mbox{\hspace{1em}}B\mbox{\hspace{0.50em}}{\char `\:}\mbox{\hspace{0.50em}}Set\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{1em}}B\mbox{\hspace{0.50em}}{\char `\=}\mbox{\hspace{0.50em}}\makebox[2.44ex][c]{$ \mathbb{{N}} $}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{1em}}false\mbox{\hspace{0.50em}}{\char `\:}\mbox{\hspace{0.50em}}B\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{1em}}false\mbox{\hspace{0.50em}}{\char `\=}\mbox{\hspace{0.50em}}0\vphantom{$\{$}{\nopagebreak[4] \newline%
}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{1em}}true\mbox{\hspace{0.50em}}{\char `\:}\mbox{\hspace{0.50em}}B\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{1em}}true\mbox{\hspace{0.50em}}{\char `\=}\mbox{\hspace{0.50em}}1\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{1em}}}

%
%comment:
%  _∨_ : B → B → B
%  m ∨ n = m + n
%
%


~\\~\texttt{\mbox{\hspace{1em}}\makebox[1.22ex][c]{{\char `\_}}\makebox[2.44ex][c]{$ \vee $}\makebox[1.22ex][c]{{\char `\_}}\mbox{\hspace{0.50em}}{\char `\:}\mbox{\hspace{0.50em}}B\mbox{\hspace{0.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}B\mbox{\hspace{0.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}B\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{1em}}m\mbox{\hspace{0.50em}}\makebox[2.44ex][c]{$ \vee $}\mbox{\hspace{0.50em}}n\mbox{\hspace{0.50em}}{\char `\=}\mbox{\hspace{0.50em}}m\mbox{\hspace{0.50em}}{\char `\+}\mbox{\hspace{0.50em}}n\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{1em}}}

%
%comment:
%  is42? : B → B
%  is42? 42 = true
%  is42? _  = false
%
%


~\\~\texttt{\mbox{\hspace{1em}}is42{\char `\?}\mbox{\hspace{0.50em}}{\char `\:}\mbox{\hspace{0.50em}}B\mbox{\hspace{0.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}B\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{1em}}is42{\char `\?}\mbox{\hspace{0.50em}}42\mbox{\hspace{0.50em}}{\char `\=}\mbox{\hspace{0.50em}}true\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{1em}}is42{\char `\?}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{{\char `\_}}\mbox{\hspace{1em}}{\char `\=}\mbox{\hspace{0.50em}}false\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{1em}}}

%
%paragraphName: introduce ⟦B⟧
The next  step is to  define our expectations. To  do so, we  give a
    binary  relation which  tells when  two  \texttt{B} values  have the  same
    meaning. We do so with an (inductive) data type named \texttt{⟦}\texttt{B}\texttt{⟧} which
    states that  $ {0} $ is related only  with itself, and that  any two
    non zero numbers are related$:$%


%
%comment:
%  data ⟦B⟧ : B → B → Set where
%    ⟦false⟧ : ⟦B⟧ 0 0
%    ⟦true⟧  : ∀ {m n} → ⟦B⟧ (suc m) (suc n)
%
%


~\\~\texttt{\mbox{\hspace{1em}}data\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{⟦}B\makebox[1.22ex][c]{⟧}\mbox{\hspace{0.50em}}{\char `\:}\mbox{\hspace{0.50em}}B\mbox{\hspace{0.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}B\mbox{\hspace{0.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}Set\mbox{\hspace{0.50em}}where\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{2em}}\makebox[1.22ex][c]{⟦}false\makebox[1.22ex][c]{⟧}\mbox{\hspace{0.50em}}{\char `\:}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{⟦}B\makebox[1.22ex][c]{⟧}\mbox{\hspace{0.50em}}0\mbox{\hspace{0.50em}}0\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{2em}}\makebox[1.22ex][c]{⟦}true\makebox[1.22ex][c]{⟧}\mbox{\hspace{1em}}{\char `\:}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \forall $}\mbox{\hspace{0.50em}}\{m\mbox{\hspace{0.50em}}n\}\mbox{\hspace{0.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{⟦}B\makebox[1.22ex][c]{⟧}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}suc\mbox{\hspace{0.50em}}m\makebox[1.22ex][c]{$ {)} $}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}suc\mbox{\hspace{0.50em}}n\makebox[1.22ex][c]{$ {)} $}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{1em}}}

%
%paragraphName: plugging ⟦B⟧
When plugged  into the  machinery of  logical relations  this single
    definition  suffices  to  define  a  complete  model  of  well-typed
    programs.  However,  the  plumbing  requires some  care.  While  the
    \textsc{Agda} logical  relation is  universal, we  have no  such guarantee
    about the \textsc{Agda} logical relation where the relation for \texttt{B} is no
    longer \texttt{⟦$ \mathbb{{N}} $⟧}  but \texttt{⟦}\texttt{B}\texttt{⟧}. Fortunately  changing the relation
    at a given type (\texttt{B} here) can be done safely. All we have to do is
    to consider programs  abstracted away from \texttt{B}  and its operations$:$
    \texttt{true},  \texttt{false} and  \texttt{{\char `\_}}\texttt{$ \vee $}\texttt{{\char `\_}}. This  can  be done  either through  a
    mechanism for  abstract types, or  by requiring  the client to  be a
    function taking  the implementation for  \texttt{B} and its  operations as
    argument.%


%
%paragraphName: proof obligations when plugging ⟦B⟧
However to use  \texttt{⟦}\texttt{B}\texttt{⟧} as the  relation for \texttt{B}, we  have to show
    that the definitions  which make use of the  representation of \texttt{B}    actually  fit the  relation. Since  \texttt{⟦}\texttt{true}\texttt{⟧}  and \texttt{⟦}\texttt{false}\texttt{⟧} are
    obvious witnesses  for \texttt{true} and  \texttt{false}, only \texttt{{\char `\_}}\texttt{$ \vee $}\texttt{{\char `\_}}  and \texttt{is42{\char `\?}}    are left  to be proved. Each  time the goal to  prove is mechanical$:$
    wrap the type with \texttt{⟦$ \cdotp $⟧} on  each constructor and put the name
    of the function twice  to state we want it to  be related to itself.
    Here is the definition for \texttt{{\char `\_}}\texttt{⟦}\texttt{$ \vee $}\texttt{⟧}\texttt{{\char `\_}}$:$%


%
%comment:
%  _⟦∨⟧_ : (⟦B⟧ ⟦→⟧ ⟦B⟧ ⟦→⟧ ⟦B⟧) _∨_ _∨_
%
%


~\\~\texttt{\mbox{\hspace{1em}}\makebox[1.22ex][c]{{\char `\_}}\makebox[1.22ex][c]{⟦}\makebox[2.44ex][c]{$ \vee $}\makebox[1.22ex][c]{⟧}\makebox[1.22ex][c]{{\char `\_}}\mbox{\hspace{0.50em}}{\char `\:}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}\makebox[1.22ex][c]{⟦}B\makebox[1.22ex][c]{⟧}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{⟦}$ \rightarrow $\makebox[1.22ex][c]{⟧}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{⟦}B\makebox[1.22ex][c]{⟧}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{⟦}$ \rightarrow $\makebox[1.22ex][c]{⟧}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{⟦}B\makebox[1.22ex][c]{⟧}\makebox[1.22ex][c]{$ {)} $}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{{\char `\_}}\makebox[2.44ex][c]{$ \vee $}\makebox[1.22ex][c]{{\char `\_}}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{{\char `\_}}\makebox[2.44ex][c]{$ \vee $}\makebox[1.22ex][c]{{\char `\_}}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{1em}}}

%
%paragraphName: _⟦∨⟧_'s type, description
The  type of  \texttt{{\char `\_}}\texttt{⟦}\texttt{$ \vee $}\texttt{⟧}\texttt{{\char `\_}} means  that given  inputs related  in the
    model, the results  are related in the model as  well. Once unfolded
    the type looks like$:$%


%
%comment:
%  _⟦∨⟧_ : ∀ {x₁ x₂} (xᵣ : ⟦B⟧ x₁ x₂)
%             {y₁ y₂} (yᵣ : ⟦B⟧ y₁ y₂)
%          → ⟦B⟧ (x₁ ∨ y₁) (x₂ ∨ y₂)
%
%


~\\~\texttt{\mbox{\hspace{1em}}\makebox[1.22ex][c]{{\char `\_}}\makebox[1.22ex][c]{⟦}\makebox[2.44ex][c]{$ \vee $}\makebox[1.22ex][c]{⟧}\makebox[1.22ex][c]{{\char `\_}}\mbox{\hspace{0.50em}}{\char `\:}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \forall $}\mbox{\hspace{0.50em}}\{x\makebox[0.61ex][c]{₁}\mbox{\hspace{0.50em}}x\makebox[0.61ex][c]{₂}\}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}x\makebox[0.61ex][c]{ᵣ}\mbox{\hspace{0.50em}}{\char `\:}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{⟦}B\makebox[1.22ex][c]{⟧}\mbox{\hspace{0.50em}}x\makebox[0.61ex][c]{₁}\mbox{\hspace{0.50em}}x\makebox[0.61ex][c]{₂}\makebox[1.22ex][c]{$ {)} $}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{6.50em}}\{y\makebox[0.61ex][c]{₁}\mbox{\hspace{0.50em}}y\makebox[0.61ex][c]{₂}\}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}y\makebox[0.61ex][c]{ᵣ}\mbox{\hspace{0.50em}}{\char `\:}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{⟦}B\makebox[1.22ex][c]{⟧}\mbox{\hspace{0.50em}}y\makebox[0.61ex][c]{₁}\mbox{\hspace{0.50em}}y\makebox[0.61ex][c]{₂}\makebox[1.22ex][c]{$ {)} $}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{5em}}$ \rightarrow $\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{⟦}B\makebox[1.22ex][c]{⟧}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}x\makebox[0.61ex][c]{₁}\mbox{\hspace{0.50em}}\makebox[2.44ex][c]{$ \vee $}\mbox{\hspace{0.50em}}y\makebox[0.61ex][c]{₁}\makebox[1.22ex][c]{$ {)} $}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}x\makebox[0.61ex][c]{₂}\mbox{\hspace{0.50em}}\makebox[2.44ex][c]{$ \vee $}\mbox{\hspace{0.50em}}y\makebox[0.61ex][c]{₂}\makebox[1.22ex][c]{$ {)} $}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{1em}}}

%
%paragraphName: _⟦∨⟧_ description
The  fact  that input  arguments  come  as implicit  arguments  will
    greatly shorten definitions. Now, thanks to the inductive definition
    of \texttt{{\char `\_}}\texttt{{\char `\+}}\texttt{{\char `\_}}, simply pattern-matching on the first relation suffices
    to reduce the goal, and allows this nice looking definition where we
    see the usual lazy definition of the left biased disjunction$:$%


%
%comment:
%  ⟦false⟧  ⟦∨⟧  x  =  x
%  ⟦true⟧   ⟦∨⟧  _  =  ⟦true⟧
%
%


~\\~\texttt{\mbox{\hspace{1em}}\makebox[1.22ex][c]{⟦}false\makebox[1.22ex][c]{⟧}\mbox{\hspace{1em}}\makebox[1.22ex][c]{⟦}\makebox[2.44ex][c]{$ \vee $}\makebox[1.22ex][c]{⟧}\mbox{\hspace{1em}}x\mbox{\hspace{1em}}{\char `\=}\mbox{\hspace{1em}}x\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{1em}}\makebox[1.22ex][c]{⟦}true\makebox[1.22ex][c]{⟧}\mbox{\hspace{1.50em}}\makebox[1.22ex][c]{⟦}\makebox[2.44ex][c]{$ \vee $}\makebox[1.22ex][c]{⟧}\mbox{\hspace{1em}}\makebox[1.22ex][c]{{\char `\_}}\mbox{\hspace{1em}}{\char `\=}\mbox{\hspace{1em}}\makebox[1.22ex][c]{⟦}true\makebox[1.22ex][c]{⟧}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{1em}}}

%
%paragraphName: ¬⟦is42?⟧ description
Let us  now consider  a proof for  the \texttt{is42{\char `\?}}  function. Fortunately
    there  is  no such  proof  since  this  function gladly  breaks  the
    intended  abstraction.   Instead  we   simply  prove   its  negation
    by  exhibiting   that  given   two  related  inputs   ($ {4}{2} $  and
    $ {2}{7} $)  we  get  non related  outputs  (\texttt{is42{\char `\?} 42 {\char `\=} 1}  and
    \texttt{is42{\char `\?} 27 {\char `\=} 0}).%


%
%comment:
%  ¬⟦is42?⟧ : ¬((⟦B⟧ ⟦→⟧ ⟦B⟧) is42? is42?)
%  ¬⟦is42?⟧ ⟦is42?⟧ with ⟦is42?⟧ {42} {27} ⟦true⟧
%  ...                  | () -- absurd
%
%


~\\~\texttt{\mbox{\hspace{1em}}\makebox[2.44ex][c]{$ \neg $}\makebox[1.22ex][c]{⟦}is42{\char `\?}\makebox[1.22ex][c]{⟧}\mbox{\hspace{0.50em}}{\char `\:}\mbox{\hspace{0.50em}}\makebox[2.44ex][c]{$ \neg $}\makebox[1.22ex][c]{$ {(} $}\makebox[1.22ex][c]{$ {(} $}\makebox[1.22ex][c]{⟦}B\makebox[1.22ex][c]{⟧}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{⟦}$ \rightarrow $\makebox[1.22ex][c]{⟧}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{⟦}B\makebox[1.22ex][c]{⟧}\makebox[1.22ex][c]{$ {)} $}\mbox{\hspace{0.50em}}is42{\char `\?}\mbox{\hspace{0.50em}}is42{\char `\?}\makebox[1.22ex][c]{$ {)} $}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{1em}}\makebox[2.44ex][c]{$ \neg $}\makebox[1.22ex][c]{⟦}is42{\char `\?}\makebox[1.22ex][c]{⟧}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{⟦}is42{\char `\?}\makebox[1.22ex][c]{⟧}\mbox{\hspace{0.50em}}with\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{⟦}is42{\char `\?}\makebox[1.22ex][c]{⟧}\mbox{\hspace{0.50em}}\{42\}\mbox{\hspace{0.50em}}\{27\}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{⟦}true\makebox[1.22ex][c]{⟧}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{1em}}{\char `\.}{\char `\.}{\char `\.}\mbox{\hspace{9em}}{\char `\|}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}\makebox[1.22ex][c]{$ {)} $}\mbox{\hspace{0.50em}}{\char `\-}{\char `\-}\mbox{\hspace{0.50em}}absurd\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{1em}}}

%
%paragraphName: model vs interface only
Note that  \texttt{is42{\char `\?}} is  rejected by our  model with  no considerations
    about   the   other   exported  functions.   Indeed   with   another
    implementation of \texttt{{\char `\_}}\texttt{$ \vee $}\texttt{{\char `\_}} there would  be no way to produce $ {4}{2} $    and  so no  way to  expose the  wrong behavior  of \texttt{is42{\char `\?}}  using the
    interface. Using a model provides a better forward compatibility and
    enables proofs to be done in a modular way.%


\subsection{Relations for \textsc{NaPa}}

%
%paragraphName: same process as for B
For  \textsc{NaPa},  we  apply  the  same  process  as  with  booleans.  We
    define  our  expectations,  by  defining  relations  for  introduced
    types (worlds,  names, and inclusions).  Finally we prove  that each
    value/function exported fits the relation.%


\subsubsection{Relations for \textsc{NaPa} types}

%
%paragraphName: functional and injective
Valid names are  those which belong to their worlds,  names with the
    same meaning are those related by the relation between their worlds.
    What matters is  not just the fact that two  worlds are related, but
    ``how'' they  are related. Indeed  this will dictate when  two names
    are related.  We need  to define  a set  of valid  relations between
    worlds. The more relations are accepted,  the more power it gives to
    the free  theorems of  world-polymorphic functions. However  we want
    the equality  test on names  to be accepted.  Thus we at  least need
    the  relation to  preserve name  equalities across  the relation  in
    both directions.  We require  these relations  to be  functional and
    injective$:$%


%
%comment:
%  FunctionalAndInjective ℛ =
%     ∀ x₁ y₁ x₂ y₂ → ℛ x₁ x₂ → ℛ y₁ y₂
%                 → x₁ ≡ y₁ ↔ x₂ ≡ y₂
%
%


~\\~\texttt{\mbox{\hspace{1em}}FunctionalAndInjective\mbox{\hspace{0.50em}}$ \mathcal{{R}} $\mbox{\hspace{0.50em}}{\char `\=}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{2.50em}}\makebox[1.22ex][c]{$ \forall $}\mbox{\hspace{0.50em}}x\makebox[0.61ex][c]{₁}\mbox{\hspace{0.50em}}y\makebox[0.61ex][c]{₁}\mbox{\hspace{0.50em}}x\makebox[0.61ex][c]{₂}\mbox{\hspace{0.50em}}y\makebox[0.61ex][c]{₂}\mbox{\hspace{0.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}$ \mathcal{{R}} $\mbox{\hspace{0.50em}}x\makebox[0.61ex][c]{₁}\mbox{\hspace{0.50em}}x\makebox[0.61ex][c]{₂}\mbox{\hspace{0.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}$ \mathcal{{R}} $\mbox{\hspace{0.50em}}y\makebox[0.61ex][c]{₁}\mbox{\hspace{0.50em}}y\makebox[0.61ex][c]{₂}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{8.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}x\makebox[0.61ex][c]{₁}\mbox{\hspace{0.50em}}$ \equiv $\mbox{\hspace{0.50em}}y\makebox[0.61ex][c]{₁}\mbox{\hspace{0.50em}}$ \leftrightarrow $\mbox{\hspace{0.50em}}x\makebox[0.61ex][c]{₂}\mbox{\hspace{0.50em}}$ \equiv $\mbox{\hspace{0.50em}}y\makebox[0.61ex][c]{₂}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{1em}}}

%
%paragraphName: ⟦World⟧ and ⟦Name⟧
The  relation  \texttt{⟦}\texttt{World}\texttt{⟧}   between  two  worlds  \texttt{$ \alpha $₁}  and
    \texttt{$ \alpha $₂} is the set of  functional and injective relations between
    \texttt{Name $ \alpha $₁}  and  \texttt{Name $ \alpha $₂}.  Then,  two  names  \texttt{x}    (in  \texttt{$ \alpha $₁})  and  \texttt{y}  (in  \texttt{$ \alpha $₂})  are  related  by
    \texttt{ ⟦Name⟧ $ \alpha $ᵣ }  if  and  only  if   they  are  related  by  the
    \texttt{$ \alpha $ᵣ} relation.%


%
%paragraphName: _⟦⊆⟧_
For the  \texttt{{\char `\_}}\texttt{⟦}\texttt{$ \subseteq $}\texttt{⟧}\texttt{{\char `\_}} relation, we  exploit the fact there  is only
    one way to use an inclusion witness, namely \texttt{coerceᴺ}. Thus, for the
    purpose of building the model, we identify inclusions with their use
    in  \texttt{coerceᴺ}.  Put  differently, whatever  the  representation  for
    inclusions  is, the  model takes  them  as functions  from names  to
    names. Yet  another way  to look  at it is  from the  perspective of
    relation  inclusions. A  relation \texttt{$ \mathcal{{R}} $₁}  is included  in a  relation
    \texttt{$ \mathcal{{R}} $₂} if and only if all pairs related by \texttt{$ \mathcal{{R}} $₁} are related by \texttt{$ \mathcal{{R}} $₂}    as well. The \texttt{coerceᴺ} function  behaving like the identity function
    all  these  definitions coincide.  For  instance  if we  expand  the
    definitions for \texttt{⟦}\texttt{Name}\texttt{⟧} and \texttt{⟦$ \rightarrow $⟧}, we  get the definition
    for relation inclusion modulo the coercions$:$%


%
%comment:
%_⟦⊆⟧_ αᵣ βᵣ p₁ p₂
%  = ∀ {x₁ x₂} → (x₁ , x₂) ∈ αᵣ
%             → (coerceᴺ p₁ x₁ , coerceᴺ p₂ x₂) ∈ βᵣ
%
%


~\\~\texttt{\makebox[1.22ex][c]{{\char `\_}}\makebox[1.22ex][c]{⟦}\makebox[2.44ex][c]{$ \subseteq $}\makebox[1.22ex][c]{⟧}\makebox[1.22ex][c]{{\char `\_}}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \alpha $}\makebox[0.61ex][c]{ᵣ}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \beta $}\makebox[0.61ex][c]{ᵣ}\mbox{\hspace{0.50em}}p\makebox[0.61ex][c]{₁}\mbox{\hspace{0.50em}}p\makebox[0.61ex][c]{₂}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{1em}}{\char `\=}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \forall $}\mbox{\hspace{0.50em}}\{x\makebox[0.61ex][c]{₁}\mbox{\hspace{0.50em}}x\makebox[0.61ex][c]{₂}\}\mbox{\hspace{0.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}x\makebox[0.61ex][c]{₁}\mbox{\hspace{0.50em}}{\char `\,}\mbox{\hspace{0.50em}}x\makebox[0.61ex][c]{₂}\makebox[1.22ex][c]{$ {)} $}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \in $}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \alpha $}\makebox[0.61ex][c]{ᵣ}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{6.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}coerce\makebox[0.61ex][c]{ᴺ}\mbox{\hspace{0.50em}}p\makebox[0.61ex][c]{₁}\mbox{\hspace{0.50em}}x\makebox[0.61ex][c]{₁}\mbox{\hspace{0.50em}}{\char `\,}\mbox{\hspace{0.50em}}coerce\makebox[0.61ex][c]{ᴺ}\mbox{\hspace{0.50em}}p\makebox[0.61ex][c]{₂}\mbox{\hspace{0.50em}}x\makebox[0.61ex][c]{₂}\makebox[1.22ex][c]{$ {)} $}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \in $}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \beta $}\makebox[0.61ex][c]{ᵣ}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{1em}}}

\begin{figure}[]
%
%comment:
%    record ⟦World⟧ α₁ α₂ : Set where
%      constructor _,_
%      field
%        ℛ : Name α₁ → Name α₂ → Set
%        ℛ-fun-inj : FunctionalAndInjective ℛ
%
%    ⟦Name⟧ : (⟦World⟧ ⟦→⟧ ⟦Set₀⟧) Name Name
%    ⟦Name⟧ (ℛ , _) x₁ x₂ = ℛ x₁ x₂
%
%    _⟦⊆⟧_ : (⟦World⟧ ⟦→⟧ ⟦World⟧ ⟦→⟧ ⟦Set₀⟧)
%              _⊆_ _⊆_
%    _⟦⊆⟧_ αᵣ βᵣ α₁⊆β₁ α₂⊆β₂
%      = (⟦Name⟧ αᵣ ⟦→⟧ ⟦Name⟧ βᵣ) (coerceᴺ α₁⊆β₁)
%                                  (coerceᴺ α₂⊆β₂)
%
%


~\\~\texttt{\mbox{\hspace{2em}}record\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{⟦}World\makebox[1.22ex][c]{⟧}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \alpha $}\makebox[0.61ex][c]{₁}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \alpha $}\makebox[0.61ex][c]{₂}\mbox{\hspace{0.50em}}{\char `\:}\mbox{\hspace{0.50em}}Set\mbox{\hspace{0.50em}}where\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{3em}}constructor\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{{\char `\_}}{\char `\,}\makebox[1.22ex][c]{{\char `\_}}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{3em}}field\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{4em}}$ \mathcal{{R}} $\mbox{\hspace{0.50em}}{\char `\:}\mbox{\hspace{0.50em}}Name\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \alpha $}\makebox[0.61ex][c]{₁}\mbox{\hspace{0.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}Name\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \alpha $}\makebox[0.61ex][c]{₂}\mbox{\hspace{0.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}Set\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{4em}}$ \mathcal{{R}} ${\char `\-}fun{\char `\-}inj\mbox{\hspace{0.50em}}{\char `\:}\mbox{\hspace{0.50em}}FunctionalAndInjective\mbox{\hspace{0.50em}}$ \mathcal{{R}} $\vphantom{$\{$}{\nopagebreak[4] \newline%
}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{2em}}\makebox[1.22ex][c]{⟦}Name\makebox[1.22ex][c]{⟧}\mbox{\hspace{0.50em}}{\char `\:}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}\makebox[1.22ex][c]{⟦}World\makebox[1.22ex][c]{⟧}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{⟦}$ \rightarrow $\makebox[1.22ex][c]{⟧}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{⟦}Set₀\makebox[1.22ex][c]{⟧}\makebox[1.22ex][c]{$ {)} $}\mbox{\hspace{0.50em}}Name\mbox{\hspace{0.50em}}Name\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{2em}}\makebox[1.22ex][c]{⟦}Name\makebox[1.22ex][c]{⟧}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}$ \mathcal{{R}} $\mbox{\hspace{0.50em}}{\char `\,}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{{\char `\_}}\makebox[1.22ex][c]{$ {)} $}\mbox{\hspace{0.50em}}x\makebox[0.61ex][c]{₁}\mbox{\hspace{0.50em}}x\makebox[0.61ex][c]{₂}\mbox{\hspace{0.50em}}{\char `\=}\mbox{\hspace{0.50em}}$ \mathcal{{R}} $\mbox{\hspace{0.50em}}x\makebox[0.61ex][c]{₁}\mbox{\hspace{0.50em}}x\makebox[0.61ex][c]{₂}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{2em}}\makebox[1.22ex][c]{{\char `\_}}\makebox[1.22ex][c]{⟦}\makebox[2.44ex][c]{$ \subseteq $}\makebox[1.22ex][c]{⟧}\makebox[1.22ex][c]{{\char `\_}}\mbox{\hspace{0.50em}}{\char `\:}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}\makebox[1.22ex][c]{⟦}World\makebox[1.22ex][c]{⟧}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{⟦}$ \rightarrow $\makebox[1.22ex][c]{⟧}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{⟦}World\makebox[1.22ex][c]{⟧}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{⟦}$ \rightarrow $\makebox[1.22ex][c]{⟧}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{⟦}Set₀\makebox[1.22ex][c]{⟧}\makebox[1.22ex][c]{$ {)} $}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{7em}}\makebox[1.22ex][c]{{\char `\_}}\makebox[2.44ex][c]{$ \subseteq $}\makebox[1.22ex][c]{{\char `\_}}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{{\char `\_}}\makebox[2.44ex][c]{$ \subseteq $}\makebox[1.22ex][c]{{\char `\_}}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{2em}}\makebox[1.22ex][c]{{\char `\_}}\makebox[1.22ex][c]{⟦}\makebox[2.44ex][c]{$ \subseteq $}\makebox[1.22ex][c]{⟧}\makebox[1.22ex][c]{{\char `\_}}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \alpha $}\makebox[0.61ex][c]{ᵣ}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \beta $}\makebox[0.61ex][c]{ᵣ}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \alpha $}\makebox[0.61ex][c]{₁}\makebox[2.44ex][c]{$ \subseteq $}\makebox[1.22ex][c]{$ \beta $}\makebox[0.61ex][c]{₁}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \alpha $}\makebox[0.61ex][c]{₂}\makebox[2.44ex][c]{$ \subseteq $}\makebox[1.22ex][c]{$ \beta $}\makebox[0.61ex][c]{₂}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{3em}}{\char `\=}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}\makebox[1.22ex][c]{⟦}Name\makebox[1.22ex][c]{⟧}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \alpha $}\makebox[0.61ex][c]{ᵣ}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{⟦}$ \rightarrow $\makebox[1.22ex][c]{⟧}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{⟦}Name\makebox[1.22ex][c]{⟧}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \beta $}\makebox[0.61ex][c]{ᵣ}\makebox[1.22ex][c]{$ {)} $}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}coerce\makebox[0.61ex][c]{ᴺ}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \alpha $}\makebox[0.61ex][c]{₁}\makebox[2.44ex][c]{$ \subseteq $}\makebox[1.22ex][c]{$ \beta $}\makebox[0.61ex][c]{₁}\makebox[1.22ex][c]{$ {)} $}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{17em}}\makebox[1.22ex][c]{$ {(} $}coerce\makebox[0.61ex][c]{ᴺ}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \alpha $}\makebox[0.61ex][c]{₂}\makebox[2.44ex][c]{$ \subseteq $}\makebox[1.22ex][c]{$ \beta $}\makebox[0.61ex][c]{₂}\makebox[1.22ex][c]{$ {)} $}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{2em}}}

\caption{Relations for \textsc{NaPa} types\label{coreTypesRelF}}
\end{figure}

%
%paragraphName: world operation lemmas
We now  have to  define operations  on worlds  that fit  the logical
    relation. The  case for  \texttt{⟦}\texttt{$ \emptyset $}\texttt{⟧} is  trivial. Then  $ \alpha\mbox{ᵣ}\mbox{ }\mbox{⟦}\mbox{+}{1}\mbox{⟧} $ is
    defined by  $ \mbox{ }\mbox{\{}\mbox{ }\mbox{(}{x}\mbox{+}{1}\mbox{,}\mbox{ }{y}\mbox{+}{1}\mbox{)}\mbox{ }\mbox{\textbar{}}\mbox{ }\mbox{(}{x}\mbox{,}\mbox{ }{y}\mbox{)} ${ }$ \in ${ }$ \alpha\mbox{ᵣ}\mbox{ }\mbox{\}}\mbox{ } $  and \texttt{$ \alpha $ᵣ ⟦$ \uparrow $1⟧}    is  defined   by  $ \mbox{ }\mbox{\{}\mbox{(}{0}\mbox{,}\mbox{ }{0}\mbox{)}\mbox{\}}\mbox{ }\cup\mbox{ }\alpha\mbox{ᵣ}\mbox{ }\mbox{⟦}\mbox{+}{1}\mbox{⟧}\mbox{ } $.  We  shown   that  both
    operations preserve  functionality and  injectiveness. Here  are the
    signatures that these operations fit the relation$:$%


%
%comment:
%  ⟦ø⟧    : ⟦World⟧ ø ø
%  _⟦+1⟧  : (⟦World⟧ ⟦→⟧ ⟦World⟧) _+1 _+1
%  _⟦↑1⟧  : (⟦World⟧ ⟦→⟧ ⟦World⟧) _↑1 _↑1
%
%


~\\~\texttt{\mbox{\hspace{1em}}\makebox[1.22ex][c]{⟦}\makebox[1.22ex][c]{$ \emptyset $}\makebox[1.22ex][c]{⟧}\mbox{\hspace{2em}}{\char `\:}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{⟦}World\makebox[1.22ex][c]{⟧}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \emptyset $}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \emptyset $}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{1em}}\makebox[1.22ex][c]{{\char `\_}}\makebox[1.22ex][c]{⟦}{\char `\+}1\makebox[1.22ex][c]{⟧}\mbox{\hspace{1em}}{\char `\:}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}\makebox[1.22ex][c]{⟦}World\makebox[1.22ex][c]{⟧}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{⟦}$ \rightarrow $\makebox[1.22ex][c]{⟧}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{⟦}World\makebox[1.22ex][c]{⟧}\makebox[1.22ex][c]{$ {)} $}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{{\char `\_}}{\char `\+}1\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{{\char `\_}}{\char `\+}1\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{1em}}\makebox[1.22ex][c]{{\char `\_}}\makebox[1.22ex][c]{⟦}\makebox[1.22ex][c]{$ \uparrow $}1\makebox[1.22ex][c]{⟧}\mbox{\hspace{1em}}{\char `\:}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}\makebox[1.22ex][c]{⟦}World\makebox[1.22ex][c]{⟧}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{⟦}$ \rightarrow $\makebox[1.22ex][c]{⟧}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{⟦}World\makebox[1.22ex][c]{⟧}\makebox[1.22ex][c]{$ {)} $}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{{\char `\_}}\makebox[1.22ex][c]{$ \uparrow $}1\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{{\char `\_}}\makebox[1.22ex][c]{$ \uparrow $}1\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{1em}}}

\subsubsection{\textsc{NaPa} values fit the relation}

%
%paragraphName: zeroᴺ, addᴺ, subtractᴺ, and ¬Nameø
We  now give  a short  overview of  the proofs  needed to  show that
    our  functions  fit  the  relation.  Thanks  to  the  definition  of
    \texttt{{\char `\_}⟦$ \uparrow $1⟧}, \texttt{zeroᴺ}  fits the  relation by  definition. Thanks  to the
    definition of  \texttt{{\char `\_}⟦{\char `\+}1⟧}, \texttt{addᴺ 1} and  \texttt{subtractᴺ 1} fit
    the relation as well. These two are later extended to \texttt{addᴺ k}    and  \texttt{subtractᴺ k}   by  an  induction  on   \texttt{k}.  Since
    \texttt{⟦$ \neg $Name$ \emptyset $⟧}  receives names  in the  empty world,  it trivially
    holds. Here is for instance the type signature for \texttt{⟦}\texttt{addᴺ}\texttt{⟧}$:$%


%
%comment:
%  ⟦addᴺ⟧ : (∀⟨ αᵣ ∶ ⟦World⟧     ⟩⟦→⟧
%             ⟨ kᵣ ∶ ⟦ℕ⟧        ⟩⟦→⟧
%             ⟦Name⟧ αᵣ ⟦→⟧
%             ⟦Name⟧ (αᵣ ⟦+ᵂ⟧ kᵣ)) addᴺ addᴺ
%
%


~\\~\texttt{\mbox{\hspace{1em}}\makebox[1.22ex][c]{⟦}add\makebox[0.61ex][c]{ᴺ}\makebox[1.22ex][c]{⟧}\mbox{\hspace{0.50em}}{\char `\:}\mbox{\hspace{0.50em}}\makebox[0.61ex][c]{ }\makebox[1.22ex][c]{$ {(} $}\makebox[1.22ex][c]{$ \forall $}\makebox[1.22ex][c]{⟨}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \alpha $}\makebox[0.61ex][c]{ᵣ}\mbox{\hspace{0.50em}}∶\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{⟦}World\makebox[1.22ex][c]{⟧}\mbox{\hspace{2.50em}}\makebox[1.22ex][c]{⟩}\makebox[1.22ex][c]{⟦}$ \rightarrow $\makebox[1.22ex][c]{⟧}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{6.50em}}\makebox[1.22ex][c]{⟨}\mbox{\hspace{0.50em}}k\makebox[0.61ex][c]{ᵣ}\mbox{\hspace{0.50em}}∶\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{⟦}\makebox[2.44ex][c]{$ \mathbb{{N}} $}\makebox[1.22ex][c]{⟧}\mbox{\hspace{4em}}\makebox[1.22ex][c]{⟩}\makebox[1.22ex][c]{⟦}$ \rightarrow $\makebox[1.22ex][c]{⟧}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{6.50em}}\makebox[1.22ex][c]{⟦}Name\makebox[1.22ex][c]{⟧}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \alpha $}\makebox[0.61ex][c]{ᵣ}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{⟦}$ \rightarrow $\makebox[1.22ex][c]{⟧}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{6.50em}}\makebox[1.22ex][c]{⟦}Name\makebox[1.22ex][c]{⟧}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}\makebox[1.22ex][c]{$ \alpha $}\makebox[0.61ex][c]{ᵣ}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{⟦}{\char `\+}\makebox[0.61ex][c]{ᵂ}\makebox[1.22ex][c]{⟧}\mbox{\hspace{0.50em}}k\makebox[0.61ex][c]{ᵣ}\makebox[1.22ex][c]{$ {)} $}\makebox[1.22ex][c]{$ {)} $}\mbox{\hspace{0.50em}}add\makebox[0.61ex][c]{ᴺ}\mbox{\hspace{0.50em}}add\makebox[0.61ex][c]{ᴺ}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{1em}}}

%
%paragraphName: ==ᴺ
For  \texttt{{\char `\_}}\texttt{⟦}\texttt{{\char `\=}{\char `\=}ᴺ}\texttt{⟧}\texttt{{\char `\_}},  once  unfolded,  the statement  tells  that  the
    equality  test  commutes  with  a  renaming.  This  means  that  the
    result of  the equality  test does  not change  when its  inputs are
    consistently  renamed. The  proof for  \texttt{{\char `\_}}\texttt{⟦}\texttt{{\char `\=}{\char `\=}ᴺ}\texttt{⟧}\texttt{{\char `\_}} is  done in  two
    parts. First, we have to relate the Boolean-valued function \texttt{{\char `\_}}\texttt{{\char `\=}{\char `\=}ᴺ}\texttt{{\char `\_}}    to the fact it decides equality on names. Second, we make use of the
    two  properties (functionality  and injectiveness)  of the  relation
    between the two worlds.%


%
%paragraphName: cmpᴺ
The definition  of \texttt{cmpᴺ}  is not  a simple  induction on  its first
    argument. It calls  \texttt{{\char `\_}}\texttt{{\char `\<}{\char `\=}}\texttt{{\char `\_}} (which does an induction)  and returns a
    Boolean  value. Based  on this  Boolean value,  the function  \texttt{cmpᴺ}    returns either \texttt{inj₁}  or \texttt{inj₂} (the constructors  of \texttt{{\char `\_}}\texttt{⊎}\texttt{{\char `\_}})
    with the same name (with  a different proof). To prove \texttt{{\char `\_}}\texttt{⟦}\texttt{cmpᴺ}\texttt{⟧}\texttt{{\char `\_}}    we show the  equivalence with a simpler inductive  function and show
    that  this  simpler function  is  in  the  relation. Thanks  to  the
    extensionality  of  the logical  relation,  no  additional axiom  is
    required to show that \texttt{cmpᴺ} fits the relation.%


%
%paragraphName: coerceᴺ and ⊆ rules
Thanks to the definition of  \texttt{{\char `\_}}\texttt{⟦}\texttt{$ \subseteq $}\texttt{⟧}\texttt{{\char `\_}}, the proof that \texttt{coerceᴺ}    fits the  relation is a  simple application of the  hypotheses. Then
    the  real job  is  to show  that  all the  inclusion  rules fit  the
    relation. This means that they  all behave as the identity function.
    All eleven  rules stated in figure  \ref{subfig} have been  shown to
    fit the relation.%


\newpage

\subsection{On the strength of free theorems}

%
%paragraphName: free theorems
Every   well-typed    function   comes    with   a    free   theorem
    \cite{wadler-free-89}. However depending on  the type of the function
    the  strength  of  the  theorem   varies  a  lot.  For  instance  at
    type  \texttt{Int $ \rightarrow $ Bool}  it  says  no more  than  the  function  is
    deterministic. At type \texttt{ $ \forall $\{A {\char `\:} Set\} $ \rightarrow $}{ }\texttt{A $ \rightarrow $ A}  it says that the
    function behaves like the identity function, which is much stronger.
    We now give a  few elements of what can affect  the strength of free
    theorems in our  context. We will continue to use  our \texttt{Tm} type to
    represent some data  structures with names and binders  but it could
    be any other.%


\paragraph{Various term types}

%
%paragraphName: the weakest
The weakest type  we can give to  a value with names  and binders is
    \texttt{Tm $ {(} $$ \emptyset $ $ \uparrow $ ℓ$ {)} $} for  a given  \texttt{ℓ}. Such a  term can  have a
    statically unknown  number of distinct  free variables, but  we know
    that these variables are comprised in the interval $ \mbox{{[}}{0}\mbox{ }\mbox{.}\mbox{.}\mbox{ }\mbox{ℓ}\mbox{-}{1}\mbox{{]}} $.
    The free theorem of \texttt{$ \forall $\{ℓ\} $ \rightarrow $}{ }\texttt{Tm $ {(} $$ \emptyset $ $ \uparrow $ }{ }\texttt{ℓ$ {)} $ $ \rightarrow $}{ }\texttt{Tm $ {(} $$ \emptyset $ }{ }\texttt{$ \uparrow $ ℓ$ {)} $} says no
    more than ``the function is deterministic''. We also know because of
    typing  that  the  resulting  term cannot have ℓ-free occurrences.%


%
%paragraphName: Tm (α ↑ ℓ)
A  stronger  type  is  to  use   any  world  instead  of  the  empty
    world, but  still have  a known  amount of  bindings. A  function of
    type \texttt{$ \forall $\{$ \alpha $ ℓ\} $ \rightarrow $}{ }\texttt{Tm $ {(} $$ \alpha $ $ \uparrow $ ℓ$ {)} $ $ \rightarrow $}{ }\texttt{Tm $ {(} $$ \alpha $ $ \uparrow $ ℓ$ {)} $}  has a  stronger free
    theorem. It says  that the function commutes with a  renaming of the
    variables in the  world $ \alpha $ (section \ref{paramSection}).  This is a
    common type  to deal  with open terms  under a  partial environment$:$
    \texttt{$ \forall $\{$ \alpha $ ℓ\} $ \rightarrow $}{ }\texttt{Vec Info ℓ $ \rightarrow $}{ }\texttt{Tm $ {(} $$ \alpha $ $ \uparrow $ ℓ$ {)} $ $ \rightarrow $}{ }\texttt{Tm $ {(} $$ \alpha $ $ \uparrow $ ℓ$ {)} $}.%


%
%paragraphName: Tm α
The strongest type for terms is to make no assumptions on their free
    variables. This  can be done  by quantifying by an  arbitrary world.
    The  free  theorem associated  with  the  type \texttt{$ \forall $ \{$ \alpha $\} $ \rightarrow $}{ }\texttt{Tm $ \alpha $ $ \rightarrow $}{ }\texttt{Tm $ \alpha $} says  that the function  commutes with renamings of  the free
    variables. This particular type is  studied in detail in the section
    \ref{paramSection}.%


\paragraph{Extra arguments}

%
%paragraphName: extra arguments
Note  that adding  extra  arguments to  a  function can  drastically
   affect the  strength of its free  theorem. An extreme example  is the
   type  \texttt{$ \forall $\{$ \alpha $\} $ \rightarrow $ $ {(} $$ \alpha $ $ \equiv $ $ \emptyset $$ {)} $ $ \rightarrow $}{ }\texttt{Tm $ \alpha $ $ \rightarrow $}{ }\texttt{Tm $ \alpha $}, which  is ruined  by its
   \texttt{$ \alpha $ $ \equiv $ $ \emptyset $} argument. While  the above example is  extreme, this is
   an important point to watch out  for when adding extra arguments to a
   function. Another  example is  the type \texttt{$ \forall $\{$ \alpha $ $ \beta $\} $ \rightarrow $}{ }\texttt{Tm $ \alpha $ $ \rightarrow $}{ }\texttt{Tm $ \beta $ $ \rightarrow $}{ }\texttt{Tm $ \beta $} versus \texttt{$ \forall $\{$ \alpha $ $ \beta $\} $ \rightarrow $}{ }\texttt{$ {(} $Name $ \alpha $ $ \rightarrow $}{ }\texttt{Name $ \beta $ $ \rightarrow $}{ }\texttt{Bool$ {)} $}{ }\texttt{$ \rightarrow $}{ }\texttt{Tm $ \alpha $ $ \rightarrow $}{ }\texttt{Tm $ \beta $ $ \rightarrow $}{ }\texttt{Tm $ \beta $}, the  first one cannot compare  the free variables of  the two
   given terms while the second can apply a user-supplied function to do
   so.%


\paragraph{Shifting versus adding}

%
%paragraphName: ↑ versus +ᵂ
Last but not least using \texttt{{\char `\+}ᵂ} instead of \texttt{$ \uparrow $} significantly improves
    the strength of the associated free theorem. Consider the function$:$%


%
%comment:
%protectedAdd : ∀ {α} ℓ k → Name (α ↑ ℓ)
%                         → Name (α +ᵂ k ↑ ℓ)
%protectedAdd ℓ k = protect↑ ℓ (addᴺ k)
%
%


~\\~\texttt{protectedAdd\mbox{\hspace{0.50em}}{\char `\:}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \forall $}\mbox{\hspace{0.50em}}\{\makebox[1.22ex][c]{$ \alpha $}\}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{ℓ}\mbox{\hspace{0.50em}}k\mbox{\hspace{0.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}Name\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}\makebox[1.22ex][c]{$ \alpha $}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \uparrow $}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{ℓ}\makebox[1.22ex][c]{$ {)} $}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{12.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}Name\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}\makebox[1.22ex][c]{$ \alpha $}\mbox{\hspace{0.50em}}{\char `\+}\makebox[0.61ex][c]{ᵂ}\mbox{\hspace{0.50em}}k\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \uparrow $}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{ℓ}\makebox[1.22ex][c]{$ {)} $}\vphantom{$\{$}{\nopagebreak[4] \newline%
}protectedAdd\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{ℓ}\mbox{\hspace{0.50em}}k\mbox{\hspace{0.50em}}{\char `\=}\mbox{\hspace{0.50em}}protect\makebox[1.22ex][c]{$ \uparrow $}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{ℓ}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}add\makebox[0.61ex][c]{ᴺ}\mbox{\hspace{0.50em}}k\makebox[1.22ex][c]{$ {)} $}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{1em}}}

%
%paragraphName: protectedAdd↑
Consider now a weaker type, namely$:$%


%
%comment:
%protectedAdd↑ : ∀ {α} ℓ k → Name (α ↑ ℓ)
%                          → Name (α ↑ k ↑ ℓ)
%protectedAdd↑ ℓ k = protect↑ ℓ (addᴺ↑ k)
%
%


~\\~\texttt{protectedAdd\makebox[1.22ex][c]{$ \uparrow $}\mbox{\hspace{0.50em}}{\char `\:}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \forall $}\mbox{\hspace{0.50em}}\{\makebox[1.22ex][c]{$ \alpha $}\}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{ℓ}\mbox{\hspace{0.50em}}k\mbox{\hspace{0.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}Name\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}\makebox[1.22ex][c]{$ \alpha $}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \uparrow $}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{ℓ}\makebox[1.22ex][c]{$ {)} $}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{13em}}$ \rightarrow $\mbox{\hspace{0.50em}}Name\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}\makebox[1.22ex][c]{$ \alpha $}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \uparrow $}\mbox{\hspace{0.50em}}k\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \uparrow $}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{ℓ}\makebox[1.22ex][c]{$ {)} $}\vphantom{$\{$}{\nopagebreak[4] \newline%
}protectedAdd\makebox[1.22ex][c]{$ \uparrow $}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{ℓ}\mbox{\hspace{0.50em}}k\mbox{\hspace{0.50em}}{\char `\=}\mbox{\hspace{0.50em}}protect\makebox[1.22ex][c]{$ \uparrow $}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{ℓ}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}add\makebox[0.61ex][c]{ᴺ}\makebox[1.22ex][c]{$ \uparrow $}\mbox{\hspace{0.50em}}k\makebox[1.22ex][c]{$ {)} $}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{1em}}}

%
%paragraphName: unprotectedAdd↑
We simply replaced the occurrence  of \texttt{{\char `\+}ᵂ} by \texttt{$ \uparrow $}. The consequences
    of this change  are disastrous$:$ this type allows  more behaviors for
    its functions. Indeed  the \texttt{addᴺ k} function can  be given the
    latter  type  (but  not  the  former)  when  using  the  appropriate
    inclusion witness to exploit the commutativity of \texttt{$ \uparrow $}$:$%


%
%comment:
%unprotectedAdd : ∀ {α} ℓ k → Name (α ↑ ℓ)
%                           → Name (α ↑ k ↑ ℓ)
%unprotectedAdd ℓ k
%  = coerceᴺ (⊆-exch-↑-↑′ ℓ k) ∘ addᴺ↑ k
%
%


~\\~\texttt{unprotectedAdd\mbox{\hspace{0.50em}}{\char `\:}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \forall $}\mbox{\hspace{0.50em}}\{\makebox[1.22ex][c]{$ \alpha $}\}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{ℓ}\mbox{\hspace{0.50em}}k\mbox{\hspace{0.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}Name\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}\makebox[1.22ex][c]{$ \alpha $}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \uparrow $}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{ℓ}\makebox[1.22ex][c]{$ {)} $}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{13.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}Name\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}\makebox[1.22ex][c]{$ \alpha $}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \uparrow $}\mbox{\hspace{0.50em}}k\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \uparrow $}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{ℓ}\makebox[1.22ex][c]{$ {)} $}\vphantom{$\{$}{\nopagebreak[4] \newline%
}unprotectedAdd\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{ℓ}\mbox{\hspace{0.50em}}k\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{1em}}{\char `\=}\mbox{\hspace{0.50em}}coerce\makebox[0.61ex][c]{ᴺ}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}\makebox[2.44ex][c]{$ \subseteq $}{\char `\-}exch{\char `\-}\makebox[1.22ex][c]{$ \uparrow $}{\char `\-}\makebox[1.22ex][c]{$ \uparrow $}′\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{ℓ}\mbox{\hspace{0.50em}}k\makebox[1.22ex][c]{$ {)} $}\mbox{\hspace{0.50em}}$ \circ $\mbox{\hspace{0.50em}}add\makebox[0.61ex][c]{ᴺ}\makebox[1.22ex][c]{$ \uparrow $}\mbox{\hspace{0.50em}}k\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{1em}}}

%
%paragraphName: the bug
In our  previous work  \cite{pouillard-pottier-10}  we had  only the
    \texttt{$ \uparrow $} operation. Our function \texttt{shiftName} (\texttt{protectedAdd}    in  this  example)  was   defined  with  the  \texttt{unprotectedAdd}    behavior. It took us a long  time to discover this mistake, since we
    thought that our logical relation argument was enough. In summary we
    want to  emphasis that all the  logical relations proofs have  to be
    taken with great care. A weaker function type than expected can ruin
    the intended informal properties.%


\subsection{Using logical relations and parametricity\label{paramSection}}

%
%paragraphName: using the parametricity results
To formally show that a world-polymorphic function \texttt{f} of type
    \texttt{$ \forall $ \{$ \alpha $\} $ \rightarrow $ Tm $ \alpha $ $ \rightarrow $ Tm $ \alpha $}  commutes with  a renaming  of the  free
    variables,  we  proceed as  follows.  First  we recall  the  natural
    definition of logical relation on  the type \texttt{Tm}. Second we present
    the  type \texttt{Ren}  of  renamings as  injective functions.  Third
    renaming is  shown equivalent  to being related  at the  type \texttt{Tm}.
    Finally we  prove our  commutation lemma  by using  the free-theorem
    associated to the function \texttt{f}.%


%
%paragraphName: ⟦Tm⟧
The logical  relation for  the type \texttt{Tm}  is mechanical.  It states
    that  two terms  are related  if they  have the  same structure  and
    related free variables$:$%


%
%comment:
%data ⟦Tm⟧ {α₁ α₂} (αᵣ : ⟦World⟧ α₁ α₂) :
%          Tm α₁ → Tm α₂ → Set where
%  ⟦V⟧    : ∀ {x₁ x₂} (xᵣ : ⟦Name⟧ αᵣ x₁ x₂)
%           → ⟦Tm⟧ αᵣ (V x₁) (V x₂)
%  _⟦·⟧_  : ∀ {t₁ t₂ u₁ u₂}
%             (tᵣ : ⟦Tm⟧ αᵣ t₁ t₂)
%             (uᵣ : ⟦Tm⟧ αᵣ u₁ u₂)
%           → ⟦Tm⟧ αᵣ (t₁ · u₁) (t₂ · u₂)
%  ⟦ƛ⟧    : ∀ {t₁ t₂} (tᵣ : ⟦Tm⟧ (αᵣ ⟦↑1⟧) t₁ t₂)
%           → ⟦Tm⟧ αᵣ (ƛ t₁) (ƛ t₂)
%  ⟦Let⟧  : ∀ {t₁ t₂ u₁ u₂}
%             (tᵣ : ⟦Tm⟧ αᵣ t₁ t₂)
%             (uᵣ : ⟦Tm⟧ (αᵣ ⟦↑1⟧) u₁ u₂)
%           → ⟦Tm⟧ αᵣ (Let t₁ u₁) (Let t₂ u₂)
%
%


~\\~\texttt{data\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{⟦}Tm\makebox[1.22ex][c]{⟧}\mbox{\hspace{0.50em}}\{\makebox[1.22ex][c]{$ \alpha $}\makebox[0.61ex][c]{₁}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \alpha $}\makebox[0.61ex][c]{₂}\}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}\makebox[1.22ex][c]{$ \alpha $}\makebox[0.61ex][c]{ᵣ}\mbox{\hspace{0.50em}}{\char `\:}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{⟦}World\makebox[1.22ex][c]{⟧}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \alpha $}\makebox[0.61ex][c]{₁}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \alpha $}\makebox[0.61ex][c]{₂}\makebox[1.22ex][c]{$ {)} $}\mbox{\hspace{0.50em}}{\char `\:}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{5em}}Tm\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \alpha $}\makebox[0.61ex][c]{₁}\mbox{\hspace{0.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}Tm\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \alpha $}\makebox[0.61ex][c]{₂}\mbox{\hspace{0.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}Set\mbox{\hspace{0.50em}}where\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{1em}}\makebox[1.22ex][c]{⟦}V\makebox[1.22ex][c]{⟧}\mbox{\hspace{2em}}{\char `\:}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \forall $}\mbox{\hspace{0.50em}}\{x\makebox[0.61ex][c]{₁}\mbox{\hspace{0.50em}}x\makebox[0.61ex][c]{₂}\}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}x\makebox[0.61ex][c]{ᵣ}\mbox{\hspace{0.50em}}{\char `\:}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{⟦}Name\makebox[1.22ex][c]{⟧}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \alpha $}\makebox[0.61ex][c]{ᵣ}\mbox{\hspace{0.50em}}x\makebox[0.61ex][c]{₁}\mbox{\hspace{0.50em}}x\makebox[0.61ex][c]{₂}\makebox[1.22ex][c]{$ {)} $}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{5.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{⟦}Tm\makebox[1.22ex][c]{⟧}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \alpha $}\makebox[0.61ex][c]{ᵣ}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}V\mbox{\hspace{0.50em}}x\makebox[0.61ex][c]{₁}\makebox[1.22ex][c]{$ {)} $}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}V\mbox{\hspace{0.50em}}x\makebox[0.61ex][c]{₂}\makebox[1.22ex][c]{$ {)} $}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{1em}}\makebox[1.22ex][c]{{\char `\_}}\makebox[1.22ex][c]{⟦}\makebox[1.22ex][c]{$ \cdotp $}\makebox[1.22ex][c]{⟧}\makebox[1.22ex][c]{{\char `\_}}\mbox{\hspace{1em}}{\char `\:}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \forall $}\mbox{\hspace{0.50em}}\{t\makebox[0.61ex][c]{₁}\mbox{\hspace{0.50em}}t\makebox[0.61ex][c]{₂}\mbox{\hspace{0.50em}}u\makebox[0.61ex][c]{₁}\mbox{\hspace{0.50em}}u\makebox[0.61ex][c]{₂}\}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{6.50em}}\makebox[1.22ex][c]{$ {(} $}t\makebox[0.61ex][c]{ᵣ}\mbox{\hspace{0.50em}}{\char `\:}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{⟦}Tm\makebox[1.22ex][c]{⟧}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \alpha $}\makebox[0.61ex][c]{ᵣ}\mbox{\hspace{0.50em}}t\makebox[0.61ex][c]{₁}\mbox{\hspace{0.50em}}t\makebox[0.61ex][c]{₂}\makebox[1.22ex][c]{$ {)} $}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{6.50em}}\makebox[1.22ex][c]{$ {(} $}u\makebox[0.61ex][c]{ᵣ}\mbox{\hspace{0.50em}}{\char `\:}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{⟦}Tm\makebox[1.22ex][c]{⟧}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \alpha $}\makebox[0.61ex][c]{ᵣ}\mbox{\hspace{0.50em}}u\makebox[0.61ex][c]{₁}\mbox{\hspace{0.50em}}u\makebox[0.61ex][c]{₂}\makebox[1.22ex][c]{$ {)} $}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{5.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{⟦}Tm\makebox[1.22ex][c]{⟧}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \alpha $}\makebox[0.61ex][c]{ᵣ}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}t\makebox[0.61ex][c]{₁}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \cdotp $}\mbox{\hspace{0.50em}}u\makebox[0.61ex][c]{₁}\makebox[1.22ex][c]{$ {)} $}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}t\makebox[0.61ex][c]{₂}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \cdotp $}\mbox{\hspace{0.50em}}u\makebox[0.61ex][c]{₂}\makebox[1.22ex][c]{$ {)} $}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{1em}}\makebox[1.22ex][c]{⟦}\makebox[1.22ex][c]{ƛ}\makebox[1.22ex][c]{⟧}\mbox{\hspace{2em}}{\char `\:}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \forall $}\mbox{\hspace{0.50em}}\{t\makebox[0.61ex][c]{₁}\mbox{\hspace{0.50em}}t\makebox[0.61ex][c]{₂}\}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}t\makebox[0.61ex][c]{ᵣ}\mbox{\hspace{0.50em}}{\char `\:}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{⟦}Tm\makebox[1.22ex][c]{⟧}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}\makebox[1.22ex][c]{$ \alpha $}\makebox[0.61ex][c]{ᵣ}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{⟦}\makebox[1.22ex][c]{$ \uparrow $}1\makebox[1.22ex][c]{⟧}\makebox[1.22ex][c]{$ {)} $}\mbox{\hspace{0.50em}}t\makebox[0.61ex][c]{₁}\mbox{\hspace{0.50em}}t\makebox[0.61ex][c]{₂}\makebox[1.22ex][c]{$ {)} $}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{5.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{⟦}Tm\makebox[1.22ex][c]{⟧}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \alpha $}\makebox[0.61ex][c]{ᵣ}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}\makebox[1.22ex][c]{ƛ}\mbox{\hspace{0.50em}}t\makebox[0.61ex][c]{₁}\makebox[1.22ex][c]{$ {)} $}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}\makebox[1.22ex][c]{ƛ}\mbox{\hspace{0.50em}}t\makebox[0.61ex][c]{₂}\makebox[1.22ex][c]{$ {)} $}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{1em}}\makebox[1.22ex][c]{⟦}Let\makebox[1.22ex][c]{⟧}\mbox{\hspace{1em}}{\char `\:}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \forall $}\mbox{\hspace{0.50em}}\{t\makebox[0.61ex][c]{₁}\mbox{\hspace{0.50em}}t\makebox[0.61ex][c]{₂}\mbox{\hspace{0.50em}}u\makebox[0.61ex][c]{₁}\mbox{\hspace{0.50em}}u\makebox[0.61ex][c]{₂}\}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{6.50em}}\makebox[1.22ex][c]{$ {(} $}t\makebox[0.61ex][c]{ᵣ}\mbox{\hspace{0.50em}}{\char `\:}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{⟦}Tm\makebox[1.22ex][c]{⟧}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \alpha $}\makebox[0.61ex][c]{ᵣ}\mbox{\hspace{0.50em}}t\makebox[0.61ex][c]{₁}\mbox{\hspace{0.50em}}t\makebox[0.61ex][c]{₂}\makebox[1.22ex][c]{$ {)} $}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{6.50em}}\makebox[1.22ex][c]{$ {(} $}u\makebox[0.61ex][c]{ᵣ}\mbox{\hspace{0.50em}}{\char `\:}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{⟦}Tm\makebox[1.22ex][c]{⟧}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}\makebox[1.22ex][c]{$ \alpha $}\makebox[0.61ex][c]{ᵣ}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{⟦}\makebox[1.22ex][c]{$ \uparrow $}1\makebox[1.22ex][c]{⟧}\makebox[1.22ex][c]{$ {)} $}\mbox{\hspace{0.50em}}u\makebox[0.61ex][c]{₁}\mbox{\hspace{0.50em}}u\makebox[0.61ex][c]{₂}\makebox[1.22ex][c]{$ {)} $}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{5.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{⟦}Tm\makebox[1.22ex][c]{⟧}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \alpha $}\makebox[0.61ex][c]{ᵣ}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}Let\mbox{\hspace{0.50em}}t\makebox[0.61ex][c]{₁}\mbox{\hspace{0.50em}}u\makebox[0.61ex][c]{₁}\makebox[1.22ex][c]{$ {)} $}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}Let\mbox{\hspace{0.50em}}t\makebox[0.61ex][c]{₂}\mbox{\hspace{0.50em}}u\makebox[0.61ex][c]{₂}\makebox[1.22ex][c]{$ {)} $}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{1em}}}

%
%paragraphName: Ren
Then  we need  a  notion of  renaming. We  choose  to use  injective
    functions over  names. The type  for a renaming is  \texttt{Ren}, and
    the  functions \texttt{⟨{\char `\_}⟩}  and \texttt{⟪{\char `\_}⟫}  respectively convert  a
    renaming to a function over names, and to a relation over worlds$:$%


%
%comment:
%Ren : (α β : World) → Set
%
%⟨_⟩ : ∀ {α β} → Ren α β → Tm α → Tm β
%
%⟪_⟫ : ∀ {α β} → Ren α β → ⟦World⟧ α β
%
%


~\\~\texttt{Ren\mbox{\hspace{0.50em}}{\char `\:}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}\makebox[1.22ex][c]{$ \alpha $}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \beta $}\mbox{\hspace{0.50em}}{\char `\:}\mbox{\hspace{0.50em}}World\makebox[1.22ex][c]{$ {)} $}\mbox{\hspace{0.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}Set\vphantom{$\{$}{\nopagebreak[4] \newline%
}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\makebox[1.22ex][c]{⟨}\makebox[1.22ex][c]{{\char `\_}}\makebox[1.22ex][c]{⟩}\mbox{\hspace{0.50em}}{\char `\:}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \forall $}\mbox{\hspace{0.50em}}\{\makebox[1.22ex][c]{$ \alpha $}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \beta $}\}\mbox{\hspace{0.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}Ren\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \alpha $}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \beta $}\mbox{\hspace{0.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}Tm\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \alpha $}\mbox{\hspace{0.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}Tm\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \beta $}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\vphantom{$\{$}{\nopagebreak[4] \newline%
}⟪\makebox[1.22ex][c]{{\char `\_}}⟫\mbox{\hspace{0.50em}}{\char `\:}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \forall $}\mbox{\hspace{0.50em}}\{\makebox[1.22ex][c]{$ \alpha $}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \beta $}\}\mbox{\hspace{0.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}Ren\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \alpha $}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \beta $}\mbox{\hspace{0.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{⟦}World\makebox[1.22ex][c]{⟧}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \alpha $}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \beta $}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{1em}}}

%
%paragraphName: ⟦Tm⟧⇔rename
We now  observe that  given a renaming  \texttt{$ \Phi $}, it  is equivalent
    for  two   terms  \texttt{t₁}  and   \texttt{t₂}  to  be   related  by
    \texttt{⟦Tm⟧ ⟪ $ \Phi $ ⟫}  and for  \texttt{t₂}  to be  equal to  \texttt{t₁}    renamed with \texttt{$ \Phi $}.%


%
%comment:
%⟦Tm⟧⇔rename :
%   ∀ {α β} (Φ : Ren α β) {t₁ t₂}
%   → ⟦Tm⟧ ⟪ Φ ⟫ t₁ t₂ ⇔ (⟨ Φ ⟩ t₁) ≡ t₂
%
%


~\\~\texttt{\makebox[1.22ex][c]{⟦}Tm\makebox[1.22ex][c]{⟧}$ \Leftrightarrow $rename\mbox{\hspace{0.50em}}{\char `\:}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{1.50em}}\makebox[1.22ex][c]{$ \forall $}\mbox{\hspace{0.50em}}\{\makebox[1.22ex][c]{$ \alpha $}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \beta $}\}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}$ \Phi $\mbox{\hspace{0.50em}}{\char `\:}\mbox{\hspace{0.50em}}Ren\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \alpha $}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \beta $}\makebox[1.22ex][c]{$ {)} $}\mbox{\hspace{0.50em}}\{t\makebox[0.61ex][c]{₁}\mbox{\hspace{0.50em}}t\makebox[0.61ex][c]{₂}\}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{1.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{⟦}Tm\makebox[1.22ex][c]{⟧}\mbox{\hspace{0.50em}}⟪\mbox{\hspace{0.50em}}$ \Phi $\mbox{\hspace{0.50em}}⟫\mbox{\hspace{0.50em}}t\makebox[0.61ex][c]{₁}\mbox{\hspace{0.50em}}t\makebox[0.61ex][c]{₂}\mbox{\hspace{0.50em}}$ \Leftrightarrow $\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}\makebox[1.22ex][c]{⟨}\mbox{\hspace{0.50em}}$ \Phi $\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{⟩}\mbox{\hspace{0.50em}}t\makebox[0.61ex][c]{₁}\makebox[1.22ex][c]{$ {)} $}\mbox{\hspace{0.50em}}$ \equiv $\mbox{\hspace{0.50em}}t\makebox[0.61ex][c]{₂}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{1em}}}

\newpage

%
%paragraphName: ren-comm
Finally  given a  function  \texttt{f} and  a  proof \texttt{fᵣ}  that
    \texttt{f} is in the logical relation,  we can show that any renaming
    \texttt{$ \Phi $} commutes with the function \texttt{f}. To prove so we apply
    our \texttt{⟦Tm⟧$ \Leftrightarrow $rename} lemma in  both directions and use \texttt{fᵣ}    with the renaming \texttt{$ \Phi $} lifted as a \texttt{⟦World⟧}.%


%
%comment:
%ren-comm :
% (f : ∀ {α} → Tm α → Tm α)
% (fᵣ:(∀⟨ αᵣ ∶ ⟦World⟧ ⟩⟦→⟧ ⟦Tm⟧ αᵣ ⟦→⟧ ⟦Tm⟧ αᵣ)f f)
% → ∀ {α β} (Φ : Ren α β)
% → ⟨ Φ ⟩ ∘ f ≗ f ∘ ⟨ Φ ⟩
%ren-comm f fᵣ Φ t
%   = ⟦Tm⟧⇒rename Φ
%        (fᵣ ⟪ Φ ⟫ (rename⇒⟦Tm⟧ Φ ≡.refl))
%
%


~\\~\texttt{ren{\char `\-}comm\mbox{\hspace{0.50em}}{\char `\:}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}f\mbox{\hspace{0.50em}}{\char `\:}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \forall $}\mbox{\hspace{0.50em}}\{\makebox[1.22ex][c]{$ \alpha $}\}\mbox{\hspace{0.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}Tm\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \alpha $}\mbox{\hspace{0.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}Tm\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \alpha $}\makebox[1.22ex][c]{$ {)} $}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}f\makebox[0.61ex][c]{ᵣ}{\char `\:}\makebox[1.22ex][c]{$ {(} $}\makebox[1.22ex][c]{$ \forall $}\makebox[1.22ex][c]{⟨}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \alpha $}\makebox[0.61ex][c]{ᵣ}\mbox{\hspace{0.50em}}∶\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{⟦}World\makebox[1.22ex][c]{⟧}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{⟩}\makebox[1.22ex][c]{⟦}$ \rightarrow $\makebox[1.22ex][c]{⟧}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{⟦}Tm\makebox[1.22ex][c]{⟧}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \alpha $}\makebox[0.61ex][c]{ᵣ}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{⟦}$ \rightarrow $\makebox[1.22ex][c]{⟧}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{⟦}Tm\makebox[1.22ex][c]{⟧}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \alpha $}\makebox[0.61ex][c]{ᵣ}\makebox[1.22ex][c]{$ {)} $}f\mbox{\hspace{0.50em}}f\makebox[1.22ex][c]{$ {)} $}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{0.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \forall $}\mbox{\hspace{0.50em}}\{\makebox[1.22ex][c]{$ \alpha $}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \beta $}\}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}$ \Phi $\mbox{\hspace{0.50em}}{\char `\:}\mbox{\hspace{0.50em}}Ren\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \alpha $}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ \beta $}\makebox[1.22ex][c]{$ {)} $}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{0.50em}}$ \rightarrow $\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{⟨}\mbox{\hspace{0.50em}}$ \Phi $\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{⟩}\mbox{\hspace{0.50em}}$ \circ $\mbox{\hspace{0.50em}}f\mbox{\hspace{0.50em}}≗\mbox{\hspace{0.50em}}f\mbox{\hspace{0.50em}}$ \circ $\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{⟨}\mbox{\hspace{0.50em}}$ \Phi $\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{⟩}\vphantom{$\{$}{\nopagebreak[4] \newline%
}ren{\char `\-}comm\mbox{\hspace{0.50em}}f\mbox{\hspace{0.50em}}f\makebox[0.61ex][c]{ᵣ}\mbox{\hspace{0.50em}}$ \Phi $\mbox{\hspace{0.50em}}t\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{1.50em}}{\char `\=}\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{⟦}Tm\makebox[1.22ex][c]{⟧}$ \Rightarrow $rename\mbox{\hspace{0.50em}}$ \Phi $\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{4em}}\makebox[1.22ex][c]{$ {(} $}f\makebox[0.61ex][c]{ᵣ}\mbox{\hspace{0.50em}}⟪\mbox{\hspace{0.50em}}$ \Phi $\mbox{\hspace{0.50em}}⟫\mbox{\hspace{0.50em}}\makebox[1.22ex][c]{$ {(} $}rename$ \Rightarrow $\makebox[1.22ex][c]{⟦}Tm\makebox[1.22ex][c]{⟧}\mbox{\hspace{0.50em}}$ \Phi $\mbox{\hspace{0.50em}}$ \equiv ${\char `\.}refl\makebox[1.22ex][c]{$ {)} $}\makebox[1.22ex][c]{$ {)} $}\vphantom{$\{$}{\nopagebreak[4] \newline%
}\mbox{\hspace{1em}}}

\section{Conclusion and future work\label{concl}}

%
%paragraphName: conclusion
We  have shown  a  new  approach for  a  safer nameless  programming
    interface.  Our work  relies on  a different  notion of  worlds both
    finer and more  abstract. The type of names  while being represented
    as a natural  number is kept abstract as well.  Only a few functions
    are  required from  the  interface to  get complete  expressiveness.
    Indeed  while  our  worlds  are more  precise,  nothing  forces  the
    programmer  to be  precise  with  them. Thus  there  is  no loss  of
    expressiveness  compared to  the \texttt{Fin}  approach. Through  concrete
    examples  we have  shown how  we can  program in  this system  using
    classical examples  like capture avoiding substitution.  However the
    most challenging result comes  from the solid mechanized development
    we  have made  in \textsc{Agda}.  This development  not only  demonstrates
    the  soundness  of our  approach  but  allows to  derive  properties
    of  functions  using  the  system.  This  way  we  have  shown  that
    world-polymorphic  functions over  terms commute  with renamings  of
    free variables. These  soundness results are shown in  a modular way
    and reuse the solid foundations of logical relations.%


%
%paragraphName: future work
As future  work we  would like  to explore  more properties  of this
    system. We  have also seen that  a major convenience problem  in our
    system  was to  build world  inclusion witnesses.  We would  like to
    address  this  problem  through  a witness  inference  system  built
    within  \textsc{Agda},  using  the recent  reflection  mechanism.  Another
    time-consuming task  was to apply  the \textsc{Agda} logical  relations to
    types and operations, so we would like to explore the integration of
    inspection primitives  and meta-programming facilities  for \textsc{Agda},
    namely \textsc{Template Agda}.  Finally we  would like to  investigate how
    this system could scale to representations of well-typed terms.%


\paragraph{Acknowledgements}

%
%paragraphName: Acknowledgements
Thanks  to  François   Pottier,  Jean-Philippe  Bernardy,  Alexandre
    Pilkiewicz, and the  anonymous reviewers for providing  us with very
    valuable feedback.%


\newpage

\bibliographystyle{plain}

\bibliography{bib,local}
\end{document}