183 Laws about datatypes, such as \isa{[] \isasymnoteq~x\#xs} and |
183 Laws about datatypes, such as \isa{[] \isasymnoteq~x\#xs} and |
184 \isa{(x\#xs = y\#ys) = (x=y \isasymand~xs=ys)}, are used automatically |
184 \isa{(x\#xs = y\#ys) = (x=y \isasymand~xs=ys)}, are used automatically |
185 during proofs by simplification. The same is true for the equations in |
185 during proofs by simplification. The same is true for the equations in |
186 primitive recursive function definitions. |
186 primitive recursive function definitions. |
187 |
187 |
|
188 Every datatype $t$ comes equipped with a \isa{size} function from $t$ into |
|
189 the natural numbers (see~\S\ref{sec:nat} below). For lists, \isa{size} is |
|
190 just the length, i.e.\ \isa{size [] = 0} and \isa{size(x \# xs) = size xs + |
|
191 1}. In general, \isa{size} returns \isa{0} for all constructors that do |
|
192 not have an argument of type $t$, and for all other constructors \isa{1 +} |
|
193 the sum of the sizes of all arguments of type $t$. Note that because |
|
194 \isa{size} is defined on every datatype, it is overloaded; on lists |
|
195 \isa{size} is also called \isa{length}, which is not overloaded. |
|
196 |
|
197 |
188 \subsection{Primitive recursion} |
198 \subsection{Primitive recursion} |
189 |
199 |
190 Functions on datatypes are usually defined by recursion. In fact, most of the |
200 Functions on datatypes are usually defined by recursion. In fact, most of the |
191 time they are defined by what is called \bfindex{primitive recursion}. |
201 time they are defined by what is called \bfindex{primitive recursion}. |
192 The keyword \isacommand{primrec}\indexbold{*primrec} is followed by a list of |
202 The keyword \isacommand{primrec}\indexbold{*primrec} is followed by a list of |
265 Note that we do not need to give a lemma a name if we do not intend to refer |
275 Note that we do not need to give a lemma a name if we do not intend to refer |
266 to it explicitly in the future. |
276 to it explicitly in the future. |
267 |
277 |
268 \begin{warn} |
278 \begin{warn} |
269 Induction is only allowed on free (or \isasymAnd-bound) variables that |
279 Induction is only allowed on free (or \isasymAnd-bound) variables that |
270 should not occur among the assumptions of the subgoal. Case distinction |
280 should not occur among the assumptions of the subgoal; see |
|
281 \S\ref{sec:ind-var-in-prems} for details. Case distinction |
271 (\isa{case_tac}) works for arbitrary terms, which need to be |
282 (\isa{case_tac}) works for arbitrary terms, which need to be |
272 quoted if they are non-atomic. |
283 quoted if they are non-atomic. |
273 \end{warn} |
284 \end{warn} |
274 |
285 |
275 |
286 |
692 \label{sec:datatype-mut-rec} |
704 \label{sec:datatype-mut-rec} |
693 |
705 |
694 \input{Datatype/document/ABexpr.tex} |
706 \input{Datatype/document/ABexpr.tex} |
695 |
707 |
696 \subsection{Nested recursion} |
708 \subsection{Nested recursion} |
697 |
709 \label{sec:nested-datatype} |
698 \input{Datatype/document/Nested.tex} |
710 |
|
711 {\makeatother\input{Datatype/document/Nested.tex}} |
699 |
712 |
700 |
713 |
701 \subsection{The limits of nested recursion} |
714 \subsection{The limits of nested recursion} |
702 |
715 |
703 How far can we push nested recursion? By the unfolding argument above, we can |
716 How far can we push nested recursion? By the unfolding argument above, we can |
826 |
839 |
827 \subsection{Simplification with recdef} |
840 \subsection{Simplification with recdef} |
828 |
841 |
829 \input{Recdef/document/simplification.tex} |
842 \input{Recdef/document/simplification.tex} |
830 |
843 |
831 |
|
832 \subsection{Induction} |
844 \subsection{Induction} |
833 \index{induction!recursion|(} |
845 \index{induction!recursion|(} |
834 \index{recursion induction|(} |
846 \index{recursion induction|(} |
835 |
847 |
836 \input{Recdef/document/Induction.tex} |
848 \input{Recdef/document/Induction.tex} |
|
849 \label{sec:recdef-induction} |
837 |
850 |
838 \index{induction!recursion|)} |
851 \index{induction!recursion|)} |
839 \index{recursion induction|)} |
852 \index{recursion induction|)} |
|
853 |
|
854 %\subsection{Advanced forms of recursion} |
|
855 |
|
856 %\input{Recdef/document/Nested0.tex} |
|
857 %\input{Recdef/document/Nested1.tex} |
|
858 |
840 \index{*recdef|)} |
859 \index{*recdef|)} |
|
860 |
|
861 \section{Advanced induction techniques} |
|
862 \label{sec:advanced-ind} |
|
863 \input{Misc/document/AdvancedInd.tex} |
|
864 |
|
865 \input{Datatype/document/Nested2.tex} |