src/Doc/Implementation/Logic.thy
changeset 69597 ff784d5a5bfb
parent 69307 196347d2fd2d
child 70389 2adff54de67e
equal deleted inserted replaced
69596:c8a2755bf220 69597:ff784d5a5bfb
   118   @{index_ML Sign.primitive_class: "binding * class list -> theory -> theory"} \\
   118   @{index_ML Sign.primitive_class: "binding * class list -> theory -> theory"} \\
   119   @{index_ML Sign.primitive_classrel: "class * class -> theory -> theory"} \\
   119   @{index_ML Sign.primitive_classrel: "class * class -> theory -> theory"} \\
   120   @{index_ML Sign.primitive_arity: "arity -> theory -> theory"} \\
   120   @{index_ML Sign.primitive_arity: "arity -> theory -> theory"} \\
   121   \end{mldecls}
   121   \end{mldecls}
   122 
   122 
   123   \<^descr> Type @{ML_type class} represents type classes.
   123   \<^descr> Type \<^ML_type>\<open>class\<close> represents type classes.
   124 
   124 
   125   \<^descr> Type @{ML_type sort} represents sorts, i.e.\ finite intersections of
   125   \<^descr> Type \<^ML_type>\<open>sort\<close> represents sorts, i.e.\ finite intersections of
   126   classes. The empty list @{ML "[]: sort"} refers to the empty class
   126   classes. The empty list \<^ML>\<open>[]: sort\<close> refers to the empty class
   127   intersection, i.e.\ the ``full sort''.
   127   intersection, i.e.\ the ``full sort''.
   128 
   128 
   129   \<^descr> Type @{ML_type arity} represents type arities. A triple \<open>(\<kappa>, \<^vec>s, s)
   129   \<^descr> Type \<^ML_type>\<open>arity\<close> represents type arities. A triple \<open>(\<kappa>, \<^vec>s, s)
   130   : arity\<close> represents \<open>\<kappa> :: (\<^vec>s)s\<close> as described above.
   130   : arity\<close> represents \<open>\<kappa> :: (\<^vec>s)s\<close> as described above.
   131 
   131 
   132   \<^descr> Type @{ML_type typ} represents types; this is a datatype with constructors
   132   \<^descr> Type \<^ML_type>\<open>typ\<close> represents types; this is a datatype with constructors
   133   @{ML TFree}, @{ML TVar}, @{ML Type}.
   133   \<^ML>\<open>TFree\<close>, \<^ML>\<open>TVar\<close>, \<^ML>\<open>Type\<close>.
   134 
   134 
   135   \<^descr> @{ML Term.map_atyps}~\<open>f \<tau>\<close> applies the mapping \<open>f\<close> to all atomic types
   135   \<^descr> \<^ML>\<open>Term.map_atyps\<close>~\<open>f \<tau>\<close> applies the mapping \<open>f\<close> to all atomic types
   136   (@{ML TFree}, @{ML TVar}) occurring in \<open>\<tau>\<close>.
   136   (\<^ML>\<open>TFree\<close>, \<^ML>\<open>TVar\<close>) occurring in \<open>\<tau>\<close>.
   137 
   137 
   138   \<^descr> @{ML Term.fold_atyps}~\<open>f \<tau>\<close> iterates the operation \<open>f\<close> over all
   138   \<^descr> \<^ML>\<open>Term.fold_atyps\<close>~\<open>f \<tau>\<close> iterates the operation \<open>f\<close> over all
   139   occurrences of atomic types (@{ML TFree}, @{ML TVar}) in \<open>\<tau>\<close>; the type
   139   occurrences of atomic types (\<^ML>\<open>TFree\<close>, \<^ML>\<open>TVar\<close>) in \<open>\<tau>\<close>; the type
   140   structure is traversed from left to right.
   140   structure is traversed from left to right.
   141 
   141 
   142   \<^descr> @{ML Sign.subsort}~\<open>thy (s\<^sub>1, s\<^sub>2)\<close> tests the subsort relation \<open>s\<^sub>1 \<subseteq>
   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>
   143   s\<^sub>2\<close>.
   143   s\<^sub>2\<close>.
   144 
   144 
   145   \<^descr> @{ML Sign.of_sort}~\<open>thy (\<tau>, s)\<close> tests whether type \<open>\<tau>\<close> is of sort \<open>s\<close>.
   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>.
   146 
   146 
   147   \<^descr> @{ML Sign.add_type}~\<open>ctxt (\<kappa>, k, mx)\<close> declares a new type constructors \<open>\<kappa>\<close>
   147   \<^descr> \<^ML>\<open>Sign.add_type\<close>~\<open>ctxt (\<kappa>, k, mx)\<close> declares a new type constructors \<open>\<kappa>\<close>
   148   with \<open>k\<close> arguments and optional mixfix syntax.
   148   with \<open>k\<close> arguments and optional mixfix syntax.
   149 
   149 
   150   \<^descr> @{ML Sign.add_type_abbrev}~\<open>ctxt (\<kappa>, \<^vec>\<alpha>, \<tau>)\<close> defines a new type
   150   \<^descr> \<^ML>\<open>Sign.add_type_abbrev\<close>~\<open>ctxt (\<kappa>, \<^vec>\<alpha>, \<tau>)\<close> defines a new type
   151   abbreviation \<open>(\<^vec>\<alpha>)\<kappa> = \<tau>\<close>.
   151   abbreviation \<open>(\<^vec>\<alpha>)\<kappa> = \<tau>\<close>.
   152 
   152 
   153   \<^descr> @{ML Sign.primitive_class}~\<open>(c, [c\<^sub>1, \<dots>, c\<^sub>n])\<close> declares a new class \<open>c\<close>,
   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>,
   154   together with class relations \<open>c \<subseteq> c\<^sub>i\<close>, for \<open>i = 1, \<dots>, n\<close>.
   154   together with class relations \<open>c \<subseteq> c\<^sub>i\<close>, for \<open>i = 1, \<dots>, n\<close>.
   155 
   155 
   156   \<^descr> @{ML Sign.primitive_classrel}~\<open>(c\<^sub>1, c\<^sub>2)\<close> declares the class relation
   156   \<^descr> \<^ML>\<open>Sign.primitive_classrel\<close>~\<open>(c\<^sub>1, c\<^sub>2)\<close> declares the class relation
   157   \<open>c\<^sub>1 \<subseteq> c\<^sub>2\<close>.
   157   \<open>c\<^sub>1 \<subseteq> c\<^sub>2\<close>.
   158 
   158 
   159   \<^descr> @{ML Sign.primitive_arity}~\<open>(\<kappa>, \<^vec>s, s)\<close> declares the arity \<open>\<kappa> ::
   159   \<^descr> \<^ML>\<open>Sign.primitive_arity\<close>~\<open>(\<kappa>, \<^vec>s, s)\<close> declares the arity \<open>\<kappa> ::
   160   (\<^vec>s)s\<close>.
   160   (\<^vec>s)s\<close>.
   161 \<close>
   161 \<close>
   162 
   162 
   163 text %mlantiq \<open>
   163 text %mlantiq \<open>
   164   \begin{matharray}{rcl}
   164   \begin{matharray}{rcl}
   168   @{ML_antiquotation_def "type_abbrev"} & : & \<open>ML_antiquotation\<close> \\
   168   @{ML_antiquotation_def "type_abbrev"} & : & \<open>ML_antiquotation\<close> \\
   169   @{ML_antiquotation_def "nonterminal"} & : & \<open>ML_antiquotation\<close> \\
   169   @{ML_antiquotation_def "nonterminal"} & : & \<open>ML_antiquotation\<close> \\
   170   @{ML_antiquotation_def "typ"} & : & \<open>ML_antiquotation\<close> \\
   170   @{ML_antiquotation_def "typ"} & : & \<open>ML_antiquotation\<close> \\
   171   \end{matharray}
   171   \end{matharray}
   172 
   172 
   173   @{rail \<open>
   173   \<^rail>\<open>
   174   @@{ML_antiquotation class} embedded
   174   @@{ML_antiquotation class} embedded
   175   ;
   175   ;
   176   @@{ML_antiquotation sort} sort
   176   @@{ML_antiquotation sort} sort
   177   ;
   177   ;
   178   (@@{ML_antiquotation type_name} |
   178   (@@{ML_antiquotation type_name} |
   179    @@{ML_antiquotation type_abbrev} |
   179    @@{ML_antiquotation type_abbrev} |
   180    @@{ML_antiquotation nonterminal}) embedded
   180    @@{ML_antiquotation nonterminal}) embedded
   181   ;
   181   ;
   182   @@{ML_antiquotation typ} type
   182   @@{ML_antiquotation typ} type
   183   \<close>}
   183   \<close>
   184 
   184 
   185   \<^descr> \<open>@{class c}\<close> inlines the internalized class \<open>c\<close> --- as @{ML_type string}
   185   \<^descr> \<open>@{class c}\<close> inlines the internalized class \<open>c\<close> --- as \<^ML_type>\<open>string\<close>
   186   literal.
   186   literal.
   187 
   187 
   188   \<^descr> \<open>@{sort s}\<close> inlines the internalized sort \<open>s\<close> --- as @{ML_type "string
   188   \<^descr> \<open>@{sort s}\<close> inlines the internalized sort \<open>s\<close> --- as \<^ML_type>\<open>string
   189   list"} literal.
   189   list\<close> literal.
   190 
   190 
   191   \<^descr> \<open>@{type_name c}\<close> inlines the internalized type constructor \<open>c\<close> --- as
   191   \<^descr> \<open>@{type_name c}\<close> inlines the internalized type constructor \<open>c\<close> --- as
   192   @{ML_type string} literal.
   192   \<^ML_type>\<open>string\<close> literal.
   193 
   193 
   194   \<^descr> \<open>@{type_abbrev c}\<close> inlines the internalized type abbreviation \<open>c\<close> --- as
   194   \<^descr> \<open>@{type_abbrev c}\<close> inlines the internalized type abbreviation \<open>c\<close> --- as
   195   @{ML_type string} literal.
   195   \<^ML_type>\<open>string\<close> literal.
   196 
   196 
   197   \<^descr> \<open>@{nonterminal c}\<close> inlines the internalized syntactic type~/ grammar
   197   \<^descr> \<open>@{nonterminal c}\<close> inlines the internalized syntactic type~/ grammar
   198   nonterminal \<open>c\<close> --- as @{ML_type string} literal.
   198   nonterminal \<open>c\<close> --- as \<^ML_type>\<open>string\<close> literal.
   199 
   199 
   200   \<^descr> \<open>@{typ \<tau>}\<close> inlines the internalized type \<open>\<tau>\<close> --- as constructor term for
   200   \<^descr> \<open>@{typ \<tau>}\<close> inlines the internalized type \<open>\<tau>\<close> --- as constructor term for
   201   datatype @{ML_type typ}.
   201   datatype \<^ML_type>\<open>typ\<close>.
   202 \<close>
   202 \<close>
   203 
   203 
   204 
   204 
   205 section \<open>Terms \label{sec:terms}\<close>
   205 section \<open>Terms \label{sec:terms}\<close>
   206 
   206 
   331   theory -> (term * term) * theory"} \\
   331   theory -> (term * term) * theory"} \\
   332   @{index_ML Sign.const_typargs: "theory -> string * typ -> typ list"} \\
   332   @{index_ML Sign.const_typargs: "theory -> string * typ -> typ list"} \\
   333   @{index_ML Sign.const_instance: "theory -> string * typ list -> typ"} \\
   333   @{index_ML Sign.const_instance: "theory -> string * typ list -> typ"} \\
   334   \end{mldecls}
   334   \end{mldecls}
   335 
   335 
   336   \<^descr> Type @{ML_type term} represents de-Bruijn terms, with comments in
   336   \<^descr> Type \<^ML_type>\<open>term\<close> represents de-Bruijn terms, with comments in
   337   abstractions, and explicitly named free variables and constants; this is a
   337   abstractions, and explicitly named free variables and constants; this is a
   338   datatype with constructors @{index_ML Bound}, @{index_ML Free}, @{index_ML
   338   datatype with constructors @{index_ML Bound}, @{index_ML Free}, @{index_ML
   339   Var}, @{index_ML Const}, @{index_ML Abs}, @{index_ML_op "$"}.
   339   Var}, @{index_ML Const}, @{index_ML Abs}, @{index_ML_op "$"}.
   340 
   340 
   341   \<^descr> \<open>t\<close>~@{ML_text aconv}~\<open>u\<close> checks \<open>\<alpha>\<close>-equivalence of two terms. This is the
   341   \<^descr> \<open>t\<close>~\<^ML_text>\<open>aconv\<close>~\<open>u\<close> checks \<open>\<alpha>\<close>-equivalence of two terms. This is the
   342   basic equality relation on type @{ML_type term}; raw datatype equality
   342   basic equality relation on type \<^ML_type>\<open>term\<close>; raw datatype equality
   343   should only be used for operations related to parsing or printing!
   343   should only be used for operations related to parsing or printing!
   344 
   344 
   345   \<^descr> @{ML Term.map_types}~\<open>f t\<close> applies the mapping \<open>f\<close> to all types occurring
   345   \<^descr> \<^ML>\<open>Term.map_types\<close>~\<open>f t\<close> applies the mapping \<open>f\<close> to all types occurring
   346   in \<open>t\<close>.
   346   in \<open>t\<close>.
   347 
   347 
   348   \<^descr> @{ML Term.fold_types}~\<open>f t\<close> iterates the operation \<open>f\<close> over all
   348   \<^descr> \<^ML>\<open>Term.fold_types\<close>~\<open>f t\<close> iterates the operation \<open>f\<close> over all
   349   occurrences of types in \<open>t\<close>; the term structure is traversed from left to
   349   occurrences of types in \<open>t\<close>; the term structure is traversed from left to
   350   right.
   350   right.
   351 
   351 
   352   \<^descr> @{ML Term.map_aterms}~\<open>f t\<close> applies the mapping \<open>f\<close> to all atomic terms
   352   \<^descr> \<^ML>\<open>Term.map_aterms\<close>~\<open>f t\<close> applies the mapping \<open>f\<close> to all atomic terms
   353   (@{ML Bound}, @{ML Free}, @{ML Var}, @{ML Const}) occurring in \<open>t\<close>.
   353   (\<^ML>\<open>Bound\<close>, \<^ML>\<open>Free\<close>, \<^ML>\<open>Var\<close>, \<^ML>\<open>Const\<close>) occurring in \<open>t\<close>.
   354 
   354 
   355   \<^descr> @{ML Term.fold_aterms}~\<open>f t\<close> iterates the operation \<open>f\<close> over all
   355   \<^descr> \<^ML>\<open>Term.fold_aterms\<close>~\<open>f t\<close> iterates the operation \<open>f\<close> over all
   356   occurrences of atomic terms (@{ML Bound}, @{ML Free}, @{ML Var}, @{ML
   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.
   357   Const}) in \<open>t\<close>; the term structure is traversed from left to right.
   357 
   358 
   358   \<^descr> \<^ML>\<open>fastype_of\<close>~\<open>t\<close> determines the type of a well-typed term. This
   359   \<^descr> @{ML fastype_of}~\<open>t\<close> determines the type of a well-typed term. This
       
   360   operation is relatively slow, despite the omission of any sanity checks.
   359   operation is relatively slow, despite the omission of any sanity checks.
   361 
   360 
   362   \<^descr> @{ML lambda}~\<open>a b\<close> produces an abstraction \<open>\<lambda>a. b\<close>, where occurrences of
   361   \<^descr> \<^ML>\<open>lambda\<close>~\<open>a b\<close> produces an abstraction \<open>\<lambda>a. b\<close>, where occurrences of
   363   the atomic term \<open>a\<close> in the body \<open>b\<close> are replaced by bound variables.
   362   the atomic term \<open>a\<close> in the body \<open>b\<close> are replaced by bound variables.
   364 
   363 
   365   \<^descr> @{ML betapply}~\<open>(t, u)\<close> produces an application \<open>t u\<close>, with topmost
   364   \<^descr> \<^ML>\<open>betapply\<close>~\<open>(t, u)\<close> produces an application \<open>t u\<close>, with topmost
   366   \<open>\<beta>\<close>-conversion if \<open>t\<close> is an abstraction.
   365   \<open>\<beta>\<close>-conversion if \<open>t\<close> is an abstraction.
   367 
   366 
   368   \<^descr> @{ML incr_boundvars}~\<open>j\<close> increments a term's dangling bound variables by
   367   \<^descr> \<^ML>\<open>incr_boundvars\<close>~\<open>j\<close> increments a term's dangling bound variables by
   369   the offset \<open>j\<close>. This is required when moving a subterm into a context where
   368   the offset \<open>j\<close>. This is required when moving a subterm into a context where
   370   it is enclosed by a different number of abstractions. Bound variables with a
   369   it is enclosed by a different number of abstractions. Bound variables with a
   371   matching abstraction are unaffected.
   370   matching abstraction are unaffected.
   372 
   371 
   373   \<^descr> @{ML Sign.declare_const}~\<open>ctxt ((c, \<sigma>), mx)\<close> declares a new constant \<open>c ::
   372   \<^descr> \<^ML>\<open>Sign.declare_const\<close>~\<open>ctxt ((c, \<sigma>), mx)\<close> declares a new constant \<open>c ::
   374   \<sigma>\<close> with optional mixfix syntax.
   373   \<sigma>\<close> with optional mixfix syntax.
   375 
   374 
   376   \<^descr> @{ML Sign.add_abbrev}~\<open>print_mode (c, t)\<close> introduces a new term
   375   \<^descr> \<^ML>\<open>Sign.add_abbrev\<close>~\<open>print_mode (c, t)\<close> introduces a new term
   377   abbreviation \<open>c \<equiv> t\<close>.
   376   abbreviation \<open>c \<equiv> t\<close>.
   378 
   377 
   379   \<^descr> @{ML Sign.const_typargs}~\<open>thy (c, \<tau>)\<close> and @{ML Sign.const_instance}~\<open>thy
   378   \<^descr> \<^ML>\<open>Sign.const_typargs\<close>~\<open>thy (c, \<tau>)\<close> and \<^ML>\<open>Sign.const_instance\<close>~\<open>thy
   380   (c, [\<tau>\<^sub>1, \<dots>, \<tau>\<^sub>n])\<close> convert between two representations of polymorphic
   379   (c, [\<tau>\<^sub>1, \<dots>, \<tau>\<^sub>n])\<close> convert between two representations of polymorphic
   381   constants: full type instance vs.\ compact type arguments form.
   380   constants: full type instance vs.\ compact type arguments form.
   382 \<close>
   381 \<close>
   383 
   382 
   384 text %mlantiq \<open>
   383 text %mlantiq \<open>
   388   @{ML_antiquotation_def "const"} & : & \<open>ML_antiquotation\<close> \\
   387   @{ML_antiquotation_def "const"} & : & \<open>ML_antiquotation\<close> \\
   389   @{ML_antiquotation_def "term"} & : & \<open>ML_antiquotation\<close> \\
   388   @{ML_antiquotation_def "term"} & : & \<open>ML_antiquotation\<close> \\
   390   @{ML_antiquotation_def "prop"} & : & \<open>ML_antiquotation\<close> \\
   389   @{ML_antiquotation_def "prop"} & : & \<open>ML_antiquotation\<close> \\
   391   \end{matharray}
   390   \end{matharray}
   392 
   391 
   393   @{rail \<open>
   392   \<^rail>\<open>
   394   (@@{ML_antiquotation const_name} |
   393   (@@{ML_antiquotation const_name} |
   395    @@{ML_antiquotation const_abbrev}) embedded
   394    @@{ML_antiquotation const_abbrev}) embedded
   396   ;
   395   ;
   397   @@{ML_antiquotation const} ('(' (type + ',') ')')?
   396   @@{ML_antiquotation const} ('(' (type + ',') ')')?
   398   ;
   397   ;
   399   @@{ML_antiquotation term} term
   398   @@{ML_antiquotation term} term
   400   ;
   399   ;
   401   @@{ML_antiquotation prop} prop
   400   @@{ML_antiquotation prop} prop
   402   \<close>}
   401   \<close>
   403 
   402 
   404   \<^descr> \<open>@{const_name c}\<close> inlines the internalized logical constant name \<open>c\<close> ---
   403   \<^descr> \<open>@{const_name c}\<close> inlines the internalized logical constant name \<open>c\<close> ---
   405   as @{ML_type string} literal.
   404   as \<^ML_type>\<open>string\<close> literal.
   406 
   405 
   407   \<^descr> \<open>@{const_abbrev c}\<close> inlines the internalized abbreviated constant name \<open>c\<close>
   406   \<^descr> \<open>@{const_abbrev c}\<close> inlines the internalized abbreviated constant name \<open>c\<close>
   408   --- as @{ML_type string} literal.
   407   --- as \<^ML_type>\<open>string\<close> literal.
   409 
   408 
   410   \<^descr> \<open>@{const c(\<^vec>\<tau>)}\<close> inlines the internalized constant \<open>c\<close> with precise
   409   \<^descr> \<open>@{const c(\<^vec>\<tau>)}\<close> inlines the internalized constant \<open>c\<close> with precise
   411   type instantiation in the sense of @{ML Sign.const_instance} --- as @{ML
   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>.
   412   Const} constructor term for datatype @{ML_type term}.
       
   413 
   411 
   414   \<^descr> \<open>@{term t}\<close> inlines the internalized term \<open>t\<close> --- as constructor term for
   412   \<^descr> \<open>@{term t}\<close> inlines the internalized term \<open>t\<close> --- as constructor term for
   415   datatype @{ML_type term}.
   413   datatype \<^ML_type>\<open>term\<close>.
   416 
   414 
   417   \<^descr> \<open>@{prop \<phi>}\<close> inlines the internalized proposition \<open>\<phi>\<close> --- as constructor
   415   \<^descr> \<open>@{prop \<phi>}\<close> inlines the internalized proposition \<open>\<phi>\<close> --- as constructor
   418   term for datatype @{ML_type term}.
   416   term for datatype \<^ML_type>\<open>term\<close>.
   419 \<close>
   417 \<close>
   420 
   418 
   421 
   419 
   422 section \<open>Theorems \label{sec:thms}\<close>
   420 section \<open>Theorems \label{sec:thms}\<close>
   423 
   421 
   599   \begin{mldecls}
   597   \begin{mldecls}
   600   @{index_ML Theory.add_deps: "Defs.context -> string ->
   598   @{index_ML Theory.add_deps: "Defs.context -> string ->
   601   Defs.entry -> Defs.entry list -> theory -> theory"} \\
   599   Defs.entry -> Defs.entry list -> theory -> theory"} \\
   602   \end{mldecls}
   600   \end{mldecls}
   603 
   601 
   604   \<^descr> @{ML Thm.peek_status}~\<open>thm\<close> informs about the current status of the
   602   \<^descr> \<^ML>\<open>Thm.peek_status\<close>~\<open>thm\<close> informs about the current status of the
   605   derivation object behind the given theorem. This is a snapshot of a
   603   derivation object behind the given theorem. This is a snapshot of a
   606   potentially ongoing (parallel) evaluation of proofs. The three Boolean
   604   potentially ongoing (parallel) evaluation of proofs. The three Boolean
   607   values indicate the following: \<^verbatim>\<open>oracle\<close> if the finished part contains some
   605   values indicate the following: \<^verbatim>\<open>oracle\<close> if the finished part contains some
   608   oracle invocation; \<^verbatim>\<open>unfinished\<close> if some future proofs are still pending;
   606   oracle invocation; \<^verbatim>\<open>unfinished\<close> if some future proofs are still pending;
   609   \<^verbatim>\<open>failed\<close> if some future proof has failed, rendering the theorem invalid!
   607   \<^verbatim>\<open>failed\<close> if some future proof has failed, rendering the theorem invalid!
   610 
   608 
   611   \<^descr> @{ML Logic.all}~\<open>a B\<close> produces a Pure quantification \<open>\<And>a. B\<close>, where
   609   \<^descr> \<^ML>\<open>Logic.all\<close>~\<open>a B\<close> produces a Pure quantification \<open>\<And>a. B\<close>, where
   612   occurrences of the atomic term \<open>a\<close> in the body proposition \<open>B\<close> are replaced
   610   occurrences of the atomic term \<open>a\<close> in the body proposition \<open>B\<close> are replaced
   613   by bound variables. (See also @{ML lambda} on terms.)
   611   by bound variables. (See also \<^ML>\<open>lambda\<close> on terms.)
   614 
   612 
   615   \<^descr> @{ML Logic.mk_implies}~\<open>(A, B)\<close> produces a Pure implication \<open>A \<Longrightarrow> B\<close>.
   613   \<^descr> \<^ML>\<open>Logic.mk_implies\<close>~\<open>(A, B)\<close> produces a Pure implication \<open>A \<Longrightarrow> B\<close>.
   616 
   614 
   617   \<^descr> Types @{ML_type ctyp} and @{ML_type cterm} represent certified types and
   615   \<^descr> Types \<^ML_type>\<open>ctyp\<close> and \<^ML_type>\<open>cterm\<close> represent certified types and
   618   terms, respectively. These are abstract datatypes that guarantee that its
   616   terms, respectively. These are abstract datatypes that guarantee that its
   619   values have passed the full well-formedness (and well-typedness) checks,
   617   values have passed the full well-formedness (and well-typedness) checks,
   620   relative to the declarations of type constructors, constants etc.\ in the
   618   relative to the declarations of type constructors, constants etc.\ in the
   621   background theory. The abstract types @{ML_type ctyp} and @{ML_type cterm}
   619   background theory. The abstract types \<^ML_type>\<open>ctyp\<close> and \<^ML_type>\<open>cterm\<close>
   622   are part of the same inference kernel that is mainly responsible for
   620   are part of the same inference kernel that is mainly responsible for
   623   @{ML_type thm}. Thus syntactic operations on @{ML_type ctyp} and @{ML_type
   621   \<^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
   624   cterm} are located in the @{ML_structure Thm} module, even though theorems
       
   625   are not yet involved at that stage.
   622   are not yet involved at that stage.
   626 
   623 
   627   \<^descr> @{ML Thm.ctyp_of}~\<open>ctxt \<tau>\<close> and @{ML Thm.cterm_of}~\<open>ctxt t\<close> explicitly
   624   \<^descr> \<^ML>\<open>Thm.ctyp_of\<close>~\<open>ctxt \<tau>\<close> and \<^ML>\<open>Thm.cterm_of\<close>~\<open>ctxt t\<close> explicitly
   628   check types and terms, respectively. This also involves some basic
   625   check types and terms, respectively. This also involves some basic
   629   normalizations, such expansion of type and term abbreviations from the
   626   normalizations, such expansion of type and term abbreviations from the
   630   underlying theory context. Full re-certification is relatively slow and
   627   underlying theory context. Full re-certification is relatively slow and
   631   should be avoided in tight reasoning loops.
   628   should be avoided in tight reasoning loops.
   632 
   629 
   633   \<^descr> @{ML Thm.apply}, @{ML Thm.lambda}, @{ML Thm.all}, @{ML Drule.mk_implies}
   630   \<^descr> \<^ML>\<open>Thm.apply\<close>, \<^ML>\<open>Thm.lambda\<close>, \<^ML>\<open>Thm.all\<close>, \<^ML>\<open>Drule.mk_implies\<close>
   634   etc.\ compose certified terms (or propositions) incrementally. This is
   631   etc.\ compose certified terms (or propositions) incrementally. This is
   635   equivalent to @{ML Thm.cterm_of} after unchecked @{ML_op "$"}, @{ML lambda},
   632   equivalent to \<^ML>\<open>Thm.cterm_of\<close> after unchecked \<^ML_op>\<open>$\<close>, \<^ML>\<open>lambda\<close>,
   636   @{ML Logic.all}, @{ML Logic.mk_implies} etc., but there can be a big
   633   \<^ML>\<open>Logic.all\<close>, \<^ML>\<open>Logic.mk_implies\<close> etc., but there can be a big
   637   difference in performance when large existing entities are composed by a few
   634   difference in performance when large existing entities are composed by a few
   638   extra constructions on top. There are separate operations to decompose
   635   extra constructions on top. There are separate operations to decompose
   639   certified terms and theorems to produce certified terms again.
   636   certified terms and theorems to produce certified terms again.
   640 
   637 
   641   \<^descr> Type @{ML_type thm} represents proven propositions. This is an abstract
   638   \<^descr> Type \<^ML_type>\<open>thm\<close> represents proven propositions. This is an abstract
   642   datatype that guarantees that its values have been constructed by basic
   639   datatype that guarantees that its values have been constructed by basic
   643   principles of the @{ML_structure Thm} module. Every @{ML_type thm} value
   640   principles of the \<^ML_structure>\<open>Thm\<close> module. Every \<^ML_type>\<open>thm\<close> value
   644   refers its background theory, cf.\ \secref{sec:context-theory}.
   641   refers its background theory, cf.\ \secref{sec:context-theory}.
   645 
   642 
   646   \<^descr> @{ML Thm.transfer}~\<open>thy thm\<close> transfers the given theorem to a \<^emph>\<open>larger\<close>
   643   \<^descr> \<^ML>\<open>Thm.transfer\<close>~\<open>thy thm\<close> transfers the given theorem to a \<^emph>\<open>larger\<close>
   647   theory, see also \secref{sec:context}. This formal adjustment of the
   644   theory, see also \secref{sec:context}. This formal adjustment of the
   648   background context has no logical significance, but is occasionally required
   645   background context has no logical significance, but is occasionally required
   649   for formal reasons, e.g.\ when theorems that are imported from more basic
   646   for formal reasons, e.g.\ when theorems that are imported from more basic
   650   theories are used in the current situation.
   647   theories are used in the current situation.
   651 
   648 
   652   \<^descr> @{ML Thm.assume}, @{ML Thm.forall_intr}, @{ML Thm.forall_elim}, @{ML
   649   \<^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
   653   Thm.implies_intr}, and @{ML Thm.implies_elim} correspond to the primitive
       
   654   inferences of \figref{fig:prim-rules}.
   650   inferences of \figref{fig:prim-rules}.
   655 
   651 
   656   \<^descr> @{ML Thm.generalize}~\<open>(\<^vec>\<alpha>, \<^vec>x)\<close> corresponds to the
   652   \<^descr> \<^ML>\<open>Thm.generalize\<close>~\<open>(\<^vec>\<alpha>, \<^vec>x)\<close> corresponds to the
   657   \<open>generalize\<close> rules of \figref{fig:subst-rules}. Here collections of type and
   653   \<open>generalize\<close> rules of \figref{fig:subst-rules}. Here collections of type and
   658   term variables are generalized simultaneously, specified by the given basic
   654   term variables are generalized simultaneously, specified by the given basic
   659   names.
   655   names.
   660 
   656 
   661   \<^descr> @{ML Thm.instantiate}~\<open>(\<^vec>\<alpha>\<^sub>s, \<^vec>x\<^sub>\<tau>)\<close> corresponds to the
   657   \<^descr> \<^ML>\<open>Thm.instantiate\<close>~\<open>(\<^vec>\<alpha>\<^sub>s, \<^vec>x\<^sub>\<tau>)\<close> corresponds to the
   662   \<open>instantiate\<close> rules of \figref{fig:subst-rules}. Type variables are
   658   \<open>instantiate\<close> rules of \figref{fig:subst-rules}. Type variables are
   663   substituted before term variables. Note that the types in \<open>\<^vec>x\<^sub>\<tau>\<close> refer
   659   substituted before term variables. Note that the types in \<open>\<^vec>x\<^sub>\<tau>\<close> refer
   664   to the instantiated versions.
   660   to the instantiated versions.
   665 
   661 
   666   \<^descr> @{ML Thm.add_axiom}~\<open>ctxt (name, A)\<close> declares an arbitrary proposition as
   662   \<^descr> \<^ML>\<open>Thm.add_axiom\<close>~\<open>ctxt (name, A)\<close> declares an arbitrary proposition as
   667   axiom, and retrieves it as a theorem from the resulting theory, cf.\ \<open>axiom\<close>
   663   axiom, and retrieves it as a theorem from the resulting theory, cf.\ \<open>axiom\<close>
   668   in \figref{fig:prim-rules}. Note that the low-level representation in the
   664   in \figref{fig:prim-rules}. Note that the low-level representation in the
   669   axiom table may differ slightly from the returned theorem.
   665   axiom table may differ slightly from the returned theorem.
   670 
   666 
   671   \<^descr> @{ML Thm.add_oracle}~\<open>(binding, oracle)\<close> produces a named oracle rule,
   667   \<^descr> \<^ML>\<open>Thm.add_oracle\<close>~\<open>(binding, oracle)\<close> produces a named oracle rule,
   672   essentially generating arbitrary axioms on the fly, cf.\ \<open>axiom\<close> in
   668   essentially generating arbitrary axioms on the fly, cf.\ \<open>axiom\<close> in
   673   \figref{fig:prim-rules}.
   669   \figref{fig:prim-rules}.
   674 
   670 
   675   \<^descr> @{ML Thm.add_def}~\<open>ctxt unchecked overloaded (name, c \<^vec>x \<equiv> t)\<close>
   671   \<^descr> \<^ML>\<open>Thm.add_def\<close>~\<open>ctxt unchecked overloaded (name, c \<^vec>x \<equiv> t)\<close>
   676   states a definitional axiom for an existing constant \<open>c\<close>. Dependencies are
   672   states a definitional axiom for an existing constant \<open>c\<close>. Dependencies are
   677   recorded via @{ML Theory.add_deps}, unless the \<open>unchecked\<close> option is set.
   673   recorded via \<^ML>\<open>Theory.add_deps\<close>, unless the \<open>unchecked\<close> option is set.
   678   Note that the low-level representation in the axiom table may differ
   674   Note that the low-level representation in the axiom table may differ
   679   slightly from the returned theorem.
   675   slightly from the returned theorem.
   680 
   676 
   681   \<^descr> @{ML Theory.add_deps}~\<open>ctxt name c\<^sub>\<tau> \<^vec>d\<^sub>\<sigma>\<close> declares dependencies of
   677   \<^descr> \<^ML>\<open>Theory.add_deps\<close>~\<open>ctxt name c\<^sub>\<tau> \<^vec>d\<^sub>\<sigma>\<close> declares dependencies of
   682   a named specification for constant \<open>c\<^sub>\<tau>\<close>, relative to existing
   678   a named specification for constant \<open>c\<^sub>\<tau>\<close>, relative to existing
   683   specifications for constants \<open>\<^vec>d\<^sub>\<sigma>\<close>. This also works for type
   679   specifications for constants \<open>\<^vec>d\<^sub>\<sigma>\<close>. This also works for type
   684   constructors.
   680   constructors.
   685 \<close>
   681 \<close>
   686 
   682 
   692   @{ML_antiquotation_def "thm"} & : & \<open>ML_antiquotation\<close> \\
   688   @{ML_antiquotation_def "thm"} & : & \<open>ML_antiquotation\<close> \\
   693   @{ML_antiquotation_def "thms"} & : & \<open>ML_antiquotation\<close> \\
   689   @{ML_antiquotation_def "thms"} & : & \<open>ML_antiquotation\<close> \\
   694   @{ML_antiquotation_def "lemma"} & : & \<open>ML_antiquotation\<close> \\
   690   @{ML_antiquotation_def "lemma"} & : & \<open>ML_antiquotation\<close> \\
   695   \end{matharray}
   691   \end{matharray}
   696 
   692 
   697   @{rail \<open>
   693   \<^rail>\<open>
   698   @@{ML_antiquotation ctyp} typ
   694   @@{ML_antiquotation ctyp} typ
   699   ;
   695   ;
   700   @@{ML_antiquotation cterm} term
   696   @@{ML_antiquotation cterm} term
   701   ;
   697   ;
   702   @@{ML_antiquotation cprop} prop
   698   @@{ML_antiquotation cprop} prop
   705   ;
   701   ;
   706   @@{ML_antiquotation thms} thms
   702   @@{ML_antiquotation thms} thms
   707   ;
   703   ;
   708   @@{ML_antiquotation lemma} ('(' @'open' ')')? ((prop +) + @'and') \<newline>
   704   @@{ML_antiquotation lemma} ('(' @'open' ')')? ((prop +) + @'and') \<newline>
   709     @'by' method method?
   705     @'by' method method?
   710   \<close>}
   706   \<close>
   711 
   707 
   712   \<^descr> \<open>@{ctyp \<tau>}\<close> produces a certified type wrt.\ the current background theory
   708   \<^descr> \<open>@{ctyp \<tau>}\<close> produces a certified type wrt.\ the current background theory
   713   --- as abstract value of type @{ML_type ctyp}.
   709   --- as abstract value of type \<^ML_type>\<open>ctyp\<close>.
   714 
   710 
   715   \<^descr> \<open>@{cterm t}\<close> and \<open>@{cprop \<phi>}\<close> produce a certified term wrt.\ the current
   711   \<^descr> \<open>@{cterm t}\<close> and \<open>@{cprop \<phi>}\<close> produce a certified term wrt.\ the current
   716   background theory --- as abstract value of type @{ML_type cterm}.
   712   background theory --- as abstract value of type \<^ML_type>\<open>cterm\<close>.
   717 
   713 
   718   \<^descr> \<open>@{thm a}\<close> produces a singleton fact --- as abstract value of type
   714   \<^descr> \<open>@{thm a}\<close> produces a singleton fact --- as abstract value of type
   719   @{ML_type thm}.
   715   \<^ML_type>\<open>thm\<close>.
   720 
   716 
   721   \<^descr> \<open>@{thms a}\<close> produces a general fact --- as abstract value of type
   717   \<^descr> \<open>@{thms a}\<close> produces a general fact --- as abstract value of type
   722   @{ML_type "thm list"}.
   718   \<^ML_type>\<open>thm list\<close>.
   723 
   719 
   724   \<^descr> \<open>@{lemma \<phi> by meth}\<close> produces a fact that is proven on the spot according
   720   \<^descr> \<open>@{lemma \<phi> by meth}\<close> produces a fact that is proven on the spot according
   725   to the minimal proof, which imitates a terminal Isar proof. The result is an
   721   to the minimal proof, which imitates a terminal Isar proof. The result is an
   726   abstract value of type @{ML_type thm} or @{ML_type "thm list"}, depending on
   722   abstract value of type \<^ML_type>\<open>thm\<close> or \<^ML_type>\<open>thm list\<close>, depending on
   727   the number of propositions given here.
   723   the number of propositions given here.
   728 
   724 
   729   The internal derivation object lacks a proper theorem name, but it is
   725   The internal derivation object lacks a proper theorem name, but it is
   730   formally closed, unless the \<open>(open)\<close> option is specified (this may impact
   726   formally closed, unless the \<open>(open)\<close> option is specified (this may impact
   731   performance of applications with proof terms).
   727   performance of applications with proof terms).
   798   @{index_ML Drule.dest_term: "thm -> cterm"} \\
   794   @{index_ML Drule.dest_term: "thm -> cterm"} \\
   799   @{index_ML Logic.mk_type: "typ -> term"} \\
   795   @{index_ML Logic.mk_type: "typ -> term"} \\
   800   @{index_ML Logic.dest_type: "term -> typ"} \\
   796   @{index_ML Logic.dest_type: "term -> typ"} \\
   801   \end{mldecls}
   797   \end{mldecls}
   802 
   798 
   803   \<^descr> @{ML Conjunction.intr} derives \<open>A &&& B\<close> from \<open>A\<close> and \<open>B\<close>.
   799   \<^descr> \<^ML>\<open>Conjunction.intr\<close> derives \<open>A &&& B\<close> from \<open>A\<close> and \<open>B\<close>.
   804 
   800 
   805   \<^descr> @{ML Conjunction.elim} derives \<open>A\<close> and \<open>B\<close> from \<open>A &&& B\<close>.
   801   \<^descr> \<^ML>\<open>Conjunction.elim\<close> derives \<open>A\<close> and \<open>B\<close> from \<open>A &&& B\<close>.
   806 
   802 
   807   \<^descr> @{ML Drule.mk_term} derives \<open>TERM t\<close>.
   803   \<^descr> \<^ML>\<open>Drule.mk_term\<close> derives \<open>TERM t\<close>.
   808 
   804 
   809   \<^descr> @{ML Drule.dest_term} recovers term \<open>t\<close> from \<open>TERM t\<close>.
   805   \<^descr> \<^ML>\<open>Drule.dest_term\<close> recovers term \<open>t\<close> from \<open>TERM t\<close>.
   810 
   806 
   811   \<^descr> @{ML Logic.mk_type}~\<open>\<tau>\<close> produces the term \<open>TYPE(\<tau>)\<close>.
   807   \<^descr> \<^ML>\<open>Logic.mk_type\<close>~\<open>\<tau>\<close> produces the term \<open>TYPE(\<tau>)\<close>.
   812 
   808 
   813   \<^descr> @{ML Logic.dest_type}~\<open>TYPE(\<tau>)\<close> recovers the type \<open>\<tau>\<close>.
   809   \<^descr> \<^ML>\<open>Logic.dest_type\<close>~\<open>TYPE(\<tau>)\<close> recovers the type \<open>\<tau>\<close>.
   814 \<close>
   810 \<close>
   815 
   811 
   816 
   812 
   817 subsection \<open>Sort hypotheses\<close>
   813 subsection \<open>Sort hypotheses\<close>
   818 
   814 
   844   \begin{mldecls}
   840   \begin{mldecls}
   845   @{index_ML Thm.extra_shyps: "thm -> sort list"} \\
   841   @{index_ML Thm.extra_shyps: "thm -> sort list"} \\
   846   @{index_ML Thm.strip_shyps: "thm -> thm"} \\
   842   @{index_ML Thm.strip_shyps: "thm -> thm"} \\
   847   \end{mldecls}
   843   \end{mldecls}
   848 
   844 
   849   \<^descr> @{ML Thm.extra_shyps}~\<open>thm\<close> determines the extraneous sort hypotheses of
   845   \<^descr> \<^ML>\<open>Thm.extra_shyps\<close>~\<open>thm\<close> determines the extraneous sort hypotheses of
   850   the given theorem, i.e.\ the sorts that are not present within type
   846   the given theorem, i.e.\ the sorts that are not present within type
   851   variables of the statement.
   847   variables of the statement.
   852 
   848 
   853   \<^descr> @{ML Thm.strip_shyps}~\<open>thm\<close> removes any extraneous sort hypotheses that
   849   \<^descr> \<^ML>\<open>Thm.strip_shyps\<close>~\<open>thm\<close> removes any extraneous sort hypotheses that
   854   can be witnessed from the type signature.
   850   can be witnessed from the type signature.
   855 \<close>
   851 \<close>
   856 
   852 
   857 text %mlex \<open>
   853 text %mlex \<open>
   858   The following artificial example demonstrates the derivation of @{prop
   854   The following artificial example demonstrates the derivation of \<^prop>\<open>False\<close> with a pending sort hypothesis involving a logically empty sort.
   859   False} with a pending sort hypothesis involving a logically empty sort.
       
   860 \<close>
   855 \<close>
   861 
   856 
   862 class empty =
   857 class empty =
   863   assumes bad: "\<And>(x::'a) y. x \<noteq> y"
   858   assumes bad: "\<And>(x::'a) y. x \<noteq> y"
   864 
   859 
   865 theorem (in empty) false: False
   860 theorem (in empty) false: False
   866   using bad by blast
   861   using bad by blast
   867 
   862 
   868 ML_val \<open>@{assert} (Thm.extra_shyps @{thm false} = [@{sort empty}])\<close>
   863 ML_val \<open>\<^assert> (Thm.extra_shyps @{thm false} = [\<^sort>\<open>empty\<close>])\<close>
   869 
   864 
   870 text \<open>
   865 text \<open>
   871   Thanks to the inference kernel managing sort hypothesis according to their
   866   Thanks to the inference kernel managing sort hypothesis according to their
   872   logical significance, this example is merely an instance of \<^emph>\<open>ex falso
   867   logical significance, this example is merely an instance of \<^emph>\<open>ex falso
   873   quodlibet consequitur\<close> --- not a collapse of the logical framework!
   868   quodlibet consequitur\<close> --- not a collapse of the logical framework!
   949 text %mlref \<open>
   944 text %mlref \<open>
   950   \begin{mldecls}
   945   \begin{mldecls}
   951   @{index_ML Simplifier.norm_hhf: "Proof.context -> thm -> thm"} \\
   946   @{index_ML Simplifier.norm_hhf: "Proof.context -> thm -> thm"} \\
   952   \end{mldecls}
   947   \end{mldecls}
   953 
   948 
   954   \<^descr> @{ML Simplifier.norm_hhf}~\<open>ctxt thm\<close> normalizes the given theorem
   949   \<^descr> \<^ML>\<open>Simplifier.norm_hhf\<close>~\<open>ctxt thm\<close> normalizes the given theorem
   955   according to the canonical form specified above. This is occasionally
   950   according to the canonical form specified above. This is occasionally
   956   helpful to repair some low-level tools that do not handle Hereditary Harrop
   951   helpful to repair some low-level tools that do not handle Hereditary Harrop
   957   Formulae properly.
   952   Formulae properly.
   958 \<close>
   953 \<close>
   959 
   954 
  1030   \end{mldecls}
  1025   \end{mldecls}
  1031 
  1026 
  1032   \<^descr> \<open>rule\<^sub>1 RSN (i, rule\<^sub>2)\<close> resolves the conclusion of \<open>rule\<^sub>1\<close> with the
  1027   \<^descr> \<open>rule\<^sub>1 RSN (i, rule\<^sub>2)\<close> resolves the conclusion of \<open>rule\<^sub>1\<close> with the
  1033   \<open>i\<close>-th premise of \<open>rule\<^sub>2\<close>, according to the @{inference resolution}
  1028   \<open>i\<close>-th premise of \<open>rule\<^sub>2\<close>, according to the @{inference resolution}
  1034   principle explained above. Unless there is precisely one resolvent it raises
  1029   principle explained above. Unless there is precisely one resolvent it raises
  1035   exception @{ML THM}.
  1030   exception \<^ML>\<open>THM\<close>.
  1036 
  1031 
  1037   This corresponds to the rule attribute @{attribute THEN} in Isar source
  1032   This corresponds to the rule attribute @{attribute THEN} in Isar source
  1038   language.
  1033   language.
  1039 
  1034 
  1040   \<^descr> \<open>rule\<^sub>1 RS rule\<^sub>2\<close> abbreviates \<open>rule\<^sub>1 RSN (1, rule\<^sub>2)\<close>.
  1035   \<^descr> \<open>rule\<^sub>1 RS rule\<^sub>2\<close> abbreviates \<open>rule\<^sub>1 RSN (1, rule\<^sub>2)\<close>.
  1042   \<^descr> \<open>rules\<^sub>1 RLN (i, rules\<^sub>2)\<close> joins lists of rules. For every \<open>rule\<^sub>1\<close> in
  1037   \<^descr> \<open>rules\<^sub>1 RLN (i, rules\<^sub>2)\<close> joins lists of rules. For every \<open>rule\<^sub>1\<close> in
  1043   \<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>
  1038   \<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>
  1044   with the \<open>i\<close>-th premise of \<open>rule\<^sub>2\<close>, accumulating multiple results in one
  1039   with the \<open>i\<close>-th premise of \<open>rule\<^sub>2\<close>, accumulating multiple results in one
  1045   big list. Note that such strict enumerations of higher-order unifications
  1040   big list. Note that such strict enumerations of higher-order unifications
  1046   can be inefficient compared to the lazy variant seen in elementary tactics
  1041   can be inefficient compared to the lazy variant seen in elementary tactics
  1047   like @{ML resolve_tac}.
  1042   like \<^ML>\<open>resolve_tac\<close>.
  1048 
  1043 
  1049   \<^descr> \<open>rules\<^sub>1 RL rules\<^sub>2\<close> abbreviates \<open>rules\<^sub>1 RLN (1, rules\<^sub>2)\<close>.
  1044   \<^descr> \<open>rules\<^sub>1 RL rules\<^sub>2\<close> abbreviates \<open>rules\<^sub>1 RLN (1, rules\<^sub>2)\<close>.
  1050 
  1045 
  1051   \<^descr> \<open>[rule\<^sub>1, \<dots>, rule\<^sub>n] MRS rule\<close> resolves \<open>rule\<^sub>i\<close> against premise \<open>i\<close> of
  1046   \<^descr> \<open>[rule\<^sub>1, \<dots>, rule\<^sub>n] MRS rule\<close> resolves \<open>rule\<^sub>i\<close> against premise \<open>i\<close> of
  1052   \<open>rule\<close>, for \<open>i = n, \<dots>, 1\<close>. By working from right to left, newly emerging
  1047   \<open>rule\<close>, for \<open>i = n, \<dots>, 1\<close>. By working from right to left, newly emerging
  1194   @{index_ML Proof_Checker.thm_of_proof: "theory -> proof -> thm"} \\
  1189   @{index_ML Proof_Checker.thm_of_proof: "theory -> proof -> thm"} \\
  1195   @{index_ML Proof_Syntax.read_proof: "theory -> bool -> bool -> string -> proof"} \\
  1190   @{index_ML Proof_Syntax.read_proof: "theory -> bool -> bool -> string -> proof"} \\
  1196   @{index_ML Proof_Syntax.pretty_proof: "Proof.context -> proof -> Pretty.T"} \\
  1191   @{index_ML Proof_Syntax.pretty_proof: "Proof.context -> proof -> Pretty.T"} \\
  1197   \end{mldecls}
  1192   \end{mldecls}
  1198 
  1193 
  1199   \<^descr> Type @{ML_type proof} represents proof terms; this is a datatype with
  1194   \<^descr> Type \<^ML_type>\<open>proof\<close> represents proof terms; this is a datatype with
  1200   constructors @{index_ML Abst}, @{index_ML AbsP}, @{index_ML_op "%"},
  1195   constructors @{index_ML Abst}, @{index_ML AbsP}, @{index_ML_op "%"},
  1201   @{index_ML_op "%%"}, @{index_ML PBound}, @{index_ML MinProof}, @{index_ML
  1196   @{index_ML_op "%%"}, @{index_ML PBound}, @{index_ML MinProof}, @{index_ML
  1202   Hyp}, @{index_ML PAxm}, @{index_ML Oracle}, @{index_ML Promise}, @{index_ML
  1197   Hyp}, @{index_ML PAxm}, @{index_ML Oracle}, @{index_ML Promise}, @{index_ML
  1203   PThm} as explained above. %FIXME OfClass (!?)
  1198   PThm} as explained above. %FIXME OfClass (!?)
  1204 
  1199 
  1205   \<^descr> Type @{ML_type proof_body} represents the nested proof information of a
  1200   \<^descr> Type \<^ML_type>\<open>proof_body\<close> represents the nested proof information of a
  1206   named theorem, consisting of a digest of oracles and named theorem over some
  1201   named theorem, consisting of a digest of oracles and named theorem over some
  1207   proof term. The digest only covers the directly visible part of the proof:
  1202   proof term. The digest only covers the directly visible part of the proof:
  1208   in order to get the full information, the implicit graph of nested theorems
  1203   in order to get the full information, the implicit graph of nested theorems
  1209   needs to be traversed (e.g.\ using @{ML Proofterm.fold_body_thms}).
  1204   needs to be traversed (e.g.\ using \<^ML>\<open>Proofterm.fold_body_thms\<close>).
  1210 
  1205 
  1211   \<^descr> @{ML Thm.proof_of}~\<open>thm\<close> and @{ML Thm.proof_body_of}~\<open>thm\<close> produce the
  1206   \<^descr> \<^ML>\<open>Thm.proof_of\<close>~\<open>thm\<close> and \<^ML>\<open>Thm.proof_body_of\<close>~\<open>thm\<close> produce the
  1212   proof term or proof body (with digest of oracles and theorems) from a given
  1207   proof term or proof body (with digest of oracles and theorems) from a given
  1213   theorem. Note that this involves a full join of internal futures that
  1208   theorem. Note that this involves a full join of internal futures that
  1214   fulfill pending proof promises, and thus disrupts the natural bottom-up
  1209   fulfill pending proof promises, and thus disrupts the natural bottom-up
  1215   construction of proofs by introducing dynamic ad-hoc dependencies. Parallel
  1210   construction of proofs by introducing dynamic ad-hoc dependencies. Parallel
  1216   performance may suffer by inspecting proof terms at run-time.
  1211   performance may suffer by inspecting proof terms at run-time.
  1217 
  1212 
  1218   \<^descr> @{ML Proofterm.proofs} specifies the detail of proof recording within
  1213   \<^descr> \<^ML>\<open>Proofterm.proofs\<close> specifies the detail of proof recording within
  1219   @{ML_type thm} values produced by the inference kernel: @{ML 0} records only
  1214   \<^ML_type>\<open>thm\<close> values produced by the inference kernel: \<^ML>\<open>0\<close> records only
  1220   the names of oracles, @{ML 1} records oracle names and propositions, @{ML 2}
  1215   the names of oracles, \<^ML>\<open>1\<close> records oracle names and propositions, \<^ML>\<open>2\<close>
  1221   additionally records full proof terms. Officially named theorems that
  1216   additionally records full proof terms. Officially named theorems that
  1222   contribute to a result are recorded in any case.
  1217   contribute to a result are recorded in any case.
  1223 
  1218 
  1224   \<^descr> @{ML Reconstruct.reconstruct_proof}~\<open>ctxt prop prf\<close> turns the implicit
  1219   \<^descr> \<^ML>\<open>Reconstruct.reconstruct_proof\<close>~\<open>ctxt prop prf\<close> turns the implicit
  1225   proof term \<open>prf\<close> into a full proof of the given proposition.
  1220   proof term \<open>prf\<close> into a full proof of the given proposition.
  1226 
  1221 
  1227   Reconstruction may fail if \<open>prf\<close> is not a proof of \<open>prop\<close>, or if it does not
  1222   Reconstruction may fail if \<open>prf\<close> is not a proof of \<open>prop\<close>, or if it does not
  1228   contain sufficient information for reconstruction. Failure may only happen
  1223   contain sufficient information for reconstruction. Failure may only happen
  1229   for proofs that are constructed manually, but not for those produced
  1224   for proofs that are constructed manually, but not for those produced
  1230   automatically by the inference kernel.
  1225   automatically by the inference kernel.
  1231 
  1226 
  1232   \<^descr> @{ML Reconstruct.expand_proof}~\<open>ctxt [thm\<^sub>1, \<dots>, thm\<^sub>n] prf\<close> expands and
  1227   \<^descr> \<^ML>\<open>Reconstruct.expand_proof\<close>~\<open>ctxt [thm\<^sub>1, \<dots>, thm\<^sub>n] prf\<close> expands and
  1233   reconstructs the proofs of all specified theorems, with the given (full)
  1228   reconstructs the proofs of all specified theorems, with the given (full)
  1234   proof. Theorems that are not unique specified via their name may be
  1229   proof. Theorems that are not unique specified via their name may be
  1235   disambiguated by giving their proposition.
  1230   disambiguated by giving their proposition.
  1236 
  1231 
  1237   \<^descr> @{ML Proof_Checker.thm_of_proof}~\<open>thy prf\<close> turns the given (full) proof
  1232   \<^descr> \<^ML>\<open>Proof_Checker.thm_of_proof\<close>~\<open>thy prf\<close> turns the given (full) proof
  1238   into a theorem, by replaying it using only primitive rules of the inference
  1233   into a theorem, by replaying it using only primitive rules of the inference
  1239   kernel.
  1234   kernel.
  1240 
  1235 
  1241   \<^descr> @{ML Proof_Syntax.read_proof}~\<open>thy b\<^sub>1 b\<^sub>2 s\<close> reads in a proof term. The
  1236   \<^descr> \<^ML>\<open>Proof_Syntax.read_proof\<close>~\<open>thy b\<^sub>1 b\<^sub>2 s\<close> reads in a proof term. The
  1242   Boolean flags indicate the use of sort and type information. Usually, typing
  1237   Boolean flags indicate the use of sort and type information. Usually, typing
  1243   information is left implicit and is inferred during proof reconstruction.
  1238   information is left implicit and is inferred during proof reconstruction.
  1244   %FIXME eliminate flags!?
  1239   %FIXME eliminate flags!?
  1245 
  1240 
  1246   \<^descr> @{ML Proof_Syntax.pretty_proof}~\<open>ctxt prf\<close> pretty-prints the given proof
  1241   \<^descr> \<^ML>\<open>Proof_Syntax.pretty_proof\<close>~\<open>ctxt prf\<close> pretty-prints the given proof
  1247   term.
  1242   term.
  1248 \<close>
  1243 \<close>
  1249 
  1244 
  1250 text %mlex \<open>
  1245 text %mlex \<open>
  1251   \<^item> \<^file>\<open>~~/src/HOL/Proofs/ex/Proof_Terms.thy\<close> provides basic examples involving
  1246   \<^item> \<^file>\<open>~~/src/HOL/Proofs/ex/Proof_Terms.thy\<close> provides basic examples involving