doc-src/IsarRef/generic.tex
changeset 12976 5cfe2941a5db
parent 12967 c61def7021e8
child 13015 7c3726a3dbec
equal deleted inserted replaced
12975:d796a2fd6c69 12976:5cfe2941a5db
     2 \chapter{Generic Tools and Packages}\label{ch:gen-tools}
     2 \chapter{Generic Tools and Packages}\label{ch:gen-tools}
     3 
     3 
     4 \section{Theory specification commands}
     4 \section{Theory specification commands}
     5 
     5 
     6 \subsection{Axiomatic type classes}\label{sec:axclass}
     6 \subsection{Axiomatic type classes}\label{sec:axclass}
     7 
       
     8 %FIXME
       
     9 % - qualified names
       
    10 % - class intro rules;
       
    11 % - class axioms;
       
    12 
     7 
    13 \indexisarcmd{axclass}\indexisarcmd{instance}\indexisarmeth{intro-classes}
     8 \indexisarcmd{axclass}\indexisarcmd{instance}\indexisarmeth{intro-classes}
    14 \begin{matharray}{rcl}
     9 \begin{matharray}{rcl}
    15   \isarcmd{axclass} & : & \isartrans{theory}{theory} \\
    10   \isarcmd{axclass} & : & \isartrans{theory}{theory} \\
    16   \isarcmd{instance} & : & \isartrans{theory}{proof(prove)} \\
    11   \isarcmd{instance} & : & \isartrans{theory}{proof(prove)} \\
    34 \begin{descr}
    29 \begin{descr}
    35 \item [$\AXCLASS~c \subseteq \vec c~axms$] defines an axiomatic type class as
    30 \item [$\AXCLASS~c \subseteq \vec c~axms$] defines an axiomatic type class as
    36   the intersection of existing classes, with additional axioms holding.  Class
    31   the intersection of existing classes, with additional axioms holding.  Class
    37   axioms may not contain more than one type variable.  The class axioms (with
    32   axioms may not contain more than one type variable.  The class axioms (with
    38   implicit sort constraints added) are bound to the given names.  Furthermore
    33   implicit sort constraints added) are bound to the given names.  Furthermore
    39   a class introduction rule is generated, which is employed by method
    34   a class introduction rule is generated (being bound as $c{.}intro$); this
    40   $intro_classes$ to support instantiation proofs of this class.
    35   rule is employed by method $intro_classes$ to support instantiation proofs
       
    36   of this class.
       
    37   
       
    38   The ``axioms'' are stored as theorems according to the given name
       
    39   specifications, adding the class name $c$ as name space prefix; these facts
       
    40   are stored collectively as $c.axioms$, too.
    41   
    41   
    42 \item [$\INSTANCE~c@1 \subseteq c@2$ and $\INSTANCE~t :: (\vec s)c$] setup a
    42 \item [$\INSTANCE~c@1 \subseteq c@2$ and $\INSTANCE~t :: (\vec s)c$] setup a
    43   goal stating a class relation or type arity.  The proof would usually
    43   goal stating a class relation or type arity.  The proof would usually
    44   proceed by $intro_classes$, and then establish the characteristic theorems
    44   proceed by $intro_classes$, and then establish the characteristic theorems
    45   of the type classes involved.  After finishing the proof, the theory will be
    45   of the type classes involved.  After finishing the proof, the theory will be
    46   augmented by a type signature declaration corresponding to the resulting
    46   augmented by a type signature declaration corresponding to the resulting
    47   theorem.
    47   theorem.
       
    48 
    48 \item [$intro_classes$] repeatedly expands all class introduction rules of
    49 \item [$intro_classes$] repeatedly expands all class introduction rules of
    49   this theory.  Note that this method usually needs not be named explicitly,
    50   this theory.  Note that this method usually needs not be named explicitly,
    50   as it is already included in the default proof step (of $\PROOFNAME$,
    51   as it is already included in the default proof step (of $\PROOFNAME$,
    51   $\BYNAME$, etc.).  In particular, instantiation of trivial (syntactic)
    52   $\BYNAME$, etc.).  In particular, instantiation of trivial (syntactic)
    52   classes may be performed by a single ``$\DDOT$'' proof step.
    53   classes may be performed by a single ``$\DDOT$'' proof step.
    53 \end{descr}
    54 \end{descr}
    54 
    55 
    55 
    56 
    56 \subsection{Locales and local contexts}\label{sec:locale}
    57 \subsection{Locales and local contexts}\label{sec:locale}
    57 
    58 
    58 FIXME
    59 Locales are named local contexts, consisting of a declaration elements that
    59 
    60 are modeled after the Isar proof context (cf.\ \S\ref{sec:proof-context}).
    60 \indexouternonterm{locale}\indexouternonterm{contextelem}
    61 
    61 
    62 \subsubsection{Localized commands}
       
    63 
       
    64 Existing locales may be augmented later on by adding new facts.  Note that the
       
    65 actual context definition may not be changed!  Several theory commands that
       
    66 produce facts in some way are available in ``localized'' versions, referring
       
    67 to a named locale instead of the global theory context.
       
    68 
       
    69 \indexouternonterm{locale}
    62 \begin{rail}
    70 \begin{rail}
    63   locale: '(' 'in' name ')'
    71   locale: '(' 'in' name ')'
    64   ;
    72   ;
    65 
    73 \end{rail}
    66   contextelem: FIXME
    74 
    67   ;  
    75 Emerging facts of localized commands are stored in two versions, both in the
    68 \end{rail}
    76 target locale and the theory (after export).  The latter view produces a
       
    77 qualified binding, using the locale name as a name space prefix.
       
    78 
       
    79 For example, ``$\LEMMAS~(\IN~loc)~a = \vec b$'' retrieves facts $\vec b$ from
       
    80 the locale context of $loc$ and augments its body by an appropriate
       
    81 ``$\isarkeyword{notes}$'' element (see below).  The exported view of $a$,
       
    82 after discharging the locale context, is stored as $loc{.}a$ within the global
       
    83 theory.  A localized goal ``$\LEMMANAME~(\IN~loc)~a:~\phi$'' work similarly,
       
    84 only that the fact emerges through the subsequent proof,
       
    85 which may refer to the full infrastructure of the locale context (including
       
    86 local parameters with typing and concrete syntax, assumptions, definitions
       
    87 etc.).  Most notably, fact declarations of the locale are active during the
       
    88 proof, too (e.g.\ local $simp$ rules).
       
    89 
       
    90 
       
    91 \subsubsection{Locale specifications}
       
    92 
       
    93 \indexisarcmd{locale}\indexisarcmd{print-locale}\indexisarcmd{print-locales}
       
    94 \begin{matharray}{rcl}
       
    95   \isarcmd{locale} & : & \isarkeep{theory} \\
       
    96   \isarcmd{print_locale}^* & : & \isarkeep{theory~|~proof} \\
       
    97   \isarcmd{print_locales}^* & : & \isarkeep{theory~|~proof} \\
       
    98 \end{matharray}
       
    99 
       
   100 \indexouternonterm{contextexpr}\indexouternonterm{contextelem}
       
   101 
       
   102 \railalias{printlocale}{print\_locale}
       
   103 \railterm{printlocale}
       
   104 
       
   105 \begin{rail}
       
   106   'locale' name ('=' localeexpr)?
       
   107   ;
       
   108   printlocale localeexpr
       
   109   ;
       
   110   localeexpr: ((contextexpr '+' (contextelem+)) | contextexpr | (contextelem+))
       
   111   ;
       
   112 
       
   113   contextexpr: nameref | '(' contextexpr ')' |
       
   114   (contextexpr (name+)) | (contextexpr + '+')
       
   115   ;
       
   116   contextelem: fixes | assumes | defines | notes | includes
       
   117   ;
       
   118   fixes: 'fixes' (name ('::' type)? structmixfix? + 'and')
       
   119   ;
       
   120   assumes: 'assumes' (thmdecl? props + 'and')
       
   121   ;
       
   122   defines: 'defines' (thmdecl? prop proppat? + 'and')
       
   123   ;
       
   124   notes: 'notes' (thmdef? thmrefs + 'and')
       
   125   ;
       
   126   includes: 'includes' contextexpr
       
   127   ;
       
   128 \end{rail}
       
   129 
       
   130 \begin{descr}
       
   131   
       
   132 \item [$\LOCALE~loc~=~import~+~body$] defines new locale $loc$ as a context
       
   133   consisting of a certain view of existing locales ($import$) plus some
       
   134   additional elements ($body$).  Both $import$ and $body$ are optional; the
       
   135   trivial $\LOCALE~loc$ defines an empty locale, which may still be useful to
       
   136   collect declarations of facts later on.  Type-inference on locale
       
   137   expressions automatically takes care of the most general typing that the
       
   138   combined context elements may acquire.
       
   139   
       
   140   The $import$ consists of a structured context expression, consisting of
       
   141   references to existing locales, renamed contexts, or merged contexts.
       
   142   Renaming uses positional notation: $c~\vec x$ means that (a prefix) the
       
   143   fixed parameters of context $c$ are named according to $\vec x$; a
       
   144   ``\texttt{_}'' (underscore).\indexisarthm{_@\texttt{_}} means to skip that
       
   145   position.  Also note that concrete syntax only works with the original name.
       
   146   Merging proceeds from left-to-right, suppressing any duplicates emerging
       
   147   from different paths through an import hierarchy.
       
   148   
       
   149   The $body$ consists of basic context elements, further context expressions
       
   150   may be included as well.
       
   151 
       
   152   \begin{descr}
       
   153     
       
   154   \item [$\FIXES{~x::\tau~(mx)}$] declares a local parameter of type $\tau$
       
   155     and mixfix annotation $mx$ (both are optional).  The special syntax
       
   156     declaration $(structure)$ means that $x$ may be referenced
       
   157     implicitly in this context. %see also FIXME
       
   158     
       
   159   \item [$\ASSUMES{a}{\vec\phi}$] introduces local premises, similar to
       
   160     $\ASSUMENAME$ within a proof (cf.\ \S\ref{sec:proof-context}).
       
   161     
       
   162   \item [$\DEFINES{a}{x \equiv t}$] defines a previously declared parameter.
       
   163     This is close to $\DEFNAME$ within a proof (cf.\ 
       
   164     \S\ref{sec:proof-context}), but $\DEFINESNAME$ takes an equational
       
   165     proposition instead of variable-term.  The left-hand side of the equation
       
   166     may have additional arguments, e.g.\ $\DEFINES{}{f~\vec x \equiv t}$.
       
   167     
       
   168   \item [$\NOTES{a}{\vec b}$] reconsiders facts within a local context.  Most
       
   169     notably, this may include arbitrary declarations in any attribute
       
   170     specifications included here, e.g.\ a local $simp$ rule.
       
   171     
       
   172   \item [$\INCLUDES{c}$] copies the specified context in a statically scoped
       
   173     manner.
       
   174     
       
   175     In contrast, the initial $import$ specification of a locale expression
       
   176     maintains a dynamic relation to the locales being referenced (benefiting
       
   177     from any later fact declarations in the obvious manner).
       
   178   \end{descr}
       
   179   
       
   180   Note that $\IS{p}$ patterns given in the syntax of $\ASSUMESNAME$ and
       
   181   $\DEFINESNAME$ above is actually illegal in locale definitions.  In the long
       
   182   goal format of \S\ref{sec:goals}, term bindings may be included as expected.
       
   183 
       
   184 \item [$\isarkeyword{print_locale}~import~+~body$] prints the specified locale
       
   185   expression in a flattened form.  The notable special case
       
   186   $\isarkeyword{print_locale}~loc$ just prints the contents of the named
       
   187   locale, but keep in mind that type-inference will normalize type variables
       
   188   according to the usual alphabetical order.
       
   189   
       
   190 \item [$\isarkeyword{print_locales}$] prints the names of all locales of the
       
   191   current theory.
       
   192 
       
   193 \end{descr}
    69 
   194 
    70 
   195 
    71 \section{Derived proof schemes}
   196 \section{Derived proof schemes}
    72 
   197 
    73 \subsection{Generalized elimination}\label{sec:obtain}
   198 \subsection{Generalized elimination}\label{sec:obtain}
   122 
   247 
   123 \subsection{Calculational reasoning}\label{sec:calculation}
   248 \subsection{Calculational reasoning}\label{sec:calculation}
   124 
   249 
   125 \indexisarcmd{also}\indexisarcmd{finally}
   250 \indexisarcmd{also}\indexisarcmd{finally}
   126 \indexisarcmd{moreover}\indexisarcmd{ultimately}
   251 \indexisarcmd{moreover}\indexisarcmd{ultimately}
   127 \indexisarcmd{print-trans-rules}\indexisaratt{trans}
   252 \indexisarcmd{print-trans-rules}
       
   253 \indexisaratt{trans}\indexisaratt{sym}\indexisaratt{symmetric}
   128 \begin{matharray}{rcl}
   254 \begin{matharray}{rcl}
   129   \isarcmd{also} & : & \isartrans{proof(state)}{proof(state)} \\
   255   \isarcmd{also} & : & \isartrans{proof(state)}{proof(state)} \\
   130   \isarcmd{finally} & : & \isartrans{proof(state)}{proof(chain)} \\
   256   \isarcmd{finally} & : & \isartrans{proof(state)}{proof(chain)} \\
   131   \isarcmd{moreover} & : & \isartrans{proof(state)}{proof(state)} \\
   257   \isarcmd{moreover} & : & \isartrans{proof(state)}{proof(state)} \\
   132   \isarcmd{ultimately} & : & \isartrans{proof(state)}{proof(chain)} \\
   258   \isarcmd{ultimately} & : & \isartrans{proof(state)}{proof(chain)} \\
   133   \isarcmd{print_trans_rules}^* & : & \isarkeep{theory~|~proof} \\
   259   \isarcmd{print_trans_rules}^* & : & \isarkeep{theory~|~proof} \\
   134   trans & : & \isaratt \\
   260   trans & : & \isaratt \\
       
   261   sym & : & \isaratt \\
       
   262   symmetric & : & \isaratt \\
   135 \end{matharray}
   263 \end{matharray}
   136 
   264 
   137 Calculational proof is forward reasoning with implicit application of
   265 Calculational proof is forward reasoning with implicit application of
   138 transitivity rules (such those of $=$, $\leq$, $<$).  Isabelle/Isar maintains
   266 transitivity rules (such those of $=$, $\leq$, $<$).  Isabelle/Isar maintains
   139 an auxiliary register $calculation$\indexisarthm{calculation} for accumulating
   267 an auxiliary register $calculation$\indexisarthm{calculation} for accumulating
   202   
   330   
   203 \item [$\isarkeyword{print_trans_rules}$] prints the list of transitivity (and
   331 \item [$\isarkeyword{print_trans_rules}$] prints the list of transitivity (and
   204   symmetry) rules declared in the current context.
   332   symmetry) rules declared in the current context.
   205 
   333 
   206 \item [$trans$] declares theorems as transitivity rules.
   334 \item [$trans$] declares theorems as transitivity rules.
       
   335   
       
   336 \item [$sym$] declares symmetry rules, to be used either with the $symmetric$
       
   337   operation (see below), or in canonical single-step eliminations (such as
       
   338   ``$\ASSUME{}{x = y}~\HENCE{}{y = x}~\DDOT$'').
       
   339   
       
   340   Isabelle/Pure declares symmetry of $\equiv$, common object-logics add
       
   341   further standard rules, such as symmetry of $=$ and $\not=$.
       
   342   
       
   343 \item [$symmetric$] resolves a theorem with some rule declared as $sym$ in the
       
   344   current context.  For example, ``$\ASSUME{[symmetric]}{x = y}$'' produces a
       
   345   swapped fact derived from that assumption.
   207 
   346 
   208 \end{descr}
   347 \end{descr}
   209 
   348 
   210 
   349 
   211 \section{Specific proof tools}
   350 \section{Specific proof tools}
   579 
   718 
   580 \subsubsection{Basic equational reasoning}\label{sec:basic-eq}
   719 \subsubsection{Basic equational reasoning}\label{sec:basic-eq}
   581 
   720 
   582 FIXME move?
   721 FIXME move?
   583 
   722 
   584 \indexisarmeth{subst}\indexisarmeth{hypsubst}\indexisarmeth{split}\indexisaratt{symmetric}
   723 \indexisarmeth{subst}\indexisarmeth{hypsubst}\indexisarmeth{split}
   585 \begin{matharray}{rcl}
   724 \begin{matharray}{rcl}
   586   subst & : & \isarmeth \\
   725   subst & : & \isarmeth \\
   587   hypsubst^* & : & \isarmeth \\
   726   hypsubst^* & : & \isarmeth \\
   588   split & : & \isarmeth \\
   727   split & : & \isarmeth \\
   589   symmetric & : & \isaratt \\
       
   590 \end{matharray}
   728 \end{matharray}
   591 
   729 
   592 \begin{rail}
   730 \begin{rail}
   593   'subst' thmref
   731   'subst' thmref
   594   ;
   732   ;
   610   By default, splitting is performed in the conclusion of a goal; the $asm$
   748   By default, splitting is performed in the conclusion of a goal; the $asm$
   611   option indicates to operate on assumptions instead.
   749   option indicates to operate on assumptions instead.
   612   
   750   
   613   Note that the $simp$ method already involves repeated application of split
   751   Note that the $simp$ method already involves repeated application of split
   614   rules as declared in the current context (see \S\ref{sec:simp}).
   752   rules as declared in the current context (see \S\ref{sec:simp}).
   615 \item [$symmetric$] applies the symmetry rule of meta or object equality.
       
   616   FIXME sym decl
       
   617 \end{descr}
   753 \end{descr}
   618 
   754 
   619 
   755 
   620 \subsection{The Classical Reasoner}\label{sec:classical}
   756 \subsection{The Classical Reasoner}\label{sec:classical}
   621 
   757