diff -r 6e2479089226 -r cecd7a941885 ProgTutorial/Package/Ind_General_Scheme.thy --- a/ProgTutorial/Package/Ind_General_Scheme.thy Tue May 14 16:59:53 2019 +0200 +++ b/ProgTutorial/Package/Ind_General_Scheme.thy Tue May 14 17:10:47 2019 +0200 @@ -36,45 +36,42 @@ (*>*) -section {* The Code in a Nutshell\label{sec:nutshell} *} +section \The Code in a Nutshell\label{sec:nutshell}\ -text {* +text \ The inductive package will generate the reasoning infrastructure for - mutually recursive predicates, say @{text "pred\<^sub>1\pred\<^sub>n"}. In what + mutually recursive predicates, say \pred\<^sub>1\pred\<^sub>n\. In what follows we will have the convention that various, possibly empty collections of ``things'' (lists, terms, nested implications and so on) are indicated either by adding an @{text [quotes] "s"} or by adding a superscript @{text [quotes] - "\<^sup>*"}. The shorthand for the predicates will therefore be @{text - "preds"} or @{text "pred\<^sup>*"}. In the case of the predicates there must + "\<^sup>*"}. The shorthand for the predicates will therefore be \preds\ or \pred\<^sup>*\. In the case of the predicates there must be, of course, at least a single one in order to obtain a meaningful definition. - The input for the inductive package will be some @{text "preds"} with possible + The input for the inductive package will be some \preds\ with possible typing and syntax annotations, and also some introduction rules. We call below the - introduction rules short as @{text "rules"}. Borrowing some idealised Isabelle - notation, one such @{text "rule"} is assumed to be of the form + introduction rules short as \rules\. Borrowing some idealised Isabelle + notation, one such \rule\ is assumed to be of the form \begin{isabelle} - @{text "rule ::= - \xs. \<^latex>\$\\underbrace{\\mbox{\As\<^latex>\}}_{\\text{\\makebox[0mm]{\\rm non-recursive premises}}}$\ \ - \<^latex>\$\\underbrace{\\mbox{\(\ys. Bs \ pred ss)\<^sup>*\<^latex>\}}_{\\text{\\rm recursive premises}}$>\ - \ pred ts"} + \rule ::= + \xs. \<^latex>\$\underbrace{\mbox{\As\<^latex>\}}_{\text{\makebox[0mm]{\rm non-recursive premises}}}$\ \ + \<^latex>\$\underbrace{\mbox{\(\ys. Bs \ pred ss)\<^sup>*\<^latex>\}}_{\text{\rm recursive premises}}$>\ + \ pred ts\ \end{isabelle} - For the purposes here, we will assume the @{text rules} have this format and + For the purposes here, we will assume the \rules\ have this format and omit any code that actually tests this. Therefore ``things'' can go horribly - wrong, if the @{text "rules"} are not of this form. The @{text As} and - @{text Bs} in a @{text "rule"} stand for formulae not involving the - inductive predicates @{text "preds"}; the instances @{text "pred ss"} and - @{text "pred ts"} can stand for different predicates, like @{text - "pred\<^sub>1 ss"} and @{text "pred\<^sub>2 ts"}, in case mutual recursive - predicates are defined; the terms @{text ss} and @{text ts} are the + wrong, if the \rules\ are not of this form. The \As\ and + \Bs\ in a \rule\ stand for formulae not involving the + inductive predicates \preds\; the instances \pred ss\ and + \pred ts\ can stand for different predicates, like \pred\<^sub>1 ss\ and \pred\<^sub>2 ts\, in case mutual recursive + predicates are defined; the terms \ss\ and \ts\ are the arguments of these predicates. Every formula left of @{text [quotes] "\ pred - ts"} is a premise of the rule. The outermost quantified variables @{text - "xs"} are usually omitted in the user's input. The quantification for the - variables @{text "ys"} is local with respect to one recursive premise and - must be given. Some examples of @{text "rule"}s are + ts"} is a premise of the rule. The outermost quantified variables \xs\ are usually omitted in the user's input. The quantification for the + variables \ys\ is local with respect to one recursive premise and + must be given. Some examples of \rule\s are @{thm [display] fresh_var[no_vars]} @@ -88,35 +85,35 @@ @{thm [display] accpartI[no_vars]} has a single recursive premise that has a precondition. As is custom all - rules are stated without the leading meta-quantification @{text "\xs"}. + rules are stated without the leading meta-quantification \\xs\. The output of the inductive package will be definitions for the predicates, induction principles and introduction rules. For the definitions we need to have the - @{text rules} in a form where the meta-quantifiers and meta-implications are - replaced by their object logic equivalents. Therefore an @{text "orule"} is + \rules\ in a form where the meta-quantifiers and meta-implications are + replaced by their object logic equivalents. Therefore an \orule\ is of the form @{text [display] "orule ::= \xs. As \ (\ys. Bs \ pred ss)\<^sup>* \ pred ts"} - A definition for the predicate @{text "pred"} has then the form + A definition for the predicate \pred\ has then the form @{text [display] "def ::= pred \ \zs. \preds. orules \ pred zs"} - The induction principles for every predicate @{text "pred"} are of the + The induction principles for every predicate \pred\ are of the form @{text [display] "ind ::= pred ?zs \ rules[preds := ?Ps] \ ?P ?zs"} - where in the @{text "rules"}-part every @{text pred} is replaced by a fresh - schematic variable @{text "?P"}. + where in the \rules\-part every \pred\ is replaced by a fresh + schematic variable \?P\. - In order to derive an induction principle for the predicate @{text "pred"}, - we first transform @{text ind} into the object logic and fix the schematic variables. + In order to derive an induction principle for the predicate \pred\, + we first transform \ind\ into the object logic and fix the schematic variables. Hence we have to prove a formula of the form @{text [display] "pred zs \ orules[preds := Ps] \ P zs"} - If we assume @{text "pred zs"} and unfold its definition, then we have an + If we assume \pred zs\ and unfold its definition, then we have an assumption @{text [display] "\preds. orules \ pred zs"} @@ -125,12 +122,12 @@ @{text [display] "orules[preds := Ps] \ P zs"} - This can be done by instantiating the @{text "\preds"}-quantification - with the @{text "Ps"}. Then we are done since we are left with a simple + This can be done by instantiating the \\preds\-quantification + with the \Ps\. Then we are done since we are left with a simple identity. - Although the user declares the introduction rules @{text rules}, they must - also be derived from the @{text defs}. These derivations are a bit involved. + Although the user declares the introduction rules \rules\, they must + also be derived from the \defs\. These derivations are a bit involved. Assuming we want to prove the introduction rule @{text [display] "\xs. As \ (\ys. Bs \ pred ss)\<^sup>* \ pred ts"} @@ -138,29 +135,29 @@ then we have assumptions of the form \begin{isabelle} - (i)~~@{text "As"}\\ - (ii)~@{text "(\ys. Bs \ pred ss)\<^sup>*"} + (i)~~\As\\\ + (ii)~\(\ys. Bs \ pred ss)\<^sup>*\ \end{isabelle} and must show the goal @{text [display] "pred ts"} - If we now unfold the definitions for the @{text preds}, we have assumptions + If we now unfold the definitions for the \preds\, we have assumptions \begin{isabelle} - (i)~~~@{text "As"}\\ - (ii)~~@{text "(\ys. Bs \ \preds. orules \ pred ss)\<^sup>*"}\\ - (iii)~@{text "orules"} + (i)~~~\As\\\ + (ii)~~\(\ys. Bs \ \preds. orules \ pred ss)\<^sup>*\\\ + (iii)~\orules\ \end{isabelle} and need to show @{text [display] "pred ts"} - In the last step we removed some quantifiers and moved the precondition @{text "orules"} - into the assumption. The @{text "orules"} stand for all introduction rules that are given - by the user. We apply the @{text orule} that corresponds to introduction rule we are + In the last step we removed some quantifiers and moved the precondition \orules\ + into the assumption. The \orules\ stand for all introduction rules that are given + by the user. We apply the \orule\ that corresponds to introduction rule we are proving. After transforming the object connectives into meta-connectives, this introduction rule must necessarily be of the form @@ -170,34 +167,34 @@ goals of the form \begin{isabelle} - (a)~@{text "As"}\\ - (b)~@{text "(\ys. Bs \ pred ss)\<^sup>*"} + (a)~\As\\\ + (b)~\(\ys. Bs \ pred ss)\<^sup>*\ \end{isabelle} - We can immediately discharge the goals @{text "As"} using the assumptions in - @{text "(i)"}. The goals in @{text "(b)"} can be discharged as follows: we - assume the @{text "Bs"} and prove @{text "pred ss"}. For this we resolve the - @{text "Bs"} with the assumptions in @{text "(ii)"}. This gives us the + We can immediately discharge the goals \As\ using the assumptions in + \(i)\. The goals in \(b)\ can be discharged as follows: we + assume the \Bs\ and prove \pred ss\. For this we resolve the + \Bs\ with the assumptions in \(ii)\. This gives us the assumptions @{text [display] "(\preds. orules \ pred ss)\<^sup>*"} Instantiating the universal quantifiers and then resolving with the assumptions - in @{text "(iii)"} gives us @{text "pred ss"}, which is the goal we are after. + in \(iii)\ gives us \pred ss\, which is the goal we are after. This completes the proof for introduction rules. What remains is to implement in Isabelle the reasoning outlined in this section. We will describe the code in the next section. For building testcases, we use the shorthands for - @{text "even/odd"}, @{term "fresh"} and @{term "accpart"} + \even/odd\, @{term "fresh"} and @{term "accpart"} defined in Figure~\ref{fig:shorthands}. -*} +\ -text_raw{* +text_raw\ \begin{figure}[p] \begin{minipage}{\textwidth} -\begin{isabelle}*} -ML %grayML{*(* even-odd example *) +\begin{isabelle}\ +ML %grayML\(* even-odd example *) val eo_defs = [@{thm even_def}, @{thm odd_def}] val eo_rules = @@ -240,17 +237,17 @@ (* accessible-part example *) val acc_rules = [@{prop "\R x. (\y. R y x \ accpart R y) \ accpart R x"}] -val acc_pred = @{term "accpart::('a \ 'a \ bool) \'a \ bool"}*} -text_raw{* +val acc_pred = @{term "accpart::('a \ 'a \ bool) \'a \ bool"}\ +text_raw\ \end{isabelle} \end{minipage} -\caption{Shorthands for the inductive predicates @{text "even"}/@{text "odd"}, - @{text "fresh"} and @{text "accpart"}. The names of these shorthands follow - the convention @{text "rules"}, @{text "orules"}, @{text "preds"} and so on. +\caption{Shorthands for the inductive predicates \even\/\odd\, + \fresh\ and \accpart\. The names of these shorthands follow + the convention \rules\, \orules\, \preds\ and so on. The purpose of these shorthands is to simplify the construction of testcases in Section~\ref{sec:code}.\label{fig:shorthands}} \end{figure} -*} +\