
\section{Convergence of Bellantoni-Cook programs}

\anupam{In this section, use whatever form of the deduction theorem is necessary and reverse engineer precise statement later.}


\subsection{Bellantoni-Cook programs}
We first recall the notion of safe recursion on notation from BC. TODO

\anupam{Do we need simultaneous PRN? cf.\ Bellantoni's thesis.}

\todo{reformulate below for binary words, not natural numbers?}

\begin{definition}
	[BC functions]
	BC is the set of functions generated by the following initial functions and closure schemes.
	
%	\paragraph{Initial functions}
	There are the following initial functions:
	\begin{enumerate}
		\item The constant function $0$ which takes no arguments and outputs $0 \in \Nat$.
		\item The projection functions $\pi^{m,n}_k ( x_1 , \dots , x_m ; x_{m+1} , \dots, x_{m+n} )  := x_k$ for $n,m \in \Nat$ and $1 \leq k \leq m+n$.
		\item The successor functions $\succ_i ( ; x) := xi$ for $i = 0,1$.
		\item The predecessor function $\pred (; x) := \begin{cases}
		0 & x = 0 \\
		x' & x = x'i
		\end{cases}$.
		\item The conditional function $\cond (;x,y,z) := \begin{cases}
		y & x \mod{2} = 0 \\
		z & \text{otherwise}
		\end{cases}$.
	\end{enumerate}
	
	There are the following closure properties.
	\begin{enumerate}
	\setcounter{enumi}{5}
	\item Predicative recursion on notation. If $g, h_0, h_1 $ are in BC then so is the function $f$ defined by,
	\[
	\begin{array}{rcl}
	f(0, \vec v ; \vec x) & := & g(\vec v ; \vec x) \\
	f (\succ_i u , \vec v ; \vec x ) & := & h_i ( u , \vec v ; \vec x , f (u , \vec v ; \vec x) )
	\end{array}
	\]
	for $i = 0,1$, so long as the expressions are well-formed (i.e.\ in number/sort of arguments).
	\item Safe composition. If $g, \vec h, \vec h'$ are in BC then so is $f$ defined by,
	\[
	f (\vec u ; \vec x) \quad := \quad g ( \vec h(\vec u ; ) ; \vec h' (\vec u ; \vec x) )
	\]
	so long as the expression is well-formed.
	\end{enumerate}
	\end{definition}


\anupam{simultaneous recursion?}

\subsection{Convergence in arithmetic}
\begin{theorem}
	[Convergence]
	If $\Phi(f)$ is an equational specification corresponding to a BC-program defining $f$, then $\cax{\Sigma^N_1}{\pind} \proves  \ !\Phi(f) \limp \forall \vec{x}^{!N} . N(f(\vec x))$.
\end{theorem}
\begin{proof}
%	We write function symbols in $\arith$ with arguments delimited by $;$, as for BC-programs. 
	We show by induction on the structure of a BC-program for $f(\vec u ; \vec x)$ that:
	\begin{equation}
	\label{eqn:prv-cvg-ih}
	\Phi(f) \proves \ \forall \vec{u}^{!\nat} . \forall \vec{x}^\nat . \nat(f(\vec u ; \vec x))
	\end{equation}
	We give some key cases in what follows.
	
	Suppose $f$ is defined by PRN as:
	\[
	\begin{array}{rcl}
	f(0,\vec v ; \vec x) & = & g(\vec v ; \vec x) \\
	f(\succ_i u , \vec v; \vec x) & = & h_i (u, \vec v ; \vec x , f(u , \vec v ; \vec x))
	\end{array}
	\]
	By the inductive hypothesis we already have \eqref{eqn:prv-cvg-ih} for $g,h_0,h_1$ in place of $f$, so let us suppose that $\nat(\vec v)$ and prove,
	\begin{equation}
% \forall u^{!\nat} .  (\nat(\vec x) \limp \nat(f(u , \vec v ; \vec x)  )
!\nat (u) , !\nat (\vec v) , \nat (\vec x) \seqar \nat ( f(u, \vec v ; \vec x) )
	\end{equation}
	by $\cax{\Sigma^N_1}{\pind}$ on $u$. After this the result will follow by $\forall$-introduction for $u, \vec v , \vec x$.
	
	In the base case we have the following proof,
	\[
%	\vlderivation{
%	\vlin{\rigrul{\limp}}{}{ \seqar \nat (\vec x) \limp \nat (f(\epsilon , \vec v ; \vec x )) }{
%		\vliq{\beta}{}{ \nat (\vec x) \seqar \nat ( f( \epsilon , \vec v ; \vec x) ) }{
%			\vliq{\alpha}{}{ \nat (\vec x) \seqar \nat ( g (\vec v ; \vec x) ) }{
%				\vltr{IH}{\seqar \forall v^{!\nat} . \forall x^\nat . \nat( g(\vec v ; \vec x) ) }{\vlhy{\quad}}{\vlhy{}}{\vlhy{\quad}}
%				}
%			}
%		}		
%		}
\vlderivation{
	\vliq{\beta}{}{!\nat(\vec v) , \nat (\vec x) \seqar \nat(f (\epsilon , \vec v ; \vec x)) }{
		\vliq{\alpha}{}{!\nat (\vec v) , \nat (\vec x) \seqar \nat (g (\vec v ; \vec x) ) }{
			\vltr{\IH}{\seqar \forall \vec v^{!\nat} . \forall \vec x^\nat . \nat (g (\vec v ; \vec x)) }{\vlhy{\quad}}{\vlhy{}}{\vlhy{\quad}}
			}
		}
	}
\]
where $\alpha$ is,
\[
\vlderivation{
%	\vliin{\cut}{}{ \nat (\vec x) \seqar \nat ( g (\vec v ; \vec x)) }{
%		\vlin{\rigrul{!}}{}{\seqar !\nat (v)}{
%			\vlin{assump}{}{\seqar \nat (\vec v)}{\vlhy{}}
%			}
%		}{
		\vliin{\cut}{}{ !\nat (\vec v ) , \nat (\vec x) \seqar \nat (g (\vec v ; \vec x )) }{
			\vlhy{\seqar \forall \vec v^{!\nat} . \forall \vec x^\nat . \nat (g (\vec v ; \vec x)) }
			}{
			\vliq{\lefrul{\forall}}{  }{ !\nat (\vec v) , \nat (\vec x) , \forall \vec v^{!\nat} . \forall \vec x^\nat \nat (g(\vec v ; \vec x )) \seqar \nat (g(\vec v ; \vec x )) }{
				\vlin{\id}{}{\nat (g(\vec v ; \vec x )) \seqar \nat (g(\vec v ; \vec x ))}{\vlhy{}}
				}
			}
%		}
	}
\]
and $\beta$ is:
\[
\vlderivation{
	\vliin{\cut}{}{!\nat (\vec v) , \nat (\vec x) \seqar \nat ( f ( \epsilon , \vec v ; \vec x ) ) }{
		\vlhy{!\nat (\vec v) , \nat (\vec x) \seqar \nat (g (\vec v ; \vec x) ) }
		}{
		\vliin{\cut}{}{ \nat (g (\vec v ; \vec x) ) \seqar \nat (f (\epsilon, \vec v ; \vec x) ) }{
			\vlin{\Phi}{}{ \seqar f(\epsilon , \vec v ; \vec x) = g(\vec v ; \vec x) }{\vlhy{}}
			}{
			\vlin{=}{}{\nat ( g(\vec v ; \vec x) ) , f(\epsilon , \vec v ; \vec x) = g(\vec v ; \vec x)  \seqar \nat (f (\epsilon, \vec v ; \vec x) ) }{\vlhy{}}
			}
		}
	}
\]

For the inductive step, we suppose that $\nat (u)$ and the proof is as follows,
\[
%\vlderivation{
%	\vlin{\rigrul{\limp}}{}{ \nat(\vec x) \limp \nat ( f(u, \vec v ; \vec x) )  \seqar \nat (\vec x) \limp \nat( f(\succ_i u , \vec v ; \vec x) ) }{
%	\vliq{\gamma}{}{\nat(\vec x), \nat(\vec x) \limp \nat ( f(u, \vec v ; \vec x) )  \seqar \nat( f(\succ_i u , \vec v ; \vec x) )   }{
%		\vliin{\lefrul{\limp}}{}{\nat(\vec x), \nat(\vec x), \nat(\vec x) \limp \nat ( f(u, \vec v ; \vec x) )  \seqar \nat( f(\succ_i u , \vec v ; \vec x) )    }{
%			\vlin{\id}{}{\nat(\vec x) \seqar \nat (\vec x) }{\vlhy{}}
%			}{
%			\vliq{\beta}{}{  \nat (\vec x) , \nat (f(u , \vec v ; \vec x) ) \seqar \nat ( f(\succ_i u , \vec v ; \vec x) ) }{
%				\vliq{\alpha}{}{ \nat (\vec x) , \nat (f(u , \vec v ; \vec x) ) \seqar \nat ( h_i( u , \vec v ; \vec x , f( u, \vec v ; \vec x )) ) }{
%					\vltr{IH}{ \seqar \forall  u^{!\nat}, \vec v^{!\nat} . \forall \vec x^\nat , y^\nat . \nat( h_i (u, \vec v ; \vec x, y) ) }{\vlhy{\quad}}{\vlhy{}}{\vlhy{\quad}}
%					}
%				}
%			}
%		}
%	}
%	}
\vlderivation{
	\vliq{\beta}{}{ !\nat (u) , !\nat (\vec v)  , \nat (\vec x) , \nat (f ( u , \vec v ; \vec x ) ) \seqar \nat (f (\succ_i u , \vec{v} ; \vec x ) )  }{
		\vliq{\alpha}{}{  !\nat (u) , !\nat (\vec v)  , \nat (\vec x) , \nat (f ( u , \vec v ; \vec x ) ) \seqar \nat ( h_i ( u , \vec v ; \vec x , f( u , \vec v ; \vec x ) ) )   }{
			\vltr{\IH}{ \seqar \forall u^{!\nat} , \vec v^{!\nat} . \forall \vec x^\nat , y^\nat  .  \nat ( h_i ( u, \vec v ; \vec x, y ) ) }{ \vlhy{\quad} }{\vlhy{}}{\vlhy{\quad}}
		}
	}
}
\]
where the steps indicated $\alpha$ and $\beta$ are analogous to those for the base case, and $\gamma$ is an instance of the general scheme:
\begin{equation}
\label{eqn:nat-cntr-left-derivation}
\vlderivation{
	\vliin{\cut}{}{ \nat (t) , \Gamma \seqar \Delta }{
		\vlin{\natcntr}{}{ \nat (t) \seqar \nat (t) \land \nat (t) }{\vlhy{}}
		}{
		\vlin{\lefrul{\land}}{}{\nat (t)  \land \nat (t) , \Gamma \seqar \Delta}{ \vlhy{\nat (t)  ,\nat (t) , \Gamma \seqar \Delta} }
		}
	}
\end{equation}

%
%For the inductive step, we need to show that,
%\[
%\forall x^{!N} . (( N(\vec y) \limp N( f(x, \vec x ; \vec y) ) ) \limp N(\vec y) \limp N(f(\succ_i x , \vec x ; \vec y) )   )
%\]
%so let us suppose that $N(x)$ and we give the following proof:
%\[
%\vlderivation{
%	\vlin{N\cntr}{}{N(y) \limp ( N(y ) \limp N(f( x , \vec x ; \vec y ) ) ) \limp N(f (\succ_i x , \vec x ; \vec y)  ) }{
%		\vliin{}{}{N(y) \limp N(y) \limp ( N(y ) \limp N(f( x , \vec x ; \vec y ) ) ) \limp N(f (\succ_i x , \vec x ; \vec y)  ) }{
%			\vliin{}{}{ N(y) \limp N(y) \limp ( N(y) \limp N( f(x, \vec x ; \vec y) ) ) \limp N( h_i (x , \vec x ; \vec y , f(x , \vec x ; \vec y) ) ) }{
%				\vltr{MLL}{( N(\vec y) \limp (N (\vec y) \limp N(f(x, \vec x ; \vec y) )) \limp N(f(x, \vec x ; \vec y)) }{\vlhy{\quad }}{\vlhy{\ }}{\vlhy{\quad }}
%			}{
%			\vlhy{2}
%		}
%	}{
%	\vlhy{3}
%}
%}
%}
%\]
%TOFINISH
\end{proof}


