doc-src/IsarImplementation/Thy/document/logic.tex
author wenzelm
Fri, 15 Sep 2006 16:49:41 +0200
changeset 20543 dc294418ff17
parent 20542 a54ca4e90874
child 20547 796ae7fa1049
permissions -rw-r--r--
tuned;
wenzelm@18537
     1
%
wenzelm@18537
     2
\begin{isabellebody}%
wenzelm@18537
     3
\def\isabellecontext{logic}%
wenzelm@18537
     4
%
wenzelm@18537
     5
\isadelimtheory
wenzelm@18537
     6
\isanewline
wenzelm@18537
     7
\isanewline
wenzelm@18537
     8
\isanewline
wenzelm@18537
     9
%
wenzelm@18537
    10
\endisadelimtheory
wenzelm@18537
    11
%
wenzelm@18537
    12
\isatagtheory
wenzelm@18537
    13
\isacommand{theory}\isamarkupfalse%
wenzelm@18537
    14
\ logic\ \isakeyword{imports}\ base\ \isakeyword{begin}%
wenzelm@18537
    15
\endisatagtheory
wenzelm@18537
    16
{\isafoldtheory}%
wenzelm@18537
    17
%
wenzelm@18537
    18
\isadelimtheory
wenzelm@18537
    19
%
wenzelm@18537
    20
\endisadelimtheory
wenzelm@18537
    21
%
wenzelm@20471
    22
\isamarkupchapter{Primitive logic \label{ch:logic}%
wenzelm@18537
    23
}
wenzelm@18537
    24
\isamarkuptrue%
wenzelm@18537
    25
%
wenzelm@20481
    26
\begin{isamarkuptext}%
wenzelm@20481
    27
The logical foundations of Isabelle/Isar are that of the Pure logic,
wenzelm@20481
    28
  which has been introduced as a natural-deduction framework in
wenzelm@20493
    29
  \cite{paulson700}.  This is essentially the same logic as ``\isa{{\isasymlambda}HOL}'' in the more abstract setting of Pure Type Systems (PTS)
wenzelm@20481
    30
  \cite{Barendregt-Geuvers:2001}, although there are some key
wenzelm@20491
    31
  differences in the specific treatment of simple types in
wenzelm@20491
    32
  Isabelle/Pure.
wenzelm@20481
    33
wenzelm@20481
    34
  Following type-theoretic parlance, the Pure logic consists of three
wenzelm@20543
    35
  levels of \isa{{\isasymlambda}}-calculus with corresponding arrows, \isa{{\isasymRightarrow}} for syntactic function space (terms depending on terms), \isa{{\isasymAnd}} for universal quantification (proofs depending on terms), and
wenzelm@20481
    36
  \isa{{\isasymLongrightarrow}} for implication (proofs depending on proofs).
wenzelm@20481
    37
wenzelm@20537
    38
  Derivations are relative to a logical theory, which declares type
wenzelm@20537
    39
  constructors, constants, and axioms.  Theory declarations support
wenzelm@20537
    40
  schematic polymorphism, which is strictly speaking outside the
wenzelm@20537
    41
  logic.\footnote{This is the deeper logical reason, why the theory
wenzelm@20537
    42
  context \isa{{\isasymTheta}} is separate from the proof context \isa{{\isasymGamma}}
wenzelm@20537
    43
  of the core calculus.}%
wenzelm@20481
    44
\end{isamarkuptext}%
wenzelm@20481
    45
\isamarkuptrue%
wenzelm@20481
    46
%
wenzelm@20451
    47
\isamarkupsection{Types \label{sec:types}%
wenzelm@18537
    48
}
wenzelm@18537
    49
\isamarkuptrue%
wenzelm@18537
    50
%
wenzelm@18537
    51
\begin{isamarkuptext}%
wenzelm@20481
    52
The language of types is an uninterpreted order-sorted first-order
wenzelm@20481
    53
  algebra; types are qualified by ordered type classes.
wenzelm@18537
    54
wenzelm@20481
    55
  \medskip A \emph{type class} is an abstract syntactic entity
wenzelm@20481
    56
  declared in the theory context.  The \emph{subclass relation} \isa{c\isactrlisub {\isadigit{1}}\ {\isasymsubseteq}\ c\isactrlisub {\isadigit{2}}} is specified by stating an acyclic
wenzelm@20491
    57
  generating relation; the transitive closure is maintained
wenzelm@20491
    58
  internally.  The resulting relation is an ordering: reflexive,
wenzelm@20491
    59
  transitive, and antisymmetric.
wenzelm@20451
    60
wenzelm@20537
    61
  A \emph{sort} is a list of type classes written as \isa{s\ {\isacharequal}\ {\isacharbraceleft}c\isactrlisub {\isadigit{1}}{\isacharcomma}\ {\isasymdots}{\isacharcomma}\ c\isactrlisub m{\isacharbraceright}}, which represents symbolic
wenzelm@20481
    62
  intersection.  Notationally, the curly braces are omitted for
wenzelm@20481
    63
  singleton intersections, i.e.\ any class \isa{c} may be read as
wenzelm@20481
    64
  a sort \isa{{\isacharbraceleft}c{\isacharbraceright}}.  The ordering on type classes is extended to
wenzelm@20491
    65
  sorts according to the meaning of intersections: \isa{{\isacharbraceleft}c\isactrlisub {\isadigit{1}}{\isacharcomma}\ {\isasymdots}\ c\isactrlisub m{\isacharbraceright}\ {\isasymsubseteq}\ {\isacharbraceleft}d\isactrlisub {\isadigit{1}}{\isacharcomma}\ {\isasymdots}{\isacharcomma}\ d\isactrlisub n{\isacharbraceright}} iff
wenzelm@20491
    66
  \isa{{\isasymforall}j{\isachardot}\ {\isasymexists}i{\isachardot}\ c\isactrlisub i\ {\isasymsubseteq}\ d\isactrlisub j}.  The empty intersection
wenzelm@20491
    67
  \isa{{\isacharbraceleft}{\isacharbraceright}} refers to the universal sort, which is the largest
wenzelm@20491
    68
  element wrt.\ the sort order.  The intersections of all (finitely
wenzelm@20491
    69
  many) classes declared in the current theory are the minimal
wenzelm@20491
    70
  elements wrt.\ the sort order.
wenzelm@20451
    71
wenzelm@20491
    72
  \medskip A \emph{fixed type variable} is a pair of a basic name
wenzelm@20537
    73
  (starting with a \isa{{\isacharprime}} character) and a sort constraint, e.g.\
wenzelm@20537
    74
  \isa{{\isacharparenleft}{\isacharprime}a{\isacharcomma}\ s{\isacharparenright}} which is usually printed as \isa{{\isasymalpha}\isactrlisub s}.
wenzelm@20537
    75
  A \emph{schematic type variable} is a pair of an indexname and a
wenzelm@20537
    76
  sort constraint, e.g.\ \isa{{\isacharparenleft}{\isacharparenleft}{\isacharprime}a{\isacharcomma}\ {\isadigit{0}}{\isacharparenright}{\isacharcomma}\ s{\isacharparenright}} which is usually
wenzelm@20537
    77
  printed as \isa{{\isacharquery}{\isasymalpha}\isactrlisub s}.
wenzelm@20451
    78
wenzelm@20481
    79
  Note that \emph{all} syntactic components contribute to the identity
wenzelm@20493
    80
  of type variables, including the sort constraint.  The core logic
wenzelm@20493
    81
  handles type variables with the same name but different sorts as
wenzelm@20493
    82
  different, although some outer layers of the system make it hard to
wenzelm@20493
    83
  produce anything like this.
wenzelm@20451
    84
wenzelm@20493
    85
  A \emph{type constructor} \isa{{\isasymkappa}} is a \isa{k}-ary operator
wenzelm@20493
    86
  on types declared in the theory.  Type constructor application is
wenzelm@20537
    87
  written postfix as \isa{{\isacharparenleft}{\isasymalpha}\isactrlisub {\isadigit{1}}{\isacharcomma}\ {\isasymdots}{\isacharcomma}\ {\isasymalpha}\isactrlisub k{\isacharparenright}{\isasymkappa}}.  For
wenzelm@20537
    88
  \isa{k\ {\isacharequal}\ {\isadigit{0}}} the argument tuple is omitted, e.g.\ \isa{prop}
wenzelm@20537
    89
  instead of \isa{{\isacharparenleft}{\isacharparenright}prop}.  For \isa{k\ {\isacharequal}\ {\isadigit{1}}} the parentheses
wenzelm@20537
    90
  are omitted, e.g.\ \isa{{\isasymalpha}\ list} instead of \isa{{\isacharparenleft}{\isasymalpha}{\isacharparenright}list}.
wenzelm@20537
    91
  Further notation is provided for specific constructors, notably the
wenzelm@20537
    92
  right-associative infix \isa{{\isasymalpha}\ {\isasymRightarrow}\ {\isasymbeta}} instead of \isa{{\isacharparenleft}{\isasymalpha}{\isacharcomma}\ {\isasymbeta}{\isacharparenright}fun}.
wenzelm@20481
    93
  
wenzelm@20537
    94
  A \emph{type} is defined inductively over type variables and type
wenzelm@20543
    95
  constructors as follows: \isa{{\isasymtau}\ {\isacharequal}\ {\isasymalpha}\isactrlisub s\ {\isacharbar}\ {\isacharquery}{\isasymalpha}\isactrlisub s\ {\isacharbar}\ {\isacharparenleft}{\isasymtau}\isactrlsub {\isadigit{1}}{\isacharcomma}\ {\isasymdots}{\isacharcomma}\ {\isasymtau}\isactrlsub k{\isacharparenright}{\isasymkappa}}.
wenzelm@20451
    96
wenzelm@20514
    97
  A \emph{type abbreviation} is a syntactic definition \isa{{\isacharparenleft}\isactrlvec {\isasymalpha}{\isacharparenright}{\isasymkappa}\ {\isacharequal}\ {\isasymtau}} of an arbitrary type expression \isa{{\isasymtau}} over
wenzelm@20537
    98
  variables \isa{\isactrlvec {\isasymalpha}}.  Type abbreviations appear as type
wenzelm@20537
    99
  constructors in the syntax, but are expanded before entering the
wenzelm@20537
   100
  logical core.
wenzelm@20451
   101
wenzelm@20481
   102
  A \emph{type arity} declares the image behavior of a type
wenzelm@20494
   103
  constructor wrt.\ the algebra of sorts: \isa{{\isasymkappa}\ {\isacharcolon}{\isacharcolon}\ {\isacharparenleft}s\isactrlisub {\isadigit{1}}{\isacharcomma}\ {\isasymdots}{\isacharcomma}\ s\isactrlisub k{\isacharparenright}s} means that \isa{{\isacharparenleft}{\isasymtau}\isactrlisub {\isadigit{1}}{\isacharcomma}\ {\isasymdots}{\isacharcomma}\ {\isasymtau}\isactrlisub k{\isacharparenright}{\isasymkappa}} is
wenzelm@20494
   104
  of sort \isa{s} if every argument type \isa{{\isasymtau}\isactrlisub i} is
wenzelm@20494
   105
  of sort \isa{s\isactrlisub i}.  Arity declarations are implicitly
wenzelm@20494
   106
  completed, i.e.\ \isa{{\isasymkappa}\ {\isacharcolon}{\isacharcolon}\ {\isacharparenleft}\isactrlvec s{\isacharparenright}c} entails \isa{{\isasymkappa}\ {\isacharcolon}{\isacharcolon}\ {\isacharparenleft}\isactrlvec s{\isacharparenright}c{\isacharprime}} for any \isa{c{\isacharprime}\ {\isasymsupseteq}\ c}.
wenzelm@20451
   107
wenzelm@20491
   108
  \medskip The sort algebra is always maintained as \emph{coregular},
wenzelm@20491
   109
  which means that type arities are consistent with the subclass
wenzelm@20537
   110
  relation: for any type constructor \isa{{\isasymkappa}}, and classes \isa{c\isactrlisub {\isadigit{1}}\ {\isasymsubseteq}\ c\isactrlisub {\isadigit{2}}}, and arities \isa{{\isasymkappa}\ {\isacharcolon}{\isacharcolon}\ {\isacharparenleft}\isactrlvec s\isactrlisub {\isadigit{1}}{\isacharparenright}c\isactrlisub {\isadigit{1}}} and \isa{{\isasymkappa}\ {\isacharcolon}{\isacharcolon}\ {\isacharparenleft}\isactrlvec s\isactrlisub {\isadigit{2}}{\isacharparenright}c\isactrlisub {\isadigit{2}}} holds \isa{\isactrlvec s\isactrlisub {\isadigit{1}}\ {\isasymsubseteq}\ \isactrlvec s\isactrlisub {\isadigit{2}}} component-wise.
wenzelm@20491
   111
wenzelm@20491
   112
  The key property of a coregular order-sorted algebra is that sort
wenzelm@20537
   113
  constraints can be solved in a most general fashion: for each type
wenzelm@20537
   114
  constructor \isa{{\isasymkappa}} and sort \isa{s} there is a most general
wenzelm@20537
   115
  vector of argument sorts \isa{{\isacharparenleft}s\isactrlisub {\isadigit{1}}{\isacharcomma}\ {\isasymdots}{\isacharcomma}\ s\isactrlisub k{\isacharparenright}} such
wenzelm@20537
   116
  that a type scheme \isa{{\isacharparenleft}{\isasymalpha}\isactrlbsub s\isactrlisub {\isadigit{1}}\isactrlesub {\isacharcomma}\ {\isasymdots}{\isacharcomma}\ {\isasymalpha}\isactrlbsub s\isactrlisub k\isactrlesub {\isacharparenright}{\isasymkappa}} is of sort \isa{s}.
wenzelm@20543
   117
  Consequently, type unification has most general solutions (modulo
wenzelm@20543
   118
  equivalence of sorts), so type-inference produces primary types as
wenzelm@20543
   119
  expected \cite{nipkow-prehofer}.%
wenzelm@18537
   120
\end{isamarkuptext}%
wenzelm@18537
   121
\isamarkuptrue%
wenzelm@18537
   122
%
wenzelm@20481
   123
\isadelimmlref
wenzelm@20481
   124
%
wenzelm@20481
   125
\endisadelimmlref
wenzelm@20481
   126
%
wenzelm@20481
   127
\isatagmlref
wenzelm@20481
   128
%
wenzelm@20481
   129
\begin{isamarkuptext}%
wenzelm@20481
   130
\begin{mldecls}
wenzelm@20481
   131
  \indexmltype{class}\verb|type class| \\
wenzelm@20481
   132
  \indexmltype{sort}\verb|type sort| \\
wenzelm@20494
   133
  \indexmltype{arity}\verb|type arity| \\
wenzelm@20481
   134
  \indexmltype{typ}\verb|type typ| \\
wenzelm@20519
   135
  \indexml{map-atyps}\verb|map_atyps: (typ -> typ) -> typ -> typ| \\
wenzelm@20494
   136
  \indexml{fold-atyps}\verb|fold_atyps: (typ -> 'a -> 'a) -> typ -> 'a -> 'a| \\
wenzelm@20481
   137
  \indexml{Sign.subsort}\verb|Sign.subsort: theory -> sort * sort -> bool| \\
wenzelm@20481
   138
  \indexml{Sign.of-sort}\verb|Sign.of_sort: theory -> typ * sort -> bool| \\
wenzelm@20520
   139
  \indexml{Sign.add-types}\verb|Sign.add_types: (string * int * mixfix) list -> theory -> theory| \\
wenzelm@20481
   140
  \indexml{Sign.add-tyabbrs-i}\verb|Sign.add_tyabbrs_i: |\isasep\isanewline%
wenzelm@20520
   141
\verb|  (string * string list * typ * mixfix) list -> theory -> theory| \\
wenzelm@20481
   142
  \indexml{Sign.primitive-class}\verb|Sign.primitive_class: string * class list -> theory -> theory| \\
wenzelm@20481
   143
  \indexml{Sign.primitive-classrel}\verb|Sign.primitive_classrel: class * class -> theory -> theory| \\
wenzelm@20481
   144
  \indexml{Sign.primitive-arity}\verb|Sign.primitive_arity: arity -> theory -> theory| \\
wenzelm@20481
   145
  \end{mldecls}
wenzelm@20481
   146
wenzelm@20481
   147
  \begin{description}
wenzelm@20481
   148
wenzelm@20481
   149
  \item \verb|class| represents type classes; this is an alias for
wenzelm@20481
   150
  \verb|string|.
wenzelm@20481
   151
wenzelm@20481
   152
  \item \verb|sort| represents sorts; this is an alias for
wenzelm@20481
   153
  \verb|class list|.
wenzelm@20481
   154
wenzelm@20481
   155
  \item \verb|arity| represents type arities; this is an alias for
wenzelm@20494
   156
  triples of the form \isa{{\isacharparenleft}{\isasymkappa}{\isacharcomma}\ \isactrlvec s{\isacharcomma}\ s{\isacharparenright}} for \isa{{\isasymkappa}\ {\isacharcolon}{\isacharcolon}\ {\isacharparenleft}\isactrlvec s{\isacharparenright}s} described above.
wenzelm@20481
   157
wenzelm@20481
   158
  \item \verb|typ| represents types; this is a datatype with
wenzelm@20481
   159
  constructors \verb|TFree|, \verb|TVar|, \verb|Type|.
wenzelm@20481
   160
wenzelm@20537
   161
  \item \verb|map_atyps|~\isa{f\ {\isasymtau}} applies the mapping \isa{f}
wenzelm@20537
   162
  to all atomic types (\verb|TFree|, \verb|TVar|) occurring in \isa{{\isasymtau}}.
wenzelm@20519
   163
wenzelm@20537
   164
  \item \verb|fold_atyps|~\isa{f\ {\isasymtau}} iterates the operation \isa{f} over all occurrences of atomic types (\verb|TFree|, \verb|TVar|)
wenzelm@20537
   165
  in \isa{{\isasymtau}}; the type structure is traversed from left to right.
wenzelm@20494
   166
wenzelm@20481
   167
  \item \verb|Sign.subsort|~\isa{thy\ {\isacharparenleft}s\isactrlisub {\isadigit{1}}{\isacharcomma}\ s\isactrlisub {\isadigit{2}}{\isacharparenright}}
wenzelm@20481
   168
  tests the subsort relation \isa{s\isactrlisub {\isadigit{1}}\ {\isasymsubseteq}\ s\isactrlisub {\isadigit{2}}}.
wenzelm@20481
   169
wenzelm@20537
   170
  \item \verb|Sign.of_sort|~\isa{thy\ {\isacharparenleft}{\isasymtau}{\isacharcomma}\ s{\isacharparenright}} tests whether type
wenzelm@20537
   171
  \isa{{\isasymtau}} is of sort \isa{s}.
wenzelm@20481
   172
wenzelm@20537
   173
  \item \verb|Sign.add_types|~\isa{{\isacharbrackleft}{\isacharparenleft}{\isasymkappa}{\isacharcomma}\ k{\isacharcomma}\ mx{\isacharparenright}{\isacharcomma}\ {\isasymdots}{\isacharbrackright}} declares a new
wenzelm@20494
   174
  type constructors \isa{{\isasymkappa}} with \isa{k} arguments and
wenzelm@20481
   175
  optional mixfix syntax.
wenzelm@20481
   176
wenzelm@20494
   177
  \item \verb|Sign.add_tyabbrs_i|~\isa{{\isacharbrackleft}{\isacharparenleft}{\isasymkappa}{\isacharcomma}\ \isactrlvec {\isasymalpha}{\isacharcomma}\ {\isasymtau}{\isacharcomma}\ mx{\isacharparenright}{\isacharcomma}\ {\isasymdots}{\isacharbrackright}}
wenzelm@20494
   178
  defines a new type abbreviation \isa{{\isacharparenleft}\isactrlvec {\isasymalpha}{\isacharparenright}{\isasymkappa}\ {\isacharequal}\ {\isasymtau}} with
wenzelm@20491
   179
  optional mixfix syntax.
wenzelm@20481
   180
wenzelm@20537
   181
  \item \verb|Sign.primitive_class|~\isa{{\isacharparenleft}c{\isacharcomma}\ {\isacharbrackleft}c\isactrlisub {\isadigit{1}}{\isacharcomma}\ {\isasymdots}{\isacharcomma}\ c\isactrlisub n{\isacharbrackright}{\isacharparenright}} declares a new class \isa{c}, together with class
wenzelm@20494
   182
  relations \isa{c\ {\isasymsubseteq}\ c\isactrlisub i}, for \isa{i\ {\isacharequal}\ {\isadigit{1}}{\isacharcomma}\ {\isasymdots}{\isacharcomma}\ n}.
wenzelm@20481
   183
wenzelm@20543
   184
  \item \verb|Sign.primitive_classrel|~\isa{{\isacharparenleft}c\isactrlisub {\isadigit{1}}{\isacharcomma}\ c\isactrlisub {\isadigit{2}}{\isacharparenright}} declares the class relation \isa{c\isactrlisub {\isadigit{1}}\ {\isasymsubseteq}\ c\isactrlisub {\isadigit{2}}}.
wenzelm@20481
   185
wenzelm@20494
   186
  \item \verb|Sign.primitive_arity|~\isa{{\isacharparenleft}{\isasymkappa}{\isacharcomma}\ \isactrlvec s{\isacharcomma}\ s{\isacharparenright}} declares
wenzelm@20537
   187
  the arity \isa{{\isasymkappa}\ {\isacharcolon}{\isacharcolon}\ {\isacharparenleft}\isactrlvec s{\isacharparenright}s}.
wenzelm@20481
   188
wenzelm@20481
   189
  \end{description}%
wenzelm@20481
   190
\end{isamarkuptext}%
wenzelm@20481
   191
\isamarkuptrue%
wenzelm@20481
   192
%
wenzelm@20481
   193
\endisatagmlref
wenzelm@20481
   194
{\isafoldmlref}%
wenzelm@20481
   195
%
wenzelm@20481
   196
\isadelimmlref
wenzelm@20481
   197
%
wenzelm@20481
   198
\endisadelimmlref
wenzelm@20481
   199
%
wenzelm@20451
   200
\isamarkupsection{Terms \label{sec:terms}%
wenzelm@18537
   201
}
wenzelm@18537
   202
\isamarkuptrue%
wenzelm@18537
   203
%
wenzelm@18537
   204
\begin{isamarkuptext}%
wenzelm@20451
   205
\glossary{Term}{FIXME}
wenzelm@18537
   206
wenzelm@20491
   207
  The language of terms is that of simply-typed \isa{{\isasymlambda}}-calculus
wenzelm@20520
   208
  with de-Bruijn indices for bound variables (cf.\ \cite{debruijn72}
wenzelm@20537
   209
  or \cite{paulson-ml2}), with the types being determined determined
wenzelm@20537
   210
  by the corresponding binders.  In contrast, free variables and
wenzelm@20537
   211
  constants are have an explicit name and type in each occurrence.
wenzelm@20491
   212
wenzelm@20514
   213
  \medskip A \emph{bound variable} is a natural number \isa{b},
wenzelm@20537
   214
  which accounts for the number of intermediate binders between the
wenzelm@20537
   215
  variable occurrence in the body and its binding position.  For
wenzelm@20543
   216
  example, the de-Bruijn term \isa{{\isasymlambda}\isactrlbsub nat\isactrlesub {\isachardot}\ {\isasymlambda}\isactrlbsub nat\isactrlesub {\isachardot}\ {\isadigit{1}}\ {\isacharplus}\ {\isadigit{0}}} would
wenzelm@20543
   217
  correspond to \isa{{\isasymlambda}x\isactrlbsub nat\isactrlesub {\isachardot}\ {\isasymlambda}y\isactrlbsub nat\isactrlesub {\isachardot}\ x\ {\isacharplus}\ y} in a named
wenzelm@20543
   218
  representation.  Note that a bound variable may be represented by
wenzelm@20543
   219
  different de-Bruijn indices at different occurrences, depending on
wenzelm@20543
   220
  the nesting of abstractions.
wenzelm@20481
   221
wenzelm@20543
   222
  A \emph{loose variable} is a bound variable that is outside the
wenzelm@20537
   223
  scope of local binders.  The types (and names) for loose variables
wenzelm@20543
   224
  can be managed as a separate context, that is maintained as a stack
wenzelm@20543
   225
  of hypothetical binders.  The core logic operates on closed terms,
wenzelm@20543
   226
  without any loose variables.
wenzelm@20481
   227
wenzelm@20537
   228
  A \emph{fixed variable} is a pair of a basic name and a type, e.g.\
wenzelm@20537
   229
  \isa{{\isacharparenleft}x{\isacharcomma}\ {\isasymtau}{\isacharparenright}} which is usually printed \isa{x\isactrlisub {\isasymtau}}.  A
wenzelm@20537
   230
  \emph{schematic variable} is a pair of an indexname and a type,
wenzelm@20537
   231
  e.g.\ \isa{{\isacharparenleft}{\isacharparenleft}x{\isacharcomma}\ {\isadigit{0}}{\isacharparenright}{\isacharcomma}\ {\isasymtau}{\isacharparenright}} which is usually printed as \isa{{\isacharquery}x\isactrlisub {\isasymtau}}.
wenzelm@20499
   232
wenzelm@20537
   233
  \medskip A \emph{constant} is a pair of a basic name and a type,
wenzelm@20537
   234
  e.g.\ \isa{{\isacharparenleft}c{\isacharcomma}\ {\isasymtau}{\isacharparenright}} which is usually printed as \isa{c\isactrlisub {\isasymtau}}.  Constants are declared in the context as polymorphic
wenzelm@20543
   235
  families \isa{c\ {\isacharcolon}{\isacharcolon}\ {\isasymsigma}}, meaning that all substitution instances
wenzelm@20543
   236
  \isa{c\isactrlisub {\isasymtau}} for \isa{{\isasymtau}\ {\isacharequal}\ {\isasymsigma}{\isasymvartheta}} are valid.
wenzelm@20537
   237
wenzelm@20537
   238
  The vector of \emph{type arguments} of constant \isa{c\isactrlisub {\isasymtau}}
wenzelm@20537
   239
  wrt.\ the declaration \isa{c\ {\isacharcolon}{\isacharcolon}\ {\isasymsigma}} is defined as the codomain of
wenzelm@20537
   240
  the matcher \isa{{\isasymvartheta}\ {\isacharequal}\ {\isacharbraceleft}{\isacharquery}{\isasymalpha}\isactrlisub {\isadigit{1}}\ {\isasymmapsto}\ {\isasymtau}\isactrlisub {\isadigit{1}}{\isacharcomma}\ {\isasymdots}{\isacharcomma}\ {\isacharquery}{\isasymalpha}\isactrlisub n\ {\isasymmapsto}\ {\isasymtau}\isactrlisub n{\isacharbraceright}} presented in canonical order \isa{{\isacharparenleft}{\isasymtau}\isactrlisub {\isadigit{1}}{\isacharcomma}\ {\isasymdots}{\isacharcomma}\ {\isasymtau}\isactrlisub n{\isacharparenright}}.  Within a given theory context,
wenzelm@20537
   241
  there is a one-to-one correspondence between any constant \isa{c\isactrlisub {\isasymtau}} and the application \isa{c{\isacharparenleft}{\isasymtau}\isactrlisub {\isadigit{1}}{\isacharcomma}\ {\isasymdots}{\isacharcomma}\ {\isasymtau}\isactrlisub n{\isacharparenright}} of its type arguments.  For example, with \isa{plus\ {\isacharcolon}{\isacharcolon}\ {\isasymalpha}\ {\isasymRightarrow}\ {\isasymalpha}\ {\isasymRightarrow}\ {\isasymalpha}}, the instance \isa{plus\isactrlbsub nat\ {\isasymRightarrow}\ nat\ {\isasymRightarrow}\ nat\isactrlesub } corresponds to \isa{plus{\isacharparenleft}nat{\isacharparenright}}.
wenzelm@20514
   242
wenzelm@20514
   243
  Constant declarations \isa{c\ {\isacharcolon}{\isacharcolon}\ {\isasymsigma}} may contain sort constraints
wenzelm@20514
   244
  for type variables in \isa{{\isasymsigma}}.  These are observed by
wenzelm@20514
   245
  type-inference as expected, but \emph{ignored} by the core logic.
wenzelm@20514
   246
  This means the primitive logic is able to reason with instances of
wenzelm@20537
   247
  polymorphic constants that the user-level type-checker would reject
wenzelm@20537
   248
  due to violation of type class restrictions.
wenzelm@20514
   249
wenzelm@20543
   250
  \medskip An \emph{atomic} term is either a variable or constant.  A
wenzelm@20543
   251
  \emph{term} is defined inductively over atomic terms, with
wenzelm@20543
   252
  abstraction and application as follows: \isa{t\ {\isacharequal}\ b\ {\isacharbar}\ x\isactrlisub {\isasymtau}\ {\isacharbar}\ {\isacharquery}x\isactrlisub {\isasymtau}\ {\isacharbar}\ c\isactrlisub {\isasymtau}\ {\isacharbar}\ {\isasymlambda}\isactrlisub {\isasymtau}{\isachardot}\ t\ {\isacharbar}\ t\isactrlisub {\isadigit{1}}\ t\isactrlisub {\isadigit{2}}}.
wenzelm@20543
   253
  Parsing and printing takes care of converting between an external
wenzelm@20543
   254
  representation with named bound variables.  Subsequently, we shall
wenzelm@20543
   255
  use the latter notation instead of internal de-Bruijn
wenzelm@20543
   256
  representation.
wenzelm@20514
   257
wenzelm@20537
   258
  The inductive relation \isa{t\ {\isacharcolon}{\isacharcolon}\ {\isasymtau}} assigns a (unique) type to a
wenzelm@20537
   259
  term according to the structure of atomic terms, abstractions, and
wenzelm@20537
   260
  applicatins:
wenzelm@20499
   261
  \[
wenzelm@20502
   262
  \infer{\isa{a\isactrlisub {\isasymtau}\ {\isacharcolon}{\isacharcolon}\ {\isasymtau}}}{}
wenzelm@20499
   263
  \qquad
wenzelm@20502
   264
  \infer{\isa{{\isacharparenleft}{\isasymlambda}x\isactrlsub {\isasymtau}{\isachardot}\ t{\isacharparenright}\ {\isacharcolon}{\isacharcolon}\ {\isasymtau}\ {\isasymRightarrow}\ {\isasymsigma}}}{\isa{t\ {\isacharcolon}{\isacharcolon}\ {\isasymsigma}}}
wenzelm@20502
   265
  \qquad
wenzelm@20502
   266
  \infer{\isa{t\ u\ {\isacharcolon}{\isacharcolon}\ {\isasymsigma}}}{\isa{t\ {\isacharcolon}{\isacharcolon}\ {\isasymtau}\ {\isasymRightarrow}\ {\isasymsigma}} & \isa{u\ {\isacharcolon}{\isacharcolon}\ {\isasymtau}}}
wenzelm@20514
   267
  \]
wenzelm@20514
   268
  A \emph{well-typed term} is a term that can be typed according to these rules.
wenzelm@20514
   269
wenzelm@20514
   270
  Typing information can be omitted: type-inference is able to
wenzelm@20514
   271
  reconstruct the most general type of a raw term, while assigning
wenzelm@20514
   272
  most general types to all of its variables and constants.
wenzelm@20514
   273
  Type-inference depends on a context of type constraints for fixed
wenzelm@20514
   274
  variables, and declarations for polymorphic constants.
wenzelm@20514
   275
wenzelm@20537
   276
  The identity of atomic terms consists both of the name and the type
wenzelm@20537
   277
  component.  This means that different variables \isa{x\isactrlbsub {\isasymtau}\isactrlisub {\isadigit{1}}\isactrlesub } and \isa{x\isactrlbsub {\isasymtau}\isactrlisub {\isadigit{2}}\isactrlesub } may become the same after type
wenzelm@20537
   278
  instantiation.  Some outer layers of the system make it hard to
wenzelm@20537
   279
  produce variables of the same name, but different types.  In
wenzelm@20543
   280
  contrast, mixed instances of polymorphic constants occur frequently.
wenzelm@20514
   281
wenzelm@20514
   282
  \medskip The \emph{hidden polymorphism} of a term \isa{t\ {\isacharcolon}{\isacharcolon}\ {\isasymsigma}}
wenzelm@20514
   283
  is the set of type variables occurring in \isa{t}, but not in
wenzelm@20537
   284
  \isa{{\isasymsigma}}.  This means that the term implicitly depends on type
wenzelm@20543
   285
  arguments that are not accounted in the result type, i.e.\ there are
wenzelm@20537
   286
  different type instances \isa{t{\isasymvartheta}\ {\isacharcolon}{\isacharcolon}\ {\isasymsigma}} and \isa{t{\isasymvartheta}{\isacharprime}\ {\isacharcolon}{\isacharcolon}\ {\isasymsigma}} with the same type.  This slightly
wenzelm@20543
   287
  pathological situation notoriously demands additional care.
wenzelm@20514
   288
wenzelm@20537
   289
  \medskip A \emph{term abbreviation} is a syntactic definition \isa{c\isactrlisub {\isasymsigma}\ {\isasymequiv}\ t} of a closed term \isa{t} of type \isa{{\isasymsigma}},
wenzelm@20537
   290
  without any hidden polymorphism.  A term abbreviation looks like a
wenzelm@20543
   291
  constant in the syntax, but is expanded before entering the logical
wenzelm@20543
   292
  core.  Abbreviations are usually reverted when printing terms, using
wenzelm@20543
   293
  \isa{t\ {\isasymrightarrow}\ c\isactrlisub {\isasymsigma}} as rules for higher-order rewriting.
wenzelm@20519
   294
wenzelm@20537
   295
  \medskip Canonical operations on \isa{{\isasymlambda}}-terms include \isa{{\isasymalpha}{\isasymbeta}{\isasymeta}}-conversion: \isa{{\isasymalpha}}-conversion refers to capture-free
wenzelm@20519
   296
  renaming of bound variables; \isa{{\isasymbeta}}-conversion contracts an
wenzelm@20537
   297
  abstraction applied to an argument term, substituting the argument
wenzelm@20519
   298
  in the body: \isa{{\isacharparenleft}{\isasymlambda}x{\isachardot}\ b{\isacharparenright}a} becomes \isa{b{\isacharbrackleft}a{\isacharslash}x{\isacharbrackright}}; \isa{{\isasymeta}}-conversion contracts vacuous application-abstraction: \isa{{\isasymlambda}x{\isachardot}\ f\ x} becomes \isa{f}, provided that the bound variable
wenzelm@20537
   299
  does not occur in \isa{f}.
wenzelm@20519
   300
wenzelm@20537
   301
  Terms are normally treated modulo \isa{{\isasymalpha}}-conversion, which is
wenzelm@20537
   302
  implicit in the de-Bruijn representation.  Names for bound variables
wenzelm@20537
   303
  in abstractions are maintained separately as (meaningless) comments,
wenzelm@20537
   304
  mostly for parsing and printing.  Full \isa{{\isasymalpha}{\isasymbeta}{\isasymeta}}-conversion is
wenzelm@20543
   305
  commonplace in various standard operations (\secref{sec:rules}) that
wenzelm@20537
   306
  are based on higher-order unification and matching.%
wenzelm@18537
   307
\end{isamarkuptext}%
wenzelm@18537
   308
\isamarkuptrue%
wenzelm@18537
   309
%
wenzelm@20514
   310
\isadelimmlref
wenzelm@20514
   311
%
wenzelm@20514
   312
\endisadelimmlref
wenzelm@20514
   313
%
wenzelm@20514
   314
\isatagmlref
wenzelm@20514
   315
%
wenzelm@18537
   316
\begin{isamarkuptext}%
wenzelm@20514
   317
\begin{mldecls}
wenzelm@20514
   318
  \indexmltype{term}\verb|type term| \\
wenzelm@20519
   319
  \indexml{op aconv}\verb|op aconv: term * term -> bool| \\
wenzelm@20519
   320
  \indexml{map-term-types}\verb|map_term_types: (typ -> typ) -> term -> term| \\  %FIXME rename map_types
wenzelm@20519
   321
  \indexml{fold-types}\verb|fold_types: (typ -> 'a -> 'a) -> term -> 'a -> 'a| \\
wenzelm@20514
   322
  \indexml{map-aterms}\verb|map_aterms: (term -> term) -> term -> term| \\
wenzelm@20514
   323
  \indexml{fold-aterms}\verb|fold_aterms: (term -> 'a -> 'a) -> term -> 'a -> 'a| \\
wenzelm@20514
   324
  \indexml{fastype-of}\verb|fastype_of: term -> typ| \\
wenzelm@20519
   325
  \indexml{lambda}\verb|lambda: term -> term -> term| \\
wenzelm@20519
   326
  \indexml{betapply}\verb|betapply: term * term -> term| \\
wenzelm@20520
   327
  \indexml{Sign.add-consts-i}\verb|Sign.add_consts_i: (string * typ * mixfix) list -> theory -> theory| \\
wenzelm@20519
   328
  \indexml{Sign.add-abbrevs}\verb|Sign.add_abbrevs: string * bool ->|\isasep\isanewline%
wenzelm@20520
   329
\verb|  ((string * mixfix) * term) list -> theory -> theory| \\
wenzelm@20519
   330
  \indexml{Sign.const-typargs}\verb|Sign.const_typargs: theory -> string * typ -> typ list| \\
wenzelm@20519
   331
  \indexml{Sign.const-instance}\verb|Sign.const_instance: theory -> string * typ list -> typ| \\
wenzelm@20514
   332
  \end{mldecls}
wenzelm@18537
   333
wenzelm@20514
   334
  \begin{description}
wenzelm@18537
   335
wenzelm@20537
   336
  \item \verb|term| represents de-Bruijn terms, with comments in
wenzelm@20537
   337
  abstractions, and explicitly named free variables and constants;
wenzelm@20537
   338
  this is a datatype with constructors \verb|Bound|, \verb|Free|, \verb|Var|, \verb|Const|, \verb|Abs|, \verb|op $|.
wenzelm@20519
   339
wenzelm@20519
   340
  \item \isa{t}~\verb|aconv|~\isa{u} checks \isa{{\isasymalpha}}-equivalence of two terms.  This is the basic equality relation
wenzelm@20519
   341
  on type \verb|term|; raw datatype equality should only be used
wenzelm@20519
   342
  for operations related to parsing or printing!
wenzelm@20519
   343
wenzelm@20537
   344
  \item \verb|map_term_types|~\isa{f\ t} applies the mapping \isa{f} to all types occurring in \isa{t}.
wenzelm@20519
   345
wenzelm@20537
   346
  \item \verb|fold_types|~\isa{f\ t} iterates the operation \isa{f} over all occurrences of types in \isa{t}; the term
wenzelm@20537
   347
  structure is traversed from left to right.
wenzelm@20537
   348
wenzelm@20537
   349
  \item \verb|map_aterms|~\isa{f\ t} applies the mapping \isa{f}
wenzelm@20537
   350
  to all atomic terms (\verb|Bound|, \verb|Free|, \verb|Var|, \verb|Const|) occurring in \isa{t}.
wenzelm@20537
   351
wenzelm@20537
   352
  \item \verb|fold_aterms|~\isa{f\ t} iterates the operation \isa{f} over all occurrences of atomic terms (\verb|Bound|, \verb|Free|,
wenzelm@20537
   353
  \verb|Var|, \verb|Const|) in \isa{t}; the term structure is
wenzelm@20519
   354
  traversed from left to right.
wenzelm@20519
   355
wenzelm@20537
   356
  \item \verb|fastype_of|~\isa{t} determines the type of a
wenzelm@20537
   357
  well-typed term.  This operation is relatively slow, despite the
wenzelm@20537
   358
  omission of any sanity checks.
wenzelm@20519
   359
wenzelm@20537
   360
  \item \verb|lambda|~\isa{a\ b} produces an abstraction \isa{{\isasymlambda}a{\isachardot}\ b}, where occurrences of the atomic term \isa{a} in the
wenzelm@20537
   361
  body \isa{b} are replaced by bound variables.
wenzelm@20519
   362
wenzelm@20537
   363
  \item \verb|betapply|~\isa{{\isacharparenleft}t{\isacharcomma}\ u{\isacharparenright}} produces an application \isa{t\ u}, with topmost \isa{{\isasymbeta}}-conversion if \isa{t} is an
wenzelm@20537
   364
  abstraction.
wenzelm@20519
   365
wenzelm@20519
   366
  \item \verb|Sign.add_consts_i|~\isa{{\isacharbrackleft}{\isacharparenleft}c{\isacharcomma}\ {\isasymsigma}{\isacharcomma}\ mx{\isacharparenright}{\isacharcomma}\ {\isasymdots}{\isacharbrackright}} declares a
wenzelm@20519
   367
  new constant \isa{c\ {\isacharcolon}{\isacharcolon}\ {\isasymsigma}} with optional mixfix syntax.
wenzelm@20519
   368
wenzelm@20519
   369
  \item \verb|Sign.add_abbrevs|~\isa{print{\isacharunderscore}mode\ {\isacharbrackleft}{\isacharparenleft}{\isacharparenleft}c{\isacharcomma}\ t{\isacharparenright}{\isacharcomma}\ mx{\isacharparenright}{\isacharcomma}\ {\isasymdots}{\isacharbrackright}}
wenzelm@20519
   370
  declares a new term abbreviation \isa{c\ {\isasymequiv}\ t} with optional
wenzelm@20519
   371
  mixfix syntax.
wenzelm@20519
   372
wenzelm@20520
   373
  \item \verb|Sign.const_typargs|~\isa{thy\ {\isacharparenleft}c{\isacharcomma}\ {\isasymtau}{\isacharparenright}} and \verb|Sign.const_instance|~\isa{thy\ {\isacharparenleft}c{\isacharcomma}\ {\isacharbrackleft}{\isasymtau}\isactrlisub {\isadigit{1}}{\isacharcomma}\ {\isasymdots}{\isacharcomma}\ {\isasymtau}\isactrlisub n{\isacharbrackright}{\isacharparenright}}
wenzelm@20543
   374
  convert between two representations of polymorphic constants: full
wenzelm@20543
   375
  type instance vs.\ compact type arguments form.
wenzelm@20514
   376
wenzelm@20514
   377
  \end{description}%
wenzelm@18537
   378
\end{isamarkuptext}%
wenzelm@18537
   379
\isamarkuptrue%
wenzelm@18537
   380
%
wenzelm@20514
   381
\endisatagmlref
wenzelm@20514
   382
{\isafoldmlref}%
wenzelm@20514
   383
%
wenzelm@20514
   384
\isadelimmlref
wenzelm@20514
   385
%
wenzelm@20514
   386
\endisadelimmlref
wenzelm@20514
   387
%
wenzelm@20451
   388
\isamarkupsection{Theorems \label{sec:thms}%
wenzelm@18537
   389
}
wenzelm@18537
   390
\isamarkuptrue%
wenzelm@18537
   391
%
wenzelm@18537
   392
\begin{isamarkuptext}%
wenzelm@20521
   393
\glossary{Proposition}{FIXME A \seeglossary{term} of
wenzelm@20521
   394
  \seeglossary{type} \isa{prop}.  Internally, there is nothing
wenzelm@20521
   395
  special about propositions apart from their type, but the concrete
wenzelm@20521
   396
  syntax enforces a clear distinction.  Propositions are structured
wenzelm@20521
   397
  via implication \isa{A\ {\isasymLongrightarrow}\ B} or universal quantification \isa{{\isasymAnd}x{\isachardot}\ B\ x} --- anything else is considered atomic.  The canonical
wenzelm@20521
   398
  form for propositions is that of a \seeglossary{Hereditary Harrop
wenzelm@20521
   399
  Formula}. FIXME}
wenzelm@20481
   400
wenzelm@20502
   401
  \glossary{Theorem}{A proven proposition within a certain theory and
wenzelm@20502
   402
  proof context, formally \isa{{\isasymGamma}\ {\isasymturnstile}\isactrlsub {\isasymTheta}\ {\isasymphi}}; both contexts are
wenzelm@20502
   403
  rarely spelled out explicitly.  Theorems are usually normalized
wenzelm@20502
   404
  according to the \seeglossary{HHF} format. FIXME}
wenzelm@20481
   405
wenzelm@20519
   406
  \glossary{Fact}{Sometimes used interchangeably for
wenzelm@20502
   407
  \seeglossary{theorem}.  Strictly speaking, a list of theorems,
wenzelm@20502
   408
  essentially an extra-logical conjunction.  Facts emerge either as
wenzelm@20502
   409
  local assumptions, or as results of local goal statements --- both
wenzelm@20502
   410
  may be simultaneous, hence the list representation. FIXME}
wenzelm@20481
   411
wenzelm@20502
   412
  \glossary{Schematic variable}{FIXME}
wenzelm@20481
   413
wenzelm@20502
   414
  \glossary{Fixed variable}{A variable that is bound within a certain
wenzelm@20502
   415
  proof context; an arbitrary-but-fixed entity within a portion of
wenzelm@20502
   416
  proof text. FIXME}
wenzelm@18537
   417
wenzelm@20502
   418
  \glossary{Free variable}{Synonymous for \seeglossary{fixed
wenzelm@20502
   419
  variable}. FIXME}
wenzelm@18537
   420
wenzelm@20502
   421
  \glossary{Bound variable}{FIXME}
wenzelm@18537
   422
wenzelm@20502
   423
  \glossary{Variable}{See \seeglossary{schematic variable},
wenzelm@20502
   424
  \seeglossary{fixed variable}, \seeglossary{bound variable}, or
wenzelm@20502
   425
  \seeglossary{type variable}.  The distinguishing feature of
wenzelm@20502
   426
  different variables is their binding scope. FIXME}
wenzelm@18537
   427
wenzelm@20543
   428
  A \emph{proposition} is a well-typed term of type \isa{prop}, a
wenzelm@20521
   429
  \emph{theorem} is a proven proposition (depending on a context of
wenzelm@20521
   430
  hypotheses and the background theory).  Primitive inferences include
wenzelm@20537
   431
  plain natural deduction rules for the primary connectives \isa{{\isasymAnd}} and \isa{{\isasymLongrightarrow}} of the framework.  There is also a builtin
wenzelm@20537
   432
  notion of equality/equivalence \isa{{\isasymequiv}}.%
wenzelm@20521
   433
\end{isamarkuptext}%
wenzelm@20521
   434
\isamarkuptrue%
wenzelm@20521
   435
%
wenzelm@20537
   436
\isamarkupsubsection{Primitive connectives and rules%
wenzelm@20521
   437
}
wenzelm@20521
   438
\isamarkuptrue%
wenzelm@20521
   439
%
wenzelm@20521
   440
\begin{isamarkuptext}%
wenzelm@20543
   441
The theory \isa{Pure} contains constant declarations for the
wenzelm@20543
   442
  primitive connectives \isa{{\isasymAnd}}, \isa{{\isasymLongrightarrow}}, and \isa{{\isasymequiv}} of
wenzelm@20543
   443
  the logical framework, see \figref{fig:pure-connectives}.  The
wenzelm@20543
   444
  derivability judgment \isa{A\isactrlisub {\isadigit{1}}{\isacharcomma}\ {\isasymdots}{\isacharcomma}\ A\isactrlisub n\ {\isasymturnstile}\ B} is
wenzelm@20543
   445
  defined inductively by the primitive inferences given in
wenzelm@20543
   446
  \figref{fig:prim-rules}, with the global restriction that the
wenzelm@20543
   447
  hypotheses must \emph{not} contain any schematic variables.  The
wenzelm@20543
   448
  builtin equality is conceptually axiomatized as shown in
wenzelm@20521
   449
  \figref{fig:pure-equality}, although the implementation works
wenzelm@20543
   450
  directly with derived inferences.
wenzelm@18537
   451
wenzelm@20521
   452
  \begin{figure}[htb]
wenzelm@20521
   453
  \begin{center}
wenzelm@20502
   454
  \begin{tabular}{ll}
wenzelm@20502
   455
  \isa{all\ {\isacharcolon}{\isacharcolon}\ {\isacharparenleft}{\isasymalpha}\ {\isasymRightarrow}\ prop{\isacharparenright}\ {\isasymRightarrow}\ prop} & universal quantification (binder \isa{{\isasymAnd}}) \\
wenzelm@20502
   456
  \isa{{\isasymLongrightarrow}\ {\isacharcolon}{\isacharcolon}\ prop\ {\isasymRightarrow}\ prop\ {\isasymRightarrow}\ prop} & implication (right associative infix) \\
wenzelm@20521
   457
  \isa{{\isasymequiv}\ {\isacharcolon}{\isacharcolon}\ {\isasymalpha}\ {\isasymRightarrow}\ {\isasymalpha}\ {\isasymRightarrow}\ prop} & equality relation (infix) \\
wenzelm@20502
   458
  \end{tabular}
wenzelm@20537
   459
  \caption{Primitive connectives of Pure}\label{fig:pure-connectives}
wenzelm@20521
   460
  \end{center}
wenzelm@20521
   461
  \end{figure}
wenzelm@18537
   462
wenzelm@20502
   463
  \begin{figure}[htb]
wenzelm@20502
   464
  \begin{center}
wenzelm@20499
   465
  \[
wenzelm@20499
   466
  \infer[\isa{{\isacharparenleft}axiom{\isacharparenright}}]{\isa{{\isasymturnstile}\ A}}{\isa{A\ {\isasymin}\ {\isasymTheta}}}
wenzelm@20499
   467
  \qquad
wenzelm@20499
   468
  \infer[\isa{{\isacharparenleft}assume{\isacharparenright}}]{\isa{A\ {\isasymturnstile}\ A}}{}
wenzelm@20499
   469
  \]
wenzelm@20499
   470
  \[
wenzelm@20537
   471
  \infer[\isa{{\isacharparenleft}{\isasymAnd}{\isacharunderscore}intro{\isacharparenright}}]{\isa{{\isasymGamma}\ {\isasymturnstile}\ {\isasymAnd}x{\isachardot}\ b{\isacharbrackleft}x{\isacharbrackright}}}{\isa{{\isasymGamma}\ {\isasymturnstile}\ b{\isacharbrackleft}x{\isacharbrackright}} & \isa{x\ {\isasymnotin}\ {\isasymGamma}}}
wenzelm@20499
   472
  \qquad
wenzelm@20537
   473
  \infer[\isa{{\isacharparenleft}{\isasymAnd}{\isacharunderscore}elim{\isacharparenright}}]{\isa{{\isasymGamma}\ {\isasymturnstile}\ b{\isacharbrackleft}a{\isacharbrackright}}}{\isa{{\isasymGamma}\ {\isasymturnstile}\ {\isasymAnd}x{\isachardot}\ b{\isacharbrackleft}x{\isacharbrackright}}}
wenzelm@20499
   474
  \]
wenzelm@20499
   475
  \[
wenzelm@20499
   476
  \infer[\isa{{\isacharparenleft}{\isasymLongrightarrow}{\isacharunderscore}intro{\isacharparenright}}]{\isa{{\isasymGamma}\ {\isacharminus}\ A\ {\isasymturnstile}\ A\ {\isasymLongrightarrow}\ B}}{\isa{{\isasymGamma}\ {\isasymturnstile}\ B}}
wenzelm@20499
   477
  \qquad
wenzelm@20499
   478
  \infer[\isa{{\isacharparenleft}{\isasymLongrightarrow}{\isacharunderscore}elim{\isacharparenright}}]{\isa{{\isasymGamma}\isactrlsub {\isadigit{1}}\ {\isasymunion}\ {\isasymGamma}\isactrlsub {\isadigit{2}}\ {\isasymturnstile}\ B}}{\isa{{\isasymGamma}\isactrlsub {\isadigit{1}}\ {\isasymturnstile}\ A\ {\isasymLongrightarrow}\ B} & \isa{{\isasymGamma}\isactrlsub {\isadigit{2}}\ {\isasymturnstile}\ A}}
wenzelm@20499
   479
  \]
wenzelm@20521
   480
  \caption{Primitive inferences of Pure}\label{fig:prim-rules}
wenzelm@20521
   481
  \end{center}
wenzelm@20521
   482
  \end{figure}
wenzelm@20521
   483
wenzelm@20521
   484
  \begin{figure}[htb]
wenzelm@20521
   485
  \begin{center}
wenzelm@20521
   486
  \begin{tabular}{ll}
wenzelm@20537
   487
  \isa{{\isasymturnstile}\ {\isacharparenleft}{\isasymlambda}x{\isachardot}\ b{\isacharbrackleft}x{\isacharbrackright}{\isacharparenright}\ a\ {\isasymequiv}\ b{\isacharbrackleft}a{\isacharbrackright}} & \isa{{\isasymbeta}}-conversion \\
wenzelm@20521
   488
  \isa{{\isasymturnstile}\ x\ {\isasymequiv}\ x} & reflexivity \\
wenzelm@20521
   489
  \isa{{\isasymturnstile}\ x\ {\isasymequiv}\ y\ {\isasymLongrightarrow}\ P\ x\ {\isasymLongrightarrow}\ P\ y} & substitution \\
wenzelm@20521
   490
  \isa{{\isasymturnstile}\ {\isacharparenleft}{\isasymAnd}x{\isachardot}\ f\ x\ {\isasymequiv}\ g\ x{\isacharparenright}\ {\isasymLongrightarrow}\ f\ {\isasymequiv}\ g} & extensionality \\
wenzelm@20537
   491
  \isa{{\isasymturnstile}\ {\isacharparenleft}A\ {\isasymLongrightarrow}\ B{\isacharparenright}\ {\isasymLongrightarrow}\ {\isacharparenleft}B\ {\isasymLongrightarrow}\ A{\isacharparenright}\ {\isasymLongrightarrow}\ A\ {\isasymequiv}\ B} & logical equivalence \\
wenzelm@20521
   492
  \end{tabular}
wenzelm@20542
   493
  \caption{Conceptual axiomatization of Pure equality}\label{fig:pure-equality}
wenzelm@20502
   494
  \end{center}
wenzelm@20502
   495
  \end{figure}
wenzelm@20499
   496
wenzelm@20537
   497
  The introduction and elimination rules for \isa{{\isasymAnd}} and \isa{{\isasymLongrightarrow}} are analogous to formation of dependently typed \isa{{\isasymlambda}}-terms representing the underlying proof objects.  Proof terms
wenzelm@20543
   498
  are irrelevant in the Pure logic, though; they cannot occur within
wenzelm@20543
   499
  propositions.  The system provides a runtime option to record
wenzelm@20537
   500
  explicit proof terms for primitive inferences.  Thus all three
wenzelm@20537
   501
  levels of \isa{{\isasymlambda}}-calculus become explicit: \isa{{\isasymRightarrow}} for
wenzelm@20537
   502
  terms, and \isa{{\isasymAnd}{\isacharslash}{\isasymLongrightarrow}} for proofs (cf.\
wenzelm@20537
   503
  \cite{Berghofer-Nipkow:2000:TPHOL}).
wenzelm@20499
   504
wenzelm@20537
   505
  Observe that locally fixed parameters (as in \isa{{\isasymAnd}{\isacharunderscore}intro}) need
wenzelm@20537
   506
  not be recorded in the hypotheses, because the simple syntactic
wenzelm@20543
   507
  types of Pure are always inhabitable.  ``Assumptions'' \isa{x\ {\isacharcolon}{\isacharcolon}\ {\isasymtau}} for type-membership are only present as long as some \isa{x\isactrlisub {\isasymtau}} occurs in the statement body.\footnote{This is the key
wenzelm@20543
   508
  difference to ``\isa{{\isasymlambda}HOL}'' in the PTS framework
wenzelm@20543
   509
  \cite{Barendregt-Geuvers:2001}, where hypotheses \isa{x\ {\isacharcolon}\ A} are
wenzelm@20543
   510
  treated uniformly for propositions and types.}
wenzelm@20502
   511
wenzelm@20502
   512
  \medskip The axiomatization of a theory is implicitly closed by
wenzelm@20537
   513
  forming all instances of type and term variables: \isa{{\isasymturnstile}\ A{\isasymvartheta}} holds for any substitution instance of an axiom
wenzelm@20543
   514
  \isa{{\isasymturnstile}\ A}.  By pushing substitutions through derivations
wenzelm@20543
   515
  inductively, we also get admissible \isa{generalize} and \isa{instance} rules as shown in \figref{fig:subst-rules}.
wenzelm@20502
   516
wenzelm@20502
   517
  \begin{figure}[htb]
wenzelm@20502
   518
  \begin{center}
wenzelm@20499
   519
  \[
wenzelm@20502
   520
  \infer{\isa{{\isasymGamma}\ {\isasymturnstile}\ B{\isacharbrackleft}{\isacharquery}{\isasymalpha}{\isacharbrackright}}}{\isa{{\isasymGamma}\ {\isasymturnstile}\ B{\isacharbrackleft}{\isasymalpha}{\isacharbrackright}} & \isa{{\isasymalpha}\ {\isasymnotin}\ {\isasymGamma}}}
wenzelm@20502
   521
  \quad
wenzelm@20502
   522
  \infer[\quad\isa{{\isacharparenleft}generalize{\isacharparenright}}]{\isa{{\isasymGamma}\ {\isasymturnstile}\ B{\isacharbrackleft}{\isacharquery}x{\isacharbrackright}}}{\isa{{\isasymGamma}\ {\isasymturnstile}\ B{\isacharbrackleft}x{\isacharbrackright}} & \isa{x\ {\isasymnotin}\ {\isasymGamma}}}
wenzelm@20499
   523
  \]
wenzelm@20499
   524
  \[
wenzelm@20502
   525
  \infer{\isa{{\isasymGamma}\ {\isasymturnstile}\ B{\isacharbrackleft}{\isasymtau}{\isacharbrackright}}}{\isa{{\isasymGamma}\ {\isasymturnstile}\ B{\isacharbrackleft}{\isacharquery}{\isasymalpha}{\isacharbrackright}}}
wenzelm@20502
   526
  \quad
wenzelm@20502
   527
  \infer[\quad\isa{{\isacharparenleft}instantiate{\isacharparenright}}]{\isa{{\isasymGamma}\ {\isasymturnstile}\ B{\isacharbrackleft}t{\isacharbrackright}}}{\isa{{\isasymGamma}\ {\isasymturnstile}\ B{\isacharbrackleft}{\isacharquery}x{\isacharbrackright}}}
wenzelm@20499
   528
  \]
wenzelm@20502
   529
  \caption{Admissible substitution rules}\label{fig:subst-rules}
wenzelm@20502
   530
  \end{center}
wenzelm@20502
   531
  \end{figure}
wenzelm@20499
   532
wenzelm@20537
   533
  Note that \isa{instantiate} does not require an explicit
wenzelm@20537
   534
  side-condition, because \isa{{\isasymGamma}} may never contain schematic
wenzelm@20537
   535
  variables.
wenzelm@20537
   536
wenzelm@20537
   537
  In principle, variables could be substituted in hypotheses as well,
wenzelm@20543
   538
  but this would disrupt the monotonicity of reasoning: deriving
wenzelm@20543
   539
  \isa{{\isasymGamma}{\isasymvartheta}\ {\isasymturnstile}\ B{\isasymvartheta}} from \isa{{\isasymGamma}\ {\isasymturnstile}\ B} is
wenzelm@20543
   540
  correct, but \isa{{\isasymGamma}{\isasymvartheta}\ {\isasymsupseteq}\ {\isasymGamma}} does not necessarily hold:
wenzelm@20543
   541
  the result belongs to a different proof context.
wenzelm@20542
   542
wenzelm@20543
   543
  \medskip An \emph{oracle} is a function that produces axioms on the
wenzelm@20543
   544
  fly.  Logically, this is an instance of the \isa{axiom} rule
wenzelm@20543
   545
  (\figref{fig:prim-rules}), but there is an operational difference.
wenzelm@20543
   546
  The system always records oracle invocations within derivations of
wenzelm@20543
   547
  theorems.  Tracing plain axioms (and named theorems) is optional.
wenzelm@20542
   548
wenzelm@20542
   549
  Axiomatizations should be limited to the bare minimum, typically as
wenzelm@20542
   550
  part of the initial logical basis of an object-logic formalization.
wenzelm@20543
   551
  Later on, theories are usually developed in a strictly definitional
wenzelm@20543
   552
  fashion, by stating only certain equalities over new constants.
wenzelm@20542
   553
wenzelm@20543
   554
  A \emph{simple definition} consists of a constant declaration \isa{c\ {\isacharcolon}{\isacharcolon}\ {\isasymsigma}} together with an axiom \isa{{\isasymturnstile}\ c\ {\isasymequiv}\ t}, where \isa{t\ {\isacharcolon}{\isacharcolon}\ {\isasymsigma}} is a closed term without any hidden polymorphism.  The RHS
wenzelm@20543
   555
  may depend on further defined constants, but not \isa{c} itself.
wenzelm@20543
   556
  Definitions of functions may be presented as \isa{c\ \isactrlvec x\ {\isasymequiv}\ t} instead of the puristic \isa{c\ {\isasymequiv}\ {\isasymlambda}\isactrlvec x{\isachardot}\ t}.
wenzelm@20542
   557
wenzelm@20543
   558
  An \emph{overloaded definition} consists of a collection of axioms
wenzelm@20543
   559
  for the same constant, with zero or one equations \isa{c{\isacharparenleft}{\isacharparenleft}\isactrlvec {\isasymalpha}{\isacharparenright}{\isasymkappa}{\isacharparenright}\ {\isasymequiv}\ t} for each type constructor \isa{{\isasymkappa}} (for
wenzelm@20543
   560
  distinct variables \isa{\isactrlvec {\isasymalpha}}).  The RHS may mention
wenzelm@20543
   561
  previously defined constants as above, or arbitrary constants \isa{d{\isacharparenleft}{\isasymalpha}\isactrlisub i{\isacharparenright}} for some \isa{{\isasymalpha}\isactrlisub i} projected from \isa{\isactrlvec {\isasymalpha}}.  Thus overloaded definitions essentially work by
wenzelm@20543
   562
  primitive recursion over the syntactic structure of a single type
wenzelm@20543
   563
  argument.%
wenzelm@20521
   564
\end{isamarkuptext}%
wenzelm@20521
   565
\isamarkuptrue%
wenzelm@20521
   566
%
wenzelm@20521
   567
\isadelimmlref
wenzelm@20521
   568
%
wenzelm@20521
   569
\endisadelimmlref
wenzelm@20521
   570
%
wenzelm@20521
   571
\isatagmlref
wenzelm@20521
   572
%
wenzelm@20521
   573
\begin{isamarkuptext}%
wenzelm@20521
   574
\begin{mldecls}
wenzelm@20521
   575
  \indexmltype{ctyp}\verb|type ctyp| \\
wenzelm@20521
   576
  \indexmltype{cterm}\verb|type cterm| \\
wenzelm@20521
   577
  \indexmltype{thm}\verb|type thm| \\
wenzelm@20542
   578
  \indexml{proofs}\verb|proofs: int ref| \\
wenzelm@20542
   579
  \indexml{Thm.ctyp-of}\verb|Thm.ctyp_of: theory -> typ -> ctyp| \\
wenzelm@20542
   580
  \indexml{Thm.cterm-of}\verb|Thm.cterm_of: theory -> term -> cterm| \\
wenzelm@20542
   581
  \indexml{Thm.assume}\verb|Thm.assume: cterm -> thm| \\
wenzelm@20542
   582
  \indexml{Thm.forall-intr}\verb|Thm.forall_intr: cterm -> thm -> thm| \\
wenzelm@20542
   583
  \indexml{Thm.forall-elim}\verb|Thm.forall_elim: cterm -> thm -> thm| \\
wenzelm@20542
   584
  \indexml{Thm.implies-intr}\verb|Thm.implies_intr: cterm -> thm -> thm| \\
wenzelm@20542
   585
  \indexml{Thm.implies-elim}\verb|Thm.implies_elim: thm -> thm -> thm| \\
wenzelm@20542
   586
  \indexml{Thm.generalize}\verb|Thm.generalize: string list * string list -> int -> thm -> thm| \\
wenzelm@20542
   587
  \indexml{Thm.instantiate}\verb|Thm.instantiate: (ctyp * ctyp) list * (cterm * cterm) list -> thm -> thm| \\
wenzelm@20542
   588
  \indexml{Thm.get-axiom-i}\verb|Thm.get_axiom_i: theory -> string -> thm| \\
wenzelm@20542
   589
  \indexml{Thm.invoke-oracle-i}\verb|Thm.invoke_oracle_i: theory -> string -> theory * Object.T -> thm| \\
wenzelm@20542
   590
  \indexml{Theory.add-axioms-i}\verb|Theory.add_axioms_i: (string * term) list -> theory -> theory| \\
wenzelm@20542
   591
  \indexml{Theory.add-deps}\verb|Theory.add_deps: string -> string * typ -> (string * typ) list -> theory -> theory| \\
wenzelm@20542
   592
  \indexml{Theory.add-oracle}\verb|Theory.add_oracle: string * (theory * Object.T -> term) -> theory -> theory| \\
wenzelm@20542
   593
  \indexml{Theory.add-defs-i}\verb|Theory.add_defs_i: bool -> bool -> (bstring * term) list -> theory -> theory| \\
wenzelm@20521
   594
  \end{mldecls}
wenzelm@20499
   595
wenzelm@20521
   596
  \begin{description}
wenzelm@20521
   597
wenzelm@20542
   598
  \item \verb|ctyp| and \verb|cterm| represent certified types
wenzelm@20542
   599
  and terms, respectively.  These are abstract datatypes that
wenzelm@20542
   600
  guarantee that its values have passed the full well-formedness (and
wenzelm@20542
   601
  well-typedness) checks, relative to the declarations of type
wenzelm@20542
   602
  constructors, constants etc. in the theory.
wenzelm@20521
   603
wenzelm@20542
   604
  This representation avoids syntactic rechecking in tight loops of
wenzelm@20542
   605
  inferences.  There are separate operations to decompose certified
wenzelm@20542
   606
  entities (including actual theorems).
wenzelm@20521
   607
wenzelm@20542
   608
  \item \verb|thm| represents proven propositions.  This is an
wenzelm@20542
   609
  abstract datatype that guarantees that its values have been
wenzelm@20542
   610
  constructed by basic principles of the \verb|Thm| module.
wenzelm@20543
   611
  Every \verb|thm| value contains a sliding back-reference to the
wenzelm@20543
   612
  enclosing theory, cf.\ \secref{sec:context-theory}.
wenzelm@20542
   613
wenzelm@20543
   614
  \item \verb|proofs| determines the detail of proof recording within
wenzelm@20543
   615
  \verb|thm| values: \verb|0| records only oracles, \verb|1| records
wenzelm@20543
   616
  oracles, axioms and named theorems, \verb|2| records full proof
wenzelm@20543
   617
  terms.
wenzelm@20542
   618
wenzelm@20542
   619
  \item \verb|Thm.assume|, \verb|Thm.forall_intr|, \verb|Thm.forall_elim|, \verb|Thm.implies_intr|, and \verb|Thm.implies_elim|
wenzelm@20542
   620
  correspond to the primitive inferences of \figref{fig:prim-rules}.
wenzelm@20542
   621
wenzelm@20542
   622
  \item \verb|Thm.generalize|~\isa{{\isacharparenleft}\isactrlvec {\isasymalpha}{\isacharcomma}\ \isactrlvec x{\isacharparenright}}
wenzelm@20542
   623
  corresponds to the \isa{generalize} rules of
wenzelm@20543
   624
  \figref{fig:subst-rules}.  Here collections of type and term
wenzelm@20543
   625
  variables are generalized simultaneously, specified by the given
wenzelm@20543
   626
  basic names.
wenzelm@20542
   627
wenzelm@20542
   628
  \item \verb|Thm.instantiate|~\isa{{\isacharparenleft}\isactrlvec {\isasymalpha}\isactrlisub s{\isacharcomma}\ \isactrlvec x\isactrlisub {\isasymtau}{\isacharparenright}} corresponds to the \isa{instantiate} rules
wenzelm@20542
   629
  of \figref{fig:subst-rules}.  Type variables are substituted before
wenzelm@20542
   630
  term variables.  Note that the types in \isa{\isactrlvec x\isactrlisub {\isasymtau}}
wenzelm@20542
   631
  refer to the instantiated versions.
wenzelm@20542
   632
wenzelm@20542
   633
  \item \verb|Thm.get_axiom_i|~\isa{thy\ name} retrieves a named
wenzelm@20542
   634
  axiom, cf.\ \isa{axiom} in \figref{fig:prim-rules}.
wenzelm@20542
   635
wenzelm@20543
   636
  \item \verb|Thm.invoke_oracle_i|~\isa{thy\ name\ arg} invokes a
wenzelm@20543
   637
  named oracle function, cf.\ \isa{axiom} in
wenzelm@20543
   638
  \figref{fig:prim-rules}.
wenzelm@20542
   639
wenzelm@20543
   640
  \item \verb|Theory.add_axioms_i|~\isa{{\isacharbrackleft}{\isacharparenleft}name{\isacharcomma}\ A{\isacharparenright}{\isacharcomma}\ {\isasymdots}{\isacharbrackright}} declares
wenzelm@20543
   641
  arbitrary propositions as axioms.
wenzelm@20542
   642
wenzelm@20543
   643
  \item \verb|Theory.add_oracle|~\isa{{\isacharparenleft}name{\isacharcomma}\ f{\isacharparenright}} declares an oracle
wenzelm@20543
   644
  function for generating arbitrary axioms on the fly.
wenzelm@20542
   645
wenzelm@20543
   646
  \item \verb|Theory.add_deps|~\isa{name\ c\isactrlisub {\isasymtau}\ \isactrlvec d\isactrlisub {\isasymsigma}} declares dependencies of a named specification
wenzelm@20543
   647
  for constant \isa{c\isactrlisub {\isasymtau}}, relative to existing
wenzelm@20543
   648
  specifications for constants \isa{\isactrlvec d\isactrlisub {\isasymsigma}}.
wenzelm@20542
   649
wenzelm@20543
   650
  \item \verb|Theory.add_defs_i|~\isa{unchecked\ overloaded\ {\isacharbrackleft}{\isacharparenleft}name{\isacharcomma}\ c\ \isactrlvec x\ {\isasymequiv}\ t{\isacharparenright}{\isacharcomma}\ {\isasymdots}{\isacharbrackright}} states a definitional axiom for an existing
wenzelm@20543
   651
  constant \isa{c}.  Dependencies are recorded (cf.\ \verb|Theory.add_deps|), unless the \isa{unchecked} option is set.
wenzelm@20521
   652
wenzelm@20521
   653
  \end{description}%
wenzelm@20521
   654
\end{isamarkuptext}%
wenzelm@20521
   655
\isamarkuptrue%
wenzelm@20521
   656
%
wenzelm@20521
   657
\endisatagmlref
wenzelm@20521
   658
{\isafoldmlref}%
wenzelm@20521
   659
%
wenzelm@20521
   660
\isadelimmlref
wenzelm@20521
   661
%
wenzelm@20521
   662
\endisadelimmlref
wenzelm@20521
   663
%
wenzelm@20543
   664
\isamarkupsubsection{Auxiliary definitions%
wenzelm@20521
   665
}
wenzelm@20521
   666
\isamarkuptrue%
wenzelm@20521
   667
%
wenzelm@20521
   668
\begin{isamarkuptext}%
wenzelm@20543
   669
Theory \isa{Pure} provides a few auxiliary definitions, see
wenzelm@20543
   670
  \figref{fig:pure-aux}.  These special constants are normally not
wenzelm@20543
   671
  exposed to the user, but appear in internal encodings.
wenzelm@20499
   672
wenzelm@20502
   673
  \begin{figure}[htb]
wenzelm@20502
   674
  \begin{center}
wenzelm@20499
   675
  \begin{tabular}{ll}
wenzelm@20521
   676
  \isa{conjunction\ {\isacharcolon}{\isacharcolon}\ prop\ {\isasymRightarrow}\ prop\ {\isasymRightarrow}\ prop} & (infix \isa{{\isacharampersand}}) \\
wenzelm@20521
   677
  \isa{{\isasymturnstile}\ A\ {\isacharampersand}\ B\ {\isasymequiv}\ {\isacharparenleft}{\isasymAnd}C{\isachardot}\ {\isacharparenleft}A\ {\isasymLongrightarrow}\ B\ {\isasymLongrightarrow}\ C{\isacharparenright}\ {\isasymLongrightarrow}\ C{\isacharparenright}} \\[1ex]
wenzelm@20543
   678
  \isa{prop\ {\isacharcolon}{\isacharcolon}\ prop\ {\isasymRightarrow}\ prop} & (prefix \isa{{\isacharhash}}, suppressed) \\
wenzelm@20521
   679
  \isa{{\isacharhash}A\ {\isasymequiv}\ A} \\[1ex]
wenzelm@20521
   680
  \isa{term\ {\isacharcolon}{\isacharcolon}\ {\isasymalpha}\ {\isasymRightarrow}\ prop} & (prefix \isa{TERM}) \\
wenzelm@20521
   681
  \isa{term\ x\ {\isasymequiv}\ {\isacharparenleft}{\isasymAnd}A{\isachardot}\ A\ {\isasymLongrightarrow}\ A{\isacharparenright}} \\[1ex]
wenzelm@20521
   682
  \isa{TYPE\ {\isacharcolon}{\isacharcolon}\ {\isasymalpha}\ itself} & (prefix \isa{TYPE}) \\
wenzelm@20521
   683
  \isa{{\isacharparenleft}unspecified{\isacharparenright}} \\
wenzelm@20499
   684
  \end{tabular}
wenzelm@20521
   685
  \caption{Definitions of auxiliary connectives}\label{fig:pure-aux}
wenzelm@20502
   686
  \end{center}
wenzelm@20502
   687
  \end{figure}
wenzelm@20502
   688
wenzelm@20537
   689
  Derived conjunction rules include introduction \isa{A\ {\isasymLongrightarrow}\ B\ {\isasymLongrightarrow}\ A\ {\isacharampersand}\ B}, and destructions \isa{A\ {\isacharampersand}\ B\ {\isasymLongrightarrow}\ A} and \isa{A\ {\isacharampersand}\ B\ {\isasymLongrightarrow}\ B}.
wenzelm@20537
   690
  Conjunction allows to treat simultaneous assumptions and conclusions
wenzelm@20537
   691
  uniformly.  For example, multiple claims are intermediately
wenzelm@20543
   692
  represented as explicit conjunction, but this is refined into
wenzelm@20543
   693
  separate sub-goals before the user continues the proof; the final
wenzelm@20543
   694
  result is projected into a list of theorems (cf.\
wenzelm@20537
   695
  \secref{sec:tactical-goals}).
wenzelm@20502
   696
wenzelm@20537
   697
  The \isa{prop} marker (\isa{{\isacharhash}}) makes arbitrarily complex
wenzelm@20537
   698
  propositions appear as atomic, without changing the meaning: \isa{{\isasymGamma}\ {\isasymturnstile}\ A} and \isa{{\isasymGamma}\ {\isasymturnstile}\ {\isacharhash}A} are interchangeable.  See
wenzelm@20537
   699
  \secref{sec:tactical-goals} for specific operations.
wenzelm@20502
   700
wenzelm@20543
   701
  The \isa{term} marker turns any well-typed term into a derivable
wenzelm@20543
   702
  proposition: \isa{{\isasymturnstile}\ TERM\ t} holds unconditionally.  Although
wenzelm@20543
   703
  this is logically vacuous, it allows to treat terms and proofs
wenzelm@20543
   704
  uniformly, similar to a type-theoretic framework.
wenzelm@20502
   705
wenzelm@20537
   706
  The \isa{TYPE} constructor is the canonical representative of
wenzelm@20537
   707
  the unspecified type \isa{{\isasymalpha}\ itself}; it essentially injects the
wenzelm@20537
   708
  language of types into that of terms.  There is specific notation
wenzelm@20537
   709
  \isa{TYPE{\isacharparenleft}{\isasymtau}{\isacharparenright}} for \isa{TYPE\isactrlbsub {\isasymtau}\ itself\isactrlesub }.
wenzelm@20537
   710
  Although being devoid of any particular meaning, the \isa{TYPE{\isacharparenleft}{\isasymtau}{\isacharparenright}} accounts for the type \isa{{\isasymtau}} within the term
wenzelm@20537
   711
  language.  In particular, \isa{TYPE{\isacharparenleft}{\isasymalpha}{\isacharparenright}} may be used as formal
wenzelm@20537
   712
  argument in primitive definitions, in order to circumvent hidden
wenzelm@20537
   713
  polymorphism (cf.\ \secref{sec:terms}).  For example, \isa{c\ TYPE{\isacharparenleft}{\isasymalpha}{\isacharparenright}\ {\isasymequiv}\ A{\isacharbrackleft}{\isasymalpha}{\isacharbrackright}} defines \isa{c\ {\isacharcolon}{\isacharcolon}\ {\isasymalpha}\ itself\ {\isasymRightarrow}\ prop} in terms of
wenzelm@20537
   714
  a proposition \isa{A} that depends on an additional type
wenzelm@20537
   715
  argument, which is essentially a predicate on types.%
wenzelm@18537
   716
\end{isamarkuptext}%
wenzelm@18537
   717
\isamarkuptrue%
wenzelm@18537
   718
%
wenzelm@20521
   719
\isadelimmlref
wenzelm@20521
   720
%
wenzelm@20521
   721
\endisadelimmlref
wenzelm@20521
   722
%
wenzelm@20521
   723
\isatagmlref
wenzelm@20521
   724
%
wenzelm@20521
   725
\begin{isamarkuptext}%
wenzelm@20521
   726
\begin{mldecls}
wenzelm@20521
   727
  \indexml{Conjunction.intr}\verb|Conjunction.intr: thm -> thm -> thm| \\
wenzelm@20521
   728
  \indexml{Conjunction.elim}\verb|Conjunction.elim: thm -> thm * thm| \\
wenzelm@20521
   729
  \indexml{Drule.mk-term}\verb|Drule.mk_term: cterm -> thm| \\
wenzelm@20521
   730
  \indexml{Drule.dest-term}\verb|Drule.dest_term: thm -> cterm| \\
wenzelm@20521
   731
  \indexml{Logic.mk-type}\verb|Logic.mk_type: typ -> term| \\
wenzelm@20521
   732
  \indexml{Logic.dest-type}\verb|Logic.dest_type: term -> typ| \\
wenzelm@20521
   733
  \end{mldecls}
wenzelm@20521
   734
wenzelm@20521
   735
  \begin{description}
wenzelm@20521
   736
wenzelm@20542
   737
  \item \verb|Conjunction.intr| derives \isa{A\ {\isacharampersand}\ B} from \isa{A} and \isa{B}.
wenzelm@20542
   738
wenzelm@20543
   739
  \item \verb|Conjunction.elim| derives \isa{A} and \isa{B}
wenzelm@20542
   740
  from \isa{A\ {\isacharampersand}\ B}.
wenzelm@20542
   741
wenzelm@20543
   742
  \item \verb|Drule.mk_term| derives \isa{TERM\ t}.
wenzelm@20542
   743
wenzelm@20543
   744
  \item \verb|Drule.dest_term| recovers term \isa{t} from \isa{TERM\ t}.
wenzelm@20542
   745
wenzelm@20542
   746
  \item \verb|Logic.mk_type|~\isa{{\isasymtau}} produces the term \isa{TYPE{\isacharparenleft}{\isasymtau}{\isacharparenright}}.
wenzelm@20542
   747
wenzelm@20542
   748
  \item \verb|Logic.dest_type|~\isa{TYPE{\isacharparenleft}{\isasymtau}{\isacharparenright}} recovers the type
wenzelm@20542
   749
  \isa{{\isasymtau}}.
wenzelm@20521
   750
wenzelm@20521
   751
  \end{description}%
wenzelm@20521
   752
\end{isamarkuptext}%
wenzelm@20521
   753
\isamarkuptrue%
wenzelm@20521
   754
%
wenzelm@20521
   755
\endisatagmlref
wenzelm@20521
   756
{\isafoldmlref}%
wenzelm@20521
   757
%
wenzelm@20521
   758
\isadelimmlref
wenzelm@20521
   759
%
wenzelm@20521
   760
\endisadelimmlref
wenzelm@20521
   761
%
wenzelm@20491
   762
\isamarkupsection{Rules \label{sec:rules}%
wenzelm@18537
   763
}
wenzelm@18537
   764
\isamarkuptrue%
wenzelm@18537
   765
%
wenzelm@18537
   766
\begin{isamarkuptext}%
wenzelm@18537
   767
FIXME
wenzelm@18537
   768
wenzelm@20491
   769
  A \emph{rule} is any Pure theorem in HHF normal form; there is a
wenzelm@20491
   770
  separate calculus for rule composition, which is modeled after
wenzelm@20491
   771
  Gentzen's Natural Deduction \cite{Gentzen:1935}, but allows
wenzelm@20491
   772
  rules to be nested arbitrarily, similar to \cite{extensions91}.
wenzelm@20491
   773
wenzelm@20491
   774
  Normally, all theorems accessible to the user are proper rules.
wenzelm@20491
   775
  Low-level inferences are occasional required internally, but the
wenzelm@20491
   776
  result should be always presented in canonical form.  The higher
wenzelm@20491
   777
  interfaces of Isabelle/Isar will always produce proper rules.  It is
wenzelm@20491
   778
  important to maintain this invariant in add-on applications!
wenzelm@20491
   779
wenzelm@20491
   780
  There are two main principles of rule composition: \isa{resolution} (i.e.\ backchaining of rules) and \isa{by{\isacharminus}assumption} (i.e.\ closing a branch); both principles are
wenzelm@20519
   781
  combined in the variants of \isa{elim{\isacharminus}resolution} and \isa{dest{\isacharminus}resolution}.  Raw \isa{composition} is occasionally
wenzelm@20491
   782
  useful as well, also it is strictly speaking outside of the proper
wenzelm@20491
   783
  rule calculus.
wenzelm@20491
   784
wenzelm@20491
   785
  Rules are treated modulo general higher-order unification, which is
wenzelm@20491
   786
  unification modulo the equational theory of \isa{{\isasymalpha}{\isasymbeta}{\isasymeta}}-conversion
wenzelm@20491
   787
  on \isa{{\isasymlambda}}-terms.  Moreover, propositions are understood modulo
wenzelm@20491
   788
  the (derived) equivalence \isa{{\isacharparenleft}A\ {\isasymLongrightarrow}\ {\isacharparenleft}{\isasymAnd}x{\isachardot}\ B\ x{\isacharparenright}{\isacharparenright}\ {\isasymequiv}\ {\isacharparenleft}{\isasymAnd}x{\isachardot}\ A\ {\isasymLongrightarrow}\ B\ x{\isacharparenright}}.
wenzelm@20491
   789
wenzelm@20491
   790
  This means that any operations within the rule calculus may be
wenzelm@20491
   791
  subject to spontaneous \isa{{\isasymalpha}{\isasymbeta}{\isasymeta}}-HHF conversions.  It is common
wenzelm@20491
   792
  practice not to contract or expand unnecessarily.  Some mechanisms
wenzelm@20491
   793
  prefer an one form, others the opposite, so there is a potential
wenzelm@20491
   794
  danger to produce some oscillation!
wenzelm@20491
   795
wenzelm@20491
   796
  Only few operations really work \emph{modulo} HHF conversion, but
wenzelm@20491
   797
  expect a normal form: quantifiers \isa{{\isasymAnd}} before implications
wenzelm@20491
   798
  \isa{{\isasymLongrightarrow}} at each level of nesting.
wenzelm@20491
   799
wenzelm@18537
   800
\glossary{Hereditary Harrop Formula}{The set of propositions in HHF
wenzelm@18537
   801
format is defined inductively as \isa{H\ {\isacharequal}\ {\isacharparenleft}{\isasymAnd}x\isactrlsup {\isacharasterisk}{\isachardot}\ H\isactrlsup {\isacharasterisk}\ {\isasymLongrightarrow}\ A{\isacharparenright}}, for variables \isa{x} and atomic propositions \isa{A}.
wenzelm@18537
   802
Any proposition may be put into HHF form by normalizing with the rule
wenzelm@18537
   803
\isa{{\isacharparenleft}A\ {\isasymLongrightarrow}\ {\isacharparenleft}{\isasymAnd}x{\isachardot}\ B\ x{\isacharparenright}{\isacharparenright}\ {\isasymequiv}\ {\isacharparenleft}{\isasymAnd}x{\isachardot}\ A\ {\isasymLongrightarrow}\ B\ x{\isacharparenright}}.  In Isabelle, the outermost
wenzelm@18537
   804
quantifier prefix is represented via \seeglossary{schematic
wenzelm@18537
   805
variables}, such that the top-level structure is merely that of a
wenzelm@18537
   806
\seeglossary{Horn Clause}}.
wenzelm@18537
   807
wenzelm@20499
   808
\glossary{HHF}{See \seeglossary{Hereditary Harrop Formula}.}
wenzelm@20499
   809
wenzelm@20499
   810
wenzelm@20499
   811
  \[
wenzelm@20499
   812
  \infer[\isa{{\isacharparenleft}assumption{\isacharparenright}}]{\isa{C{\isasymvartheta}}}
wenzelm@20499
   813
  {\isa{{\isacharparenleft}{\isasymAnd}\isactrlvec x{\isachardot}\ \isactrlvec H\ \isactrlvec x\ {\isasymLongrightarrow}\ A\ \isactrlvec x{\isacharparenright}\ {\isasymLongrightarrow}\ C} & \isa{A{\isasymvartheta}\ {\isacharequal}\ H\isactrlsub i{\isasymvartheta}}~~\text{(for some~\isa{i})}}
wenzelm@20499
   814
  \]
wenzelm@20499
   815
wenzelm@20499
   816
wenzelm@20499
   817
  \[
wenzelm@20499
   818
  \infer[\isa{{\isacharparenleft}compose{\isacharparenright}}]{\isa{\isactrlvec A{\isasymvartheta}\ {\isasymLongrightarrow}\ C{\isasymvartheta}}}
wenzelm@20499
   819
  {\isa{\isactrlvec A\ {\isasymLongrightarrow}\ B} & \isa{B{\isacharprime}\ {\isasymLongrightarrow}\ C} & \isa{B{\isasymvartheta}\ {\isacharequal}\ B{\isacharprime}{\isasymvartheta}}}
wenzelm@20499
   820
  \]
wenzelm@20499
   821
wenzelm@20499
   822
wenzelm@20499
   823
  \[
wenzelm@20499
   824
  \infer[\isa{{\isacharparenleft}{\isasymAnd}{\isacharunderscore}lift{\isacharparenright}}]{\isa{{\isacharparenleft}{\isasymAnd}\isactrlvec x{\isachardot}\ \isactrlvec A\ {\isacharparenleft}{\isacharquery}\isactrlvec a\ \isactrlvec x{\isacharparenright}{\isacharparenright}\ {\isasymLongrightarrow}\ {\isacharparenleft}{\isasymAnd}\isactrlvec x{\isachardot}\ B\ {\isacharparenleft}{\isacharquery}\isactrlvec a\ \isactrlvec x{\isacharparenright}{\isacharparenright}}}{\isa{\isactrlvec A\ {\isacharquery}\isactrlvec a\ {\isasymLongrightarrow}\ B\ {\isacharquery}\isactrlvec a}}
wenzelm@20499
   825
  \]
wenzelm@20499
   826
  \[
wenzelm@20499
   827
  \infer[\isa{{\isacharparenleft}{\isasymLongrightarrow}{\isacharunderscore}lift{\isacharparenright}}]{\isa{{\isacharparenleft}\isactrlvec H\ {\isasymLongrightarrow}\ \isactrlvec A{\isacharparenright}\ {\isasymLongrightarrow}\ {\isacharparenleft}\isactrlvec H\ {\isasymLongrightarrow}\ B{\isacharparenright}}}{\isa{\isactrlvec A\ {\isasymLongrightarrow}\ B}}
wenzelm@20499
   828
  \]
wenzelm@20499
   829
wenzelm@20499
   830
  The \isa{resolve} scheme is now acquired from \isa{{\isasymAnd}{\isacharunderscore}lift},
wenzelm@20499
   831
  \isa{{\isasymLongrightarrow}{\isacharunderscore}lift}, and \isa{compose}.
wenzelm@20499
   832
wenzelm@20499
   833
  \[
wenzelm@20499
   834
  \infer[\isa{{\isacharparenleft}resolution{\isacharparenright}}]
wenzelm@20499
   835
  {\isa{{\isacharparenleft}{\isasymAnd}\isactrlvec x{\isachardot}\ \isactrlvec H\ \isactrlvec x\ {\isasymLongrightarrow}\ \isactrlvec A\ {\isacharparenleft}{\isacharquery}\isactrlvec a\ \isactrlvec x{\isacharparenright}{\isacharparenright}{\isasymvartheta}\ {\isasymLongrightarrow}\ C{\isasymvartheta}}}
wenzelm@20499
   836
  {\begin{tabular}{l}
wenzelm@20499
   837
    \isa{\isactrlvec A\ {\isacharquery}\isactrlvec a\ {\isasymLongrightarrow}\ B\ {\isacharquery}\isactrlvec a} \\
wenzelm@20499
   838
    \isa{{\isacharparenleft}{\isasymAnd}\isactrlvec x{\isachardot}\ \isactrlvec H\ \isactrlvec x\ {\isasymLongrightarrow}\ B{\isacharprime}\ \isactrlvec x{\isacharparenright}\ {\isasymLongrightarrow}\ C} \\
wenzelm@20499
   839
    \isa{{\isacharparenleft}{\isasymlambda}\isactrlvec x{\isachardot}\ B\ {\isacharparenleft}{\isacharquery}\isactrlvec a\ \isactrlvec x{\isacharparenright}{\isacharparenright}{\isasymvartheta}\ {\isacharequal}\ B{\isacharprime}{\isasymvartheta}} \\
wenzelm@20499
   840
   \end{tabular}}
wenzelm@20499
   841
  \]
wenzelm@20499
   842
wenzelm@20499
   843
wenzelm@20499
   844
  FIXME \isa{elim{\isacharunderscore}resolution}, \isa{dest{\isacharunderscore}resolution}%
wenzelm@18537
   845
\end{isamarkuptext}%
wenzelm@18537
   846
\isamarkuptrue%
wenzelm@18537
   847
%
wenzelm@18537
   848
\isadelimtheory
wenzelm@18537
   849
%
wenzelm@18537
   850
\endisadelimtheory
wenzelm@18537
   851
%
wenzelm@18537
   852
\isatagtheory
wenzelm@18537
   853
\isacommand{end}\isamarkupfalse%
wenzelm@18537
   854
%
wenzelm@18537
   855
\endisatagtheory
wenzelm@18537
   856
{\isafoldtheory}%
wenzelm@18537
   857
%
wenzelm@18537
   858
\isadelimtheory
wenzelm@18537
   859
%
wenzelm@18537
   860
\endisadelimtheory
wenzelm@18537
   861
\isanewline
wenzelm@18537
   862
\end{isabellebody}%
wenzelm@18537
   863
%%% Local Variables:
wenzelm@18537
   864
%%% mode: latex
wenzelm@18537
   865
%%% TeX-master: "root"
wenzelm@18537
   866
%%% End: