doc-src/ProgProve/Thys/document/Bool_nat_list.tex
changeset 47711 c1cca2a052e4
parent 47306 56d72c923281
child 47719 8aac84627b84
equal deleted inserted replaced
47710:4ced56100757 47711:c1cca2a052e4
   190   \end{tabular}
   190   \end{tabular}
   191 \end{itemize}
   191 \end{itemize}
   192 Throughout this book, \concept{IH} will stand for ``induction hypothesis''.
   192 Throughout this book, \concept{IH} will stand for ``induction hypothesis''.
   193 
   193 
   194 We have now seen three proofs of \isa{add\ m\ {\isadigit{0}}\ {\isaliteral{3D}{\isacharequal}}\ {\isadigit{0}}}: the Isabelle one, the
   194 We have now seen three proofs of \isa{add\ m\ {\isadigit{0}}\ {\isaliteral{3D}{\isacharequal}}\ {\isadigit{0}}}: the Isabelle one, the
   195 terse 4 lines explaining the base case and the induction step, and just now a
   195 terse four lines explaining the base case and the induction step, and just now a
   196 model of a traditional inductive proof. The three proofs differ in the level
   196 model of a traditional inductive proof. The three proofs differ in the level
   197 of detail given and the intended reader: the Isabelle proof is for the
   197 of detail given and the intended reader: the Isabelle proof is for the
   198 machine, the informal proofs are for humans. Although this book concentrates
   198 machine, the informal proofs are for humans. Although this book concentrates
   199 of Isabelle proofs, it is important to be able to rephrase those proofs
   199 on Isabelle proofs, it is important to be able to rephrase those proofs
   200 as informal text comprehensible to a reader familiar with traditional
   200 as informal text comprehensible to a reader familiar with traditional
   201 mathematical proofs. Later on we will introduce an Isabelle proof language
   201 mathematical proofs. Later on we will introduce an Isabelle proof language
   202 that is closer to traditional informal mathematical language and is often
   202 that is closer to traditional informal mathematical language and is often
   203 directly readable.
   203 directly readable.
   204 
   204 
   217 \endisadelimproof
   217 \endisadelimproof
   218 \isacommand{datatype}\isamarkupfalse%
   218 \isacommand{datatype}\isamarkupfalse%
   219 \ {\isaliteral{27}{\isacharprime}}a\ list\ {\isaliteral{3D}{\isacharequal}}\ Nil\ {\isaliteral{7C}{\isacharbar}}\ Cons\ {\isaliteral{27}{\isacharprime}}a\ {\isaliteral{22}{\isachardoublequoteopen}}{\isaliteral{27}{\isacharprime}}a\ list{\isaliteral{22}{\isachardoublequoteclose}}%
   219 \ {\isaliteral{27}{\isacharprime}}a\ list\ {\isaliteral{3D}{\isacharequal}}\ Nil\ {\isaliteral{7C}{\isacharbar}}\ Cons\ {\isaliteral{27}{\isacharprime}}a\ {\isaliteral{22}{\isachardoublequoteopen}}{\isaliteral{27}{\isacharprime}}a\ list{\isaliteral{22}{\isachardoublequoteclose}}%
   220 \begin{isamarkuptext}%
   220 \begin{isamarkuptext}%
   221 \begin{itemize}
   221 \begin{itemize}
   222 \item Type \isa{{\isaliteral{27}{\isacharprime}}a\ list} is the type of list over elements of type \isa{{\isaliteral{27}{\isacharprime}}a}. Because \isa{{\isaliteral{27}{\isacharprime}}a} is a type variable, lists are in fact \concept{polymorphic}: the elements of a list can be of arbitrary type (but must all be of the same type).
   222 \item Type \isa{{\isaliteral{27}{\isacharprime}}a\ list} is the type of lists over elements of type \isa{{\isaliteral{27}{\isacharprime}}a}. Because \isa{{\isaliteral{27}{\isacharprime}}a} is a type variable, lists are in fact \concept{polymorphic}: the elements of a list can be of arbitrary type (but must all be of the same type).
   223 \item Lists have two constructors: \isa{Nil}, the empty list, and \isa{Cons}, which puts an element (of type \isa{{\isaliteral{27}{\isacharprime}}a}) in front of a list (of type \isa{{\isaliteral{27}{\isacharprime}}a\ list}).
   223 \item Lists have two constructors: \isa{Nil}, the empty list, and \isa{Cons}, which puts an element (of type \isa{{\isaliteral{27}{\isacharprime}}a}) in front of a list (of type \isa{{\isaliteral{27}{\isacharprime}}a\ list}).
   224 Hence all lists are of the form \isa{Nil}, or \isa{Cons\ x\ Nil},
   224 Hence all lists are of the form \isa{Nil}, or \isa{Cons\ x\ Nil},
   225 or \isa{Cons\ x\ {\isaliteral{28}{\isacharparenleft}}Cons\ y\ Nil{\isaliteral{29}{\isacharparenright}}} etc.
   225 or \isa{Cons\ x\ {\isaliteral{28}{\isacharparenleft}}Cons\ y\ Nil{\isaliteral{29}{\isacharparenright}}} etc.
   226 \item \isacom{datatype} requires no quotation marks on the
   226 \item \isacom{datatype} requires no quotation marks on the
   227 left-hand side, but on the right-hand side each of the argument
   227 left-hand side, but on the right-hand side each of the argument
   280 the list, although the length remains implicit. To prove that some property
   280 the list, although the length remains implicit. To prove that some property
   281 \isa{P} holds for all lists \isa{xs}, i.e.\ \mbox{\isa{P\ xs}},
   281 \isa{P} holds for all lists \isa{xs}, i.e.\ \mbox{\isa{P\ xs}},
   282 you need to prove
   282 you need to prove
   283 \begin{enumerate}
   283 \begin{enumerate}
   284 \item the base case \isa{P\ Nil} and
   284 \item the base case \isa{P\ Nil} and
   285 \item the inductive case \isa{P\ {\isaliteral{28}{\isacharparenleft}}Cons\ x\ xs{\isaliteral{29}{\isacharparenright}}} under the assumption \isa{P\ xs}, for some arbitrary but fixed \isa{xs}.
   285 \item the inductive case \isa{P\ {\isaliteral{28}{\isacharparenleft}}Cons\ x\ xs{\isaliteral{29}{\isacharparenright}}} under the assumption \isa{P\ xs}, for some arbitrary but fixed \isa{x} and \isa{xs}.
   286 \end{enumerate}
   286 \end{enumerate}
   287 This is often called \concept{structural induction}.
   287 This is often called \concept{structural induction}.
   288 
   288 
   289 \subsection{The Proof Process}
   289 \subsection{The Proof Process}
   290 
   290 
   433 \ {\isadigit{1}}{\isaliteral{2E}{\isachardot}}\ {\isaliteral{5C3C416E643E}{\isasymAnd}}a\ xs{\isaliteral{2E}{\isachardot}}\isanewline
   433 \ {\isadigit{1}}{\isaliteral{2E}{\isachardot}}\ {\isaliteral{5C3C416E643E}{\isasymAnd}}a\ xs{\isaliteral{2E}{\isachardot}}\isanewline
   434 \isaindent{\ {\isadigit{1}}{\isaliteral{2E}{\isachardot}}\ \ \ \ }rev\ {\isaliteral{28}{\isacharparenleft}}app\ xs\ ys{\isaliteral{29}{\isacharparenright}}\ {\isaliteral{3D}{\isacharequal}}\ app\ {\isaliteral{28}{\isacharparenleft}}rev\ ys{\isaliteral{29}{\isacharparenright}}\ {\isaliteral{28}{\isacharparenleft}}rev\ xs{\isaliteral{29}{\isacharparenright}}\ {\isaliteral{5C3C4C6F6E6772696768746172726F773E}{\isasymLongrightarrow}}\isanewline
   434 \isaindent{\ {\isadigit{1}}{\isaliteral{2E}{\isachardot}}\ \ \ \ }rev\ {\isaliteral{28}{\isacharparenleft}}app\ xs\ ys{\isaliteral{29}{\isacharparenright}}\ {\isaliteral{3D}{\isacharequal}}\ app\ {\isaliteral{28}{\isacharparenleft}}rev\ ys{\isaliteral{29}{\isacharparenright}}\ {\isaliteral{28}{\isacharparenleft}}rev\ xs{\isaliteral{29}{\isacharparenright}}\ {\isaliteral{5C3C4C6F6E6772696768746172726F773E}{\isasymLongrightarrow}}\isanewline
   435 \isaindent{\ {\isadigit{1}}{\isaliteral{2E}{\isachardot}}\ \ \ \ }app\ {\isaliteral{28}{\isacharparenleft}}app\ {\isaliteral{28}{\isacharparenleft}}rev\ ys{\isaliteral{29}{\isacharparenright}}\ {\isaliteral{28}{\isacharparenleft}}rev\ xs{\isaliteral{29}{\isacharparenright}}{\isaliteral{29}{\isacharparenright}}\ {\isaliteral{28}{\isacharparenleft}}Cons\ a\ Nil{\isaliteral{29}{\isacharparenright}}\ {\isaliteral{3D}{\isacharequal}}\isanewline
   435 \isaindent{\ {\isadigit{1}}{\isaliteral{2E}{\isachardot}}\ \ \ \ }app\ {\isaliteral{28}{\isacharparenleft}}app\ {\isaliteral{28}{\isacharparenleft}}rev\ ys{\isaliteral{29}{\isacharparenright}}\ {\isaliteral{28}{\isacharparenleft}}rev\ xs{\isaliteral{29}{\isacharparenright}}{\isaliteral{29}{\isacharparenright}}\ {\isaliteral{28}{\isacharparenleft}}Cons\ a\ Nil{\isaliteral{29}{\isacharparenright}}\ {\isaliteral{3D}{\isacharequal}}\isanewline
   436 \isaindent{\ {\isadigit{1}}{\isaliteral{2E}{\isachardot}}\ \ \ \ }app\ {\isaliteral{28}{\isacharparenleft}}rev\ ys{\isaliteral{29}{\isacharparenright}}\ {\isaliteral{28}{\isacharparenleft}}app\ {\isaliteral{28}{\isacharparenleft}}rev\ xs{\isaliteral{29}{\isacharparenright}}\ {\isaliteral{28}{\isacharparenleft}}Cons\ a\ Nil{\isaliteral{29}{\isacharparenright}}{\isaliteral{29}{\isacharparenright}}%
   436 \isaindent{\ {\isadigit{1}}{\isaliteral{2E}{\isachardot}}\ \ \ \ }app\ {\isaliteral{28}{\isacharparenleft}}rev\ ys{\isaliteral{29}{\isacharparenright}}\ {\isaliteral{28}{\isacharparenleft}}app\ {\isaliteral{28}{\isacharparenleft}}rev\ xs{\isaliteral{29}{\isacharparenright}}\ {\isaliteral{28}{\isacharparenleft}}Cons\ a\ Nil{\isaliteral{29}{\isacharparenright}}{\isaliteral{29}{\isacharparenright}}%
   437 \end{isabelle}
   437 \end{isabelle}
   438 The the missing lemma is associativity of \isa{app},
   438 The missing lemma is associativity of \isa{app},
   439 which we insert in front of the failed lemma \isa{rev{\isaliteral{5F}{\isacharunderscore}}app}.
   439 which we insert in front of the failed lemma \isa{rev{\isaliteral{5F}{\isacharunderscore}}app}.
   440 
   440 
   441 \subsubsection{Associativity of \isa{app}}
   441 \subsubsection{Associativity of \isa{app}}
   442 
   442 
   443 The canonical proof procedure succeeds without further ado:%
   443 The canonical proof procedure succeeds without further ado:%