src/Doc/Implementation/Logic.thy
author wenzelm
Tue, 22 Sep 2015 22:38:22 +0200
changeset 61255 15865e0c5598
parent 61246 077b88f9ec16
child 61261 ddb2da7cb2e4
permissions -rw-r--r--
eliminated separate type Theory.dep: use typeargs uniformly for consts/types; Object_Logic.add_judgment more like Theory.specify_const;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
29755
d66b34e46bdf observe usual theory naming conventions;
wenzelm
parents: 29615
diff changeset
     1
theory Logic
d66b34e46bdf observe usual theory naming conventions;
wenzelm
parents: 29615
diff changeset
     2
imports Base
d66b34e46bdf observe usual theory naming conventions;
wenzelm
parents: 29615
diff changeset
     3
begin
18537
2681f9e34390 "The Isabelle/Isar Implementation" manual;
wenzelm
parents:
diff changeset
     4
58618
782f0b662cae more cartouches;
wenzelm
parents: 58555
diff changeset
     5
chapter \<open>Primitive logic \label{ch:logic}\<close>
18537
2681f9e34390 "The Isabelle/Isar Implementation" manual;
wenzelm
parents:
diff changeset
     6
58618
782f0b662cae more cartouches;
wenzelm
parents: 58555
diff changeset
     7
text \<open>
20480
4e0522d38968 more on types and type classes;
wenzelm
parents: 20477
diff changeset
     8
  The logical foundations of Isabelle/Isar are that of the Pure logic,
29774
wenzelm
parents: 29771
diff changeset
     9
  which has been introduced as a Natural Deduction framework in
58555
7975676c08c0 prefer @{cite} antiquotation;
wenzelm
parents: 56579
diff changeset
    10
  @{cite paulson700}.  This is essentially the same logic as ``@{text
20493
wenzelm
parents: 20491
diff changeset
    11
  "\<lambda>HOL"}'' in the more abstract setting of Pure Type Systems (PTS)
58555
7975676c08c0 prefer @{cite} antiquotation;
wenzelm
parents: 56579
diff changeset
    12
  @{cite "Barendregt-Geuvers:2001"}, although there are some key
20491
wenzelm
parents: 20480
diff changeset
    13
  differences in the specific treatment of simple types in
wenzelm
parents: 20480
diff changeset
    14
  Isabelle/Pure.
20480
4e0522d38968 more on types and type classes;
wenzelm
parents: 20477
diff changeset
    15
4e0522d38968 more on types and type classes;
wenzelm
parents: 20477
diff changeset
    16
  Following type-theoretic parlance, the Pure logic consists of three
20543
wenzelm
parents: 20542
diff changeset
    17
  levels of @{text "\<lambda>"}-calculus with corresponding arrows, @{text
20480
4e0522d38968 more on types and type classes;
wenzelm
parents: 20477
diff changeset
    18
  "\<Rightarrow>"} for syntactic function space (terms depending on terms), @{text
4e0522d38968 more on types and type classes;
wenzelm
parents: 20477
diff changeset
    19
  "\<And>"} for universal quantification (proofs depending on terms), and
4e0522d38968 more on types and type classes;
wenzelm
parents: 20477
diff changeset
    20
  @{text "\<Longrightarrow>"} for implication (proofs depending on proofs).
4e0522d38968 more on types and type classes;
wenzelm
parents: 20477
diff changeset
    21
20537
b6b49903db7e *** empty log message ***
wenzelm
parents: 20521
diff changeset
    22
  Derivations are relative to a logical theory, which declares type
b6b49903db7e *** empty log message ***
wenzelm
parents: 20521
diff changeset
    23
  constructors, constants, and axioms.  Theory declarations support
b6b49903db7e *** empty log message ***
wenzelm
parents: 20521
diff changeset
    24
  schematic polymorphism, which is strictly speaking outside the
b6b49903db7e *** empty log message ***
wenzelm
parents: 20521
diff changeset
    25
  logic.\footnote{This is the deeper logical reason, why the theory
b6b49903db7e *** empty log message ***
wenzelm
parents: 20521
diff changeset
    26
  context @{text "\<Theta>"} is separate from the proof context @{text "\<Gamma>"}
34929
9700a87f1cc2 misc tuning and clarification;
wenzelm
parents: 34921
diff changeset
    27
  of the core calculus: type constructors, term constants, and facts
9700a87f1cc2 misc tuning and clarification;
wenzelm
parents: 34921
diff changeset
    28
  (proof constants) may involve arbitrary type schemes, but the type
9700a87f1cc2 misc tuning and clarification;
wenzelm
parents: 34921
diff changeset
    29
  of a locally fixed term parameter is also fixed!}
58618
782f0b662cae more cartouches;
wenzelm
parents: 58555
diff changeset
    30
\<close>
20480
4e0522d38968 more on types and type classes;
wenzelm
parents: 20477
diff changeset
    31
4e0522d38968 more on types and type classes;
wenzelm
parents: 20477
diff changeset
    32
58618
782f0b662cae more cartouches;
wenzelm
parents: 58555
diff changeset
    33
section \<open>Types \label{sec:types}\<close>
20437
wenzelm
parents: 18537
diff changeset
    34
58618
782f0b662cae more cartouches;
wenzelm
parents: 58555
diff changeset
    35
text \<open>
20480
4e0522d38968 more on types and type classes;
wenzelm
parents: 20477
diff changeset
    36
  The language of types is an uninterpreted order-sorted first-order
4e0522d38968 more on types and type classes;
wenzelm
parents: 20477
diff changeset
    37
  algebra; types are qualified by ordered type classes.
4e0522d38968 more on types and type classes;
wenzelm
parents: 20477
diff changeset
    38
4e0522d38968 more on types and type classes;
wenzelm
parents: 20477
diff changeset
    39
  \medskip A \emph{type class} is an abstract syntactic entity
4e0522d38968 more on types and type classes;
wenzelm
parents: 20477
diff changeset
    40
  declared in the theory context.  The \emph{subclass relation} @{text
53015
a1119cf551e8 standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
wenzelm
parents: 52788
diff changeset
    41
  "c\<^sub>1 \<subseteq> c\<^sub>2"} is specified by stating an acyclic
20491
wenzelm
parents: 20480
diff changeset
    42
  generating relation; the transitive closure is maintained
wenzelm
parents: 20480
diff changeset
    43
  internally.  The resulting relation is an ordering: reflexive,
wenzelm
parents: 20480
diff changeset
    44
  transitive, and antisymmetric.
20451
27ea2ba48fa3 misc cleanup;
wenzelm
parents: 20450
diff changeset
    45
53015
a1119cf551e8 standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
wenzelm
parents: 52788
diff changeset
    46
  A \emph{sort} is a list of type classes written as @{text "s = {c\<^sub>1,
a1119cf551e8 standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
wenzelm
parents: 52788
diff changeset
    47
  \<dots>, c\<^sub>m}"}, it represents symbolic intersection.  Notationally, the
34929
9700a87f1cc2 misc tuning and clarification;
wenzelm
parents: 34921
diff changeset
    48
  curly braces are omitted for singleton intersections, i.e.\ any
9700a87f1cc2 misc tuning and clarification;
wenzelm
parents: 34921
diff changeset
    49
  class @{text "c"} may be read as a sort @{text "{c}"}.  The ordering
9700a87f1cc2 misc tuning and clarification;
wenzelm
parents: 34921
diff changeset
    50
  on type classes is extended to sorts according to the meaning of
53015
a1119cf551e8 standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
wenzelm
parents: 52788
diff changeset
    51
  intersections: @{text "{c\<^sub>1, \<dots> c\<^sub>m} \<subseteq> {d\<^sub>1, \<dots>, d\<^sub>n}"} iff @{text
a1119cf551e8 standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
wenzelm
parents: 52788
diff changeset
    52
  "\<forall>j. \<exists>i. c\<^sub>i \<subseteq> d\<^sub>j"}.  The empty intersection @{text "{}"} refers to
34929
9700a87f1cc2 misc tuning and clarification;
wenzelm
parents: 34921
diff changeset
    53
  the universal sort, which is the largest element wrt.\ the sort
9700a87f1cc2 misc tuning and clarification;
wenzelm
parents: 34921
diff changeset
    54
  order.  Thus @{text "{}"} represents the ``full sort'', not the
9700a87f1cc2 misc tuning and clarification;
wenzelm
parents: 34921
diff changeset
    55
  empty one!  The intersection of all (finitely many) classes declared
9700a87f1cc2 misc tuning and clarification;
wenzelm
parents: 34921
diff changeset
    56
  in the current theory is the least element wrt.\ the sort ordering.
20480
4e0522d38968 more on types and type classes;
wenzelm
parents: 20477
diff changeset
    57
20491
wenzelm
parents: 20480
diff changeset
    58
  \medskip A \emph{fixed type variable} is a pair of a basic name
20537
b6b49903db7e *** empty log message ***
wenzelm
parents: 20521
diff changeset
    59
  (starting with a @{text "'"} character) and a sort constraint, e.g.\
53015
a1119cf551e8 standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
wenzelm
parents: 52788
diff changeset
    60
  @{text "('a, s)"} which is usually printed as @{text "\<alpha>\<^sub>s"}.
20537
b6b49903db7e *** empty log message ***
wenzelm
parents: 20521
diff changeset
    61
  A \emph{schematic type variable} is a pair of an indexname and a
b6b49903db7e *** empty log message ***
wenzelm
parents: 20521
diff changeset
    62
  sort constraint, e.g.\ @{text "(('a, 0), s)"} which is usually
53015
a1119cf551e8 standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
wenzelm
parents: 52788
diff changeset
    63
  printed as @{text "?\<alpha>\<^sub>s"}.
20451
27ea2ba48fa3 misc cleanup;
wenzelm
parents: 20450
diff changeset
    64
20480
4e0522d38968 more on types and type classes;
wenzelm
parents: 20477
diff changeset
    65
  Note that \emph{all} syntactic components contribute to the identity
34929
9700a87f1cc2 misc tuning and clarification;
wenzelm
parents: 34921
diff changeset
    66
  of type variables: basic name, index, and sort constraint.  The core
9700a87f1cc2 misc tuning and clarification;
wenzelm
parents: 34921
diff changeset
    67
  logic handles type variables with the same name but different sorts
9700a87f1cc2 misc tuning and clarification;
wenzelm
parents: 34921
diff changeset
    68
  as different, although the type-inference layer (which is outside
9700a87f1cc2 misc tuning and clarification;
wenzelm
parents: 34921
diff changeset
    69
  the core) rejects anything like that.
20451
27ea2ba48fa3 misc cleanup;
wenzelm
parents: 20450
diff changeset
    70
20493
wenzelm
parents: 20491
diff changeset
    71
  A \emph{type constructor} @{text "\<kappa>"} is a @{text "k"}-ary operator
wenzelm
parents: 20491
diff changeset
    72
  on types declared in the theory.  Type constructor application is
53015
a1119cf551e8 standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
wenzelm
parents: 52788
diff changeset
    73
  written postfix as @{text "(\<alpha>\<^sub>1, \<dots>, \<alpha>\<^sub>k)\<kappa>"}.  For
20537
b6b49903db7e *** empty log message ***
wenzelm
parents: 20521
diff changeset
    74
  @{text "k = 0"} the argument tuple is omitted, e.g.\ @{text "prop"}
b6b49903db7e *** empty log message ***
wenzelm
parents: 20521
diff changeset
    75
  instead of @{text "()prop"}.  For @{text "k = 1"} the parentheses
b6b49903db7e *** empty log message ***
wenzelm
parents: 20521
diff changeset
    76
  are omitted, e.g.\ @{text "\<alpha> list"} instead of @{text "(\<alpha>)list"}.
b6b49903db7e *** empty log message ***
wenzelm
parents: 20521
diff changeset
    77
  Further notation is provided for specific constructors, notably the
b6b49903db7e *** empty log message ***
wenzelm
parents: 20521
diff changeset
    78
  right-associative infix @{text "\<alpha> \<Rightarrow> \<beta>"} instead of @{text "(\<alpha>,
b6b49903db7e *** empty log message ***
wenzelm
parents: 20521
diff changeset
    79
  \<beta>)fun"}.
20480
4e0522d38968 more on types and type classes;
wenzelm
parents: 20477
diff changeset
    80
  
34929
9700a87f1cc2 misc tuning and clarification;
wenzelm
parents: 34921
diff changeset
    81
  The logical category \emph{type} is defined inductively over type
53015
a1119cf551e8 standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
wenzelm
parents: 52788
diff changeset
    82
  variables and type constructors as follows: @{text "\<tau> = \<alpha>\<^sub>s | ?\<alpha>\<^sub>s |
20543
wenzelm
parents: 20542
diff changeset
    83
  (\<tau>\<^sub>1, \<dots>, \<tau>\<^sub>k)\<kappa>"}.
20451
27ea2ba48fa3 misc cleanup;
wenzelm
parents: 20450
diff changeset
    84
20514
5ede702cd2ca more on terms;
wenzelm
parents: 20501
diff changeset
    85
  A \emph{type abbreviation} is a syntactic definition @{text
20494
wenzelm
parents: 20493
diff changeset
    86
  "(\<^vec>\<alpha>)\<kappa> = \<tau>"} of an arbitrary type expression @{text "\<tau>"} over
20537
b6b49903db7e *** empty log message ***
wenzelm
parents: 20521
diff changeset
    87
  variables @{text "\<^vec>\<alpha>"}.  Type abbreviations appear as type
b6b49903db7e *** empty log message ***
wenzelm
parents: 20521
diff changeset
    88
  constructors in the syntax, but are expanded before entering the
b6b49903db7e *** empty log message ***
wenzelm
parents: 20521
diff changeset
    89
  logical core.
20480
4e0522d38968 more on types and type classes;
wenzelm
parents: 20477
diff changeset
    90
4e0522d38968 more on types and type classes;
wenzelm
parents: 20477
diff changeset
    91
  A \emph{type arity} declares the image behavior of a type
53015
a1119cf551e8 standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
wenzelm
parents: 52788
diff changeset
    92
  constructor wrt.\ the algebra of sorts: @{text "\<kappa> :: (s\<^sub>1, \<dots>,
a1119cf551e8 standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
wenzelm
parents: 52788
diff changeset
    93
  s\<^sub>k)s"} means that @{text "(\<tau>\<^sub>1, \<dots>, \<tau>\<^sub>k)\<kappa>"} is
a1119cf551e8 standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
wenzelm
parents: 52788
diff changeset
    94
  of sort @{text "s"} if every argument type @{text "\<tau>\<^sub>i"} is
a1119cf551e8 standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
wenzelm
parents: 52788
diff changeset
    95
  of sort @{text "s\<^sub>i"}.  Arity declarations are implicitly
20494
wenzelm
parents: 20493
diff changeset
    96
  completed, i.e.\ @{text "\<kappa> :: (\<^vec>s)c"} entails @{text "\<kappa> ::
20491
wenzelm
parents: 20480
diff changeset
    97
  (\<^vec>s)c'"} for any @{text "c' \<supseteq> c"}.
wenzelm
parents: 20480
diff changeset
    98
wenzelm
parents: 20480
diff changeset
    99
  \medskip The sort algebra is always maintained as \emph{coregular},
wenzelm
parents: 20480
diff changeset
   100
  which means that type arities are consistent with the subclass
20537
b6b49903db7e *** empty log message ***
wenzelm
parents: 20521
diff changeset
   101
  relation: for any type constructor @{text "\<kappa>"}, and classes @{text
53015
a1119cf551e8 standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
wenzelm
parents: 52788
diff changeset
   102
  "c\<^sub>1 \<subseteq> c\<^sub>2"}, and arities @{text "\<kappa> ::
a1119cf551e8 standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
wenzelm
parents: 52788
diff changeset
   103
  (\<^vec>s\<^sub>1)c\<^sub>1"} and @{text "\<kappa> ::
a1119cf551e8 standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
wenzelm
parents: 52788
diff changeset
   104
  (\<^vec>s\<^sub>2)c\<^sub>2"} holds @{text "\<^vec>s\<^sub>1 \<subseteq>
a1119cf551e8 standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
wenzelm
parents: 52788
diff changeset
   105
  \<^vec>s\<^sub>2"} component-wise.
20451
27ea2ba48fa3 misc cleanup;
wenzelm
parents: 20450
diff changeset
   106
20491
wenzelm
parents: 20480
diff changeset
   107
  The key property of a coregular order-sorted algebra is that sort
20537
b6b49903db7e *** empty log message ***
wenzelm
parents: 20521
diff changeset
   108
  constraints can be solved in a most general fashion: for each type
b6b49903db7e *** empty log message ***
wenzelm
parents: 20521
diff changeset
   109
  constructor @{text "\<kappa>"} and sort @{text "s"} there is a most general
53015
a1119cf551e8 standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
wenzelm
parents: 52788
diff changeset
   110
  vector of argument sorts @{text "(s\<^sub>1, \<dots>, s\<^sub>k)"} such
a1119cf551e8 standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
wenzelm
parents: 52788
diff changeset
   111
  that a type scheme @{text "(\<alpha>\<^bsub>s\<^sub>1\<^esub>, \<dots>,
a1119cf551e8 standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
wenzelm
parents: 52788
diff changeset
   112
  \<alpha>\<^bsub>s\<^sub>k\<^esub>)\<kappa>"} is of sort @{text "s"}.
20543
wenzelm
parents: 20542
diff changeset
   113
  Consequently, type unification has most general solutions (modulo
wenzelm
parents: 20542
diff changeset
   114
  equivalence of sorts), so type-inference produces primary types as
58555
7975676c08c0 prefer @{cite} antiquotation;
wenzelm
parents: 56579
diff changeset
   115
  expected @{cite "nipkow-prehofer"}.
58618
782f0b662cae more cartouches;
wenzelm
parents: 58555
diff changeset
   116
\<close>
20451
27ea2ba48fa3 misc cleanup;
wenzelm
parents: 20450
diff changeset
   117
58618
782f0b662cae more cartouches;
wenzelm
parents: 58555
diff changeset
   118
text %mlref \<open>
20480
4e0522d38968 more on types and type classes;
wenzelm
parents: 20477
diff changeset
   119
  \begin{mldecls}
34921
008126f730a0 formal markup of type aliases;
wenzelm
parents: 33174
diff changeset
   120
  @{index_ML_type class: string} \\
008126f730a0 formal markup of type aliases;
wenzelm
parents: 33174
diff changeset
   121
  @{index_ML_type sort: "class list"} \\
008126f730a0 formal markup of type aliases;
wenzelm
parents: 33174
diff changeset
   122
  @{index_ML_type arity: "string * sort list * sort"} \\
20480
4e0522d38968 more on types and type classes;
wenzelm
parents: 20477
diff changeset
   123
  @{index_ML_type typ} \\
39846
cb6634eb8926 examples in Isabelle/HOL;
wenzelm
parents: 39840
diff changeset
   124
  @{index_ML Term.map_atyps: "(typ -> typ) -> typ -> typ"} \\
cb6634eb8926 examples in Isabelle/HOL;
wenzelm
parents: 39840
diff changeset
   125
  @{index_ML Term.fold_atyps: "(typ -> 'a -> 'a) -> typ -> 'a -> 'a"} \\
20547
wenzelm
parents: 20543
diff changeset
   126
  \end{mldecls}
wenzelm
parents: 20543
diff changeset
   127
  \begin{mldecls}
20480
4e0522d38968 more on types and type classes;
wenzelm
parents: 20477
diff changeset
   128
  @{index_ML Sign.subsort: "theory -> sort * sort -> bool"} \\
4e0522d38968 more on types and type classes;
wenzelm
parents: 20477
diff changeset
   129
  @{index_ML Sign.of_sort: "theory -> typ * sort -> bool"} \\
47174
b9b2e183e94d updated Sign.add_type, Name_Space.declare;
wenzelm
parents: 46497
diff changeset
   130
  @{index_ML Sign.add_type: "Proof.context -> binding * int * mixfix -> theory -> theory"} \\
42401
9bfaf6819291 updated some theory primitives, which now depend on auxiliary context;
wenzelm
parents: 40255
diff changeset
   131
  @{index_ML Sign.add_type_abbrev: "Proof.context ->
9bfaf6819291 updated some theory primitives, which now depend on auxiliary context;
wenzelm
parents: 40255
diff changeset
   132
  binding * string list * typ -> theory -> theory"} \\
30355
8066d80cd51e use binding type;
wenzelm
parents: 30288
diff changeset
   133
  @{index_ML Sign.primitive_class: "binding * class list -> theory -> theory"} \\
20480
4e0522d38968 more on types and type classes;
wenzelm
parents: 20477
diff changeset
   134
  @{index_ML Sign.primitive_classrel: "class * class -> theory -> theory"} \\
4e0522d38968 more on types and type classes;
wenzelm
parents: 20477
diff changeset
   135
  @{index_ML Sign.primitive_arity: "arity -> theory -> theory"} \\
4e0522d38968 more on types and type classes;
wenzelm
parents: 20477
diff changeset
   136
  \end{mldecls}
4e0522d38968 more on types and type classes;
wenzelm
parents: 20477
diff changeset
   137
4e0522d38968 more on types and type classes;
wenzelm
parents: 20477
diff changeset
   138
  \begin{description}
4e0522d38968 more on types and type classes;
wenzelm
parents: 20477
diff changeset
   139
39864
wenzelm
parents: 39861
diff changeset
   140
  \item Type @{ML_type class} represents type classes.
20480
4e0522d38968 more on types and type classes;
wenzelm
parents: 20477
diff changeset
   141
39864
wenzelm
parents: 39861
diff changeset
   142
  \item Type @{ML_type sort} represents sorts, i.e.\ finite
wenzelm
parents: 39861
diff changeset
   143
  intersections of classes.  The empty list @{ML "[]: sort"} refers to
wenzelm
parents: 39861
diff changeset
   144
  the empty class intersection, i.e.\ the ``full sort''.
20451
27ea2ba48fa3 misc cleanup;
wenzelm
parents: 20450
diff changeset
   145
39864
wenzelm
parents: 39861
diff changeset
   146
  \item Type @{ML_type arity} represents type arities.  A triple
wenzelm
parents: 39861
diff changeset
   147
  @{text "(\<kappa>, \<^vec>s, s) : arity"} represents @{text "\<kappa> ::
wenzelm
parents: 39861
diff changeset
   148
  (\<^vec>s)s"} as described above.
20480
4e0522d38968 more on types and type classes;
wenzelm
parents: 20477
diff changeset
   149
39864
wenzelm
parents: 39861
diff changeset
   150
  \item Type @{ML_type typ} represents types; this is a datatype with
20480
4e0522d38968 more on types and type classes;
wenzelm
parents: 20477
diff changeset
   151
  constructors @{ML TFree}, @{ML TVar}, @{ML Type}.
4e0522d38968 more on types and type classes;
wenzelm
parents: 20477
diff changeset
   152
39846
cb6634eb8926 examples in Isabelle/HOL;
wenzelm
parents: 39840
diff changeset
   153
  \item @{ML Term.map_atyps}~@{text "f \<tau>"} applies the mapping @{text
cb6634eb8926 examples in Isabelle/HOL;
wenzelm
parents: 39840
diff changeset
   154
  "f"} to all atomic types (@{ML TFree}, @{ML TVar}) occurring in
cb6634eb8926 examples in Isabelle/HOL;
wenzelm
parents: 39840
diff changeset
   155
  @{text "\<tau>"}.
20519
d7ad1217c24a more on terms;
wenzelm
parents: 20514
diff changeset
   156
39846
cb6634eb8926 examples in Isabelle/HOL;
wenzelm
parents: 39840
diff changeset
   157
  \item @{ML Term.fold_atyps}~@{text "f \<tau>"} iterates the operation
cb6634eb8926 examples in Isabelle/HOL;
wenzelm
parents: 39840
diff changeset
   158
  @{text "f"} over all occurrences of atomic types (@{ML TFree}, @{ML
cb6634eb8926 examples in Isabelle/HOL;
wenzelm
parents: 39840
diff changeset
   159
  TVar}) in @{text "\<tau>"}; the type structure is traversed from left to
cb6634eb8926 examples in Isabelle/HOL;
wenzelm
parents: 39840
diff changeset
   160
  right.
20494
wenzelm
parents: 20493
diff changeset
   161
53015
a1119cf551e8 standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
wenzelm
parents: 52788
diff changeset
   162
  \item @{ML Sign.subsort}~@{text "thy (s\<^sub>1, s\<^sub>2)"}
a1119cf551e8 standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
wenzelm
parents: 52788
diff changeset
   163
  tests the subsort relation @{text "s\<^sub>1 \<subseteq> s\<^sub>2"}.
20480
4e0522d38968 more on types and type classes;
wenzelm
parents: 20477
diff changeset
   164
20537
b6b49903db7e *** empty log message ***
wenzelm
parents: 20521
diff changeset
   165
  \item @{ML Sign.of_sort}~@{text "thy (\<tau>, s)"} tests whether type
b6b49903db7e *** empty log message ***
wenzelm
parents: 20521
diff changeset
   166
  @{text "\<tau>"} is of sort @{text "s"}.
20480
4e0522d38968 more on types and type classes;
wenzelm
parents: 20477
diff changeset
   167
47174
b9b2e183e94d updated Sign.add_type, Name_Space.declare;
wenzelm
parents: 46497
diff changeset
   168
  \item @{ML Sign.add_type}~@{text "ctxt (\<kappa>, k, mx)"} declares a
42401
9bfaf6819291 updated some theory primitives, which now depend on auxiliary context;
wenzelm
parents: 40255
diff changeset
   169
  new type constructors @{text "\<kappa>"} with @{text "k"} arguments and
20480
4e0522d38968 more on types and type classes;
wenzelm
parents: 20477
diff changeset
   170
  optional mixfix syntax.
20451
27ea2ba48fa3 misc cleanup;
wenzelm
parents: 20450
diff changeset
   171
42401
9bfaf6819291 updated some theory primitives, which now depend on auxiliary context;
wenzelm
parents: 40255
diff changeset
   172
  \item @{ML Sign.add_type_abbrev}~@{text "ctxt (\<kappa>, \<^vec>\<alpha>, \<tau>)"}
9bfaf6819291 updated some theory primitives, which now depend on auxiliary context;
wenzelm
parents: 40255
diff changeset
   173
  defines a new type abbreviation @{text "(\<^vec>\<alpha>)\<kappa> = \<tau>"}.
20480
4e0522d38968 more on types and type classes;
wenzelm
parents: 20477
diff changeset
   174
53015
a1119cf551e8 standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
wenzelm
parents: 52788
diff changeset
   175
  \item @{ML Sign.primitive_class}~@{text "(c, [c\<^sub>1, \<dots>,
a1119cf551e8 standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
wenzelm
parents: 52788
diff changeset
   176
  c\<^sub>n])"} declares a new class @{text "c"}, together with class
a1119cf551e8 standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
wenzelm
parents: 52788
diff changeset
   177
  relations @{text "c \<subseteq> c\<^sub>i"}, for @{text "i = 1, \<dots>, n"}.
20480
4e0522d38968 more on types and type classes;
wenzelm
parents: 20477
diff changeset
   178
53015
a1119cf551e8 standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
wenzelm
parents: 52788
diff changeset
   179
  \item @{ML Sign.primitive_classrel}~@{text "(c\<^sub>1,
a1119cf551e8 standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
wenzelm
parents: 52788
diff changeset
   180
  c\<^sub>2)"} declares the class relation @{text "c\<^sub>1 \<subseteq>
a1119cf551e8 standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
wenzelm
parents: 52788
diff changeset
   181
  c\<^sub>2"}.
20480
4e0522d38968 more on types and type classes;
wenzelm
parents: 20477
diff changeset
   182
20494
wenzelm
parents: 20493
diff changeset
   183
  \item @{ML Sign.primitive_arity}~@{text "(\<kappa>, \<^vec>s, s)"} declares
20537
b6b49903db7e *** empty log message ***
wenzelm
parents: 20521
diff changeset
   184
  the arity @{text "\<kappa> :: (\<^vec>s)s"}.
20480
4e0522d38968 more on types and type classes;
wenzelm
parents: 20477
diff changeset
   185
4e0522d38968 more on types and type classes;
wenzelm
parents: 20477
diff changeset
   186
  \end{description}
58618
782f0b662cae more cartouches;
wenzelm
parents: 58555
diff changeset
   187
\<close>
20437
wenzelm
parents: 18537
diff changeset
   188
58618
782f0b662cae more cartouches;
wenzelm
parents: 58555
diff changeset
   189
text %mlantiq \<open>
39832
1080dee73a53 various concrete ML antiquotations;
wenzelm
parents: 39821
diff changeset
   190
  \begin{matharray}{rcl}
1080dee73a53 various concrete ML antiquotations;
wenzelm
parents: 39821
diff changeset
   191
  @{ML_antiquotation_def "class"} & : & @{text ML_antiquotation} \\
1080dee73a53 various concrete ML antiquotations;
wenzelm
parents: 39821
diff changeset
   192
  @{ML_antiquotation_def "sort"} & : & @{text ML_antiquotation} \\
1080dee73a53 various concrete ML antiquotations;
wenzelm
parents: 39821
diff changeset
   193
  @{ML_antiquotation_def "type_name"} & : & @{text ML_antiquotation} \\
1080dee73a53 various concrete ML antiquotations;
wenzelm
parents: 39821
diff changeset
   194
  @{ML_antiquotation_def "type_abbrev"} & : & @{text ML_antiquotation} \\
1080dee73a53 various concrete ML antiquotations;
wenzelm
parents: 39821
diff changeset
   195
  @{ML_antiquotation_def "nonterminal"} & : & @{text ML_antiquotation} \\
1080dee73a53 various concrete ML antiquotations;
wenzelm
parents: 39821
diff changeset
   196
  @{ML_antiquotation_def "typ"} & : & @{text ML_antiquotation} \\
1080dee73a53 various concrete ML antiquotations;
wenzelm
parents: 39821
diff changeset
   197
  \end{matharray}
1080dee73a53 various concrete ML antiquotations;
wenzelm
parents: 39821
diff changeset
   198
55112
b1a5d603fd12 prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents: 55029
diff changeset
   199
  @{rail \<open>
42510
b9c106763325 use @{rail} antiquotation (with some nested markup);
wenzelm
parents: 42401
diff changeset
   200
  @@{ML_antiquotation class} nameref
39832
1080dee73a53 various concrete ML antiquotations;
wenzelm
parents: 39821
diff changeset
   201
  ;
42510
b9c106763325 use @{rail} antiquotation (with some nested markup);
wenzelm
parents: 42401
diff changeset
   202
  @@{ML_antiquotation sort} sort
39832
1080dee73a53 various concrete ML antiquotations;
wenzelm
parents: 39821
diff changeset
   203
  ;
42510
b9c106763325 use @{rail} antiquotation (with some nested markup);
wenzelm
parents: 42401
diff changeset
   204
  (@@{ML_antiquotation type_name} |
b9c106763325 use @{rail} antiquotation (with some nested markup);
wenzelm
parents: 42401
diff changeset
   205
   @@{ML_antiquotation type_abbrev} |
b9c106763325 use @{rail} antiquotation (with some nested markup);
wenzelm
parents: 42401
diff changeset
   206
   @@{ML_antiquotation nonterminal}) nameref
39832
1080dee73a53 various concrete ML antiquotations;
wenzelm
parents: 39821
diff changeset
   207
  ;
42510
b9c106763325 use @{rail} antiquotation (with some nested markup);
wenzelm
parents: 42401
diff changeset
   208
  @@{ML_antiquotation typ} type
55112
b1a5d603fd12 prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents: 55029
diff changeset
   209
  \<close>}
39832
1080dee73a53 various concrete ML antiquotations;
wenzelm
parents: 39821
diff changeset
   210
1080dee73a53 various concrete ML antiquotations;
wenzelm
parents: 39821
diff changeset
   211
  \begin{description}
1080dee73a53 various concrete ML antiquotations;
wenzelm
parents: 39821
diff changeset
   212
1080dee73a53 various concrete ML antiquotations;
wenzelm
parents: 39821
diff changeset
   213
  \item @{text "@{class c}"} inlines the internalized class @{text
1080dee73a53 various concrete ML antiquotations;
wenzelm
parents: 39821
diff changeset
   214
  "c"} --- as @{ML_type string} literal.
1080dee73a53 various concrete ML antiquotations;
wenzelm
parents: 39821
diff changeset
   215
1080dee73a53 various concrete ML antiquotations;
wenzelm
parents: 39821
diff changeset
   216
  \item @{text "@{sort s}"} inlines the internalized sort @{text "s"}
1080dee73a53 various concrete ML antiquotations;
wenzelm
parents: 39821
diff changeset
   217
  --- as @{ML_type "string list"} literal.
1080dee73a53 various concrete ML antiquotations;
wenzelm
parents: 39821
diff changeset
   218
1080dee73a53 various concrete ML antiquotations;
wenzelm
parents: 39821
diff changeset
   219
  \item @{text "@{type_name c}"} inlines the internalized type
1080dee73a53 various concrete ML antiquotations;
wenzelm
parents: 39821
diff changeset
   220
  constructor @{text "c"} --- as @{ML_type string} literal.
1080dee73a53 various concrete ML antiquotations;
wenzelm
parents: 39821
diff changeset
   221
1080dee73a53 various concrete ML antiquotations;
wenzelm
parents: 39821
diff changeset
   222
  \item @{text "@{type_abbrev c}"} inlines the internalized type
1080dee73a53 various concrete ML antiquotations;
wenzelm
parents: 39821
diff changeset
   223
  abbreviation @{text "c"} --- as @{ML_type string} literal.
1080dee73a53 various concrete ML antiquotations;
wenzelm
parents: 39821
diff changeset
   224
1080dee73a53 various concrete ML antiquotations;
wenzelm
parents: 39821
diff changeset
   225
  \item @{text "@{nonterminal c}"} inlines the internalized syntactic
1080dee73a53 various concrete ML antiquotations;
wenzelm
parents: 39821
diff changeset
   226
  type~/ grammar nonterminal @{text "c"} --- as @{ML_type string}
1080dee73a53 various concrete ML antiquotations;
wenzelm
parents: 39821
diff changeset
   227
  literal.
1080dee73a53 various concrete ML antiquotations;
wenzelm
parents: 39821
diff changeset
   228
1080dee73a53 various concrete ML antiquotations;
wenzelm
parents: 39821
diff changeset
   229
  \item @{text "@{typ \<tau>}"} inlines the internalized type @{text "\<tau>"}
1080dee73a53 various concrete ML antiquotations;
wenzelm
parents: 39821
diff changeset
   230
  --- as constructor term for datatype @{ML_type typ}.
1080dee73a53 various concrete ML antiquotations;
wenzelm
parents: 39821
diff changeset
   231
1080dee73a53 various concrete ML antiquotations;
wenzelm
parents: 39821
diff changeset
   232
  \end{description}
58618
782f0b662cae more cartouches;
wenzelm
parents: 58555
diff changeset
   233
\<close>
39832
1080dee73a53 various concrete ML antiquotations;
wenzelm
parents: 39821
diff changeset
   234
20437
wenzelm
parents: 18537
diff changeset
   235
58618
782f0b662cae more cartouches;
wenzelm
parents: 58555
diff changeset
   236
section \<open>Terms \label{sec:terms}\<close>
18537
2681f9e34390 "The Isabelle/Isar Implementation" manual;
wenzelm
parents:
diff changeset
   237
58618
782f0b662cae more cartouches;
wenzelm
parents: 58555
diff changeset
   238
text \<open>
20491
wenzelm
parents: 20480
diff changeset
   239
  The language of terms is that of simply-typed @{text "\<lambda>"}-calculus
58555
7975676c08c0 prefer @{cite} antiquotation;
wenzelm
parents: 56579
diff changeset
   240
  with de-Bruijn indices for bound variables (cf.\ @{cite debruijn72}
7975676c08c0 prefer @{cite} antiquotation;
wenzelm
parents: 56579
diff changeset
   241
  or @{cite "paulson-ml2"}), with the types being determined by the
29761
2b658e50683a minor tuning and typographic fixes;
wenzelm
parents: 29758
diff changeset
   242
  corresponding binders.  In contrast, free variables and constants
34929
9700a87f1cc2 misc tuning and clarification;
wenzelm
parents: 34921
diff changeset
   243
  have an explicit name and type in each occurrence.
20514
5ede702cd2ca more on terms;
wenzelm
parents: 20501
diff changeset
   244
5ede702cd2ca more on terms;
wenzelm
parents: 20501
diff changeset
   245
  \medskip A \emph{bound variable} is a natural number @{text "b"},
20537
b6b49903db7e *** empty log message ***
wenzelm
parents: 20521
diff changeset
   246
  which accounts for the number of intermediate binders between the
b6b49903db7e *** empty log message ***
wenzelm
parents: 20521
diff changeset
   247
  variable occurrence in the body and its binding position.  For
34929
9700a87f1cc2 misc tuning and clarification;
wenzelm
parents: 34921
diff changeset
   248
  example, the de-Bruijn term @{text "\<lambda>\<^bsub>bool\<^esub>. \<lambda>\<^bsub>bool\<^esub>. 1 \<and> 0"} would
9700a87f1cc2 misc tuning and clarification;
wenzelm
parents: 34921
diff changeset
   249
  correspond to @{text "\<lambda>x\<^bsub>bool\<^esub>. \<lambda>y\<^bsub>bool\<^esub>. x \<and> y"} in a named
20543
wenzelm
parents: 20542
diff changeset
   250
  representation.  Note that a bound variable may be represented by
wenzelm
parents: 20542
diff changeset
   251
  different de-Bruijn indices at different occurrences, depending on
wenzelm
parents: 20542
diff changeset
   252
  the nesting of abstractions.
20537
b6b49903db7e *** empty log message ***
wenzelm
parents: 20521
diff changeset
   253
20543
wenzelm
parents: 20542
diff changeset
   254
  A \emph{loose variable} is a bound variable that is outside the
20537
b6b49903db7e *** empty log message ***
wenzelm
parents: 20521
diff changeset
   255
  scope of local binders.  The types (and names) for loose variables
20543
wenzelm
parents: 20542
diff changeset
   256
  can be managed as a separate context, that is maintained as a stack
wenzelm
parents: 20542
diff changeset
   257
  of hypothetical binders.  The core logic operates on closed terms,
wenzelm
parents: 20542
diff changeset
   258
  without any loose variables.
20514
5ede702cd2ca more on terms;
wenzelm
parents: 20501
diff changeset
   259
20537
b6b49903db7e *** empty log message ***
wenzelm
parents: 20521
diff changeset
   260
  A \emph{fixed variable} is a pair of a basic name and a type, e.g.\
53015
a1119cf551e8 standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
wenzelm
parents: 52788
diff changeset
   261
  @{text "(x, \<tau>)"} which is usually printed @{text "x\<^sub>\<tau>"} here.  A
20537
b6b49903db7e *** empty log message ***
wenzelm
parents: 20521
diff changeset
   262
  \emph{schematic variable} is a pair of an indexname and a type,
34929
9700a87f1cc2 misc tuning and clarification;
wenzelm
parents: 34921
diff changeset
   263
  e.g.\ @{text "((x, 0), \<tau>)"} which is likewise printed as @{text
53015
a1119cf551e8 standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
wenzelm
parents: 52788
diff changeset
   264
  "?x\<^sub>\<tau>"}.
20491
wenzelm
parents: 20480
diff changeset
   265
20537
b6b49903db7e *** empty log message ***
wenzelm
parents: 20521
diff changeset
   266
  \medskip A \emph{constant} is a pair of a basic name and a type,
53015
a1119cf551e8 standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
wenzelm
parents: 52788
diff changeset
   267
  e.g.\ @{text "(c, \<tau>)"} which is usually printed as @{text "c\<^sub>\<tau>"}
34929
9700a87f1cc2 misc tuning and clarification;
wenzelm
parents: 34921
diff changeset
   268
  here.  Constants are declared in the context as polymorphic families
9700a87f1cc2 misc tuning and clarification;
wenzelm
parents: 34921
diff changeset
   269
  @{text "c :: \<sigma>"}, meaning that all substitution instances @{text
53015
a1119cf551e8 standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
wenzelm
parents: 52788
diff changeset
   270
  "c\<^sub>\<tau>"} for @{text "\<tau> = \<sigma>\<vartheta>"} are valid.
20514
5ede702cd2ca more on terms;
wenzelm
parents: 20501
diff changeset
   271
53015
a1119cf551e8 standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
wenzelm
parents: 52788
diff changeset
   272
  The vector of \emph{type arguments} of constant @{text "c\<^sub>\<tau>"} wrt.\
34929
9700a87f1cc2 misc tuning and clarification;
wenzelm
parents: 34921
diff changeset
   273
  the declaration @{text "c :: \<sigma>"} is defined as the codomain of the
53015
a1119cf551e8 standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
wenzelm
parents: 52788
diff changeset
   274
  matcher @{text "\<vartheta> = {?\<alpha>\<^sub>1 \<mapsto> \<tau>\<^sub>1, \<dots>, ?\<alpha>\<^sub>n \<mapsto> \<tau>\<^sub>n}"} presented in
a1119cf551e8 standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
wenzelm
parents: 52788
diff changeset
   275
  canonical order @{text "(\<tau>\<^sub>1, \<dots>, \<tau>\<^sub>n)"}, corresponding to the
a1119cf551e8 standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
wenzelm
parents: 52788
diff changeset
   276
  left-to-right occurrences of the @{text "\<alpha>\<^sub>i"} in @{text "\<sigma>"}.
34929
9700a87f1cc2 misc tuning and clarification;
wenzelm
parents: 34921
diff changeset
   277
  Within a given theory context, there is a one-to-one correspondence
53015
a1119cf551e8 standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
wenzelm
parents: 52788
diff changeset
   278
  between any constant @{text "c\<^sub>\<tau>"} and the application @{text "c(\<tau>\<^sub>1,
a1119cf551e8 standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
wenzelm
parents: 52788
diff changeset
   279
  \<dots>, \<tau>\<^sub>n)"} of its type arguments.  For example, with @{text "plus :: \<alpha>
34929
9700a87f1cc2 misc tuning and clarification;
wenzelm
parents: 34921
diff changeset
   280
  \<Rightarrow> \<alpha> \<Rightarrow> \<alpha>"}, the instance @{text "plus\<^bsub>nat \<Rightarrow> nat \<Rightarrow> nat\<^esub>"} corresponds to
9700a87f1cc2 misc tuning and clarification;
wenzelm
parents: 34921
diff changeset
   281
  @{text "plus(nat)"}.
20480
4e0522d38968 more on types and type classes;
wenzelm
parents: 20477
diff changeset
   282
20514
5ede702cd2ca more on terms;
wenzelm
parents: 20501
diff changeset
   283
  Constant declarations @{text "c :: \<sigma>"} may contain sort constraints
5ede702cd2ca more on terms;
wenzelm
parents: 20501
diff changeset
   284
  for type variables in @{text "\<sigma>"}.  These are observed by
5ede702cd2ca more on terms;
wenzelm
parents: 20501
diff changeset
   285
  type-inference as expected, but \emph{ignored} by the core logic.
5ede702cd2ca more on terms;
wenzelm
parents: 20501
diff changeset
   286
  This means the primitive logic is able to reason with instances of
20537
b6b49903db7e *** empty log message ***
wenzelm
parents: 20521
diff changeset
   287
  polymorphic constants that the user-level type-checker would reject
b6b49903db7e *** empty log message ***
wenzelm
parents: 20521
diff changeset
   288
  due to violation of type class restrictions.
20480
4e0522d38968 more on types and type classes;
wenzelm
parents: 20477
diff changeset
   289
39861
b8d89db3e238 use continental paragraph style, which works better with mixture of (in)formal text;
wenzelm
parents: 39846
diff changeset
   290
  \medskip An \emph{atomic term} is either a variable or constant.
34929
9700a87f1cc2 misc tuning and clarification;
wenzelm
parents: 34921
diff changeset
   291
  The logical category \emph{term} is defined inductively over atomic
9700a87f1cc2 misc tuning and clarification;
wenzelm
parents: 34921
diff changeset
   292
  terms, with abstraction and application as follows: @{text "t = b |
53015
a1119cf551e8 standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
wenzelm
parents: 52788
diff changeset
   293
  x\<^sub>\<tau> | ?x\<^sub>\<tau> | c\<^sub>\<tau> | \<lambda>\<^sub>\<tau>. t | t\<^sub>1 t\<^sub>2"}.  Parsing and printing takes care of
34929
9700a87f1cc2 misc tuning and clarification;
wenzelm
parents: 34921
diff changeset
   294
  converting between an external representation with named bound
9700a87f1cc2 misc tuning and clarification;
wenzelm
parents: 34921
diff changeset
   295
  variables.  Subsequently, we shall use the latter notation instead
9700a87f1cc2 misc tuning and clarification;
wenzelm
parents: 34921
diff changeset
   296
  of internal de-Bruijn representation.
20498
825a8d2335ce more rules;
wenzelm
parents: 20494
diff changeset
   297
20537
b6b49903db7e *** empty log message ***
wenzelm
parents: 20521
diff changeset
   298
  The inductive relation @{text "t :: \<tau>"} assigns a (unique) type to a
b6b49903db7e *** empty log message ***
wenzelm
parents: 20521
diff changeset
   299
  term according to the structure of atomic terms, abstractions, and
56579
4c94f631c595 tuned spelling;
wenzelm
parents: 56420
diff changeset
   300
  applications:
20498
825a8d2335ce more rules;
wenzelm
parents: 20494
diff changeset
   301
  \[
53015
a1119cf551e8 standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
wenzelm
parents: 52788
diff changeset
   302
  \infer{@{text "a\<^sub>\<tau> :: \<tau>"}}{}
20498
825a8d2335ce more rules;
wenzelm
parents: 20494
diff changeset
   303
  \qquad
20501
de0b523b0d62 more rules;
wenzelm
parents: 20498
diff changeset
   304
  \infer{@{text "(\<lambda>x\<^sub>\<tau>. t) :: \<tau> \<Rightarrow> \<sigma>"}}{@{text "t :: \<sigma>"}}
de0b523b0d62 more rules;
wenzelm
parents: 20498
diff changeset
   305
  \qquad
de0b523b0d62 more rules;
wenzelm
parents: 20498
diff changeset
   306
  \infer{@{text "t u :: \<sigma>"}}{@{text "t :: \<tau> \<Rightarrow> \<sigma>"} & @{text "u :: \<tau>"}}
20498
825a8d2335ce more rules;
wenzelm
parents: 20494
diff changeset
   307
  \]
20514
5ede702cd2ca more on terms;
wenzelm
parents: 20501
diff changeset
   308
  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
   309
20514
5ede702cd2ca more on terms;
wenzelm
parents: 20501
diff changeset
   310
  Typing information can be omitted: type-inference is able to
5ede702cd2ca more on terms;
wenzelm
parents: 20501
diff changeset
   311
  reconstruct the most general type of a raw term, while assigning
5ede702cd2ca more on terms;
wenzelm
parents: 20501
diff changeset
   312
  most general types to all of its variables and constants.
5ede702cd2ca more on terms;
wenzelm
parents: 20501
diff changeset
   313
  Type-inference depends on a context of type constraints for fixed
5ede702cd2ca more on terms;
wenzelm
parents: 20501
diff changeset
   314
  variables, and declarations for polymorphic constants.
5ede702cd2ca more on terms;
wenzelm
parents: 20501
diff changeset
   315
20537
b6b49903db7e *** empty log message ***
wenzelm
parents: 20521
diff changeset
   316
  The identity of atomic terms consists both of the name and the type
b6b49903db7e *** empty log message ***
wenzelm
parents: 20521
diff changeset
   317
  component.  This means that different variables @{text
53015
a1119cf551e8 standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
wenzelm
parents: 52788
diff changeset
   318
  "x\<^bsub>\<tau>\<^sub>1\<^esub>"} and @{text "x\<^bsub>\<tau>\<^sub>2\<^esub>"} may become the same after
34929
9700a87f1cc2 misc tuning and clarification;
wenzelm
parents: 34921
diff changeset
   319
  type instantiation.  Type-inference rejects variables of the same
9700a87f1cc2 misc tuning and clarification;
wenzelm
parents: 34921
diff changeset
   320
  name, but different types.  In contrast, mixed instances of
9700a87f1cc2 misc tuning and clarification;
wenzelm
parents: 34921
diff changeset
   321
  polymorphic constants occur routinely.
20514
5ede702cd2ca more on terms;
wenzelm
parents: 20501
diff changeset
   322
5ede702cd2ca more on terms;
wenzelm
parents: 20501
diff changeset
   323
  \medskip The \emph{hidden polymorphism} of a term @{text "t :: \<sigma>"}
5ede702cd2ca more on terms;
wenzelm
parents: 20501
diff changeset
   324
  is the set of type variables occurring in @{text "t"}, but not in
34929
9700a87f1cc2 misc tuning and clarification;
wenzelm
parents: 34921
diff changeset
   325
  its type @{text "\<sigma>"}.  This means that the term implicitly depends
9700a87f1cc2 misc tuning and clarification;
wenzelm
parents: 34921
diff changeset
   326
  on type arguments that are not accounted in the result type, i.e.\
9700a87f1cc2 misc tuning and clarification;
wenzelm
parents: 34921
diff changeset
   327
  there are different type instances @{text "t\<vartheta> :: \<sigma>"} and
9700a87f1cc2 misc tuning and clarification;
wenzelm
parents: 34921
diff changeset
   328
  @{text "t\<vartheta>' :: \<sigma>"} with the same type.  This slightly
20543
wenzelm
parents: 20542
diff changeset
   329
  pathological situation notoriously demands additional care.
20514
5ede702cd2ca more on terms;
wenzelm
parents: 20501
diff changeset
   330
5ede702cd2ca more on terms;
wenzelm
parents: 20501
diff changeset
   331
  \medskip A \emph{term abbreviation} is a syntactic definition @{text
53015
a1119cf551e8 standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
wenzelm
parents: 52788
diff changeset
   332
  "c\<^sub>\<sigma> \<equiv> t"} of a closed term @{text "t"} of type @{text "\<sigma>"},
20537
b6b49903db7e *** empty log message ***
wenzelm
parents: 20521
diff changeset
   333
  without any hidden polymorphism.  A term abbreviation looks like a
20543
wenzelm
parents: 20542
diff changeset
   334
  constant in the syntax, but is expanded before entering the logical
wenzelm
parents: 20542
diff changeset
   335
  core.  Abbreviations are usually reverted when printing terms, using
53015
a1119cf551e8 standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
wenzelm
parents: 52788
diff changeset
   336
  @{text "t \<rightarrow> c\<^sub>\<sigma>"} as rules for higher-order rewriting.
20519
d7ad1217c24a more on terms;
wenzelm
parents: 20514
diff changeset
   337
d7ad1217c24a more on terms;
wenzelm
parents: 20514
diff changeset
   338
  \medskip Canonical operations on @{text "\<lambda>"}-terms include @{text
20537
b6b49903db7e *** empty log message ***
wenzelm
parents: 20521
diff changeset
   339
  "\<alpha>\<beta>\<eta>"}-conversion: @{text "\<alpha>"}-conversion refers to capture-free
20519
d7ad1217c24a more on terms;
wenzelm
parents: 20514
diff changeset
   340
  renaming of bound variables; @{text "\<beta>"}-conversion contracts an
20537
b6b49903db7e *** empty log message ***
wenzelm
parents: 20521
diff changeset
   341
  abstraction applied to an argument term, substituting the argument
20519
d7ad1217c24a more on terms;
wenzelm
parents: 20514
diff changeset
   342
  in the body: @{text "(\<lambda>x. b)a"} becomes @{text "b[a/x]"}; @{text
d7ad1217c24a more on terms;
wenzelm
parents: 20514
diff changeset
   343
  "\<eta>"}-conversion contracts vacuous application-abstraction: @{text
d7ad1217c24a more on terms;
wenzelm
parents: 20514
diff changeset
   344
  "\<lambda>x. f x"} becomes @{text "f"}, provided that the bound variable
20537
b6b49903db7e *** empty log message ***
wenzelm
parents: 20521
diff changeset
   345
  does not occur in @{text "f"}.
20519
d7ad1217c24a more on terms;
wenzelm
parents: 20514
diff changeset
   346
20537
b6b49903db7e *** empty log message ***
wenzelm
parents: 20521
diff changeset
   347
  Terms are normally treated modulo @{text "\<alpha>"}-conversion, which is
b6b49903db7e *** empty log message ***
wenzelm
parents: 20521
diff changeset
   348
  implicit in the de-Bruijn representation.  Names for bound variables
b6b49903db7e *** empty log message ***
wenzelm
parents: 20521
diff changeset
   349
  in abstractions are maintained separately as (meaningless) comments,
b6b49903db7e *** empty log message ***
wenzelm
parents: 20521
diff changeset
   350
  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
   351
  commonplace in various standard operations (\secref{sec:obj-rules})
9495aec512e2 renamed "Rules" to "Object-level rules";
wenzelm
parents: 28674
diff changeset
   352
  that are based on higher-order unification and matching.
58618
782f0b662cae more cartouches;
wenzelm
parents: 58555
diff changeset
   353
\<close>
18537
2681f9e34390 "The Isabelle/Isar Implementation" manual;
wenzelm
parents:
diff changeset
   354
58618
782f0b662cae more cartouches;
wenzelm
parents: 58555
diff changeset
   355
text %mlref \<open>
20514
5ede702cd2ca more on terms;
wenzelm
parents: 20501
diff changeset
   356
  \begin{mldecls}
5ede702cd2ca more on terms;
wenzelm
parents: 20501
diff changeset
   357
  @{index_ML_type term} \\
46262
912b42e64fde tuned ML infixes;
wenzelm
parents: 46256
diff changeset
   358
  @{index_ML_op "aconv": "term * term -> bool"} \\
39846
cb6634eb8926 examples in Isabelle/HOL;
wenzelm
parents: 39840
diff changeset
   359
  @{index_ML Term.map_types: "(typ -> typ) -> term -> term"} \\
cb6634eb8926 examples in Isabelle/HOL;
wenzelm
parents: 39840
diff changeset
   360
  @{index_ML Term.fold_types: "(typ -> 'a -> 'a) -> term -> 'a -> 'a"} \\
cb6634eb8926 examples in Isabelle/HOL;
wenzelm
parents: 39840
diff changeset
   361
  @{index_ML Term.map_aterms: "(term -> term) -> term -> term"} \\
cb6634eb8926 examples in Isabelle/HOL;
wenzelm
parents: 39840
diff changeset
   362
  @{index_ML Term.fold_aterms: "(term -> 'a -> 'a) -> term -> 'a -> 'a"} \\
20547
wenzelm
parents: 20543
diff changeset
   363
  \end{mldecls}
wenzelm
parents: 20543
diff changeset
   364
  \begin{mldecls}
20514
5ede702cd2ca more on terms;
wenzelm
parents: 20501
diff changeset
   365
  @{index_ML fastype_of: "term -> typ"} \\
20519
d7ad1217c24a more on terms;
wenzelm
parents: 20514
diff changeset
   366
  @{index_ML lambda: "term -> term -> term"} \\
d7ad1217c24a more on terms;
wenzelm
parents: 20514
diff changeset
   367
  @{index_ML betapply: "term * term -> term"} \\
42934
287182c2f23a moved incr_boundvars;
wenzelm
parents: 42933
diff changeset
   368
  @{index_ML incr_boundvars: "int -> term -> term"} \\
42401
9bfaf6819291 updated some theory primitives, which now depend on auxiliary context;
wenzelm
parents: 40255
diff changeset
   369
  @{index_ML Sign.declare_const: "Proof.context ->
9bfaf6819291 updated some theory primitives, which now depend on auxiliary context;
wenzelm
parents: 40255
diff changeset
   370
  (binding * typ) * mixfix -> theory -> term * theory"} \\
33174
1f2051f41335 adjusted to changes in corresponding ML code
haftmann
parents: 32833
diff changeset
   371
  @{index_ML Sign.add_abbrev: "string -> binding * term ->
24972
acafb18a47dc replaced Sign.add_consts_i by Sign.declare_const;
wenzelm
parents: 24828
diff changeset
   372
  theory -> (term * term) * theory"} \\
20519
d7ad1217c24a more on terms;
wenzelm
parents: 20514
diff changeset
   373
  @{index_ML Sign.const_typargs: "theory -> string * typ -> typ list"} \\
d7ad1217c24a more on terms;
wenzelm
parents: 20514
diff changeset
   374
  @{index_ML Sign.const_instance: "theory -> string * typ list -> typ"} \\
20514
5ede702cd2ca more on terms;
wenzelm
parents: 20501
diff changeset
   375
  \end{mldecls}
18537
2681f9e34390 "The Isabelle/Isar Implementation" manual;
wenzelm
parents:
diff changeset
   376
20514
5ede702cd2ca more on terms;
wenzelm
parents: 20501
diff changeset
   377
  \begin{description}
18537
2681f9e34390 "The Isabelle/Isar Implementation" manual;
wenzelm
parents:
diff changeset
   378
39864
wenzelm
parents: 39861
diff changeset
   379
  \item Type @{ML_type term} represents de-Bruijn terms, with comments
wenzelm
parents: 39861
diff changeset
   380
  in abstractions, and explicitly named free variables and constants;
52408
fa2dc6c6c94f updated operations on proof terms;
wenzelm
parents: 52407
diff changeset
   381
  this is a datatype with constructors @{index_ML Bound}, @{index_ML
fa2dc6c6c94f updated operations on proof terms;
wenzelm
parents: 52407
diff changeset
   382
  Free}, @{index_ML Var}, @{index_ML Const}, @{index_ML Abs},
fa2dc6c6c94f updated operations on proof terms;
wenzelm
parents: 52407
diff changeset
   383
  @{index_ML_op "$"}.
20519
d7ad1217c24a more on terms;
wenzelm
parents: 20514
diff changeset
   384
36166
da7b40aa2215 made SML/NJ happy;
wenzelm
parents: 36134
diff changeset
   385
  \item @{text "t"}~@{ML_text aconv}~@{text "u"} checks @{text
20519
d7ad1217c24a more on terms;
wenzelm
parents: 20514
diff changeset
   386
  "\<alpha>"}-equivalence of two terms.  This is the basic equality relation
d7ad1217c24a more on terms;
wenzelm
parents: 20514
diff changeset
   387
  on type @{ML_type term}; raw datatype equality should only be used
d7ad1217c24a more on terms;
wenzelm
parents: 20514
diff changeset
   388
  for operations related to parsing or printing!
d7ad1217c24a more on terms;
wenzelm
parents: 20514
diff changeset
   389
39846
cb6634eb8926 examples in Isabelle/HOL;
wenzelm
parents: 39840
diff changeset
   390
  \item @{ML Term.map_types}~@{text "f t"} applies the mapping @{text
20537
b6b49903db7e *** empty log message ***
wenzelm
parents: 20521
diff changeset
   391
  "f"} to all types occurring in @{text "t"}.
b6b49903db7e *** empty log message ***
wenzelm
parents: 20521
diff changeset
   392
39846
cb6634eb8926 examples in Isabelle/HOL;
wenzelm
parents: 39840
diff changeset
   393
  \item @{ML Term.fold_types}~@{text "f t"} iterates the operation
cb6634eb8926 examples in Isabelle/HOL;
wenzelm
parents: 39840
diff changeset
   394
  @{text "f"} over all occurrences of types in @{text "t"}; the term
20537
b6b49903db7e *** empty log message ***
wenzelm
parents: 20521
diff changeset
   395
  structure is traversed from left to right.
20519
d7ad1217c24a more on terms;
wenzelm
parents: 20514
diff changeset
   396
39846
cb6634eb8926 examples in Isabelle/HOL;
wenzelm
parents: 39840
diff changeset
   397
  \item @{ML Term.map_aterms}~@{text "f t"} applies the mapping @{text
cb6634eb8926 examples in Isabelle/HOL;
wenzelm
parents: 39840
diff changeset
   398
  "f"} to all atomic terms (@{ML Bound}, @{ML Free}, @{ML Var}, @{ML
20537
b6b49903db7e *** empty log message ***
wenzelm
parents: 20521
diff changeset
   399
  Const}) occurring in @{text "t"}.
b6b49903db7e *** empty log message ***
wenzelm
parents: 20521
diff changeset
   400
39846
cb6634eb8926 examples in Isabelle/HOL;
wenzelm
parents: 39840
diff changeset
   401
  \item @{ML Term.fold_aterms}~@{text "f t"} iterates the operation
cb6634eb8926 examples in Isabelle/HOL;
wenzelm
parents: 39840
diff changeset
   402
  @{text "f"} over all occurrences of atomic terms (@{ML Bound}, @{ML
cb6634eb8926 examples in Isabelle/HOL;
wenzelm
parents: 39840
diff changeset
   403
  Free}, @{ML Var}, @{ML Const}) in @{text "t"}; the term structure is
20519
d7ad1217c24a more on terms;
wenzelm
parents: 20514
diff changeset
   404
  traversed from left to right.
d7ad1217c24a more on terms;
wenzelm
parents: 20514
diff changeset
   405
20537
b6b49903db7e *** empty log message ***
wenzelm
parents: 20521
diff changeset
   406
  \item @{ML fastype_of}~@{text "t"} determines the type of a
b6b49903db7e *** empty log message ***
wenzelm
parents: 20521
diff changeset
   407
  well-typed term.  This operation is relatively slow, despite the
b6b49903db7e *** empty log message ***
wenzelm
parents: 20521
diff changeset
   408
  omission of any sanity checks.
20519
d7ad1217c24a more on terms;
wenzelm
parents: 20514
diff changeset
   409
d7ad1217c24a more on terms;
wenzelm
parents: 20514
diff changeset
   410
  \item @{ML lambda}~@{text "a b"} produces an abstraction @{text
20537
b6b49903db7e *** empty log message ***
wenzelm
parents: 20521
diff changeset
   411
  "\<lambda>a. b"}, where occurrences of the atomic term @{text "a"} in the
b6b49903db7e *** empty log message ***
wenzelm
parents: 20521
diff changeset
   412
  body @{text "b"} are replaced by bound variables.
20519
d7ad1217c24a more on terms;
wenzelm
parents: 20514
diff changeset
   413
20537
b6b49903db7e *** empty log message ***
wenzelm
parents: 20521
diff changeset
   414
  \item @{ML betapply}~@{text "(t, u)"} produces an application @{text
b6b49903db7e *** empty log message ***
wenzelm
parents: 20521
diff changeset
   415
  "t u"}, with topmost @{text "\<beta>"}-conversion if @{text "t"} is an
b6b49903db7e *** empty log message ***
wenzelm
parents: 20521
diff changeset
   416
  abstraction.
20519
d7ad1217c24a more on terms;
wenzelm
parents: 20514
diff changeset
   417
42934
287182c2f23a moved incr_boundvars;
wenzelm
parents: 42933
diff changeset
   418
  \item @{ML incr_boundvars}~@{text "j"} increments a term's dangling
287182c2f23a moved incr_boundvars;
wenzelm
parents: 42933
diff changeset
   419
  bound variables by the offset @{text "j"}.  This is required when
287182c2f23a moved incr_boundvars;
wenzelm
parents: 42933
diff changeset
   420
  moving a subterm into a context where it is enclosed by a different
287182c2f23a moved incr_boundvars;
wenzelm
parents: 42933
diff changeset
   421
  number of abstractions.  Bound variables with a matching abstraction
287182c2f23a moved incr_boundvars;
wenzelm
parents: 42933
diff changeset
   422
  are unaffected.
287182c2f23a moved incr_boundvars;
wenzelm
parents: 42933
diff changeset
   423
42401
9bfaf6819291 updated some theory primitives, which now depend on auxiliary context;
wenzelm
parents: 40255
diff changeset
   424
  \item @{ML Sign.declare_const}~@{text "ctxt ((c, \<sigma>), mx)"} declares
9bfaf6819291 updated some theory primitives, which now depend on auxiliary context;
wenzelm
parents: 40255
diff changeset
   425
  a new constant @{text "c :: \<sigma>"} with optional mixfix syntax.
20519
d7ad1217c24a more on terms;
wenzelm
parents: 20514
diff changeset
   426
33174
1f2051f41335 adjusted to changes in corresponding ML code
haftmann
parents: 32833
diff changeset
   427
  \item @{ML Sign.add_abbrev}~@{text "print_mode (c, t)"}
21827
0b1d07f79c1e updated;
wenzelm
parents: 21324
diff changeset
   428
  introduces a new term abbreviation @{text "c \<equiv> t"}.
20519
d7ad1217c24a more on terms;
wenzelm
parents: 20514
diff changeset
   429
20520
wenzelm
parents: 20519
diff changeset
   430
  \item @{ML Sign.const_typargs}~@{text "thy (c, \<tau>)"} and @{ML
53015
a1119cf551e8 standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
wenzelm
parents: 52788
diff changeset
   431
  Sign.const_instance}~@{text "thy (c, [\<tau>\<^sub>1, \<dots>, \<tau>\<^sub>n])"}
20543
wenzelm
parents: 20542
diff changeset
   432
  convert between two representations of polymorphic constants: full
wenzelm
parents: 20542
diff changeset
   433
  type instance vs.\ compact type arguments form.
18537
2681f9e34390 "The Isabelle/Isar Implementation" manual;
wenzelm
parents:
diff changeset
   434
20514
5ede702cd2ca more on terms;
wenzelm
parents: 20501
diff changeset
   435
  \end{description}
58618
782f0b662cae more cartouches;
wenzelm
parents: 58555
diff changeset
   436
\<close>
18537
2681f9e34390 "The Isabelle/Isar Implementation" manual;
wenzelm
parents:
diff changeset
   437
58618
782f0b662cae more cartouches;
wenzelm
parents: 58555
diff changeset
   438
text %mlantiq \<open>
39832
1080dee73a53 various concrete ML antiquotations;
wenzelm
parents: 39821
diff changeset
   439
  \begin{matharray}{rcl}
1080dee73a53 various concrete ML antiquotations;
wenzelm
parents: 39821
diff changeset
   440
  @{ML_antiquotation_def "const_name"} & : & @{text ML_antiquotation} \\
1080dee73a53 various concrete ML antiquotations;
wenzelm
parents: 39821
diff changeset
   441
  @{ML_antiquotation_def "const_abbrev"} & : & @{text ML_antiquotation} \\
1080dee73a53 various concrete ML antiquotations;
wenzelm
parents: 39821
diff changeset
   442
  @{ML_antiquotation_def "const"} & : & @{text ML_antiquotation} \\
1080dee73a53 various concrete ML antiquotations;
wenzelm
parents: 39821
diff changeset
   443
  @{ML_antiquotation_def "term"} & : & @{text ML_antiquotation} \\
1080dee73a53 various concrete ML antiquotations;
wenzelm
parents: 39821
diff changeset
   444
  @{ML_antiquotation_def "prop"} & : & @{text ML_antiquotation} \\
1080dee73a53 various concrete ML antiquotations;
wenzelm
parents: 39821
diff changeset
   445
  \end{matharray}
1080dee73a53 various concrete ML antiquotations;
wenzelm
parents: 39821
diff changeset
   446
55112
b1a5d603fd12 prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents: 55029
diff changeset
   447
  @{rail \<open>
42510
b9c106763325 use @{rail} antiquotation (with some nested markup);
wenzelm
parents: 42401
diff changeset
   448
  (@@{ML_antiquotation const_name} |
b9c106763325 use @{rail} antiquotation (with some nested markup);
wenzelm
parents: 42401
diff changeset
   449
   @@{ML_antiquotation const_abbrev}) nameref
39832
1080dee73a53 various concrete ML antiquotations;
wenzelm
parents: 39821
diff changeset
   450
  ;
42510
b9c106763325 use @{rail} antiquotation (with some nested markup);
wenzelm
parents: 42401
diff changeset
   451
  @@{ML_antiquotation const} ('(' (type + ',') ')')?
39832
1080dee73a53 various concrete ML antiquotations;
wenzelm
parents: 39821
diff changeset
   452
  ;
42510
b9c106763325 use @{rail} antiquotation (with some nested markup);
wenzelm
parents: 42401
diff changeset
   453
  @@{ML_antiquotation term} term
39832
1080dee73a53 various concrete ML antiquotations;
wenzelm
parents: 39821
diff changeset
   454
  ;
42510
b9c106763325 use @{rail} antiquotation (with some nested markup);
wenzelm
parents: 42401
diff changeset
   455
  @@{ML_antiquotation prop} prop
55112
b1a5d603fd12 prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents: 55029
diff changeset
   456
  \<close>}
39832
1080dee73a53 various concrete ML antiquotations;
wenzelm
parents: 39821
diff changeset
   457
1080dee73a53 various concrete ML antiquotations;
wenzelm
parents: 39821
diff changeset
   458
  \begin{description}
1080dee73a53 various concrete ML antiquotations;
wenzelm
parents: 39821
diff changeset
   459
1080dee73a53 various concrete ML antiquotations;
wenzelm
parents: 39821
diff changeset
   460
  \item @{text "@{const_name c}"} inlines the internalized logical
1080dee73a53 various concrete ML antiquotations;
wenzelm
parents: 39821
diff changeset
   461
  constant name @{text "c"} --- as @{ML_type string} literal.
1080dee73a53 various concrete ML antiquotations;
wenzelm
parents: 39821
diff changeset
   462
1080dee73a53 various concrete ML antiquotations;
wenzelm
parents: 39821
diff changeset
   463
  \item @{text "@{const_abbrev c}"} inlines the internalized
1080dee73a53 various concrete ML antiquotations;
wenzelm
parents: 39821
diff changeset
   464
  abbreviated constant name @{text "c"} --- as @{ML_type string}
1080dee73a53 various concrete ML antiquotations;
wenzelm
parents: 39821
diff changeset
   465
  literal.
1080dee73a53 various concrete ML antiquotations;
wenzelm
parents: 39821
diff changeset
   466
1080dee73a53 various concrete ML antiquotations;
wenzelm
parents: 39821
diff changeset
   467
  \item @{text "@{const c(\<^vec>\<tau>)}"} inlines the internalized
1080dee73a53 various concrete ML antiquotations;
wenzelm
parents: 39821
diff changeset
   468
  constant @{text "c"} with precise type instantiation in the sense of
1080dee73a53 various concrete ML antiquotations;
wenzelm
parents: 39821
diff changeset
   469
  @{ML Sign.const_instance} --- as @{ML Const} constructor term for
1080dee73a53 various concrete ML antiquotations;
wenzelm
parents: 39821
diff changeset
   470
  datatype @{ML_type term}.
1080dee73a53 various concrete ML antiquotations;
wenzelm
parents: 39821
diff changeset
   471
1080dee73a53 various concrete ML antiquotations;
wenzelm
parents: 39821
diff changeset
   472
  \item @{text "@{term t}"} inlines the internalized term @{text "t"}
1080dee73a53 various concrete ML antiquotations;
wenzelm
parents: 39821
diff changeset
   473
  --- as constructor term for datatype @{ML_type term}.
1080dee73a53 various concrete ML antiquotations;
wenzelm
parents: 39821
diff changeset
   474
1080dee73a53 various concrete ML antiquotations;
wenzelm
parents: 39821
diff changeset
   475
  \item @{text "@{prop \<phi>}"} inlines the internalized proposition
1080dee73a53 various concrete ML antiquotations;
wenzelm
parents: 39821
diff changeset
   476
  @{text "\<phi>"} --- as constructor term for datatype @{ML_type term}.
1080dee73a53 various concrete ML antiquotations;
wenzelm
parents: 39821
diff changeset
   477
1080dee73a53 various concrete ML antiquotations;
wenzelm
parents: 39821
diff changeset
   478
  \end{description}
58618
782f0b662cae more cartouches;
wenzelm
parents: 58555
diff changeset
   479
\<close>
39832
1080dee73a53 various concrete ML antiquotations;
wenzelm
parents: 39821
diff changeset
   480
18537
2681f9e34390 "The Isabelle/Isar Implementation" manual;
wenzelm
parents:
diff changeset
   481
58618
782f0b662cae more cartouches;
wenzelm
parents: 58555
diff changeset
   482
section \<open>Theorems \label{sec:thms}\<close>
18537
2681f9e34390 "The Isabelle/Isar Implementation" manual;
wenzelm
parents:
diff changeset
   483
58618
782f0b662cae more cartouches;
wenzelm
parents: 58555
diff changeset
   484
text \<open>
20543
wenzelm
parents: 20542
diff changeset
   485
  A \emph{proposition} is a well-typed term of type @{text "prop"}, a
20521
189811b39869 more on theorems;
wenzelm
parents: 20520
diff changeset
   486
  \emph{theorem} is a proven proposition (depending on a context of
189811b39869 more on theorems;
wenzelm
parents: 20520
diff changeset
   487
  hypotheses and the background theory).  Primitive inferences include
29774
wenzelm
parents: 29771
diff changeset
   488
  plain Natural Deduction rules for the primary connectives @{text
20537
b6b49903db7e *** empty log message ***
wenzelm
parents: 20521
diff changeset
   489
  "\<And>"} and @{text "\<Longrightarrow>"} of the framework.  There is also a builtin
b6b49903db7e *** empty log message ***
wenzelm
parents: 20521
diff changeset
   490
  notion of equality/equivalence @{text "\<equiv>"}.
58618
782f0b662cae more cartouches;
wenzelm
parents: 58555
diff changeset
   491
\<close>
20521
189811b39869 more on theorems;
wenzelm
parents: 20520
diff changeset
   492
29758
7a3b5bbed313 removed rudiments of glossary;
wenzelm
parents: 29755
diff changeset
   493
58618
782f0b662cae more cartouches;
wenzelm
parents: 58555
diff changeset
   494
subsection \<open>Primitive connectives and rules \label{sec:prim-rules}\<close>
18537
2681f9e34390 "The Isabelle/Isar Implementation" manual;
wenzelm
parents:
diff changeset
   495
58618
782f0b662cae more cartouches;
wenzelm
parents: 58555
diff changeset
   496
text \<open>
20543
wenzelm
parents: 20542
diff changeset
   497
  The theory @{text "Pure"} contains constant declarations for the
wenzelm
parents: 20542
diff changeset
   498
  primitive connectives @{text "\<And>"}, @{text "\<Longrightarrow>"}, and @{text "\<equiv>"} of
wenzelm
parents: 20542
diff changeset
   499
  the logical framework, see \figref{fig:pure-connectives}.  The
53015
a1119cf551e8 standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
wenzelm
parents: 52788
diff changeset
   500
  derivability judgment @{text "A\<^sub>1, \<dots>, A\<^sub>n \<turnstile> B"} is
20543
wenzelm
parents: 20542
diff changeset
   501
  defined inductively by the primitive inferences given in
wenzelm
parents: 20542
diff changeset
   502
  \figref{fig:prim-rules}, with the global restriction that the
wenzelm
parents: 20542
diff changeset
   503
  hypotheses must \emph{not} contain any schematic variables.  The
wenzelm
parents: 20542
diff changeset
   504
  builtin equality is conceptually axiomatized as shown in
20521
189811b39869 more on theorems;
wenzelm
parents: 20520
diff changeset
   505
  \figref{fig:pure-equality}, although the implementation works
20543
wenzelm
parents: 20542
diff changeset
   506
  directly with derived inferences.
20521
189811b39869 more on theorems;
wenzelm
parents: 20520
diff changeset
   507
189811b39869 more on theorems;
wenzelm
parents: 20520
diff changeset
   508
  \begin{figure}[htb]
189811b39869 more on theorems;
wenzelm
parents: 20520
diff changeset
   509
  \begin{center}
20501
de0b523b0d62 more rules;
wenzelm
parents: 20498
diff changeset
   510
  \begin{tabular}{ll}
de0b523b0d62 more rules;
wenzelm
parents: 20498
diff changeset
   511
  @{text "all :: (\<alpha> \<Rightarrow> prop) \<Rightarrow> prop"} & universal quantification (binder @{text "\<And>"}) \\
de0b523b0d62 more rules;
wenzelm
parents: 20498
diff changeset
   512
  @{text "\<Longrightarrow> :: prop \<Rightarrow> prop \<Rightarrow> prop"} & implication (right associative infix) \\
20521
189811b39869 more on theorems;
wenzelm
parents: 20520
diff changeset
   513
  @{text "\<equiv> :: \<alpha> \<Rightarrow> \<alpha> \<Rightarrow> prop"} & equality relation (infix) \\
20501
de0b523b0d62 more rules;
wenzelm
parents: 20498
diff changeset
   514
  \end{tabular}
20537
b6b49903db7e *** empty log message ***
wenzelm
parents: 20521
diff changeset
   515
  \caption{Primitive connectives of Pure}\label{fig:pure-connectives}
20521
189811b39869 more on theorems;
wenzelm
parents: 20520
diff changeset
   516
  \end{center}
189811b39869 more on theorems;
wenzelm
parents: 20520
diff changeset
   517
  \end{figure}
18537
2681f9e34390 "The Isabelle/Isar Implementation" manual;
wenzelm
parents:
diff changeset
   518
20501
de0b523b0d62 more rules;
wenzelm
parents: 20498
diff changeset
   519
  \begin{figure}[htb]
de0b523b0d62 more rules;
wenzelm
parents: 20498
diff changeset
   520
  \begin{center}
20498
825a8d2335ce more rules;
wenzelm
parents: 20494
diff changeset
   521
  \[
825a8d2335ce more rules;
wenzelm
parents: 20494
diff changeset
   522
  \infer[@{text "(axiom)"}]{@{text "\<turnstile> A"}}{@{text "A \<in> \<Theta>"}}
825a8d2335ce more rules;
wenzelm
parents: 20494
diff changeset
   523
  \qquad
825a8d2335ce more rules;
wenzelm
parents: 20494
diff changeset
   524
  \infer[@{text "(assume)"}]{@{text "A \<turnstile> A"}}{}
825a8d2335ce more rules;
wenzelm
parents: 20494
diff changeset
   525
  \]
825a8d2335ce more rules;
wenzelm
parents: 20494
diff changeset
   526
  \[
52407
e4662afb3483 more on proof terms;
wenzelm
parents: 52406
diff changeset
   527
  \infer[@{text "(\<And>\<hyphen>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
   528
  \qquad
52407
e4662afb3483 more on proof terms;
wenzelm
parents: 52406
diff changeset
   529
  \infer[@{text "(\<And>\<hyphen>elim)"}]{@{text "\<Gamma> \<turnstile> B[a]"}}{@{text "\<Gamma> \<turnstile> \<And>x. B[x]"}}
20498
825a8d2335ce more rules;
wenzelm
parents: 20494
diff changeset
   530
  \]
825a8d2335ce more rules;
wenzelm
parents: 20494
diff changeset
   531
  \[
42666
fee67c099d03 use existing \<hyphen>;
wenzelm
parents: 42517
diff changeset
   532
  \infer[@{text "(\<Longrightarrow>\<hyphen>intro)"}]{@{text "\<Gamma> - A \<turnstile> A \<Longrightarrow> B"}}{@{text "\<Gamma> \<turnstile> B"}}
20498
825a8d2335ce more rules;
wenzelm
parents: 20494
diff changeset
   533
  \qquad
42666
fee67c099d03 use existing \<hyphen>;
wenzelm
parents: 42517
diff changeset
   534
  \infer[@{text "(\<Longrightarrow>\<hyphen>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"}}
20498
825a8d2335ce more rules;
wenzelm
parents: 20494
diff changeset
   535
  \]
20521
189811b39869 more on theorems;
wenzelm
parents: 20520
diff changeset
   536
  \caption{Primitive inferences of Pure}\label{fig:prim-rules}
189811b39869 more on theorems;
wenzelm
parents: 20520
diff changeset
   537
  \end{center}
189811b39869 more on theorems;
wenzelm
parents: 20520
diff changeset
   538
  \end{figure}
189811b39869 more on theorems;
wenzelm
parents: 20520
diff changeset
   539
189811b39869 more on theorems;
wenzelm
parents: 20520
diff changeset
   540
  \begin{figure}[htb]
189811b39869 more on theorems;
wenzelm
parents: 20520
diff changeset
   541
  \begin{center}
189811b39869 more on theorems;
wenzelm
parents: 20520
diff changeset
   542
  \begin{tabular}{ll}
20537
b6b49903db7e *** empty log message ***
wenzelm
parents: 20521
diff changeset
   543
  @{text "\<turnstile> (\<lambda>x. b[x]) a \<equiv> b[a]"} & @{text "\<beta>"}-conversion \\
20521
189811b39869 more on theorems;
wenzelm
parents: 20520
diff changeset
   544
  @{text "\<turnstile> x \<equiv> x"} & reflexivity \\
189811b39869 more on theorems;
wenzelm
parents: 20520
diff changeset
   545
  @{text "\<turnstile> x \<equiv> y \<Longrightarrow> P x \<Longrightarrow> P y"} & substitution \\
189811b39869 more on theorems;
wenzelm
parents: 20520
diff changeset
   546
  @{text "\<turnstile> (\<And>x. f x \<equiv> g x) \<Longrightarrow> f \<equiv> g"} & extensionality \\
20537
b6b49903db7e *** empty log message ***
wenzelm
parents: 20521
diff changeset
   547
  @{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
   548
  \end{tabular}
20542
a54ca4e90874 more on theorems;
wenzelm
parents: 20537
diff changeset
   549
  \caption{Conceptual axiomatization of Pure equality}\label{fig:pure-equality}
20501
de0b523b0d62 more rules;
wenzelm
parents: 20498
diff changeset
   550
  \end{center}
de0b523b0d62 more rules;
wenzelm
parents: 20498
diff changeset
   551
  \end{figure}
18537
2681f9e34390 "The Isabelle/Isar Implementation" manual;
wenzelm
parents:
diff changeset
   552
20501
de0b523b0d62 more rules;
wenzelm
parents: 20498
diff changeset
   553
  The introduction and elimination rules for @{text "\<And>"} and @{text
20537
b6b49903db7e *** empty log message ***
wenzelm
parents: 20521
diff changeset
   554
  "\<Longrightarrow>"} are analogous to formation of dependently typed @{text
20501
de0b523b0d62 more rules;
wenzelm
parents: 20498
diff changeset
   555
  "\<lambda>"}-terms representing the underlying proof objects.  Proof terms
20543
wenzelm
parents: 20542
diff changeset
   556
  are irrelevant in the Pure logic, though; they cannot occur within
wenzelm
parents: 20542
diff changeset
   557
  propositions.  The system provides a runtime option to record
52408
fa2dc6c6c94f updated operations on proof terms;
wenzelm
parents: 52407
diff changeset
   558
  explicit proof terms for primitive inferences, see also
fa2dc6c6c94f updated operations on proof terms;
wenzelm
parents: 52407
diff changeset
   559
  \secref{sec:proof-terms}.  Thus all three levels of @{text
fa2dc6c6c94f updated operations on proof terms;
wenzelm
parents: 52407
diff changeset
   560
  "\<lambda>"}-calculus become explicit: @{text "\<Rightarrow>"} for terms, and @{text
58555
7975676c08c0 prefer @{cite} antiquotation;
wenzelm
parents: 56579
diff changeset
   561
  "\<And>/\<Longrightarrow>"} for proofs (cf.\ @{cite "Berghofer-Nipkow:2000:TPHOL"}).
20491
wenzelm
parents: 20480
diff changeset
   562
34929
9700a87f1cc2 misc tuning and clarification;
wenzelm
parents: 34921
diff changeset
   563
  Observe that locally fixed parameters (as in @{text
42666
fee67c099d03 use existing \<hyphen>;
wenzelm
parents: 42517
diff changeset
   564
  "\<And>\<hyphen>intro"}) need not be recorded in the hypotheses, because
34929
9700a87f1cc2 misc tuning and clarification;
wenzelm
parents: 34921
diff changeset
   565
  the simple syntactic types of Pure are always inhabitable.
9700a87f1cc2 misc tuning and clarification;
wenzelm
parents: 34921
diff changeset
   566
  ``Assumptions'' @{text "x :: \<tau>"} for type-membership are only
53015
a1119cf551e8 standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
wenzelm
parents: 52788
diff changeset
   567
  present as long as some @{text "x\<^sub>\<tau>"} occurs in the statement
34929
9700a87f1cc2 misc tuning and clarification;
wenzelm
parents: 34921
diff changeset
   568
  body.\footnote{This is the key difference to ``@{text "\<lambda>HOL"}'' in
58555
7975676c08c0 prefer @{cite} antiquotation;
wenzelm
parents: 56579
diff changeset
   569
  the PTS framework @{cite "Barendregt-Geuvers:2001"}, where hypotheses
34929
9700a87f1cc2 misc tuning and clarification;
wenzelm
parents: 34921
diff changeset
   570
  @{text "x : A"} are treated uniformly for propositions and types.}
20501
de0b523b0d62 more rules;
wenzelm
parents: 20498
diff changeset
   571
de0b523b0d62 more rules;
wenzelm
parents: 20498
diff changeset
   572
  \medskip The axiomatization of a theory is implicitly closed by
20537
b6b49903db7e *** empty log message ***
wenzelm
parents: 20521
diff changeset
   573
  forming all instances of type and term variables: @{text "\<turnstile>
b6b49903db7e *** empty log message ***
wenzelm
parents: 20521
diff changeset
   574
  A\<vartheta>"} holds for any substitution instance of an axiom
20543
wenzelm
parents: 20542
diff changeset
   575
  @{text "\<turnstile> A"}.  By pushing substitutions through derivations
wenzelm
parents: 20542
diff changeset
   576
  inductively, we also get admissible @{text "generalize"} and @{text
34929
9700a87f1cc2 misc tuning and clarification;
wenzelm
parents: 34921
diff changeset
   577
  "instantiate"} rules as shown in \figref{fig:subst-rules}.
20501
de0b523b0d62 more rules;
wenzelm
parents: 20498
diff changeset
   578
de0b523b0d62 more rules;
wenzelm
parents: 20498
diff changeset
   579
  \begin{figure}[htb]
de0b523b0d62 more rules;
wenzelm
parents: 20498
diff changeset
   580
  \begin{center}
20498
825a8d2335ce more rules;
wenzelm
parents: 20494
diff changeset
   581
  \[
20501
de0b523b0d62 more rules;
wenzelm
parents: 20498
diff changeset
   582
  \infer{@{text "\<Gamma> \<turnstile> B[?\<alpha>]"}}{@{text "\<Gamma> \<turnstile> B[\<alpha>]"} & @{text "\<alpha> \<notin> \<Gamma>"}}
de0b523b0d62 more rules;
wenzelm
parents: 20498
diff changeset
   583
  \quad
de0b523b0d62 more rules;
wenzelm
parents: 20498
diff changeset
   584
  \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
   585
  \]
825a8d2335ce more rules;
wenzelm
parents: 20494
diff changeset
   586
  \[
20501
de0b523b0d62 more rules;
wenzelm
parents: 20498
diff changeset
   587
  \infer{@{text "\<Gamma> \<turnstile> B[\<tau>]"}}{@{text "\<Gamma> \<turnstile> B[?\<alpha>]"}}
de0b523b0d62 more rules;
wenzelm
parents: 20498
diff changeset
   588
  \quad
de0b523b0d62 more rules;
wenzelm
parents: 20498
diff changeset
   589
  \infer[\quad@{text "(instantiate)"}]{@{text "\<Gamma> \<turnstile> B[t]"}}{@{text "\<Gamma> \<turnstile> B[?x]"}}
20498
825a8d2335ce more rules;
wenzelm
parents: 20494
diff changeset
   590
  \]
20501
de0b523b0d62 more rules;
wenzelm
parents: 20498
diff changeset
   591
  \caption{Admissible substitution rules}\label{fig:subst-rules}
de0b523b0d62 more rules;
wenzelm
parents: 20498
diff changeset
   592
  \end{center}
de0b523b0d62 more rules;
wenzelm
parents: 20498
diff changeset
   593
  \end{figure}
18537
2681f9e34390 "The Isabelle/Isar Implementation" manual;
wenzelm
parents:
diff changeset
   594
20537
b6b49903db7e *** empty log message ***
wenzelm
parents: 20521
diff changeset
   595
  Note that @{text "instantiate"} does not require an explicit
b6b49903db7e *** empty log message ***
wenzelm
parents: 20521
diff changeset
   596
  side-condition, because @{text "\<Gamma>"} may never contain schematic
b6b49903db7e *** empty log message ***
wenzelm
parents: 20521
diff changeset
   597
  variables.
b6b49903db7e *** empty log message ***
wenzelm
parents: 20521
diff changeset
   598
b6b49903db7e *** empty log message ***
wenzelm
parents: 20521
diff changeset
   599
  In principle, variables could be substituted in hypotheses as well,
20543
wenzelm
parents: 20542
diff changeset
   600
  but this would disrupt the monotonicity of reasoning: deriving
wenzelm
parents: 20542
diff changeset
   601
  @{text "\<Gamma>\<vartheta> \<turnstile> B\<vartheta>"} from @{text "\<Gamma> \<turnstile> B"} is
wenzelm
parents: 20542
diff changeset
   602
  correct, but @{text "\<Gamma>\<vartheta> \<supseteq> \<Gamma>"} does not necessarily hold:
wenzelm
parents: 20542
diff changeset
   603
  the result belongs to a different proof context.
20542
a54ca4e90874 more on theorems;
wenzelm
parents: 20537
diff changeset
   604
20543
wenzelm
parents: 20542
diff changeset
   605
  \medskip An \emph{oracle} is a function that produces axioms on the
wenzelm
parents: 20542
diff changeset
   606
  fly.  Logically, this is an instance of the @{text "axiom"} rule
wenzelm
parents: 20542
diff changeset
   607
  (\figref{fig:prim-rules}), but there is an operational difference.
wenzelm
parents: 20542
diff changeset
   608
  The system always records oracle invocations within derivations of
29768
64a50ff3f308 more on object-level rules;
wenzelm
parents: 29761
diff changeset
   609
  theorems by a unique tag.
20542
a54ca4e90874 more on theorems;
wenzelm
parents: 20537
diff changeset
   610
a54ca4e90874 more on theorems;
wenzelm
parents: 20537
diff changeset
   611
  Axiomatizations should be limited to the bare minimum, typically as
a54ca4e90874 more on theorems;
wenzelm
parents: 20537
diff changeset
   612
  part of the initial logical basis of an object-logic formalization.
20543
wenzelm
parents: 20542
diff changeset
   613
  Later on, theories are usually developed in a strictly definitional
wenzelm
parents: 20542
diff changeset
   614
  fashion, by stating only certain equalities over new constants.
20542
a54ca4e90874 more on theorems;
wenzelm
parents: 20537
diff changeset
   615
a54ca4e90874 more on theorems;
wenzelm
parents: 20537
diff changeset
   616
  A \emph{simple definition} consists of a constant declaration @{text
20543
wenzelm
parents: 20542
diff changeset
   617
  "c :: \<sigma>"} together with an axiom @{text "\<turnstile> c \<equiv> t"}, where @{text "t
wenzelm
parents: 20542
diff changeset
   618
  :: \<sigma>"} is a closed term without any hidden polymorphism.  The RHS
wenzelm
parents: 20542
diff changeset
   619
  may depend on further defined constants, but not @{text "c"} itself.
wenzelm
parents: 20542
diff changeset
   620
  Definitions of functions may be presented as @{text "c \<^vec>x \<equiv>
wenzelm
parents: 20542
diff changeset
   621
  t"} instead of the puristic @{text "c \<equiv> \<lambda>\<^vec>x. t"}.
20542
a54ca4e90874 more on theorems;
wenzelm
parents: 20537
diff changeset
   622
20543
wenzelm
parents: 20542
diff changeset
   623
  An \emph{overloaded definition} consists of a collection of axioms
wenzelm
parents: 20542
diff changeset
   624
  for the same constant, with zero or one equations @{text
wenzelm
parents: 20542
diff changeset
   625
  "c((\<^vec>\<alpha>)\<kappa>) \<equiv> t"} for each type constructor @{text "\<kappa>"} (for
wenzelm
parents: 20542
diff changeset
   626
  distinct variables @{text "\<^vec>\<alpha>"}).  The RHS may mention
wenzelm
parents: 20542
diff changeset
   627
  previously defined constants as above, or arbitrary constants @{text
53015
a1119cf551e8 standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
wenzelm
parents: 52788
diff changeset
   628
  "d(\<alpha>\<^sub>i)"} for some @{text "\<alpha>\<^sub>i"} projected from @{text
20543
wenzelm
parents: 20542
diff changeset
   629
  "\<^vec>\<alpha>"}.  Thus overloaded definitions essentially work by
wenzelm
parents: 20542
diff changeset
   630
  primitive recursion over the syntactic structure of a single type
58555
7975676c08c0 prefer @{cite} antiquotation;
wenzelm
parents: 56579
diff changeset
   631
  argument.  See also @{cite \<open>\S4.3\<close> "Haftmann-Wenzel:2006:classes"}.
58618
782f0b662cae more cartouches;
wenzelm
parents: 58555
diff changeset
   632
\<close>
20498
825a8d2335ce more rules;
wenzelm
parents: 20494
diff changeset
   633
58618
782f0b662cae more cartouches;
wenzelm
parents: 58555
diff changeset
   634
text %mlref \<open>
20521
189811b39869 more on theorems;
wenzelm
parents: 20520
diff changeset
   635
  \begin{mldecls}
46253
3e427a12f0f3 more on Logic.all/mk_implies etc.;
wenzelm
parents: 42934
diff changeset
   636
  @{index_ML Logic.all: "term -> term -> term"} \\
3e427a12f0f3 more on Logic.all/mk_implies etc.;
wenzelm
parents: 42934
diff changeset
   637
  @{index_ML Logic.mk_implies: "term * term -> term"} \\
3e427a12f0f3 more on Logic.all/mk_implies etc.;
wenzelm
parents: 42934
diff changeset
   638
  \end{mldecls}
3e427a12f0f3 more on Logic.all/mk_implies etc.;
wenzelm
parents: 42934
diff changeset
   639
  \begin{mldecls}
20521
189811b39869 more on theorems;
wenzelm
parents: 20520
diff changeset
   640
  @{index_ML_type ctyp} \\
189811b39869 more on theorems;
wenzelm
parents: 20520
diff changeset
   641
  @{index_ML_type cterm} \\
59621
291934bac95e Thm.cterm_of and Thm.ctyp_of operate on local context;
wenzelm
parents: 58728
diff changeset
   642
  @{index_ML Thm.ctyp_of: "Proof.context -> typ -> ctyp"} \\
291934bac95e Thm.cterm_of and Thm.ctyp_of operate on local context;
wenzelm
parents: 58728
diff changeset
   643
  @{index_ML Thm.cterm_of: "Proof.context -> term -> cterm"} \\
46497
89ccf66aa73d renamed Thm.capply to Thm.apply, and Thm.cabs to Thm.lambda in conformance with similar operations in structure Term and Logic;
wenzelm
parents: 46262
diff changeset
   644
  @{index_ML Thm.apply: "cterm -> cterm -> cterm"} \\
89ccf66aa73d renamed Thm.capply to Thm.apply, and Thm.cabs to Thm.lambda in conformance with similar operations in structure Term and Logic;
wenzelm
parents: 46262
diff changeset
   645
  @{index_ML Thm.lambda: "cterm -> cterm -> cterm"} \\
60938
b316f218ef34 clarified context;
wenzelm
parents: 60642
diff changeset
   646
  @{index_ML Thm.all: "Proof.context -> cterm -> cterm -> cterm"} \\
46253
3e427a12f0f3 more on Logic.all/mk_implies etc.;
wenzelm
parents: 42934
diff changeset
   647
  @{index_ML Drule.mk_implies: "cterm * cterm -> cterm"} \\
20547
wenzelm
parents: 20543
diff changeset
   648
  \end{mldecls}
wenzelm
parents: 20543
diff changeset
   649
  \begin{mldecls}
20521
189811b39869 more on theorems;
wenzelm
parents: 20520
diff changeset
   650
  @{index_ML_type thm} \\
50126
3dec88149176 theorem status about oracles/futures is no longer printed by default;
wenzelm
parents: 48985
diff changeset
   651
  @{index_ML Thm.peek_status: "thm -> {oracle: bool, unfinished: bool, failed: bool}"} \\
42933
7860ffc5ec08 modernized and re-unified Thm.transfer;
wenzelm
parents: 42666
diff changeset
   652
  @{index_ML Thm.transfer: "theory -> thm -> thm"} \\
20542
a54ca4e90874 more on theorems;
wenzelm
parents: 20537
diff changeset
   653
  @{index_ML Thm.assume: "cterm -> thm"} \\
a54ca4e90874 more on theorems;
wenzelm
parents: 20537
diff changeset
   654
  @{index_ML Thm.forall_intr: "cterm -> thm -> thm"} \\
a54ca4e90874 more on theorems;
wenzelm
parents: 20537
diff changeset
   655
  @{index_ML Thm.forall_elim: "cterm -> thm -> thm"} \\
a54ca4e90874 more on theorems;
wenzelm
parents: 20537
diff changeset
   656
  @{index_ML Thm.implies_intr: "cterm -> thm -> thm"} \\
a54ca4e90874 more on theorems;
wenzelm
parents: 20537
diff changeset
   657
  @{index_ML Thm.implies_elim: "thm -> thm -> thm"} \\
a54ca4e90874 more on theorems;
wenzelm
parents: 20537
diff changeset
   658
  @{index_ML Thm.generalize: "string list * string list -> int -> thm -> thm"} \\
60642
48dd1cefb4ae simplified Thm.instantiate and derivatives: the LHS refers to non-certified variables -- this merely serves as index into already certified structures (or is ignored);
wenzelm
parents: 59902
diff changeset
   659
  @{index_ML Thm.instantiate: "((indexname * sort) * ctyp) list * ((indexname * typ) * cterm) list
48dd1cefb4ae simplified Thm.instantiate and derivatives: the LHS refers to non-certified variables -- this merely serves as index into already certified structures (or is ignored);
wenzelm
parents: 59902
diff changeset
   660
  -> thm -> thm"} \\
42401
9bfaf6819291 updated some theory primitives, which now depend on auxiliary context;
wenzelm
parents: 40255
diff changeset
   661
  @{index_ML Thm.add_axiom: "Proof.context ->
9bfaf6819291 updated some theory primitives, which now depend on auxiliary context;
wenzelm
parents: 40255
diff changeset
   662
  binding * term -> theory -> (string * thm) * theory"} \\
39821
bf164c153d10 minor tuning and updating;
wenzelm
parents: 39281
diff changeset
   663
  @{index_ML Thm.add_oracle: "binding * ('a -> cterm) -> theory ->
bf164c153d10 minor tuning and updating;
wenzelm
parents: 39281
diff changeset
   664
  (string * ('a -> thm)) * theory"} \\
42401
9bfaf6819291 updated some theory primitives, which now depend on auxiliary context;
wenzelm
parents: 40255
diff changeset
   665
  @{index_ML Thm.add_def: "Proof.context -> bool -> bool ->
9bfaf6819291 updated some theory primitives, which now depend on auxiliary context;
wenzelm
parents: 40255
diff changeset
   666
  binding * term -> theory -> (string * thm) * theory"} \\
20547
wenzelm
parents: 20543
diff changeset
   667
  \end{mldecls}
wenzelm
parents: 20543
diff changeset
   668
  \begin{mldecls}
42401
9bfaf6819291 updated some theory primitives, which now depend on auxiliary context;
wenzelm
parents: 40255
diff changeset
   669
  @{index_ML Theory.add_deps: "Proof.context -> string ->
61255
15865e0c5598 eliminated separate type Theory.dep: use typeargs uniformly for consts/types;
wenzelm
parents: 61246
diff changeset
   670
  Defs.entry -> Defs.entry list -> theory -> theory"} \\
20521
189811b39869 more on theorems;
wenzelm
parents: 20520
diff changeset
   671
  \end{mldecls}
189811b39869 more on theorems;
wenzelm
parents: 20520
diff changeset
   672
189811b39869 more on theorems;
wenzelm
parents: 20520
diff changeset
   673
  \begin{description}
189811b39869 more on theorems;
wenzelm
parents: 20520
diff changeset
   674
50126
3dec88149176 theorem status about oracles/futures is no longer printed by default;
wenzelm
parents: 48985
diff changeset
   675
  \item @{ML Thm.peek_status}~@{text "thm"} informs about the current
3dec88149176 theorem status about oracles/futures is no longer printed by default;
wenzelm
parents: 48985
diff changeset
   676
  status of the derivation object behind the given theorem.  This is a
3dec88149176 theorem status about oracles/futures is no longer printed by default;
wenzelm
parents: 48985
diff changeset
   677
  snapshot of a potentially ongoing (parallel) evaluation of proofs.
3dec88149176 theorem status about oracles/futures is no longer printed by default;
wenzelm
parents: 48985
diff changeset
   678
  The three Boolean values indicate the following: @{verbatim oracle}
3dec88149176 theorem status about oracles/futures is no longer printed by default;
wenzelm
parents: 48985
diff changeset
   679
  if the finished part contains some oracle invocation; @{verbatim
3dec88149176 theorem status about oracles/futures is no longer printed by default;
wenzelm
parents: 48985
diff changeset
   680
  unfinished} if some future proofs are still pending; @{verbatim
3dec88149176 theorem status about oracles/futures is no longer printed by default;
wenzelm
parents: 48985
diff changeset
   681
  failed} if some future proof has failed, rendering the theorem
3dec88149176 theorem status about oracles/futures is no longer printed by default;
wenzelm
parents: 48985
diff changeset
   682
  invalid!
3dec88149176 theorem status about oracles/futures is no longer printed by default;
wenzelm
parents: 48985
diff changeset
   683
46253
3e427a12f0f3 more on Logic.all/mk_implies etc.;
wenzelm
parents: 42934
diff changeset
   684
  \item @{ML Logic.all}~@{text "a B"} produces a Pure quantification
3e427a12f0f3 more on Logic.all/mk_implies etc.;
wenzelm
parents: 42934
diff changeset
   685
  @{text "\<And>a. B"}, where occurrences of the atomic term @{text "a"} in
3e427a12f0f3 more on Logic.all/mk_implies etc.;
wenzelm
parents: 42934
diff changeset
   686
  the body proposition @{text "B"} are replaced by bound variables.
3e427a12f0f3 more on Logic.all/mk_implies etc.;
wenzelm
parents: 42934
diff changeset
   687
  (See also @{ML lambda} on terms.)
3e427a12f0f3 more on Logic.all/mk_implies etc.;
wenzelm
parents: 42934
diff changeset
   688
3e427a12f0f3 more on Logic.all/mk_implies etc.;
wenzelm
parents: 42934
diff changeset
   689
  \item @{ML Logic.mk_implies}~@{text "(A, B)"} produces a Pure
3e427a12f0f3 more on Logic.all/mk_implies etc.;
wenzelm
parents: 42934
diff changeset
   690
  implication @{text "A \<Longrightarrow> B"}.
3e427a12f0f3 more on Logic.all/mk_implies etc.;
wenzelm
parents: 42934
diff changeset
   691
39864
wenzelm
parents: 39861
diff changeset
   692
  \item Types @{ML_type ctyp} and @{ML_type cterm} represent certified
wenzelm
parents: 39861
diff changeset
   693
  types and terms, respectively.  These are abstract datatypes that
20542
a54ca4e90874 more on theorems;
wenzelm
parents: 20537
diff changeset
   694
  guarantee that its values have passed the full well-formedness (and
a54ca4e90874 more on theorems;
wenzelm
parents: 20537
diff changeset
   695
  well-typedness) checks, relative to the declarations of type
46253
3e427a12f0f3 more on Logic.all/mk_implies etc.;
wenzelm
parents: 42934
diff changeset
   696
  constructors, constants etc.\ in the background theory.  The
3e427a12f0f3 more on Logic.all/mk_implies etc.;
wenzelm
parents: 42934
diff changeset
   697
  abstract types @{ML_type ctyp} and @{ML_type cterm} are part of the
3e427a12f0f3 more on Logic.all/mk_implies etc.;
wenzelm
parents: 42934
diff changeset
   698
  same inference kernel that is mainly responsible for @{ML_type thm}.
3e427a12f0f3 more on Logic.all/mk_implies etc.;
wenzelm
parents: 42934
diff changeset
   699
  Thus syntactic operations on @{ML_type ctyp} and @{ML_type cterm}
55837
154855d9a564 clarified names of antiquotations and markup;
wenzelm
parents: 55112
diff changeset
   700
  are located in the @{ML_structure Thm} module, even though theorems are
46253
3e427a12f0f3 more on Logic.all/mk_implies etc.;
wenzelm
parents: 42934
diff changeset
   701
  not yet involved at that stage.
20542
a54ca4e90874 more on theorems;
wenzelm
parents: 20537
diff changeset
   702
59621
291934bac95e Thm.cterm_of and Thm.ctyp_of operate on local context;
wenzelm
parents: 58728
diff changeset
   703
  \item @{ML Thm.ctyp_of}~@{text "ctxt \<tau>"} and @{ML
291934bac95e Thm.cterm_of and Thm.ctyp_of operate on local context;
wenzelm
parents: 58728
diff changeset
   704
  Thm.cterm_of}~@{text "ctxt t"} explicitly check types and terms,
29768
64a50ff3f308 more on object-level rules;
wenzelm
parents: 29761
diff changeset
   705
  respectively.  This also involves some basic normalizations, such
59621
291934bac95e Thm.cterm_of and Thm.ctyp_of operate on local context;
wenzelm
parents: 58728
diff changeset
   706
  expansion of type and term abbreviations from the underlying
291934bac95e Thm.cterm_of and Thm.ctyp_of operate on local context;
wenzelm
parents: 58728
diff changeset
   707
  theory context.
46253
3e427a12f0f3 more on Logic.all/mk_implies etc.;
wenzelm
parents: 42934
diff changeset
   708
  Full re-certification is relatively slow and should be avoided in
3e427a12f0f3 more on Logic.all/mk_implies etc.;
wenzelm
parents: 42934
diff changeset
   709
  tight reasoning loops.
20547
wenzelm
parents: 20543
diff changeset
   710
46497
89ccf66aa73d renamed Thm.capply to Thm.apply, and Thm.cabs to Thm.lambda in conformance with similar operations in structure Term and Logic;
wenzelm
parents: 46262
diff changeset
   711
  \item @{ML Thm.apply}, @{ML Thm.lambda}, @{ML Thm.all}, @{ML
46253
3e427a12f0f3 more on Logic.all/mk_implies etc.;
wenzelm
parents: 42934
diff changeset
   712
  Drule.mk_implies} etc.\ compose certified terms (or propositions)
3e427a12f0f3 more on Logic.all/mk_implies etc.;
wenzelm
parents: 42934
diff changeset
   713
  incrementally.  This is equivalent to @{ML Thm.cterm_of} after
46262
912b42e64fde tuned ML infixes;
wenzelm
parents: 46256
diff changeset
   714
  unchecked @{ML_op "$"}, @{ML lambda}, @{ML Logic.all}, @{ML
46253
3e427a12f0f3 more on Logic.all/mk_implies etc.;
wenzelm
parents: 42934
diff changeset
   715
  Logic.mk_implies} etc., but there can be a big difference in
3e427a12f0f3 more on Logic.all/mk_implies etc.;
wenzelm
parents: 42934
diff changeset
   716
  performance when large existing entities are composed by a few extra
3e427a12f0f3 more on Logic.all/mk_implies etc.;
wenzelm
parents: 42934
diff changeset
   717
  constructions on top.  There are separate operations to decompose
3e427a12f0f3 more on Logic.all/mk_implies etc.;
wenzelm
parents: 42934
diff changeset
   718
  certified terms and theorems to produce certified terms again.
20542
a54ca4e90874 more on theorems;
wenzelm
parents: 20537
diff changeset
   719
39864
wenzelm
parents: 39861
diff changeset
   720
  \item Type @{ML_type thm} represents proven propositions.  This is
wenzelm
parents: 39861
diff changeset
   721
  an abstract datatype that guarantees that its values have been
55837
154855d9a564 clarified names of antiquotations and markup;
wenzelm
parents: 55112
diff changeset
   722
  constructed by basic principles of the @{ML_structure Thm} module.
52788
da1fdbfebd39 type theory is purely value-oriented;
wenzelm
parents: 52630
diff changeset
   723
  Every @{ML_type thm} value refers its background theory,
da1fdbfebd39 type theory is purely value-oriented;
wenzelm
parents: 52630
diff changeset
   724
  cf.\ \secref{sec:context-theory}.
20542
a54ca4e90874 more on theorems;
wenzelm
parents: 20537
diff changeset
   725
42933
7860ffc5ec08 modernized and re-unified Thm.transfer;
wenzelm
parents: 42666
diff changeset
   726
  \item @{ML Thm.transfer}~@{text "thy thm"} transfers the given
7860ffc5ec08 modernized and re-unified Thm.transfer;
wenzelm
parents: 42666
diff changeset
   727
  theorem to a \emph{larger} theory, see also \secref{sec:context}.
7860ffc5ec08 modernized and re-unified Thm.transfer;
wenzelm
parents: 42666
diff changeset
   728
  This formal adjustment of the background context has no logical
7860ffc5ec08 modernized and re-unified Thm.transfer;
wenzelm
parents: 42666
diff changeset
   729
  significance, but is occasionally required for formal reasons, e.g.\
7860ffc5ec08 modernized and re-unified Thm.transfer;
wenzelm
parents: 42666
diff changeset
   730
  when theorems that are imported from more basic theories are used in
7860ffc5ec08 modernized and re-unified Thm.transfer;
wenzelm
parents: 42666
diff changeset
   731
  the current situation.
7860ffc5ec08 modernized and re-unified Thm.transfer;
wenzelm
parents: 42666
diff changeset
   732
20542
a54ca4e90874 more on theorems;
wenzelm
parents: 20537
diff changeset
   733
  \item @{ML Thm.assume}, @{ML Thm.forall_intr}, @{ML
a54ca4e90874 more on theorems;
wenzelm
parents: 20537
diff changeset
   734
  Thm.forall_elim}, @{ML Thm.implies_intr}, and @{ML Thm.implies_elim}
a54ca4e90874 more on theorems;
wenzelm
parents: 20537
diff changeset
   735
  correspond to the primitive inferences of \figref{fig:prim-rules}.
a54ca4e90874 more on theorems;
wenzelm
parents: 20537
diff changeset
   736
a54ca4e90874 more on theorems;
wenzelm
parents: 20537
diff changeset
   737
  \item @{ML Thm.generalize}~@{text "(\<^vec>\<alpha>, \<^vec>x)"}
a54ca4e90874 more on theorems;
wenzelm
parents: 20537
diff changeset
   738
  corresponds to the @{text "generalize"} rules of
20543
wenzelm
parents: 20542
diff changeset
   739
  \figref{fig:subst-rules}.  Here collections of type and term
wenzelm
parents: 20542
diff changeset
   740
  variables are generalized simultaneously, specified by the given
wenzelm
parents: 20542
diff changeset
   741
  basic names.
20521
189811b39869 more on theorems;
wenzelm
parents: 20520
diff changeset
   742
53015
a1119cf551e8 standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
wenzelm
parents: 52788
diff changeset
   743
  \item @{ML Thm.instantiate}~@{text "(\<^vec>\<alpha>\<^sub>s,
a1119cf551e8 standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
wenzelm
parents: 52788
diff changeset
   744
  \<^vec>x\<^sub>\<tau>)"} corresponds to the @{text "instantiate"} rules
20542
a54ca4e90874 more on theorems;
wenzelm
parents: 20537
diff changeset
   745
  of \figref{fig:subst-rules}.  Type variables are substituted before
53015
a1119cf551e8 standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
wenzelm
parents: 52788
diff changeset
   746
  term variables.  Note that the types in @{text "\<^vec>x\<^sub>\<tau>"}
20542
a54ca4e90874 more on theorems;
wenzelm
parents: 20537
diff changeset
   747
  refer to the instantiated versions.
a54ca4e90874 more on theorems;
wenzelm
parents: 20537
diff changeset
   748
42401
9bfaf6819291 updated some theory primitives, which now depend on auxiliary context;
wenzelm
parents: 40255
diff changeset
   749
  \item @{ML Thm.add_axiom}~@{text "ctxt (name, A)"} declares an
35927
343d5b0df29a updated Thm.add_axiom/add_def;
wenzelm
parents: 34929
diff changeset
   750
  arbitrary proposition as axiom, and retrieves it as a theorem from
343d5b0df29a updated Thm.add_axiom/add_def;
wenzelm
parents: 34929
diff changeset
   751
  the resulting theory, cf.\ @{text "axiom"} in
343d5b0df29a updated Thm.add_axiom/add_def;
wenzelm
parents: 34929
diff changeset
   752
  \figref{fig:prim-rules}.  Note that the low-level representation in
343d5b0df29a updated Thm.add_axiom/add_def;
wenzelm
parents: 34929
diff changeset
   753
  the axiom table may differ slightly from the returned theorem.
20542
a54ca4e90874 more on theorems;
wenzelm
parents: 20537
diff changeset
   754
30288
a32700e45ab3 Thm.add_oracle interface: replaced old bstring by binding;
wenzelm
parents: 30272
diff changeset
   755
  \item @{ML Thm.add_oracle}~@{text "(binding, oracle)"} produces a named
28290
4cc2b6046258 simplified oracle interface;
wenzelm
parents: 28110
diff changeset
   756
  oracle rule, essentially generating arbitrary axioms on the fly,
4cc2b6046258 simplified oracle interface;
wenzelm
parents: 28110
diff changeset
   757
  cf.\ @{text "axiom"} in \figref{fig:prim-rules}.
20521
189811b39869 more on theorems;
wenzelm
parents: 20520
diff changeset
   758
42401
9bfaf6819291 updated some theory primitives, which now depend on auxiliary context;
wenzelm
parents: 40255
diff changeset
   759
  \item @{ML Thm.add_def}~@{text "ctxt unchecked overloaded (name, c
35927
343d5b0df29a updated Thm.add_axiom/add_def;
wenzelm
parents: 34929
diff changeset
   760
  \<^vec>x \<equiv> t)"} states a definitional axiom for an existing constant
343d5b0df29a updated Thm.add_axiom/add_def;
wenzelm
parents: 34929
diff changeset
   761
  @{text "c"}.  Dependencies are recorded via @{ML Theory.add_deps},
343d5b0df29a updated Thm.add_axiom/add_def;
wenzelm
parents: 34929
diff changeset
   762
  unless the @{text "unchecked"} option is set.  Note that the
343d5b0df29a updated Thm.add_axiom/add_def;
wenzelm
parents: 34929
diff changeset
   763
  low-level representation in the axiom table may differ slightly from
343d5b0df29a updated Thm.add_axiom/add_def;
wenzelm
parents: 34929
diff changeset
   764
  the returned theorem.
20542
a54ca4e90874 more on theorems;
wenzelm
parents: 20537
diff changeset
   765
53015
a1119cf551e8 standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
wenzelm
parents: 52788
diff changeset
   766
  \item @{ML Theory.add_deps}~@{text "ctxt name c\<^sub>\<tau> \<^vec>d\<^sub>\<sigma>"}
42401
9bfaf6819291 updated some theory primitives, which now depend on auxiliary context;
wenzelm
parents: 40255
diff changeset
   767
  declares dependencies of a named specification for constant @{text
53015
a1119cf551e8 standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
wenzelm
parents: 52788
diff changeset
   768
  "c\<^sub>\<tau>"}, relative to existing specifications for constants @{text
61255
15865e0c5598 eliminated separate type Theory.dep: use typeargs uniformly for consts/types;
wenzelm
parents: 61246
diff changeset
   769
  "\<^vec>d\<^sub>\<sigma>"}.  This also works for type constructors.
20542
a54ca4e90874 more on theorems;
wenzelm
parents: 20537
diff changeset
   770
20521
189811b39869 more on theorems;
wenzelm
parents: 20520
diff changeset
   771
  \end{description}
58618
782f0b662cae more cartouches;
wenzelm
parents: 58555
diff changeset
   772
\<close>
20521
189811b39869 more on theorems;
wenzelm
parents: 20520
diff changeset
   773
189811b39869 more on theorems;
wenzelm
parents: 20520
diff changeset
   774
58618
782f0b662cae more cartouches;
wenzelm
parents: 58555
diff changeset
   775
text %mlantiq \<open>
39832
1080dee73a53 various concrete ML antiquotations;
wenzelm
parents: 39821
diff changeset
   776
  \begin{matharray}{rcl}
1080dee73a53 various concrete ML antiquotations;
wenzelm
parents: 39821
diff changeset
   777
  @{ML_antiquotation_def "ctyp"} & : & @{text ML_antiquotation} \\
1080dee73a53 various concrete ML antiquotations;
wenzelm
parents: 39821
diff changeset
   778
  @{ML_antiquotation_def "cterm"} & : & @{text ML_antiquotation} \\
1080dee73a53 various concrete ML antiquotations;
wenzelm
parents: 39821
diff changeset
   779
  @{ML_antiquotation_def "cprop"} & : & @{text ML_antiquotation} \\
1080dee73a53 various concrete ML antiquotations;
wenzelm
parents: 39821
diff changeset
   780
  @{ML_antiquotation_def "thm"} & : & @{text ML_antiquotation} \\
1080dee73a53 various concrete ML antiquotations;
wenzelm
parents: 39821
diff changeset
   781
  @{ML_antiquotation_def "thms"} & : & @{text ML_antiquotation} \\
1080dee73a53 various concrete ML antiquotations;
wenzelm
parents: 39821
diff changeset
   782
  @{ML_antiquotation_def "lemma"} & : & @{text ML_antiquotation} \\
1080dee73a53 various concrete ML antiquotations;
wenzelm
parents: 39821
diff changeset
   783
  \end{matharray}
1080dee73a53 various concrete ML antiquotations;
wenzelm
parents: 39821
diff changeset
   784
55112
b1a5d603fd12 prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents: 55029
diff changeset
   785
  @{rail \<open>
42510
b9c106763325 use @{rail} antiquotation (with some nested markup);
wenzelm
parents: 42401
diff changeset
   786
  @@{ML_antiquotation ctyp} typ
39832
1080dee73a53 various concrete ML antiquotations;
wenzelm
parents: 39821
diff changeset
   787
  ;
42510
b9c106763325 use @{rail} antiquotation (with some nested markup);
wenzelm
parents: 42401
diff changeset
   788
  @@{ML_antiquotation cterm} term
39832
1080dee73a53 various concrete ML antiquotations;
wenzelm
parents: 39821
diff changeset
   789
  ;
42510
b9c106763325 use @{rail} antiquotation (with some nested markup);
wenzelm
parents: 42401
diff changeset
   790
  @@{ML_antiquotation cprop} prop
39832
1080dee73a53 various concrete ML antiquotations;
wenzelm
parents: 39821
diff changeset
   791
  ;
42510
b9c106763325 use @{rail} antiquotation (with some nested markup);
wenzelm
parents: 42401
diff changeset
   792
  @@{ML_antiquotation thm} thmref
b9c106763325 use @{rail} antiquotation (with some nested markup);
wenzelm
parents: 42401
diff changeset
   793
  ;
b9c106763325 use @{rail} antiquotation (with some nested markup);
wenzelm
parents: 42401
diff changeset
   794
  @@{ML_antiquotation thms} thmrefs
39832
1080dee73a53 various concrete ML antiquotations;
wenzelm
parents: 39821
diff changeset
   795
  ;
55029
61a6bf7d4b02 clarified @{rail} syntax: prefer explicit \<newline> symbol;
wenzelm
parents: 54883
diff changeset
   796
  @@{ML_antiquotation lemma} ('(' @'open' ')')? ((prop +) + @'and') \<newline>
42517
b68e1c27709a simplified keyword markup (without formal checking);
wenzelm
parents: 42510
diff changeset
   797
    @'by' method method?
55112
b1a5d603fd12 prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents: 55029
diff changeset
   798
  \<close>}
39832
1080dee73a53 various concrete ML antiquotations;
wenzelm
parents: 39821
diff changeset
   799
1080dee73a53 various concrete ML antiquotations;
wenzelm
parents: 39821
diff changeset
   800
  \begin{description}
1080dee73a53 various concrete ML antiquotations;
wenzelm
parents: 39821
diff changeset
   801
1080dee73a53 various concrete ML antiquotations;
wenzelm
parents: 39821
diff changeset
   802
  \item @{text "@{ctyp \<tau>}"} produces a certified type wrt.\ the
1080dee73a53 various concrete ML antiquotations;
wenzelm
parents: 39821
diff changeset
   803
  current background theory --- as abstract value of type @{ML_type
1080dee73a53 various concrete ML antiquotations;
wenzelm
parents: 39821
diff changeset
   804
  ctyp}.
1080dee73a53 various concrete ML antiquotations;
wenzelm
parents: 39821
diff changeset
   805
1080dee73a53 various concrete ML antiquotations;
wenzelm
parents: 39821
diff changeset
   806
  \item @{text "@{cterm t}"} and @{text "@{cprop \<phi>}"} produce a
1080dee73a53 various concrete ML antiquotations;
wenzelm
parents: 39821
diff changeset
   807
  certified term wrt.\ the current background theory --- as abstract
1080dee73a53 various concrete ML antiquotations;
wenzelm
parents: 39821
diff changeset
   808
  value of type @{ML_type cterm}.
1080dee73a53 various concrete ML antiquotations;
wenzelm
parents: 39821
diff changeset
   809
1080dee73a53 various concrete ML antiquotations;
wenzelm
parents: 39821
diff changeset
   810
  \item @{text "@{thm a}"} produces a singleton fact --- as abstract
1080dee73a53 various concrete ML antiquotations;
wenzelm
parents: 39821
diff changeset
   811
  value of type @{ML_type thm}.
1080dee73a53 various concrete ML antiquotations;
wenzelm
parents: 39821
diff changeset
   812
1080dee73a53 various concrete ML antiquotations;
wenzelm
parents: 39821
diff changeset
   813
  \item @{text "@{thms a}"} produces a general fact --- as abstract
1080dee73a53 various concrete ML antiquotations;
wenzelm
parents: 39821
diff changeset
   814
  value of type @{ML_type "thm list"}.
1080dee73a53 various concrete ML antiquotations;
wenzelm
parents: 39821
diff changeset
   815
1080dee73a53 various concrete ML antiquotations;
wenzelm
parents: 39821
diff changeset
   816
  \item @{text "@{lemma \<phi> by meth}"} produces a fact that is proven on
1080dee73a53 various concrete ML antiquotations;
wenzelm
parents: 39821
diff changeset
   817
  the spot according to the minimal proof, which imitates a terminal
1080dee73a53 various concrete ML antiquotations;
wenzelm
parents: 39821
diff changeset
   818
  Isar proof.  The result is an abstract value of type @{ML_type thm}
1080dee73a53 various concrete ML antiquotations;
wenzelm
parents: 39821
diff changeset
   819
  or @{ML_type "thm list"}, depending on the number of propositions
1080dee73a53 various concrete ML antiquotations;
wenzelm
parents: 39821
diff changeset
   820
  given here.
1080dee73a53 various concrete ML antiquotations;
wenzelm
parents: 39821
diff changeset
   821
1080dee73a53 various concrete ML antiquotations;
wenzelm
parents: 39821
diff changeset
   822
  The internal derivation object lacks a proper theorem name, but it
1080dee73a53 various concrete ML antiquotations;
wenzelm
parents: 39821
diff changeset
   823
  is formally closed, unless the @{text "(open)"} option is specified
1080dee73a53 various concrete ML antiquotations;
wenzelm
parents: 39821
diff changeset
   824
  (this may impact performance of applications with proof terms).
1080dee73a53 various concrete ML antiquotations;
wenzelm
parents: 39821
diff changeset
   825
1080dee73a53 various concrete ML antiquotations;
wenzelm
parents: 39821
diff changeset
   826
  Since ML antiquotations are always evaluated at compile-time, there
1080dee73a53 various concrete ML antiquotations;
wenzelm
parents: 39821
diff changeset
   827
  is no run-time overhead even for non-trivial proofs.  Nonetheless,
1080dee73a53 various concrete ML antiquotations;
wenzelm
parents: 39821
diff changeset
   828
  the justification is syntactically limited to a single @{command
1080dee73a53 various concrete ML antiquotations;
wenzelm
parents: 39821
diff changeset
   829
  "by"} step.  More complex Isar proofs should be done in regular
1080dee73a53 various concrete ML antiquotations;
wenzelm
parents: 39821
diff changeset
   830
  theory source, before compiling the corresponding ML text that uses
1080dee73a53 various concrete ML antiquotations;
wenzelm
parents: 39821
diff changeset
   831
  the result.
1080dee73a53 various concrete ML antiquotations;
wenzelm
parents: 39821
diff changeset
   832
1080dee73a53 various concrete ML antiquotations;
wenzelm
parents: 39821
diff changeset
   833
  \end{description}
1080dee73a53 various concrete ML antiquotations;
wenzelm
parents: 39821
diff changeset
   834
58618
782f0b662cae more cartouches;
wenzelm
parents: 58555
diff changeset
   835
\<close>
39832
1080dee73a53 various concrete ML antiquotations;
wenzelm
parents: 39821
diff changeset
   836
1080dee73a53 various concrete ML antiquotations;
wenzelm
parents: 39821
diff changeset
   837
58618
782f0b662cae more cartouches;
wenzelm
parents: 58555
diff changeset
   838
subsection \<open>Auxiliary connectives \label{sec:logic-aux}\<close>
20521
189811b39869 more on theorems;
wenzelm
parents: 20520
diff changeset
   839
58618
782f0b662cae more cartouches;
wenzelm
parents: 58555
diff changeset
   840
text \<open>Theory @{text "Pure"} provides a few auxiliary connectives
46254
wenzelm
parents: 46253
diff changeset
   841
  that are defined on top of the primitive ones, see
wenzelm
parents: 46253
diff changeset
   842
  \figref{fig:pure-aux}.  These special constants are useful in
wenzelm
parents: 46253
diff changeset
   843
  certain internal encodings, and are normally not directly exposed to
wenzelm
parents: 46253
diff changeset
   844
  the user.
20501
de0b523b0d62 more rules;
wenzelm
parents: 20498
diff changeset
   845
de0b523b0d62 more rules;
wenzelm
parents: 20498
diff changeset
   846
  \begin{figure}[htb]
de0b523b0d62 more rules;
wenzelm
parents: 20498
diff changeset
   847
  \begin{center}
20498
825a8d2335ce more rules;
wenzelm
parents: 20494
diff changeset
   848
  \begin{tabular}{ll}
34929
9700a87f1cc2 misc tuning and clarification;
wenzelm
parents: 34921
diff changeset
   849
  @{text "conjunction :: prop \<Rightarrow> prop \<Rightarrow> prop"} & (infix @{text "&&&"}) \\
9700a87f1cc2 misc tuning and clarification;
wenzelm
parents: 34921
diff changeset
   850
  @{text "\<turnstile> A &&& B \<equiv> (\<And>C. (A \<Longrightarrow> B \<Longrightarrow> C) \<Longrightarrow> C)"} \\[1ex]
20543
wenzelm
parents: 20542
diff changeset
   851
  @{text "prop :: prop \<Rightarrow> prop"} & (prefix @{text "#"}, suppressed) \\
20521
189811b39869 more on theorems;
wenzelm
parents: 20520
diff changeset
   852
  @{text "#A \<equiv> A"} \\[1ex]
189811b39869 more on theorems;
wenzelm
parents: 20520
diff changeset
   853
  @{text "term :: \<alpha> \<Rightarrow> prop"} & (prefix @{text "TERM"}) \\
189811b39869 more on theorems;
wenzelm
parents: 20520
diff changeset
   854
  @{text "term x \<equiv> (\<And>A. A \<Longrightarrow> A)"} \\[1ex]
56243
2e10a36b8d46 more qualified names;
wenzelm
parents: 55837
diff changeset
   855
  @{text "type :: \<alpha> itself"} & (prefix @{text "TYPE"}) \\
20521
189811b39869 more on theorems;
wenzelm
parents: 20520
diff changeset
   856
  @{text "(unspecified)"} \\
20498
825a8d2335ce more rules;
wenzelm
parents: 20494
diff changeset
   857
  \end{tabular}
20521
189811b39869 more on theorems;
wenzelm
parents: 20520
diff changeset
   858
  \caption{Definitions of auxiliary connectives}\label{fig:pure-aux}
20501
de0b523b0d62 more rules;
wenzelm
parents: 20498
diff changeset
   859
  \end{center}
de0b523b0d62 more rules;
wenzelm
parents: 20498
diff changeset
   860
  \end{figure}
de0b523b0d62 more rules;
wenzelm
parents: 20498
diff changeset
   861
34929
9700a87f1cc2 misc tuning and clarification;
wenzelm
parents: 34921
diff changeset
   862
  The introduction @{text "A \<Longrightarrow> B \<Longrightarrow> A &&& B"}, and eliminations
9700a87f1cc2 misc tuning and clarification;
wenzelm
parents: 34921
diff changeset
   863
  (projections) @{text "A &&& B \<Longrightarrow> A"} and @{text "A &&& B \<Longrightarrow> B"} are
9700a87f1cc2 misc tuning and clarification;
wenzelm
parents: 34921
diff changeset
   864
  available as derived rules.  Conjunction allows to treat
9700a87f1cc2 misc tuning and clarification;
wenzelm
parents: 34921
diff changeset
   865
  simultaneous assumptions and conclusions uniformly, e.g.\ consider
9700a87f1cc2 misc tuning and clarification;
wenzelm
parents: 34921
diff changeset
   866
  @{text "A \<Longrightarrow> B \<Longrightarrow> C &&& D"}.  In particular, the goal mechanism
9700a87f1cc2 misc tuning and clarification;
wenzelm
parents: 34921
diff changeset
   867
  represents multiple claims as explicit conjunction internally, but
9700a87f1cc2 misc tuning and clarification;
wenzelm
parents: 34921
diff changeset
   868
  this is refined (via backwards introduction) into separate sub-goals
9700a87f1cc2 misc tuning and clarification;
wenzelm
parents: 34921
diff changeset
   869
  before the user commences the proof; the final result is projected
9700a87f1cc2 misc tuning and clarification;
wenzelm
parents: 34921
diff changeset
   870
  into a list of theorems using eliminations (cf.\
20537
b6b49903db7e *** empty log message ***
wenzelm
parents: 20521
diff changeset
   871
  \secref{sec:tactical-goals}).
20498
825a8d2335ce more rules;
wenzelm
parents: 20494
diff changeset
   872
20537
b6b49903db7e *** empty log message ***
wenzelm
parents: 20521
diff changeset
   873
  The @{text "prop"} marker (@{text "#"}) makes arbitrarily complex
b6b49903db7e *** empty log message ***
wenzelm
parents: 20521
diff changeset
   874
  propositions appear as atomic, without changing the meaning: @{text
b6b49903db7e *** empty log message ***
wenzelm
parents: 20521
diff changeset
   875
  "\<Gamma> \<turnstile> A"} and @{text "\<Gamma> \<turnstile> #A"} are interchangeable.  See
b6b49903db7e *** empty log message ***
wenzelm
parents: 20521
diff changeset
   876
  \secref{sec:tactical-goals} for specific operations.
20521
189811b39869 more on theorems;
wenzelm
parents: 20520
diff changeset
   877
20543
wenzelm
parents: 20542
diff changeset
   878
  The @{text "term"} marker turns any well-typed term into a derivable
wenzelm
parents: 20542
diff changeset
   879
  proposition: @{text "\<turnstile> TERM t"} holds unconditionally.  Although
wenzelm
parents: 20542
diff changeset
   880
  this is logically vacuous, it allows to treat terms and proofs
wenzelm
parents: 20542
diff changeset
   881
  uniformly, similar to a type-theoretic framework.
20498
825a8d2335ce more rules;
wenzelm
parents: 20494
diff changeset
   882
20537
b6b49903db7e *** empty log message ***
wenzelm
parents: 20521
diff changeset
   883
  The @{text "TYPE"} constructor is the canonical representative of
b6b49903db7e *** empty log message ***
wenzelm
parents: 20521
diff changeset
   884
  the unspecified type @{text "\<alpha> itself"}; it essentially injects the
b6b49903db7e *** empty log message ***
wenzelm
parents: 20521
diff changeset
   885
  language of types into that of terms.  There is specific notation
53071
wenzelm
parents: 53015
diff changeset
   886
  @{text "TYPE(\<tau>)"} for @{text "TYPE\<^bsub>\<tau> itself\<^esub>"}.
34929
9700a87f1cc2 misc tuning and clarification;
wenzelm
parents: 34921
diff changeset
   887
  Although being devoid of any particular meaning, the term @{text
20537
b6b49903db7e *** empty log message ***
wenzelm
parents: 20521
diff changeset
   888
  "TYPE(\<tau>)"} accounts for the type @{text "\<tau>"} within the term
b6b49903db7e *** empty log message ***
wenzelm
parents: 20521
diff changeset
   889
  language.  In particular, @{text "TYPE(\<alpha>)"} may be used as formal
b6b49903db7e *** empty log message ***
wenzelm
parents: 20521
diff changeset
   890
  argument in primitive definitions, in order to circumvent hidden
b6b49903db7e *** empty log message ***
wenzelm
parents: 20521
diff changeset
   891
  polymorphism (cf.\ \secref{sec:terms}).  For example, @{text "c
b6b49903db7e *** empty log message ***
wenzelm
parents: 20521
diff changeset
   892
  TYPE(\<alpha>) \<equiv> A[\<alpha>]"} defines @{text "c :: \<alpha> itself \<Rightarrow> prop"} in terms of
b6b49903db7e *** empty log message ***
wenzelm
parents: 20521
diff changeset
   893
  a proposition @{text "A"} that depends on an additional type
b6b49903db7e *** empty log message ***
wenzelm
parents: 20521
diff changeset
   894
  argument, which is essentially a predicate on types.
58618
782f0b662cae more cartouches;
wenzelm
parents: 58555
diff changeset
   895
\<close>
20501
de0b523b0d62 more rules;
wenzelm
parents: 20498
diff changeset
   896
58618
782f0b662cae more cartouches;
wenzelm
parents: 58555
diff changeset
   897
text %mlref \<open>
20521
189811b39869 more on theorems;
wenzelm
parents: 20520
diff changeset
   898
  \begin{mldecls}
189811b39869 more on theorems;
wenzelm
parents: 20520
diff changeset
   899
  @{index_ML Conjunction.intr: "thm -> thm -> thm"} \\
189811b39869 more on theorems;
wenzelm
parents: 20520
diff changeset
   900
  @{index_ML Conjunction.elim: "thm -> thm * thm"} \\
189811b39869 more on theorems;
wenzelm
parents: 20520
diff changeset
   901
  @{index_ML Drule.mk_term: "cterm -> thm"} \\
189811b39869 more on theorems;
wenzelm
parents: 20520
diff changeset
   902
  @{index_ML Drule.dest_term: "thm -> cterm"} \\
189811b39869 more on theorems;
wenzelm
parents: 20520
diff changeset
   903
  @{index_ML Logic.mk_type: "typ -> term"} \\
189811b39869 more on theorems;
wenzelm
parents: 20520
diff changeset
   904
  @{index_ML Logic.dest_type: "term -> typ"} \\
189811b39869 more on theorems;
wenzelm
parents: 20520
diff changeset
   905
  \end{mldecls}
189811b39869 more on theorems;
wenzelm
parents: 20520
diff changeset
   906
189811b39869 more on theorems;
wenzelm
parents: 20520
diff changeset
   907
  \begin{description}
189811b39869 more on theorems;
wenzelm
parents: 20520
diff changeset
   908
34929
9700a87f1cc2 misc tuning and clarification;
wenzelm
parents: 34921
diff changeset
   909
  \item @{ML Conjunction.intr} derives @{text "A &&& B"} from @{text
20542
a54ca4e90874 more on theorems;
wenzelm
parents: 20537
diff changeset
   910
  "A"} and @{text "B"}.
a54ca4e90874 more on theorems;
wenzelm
parents: 20537
diff changeset
   911
20543
wenzelm
parents: 20542
diff changeset
   912
  \item @{ML Conjunction.elim} derives @{text "A"} and @{text "B"}
34929
9700a87f1cc2 misc tuning and clarification;
wenzelm
parents: 34921
diff changeset
   913
  from @{text "A &&& B"}.
20542
a54ca4e90874 more on theorems;
wenzelm
parents: 20537
diff changeset
   914
20543
wenzelm
parents: 20542
diff changeset
   915
  \item @{ML Drule.mk_term} derives @{text "TERM t"}.
20542
a54ca4e90874 more on theorems;
wenzelm
parents: 20537
diff changeset
   916
20543
wenzelm
parents: 20542
diff changeset
   917
  \item @{ML Drule.dest_term} recovers term @{text "t"} from @{text
wenzelm
parents: 20542
diff changeset
   918
  "TERM t"}.
20542
a54ca4e90874 more on theorems;
wenzelm
parents: 20537
diff changeset
   919
a54ca4e90874 more on theorems;
wenzelm
parents: 20537
diff changeset
   920
  \item @{ML Logic.mk_type}~@{text "\<tau>"} produces the term @{text
a54ca4e90874 more on theorems;
wenzelm
parents: 20537
diff changeset
   921
  "TYPE(\<tau>)"}.
a54ca4e90874 more on theorems;
wenzelm
parents: 20537
diff changeset
   922
a54ca4e90874 more on theorems;
wenzelm
parents: 20537
diff changeset
   923
  \item @{ML Logic.dest_type}~@{text "TYPE(\<tau>)"} recovers the type
a54ca4e90874 more on theorems;
wenzelm
parents: 20537
diff changeset
   924
  @{text "\<tau>"}.
20521
189811b39869 more on theorems;
wenzelm
parents: 20520
diff changeset
   925
189811b39869 more on theorems;
wenzelm
parents: 20520
diff changeset
   926
  \end{description}
58618
782f0b662cae more cartouches;
wenzelm
parents: 58555
diff changeset
   927
\<close>
18537
2681f9e34390 "The Isabelle/Isar Implementation" manual;
wenzelm
parents:
diff changeset
   928
20480
4e0522d38968 more on types and type classes;
wenzelm
parents: 20477
diff changeset
   929
58618
782f0b662cae more cartouches;
wenzelm
parents: 58555
diff changeset
   930
subsection \<open>Sort hypotheses\<close>
52406
1e57c3c4e05c updated documentation of sort hypotheses;
wenzelm
parents: 50126
diff changeset
   931
58618
782f0b662cae more cartouches;
wenzelm
parents: 58555
diff changeset
   932
text \<open>Type variables are decorated with sorts, as explained in
52406
1e57c3c4e05c updated documentation of sort hypotheses;
wenzelm
parents: 50126
diff changeset
   933
  \secref{sec:types}.  This constrains type instantiation to certain
1e57c3c4e05c updated documentation of sort hypotheses;
wenzelm
parents: 50126
diff changeset
   934
  ranges of types: variable @{text "\<alpha>\<^sub>s"} may only be assigned to types
1e57c3c4e05c updated documentation of sort hypotheses;
wenzelm
parents: 50126
diff changeset
   935
  @{text "\<tau>"} that belong to sort @{text "s"}.  Within the logic, sort
1e57c3c4e05c updated documentation of sort hypotheses;
wenzelm
parents: 50126
diff changeset
   936
  constraints act like implicit preconditions on the result @{text
1e57c3c4e05c updated documentation of sort hypotheses;
wenzelm
parents: 50126
diff changeset
   937
  "\<lparr>\<alpha>\<^sub>1 : s\<^sub>1\<rparr>, \<dots>, \<lparr>\<alpha>\<^sub>n : s\<^sub>n\<rparr>, \<Gamma> \<turnstile> \<phi>"} where the type variables @{text
1e57c3c4e05c updated documentation of sort hypotheses;
wenzelm
parents: 50126
diff changeset
   938
  "\<alpha>\<^sub>1, \<dots>, \<alpha>\<^sub>n"} cover the propositions @{text "\<Gamma>"}, @{text "\<phi>"}, as
1e57c3c4e05c updated documentation of sort hypotheses;
wenzelm
parents: 50126
diff changeset
   939
  well as the proof of @{text "\<Gamma> \<turnstile> \<phi>"}.
1e57c3c4e05c updated documentation of sort hypotheses;
wenzelm
parents: 50126
diff changeset
   940
1e57c3c4e05c updated documentation of sort hypotheses;
wenzelm
parents: 50126
diff changeset
   941
  These \emph{sort hypothesis} of a theorem are passed monotonically
1e57c3c4e05c updated documentation of sort hypotheses;
wenzelm
parents: 50126
diff changeset
   942
  through further derivations.  They are redundant, as long as the
1e57c3c4e05c updated documentation of sort hypotheses;
wenzelm
parents: 50126
diff changeset
   943
  statement of a theorem still contains the type variables that are
1e57c3c4e05c updated documentation of sort hypotheses;
wenzelm
parents: 50126
diff changeset
   944
  accounted here.  The logical significance of sort hypotheses is
1e57c3c4e05c updated documentation of sort hypotheses;
wenzelm
parents: 50126
diff changeset
   945
  limited to the boundary case where type variables disappear from the
1e57c3c4e05c updated documentation of sort hypotheses;
wenzelm
parents: 50126
diff changeset
   946
  proposition, e.g.\ @{text "\<lparr>\<alpha>\<^sub>s : s\<rparr> \<turnstile> \<phi>"}.  Since such dangling type
1e57c3c4e05c updated documentation of sort hypotheses;
wenzelm
parents: 50126
diff changeset
   947
  variables can be renamed arbitrarily without changing the
1e57c3c4e05c updated documentation of sort hypotheses;
wenzelm
parents: 50126
diff changeset
   948
  proposition @{text "\<phi>"}, the inference kernel maintains sort
1e57c3c4e05c updated documentation of sort hypotheses;
wenzelm
parents: 50126
diff changeset
   949
  hypotheses in anonymous form @{text "s \<turnstile> \<phi>"}.
1e57c3c4e05c updated documentation of sort hypotheses;
wenzelm
parents: 50126
diff changeset
   950
1e57c3c4e05c updated documentation of sort hypotheses;
wenzelm
parents: 50126
diff changeset
   951
  In most practical situations, such extra sort hypotheses may be
1e57c3c4e05c updated documentation of sort hypotheses;
wenzelm
parents: 50126
diff changeset
   952
  stripped in a final bookkeeping step, e.g.\ at the end of a proof:
1e57c3c4e05c updated documentation of sort hypotheses;
wenzelm
parents: 50126
diff changeset
   953
  they are typically left over from intermediate reasoning with type
1e57c3c4e05c updated documentation of sort hypotheses;
wenzelm
parents: 50126
diff changeset
   954
  classes that can be satisfied by some concrete type @{text "\<tau>"} of
1e57c3c4e05c updated documentation of sort hypotheses;
wenzelm
parents: 50126
diff changeset
   955
  sort @{text "s"} to replace the hypothetical type variable @{text
58618
782f0b662cae more cartouches;
wenzelm
parents: 58555
diff changeset
   956
  "\<alpha>\<^sub>s"}.\<close>
52406
1e57c3c4e05c updated documentation of sort hypotheses;
wenzelm
parents: 50126
diff changeset
   957
58618
782f0b662cae more cartouches;
wenzelm
parents: 58555
diff changeset
   958
text %mlref \<open>
52406
1e57c3c4e05c updated documentation of sort hypotheses;
wenzelm
parents: 50126
diff changeset
   959
  \begin{mldecls}
1e57c3c4e05c updated documentation of sort hypotheses;
wenzelm
parents: 50126
diff changeset
   960
  @{index_ML Thm.extra_shyps: "thm -> sort list"} \\
1e57c3c4e05c updated documentation of sort hypotheses;
wenzelm
parents: 50126
diff changeset
   961
  @{index_ML Thm.strip_shyps: "thm -> thm"} \\
1e57c3c4e05c updated documentation of sort hypotheses;
wenzelm
parents: 50126
diff changeset
   962
  \end{mldecls}
1e57c3c4e05c updated documentation of sort hypotheses;
wenzelm
parents: 50126
diff changeset
   963
1e57c3c4e05c updated documentation of sort hypotheses;
wenzelm
parents: 50126
diff changeset
   964
  \begin{description}
1e57c3c4e05c updated documentation of sort hypotheses;
wenzelm
parents: 50126
diff changeset
   965
1e57c3c4e05c updated documentation of sort hypotheses;
wenzelm
parents: 50126
diff changeset
   966
  \item @{ML Thm.extra_shyps}~@{text "thm"} determines the extraneous
1e57c3c4e05c updated documentation of sort hypotheses;
wenzelm
parents: 50126
diff changeset
   967
  sort hypotheses of the given theorem, i.e.\ the sorts that are not
1e57c3c4e05c updated documentation of sort hypotheses;
wenzelm
parents: 50126
diff changeset
   968
  present within type variables of the statement.
1e57c3c4e05c updated documentation of sort hypotheses;
wenzelm
parents: 50126
diff changeset
   969
1e57c3c4e05c updated documentation of sort hypotheses;
wenzelm
parents: 50126
diff changeset
   970
  \item @{ML Thm.strip_shyps}~@{text "thm"} removes any extraneous
1e57c3c4e05c updated documentation of sort hypotheses;
wenzelm
parents: 50126
diff changeset
   971
  sort hypotheses that can be witnessed from the type signature.
1e57c3c4e05c updated documentation of sort hypotheses;
wenzelm
parents: 50126
diff changeset
   972
1e57c3c4e05c updated documentation of sort hypotheses;
wenzelm
parents: 50126
diff changeset
   973
  \end{description}
58618
782f0b662cae more cartouches;
wenzelm
parents: 58555
diff changeset
   974
\<close>
52406
1e57c3c4e05c updated documentation of sort hypotheses;
wenzelm
parents: 50126
diff changeset
   975
58618
782f0b662cae more cartouches;
wenzelm
parents: 58555
diff changeset
   976
text %mlex \<open>The following artificial example demonstrates the
52406
1e57c3c4e05c updated documentation of sort hypotheses;
wenzelm
parents: 50126
diff changeset
   977
  derivation of @{prop False} with a pending sort hypothesis involving
58618
782f0b662cae more cartouches;
wenzelm
parents: 58555
diff changeset
   978
  a logically empty sort.\<close>
52406
1e57c3c4e05c updated documentation of sort hypotheses;
wenzelm
parents: 50126
diff changeset
   979
1e57c3c4e05c updated documentation of sort hypotheses;
wenzelm
parents: 50126
diff changeset
   980
class empty =
1e57c3c4e05c updated documentation of sort hypotheses;
wenzelm
parents: 50126
diff changeset
   981
  assumes bad: "\<And>(x::'a) y. x \<noteq> y"
1e57c3c4e05c updated documentation of sort hypotheses;
wenzelm
parents: 50126
diff changeset
   982
1e57c3c4e05c updated documentation of sort hypotheses;
wenzelm
parents: 50126
diff changeset
   983
theorem (in empty) false: False
1e57c3c4e05c updated documentation of sort hypotheses;
wenzelm
parents: 50126
diff changeset
   984
  using bad by blast
1e57c3c4e05c updated documentation of sort hypotheses;
wenzelm
parents: 50126
diff changeset
   985
59902
6afbe5a99139 misc tuning -- keep name space more clean;
wenzelm
parents: 59621
diff changeset
   986
ML_val \<open>@{assert} (Thm.extra_shyps @{thm false} = [@{sort empty}])\<close>
52406
1e57c3c4e05c updated documentation of sort hypotheses;
wenzelm
parents: 50126
diff changeset
   987
58618
782f0b662cae more cartouches;
wenzelm
parents: 58555
diff changeset
   988
text \<open>Thanks to the inference kernel managing sort hypothesis
52406
1e57c3c4e05c updated documentation of sort hypotheses;
wenzelm
parents: 50126
diff changeset
   989
  according to their logical significance, this example is merely an
1e57c3c4e05c updated documentation of sort hypotheses;
wenzelm
parents: 50126
diff changeset
   990
  instance of \emph{ex falso quodlibet consequitur} --- not a collapse
58618
782f0b662cae more cartouches;
wenzelm
parents: 58555
diff changeset
   991
  of the logical framework!\<close>
52406
1e57c3c4e05c updated documentation of sort hypotheses;
wenzelm
parents: 50126
diff changeset
   992
1e57c3c4e05c updated documentation of sort hypotheses;
wenzelm
parents: 50126
diff changeset
   993
58618
782f0b662cae more cartouches;
wenzelm
parents: 58555
diff changeset
   994
section \<open>Object-level rules \label{sec:obj-rules}\<close>
18537
2681f9e34390 "The Isabelle/Isar Implementation" manual;
wenzelm
parents:
diff changeset
   995
58618
782f0b662cae more cartouches;
wenzelm
parents: 58555
diff changeset
   996
text \<open>
29768
64a50ff3f308 more on object-level rules;
wenzelm
parents: 29761
diff changeset
   997
  The primitive inferences covered so far mostly serve foundational
64a50ff3f308 more on object-level rules;
wenzelm
parents: 29761
diff changeset
   998
  purposes.  User-level reasoning usually works via object-level rules
64a50ff3f308 more on object-level rules;
wenzelm
parents: 29761
diff changeset
   999
  that are represented as theorems of Pure.  Composition of rules
29771
aa1d3b5d1b5e improved section "Rule composition";
wenzelm
parents: 29770
diff changeset
  1000
  involves \emph{backchaining}, \emph{higher-order unification} modulo
aa1d3b5d1b5e improved section "Rule composition";
wenzelm
parents: 29770
diff changeset
  1001
  @{text "\<alpha>\<beta>\<eta>"}-conversion of @{text "\<lambda>"}-terms, and so-called
aa1d3b5d1b5e improved section "Rule composition";
wenzelm
parents: 29770
diff changeset
  1002
  \emph{lifting} of rules into a context of @{text "\<And>"} and @{text
29774
wenzelm
parents: 29771
diff changeset
  1003
  "\<Longrightarrow>"} connectives.  Thus the full power of higher-order Natural
wenzelm
parents: 29771
diff changeset
  1004
  Deduction in Isabelle/Pure becomes readily available.
58618
782f0b662cae more cartouches;
wenzelm
parents: 58555
diff changeset
  1005
\<close>
20491
wenzelm
parents: 20480
diff changeset
  1006
29769
03634a9e91ae improved section on "Hereditary Harrop Formulae";
wenzelm
parents: 29768
diff changeset
  1007
58618
782f0b662cae more cartouches;
wenzelm
parents: 58555
diff changeset
  1008
subsection \<open>Hereditary Harrop Formulae\<close>
29769
03634a9e91ae improved section on "Hereditary Harrop Formulae";
wenzelm
parents: 29768
diff changeset
  1009
58618
782f0b662cae more cartouches;
wenzelm
parents: 58555
diff changeset
  1010
text \<open>
29768
64a50ff3f308 more on object-level rules;
wenzelm
parents: 29761
diff changeset
  1011
  The idea of object-level rules is to model Natural Deduction
58555
7975676c08c0 prefer @{cite} antiquotation;
wenzelm
parents: 56579
diff changeset
  1012
  inferences in the style of Gentzen @{cite "Gentzen:1935"}, but we allow
7975676c08c0 prefer @{cite} antiquotation;
wenzelm
parents: 56579
diff changeset
  1013
  arbitrary nesting similar to @{cite extensions91}.  The most basic
29768
64a50ff3f308 more on object-level rules;
wenzelm
parents: 29761
diff changeset
  1014
  rule format is that of a \emph{Horn Clause}:
64a50ff3f308 more on object-level rules;
wenzelm
parents: 29761
diff changeset
  1015
  \[
64a50ff3f308 more on object-level rules;
wenzelm
parents: 29761
diff changeset
  1016
  \infer{@{text "A"}}{@{text "A\<^sub>1"} & @{text "\<dots>"} & @{text "A\<^sub>n"}}
64a50ff3f308 more on object-level rules;
wenzelm
parents: 29761
diff changeset
  1017
  \]
64a50ff3f308 more on object-level rules;
wenzelm
parents: 29761
diff changeset
  1018
  where @{text "A, A\<^sub>1, \<dots>, A\<^sub>n"} are atomic propositions
64a50ff3f308 more on object-level rules;
wenzelm
parents: 29761
diff changeset
  1019
  of the framework, usually of the form @{text "Trueprop B"}, where
64a50ff3f308 more on object-level rules;
wenzelm
parents: 29761
diff changeset
  1020
  @{text "B"} is a (compound) object-level statement.  This
64a50ff3f308 more on object-level rules;
wenzelm
parents: 29761
diff changeset
  1021
  object-level inference corresponds to an iterated implication in
64a50ff3f308 more on object-level rules;
wenzelm
parents: 29761
diff changeset
  1022
  Pure like this:
64a50ff3f308 more on object-level rules;
wenzelm
parents: 29761
diff changeset
  1023
  \[
64a50ff3f308 more on object-level rules;
wenzelm
parents: 29761
diff changeset
  1024
  @{text "A\<^sub>1 \<Longrightarrow> \<dots> A\<^sub>n \<Longrightarrow> A"}
64a50ff3f308 more on object-level rules;
wenzelm
parents: 29761
diff changeset
  1025
  \]
29769
03634a9e91ae improved section on "Hereditary Harrop Formulae";
wenzelm
parents: 29768
diff changeset
  1026
  As an example consider conjunction introduction: @{text "A \<Longrightarrow> B \<Longrightarrow> A \<and>
03634a9e91ae improved section on "Hereditary Harrop Formulae";
wenzelm
parents: 29768
diff changeset
  1027
  B"}.  Any parameters occurring in such rule statements are
03634a9e91ae improved section on "Hereditary Harrop Formulae";
wenzelm
parents: 29768
diff changeset
  1028
  conceptionally treated as arbitrary:
29768
64a50ff3f308 more on object-level rules;
wenzelm
parents: 29761
diff changeset
  1029
  \[
29769
03634a9e91ae improved section on "Hereditary Harrop Formulae";
wenzelm
parents: 29768
diff changeset
  1030
  @{text "\<And>x\<^sub>1 \<dots> x\<^sub>m. A\<^sub>1 x\<^sub>1 \<dots> x\<^sub>m \<Longrightarrow> \<dots> A\<^sub>n x\<^sub>1 \<dots> x\<^sub>m \<Longrightarrow> A x\<^sub>1 \<dots> x\<^sub>m"}
29768
64a50ff3f308 more on object-level rules;
wenzelm
parents: 29761
diff changeset
  1031
  \]
20491
wenzelm
parents: 20480
diff changeset
  1032
29769
03634a9e91ae improved section on "Hereditary Harrop Formulae";
wenzelm
parents: 29768
diff changeset
  1033
  Nesting of rules means that the positions of @{text "A\<^sub>i"} may
29770
wenzelm
parents: 29769
diff changeset
  1034
  again hold compound rules, not just atomic propositions.
29769
03634a9e91ae improved section on "Hereditary Harrop Formulae";
wenzelm
parents: 29768
diff changeset
  1035
  Propositions of this format are called \emph{Hereditary Harrop
58555
7975676c08c0 prefer @{cite} antiquotation;
wenzelm
parents: 56579
diff changeset
  1036
  Formulae} in the literature @{cite "Miller:1991"}.  Here we give an
29769
03634a9e91ae improved section on "Hereditary Harrop Formulae";
wenzelm
parents: 29768
diff changeset
  1037
  inductive characterization as follows:
29768
64a50ff3f308 more on object-level rules;
wenzelm
parents: 29761
diff changeset
  1038
64a50ff3f308 more on object-level rules;
wenzelm
parents: 29761
diff changeset
  1039
  \medskip
64a50ff3f308 more on object-level rules;
wenzelm
parents: 29761
diff changeset
  1040
  \begin{tabular}{ll}
64a50ff3f308 more on object-level rules;
wenzelm
parents: 29761
diff changeset
  1041
  @{text "\<^bold>x"} & set of variables \\
64a50ff3f308 more on object-level rules;
wenzelm
parents: 29761
diff changeset
  1042
  @{text "\<^bold>A"} & set of atomic propositions \\
64a50ff3f308 more on object-level rules;
wenzelm
parents: 29761
diff changeset
  1043
  @{text "\<^bold>H  =  \<And>\<^bold>x\<^sup>*. \<^bold>H\<^sup>* \<Longrightarrow> \<^bold>A"} & set of Hereditary Harrop Formulas \\
64a50ff3f308 more on object-level rules;
wenzelm
parents: 29761
diff changeset
  1044
  \end{tabular}
64a50ff3f308 more on object-level rules;
wenzelm
parents: 29761
diff changeset
  1045
  \medskip
64a50ff3f308 more on object-level rules;
wenzelm
parents: 29761
diff changeset
  1046
39861
b8d89db3e238 use continental paragraph style, which works better with mixture of (in)formal text;
wenzelm
parents: 39846
diff changeset
  1047
  Thus we essentially impose nesting levels on propositions formed
b8d89db3e238 use continental paragraph style, which works better with mixture of (in)formal text;
wenzelm
parents: 39846
diff changeset
  1048
  from @{text "\<And>"} and @{text "\<Longrightarrow>"}.  At each level there is a prefix
b8d89db3e238 use continental paragraph style, which works better with mixture of (in)formal text;
wenzelm
parents: 39846
diff changeset
  1049
  of parameters and compound premises, concluding an atomic
29770
wenzelm
parents: 29769
diff changeset
  1050
  proposition.  Typical examples are @{text "\<longrightarrow>"}-introduction @{text
wenzelm
parents: 29769
diff changeset
  1051
  "(A \<Longrightarrow> B) \<Longrightarrow> A \<longrightarrow> B"} or mathematical induction @{text "P 0 \<Longrightarrow> (\<And>n. P n
wenzelm
parents: 29769
diff changeset
  1052
  \<Longrightarrow> P (Suc n)) \<Longrightarrow> P n"}.  Even deeper nesting occurs in well-founded
wenzelm
parents: 29769
diff changeset
  1053
  induction @{text "(\<And>x. (\<And>y. y \<prec> x \<Longrightarrow> P y) \<Longrightarrow> P x) \<Longrightarrow> P x"}, but this
34929
9700a87f1cc2 misc tuning and clarification;
wenzelm
parents: 34921
diff changeset
  1054
  already marks the limit of rule complexity that is usually seen in
9700a87f1cc2 misc tuning and clarification;
wenzelm
parents: 34921
diff changeset
  1055
  practice.
29769
03634a9e91ae improved section on "Hereditary Harrop Formulae";
wenzelm
parents: 29768
diff changeset
  1056
29770
wenzelm
parents: 29769
diff changeset
  1057
  \medskip Regular user-level inferences in Isabelle/Pure always
wenzelm
parents: 29769
diff changeset
  1058
  maintain the following canonical form of results:
29769
03634a9e91ae improved section on "Hereditary Harrop Formulae";
wenzelm
parents: 29768
diff changeset
  1059
03634a9e91ae improved section on "Hereditary Harrop Formulae";
wenzelm
parents: 29768
diff changeset
  1060
  \begin{itemize}
29768
64a50ff3f308 more on object-level rules;
wenzelm
parents: 29761
diff changeset
  1061
29774
wenzelm
parents: 29771
diff changeset
  1062
  \item Normalization by @{text "(A \<Longrightarrow> (\<And>x. B x)) \<equiv> (\<And>x. A \<Longrightarrow> B x)"},
wenzelm
parents: 29771
diff changeset
  1063
  which is a theorem of Pure, means that quantifiers are pushed in
wenzelm
parents: 29771
diff changeset
  1064
  front of implication at each level of nesting.  The normal form is a
wenzelm
parents: 29771
diff changeset
  1065
  Hereditary Harrop Formula.
29769
03634a9e91ae improved section on "Hereditary Harrop Formulae";
wenzelm
parents: 29768
diff changeset
  1066
03634a9e91ae improved section on "Hereditary Harrop Formulae";
wenzelm
parents: 29768
diff changeset
  1067
  \item The outermost prefix of parameters is represented via
29770
wenzelm
parents: 29769
diff changeset
  1068
  schematic variables: instead of @{text "\<And>\<^vec>x. \<^vec>H \<^vec>x
29774
wenzelm
parents: 29771
diff changeset
  1069
  \<Longrightarrow> A \<^vec>x"} we have @{text "\<^vec>H ?\<^vec>x \<Longrightarrow> A ?\<^vec>x"}.
wenzelm
parents: 29771
diff changeset
  1070
  Note that this representation looses information about the order of
wenzelm
parents: 29771
diff changeset
  1071
  parameters, and vacuous quantifiers vanish automatically.
29769
03634a9e91ae improved section on "Hereditary Harrop Formulae";
wenzelm
parents: 29768
diff changeset
  1072
03634a9e91ae improved section on "Hereditary Harrop Formulae";
wenzelm
parents: 29768
diff changeset
  1073
  \end{itemize}
58618
782f0b662cae more cartouches;
wenzelm
parents: 58555
diff changeset
  1074
\<close>
29769
03634a9e91ae improved section on "Hereditary Harrop Formulae";
wenzelm
parents: 29768
diff changeset
  1075
58618
782f0b662cae more cartouches;
wenzelm
parents: 58555
diff changeset
  1076
text %mlref \<open>
29771
aa1d3b5d1b5e improved section "Rule composition";
wenzelm
parents: 29770
diff changeset
  1077
  \begin{mldecls}
54883
dd04a8b654fc proper context for norm_hhf and derived operations;
wenzelm
parents: 53200
diff changeset
  1078
  @{index_ML Simplifier.norm_hhf: "Proof.context -> thm -> thm"} \\
29771
aa1d3b5d1b5e improved section "Rule composition";
wenzelm
parents: 29770
diff changeset
  1079
  \end{mldecls}
aa1d3b5d1b5e improved section "Rule composition";
wenzelm
parents: 29770
diff changeset
  1080
aa1d3b5d1b5e improved section "Rule composition";
wenzelm
parents: 29770
diff changeset
  1081
  \begin{description}
aa1d3b5d1b5e improved section "Rule composition";
wenzelm
parents: 29770
diff changeset
  1082
54883
dd04a8b654fc proper context for norm_hhf and derived operations;
wenzelm
parents: 53200
diff changeset
  1083
  \item @{ML Simplifier.norm_hhf}~@{text "ctxt thm"} normalizes the given
29771
aa1d3b5d1b5e improved section "Rule composition";
wenzelm
parents: 29770
diff changeset
  1084
  theorem according to the canonical form specified above.  This is
aa1d3b5d1b5e improved section "Rule composition";
wenzelm
parents: 29770
diff changeset
  1085
  occasionally helpful to repair some low-level tools that do not
aa1d3b5d1b5e improved section "Rule composition";
wenzelm
parents: 29770
diff changeset
  1086
  handle Hereditary Harrop Formulae properly.
aa1d3b5d1b5e improved section "Rule composition";
wenzelm
parents: 29770
diff changeset
  1087
aa1d3b5d1b5e improved section "Rule composition";
wenzelm
parents: 29770
diff changeset
  1088
  \end{description}
58618
782f0b662cae more cartouches;
wenzelm
parents: 58555
diff changeset
  1089
\<close>
29771
aa1d3b5d1b5e improved section "Rule composition";
wenzelm
parents: 29770
diff changeset
  1090
29769
03634a9e91ae improved section on "Hereditary Harrop Formulae";
wenzelm
parents: 29768
diff changeset
  1091
58618
782f0b662cae more cartouches;
wenzelm
parents: 58555
diff changeset
  1092
subsection \<open>Rule composition\<close>
29769
03634a9e91ae improved section on "Hereditary Harrop Formulae";
wenzelm
parents: 29768
diff changeset
  1093
58618
782f0b662cae more cartouches;
wenzelm
parents: 58555
diff changeset
  1094
text \<open>
29771
aa1d3b5d1b5e improved section "Rule composition";
wenzelm
parents: 29770
diff changeset
  1095
  The rule calculus of Isabelle/Pure provides two main inferences:
aa1d3b5d1b5e improved section "Rule composition";
wenzelm
parents: 29770
diff changeset
  1096
  @{inference resolution} (i.e.\ back-chaining of rules) and
aa1d3b5d1b5e improved section "Rule composition";
wenzelm
parents: 29770
diff changeset
  1097
  @{inference assumption} (i.e.\ closing a branch), both modulo
aa1d3b5d1b5e improved section "Rule composition";
wenzelm
parents: 29770
diff changeset
  1098
  higher-order unification.  There are also combined variants, notably
aa1d3b5d1b5e improved section "Rule composition";
wenzelm
parents: 29770
diff changeset
  1099
  @{inference elim_resolution} and @{inference dest_resolution}.
20491
wenzelm
parents: 20480
diff changeset
  1100
29771
aa1d3b5d1b5e improved section "Rule composition";
wenzelm
parents: 29770
diff changeset
  1101
  To understand the all-important @{inference resolution} principle,
aa1d3b5d1b5e improved section "Rule composition";
wenzelm
parents: 29770
diff changeset
  1102
  we first consider raw @{inference_def composition} (modulo
aa1d3b5d1b5e improved section "Rule composition";
wenzelm
parents: 29770
diff changeset
  1103
  higher-order unification with substitution @{text "\<vartheta>"}):
20498
825a8d2335ce more rules;
wenzelm
parents: 20494
diff changeset
  1104
  \[
29771
aa1d3b5d1b5e improved section "Rule composition";
wenzelm
parents: 29770
diff changeset
  1105
  \infer[(@{inference_def composition})]{@{text "\<^vec>A\<vartheta> \<Longrightarrow> C\<vartheta>"}}
20498
825a8d2335ce more rules;
wenzelm
parents: 20494
diff changeset
  1106
  {@{text "\<^vec>A \<Longrightarrow> B"} & @{text "B' \<Longrightarrow> C"} & @{text "B\<vartheta> = B'\<vartheta>"}}
825a8d2335ce more rules;
wenzelm
parents: 20494
diff changeset
  1107
  \]
29771
aa1d3b5d1b5e improved section "Rule composition";
wenzelm
parents: 29770
diff changeset
  1108
  Here the conclusion of the first rule is unified with the premise of
aa1d3b5d1b5e improved section "Rule composition";
wenzelm
parents: 29770
diff changeset
  1109
  the second; the resulting rule instance inherits the premises of the
aa1d3b5d1b5e improved section "Rule composition";
wenzelm
parents: 29770
diff changeset
  1110
  first and conclusion of the second.  Note that @{text "C"} can again
aa1d3b5d1b5e improved section "Rule composition";
wenzelm
parents: 29770
diff changeset
  1111
  consist of iterated implications.  We can also permute the premises
aa1d3b5d1b5e improved section "Rule composition";
wenzelm
parents: 29770
diff changeset
  1112
  of the second rule back-and-forth in order to compose with @{text
aa1d3b5d1b5e improved section "Rule composition";
wenzelm
parents: 29770
diff changeset
  1113
  "B'"} in any position (subsequently we shall always refer to
aa1d3b5d1b5e improved section "Rule composition";
wenzelm
parents: 29770
diff changeset
  1114
  position 1 w.l.o.g.).
20498
825a8d2335ce more rules;
wenzelm
parents: 20494
diff changeset
  1115
29774
wenzelm
parents: 29771
diff changeset
  1116
  In @{inference composition} the internal structure of the common
wenzelm
parents: 29771
diff changeset
  1117
  part @{text "B"} and @{text "B'"} is not taken into account.  For
wenzelm
parents: 29771
diff changeset
  1118
  proper @{inference resolution} we require @{text "B"} to be atomic,
wenzelm
parents: 29771
diff changeset
  1119
  and explicitly observe the structure @{text "\<And>\<^vec>x. \<^vec>H
wenzelm
parents: 29771
diff changeset
  1120
  \<^vec>x \<Longrightarrow> B' \<^vec>x"} of the premise of the second rule.  The
wenzelm
parents: 29771
diff changeset
  1121
  idea is to adapt the first rule by ``lifting'' it into this context,
wenzelm
parents: 29771
diff changeset
  1122
  by means of iterated application of the following inferences:
20498
825a8d2335ce more rules;
wenzelm
parents: 20494
diff changeset
  1123
  \[
29771
aa1d3b5d1b5e improved section "Rule composition";
wenzelm
parents: 29770
diff changeset
  1124
  \infer[(@{inference_def imp_lift})]{@{text "(\<^vec>H \<Longrightarrow> \<^vec>A) \<Longrightarrow> (\<^vec>H \<Longrightarrow> B)"}}{@{text "\<^vec>A \<Longrightarrow> B"}}
20498
825a8d2335ce more rules;
wenzelm
parents: 20494
diff changeset
  1125
  \]
825a8d2335ce more rules;
wenzelm
parents: 20494
diff changeset
  1126
  \[
29771
aa1d3b5d1b5e improved section "Rule composition";
wenzelm
parents: 29770
diff changeset
  1127
  \infer[(@{inference_def all_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"}}
20498
825a8d2335ce more rules;
wenzelm
parents: 20494
diff changeset
  1128
  \]
29771
aa1d3b5d1b5e improved section "Rule composition";
wenzelm
parents: 29770
diff changeset
  1129
  By combining raw composition with lifting, we get full @{inference
aa1d3b5d1b5e improved section "Rule composition";
wenzelm
parents: 29770
diff changeset
  1130
  resolution} as follows:
20498
825a8d2335ce more rules;
wenzelm
parents: 20494
diff changeset
  1131
  \[
29771
aa1d3b5d1b5e improved section "Rule composition";
wenzelm
parents: 29770
diff changeset
  1132
  \infer[(@{inference_def resolution})]
20498
825a8d2335ce more rules;
wenzelm
parents: 20494
diff changeset
  1133
  {@{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
  1134
  {\begin{tabular}{l}
825a8d2335ce more rules;
wenzelm
parents: 20494
diff changeset
  1135
    @{text "\<^vec>A ?\<^vec>a \<Longrightarrow> B ?\<^vec>a"} \\
825a8d2335ce more rules;
wenzelm
parents: 20494
diff changeset
  1136
    @{text "(\<And>\<^vec>x. \<^vec>H \<^vec>x \<Longrightarrow> B' \<^vec>x) \<Longrightarrow> C"} \\
825a8d2335ce more rules;
wenzelm
parents: 20494
diff changeset
  1137
    @{text "(\<lambda>\<^vec>x. B (?\<^vec>a \<^vec>x))\<vartheta> = B'\<vartheta>"} \\
825a8d2335ce more rules;
wenzelm
parents: 20494
diff changeset
  1138
   \end{tabular}}
825a8d2335ce more rules;
wenzelm
parents: 20494
diff changeset
  1139
  \]
825a8d2335ce more rules;
wenzelm
parents: 20494
diff changeset
  1140
29774
wenzelm
parents: 29771
diff changeset
  1141
  Continued resolution of rules allows to back-chain a problem towards
wenzelm
parents: 29771
diff changeset
  1142
  more and sub-problems.  Branches are closed either by resolving with
wenzelm
parents: 29771
diff changeset
  1143
  a rule of 0 premises, or by producing a ``short-circuit'' within a
wenzelm
parents: 29771
diff changeset
  1144
  solved situation (again modulo unification):
29771
aa1d3b5d1b5e improved section "Rule composition";
wenzelm
parents: 29770
diff changeset
  1145
  \[
aa1d3b5d1b5e improved section "Rule composition";
wenzelm
parents: 29770
diff changeset
  1146
  \infer[(@{inference_def assumption})]{@{text "C\<vartheta>"}}
aa1d3b5d1b5e improved section "Rule composition";
wenzelm
parents: 29770
diff changeset
  1147
  {@{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})}}
aa1d3b5d1b5e improved section "Rule composition";
wenzelm
parents: 29770
diff changeset
  1148
  \]
20498
825a8d2335ce more rules;
wenzelm
parents: 20494
diff changeset
  1149
52422
wenzelm
parents: 52412
diff changeset
  1150
  %FIXME @{inference_def elim_resolution}, @{inference_def dest_resolution}
58618
782f0b662cae more cartouches;
wenzelm
parents: 58555
diff changeset
  1151
\<close>
18537
2681f9e34390 "The Isabelle/Isar Implementation" manual;
wenzelm
parents:
diff changeset
  1152
58618
782f0b662cae more cartouches;
wenzelm
parents: 58555
diff changeset
  1153
text %mlref \<open>
29768
64a50ff3f308 more on object-level rules;
wenzelm
parents: 29761
diff changeset
  1154
  \begin{mldecls}
46262
912b42e64fde tuned ML infixes;
wenzelm
parents: 46256
diff changeset
  1155
  @{index_ML_op "RSN": "thm * (int * thm) -> thm"} \\
912b42e64fde tuned ML infixes;
wenzelm
parents: 46256
diff changeset
  1156
  @{index_ML_op "RS": "thm * thm -> thm"} \\
46256
bc874d2ee55a updated RSN, RL, RLN, MRS;
wenzelm
parents: 46254
diff changeset
  1157
46262
912b42e64fde tuned ML infixes;
wenzelm
parents: 46256
diff changeset
  1158
  @{index_ML_op "RLN": "thm list * (int * thm list) -> thm list"} \\
912b42e64fde tuned ML infixes;
wenzelm
parents: 46256
diff changeset
  1159
  @{index_ML_op "RL": "thm list * thm list -> thm list"} \\
46256
bc874d2ee55a updated RSN, RL, RLN, MRS;
wenzelm
parents: 46254
diff changeset
  1160
46262
912b42e64fde tuned ML infixes;
wenzelm
parents: 46256
diff changeset
  1161
  @{index_ML_op "MRS": "thm list * thm -> thm"} \\
912b42e64fde tuned ML infixes;
wenzelm
parents: 46256
diff changeset
  1162
  @{index_ML_op "OF": "thm * thm list -> thm"} \\
29768
64a50ff3f308 more on object-level rules;
wenzelm
parents: 29761
diff changeset
  1163
  \end{mldecls}
64a50ff3f308 more on object-level rules;
wenzelm
parents: 29761
diff changeset
  1164
64a50ff3f308 more on object-level rules;
wenzelm
parents: 29761
diff changeset
  1165
  \begin{description}
64a50ff3f308 more on object-level rules;
wenzelm
parents: 29761
diff changeset
  1166
46256
bc874d2ee55a updated RSN, RL, RLN, MRS;
wenzelm
parents: 46254
diff changeset
  1167
  \item @{text "rule\<^sub>1 RSN (i, rule\<^sub>2)"} resolves the conclusion of
bc874d2ee55a updated RSN, RL, RLN, MRS;
wenzelm
parents: 46254
diff changeset
  1168
  @{text "rule\<^sub>1"} with the @{text i}-th premise of @{text "rule\<^sub>2"},
bc874d2ee55a updated RSN, RL, RLN, MRS;
wenzelm
parents: 46254
diff changeset
  1169
  according to the @{inference resolution} principle explained above.
bc874d2ee55a updated RSN, RL, RLN, MRS;
wenzelm
parents: 46254
diff changeset
  1170
  Unless there is precisely one resolvent it raises exception @{ML
bc874d2ee55a updated RSN, RL, RLN, MRS;
wenzelm
parents: 46254
diff changeset
  1171
  THM}.
bc874d2ee55a updated RSN, RL, RLN, MRS;
wenzelm
parents: 46254
diff changeset
  1172
bc874d2ee55a updated RSN, RL, RLN, MRS;
wenzelm
parents: 46254
diff changeset
  1173
  This corresponds to the rule attribute @{attribute THEN} in Isar
bc874d2ee55a updated RSN, RL, RLN, MRS;
wenzelm
parents: 46254
diff changeset
  1174
  source language.
bc874d2ee55a updated RSN, RL, RLN, MRS;
wenzelm
parents: 46254
diff changeset
  1175
53200
09e8c42dbb06 tuned unchecked ML;
wenzelm
parents: 53071
diff changeset
  1176
  \item @{text "rule\<^sub>1 RS rule\<^sub>2"} abbreviates @{text "rule\<^sub>1 RSN (1,
46256
bc874d2ee55a updated RSN, RL, RLN, MRS;
wenzelm
parents: 46254
diff changeset
  1177
  rule\<^sub>2)"}.
29768
64a50ff3f308 more on object-level rules;
wenzelm
parents: 29761
diff changeset
  1178
46256
bc874d2ee55a updated RSN, RL, RLN, MRS;
wenzelm
parents: 46254
diff changeset
  1179
  \item @{text "rules\<^sub>1 RLN (i, rules\<^sub>2)"} joins lists of rules.  For
bc874d2ee55a updated RSN, RL, RLN, MRS;
wenzelm
parents: 46254
diff changeset
  1180
  every @{text "rule\<^sub>1"} in @{text "rules\<^sub>1"} and @{text "rule\<^sub>2"} in
bc874d2ee55a updated RSN, RL, RLN, MRS;
wenzelm
parents: 46254
diff changeset
  1181
  @{text "rules\<^sub>2"}, it resolves the conclusion of @{text "rule\<^sub>1"} with
bc874d2ee55a updated RSN, RL, RLN, MRS;
wenzelm
parents: 46254
diff changeset
  1182
  the @{text "i"}-th premise of @{text "rule\<^sub>2"}, accumulating multiple
bc874d2ee55a updated RSN, RL, RLN, MRS;
wenzelm
parents: 46254
diff changeset
  1183
  results in one big list.  Note that such strict enumerations of
bc874d2ee55a updated RSN, RL, RLN, MRS;
wenzelm
parents: 46254
diff changeset
  1184
  higher-order unifications can be inefficient compared to the lazy
bc874d2ee55a updated RSN, RL, RLN, MRS;
wenzelm
parents: 46254
diff changeset
  1185
  variant seen in elementary tactics like @{ML resolve_tac}.
bc874d2ee55a updated RSN, RL, RLN, MRS;
wenzelm
parents: 46254
diff changeset
  1186
bc874d2ee55a updated RSN, RL, RLN, MRS;
wenzelm
parents: 46254
diff changeset
  1187
  \item @{text "rules\<^sub>1 RL rules\<^sub>2"} abbreviates @{text "rules\<^sub>1 RLN (1,
bc874d2ee55a updated RSN, RL, RLN, MRS;
wenzelm
parents: 46254
diff changeset
  1188
  rules\<^sub>2)"}.
bc874d2ee55a updated RSN, RL, RLN, MRS;
wenzelm
parents: 46254
diff changeset
  1189
53015
a1119cf551e8 standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
wenzelm
parents: 52788
diff changeset
  1190
  \item @{text "[rule\<^sub>1, \<dots>, rule\<^sub>n] MRS rule"} resolves @{text "rule\<^sub>i"}
46256
bc874d2ee55a updated RSN, RL, RLN, MRS;
wenzelm
parents: 46254
diff changeset
  1191
  against premise @{text "i"} of @{text "rule"}, for @{text "i = n, \<dots>,
bc874d2ee55a updated RSN, RL, RLN, MRS;
wenzelm
parents: 46254
diff changeset
  1192
  1"}.  By working from right to left, newly emerging premises are
bc874d2ee55a updated RSN, RL, RLN, MRS;
wenzelm
parents: 46254
diff changeset
  1193
  concatenated in the result, without interfering.
bc874d2ee55a updated RSN, RL, RLN, MRS;
wenzelm
parents: 46254
diff changeset
  1194
47498
e3fc50c7da13 updated and clarified OF/MRS;
wenzelm
parents: 47174
diff changeset
  1195
  \item @{text "rule OF rules"} is an alternative notation for @{text
e3fc50c7da13 updated and clarified OF/MRS;
wenzelm
parents: 47174
diff changeset
  1196
  "rules MRS rule"}, which makes rule composition look more like
e3fc50c7da13 updated and clarified OF/MRS;
wenzelm
parents: 47174
diff changeset
  1197
  function application.  Note that the argument @{text "rules"} need
e3fc50c7da13 updated and clarified OF/MRS;
wenzelm
parents: 47174
diff changeset
  1198
  not be atomic.
46256
bc874d2ee55a updated RSN, RL, RLN, MRS;
wenzelm
parents: 46254
diff changeset
  1199
bc874d2ee55a updated RSN, RL, RLN, MRS;
wenzelm
parents: 46254
diff changeset
  1200
  This corresponds to the rule attribute @{attribute OF} in Isar
bc874d2ee55a updated RSN, RL, RLN, MRS;
wenzelm
parents: 46254
diff changeset
  1201
  source language.
29768
64a50ff3f308 more on object-level rules;
wenzelm
parents: 29761
diff changeset
  1202
64a50ff3f308 more on object-level rules;
wenzelm
parents: 29761
diff changeset
  1203
  \end{description}
58618
782f0b662cae more cartouches;
wenzelm
parents: 58555
diff changeset
  1204
\<close>
30272
2d612824e642 regenerated document;
wenzelm
parents: 30270
diff changeset
  1205
52407
e4662afb3483 more on proof terms;
wenzelm
parents: 52406
diff changeset
  1206
58618
782f0b662cae more cartouches;
wenzelm
parents: 58555
diff changeset
  1207
section \<open>Proof terms \label{sec:proof-terms}\<close>
52407
e4662afb3483 more on proof terms;
wenzelm
parents: 52406
diff changeset
  1208
58618
782f0b662cae more cartouches;
wenzelm
parents: 58555
diff changeset
  1209
text \<open>The Isabelle/Pure inference kernel can record the proof of
52407
e4662afb3483 more on proof terms;
wenzelm
parents: 52406
diff changeset
  1210
  each theorem as a proof term that contains all logical inferences in
e4662afb3483 more on proof terms;
wenzelm
parents: 52406
diff changeset
  1211
  detail.  Rule composition by resolution (\secref{sec:obj-rules}) and
e4662afb3483 more on proof terms;
wenzelm
parents: 52406
diff changeset
  1212
  type-class reasoning is broken down to primitive rules of the
e4662afb3483 more on proof terms;
wenzelm
parents: 52406
diff changeset
  1213
  logical framework.  The proof term can be inspected by a separate
e4662afb3483 more on proof terms;
wenzelm
parents: 52406
diff changeset
  1214
  proof-checker, for example.
e4662afb3483 more on proof terms;
wenzelm
parents: 52406
diff changeset
  1215
e4662afb3483 more on proof terms;
wenzelm
parents: 52406
diff changeset
  1216
  According to the well-known \emph{Curry-Howard isomorphism}, a proof
e4662afb3483 more on proof terms;
wenzelm
parents: 52406
diff changeset
  1217
  can be viewed as a @{text "\<lambda>"}-term. Following this idea, proofs in
e4662afb3483 more on proof terms;
wenzelm
parents: 52406
diff changeset
  1218
  Isabelle are internally represented by a datatype similar to the one
e4662afb3483 more on proof terms;
wenzelm
parents: 52406
diff changeset
  1219
  for terms described in \secref{sec:terms}.  On top of these
e4662afb3483 more on proof terms;
wenzelm
parents: 52406
diff changeset
  1220
  syntactic terms, two more layers of @{text "\<lambda>"}-calculus are added,
e4662afb3483 more on proof terms;
wenzelm
parents: 52406
diff changeset
  1221
  which correspond to @{text "\<And>x :: \<alpha>. B x"} and @{text "A \<Longrightarrow> B"}
e4662afb3483 more on proof terms;
wenzelm
parents: 52406
diff changeset
  1222
  according to the propositions-as-types principle.  The resulting
e4662afb3483 more on proof terms;
wenzelm
parents: 52406
diff changeset
  1223
  3-level @{text "\<lambda>"}-calculus resembles ``@{text "\<lambda>HOL"}'' in the
e4662afb3483 more on proof terms;
wenzelm
parents: 52406
diff changeset
  1224
  more abstract setting of Pure Type Systems (PTS)
58555
7975676c08c0 prefer @{cite} antiquotation;
wenzelm
parents: 56579
diff changeset
  1225
  @{cite "Barendregt-Geuvers:2001"}, if some fine points like schematic
52407
e4662afb3483 more on proof terms;
wenzelm
parents: 52406
diff changeset
  1226
  polymorphism and type classes are ignored.
e4662afb3483 more on proof terms;
wenzelm
parents: 52406
diff changeset
  1227
e4662afb3483 more on proof terms;
wenzelm
parents: 52406
diff changeset
  1228
  \medskip\emph{Proof abstractions} of the form @{text "\<^bold>\<lambda>x :: \<alpha>. prf"}
e4662afb3483 more on proof terms;
wenzelm
parents: 52406
diff changeset
  1229
  or @{text "\<^bold>\<lambda>p : A. prf"} correspond to introduction of @{text
e4662afb3483 more on proof terms;
wenzelm
parents: 52406
diff changeset
  1230
  "\<And>"}/@{text "\<Longrightarrow>"}, and \emph{proof applications} of the form @{text
e4662afb3483 more on proof terms;
wenzelm
parents: 52406
diff changeset
  1231
  "p \<cdot> t"} or @{text "p \<bullet> q"} correspond to elimination of @{text
e4662afb3483 more on proof terms;
wenzelm
parents: 52406
diff changeset
  1232
  "\<And>"}/@{text "\<Longrightarrow>"}.  Actual types @{text "\<alpha>"}, propositions @{text
e4662afb3483 more on proof terms;
wenzelm
parents: 52406
diff changeset
  1233
  "A"}, and terms @{text "t"} might be suppressed and reconstructed
e4662afb3483 more on proof terms;
wenzelm
parents: 52406
diff changeset
  1234
  from the overall proof term.
e4662afb3483 more on proof terms;
wenzelm
parents: 52406
diff changeset
  1235
e4662afb3483 more on proof terms;
wenzelm
parents: 52406
diff changeset
  1236
  \medskip Various atomic proofs indicate special situations within
e4662afb3483 more on proof terms;
wenzelm
parents: 52406
diff changeset
  1237
  the proof construction as follows.
e4662afb3483 more on proof terms;
wenzelm
parents: 52406
diff changeset
  1238
e4662afb3483 more on proof terms;
wenzelm
parents: 52406
diff changeset
  1239
  A \emph{bound proof variable} is a natural number @{text "b"} that
e4662afb3483 more on proof terms;
wenzelm
parents: 52406
diff changeset
  1240
  acts as de-Bruijn index for proof term abstractions.
e4662afb3483 more on proof terms;
wenzelm
parents: 52406
diff changeset
  1241
e4662afb3483 more on proof terms;
wenzelm
parents: 52406
diff changeset
  1242
  A \emph{minimal proof} ``@{text "?"}'' is a dummy proof term.  This
e4662afb3483 more on proof terms;
wenzelm
parents: 52406
diff changeset
  1243
  indicates some unrecorded part of the proof.
e4662afb3483 more on proof terms;
wenzelm
parents: 52406
diff changeset
  1244
e4662afb3483 more on proof terms;
wenzelm
parents: 52406
diff changeset
  1245
  @{text "Hyp A"} refers to some pending hypothesis by giving its
e4662afb3483 more on proof terms;
wenzelm
parents: 52406
diff changeset
  1246
  proposition.  This indicates an open context of implicit hypotheses,
e4662afb3483 more on proof terms;
wenzelm
parents: 52406
diff changeset
  1247
  similar to loose bound variables or free variables within a term
e4662afb3483 more on proof terms;
wenzelm
parents: 52406
diff changeset
  1248
  (\secref{sec:terms}).
e4662afb3483 more on proof terms;
wenzelm
parents: 52406
diff changeset
  1249
e4662afb3483 more on proof terms;
wenzelm
parents: 52406
diff changeset
  1250
  An \emph{axiom} or \emph{oracle} @{text "a : A[\<^vec>\<tau>]"} refers
e4662afb3483 more on proof terms;
wenzelm
parents: 52406
diff changeset
  1251
  some postulated @{text "proof constant"}, which is subject to
e4662afb3483 more on proof terms;
wenzelm
parents: 52406
diff changeset
  1252
  schematic polymorphism of theory content, and the particular type
e4662afb3483 more on proof terms;
wenzelm
parents: 52406
diff changeset
  1253
  instantiation may be given explicitly.  The vector of types @{text
e4662afb3483 more on proof terms;
wenzelm
parents: 52406
diff changeset
  1254
  "\<^vec>\<tau>"} refers to the schematic type variables in the generic
e4662afb3483 more on proof terms;
wenzelm
parents: 52406
diff changeset
  1255
  proposition @{text "A"} in canonical order.
e4662afb3483 more on proof terms;
wenzelm
parents: 52406
diff changeset
  1256
e4662afb3483 more on proof terms;
wenzelm
parents: 52406
diff changeset
  1257
  A \emph{proof promise} @{text "a : A[\<^vec>\<tau>]"} is a placeholder
e4662afb3483 more on proof terms;
wenzelm
parents: 52406
diff changeset
  1258
  for some proof of polymorphic proposition @{text "A"}, with explicit
e4662afb3483 more on proof terms;
wenzelm
parents: 52406
diff changeset
  1259
  type instantiation as given by the vector @{text "\<^vec>\<tau>"}, as
e4662afb3483 more on proof terms;
wenzelm
parents: 52406
diff changeset
  1260
  above.  Unlike axioms or oracles, proof promises may be
e4662afb3483 more on proof terms;
wenzelm
parents: 52406
diff changeset
  1261
  \emph{fulfilled} eventually, by substituting @{text "a"} by some
e4662afb3483 more on proof terms;
wenzelm
parents: 52406
diff changeset
  1262
  particular proof @{text "q"} at the corresponding type instance.
e4662afb3483 more on proof terms;
wenzelm
parents: 52406
diff changeset
  1263
  This acts like Hindley-Milner @{text "let"}-polymorphism: a generic
e4662afb3483 more on proof terms;
wenzelm
parents: 52406
diff changeset
  1264
  local proof definition may get used at different type instances, and
e4662afb3483 more on proof terms;
wenzelm
parents: 52406
diff changeset
  1265
  is replaced by the concrete instance eventually.
e4662afb3483 more on proof terms;
wenzelm
parents: 52406
diff changeset
  1266
e4662afb3483 more on proof terms;
wenzelm
parents: 52406
diff changeset
  1267
  A \emph{named theorem} wraps up some concrete proof as a closed
e4662afb3483 more on proof terms;
wenzelm
parents: 52406
diff changeset
  1268
  formal entity, in the manner of constant definitions for proof
e4662afb3483 more on proof terms;
wenzelm
parents: 52406
diff changeset
  1269
  terms.  The \emph{proof body} of such boxed theorems involves some
e4662afb3483 more on proof terms;
wenzelm
parents: 52406
diff changeset
  1270
  digest about oracles and promises occurring in the original proof.
e4662afb3483 more on proof terms;
wenzelm
parents: 52406
diff changeset
  1271
  This allows the inference kernel to manage this critical information
e4662afb3483 more on proof terms;
wenzelm
parents: 52406
diff changeset
  1272
  without the full overhead of explicit proof terms.
58618
782f0b662cae more cartouches;
wenzelm
parents: 58555
diff changeset
  1273
\<close>
52407
e4662afb3483 more on proof terms;
wenzelm
parents: 52406
diff changeset
  1274
52411
f192c4ea5b17 more on reconstructing and checking proof terms;
wenzelm
parents: 52410
diff changeset
  1275
58618
782f0b662cae more cartouches;
wenzelm
parents: 58555
diff changeset
  1276
subsection \<open>Reconstructing and checking proof terms\<close>
52411
f192c4ea5b17 more on reconstructing and checking proof terms;
wenzelm
parents: 52410
diff changeset
  1277
58618
782f0b662cae more cartouches;
wenzelm
parents: 58555
diff changeset
  1278
text \<open>Fully explicit proof terms can be large, but most of this
52411
f192c4ea5b17 more on reconstructing and checking proof terms;
wenzelm
parents: 52410
diff changeset
  1279
  information is redundant and can be reconstructed from the context.
f192c4ea5b17 more on reconstructing and checking proof terms;
wenzelm
parents: 52410
diff changeset
  1280
  Therefore, the Isabelle/Pure inference kernel records only
f192c4ea5b17 more on reconstructing and checking proof terms;
wenzelm
parents: 52410
diff changeset
  1281
  \emph{implicit} proof terms, by omitting all typing information in
f192c4ea5b17 more on reconstructing and checking proof terms;
wenzelm
parents: 52410
diff changeset
  1282
  terms, all term and type labels of proof abstractions, and some
f192c4ea5b17 more on reconstructing and checking proof terms;
wenzelm
parents: 52410
diff changeset
  1283
  argument terms of applications @{text "p \<cdot> t"} (if possible).
f192c4ea5b17 more on reconstructing and checking proof terms;
wenzelm
parents: 52410
diff changeset
  1284
f192c4ea5b17 more on reconstructing and checking proof terms;
wenzelm
parents: 52410
diff changeset
  1285
  There are separate operations to reconstruct the full proof term
f192c4ea5b17 more on reconstructing and checking proof terms;
wenzelm
parents: 52410
diff changeset
  1286
  later on, using \emph{higher-order pattern unification}
58555
7975676c08c0 prefer @{cite} antiquotation;
wenzelm
parents: 56579
diff changeset
  1287
  @{cite "nipkow-patterns" and "Berghofer-Nipkow:2000:TPHOL"}.
52411
f192c4ea5b17 more on reconstructing and checking proof terms;
wenzelm
parents: 52410
diff changeset
  1288
f192c4ea5b17 more on reconstructing and checking proof terms;
wenzelm
parents: 52410
diff changeset
  1289
  The \emph{proof checker} expects a fully reconstructed proof term,
f192c4ea5b17 more on reconstructing and checking proof terms;
wenzelm
parents: 52410
diff changeset
  1290
  and can turn it into a theorem by replaying its primitive inferences
58618
782f0b662cae more cartouches;
wenzelm
parents: 58555
diff changeset
  1291
  within the kernel.\<close>
52411
f192c4ea5b17 more on reconstructing and checking proof terms;
wenzelm
parents: 52410
diff changeset
  1292
52412
4cfa094da3cb more on concrete syntax of proof terms;
wenzelm
parents: 52411
diff changeset
  1293
58618
782f0b662cae more cartouches;
wenzelm
parents: 58555
diff changeset
  1294
subsection \<open>Concrete syntax of proof terms\<close>
52412
4cfa094da3cb more on concrete syntax of proof terms;
wenzelm
parents: 52411
diff changeset
  1295
58618
782f0b662cae more cartouches;
wenzelm
parents: 58555
diff changeset
  1296
text \<open>The concrete syntax of proof terms is a slight extension of
58555
7975676c08c0 prefer @{cite} antiquotation;
wenzelm
parents: 56579
diff changeset
  1297
  the regular inner syntax of Isabelle/Pure @{cite "isabelle-isar-ref"}.
52412
4cfa094da3cb more on concrete syntax of proof terms;
wenzelm
parents: 52411
diff changeset
  1298
  Its main syntactic category @{syntax (inner) proof} is defined as
4cfa094da3cb more on concrete syntax of proof terms;
wenzelm
parents: 52411
diff changeset
  1299
  follows:
4cfa094da3cb more on concrete syntax of proof terms;
wenzelm
parents: 52411
diff changeset
  1300
4cfa094da3cb more on concrete syntax of proof terms;
wenzelm
parents: 52411
diff changeset
  1301
  \begin{center}
4cfa094da3cb more on concrete syntax of proof terms;
wenzelm
parents: 52411
diff changeset
  1302
  \begin{supertabular}{rclr}
4cfa094da3cb more on concrete syntax of proof terms;
wenzelm
parents: 52411
diff changeset
  1303
4cfa094da3cb more on concrete syntax of proof terms;
wenzelm
parents: 52411
diff changeset
  1304
  @{syntax_def (inner) proof} & = & @{verbatim Lam} @{text params} @{verbatim "."} @{text proof} \\
52486
b1565e37678b just one alternative proof syntax, which also works for Proof_Syntax.pretty_proof/Proof_Syntax.read_proof roundtrip;
wenzelm
parents: 52470
diff changeset
  1305
    & @{text "|"} & @{text "\<^bold>\<lambda>"} @{text "params"} @{verbatim "."} @{text proof} \\
52412
4cfa094da3cb more on concrete syntax of proof terms;
wenzelm
parents: 52411
diff changeset
  1306
    & @{text "|"} & @{text proof} @{verbatim "%"} @{text any} \\
4cfa094da3cb more on concrete syntax of proof terms;
wenzelm
parents: 52411
diff changeset
  1307
    & @{text "|"} & @{text proof} @{text "\<cdot>"} @{text any} \\
4cfa094da3cb more on concrete syntax of proof terms;
wenzelm
parents: 52411
diff changeset
  1308
    & @{text "|"} & @{text proof} @{verbatim "%%"} @{text proof} \\
4cfa094da3cb more on concrete syntax of proof terms;
wenzelm
parents: 52411
diff changeset
  1309
    & @{text "|"} & @{text proof} @{text "\<bullet>"} @{text proof} \\
4cfa094da3cb more on concrete syntax of proof terms;
wenzelm
parents: 52411
diff changeset
  1310
    & @{text "|"} & @{text "id  |  longid"} \\
4cfa094da3cb more on concrete syntax of proof terms;
wenzelm
parents: 52411
diff changeset
  1311
  \\
4cfa094da3cb more on concrete syntax of proof terms;
wenzelm
parents: 52411
diff changeset
  1312
4cfa094da3cb more on concrete syntax of proof terms;
wenzelm
parents: 52411
diff changeset
  1313
  @{text param} & = & @{text idt} \\
4cfa094da3cb more on concrete syntax of proof terms;
wenzelm
parents: 52411
diff changeset
  1314
    & @{text "|"} & @{text idt} @{verbatim ":"} @{text prop} \\
4cfa094da3cb more on concrete syntax of proof terms;
wenzelm
parents: 52411
diff changeset
  1315
    & @{text "|"} & @{verbatim "("} @{text param} @{verbatim ")"} \\
4cfa094da3cb more on concrete syntax of proof terms;
wenzelm
parents: 52411
diff changeset
  1316
  \\
4cfa094da3cb more on concrete syntax of proof terms;
wenzelm
parents: 52411
diff changeset
  1317
4cfa094da3cb more on concrete syntax of proof terms;
wenzelm
parents: 52411
diff changeset
  1318
  @{text params} & = & @{text param} \\
4cfa094da3cb more on concrete syntax of proof terms;
wenzelm
parents: 52411
diff changeset
  1319
    & @{text "|"} & @{text param} @{text params} \\
4cfa094da3cb more on concrete syntax of proof terms;
wenzelm
parents: 52411
diff changeset
  1320
4cfa094da3cb more on concrete syntax of proof terms;
wenzelm
parents: 52411
diff changeset
  1321
  \end{supertabular}
4cfa094da3cb more on concrete syntax of proof terms;
wenzelm
parents: 52411
diff changeset
  1322
  \end{center}
4cfa094da3cb more on concrete syntax of proof terms;
wenzelm
parents: 52411
diff changeset
  1323
4cfa094da3cb more on concrete syntax of proof terms;
wenzelm
parents: 52411
diff changeset
  1324
  Implicit term arguments in partial proofs are indicated by ``@{text
4cfa094da3cb more on concrete syntax of proof terms;
wenzelm
parents: 52411
diff changeset
  1325
  "_"}''.  Type arguments for theorems and axioms may be specified
4cfa094da3cb more on concrete syntax of proof terms;
wenzelm
parents: 52411
diff changeset
  1326
  using @{text "p \<cdot> TYPE(type)"} (they must appear before any other
4cfa094da3cb more on concrete syntax of proof terms;
wenzelm
parents: 52411
diff changeset
  1327
  term argument of a theorem or axiom, but may be omitted altogether).
4cfa094da3cb more on concrete syntax of proof terms;
wenzelm
parents: 52411
diff changeset
  1328
4cfa094da3cb more on concrete syntax of proof terms;
wenzelm
parents: 52411
diff changeset
  1329
  \medskip There are separate read and print operations for proof
4cfa094da3cb more on concrete syntax of proof terms;
wenzelm
parents: 52411
diff changeset
  1330
  terms, in order to avoid conflicts with the regular term language.
58618
782f0b662cae more cartouches;
wenzelm
parents: 58555
diff changeset
  1331
\<close>
52412
4cfa094da3cb more on concrete syntax of proof terms;
wenzelm
parents: 52411
diff changeset
  1332
58618
782f0b662cae more cartouches;
wenzelm
parents: 58555
diff changeset
  1333
text %mlref \<open>
52408
fa2dc6c6c94f updated operations on proof terms;
wenzelm
parents: 52407
diff changeset
  1334
  \begin{mldecls}
fa2dc6c6c94f updated operations on proof terms;
wenzelm
parents: 52407
diff changeset
  1335
  @{index_ML_type proof} \\
fa2dc6c6c94f updated operations on proof terms;
wenzelm
parents: 52407
diff changeset
  1336
  @{index_ML_type proof_body} \\
52487
48bc24467008 backout dedd7952a62c: static "proofs" value within theory prevents later inferencing with different configuration;
wenzelm
parents: 52486
diff changeset
  1337
  @{index_ML proofs: "int Unsynchronized.ref"} \\
52411
f192c4ea5b17 more on reconstructing and checking proof terms;
wenzelm
parents: 52410
diff changeset
  1338
  @{index_ML Reconstruct.reconstruct_proof:
f192c4ea5b17 more on reconstructing and checking proof terms;
wenzelm
parents: 52410
diff changeset
  1339
  "theory -> term -> proof -> proof"} \\
f192c4ea5b17 more on reconstructing and checking proof terms;
wenzelm
parents: 52410
diff changeset
  1340
  @{index_ML Reconstruct.expand_proof: "theory ->
f192c4ea5b17 more on reconstructing and checking proof terms;
wenzelm
parents: 52410
diff changeset
  1341
  (string * term option) list -> proof -> proof"} \\
52412
4cfa094da3cb more on concrete syntax of proof terms;
wenzelm
parents: 52411
diff changeset
  1342
  @{index_ML Proof_Checker.thm_of_proof: "theory -> proof -> thm"} \\
4cfa094da3cb more on concrete syntax of proof terms;
wenzelm
parents: 52411
diff changeset
  1343
  @{index_ML Proof_Syntax.read_proof: "theory -> bool -> bool -> string -> proof"} \\
4cfa094da3cb more on concrete syntax of proof terms;
wenzelm
parents: 52411
diff changeset
  1344
  @{index_ML Proof_Syntax.pretty_proof: "Proof.context -> proof -> Pretty.T"} \\
52408
fa2dc6c6c94f updated operations on proof terms;
wenzelm
parents: 52407
diff changeset
  1345
  \end{mldecls}
fa2dc6c6c94f updated operations on proof terms;
wenzelm
parents: 52407
diff changeset
  1346
fa2dc6c6c94f updated operations on proof terms;
wenzelm
parents: 52407
diff changeset
  1347
  \begin{description}
fa2dc6c6c94f updated operations on proof terms;
wenzelm
parents: 52407
diff changeset
  1348
fa2dc6c6c94f updated operations on proof terms;
wenzelm
parents: 52407
diff changeset
  1349
  \item Type @{ML_type proof} represents proof terms; this is a
fa2dc6c6c94f updated operations on proof terms;
wenzelm
parents: 52407
diff changeset
  1350
  datatype with constructors @{index_ML Abst}, @{index_ML AbsP},
fa2dc6c6c94f updated operations on proof terms;
wenzelm
parents: 52407
diff changeset
  1351
  @{index_ML_op "%"}, @{index_ML_op "%%"}, @{index_ML PBound},
fa2dc6c6c94f updated operations on proof terms;
wenzelm
parents: 52407
diff changeset
  1352
  @{index_ML MinProof}, @{index_ML Hyp}, @{index_ML PAxm}, @{index_ML
fa2dc6c6c94f updated operations on proof terms;
wenzelm
parents: 52407
diff changeset
  1353
  Oracle}, @{index_ML Promise}, @{index_ML PThm} as explained above.
52436
wenzelm
parents: 52422
diff changeset
  1354
  %FIXME OfClass (!?)
52408
fa2dc6c6c94f updated operations on proof terms;
wenzelm
parents: 52407
diff changeset
  1355
fa2dc6c6c94f updated operations on proof terms;
wenzelm
parents: 52407
diff changeset
  1356
  \item Type @{ML_type proof_body} represents the nested proof
fa2dc6c6c94f updated operations on proof terms;
wenzelm
parents: 52407
diff changeset
  1357
  information of a named theorem, consisting of a digest of oracles
fa2dc6c6c94f updated operations on proof terms;
wenzelm
parents: 52407
diff changeset
  1358
  and named theorem over some proof term.  The digest only covers the
fa2dc6c6c94f updated operations on proof terms;
wenzelm
parents: 52407
diff changeset
  1359
  directly visible part of the proof: in order to get the full
fa2dc6c6c94f updated operations on proof terms;
wenzelm
parents: 52407
diff changeset
  1360
  information, the implicit graph of nested theorems needs to be
fa2dc6c6c94f updated operations on proof terms;
wenzelm
parents: 52407
diff changeset
  1361
  traversed (e.g.\ using @{ML Proofterm.fold_body_thms}).
fa2dc6c6c94f updated operations on proof terms;
wenzelm
parents: 52407
diff changeset
  1362
fa2dc6c6c94f updated operations on proof terms;
wenzelm
parents: 52407
diff changeset
  1363
  \item @{ML Thm.proof_of}~@{text "thm"} and @{ML
fa2dc6c6c94f updated operations on proof terms;
wenzelm
parents: 52407
diff changeset
  1364
  Thm.proof_body_of}~@{text "thm"} produce the proof term or proof
fa2dc6c6c94f updated operations on proof terms;
wenzelm
parents: 52407
diff changeset
  1365
  body (with digest of oracles and theorems) from a given theorem.
fa2dc6c6c94f updated operations on proof terms;
wenzelm
parents: 52407
diff changeset
  1366
  Note that this involves a full join of internal futures that fulfill
fa2dc6c6c94f updated operations on proof terms;
wenzelm
parents: 52407
diff changeset
  1367
  pending proof promises, and thus disrupts the natural bottom-up
fa2dc6c6c94f updated operations on proof terms;
wenzelm
parents: 52407
diff changeset
  1368
  construction of proofs by introducing dynamic ad-hoc dependencies.
fa2dc6c6c94f updated operations on proof terms;
wenzelm
parents: 52407
diff changeset
  1369
  Parallel performance may suffer by inspecting proof terms at
fa2dc6c6c94f updated operations on proof terms;
wenzelm
parents: 52407
diff changeset
  1370
  run-time.
fa2dc6c6c94f updated operations on proof terms;
wenzelm
parents: 52407
diff changeset
  1371
52487
48bc24467008 backout dedd7952a62c: static "proofs" value within theory prevents later inferencing with different configuration;
wenzelm
parents: 52486
diff changeset
  1372
  \item @{ML proofs} specifies the detail of proof recording within
48bc24467008 backout dedd7952a62c: static "proofs" value within theory prevents later inferencing with different configuration;
wenzelm
parents: 52486
diff changeset
  1373
  @{ML_type thm} values produced by the inference kernel: @{ML 0}
48bc24467008 backout dedd7952a62c: static "proofs" value within theory prevents later inferencing with different configuration;
wenzelm
parents: 52486
diff changeset
  1374
  records only the names of oracles, @{ML 1} records oracle names and
48bc24467008 backout dedd7952a62c: static "proofs" value within theory prevents later inferencing with different configuration;
wenzelm
parents: 52486
diff changeset
  1375
  propositions, @{ML 2} additionally records full proof terms.
48bc24467008 backout dedd7952a62c: static "proofs" value within theory prevents later inferencing with different configuration;
wenzelm
parents: 52486
diff changeset
  1376
  Officially named theorems that contribute to a result are recorded
48bc24467008 backout dedd7952a62c: static "proofs" value within theory prevents later inferencing with different configuration;
wenzelm
parents: 52486
diff changeset
  1377
  in any case.
48bc24467008 backout dedd7952a62c: static "proofs" value within theory prevents later inferencing with different configuration;
wenzelm
parents: 52486
diff changeset
  1378
52411
f192c4ea5b17 more on reconstructing and checking proof terms;
wenzelm
parents: 52410
diff changeset
  1379
  \item @{ML Reconstruct.reconstruct_proof}~@{text "thy prop prf"}
f192c4ea5b17 more on reconstructing and checking proof terms;
wenzelm
parents: 52410
diff changeset
  1380
  turns the implicit proof term @{text "prf"} into a full proof of the
f192c4ea5b17 more on reconstructing and checking proof terms;
wenzelm
parents: 52410
diff changeset
  1381
  given proposition.
f192c4ea5b17 more on reconstructing and checking proof terms;
wenzelm
parents: 52410
diff changeset
  1382
f192c4ea5b17 more on reconstructing and checking proof terms;
wenzelm
parents: 52410
diff changeset
  1383
  Reconstruction may fail if @{text "prf"} is not a proof of @{text
f192c4ea5b17 more on reconstructing and checking proof terms;
wenzelm
parents: 52410
diff changeset
  1384
  "prop"}, or if it does not contain sufficient information for
f192c4ea5b17 more on reconstructing and checking proof terms;
wenzelm
parents: 52410
diff changeset
  1385
  reconstruction.  Failure may only happen for proofs that are
f192c4ea5b17 more on reconstructing and checking proof terms;
wenzelm
parents: 52410
diff changeset
  1386
  constructed manually, but not for those produced automatically by
f192c4ea5b17 more on reconstructing and checking proof terms;
wenzelm
parents: 52410
diff changeset
  1387
  the inference kernel.
f192c4ea5b17 more on reconstructing and checking proof terms;
wenzelm
parents: 52410
diff changeset
  1388
f192c4ea5b17 more on reconstructing and checking proof terms;
wenzelm
parents: 52410
diff changeset
  1389
  \item @{ML Reconstruct.expand_proof}~@{text "thy [thm\<^sub>1, \<dots>, thm\<^sub>n]
f192c4ea5b17 more on reconstructing and checking proof terms;
wenzelm
parents: 52410
diff changeset
  1390
  prf"} expands and reconstructs the proofs of all specified theorems,
f192c4ea5b17 more on reconstructing and checking proof terms;
wenzelm
parents: 52410
diff changeset
  1391
  with the given (full) proof.  Theorems that are not unique specified
f192c4ea5b17 more on reconstructing and checking proof terms;
wenzelm
parents: 52410
diff changeset
  1392
  via their name may be disambiguated by giving their proposition.
f192c4ea5b17 more on reconstructing and checking proof terms;
wenzelm
parents: 52410
diff changeset
  1393
f192c4ea5b17 more on reconstructing and checking proof terms;
wenzelm
parents: 52410
diff changeset
  1394
  \item @{ML Proof_Checker.thm_of_proof}~@{text "thy prf"} turns the
f192c4ea5b17 more on reconstructing and checking proof terms;
wenzelm
parents: 52410
diff changeset
  1395
  given (full) proof into a theorem, by replaying it using only
f192c4ea5b17 more on reconstructing and checking proof terms;
wenzelm
parents: 52410
diff changeset
  1396
  primitive rules of the inference kernel.
f192c4ea5b17 more on reconstructing and checking proof terms;
wenzelm
parents: 52410
diff changeset
  1397
52412
4cfa094da3cb more on concrete syntax of proof terms;
wenzelm
parents: 52411
diff changeset
  1398
  \item @{ML Proof_Syntax.read_proof}~@{text "thy b\<^sub>1 b\<^sub>2 s"} reads in a
4cfa094da3cb more on concrete syntax of proof terms;
wenzelm
parents: 52411
diff changeset
  1399
  proof term. The Boolean flags indicate the use of sort and type
4cfa094da3cb more on concrete syntax of proof terms;
wenzelm
parents: 52411
diff changeset
  1400
  information.  Usually, typing information is left implicit and is
4cfa094da3cb more on concrete syntax of proof terms;
wenzelm
parents: 52411
diff changeset
  1401
  inferred during proof reconstruction.  %FIXME eliminate flags!?
4cfa094da3cb more on concrete syntax of proof terms;
wenzelm
parents: 52411
diff changeset
  1402
4cfa094da3cb more on concrete syntax of proof terms;
wenzelm
parents: 52411
diff changeset
  1403
  \item @{ML Proof_Syntax.pretty_proof}~@{text "ctxt prf"}
4cfa094da3cb more on concrete syntax of proof terms;
wenzelm
parents: 52411
diff changeset
  1404
  pretty-prints the given proof term.
4cfa094da3cb more on concrete syntax of proof terms;
wenzelm
parents: 52411
diff changeset
  1405
52408
fa2dc6c6c94f updated operations on proof terms;
wenzelm
parents: 52407
diff changeset
  1406
  \end{description}
58618
782f0b662cae more cartouches;
wenzelm
parents: 58555
diff changeset
  1407
\<close>
52408
fa2dc6c6c94f updated operations on proof terms;
wenzelm
parents: 52407
diff changeset
  1408
58618
782f0b662cae more cartouches;
wenzelm
parents: 58555
diff changeset
  1409
text %mlex \<open>Detailed proof information of a theorem may be retrieved
782f0b662cae more cartouches;
wenzelm
parents: 58555
diff changeset
  1410
  as follows:\<close>
52410
fb1fb867c146 more examples on proof terms;
wenzelm
parents: 52408
diff changeset
  1411
fb1fb867c146 more examples on proof terms;
wenzelm
parents: 52408
diff changeset
  1412
lemma ex: "A \<and> B \<longrightarrow> B \<and> A"
fb1fb867c146 more examples on proof terms;
wenzelm
parents: 52408
diff changeset
  1413
proof
fb1fb867c146 more examples on proof terms;
wenzelm
parents: 52408
diff changeset
  1414
  assume "A \<and> B"
fb1fb867c146 more examples on proof terms;
wenzelm
parents: 52408
diff changeset
  1415
  then obtain B and A ..
fb1fb867c146 more examples on proof terms;
wenzelm
parents: 52408
diff changeset
  1416
  then show "B \<and> A" ..
fb1fb867c146 more examples on proof terms;
wenzelm
parents: 52408
diff changeset
  1417
qed
fb1fb867c146 more examples on proof terms;
wenzelm
parents: 52408
diff changeset
  1418
58618
782f0b662cae more cartouches;
wenzelm
parents: 58555
diff changeset
  1419
ML_val \<open>
52410
fb1fb867c146 more examples on proof terms;
wenzelm
parents: 52408
diff changeset
  1420
  (*proof body with digest*)
fb1fb867c146 more examples on proof terms;
wenzelm
parents: 52408
diff changeset
  1421
  val body = Proofterm.strip_thm (Thm.proof_body_of @{thm ex});
fb1fb867c146 more examples on proof terms;
wenzelm
parents: 52408
diff changeset
  1422
fb1fb867c146 more examples on proof terms;
wenzelm
parents: 52408
diff changeset
  1423
  (*proof term only*)
fb1fb867c146 more examples on proof terms;
wenzelm
parents: 52408
diff changeset
  1424
  val prf = Proofterm.proof_of body;
fb1fb867c146 more examples on proof terms;
wenzelm
parents: 52408
diff changeset
  1425
  Pretty.writeln (Proof_Syntax.pretty_proof @{context} prf);
fb1fb867c146 more examples on proof terms;
wenzelm
parents: 52408
diff changeset
  1426
fb1fb867c146 more examples on proof terms;
wenzelm
parents: 52408
diff changeset
  1427
  (*all theorems used in the graph of nested proofs*)
fb1fb867c146 more examples on proof terms;
wenzelm
parents: 52408
diff changeset
  1428
  val all_thms =
fb1fb867c146 more examples on proof terms;
wenzelm
parents: 52408
diff changeset
  1429
    Proofterm.fold_body_thms
fb1fb867c146 more examples on proof terms;
wenzelm
parents: 52408
diff changeset
  1430
      (fn (name, _, _) => insert (op =) name) [body] [];
58618
782f0b662cae more cartouches;
wenzelm
parents: 58555
diff changeset
  1431
\<close>
52410
fb1fb867c146 more examples on proof terms;
wenzelm
parents: 52408
diff changeset
  1432
58618
782f0b662cae more cartouches;
wenzelm
parents: 58555
diff changeset
  1433
text \<open>The result refers to various basic facts of Isabelle/HOL:
52410
fb1fb867c146 more examples on proof terms;
wenzelm
parents: 52408
diff changeset
  1434
  @{thm [source] HOL.impI}, @{thm [source] HOL.conjE}, @{thm [source]
fb1fb867c146 more examples on proof terms;
wenzelm
parents: 52408
diff changeset
  1435
  HOL.conjI} etc.  The combinator @{ML Proofterm.fold_body_thms}
fb1fb867c146 more examples on proof terms;
wenzelm
parents: 52408
diff changeset
  1436
  recursively explores the graph of the proofs of all theorems being
fb1fb867c146 more examples on proof terms;
wenzelm
parents: 52408
diff changeset
  1437
  used here.
fb1fb867c146 more examples on proof terms;
wenzelm
parents: 52408
diff changeset
  1438
fb1fb867c146 more examples on proof terms;
wenzelm
parents: 52408
diff changeset
  1439
  \medskip Alternatively, we may produce a proof term manually, and
58618
782f0b662cae more cartouches;
wenzelm
parents: 58555
diff changeset
  1440
  turn it into a theorem as follows:\<close>
52410
fb1fb867c146 more examples on proof terms;
wenzelm
parents: 52408
diff changeset
  1441
58618
782f0b662cae more cartouches;
wenzelm
parents: 58555
diff changeset
  1442
ML_val \<open>
52410
fb1fb867c146 more examples on proof terms;
wenzelm
parents: 52408
diff changeset
  1443
  val thy = @{theory};
fb1fb867c146 more examples on proof terms;
wenzelm
parents: 52408
diff changeset
  1444
  val prf =
fb1fb867c146 more examples on proof terms;
wenzelm
parents: 52408
diff changeset
  1445
    Proof_Syntax.read_proof thy true false
fb1fb867c146 more examples on proof terms;
wenzelm
parents: 52408
diff changeset
  1446
      "impI \<cdot> _ \<cdot> _ \<bullet> \
52486
b1565e37678b just one alternative proof syntax, which also works for Proof_Syntax.pretty_proof/Proof_Syntax.read_proof roundtrip;
wenzelm
parents: 52470
diff changeset
  1447
      \   (\<^bold>\<lambda>H: _. \
52410
fb1fb867c146 more examples on proof terms;
wenzelm
parents: 52408
diff changeset
  1448
      \     conjE \<cdot> _ \<cdot> _ \<cdot> _ \<bullet> H \<bullet> \
52486
b1565e37678b just one alternative proof syntax, which also works for Proof_Syntax.pretty_proof/Proof_Syntax.read_proof roundtrip;
wenzelm
parents: 52470
diff changeset
  1449
      \       (\<^bold>\<lambda>(H: _) Ha: _. conjI \<cdot> _ \<cdot> _ \<bullet> Ha \<bullet> H))";
52410
fb1fb867c146 more examples on proof terms;
wenzelm
parents: 52408
diff changeset
  1450
  val thm =
fb1fb867c146 more examples on proof terms;
wenzelm
parents: 52408
diff changeset
  1451
    prf
fb1fb867c146 more examples on proof terms;
wenzelm
parents: 52408
diff changeset
  1452
    |> Reconstruct.reconstruct_proof thy @{prop "A \<and> B \<longrightarrow> B \<and> A"}
fb1fb867c146 more examples on proof terms;
wenzelm
parents: 52408
diff changeset
  1453
    |> Proof_Checker.thm_of_proof thy
fb1fb867c146 more examples on proof terms;
wenzelm
parents: 52408
diff changeset
  1454
    |> Drule.export_without_context;
58618
782f0b662cae more cartouches;
wenzelm
parents: 58555
diff changeset
  1455
\<close>
52410
fb1fb867c146 more examples on proof terms;
wenzelm
parents: 52408
diff changeset
  1456
58618
782f0b662cae more cartouches;
wenzelm
parents: 58555
diff changeset
  1457
text \<open>\medskip See also @{file "~~/src/HOL/Proofs/ex/XML_Data.thy"}
52630
fe411c1dc180 more robust proof export / import due to Stefan Berghofer;
wenzelm
parents: 52487
diff changeset
  1458
  for further examples, with export and import of proof terms via
fe411c1dc180 more robust proof export / import due to Stefan Berghofer;
wenzelm
parents: 52487
diff changeset
  1459
  XML/ML data representation.
58618
782f0b662cae more cartouches;
wenzelm
parents: 58555
diff changeset
  1460
\<close>
52410
fb1fb867c146 more examples on proof terms;
wenzelm
parents: 52408
diff changeset
  1461
18537
2681f9e34390 "The Isabelle/Isar Implementation" manual;
wenzelm
parents:
diff changeset
  1462
end