Straightfoward, by induction on the structure of $\ts$.
Straightfoward, by induction on the structure of $\ts$.
\end{proof}
\begin{lemma}[Monotonicity of the algorithm] Let $\Gamma$, $\Gamma'$ and $e$ such that $\Gamma'\leqA^e \Gamma$ and $\tyof e \Gamma\neq\tsempty$. We have:
...
...
@@ -1181,8 +1183,7 @@
Let's prove the first property: $\tyof e {\Gamma'}\leq\tyof e {\Gamma}\text{ and }\tsrep{\tyof e {\Gamma'}}\leq\tsrep{\tyof e {\Gamma}}$.
We will focus on showing $\tyof e {\Gamma'}\leq\tyof e {\Gamma}$. The property $\tsrep{\tyof e {\Gamma'}}\leq\tsrep{\tyof e {\Gamma}}$
can be proved in a very similar way, by using the fact that $\tsrep{t \tsand\ts}\leq t \land\tsrep{\ts}$,
$\tsrep{\ts_1\tsor\ts_2}=\tsrep{\ts_1}\vee\tsrep{\ts_2}$ and $\tsrep{\ts_1\tstimes\ts_2}=\pair{\tsrep{\ts_1}}{\tsrep{\ts_2}}$.
can be proved in a very similar way, by using the fact that operators on type schemes like $\tsand$ or $\apply{}{}$ are also monotone.
(Note that the only rule that introduces the type scheme constructor $\tsfun{\_}$ is \Rule{Abs\Aa}.)
If $\Gamma' =\bot$ we can conclude directly with the rule \Rule{Efq}.
...
...
@@ -1299,7 +1300,7 @@
$\bigwedge_{\{\varpi\alt\occ e \varpi\equiv e'\}}\env{\Gamma',e,t}(\varpi)\leq\bigwedge_{\{\varpi\alt\occ e \varpi\equiv e'\}}\env{\Gamma,e,t}(\varpi)$.
The rest follows.
\end{proof}
\end{proof}
\begin{theorem}[Completeness of the algorithm for positive derivations]
For any $\Gamma$, $e$, $t$ such that we have a positive derivation of $\Gamma\vdash e:t$,
...
...
@@ -1307,18 +1308,129 @@
More precisely:
\begin{align*}
&\forall\Gamma, e, t.\ \Gamma\vdash e:t \text{ has a positive derivation }\Rightarrow\tsrep{\tyof e \Gamma}\leq t \text{ (for $n_o$ large enough)}\\
&\forall\Gamma, e, t, t', \varpi.\ \pvdash\Gamma e t \varpi:t' \text{ has a positive derivation }\Rightarrow\env{\Gamma,e,t} (\varpi) \leq t' \text{ (for $n_o$ large enough)}\\
&\forall\Gamma, e, t.\ \Gamma\vdash e:t \text{ has a positive derivation }\Rightarrow\tsrep{\tyof e \Gamma}\leq t\\
&\forall\Gamma, \Gamma', e, t.\ \Gamma\evdash e t \Gamma' \text{ has a positive derivation }\Rightarrow\Refine{e,t}\Gamma\leqA\Gamma' \text{ (for $n_o$ large enough)}
\end{align*}
\end{theorem}
\begin{proof}
We proceed by induction on the declarative derivation.
We proceed by induction on the derivation.
Let's prove the first property. We have a positive derivation of $\Gamma\vdash e:t$.
If $\Gamma=\bot$, we can conclude directly using \Rule{Efq\Aa}. Thus, let's suppose $\Gamma\neq\bot$.
If $e=x$ is a variable, then the derivation only uses \Rule{Env}, \Rule{Inter} and \Rule{Subs}.
We can easily conclude just be using \Rule{Var\Aa}. Thus, let's suppose $e$ is not a variable.
If $e\in\dom\Gamma$, we can have the rule \Rule{Env} in our derivation, but there can only be
\Rule{Inter} and \Rule{Subs} after it (not \Rule{Abs-} as we have a positive derivation).
Thus, we can build a positive derivation of $\Gamma\vdash e:t'$ that does not use the rule \Rule{Env} on $e$
and such that $t'\land\Gamma(e)\leq t$. Thus we have a positive derivation for $\Gamma\setminus\{e\}\vdash e:t'$.
By using the induction hypothesis we deduce that $\tsrep{\tyof e {\Gamma\setminus\{e\}}}\leq t'$.
Thus, by looking at the rule \Rule{Env\Aa},
we deduce $\tsrep{\tyof e \Gamma}\leq\Gamma(e)\land\tsrep{\tyof e {\Gamma\setminus\{e\}}}\leq t$.
It concludes this case, so let's assume $e\not\in\dom\Gamma$.
Now we analyze the last rule of the derivation:
\begin{description}
\item[\Rule{Env}] Impossible case ($e\not\in\dom\Gamma$).
\item[\Rule{Inter}] By using the induction hypothesis we get $\tsrep{\tyof e \Gamma}\leq t_1$ and $\tsrep{\tyof e \Gamma}\leq t_2$.
Thus, we have $\tsrep{\tyof e \Gamma}\leq t_1\land t_2$.
\item[\Rule{Subs}] Trivial using the induction hypothesis.
\item[\Rule{Const}] We know that the derivation of $\tyof e \Gamma$ ends with the rule \Rule{Const\Aa}.
Thus this case is trivial.
\item[\Rule{App}] We know that the derivation of $\tyof e \Gamma$ ends with the rule \Rule{App\Aa}.
Let $\ts_1=\tyof{e_1}\Gamma$ and $\ts_2=\tyof{e_2}\Gamma$.
With the induction hypothesis we have $\tsrep{\ts_1}\leq\arrow{t_1}{t_2}$ and $\tsrep{\ts_2}\leq t_1$, with $t_2=t$.
According to the descriptive definition of $\apply{}{}$, we have
And thus $\worra{\tsrep{\tyof{\occ e {\varpi.0}}{\Gamma''}}}{\env{\Gamma'',e,t}(\varpi)}\leq\neg t_1$.
It concludes this case.
\item[\Rule{PAppL}] By using the induction hypothesis we get
$\env{\Gamma_1'',e,t}(\varpi.1)\leq t_1$ and $\env{\Gamma_2'',e,t}(\varpi)\leq t_2$
with $\RefineStep{e,t}^{n_1}(\Gamma_2)\leqA\Gamma_1''$ and
$\RefineStep{e,t}^{n_2}(\Gamma_2)\leqA\Gamma_2''$. By taking $n'=\max(n_1,n_2)$,
we have $\RefineStep{e,t}^{n'}(\Gamma_2)\leqA\Gamma''$ with $\Gamma'' \leqA\Gamma_1''$ and $\Gamma'' \leqA\Gamma_2''$.
Thus, by using the monotonicity lemma, we can obtain $\env{\Gamma'',e,t}(\varpi.0)\leq\neg(\arrow{t_1}{\neg t_2})= t'$.
\item[\Rule{PPairL}] Trivial using the induction hypothesis and the descriptive definition of $\bpi_1$.
\item[\Rule{PPairR}] Trivial using the induction hypothesis and the descriptive definition of $\bpi_2$.
\item[\Rule{PFst}] Trivial using the induction hypothesis.
\item[\Rule{PSnd}] Trivial using the induction hypothesis.
\end{description}
\end{description}
\end{proof}
...
...
@@ -1328,9 +1440,8 @@
More precisely:
\begin{align*}
&\forall\Gamma, e, t.\ \Gamma\vdash e:t \text{ has an acceptable derivation }\Rightarrow\tyof e \Gamma\leq t \text{ (for $n_o$ large enough)}\\
&\forall\Gamma, e, t, t', \varpi.\ \pvdash\Gamma e t \varpi:t' \text{ has an acceptable derivation }\Rightarrow\env{\Gamma,e,t} (\varpi) \tsand\tyof{\occ e \varpi}\Gamma\leq t' \text{ (for $n_o$ large enough)}\\
&\forall\Gamma, e, t.\ \Gamma\vdash e:t \text{ has an acceptable derivation }\Rightarrow\tyof e \Gamma\leq t\\
&\forall\Gamma, \Gamma', e, t.\ \Gamma\evdash e t \Gamma' \text{ has an acceptable derivation }\Rightarrow\Refine{e,t}\Gamma\leqA\Gamma' \text{ (for $n_o$ large enough)}