src/Doc/Implementation/Logic.thy
changeset 76987 4c275405faae
parent 74915 cdd2284c8047
child 77730 4a174bea55e2
equal deleted inserted replaced
76986:1e31ddcab458 76987:4c275405faae
     6 
     6 
     7 chapter \<open>Primitive logic \label{ch:logic}\<close>
     7 chapter \<open>Primitive logic \label{ch:logic}\<close>
     8 
     8 
     9 text \<open>
     9 text \<open>
    10   The logical foundations of Isabelle/Isar are that of the Pure logic, which
    10   The logical foundations of Isabelle/Isar are that of the Pure logic, which
    11   has been introduced as a Natural Deduction framework in @{cite paulson700}.
    11   has been introduced as a Natural Deduction framework in \<^cite>\<open>paulson700\<close>.
    12   This is essentially the same logic as ``\<open>\<lambda>HOL\<close>'' in the more abstract
    12   This is essentially the same logic as ``\<open>\<lambda>HOL\<close>'' in the more abstract
    13   setting of Pure Type Systems (PTS) @{cite "Barendregt-Geuvers:2001"},
    13   setting of Pure Type Systems (PTS) \<^cite>\<open>"Barendregt-Geuvers:2001"\<close>,
    14   although there are some key differences in the specific treatment of simple
    14   although there are some key differences in the specific treatment of simple
    15   types in Isabelle/Pure.
    15   types in Isabelle/Pure.
    16 
    16 
    17   Following type-theoretic parlance, the Pure logic consists of three levels
    17   Following type-theoretic parlance, the Pure logic consists of three levels
    18   of \<open>\<lambda>\<close>-calculus with corresponding arrows, \<open>\<Rightarrow>\<close> for syntactic function space
    18   of \<open>\<lambda>\<close>-calculus with corresponding arrows, \<open>\<Rightarrow>\<close> for syntactic function space
    95   constraints can be solved in a most general fashion: for each type
    95   constraints can be solved in a most general fashion: for each type
    96   constructor \<open>\<kappa>\<close> and sort \<open>s\<close> there is a most general vector of argument
    96   constructor \<open>\<kappa>\<close> and sort \<open>s\<close> there is a most general vector of argument
    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
    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
    98   sort \<open>s\<close>. Consequently, type unification has most general solutions (modulo
    98   sort \<open>s\<close>. Consequently, type unification has most general solutions (modulo
    99   equivalence of sorts), so type-inference produces primary types as expected
    99   equivalence of sorts), so type-inference produces primary types as expected
   100   @{cite "nipkow-prehofer"}.
   100   \<^cite>\<open>"nipkow-prehofer"\<close>.
   101 \<close>
   101 \<close>
   102 
   102 
   103 text %mlref \<open>
   103 text %mlref \<open>
   104   \begin{mldecls}
   104   \begin{mldecls}
   105   @{define_ML_type class = string} \\
   105   @{define_ML_type class = string} \\
   253 
   253 
   254 section \<open>Terms \label{sec:terms}\<close>
   254 section \<open>Terms \label{sec:terms}\<close>
   255 
   255 
   256 text \<open>
   256 text \<open>
   257   The language of terms is that of simply-typed \<open>\<lambda>\<close>-calculus with de-Bruijn
   257   The language of terms is that of simply-typed \<open>\<lambda>\<close>-calculus with de-Bruijn
   258   indices for bound variables (cf.\ @{cite debruijn72} or @{cite
   258   indices for bound variables (cf.\ \<^cite>\<open>debruijn72\<close> or \<^cite>\<open>"paulson-ml2"\<close>), with the types being determined by the corresponding
   259   "paulson-ml2"}), with the types being determined by the corresponding
       
   260   binders. In contrast, free variables and constants have an explicit name and
   259   binders. In contrast, free variables and constants have an explicit name and
   261   type in each occurrence.
   260   type in each occurrence.
   262 
   261 
   263   \<^medskip>
   262   \<^medskip>
   264   A \<^emph>\<open>bound variable\<close> is a natural number \<open>b\<close>, which accounts for the number
   263   A \<^emph>\<open>bound variable\<close> is a natural number \<open>b\<close>, which accounts for the number
   596   formation of dependently typed \<open>\<lambda>\<close>-terms representing the underlying proof
   595   formation of dependently typed \<open>\<lambda>\<close>-terms representing the underlying proof
   597   objects. Proof terms are irrelevant in the Pure logic, though; they cannot
   596   objects. Proof terms are irrelevant in the Pure logic, though; they cannot
   598   occur within propositions. The system provides a runtime option to record
   597   occur within propositions. The system provides a runtime option to record
   599   explicit proof terms for primitive inferences, see also
   598   explicit proof terms for primitive inferences, see also
   600   \secref{sec:proof-terms}. Thus all three levels of \<open>\<lambda>\<close>-calculus become
   599   \secref{sec:proof-terms}. Thus all three levels of \<open>\<lambda>\<close>-calculus become
   601   explicit: \<open>\<Rightarrow>\<close> for terms, and \<open>\<And>/\<Longrightarrow>\<close> for proofs (cf.\ @{cite
   600   explicit: \<open>\<Rightarrow>\<close> for terms, and \<open>\<And>/\<Longrightarrow>\<close> for proofs (cf.\ \<^cite>\<open>"Berghofer-Nipkow:2000:TPHOL"\<close>).
   602   "Berghofer-Nipkow:2000:TPHOL"}).
       
   603 
   601 
   604   Observe that locally fixed parameters (as in \<open>\<And>\<hyphen>intro\<close>) need not be recorded
   602   Observe that locally fixed parameters (as in \<open>\<And>\<hyphen>intro\<close>) need not be recorded
   605   in the hypotheses, because the simple syntactic types of Pure are always
   603   in the hypotheses, because the simple syntactic types of Pure are always
   606   inhabitable. ``Assumptions'' \<open>x :: \<tau>\<close> for type-membership are only present
   604   inhabitable. ``Assumptions'' \<open>x :: \<tau>\<close> for type-membership are only present
   607   as long as some \<open>x\<^sub>\<tau>\<close> occurs in the statement body.\<^footnote>\<open>This is the key
   605   as long as some \<open>x\<^sub>\<tau>\<close> occurs in the statement body.\<^footnote>\<open>This is the key
   608   difference to ``\<open>\<lambda>HOL\<close>'' in the PTS framework @{cite
   606   difference to ``\<open>\<lambda>HOL\<close>'' in the PTS framework \<^cite>\<open>"Barendregt-Geuvers:2001"\<close>, where hypotheses \<open>x : A\<close> are treated uniformly
   609   "Barendregt-Geuvers:2001"}, where hypotheses \<open>x : A\<close> are treated uniformly
       
   610   for propositions and types.\<close>
   607   for propositions and types.\<close>
   611 
   608 
   612   \<^medskip>
   609   \<^medskip>
   613   The axiomatization of a theory is implicitly closed by forming all instances
   610   The axiomatization of a theory is implicitly closed by forming all instances
   614   of type and term variables: \<open>\<turnstile> A\<vartheta>\<close> holds for any substitution
   611   of type and term variables: \<open>\<turnstile> A\<vartheta>\<close> holds for any substitution
   663   constant, with zero or one equations \<open>c((\<^vec>\<alpha>)\<kappa>) \<equiv> t\<close> for each type
   660   constant, with zero or one equations \<open>c((\<^vec>\<alpha>)\<kappa>) \<equiv> t\<close> for each type
   664   constructor \<open>\<kappa>\<close> (for distinct variables \<open>\<^vec>\<alpha>\<close>). The RHS may mention
   661   constructor \<open>\<kappa>\<close> (for distinct variables \<open>\<^vec>\<alpha>\<close>). The RHS may mention
   665   previously defined constants as above, or arbitrary constants \<open>d(\<alpha>\<^sub>i)\<close> for
   662   previously defined constants as above, or arbitrary constants \<open>d(\<alpha>\<^sub>i)\<close> for
   666   some \<open>\<alpha>\<^sub>i\<close> projected from \<open>\<^vec>\<alpha>\<close>. Thus overloaded definitions
   663   some \<open>\<alpha>\<^sub>i\<close> projected from \<open>\<^vec>\<alpha>\<close>. Thus overloaded definitions
   667   essentially work by primitive recursion over the syntactic structure of a
   664   essentially work by primitive recursion over the syntactic structure of a
   668   single type argument. See also @{cite \<open>\S4.3\<close>
   665   single type argument. See also \<^cite>\<open>\<open>\S4.3\<close> in
   669   "Haftmann-Wenzel:2006:classes"}.
   666   "Haftmann-Wenzel:2006:classes"\<close>.
   670 \<close>
   667 \<close>
   671 
   668 
   672 text %mlref \<open>
   669 text %mlref \<open>
   673   \begin{mldecls}
   670   \begin{mldecls}
   674   @{define_ML Logic.all: "term -> term -> term"} \\
   671   @{define_ML Logic.all: "term -> term -> term"} \\
   998 
   995 
   999 subsection \<open>Hereditary Harrop Formulae\<close>
   996 subsection \<open>Hereditary Harrop Formulae\<close>
  1000 
   997 
  1001 text \<open>
   998 text \<open>
  1002   The idea of object-level rules is to model Natural Deduction inferences in
   999   The idea of object-level rules is to model Natural Deduction inferences in
  1003   the style of Gentzen @{cite "Gentzen:1935"}, but we allow arbitrary nesting
  1000   the style of Gentzen \<^cite>\<open>"Gentzen:1935"\<close>, but we allow arbitrary nesting
  1004   similar to @{cite "Schroeder-Heister:1984"}. The most basic rule format is
  1001   similar to \<^cite>\<open>"Schroeder-Heister:1984"\<close>. The most basic rule format is
  1005   that of a \<^emph>\<open>Horn Clause\<close>:
  1002   that of a \<^emph>\<open>Horn Clause\<close>:
  1006   \[
  1003   \[
  1007   \infer{\<open>A\<close>}{\<open>A\<^sub>1\<close> & \<open>\<dots>\<close> & \<open>A\<^sub>n\<close>}
  1004   \infer{\<open>A\<close>}{\<open>A\<^sub>1\<close> & \<open>\<dots>\<close> & \<open>A\<^sub>n\<close>}
  1008   \]
  1005   \]
  1009   where \<open>A, A\<^sub>1, \<dots>, A\<^sub>n\<close> are atomic propositions of the framework, usually of
  1006   where \<open>A, A\<^sub>1, \<dots>, A\<^sub>n\<close> are atomic propositions of the framework, usually of
  1020   \<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>
  1017   \<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>
  1021   \]
  1018   \]
  1022 
  1019 
  1023   Nesting of rules means that the positions of \<open>A\<^sub>i\<close> may again hold compound
  1020   Nesting of rules means that the positions of \<open>A\<^sub>i\<close> may again hold compound
  1024   rules, not just atomic propositions. Propositions of this format are called
  1021   rules, not just atomic propositions. Propositions of this format are called
  1025   \<^emph>\<open>Hereditary Harrop Formulae\<close> in the literature @{cite "Miller:1991"}. Here
  1022   \<^emph>\<open>Hereditary Harrop Formulae\<close> in the literature \<^cite>\<open>"Miller:1991"\<close>. Here
  1026   we give an inductive characterization as follows:
  1023   we give an inductive characterization as follows:
  1027 
  1024 
  1028   \<^medskip>
  1025   \<^medskip>
  1029   \begin{tabular}{ll}
  1026   \begin{tabular}{ll}
  1030   \<open>\<^bold>x\<close> & set of variables \\
  1027   \<open>\<^bold>x\<close> & set of variables \\
  1184   represented by a datatype similar to the one for terms described in
  1181   represented by a datatype similar to the one for terms described in
  1185   \secref{sec:terms}. On top of these syntactic terms, two more layers of
  1182   \secref{sec:terms}. On top of these syntactic terms, two more layers of
  1186   \<open>\<lambda>\<close>-calculus are added, which correspond to \<open>\<And>x :: \<alpha>. B x\<close> and \<open>A \<Longrightarrow> B\<close>
  1183   \<open>\<lambda>\<close>-calculus are added, which correspond to \<open>\<And>x :: \<alpha>. B x\<close> and \<open>A \<Longrightarrow> B\<close>
  1187   according to the propositions-as-types principle. The resulting 3-level
  1184   according to the propositions-as-types principle. The resulting 3-level
  1188   \<open>\<lambda>\<close>-calculus resembles ``\<open>\<lambda>HOL\<close>'' in the more abstract setting of Pure Type
  1185   \<open>\<lambda>\<close>-calculus resembles ``\<open>\<lambda>HOL\<close>'' in the more abstract setting of Pure Type
  1189   Systems (PTS) @{cite "Barendregt-Geuvers:2001"}, if some fine points like
  1186   Systems (PTS) \<^cite>\<open>"Barendregt-Geuvers:2001"\<close>, if some fine points like
  1190   schematic polymorphism and type classes are ignored.
  1187   schematic polymorphism and type classes are ignored.
  1191 
  1188 
  1192   \<^medskip>
  1189   \<^medskip>
  1193   \<^emph>\<open>Proof abstractions\<close> of the form \<open>\<^bold>\<lambda>x :: \<alpha>. prf\<close> or \<open>\<^bold>\<lambda>p : A. prf\<close>
  1190   \<^emph>\<open>Proof abstractions\<close> of the form \<open>\<^bold>\<lambda>x :: \<alpha>. prf\<close> or \<open>\<^bold>\<lambda>p : A. prf\<close>
  1194   correspond to introduction of \<open>\<And>\<close>/\<open>\<Longrightarrow>\<close>, and \<^emph>\<open>proof applications\<close> of the form
  1191   correspond to introduction of \<open>\<And>\<close>/\<open>\<Longrightarrow>\<close>, and \<^emph>\<open>proof applications\<close> of the form
  1241   Isabelle/Pure inference kernel records only \<^emph>\<open>implicit\<close> proof terms, by
  1238   Isabelle/Pure inference kernel records only \<^emph>\<open>implicit\<close> proof terms, by
  1242   omitting all typing information in terms, all term and type labels of proof
  1239   omitting all typing information in terms, all term and type labels of proof
  1243   abstractions, and some argument terms of applications \<open>p \<cdot> t\<close> (if possible).
  1240   abstractions, and some argument terms of applications \<open>p \<cdot> t\<close> (if possible).
  1244 
  1241 
  1245   There are separate operations to reconstruct the full proof term later on,
  1242   There are separate operations to reconstruct the full proof term later on,
  1246   using \<^emph>\<open>higher-order pattern unification\<close> @{cite "nipkow-patterns" and
  1243   using \<^emph>\<open>higher-order pattern unification\<close> \<^cite>\<open>"nipkow-patterns" and
  1247   "Berghofer-Nipkow:2000:TPHOL"}.
  1244   "Berghofer-Nipkow:2000:TPHOL"\<close>.
  1248 
  1245 
  1249   The \<^emph>\<open>proof checker\<close> expects a fully reconstructed proof term, and can turn
  1246   The \<^emph>\<open>proof checker\<close> expects a fully reconstructed proof term, and can turn
  1250   it into a theorem by replaying its primitive inferences within the kernel.
  1247   it into a theorem by replaying its primitive inferences within the kernel.
  1251 \<close>
  1248 \<close>
  1252 
  1249 
  1253 
  1250 
  1254 subsection \<open>Concrete syntax of proof terms\<close>
  1251 subsection \<open>Concrete syntax of proof terms\<close>
  1255 
  1252 
  1256 text \<open>
  1253 text \<open>
  1257   The concrete syntax of proof terms is a slight extension of the regular
  1254   The concrete syntax of proof terms is a slight extension of the regular
  1258   inner syntax of Isabelle/Pure @{cite "isabelle-isar-ref"}. Its main
  1255   inner syntax of Isabelle/Pure \<^cite>\<open>"isabelle-isar-ref"\<close>. Its main
  1259   syntactic category @{syntax (inner) proof} is defined as follows:
  1256   syntactic category @{syntax (inner) proof} is defined as follows:
  1260 
  1257 
  1261   \begin{center}
  1258   \begin{center}
  1262   \begin{supertabular}{rclr}
  1259   \begin{supertabular}{rclr}
  1263 
  1260