\section{peano.c File Reference}
\label{peano_8c}\index{peano.c@{peano.c}}
The implementation for Peano Arithmetic. 


{\tt \#include \char`\"{}peano.h\char`\"{}}\par


Include dependency graph for peano.c:\begin{figure}[H]
\begin{center}
\leavevmode
\includegraphics[width=41pt]{peano_8c__incl}
\end{center}
\end{figure}
\subsection*{Functions}
\begin{CompactItemize}
\item 
void {\bf error} (const char $\ast$s, const int n)
\item 
{\bf Natnum\_\-t} {\bf Natnum\_\-malloc} ()
\item 
{\bf Natnum\_\-t} {\bf Z} ()
\item 
{\bf Natnum\_\-t} {\bf S} (const {\bf Natnum\_\-t} n)
\item 
{\bf Natnum\_\-t} {\bf recsum} (const {\bf Natnum\_\-t} s0, const {\bf Natnum\_\-t} s1)
\item 
{\bf Natnum\_\-t} {\bf itsum} (const {\bf Natnum\_\-t} s0, const {\bf Natnum\_\-t} s1)
\item 
{\bf Natnum\_\-t} {\bf loopsum} ({\bf Natnum\_\-t} s0, {\bf Natnum\_\-t} s1)
\item 
int {\bf Zeq} ({\bf Natnum\_\-t} n)
\item 
const {\bf Natnum\_\-t} {\bf pred} (const {\bf Natnum\_\-t} n)
\item 
int {\bf eq} ({\bf Natnum\_\-t} n0, {\bf Natnum\_\-t} n1)
\item 
unsigned {\bf nn2uns} ({\bf Natnum\_\-t} nn)
\item 
{\bf Natnum\_\-t} {\bf uns2nn} (unsigned u)
\end{CompactItemize}


\subsection{Detailed Description}
The implementation for Peano Arithmetic.

 

Operations on Natnum\_\-t objects are defined.

struct {\bf Natnum} {\rm (p.\,\pageref{structNatnum})} is a cell containing just a pointer. A linked list with $N$ of those cells, followed by a null pointer represents the integer $N$: $N$ iterations of $S$, the sucessor function applied to $Z$, the zero constructor.



\subsection{Function Documentation}
\index{peano.c@{peano.c}!eq@{eq}}
\index{eq@{eq}!peano.c@{peano.c}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}int eq ({\bf Natnum\_\-t} {\em n0}, {\bf Natnum\_\-t} {\em n1})}\label{peano_8c_a9}


equlity test

Notice that equality is defined with respect to the intended representation \index{peano.c@{peano.c}!error@{error}}
\index{error@{error}!peano.c@{peano.c}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}void error (const char $\ast$ {\em s}, const int {\em n})\hspace{0.3cm}{\tt  [static]}}\label{peano_8c_a0}


a local error procedure

A procedure for producing an error message and aborting the program \begin{Desc}
\item[Parameters: ]\par
\begin{description}
\item[{\em 
s}]pointer to error message \item[{\em 
n}]an interger constant to be returned to the operating system \end{description}
\end{Desc}
\index{peano.c@{peano.c}!itsum@{itsum}}
\index{itsum@{itsum}!peano.c@{peano.c}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}{\bf Natnum\_\-t} itsum (const {\bf Natnum\_\-t} {\em s0}, const {\bf Natnum\_\-t} {\em s1})}\label{peano_8c_a5}


tail recursive function for computing sum over {\bf Natnum} {\rm (p.\,\pageref{structNatnum})} \index{peano.c@{peano.c}!loopsum@{loopsum}}
\index{loopsum@{loopsum}!peano.c@{peano.c}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}{\bf Natnum\_\-t} loopsum ({\bf Natnum\_\-t} {\em s0}, {\bf Natnum\_\-t} {\em s1})}\label{peano_8c_a6}


The sum of two {\bf Natnum} {\rm (p.\,\pageref{structNatnum})} object, using iteration

It implements invariant assertion. \index{peano.c@{peano.c}!Natnum_malloc@{Natnum\_\-malloc}}
\index{Natnum_malloc@{Natnum\_\-malloc}!peano.c@{peano.c}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}{\bf Natnum\_\-t} Natnum\_\-malloc ()\hspace{0.3cm}{\tt  [static]}}\label{peano_8c_a1}


An allocator for {\bf Natnum} {\rm (p.\,\pageref{structNatnum})}

It uses malloc to allocate space for {\bf Natnum} {\rm (p.\,\pageref{structNatnum})}, possibly aborting the program \begin{Desc}
\item[Returns: ]\par
pointer to newly allocated {\bf Natnum} {\rm (p.\,\pageref{structNatnum})} \end{Desc}
\index{peano.c@{peano.c}!nn2uns@{nn2uns}}
\index{nn2uns@{nn2uns}!peano.c@{peano.c}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}unsigned nn2uns ({\bf Natnum\_\-t})}\label{peano_8c_a10}


Converting a Natnum\_\-t to binary representation \index{peano.c@{peano.c}!pred@{pred}}
\index{pred@{pred}!peano.c@{peano.c}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}const {\bf Natnum\_\-t} pred (const {\em Natnum\_\-t})}\label{peano_8c_a8}


the predecessor of a given number \index{peano.c@{peano.c}!recsum@{recsum}}
\index{recsum@{recsum}!peano.c@{peano.c}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}{\bf Natnum\_\-t} recsum (const {\bf Natnum\_\-t} {\em s0}, const {\bf Natnum\_\-t} {\em s1})}\label{peano_8c_a4}


recursive function for computing sum over {\bf Natnum} {\rm (p.\,\pageref{structNatnum})}

it computes sum of two {\bf Natnum} {\rm (p.\,\pageref{structNatnum})} objects, using recursion with suspended computation (computation with draft on stack) \index{peano.c@{peano.c}!S@{S}}
\index{S@{S}!peano.c@{peano.c}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}{\bf Natnum\_\-t} S (const {\bf Natnum\_\-t} {\em n})}\label{peano_8c_a3}


A constructor for an object representing the successor of a given number \begin{Desc}
\item[Parameters: ]\par
\begin{description}
\item[{\em 
n}]a number \end{description}
\end{Desc}
\begin{Desc}
\item[Returns: ]\par
the successor of n \end{Desc}
\index{peano.c@{peano.c}!uns2nn@{uns2nn}}
\index{uns2nn@{uns2nn}!peano.c@{peano.c}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}{\bf Natnum\_\-t} uns2nn (unsigned)}\label{peano_8c_a11}


From binary to Natnum\_\-t \index{peano.c@{peano.c}!Z@{Z}}
\index{Z@{Z}!peano.c@{peano.c}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}{\bf Natnum\_\-t} Z ()}\label{peano_8c_a2}


\index{peano.c@{peano.c}!Zeq@{Zeq}}
\index{Zeq@{Zeq}!peano.c@{peano.c}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}int Zeq ({\bf Natnum\_\-t})}\label{peano_8c_a7}


whether a number is zero 