doc-src/IsarImplementation/Thy/logic.thy
author wenzelm
Mon Sep 11 12:27:30 2006 +0200 (2006-09-11)
changeset 20498 825a8d2335ce
parent 20494 99ad217b6974
child 20501 de0b523b0d62
permissions -rw-r--r--
more rules;
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@20480
    23
  Pure derivations are relative to a logical theory, which declares
wenzelm@20491
    24
  type constructors, term constants, and axioms.  Theory declarations
wenzelm@20491
    25
  support schematic polymorphism, which is strictly speaking outside
wenzelm@20491
    26
  the logic.\footnote{Incidently, this is the main logical reason, why
wenzelm@20491
    27
  the theory context @{text "\<Theta>"} is separate from the context @{text
wenzelm@20491
    28
  "\<Gamma>"} 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@20480
    45
  A \emph{sort} is a list of type classes written as @{text
wenzelm@20480
    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@20493
    59
  (starting with a @{text "'"} character) and a sort constraint.  For
wenzelm@20480
    60
  example, @{text "('a, s)"} which is usually printed as @{text
wenzelm@20480
    61
  "\<alpha>\<^isub>s"}.  A \emph{schematic type variable} is a pair of an
wenzelm@20480
    62
  indexname and a sort constraint.  For example, @{text "(('a, 0),
wenzelm@20491
    63
  s)"} which is usually 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@20494
    73
  usually written postfix as @{text "(\<alpha>\<^isub>1, \<dots>, \<alpha>\<^isub>k)\<kappa>"}.
wenzelm@20494
    74
  For @{text "k = 0"} the argument tuple is omitted, e.g.\ @{text
wenzelm@20494
    75
  "prop"} instead of @{text "()prop"}.  For @{text "k = 1"} the
wenzelm@20494
    76
  parentheses are omitted, e.g.\ @{text "\<alpha> list"} instead of @{text
wenzelm@20494
    77
  "(\<alpha>)list"}.  Further notation is provided for specific constructors,
wenzelm@20494
    78
  notably the right-associative infix @{text "\<alpha> \<Rightarrow> \<beta>"} instead of
wenzelm@20494
    79
  @{text "(\<alpha>, \<beta>)fun"}.
wenzelm@20480
    80
  
wenzelm@20480
    81
  A \emph{type} is defined inductively over type variables and type
wenzelm@20491
    82
  constructors as follows: @{text "\<tau> = \<alpha>\<^isub>s | ?\<alpha>\<^isub>s |
wenzelm@20494
    83
  (\<tau>\<^sub>1, \<dots>, \<tau>\<^sub>k)k"}.
wenzelm@20451
    84
wenzelm@20494
    85
  A \emph{type abbreviation} is a syntactic abbreviation @{text
wenzelm@20494
    86
  "(\<^vec>\<alpha>)\<kappa> = \<tau>"} of an arbitrary type expression @{text "\<tau>"} over
wenzelm@20494
    87
  variables @{text "\<^vec>\<alpha>"}.  Type abbreviations looks like type
wenzelm@20494
    88
  constructors at the surface, but are fully expanded before entering
wenzelm@20494
    89
  the 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@20494
   101
  relation: for each type constructor @{text "\<kappa>"} and classes @{text
wenzelm@20494
   102
  "c\<^isub>1 \<subseteq> c\<^isub>2"}, any arity @{text "\<kappa> ::
wenzelm@20494
   103
  (\<^vec>s\<^isub>1)c\<^isub>1"} has a corresponding arity @{text "\<kappa>
wenzelm@20480
   104
  :: (\<^vec>s\<^isub>2)c\<^isub>2"} where @{text "\<^vec>s\<^isub>1 \<subseteq>
wenzelm@20494
   105
  \<^vec>s\<^isub>2"} holds componentwise.
wenzelm@20451
   106
wenzelm@20491
   107
  The key property of a coregular order-sorted algebra is that sort
wenzelm@20494
   108
  constraints may be always solved in a most general fashion: for each
wenzelm@20494
   109
  type constructor @{text "\<kappa>"} and sort @{text "s"} there is a most
wenzelm@20494
   110
  general vector of argument sorts @{text "(s\<^isub>1, \<dots>,
wenzelm@20491
   111
  s\<^isub>k)"} such that a type scheme @{text
wenzelm@20494
   112
  "(\<alpha>\<^bsub>s\<^isub>1\<^esub>, \<dots>, \<alpha>\<^bsub>s\<^isub>k\<^esub>)\<kappa>"} is
wenzelm@20491
   113
  of sort @{text "s"}.  Consequently, the unification problem on the
wenzelm@20491
   114
  algebra of types has most general solutions (modulo renaming and
wenzelm@20491
   115
  equivalence of sorts).  Moreover, the usual type-inference algorithm
wenzelm@20491
   116
  will produce primary types as expected \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@20494
   125
  @{index_ML fold_atyps: "(typ -> 'a -> 'a) -> typ -> 'a -> 'a"} \\
wenzelm@20480
   126
  @{index_ML Sign.subsort: "theory -> sort * sort -> bool"} \\
wenzelm@20480
   127
  @{index_ML Sign.of_sort: "theory -> typ * sort -> bool"} \\
wenzelm@20480
   128
  @{index_ML Sign.add_types: "(bstring * int * mixfix) list -> theory -> theory"} \\
wenzelm@20480
   129
  @{index_ML Sign.add_tyabbrs_i: "
wenzelm@20480
   130
  (bstring * string list * typ * mixfix) list -> theory -> theory"} \\
wenzelm@20480
   131
  @{index_ML Sign.primitive_class: "string * class list -> theory -> theory"} \\
wenzelm@20480
   132
  @{index_ML Sign.primitive_classrel: "class * class -> theory -> theory"} \\
wenzelm@20480
   133
  @{index_ML Sign.primitive_arity: "arity -> theory -> theory"} \\
wenzelm@20480
   134
  \end{mldecls}
wenzelm@20480
   135
wenzelm@20480
   136
  \begin{description}
wenzelm@20480
   137
wenzelm@20480
   138
  \item @{ML_type class} represents type classes; this is an alias for
wenzelm@20480
   139
  @{ML_type string}.
wenzelm@20480
   140
wenzelm@20480
   141
  \item @{ML_type sort} represents sorts; this is an alias for
wenzelm@20480
   142
  @{ML_type "class list"}.
wenzelm@20451
   143
wenzelm@20480
   144
  \item @{ML_type arity} represents type arities; this is an alias for
wenzelm@20494
   145
  triples of the form @{text "(\<kappa>, \<^vec>s, s)"} for @{text "\<kappa> ::
wenzelm@20480
   146
  (\<^vec>s)s"} described above.
wenzelm@20480
   147
wenzelm@20480
   148
  \item @{ML_type typ} represents types; this is a datatype with
wenzelm@20480
   149
  constructors @{ML TFree}, @{ML TVar}, @{ML Type}.
wenzelm@20480
   150
wenzelm@20494
   151
  \item @{ML fold_atyps}~@{text "f \<tau>"} iterates function @{text "f"}
wenzelm@20494
   152
  over all occurrences of atoms (@{ML TFree} or @{ML TVar}) of @{text
wenzelm@20494
   153
  "\<tau>"}; the type structure is traversed from left to right.
wenzelm@20494
   154
wenzelm@20480
   155
  \item @{ML Sign.subsort}~@{text "thy (s\<^isub>1, s\<^isub>2)"}
wenzelm@20480
   156
  tests the subsort relation @{text "s\<^isub>1 \<subseteq> s\<^isub>2"}.
wenzelm@20480
   157
wenzelm@20480
   158
  \item @{ML Sign.of_sort}~@{text "thy (\<tau>, s)"} tests whether a type
wenzelm@20491
   159
  is of a given sort.
wenzelm@20480
   160
wenzelm@20494
   161
  \item @{ML Sign.add_types}~@{text "[(\<kappa>, k, mx), \<dots>]"} declares new
wenzelm@20494
   162
  type constructors @{text "\<kappa>"} with @{text "k"} arguments and
wenzelm@20480
   163
  optional mixfix syntax.
wenzelm@20451
   164
wenzelm@20494
   165
  \item @{ML Sign.add_tyabbrs_i}~@{text "[(\<kappa>, \<^vec>\<alpha>, \<tau>, mx), \<dots>]"}
wenzelm@20494
   166
  defines a new type abbreviation @{text "(\<^vec>\<alpha>)\<kappa> = \<tau>"} with
wenzelm@20491
   167
  optional mixfix syntax.
wenzelm@20480
   168
wenzelm@20480
   169
  \item @{ML Sign.primitive_class}~@{text "(c, [c\<^isub>1, \<dots>,
wenzelm@20494
   170
  c\<^isub>n])"} declares new class @{text "c"}, together with class
wenzelm@20494
   171
  relations @{text "c \<subseteq> c\<^isub>i"}, for @{text "i = 1, \<dots>, n"}.
wenzelm@20480
   172
wenzelm@20480
   173
  \item @{ML Sign.primitive_classrel}~@{text "(c\<^isub>1,
wenzelm@20480
   174
  c\<^isub>2)"} declares class relation @{text "c\<^isub>1 \<subseteq>
wenzelm@20480
   175
  c\<^isub>2"}.
wenzelm@20480
   176
wenzelm@20494
   177
  \item @{ML Sign.primitive_arity}~@{text "(\<kappa>, \<^vec>s, s)"} declares
wenzelm@20494
   178
  arity @{text "\<kappa> :: (\<^vec>s)s"}.
wenzelm@20480
   179
wenzelm@20480
   180
  \end{description}
wenzelm@20437
   181
*}
wenzelm@20437
   182
wenzelm@20437
   183
wenzelm@20480
   184
wenzelm@20451
   185
section {* Terms \label{sec:terms} *}
wenzelm@18537
   186
wenzelm@18537
   187
text {*
wenzelm@20451
   188
  \glossary{Term}{FIXME}
wenzelm@18537
   189
wenzelm@20491
   190
  The language of terms is that of simply-typed @{text "\<lambda>"}-calculus
wenzelm@20491
   191
  with de-Bruijn indices for bound variables, and named free
wenzelm@20491
   192
  variables, and constants.  Terms with loose bound variables are
wenzelm@20491
   193
  usually considered malformed.  The types of variables and constants
wenzelm@20491
   194
  is stored explicitly at each occurrence in the term (which is a
wenzelm@20491
   195
  known performance issue).
wenzelm@20491
   196
wenzelm@20451
   197
  FIXME de-Bruijn representation of lambda terms
wenzelm@20480
   198
wenzelm@20480
   199
  Term syntax provides explicit abstraction @{text "\<lambda>x :: \<alpha>. b(x)"}
wenzelm@20480
   200
  and application @{text "t u"}, while types are usually implicit
wenzelm@20480
   201
  thanks to type-inference.
wenzelm@20480
   202
wenzelm@20480
   203
  Terms of type @{text "prop"} are called
wenzelm@20480
   204
  propositions.  Logical statements are composed via @{text "\<And>x ::
wenzelm@20480
   205
  \<alpha>. B(x)"} and @{text "A \<Longrightarrow> B"}.
wenzelm@20498
   206
wenzelm@20498
   207
wenzelm@20498
   208
  \[
wenzelm@20498
   209
  \infer{@{text "(\<lambda>x\<^sub>\<tau>. t): \<tau> \<Rightarrow> \<sigma>"}}{@{text "t: \<sigma>"}}
wenzelm@20498
   210
  \qquad
wenzelm@20498
   211
  \infer{@{text "(t u): \<sigma>"}}{@{text "t: \<tau> \<Rightarrow> \<sigma>"} & @{text "u: \<tau>"}}
wenzelm@20498
   212
  \]
wenzelm@20498
   213
wenzelm@18537
   214
*}
wenzelm@18537
   215
wenzelm@18537
   216
wenzelm@18537
   217
text {*
wenzelm@18537
   218
wenzelm@18537
   219
FIXME
wenzelm@18537
   220
wenzelm@18537
   221
\glossary{Schematic polymorphism}{FIXME}
wenzelm@18537
   222
wenzelm@18537
   223
\glossary{Type variable}{FIXME}
wenzelm@18537
   224
wenzelm@18537
   225
*}
wenzelm@18537
   226
wenzelm@18537
   227
wenzelm@20451
   228
section {* Theorems \label{sec:thms} *}
wenzelm@18537
   229
wenzelm@18537
   230
text {*
wenzelm@18537
   231
wenzelm@20480
   232
  Primitive reasoning operates on judgments of the form @{text "\<Gamma> \<turnstile>
wenzelm@20480
   233
  \<phi>"}, with standard introduction and elimination rules for @{text
wenzelm@20480
   234
  "\<And>"} and @{text "\<Longrightarrow>"} that refer to fixed parameters @{text "x"} and
wenzelm@20480
   235
  hypotheses @{text "A"} from the context @{text "\<Gamma>"}.  The
wenzelm@20480
   236
  corresponding proof terms are left implicit in the classic
wenzelm@20480
   237
  ``LCF-approach'', although they could be exploited separately
wenzelm@20480
   238
  \cite{Berghofer-Nipkow:2000}.
wenzelm@20480
   239
wenzelm@20480
   240
  The framework also provides definitional equality @{text "\<equiv> :: \<alpha> \<Rightarrow> \<alpha>
wenzelm@20480
   241
  \<Rightarrow> prop"}, with @{text "\<alpha>\<beta>\<eta>"}-conversion rules.  The internal
wenzelm@20480
   242
  conjunction @{text "& :: prop \<Rightarrow> prop \<Rightarrow> prop"} enables the view of
wenzelm@20480
   243
  assumptions and conclusions emerging uniformly as simultaneous
wenzelm@20480
   244
  statements.
wenzelm@20480
   245
wenzelm@20480
   246
wenzelm@20480
   247
wenzelm@18537
   248
  FIXME
wenzelm@18537
   249
wenzelm@18537
   250
\glossary{Proposition}{A \seeglossary{term} of \seeglossary{type}
wenzelm@18537
   251
@{text "prop"}.  Internally, there is nothing special about
wenzelm@18537
   252
propositions apart from their type, but the concrete syntax enforces a
wenzelm@18537
   253
clear distinction.  Propositions are structured via implication @{text
wenzelm@18537
   254
"A \<Longrightarrow> B"} or universal quantification @{text "\<And>x. B x"} --- anything
wenzelm@18537
   255
else is considered atomic.  The canonical form for propositions is
wenzelm@18537
   256
that of a \seeglossary{Hereditary Harrop Formula}.}
wenzelm@18537
   257
wenzelm@18537
   258
\glossary{Theorem}{A proven proposition within a certain theory and
wenzelm@18537
   259
proof context, formally @{text "\<Gamma> \<turnstile>\<^sub>\<Theta> \<phi>"}; both contexts are
wenzelm@18537
   260
rarely spelled out explicitly.  Theorems are usually normalized
wenzelm@18537
   261
according to the \seeglossary{HHF} format.}
wenzelm@18537
   262
wenzelm@18537
   263
\glossary{Fact}{Sometimes used interchangably for
wenzelm@18537
   264
\seeglossary{theorem}.  Strictly speaking, a list of theorems,
wenzelm@18537
   265
essentially an extra-logical conjunction.  Facts emerge either as
wenzelm@18537
   266
local assumptions, or as results of local goal statements --- both may
wenzelm@18537
   267
be simultaneous, hence the list representation.}
wenzelm@18537
   268
wenzelm@18537
   269
\glossary{Schematic variable}{FIXME}
wenzelm@18537
   270
wenzelm@18537
   271
\glossary{Fixed variable}{A variable that is bound within a certain
wenzelm@18537
   272
proof context; an arbitrary-but-fixed entity within a portion of proof
wenzelm@18537
   273
text.}
wenzelm@18537
   274
wenzelm@18537
   275
\glossary{Free variable}{Synonymous for \seeglossary{fixed variable}.}
wenzelm@18537
   276
wenzelm@18537
   277
\glossary{Bound variable}{FIXME}
wenzelm@18537
   278
wenzelm@18537
   279
\glossary{Variable}{See \seeglossary{schematic variable},
wenzelm@18537
   280
\seeglossary{fixed variable}, \seeglossary{bound variable}, or
wenzelm@18537
   281
\seeglossary{type variable}.  The distinguishing feature of different
wenzelm@18537
   282
variables is their binding scope.}
wenzelm@18537
   283
wenzelm@20498
   284
wenzelm@20498
   285
  \[
wenzelm@20498
   286
  \infer[@{text "(axiom)"}]{@{text "\<turnstile> A"}}{@{text "A \<in> \<Theta>"}}
wenzelm@20498
   287
  \qquad
wenzelm@20498
   288
  \infer[@{text "(assume)"}]{@{text "A \<turnstile> A"}}{}
wenzelm@20498
   289
  \]
wenzelm@20498
   290
  \[
wenzelm@20498
   291
  \infer[@{text "(\<And>_intro)"}]{@{text "\<Gamma> \<turnstile> \<And>x. b x"}}{@{text "\<Gamma> \<turnstile> b x"} & @{text "x \<notin> \<Gamma>"}}
wenzelm@20498
   292
  \qquad
wenzelm@20498
   293
  \infer[@{text "(\<And>_elim)"}]{@{text "\<Gamma> \<turnstile> b a"}}{@{text "\<Gamma> \<turnstile> \<And>x. b x"}}
wenzelm@20498
   294
  \]
wenzelm@20498
   295
  \[
wenzelm@20498
   296
  \infer[@{text "(\<Longrightarrow>_intro)"}]{@{text "\<Gamma> - A \<turnstile> A \<Longrightarrow> B"}}{@{text "\<Gamma> \<turnstile> B"}}
wenzelm@20498
   297
  \qquad
wenzelm@20498
   298
  \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
   299
  \]
wenzelm@18537
   300
wenzelm@20491
   301
wenzelm@20498
   302
  Admissible rules:
wenzelm@20498
   303
  \[
wenzelm@20498
   304
  \infer[@{text "(generalize_type)"}]{@{text "\<Gamma> \<turnstile> B[?\<alpha>]"}}{@{text "\<Gamma> \<turnstile> B[\<alpha>]"} & @{text "\<alpha> \<notin> \<Gamma>"}}
wenzelm@20498
   305
  \qquad
wenzelm@20498
   306
  \infer[@{text "(generalize_term)"}]{@{text "\<Gamma> \<turnstile> B[?x]"}}{@{text "\<Gamma> \<turnstile> B[x]"} & @{text "x \<notin> \<Gamma>"}}
wenzelm@20498
   307
  \]
wenzelm@20498
   308
  \[
wenzelm@20498
   309
  \infer[@{text "(instantiate_type)"}]{@{text "\<Gamma> \<turnstile> B[\<tau>]"}}{@{text "\<Gamma> \<turnstile> B[?\<alpha>]"}}
wenzelm@20498
   310
  \qquad
wenzelm@20498
   311
  \infer[@{text "(instantiate_term)"}]{@{text "\<Gamma> \<turnstile> B[t]"}}{@{text "\<Gamma> \<turnstile> B[?x]"}}
wenzelm@20498
   312
  \]
wenzelm@18537
   313
wenzelm@20498
   314
  Note that @{text "instantiate_term"} could be derived using @{text
wenzelm@20498
   315
  "\<And>_intro/elim"}, but this is not how it is implemented.  The type
wenzelm@20498
   316
  instantiation rule is a genuine admissible one, due to the lack of true
wenzelm@20498
   317
  polymorphism in the logic.
wenzelm@20498
   318
wenzelm@20498
   319
wenzelm@20498
   320
  Equality and logical equivalence:
wenzelm@20498
   321
wenzelm@20498
   322
  \smallskip
wenzelm@20498
   323
  \begin{tabular}{ll}
wenzelm@20498
   324
  @{text "\<equiv> :: \<alpha> \<Rightarrow> \<alpha> \<Rightarrow> prop"} & equality relation (infix) \\
wenzelm@20498
   325
  @{text "\<turnstile> x \<equiv> x"} & reflexivity law \\
wenzelm@20498
   326
  @{text "\<turnstile> x \<equiv> y \<Longrightarrow> P x \<Longrightarrow> P y"} & substitution law \\
wenzelm@20498
   327
  @{text "\<turnstile> (\<And>x. f x \<equiv> g x) \<Longrightarrow> f \<equiv> g"} & extensionality \\
wenzelm@20498
   328
  @{text "\<turnstile> (A \<Longrightarrow> B) \<Longrightarrow> (B \<Longrightarrow> A) \<Longrightarrow> A \<equiv> B"} & coincidence with equivalence \\
wenzelm@20498
   329
  \end{tabular}
wenzelm@20498
   330
  \smallskip
wenzelm@20498
   331
wenzelm@20498
   332
wenzelm@20498
   333
wenzelm@20491
   334
*}
wenzelm@18537
   335
wenzelm@20480
   336
wenzelm@20491
   337
section {* Rules \label{sec:rules} *}
wenzelm@18537
   338
wenzelm@18537
   339
text {*
wenzelm@18537
   340
wenzelm@18537
   341
FIXME
wenzelm@18537
   342
wenzelm@20491
   343
  A \emph{rule} is any Pure theorem in HHF normal form; there is a
wenzelm@20491
   344
  separate calculus for rule composition, which is modeled after
wenzelm@20491
   345
  Gentzen's Natural Deduction \cite{Gentzen:1935}, but allows
wenzelm@20491
   346
  rules to be nested arbitrarily, similar to \cite{extensions91}.
wenzelm@20491
   347
wenzelm@20491
   348
  Normally, all theorems accessible to the user are proper rules.
wenzelm@20491
   349
  Low-level inferences are occasional required internally, but the
wenzelm@20491
   350
  result should be always presented in canonical form.  The higher
wenzelm@20491
   351
  interfaces of Isabelle/Isar will always produce proper rules.  It is
wenzelm@20491
   352
  important to maintain this invariant in add-on applications!
wenzelm@20491
   353
wenzelm@20491
   354
  There are two main principles of rule composition: @{text
wenzelm@20491
   355
  "resolution"} (i.e.\ backchaining of rules) and @{text
wenzelm@20491
   356
  "by-assumption"} (i.e.\ closing a branch); both principles are
wenzelm@20491
   357
  combined in the variants of @{text "elim-resosultion"} and @{text
wenzelm@20491
   358
  "dest-resolution"}.  Raw @{text "composition"} is occasionally
wenzelm@20491
   359
  useful as well, also it is strictly speaking outside of the proper
wenzelm@20491
   360
  rule calculus.
wenzelm@20491
   361
wenzelm@20491
   362
  Rules are treated modulo general higher-order unification, which is
wenzelm@20491
   363
  unification modulo the equational theory of @{text "\<alpha>\<beta>\<eta>"}-conversion
wenzelm@20491
   364
  on @{text "\<lambda>"}-terms.  Moreover, propositions are understood modulo
wenzelm@20491
   365
  the (derived) equivalence @{text "(A \<Longrightarrow> (\<And>x. B x)) \<equiv> (\<And>x. A \<Longrightarrow> B x)"}.
wenzelm@20491
   366
wenzelm@20491
   367
  This means that any operations within the rule calculus may be
wenzelm@20491
   368
  subject to spontaneous @{text "\<alpha>\<beta>\<eta>"}-HHF conversions.  It is common
wenzelm@20491
   369
  practice not to contract or expand unnecessarily.  Some mechanisms
wenzelm@20491
   370
  prefer an one form, others the opposite, so there is a potential
wenzelm@20491
   371
  danger to produce some oscillation!
wenzelm@20491
   372
wenzelm@20491
   373
  Only few operations really work \emph{modulo} HHF conversion, but
wenzelm@20491
   374
  expect a normal form: quantifiers @{text "\<And>"} before implications
wenzelm@20491
   375
  @{text "\<Longrightarrow>"} at each level of nesting.
wenzelm@20491
   376
wenzelm@18537
   377
\glossary{Hereditary Harrop Formula}{The set of propositions in HHF
wenzelm@18537
   378
format is defined inductively as @{text "H = (\<And>x\<^sup>*. H\<^sup>* \<Longrightarrow>
wenzelm@18537
   379
A)"}, for variables @{text "x"} and atomic propositions @{text "A"}.
wenzelm@18537
   380
Any proposition may be put into HHF form by normalizing with the rule
wenzelm@18537
   381
@{text "(A \<Longrightarrow> (\<And>x. B x)) \<equiv> (\<And>x. A \<Longrightarrow> B x)"}.  In Isabelle, the outermost
wenzelm@18537
   382
quantifier prefix is represented via \seeglossary{schematic
wenzelm@18537
   383
variables}, such that the top-level structure is merely that of a
wenzelm@18537
   384
\seeglossary{Horn Clause}}.
wenzelm@18537
   385
wenzelm@18537
   386
\glossary{HHF}{See \seeglossary{Hereditary Harrop Formula}.}
wenzelm@18537
   387
wenzelm@20498
   388
wenzelm@20498
   389
  \[
wenzelm@20498
   390
  \infer[@{text "(assumption)"}]{@{text "C\<vartheta>"}}
wenzelm@20498
   391
  {@{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
   392
  \]
wenzelm@20498
   393
wenzelm@20498
   394
wenzelm@20498
   395
  \[
wenzelm@20498
   396
  \infer[@{text "(compose)"}]{@{text "\<^vec>A\<vartheta> \<Longrightarrow> C\<vartheta>"}}
wenzelm@20498
   397
  {@{text "\<^vec>A \<Longrightarrow> B"} & @{text "B' \<Longrightarrow> C"} & @{text "B\<vartheta> = B'\<vartheta>"}}
wenzelm@20498
   398
  \]
wenzelm@20498
   399
wenzelm@20498
   400
wenzelm@20498
   401
  \[
wenzelm@20498
   402
  \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
   403
  \]
wenzelm@20498
   404
  \[
wenzelm@20498
   405
  \infer[@{text "(\<Longrightarrow>_lift)"}]{@{text "(\<^vec>H \<Longrightarrow> \<^vec>A) \<Longrightarrow> (\<^vec>H \<Longrightarrow> B)"}}{@{text "\<^vec>A \<Longrightarrow> B"}}
wenzelm@20498
   406
  \]
wenzelm@20498
   407
wenzelm@20498
   408
  The @{text resolve} scheme is now acquired from @{text "\<And>_lift"},
wenzelm@20498
   409
  @{text "\<Longrightarrow>_lift"}, and @{text compose}.
wenzelm@20498
   410
wenzelm@20498
   411
  \[
wenzelm@20498
   412
  \infer[@{text "(resolution)"}]
wenzelm@20498
   413
  {@{text "(\<And>\<^vec>x. \<^vec>H \<^vec>x \<Longrightarrow> \<^vec>A (?\<^vec>a \<^vec>x))\<vartheta> \<Longrightarrow> C\<vartheta>"}}
wenzelm@20498
   414
  {\begin{tabular}{l}
wenzelm@20498
   415
    @{text "\<^vec>A ?\<^vec>a \<Longrightarrow> B ?\<^vec>a"} \\
wenzelm@20498
   416
    @{text "(\<And>\<^vec>x. \<^vec>H \<^vec>x \<Longrightarrow> B' \<^vec>x) \<Longrightarrow> C"} \\
wenzelm@20498
   417
    @{text "(\<lambda>\<^vec>x. B (?\<^vec>a \<^vec>x))\<vartheta> = B'\<vartheta>"} \\
wenzelm@20498
   418
   \end{tabular}}
wenzelm@20498
   419
  \]
wenzelm@20498
   420
wenzelm@20498
   421
wenzelm@20498
   422
  FIXME @{text "elim_resolution"}, @{text "dest_resolution"}
wenzelm@18537
   423
*}
wenzelm@18537
   424
wenzelm@20498
   425
wenzelm@18537
   426
end