doc-src/IsarRef/Thy/document/Generic.tex
author wenzelm
Thu, 08 May 2008 22:20:33 +0200
changeset 26854 9b4aec46ad78
parent 26842 81308d44fe0a
child 26870 94bedbb34b92
permissions -rw-r--r--
improved treatment of "_" thanks to underscore.sty;
wenzelm@26782
     1
%
wenzelm@26782
     2
\begin{isabellebody}%
wenzelm@26782
     3
\def\isabellecontext{Generic}%
wenzelm@26782
     4
%
wenzelm@26782
     5
\isadelimtheory
wenzelm@26782
     6
\isanewline
wenzelm@26782
     7
\isanewline
wenzelm@26782
     8
%
wenzelm@26782
     9
\endisadelimtheory
wenzelm@26782
    10
%
wenzelm@26782
    11
\isatagtheory
wenzelm@26782
    12
\isacommand{theory}\isamarkupfalse%
wenzelm@26782
    13
\ Generic\isanewline
wenzelm@26782
    14
\isakeyword{imports}\ CPure\isanewline
wenzelm@26782
    15
\isakeyword{begin}%
wenzelm@26782
    16
\endisatagtheory
wenzelm@26782
    17
{\isafoldtheory}%
wenzelm@26782
    18
%
wenzelm@26782
    19
\isadelimtheory
wenzelm@26782
    20
%
wenzelm@26782
    21
\endisadelimtheory
wenzelm@26782
    22
%
wenzelm@26782
    23
\isamarkupchapter{Generic tools and packages \label{ch:gen-tools}%
wenzelm@26782
    24
}
wenzelm@26782
    25
\isamarkuptrue%
wenzelm@26782
    26
%
wenzelm@26782
    27
\isamarkupsection{Specification commands%
wenzelm@26782
    28
}
wenzelm@26782
    29
\isamarkuptrue%
wenzelm@26782
    30
%
wenzelm@26782
    31
\isamarkupsubsection{Derived specifications%
wenzelm@26782
    32
}
wenzelm@26782
    33
\isamarkuptrue%
wenzelm@26782
    34
%
wenzelm@26782
    35
\begin{isamarkuptext}%
wenzelm@26782
    36
\begin{matharray}{rcll}
wenzelm@26782
    37
    \indexdef{}{command}{axiomatization}\mbox{\isa{\isacommand{axiomatization}}} & : & \isarkeep{local{\dsh}theory} & (axiomatic!)\\
wenzelm@26782
    38
    \indexdef{}{command}{definition}\mbox{\isa{\isacommand{definition}}} & : & \isarkeep{local{\dsh}theory} \\
wenzelm@26782
    39
    \indexdef{}{attribute}{defn}\mbox{\isa{defn}} & : & \isaratt \\
wenzelm@26782
    40
    \indexdef{}{command}{abbreviation}\mbox{\isa{\isacommand{abbreviation}}} & : & \isarkeep{local{\dsh}theory} \\
wenzelm@26854
    41
    \indexdef{}{command}{print\_abbrevs}\mbox{\isa{\isacommand{print{\isacharunderscore}abbrevs}}}\isa{{\isachardoublequote}\isactrlsup {\isacharasterisk}{\isachardoublequote}} & : & \isarkeep{theory~|~proof} \\
wenzelm@26782
    42
    \indexdef{}{command}{notation}\mbox{\isa{\isacommand{notation}}} & : & \isarkeep{local{\dsh}theory} \\
wenzelm@26854
    43
    \indexdef{}{command}{no\_notation}\mbox{\isa{\isacommand{no{\isacharunderscore}notation}}} & : & \isarkeep{local{\dsh}theory} \\
wenzelm@26782
    44
  \end{matharray}
wenzelm@26782
    45
wenzelm@26782
    46
  These specification mechanisms provide a slightly more abstract view
wenzelm@26782
    47
  than the underlying primitives of \mbox{\isa{\isacommand{consts}}}, \mbox{\isa{\isacommand{defs}}} (see \secref{sec:consts}), and \mbox{\isa{\isacommand{axioms}}} (see
wenzelm@26782
    48
  \secref{sec:axms-thms}).  In particular, type-inference is commonly
wenzelm@26782
    49
  available, and result names need not be given.
wenzelm@26782
    50
wenzelm@26782
    51
  \begin{rail}
wenzelm@26782
    52
    'axiomatization' target? fixes? ('where' specs)?
wenzelm@26782
    53
    ;
wenzelm@26782
    54
    'definition' target? (decl 'where')? thmdecl? prop
wenzelm@26782
    55
    ;
wenzelm@26782
    56
    'abbreviation' target? mode? (decl 'where')? prop
wenzelm@26782
    57
    ;
wenzelm@26782
    58
    ('notation' | 'no\_notation') target? mode? (nameref structmixfix + 'and')
wenzelm@26782
    59
    ;
wenzelm@26782
    60
wenzelm@26782
    61
    fixes: ((name ('::' type)? mixfix? | vars) + 'and')
wenzelm@26782
    62
    ;
wenzelm@26782
    63
    specs: (thmdecl? props + 'and')
wenzelm@26782
    64
    ;
wenzelm@26782
    65
    decl: name ('::' type)? mixfix?
wenzelm@26782
    66
    ;
wenzelm@26782
    67
  \end{rail}
wenzelm@26782
    68
wenzelm@26782
    69
  \begin{descr}
wenzelm@26782
    70
  
wenzelm@26842
    71
  \item [\mbox{\isa{\isacommand{axiomatization}}}~\isa{{\isachardoublequote}c\isactrlsub {\isadigit{1}}\ {\isasymdots}\ c\isactrlsub m\ {\isasymWHERE}\ {\isasymphi}\isactrlsub {\isadigit{1}}\ {\isasymdots}\ {\isasymphi}\isactrlsub n{\isachardoublequote}}] introduces several constants
wenzelm@26782
    72
  simultaneously and states axiomatic properties for these.  The
wenzelm@26782
    73
  constants are marked as being specified once and for all, which
wenzelm@26782
    74
  prevents additional specifications being issued later on.
wenzelm@26782
    75
  
wenzelm@26782
    76
  Note that axiomatic specifications are only appropriate when
wenzelm@26782
    77
  declaring a new logical system.  Normal applications should only use
wenzelm@26782
    78
  definitional mechanisms!
wenzelm@26782
    79
wenzelm@26842
    80
  \item [\mbox{\isa{\isacommand{definition}}}~\isa{{\isachardoublequote}c\ {\isasymWHERE}\ eq{\isachardoublequote}}] produces an
wenzelm@26842
    81
  internal definition \isa{{\isachardoublequote}c\ {\isasymequiv}\ t{\isachardoublequote}} according to the specification
wenzelm@26782
    82
  given as \isa{eq}, which is then turned into a proven fact.  The
wenzelm@26782
    83
  given proposition may deviate from internal meta-level equality
wenzelm@26782
    84
  according to the rewrite rules declared as \mbox{\isa{defn}} by the
wenzelm@26842
    85
  object-logic.  This usually covers object-level equality \isa{{\isachardoublequote}x\ {\isacharequal}\ y{\isachardoublequote}} and equivalence \isa{{\isachardoublequote}A\ {\isasymleftrightarrow}\ B{\isachardoublequote}}.  End-users normally need not
wenzelm@26782
    86
  change the \mbox{\isa{defn}} setup.
wenzelm@26782
    87
  
wenzelm@26782
    88
  Definitions may be presented with explicit arguments on the LHS, as
wenzelm@26842
    89
  well as additional conditions, e.g.\ \isa{{\isachardoublequote}f\ x\ y\ {\isacharequal}\ t{\isachardoublequote}} instead of
wenzelm@26842
    90
  \isa{{\isachardoublequote}f\ {\isasymequiv}\ {\isasymlambda}x\ y{\isachardot}\ t{\isachardoublequote}} and \isa{{\isachardoublequote}y\ {\isasymnoteq}\ {\isadigit{0}}\ {\isasymLongrightarrow}\ g\ x\ y\ {\isacharequal}\ u{\isachardoublequote}} instead of an
wenzelm@26842
    91
  unrestricted \isa{{\isachardoublequote}g\ {\isasymequiv}\ {\isasymlambda}x\ y{\isachardot}\ u{\isachardoublequote}}.
wenzelm@26782
    92
  
wenzelm@26842
    93
  \item [\mbox{\isa{\isacommand{abbreviation}}}~\isa{{\isachardoublequote}c\ {\isasymWHERE}\ eq{\isachardoublequote}}] introduces
wenzelm@26782
    94
  a syntactic constant which is associated with a certain term
wenzelm@26782
    95
  according to the meta-level equality \isa{eq}.
wenzelm@26782
    96
  
wenzelm@26782
    97
  Abbreviations participate in the usual type-inference process, but
wenzelm@26782
    98
  are expanded before the logic ever sees them.  Pretty printing of
wenzelm@26782
    99
  terms involves higher-order rewriting with rules stemming from
wenzelm@26782
   100
  reverted abbreviations.  This needs some care to avoid overlapping
wenzelm@26782
   101
  or looping syntactic replacements!
wenzelm@26782
   102
  
wenzelm@26782
   103
  The optional \isa{mode} specification restricts output to a
wenzelm@26782
   104
  particular print mode; using ``\isa{input}'' here achieves the
wenzelm@26782
   105
  effect of one-way abbreviations.  The mode may also include an
wenzelm@26782
   106
  ``\mbox{\isa{\isakeyword{output}}}'' qualifier that affects the concrete syntax
wenzelm@26782
   107
  declared for abbreviations, cf.\ \mbox{\isa{\isacommand{syntax}}} in
wenzelm@26782
   108
  \secref{sec:syn-trans}.
wenzelm@26782
   109
  
wenzelm@26782
   110
  \item [\mbox{\isa{\isacommand{print{\isacharunderscore}abbrevs}}}] prints all constant abbreviations
wenzelm@26782
   111
  of the current context.
wenzelm@26782
   112
  
wenzelm@26842
   113
  \item [\mbox{\isa{\isacommand{notation}}}~\isa{{\isachardoublequote}c\ {\isacharparenleft}mx{\isacharparenright}{\isachardoublequote}}] associates mixfix
wenzelm@26782
   114
  syntax with an existing constant or fixed variable.  This is a
wenzelm@26782
   115
  robust interface to the underlying \mbox{\isa{\isacommand{syntax}}} primitive
wenzelm@26782
   116
  (\secref{sec:syn-trans}).  Type declaration and internal syntactic
wenzelm@26782
   117
  representation of the given entity is retrieved from the context.
wenzelm@26782
   118
  
wenzelm@26782
   119
  \item [\mbox{\isa{\isacommand{no{\isacharunderscore}notation}}}] is similar to \mbox{\isa{\isacommand{notation}}}, but removes the specified syntax annotation from the
wenzelm@26782
   120
  present context.
wenzelm@26782
   121
wenzelm@26782
   122
  \end{descr}
wenzelm@26782
   123
wenzelm@26782
   124
  All of these specifications support local theory targets (cf.\
wenzelm@26782
   125
  \secref{sec:target}).%
wenzelm@26782
   126
\end{isamarkuptext}%
wenzelm@26782
   127
\isamarkuptrue%
wenzelm@26782
   128
%
wenzelm@26782
   129
\isamarkupsubsection{Generic declarations%
wenzelm@26782
   130
}
wenzelm@26782
   131
\isamarkuptrue%
wenzelm@26782
   132
%
wenzelm@26782
   133
\begin{isamarkuptext}%
wenzelm@26782
   134
Arbitrary operations on the background context may be wrapped-up as
wenzelm@26782
   135
  generic declaration elements.  Since the underlying concept of local
wenzelm@26782
   136
  theories may be subject to later re-interpretation, there is an
wenzelm@26782
   137
  additional dependency on a morphism that tells the difference of the
wenzelm@26782
   138
  original declaration context wrt.\ the application context
wenzelm@26782
   139
  encountered later on.  A fact declaration is an important special
wenzelm@26782
   140
  case: it consists of a theorem which is applied to the context by
wenzelm@26782
   141
  means of an attribute.
wenzelm@26782
   142
wenzelm@26782
   143
  \begin{matharray}{rcl}
wenzelm@26782
   144
    \indexdef{}{command}{declaration}\mbox{\isa{\isacommand{declaration}}} & : & \isarkeep{local{\dsh}theory} \\
wenzelm@26782
   145
    \indexdef{}{command}{declare}\mbox{\isa{\isacommand{declare}}} & : & \isarkeep{local{\dsh}theory} \\
wenzelm@26782
   146
  \end{matharray}
wenzelm@26782
   147
wenzelm@26782
   148
  \begin{rail}
wenzelm@26782
   149
    'declaration' target? text
wenzelm@26782
   150
    ;
wenzelm@26782
   151
    'declare' target? (thmrefs + 'and')
wenzelm@26782
   152
    ;
wenzelm@26782
   153
  \end{rail}
wenzelm@26782
   154
wenzelm@26782
   155
  \begin{descr}
wenzelm@26782
   156
wenzelm@26782
   157
  \item [\mbox{\isa{\isacommand{declaration}}}~\isa{d}] adds the declaration
wenzelm@26782
   158
  function \isa{d} of ML type \verb|declaration|, to the current
wenzelm@26782
   159
  local theory under construction.  In later application contexts, the
wenzelm@26782
   160
  function is transformed according to the morphisms being involved in
wenzelm@26782
   161
  the interpretation hierarchy.
wenzelm@26782
   162
wenzelm@26782
   163
  \item [\mbox{\isa{\isacommand{declare}}}~\isa{thms}] declares theorems to the
wenzelm@26782
   164
  current local theory context.  No theorem binding is involved here,
wenzelm@26782
   165
  unlike \mbox{\isa{\isacommand{theorems}}} or \mbox{\isa{\isacommand{lemmas}}} (cf.\
wenzelm@26782
   166
  \secref{sec:axms-thms}), so \mbox{\isa{\isacommand{declare}}} only has the effect
wenzelm@26782
   167
  of applying attributes as included in the theorem specification.
wenzelm@26782
   168
wenzelm@26782
   169
  \end{descr}%
wenzelm@26782
   170
\end{isamarkuptext}%
wenzelm@26782
   171
\isamarkuptrue%
wenzelm@26782
   172
%
wenzelm@26782
   173
\isamarkupsubsection{Local theory targets \label{sec:target}%
wenzelm@26782
   174
}
wenzelm@26782
   175
\isamarkuptrue%
wenzelm@26782
   176
%
wenzelm@26782
   177
\begin{isamarkuptext}%
wenzelm@26782
   178
A local theory target is a context managed separately within the
wenzelm@26782
   179
  enclosing theory.  Contexts may introduce parameters (fixed
wenzelm@26782
   180
  variables) and assumptions (hypotheses).  Definitions and theorems
wenzelm@26782
   181
  depending on the context may be added incrementally later on.  Named
wenzelm@26782
   182
  contexts refer to locales (cf.\ \secref{sec:locale}) or type classes
wenzelm@26842
   183
  (cf.\ \secref{sec:class}); the name ``\isa{{\isachardoublequote}{\isacharminus}{\isachardoublequote}}'' signifies the
wenzelm@26782
   184
  global theory context.
wenzelm@26782
   185
wenzelm@26782
   186
  \begin{matharray}{rcll}
wenzelm@26782
   187
    \indexdef{}{command}{context}\mbox{\isa{\isacommand{context}}} & : & \isartrans{theory}{local{\dsh}theory} \\
wenzelm@26782
   188
    \indexdef{}{command}{end}\mbox{\isa{\isacommand{end}}} & : & \isartrans{local{\dsh}theory}{theory} \\
wenzelm@26782
   189
  \end{matharray}
wenzelm@26782
   190
wenzelm@26782
   191
  \indexouternonterm{target}
wenzelm@26782
   192
  \begin{rail}
wenzelm@26782
   193
    'context' name 'begin'
wenzelm@26782
   194
    ;
wenzelm@26782
   195
wenzelm@26782
   196
    target: '(' 'in' name ')'
wenzelm@26782
   197
    ;
wenzelm@26782
   198
  \end{rail}
wenzelm@26782
   199
wenzelm@26782
   200
  \begin{descr}
wenzelm@26782
   201
  
wenzelm@26842
   202
  \item [\mbox{\isa{\isacommand{context}}}~\isa{{\isachardoublequote}c\ {\isasymBEGIN}{\isachardoublequote}}] recommences an
wenzelm@26782
   203
  existing locale or class context \isa{c}.  Note that locale and
wenzelm@26782
   204
  class definitions allow to include the \indexref{}{keyword}{begin}\mbox{\isa{\isakeyword{begin}}}
wenzelm@26782
   205
  keyword as well, in order to continue the local theory immediately
wenzelm@26782
   206
  after the initial specification.
wenzelm@26782
   207
  
wenzelm@26782
   208
  \item [\mbox{\isa{\isacommand{end}}}] concludes the current local theory and
wenzelm@26782
   209
  continues the enclosing global theory.  Note that a non-local
wenzelm@26782
   210
  \mbox{\isa{\isacommand{end}}} has a different meaning: it concludes the theory
wenzelm@26782
   211
  itself (\secref{sec:begin-thy}).
wenzelm@26782
   212
  
wenzelm@26842
   213
  \item [\isa{{\isachardoublequote}{\isacharparenleft}{\isasymIN}\ c{\isacharparenright}{\isachardoublequote}}] given after any local theory command
wenzelm@26842
   214
  specifies an immediate target, e.g.\ ``\mbox{\isa{\isacommand{definition}}}~\isa{{\isachardoublequote}{\isacharparenleft}{\isasymIN}\ c{\isacharparenright}\ {\isasymdots}{\isachardoublequote}}'' or ``\mbox{\isa{\isacommand{theorem}}}~\isa{{\isachardoublequote}{\isacharparenleft}{\isasymIN}\ c{\isacharparenright}\ {\isasymdots}{\isachardoublequote}}''.  This works both in a local or
wenzelm@26782
   215
  global theory context; the current target context will be suspended
wenzelm@26842
   216
  for this command only.  Note that ``\isa{{\isachardoublequote}{\isacharparenleft}{\isasymIN}\ {\isacharminus}{\isacharparenright}{\isachardoublequote}}'' will
wenzelm@26788
   217
  always produce a global result independently of the current target
wenzelm@26788
   218
  context.
wenzelm@26782
   219
wenzelm@26782
   220
  \end{descr}
wenzelm@26782
   221
wenzelm@26782
   222
  The exact meaning of results produced within a local theory context
wenzelm@26782
   223
  depends on the underlying target infrastructure (locale, type class
wenzelm@26782
   224
  etc.).  The general idea is as follows, considering a context named
wenzelm@26842
   225
  \isa{c} with parameter \isa{x} and assumption \isa{{\isachardoublequote}A{\isacharbrackleft}x{\isacharbrackright}{\isachardoublequote}}.
wenzelm@26782
   226
  
wenzelm@26782
   227
  Definitions are exported by introducing a global version with
wenzelm@26782
   228
  additional arguments; a syntactic abbreviation links the long form
wenzelm@26782
   229
  with the abstract version of the target context.  For example,
wenzelm@26842
   230
  \isa{{\isachardoublequote}a\ {\isasymequiv}\ t{\isacharbrackleft}x{\isacharbrackright}{\isachardoublequote}} becomes \isa{{\isachardoublequote}c{\isachardot}a\ {\isacharquery}x\ {\isasymequiv}\ t{\isacharbrackleft}{\isacharquery}x{\isacharbrackright}{\isachardoublequote}} at the theory
wenzelm@26842
   231
  level (for arbitrary \isa{{\isachardoublequote}{\isacharquery}x{\isachardoublequote}}), together with a local
wenzelm@26842
   232
  abbreviation \isa{{\isachardoublequote}c\ {\isasymequiv}\ c{\isachardot}a\ x{\isachardoublequote}} in the target context (for the
wenzelm@26782
   233
  fixed parameter \isa{x}).
wenzelm@26782
   234
wenzelm@26782
   235
  Theorems are exported by discharging the assumptions and
wenzelm@26842
   236
  generalizing the parameters of the context.  For example, \isa{{\isachardoublequote}a{\isacharcolon}\ B{\isacharbrackleft}x{\isacharbrackright}{\isachardoublequote}} becomes \isa{{\isachardoublequote}c{\isachardot}a{\isacharcolon}\ A{\isacharbrackleft}{\isacharquery}x{\isacharbrackright}\ {\isasymLongrightarrow}\ B{\isacharbrackleft}{\isacharquery}x{\isacharbrackright}{\isachardoublequote}}, again for arbitrary
wenzelm@26842
   237
  \isa{{\isachardoublequote}{\isacharquery}x{\isachardoublequote}}.%
wenzelm@26782
   238
\end{isamarkuptext}%
wenzelm@26782
   239
\isamarkuptrue%
wenzelm@26782
   240
%
wenzelm@26782
   241
\isamarkupsubsection{Locales \label{sec:locale}%
wenzelm@26782
   242
}
wenzelm@26782
   243
\isamarkuptrue%
wenzelm@26782
   244
%
wenzelm@26782
   245
\begin{isamarkuptext}%
wenzelm@26782
   246
Locales are named local contexts, consisting of a list of
wenzelm@26782
   247
  declaration elements that are modeled after the Isar proof context
wenzelm@26782
   248
  commands (cf.\ \secref{sec:proof-context}).%
wenzelm@26782
   249
\end{isamarkuptext}%
wenzelm@26782
   250
\isamarkuptrue%
wenzelm@26782
   251
%
wenzelm@26782
   252
\isamarkupsubsubsection{Locale specifications%
wenzelm@26782
   253
}
wenzelm@26782
   254
\isamarkuptrue%
wenzelm@26782
   255
%
wenzelm@26782
   256
\begin{isamarkuptext}%
wenzelm@26782
   257
\begin{matharray}{rcl}
wenzelm@26782
   258
    \indexdef{}{command}{locale}\mbox{\isa{\isacommand{locale}}} & : & \isartrans{theory}{local{\dsh}theory} \\
wenzelm@26854
   259
    \indexdef{}{command}{print\_locale}\mbox{\isa{\isacommand{print{\isacharunderscore}locale}}}\isa{{\isachardoublequote}\isactrlsup {\isacharasterisk}{\isachardoublequote}} & : & \isarkeep{theory~|~proof} \\
wenzelm@26854
   260
    \indexdef{}{command}{print\_locales}\mbox{\isa{\isacommand{print{\isacharunderscore}locales}}}\isa{{\isachardoublequote}\isactrlsup {\isacharasterisk}{\isachardoublequote}} & : & \isarkeep{theory~|~proof} \\
wenzelm@26854
   261
    \indexdef{}{method}{intro\_locales}\mbox{\isa{intro{\isacharunderscore}locales}} & : & \isarmeth \\
wenzelm@26854
   262
    \indexdef{}{method}{unfold\_locales}\mbox{\isa{unfold{\isacharunderscore}locales}} & : & \isarmeth \\
wenzelm@26782
   263
  \end{matharray}
wenzelm@26782
   264
wenzelm@26782
   265
  \indexouternonterm{contextexpr}\indexouternonterm{contextelem}
wenzelm@26782
   266
  \indexisarelem{fixes}\indexisarelem{constrains}\indexisarelem{assumes}
wenzelm@26782
   267
  \indexisarelem{defines}\indexisarelem{notes}\indexisarelem{includes}
wenzelm@26782
   268
  \begin{rail}
wenzelm@26782
   269
    'locale' ('(open)')? name ('=' localeexpr)? 'begin'?
wenzelm@26782
   270
    ;
wenzelm@26782
   271
    'print\_locale' '!'? localeexpr
wenzelm@26782
   272
    ;
wenzelm@26782
   273
    localeexpr: ((contextexpr '+' (contextelem+)) | contextexpr | (contextelem+))
wenzelm@26782
   274
    ;
wenzelm@26782
   275
wenzelm@26782
   276
    contextexpr: nameref | '(' contextexpr ')' |
wenzelm@26782
   277
    (contextexpr (name mixfix? +)) | (contextexpr + '+')
wenzelm@26782
   278
    ;
wenzelm@26782
   279
    contextelem: fixes | constrains | assumes | defines | notes
wenzelm@26782
   280
    ;
wenzelm@26782
   281
    fixes: 'fixes' ((name ('::' type)? structmixfix? | vars) + 'and')
wenzelm@26782
   282
    ;
wenzelm@26782
   283
    constrains: 'constrains' (name '::' type + 'and')
wenzelm@26782
   284
    ;
wenzelm@26782
   285
    assumes: 'assumes' (thmdecl? props + 'and')
wenzelm@26782
   286
    ;
wenzelm@26782
   287
    defines: 'defines' (thmdecl? prop proppat? + 'and')
wenzelm@26782
   288
    ;
wenzelm@26782
   289
    notes: 'notes' (thmdef? thmrefs + 'and')
wenzelm@26782
   290
    ;
wenzelm@26782
   291
    includes: 'includes' contextexpr
wenzelm@26782
   292
    ;
wenzelm@26782
   293
  \end{rail}
wenzelm@26782
   294
wenzelm@26782
   295
  \begin{descr}
wenzelm@26782
   296
  
wenzelm@26842
   297
  \item [\mbox{\isa{\isacommand{locale}}}~\isa{{\isachardoublequote}loc\ {\isacharequal}\ import\ {\isacharplus}\ body{\isachardoublequote}}] defines a
wenzelm@26782
   298
  new locale \isa{loc} as a context consisting of a certain view of
wenzelm@26782
   299
  existing locales (\isa{import}) plus some additional elements
wenzelm@26782
   300
  (\isa{body}).  Both \isa{import} and \isa{body} are optional;
wenzelm@26782
   301
  the degenerate form \mbox{\isa{\isacommand{locale}}}~\isa{loc} defines an empty
wenzelm@26782
   302
  locale, which may still be useful to collect declarations of facts
wenzelm@26782
   303
  later on.  Type-inference on locale expressions automatically takes
wenzelm@26782
   304
  care of the most general typing that the combined context elements
wenzelm@26782
   305
  may acquire.
wenzelm@26782
   306
wenzelm@26782
   307
  The \isa{import} consists of a structured context expression,
wenzelm@26782
   308
  consisting of references to existing locales, renamed contexts, or
wenzelm@26842
   309
  merged contexts.  Renaming uses positional notation: \isa{{\isachardoublequote}c\ x\isactrlsub {\isadigit{1}}\ {\isasymdots}\ x\isactrlsub n{\isachardoublequote}} means that (a prefix of) the fixed
wenzelm@26842
   310
  parameters of context \isa{c} are named \isa{{\isachardoublequote}x\isactrlsub {\isadigit{1}}{\isacharcomma}\ {\isasymdots}{\isacharcomma}\ x\isactrlsub n{\isachardoublequote}}; a ``\isa{{\isacharunderscore}}'' (underscore) means to skip that
wenzelm@26782
   311
  position.  Renaming by default deletes concrete syntax, but new
wenzelm@26782
   312
  syntax may by specified with a mixfix annotation.  An exeption of
wenzelm@26842
   313
  this rule is the special syntax declared with ``\isa{{\isachardoublequote}{\isacharparenleft}{\isasymSTRUCTURE}{\isacharparenright}{\isachardoublequote}}'' (see below), which is neither deleted nor can it
wenzelm@26782
   314
  be changed.  Merging proceeds from left-to-right, suppressing any
wenzelm@26782
   315
  duplicates stemming from different paths through the import
wenzelm@26782
   316
  hierarchy.
wenzelm@26782
   317
wenzelm@26782
   318
  The \isa{body} consists of basic context elements, further context
wenzelm@26782
   319
  expressions may be included as well.
wenzelm@26782
   320
wenzelm@26782
   321
  \begin{descr}
wenzelm@26782
   322
wenzelm@26842
   323
  \item [\mbox{\isa{\isakeyword{fixes}}}~\isa{{\isachardoublequote}x\ {\isacharcolon}{\isacharcolon}\ {\isasymtau}\ {\isacharparenleft}mx{\isacharparenright}{\isachardoublequote}}] declares a local
wenzelm@26782
   324
  parameter of type \isa{{\isasymtau}} and mixfix annotation \isa{mx} (both
wenzelm@26842
   325
  are optional).  The special syntax declaration ``\isa{{\isachardoublequote}{\isacharparenleft}{\isasymSTRUCTURE}{\isacharparenright}{\isachardoublequote}}'' means that \isa{x} may be referenced
wenzelm@26782
   326
  implicitly in this context.
wenzelm@26782
   327
wenzelm@26842
   328
  \item [\mbox{\isa{\isakeyword{constrains}}}~\isa{{\isachardoublequote}x\ {\isacharcolon}{\isacharcolon}\ {\isasymtau}{\isachardoublequote}}] introduces a type
wenzelm@26782
   329
  constraint \isa{{\isasymtau}} on the local parameter \isa{x}.
wenzelm@26782
   330
wenzelm@26842
   331
  \item [\mbox{\isa{\isakeyword{assumes}}}~\isa{{\isachardoublequote}a{\isacharcolon}\ {\isasymphi}\isactrlsub {\isadigit{1}}\ {\isasymdots}\ {\isasymphi}\isactrlsub n{\isachardoublequote}}]
wenzelm@26782
   332
  introduces local premises, similar to \mbox{\isa{\isacommand{assume}}} within a
wenzelm@26782
   333
  proof (cf.\ \secref{sec:proof-context}).
wenzelm@26782
   334
wenzelm@26842
   335
  \item [\mbox{\isa{\isakeyword{defines}}}~\isa{{\isachardoublequote}a{\isacharcolon}\ x\ {\isasymequiv}\ t{\isachardoublequote}}] defines a previously
wenzelm@26788
   336
  declared parameter.  This is similar to \mbox{\isa{\isacommand{def}}} within a
wenzelm@26788
   337
  proof (cf.\ \secref{sec:proof-context}), but \mbox{\isa{\isakeyword{defines}}}
wenzelm@26782
   338
  takes an equational proposition instead of variable-term pair.  The
wenzelm@26782
   339
  left-hand side of the equation may have additional arguments, e.g.\
wenzelm@26842
   340
  ``\mbox{\isa{\isakeyword{defines}}}~\isa{{\isachardoublequote}f\ x\isactrlsub {\isadigit{1}}\ {\isasymdots}\ x\isactrlsub n\ {\isasymequiv}\ t{\isachardoublequote}}''.
wenzelm@26782
   341
wenzelm@26842
   342
  \item [\mbox{\isa{\isakeyword{notes}}}~\isa{{\isachardoublequote}a\ {\isacharequal}\ b\isactrlsub {\isadigit{1}}\ {\isasymdots}\ b\isactrlsub n{\isachardoublequote}}]
wenzelm@26782
   343
  reconsiders facts within a local context.  Most notably, this may
wenzelm@26782
   344
  include arbitrary declarations in any attribute specifications
wenzelm@26782
   345
  included here, e.g.\ a local \mbox{\isa{simp}} rule.
wenzelm@26782
   346
wenzelm@26788
   347
  \item [\mbox{\isa{\isakeyword{includes}}}~\isa{c}] copies the specified context
wenzelm@26782
   348
  in a statically scoped manner.  Only available in the long goal
wenzelm@26782
   349
  format of \secref{sec:goals}.
wenzelm@26782
   350
wenzelm@26782
   351
  In contrast, the initial \isa{import} specification of a locale
wenzelm@26782
   352
  expression maintains a dynamic relation to the locales being
wenzelm@26782
   353
  referenced (benefiting from any later fact declarations in the
wenzelm@26782
   354
  obvious manner).
wenzelm@26782
   355
wenzelm@26782
   356
  \end{descr}
wenzelm@26782
   357
  
wenzelm@26842
   358
  Note that ``\isa{{\isachardoublequote}{\isacharparenleft}{\isasymIS}\ p\isactrlsub {\isadigit{1}}\ {\isasymdots}\ p\isactrlsub n{\isacharparenright}{\isachardoublequote}}'' patterns given
wenzelm@26788
   359
  in the syntax of \mbox{\isa{\isakeyword{assumes}}} and \mbox{\isa{\isakeyword{defines}}} above
wenzelm@26782
   360
  are illegal in locale definitions.  In the long goal format of
wenzelm@26782
   361
  \secref{sec:goals}, term bindings may be included as expected,
wenzelm@26782
   362
  though.
wenzelm@26782
   363
  
wenzelm@26782
   364
  \medskip By default, locale specifications are ``closed up'' by
wenzelm@26782
   365
  turning the given text into a predicate definition \isa{loc{\isacharunderscore}axioms} and deriving the original assumptions as local lemmas
wenzelm@26782
   366
  (modulo local definitions).  The predicate statement covers only the
wenzelm@26782
   367
  newly specified assumptions, omitting the content of included locale
wenzelm@26782
   368
  expressions.  The full cumulative view is only provided on export,
wenzelm@26782
   369
  involving another predicate \isa{loc} that refers to the complete
wenzelm@26782
   370
  specification text.
wenzelm@26782
   371
  
wenzelm@26782
   372
  In any case, the predicate arguments are those locale parameters
wenzelm@26782
   373
  that actually occur in the respective piece of text.  Also note that
wenzelm@26782
   374
  these predicates operate at the meta-level in theory, but the locale
wenzelm@26782
   375
  packages attempts to internalize statements according to the
wenzelm@26782
   376
  object-logic setup (e.g.\ replacing \isa{{\isasymAnd}} by \isa{{\isasymforall}}, and
wenzelm@26842
   377
  \isa{{\isachardoublequote}{\isasymLongrightarrow}{\isachardoublequote}} by \isa{{\isachardoublequote}{\isasymlongrightarrow}{\isachardoublequote}} in HOL; see also
wenzelm@26782
   378
  \secref{sec:object-logic}).  Separate introduction rules \isa{loc{\isacharunderscore}axioms{\isachardot}intro} and \isa{loc{\isachardot}intro} are provided as well.
wenzelm@26782
   379
  
wenzelm@26842
   380
  The \isa{{\isachardoublequote}{\isacharparenleft}open{\isacharparenright}{\isachardoublequote}} option of a locale specification prevents both
wenzelm@26782
   381
  the current \isa{loc{\isacharunderscore}axioms} and cumulative \isa{loc} predicate
wenzelm@26782
   382
  constructions.  Predicates are also omitted for empty specification
wenzelm@26782
   383
  texts.
wenzelm@26782
   384
wenzelm@26842
   385
  \item [\mbox{\isa{\isacommand{print{\isacharunderscore}locale}}}~\isa{{\isachardoublequote}import\ {\isacharplus}\ body{\isachardoublequote}}] prints the
wenzelm@26782
   386
  specified locale expression in a flattened form.  The notable
wenzelm@26782
   387
  special case \mbox{\isa{\isacommand{print{\isacharunderscore}locale}}}~\isa{loc} just prints the
wenzelm@26782
   388
  contents of the named locale, but keep in mind that type-inference
wenzelm@26782
   389
  will normalize type variables according to the usual alphabetical
wenzelm@26788
   390
  order.  The command omits \mbox{\isa{\isakeyword{notes}}} elements by default.
wenzelm@26842
   391
  Use \mbox{\isa{\isacommand{print{\isacharunderscore}locale}}}\isa{{\isachardoublequote}{\isacharbang}{\isachardoublequote}} to get them included.
wenzelm@26782
   392
wenzelm@26782
   393
  \item [\mbox{\isa{\isacommand{print{\isacharunderscore}locales}}}] prints the names of all locales
wenzelm@26782
   394
  of the current theory.
wenzelm@26782
   395
wenzelm@26782
   396
  \item [\mbox{\isa{intro{\isacharunderscore}locales}} and \mbox{\isa{unfold{\isacharunderscore}locales}}]
wenzelm@26782
   397
  repeatedly expand all introduction rules of locale predicates of the
wenzelm@26782
   398
  theory.  While \mbox{\isa{intro{\isacharunderscore}locales}} only applies the \isa{loc{\isachardot}intro} introduction rules and therefore does not decend to
wenzelm@26782
   399
  assumptions, \mbox{\isa{unfold{\isacharunderscore}locales}} is more aggressive and applies
wenzelm@26782
   400
  \isa{loc{\isacharunderscore}axioms{\isachardot}intro} as well.  Both methods are aware of locale
wenzelm@26782
   401
  specifications entailed by the context, both from target and
wenzelm@26788
   402
  \mbox{\isa{\isakeyword{includes}}} statements, and from interpretations (see
wenzelm@26782
   403
  below).  New goals that are entailed by the current context are
wenzelm@26782
   404
  discharged automatically.
wenzelm@26782
   405
wenzelm@26782
   406
  \end{descr}%
wenzelm@26782
   407
\end{isamarkuptext}%
wenzelm@26782
   408
\isamarkuptrue%
wenzelm@26782
   409
%
wenzelm@26782
   410
\isamarkupsubsubsection{Interpretation of locales%
wenzelm@26782
   411
}
wenzelm@26782
   412
\isamarkuptrue%
wenzelm@26782
   413
%
wenzelm@26782
   414
\begin{isamarkuptext}%
wenzelm@26782
   415
Locale expressions (more precisely, \emph{context expressions}) may
wenzelm@26782
   416
  be instantiated, and the instantiated facts added to the current
wenzelm@26782
   417
  context.  This requires a proof of the instantiated specification
wenzelm@26782
   418
  and is called \emph{locale interpretation}.  Interpretation is
wenzelm@26788
   419
  possible in theories and locales (command \mbox{\isa{\isacommand{interpretation}}}) and also within a proof body (command \mbox{\isa{\isacommand{interpret}}}).
wenzelm@26782
   420
wenzelm@26782
   421
  \begin{matharray}{rcl}
wenzelm@26782
   422
    \indexdef{}{command}{interpretation}\mbox{\isa{\isacommand{interpretation}}} & : & \isartrans{theory}{proof(prove)} \\
wenzelm@26782
   423
    \indexdef{}{command}{interpret}\mbox{\isa{\isacommand{interpret}}} & : & \isartrans{proof(state) ~|~ proof(chain)}{proof(prove)} \\
wenzelm@26854
   424
    \indexdef{}{command}{print\_interps}\mbox{\isa{\isacommand{print{\isacharunderscore}interps}}}\isa{{\isachardoublequote}\isactrlsup {\isacharasterisk}{\isachardoublequote}} & : &  \isarkeep{theory~|~proof} \\
wenzelm@26782
   425
  \end{matharray}
wenzelm@26782
   426
wenzelm@26782
   427
  \indexouternonterm{interp}
wenzelm@26782
   428
  \begin{rail}
wenzelm@26782
   429
    'interpretation' (interp | name ('<' | subseteq) contextexpr)
wenzelm@26782
   430
    ;
wenzelm@26782
   431
    'interpret' interp
wenzelm@26782
   432
    ;
wenzelm@26782
   433
    'print\_interps' '!'? name
wenzelm@26782
   434
    ;
wenzelm@26782
   435
    instantiation: ('[' (inst+) ']')?
wenzelm@26782
   436
    ;
wenzelm@26782
   437
    interp: thmdecl? \\ (contextexpr instantiation |
wenzelm@26782
   438
      name instantiation 'where' (thmdecl? prop + 'and'))
wenzelm@26782
   439
    ;
wenzelm@26782
   440
  \end{rail}
wenzelm@26782
   441
wenzelm@26782
   442
  \begin{descr}
wenzelm@26782
   443
wenzelm@26842
   444
  \item [\mbox{\isa{\isacommand{interpretation}}}~\isa{{\isachardoublequote}expr\ insts\ {\isasymWHERE}\ eqns{\isachardoublequote}}]
wenzelm@26782
   445
wenzelm@26782
   446
  The first form of \mbox{\isa{\isacommand{interpretation}}} interprets \isa{expr} in the theory.  The instantiation is given as a list of terms
wenzelm@26782
   447
  \isa{insts} and is positional.  All parameters must receive an
wenzelm@26782
   448
  instantiation term --- with the exception of defined parameters.
wenzelm@26782
   449
  These are, if omitted, derived from the defining equation and other
wenzelm@26782
   450
  instantiations.  Use ``\isa{{\isacharunderscore}}'' to omit an instantiation term.
wenzelm@26782
   451
wenzelm@26782
   452
  The command generates proof obligations for the instantiated
wenzelm@26782
   453
  specifications (assumes and defines elements).  Once these are
wenzelm@26782
   454
  discharged by the user, instantiated facts are added to the theory
wenzelm@26782
   455
  in a post-processing phase.
wenzelm@26782
   456
wenzelm@26782
   457
  Additional equations, which are unfolded in facts during
wenzelm@26782
   458
  post-processing, may be given after the keyword \mbox{\isa{\isakeyword{where}}}.
wenzelm@26782
   459
  This is useful for interpreting concepts introduced through
wenzelm@26782
   460
  definition specification elements.  The equations must be proved.
wenzelm@26782
   461
  Note that if equations are present, the context expression is
wenzelm@26782
   462
  restricted to a locale name.
wenzelm@26782
   463
wenzelm@26782
   464
  The command is aware of interpretations already active in the
wenzelm@26782
   465
  theory.  No proof obligations are generated for those, neither is
wenzelm@26782
   466
  post-processing applied to their facts.  This avoids duplication of
wenzelm@26782
   467
  interpreted facts, in particular.  Note that, in the case of a
wenzelm@26782
   468
  locale with import, parts of the interpretation may already be
wenzelm@26782
   469
  active.  The command will only generate proof obligations and
wenzelm@26782
   470
  process facts for new parts.
wenzelm@26782
   471
wenzelm@26782
   472
  The context expression may be preceded by a name and/or attributes.
wenzelm@26782
   473
  These take effect in the post-processing of facts.  The name is used
wenzelm@26782
   474
  to prefix fact names, for example to avoid accidental hiding of
wenzelm@26782
   475
  other facts.  Attributes are applied after attributes of the
wenzelm@26782
   476
  interpreted facts.
wenzelm@26782
   477
wenzelm@26782
   478
  Adding facts to locales has the effect of adding interpreted facts
wenzelm@26782
   479
  to the theory for all active interpretations also.  That is,
wenzelm@26782
   480
  interpretations dynamically participate in any facts added to
wenzelm@26782
   481
  locales.
wenzelm@26782
   482
wenzelm@26842
   483
  \item [\mbox{\isa{\isacommand{interpretation}}}~\isa{{\isachardoublequote}name\ {\isasymsubseteq}\ expr{\isachardoublequote}}]
wenzelm@26782
   484
wenzelm@26782
   485
  This form of the command interprets \isa{expr} in the locale
wenzelm@26782
   486
  \isa{name}.  It requires a proof that the specification of \isa{name} implies the specification of \isa{expr}.  As in the
wenzelm@26782
   487
  localized version of the theorem command, the proof is in the
wenzelm@26782
   488
  context of \isa{name}.  After the proof obligation has been
wenzelm@26782
   489
  dischared, the facts of \isa{expr} become part of locale \isa{name} as \emph{derived} context elements and are available when the
wenzelm@26782
   490
  context \isa{name} is subsequently entered.  Note that, like
wenzelm@26782
   491
  import, this is dynamic: facts added to a locale part of \isa{expr} after interpretation become also available in \isa{name}.
wenzelm@26782
   492
  Like facts of renamed context elements, facts obtained by
wenzelm@26782
   493
  interpretation may be accessed by prefixing with the parameter
wenzelm@26782
   494
  renaming (where the parameters are separated by ``\isa{{\isacharunderscore}}'').
wenzelm@26782
   495
wenzelm@26782
   496
  Unlike interpretation in theories, instantiation is confined to the
wenzelm@26782
   497
  renaming of parameters, which may be specified as part of the
wenzelm@26782
   498
  context expression \isa{expr}.  Using defined parameters in \isa{name} one may achieve an effect similar to instantiation, though.
wenzelm@26782
   499
wenzelm@26782
   500
  Only specification fragments of \isa{expr} that are not already
wenzelm@26782
   501
  part of \isa{name} (be it imported, derived or a derived fragment
wenzelm@26782
   502
  of the import) are considered by interpretation.  This enables
wenzelm@26782
   503
  circular interpretations.
wenzelm@26782
   504
wenzelm@26782
   505
  If interpretations of \isa{name} exist in the current theory, the
wenzelm@26782
   506
  command adds interpretations for \isa{expr} as well, with the same
wenzelm@26782
   507
  prefix and attributes, although only for fragments of \isa{expr}
wenzelm@26782
   508
  that are not interpreted in the theory already.
wenzelm@26782
   509
wenzelm@26842
   510
  \item [\mbox{\isa{\isacommand{interpret}}}~\isa{{\isachardoublequote}expr\ insts\ {\isasymWHERE}\ eqns{\isachardoublequote}}]
wenzelm@26782
   511
  interprets \isa{expr} in the proof context and is otherwise
wenzelm@26788
   512
  similar to interpretation in theories.
wenzelm@26782
   513
wenzelm@26782
   514
  \item [\mbox{\isa{\isacommand{print{\isacharunderscore}interps}}}~\isa{loc}] prints the
wenzelm@26782
   515
  interpretations of a particular locale \isa{loc} that are active
wenzelm@26782
   516
  in the current context, either theory or proof context.  The
wenzelm@26782
   517
  exclamation point argument triggers printing of \emph{witness}
wenzelm@26782
   518
  theorems justifying interpretations.  These are normally omitted
wenzelm@26782
   519
  from the output.
wenzelm@26782
   520
  
wenzelm@26782
   521
  \end{descr}
wenzelm@26782
   522
wenzelm@26782
   523
  \begin{warn}
wenzelm@26782
   524
    Since attributes are applied to interpreted theorems,
wenzelm@26782
   525
    interpretation may modify the context of common proof tools, e.g.\
wenzelm@26782
   526
    the Simplifier or Classical Reasoner.  Since the behavior of such
wenzelm@26782
   527
    automated reasoning tools is \emph{not} stable under
wenzelm@26782
   528
    interpretation morphisms, manual declarations might have to be
wenzelm@26782
   529
    issued.
wenzelm@26782
   530
  \end{warn}
wenzelm@26782
   531
wenzelm@26782
   532
  \begin{warn}
wenzelm@26782
   533
    An interpretation in a theory may subsume previous
wenzelm@26782
   534
    interpretations.  This happens if the same specification fragment
wenzelm@26782
   535
    is interpreted twice and the instantiation of the second
wenzelm@26782
   536
    interpretation is more general than the interpretation of the
wenzelm@26782
   537
    first.  A warning is issued, since it is likely that these could
wenzelm@26782
   538
    have been generalized in the first place.  The locale package does
wenzelm@26782
   539
    not attempt to remove subsumed interpretations.
wenzelm@26782
   540
  \end{warn}%
wenzelm@26782
   541
\end{isamarkuptext}%
wenzelm@26782
   542
\isamarkuptrue%
wenzelm@26782
   543
%
wenzelm@26782
   544
\isamarkupsubsection{Classes \label{sec:class}%
wenzelm@26782
   545
}
wenzelm@26782
   546
\isamarkuptrue%
wenzelm@26782
   547
%
wenzelm@26782
   548
\begin{isamarkuptext}%
wenzelm@26782
   549
A class is a particular locale with \emph{exactly one} type variable
wenzelm@26782
   550
  \isa{{\isasymalpha}}.  Beyond the underlying locale, a corresponding type class
wenzelm@26782
   551
  is established which is interpreted logically as axiomatic type
wenzelm@26782
   552
  class \cite{Wenzel:1997:TPHOL} whose logical content are the
wenzelm@26782
   553
  assumptions of the locale.  Thus, classes provide the full
wenzelm@26782
   554
  generality of locales combined with the commodity of type classes
wenzelm@26782
   555
  (notably type-inference).  See \cite{isabelle-classes} for a short
wenzelm@26782
   556
  tutorial.
wenzelm@26782
   557
wenzelm@26782
   558
  \begin{matharray}{rcl}
wenzelm@26782
   559
    \indexdef{}{command}{class}\mbox{\isa{\isacommand{class}}} & : & \isartrans{theory}{local{\dsh}theory} \\
wenzelm@26782
   560
    \indexdef{}{command}{instantiation}\mbox{\isa{\isacommand{instantiation}}} & : & \isartrans{theory}{local{\dsh}theory} \\
wenzelm@26782
   561
    \indexdef{}{command}{instance}\mbox{\isa{\isacommand{instance}}} & : & \isartrans{local{\dsh}theory}{local{\dsh}theory} \\
wenzelm@26782
   562
    \indexdef{}{command}{subclass}\mbox{\isa{\isacommand{subclass}}} & : & \isartrans{local{\dsh}theory}{local{\dsh}theory} \\
wenzelm@26854
   563
    \indexdef{}{command}{print\_classes}\mbox{\isa{\isacommand{print{\isacharunderscore}classes}}}\isa{{\isachardoublequote}\isactrlsup {\isacharasterisk}{\isachardoublequote}} & : & \isarkeep{theory~|~proof} \\
wenzelm@26854
   564
    \indexdef{}{method}{intro\_classes}\mbox{\isa{intro{\isacharunderscore}classes}} & : & \isarmeth \\
wenzelm@26782
   565
  \end{matharray}
wenzelm@26782
   566
wenzelm@26782
   567
  \begin{rail}
wenzelm@26782
   568
    'class' name '=' ((superclassexpr '+' (contextelem+)) | superclassexpr | (contextelem+)) \\
wenzelm@26782
   569
      'begin'?
wenzelm@26782
   570
    ;
wenzelm@26782
   571
    'instantiation' (nameref + 'and') '::' arity 'begin'
wenzelm@26782
   572
    ;
wenzelm@26782
   573
    'instance'
wenzelm@26782
   574
    ;
wenzelm@26782
   575
    'subclass' target? nameref
wenzelm@26782
   576
    ;
wenzelm@26782
   577
    'print\_classes'
wenzelm@26782
   578
    ;
wenzelm@26782
   579
wenzelm@26782
   580
    superclassexpr: nameref | (nameref '+' superclassexpr)
wenzelm@26782
   581
    ;
wenzelm@26782
   582
  \end{rail}
wenzelm@26782
   583
wenzelm@26782
   584
  \begin{descr}
wenzelm@26782
   585
wenzelm@26842
   586
  \item [\mbox{\isa{\isacommand{class}}}~\isa{{\isachardoublequote}c\ {\isacharequal}\ superclasses\ {\isacharplus}\ body{\isachardoublequote}}] defines
wenzelm@26782
   587
  a new class \isa{c}, inheriting from \isa{superclasses}.  This
wenzelm@26782
   588
  introduces a locale \isa{c} with import of all locales \isa{superclasses}.
wenzelm@26782
   589
wenzelm@26788
   590
  Any \mbox{\isa{\isakeyword{fixes}}} in \isa{body} are lifted to the global
wenzelm@26842
   591
  theory level (\emph{class operations} \isa{{\isachardoublequote}f\isactrlsub {\isadigit{1}}{\isacharcomma}\ {\isasymdots}{\isacharcomma}\ f\isactrlsub n{\isachardoublequote}} of class \isa{c}), mapping the local type parameter
wenzelm@26842
   592
  \isa{{\isasymalpha}} to a schematic type variable \isa{{\isachardoublequote}{\isacharquery}{\isasymalpha}\ {\isacharcolon}{\isacharcolon}\ c{\isachardoublequote}}.
wenzelm@26782
   593
wenzelm@26788
   594
  Likewise, \mbox{\isa{\isakeyword{assumes}}} in \isa{body} are also lifted,
wenzelm@26842
   595
  mapping each local parameter \isa{{\isachardoublequote}f\ {\isacharcolon}{\isacharcolon}\ {\isasymtau}{\isacharbrackleft}{\isasymalpha}{\isacharbrackright}{\isachardoublequote}} to its
wenzelm@26842
   596
  corresponding global constant \isa{{\isachardoublequote}f\ {\isacharcolon}{\isacharcolon}\ {\isasymtau}{\isacharbrackleft}{\isacharquery}{\isasymalpha}\ {\isacharcolon}{\isacharcolon}\ c{\isacharbrackright}{\isachardoublequote}}.  The
wenzelm@26782
   597
  corresponding introduction rule is provided as \isa{c{\isacharunderscore}class{\isacharunderscore}axioms{\isachardot}intro}.  This rule should be rarely needed directly
wenzelm@26782
   598
  --- the \mbox{\isa{intro{\isacharunderscore}classes}} method takes care of the details of
wenzelm@26782
   599
  class membership proofs.
wenzelm@26782
   600
wenzelm@26842
   601
  \item [\mbox{\isa{\isacommand{instantiation}}}~\isa{{\isachardoublequote}t\ {\isacharcolon}{\isacharcolon}\ {\isacharparenleft}s\isactrlsub {\isadigit{1}}{\isacharcomma}\ {\isasymdots}{\isacharcomma}\ s\isactrlsub n{\isacharparenright}\ s\ {\isasymBEGIN}{\isachardoublequote}}] opens a theory target (cf.\
wenzelm@26842
   602
  \secref{sec:target}) which allows to specify class operations \isa{{\isachardoublequote}f\isactrlsub {\isadigit{1}}{\isacharcomma}\ {\isasymdots}{\isacharcomma}\ f\isactrlsub n{\isachardoublequote}} corresponding to sort \isa{s} at the
wenzelm@26842
   603
  particular type instance \isa{{\isachardoublequote}{\isacharparenleft}{\isasymalpha}\isactrlsub {\isadigit{1}}\ {\isacharcolon}{\isacharcolon}\ s\isactrlsub {\isadigit{1}}{\isacharcomma}\ {\isasymdots}{\isacharcomma}\ {\isasymalpha}\isactrlsub n\ {\isacharcolon}{\isacharcolon}\ s\isactrlsub n{\isacharparenright}\ t{\isachardoublequote}}.  A plain \mbox{\isa{\isacommand{instance}}} command
wenzelm@26782
   604
  in the target body poses a goal stating these type arities.  The
wenzelm@26782
   605
  target is concluded by an \indexref{}{command}{end}\mbox{\isa{\isacommand{end}}} command.
wenzelm@26782
   606
wenzelm@26782
   607
  Note that a list of simultaneous type constructors may be given;
wenzelm@26782
   608
  this corresponds nicely to mutual recursive type definitions, e.g.\
wenzelm@26782
   609
  in Isabelle/HOL.
wenzelm@26782
   610
wenzelm@26782
   611
  \item [\mbox{\isa{\isacommand{instance}}}] in an instantiation target body sets
wenzelm@26782
   612
  up a goal stating the type arities claimed at the opening \mbox{\isa{\isacommand{instantiation}}}.  The proof would usually proceed by \mbox{\isa{intro{\isacharunderscore}classes}}, and then establish the characteristic theorems of
wenzelm@26782
   613
  the type classes involved.  After finishing the proof, the
wenzelm@26782
   614
  background theory will be augmented by the proven type arities.
wenzelm@26782
   615
wenzelm@26782
   616
  \item [\mbox{\isa{\isacommand{subclass}}}~\isa{c}] in a class context for class
wenzelm@26782
   617
  \isa{d} sets up a goal stating that class \isa{c} is logically
wenzelm@26782
   618
  contained in class \isa{d}.  After finishing the proof, class
wenzelm@26782
   619
  \isa{d} is proven to be subclass \isa{c} and the locale \isa{c} is interpreted into \isa{d} simultaneously.
wenzelm@26782
   620
wenzelm@26782
   621
  \item [\mbox{\isa{\isacommand{print{\isacharunderscore}classes}}}] prints all classes in the current
wenzelm@26782
   622
  theory.
wenzelm@26782
   623
wenzelm@26782
   624
  \item [\mbox{\isa{intro{\isacharunderscore}classes}}] repeatedly expands all class
wenzelm@26782
   625
  introduction rules of this theory.  Note that this method usually
wenzelm@26782
   626
  needs not be named explicitly, as it is already included in the
wenzelm@26782
   627
  default proof step (e.g.\ of \mbox{\isa{\isacommand{proof}}}).  In particular,
wenzelm@26782
   628
  instantiation of trivial (syntactic) classes may be performed by a
wenzelm@26782
   629
  single ``\mbox{\isa{\isacommand{{\isachardot}{\isachardot}}}}'' proof step.
wenzelm@26782
   630
wenzelm@26782
   631
  \end{descr}%
wenzelm@26782
   632
\end{isamarkuptext}%
wenzelm@26782
   633
\isamarkuptrue%
wenzelm@26782
   634
%
wenzelm@26782
   635
\isamarkupsubsubsection{The class target%
wenzelm@26782
   636
}
wenzelm@26782
   637
\isamarkuptrue%
wenzelm@26782
   638
%
wenzelm@26782
   639
\begin{isamarkuptext}%
wenzelm@26782
   640
%FIXME check
wenzelm@26782
   641
wenzelm@26782
   642
  A named context may refer to a locale (cf.\ \secref{sec:target}).
wenzelm@26782
   643
  If this locale is also a class \isa{c}, apart from the common
wenzelm@26782
   644
  locale target behaviour the following happens.
wenzelm@26782
   645
wenzelm@26782
   646
  \begin{itemize}
wenzelm@26782
   647
wenzelm@26842
   648
  \item Local constant declarations \isa{{\isachardoublequote}g{\isacharbrackleft}{\isasymalpha}{\isacharbrackright}{\isachardoublequote}} referring to the
wenzelm@26842
   649
  local type parameter \isa{{\isasymalpha}} and local parameters \isa{{\isachardoublequote}f{\isacharbrackleft}{\isasymalpha}{\isacharbrackright}{\isachardoublequote}}
wenzelm@26842
   650
  are accompanied by theory-level constants \isa{{\isachardoublequote}g{\isacharbrackleft}{\isacharquery}{\isasymalpha}\ {\isacharcolon}{\isacharcolon}\ c{\isacharbrackright}{\isachardoublequote}}
wenzelm@26842
   651
  referring to theory-level class operations \isa{{\isachardoublequote}f{\isacharbrackleft}{\isacharquery}{\isasymalpha}\ {\isacharcolon}{\isacharcolon}\ c{\isacharbrackright}{\isachardoublequote}}.
wenzelm@26782
   652
wenzelm@26782
   653
  \item Local theorem bindings are lifted as are assumptions.
wenzelm@26782
   654
wenzelm@26842
   655
  \item Local syntax refers to local operations \isa{{\isachardoublequote}g{\isacharbrackleft}{\isasymalpha}{\isacharbrackright}{\isachardoublequote}} and
wenzelm@26842
   656
  global operations \isa{{\isachardoublequote}g{\isacharbrackleft}{\isacharquery}{\isasymalpha}\ {\isacharcolon}{\isacharcolon}\ c{\isacharbrackright}{\isachardoublequote}} uniformly.  Type inference
wenzelm@26782
   657
  resolves ambiguities.  In rare cases, manual type annotations are
wenzelm@26782
   658
  needed.
wenzelm@26782
   659
  
wenzelm@26782
   660
  \end{itemize}%
wenzelm@26782
   661
\end{isamarkuptext}%
wenzelm@26782
   662
\isamarkuptrue%
wenzelm@26782
   663
%
wenzelm@26782
   664
\isamarkupsubsection{Axiomatic type classes \label{sec:axclass}%
wenzelm@26782
   665
}
wenzelm@26782
   666
\isamarkuptrue%
wenzelm@26782
   667
%
wenzelm@26782
   668
\begin{isamarkuptext}%
wenzelm@26782
   669
\begin{matharray}{rcl}
wenzelm@26782
   670
    \indexdef{}{command}{axclass}\mbox{\isa{\isacommand{axclass}}} & : & \isartrans{theory}{theory} \\
wenzelm@26782
   671
    \indexdef{}{command}{instance}\mbox{\isa{\isacommand{instance}}} & : & \isartrans{theory}{proof(prove)} \\
wenzelm@26782
   672
  \end{matharray}
wenzelm@26782
   673
wenzelm@26782
   674
  Axiomatic type classes are Isabelle/Pure's primitive
wenzelm@26782
   675
  \emph{definitional} interface to type classes.  For practical
wenzelm@26782
   676
  applications, you should consider using classes
wenzelm@26782
   677
  (cf.~\secref{sec:classes}) which provide high level interface.
wenzelm@26782
   678
wenzelm@26782
   679
  \begin{rail}
wenzelm@26782
   680
    'axclass' classdecl (axmdecl prop +)
wenzelm@26782
   681
    ;
wenzelm@26782
   682
    'instance' (nameref ('<' | subseteq) nameref | nameref '::' arity)
wenzelm@26782
   683
    ;
wenzelm@26782
   684
  \end{rail}
wenzelm@26782
   685
wenzelm@26782
   686
  \begin{descr}
wenzelm@26782
   687
  
wenzelm@26842
   688
  \item [\mbox{\isa{\isacommand{axclass}}}~\isa{{\isachardoublequote}c\ {\isasymsubseteq}\ c\isactrlsub {\isadigit{1}}{\isacharcomma}\ {\isasymdots}{\isacharcomma}\ c\isactrlsub n\ axms{\isachardoublequote}}] defines an axiomatic type class as the intersection of
wenzelm@26782
   689
  existing classes, with additional axioms holding.  Class axioms may
wenzelm@26782
   690
  not contain more than one type variable.  The class axioms (with
wenzelm@26782
   691
  implicit sort constraints added) are bound to the given names.
wenzelm@26782
   692
  Furthermore a class introduction rule is generated (being bound as
wenzelm@26782
   693
  \isa{c{\isacharunderscore}class{\isachardot}intro}); this rule is employed by method \mbox{\isa{intro{\isacharunderscore}classes}} to support instantiation proofs of this class.
wenzelm@26782
   694
  
wenzelm@26782
   695
  The ``class axioms'' are stored as theorems according to the given
wenzelm@26842
   696
  name specifications, adding \isa{{\isachardoublequote}c{\isacharunderscore}class{\isachardoublequote}} as name space prefix;
wenzelm@26782
   697
  the same facts are also stored collectively as \isa{c{\isacharunderscore}class{\isachardot}axioms}.
wenzelm@26782
   698
  
wenzelm@26842
   699
  \item [\mbox{\isa{\isacommand{instance}}}~\isa{{\isachardoublequote}c\isactrlsub {\isadigit{1}}\ {\isasymsubseteq}\ c\isactrlsub {\isadigit{2}}{\isachardoublequote}} and
wenzelm@26842
   700
  \mbox{\isa{\isacommand{instance}}}~\isa{{\isachardoublequote}t\ {\isacharcolon}{\isacharcolon}\ {\isacharparenleft}s\isactrlsub {\isadigit{1}}{\isacharcomma}\ {\isasymdots}{\isacharcomma}\ s\isactrlsub n{\isacharparenright}\ s{\isachardoublequote}}]
wenzelm@26782
   701
  setup a goal stating a class relation or type arity.  The proof
wenzelm@26782
   702
  would usually proceed by \mbox{\isa{intro{\isacharunderscore}classes}}, and then establish
wenzelm@26782
   703
  the characteristic theorems of the type classes involved.  After
wenzelm@26782
   704
  finishing the proof, the theory will be augmented by a type
wenzelm@26782
   705
  signature declaration corresponding to the resulting theorem.
wenzelm@26782
   706
wenzelm@26782
   707
  \end{descr}%
wenzelm@26782
   708
\end{isamarkuptext}%
wenzelm@26782
   709
\isamarkuptrue%
wenzelm@26782
   710
%
wenzelm@26782
   711
\isamarkupsubsection{Arbitrary overloading%
wenzelm@26782
   712
}
wenzelm@26782
   713
\isamarkuptrue%
wenzelm@26782
   714
%
wenzelm@26782
   715
\begin{isamarkuptext}%
wenzelm@26782
   716
Isabelle/Pure's definitional schemes support certain forms of
wenzelm@26782
   717
  overloading (see \secref{sec:consts}).  At most occassions
wenzelm@26782
   718
  overloading will be used in a Haskell-like fashion together with
wenzelm@26782
   719
  type classes by means of \mbox{\isa{\isacommand{instantiation}}} (see
wenzelm@26782
   720
  \secref{sec:class}).  Sometimes low-level overloading is desirable.
wenzelm@26782
   721
  The \mbox{\isa{\isacommand{overloading}}} target provides a convenient view for
wenzelm@26782
   722
  end-users.
wenzelm@26782
   723
wenzelm@26782
   724
  \begin{matharray}{rcl}
wenzelm@26782
   725
    \indexdef{}{command}{overloading}\mbox{\isa{\isacommand{overloading}}} & : & \isartrans{theory}{local{\dsh}theory} \\
wenzelm@26782
   726
  \end{matharray}
wenzelm@26782
   727
wenzelm@26782
   728
  \begin{rail}
wenzelm@26782
   729
    'overloading' \\
wenzelm@26782
   730
    ( string ( '==' | equiv ) term ( '(' 'unchecked' ')' )? + ) 'begin'
wenzelm@26782
   731
  \end{rail}
wenzelm@26782
   732
wenzelm@26782
   733
  \begin{descr}
wenzelm@26782
   734
wenzelm@26842
   735
  \item [\mbox{\isa{\isacommand{overloading}}}~\isa{{\isachardoublequote}x\isactrlsub {\isadigit{1}}\ {\isasymequiv}\ c\isactrlsub {\isadigit{1}}\ {\isacharcolon}{\isacharcolon}\ {\isasymtau}\isactrlsub {\isadigit{1}}\ {\isasymAND}\ {\isasymdots}\ x\isactrlsub n\ {\isasymequiv}\ c\isactrlsub n\ {\isacharcolon}{\isacharcolon}\ {\isasymtau}\isactrlsub n\ {\isasymBEGIN}{\isachardoublequote}}]
wenzelm@26782
   736
  opens a theory target (cf.\ \secref{sec:target}) which allows to
wenzelm@26782
   737
  specify constants with overloaded definitions.  These are identified
wenzelm@26842
   738
  by an explicitly given mapping from variable names \isa{{\isachardoublequote}x\isactrlsub i{\isachardoublequote}} to constants \isa{{\isachardoublequote}c\isactrlsub i{\isachardoublequote}} at particular type
wenzelm@26782
   739
  instances.  The definitions themselves are established using common
wenzelm@26842
   740
  specification tools, using the names \isa{{\isachardoublequote}x\isactrlsub i{\isachardoublequote}} as
wenzelm@26782
   741
  reference to the corresponding constants.  The target is concluded
wenzelm@26782
   742
  by \mbox{\isa{\isacommand{end}}}.
wenzelm@26782
   743
wenzelm@26842
   744
  A \isa{{\isachardoublequote}{\isacharparenleft}unchecked{\isacharparenright}{\isachardoublequote}} option disables global dependency checks for
wenzelm@26782
   745
  the corresponding definition, which is occasionally useful for
wenzelm@26782
   746
  exotic overloading.  It is at the discretion of the user to avoid
wenzelm@26782
   747
  malformed theory specifications!
wenzelm@26782
   748
wenzelm@26782
   749
  \end{descr}%
wenzelm@26782
   750
\end{isamarkuptext}%
wenzelm@26782
   751
\isamarkuptrue%
wenzelm@26782
   752
%
wenzelm@26782
   753
\isamarkupsubsection{Configuration options%
wenzelm@26782
   754
}
wenzelm@26782
   755
\isamarkuptrue%
wenzelm@26782
   756
%
wenzelm@26782
   757
\begin{isamarkuptext}%
wenzelm@26782
   758
Isabelle/Pure maintains a record of named configuration options
wenzelm@26782
   759
  within the theory or proof context, with values of type \verb|bool|, \verb|int|, or \verb|string|.  Tools may declare
wenzelm@26782
   760
  options in ML, and then refer to these values (relative to the
wenzelm@26782
   761
  context).  Thus global reference variables are easily avoided.  The
wenzelm@26782
   762
  user may change the value of a configuration option by means of an
wenzelm@26782
   763
  associated attribute of the same name.  This form of context
wenzelm@26782
   764
  declaration works particularly well with commands such as \mbox{\isa{\isacommand{declare}}} or \mbox{\isa{\isacommand{using}}}.
wenzelm@26782
   765
wenzelm@26782
   766
  For historical reasons, some tools cannot take the full proof
wenzelm@26782
   767
  context into account and merely refer to the background theory.
wenzelm@26782
   768
  This is accommodated by configuration options being declared as
wenzelm@26782
   769
  ``global'', which may not be changed within a local context.
wenzelm@26782
   770
wenzelm@26782
   771
  \begin{matharray}{rcll}
wenzelm@26854
   772
    \indexdef{}{command}{print\_configs}\mbox{\isa{\isacommand{print{\isacharunderscore}configs}}} & : & \isarkeep{theory~|~proof} \\
wenzelm@26782
   773
  \end{matharray}
wenzelm@26782
   774
wenzelm@26782
   775
  \begin{rail}
wenzelm@26782
   776
    name ('=' ('true' | 'false' | int | name))?
wenzelm@26782
   777
  \end{rail}
wenzelm@26782
   778
wenzelm@26782
   779
  \begin{descr}
wenzelm@26782
   780
  
wenzelm@26782
   781
  \item [\mbox{\isa{\isacommand{print{\isacharunderscore}configs}}}] prints the available
wenzelm@26782
   782
  configuration options, with names, types, and current values.
wenzelm@26782
   783
  
wenzelm@26842
   784
  \item [\isa{{\isachardoublequote}name\ {\isacharequal}\ value{\isachardoublequote}}] as an attribute expression modifies
wenzelm@26782
   785
  the named option, with the syntax of the value depending on the
wenzelm@26782
   786
  option's type.  For \verb|bool| the default value is \isa{true}.  Any attempt to change a global option in a local context is
wenzelm@26782
   787
  ignored.
wenzelm@26782
   788
wenzelm@26782
   789
  \end{descr}%
wenzelm@26782
   790
\end{isamarkuptext}%
wenzelm@26782
   791
\isamarkuptrue%
wenzelm@26782
   792
%
wenzelm@26782
   793
\isamarkupsection{Derived proof schemes%
wenzelm@26782
   794
}
wenzelm@26782
   795
\isamarkuptrue%
wenzelm@26782
   796
%
wenzelm@26782
   797
\isamarkupsubsection{Generalized elimination \label{sec:obtain}%
wenzelm@26782
   798
}
wenzelm@26782
   799
\isamarkuptrue%
wenzelm@26782
   800
%
wenzelm@26782
   801
\begin{isamarkuptext}%
wenzelm@26782
   802
\begin{matharray}{rcl}
wenzelm@26782
   803
    \indexdef{}{command}{obtain}\mbox{\isa{\isacommand{obtain}}} & : & \isartrans{proof(state)}{proof(prove)} \\
wenzelm@26842
   804
    \indexdef{}{command}{guess}\mbox{\isa{\isacommand{guess}}}\isa{{\isachardoublequote}\isactrlsup {\isacharasterisk}{\isachardoublequote}} & : & \isartrans{proof(state)}{proof(prove)} \\
wenzelm@26782
   805
  \end{matharray}
wenzelm@26782
   806
wenzelm@26782
   807
  Generalized elimination means that additional elements with certain
wenzelm@26782
   808
  properties may be introduced in the current context, by virtue of a
wenzelm@26782
   809
  locally proven ``soundness statement''.  Technically speaking, the
wenzelm@26782
   810
  \mbox{\isa{\isacommand{obtain}}} language element is like a declaration of
wenzelm@26782
   811
  \mbox{\isa{\isacommand{fix}}} and \mbox{\isa{\isacommand{assume}}} (see also see
wenzelm@26782
   812
  \secref{sec:proof-context}), together with a soundness proof of its
wenzelm@26782
   813
  additional claim.  According to the nature of existential reasoning,
wenzelm@26782
   814
  assumptions get eliminated from any result exported from the context
wenzelm@26782
   815
  later, provided that the corresponding parameters do \emph{not}
wenzelm@26782
   816
  occur in the conclusion.
wenzelm@26782
   817
wenzelm@26782
   818
  \begin{rail}
wenzelm@26782
   819
    'obtain' parname? (vars + 'and') 'where' (props + 'and')
wenzelm@26782
   820
    ;
wenzelm@26782
   821
    'guess' (vars + 'and')
wenzelm@26782
   822
    ;
wenzelm@26782
   823
  \end{rail}
wenzelm@26782
   824
wenzelm@26782
   825
  The derived Isar command \mbox{\isa{\isacommand{obtain}}} is defined as follows
wenzelm@26842
   826
  (where \isa{{\isachardoublequote}b\isactrlsub {\isadigit{1}}{\isacharcomma}\ {\isasymdots}{\isacharcomma}\ b\isactrlsub k{\isachardoublequote}} shall refer to (optional)
wenzelm@26782
   827
  facts indicated for forward chaining).
wenzelm@26782
   828
  \begin{matharray}{l}
wenzelm@26842
   829
    \isa{{\isachardoublequote}{\isasymlangle}using\ b\isactrlsub {\isadigit{1}}\ {\isasymdots}\ b\isactrlsub k{\isasymrangle}{\isachardoublequote}}~~\mbox{\isa{\isacommand{obtain}}}~\isa{{\isachardoublequote}x\isactrlsub {\isadigit{1}}\ {\isasymdots}\ x\isactrlsub m\ {\isasymWHERE}\ a{\isacharcolon}\ {\isasymphi}\isactrlsub {\isadigit{1}}\ {\isasymdots}\ {\isasymphi}\isactrlsub n\ \ {\isasymlangle}proof{\isasymrangle}\ {\isasymequiv}{\isachardoublequote}} \\[1ex]
wenzelm@26842
   830
    \quad \mbox{\isa{\isacommand{have}}}~\isa{{\isachardoublequote}{\isasymAnd}thesis{\isachardot}\ {\isacharparenleft}{\isasymAnd}x\isactrlsub {\isadigit{1}}\ {\isasymdots}\ x\isactrlsub m{\isachardot}\ {\isasymphi}\isactrlsub {\isadigit{1}}\ {\isasymLongrightarrow}\ {\isasymdots}\ {\isasymphi}\isactrlsub n\ {\isasymLongrightarrow}\ thesis{\isacharparenright}\ {\isasymLongrightarrow}\ thesis{\isachardoublequote}} \\
wenzelm@26782
   831
    \quad \mbox{\isa{\isacommand{proof}}}~\isa{succeed} \\
wenzelm@26782
   832
    \qquad \mbox{\isa{\isacommand{fix}}}~\isa{thesis} \\
wenzelm@26842
   833
    \qquad \mbox{\isa{\isacommand{assume}}}~\isa{{\isachardoublequote}that\ {\isacharbrackleft}Pure{\isachardot}intro{\isacharquery}{\isacharbrackright}{\isacharcolon}\ {\isasymAnd}x\isactrlsub {\isadigit{1}}\ {\isasymdots}\ x\isactrlsub m{\isachardot}\ {\isasymphi}\isactrlsub {\isadigit{1}}\ {\isasymLongrightarrow}\ {\isasymdots}\ {\isasymphi}\isactrlsub n\ {\isasymLongrightarrow}\ thesis{\isachardoublequote}} \\
wenzelm@26782
   834
    \qquad \mbox{\isa{\isacommand{then}}}~\mbox{\isa{\isacommand{show}}}~\isa{thesis} \\
wenzelm@26782
   835
    \quad\qquad \mbox{\isa{\isacommand{apply}}}~\isa{{\isacharminus}} \\
wenzelm@26842
   836
    \quad\qquad \mbox{\isa{\isacommand{using}}}~\isa{{\isachardoublequote}b\isactrlsub {\isadigit{1}}\ {\isasymdots}\ b\isactrlsub k\ \ {\isasymlangle}proof{\isasymrangle}{\isachardoublequote}} \\
wenzelm@26782
   837
    \quad \mbox{\isa{\isacommand{qed}}} \\
wenzelm@26842
   838
    \quad \mbox{\isa{\isacommand{fix}}}~\isa{{\isachardoublequote}x\isactrlsub {\isadigit{1}}\ {\isasymdots}\ x\isactrlsub m{\isachardoublequote}}~\mbox{\isa{\isacommand{assume}}}\isa{{\isachardoublequote}\isactrlsup {\isacharasterisk}\ a{\isacharcolon}\ {\isasymphi}\isactrlsub {\isadigit{1}}\ {\isasymdots}\ {\isasymphi}\isactrlsub n{\isachardoublequote}} \\
wenzelm@26782
   839
  \end{matharray}
wenzelm@26782
   840
wenzelm@26782
   841
  Typically, the soundness proof is relatively straight-forward, often
wenzelm@26782
   842
  just by canonical automated tools such as ``\mbox{\isa{\isacommand{by}}}~\isa{simp}'' or ``\mbox{\isa{\isacommand{by}}}~\isa{blast}''.  Accordingly, the
wenzelm@26782
   843
  ``\isa{that}'' reduction above is declared as simplification and
wenzelm@26782
   844
  introduction rule.
wenzelm@26782
   845
wenzelm@26782
   846
  In a sense, \mbox{\isa{\isacommand{obtain}}} represents at the level of Isar
wenzelm@26782
   847
  proofs what would be meta-logical existential quantifiers and
wenzelm@26782
   848
  conjunctions.  This concept has a broad range of useful
wenzelm@26782
   849
  applications, ranging from plain elimination (or introduction) of
wenzelm@26782
   850
  object-level existential and conjunctions, to elimination over
wenzelm@26782
   851
  results of symbolic evaluation of recursive definitions, for
wenzelm@26782
   852
  example.  Also note that \mbox{\isa{\isacommand{obtain}}} without parameters acts
wenzelm@26782
   853
  much like \mbox{\isa{\isacommand{have}}}, where the result is treated as a
wenzelm@26782
   854
  genuine assumption.
wenzelm@26782
   855
wenzelm@26782
   856
  An alternative name to be used instead of ``\isa{that}'' above may
wenzelm@26782
   857
  be given in parentheses.
wenzelm@26782
   858
wenzelm@26782
   859
  \medskip The improper variant \mbox{\isa{\isacommand{guess}}} is similar to
wenzelm@26782
   860
  \mbox{\isa{\isacommand{obtain}}}, but derives the obtained statement from the
wenzelm@26782
   861
  course of reasoning!  The proof starts with a fixed goal \isa{thesis}.  The subsequent proof may refine this to anything of the
wenzelm@26842
   862
  form like \isa{{\isachardoublequote}{\isasymAnd}x\isactrlsub {\isadigit{1}}\ {\isasymdots}\ x\isactrlsub m{\isachardot}\ {\isasymphi}\isactrlsub {\isadigit{1}}\ {\isasymLongrightarrow}\ {\isasymdots}\ {\isasymphi}\isactrlsub n\ {\isasymLongrightarrow}\ thesis{\isachardoublequote}}, but must not introduce new subgoals.  The
wenzelm@26782
   863
  final goal state is then used as reduction rule for the obtain
wenzelm@26842
   864
  scheme described above.  Obtained parameters \isa{{\isachardoublequote}x\isactrlsub {\isadigit{1}}{\isacharcomma}\ {\isasymdots}{\isacharcomma}\ x\isactrlsub m{\isachardoublequote}} are marked as internal by default, which prevents the
wenzelm@26782
   865
  proof context from being polluted by ad-hoc variables.  The variable
wenzelm@26782
   866
  names and type constraints given as arguments for \mbox{\isa{\isacommand{guess}}}
wenzelm@26782
   867
  specify a prefix of obtained parameters explicitly in the text.
wenzelm@26782
   868
wenzelm@26782
   869
  It is important to note that the facts introduced by \mbox{\isa{\isacommand{obtain}}} and \mbox{\isa{\isacommand{guess}}} may not be polymorphic: any
wenzelm@26782
   870
  type-variables occurring here are fixed in the present context!%
wenzelm@26782
   871
\end{isamarkuptext}%
wenzelm@26782
   872
\isamarkuptrue%
wenzelm@26782
   873
%
wenzelm@26782
   874
\isamarkupsubsection{Calculational reasoning \label{sec:calculation}%
wenzelm@26782
   875
}
wenzelm@26782
   876
\isamarkuptrue%
wenzelm@26782
   877
%
wenzelm@26782
   878
\begin{isamarkuptext}%
wenzelm@26782
   879
\begin{matharray}{rcl}
wenzelm@26782
   880
    \indexdef{}{command}{also}\mbox{\isa{\isacommand{also}}} & : & \isartrans{proof(state)}{proof(state)} \\
wenzelm@26782
   881
    \indexdef{}{command}{finally}\mbox{\isa{\isacommand{finally}}} & : & \isartrans{proof(state)}{proof(chain)} \\
wenzelm@26782
   882
    \indexdef{}{command}{moreover}\mbox{\isa{\isacommand{moreover}}} & : & \isartrans{proof(state)}{proof(state)} \\
wenzelm@26782
   883
    \indexdef{}{command}{ultimately}\mbox{\isa{\isacommand{ultimately}}} & : & \isartrans{proof(state)}{proof(chain)} \\
wenzelm@26854
   884
    \indexdef{}{command}{print\_trans\_rules}\mbox{\isa{\isacommand{print{\isacharunderscore}trans{\isacharunderscore}rules}}}\isa{{\isachardoublequote}\isactrlsup {\isacharasterisk}{\isachardoublequote}} & : & \isarkeep{theory~|~proof} \\
wenzelm@26782
   885
    \mbox{\isa{trans}} & : & \isaratt \\
wenzelm@26782
   886
    \mbox{\isa{sym}} & : & \isaratt \\
wenzelm@26782
   887
    \mbox{\isa{symmetric}} & : & \isaratt \\
wenzelm@26782
   888
  \end{matharray}
wenzelm@26782
   889
wenzelm@26782
   890
  Calculational proof is forward reasoning with implicit application
wenzelm@26842
   891
  of transitivity rules (such those of \isa{{\isachardoublequote}{\isacharequal}{\isachardoublequote}}, \isa{{\isachardoublequote}{\isasymle}{\isachardoublequote}},
wenzelm@26842
   892
  \isa{{\isachardoublequote}{\isacharless}{\isachardoublequote}}).  Isabelle/Isar maintains an auxiliary fact register
wenzelm@26782
   893
  \indexref{}{fact}{calculation}\mbox{\isa{calculation}} for accumulating results obtained by
wenzelm@26782
   894
  transitivity composed with the current result.  Command \mbox{\isa{\isacommand{also}}} updates \mbox{\isa{calculation}} involving \mbox{\isa{this}}, while
wenzelm@26782
   895
  \mbox{\isa{\isacommand{finally}}} exhibits the final \mbox{\isa{calculation}} by
wenzelm@26782
   896
  forward chaining towards the next goal statement.  Both commands
wenzelm@26782
   897
  require valid current facts, i.e.\ may occur only after commands
wenzelm@26782
   898
  that produce theorems such as \mbox{\isa{\isacommand{assume}}}, \mbox{\isa{\isacommand{note}}}, or some finished proof of \mbox{\isa{\isacommand{have}}}, \mbox{\isa{\isacommand{show}}} etc.  The \mbox{\isa{\isacommand{moreover}}} and \mbox{\isa{\isacommand{ultimately}}}
wenzelm@26782
   899
  commands are similar to \mbox{\isa{\isacommand{also}}} and \mbox{\isa{\isacommand{finally}}},
wenzelm@26782
   900
  but only collect further results in \mbox{\isa{calculation}} without
wenzelm@26782
   901
  applying any rules yet.
wenzelm@26782
   902
wenzelm@26842
   903
  Also note that the implicit term abbreviation ``\isa{{\isachardoublequote}{\isasymdots}{\isachardoublequote}}'' has
wenzelm@26782
   904
  its canonical application with calculational proofs.  It refers to
wenzelm@26782
   905
  the argument of the preceding statement. (The argument of a curried
wenzelm@26782
   906
  infix expression happens to be its right-hand side.)
wenzelm@26782
   907
wenzelm@26782
   908
  Isabelle/Isar calculations are implicitly subject to block structure
wenzelm@26782
   909
  in the sense that new threads of calculational reasoning are
wenzelm@26782
   910
  commenced for any new block (as opened by a local goal, for
wenzelm@26782
   911
  example).  This means that, apart from being able to nest
wenzelm@26782
   912
  calculations, there is no separate \emph{begin-calculation} command
wenzelm@26782
   913
  required.
wenzelm@26782
   914
wenzelm@26782
   915
  \medskip The Isar calculation proof commands may be defined as
wenzelm@26782
   916
  follows:\footnote{We suppress internal bookkeeping such as proper
wenzelm@26782
   917
  handling of block-structure.}
wenzelm@26782
   918
wenzelm@26782
   919
  \begin{matharray}{rcl}
wenzelm@26842
   920
    \mbox{\isa{\isacommand{also}}}\isa{{\isachardoublequote}\isactrlsub {\isadigit{0}}{\isachardoublequote}} & \equiv & \mbox{\isa{\isacommand{note}}}~\isa{{\isachardoublequote}calculation\ {\isacharequal}\ this{\isachardoublequote}} \\
wenzelm@26842
   921
    \mbox{\isa{\isacommand{also}}}\isa{{\isachardoublequote}\isactrlsub n\isactrlsub {\isacharplus}\isactrlsub {\isadigit{1}}{\isachardoublequote}} & \equiv & \mbox{\isa{\isacommand{note}}}~\isa{{\isachardoublequote}calculation\ {\isacharequal}\ trans\ {\isacharbrackleft}OF\ calculation\ this{\isacharbrackright}{\isachardoublequote}} \\[0.5ex]
wenzelm@26782
   922
    \mbox{\isa{\isacommand{finally}}} & \equiv & \mbox{\isa{\isacommand{also}}}~\mbox{\isa{\isacommand{from}}}~\isa{calculation} \\[0.5ex]
wenzelm@26842
   923
    \mbox{\isa{\isacommand{moreover}}} & \equiv & \mbox{\isa{\isacommand{note}}}~\isa{{\isachardoublequote}calculation\ {\isacharequal}\ calculation\ this{\isachardoublequote}} \\
wenzelm@26782
   924
    \mbox{\isa{\isacommand{ultimately}}} & \equiv & \mbox{\isa{\isacommand{moreover}}}~\mbox{\isa{\isacommand{from}}}~\isa{calculation} \\
wenzelm@26782
   925
  \end{matharray}
wenzelm@26782
   926
wenzelm@26782
   927
  \begin{rail}
wenzelm@26782
   928
    ('also' | 'finally') ('(' thmrefs ')')?
wenzelm@26782
   929
    ;
wenzelm@26782
   930
    'trans' (() | 'add' | 'del')
wenzelm@26782
   931
    ;
wenzelm@26782
   932
  \end{rail}
wenzelm@26782
   933
wenzelm@26782
   934
  \begin{descr}
wenzelm@26782
   935
wenzelm@26842
   936
  \item [\mbox{\isa{\isacommand{also}}}~\isa{{\isachardoublequote}{\isacharparenleft}a\isactrlsub {\isadigit{1}}\ {\isasymdots}\ a\isactrlsub n{\isacharparenright}{\isachardoublequote}}]
wenzelm@26782
   937
  maintains the auxiliary \mbox{\isa{calculation}} register as follows.
wenzelm@26782
   938
  The first occurrence of \mbox{\isa{\isacommand{also}}} in some calculational
wenzelm@26782
   939
  thread initializes \mbox{\isa{calculation}} by \mbox{\isa{this}}. Any
wenzelm@26782
   940
  subsequent \mbox{\isa{\isacommand{also}}} on the same level of block-structure
wenzelm@26782
   941
  updates \mbox{\isa{calculation}} by some transitivity rule applied to
wenzelm@26782
   942
  \mbox{\isa{calculation}} and \mbox{\isa{this}} (in that order).  Transitivity
wenzelm@26782
   943
  rules are picked from the current context, unless alternative rules
wenzelm@26782
   944
  are given as explicit arguments.
wenzelm@26782
   945
wenzelm@26842
   946
  \item [\mbox{\isa{\isacommand{finally}}}~\isa{{\isachardoublequote}{\isacharparenleft}a\isactrlsub {\isadigit{1}}\ {\isasymdots}\ a\isactrlsub n{\isacharparenright}{\isachardoublequote}}]
wenzelm@26782
   947
  maintaining \mbox{\isa{calculation}} in the same way as \mbox{\isa{\isacommand{also}}}, and concludes the current calculational thread.  The final
wenzelm@26782
   948
  result is exhibited as fact for forward chaining towards the next
wenzelm@26782
   949
  goal. Basically, \mbox{\isa{\isacommand{finally}}} just abbreviates \mbox{\isa{\isacommand{also}}}~\mbox{\isa{\isacommand{from}}}~\mbox{\isa{calculation}}.  Typical idioms for
wenzelm@26782
   950
  concluding calculational proofs are ``\mbox{\isa{\isacommand{finally}}}~\mbox{\isa{\isacommand{show}}}~\isa{{\isacharquery}thesis}~\mbox{\isa{\isacommand{{\isachardot}}}}'' and ``\mbox{\isa{\isacommand{finally}}}~\mbox{\isa{\isacommand{have}}}~\isa{{\isasymphi}}~\mbox{\isa{\isacommand{{\isachardot}}}}''.
wenzelm@26782
   951
wenzelm@26782
   952
  \item [\mbox{\isa{\isacommand{moreover}}} and \mbox{\isa{\isacommand{ultimately}}}] are
wenzelm@26782
   953
  analogous to \mbox{\isa{\isacommand{also}}} and \mbox{\isa{\isacommand{finally}}}, but collect
wenzelm@26782
   954
  results only, without applying rules.
wenzelm@26782
   955
wenzelm@26782
   956
  \item [\mbox{\isa{\isacommand{print{\isacharunderscore}trans{\isacharunderscore}rules}}}] prints the list of
wenzelm@26782
   957
  transitivity rules (for calculational commands \mbox{\isa{\isacommand{also}}} and
wenzelm@26782
   958
  \mbox{\isa{\isacommand{finally}}}) and symmetry rules (for the \mbox{\isa{symmetric}} operation and single step elimination patters) of the
wenzelm@26782
   959
  current context.
wenzelm@26782
   960
wenzelm@26782
   961
  \item [\mbox{\isa{trans}}] declares theorems as transitivity rules.
wenzelm@26782
   962
wenzelm@26782
   963
  \item [\mbox{\isa{sym}}] declares symmetry rules, as well as
wenzelm@26782
   964
  \mbox{\isa{Pure{\isachardot}elim{\isacharquery}}} rules.
wenzelm@26782
   965
wenzelm@26782
   966
  \item [\mbox{\isa{symmetric}}] resolves a theorem with some rule
wenzelm@26782
   967
  declared as \mbox{\isa{sym}} in the current context.  For example,
wenzelm@26842
   968
  ``\mbox{\isa{\isacommand{assume}}}~\isa{{\isachardoublequote}{\isacharbrackleft}symmetric{\isacharbrackright}{\isacharcolon}\ x\ {\isacharequal}\ y{\isachardoublequote}}'' produces a
wenzelm@26782
   969
  swapped fact derived from that assumption.
wenzelm@26782
   970
wenzelm@26782
   971
  In structured proof texts it is often more appropriate to use an
wenzelm@26842
   972
  explicit single-step elimination proof, such as ``\mbox{\isa{\isacommand{assume}}}~\isa{{\isachardoublequote}x\ {\isacharequal}\ y{\isachardoublequote}}~\mbox{\isa{\isacommand{then}}}~\mbox{\isa{\isacommand{have}}}~\isa{{\isachardoublequote}y\ {\isacharequal}\ x{\isachardoublequote}}~\mbox{\isa{\isacommand{{\isachardot}{\isachardot}}}}''.
wenzelm@26782
   973
wenzelm@26782
   974
  \end{descr}%
wenzelm@26782
   975
\end{isamarkuptext}%
wenzelm@26782
   976
\isamarkuptrue%
wenzelm@26782
   977
%
wenzelm@26782
   978
\isamarkupsection{Proof tools%
wenzelm@26782
   979
}
wenzelm@26782
   980
\isamarkuptrue%
wenzelm@26782
   981
%
wenzelm@26782
   982
\isamarkupsubsection{Miscellaneous methods and attributes \label{sec:misc-meth-att}%
wenzelm@26782
   983
}
wenzelm@26782
   984
\isamarkuptrue%
wenzelm@26782
   985
%
wenzelm@26782
   986
\begin{isamarkuptext}%
wenzelm@26782
   987
\begin{matharray}{rcl}
wenzelm@26782
   988
    \indexdef{}{method}{unfold}\mbox{\isa{unfold}} & : & \isarmeth \\
wenzelm@26782
   989
    \indexdef{}{method}{fold}\mbox{\isa{fold}} & : & \isarmeth \\
wenzelm@26782
   990
    \indexdef{}{method}{insert}\mbox{\isa{insert}} & : & \isarmeth \\[0.5ex]
wenzelm@26842
   991
    \indexdef{}{method}{erule}\mbox{\isa{erule}}\isa{{\isachardoublequote}\isactrlsup {\isacharasterisk}{\isachardoublequote}} & : & \isarmeth \\
wenzelm@26842
   992
    \indexdef{}{method}{drule}\mbox{\isa{drule}}\isa{{\isachardoublequote}\isactrlsup {\isacharasterisk}{\isachardoublequote}} & : & \isarmeth \\
wenzelm@26842
   993
    \indexdef{}{method}{frule}\mbox{\isa{frule}}\isa{{\isachardoublequote}\isactrlsup {\isacharasterisk}{\isachardoublequote}} & : & \isarmeth \\
wenzelm@26782
   994
    \indexdef{}{method}{succeed}\mbox{\isa{succeed}} & : & \isarmeth \\
wenzelm@26782
   995
    \indexdef{}{method}{fail}\mbox{\isa{fail}} & : & \isarmeth \\
wenzelm@26782
   996
  \end{matharray}
wenzelm@26782
   997
wenzelm@26782
   998
  \begin{rail}
wenzelm@26782
   999
    ('fold' | 'unfold' | 'insert') thmrefs
wenzelm@26782
  1000
    ;
wenzelm@26782
  1001
    ('erule' | 'drule' | 'frule') ('('nat')')? thmrefs
wenzelm@26782
  1002
    ;
wenzelm@26782
  1003
  \end{rail}
wenzelm@26782
  1004
wenzelm@26782
  1005
  \begin{descr}
wenzelm@26782
  1006
  
wenzelm@26842
  1007
  \item [\mbox{\isa{unfold}}~\isa{{\isachardoublequote}a\isactrlsub {\isadigit{1}}\ {\isasymdots}\ a\isactrlsub n{\isachardoublequote}} and \mbox{\isa{fold}}~\isa{{\isachardoublequote}a\isactrlsub {\isadigit{1}}\ {\isasymdots}\ a\isactrlsub n{\isachardoublequote}}] expand (or fold back) the
wenzelm@26782
  1008
  given definitions throughout all goals; any chained facts provided
wenzelm@26782
  1009
  are inserted into the goal and subject to rewriting as well.
wenzelm@26782
  1010
wenzelm@26842
  1011
  \item [\mbox{\isa{insert}}~\isa{{\isachardoublequote}a\isactrlsub {\isadigit{1}}\ {\isasymdots}\ a\isactrlsub n{\isachardoublequote}}] inserts
wenzelm@26782
  1012
  theorems as facts into all goals of the proof state.  Note that
wenzelm@26782
  1013
  current facts indicated for forward chaining are ignored.
wenzelm@26782
  1014
wenzelm@26842
  1015
  \item [\mbox{\isa{erule}}~\isa{{\isachardoublequote}a\isactrlsub {\isadigit{1}}\ {\isasymdots}\ a\isactrlsub n{\isachardoublequote}}, \mbox{\isa{drule}}~\isa{{\isachardoublequote}a\isactrlsub {\isadigit{1}}\ {\isasymdots}\ a\isactrlsub n{\isachardoublequote}}, and \mbox{\isa{frule}}~\isa{{\isachardoublequote}a\isactrlsub {\isadigit{1}}\ {\isasymdots}\ a\isactrlsub n{\isachardoublequote}}] are similar to the basic \mbox{\isa{rule}}
wenzelm@26782
  1016
  method (see \secref{sec:pure-meth-att}), but apply rules by
wenzelm@26782
  1017
  elim-resolution, destruct-resolution, and forward-resolution,
wenzelm@26782
  1018
  respectively \cite{isabelle-ref}.  The optional natural number
wenzelm@26782
  1019
  argument (default 0) specifies additional assumption steps to be
wenzelm@26782
  1020
  performed here.
wenzelm@26782
  1021
wenzelm@26782
  1022
  Note that these methods are improper ones, mainly serving for
wenzelm@26782
  1023
  experimentation and tactic script emulation.  Different modes of
wenzelm@26782
  1024
  basic rule application are usually expressed in Isar at the proof
wenzelm@26782
  1025
  language level, rather than via implicit proof state manipulations.
wenzelm@26782
  1026
  For example, a proper single-step elimination would be done using
wenzelm@26782
  1027
  the plain \mbox{\isa{rule}} method, with forward chaining of current
wenzelm@26782
  1028
  facts.
wenzelm@26782
  1029
wenzelm@26782
  1030
  \item [\mbox{\isa{succeed}}] yields a single (unchanged) result; it is
wenzelm@26842
  1031
  the identity of the ``\isa{{\isachardoublequote}{\isacharcomma}{\isachardoublequote}}'' method combinator (cf.\
wenzelm@26782
  1032
  \secref{sec:syn-meth}).
wenzelm@26782
  1033
wenzelm@26782
  1034
  \item [\mbox{\isa{fail}}] yields an empty result sequence; it is the
wenzelm@26842
  1035
  identity of the ``\isa{{\isachardoublequote}{\isacharbar}{\isachardoublequote}}'' method combinator (cf.\
wenzelm@26782
  1036
  \secref{sec:syn-meth}).
wenzelm@26782
  1037
wenzelm@26782
  1038
  \end{descr}
wenzelm@26782
  1039
wenzelm@26782
  1040
  \begin{matharray}{rcl}
wenzelm@26782
  1041
    \indexdef{}{attribute}{tagged}\mbox{\isa{tagged}} & : & \isaratt \\
wenzelm@26782
  1042
    \indexdef{}{attribute}{untagged}\mbox{\isa{untagged}} & : & \isaratt \\[0.5ex]
wenzelm@26782
  1043
    \indexdef{}{attribute}{THEN}\mbox{\isa{THEN}} & : & \isaratt \\
wenzelm@26782
  1044
    \indexdef{}{attribute}{COMP}\mbox{\isa{COMP}} & : & \isaratt \\[0.5ex]
wenzelm@26782
  1045
    \indexdef{}{attribute}{unfolded}\mbox{\isa{unfolded}} & : & \isaratt \\
wenzelm@26782
  1046
    \indexdef{}{attribute}{folded}\mbox{\isa{folded}} & : & \isaratt \\[0.5ex]
wenzelm@26782
  1047
    \indexdef{}{attribute}{rotated}\mbox{\isa{rotated}} & : & \isaratt \\
wenzelm@26854
  1048
    \indexdef{Pure}{attribute}{elim\_format}\mbox{\isa{elim{\isacharunderscore}format}} & : & \isaratt \\
wenzelm@26842
  1049
    \indexdef{}{attribute}{standard}\mbox{\isa{standard}}\isa{{\isachardoublequote}\isactrlsup {\isacharasterisk}{\isachardoublequote}} & : & \isaratt \\
wenzelm@26854
  1050
    \indexdef{}{attribute}{no\_vars}\mbox{\isa{no{\isacharunderscore}vars}}\isa{{\isachardoublequote}\isactrlsup {\isacharasterisk}{\isachardoublequote}} & : & \isaratt \\
wenzelm@26782
  1051
  \end{matharray}
wenzelm@26782
  1052
wenzelm@26782
  1053
  \begin{rail}
wenzelm@26782
  1054
    'tagged' nameref
wenzelm@26782
  1055
    ;
wenzelm@26782
  1056
    'untagged' name
wenzelm@26782
  1057
    ;
wenzelm@26782
  1058
    ('THEN' | 'COMP') ('[' nat ']')? thmref
wenzelm@26782
  1059
    ;
wenzelm@26782
  1060
    ('unfolded' | 'folded') thmrefs
wenzelm@26782
  1061
    ;
wenzelm@26782
  1062
    'rotated' ( int )?
wenzelm@26782
  1063
  \end{rail}
wenzelm@26782
  1064
wenzelm@26782
  1065
  \begin{descr}
wenzelm@26782
  1066
wenzelm@26842
  1067
  \item [\mbox{\isa{tagged}}~\isa{{\isachardoublequote}name\ arg{\isachardoublequote}} and \mbox{\isa{untagged}}~\isa{name}] add and remove \emph{tags} of some theorem.
wenzelm@26782
  1068
  Tags may be any list of string pairs that serve as formal comment.
wenzelm@26782
  1069
  The first string is considered the tag name, the second its
wenzelm@26782
  1070
  argument.  Note that \mbox{\isa{untagged}} removes any tags of the
wenzelm@26782
  1071
  same name.
wenzelm@26782
  1072
wenzelm@26782
  1073
  \item [\mbox{\isa{THEN}}~\isa{a} and \mbox{\isa{COMP}}~\isa{a}]
wenzelm@26782
  1074
  compose rules by resolution.  \mbox{\isa{THEN}} resolves with the
wenzelm@26782
  1075
  first premise of \isa{a} (an alternative position may be also
wenzelm@26782
  1076
  specified); the \mbox{\isa{COMP}} version skips the automatic
wenzelm@26842
  1077
  lifting process that is normally intended (cf.\ \verb|"op RS"| and
wenzelm@26842
  1078
  \verb|"op COMP"| in \cite[\S5]{isabelle-ref}).
wenzelm@26782
  1079
  
wenzelm@26842
  1080
  \item [\mbox{\isa{unfolded}}~\isa{{\isachardoublequote}a\isactrlsub {\isadigit{1}}\ {\isasymdots}\ a\isactrlsub n{\isachardoublequote}} and
wenzelm@26842
  1081
  \mbox{\isa{folded}}~\isa{{\isachardoublequote}a\isactrlsub {\isadigit{1}}\ {\isasymdots}\ a\isactrlsub n{\isachardoublequote}}] expand and fold
wenzelm@26782
  1082
  back again the given definitions throughout a rule.
wenzelm@26782
  1083
wenzelm@26782
  1084
  \item [\mbox{\isa{rotated}}~\isa{n}] rotate the premises of a
wenzelm@26782
  1085
  theorem by \isa{n} (default 1).
wenzelm@26782
  1086
wenzelm@26782
  1087
  \item [\mbox{\isa{Pure{\isachardot}elim{\isacharunderscore}format}}] turns a destruction rule into
wenzelm@26782
  1088
  elimination rule format, by resolving with the rule \isa{{\isachardoublequote}PROP\ A\ {\isasymLongrightarrow}\ {\isacharparenleft}PROP\ A\ {\isasymLongrightarrow}\ PROP\ B{\isacharparenright}\ {\isasymLongrightarrow}\ PROP\ B{\isachardoublequote}}.
wenzelm@26782
  1089
  
wenzelm@26782
  1090
  Note that the Classical Reasoner (\secref{sec:classical}) provides
wenzelm@26782
  1091
  its own version of this operation.
wenzelm@26782
  1092
wenzelm@26782
  1093
  \item [\mbox{\isa{standard}}] puts a theorem into the standard form
wenzelm@26782
  1094
  of object-rules at the outermost theory level.  Note that this
wenzelm@26782
  1095
  operation violates the local proof context (including active
wenzelm@26782
  1096
  locales).
wenzelm@26782
  1097
wenzelm@26782
  1098
  \item [\mbox{\isa{no{\isacharunderscore}vars}}] replaces schematic variables by free
wenzelm@26782
  1099
  ones; this is mainly for tuning output of pretty printed theorems.
wenzelm@26782
  1100
wenzelm@26782
  1101
  \end{descr}%
wenzelm@26782
  1102
\end{isamarkuptext}%
wenzelm@26782
  1103
\isamarkuptrue%
wenzelm@26782
  1104
%
wenzelm@26782
  1105
\isamarkupsubsection{Further tactic emulations \label{sec:tactics}%
wenzelm@26782
  1106
}
wenzelm@26782
  1107
\isamarkuptrue%
wenzelm@26782
  1108
%
wenzelm@26782
  1109
\begin{isamarkuptext}%
wenzelm@26782
  1110
The following improper proof methods emulate traditional tactics.
wenzelm@26782
  1111
  These admit direct access to the goal state, which is normally
wenzelm@26782
  1112
  considered harmful!  In particular, this may involve both numbered
wenzelm@26782
  1113
  goal addressing (default 1), and dynamic instantiation within the
wenzelm@26782
  1114
  scope of some subgoal.
wenzelm@26782
  1115
wenzelm@26782
  1116
  \begin{warn}
wenzelm@26782
  1117
    Dynamic instantiations refer to universally quantified parameters
wenzelm@26782
  1118
    of a subgoal (the dynamic context) rather than fixed variables and
wenzelm@26782
  1119
    term abbreviations of a (static) Isar context.
wenzelm@26782
  1120
  \end{warn}
wenzelm@26782
  1121
wenzelm@26782
  1122
  Tactic emulation methods, unlike their ML counterparts, admit
wenzelm@26782
  1123
  simultaneous instantiation from both dynamic and static contexts.
wenzelm@26782
  1124
  If names occur in both contexts goal parameters hide locally fixed
wenzelm@26782
  1125
  variables.  Likewise, schematic variables refer to term
wenzelm@26782
  1126
  abbreviations, if present in the static context.  Otherwise the
wenzelm@26782
  1127
  schematic variable is interpreted as a schematic variable and left
wenzelm@26782
  1128
  to be solved by unification with certain parts of the subgoal.
wenzelm@26782
  1129
wenzelm@26782
  1130
  Note that the tactic emulation proof methods in Isabelle/Isar are
wenzelm@26782
  1131
  consistently named \isa{foo{\isacharunderscore}tac}.  Note also that variable names
wenzelm@26782
  1132
  occurring on left hand sides of instantiations must be preceded by a
wenzelm@26782
  1133
  question mark if they coincide with a keyword or contain dots.  This
wenzelm@26782
  1134
  is consistent with the attribute \mbox{\isa{where}} (see
wenzelm@26782
  1135
  \secref{sec:pure-meth-att}).
wenzelm@26782
  1136
wenzelm@26782
  1137
  \begin{matharray}{rcl}
wenzelm@26854
  1138
    \indexdef{}{method}{rule\_tac}\mbox{\isa{rule{\isacharunderscore}tac}}\isa{{\isachardoublequote}\isactrlsup {\isacharasterisk}{\isachardoublequote}} & : & \isarmeth \\
wenzelm@26854
  1139
    \indexdef{}{method}{erule\_tac}\mbox{\isa{erule{\isacharunderscore}tac}}\isa{{\isachardoublequote}\isactrlsup {\isacharasterisk}{\isachardoublequote}} & : & \isarmeth \\
wenzelm@26854
  1140
    \indexdef{}{method}{drule\_tac}\mbox{\isa{drule{\isacharunderscore}tac}}\isa{{\isachardoublequote}\isactrlsup {\isacharasterisk}{\isachardoublequote}} & : & \isarmeth \\
wenzelm@26854
  1141
    \indexdef{}{method}{frule\_tac}\mbox{\isa{frule{\isacharunderscore}tac}}\isa{{\isachardoublequote}\isactrlsup {\isacharasterisk}{\isachardoublequote}} & : & \isarmeth \\
wenzelm@26854
  1142
    \indexdef{}{method}{cut\_tac}\mbox{\isa{cut{\isacharunderscore}tac}}\isa{{\isachardoublequote}\isactrlsup {\isacharasterisk}{\isachardoublequote}} & : & \isarmeth \\
wenzelm@26854
  1143
    \indexdef{}{method}{thin\_tac}\mbox{\isa{thin{\isacharunderscore}tac}}\isa{{\isachardoublequote}\isactrlsup {\isacharasterisk}{\isachardoublequote}} & : & \isarmeth \\
wenzelm@26854
  1144
    \indexdef{}{method}{subgoal\_tac}\mbox{\isa{subgoal{\isacharunderscore}tac}}\isa{{\isachardoublequote}\isactrlsup {\isacharasterisk}{\isachardoublequote}} & : & \isarmeth \\
wenzelm@26854
  1145
    \indexdef{}{method}{rename\_tac}\mbox{\isa{rename{\isacharunderscore}tac}}\isa{{\isachardoublequote}\isactrlsup {\isacharasterisk}{\isachardoublequote}} & : & \isarmeth \\
wenzelm@26854
  1146
    \indexdef{}{method}{rotate\_tac}\mbox{\isa{rotate{\isacharunderscore}tac}}\isa{{\isachardoublequote}\isactrlsup {\isacharasterisk}{\isachardoublequote}} & : & \isarmeth \\
wenzelm@26842
  1147
    \indexdef{}{method}{tactic}\mbox{\isa{tactic}}\isa{{\isachardoublequote}\isactrlsup {\isacharasterisk}{\isachardoublequote}} & : & \isarmeth \\
wenzelm@26782
  1148
  \end{matharray}
wenzelm@26782
  1149
wenzelm@26782
  1150
  \begin{rail}
wenzelm@26782
  1151
    ( 'rule\_tac' | 'erule\_tac' | 'drule\_tac' | 'frule\_tac' | 'cut\_tac' | 'thin\_tac' ) goalspec?
wenzelm@26782
  1152
    ( insts thmref | thmrefs )
wenzelm@26782
  1153
    ;
wenzelm@26782
  1154
    'subgoal\_tac' goalspec? (prop +)
wenzelm@26782
  1155
    ;
wenzelm@26782
  1156
    'rename\_tac' goalspec? (name +)
wenzelm@26782
  1157
    ;
wenzelm@26782
  1158
    'rotate\_tac' goalspec? int?
wenzelm@26782
  1159
    ;
wenzelm@26782
  1160
    'tactic' text
wenzelm@26782
  1161
    ;
wenzelm@26782
  1162
wenzelm@26782
  1163
    insts: ((name '=' term) + 'and') 'in'
wenzelm@26782
  1164
    ;
wenzelm@26782
  1165
  \end{rail}
wenzelm@26782
  1166
wenzelm@26782
  1167
\begin{descr}
wenzelm@26782
  1168
wenzelm@26782
  1169
  \item [\mbox{\isa{rule{\isacharunderscore}tac}} etc.] do resolution of rules with explicit
wenzelm@26782
  1170
  instantiation.  This works the same way as the ML tactics \verb|res_inst_tac| etc. (see \cite[\S3]{isabelle-ref}).
wenzelm@26782
  1171
wenzelm@26782
  1172
  Multiple rules may be only given if there is no instantiation; then
wenzelm@26782
  1173
  \mbox{\isa{rule{\isacharunderscore}tac}} is the same as \verb|resolve_tac| in ML (see
wenzelm@26782
  1174
  \cite[\S3]{isabelle-ref}).
wenzelm@26782
  1175
wenzelm@26782
  1176
  \item [\mbox{\isa{cut{\isacharunderscore}tac}}] inserts facts into the proof state as
wenzelm@26782
  1177
  assumption of a subgoal, see also \verb|cut_facts_tac| in
wenzelm@26782
  1178
  \cite[\S3]{isabelle-ref}.  Note that the scope of schematic
wenzelm@26782
  1179
  variables is spread over the main goal statement.  Instantiations
wenzelm@26782
  1180
  may be given as well, see also ML tactic \verb|cut_inst_tac| in
wenzelm@26782
  1181
  \cite[\S3]{isabelle-ref}.
wenzelm@26782
  1182
wenzelm@26782
  1183
  \item [\mbox{\isa{thin{\isacharunderscore}tac}}~\isa{{\isasymphi}}] deletes the specified
wenzelm@26782
  1184
  assumption from a subgoal; note that \isa{{\isasymphi}} may contain schematic
wenzelm@26782
  1185
  variables.  See also \verb|thin_tac| in \cite[\S3]{isabelle-ref}.
wenzelm@26782
  1186
wenzelm@26782
  1187
  \item [\mbox{\isa{subgoal{\isacharunderscore}tac}}~\isa{{\isasymphi}}] adds \isa{{\isasymphi}} as an
wenzelm@26782
  1188
  assumption to a subgoal.  See also \verb|subgoal_tac| and \verb|subgoals_tac| in \cite[\S3]{isabelle-ref}.
wenzelm@26782
  1189
wenzelm@26842
  1190
  \item [\mbox{\isa{rename{\isacharunderscore}tac}}~\isa{{\isachardoublequote}x\isactrlsub {\isadigit{1}}\ {\isasymdots}\ x\isactrlsub n{\isachardoublequote}}] renames
wenzelm@26842
  1191
  parameters of a goal according to the list \isa{{\isachardoublequote}x\isactrlsub {\isadigit{1}}{\isacharcomma}\ {\isasymdots}{\isacharcomma}\ x\isactrlsub n{\isachardoublequote}}, which refers to the \emph{suffix} of variables.
wenzelm@26782
  1192
wenzelm@26782
  1193
  \item [\mbox{\isa{rotate{\isacharunderscore}tac}}~\isa{n}] rotates the assumptions of a
wenzelm@26782
  1194
  goal by \isa{n} positions: from right to left if \isa{n} is
wenzelm@26782
  1195
  positive, and from left to right if \isa{n} is negative; the
wenzelm@26782
  1196
  default value is 1.  See also \verb|rotate_tac| in
wenzelm@26782
  1197
  \cite[\S3]{isabelle-ref}.
wenzelm@26782
  1198
wenzelm@26842
  1199
  \item [\mbox{\isa{tactic}}~\isa{{\isachardoublequote}text{\isachardoublequote}}] produces a proof method from
wenzelm@26782
  1200
  any ML text of type \verb|tactic|.  Apart from the usual ML
wenzelm@26782
  1201
  environment and the current implicit theory context, the ML code may
wenzelm@26782
  1202
  refer to the following locally bound values:
wenzelm@26782
  1203
wenzelm@26782
  1204
%FIXME check
wenzelm@26782
  1205
{\footnotesize\begin{verbatim}
wenzelm@26782
  1206
val ctxt  : Proof.context
wenzelm@26782
  1207
val facts : thm list
wenzelm@26782
  1208
val thm   : string -> thm
wenzelm@26782
  1209
val thms  : string -> thm list
wenzelm@26782
  1210
\end{verbatim}}
wenzelm@26782
  1211
wenzelm@26782
  1212
  Here \verb|ctxt| refers to the current proof context, \verb|facts| indicates any current facts for forward-chaining, and \verb|thm|~/~\verb|thms| retrieve named facts (including global theorems)
wenzelm@26782
  1213
  from the context.
wenzelm@26782
  1214
wenzelm@26782
  1215
  \end{descr}%
wenzelm@26782
  1216
\end{isamarkuptext}%
wenzelm@26782
  1217
\isamarkuptrue%
wenzelm@26782
  1218
%
wenzelm@26782
  1219
\isamarkupsubsection{The Simplifier \label{sec:simplifier}%
wenzelm@26782
  1220
}
wenzelm@26782
  1221
\isamarkuptrue%
wenzelm@26782
  1222
%
wenzelm@26782
  1223
\isamarkupsubsubsection{Simplification methods%
wenzelm@26782
  1224
}
wenzelm@26782
  1225
\isamarkuptrue%
wenzelm@26782
  1226
%
wenzelm@26782
  1227
\begin{isamarkuptext}%
wenzelm@26782
  1228
\begin{matharray}{rcl}
wenzelm@26782
  1229
    \indexdef{}{method}{simp}\mbox{\isa{simp}} & : & \isarmeth \\
wenzelm@26854
  1230
    \indexdef{}{method}{simp\_all}\mbox{\isa{simp{\isacharunderscore}all}} & : & \isarmeth \\
wenzelm@26782
  1231
  \end{matharray}
wenzelm@26782
  1232
wenzelm@26782
  1233
  \indexouternonterm{simpmod}
wenzelm@26782
  1234
  \begin{rail}
wenzelm@26782
  1235
    ('simp' | 'simp\_all') ('!' ?) opt? (simpmod *)
wenzelm@26782
  1236
    ;
wenzelm@26782
  1237
wenzelm@26782
  1238
    opt: '(' ('no\_asm' | 'no\_asm\_simp' | 'no\_asm\_use' | 'asm\_lr' | 'depth\_limit' ':' nat) ')'
wenzelm@26782
  1239
    ;
wenzelm@26782
  1240
    simpmod: ('add' | 'del' | 'only' | 'cong' (() | 'add' | 'del') |
wenzelm@26782
  1241
      'split' (() | 'add' | 'del')) ':' thmrefs
wenzelm@26782
  1242
    ;
wenzelm@26782
  1243
  \end{rail}
wenzelm@26782
  1244
wenzelm@26782
  1245
  \begin{descr}
wenzelm@26782
  1246
wenzelm@26782
  1247
  \item [\mbox{\isa{simp}}] invokes the Simplifier, after declaring
wenzelm@26782
  1248
  additional rules according to the arguments given.  Note that the
wenzelm@26782
  1249
  \railtterm{only} modifier first removes all other rewrite rules,
wenzelm@26782
  1250
  congruences, and looper tactics (including splits), and then behaves
wenzelm@26782
  1251
  like \railtterm{add}.
wenzelm@26782
  1252
wenzelm@26782
  1253
  \medskip The \railtterm{cong} modifiers add or delete Simplifier
wenzelm@26782
  1254
  congruence rules (see also \cite{isabelle-ref}), the default is to
wenzelm@26782
  1255
  add.
wenzelm@26782
  1256
wenzelm@26782
  1257
  \medskip The \railtterm{split} modifiers add or delete rules for the
wenzelm@26782
  1258
  Splitter (see also \cite{isabelle-ref}), the default is to add.
wenzelm@26782
  1259
  This works only if the Simplifier method has been properly setup to
wenzelm@26782
  1260
  include the Splitter (all major object logics such HOL, HOLCF, FOL,
wenzelm@26782
  1261
  ZF do this already).
wenzelm@26782
  1262
wenzelm@26782
  1263
  \item [\mbox{\isa{simp{\isacharunderscore}all}}] is similar to \mbox{\isa{simp}}, but acts on
wenzelm@26782
  1264
  all goals (backwards from the last to the first one).
wenzelm@26782
  1265
wenzelm@26782
  1266
  \end{descr}
wenzelm@26782
  1267
wenzelm@26782
  1268
  By default the Simplifier methods take local assumptions fully into
wenzelm@26782
  1269
  account, using equational assumptions in the subsequent
wenzelm@26782
  1270
  normalization process, or simplifying assumptions themselves (cf.\
wenzelm@26782
  1271
  \verb|asm_full_simp_tac| in \cite[\S10]{isabelle-ref}).  In
wenzelm@26782
  1272
  structured proofs this is usually quite well behaved in practice:
wenzelm@26782
  1273
  just the local premises of the actual goal are involved, additional
wenzelm@26782
  1274
  facts may be inserted via explicit forward-chaining (via \mbox{\isa{\isacommand{then}}}, \mbox{\isa{\isacommand{from}}}, \mbox{\isa{\isacommand{using}}} etc.).  The full
wenzelm@26842
  1275
  context of premises is only included if the ``\isa{{\isachardoublequote}{\isacharbang}{\isachardoublequote}}'' (bang)
wenzelm@26782
  1276
  argument is given, which should be used with some care, though.
wenzelm@26782
  1277
wenzelm@26782
  1278
  Additional Simplifier options may be specified to tune the behavior
wenzelm@26782
  1279
  further (mostly for unstructured scripts with many accidental local
wenzelm@26842
  1280
  facts): ``\isa{{\isachardoublequote}{\isacharparenleft}no{\isacharunderscore}asm{\isacharparenright}{\isachardoublequote}}'' means assumptions are ignored
wenzelm@26842
  1281
  completely (cf.\ \verb|simp_tac|), ``\isa{{\isachardoublequote}{\isacharparenleft}no{\isacharunderscore}asm{\isacharunderscore}simp{\isacharparenright}{\isachardoublequote}}'' means
wenzelm@26782
  1282
  assumptions are used in the simplification of the conclusion but are
wenzelm@26842
  1283
  not themselves simplified (cf.\ \verb|asm_simp_tac|), and ``\isa{{\isachardoublequote}{\isacharparenleft}no{\isacharunderscore}asm{\isacharunderscore}use{\isacharparenright}{\isachardoublequote}}'' means assumptions are simplified but are not used
wenzelm@26782
  1284
  in the simplification of each other or the conclusion (cf.\ \verb|full_simp_tac|).  For compatibility reasons, there is also an option
wenzelm@26842
  1285
  ``\isa{{\isachardoublequote}{\isacharparenleft}asm{\isacharunderscore}lr{\isacharparenright}{\isachardoublequote}}'', which means that an assumption is only used
wenzelm@26782
  1286
  for simplifying assumptions which are to the right of it (cf.\ \verb|asm_lr_simp_tac|).
wenzelm@26782
  1287
wenzelm@26842
  1288
  Giving an option ``\isa{{\isachardoublequote}{\isacharparenleft}depth{\isacharunderscore}limit{\isacharcolon}\ n{\isacharparenright}{\isachardoublequote}}'' limits the number of
wenzelm@26782
  1289
  recursive invocations of the simplifier during conditional
wenzelm@26782
  1290
  rewriting.
wenzelm@26782
  1291
wenzelm@26782
  1292
  \medskip The Splitter package is usually configured to work as part
wenzelm@26842
  1293
  of the Simplifier.  The effect of repeatedly applying \verb|split_tac| can be simulated by ``\isa{{\isachardoublequote}{\isacharparenleft}simp\ only{\isacharcolon}\ split{\isacharcolon}\ a\isactrlsub {\isadigit{1}}\ {\isasymdots}\ a\isactrlsub n{\isacharparenright}{\isachardoublequote}}''.  There is also a separate \isa{split}
wenzelm@26782
  1294
  method available for single-step case splitting.%
wenzelm@26782
  1295
\end{isamarkuptext}%
wenzelm@26782
  1296
\isamarkuptrue%
wenzelm@26782
  1297
%
wenzelm@26782
  1298
\isamarkupsubsubsection{Declaring rules%
wenzelm@26782
  1299
}
wenzelm@26782
  1300
\isamarkuptrue%
wenzelm@26782
  1301
%
wenzelm@26782
  1302
\begin{isamarkuptext}%
wenzelm@26782
  1303
\begin{matharray}{rcl}
wenzelm@26854
  1304
    \indexdef{}{command}{print\_simpset}\mbox{\isa{\isacommand{print{\isacharunderscore}simpset}}}\isa{{\isachardoublequote}\isactrlsup {\isacharasterisk}{\isachardoublequote}} & : & \isarkeep{theory~|~proof} \\
wenzelm@26782
  1305
    \indexdef{}{attribute}{simp}\mbox{\isa{simp}} & : & \isaratt \\
wenzelm@26782
  1306
    \indexdef{}{attribute}{cong}\mbox{\isa{cong}} & : & \isaratt \\
wenzelm@26782
  1307
    \indexdef{}{attribute}{split}\mbox{\isa{split}} & : & \isaratt \\
wenzelm@26782
  1308
  \end{matharray}
wenzelm@26782
  1309
wenzelm@26782
  1310
  \begin{rail}
wenzelm@26782
  1311
    ('simp' | 'cong' | 'split') (() | 'add' | 'del')
wenzelm@26782
  1312
    ;
wenzelm@26782
  1313
  \end{rail}
wenzelm@26782
  1314
wenzelm@26782
  1315
  \begin{descr}
wenzelm@26782
  1316
wenzelm@26782
  1317
  \item [\mbox{\isa{\isacommand{print{\isacharunderscore}simpset}}}] prints the collection of rules
wenzelm@26782
  1318
  declared to the Simplifier, which is also known as ``simpset''
wenzelm@26782
  1319
  internally \cite{isabelle-ref}.
wenzelm@26782
  1320
wenzelm@26782
  1321
  \item [\mbox{\isa{simp}}] declares simplification rules.
wenzelm@26782
  1322
wenzelm@26782
  1323
  \item [\mbox{\isa{cong}}] declares congruence rules.
wenzelm@26782
  1324
wenzelm@26782
  1325
  \item [\mbox{\isa{split}}] declares case split rules.
wenzelm@26782
  1326
wenzelm@26782
  1327
  \end{descr}%
wenzelm@26782
  1328
\end{isamarkuptext}%
wenzelm@26782
  1329
\isamarkuptrue%
wenzelm@26782
  1330
%
wenzelm@26782
  1331
\isamarkupsubsubsection{Simplification procedures%
wenzelm@26782
  1332
}
wenzelm@26782
  1333
\isamarkuptrue%
wenzelm@26782
  1334
%
wenzelm@26782
  1335
\begin{isamarkuptext}%
wenzelm@26782
  1336
\begin{matharray}{rcl}
wenzelm@26854
  1337
    \indexdef{}{command}{simproc\_setup}\mbox{\isa{\isacommand{simproc{\isacharunderscore}setup}}} & : & \isarkeep{local{\dsh}theory} \\
wenzelm@26782
  1338
    simproc & : & \isaratt \\
wenzelm@26782
  1339
  \end{matharray}
wenzelm@26782
  1340
wenzelm@26782
  1341
  \begin{rail}
wenzelm@26782
  1342
    'simproc\_setup' name '(' (term + '|') ')' '=' text \\ ('identifier' (nameref+))?
wenzelm@26782
  1343
    ;
wenzelm@26782
  1344
wenzelm@26782
  1345
    'simproc' (('add' ':')? | 'del' ':') (name+)
wenzelm@26782
  1346
    ;
wenzelm@26782
  1347
  \end{rail}
wenzelm@26782
  1348
wenzelm@26782
  1349
  \begin{descr}
wenzelm@26782
  1350
wenzelm@26782
  1351
  \item [\mbox{\isa{\isacommand{simproc{\isacharunderscore}setup}}}] defines a named simplification
wenzelm@26782
  1352
  procedure that is invoked by the Simplifier whenever any of the
wenzelm@26782
  1353
  given term patterns match the current redex.  The implementation,
wenzelm@26842
  1354
  which is provided as ML source text, needs to be of type \verb|"morphism -> simpset -> cterm -> thm option"|, where the \verb|cterm| represents the current redex \isa{r} and the result is
wenzelm@26842
  1355
  supposed to be some proven rewrite rule \isa{{\isachardoublequote}r\ {\isasymequiv}\ r{\isacharprime}{\isachardoublequote}} (or a
wenzelm@26782
  1356
  generalized version), or \verb|NONE| to indicate failure.  The
wenzelm@26782
  1357
  \verb|simpset| argument holds the full context of the current
wenzelm@26782
  1358
  Simplifier invocation, including the actual Isar proof context.  The
wenzelm@26782
  1359
  \verb|morphism| informs about the difference of the original
wenzelm@26782
  1360
  compilation context wrt.\ the one of the actual application later
wenzelm@26782
  1361
  on.  The optional \mbox{\isa{\isakeyword{identifier}}} specifies theorems that
wenzelm@26782
  1362
  represent the logical content of the abstract theory of this
wenzelm@26782
  1363
  simproc.
wenzelm@26782
  1364
wenzelm@26782
  1365
  Morphisms and identifiers are only relevant for simprocs that are
wenzelm@26782
  1366
  defined within a local target context, e.g.\ in a locale.
wenzelm@26782
  1367
wenzelm@26842
  1368
  \item [\isa{{\isachardoublequote}simproc\ add{\isacharcolon}\ name{\isachardoublequote}} and \isa{{\isachardoublequote}simproc\ del{\isacharcolon}\ name{\isachardoublequote}}]
wenzelm@26782
  1369
  add or delete named simprocs to the current Simplifier context.  The
wenzelm@26782
  1370
  default is to add a simproc.  Note that \mbox{\isa{\isacommand{simproc{\isacharunderscore}setup}}}
wenzelm@26782
  1371
  already adds the new simproc to the subsequent context.
wenzelm@26782
  1372
wenzelm@26782
  1373
  \end{descr}%
wenzelm@26782
  1374
\end{isamarkuptext}%
wenzelm@26782
  1375
\isamarkuptrue%
wenzelm@26782
  1376
%
wenzelm@26782
  1377
\isamarkupsubsubsection{Forward simplification%
wenzelm@26782
  1378
}
wenzelm@26782
  1379
\isamarkuptrue%
wenzelm@26782
  1380
%
wenzelm@26782
  1381
\begin{isamarkuptext}%
wenzelm@26782
  1382
\begin{matharray}{rcl}
wenzelm@26782
  1383
    \indexdef{}{attribute}{simplified}\mbox{\isa{simplified}} & : & \isaratt \\
wenzelm@26782
  1384
  \end{matharray}
wenzelm@26782
  1385
wenzelm@26782
  1386
  \begin{rail}
wenzelm@26782
  1387
    'simplified' opt? thmrefs?
wenzelm@26782
  1388
    ;
wenzelm@26782
  1389
wenzelm@26788
  1390
    opt: '(' ('no\_asm' | 'no\_asm\_simp' | 'no\_asm\_use') ')'
wenzelm@26782
  1391
    ;
wenzelm@26782
  1392
  \end{rail}
wenzelm@26782
  1393
wenzelm@26782
  1394
  \begin{descr}
wenzelm@26782
  1395
  
wenzelm@26842
  1396
  \item [\mbox{\isa{simplified}}~\isa{{\isachardoublequote}a\isactrlsub {\isadigit{1}}\ {\isasymdots}\ a\isactrlsub n{\isachardoublequote}}]
wenzelm@26782
  1397
  causes a theorem to be simplified, either by exactly the specified
wenzelm@26842
  1398
  rules \isa{{\isachardoublequote}a\isactrlsub {\isadigit{1}}{\isacharcomma}\ {\isasymdots}{\isacharcomma}\ a\isactrlsub n{\isachardoublequote}}, or the implicit Simplifier
wenzelm@26782
  1399
  context if no arguments are given.  The result is fully simplified
wenzelm@26782
  1400
  by default, including assumptions and conclusion; the options \isa{no{\isacharunderscore}asm} etc.\ tune the Simplifier in the same way as the for the
wenzelm@26782
  1401
  \isa{simp} method.
wenzelm@26782
  1402
wenzelm@26782
  1403
  Note that forward simplification restricts the simplifier to its
wenzelm@26782
  1404
  most basic operation of term rewriting; solver and looper tactics
wenzelm@26782
  1405
  \cite{isabelle-ref} are \emph{not} involved here.  The \isa{simplified} attribute should be only rarely required under normal
wenzelm@26782
  1406
  circumstances.
wenzelm@26782
  1407
wenzelm@26782
  1408
  \end{descr}%
wenzelm@26782
  1409
\end{isamarkuptext}%
wenzelm@26782
  1410
\isamarkuptrue%
wenzelm@26782
  1411
%
wenzelm@26782
  1412
\isamarkupsubsubsection{Low-level equational reasoning%
wenzelm@26782
  1413
}
wenzelm@26782
  1414
\isamarkuptrue%
wenzelm@26782
  1415
%
wenzelm@26782
  1416
\begin{isamarkuptext}%
wenzelm@26782
  1417
\begin{matharray}{rcl}
wenzelm@26842
  1418
    \indexdef{}{method}{subst}\mbox{\isa{subst}}\isa{{\isachardoublequote}\isactrlsup {\isacharasterisk}{\isachardoublequote}} & : & \isarmeth \\
wenzelm@26842
  1419
    \indexdef{}{method}{hypsubst}\mbox{\isa{hypsubst}}\isa{{\isachardoublequote}\isactrlsup {\isacharasterisk}{\isachardoublequote}} & : & \isarmeth \\
wenzelm@26842
  1420
    \indexdef{}{method}{split}\mbox{\isa{split}}\isa{{\isachardoublequote}\isactrlsup {\isacharasterisk}{\isachardoublequote}} & : & \isarmeth \\
wenzelm@26782
  1421
  \end{matharray}
wenzelm@26782
  1422
wenzelm@26782
  1423
  \begin{rail}
wenzelm@26782
  1424
    'subst' ('(' 'asm' ')')? ('(' (nat+) ')')? thmref
wenzelm@26782
  1425
    ;
wenzelm@26782
  1426
    'split' ('(' 'asm' ')')? thmrefs
wenzelm@26782
  1427
    ;
wenzelm@26782
  1428
  \end{rail}
wenzelm@26782
  1429
wenzelm@26782
  1430
  These methods provide low-level facilities for equational reasoning
wenzelm@26782
  1431
  that are intended for specialized applications only.  Normally,
wenzelm@26782
  1432
  single step calculations would be performed in a structured text
wenzelm@26782
  1433
  (see also \secref{sec:calculation}), while the Simplifier methods
wenzelm@26782
  1434
  provide the canonical way for automated normalization (see
wenzelm@26782
  1435
  \secref{sec:simplifier}).
wenzelm@26782
  1436
wenzelm@26782
  1437
  \begin{descr}
wenzelm@26782
  1438
wenzelm@26782
  1439
  \item [\mbox{\isa{subst}}~\isa{eq}] performs a single substitution
wenzelm@26782
  1440
  step using rule \isa{eq}, which may be either a meta or object
wenzelm@26782
  1441
  equality.
wenzelm@26782
  1442
wenzelm@26842
  1443
  \item [\mbox{\isa{subst}}~\isa{{\isachardoublequote}{\isacharparenleft}asm{\isacharparenright}\ eq{\isachardoublequote}}] substitutes in an
wenzelm@26782
  1444
  assumption.
wenzelm@26782
  1445
wenzelm@26842
  1446
  \item [\mbox{\isa{subst}}~\isa{{\isachardoublequote}{\isacharparenleft}i\ {\isasymdots}\ j{\isacharparenright}\ eq{\isachardoublequote}}] performs several
wenzelm@26782
  1447
  substitutions in the conclusion. The numbers \isa{i} to \isa{j}
wenzelm@26782
  1448
  indicate the positions to substitute at.  Positions are ordered from
wenzelm@26782
  1449
  the top of the term tree moving down from left to right. For
wenzelm@26842
  1450
  example, in \isa{{\isachardoublequote}{\isacharparenleft}a\ {\isacharplus}\ b{\isacharparenright}\ {\isacharplus}\ {\isacharparenleft}c\ {\isacharplus}\ d{\isacharparenright}{\isachardoublequote}} there are three positions
wenzelm@26842
  1451
  where commutativity of \isa{{\isachardoublequote}{\isacharplus}{\isachardoublequote}} is applicable: 1 refers to the
wenzelm@26842
  1452
  whole term, 2 to \isa{{\isachardoublequote}a\ {\isacharplus}\ b{\isachardoublequote}} and 3 to \isa{{\isachardoublequote}c\ {\isacharplus}\ d{\isachardoublequote}}.
wenzelm@26782
  1453
wenzelm@26842
  1454
  If the positions in the list \isa{{\isachardoublequote}{\isacharparenleft}i\ {\isasymdots}\ j{\isacharparenright}{\isachardoublequote}} are non-overlapping
wenzelm@26842
  1455
  (e.g.\ \isa{{\isachardoublequote}{\isacharparenleft}{\isadigit{2}}\ {\isadigit{3}}{\isacharparenright}{\isachardoublequote}} in \isa{{\isachardoublequote}{\isacharparenleft}a\ {\isacharplus}\ b{\isacharparenright}\ {\isacharplus}\ {\isacharparenleft}c\ {\isacharplus}\ d{\isacharparenright}{\isachardoublequote}}) you may
wenzelm@26782
  1456
  assume all substitutions are performed simultaneously.  Otherwise
wenzelm@26782
  1457
  the behaviour of \isa{subst} is not specified.
wenzelm@26782
  1458
wenzelm@26842
  1459
  \item [\mbox{\isa{subst}}~\isa{{\isachardoublequote}{\isacharparenleft}asm{\isacharparenright}\ {\isacharparenleft}i\ {\isasymdots}\ j{\isacharparenright}\ eq{\isachardoublequote}}] performs the
wenzelm@26842
  1460
  substitutions in the assumptions.  Positions \isa{{\isachardoublequote}{\isadigit{1}}\ {\isasymdots}\ i\isactrlsub {\isadigit{1}}{\isachardoublequote}}
wenzelm@26842
  1461
  refer to assumption 1, positions \isa{{\isachardoublequote}i\isactrlsub {\isadigit{1}}\ {\isacharplus}\ {\isadigit{1}}\ {\isasymdots}\ i\isactrlsub {\isadigit{2}}{\isachardoublequote}}
wenzelm@26782
  1462
  to assumption 2, and so on.
wenzelm@26782
  1463
wenzelm@26782
  1464
  \item [\mbox{\isa{hypsubst}}] performs substitution using some
wenzelm@26842
  1465
  assumption; this only works for equations of the form \isa{{\isachardoublequote}x\ {\isacharequal}\ t{\isachardoublequote}} where \isa{x} is a free or bound variable.
wenzelm@26782
  1466
wenzelm@26842
  1467
  \item [\mbox{\isa{split}}~\isa{{\isachardoublequote}a\isactrlsub {\isadigit{1}}\ {\isasymdots}\ a\isactrlsub n{\isachardoublequote}}] performs
wenzelm@26782
  1468
  single-step case splitting using the given rules.  By default,
wenzelm@26842
  1469
  splitting is performed in the conclusion of a goal; the \isa{{\isachardoublequote}{\isacharparenleft}asm{\isacharparenright}{\isachardoublequote}} option indicates to operate on assumptions instead.
wenzelm@26782
  1470
  
wenzelm@26782
  1471
  Note that the \mbox{\isa{simp}} method already involves repeated
wenzelm@26782
  1472
  application of split rules as declared in the current context.
wenzelm@26782
  1473
wenzelm@26782
  1474
  \end{descr}%
wenzelm@26782
  1475
\end{isamarkuptext}%
wenzelm@26782
  1476
\isamarkuptrue%
wenzelm@26782
  1477
%
wenzelm@26782
  1478
\isamarkupsubsection{The Classical Reasoner \label{sec:classical}%
wenzelm@26782
  1479
}
wenzelm@26782
  1480
\isamarkuptrue%
wenzelm@26782
  1481
%
wenzelm@26782
  1482
\isamarkupsubsubsection{Basic methods%
wenzelm@26782
  1483
}
wenzelm@26782
  1484
\isamarkuptrue%
wenzelm@26782
  1485
%
wenzelm@26782
  1486
\begin{isamarkuptext}%
wenzelm@26782
  1487
\begin{matharray}{rcl}
wenzelm@26782
  1488
    \indexdef{}{method}{rule}\mbox{\isa{rule}} & : & \isarmeth \\
wenzelm@26782
  1489
    \indexdef{}{method}{contradiction}\mbox{\isa{contradiction}} & : & \isarmeth \\
wenzelm@26782
  1490
    \indexdef{}{method}{intro}\mbox{\isa{intro}} & : & \isarmeth \\
wenzelm@26782
  1491
    \indexdef{}{method}{elim}\mbox{\isa{elim}} & : & \isarmeth \\
wenzelm@26782
  1492
  \end{matharray}
wenzelm@26782
  1493
wenzelm@26782
  1494
  \begin{rail}
wenzelm@26782
  1495
    ('rule' | 'intro' | 'elim') thmrefs?
wenzelm@26782
  1496
    ;
wenzelm@26782
  1497
  \end{rail}
wenzelm@26782
  1498
wenzelm@26782
  1499
  \begin{descr}
wenzelm@26782
  1500
wenzelm@26782
  1501
  \item [\mbox{\isa{rule}}] as offered by the Classical Reasoner is a
wenzelm@26782
  1502
  refinement over the primitive one (see \secref{sec:pure-meth-att}).
wenzelm@26782
  1503
  Both versions essentially work the same, but the classical version
wenzelm@26782
  1504
  observes the classical rule context in addition to that of
wenzelm@26782
  1505
  Isabelle/Pure.
wenzelm@26782
  1506
wenzelm@26782
  1507
  Common object logics (HOL, ZF, etc.) declare a rich collection of
wenzelm@26782
  1508
  classical rules (even if these would qualify as intuitionistic
wenzelm@26782
  1509
  ones), but only few declarations to the rule context of
wenzelm@26782
  1510
  Isabelle/Pure (\secref{sec:pure-meth-att}).
wenzelm@26782
  1511
wenzelm@26782
  1512
  \item [\mbox{\isa{contradiction}}] solves some goal by contradiction,
wenzelm@26842
  1513
  deriving any result from both \isa{{\isachardoublequote}{\isasymnot}\ A{\isachardoublequote}} and \isa{A}.  Chained
wenzelm@26782
  1514
  facts, which are guaranteed to participate, may appear in either
wenzelm@26782
  1515
  order.
wenzelm@26782
  1516
wenzelm@26782
  1517
  \item [\mbox{\isa{intro}} and \mbox{\isa{elim}}] repeatedly refine
wenzelm@26782
  1518
  some goal by intro- or elim-resolution, after having inserted any
wenzelm@26782
  1519
  chained facts.  Exactly the rules given as arguments are taken into
wenzelm@26782
  1520
  account; this allows fine-tuned decomposition of a proof problem, in
wenzelm@26782
  1521
  contrast to common automated tools.
wenzelm@26782
  1522
wenzelm@26782
  1523
  \end{descr}%
wenzelm@26782
  1524
\end{isamarkuptext}%
wenzelm@26782
  1525
\isamarkuptrue%
wenzelm@26782
  1526
%
wenzelm@26782
  1527
\isamarkupsubsubsection{Automated methods%
wenzelm@26782
  1528
}
wenzelm@26782
  1529
\isamarkuptrue%
wenzelm@26782
  1530
%
wenzelm@26782
  1531
\begin{isamarkuptext}%
wenzelm@26782
  1532
\begin{matharray}{rcl}
wenzelm@26782
  1533
    \indexdef{}{method}{blast}\mbox{\isa{blast}} & : & \isarmeth \\
wenzelm@26782
  1534
    \indexdef{}{method}{fast}\mbox{\isa{fast}} & : & \isarmeth \\
wenzelm@26782
  1535
    \indexdef{}{method}{slow}\mbox{\isa{slow}} & : & \isarmeth \\
wenzelm@26782
  1536
    \indexdef{}{method}{best}\mbox{\isa{best}} & : & \isarmeth \\
wenzelm@26782
  1537
    \indexdef{}{method}{safe}\mbox{\isa{safe}} & : & \isarmeth \\
wenzelm@26782
  1538
    \indexdef{}{method}{clarify}\mbox{\isa{clarify}} & : & \isarmeth \\
wenzelm@26782
  1539
  \end{matharray}
wenzelm@26782
  1540
wenzelm@26782
  1541
  \indexouternonterm{clamod}
wenzelm@26782
  1542
  \begin{rail}
wenzelm@26782
  1543
    'blast' ('!' ?) nat? (clamod *)
wenzelm@26782
  1544
    ;
wenzelm@26782
  1545
    ('fast' | 'slow' | 'best' | 'safe' | 'clarify') ('!' ?) (clamod *)
wenzelm@26782
  1546
    ;
wenzelm@26782
  1547
wenzelm@26782
  1548
    clamod: (('intro' | 'elim' | 'dest') ('!' | () | '?') | 'del') ':' thmrefs
wenzelm@26782
  1549
    ;
wenzelm@26782
  1550
  \end{rail}
wenzelm@26782
  1551
wenzelm@26782
  1552
  \begin{descr}
wenzelm@26782
  1553
wenzelm@26782
  1554
  \item [\mbox{\isa{blast}}] refers to the classical tableau prover (see
wenzelm@26782
  1555
  \verb|blast_tac| in \cite[\S11]{isabelle-ref}).  The optional
wenzelm@26782
  1556
  argument specifies a user-supplied search bound (default 20).
wenzelm@26782
  1557
wenzelm@26782
  1558
  \item [\mbox{\isa{fast}}, \mbox{\isa{slow}}, \mbox{\isa{best}}, \mbox{\isa{safe}}, and \mbox{\isa{clarify}}] refer to the generic classical
wenzelm@26782
  1559
  reasoner.  See \verb|fast_tac|, \verb|slow_tac|, \verb|best_tac|, \verb|safe_tac|, and \verb|clarify_tac| in \cite[\S11]{isabelle-ref} for
wenzelm@26782
  1560
  more information.
wenzelm@26782
  1561
wenzelm@26782
  1562
  \end{descr}
wenzelm@26782
  1563
wenzelm@26782
  1564
  Any of the above methods support additional modifiers of the context
wenzelm@26782
  1565
  of classical rules.  Their semantics is analogous to the attributes
wenzelm@26782
  1566
  given before.  Facts provided by forward chaining are inserted into
wenzelm@26842
  1567
  the goal before commencing proof search.  The ``\isa{{\isachardoublequote}{\isacharbang}{\isachardoublequote}}''~argument causes the full context of assumptions to be
wenzelm@26782
  1568
  included as well.%
wenzelm@26782
  1569
\end{isamarkuptext}%
wenzelm@26782
  1570
\isamarkuptrue%
wenzelm@26782
  1571
%
wenzelm@26782
  1572
\isamarkupsubsubsection{Combined automated methods \label{sec:clasimp}%
wenzelm@26782
  1573
}
wenzelm@26782
  1574
\isamarkuptrue%
wenzelm@26782
  1575
%
wenzelm@26782
  1576
\begin{isamarkuptext}%
wenzelm@26782
  1577
\begin{matharray}{rcl}
wenzelm@26782
  1578
    \indexdef{}{method}{auto}\mbox{\isa{auto}} & : & \isarmeth \\
wenzelm@26782
  1579
    \indexdef{}{method}{force}\mbox{\isa{force}} & : & \isarmeth \\
wenzelm@26782
  1580
    \indexdef{}{method}{clarsimp}\mbox{\isa{clarsimp}} & : & \isarmeth \\
wenzelm@26782
  1581
    \indexdef{}{method}{fastsimp}\mbox{\isa{fastsimp}} & : & \isarmeth \\
wenzelm@26782
  1582
    \indexdef{}{method}{slowsimp}\mbox{\isa{slowsimp}} & : & \isarmeth \\
wenzelm@26782
  1583
    \indexdef{}{method}{bestsimp}\mbox{\isa{bestsimp}} & : & \isarmeth \\
wenzelm@26782
  1584
  \end{matharray}
wenzelm@26782
  1585
wenzelm@26782
  1586
  \indexouternonterm{clasimpmod}
wenzelm@26782
  1587
  \begin{rail}
wenzelm@26782
  1588
    'auto' '!'? (nat nat)? (clasimpmod *)
wenzelm@26782
  1589
    ;
wenzelm@26782
  1590
    ('force' | 'clarsimp' | 'fastsimp' | 'slowsimp' | 'bestsimp') '!'? (clasimpmod *)
wenzelm@26782
  1591
    ;
wenzelm@26782
  1592
wenzelm@26782
  1593
    clasimpmod: ('simp' (() | 'add' | 'del' | 'only') |
wenzelm@26782
  1594
      ('cong' | 'split') (() | 'add' | 'del') |
wenzelm@26782
  1595
      'iff' (((() | 'add') '?'?) | 'del') |
wenzelm@26782
  1596
      (('intro' | 'elim' | 'dest') ('!' | () | '?') | 'del')) ':' thmrefs
wenzelm@26782
  1597
  \end{rail}
wenzelm@26782
  1598
wenzelm@26782
  1599
  \begin{descr}
wenzelm@26782
  1600
wenzelm@26782
  1601
  \item [\mbox{\isa{auto}}, \mbox{\isa{force}}, \mbox{\isa{clarsimp}}, \mbox{\isa{fastsimp}}, \mbox{\isa{slowsimp}}, and \mbox{\isa{bestsimp}}] provide
wenzelm@26782
  1602
  access to Isabelle's combined simplification and classical reasoning
wenzelm@26782
  1603
  tactics.  These correspond to \verb|auto_tac|, \verb|force_tac|, \verb|clarsimp_tac|, and Classical Reasoner tactics with the Simplifier
wenzelm@26782
  1604
  added as wrapper, see \cite[\S11]{isabelle-ref} for more
wenzelm@26782
  1605
  information.  The modifier arguments correspond to those given in
wenzelm@26782
  1606
  \secref{sec:simplifier} and \secref{sec:classical}.  Just note that
wenzelm@26782
  1607
  the ones related to the Simplifier are prefixed by \railtterm{simp}
wenzelm@26782
  1608
  here.
wenzelm@26782
  1609
wenzelm@26782
  1610
  Facts provided by forward chaining are inserted into the goal before
wenzelm@26842
  1611
  doing the search.  The ``\isa{{\isachardoublequote}{\isacharbang}{\isachardoublequote}}'' argument causes the full
wenzelm@26782
  1612
  context of assumptions to be included as well.
wenzelm@26782
  1613
wenzelm@26782
  1614
  \end{descr}%
wenzelm@26782
  1615
\end{isamarkuptext}%
wenzelm@26782
  1616
\isamarkuptrue%
wenzelm@26782
  1617
%
wenzelm@26782
  1618
\isamarkupsubsubsection{Declaring rules%
wenzelm@26782
  1619
}
wenzelm@26782
  1620
\isamarkuptrue%
wenzelm@26782
  1621
%
wenzelm@26782
  1622
\begin{isamarkuptext}%
wenzelm@26782
  1623
\begin{matharray}{rcl}
wenzelm@26854
  1624
    \indexdef{}{command}{print\_claset}\mbox{\isa{\isacommand{print{\isacharunderscore}claset}}}\isa{{\isachardoublequote}\isactrlsup {\isacharasterisk}{\isachardoublequote}} & : & \isarkeep{theory~|~proof} \\
wenzelm@26782
  1625
    \indexdef{}{attribute}{intro}\mbox{\isa{intro}} & : & \isaratt \\
wenzelm@26782
  1626
    \indexdef{}{attribute}{elim}\mbox{\isa{elim}} & : & \isaratt \\
wenzelm@26782
  1627
    \indexdef{}{attribute}{dest}\mbox{\isa{dest}} & : & \isaratt \\
wenzelm@26782
  1628
    \indexdef{}{attribute}{rule}\mbox{\isa{rule}} & : & \isaratt \\
wenzelm@26782
  1629
    \indexdef{}{attribute}{iff}\mbox{\isa{iff}} & : & \isaratt \\
wenzelm@26782
  1630
  \end{matharray}
wenzelm@26782
  1631
wenzelm@26782
  1632
  \begin{rail}
wenzelm@26782
  1633
    ('intro' | 'elim' | 'dest') ('!' | () | '?') nat?
wenzelm@26782
  1634
    ;
wenzelm@26782
  1635
    'rule' 'del'
wenzelm@26782
  1636
    ;
wenzelm@26782
  1637
    'iff' (((() | 'add') '?'?) | 'del')
wenzelm@26782
  1638
    ;
wenzelm@26782
  1639
  \end{rail}
wenzelm@26782
  1640
wenzelm@26782
  1641
  \begin{descr}
wenzelm@26782
  1642
wenzelm@26782
  1643
  \item [\mbox{\isa{\isacommand{print{\isacharunderscore}claset}}}] prints the collection of rules
wenzelm@26782
  1644
  declared to the Classical Reasoner, which is also known as
wenzelm@26782
  1645
  ``claset'' internally \cite{isabelle-ref}.
wenzelm@26782
  1646
  
wenzelm@26782
  1647
  \item [\mbox{\isa{intro}}, \mbox{\isa{elim}}, and \mbox{\isa{dest}}]
wenzelm@26782
  1648
  declare introduction, elimination, and destruction rules,
wenzelm@26782
  1649
  respectively.  By default, rules are considered as \emph{unsafe}
wenzelm@26842
  1650
  (i.e.\ not applied blindly without backtracking), while ``\isa{{\isachardoublequote}{\isacharbang}{\isachardoublequote}}'' classifies as \emph{safe}.  Rule declarations marked by
wenzelm@26842
  1651
  ``\isa{{\isachardoublequote}{\isacharquery}{\isachardoublequote}}'' coincide with those of Isabelle/Pure, cf.\
wenzelm@26782
  1652
  \secref{sec:pure-meth-att} (i.e.\ are only applied in single steps
wenzelm@26782
  1653
  of the \mbox{\isa{rule}} method).  The optional natural number
wenzelm@26782
  1654
  specifies an explicit weight argument, which is ignored by automated
wenzelm@26782
  1655
  tools, but determines the search order of single rule steps.
wenzelm@26782
  1656
wenzelm@26782
  1657
  \item [\mbox{\isa{rule}}~\isa{del}] deletes introduction,
wenzelm@26782
  1658
  elimination, or destruction rules from the context.
wenzelm@26782
  1659
wenzelm@26782
  1660
  \item [\mbox{\isa{iff}}] declares logical equivalences to the
wenzelm@26782
  1661
  Simplifier and the Classical reasoner at the same time.
wenzelm@26782
  1662
  Non-conditional rules result in a ``safe'' introduction and
wenzelm@26782
  1663
  elimination pair; conditional ones are considered ``unsafe''.  Rules
wenzelm@26842
  1664
  with negative conclusion are automatically inverted (using \isa{{\isachardoublequote}{\isasymnot}{\isachardoublequote}}-elimination internally).
wenzelm@26782
  1665
wenzelm@26842
  1666
  The ``\isa{{\isachardoublequote}{\isacharquery}{\isachardoublequote}}'' version of \mbox{\isa{iff}} declares rules to
wenzelm@26782
  1667
  the Isabelle/Pure context only, and omits the Simplifier
wenzelm@26782
  1668
  declaration.
wenzelm@26782
  1669
wenzelm@26782
  1670
  \end{descr}%
wenzelm@26782
  1671
\end{isamarkuptext}%
wenzelm@26782
  1672
\isamarkuptrue%
wenzelm@26782
  1673
%
wenzelm@26782
  1674
\isamarkupsubsubsection{Classical operations%
wenzelm@26782
  1675
}
wenzelm@26782
  1676
\isamarkuptrue%
wenzelm@26782
  1677
%
wenzelm@26782
  1678
\begin{isamarkuptext}%
wenzelm@26782
  1679
\begin{matharray}{rcl}
wenzelm@26782
  1680
    \indexdef{}{attribute}{swapped}\mbox{\isa{swapped}} & : & \isaratt \\
wenzelm@26782
  1681
  \end{matharray}
wenzelm@26782
  1682
wenzelm@26782
  1683
  \begin{descr}
wenzelm@26782
  1684
wenzelm@26782
  1685
  \item [\mbox{\isa{swapped}}] turns an introduction rule into an
wenzelm@26842
  1686
  elimination, by resolving with the classical swap principle \isa{{\isachardoublequote}{\isacharparenleft}{\isasymnot}\ B\ {\isasymLongrightarrow}\ A{\isacharparenright}\ {\isasymLongrightarrow}\ {\isacharparenleft}{\isasymnot}\ A\ {\isasymLongrightarrow}\ B{\isacharparenright}{\isachardoublequote}}.
wenzelm@26782
  1687
wenzelm@26782
  1688
  \end{descr}%
wenzelm@26782
  1689
\end{isamarkuptext}%
wenzelm@26782
  1690
\isamarkuptrue%
wenzelm@26782
  1691
%
wenzelm@26782
  1692
\isamarkupsubsection{Proof by cases and induction \label{sec:cases-induct}%
wenzelm@26782
  1693
}
wenzelm@26782
  1694
\isamarkuptrue%
wenzelm@26782
  1695
%
wenzelm@26782
  1696
\isamarkupsubsubsection{Rule contexts%
wenzelm@26782
  1697
}
wenzelm@26782
  1698
\isamarkuptrue%
wenzelm@26782
  1699
%
wenzelm@26782
  1700
\begin{isamarkuptext}%
wenzelm@26782
  1701
\begin{matharray}{rcl}
wenzelm@26782
  1702
    \indexdef{}{command}{case}\mbox{\isa{\isacommand{case}}} & : & \isartrans{proof(state)}{proof(state)} \\
wenzelm@26854
  1703
    \indexdef{}{command}{print\_cases}\mbox{\isa{\isacommand{print{\isacharunderscore}cases}}}\isa{{\isachardoublequote}\isactrlsup {\isacharasterisk}{\isachardoublequote}} & : & \isarkeep{proof} \\
wenzelm@26854
  1704
    \indexdef{}{attribute}{case\_names}\mbox{\isa{case{\isacharunderscore}names}} & : & \isaratt \\
wenzelm@26854
  1705
    \indexdef{}{attribute}{case\_conclusion}\mbox{\isa{case{\isacharunderscore}conclusion}} & : & \isaratt \\
wenzelm@26782
  1706
    \indexdef{}{attribute}{params}\mbox{\isa{params}} & : & \isaratt \\
wenzelm@26782
  1707
    \indexdef{}{attribute}{consumes}\mbox{\isa{consumes}} & : & \isaratt \\
wenzelm@26782
  1708
  \end{matharray}
wenzelm@26782
  1709
wenzelm@26782
  1710
  The puristic way to build up Isar proof contexts is by explicit
wenzelm@26782
  1711
  language elements like \mbox{\isa{\isacommand{fix}}}, \mbox{\isa{\isacommand{assume}}},
wenzelm@26782
  1712
  \mbox{\isa{\isacommand{let}}} (see \secref{sec:proof-context}).  This is adequate
wenzelm@26782
  1713
  for plain natural deduction, but easily becomes unwieldy in concrete
wenzelm@26782
  1714
  verification tasks, which typically involve big induction rules with
wenzelm@26782
  1715
  several cases.
wenzelm@26782
  1716
wenzelm@26782
  1717
  The \mbox{\isa{\isacommand{case}}} command provides a shorthand to refer to a
wenzelm@26782
  1718
  local context symbolically: certain proof methods provide an
wenzelm@26842
  1719
  environment of named ``cases'' of the form \isa{{\isachardoublequote}c{\isacharcolon}\ x\isactrlsub {\isadigit{1}}{\isacharcomma}\ {\isasymdots}{\isacharcomma}\ x\isactrlsub m{\isacharcomma}\ {\isasymphi}\isactrlsub {\isadigit{1}}{\isacharcomma}\ {\isasymdots}{\isacharcomma}\ {\isasymphi}\isactrlsub n{\isachardoublequote}}; the effect of ``\mbox{\isa{\isacommand{case}}}~\isa{c}'' is then equivalent to ``\mbox{\isa{\isacommand{fix}}}~\isa{{\isachardoublequote}x\isactrlsub {\isadigit{1}}\ {\isasymdots}\ x\isactrlsub m{\isachardoublequote}}~\mbox{\isa{\isacommand{assume}}}~\isa{{\isachardoublequote}c{\isacharcolon}\ {\isasymphi}\isactrlsub {\isadigit{1}}\ {\isasymdots}\ {\isasymphi}\isactrlsub n{\isachardoublequote}}''.  Term bindings may be covered as well, notably
wenzelm@26788
  1720
  \mbox{\isa{{\isacharquery}case}} for the main conclusion.
wenzelm@26782
  1721
wenzelm@26842
  1722
  By default, the ``terminology'' \isa{{\isachardoublequote}x\isactrlsub {\isadigit{1}}{\isacharcomma}\ {\isasymdots}{\isacharcomma}\ x\isactrlsub m{\isachardoublequote}} of
wenzelm@26782
  1723
  a case value is marked as hidden, i.e.\ there is no way to refer to
wenzelm@26782
  1724
  such parameters in the subsequent proof text.  After all, original
wenzelm@26782
  1725
  rule parameters stem from somewhere outside of the current proof
wenzelm@26842
  1726
  text.  By using the explicit form ``\mbox{\isa{\isacommand{case}}}~\isa{{\isachardoublequote}{\isacharparenleft}c\ y\isactrlsub {\isadigit{1}}\ {\isasymdots}\ y\isactrlsub m{\isacharparenright}{\isachardoublequote}}'' instead, the proof author is able to
wenzelm@26782
  1727
  chose local names that fit nicely into the current context.
wenzelm@26782
  1728
wenzelm@26782
  1729
  \medskip It is important to note that proper use of \mbox{\isa{\isacommand{case}}} does not provide means to peek at the current goal state,
wenzelm@26782
  1730
  which is not directly observable in Isar!  Nonetheless, goal
wenzelm@26842
  1731
  refinement commands do provide named cases \isa{{\isachardoublequote}goal\isactrlsub i{\isachardoublequote}}
wenzelm@26842
  1732
  for each subgoal \isa{{\isachardoublequote}i\ {\isacharequal}\ {\isadigit{1}}{\isacharcomma}\ {\isasymdots}{\isacharcomma}\ n{\isachardoublequote}} of the resulting goal state.
wenzelm@26782
  1733
  Using this extra feature requires great care, because some bits of
wenzelm@26782
  1734
  the internal tactical machinery intrude the proof text.  In
wenzelm@26782
  1735
  particular, parameter names stemming from the left-over of automated
wenzelm@26782
  1736
  reasoning tools are usually quite unpredictable.
wenzelm@26782
  1737
wenzelm@26782
  1738
  Under normal circumstances, the text of cases emerge from standard
wenzelm@26782
  1739
  elimination or induction rules, which in turn are derived from
wenzelm@26782
  1740
  previous theory specifications in a canonical way (say from
wenzelm@26782
  1741
  \mbox{\isa{\isacommand{inductive}}} definitions).
wenzelm@26782
  1742
wenzelm@26782
  1743
  \medskip Proper cases are only available if both the proof method
wenzelm@26782
  1744
  and the rules involved support this.  By using appropriate
wenzelm@26782
  1745
  attributes, case names, conclusions, and parameters may be also
wenzelm@26782
  1746
  declared by hand.  Thus variant versions of rules that have been
wenzelm@26782
  1747
  derived manually become ready to use in advanced case analysis
wenzelm@26782
  1748
  later.
wenzelm@26782
  1749
wenzelm@26782
  1750
  \begin{rail}
wenzelm@26782
  1751
    'case' (caseref | '(' caseref ((name | underscore) +) ')')
wenzelm@26782
  1752
    ;
wenzelm@26782
  1753
    caseref: nameref attributes?
wenzelm@26782
  1754
    ;
wenzelm@26782
  1755
wenzelm@26782
  1756
    'case\_names' (name +)
wenzelm@26782
  1757
    ;
wenzelm@26782
  1758
    'case\_conclusion' name (name *)
wenzelm@26782
  1759
    ;
wenzelm@26782
  1760
    'params' ((name *) + 'and')
wenzelm@26782
  1761
    ;
wenzelm@26782
  1762
    'consumes' nat?
wenzelm@26782
  1763
    ;
wenzelm@26782
  1764
  \end{rail}
wenzelm@26782
  1765
wenzelm@26782
  1766
  \begin{descr}
wenzelm@26782
  1767
  
wenzelm@26842
  1768
  \item [\mbox{\isa{\isacommand{case}}}~\isa{{\isachardoublequote}{\isacharparenleft}c\ x\isactrlsub {\isadigit{1}}\ {\isasymdots}\ x\isactrlsub m{\isacharparenright}{\isachardoublequote}}]
wenzelm@26842
  1769
  invokes a named local context \isa{{\isachardoublequote}c{\isacharcolon}\ x\isactrlsub {\isadigit{1}}{\isacharcomma}\ {\isasymdots}{\isacharcomma}\ x\isactrlsub m{\isacharcomma}\ {\isasymphi}\isactrlsub {\isadigit{1}}{\isacharcomma}\ {\isasymdots}{\isacharcomma}\ {\isasymphi}\isactrlsub m{\isachardoublequote}}, as provided by an appropriate
wenzelm@26782
  1770
  proof method (such as \indexref{}{method}{cases}\mbox{\isa{cases}} and \indexref{}{method}{induct}\mbox{\isa{induct}}).
wenzelm@26842
  1771
  The command ``\mbox{\isa{\isacommand{case}}}~\isa{{\isachardoublequote}{\isacharparenleft}c\ x\isactrlsub {\isadigit{1}}\ {\isasymdots}\ x\isactrlsub m{\isacharparenright}{\isachardoublequote}}'' abbreviates ``\mbox{\isa{\isacommand{fix}}}~\isa{{\isachardoublequote}x\isactrlsub {\isadigit{1}}\ {\isasymdots}\ x\isactrlsub m{\isachardoublequote}}~\mbox{\isa{\isacommand{assume}}}~\isa{{\isachardoublequote}c{\isacharcolon}\ {\isasymphi}\isactrlsub {\isadigit{1}}\ {\isasymdots}\ {\isasymphi}\isactrlsub n{\isachardoublequote}}''.
wenzelm@26782
  1772
wenzelm@26782
  1773
  \item [\mbox{\isa{\isacommand{print{\isacharunderscore}cases}}}] prints all local contexts of the
wenzelm@26782
  1774
  current state, using Isar proof language notation.
wenzelm@26782
  1775
  
wenzelm@26842
  1776
  \item [\mbox{\isa{case{\isacharunderscore}names}}~\isa{{\isachardoublequote}c\isactrlsub {\isadigit{1}}\ {\isasymdots}\ c\isactrlsub k{\isachardoublequote}}]
wenzelm@26782
  1777
  declares names for the local contexts of premises of a theorem;
wenzelm@26842
  1778
  \isa{{\isachardoublequote}c\isactrlsub {\isadigit{1}}{\isacharcomma}\ {\isasymdots}{\isacharcomma}\ c\isactrlsub k{\isachardoublequote}} refers to the \emph{suffix} of the
wenzelm@26782
  1779
  list of premises.
wenzelm@26782
  1780
  
wenzelm@26842
  1781
  \item [\mbox{\isa{case{\isacharunderscore}conclusion}}~\isa{{\isachardoublequote}c\ d\isactrlsub {\isadigit{1}}\ {\isasymdots}\ d\isactrlsub k{\isachardoublequote}}] declares names for the conclusions of a named premise
wenzelm@26842
  1782
  \isa{c}; here \isa{{\isachardoublequote}d\isactrlsub {\isadigit{1}}{\isacharcomma}\ {\isasymdots}{\isacharcomma}\ d\isactrlsub k{\isachardoublequote}} refers to the
wenzelm@26782
  1783
  prefix of arguments of a logical formula built by nesting a binary
wenzelm@26842
  1784
  connective (e.g.\ \isa{{\isachardoublequote}{\isasymor}{\isachardoublequote}}).
wenzelm@26782
  1785
  
wenzelm@26782
  1786
  Note that proof methods such as \mbox{\isa{induct}} and \mbox{\isa{coinduct}} already provide a default name for the conclusion as a
wenzelm@26782
  1787
  whole.  The need to name subformulas only arises with cases that
wenzelm@26782
  1788
  split into several sub-cases, as in common co-induction rules.
wenzelm@26782
  1789
wenzelm@26842
  1790
  \item [\mbox{\isa{params}}~\isa{{\isachardoublequote}p\isactrlsub {\isadigit{1}}\ {\isasymdots}\ p\isactrlsub m\ {\isasymAND}\ {\isasymdots}\ q\isactrlsub {\isadigit{1}}\ {\isasymdots}\ q\isactrlsub n{\isachardoublequote}}] renames the innermost parameters of
wenzelm@26842
  1791
  premises \isa{{\isachardoublequote}{\isadigit{1}}{\isacharcomma}\ {\isasymdots}{\isacharcomma}\ n{\isachardoublequote}} of some theorem.  An empty list of names
wenzelm@26782
  1792
  may be given to skip positions, leaving the present parameters
wenzelm@26782
  1793
  unchanged.
wenzelm@26782
  1794
  
wenzelm@26782
  1795
  Note that the default usage of case rules does \emph{not} directly
wenzelm@26782
  1796
  expose parameters to the proof context.
wenzelm@26782
  1797
  
wenzelm@26782
  1798
  \item [\mbox{\isa{consumes}}~\isa{n}] declares the number of
wenzelm@26782
  1799
  ``major premises'' of a rule, i.e.\ the number of facts to be
wenzelm@26782
  1800
  consumed when it is applied by an appropriate proof method.  The
wenzelm@26842
  1801
  default value of \mbox{\isa{consumes}} is \isa{{\isachardoublequote}n\ {\isacharequal}\ {\isadigit{1}}{\isachardoublequote}}, which is
wenzelm@26782
  1802
  appropriate for the usual kind of cases and induction rules for
wenzelm@26782
  1803
  inductive sets (cf.\ \secref{sec:hol-inductive}).  Rules without any
wenzelm@26782
  1804
  \mbox{\isa{consumes}} declaration given are treated as if
wenzelm@26782
  1805
  \mbox{\isa{consumes}}~\isa{{\isadigit{0}}} had been specified.
wenzelm@26782
  1806
  
wenzelm@26782
  1807
  Note that explicit \mbox{\isa{consumes}} declarations are only
wenzelm@26782
  1808
  rarely needed; this is already taken care of automatically by the
wenzelm@26782
  1809
  higher-level \mbox{\isa{cases}}, \mbox{\isa{induct}}, and
wenzelm@26782
  1810
  \mbox{\isa{coinduct}} declarations.
wenzelm@26782
  1811
wenzelm@26782
  1812
  \end{descr}%
wenzelm@26782
  1813
\end{isamarkuptext}%
wenzelm@26782
  1814
\isamarkuptrue%
wenzelm@26782
  1815
%
wenzelm@26782
  1816
\isamarkupsubsubsection{Proof methods%
wenzelm@26782
  1817
}
wenzelm@26782
  1818
\isamarkuptrue%
wenzelm@26782
  1819
%
wenzelm@26782
  1820
\begin{isamarkuptext}%
wenzelm@26782
  1821
\begin{matharray}{rcl}
wenzelm@26782
  1822
    \indexdef{}{method}{cases}\mbox{\isa{cases}} & : & \isarmeth \\
wenzelm@26782
  1823
    \indexdef{}{method}{induct}\mbox{\isa{induct}} & : & \isarmeth \\
wenzelm@26782
  1824
    \indexdef{}{method}{coinduct}\mbox{\isa{coinduct}} & : & \isarmeth \\
wenzelm@26782
  1825
  \end{matharray}
wenzelm@26782
  1826
wenzelm@26782
  1827
  The \mbox{\isa{cases}}, \mbox{\isa{induct}}, and \mbox{\isa{coinduct}}
wenzelm@26782
  1828
  methods provide a uniform interface to common proof techniques over
wenzelm@26782
  1829
  datatypes, inductive predicates (or sets), recursive functions etc.
wenzelm@26782
  1830
  The corresponding rules may be specified and instantiated in a
wenzelm@26782
  1831
  casual manner.  Furthermore, these methods provide named local
wenzelm@26782
  1832
  contexts that may be invoked via the \mbox{\isa{\isacommand{case}}} proof command
wenzelm@26782
  1833
  within the subsequent proof text.  This accommodates compact proof
wenzelm@26782
  1834
  texts even when reasoning about large specifications.
wenzelm@26782
  1835
wenzelm@26782
  1836
  The \mbox{\isa{induct}} method also provides some additional
wenzelm@26782
  1837
  infrastructure in order to be applicable to structure statements
wenzelm@26782
  1838
  (either using explicit meta-level connectives, or including facts
wenzelm@26782
  1839
  and parameters separately).  This avoids cumbersome encoding of
wenzelm@26782
  1840
  ``strengthened'' inductive statements within the object-logic.
wenzelm@26782
  1841
wenzelm@26782
  1842
  \begin{rail}
wenzelm@26782
  1843
    'cases' (insts * 'and') rule?
wenzelm@26782
  1844
    ;
wenzelm@26782
  1845
    'induct' (definsts * 'and') \\ arbitrary? taking? rule?
wenzelm@26782
  1846
    ;
wenzelm@26782
  1847
    'coinduct' insts taking rule?
wenzelm@26782
  1848
    ;
wenzelm@26782
  1849
wenzelm@26782
  1850
    rule: ('type' | 'pred' | 'set') ':' (nameref +) | 'rule' ':' (thmref +)
wenzelm@26782
  1851
    ;
wenzelm@26782
  1852
    definst: name ('==' | equiv) term | inst
wenzelm@26782
  1853
    ;
wenzelm@26782
  1854
    definsts: ( definst *)
wenzelm@26782
  1855
    ;
wenzelm@26782
  1856
    arbitrary: 'arbitrary' ':' ((term *) 'and' +)
wenzelm@26782
  1857
    ;
wenzelm@26782
  1858
    taking: 'taking' ':' insts
wenzelm@26782
  1859
    ;
wenzelm@26782
  1860
  \end{rail}
wenzelm@26782
  1861
wenzelm@26782
  1862
  \begin{descr}
wenzelm@26782
  1863
wenzelm@26842
  1864
  \item [\mbox{\isa{cases}}~\isa{{\isachardoublequote}insts\ R{\isachardoublequote}}] applies method \mbox{\isa{rule}} with an appropriate case distinction theorem, instantiated to
wenzelm@26782
  1865
  the subjects \isa{insts}.  Symbolic case names are bound according
wenzelm@26782
  1866
  to the rule's local contexts.
wenzelm@26782
  1867
wenzelm@26782
  1868
  The rule is determined as follows, according to the facts and
wenzelm@26782
  1869
  arguments passed to the \mbox{\isa{cases}} method:
wenzelm@26782
  1870
wenzelm@26782
  1871
  \medskip
wenzelm@26782
  1872
  \begin{tabular}{llll}
wenzelm@26788
  1873
    facts           &                 & arguments   & rule \\\hline
wenzelm@26788
  1874
                    & \mbox{\isa{cases}} &             & classical case split \\
wenzelm@26788
  1875
                    & \mbox{\isa{cases}} & \isa{t}   & datatype exhaustion (type of \isa{t}) \\
wenzelm@26842
  1876
    \isa{{\isachardoublequote}{\isasymturnstile}\ A\ t{\isachardoublequote}} & \mbox{\isa{cases}} & \isa{{\isachardoublequote}{\isasymdots}{\isachardoublequote}} & inductive predicate/set elimination (of \isa{A}) \\
wenzelm@26842
  1877
    \isa{{\isachardoublequote}{\isasymdots}{\isachardoublequote}}     & \mbox{\isa{cases}} & \isa{{\isachardoublequote}{\isasymdots}\ rule{\isacharcolon}\ R{\isachardoublequote}} & explicit rule \isa{R} \\
wenzelm@26782
  1878
  \end{tabular}
wenzelm@26782
  1879
  \medskip
wenzelm@26782
  1880
wenzelm@26782
  1881
  Several instantiations may be given, referring to the \emph{suffix}
wenzelm@26782
  1882
  of premises of the case rule; within each premise, the \emph{prefix}
wenzelm@26782
  1883
  of variables is instantiated.  In most situations, only a single
wenzelm@26782
  1884
  term needs to be specified; this refers to the first variable of the
wenzelm@26782
  1885
  last premise (it is usually the same for all cases).
wenzelm@26782
  1886
wenzelm@26842
  1887
  \item [\mbox{\isa{induct}}~\isa{{\isachardoublequote}insts\ R{\isachardoublequote}}] is analogous to the
wenzelm@26782
  1888
  \mbox{\isa{cases}} method, but refers to induction rules, which are
wenzelm@26782
  1889
  determined as follows:
wenzelm@26782
  1890
wenzelm@26782
  1891
  \medskip
wenzelm@26782
  1892
  \begin{tabular}{llll}
wenzelm@26788
  1893
    facts           &                  & arguments            & rule \\\hline
wenzelm@26842
  1894
                    & \mbox{\isa{induct}} & \isa{{\isachardoublequote}P\ x{\isachardoublequote}}        & datatype induction (type of \isa{x}) \\
wenzelm@26842
  1895
    \isa{{\isachardoublequote}{\isasymturnstile}\ A\ x{\isachardoublequote}} & \mbox{\isa{induct}} & \isa{{\isachardoublequote}{\isasymdots}{\isachardoublequote}}          & predicate/set induction (of \isa{A}) \\
wenzelm@26842
  1896
    \isa{{\isachardoublequote}{\isasymdots}{\isachardoublequote}}     & \mbox{\isa{induct}} & \isa{{\isachardoublequote}{\isasymdots}\ rule{\isacharcolon}\ R{\isachardoublequote}} & explicit rule \isa{R} \\
wenzelm@26782
  1897
  \end{tabular}
wenzelm@26782
  1898
  \medskip
wenzelm@26782
  1899
  
wenzelm@26782
  1900
  Several instantiations may be given, each referring to some part of
wenzelm@26782
  1901
  a mutual inductive definition or datatype --- only related partial
wenzelm@26782
  1902
  induction rules may be used together, though.  Any of the lists of
wenzelm@26842
  1903
  terms \isa{{\isachardoublequote}P{\isacharcomma}\ x{\isacharcomma}\ {\isasymdots}{\isachardoublequote}} refers to the \emph{suffix} of variables
wenzelm@26782
  1904
  present in the induction rule.  This enables the writer to specify
wenzelm@26782
  1905
  only induction variables, or both predicates and variables, for
wenzelm@26782
  1906
  example.
wenzelm@26782
  1907
  
wenzelm@26842
  1908
  Instantiations may be definitional: equations \isa{{\isachardoublequote}x\ {\isasymequiv}\ t{\isachardoublequote}}
wenzelm@26782
  1909
  introduce local definitions, which are inserted into the claim and
wenzelm@26782
  1910
  discharged after applying the induction rule.  Equalities reappear
wenzelm@26782
  1911
  in the inductive cases, but have been transformed according to the
wenzelm@26782
  1912
  induction principle being involved here.  In order to achieve
wenzelm@26782
  1913
  practically useful induction hypotheses, some variables occurring in
wenzelm@26782
  1914
  \isa{t} need to be fixed (see below).
wenzelm@26782
  1915
  
wenzelm@26842
  1916
  The optional ``\isa{{\isachardoublequote}arbitrary{\isacharcolon}\ x\isactrlsub {\isadigit{1}}\ {\isasymdots}\ x\isactrlsub m{\isachardoublequote}}''
wenzelm@26842
  1917
  specification generalizes variables \isa{{\isachardoublequote}x\isactrlsub {\isadigit{1}}{\isacharcomma}\ {\isasymdots}{\isacharcomma}\ x\isactrlsub m{\isachardoublequote}} of the original goal before applying induction.  Thus
wenzelm@26782
  1918
  induction hypotheses may become sufficiently general to get the
wenzelm@26782
  1919
  proof through.  Together with definitional instantiations, one may
wenzelm@26782
  1920
  effectively perform induction over expressions of a certain
wenzelm@26782
  1921
  structure.
wenzelm@26782
  1922
  
wenzelm@26842
  1923
  The optional ``\isa{{\isachardoublequote}taking{\isacharcolon}\ t\isactrlsub {\isadigit{1}}\ {\isasymdots}\ t\isactrlsub n{\isachardoublequote}}''
wenzelm@26782
  1924
  specification provides additional instantiations of a prefix of
wenzelm@26782
  1925
  pending variables in the rule.  Such schematic induction rules
wenzelm@26782
  1926
  rarely occur in practice, though.
wenzelm@26782
  1927
wenzelm@26842
  1928
  \item [\mbox{\isa{coinduct}}~\isa{{\isachardoublequote}inst\ R{\isachardoublequote}}] is analogous to the
wenzelm@26782
  1929
  \mbox{\isa{induct}} method, but refers to coinduction rules, which are
wenzelm@26782
  1930
  determined as follows:
wenzelm@26782
  1931
wenzelm@26782
  1932
  \medskip
wenzelm@26782
  1933
  \begin{tabular}{llll}
wenzelm@26788
  1934
    goal          &                    & arguments & rule \\\hline
wenzelm@26788
  1935
                  & \mbox{\isa{coinduct}} & \isa{x} & type coinduction (type of \isa{x}) \\
wenzelm@26842
  1936
    \isa{{\isachardoublequote}A\ x{\isachardoublequote}} & \mbox{\isa{coinduct}} & \isa{{\isachardoublequote}{\isasymdots}{\isachardoublequote}} & predicate/set coinduction (of \isa{A}) \\
wenzelm@26842
  1937
    \isa{{\isachardoublequote}{\isasymdots}{\isachardoublequote}}   & \mbox{\isa{coinduct}} & \isa{{\isachardoublequote}{\isasymdots}\ rule{\isacharcolon}\ R{\isachardoublequote}} & explicit rule \isa{R} \\
wenzelm@26782
  1938
  \end{tabular}
wenzelm@26782
  1939
  
wenzelm@26782
  1940
  Coinduction is the dual of induction.  Induction essentially
wenzelm@26842
  1941
  eliminates \isa{{\isachardoublequote}A\ x{\isachardoublequote}} towards a generic result \isa{{\isachardoublequote}P\ x{\isachardoublequote}},
wenzelm@26842
  1942
  while coinduction introduces \isa{{\isachardoublequote}A\ x{\isachardoublequote}} starting with \isa{{\isachardoublequote}B\ x{\isachardoublequote}}, for a suitable ``bisimulation'' \isa{B}.  The cases of a
wenzelm@26782
  1943
  coinduct rule are typically named after the predicates or sets being
wenzelm@26782
  1944
  covered, while the conclusions consist of several alternatives being
wenzelm@26782
  1945
  named after the individual destructor patterns.
wenzelm@26782
  1946
  
wenzelm@26782
  1947
  The given instantiation refers to the \emph{suffix} of variables
wenzelm@26782
  1948
  occurring in the rule's major premise, or conclusion if unavailable.
wenzelm@26842
  1949
  An additional ``\isa{{\isachardoublequote}taking{\isacharcolon}\ t\isactrlsub {\isadigit{1}}\ {\isasymdots}\ t\isactrlsub n{\isachardoublequote}}''
wenzelm@26782
  1950
  specification may be required in order to specify the bisimulation
wenzelm@26782
  1951
  to be used in the coinduction step.
wenzelm@26782
  1952
wenzelm@26782
  1953
  \end{descr}
wenzelm@26782
  1954
wenzelm@26782
  1955
  Above methods produce named local contexts, as determined by the
wenzelm@26782
  1956
  instantiated rule as given in the text.  Beyond that, the \mbox{\isa{induct}} and \mbox{\isa{coinduct}} methods guess further instantiations
wenzelm@26782
  1957
  from the goal specification itself.  Any persisting unresolved
wenzelm@26782
  1958
  schematic variables of the resulting rule will render the the
wenzelm@26782
  1959
  corresponding case invalid.  The term binding \mbox{\isa{{\isacharquery}case}} for
wenzelm@26782
  1960
  the conclusion will be provided with each case, provided that term
wenzelm@26782
  1961
  is fully specified.
wenzelm@26782
  1962
wenzelm@26782
  1963
  The \mbox{\isa{\isacommand{print{\isacharunderscore}cases}}} command prints all named cases present
wenzelm@26782
  1964
  in the current proof state.
wenzelm@26782
  1965
wenzelm@26782
  1966
  \medskip Despite the additional infrastructure, both \mbox{\isa{cases}}
wenzelm@26782
  1967
  and \mbox{\isa{coinduct}} merely apply a certain rule, after
wenzelm@26782
  1968
  instantiation, while conforming due to the usual way of monotonic
wenzelm@26842
  1969
  natural deduction: the context of a structured statement \isa{{\isachardoublequote}{\isasymAnd}x\isactrlsub {\isadigit{1}}\ {\isasymdots}\ x\isactrlsub m{\isachardot}\ {\isasymphi}\isactrlsub {\isadigit{1}}\ {\isasymLongrightarrow}\ {\isasymdots}\ {\isasymphi}\isactrlsub n\ {\isasymLongrightarrow}\ {\isasymdots}{\isachardoublequote}}
wenzelm@26782
  1970
  reappears unchanged after the case split.
wenzelm@26782
  1971
wenzelm@26782
  1972
  The \mbox{\isa{induct}} method is fundamentally different in this
wenzelm@26782
  1973
  respect: the meta-level structure is passed through the
wenzelm@26782
  1974
  ``recursive'' course involved in the induction.  Thus the original
wenzelm@26782
  1975
  statement is basically replaced by separate copies, corresponding to
wenzelm@26782
  1976
  the induction hypotheses and conclusion; the original goal context
wenzelm@26782
  1977
  is no longer available.  Thus local assumptions, fixed parameters
wenzelm@26782
  1978
  and definitions effectively participate in the inductive rephrasing
wenzelm@26782
  1979
  of the original statement.
wenzelm@26782
  1980
wenzelm@26782
  1981
  In induction proofs, local assumptions introduced by cases are split
wenzelm@26782
  1982
  into two different kinds: \isa{hyps} stemming from the rule and
wenzelm@26782
  1983
  \isa{prems} from the goal statement.  This is reflected in the
wenzelm@26782
  1984
  extracted cases accordingly, so invoking ``\mbox{\isa{\isacommand{case}}}~\isa{c}'' will provide separate facts \isa{c{\isachardot}hyps} and \isa{c{\isachardot}prems},
wenzelm@26782
  1985
  as well as fact \isa{c} to hold the all-inclusive list.
wenzelm@26782
  1986
wenzelm@26782
  1987
  \medskip Facts presented to either method are consumed according to
wenzelm@26782
  1988
  the number of ``major premises'' of the rule involved, which is
wenzelm@26782
  1989
  usually 0 for plain cases and induction rules of datatypes etc.\ and
wenzelm@26782
  1990
  1 for rules of inductive predicates or sets and the like.  The
wenzelm@26782
  1991
  remaining facts are inserted into the goal verbatim before the
wenzelm@26782
  1992
  actual \isa{cases}, \isa{induct}, or \isa{coinduct} rule is
wenzelm@26782
  1993
  applied.%
wenzelm@26782
  1994
\end{isamarkuptext}%
wenzelm@26782
  1995
\isamarkuptrue%
wenzelm@26782
  1996
%
wenzelm@26782
  1997
\isamarkupsubsubsection{Declaring rules%
wenzelm@26782
  1998
}
wenzelm@26782
  1999
\isamarkuptrue%
wenzelm@26782
  2000
%
wenzelm@26782
  2001
\begin{isamarkuptext}%
wenzelm@26782
  2002
\begin{matharray}{rcl}
wenzelm@26854
  2003
    \indexdef{}{command}{print\_induct\_rules}\mbox{\isa{\isacommand{print{\isacharunderscore}induct{\isacharunderscore}rules}}}\isa{{\isachardoublequote}\isactrlsup {\isacharasterisk}{\isachardoublequote}} & : & \isarkeep{theory~|~proof} \\
wenzelm@26782
  2004
    \indexdef{}{attribute}{cases}\mbox{\isa{cases}} & : & \isaratt \\
wenzelm@26782
  2005
    \indexdef{}{attribute}{induct}\mbox{\isa{induct}} & : & \isaratt \\
wenzelm@26782
  2006
    \indexdef{}{attribute}{coinduct}\mbox{\isa{coinduct}} & : & \isaratt \\
wenzelm@26782
  2007
  \end{matharray}
wenzelm@26782
  2008
wenzelm@26782
  2009
  \begin{rail}
wenzelm@26782
  2010
    'cases' spec
wenzelm@26782
  2011
    ;
wenzelm@26782
  2012
    'induct' spec
wenzelm@26782
  2013
    ;
wenzelm@26782
  2014
    'coinduct' spec
wenzelm@26782
  2015
    ;
wenzelm@26782
  2016
wenzelm@26782
  2017
    spec: ('type' | 'pred' | 'set') ':' nameref
wenzelm@26782
  2018
    ;
wenzelm@26782
  2019
  \end{rail}
wenzelm@26782
  2020
wenzelm@26782
  2021
  \begin{descr}
wenzelm@26782
  2022
wenzelm@26782
  2023
  \item [\mbox{\isa{\isacommand{print{\isacharunderscore}induct{\isacharunderscore}rules}}}] prints cases and induct
wenzelm@26782
  2024
  rules for predicates (or sets) and types of the current context.
wenzelm@26782
  2025
  
wenzelm@26782
  2026
  \item [\mbox{\isa{cases}}, \mbox{\isa{induct}}, and \mbox{\isa{coinduct}}] (as attributes) augment the corresponding context of
wenzelm@26782
  2027
  rules for reasoning about (co)inductive predicates (or sets) and
wenzelm@26782
  2028
  types, using the corresponding methods of the same name.  Certain
wenzelm@26782
  2029
  definitional packages of object-logics usually declare emerging
wenzelm@26782
  2030
  cases and induction rules as expected, so users rarely need to
wenzelm@26782
  2031
  intervene.
wenzelm@26782
  2032
  
wenzelm@26782
  2033
  Manual rule declarations usually refer to the \mbox{\isa{case{\isacharunderscore}names}} and \mbox{\isa{params}} attributes to adjust names of
wenzelm@26782
  2034
  cases and parameters of a rule; the \mbox{\isa{consumes}}
wenzelm@26782
  2035
  declaration is taken care of automatically: \mbox{\isa{consumes}}~\isa{{\isadigit{0}}} is specified for ``type'' rules and \mbox{\isa{consumes}}~\isa{{\isadigit{1}}} for ``predicate'' / ``set'' rules.
wenzelm@26782
  2036
wenzelm@26782
  2037
  \end{descr}%
wenzelm@26782
  2038
\end{isamarkuptext}%
wenzelm@26782
  2039
\isamarkuptrue%
wenzelm@26782
  2040
%
wenzelm@26790
  2041
\isamarkupsection{General logic setup \label{sec:object-logic}%
wenzelm@26790
  2042
}
wenzelm@26790
  2043
\isamarkuptrue%
wenzelm@26790
  2044
%
wenzelm@26790
  2045
\begin{isamarkuptext}%
wenzelm@26790
  2046
\begin{matharray}{rcl}
wenzelm@26790
  2047
    \indexdef{}{command}{judgment}\mbox{\isa{\isacommand{judgment}}} & : & \isartrans{theory}{theory} \\
wenzelm@26790
  2048
    \indexdef{}{method}{atomize}\mbox{\isa{atomize}} & : & \isarmeth \\
wenzelm@26790
  2049
    \indexdef{}{attribute}{atomize}\mbox{\isa{atomize}} & : & \isaratt \\
wenzelm@26854
  2050
    \indexdef{}{attribute}{rule\_format}\mbox{\isa{rule{\isacharunderscore}format}} & : & \isaratt \\
wenzelm@26790
  2051
    \indexdef{}{attribute}{rulify}\mbox{\isa{rulify}} & : & \isaratt \\
wenzelm@26790
  2052
  \end{matharray}
wenzelm@26790
  2053
wenzelm@26790
  2054
  The very starting point for any Isabelle object-logic is a ``truth
wenzelm@26790
  2055
  judgment'' that links object-level statements to the meta-logic
wenzelm@26790
  2056
  (with its minimal language of \isa{prop} that covers universal
wenzelm@26842
  2057
  quantification \isa{{\isachardoublequote}{\isasymAnd}{\isachardoublequote}} and implication \isa{{\isachardoublequote}{\isasymLongrightarrow}{\isachardoublequote}}).
wenzelm@26790
  2058
wenzelm@26790
  2059
  Common object-logics are sufficiently expressive to internalize rule
wenzelm@26842
  2060
  statements over \isa{{\isachardoublequote}{\isasymAnd}{\isachardoublequote}} and \isa{{\isachardoublequote}{\isasymLongrightarrow}{\isachardoublequote}} within their own
wenzelm@26790
  2061
  language.  This is useful in certain situations where a rule needs
wenzelm@26790
  2062
  to be viewed as an atomic statement from the meta-level perspective,
wenzelm@26842
  2063
  e.g.\ \isa{{\isachardoublequote}{\isasymAnd}x{\isachardot}\ x\ {\isasymin}\ A\ {\isasymLongrightarrow}\ P\ x{\isachardoublequote}} versus \isa{{\isachardoublequote}{\isasymforall}x\ {\isasymin}\ A{\isachardot}\ P\ x{\isachardoublequote}}.
wenzelm@26790
  2064
wenzelm@26790
  2065
  From the following language elements, only the \mbox{\isa{atomize}}
wenzelm@26790
  2066
  method and \mbox{\isa{rule{\isacharunderscore}format}} attribute are occasionally
wenzelm@26790
  2067
  required by end-users, the rest is for those who need to setup their
wenzelm@26790
  2068
  own object-logic.  In the latter case existing formulations of
wenzelm@26790
  2069
  Isabelle/FOL or Isabelle/HOL may be taken as realistic examples.
wenzelm@26790
  2070
wenzelm@26790
  2071
  Generic tools may refer to the information provided by object-logic
wenzelm@26790
  2072
  declarations internally.
wenzelm@26790
  2073
wenzelm@26790
  2074
  \begin{rail}
wenzelm@26790
  2075
    'judgment' constdecl
wenzelm@26790
  2076
    ;
wenzelm@26790
  2077
    'atomize' ('(' 'full' ')')?
wenzelm@26790
  2078
    ;
wenzelm@26790
  2079
    'rule\_format' ('(' 'noasm' ')')?
wenzelm@26790
  2080
    ;
wenzelm@26790
  2081
  \end{rail}
wenzelm@26790
  2082
wenzelm@26790
  2083
  \begin{descr}
wenzelm@26790
  2084
  
wenzelm@26842
  2085
  \item [\mbox{\isa{\isacommand{judgment}}}~\isa{{\isachardoublequote}c\ {\isacharcolon}{\isacharcolon}\ {\isasymsigma}\ {\isacharparenleft}mx{\isacharparenright}{\isachardoublequote}}] declares
wenzelm@26790
  2086
  constant \isa{c} as the truth judgment of the current
wenzelm@26790
  2087
  object-logic.  Its type \isa{{\isasymsigma}} should specify a coercion of the
wenzelm@26790
  2088
  category of object-level propositions to \isa{prop} of the Pure
wenzelm@26842
  2089
  meta-logic; the mixfix annotation \isa{{\isachardoublequote}{\isacharparenleft}mx{\isacharparenright}{\isachardoublequote}} would typically
wenzelm@26790
  2090
  just link the object language (internally of syntactic category
wenzelm@26790
  2091
  \isa{logic}) with that of \isa{prop}.  Only one \mbox{\isa{\isacommand{judgment}}} declaration may be given in any theory development.
wenzelm@26790
  2092
  
wenzelm@26790
  2093
  \item [\mbox{\isa{atomize}} (as a method)] rewrites any non-atomic
wenzelm@26790
  2094
  premises of a sub-goal, using the meta-level equations declared via
wenzelm@26790
  2095
  \mbox{\isa{atomize}} (as an attribute) beforehand.  As a result,
wenzelm@26790
  2096
  heavily nested goals become amenable to fundamental operations such
wenzelm@26842
  2097
  as resolution (cf.\ the \mbox{\isa{rule}} method).  Giving the ``\isa{{\isachardoublequote}{\isacharparenleft}full{\isacharparenright}{\isachardoublequote}}'' option here means to turn the whole subgoal into an
wenzelm@26790
  2098
  object-statement (if possible), including the outermost parameters
wenzelm@26790
  2099
  and assumptions as well.
wenzelm@26790
  2100
wenzelm@26790
  2101
  A typical collection of \mbox{\isa{atomize}} rules for a particular
wenzelm@26790
  2102
  object-logic would provide an internalization for each of the
wenzelm@26842
  2103
  connectives of \isa{{\isachardoublequote}{\isasymAnd}{\isachardoublequote}}, \isa{{\isachardoublequote}{\isasymLongrightarrow}{\isachardoublequote}}, and \isa{{\isachardoublequote}{\isasymequiv}{\isachardoublequote}}.
wenzelm@26790
  2104
  Meta-level conjunction should be covered as well (this is
wenzelm@26790
  2105
  particularly important for locales, see \secref{sec:locale}).
wenzelm@26790
  2106
wenzelm@26790
  2107
  \item [\mbox{\isa{rule{\isacharunderscore}format}}] rewrites a theorem by the
wenzelm@26790
  2108
  equalities declared as \mbox{\isa{rulify}} rules in the current
wenzelm@26790
  2109
  object-logic.  By default, the result is fully normalized, including
wenzelm@26842
  2110
  assumptions and conclusions at any depth.  The \isa{{\isachardoublequote}{\isacharparenleft}no{\isacharunderscore}asm{\isacharparenright}{\isachardoublequote}}
wenzelm@26790
  2111
  option restricts the transformation to the conclusion of a rule.
wenzelm@26790
  2112
wenzelm@26790
  2113
  In common object-logics (HOL, FOL, ZF), the effect of \mbox{\isa{rule{\isacharunderscore}format}} is to replace (bounded) universal quantification
wenzelm@26842
  2114
  (\isa{{\isachardoublequote}{\isasymforall}{\isachardoublequote}}) and implication (\isa{{\isachardoublequote}{\isasymlongrightarrow}{\isachardoublequote}}) by the corresponding
wenzelm@26842
  2115
  rule statements over \isa{{\isachardoublequote}{\isasymAnd}{\isachardoublequote}} and \isa{{\isachardoublequote}{\isasymLongrightarrow}{\isachardoublequote}}.
wenzelm@26790
  2116
wenzelm@26790
  2117
  \end{descr}%
wenzelm@26790
  2118
\end{isamarkuptext}%
wenzelm@26790
  2119
\isamarkuptrue%
wenzelm@26790
  2120
%
wenzelm@26782
  2121
\isadelimtheory
wenzelm@26782
  2122
%
wenzelm@26782
  2123
\endisadelimtheory
wenzelm@26782
  2124
%
wenzelm@26782
  2125
\isatagtheory
wenzelm@26782
  2126
\isacommand{end}\isamarkupfalse%
wenzelm@26782
  2127
%
wenzelm@26782
  2128
\endisatagtheory
wenzelm@26782
  2129
{\isafoldtheory}%
wenzelm@26782
  2130
%
wenzelm@26782
  2131
\isadelimtheory
wenzelm@26782
  2132
%
wenzelm@26782
  2133
\endisadelimtheory
wenzelm@26782
  2134
\isanewline
wenzelm@26782
  2135
\end{isabellebody}%
wenzelm@26782
  2136
%%% Local Variables:
wenzelm@26782
  2137
%%% mode: latex
wenzelm@26782
  2138
%%% TeX-master: "root"
wenzelm@26782
  2139
%%% End: