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