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