src/Doc/Implementation/Logic.thy
changeset 73764 35d8132633c6
parent 73763 eccc4a13216d
child 73765 ebaed09ce06e
equal deleted inserted replaced
73763:eccc4a13216d 73764:35d8132633c6
   100   @{cite "nipkow-prehofer"}.
   100   @{cite "nipkow-prehofer"}.
   101 \<close>
   101 \<close>
   102 
   102 
   103 text %mlref \<open>
   103 text %mlref \<open>
   104   \begin{mldecls}
   104   \begin{mldecls}
   105   @{index_ML_type class = string} \\
   105   @{define_ML_type class = string} \\
   106   @{index_ML_type sort = "class list"} \\
   106   @{define_ML_type sort = "class list"} \\
   107   @{index_ML_type arity = "string * sort list * sort"} \\
   107   @{define_ML_type arity = "string * sort list * sort"} \\
   108   @{index_ML_type typ} \\
   108   @{define_ML_type typ} \\
   109   @{index_ML Term.map_atyps: "(typ -> typ) -> typ -> typ"} \\
   109   @{define_ML Term.map_atyps: "(typ -> typ) -> typ -> typ"} \\
   110   @{index_ML Term.fold_atyps: "(typ -> 'a -> 'a) -> typ -> 'a -> 'a"} \\
   110   @{define_ML Term.fold_atyps: "(typ -> 'a -> 'a) -> typ -> 'a -> 'a"} \\
   111   \end{mldecls}
   111   \end{mldecls}
   112   \begin{mldecls}
   112   \begin{mldecls}
   113   @{index_ML Sign.subsort: "theory -> sort * sort -> bool"} \\
   113   @{define_ML Sign.subsort: "theory -> sort * sort -> bool"} \\
   114   @{index_ML Sign.of_sort: "theory -> typ * sort -> bool"} \\
   114   @{define_ML Sign.of_sort: "theory -> typ * sort -> bool"} \\
   115   @{index_ML Sign.add_type: "Proof.context -> binding * int * mixfix -> theory -> theory"} \\
   115   @{define_ML Sign.add_type: "Proof.context -> binding * int * mixfix -> theory -> theory"} \\
   116   @{index_ML Sign.add_type_abbrev: "Proof.context ->
   116   @{define_ML Sign.add_type_abbrev: "Proof.context ->
   117   binding * string list * typ -> theory -> theory"} \\
   117   binding * string list * typ -> theory -> theory"} \\
   118   @{index_ML Sign.primitive_class: "binding * class list -> theory -> theory"} \\
   118   @{define_ML Sign.primitive_class: "binding * class list -> theory -> theory"} \\
   119   @{index_ML Sign.primitive_classrel: "class * class -> theory -> theory"} \\
   119   @{define_ML Sign.primitive_classrel: "class * class -> theory -> theory"} \\
   120   @{index_ML Sign.primitive_arity: "arity -> theory -> theory"} \\
   120   @{define_ML Sign.primitive_arity: "arity -> theory -> theory"} \\
   121   \end{mldecls}
   121   \end{mldecls}
   122 
   122 
   123   \<^descr> Type \<^ML_type>\<open>class\<close> represents type classes.
   123   \<^descr> Type \<^ML_type>\<open>class\<close> represents type classes.
   124 
   124 
   125   \<^descr> Type \<^ML_type>\<open>sort\<close> represents sorts, i.e.\ finite intersections of
   125   \<^descr> Type \<^ML_type>\<open>sort\<close> represents sorts, i.e.\ finite intersections of
   311   unification and matching.
   311   unification and matching.
   312 \<close>
   312 \<close>
   313 
   313 
   314 text %mlref \<open>
   314 text %mlref \<open>
   315   \begin{mldecls}
   315   \begin{mldecls}
   316   @{index_ML_type term} \\
   316   @{define_ML_type term} \\
   317   @{index_ML_infix "aconv": "term * term -> bool"} \\
   317   @{define_ML_infix "aconv": "term * term -> bool"} \\
   318   @{index_ML Term.map_types: "(typ -> typ) -> term -> term"} \\
   318   @{define_ML Term.map_types: "(typ -> typ) -> term -> term"} \\
   319   @{index_ML Term.fold_types: "(typ -> 'a -> 'a) -> term -> 'a -> 'a"} \\
   319   @{define_ML Term.fold_types: "(typ -> 'a -> 'a) -> term -> 'a -> 'a"} \\
   320   @{index_ML Term.map_aterms: "(term -> term) -> term -> term"} \\
   320   @{define_ML Term.map_aterms: "(term -> term) -> term -> term"} \\
   321   @{index_ML Term.fold_aterms: "(term -> 'a -> 'a) -> term -> 'a -> 'a"} \\
   321   @{define_ML Term.fold_aterms: "(term -> 'a -> 'a) -> term -> 'a -> 'a"} \\
   322   \end{mldecls}
   322   \end{mldecls}
   323   \begin{mldecls}
   323   \begin{mldecls}
   324   @{index_ML fastype_of: "term -> typ"} \\
   324   @{define_ML fastype_of: "term -> typ"} \\
   325   @{index_ML lambda: "term -> term -> term"} \\
   325   @{define_ML lambda: "term -> term -> term"} \\
   326   @{index_ML betapply: "term * term -> term"} \\
   326   @{define_ML betapply: "term * term -> term"} \\
   327   @{index_ML incr_boundvars: "int -> term -> term"} \\
   327   @{define_ML incr_boundvars: "int -> term -> term"} \\
   328   @{index_ML Sign.declare_const: "Proof.context ->
   328   @{define_ML Sign.declare_const: "Proof.context ->
   329   (binding * typ) * mixfix -> theory -> term * theory"} \\
   329   (binding * typ) * mixfix -> theory -> term * theory"} \\
   330   @{index_ML Sign.add_abbrev: "string -> binding * term ->
   330   @{define_ML Sign.add_abbrev: "string -> binding * term ->
   331   theory -> (term * term) * theory"} \\
   331   theory -> (term * term) * theory"} \\
   332   @{index_ML Sign.const_typargs: "theory -> string * typ -> typ list"} \\
   332   @{define_ML Sign.const_typargs: "theory -> string * typ -> typ list"} \\
   333   @{index_ML Sign.const_instance: "theory -> string * typ list -> typ"} \\
   333   @{define_ML Sign.const_instance: "theory -> string * typ list -> typ"} \\
   334   \end{mldecls}
   334   \end{mldecls}
   335 
   335 
   336   \<^descr> Type \<^ML_type>\<open>term\<close> 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 @{define_ML Bound}, @{define_ML Free}, @{define_ML
   339   Var}, @{index_ML Const}, @{index_ML Abs}, @{index_ML_infix "$"}.
   339   Var}, @{define_ML Const}, @{define_ML Abs}, @{define_ML_infix "$"}.
   340 
   340 
   341   \<^descr> \<open>t\<close>~\<^ML_text>\<open>aconv\<close>~\<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>\<open>term\<close>; 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 
   562   "Haftmann-Wenzel:2006:classes"}.
   562   "Haftmann-Wenzel:2006:classes"}.
   563 \<close>
   563 \<close>
   564 
   564 
   565 text %mlref \<open>
   565 text %mlref \<open>
   566   \begin{mldecls}
   566   \begin{mldecls}
   567   @{index_ML Logic.all: "term -> term -> term"} \\
   567   @{define_ML Logic.all: "term -> term -> term"} \\
   568   @{index_ML Logic.mk_implies: "term * term -> term"} \\
   568   @{define_ML Logic.mk_implies: "term * term -> term"} \\
   569   \end{mldecls}
   569   \end{mldecls}
   570   \begin{mldecls}
   570   \begin{mldecls}
   571   @{index_ML_type ctyp} \\
   571   @{define_ML_type ctyp} \\
   572   @{index_ML_type cterm} \\
   572   @{define_ML_type cterm} \\
   573   @{index_ML Thm.ctyp_of: "Proof.context -> typ -> ctyp"} \\
   573   @{define_ML Thm.ctyp_of: "Proof.context -> typ -> ctyp"} \\
   574   @{index_ML Thm.cterm_of: "Proof.context -> term -> cterm"} \\
   574   @{define_ML Thm.cterm_of: "Proof.context -> term -> cterm"} \\
   575   @{index_ML Thm.apply: "cterm -> cterm -> cterm"} \\
   575   @{define_ML Thm.apply: "cterm -> cterm -> cterm"} \\
   576   @{index_ML Thm.lambda: "cterm -> cterm -> cterm"} \\
   576   @{define_ML Thm.lambda: "cterm -> cterm -> cterm"} \\
   577   @{index_ML Thm.all: "Proof.context -> cterm -> cterm -> cterm"} \\
   577   @{define_ML Thm.all: "Proof.context -> cterm -> cterm -> cterm"} \\
   578   @{index_ML Drule.mk_implies: "cterm * cterm -> cterm"} \\
   578   @{define_ML Drule.mk_implies: "cterm * cterm -> cterm"} \\
   579   \end{mldecls}
   579   \end{mldecls}
   580   \begin{mldecls}
   580   \begin{mldecls}
   581   @{index_ML_type thm} \\
   581   @{define_ML_type thm} \\
   582   @{index_ML Thm.transfer: "theory -> thm -> thm"} \\
   582   @{define_ML Thm.transfer: "theory -> thm -> thm"} \\
   583   @{index_ML Thm.assume: "cterm -> thm"} \\
   583   @{define_ML Thm.assume: "cterm -> thm"} \\
   584   @{index_ML Thm.forall_intr: "cterm -> thm -> thm"} \\
   584   @{define_ML Thm.forall_intr: "cterm -> thm -> thm"} \\
   585   @{index_ML Thm.forall_elim: "cterm -> thm -> thm"} \\
   585   @{define_ML Thm.forall_elim: "cterm -> thm -> thm"} \\
   586   @{index_ML Thm.implies_intr: "cterm -> thm -> thm"} \\
   586   @{define_ML Thm.implies_intr: "cterm -> thm -> thm"} \\
   587   @{index_ML Thm.implies_elim: "thm -> thm -> thm"} \\
   587   @{define_ML Thm.implies_elim: "thm -> thm -> thm"} \\
   588   @{index_ML Thm.generalize: "string list * string list -> int -> thm -> thm"} \\
   588   @{define_ML Thm.generalize: "string list * string list -> int -> thm -> thm"} \\
   589   @{index_ML Thm.instantiate: "((indexname * sort) * ctyp) list * ((indexname * typ) * cterm) list
   589   @{define_ML Thm.instantiate: "((indexname * sort) * ctyp) list * ((indexname * typ) * cterm) list
   590   -> thm -> thm"} \\
   590   -> thm -> thm"} \\
   591   @{index_ML Thm.add_axiom: "Proof.context ->
   591   @{define_ML Thm.add_axiom: "Proof.context ->
   592   binding * term -> theory -> (string * thm) * theory"} \\
   592   binding * term -> theory -> (string * thm) * theory"} \\
   593   @{index_ML Thm.add_oracle: "binding * ('a -> cterm) -> theory ->
   593   @{define_ML Thm.add_oracle: "binding * ('a -> cterm) -> theory ->
   594   (string * ('a -> thm)) * theory"} \\
   594   (string * ('a -> thm)) * theory"} \\
   595   @{index_ML Thm.add_def: "Defs.context -> bool -> bool ->
   595   @{define_ML Thm.add_def: "Defs.context -> bool -> bool ->
   596   binding * term -> theory -> (string * thm) * theory"} \\
   596   binding * term -> theory -> (string * thm) * theory"} \\
   597   \end{mldecls}
   597   \end{mldecls}
   598   \begin{mldecls}
   598   \begin{mldecls}
   599   @{index_ML Theory.add_deps: "Defs.context -> string ->
   599   @{define_ML Theory.add_deps: "Defs.context -> string ->
   600   Defs.entry -> Defs.entry list -> theory -> theory"} \\
   600   Defs.entry -> Defs.entry list -> theory -> theory"} \\
   601   @{index_ML Thm_Deps.all_oracles: "thm list -> Proofterm.oracle list"} \\
   601   @{define_ML Thm_Deps.all_oracles: "thm list -> Proofterm.oracle list"} \\
   602   \end{mldecls}
   602   \end{mldecls}
   603 
   603 
   604   \<^descr> \<^ML>\<open>Logic.all\<close>~\<open>a B\<close> produces a Pure quantification \<open>\<And>a. B\<close>, where
   604   \<^descr> \<^ML>\<open>Logic.all\<close>~\<open>a B\<close> produces a Pure quantification \<open>\<And>a. B\<close>, where
   605   occurrences of the atomic term \<open>a\<close> in the body proposition \<open>B\<close> are replaced
   605   occurrences of the atomic term \<open>a\<close> in the body proposition \<open>B\<close> are replaced
   606   by bound variables. (See also \<^ML>\<open>lambda\<close> on terms.)
   606   by bound variables. (See also \<^ML>\<open>lambda\<close> on terms.)
   794   an additional type argument, which is essentially a predicate on types.
   794   an additional type argument, which is essentially a predicate on types.
   795 \<close>
   795 \<close>
   796 
   796 
   797 text %mlref \<open>
   797 text %mlref \<open>
   798   \begin{mldecls}
   798   \begin{mldecls}
   799   @{index_ML Conjunction.intr: "thm -> thm -> thm"} \\
   799   @{define_ML Conjunction.intr: "thm -> thm -> thm"} \\
   800   @{index_ML Conjunction.elim: "thm -> thm * thm"} \\
   800   @{define_ML Conjunction.elim: "thm -> thm * thm"} \\
   801   @{index_ML Drule.mk_term: "cterm -> thm"} \\
   801   @{define_ML Drule.mk_term: "cterm -> thm"} \\
   802   @{index_ML Drule.dest_term: "thm -> cterm"} \\
   802   @{define_ML Drule.dest_term: "thm -> cterm"} \\
   803   @{index_ML Logic.mk_type: "typ -> term"} \\
   803   @{define_ML Logic.mk_type: "typ -> term"} \\
   804   @{index_ML Logic.dest_type: "term -> typ"} \\
   804   @{define_ML Logic.dest_type: "term -> typ"} \\
   805   \end{mldecls}
   805   \end{mldecls}
   806 
   806 
   807   \<^descr> \<^ML>\<open>Conjunction.intr\<close> derives \<open>A &&& B\<close> from \<open>A\<close> and \<open>B\<close>.
   807   \<^descr> \<^ML>\<open>Conjunction.intr\<close> derives \<open>A &&& B\<close> from \<open>A\<close> and \<open>B\<close>.
   808 
   808 
   809   \<^descr> \<^ML>\<open>Conjunction.elim\<close> derives \<open>A\<close> and \<open>B\<close> from \<open>A &&& B\<close>.
   809   \<^descr> \<^ML>\<open>Conjunction.elim\<close> derives \<open>A\<close> and \<open>B\<close> from \<open>A &&& B\<close>.
   844   type variable \<open>\<alpha>\<^sub>s\<close>.
   844   type variable \<open>\<alpha>\<^sub>s\<close>.
   845 \<close>
   845 \<close>
   846 
   846 
   847 text %mlref \<open>
   847 text %mlref \<open>
   848   \begin{mldecls}
   848   \begin{mldecls}
   849   @{index_ML Thm.extra_shyps: "thm -> sort list"} \\
   849   @{define_ML Thm.extra_shyps: "thm -> sort list"} \\
   850   @{index_ML Thm.strip_shyps: "thm -> thm"} \\
   850   @{define_ML Thm.strip_shyps: "thm -> thm"} \\
   851   \end{mldecls}
   851   \end{mldecls}
   852 
   852 
   853   \<^descr> \<^ML>\<open>Thm.extra_shyps\<close>~\<open>thm\<close> determines the extraneous sort hypotheses of
   853   \<^descr> \<^ML>\<open>Thm.extra_shyps\<close>~\<open>thm\<close> determines the extraneous sort hypotheses of
   854   the given theorem, i.e.\ the sorts that are not present within type
   854   the given theorem, i.e.\ the sorts that are not present within type
   855   variables of the statement.
   855   variables of the statement.
   949   about the order of parameters, and vacuous quantifiers vanish automatically.
   949   about the order of parameters, and vacuous quantifiers vanish automatically.
   950 \<close>
   950 \<close>
   951 
   951 
   952 text %mlref \<open>
   952 text %mlref \<open>
   953   \begin{mldecls}
   953   \begin{mldecls}
   954   @{index_ML Simplifier.norm_hhf: "Proof.context -> thm -> thm"} \\
   954   @{define_ML Simplifier.norm_hhf: "Proof.context -> thm -> thm"} \\
   955   \end{mldecls}
   955   \end{mldecls}
   956 
   956 
   957   \<^descr> \<^ML>\<open>Simplifier.norm_hhf\<close>~\<open>ctxt thm\<close> normalizes the given theorem
   957   \<^descr> \<^ML>\<open>Simplifier.norm_hhf\<close>~\<open>ctxt thm\<close> normalizes the given theorem
   958   according to the canonical form specified above. This is occasionally
   958   according to the canonical form specified above. This is occasionally
   959   helpful to repair some low-level tools that do not handle Hereditary Harrop
   959   helpful to repair some low-level tools that do not handle Hereditary Harrop
  1020   %FIXME @{inference_def elim_resolution}, @{inference_def dest_resolution}
  1020   %FIXME @{inference_def elim_resolution}, @{inference_def dest_resolution}
  1021 \<close>
  1021 \<close>
  1022 
  1022 
  1023 text %mlref \<open>
  1023 text %mlref \<open>
  1024   \begin{mldecls}
  1024   \begin{mldecls}
  1025   @{index_ML_infix "RSN": "thm * (int * thm) -> thm"} \\
  1025   @{define_ML_infix "RSN": "thm * (int * thm) -> thm"} \\
  1026   @{index_ML_infix "RS": "thm * thm -> thm"} \\
  1026   @{define_ML_infix "RS": "thm * thm -> thm"} \\
  1027 
  1027 
  1028   @{index_ML_infix "RLN": "thm list * (int * thm list) -> thm list"} \\
  1028   @{define_ML_infix "RLN": "thm list * (int * thm list) -> thm list"} \\
  1029   @{index_ML_infix "RL": "thm list * thm list -> thm list"} \\
  1029   @{define_ML_infix "RL": "thm list * thm list -> thm list"} \\
  1030 
  1030 
  1031   @{index_ML_infix "MRS": "thm list * thm -> thm"} \\
  1031   @{define_ML_infix "MRS": "thm list * thm -> thm"} \\
  1032   @{index_ML_infix "OF": "thm * thm list -> thm"} \\
  1032   @{define_ML_infix "OF": "thm * thm list -> thm"} \\
  1033   \end{mldecls}
  1033   \end{mldecls}
  1034 
  1034 
  1035   \<^descr> \<open>rule\<^sub>1 RSN (i, rule\<^sub>2)\<close> resolves the conclusion of \<open>rule\<^sub>1\<close> with the
  1035   \<^descr> \<open>rule\<^sub>1 RSN (i, rule\<^sub>2)\<close> resolves the conclusion of \<open>rule\<^sub>1\<close> with the
  1036   \<open>i\<close>-th premise of \<open>rule\<^sub>2\<close>, according to the @{inference resolution}
  1036   \<open>i\<close>-th premise of \<open>rule\<^sub>2\<close>, according to the @{inference resolution}
  1037   principle explained above. Unless there is precisely one resolvent it raises
  1037   principle explained above. Unless there is precisely one resolvent it raises
  1182   avoid conflicts with the regular term language.
  1182   avoid conflicts with the regular term language.
  1183 \<close>
  1183 \<close>
  1184 
  1184 
  1185 text %mlref \<open>
  1185 text %mlref \<open>
  1186   \begin{mldecls}
  1186   \begin{mldecls}
  1187   @{index_ML_type proof} \\
  1187   @{define_ML_type proof} \\
  1188   @{index_ML_type proof_body} \\
  1188   @{define_ML_type proof_body} \\
  1189   @{index_ML Proofterm.proofs: "int Unsynchronized.ref"} \\
  1189   @{define_ML Proofterm.proofs: "int Unsynchronized.ref"} \\
  1190   @{index_ML Proofterm.reconstruct_proof:
  1190   @{define_ML Proofterm.reconstruct_proof:
  1191   "theory -> term -> proof -> proof"} \\
  1191   "theory -> term -> proof -> proof"} \\
  1192   @{index_ML Proofterm.expand_proof: "theory ->
  1192   @{define_ML Proofterm.expand_proof: "theory ->
  1193   (Proofterm.thm_header -> string option) -> proof -> proof"} \\
  1193   (Proofterm.thm_header -> string option) -> proof -> proof"} \\
  1194   @{index_ML Proof_Checker.thm_of_proof: "theory -> proof -> thm"} \\
  1194   @{define_ML Proof_Checker.thm_of_proof: "theory -> proof -> thm"} \\
  1195   @{index_ML Proof_Syntax.read_proof: "theory -> bool -> bool -> string -> proof"} \\
  1195   @{define_ML Proof_Syntax.read_proof: "theory -> bool -> bool -> string -> proof"} \\
  1196   @{index_ML Proof_Syntax.pretty_proof: "Proof.context -> proof -> Pretty.T"} \\
  1196   @{define_ML Proof_Syntax.pretty_proof: "Proof.context -> proof -> Pretty.T"} \\
  1197   \end{mldecls}
  1197   \end{mldecls}
  1198 
  1198 
  1199   \<^descr> Type \<^ML_type>\<open>proof\<close> represents proof terms; this is a datatype with
  1199   \<^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_infix "%"},
  1200   constructors @{define_ML Abst}, @{define_ML AbsP}, @{define_ML_infix "%"},
  1201   @{index_ML_infix "%%"}, @{index_ML PBound}, @{index_ML MinProof}, @{index_ML
  1201   @{define_ML_infix "%%"}, @{define_ML PBound}, @{define_ML MinProof}, @{define_ML
  1202   Hyp}, @{index_ML PAxm}, @{index_ML Oracle}, @{index_ML PThm} as explained
  1202   Hyp}, @{define_ML PAxm}, @{define_ML Oracle}, @{define_ML PThm} as explained
  1203   above. %FIXME PClass (!?)
  1203   above. %FIXME PClass (!?)
  1204 
  1204 
  1205   \<^descr> Type \<^ML_type>\<open>proof_body\<close> represents the nested proof information of a
  1205   \<^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
  1206   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:
  1207   proof term. The digest only covers the directly visible part of the proof: