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