doc-src/IsarImplementation/Thy/logic.thy
author wenzelm
Thu Sep 14 15:51:20 2006 +0200 (2006-09-14)
changeset 20537 b6b49903db7e
parent 20521 189811b39869
child 20542 a54ca4e90874
permissions -rw-r--r--
*** empty log message ***
wenzelm@18537
     1
wenzelm@18537
     2
(* $Id$ *)
wenzelm@18537
     3
wenzelm@18537
     4
theory logic imports base begin
wenzelm@18537
     5
wenzelm@20470
     6
chapter {* Primitive logic \label{ch:logic} *}
wenzelm@18537
     7
wenzelm@20480
     8
text {*
wenzelm@20480
     9
  The logical foundations of Isabelle/Isar are that of the Pure logic,
wenzelm@20480
    10
  which has been introduced as a natural-deduction framework in
wenzelm@20480
    11
  \cite{paulson700}.  This is essentially the same logic as ``@{text
wenzelm@20493
    12
  "\<lambda>HOL"}'' in the more abstract setting of Pure Type Systems (PTS)
wenzelm@20480
    13
  \cite{Barendregt-Geuvers:2001}, although there are some key
wenzelm@20491
    14
  differences in the specific treatment of simple types in
wenzelm@20491
    15
  Isabelle/Pure.
wenzelm@20480
    16
wenzelm@20480
    17
  Following type-theoretic parlance, the Pure logic consists of three
wenzelm@20480
    18
  levels of @{text "\<lambda>"}-calculus with corresponding arrows: @{text
wenzelm@20480
    19
  "\<Rightarrow>"} for syntactic function space (terms depending on terms), @{text
wenzelm@20480
    20
  "\<And>"} for universal quantification (proofs depending on terms), and
wenzelm@20480
    21
  @{text "\<Longrightarrow>"} for implication (proofs depending on proofs).
wenzelm@20480
    22
wenzelm@20537
    23
  Derivations are relative to a logical theory, which declares type
wenzelm@20537
    24
  constructors, constants, and axioms.  Theory declarations support
wenzelm@20537
    25
  schematic polymorphism, which is strictly speaking outside the
wenzelm@20537
    26
  logic.\footnote{This is the deeper logical reason, why the theory
wenzelm@20537
    27
  context @{text "\<Theta>"} is separate from the proof context @{text "\<Gamma>"}
wenzelm@20537
    28
  of the core calculus.}
wenzelm@20480
    29
*}
wenzelm@20480
    30
wenzelm@20480
    31
wenzelm@20451
    32
section {* Types \label{sec:types} *}
wenzelm@20437
    33
wenzelm@20437
    34
text {*
wenzelm@20480
    35
  The language of types is an uninterpreted order-sorted first-order
wenzelm@20480
    36
  algebra; types are qualified by ordered type classes.
wenzelm@20480
    37
wenzelm@20480
    38
  \medskip A \emph{type class} is an abstract syntactic entity
wenzelm@20480
    39
  declared in the theory context.  The \emph{subclass relation} @{text
wenzelm@20480
    40
  "c\<^isub>1 \<subseteq> c\<^isub>2"} is specified by stating an acyclic
wenzelm@20491
    41
  generating relation; the transitive closure is maintained
wenzelm@20491
    42
  internally.  The resulting relation is an ordering: reflexive,
wenzelm@20491
    43
  transitive, and antisymmetric.
wenzelm@20451
    44
wenzelm@20537
    45
  A \emph{sort} is a list of type classes written as @{text "s =
wenzelm@20537
    46
  {c\<^isub>1, \<dots>, c\<^isub>m}"}, which represents symbolic
wenzelm@20480
    47
  intersection.  Notationally, the curly braces are omitted for
wenzelm@20480
    48
  singleton intersections, i.e.\ any class @{text "c"} may be read as
wenzelm@20480
    49
  a sort @{text "{c}"}.  The ordering on type classes is extended to
wenzelm@20491
    50
  sorts according to the meaning of intersections: @{text
wenzelm@20491
    51
  "{c\<^isub>1, \<dots> c\<^isub>m} \<subseteq> {d\<^isub>1, \<dots>, d\<^isub>n}"} iff
wenzelm@20491
    52
  @{text "\<forall>j. \<exists>i. c\<^isub>i \<subseteq> d\<^isub>j"}.  The empty intersection
wenzelm@20491
    53
  @{text "{}"} refers to the universal sort, which is the largest
wenzelm@20491
    54
  element wrt.\ the sort order.  The intersections of all (finitely
wenzelm@20491
    55
  many) classes declared in the current theory are the minimal
wenzelm@20491
    56
  elements wrt.\ the sort order.
wenzelm@20480
    57
wenzelm@20491
    58
  \medskip A \emph{fixed type variable} is a pair of a basic name
wenzelm@20537
    59
  (starting with a @{text "'"} character) and a sort constraint, e.g.\
wenzelm@20537
    60
  @{text "('a, s)"} which is usually printed as @{text "\<alpha>\<^isub>s"}.
wenzelm@20537
    61
  A \emph{schematic type variable} is a pair of an indexname and a
wenzelm@20537
    62
  sort constraint, e.g.\ @{text "(('a, 0), s)"} which is usually
wenzelm@20537
    63
  printed as @{text "?\<alpha>\<^isub>s"}.
wenzelm@20451
    64
wenzelm@20480
    65
  Note that \emph{all} syntactic components contribute to the identity
wenzelm@20493
    66
  of type variables, including the sort constraint.  The core logic
wenzelm@20493
    67
  handles type variables with the same name but different sorts as
wenzelm@20493
    68
  different, although some outer layers of the system make it hard to
wenzelm@20493
    69
  produce anything like this.
wenzelm@20451
    70
wenzelm@20493
    71
  A \emph{type constructor} @{text "\<kappa>"} is a @{text "k"}-ary operator
wenzelm@20493
    72
  on types declared in the theory.  Type constructor application is
wenzelm@20537
    73
  written postfix as @{text "(\<alpha>\<^isub>1, \<dots>, \<alpha>\<^isub>k)\<kappa>"}.  For
wenzelm@20537
    74
  @{text "k = 0"} the argument tuple is omitted, e.g.\ @{text "prop"}
wenzelm@20537
    75
  instead of @{text "()prop"}.  For @{text "k = 1"} the parentheses
wenzelm@20537
    76
  are omitted, e.g.\ @{text "\<alpha> list"} instead of @{text "(\<alpha>)list"}.
wenzelm@20537
    77
  Further notation is provided for specific constructors, notably the
wenzelm@20537
    78
  right-associative infix @{text "\<alpha> \<Rightarrow> \<beta>"} instead of @{text "(\<alpha>,
wenzelm@20537
    79
  \<beta>)fun"}.
wenzelm@20480
    80
  
wenzelm@20537
    81
  A \emph{type} is defined inductively over type variables and type
wenzelm@20537
    82
  constructors as follows: @{text "\<tau> = \<alpha>\<^isub>s | ?\<alpha>\<^isub>s |
wenzelm@20537
    83
  (\<tau>\<^sub>1, \<dots>, \<tau>\<^sub>k)k"}.
wenzelm@20451
    84
wenzelm@20514
    85
  A \emph{type abbreviation} is a syntactic definition @{text
wenzelm@20494
    86
  "(\<^vec>\<alpha>)\<kappa> = \<tau>"} of an arbitrary type expression @{text "\<tau>"} over
wenzelm@20537
    87
  variables @{text "\<^vec>\<alpha>"}.  Type abbreviations appear as type
wenzelm@20537
    88
  constructors in the syntax, but are expanded before entering the
wenzelm@20537
    89
  logical core.
wenzelm@20480
    90
wenzelm@20480
    91
  A \emph{type arity} declares the image behavior of a type
wenzelm@20494
    92
  constructor wrt.\ the algebra of sorts: @{text "\<kappa> :: (s\<^isub>1, \<dots>,
wenzelm@20494
    93
  s\<^isub>k)s"} means that @{text "(\<tau>\<^isub>1, \<dots>, \<tau>\<^isub>k)\<kappa>"} is
wenzelm@20494
    94
  of sort @{text "s"} if every argument type @{text "\<tau>\<^isub>i"} is
wenzelm@20494
    95
  of sort @{text "s\<^isub>i"}.  Arity declarations are implicitly
wenzelm@20494
    96
  completed, i.e.\ @{text "\<kappa> :: (\<^vec>s)c"} entails @{text "\<kappa> ::
wenzelm@20491
    97
  (\<^vec>s)c'"} for any @{text "c' \<supseteq> c"}.
wenzelm@20491
    98
wenzelm@20491
    99
  \medskip The sort algebra is always maintained as \emph{coregular},
wenzelm@20491
   100
  which means that type arities are consistent with the subclass
wenzelm@20537
   101
  relation: for any type constructor @{text "\<kappa>"}, and classes @{text
wenzelm@20537
   102
  "c\<^isub>1 \<subseteq> c\<^isub>2"}, and arities @{text "\<kappa> ::
wenzelm@20537
   103
  (\<^vec>s\<^isub>1)c\<^isub>1"} and @{text "\<kappa> ::
wenzelm@20537
   104
  (\<^vec>s\<^isub>2)c\<^isub>2"} holds @{text "\<^vec>s\<^isub>1 \<subseteq>
wenzelm@20537
   105
  \<^vec>s\<^isub>2"} component-wise.
wenzelm@20451
   106
wenzelm@20491
   107
  The key property of a coregular order-sorted algebra is that sort
wenzelm@20537
   108
  constraints can be solved in a most general fashion: for each type
wenzelm@20537
   109
  constructor @{text "\<kappa>"} and sort @{text "s"} there is a most general
wenzelm@20537
   110
  vector of argument sorts @{text "(s\<^isub>1, \<dots>, s\<^isub>k)"} such
wenzelm@20537
   111
  that a type scheme @{text "(\<alpha>\<^bsub>s\<^isub>1\<^esub>, \<dots>,
wenzelm@20537
   112
  \<alpha>\<^bsub>s\<^isub>k\<^esub>)\<kappa>"} is of sort @{text "s"}.
wenzelm@20537
   113
  Consequently, unification on the algebra of types has most general
wenzelm@20537
   114
  solutions (modulo equivalence of sorts).  This means that
wenzelm@20537
   115
  type-inference will produce primary types as expected
wenzelm@20537
   116
  \cite{nipkow-prehofer}.
wenzelm@20480
   117
*}
wenzelm@20451
   118
wenzelm@20480
   119
text %mlref {*
wenzelm@20480
   120
  \begin{mldecls}
wenzelm@20480
   121
  @{index_ML_type class} \\
wenzelm@20480
   122
  @{index_ML_type sort} \\
wenzelm@20494
   123
  @{index_ML_type arity} \\
wenzelm@20480
   124
  @{index_ML_type typ} \\
wenzelm@20519
   125
  @{index_ML map_atyps: "(typ -> typ) -> typ -> typ"} \\
wenzelm@20494
   126
  @{index_ML fold_atyps: "(typ -> 'a -> 'a) -> typ -> 'a -> 'a"} \\
wenzelm@20480
   127
  @{index_ML Sign.subsort: "theory -> sort * sort -> bool"} \\
wenzelm@20480
   128
  @{index_ML Sign.of_sort: "theory -> typ * sort -> bool"} \\
wenzelm@20520
   129
  @{index_ML Sign.add_types: "(string * int * mixfix) list -> theory -> theory"} \\
wenzelm@20480
   130
  @{index_ML Sign.add_tyabbrs_i: "
wenzelm@20520
   131
  (string * string list * typ * mixfix) list -> theory -> theory"} \\
wenzelm@20480
   132
  @{index_ML Sign.primitive_class: "string * class list -> theory -> theory"} \\
wenzelm@20480
   133
  @{index_ML Sign.primitive_classrel: "class * class -> theory -> theory"} \\
wenzelm@20480
   134
  @{index_ML Sign.primitive_arity: "arity -> theory -> theory"} \\
wenzelm@20480
   135
  \end{mldecls}
wenzelm@20480
   136
wenzelm@20480
   137
  \begin{description}
wenzelm@20480
   138
wenzelm@20480
   139
  \item @{ML_type class} represents type classes; this is an alias for
wenzelm@20480
   140
  @{ML_type string}.
wenzelm@20480
   141
wenzelm@20480
   142
  \item @{ML_type sort} represents sorts; this is an alias for
wenzelm@20480
   143
  @{ML_type "class list"}.
wenzelm@20451
   144
wenzelm@20480
   145
  \item @{ML_type arity} represents type arities; this is an alias for
wenzelm@20494
   146
  triples of the form @{text "(\<kappa>, \<^vec>s, s)"} for @{text "\<kappa> ::
wenzelm@20480
   147
  (\<^vec>s)s"} described above.
wenzelm@20480
   148
wenzelm@20480
   149
  \item @{ML_type typ} represents types; this is a datatype with
wenzelm@20480
   150
  constructors @{ML TFree}, @{ML TVar}, @{ML Type}.
wenzelm@20480
   151
wenzelm@20537
   152
  \item @{ML map_atyps}~@{text "f \<tau>"} applies the mapping @{text "f"}
wenzelm@20537
   153
  to all atomic types (@{ML TFree}, @{ML TVar}) occurring in @{text
wenzelm@20537
   154
  "\<tau>"}.
wenzelm@20519
   155
wenzelm@20537
   156
  \item @{ML fold_atyps}~@{text "f \<tau>"} iterates the operation @{text
wenzelm@20537
   157
  "f"} over all occurrences of atomic types (@{ML TFree}, @{ML TVar})
wenzelm@20537
   158
  in @{text "\<tau>"}; the type structure is traversed from left to right.
wenzelm@20494
   159
wenzelm@20480
   160
  \item @{ML Sign.subsort}~@{text "thy (s\<^isub>1, s\<^isub>2)"}
wenzelm@20480
   161
  tests the subsort relation @{text "s\<^isub>1 \<subseteq> s\<^isub>2"}.
wenzelm@20480
   162
wenzelm@20537
   163
  \item @{ML Sign.of_sort}~@{text "thy (\<tau>, s)"} tests whether type
wenzelm@20537
   164
  @{text "\<tau>"} is of sort @{text "s"}.
wenzelm@20480
   165
wenzelm@20537
   166
  \item @{ML Sign.add_types}~@{text "[(\<kappa>, k, mx), \<dots>]"} declares a new
wenzelm@20494
   167
  type constructors @{text "\<kappa>"} with @{text "k"} arguments and
wenzelm@20480
   168
  optional mixfix syntax.
wenzelm@20451
   169
wenzelm@20494
   170
  \item @{ML Sign.add_tyabbrs_i}~@{text "[(\<kappa>, \<^vec>\<alpha>, \<tau>, mx), \<dots>]"}
wenzelm@20494
   171
  defines a new type abbreviation @{text "(\<^vec>\<alpha>)\<kappa> = \<tau>"} with
wenzelm@20491
   172
  optional mixfix syntax.
wenzelm@20480
   173
wenzelm@20480
   174
  \item @{ML Sign.primitive_class}~@{text "(c, [c\<^isub>1, \<dots>,
wenzelm@20537
   175
  c\<^isub>n])"} declares a new class @{text "c"}, together with class
wenzelm@20494
   176
  relations @{text "c \<subseteq> c\<^isub>i"}, for @{text "i = 1, \<dots>, n"}.
wenzelm@20480
   177
wenzelm@20480
   178
  \item @{ML Sign.primitive_classrel}~@{text "(c\<^isub>1,
wenzelm@20480
   179
  c\<^isub>2)"} declares class relation @{text "c\<^isub>1 \<subseteq>
wenzelm@20480
   180
  c\<^isub>2"}.
wenzelm@20480
   181
wenzelm@20494
   182
  \item @{ML Sign.primitive_arity}~@{text "(\<kappa>, \<^vec>s, s)"} declares
wenzelm@20537
   183
  the arity @{text "\<kappa> :: (\<^vec>s)s"}.
wenzelm@20480
   184
wenzelm@20480
   185
  \end{description}
wenzelm@20437
   186
*}
wenzelm@20437
   187
wenzelm@20437
   188
wenzelm@20480
   189
wenzelm@20451
   190
section {* Terms \label{sec:terms} *}
wenzelm@18537
   191
wenzelm@18537
   192
text {*
wenzelm@20451
   193
  \glossary{Term}{FIXME}
wenzelm@18537
   194
wenzelm@20491
   195
  The language of terms is that of simply-typed @{text "\<lambda>"}-calculus
wenzelm@20520
   196
  with de-Bruijn indices for bound variables (cf.\ \cite{debruijn72}
wenzelm@20537
   197
  or \cite{paulson-ml2}), with the types being determined determined
wenzelm@20537
   198
  by the corresponding binders.  In contrast, free variables and
wenzelm@20537
   199
  constants are have an explicit name and type in each occurrence.
wenzelm@20514
   200
wenzelm@20514
   201
  \medskip A \emph{bound variable} is a natural number @{text "b"},
wenzelm@20537
   202
  which accounts for the number of intermediate binders between the
wenzelm@20537
   203
  variable occurrence in the body and its binding position.  For
wenzelm@20514
   204
  example, the de-Bruijn term @{text "\<lambda>\<^isub>\<tau>. \<lambda>\<^isub>\<tau>. 1 + 0"}
wenzelm@20537
   205
  would correspond to @{text "\<lambda>x\<^isub>\<tau>. \<lambda>y\<^isub>\<tau>. x + y"} in a
wenzelm@20537
   206
  named representation.  Note that a bound variable may be represented
wenzelm@20537
   207
  by different de-Bruijn indices at different occurrences, depending
wenzelm@20537
   208
  on the nesting of abstractions.
wenzelm@20537
   209
wenzelm@20537
   210
  A \emph{loose variables} is a bound variable that is outside the
wenzelm@20537
   211
  scope of local binders.  The types (and names) for loose variables
wenzelm@20537
   212
  can be managed as a separate context, that is maintained inside-out
wenzelm@20537
   213
  like a stack of hypothetical binders.  The core logic only operates
wenzelm@20537
   214
  on closed terms, without any loose variables.
wenzelm@20514
   215
wenzelm@20537
   216
  A \emph{fixed variable} is a pair of a basic name and a type, e.g.\
wenzelm@20537
   217
  @{text "(x, \<tau>)"} which is usually printed @{text "x\<^isub>\<tau>"}.  A
wenzelm@20537
   218
  \emph{schematic variable} is a pair of an indexname and a type,
wenzelm@20537
   219
  e.g.\ @{text "((x, 0), \<tau>)"} which is usually printed as @{text
wenzelm@20537
   220
  "?x\<^isub>\<tau>"}.
wenzelm@20491
   221
wenzelm@20537
   222
  \medskip A \emph{constant} is a pair of a basic name and a type,
wenzelm@20537
   223
  e.g.\ @{text "(c, \<tau>)"} which is usually printed as @{text
wenzelm@20537
   224
  "c\<^isub>\<tau>"}.  Constants are declared in the context as polymorphic
wenzelm@20537
   225
  families @{text "c :: \<sigma>"}, meaning that valid all substitution
wenzelm@20537
   226
  instances @{text "c\<^isub>\<tau>"} for @{text "\<tau> = \<sigma>\<vartheta>"} are valid.
wenzelm@20514
   227
wenzelm@20537
   228
  The vector of \emph{type arguments} of constant @{text "c\<^isub>\<tau>"}
wenzelm@20537
   229
  wrt.\ the declaration @{text "c :: \<sigma>"} is defined as the codomain of
wenzelm@20537
   230
  the matcher @{text "\<vartheta> = {?\<alpha>\<^isub>1 \<mapsto> \<tau>\<^isub>1, \<dots>,
wenzelm@20537
   231
  ?\<alpha>\<^isub>n \<mapsto> \<tau>\<^isub>n}"} presented in canonical order @{text
wenzelm@20537
   232
  "(\<tau>\<^isub>1, \<dots>, \<tau>\<^isub>n)"}.  Within a given theory context,
wenzelm@20537
   233
  there is a one-to-one correspondence between any constant @{text
wenzelm@20537
   234
  "c\<^isub>\<tau>"} and the application @{text "c(\<tau>\<^isub>1, \<dots>,
wenzelm@20537
   235
  \<tau>\<^isub>n)"} of its type arguments.  For example, with @{text "plus
wenzelm@20537
   236
  :: \<alpha> \<Rightarrow> \<alpha> \<Rightarrow> \<alpha>"}, the instance @{text "plus\<^bsub>nat \<Rightarrow> nat \<Rightarrow>
wenzelm@20537
   237
  nat\<^esub>"} corresponds to @{text "plus(nat)"}.
wenzelm@20480
   238
wenzelm@20514
   239
  Constant declarations @{text "c :: \<sigma>"} may contain sort constraints
wenzelm@20514
   240
  for type variables in @{text "\<sigma>"}.  These are observed by
wenzelm@20514
   241
  type-inference as expected, but \emph{ignored} by the core logic.
wenzelm@20514
   242
  This means the primitive logic is able to reason with instances of
wenzelm@20537
   243
  polymorphic constants that the user-level type-checker would reject
wenzelm@20537
   244
  due to violation of type class restrictions.
wenzelm@20480
   245
wenzelm@20537
   246
  \medskip A \emph{term} is defined inductively over variables and
wenzelm@20537
   247
  constants, with abstraction and application as follows: @{text "t =
wenzelm@20537
   248
  b | x\<^isub>\<tau> | ?x\<^isub>\<tau> | c\<^isub>\<tau> | \<lambda>\<^isub>\<tau>. t |
wenzelm@20537
   249
  t\<^isub>1 t\<^isub>2"}.  Parsing and printing takes care of
wenzelm@20537
   250
  converting between an external representation with named bound
wenzelm@20537
   251
  variables.  Subsequently, we shall use the latter notation instead
wenzelm@20537
   252
  of internal de-Bruijn representation.
wenzelm@20498
   253
wenzelm@20537
   254
  The inductive relation @{text "t :: \<tau>"} assigns a (unique) type to a
wenzelm@20537
   255
  term according to the structure of atomic terms, abstractions, and
wenzelm@20537
   256
  applicatins:
wenzelm@20498
   257
  \[
wenzelm@20501
   258
  \infer{@{text "a\<^isub>\<tau> :: \<tau>"}}{}
wenzelm@20498
   259
  \qquad
wenzelm@20501
   260
  \infer{@{text "(\<lambda>x\<^sub>\<tau>. t) :: \<tau> \<Rightarrow> \<sigma>"}}{@{text "t :: \<sigma>"}}
wenzelm@20501
   261
  \qquad
wenzelm@20501
   262
  \infer{@{text "t u :: \<sigma>"}}{@{text "t :: \<tau> \<Rightarrow> \<sigma>"} & @{text "u :: \<tau>"}}
wenzelm@20498
   263
  \]
wenzelm@20514
   264
  A \emph{well-typed term} is a term that can be typed according to these rules.
wenzelm@20498
   265
wenzelm@20514
   266
  Typing information can be omitted: type-inference is able to
wenzelm@20514
   267
  reconstruct the most general type of a raw term, while assigning
wenzelm@20514
   268
  most general types to all of its variables and constants.
wenzelm@20514
   269
  Type-inference depends on a context of type constraints for fixed
wenzelm@20514
   270
  variables, and declarations for polymorphic constants.
wenzelm@20514
   271
wenzelm@20537
   272
  The identity of atomic terms consists both of the name and the type
wenzelm@20537
   273
  component.  This means that different variables @{text
wenzelm@20537
   274
  "x\<^bsub>\<tau>\<^isub>1\<^esub>"} and @{text
wenzelm@20537
   275
  "x\<^bsub>\<tau>\<^isub>2\<^esub>"} may become the same after type
wenzelm@20537
   276
  instantiation.  Some outer layers of the system make it hard to
wenzelm@20537
   277
  produce variables of the same name, but different types.  In
wenzelm@20537
   278
  particular, type-inference always demands ``consistent'' type
wenzelm@20537
   279
  constraints for free variables.  In contrast, mixed instances of
wenzelm@20537
   280
  polymorphic constants occur frequently.
wenzelm@20514
   281
wenzelm@20514
   282
  \medskip The \emph{hidden polymorphism} of a term @{text "t :: \<sigma>"}
wenzelm@20514
   283
  is the set of type variables occurring in @{text "t"}, but not in
wenzelm@20537
   284
  @{text "\<sigma>"}.  This means that the term implicitly depends on type
wenzelm@20537
   285
  arguments that are not accounted in result type, i.e.\ there are
wenzelm@20537
   286
  different type instances @{text "t\<vartheta> :: \<sigma>"} and @{text
wenzelm@20537
   287
  "t\<vartheta>' :: \<sigma>"} with the same type.  This slightly
wenzelm@20537
   288
  pathological situation demands special care.
wenzelm@20514
   289
wenzelm@20514
   290
  \medskip A \emph{term abbreviation} is a syntactic definition @{text
wenzelm@20537
   291
  "c\<^isub>\<sigma> \<equiv> t"} of a closed term @{text "t"} of type @{text "\<sigma>"},
wenzelm@20537
   292
  without any hidden polymorphism.  A term abbreviation looks like a
wenzelm@20537
   293
  constant in the syntax, but is fully expanded before entering the
wenzelm@20537
   294
  logical core.  Abbreviations are usually reverted when printing
wenzelm@20537
   295
  terms, using the collective @{text "t \<rightarrow> c\<^isub>\<sigma>"} as rules for
wenzelm@20537
   296
  higher-order rewriting.
wenzelm@20519
   297
wenzelm@20519
   298
  \medskip Canonical operations on @{text "\<lambda>"}-terms include @{text
wenzelm@20537
   299
  "\<alpha>\<beta>\<eta>"}-conversion: @{text "\<alpha>"}-conversion refers to capture-free
wenzelm@20519
   300
  renaming of bound variables; @{text "\<beta>"}-conversion contracts an
wenzelm@20537
   301
  abstraction applied to an argument term, substituting the argument
wenzelm@20519
   302
  in the body: @{text "(\<lambda>x. b)a"} becomes @{text "b[a/x]"}; @{text
wenzelm@20519
   303
  "\<eta>"}-conversion contracts vacuous application-abstraction: @{text
wenzelm@20519
   304
  "\<lambda>x. f x"} becomes @{text "f"}, provided that the bound variable
wenzelm@20537
   305
  does not occur in @{text "f"}.
wenzelm@20519
   306
wenzelm@20537
   307
  Terms are normally treated modulo @{text "\<alpha>"}-conversion, which is
wenzelm@20537
   308
  implicit in the de-Bruijn representation.  Names for bound variables
wenzelm@20537
   309
  in abstractions are maintained separately as (meaningless) comments,
wenzelm@20537
   310
  mostly for parsing and printing.  Full @{text "\<alpha>\<beta>\<eta>"}-conversion is
wenzelm@20537
   311
  commonplace in various higher operations (\secref{sec:rules}) that
wenzelm@20537
   312
  are based on higher-order unification and matching.
wenzelm@18537
   313
*}
wenzelm@18537
   314
wenzelm@20514
   315
text %mlref {*
wenzelm@20514
   316
  \begin{mldecls}
wenzelm@20514
   317
  @{index_ML_type term} \\
wenzelm@20519
   318
  @{index_ML "op aconv": "term * term -> bool"} \\
wenzelm@20519
   319
  @{index_ML map_term_types: "(typ -> typ) -> term -> term"} \\  %FIXME rename map_types
wenzelm@20519
   320
  @{index_ML fold_types: "(typ -> 'a -> 'a) -> term -> 'a -> 'a"} \\
wenzelm@20514
   321
  @{index_ML map_aterms: "(term -> term) -> term -> term"} \\
wenzelm@20514
   322
  @{index_ML fold_aterms: "(term -> 'a -> 'a) -> term -> 'a -> 'a"} \\
wenzelm@20514
   323
  @{index_ML fastype_of: "term -> typ"} \\
wenzelm@20519
   324
  @{index_ML lambda: "term -> term -> term"} \\
wenzelm@20519
   325
  @{index_ML betapply: "term * term -> term"} \\
wenzelm@20520
   326
  @{index_ML Sign.add_consts_i: "(string * typ * mixfix) list -> theory -> theory"} \\
wenzelm@20519
   327
  @{index_ML Sign.add_abbrevs: "string * bool ->
wenzelm@20520
   328
  ((string * mixfix) * term) list -> theory -> theory"} \\
wenzelm@20519
   329
  @{index_ML Sign.const_typargs: "theory -> string * typ -> typ list"} \\
wenzelm@20519
   330
  @{index_ML Sign.const_instance: "theory -> string * typ list -> typ"} \\
wenzelm@20514
   331
  \end{mldecls}
wenzelm@18537
   332
wenzelm@20514
   333
  \begin{description}
wenzelm@18537
   334
wenzelm@20537
   335
  \item @{ML_type term} represents de-Bruijn terms, with comments in
wenzelm@20537
   336
  abstractions, and explicitly named free variables and constants;
wenzelm@20537
   337
  this is a datatype with constructors @{ML Bound}, @{ML Free}, @{ML
wenzelm@20537
   338
  Var}, @{ML Const}, @{ML Abs}, @{ML "op $"}.
wenzelm@20519
   339
wenzelm@20519
   340
  \item @{text "t"}~@{ML aconv}~@{text "u"} checks @{text
wenzelm@20519
   341
  "\<alpha>"}-equivalence of two terms.  This is the basic equality relation
wenzelm@20519
   342
  on type @{ML_type term}; raw datatype equality should only be used
wenzelm@20519
   343
  for operations related to parsing or printing!
wenzelm@20519
   344
wenzelm@20537
   345
  \item @{ML map_term_types}~@{text "f t"} applies the mapping @{text
wenzelm@20537
   346
  "f"} to all types occurring in @{text "t"}.
wenzelm@20537
   347
wenzelm@20537
   348
  \item @{ML fold_types}~@{text "f t"} iterates the operation @{text
wenzelm@20537
   349
  "f"} over all occurrences of types in @{text "t"}; the term
wenzelm@20537
   350
  structure is traversed from left to right.
wenzelm@20519
   351
wenzelm@20537
   352
  \item @{ML map_aterms}~@{text "f t"} applies the mapping @{text "f"}
wenzelm@20537
   353
  to all atomic terms (@{ML Bound}, @{ML Free}, @{ML Var}, @{ML
wenzelm@20537
   354
  Const}) occurring in @{text "t"}.
wenzelm@20537
   355
wenzelm@20537
   356
  \item @{ML fold_aterms}~@{text "f t"} iterates the operation @{text
wenzelm@20537
   357
  "f"} over all occurrences of atomic terms (@{ML Bound}, @{ML Free},
wenzelm@20537
   358
  @{ML Var}, @{ML Const}) in @{text "t"}; the term structure is
wenzelm@20519
   359
  traversed from left to right.
wenzelm@20519
   360
wenzelm@20537
   361
  \item @{ML fastype_of}~@{text "t"} determines the type of a
wenzelm@20537
   362
  well-typed term.  This operation is relatively slow, despite the
wenzelm@20537
   363
  omission of any sanity checks.
wenzelm@20519
   364
wenzelm@20519
   365
  \item @{ML lambda}~@{text "a b"} produces an abstraction @{text
wenzelm@20537
   366
  "\<lambda>a. b"}, where occurrences of the atomic term @{text "a"} in the
wenzelm@20537
   367
  body @{text "b"} are replaced by bound variables.
wenzelm@20519
   368
wenzelm@20537
   369
  \item @{ML betapply}~@{text "(t, u)"} produces an application @{text
wenzelm@20537
   370
  "t u"}, with topmost @{text "\<beta>"}-conversion if @{text "t"} is an
wenzelm@20537
   371
  abstraction.
wenzelm@20519
   372
wenzelm@20519
   373
  \item @{ML Sign.add_consts_i}~@{text "[(c, \<sigma>, mx), \<dots>]"} declares a
wenzelm@20519
   374
  new constant @{text "c :: \<sigma>"} with optional mixfix syntax.
wenzelm@20519
   375
wenzelm@20519
   376
  \item @{ML Sign.add_abbrevs}~@{text "print_mode [((c, t), mx), \<dots>]"}
wenzelm@20519
   377
  declares a new term abbreviation @{text "c \<equiv> t"} with optional
wenzelm@20519
   378
  mixfix syntax.
wenzelm@20519
   379
wenzelm@20520
   380
  \item @{ML Sign.const_typargs}~@{text "thy (c, \<tau>)"} and @{ML
wenzelm@20520
   381
  Sign.const_instance}~@{text "thy (c, [\<tau>\<^isub>1, \<dots>, \<tau>\<^isub>n])"}
wenzelm@20537
   382
  convert between the representations of polymorphic constants: the
wenzelm@20537
   383
  full type instance vs.\ the compact type arguments form (depending
wenzelm@20537
   384
  on the most general declaration given in the context).
wenzelm@18537
   385
wenzelm@20514
   386
  \end{description}
wenzelm@18537
   387
*}
wenzelm@18537
   388
wenzelm@18537
   389
wenzelm@20451
   390
section {* Theorems \label{sec:thms} *}
wenzelm@18537
   391
wenzelm@18537
   392
text {*
wenzelm@20521
   393
  \glossary{Proposition}{FIXME A \seeglossary{term} of
wenzelm@20521
   394
  \seeglossary{type} @{text "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 @{text "A \<Longrightarrow> B"} or universal quantification @{text
wenzelm@20521
   398
  "\<And>x. B x"} --- anything else is considered atomic.  The canonical
wenzelm@20521
   399
  form for propositions is that of a \seeglossary{Hereditary Harrop
wenzelm@20521
   400
  Formula}. FIXME}
wenzelm@20480
   401
wenzelm@20501
   402
  \glossary{Theorem}{A proven proposition within a certain theory and
wenzelm@20501
   403
  proof context, formally @{text "\<Gamma> \<turnstile>\<^sub>\<Theta> \<phi>"}; both contexts are
wenzelm@20501
   404
  rarely spelled out explicitly.  Theorems are usually normalized
wenzelm@20501
   405
  according to the \seeglossary{HHF} format. FIXME}
wenzelm@20480
   406
wenzelm@20519
   407
  \glossary{Fact}{Sometimes used interchangeably for
wenzelm@20501
   408
  \seeglossary{theorem}.  Strictly speaking, a list of theorems,
wenzelm@20501
   409
  essentially an extra-logical conjunction.  Facts emerge either as
wenzelm@20501
   410
  local assumptions, or as results of local goal statements --- both
wenzelm@20501
   411
  may be simultaneous, hence the list representation. FIXME}
wenzelm@18537
   412
wenzelm@20501
   413
  \glossary{Schematic variable}{FIXME}
wenzelm@20501
   414
wenzelm@20501
   415
  \glossary{Fixed variable}{A variable that is bound within a certain
wenzelm@20501
   416
  proof context; an arbitrary-but-fixed entity within a portion of
wenzelm@20501
   417
  proof text. FIXME}
wenzelm@18537
   418
wenzelm@20501
   419
  \glossary{Free variable}{Synonymous for \seeglossary{fixed
wenzelm@20501
   420
  variable}. FIXME}
wenzelm@20501
   421
wenzelm@20501
   422
  \glossary{Bound variable}{FIXME}
wenzelm@18537
   423
wenzelm@20501
   424
  \glossary{Variable}{See \seeglossary{schematic variable},
wenzelm@20501
   425
  \seeglossary{fixed variable}, \seeglossary{bound variable}, or
wenzelm@20501
   426
  \seeglossary{type variable}.  The distinguishing feature of
wenzelm@20501
   427
  different variables is their binding scope. FIXME}
wenzelm@18537
   428
wenzelm@20521
   429
  A \emph{proposition} is a well-formed term of type @{text "prop"}, a
wenzelm@20521
   430
  \emph{theorem} is a proven proposition (depending on a context of
wenzelm@20521
   431
  hypotheses and the background theory).  Primitive inferences include
wenzelm@20521
   432
  plain natural deduction rules for the primary connectives @{text
wenzelm@20537
   433
  "\<And>"} and @{text "\<Longrightarrow>"} of the framework.  There is also a builtin
wenzelm@20537
   434
  notion of equality/equivalence @{text "\<equiv>"}.
wenzelm@20521
   435
*}
wenzelm@20521
   436
wenzelm@20537
   437
subsection {* Primitive connectives and rules *}
wenzelm@18537
   438
wenzelm@20521
   439
text {*
wenzelm@20537
   440
  The theory @{text "Pure"} contains declarations for the standard
wenzelm@20537
   441
  connectives @{text "\<And>"}, @{text "\<Longrightarrow>"}, and @{text "\<equiv>"} of the logical
wenzelm@20537
   442
  framework, see \figref{fig:pure-connectives}.  The derivability
wenzelm@20537
   443
  judgment @{text "A\<^isub>1, \<dots>, A\<^isub>n \<turnstile> B"} is defined
wenzelm@20537
   444
  inductively by the primitive inferences given in
wenzelm@20537
   445
  \figref{fig:prim-rules}, with the global restriction that hypotheses
wenzelm@20537
   446
  @{text "\<Gamma>"} may \emph{not} contain schematic variables.  The builtin
wenzelm@20537
   447
  equality is conceptually axiomatized as shown in
wenzelm@20521
   448
  \figref{fig:pure-equality}, although the implementation works
wenzelm@20537
   449
  directly with derived inference rules.
wenzelm@20521
   450
wenzelm@20521
   451
  \begin{figure}[htb]
wenzelm@20521
   452
  \begin{center}
wenzelm@20501
   453
  \begin{tabular}{ll}
wenzelm@20501
   454
  @{text "all :: (\<alpha> \<Rightarrow> prop) \<Rightarrow> prop"} & universal quantification (binder @{text "\<And>"}) \\
wenzelm@20501
   455
  @{text "\<Longrightarrow> :: prop \<Rightarrow> prop \<Rightarrow> prop"} & implication (right associative infix) \\
wenzelm@20521
   456
  @{text "\<equiv> :: \<alpha> \<Rightarrow> \<alpha> \<Rightarrow> prop"} & equality relation (infix) \\
wenzelm@20501
   457
  \end{tabular}
wenzelm@20537
   458
  \caption{Primitive connectives of Pure}\label{fig:pure-connectives}
wenzelm@20521
   459
  \end{center}
wenzelm@20521
   460
  \end{figure}
wenzelm@18537
   461
wenzelm@20501
   462
  \begin{figure}[htb]
wenzelm@20501
   463
  \begin{center}
wenzelm@20498
   464
  \[
wenzelm@20498
   465
  \infer[@{text "(axiom)"}]{@{text "\<turnstile> A"}}{@{text "A \<in> \<Theta>"}}
wenzelm@20498
   466
  \qquad
wenzelm@20498
   467
  \infer[@{text "(assume)"}]{@{text "A \<turnstile> A"}}{}
wenzelm@20498
   468
  \]
wenzelm@20498
   469
  \[
wenzelm@20537
   470
  \infer[@{text "(\<And>_intro)"}]{@{text "\<Gamma> \<turnstile> \<And>x. b[x]"}}{@{text "\<Gamma> \<turnstile> b[x]"} & @{text "x \<notin> \<Gamma>"}}
wenzelm@20498
   471
  \qquad
wenzelm@20537
   472
  \infer[@{text "(\<And>_elim)"}]{@{text "\<Gamma> \<turnstile> b[a]"}}{@{text "\<Gamma> \<turnstile> \<And>x. b[x]"}}
wenzelm@20498
   473
  \]
wenzelm@20498
   474
  \[
wenzelm@20498
   475
  \infer[@{text "(\<Longrightarrow>_intro)"}]{@{text "\<Gamma> - A \<turnstile> A \<Longrightarrow> B"}}{@{text "\<Gamma> \<turnstile> B"}}
wenzelm@20498
   476
  \qquad
wenzelm@20498
   477
  \infer[@{text "(\<Longrightarrow>_elim)"}]{@{text "\<Gamma>\<^sub>1 \<union> \<Gamma>\<^sub>2 \<turnstile> B"}}{@{text "\<Gamma>\<^sub>1 \<turnstile> A \<Longrightarrow> B"} & @{text "\<Gamma>\<^sub>2 \<turnstile> A"}}
wenzelm@20498
   478
  \]
wenzelm@20521
   479
  \caption{Primitive inferences of Pure}\label{fig:prim-rules}
wenzelm@20521
   480
  \end{center}
wenzelm@20521
   481
  \end{figure}
wenzelm@20521
   482
wenzelm@20521
   483
  \begin{figure}[htb]
wenzelm@20521
   484
  \begin{center}
wenzelm@20521
   485
  \begin{tabular}{ll}
wenzelm@20537
   486
  @{text "\<turnstile> (\<lambda>x. b[x]) a \<equiv> b[a]"} & @{text "\<beta>"}-conversion \\
wenzelm@20521
   487
  @{text "\<turnstile> x \<equiv> x"} & reflexivity \\
wenzelm@20521
   488
  @{text "\<turnstile> x \<equiv> y \<Longrightarrow> P x \<Longrightarrow> P y"} & substitution \\
wenzelm@20521
   489
  @{text "\<turnstile> (\<And>x. f x \<equiv> g x) \<Longrightarrow> f \<equiv> g"} & extensionality \\
wenzelm@20537
   490
  @{text "\<turnstile> (A \<Longrightarrow> B) \<Longrightarrow> (B \<Longrightarrow> A) \<Longrightarrow> A \<equiv> B"} & logical equivalence \\
wenzelm@20521
   491
  \end{tabular}
wenzelm@20537
   492
  \caption{Conceptual axiomatization of @{text "\<equiv>"}}\label{fig:pure-equality}
wenzelm@20501
   493
  \end{center}
wenzelm@20501
   494
  \end{figure}
wenzelm@18537
   495
wenzelm@20501
   496
  The introduction and elimination rules for @{text "\<And>"} and @{text
wenzelm@20537
   497
  "\<Longrightarrow>"} are analogous to formation of dependently typed @{text
wenzelm@20501
   498
  "\<lambda>"}-terms representing the underlying proof objects.  Proof terms
wenzelm@20537
   499
  are irrelevant in the Pure logic, though, they may never occur
wenzelm@20537
   500
  within propositions.  The system provides a runtime option to record
wenzelm@20537
   501
  explicit proof terms for primitive inferences.  Thus all three
wenzelm@20537
   502
  levels of @{text "\<lambda>"}-calculus become explicit: @{text "\<Rightarrow>"} for
wenzelm@20537
   503
  terms, and @{text "\<And>/\<Longrightarrow>"} for proofs (cf.\
wenzelm@20537
   504
  \cite{Berghofer-Nipkow:2000:TPHOL}).
wenzelm@20491
   505
wenzelm@20537
   506
  Observe that locally fixed parameters (as in @{text "\<And>_intro"}) need
wenzelm@20537
   507
  not be recorded in the hypotheses, because the simple syntactic
wenzelm@20537
   508
  types of Pure are always inhabitable.  Typing ``assumptions'' @{text
wenzelm@20537
   509
  "x :: \<tau>"} are (implicitly) present only with occurrences of @{text
wenzelm@20537
   510
  "x\<^isub>\<tau>"} in the statement body.\footnote{This is the key
wenzelm@20537
   511
  difference ``@{text "\<lambda>HOL"}'' in the PTS framework
wenzelm@20537
   512
  \cite{Barendregt-Geuvers:2001}, where @{text "x : A"} hypotheses are
wenzelm@20537
   513
  treated explicitly for types, in the same way as propositions.}
wenzelm@20501
   514
wenzelm@20521
   515
  \medskip FIXME @{text "\<alpha>\<beta>\<eta>"}-equivalence and primitive definitions
wenzelm@20521
   516
wenzelm@20521
   517
  Since the basic representation of terms already accounts for @{text
wenzelm@20521
   518
  "\<alpha>"}-conversion, Pure equality essentially acts like @{text
wenzelm@20521
   519
  "\<alpha>\<beta>\<eta>"}-equivalence on terms, while coinciding with bi-implication.
wenzelm@20501
   520
wenzelm@20501
   521
  \medskip The axiomatization of a theory is implicitly closed by
wenzelm@20537
   522
  forming all instances of type and term variables: @{text "\<turnstile>
wenzelm@20537
   523
  A\<vartheta>"} holds for any substitution instance of an axiom
wenzelm@20537
   524
  @{text "\<turnstile> A"}.  By pushing substitution through derivations
wenzelm@20537
   525
  inductively, we get admissible @{text "generalize"} and @{text
wenzelm@20537
   526
  "instance"} rules shown in \figref{fig:subst-rules}.
wenzelm@20501
   527
wenzelm@20501
   528
  \begin{figure}[htb]
wenzelm@20501
   529
  \begin{center}
wenzelm@20498
   530
  \[
wenzelm@20501
   531
  \infer{@{text "\<Gamma> \<turnstile> B[?\<alpha>]"}}{@{text "\<Gamma> \<turnstile> B[\<alpha>]"} & @{text "\<alpha> \<notin> \<Gamma>"}}
wenzelm@20501
   532
  \quad
wenzelm@20501
   533
  \infer[\quad@{text "(generalize)"}]{@{text "\<Gamma> \<turnstile> B[?x]"}}{@{text "\<Gamma> \<turnstile> B[x]"} & @{text "x \<notin> \<Gamma>"}}
wenzelm@20498
   534
  \]
wenzelm@20498
   535
  \[
wenzelm@20501
   536
  \infer{@{text "\<Gamma> \<turnstile> B[\<tau>]"}}{@{text "\<Gamma> \<turnstile> B[?\<alpha>]"}}
wenzelm@20501
   537
  \quad
wenzelm@20501
   538
  \infer[\quad@{text "(instantiate)"}]{@{text "\<Gamma> \<turnstile> B[t]"}}{@{text "\<Gamma> \<turnstile> B[?x]"}}
wenzelm@20498
   539
  \]
wenzelm@20501
   540
  \caption{Admissible substitution rules}\label{fig:subst-rules}
wenzelm@20501
   541
  \end{center}
wenzelm@20501
   542
  \end{figure}
wenzelm@18537
   543
wenzelm@20537
   544
  Note that @{text "instantiate"} does not require an explicit
wenzelm@20537
   545
  side-condition, because @{text "\<Gamma>"} may never contain schematic
wenzelm@20537
   546
  variables.
wenzelm@20537
   547
wenzelm@20537
   548
  In principle, variables could be substituted in hypotheses as well,
wenzelm@20537
   549
  but this would disrupt monotonicity reasoning: deriving @{text
wenzelm@20537
   550
  "\<Gamma>\<vartheta> \<turnstile> B\<vartheta>"} from @{text "\<Gamma> \<turnstile> B"} is correct, but
wenzelm@20537
   551
  @{text "\<Gamma>\<vartheta> \<supseteq> \<Gamma>"} does not necessarily hold --- the result
wenzelm@20537
   552
  belongs to a different proof context.
wenzelm@20521
   553
*}
wenzelm@20498
   554
wenzelm@20521
   555
text %mlref {*
wenzelm@20521
   556
  \begin{mldecls}
wenzelm@20521
   557
  @{index_ML_type ctyp} \\
wenzelm@20521
   558
  @{index_ML_type cterm} \\
wenzelm@20521
   559
  @{index_ML_type thm} \\
wenzelm@20521
   560
  \end{mldecls}
wenzelm@20521
   561
wenzelm@20521
   562
  \begin{description}
wenzelm@20521
   563
wenzelm@20521
   564
  \item @{ML_type ctyp} FIXME
wenzelm@20521
   565
wenzelm@20521
   566
  \item @{ML_type cterm} FIXME
wenzelm@20521
   567
wenzelm@20521
   568
  \item @{ML_type thm} FIXME
wenzelm@20521
   569
wenzelm@20521
   570
  \end{description}
wenzelm@20521
   571
*}
wenzelm@20521
   572
wenzelm@20521
   573
wenzelm@20521
   574
subsection {* Auxiliary connectives *}
wenzelm@20521
   575
wenzelm@20521
   576
text {*
wenzelm@20537
   577
  Theory @{text "Pure"} also defines a few auxiliary connectives, see
wenzelm@20537
   578
  \figref{fig:pure-aux}.  These are normally not exposed to the user,
wenzelm@20537
   579
  but appear in internal encodings only.
wenzelm@20501
   580
wenzelm@20501
   581
  \begin{figure}[htb]
wenzelm@20501
   582
  \begin{center}
wenzelm@20498
   583
  \begin{tabular}{ll}
wenzelm@20521
   584
  @{text "conjunction :: prop \<Rightarrow> prop \<Rightarrow> prop"} & (infix @{text "&"}) \\
wenzelm@20521
   585
  @{text "\<turnstile> A & B \<equiv> (\<And>C. (A \<Longrightarrow> B \<Longrightarrow> C) \<Longrightarrow> C)"} \\[1ex]
wenzelm@20537
   586
  @{text "prop :: prop \<Rightarrow> prop"} & (prefix @{text "#"}, hidden) \\
wenzelm@20521
   587
  @{text "#A \<equiv> A"} \\[1ex]
wenzelm@20521
   588
  @{text "term :: \<alpha> \<Rightarrow> prop"} & (prefix @{text "TERM"}) \\
wenzelm@20521
   589
  @{text "term x \<equiv> (\<And>A. A \<Longrightarrow> A)"} \\[1ex]
wenzelm@20521
   590
  @{text "TYPE :: \<alpha> itself"} & (prefix @{text "TYPE"}) \\
wenzelm@20521
   591
  @{text "(unspecified)"} \\
wenzelm@20498
   592
  \end{tabular}
wenzelm@20521
   593
  \caption{Definitions of auxiliary connectives}\label{fig:pure-aux}
wenzelm@20501
   594
  \end{center}
wenzelm@20501
   595
  \end{figure}
wenzelm@20501
   596
wenzelm@20537
   597
  Derived conjunction rules include introduction @{text "A \<Longrightarrow> B \<Longrightarrow> A &
wenzelm@20537
   598
  B"}, and destructions @{text "A & B \<Longrightarrow> A"} and @{text "A & B \<Longrightarrow> B"}.
wenzelm@20537
   599
  Conjunction allows to treat simultaneous assumptions and conclusions
wenzelm@20537
   600
  uniformly.  For example, multiple claims are intermediately
wenzelm@20537
   601
  represented as explicit conjunction, but this is usually refined
wenzelm@20537
   602
  into separate sub-goals before the user continues the proof; the
wenzelm@20537
   603
  final result is projected into a list of theorems (cf.\
wenzelm@20537
   604
  \secref{sec:tactical-goals}).
wenzelm@20498
   605
wenzelm@20537
   606
  The @{text "prop"} marker (@{text "#"}) makes arbitrarily complex
wenzelm@20537
   607
  propositions appear as atomic, without changing the meaning: @{text
wenzelm@20537
   608
  "\<Gamma> \<turnstile> A"} and @{text "\<Gamma> \<turnstile> #A"} are interchangeable.  See
wenzelm@20537
   609
  \secref{sec:tactical-goals} for specific operations.
wenzelm@20521
   610
wenzelm@20537
   611
  The @{text "term"} marker turns any well-formed term into a
wenzelm@20537
   612
  derivable proposition: @{text "\<turnstile> TERM t"} holds unconditionally.
wenzelm@20537
   613
  Although this is logically vacuous, it allows to treat terms and
wenzelm@20537
   614
  proofs uniformly, similar to a type-theoretic framework.
wenzelm@20498
   615
wenzelm@20537
   616
  The @{text "TYPE"} constructor is the canonical representative of
wenzelm@20537
   617
  the unspecified type @{text "\<alpha> itself"}; it essentially injects the
wenzelm@20537
   618
  language of types into that of terms.  There is specific notation
wenzelm@20537
   619
  @{text "TYPE(\<tau>)"} for @{text "TYPE\<^bsub>\<tau>
wenzelm@20521
   620
 itself\<^esub>"}.
wenzelm@20537
   621
  Although being devoid of any particular meaning, the @{text
wenzelm@20537
   622
  "TYPE(\<tau>)"} accounts for the type @{text "\<tau>"} within the term
wenzelm@20537
   623
  language.  In particular, @{text "TYPE(\<alpha>)"} may be used as formal
wenzelm@20537
   624
  argument in primitive definitions, in order to circumvent hidden
wenzelm@20537
   625
  polymorphism (cf.\ \secref{sec:terms}).  For example, @{text "c
wenzelm@20537
   626
  TYPE(\<alpha>) \<equiv> A[\<alpha>]"} defines @{text "c :: \<alpha> itself \<Rightarrow> prop"} in terms of
wenzelm@20537
   627
  a proposition @{text "A"} that depends on an additional type
wenzelm@20537
   628
  argument, which is essentially a predicate on types.
wenzelm@20521
   629
*}
wenzelm@20501
   630
wenzelm@20521
   631
text %mlref {*
wenzelm@20521
   632
  \begin{mldecls}
wenzelm@20521
   633
  @{index_ML Conjunction.intr: "thm -> thm -> thm"} \\
wenzelm@20521
   634
  @{index_ML Conjunction.elim: "thm -> thm * thm"} \\
wenzelm@20521
   635
  @{index_ML Drule.mk_term: "cterm -> thm"} \\
wenzelm@20521
   636
  @{index_ML Drule.dest_term: "thm -> cterm"} \\
wenzelm@20521
   637
  @{index_ML Logic.mk_type: "typ -> term"} \\
wenzelm@20521
   638
  @{index_ML Logic.dest_type: "term -> typ"} \\
wenzelm@20521
   639
  \end{mldecls}
wenzelm@20521
   640
wenzelm@20521
   641
  \begin{description}
wenzelm@20521
   642
wenzelm@20521
   643
  \item FIXME
wenzelm@20521
   644
wenzelm@20521
   645
  \end{description}
wenzelm@20491
   646
*}
wenzelm@18537
   647
wenzelm@20480
   648
wenzelm@20491
   649
section {* Rules \label{sec:rules} *}
wenzelm@18537
   650
wenzelm@18537
   651
text {*
wenzelm@18537
   652
wenzelm@18537
   653
FIXME
wenzelm@18537
   654
wenzelm@20491
   655
  A \emph{rule} is any Pure theorem in HHF normal form; there is a
wenzelm@20491
   656
  separate calculus for rule composition, which is modeled after
wenzelm@20491
   657
  Gentzen's Natural Deduction \cite{Gentzen:1935}, but allows
wenzelm@20491
   658
  rules to be nested arbitrarily, similar to \cite{extensions91}.
wenzelm@20491
   659
wenzelm@20491
   660
  Normally, all theorems accessible to the user are proper rules.
wenzelm@20491
   661
  Low-level inferences are occasional required internally, but the
wenzelm@20491
   662
  result should be always presented in canonical form.  The higher
wenzelm@20491
   663
  interfaces of Isabelle/Isar will always produce proper rules.  It is
wenzelm@20491
   664
  important to maintain this invariant in add-on applications!
wenzelm@20491
   665
wenzelm@20491
   666
  There are two main principles of rule composition: @{text
wenzelm@20491
   667
  "resolution"} (i.e.\ backchaining of rules) and @{text
wenzelm@20491
   668
  "by-assumption"} (i.e.\ closing a branch); both principles are
wenzelm@20519
   669
  combined in the variants of @{text "elim-resolution"} and @{text
wenzelm@20491
   670
  "dest-resolution"}.  Raw @{text "composition"} is occasionally
wenzelm@20491
   671
  useful as well, also it is strictly speaking outside of the proper
wenzelm@20491
   672
  rule calculus.
wenzelm@20491
   673
wenzelm@20491
   674
  Rules are treated modulo general higher-order unification, which is
wenzelm@20491
   675
  unification modulo the equational theory of @{text "\<alpha>\<beta>\<eta>"}-conversion
wenzelm@20491
   676
  on @{text "\<lambda>"}-terms.  Moreover, propositions are understood modulo
wenzelm@20491
   677
  the (derived) equivalence @{text "(A \<Longrightarrow> (\<And>x. B x)) \<equiv> (\<And>x. A \<Longrightarrow> B x)"}.
wenzelm@20491
   678
wenzelm@20491
   679
  This means that any operations within the rule calculus may be
wenzelm@20491
   680
  subject to spontaneous @{text "\<alpha>\<beta>\<eta>"}-HHF conversions.  It is common
wenzelm@20491
   681
  practice not to contract or expand unnecessarily.  Some mechanisms
wenzelm@20491
   682
  prefer an one form, others the opposite, so there is a potential
wenzelm@20491
   683
  danger to produce some oscillation!
wenzelm@20491
   684
wenzelm@20491
   685
  Only few operations really work \emph{modulo} HHF conversion, but
wenzelm@20491
   686
  expect a normal form: quantifiers @{text "\<And>"} before implications
wenzelm@20491
   687
  @{text "\<Longrightarrow>"} at each level of nesting.
wenzelm@20491
   688
wenzelm@18537
   689
\glossary{Hereditary Harrop Formula}{The set of propositions in HHF
wenzelm@18537
   690
format is defined inductively as @{text "H = (\<And>x\<^sup>*. H\<^sup>* \<Longrightarrow>
wenzelm@18537
   691
A)"}, for variables @{text "x"} and atomic propositions @{text "A"}.
wenzelm@18537
   692
Any proposition may be put into HHF form by normalizing with the rule
wenzelm@18537
   693
@{text "(A \<Longrightarrow> (\<And>x. B x)) \<equiv> (\<And>x. A \<Longrightarrow> B x)"}.  In Isabelle, the outermost
wenzelm@18537
   694
quantifier prefix is represented via \seeglossary{schematic
wenzelm@18537
   695
variables}, such that the top-level structure is merely that of a
wenzelm@18537
   696
\seeglossary{Horn Clause}}.
wenzelm@18537
   697
wenzelm@18537
   698
\glossary{HHF}{See \seeglossary{Hereditary Harrop Formula}.}
wenzelm@18537
   699
wenzelm@20498
   700
wenzelm@20498
   701
  \[
wenzelm@20498
   702
  \infer[@{text "(assumption)"}]{@{text "C\<vartheta>"}}
wenzelm@20498
   703
  {@{text "(\<And>\<^vec>x. \<^vec>H \<^vec>x \<Longrightarrow> A \<^vec>x) \<Longrightarrow> C"} & @{text "A\<vartheta> = H\<^sub>i\<vartheta>"}~~\text{(for some~@{text i})}}
wenzelm@20498
   704
  \]
wenzelm@20498
   705
wenzelm@20498
   706
wenzelm@20498
   707
  \[
wenzelm@20498
   708
  \infer[@{text "(compose)"}]{@{text "\<^vec>A\<vartheta> \<Longrightarrow> C\<vartheta>"}}
wenzelm@20498
   709
  {@{text "\<^vec>A \<Longrightarrow> B"} & @{text "B' \<Longrightarrow> C"} & @{text "B\<vartheta> = B'\<vartheta>"}}
wenzelm@20498
   710
  \]
wenzelm@20498
   711
wenzelm@20498
   712
wenzelm@20498
   713
  \[
wenzelm@20498
   714
  \infer[@{text "(\<And>_lift)"}]{@{text "(\<And>\<^vec>x. \<^vec>A (?\<^vec>a \<^vec>x)) \<Longrightarrow> (\<And>\<^vec>x. B (?\<^vec>a \<^vec>x))"}}{@{text "\<^vec>A ?\<^vec>a \<Longrightarrow> B ?\<^vec>a"}}
wenzelm@20498
   715
  \]
wenzelm@20498
   716
  \[
wenzelm@20498
   717
  \infer[@{text "(\<Longrightarrow>_lift)"}]{@{text "(\<^vec>H \<Longrightarrow> \<^vec>A) \<Longrightarrow> (\<^vec>H \<Longrightarrow> B)"}}{@{text "\<^vec>A \<Longrightarrow> B"}}
wenzelm@20498
   718
  \]
wenzelm@20498
   719
wenzelm@20498
   720
  The @{text resolve} scheme is now acquired from @{text "\<And>_lift"},
wenzelm@20498
   721
  @{text "\<Longrightarrow>_lift"}, and @{text compose}.
wenzelm@20498
   722
wenzelm@20498
   723
  \[
wenzelm@20498
   724
  \infer[@{text "(resolution)"}]
wenzelm@20498
   725
  {@{text "(\<And>\<^vec>x. \<^vec>H \<^vec>x \<Longrightarrow> \<^vec>A (?\<^vec>a \<^vec>x))\<vartheta> \<Longrightarrow> C\<vartheta>"}}
wenzelm@20498
   726
  {\begin{tabular}{l}
wenzelm@20498
   727
    @{text "\<^vec>A ?\<^vec>a \<Longrightarrow> B ?\<^vec>a"} \\
wenzelm@20498
   728
    @{text "(\<And>\<^vec>x. \<^vec>H \<^vec>x \<Longrightarrow> B' \<^vec>x) \<Longrightarrow> C"} \\
wenzelm@20498
   729
    @{text "(\<lambda>\<^vec>x. B (?\<^vec>a \<^vec>x))\<vartheta> = B'\<vartheta>"} \\
wenzelm@20498
   730
   \end{tabular}}
wenzelm@20498
   731
  \]
wenzelm@20498
   732
wenzelm@20498
   733
wenzelm@20498
   734
  FIXME @{text "elim_resolution"}, @{text "dest_resolution"}
wenzelm@18537
   735
*}
wenzelm@18537
   736
wenzelm@20498
   737
wenzelm@18537
   738
end