doc-src/IsarImplementation/Thy/logic.thy
 changeset 20537 b6b49903db7e parent 20521 189811b39869 child 20542 a54ca4e90874
1.1 --- a/doc-src/IsarImplementation/Thy/logic.thy	Thu Sep 14 15:27:08 2006 +0200
1.2 +++ b/doc-src/IsarImplementation/Thy/logic.thy	Thu Sep 14 15:51:20 2006 +0200
1.3 @@ -20,12 +20,12 @@
1.4    "\<And>"} for universal quantification (proofs depending on terms), and
1.5    @{text "\<Longrightarrow>"} for implication (proofs depending on proofs).
1.7 -  Pure derivations are relative to a logical theory, which declares
1.8 -  type constructors, term constants, and axioms.  Theory declarations
1.9 -  support schematic polymorphism, which is strictly speaking outside
1.10 -  the logic.\footnote{Incidently, this is the main logical reason, why
1.11 -  the theory context @{text "\<Theta>"} is separate from the context @{text
1.12 -  "\<Gamma>"} of the core calculus.}
1.13 +  Derivations are relative to a logical theory, which declares type
1.14 +  constructors, constants, and axioms.  Theory declarations support
1.15 +  schematic polymorphism, which is strictly speaking outside the
1.16 +  logic.\footnote{This is the deeper logical reason, why the theory
1.17 +  context @{text "\<Theta>"} is separate from the proof context @{text "\<Gamma>"}
1.18 +  of the core calculus.}
1.19  *}
1.22 @@ -42,8 +42,8 @@
1.23    internally.  The resulting relation is an ordering: reflexive,
1.24    transitive, and antisymmetric.
1.26 -  A \emph{sort} is a list of type classes written as @{text
1.27 -  "{c\<^isub>1, \<dots>, c\<^isub>m}"}, which represents symbolic
1.28 +  A \emph{sort} is a list of type classes written as @{text "s =
1.29 +  {c\<^isub>1, \<dots>, c\<^isub>m}"}, which represents symbolic
1.30    intersection.  Notationally, the curly braces are omitted for
1.31    singleton intersections, i.e.\ any class @{text "c"} may be read as
1.32    a sort @{text "{c}"}.  The ordering on type classes is extended to
1.33 @@ -56,11 +56,11 @@
1.34    elements wrt.\ the sort order.
1.36    \medskip A \emph{fixed type variable} is a pair of a basic name
1.37 -  (starting with a @{text "'"} character) and a sort constraint.  For
1.38 -  example, @{text "('a, s)"} which is usually printed as @{text
1.39 -  "\<alpha>\<^isub>s"}.  A \emph{schematic type variable} is a pair of an
1.40 -  indexname and a sort constraint.  For example, @{text "(('a, 0),
1.41 -  s)"} which is usually printed as @{text "?\<alpha>\<^isub>s"}.
1.42 +  (starting with a @{text "'"} character) and a sort constraint, e.g.\
1.43 +  @{text "('a, s)"} which is usually printed as @{text "\<alpha>\<^isub>s"}.
1.44 +  A \emph{schematic type variable} is a pair of an indexname and a
1.45 +  sort constraint, e.g.\ @{text "(('a, 0), s)"} which is usually
1.46 +  printed as @{text "?\<alpha>\<^isub>s"}.
1.48    Note that \emph{all} syntactic components contribute to the identity
1.49    of type variables, including the sort constraint.  The core logic
1.50 @@ -70,23 +70,23 @@
1.52    A \emph{type constructor} @{text "\<kappa>"} is a @{text "k"}-ary operator
1.53    on types declared in the theory.  Type constructor application is
1.54 -  usually written postfix as @{text "(\<alpha>\<^isub>1, \<dots>, \<alpha>\<^isub>k)\<kappa>"}.
1.55 -  For @{text "k = 0"} the argument tuple is omitted, e.g.\ @{text
1.56 -  "prop"} instead of @{text "()prop"}.  For @{text "k = 1"} the
1.57 -  parentheses are omitted, e.g.\ @{text "\<alpha> list"} instead of @{text
1.58 -  "(\<alpha>)list"}.  Further notation is provided for specific constructors,
1.59 -  notably the right-associative infix @{text "\<alpha> \<Rightarrow> \<beta>"} instead of
1.60 -  @{text "(\<alpha>, \<beta>)fun"}.
1.61 +  written postfix as @{text "(\<alpha>\<^isub>1, \<dots>, \<alpha>\<^isub>k)\<kappa>"}.  For
1.62 +  @{text "k = 0"} the argument tuple is omitted, e.g.\ @{text "prop"}
1.63 +  instead of @{text "()prop"}.  For @{text "k = 1"} the parentheses
1.64 +  are omitted, e.g.\ @{text "\<alpha> list"} instead of @{text "(\<alpha>)list"}.
1.65 +  Further notation is provided for specific constructors, notably the
1.66 +  right-associative infix @{text "\<alpha> \<Rightarrow> \<beta>"} instead of @{text "(\<alpha>,
1.67 +  \<beta>)fun"}.
1.69 -  A \emph{type} @{text "\<tau>"} is defined inductively over type variables
1.70 -  and type constructors as follows: @{text "\<tau> = \<alpha>\<^isub>s |
1.71 -  ?\<alpha>\<^isub>s | (\<tau>\<^sub>1, \<dots>, \<tau>\<^sub>k)k"}.
1.72 +  A \emph{type} is defined inductively over type variables and type
1.73 +  constructors as follows: @{text "\<tau> = \<alpha>\<^isub>s | ?\<alpha>\<^isub>s |
1.74 +  (\<tau>\<^sub>1, \<dots>, \<tau>\<^sub>k)k"}.
1.76    A \emph{type abbreviation} is a syntactic definition @{text
1.77    "(\<^vec>\<alpha>)\<kappa> = \<tau>"} of an arbitrary type expression @{text "\<tau>"} over
1.78 -  variables @{text "\<^vec>\<alpha>"}.  Type abbreviations looks like type
1.79 -  constructors at the surface, but are fully expanded before entering
1.80 -  the logical core.
1.81 +  variables @{text "\<^vec>\<alpha>"}.  Type abbreviations appear as type
1.82 +  constructors in the syntax, but are expanded before entering the
1.83 +  logical core.
1.85    A \emph{type arity} declares the image behavior of a type
1.86    constructor wrt.\ the algebra of sorts: @{text "\<kappa> :: (s\<^isub>1, \<dots>,
1.87 @@ -98,22 +98,22 @@
1.89    \medskip The sort algebra is always maintained as \emph{coregular},
1.90    which means that type arities are consistent with the subclass
1.91 -  relation: for each type constructor @{text "\<kappa>"} and classes @{text
1.92 -  "c\<^isub>1 \<subseteq> c\<^isub>2"}, any arity @{text "\<kappa> ::
1.93 -  (\<^vec>s\<^isub>1)c\<^isub>1"} has a corresponding arity @{text "\<kappa>
1.94 -  :: (\<^vec>s\<^isub>2)c\<^isub>2"} where @{text "\<^vec>s\<^isub>1 \<subseteq>
1.95 -  \<^vec>s\<^isub>2"} holds component-wise.
1.96 +  relation: for any type constructor @{text "\<kappa>"}, and classes @{text
1.97 +  "c\<^isub>1 \<subseteq> c\<^isub>2"}, and arities @{text "\<kappa> ::
1.98 +  (\<^vec>s\<^isub>1)c\<^isub>1"} and @{text "\<kappa> ::
1.99 +  (\<^vec>s\<^isub>2)c\<^isub>2"} holds @{text "\<^vec>s\<^isub>1 \<subseteq>
1.100 +  \<^vec>s\<^isub>2"} component-wise.
1.102    The key property of a coregular order-sorted algebra is that sort
1.103 -  constraints may be always solved in a most general fashion: for each
1.104 -  type constructor @{text "\<kappa>"} and sort @{text "s"} there is a most
1.105 -  general vector of argument sorts @{text "(s\<^isub>1, \<dots>,
1.106 -  s\<^isub>k)"} such that a type scheme @{text
1.107 -  "(\<alpha>\<^bsub>s\<^isub>1\<^esub>, \<dots>, \<alpha>\<^bsub>s\<^isub>k\<^esub>)\<kappa>"} is
1.108 -  of sort @{text "s"}.  Consequently, the unification problem on the
1.109 -  algebra of types has most general solutions (modulo renaming and
1.110 -  equivalence of sorts).  Moreover, the usual type-inference algorithm
1.111 -  will produce primary types as expected \cite{nipkow-prehofer}.
1.112 +  constraints can be solved in a most general fashion: for each type
1.113 +  constructor @{text "\<kappa>"} and sort @{text "s"} there is a most general
1.114 +  vector of argument sorts @{text "(s\<^isub>1, \<dots>, s\<^isub>k)"} such
1.115 +  that a type scheme @{text "(\<alpha>\<^bsub>s\<^isub>1\<^esub>, \<dots>,
1.116 +  \<alpha>\<^bsub>s\<^isub>k\<^esub>)\<kappa>"} is of sort @{text "s"}.
1.117 +  Consequently, unification on the algebra of types has most general
1.118 +  solutions (modulo equivalence of sorts).  This means that
1.119 +  type-inference will produce primary types as expected
1.120 +  \cite{nipkow-prehofer}.
1.121  *}
1.123  text %mlref {*
1.124 @@ -149,20 +149,21 @@
1.125    \item @{ML_type typ} represents types; this is a datatype with
1.126    constructors @{ML TFree}, @{ML TVar}, @{ML Type}.
1.128 -  \item @{ML map_atyps}~@{text "f \<tau>"} applies mapping @{text "f"} to
1.129 -  all atomic types (@{ML TFree}, @{ML TVar}) occurring in @{text "\<tau>"}.
1.130 +  \item @{ML map_atyps}~@{text "f \<tau>"} applies the mapping @{text "f"}
1.131 +  to all atomic types (@{ML TFree}, @{ML TVar}) occurring in @{text
1.132 +  "\<tau>"}.
1.134 -  \item @{ML fold_atyps}~@{text "f \<tau>"} iterates operation @{text "f"}
1.135 -  over all occurrences of atoms (@{ML TFree}, @{ML TVar}) in @{text
1.136 -  "\<tau>"}; the type structure is traversed from left to right.
1.137 +  \item @{ML fold_atyps}~@{text "f \<tau>"} iterates the operation @{text
1.138 +  "f"} over all occurrences of atomic types (@{ML TFree}, @{ML TVar})
1.139 +  in @{text "\<tau>"}; the type structure is traversed from left to right.
1.141    \item @{ML Sign.subsort}~@{text "thy (s\<^isub>1, s\<^isub>2)"}
1.142    tests the subsort relation @{text "s\<^isub>1 \<subseteq> s\<^isub>2"}.
1.144 -  \item @{ML Sign.of_sort}~@{text "thy (\<tau>, s)"} tests whether a type
1.145 -  is of a given sort.
1.146 +  \item @{ML Sign.of_sort}~@{text "thy (\<tau>, s)"} tests whether type
1.147 +  @{text "\<tau>"} is of sort @{text "s"}.
1.149 -  \item @{ML Sign.add_types}~@{text "[(\<kappa>, k, mx), \<dots>]"} declares new
1.150 +  \item @{ML Sign.add_types}~@{text "[(\<kappa>, k, mx), \<dots>]"} declares a new
1.151    type constructors @{text "\<kappa>"} with @{text "k"} arguments and
1.152    optional mixfix syntax.
1.154 @@ -171,7 +172,7 @@
1.155    optional mixfix syntax.
1.157    \item @{ML Sign.primitive_class}~@{text "(c, [c\<^isub>1, \<dots>,
1.158 -  c\<^isub>n])"} declares new class @{text "c"}, together with class
1.159 +  c\<^isub>n])"} declares a new class @{text "c"}, together with class
1.160    relations @{text "c \<subseteq> c\<^isub>i"}, for @{text "i = 1, \<dots>, n"}.
1.162    \item @{ML Sign.primitive_classrel}~@{text "(c\<^isub>1,
1.163 @@ -179,7 +180,7 @@
1.164    c\<^isub>2"}.
1.166    \item @{ML Sign.primitive_arity}~@{text "(\<kappa>, \<^vec>s, s)"} declares
1.167 -  arity @{text "\<kappa> :: (\<^vec>s)s"}.
1.168 +  the arity @{text "\<kappa> :: (\<^vec>s)s"}.
1.170    \end{description}
1.171  *}
1.172 @@ -193,62 +194,66 @@
1.174    The language of terms is that of simply-typed @{text "\<lambda>"}-calculus
1.175    with de-Bruijn indices for bound variables (cf.\ \cite{debruijn72}
1.176 -  or \cite{paulson-ml2}), and named free variables and constants.
1.177 -  Terms with loose bound variables are usually considered malformed.
1.178 -  The types of variables and constants is stored explicitly at each
1.179 -  occurrence in the term.
1.180 +  or \cite{paulson-ml2}), with the types being determined determined
1.181 +  by the corresponding binders.  In contrast, free variables and
1.182 +  constants are have an explicit name and type in each occurrence.
1.184    \medskip A \emph{bound variable} is a natural number @{text "b"},
1.185 -  which refers to the next binder that is @{text "b"} steps upwards
1.186 -  from the occurrence of @{text "b"} (counting from zero).  Bindings
1.187 -  may be introduced as abstractions within the term, or as a separate
1.188 -  context (an inside-out list).  This associates each bound variable
1.189 -  with a type.  A \emph{loose variables} is a bound variable that is
1.190 -  outside the current scope of local binders or the context.  For
1.191 +  which accounts for the number of intermediate binders between the
1.192 +  variable occurrence in the body and its binding position.  For
1.193    example, the de-Bruijn term @{text "\<lambda>\<^isub>\<tau>. \<lambda>\<^isub>\<tau>. 1 + 0"}
1.194 -  corresponds to @{text "\<lambda>x\<^isub>\<tau>. \<lambda>y\<^isub>\<tau>. x + y"} in a named
1.195 -  representation.  Also note that the very same bound variable may get
1.196 -  different numbers at different occurrences.
1.197 +  would correspond to @{text "\<lambda>x\<^isub>\<tau>. \<lambda>y\<^isub>\<tau>. x + y"} in a
1.198 +  named representation.  Note that a bound variable may be represented
1.199 +  by different de-Bruijn indices at different occurrences, depending
1.200 +  on the nesting of abstractions.
1.202 +  A \emph{loose variables} is a bound variable that is outside the
1.203 +  scope of local binders.  The types (and names) for loose variables
1.204 +  can be managed as a separate context, that is maintained inside-out
1.205 +  like a stack of hypothetical binders.  The core logic only operates
1.206 +  on closed terms, without any loose variables.
1.208 -  A \emph{fixed variable} is a pair of a basic name and a type.  For
1.209 -  example, @{text "(x, \<tau>)"} which is usually printed @{text
1.210 -  "x\<^isub>\<tau>"}.  A \emph{schematic variable} is a pair of an
1.211 -  indexname and a type.  For example, @{text "((x, 0), \<tau>)"} which is
1.212 -  usually printed as @{text "?x\<^isub>\<tau>"}.
1.213 +  A \emph{fixed variable} is a pair of a basic name and a type, e.g.\
1.214 +  @{text "(x, \<tau>)"} which is usually printed @{text "x\<^isub>\<tau>"}.  A
1.215 +  \emph{schematic variable} is a pair of an indexname and a type,
1.216 +  e.g.\ @{text "((x, 0), \<tau>)"} which is usually printed as @{text
1.217 +  "?x\<^isub>\<tau>"}.
1.219 -  \medskip A \emph{constant} is a atomic terms consisting of a basic
1.220 -  name and a type.  Constants are declared in the context as
1.221 -  polymorphic families @{text "c :: \<sigma>"}, meaning that any @{text
1.222 -  "c\<^isub>\<tau>"} is a valid constant for all substitution instances
1.223 -  @{text "\<tau> \<le> \<sigma>"}.
1.224 +  \medskip A \emph{constant} is a pair of a basic name and a type,
1.225 +  e.g.\ @{text "(c, \<tau>)"} which is usually printed as @{text
1.226 +  "c\<^isub>\<tau>"}.  Constants are declared in the context as polymorphic
1.227 +  families @{text "c :: \<sigma>"}, meaning that valid all substitution
1.228 +  instances @{text "c\<^isub>\<tau>"} for @{text "\<tau> = \<sigma>\<vartheta>"} are valid.
1.230 -  The list of \emph{type arguments} of @{text "c\<^isub>\<tau>"} wrt.\ the
1.231 -  declaration @{text "c :: \<sigma>"} is the codomain of the type matcher
1.232 -  presented in canonical order (according to the left-to-right
1.233 -  occurrences of type variables in in @{text "\<sigma>"}).  Thus @{text
1.234 -  "c\<^isub>\<tau>"} can be represented more compactly as @{text
1.235 -  "c(\<tau>\<^isub>1, \<dots>, \<tau>\<^isub>n)"}.  For example, the instance @{text
1.236 -  "plus\<^bsub>nat \<Rightarrow> nat \<Rightarrow> nat\<^esub>"} of some @{text "plus :: \<alpha> \<Rightarrow> \<alpha>
1.237 -  \<Rightarrow> \<alpha>"} has the singleton list @{text "nat"} as type arguments, the
1.238 -  constant may be represented as @{text "plus(nat)"}.
1.239 +  The vector of \emph{type arguments} of constant @{text "c\<^isub>\<tau>"}
1.240 +  wrt.\ the declaration @{text "c :: \<sigma>"} is defined as the codomain of
1.241 +  the matcher @{text "\<vartheta> = {?\<alpha>\<^isub>1 \<mapsto> \<tau>\<^isub>1, \<dots>,
1.242 +  ?\<alpha>\<^isub>n \<mapsto> \<tau>\<^isub>n}"} presented in canonical order @{text
1.243 +  "(\<tau>\<^isub>1, \<dots>, \<tau>\<^isub>n)"}.  Within a given theory context,
1.244 +  there is a one-to-one correspondence between any constant @{text
1.245 +  "c\<^isub>\<tau>"} and the application @{text "c(\<tau>\<^isub>1, \<dots>,
1.246 +  \<tau>\<^isub>n)"} of its type arguments.  For example, with @{text "plus
1.247 +  :: \<alpha> \<Rightarrow> \<alpha> \<Rightarrow> \<alpha>"}, the instance @{text "plus\<^bsub>nat \<Rightarrow> nat \<Rightarrow>
1.248 +  nat\<^esub>"} corresponds to @{text "plus(nat)"}.
1.250    Constant declarations @{text "c :: \<sigma>"} may contain sort constraints
1.251    for type variables in @{text "\<sigma>"}.  These are observed by
1.252    type-inference as expected, but \emph{ignored} by the core logic.
1.253    This means the primitive logic is able to reason with instances of
1.254 -  polymorphic constants that the user-level type-checker would reject.
1.255 +  polymorphic constants that the user-level type-checker would reject
1.256 +  due to violation of type class restrictions.
1.258 -  \medskip A \emph{term} @{text "t"} is defined inductively over
1.259 -  variables and constants, with abstraction and application as
1.260 -  follows: @{text "t = b | x\<^isub>\<tau> | ?x\<^isub>\<tau> | c\<^isub>\<tau> |
1.261 -  \<lambda>\<^isub>\<tau>. t | t\<^isub>1 t\<^isub>2"}.  Parsing and printing takes
1.262 -  care of converting between an external representation with named
1.263 -  bound variables.  Subsequently, we shall use the latter notation
1.264 -  instead of internal de-Bruijn representation.
1.265 +  \medskip A \emph{term} is defined inductively over variables and
1.266 +  constants, with abstraction and application as follows: @{text "t =
1.267 +  b | x\<^isub>\<tau> | ?x\<^isub>\<tau> | c\<^isub>\<tau> | \<lambda>\<^isub>\<tau>. t |
1.268 +  t\<^isub>1 t\<^isub>2"}.  Parsing and printing takes care of
1.269 +  converting between an external representation with named bound
1.270 +  variables.  Subsequently, we shall use the latter notation instead
1.271 +  of internal de-Bruijn representation.
1.273 -  The subsequent inductive relation @{text "t :: \<tau>"} assigns a
1.274 -  (unique) type to a term, using the special type constructor @{text
1.275 -  "(\<alpha>, \<beta>)fun"}, which is written @{text "\<alpha> \<Rightarrow> \<beta>"}.
1.276 +  The inductive relation @{text "t :: \<tau>"} assigns a (unique) type to a
1.277 +  term according to the structure of atomic terms, abstractions, and
1.278 +  applicatins:
1.279    $1.280 \infer{@{text "a\<^isub>\<tau> :: \<tau>"}}{} 1.281 \qquad 1.282 @@ -264,46 +269,47 @@ 1.283 Type-inference depends on a context of type constraints for fixed 1.284 variables, and declarations for polymorphic constants. 1.286 - The identity of atomic terms consists both of the name and the type. 1.287 - Thus different entities @{text "c\<^bsub>\<tau>\<^isub>1\<^esub>"} and 1.288 - @{text "c\<^bsub>\<tau>\<^isub>2\<^esub>"} may well identified by type 1.289 - instantiation, by mapping @{text "\<tau>\<^isub>1"} and @{text 1.290 - "\<tau>\<^isub>2"} to the same @{text "\<tau>"}. Although, 1.291 - different type instances of constants of the same basic name are 1.292 - commonplace, this rarely happens for variables: type-inference 1.293 - always demands consistent'' type constraints. 1.294 + The identity of atomic terms consists both of the name and the type 1.295 + component. This means that different variables @{text 1.296 + "x\<^bsub>\<tau>\<^isub>1\<^esub>"} and @{text 1.297 + "x\<^bsub>\<tau>\<^isub>2\<^esub>"} may become the same after type 1.298 + instantiation. Some outer layers of the system make it hard to 1.299 + produce variables of the same name, but different types. In 1.300 + particular, type-inference always demands consistent'' type 1.301 + constraints for free variables. In contrast, mixed instances of 1.302 + polymorphic constants occur frequently. 1.304 \medskip The \emph{hidden polymorphism} of a term @{text "t :: \<sigma>"} 1.305 is the set of type variables occurring in @{text "t"}, but not in 1.306 - @{text "\<sigma>"}. This means that the term implicitly depends on the 1.307 - values of various type variables that are not visible in the overall 1.308 - type, i.e.\ there are different type instances @{text "t\<vartheta> 1.309 - :: \<sigma>"} and @{text "t\<vartheta>' :: \<sigma>"} with the same type. This 1.310 - slightly pathological situation is apt to cause strange effects. 1.311 + @{text "\<sigma>"}. This means that the term implicitly depends on type 1.312 + arguments that are not accounted in result type, i.e.\ there are 1.313 + different type instances @{text "t\<vartheta> :: \<sigma>"} and @{text 1.314 + "t\<vartheta>' :: \<sigma>"} with the same type. This slightly 1.315 + pathological situation demands special care. 1.317 \medskip A \emph{term abbreviation} is a syntactic definition @{text 1.318 - "c\<^isub>\<sigma> \<equiv> t"} of an arbitrary closed term @{text "t"} of type 1.319 - @{text "\<sigma>"} without any hidden polymorphism. A term abbreviation 1.320 - looks like a constant at the surface, but is fully expanded before 1.321 - entering the logical core. Abbreviations are usually reverted when 1.322 - printing terms, using rules @{text "t \<rightarrow> c\<^isub>\<sigma>"} has a 1.323 - higher-order term rewrite system. 1.324 + "c\<^isub>\<sigma> \<equiv> t"} of a closed term @{text "t"} of type @{text "\<sigma>"}, 1.325 + without any hidden polymorphism. A term abbreviation looks like a 1.326 + constant in the syntax, but is fully expanded before entering the 1.327 + logical core. Abbreviations are usually reverted when printing 1.328 + terms, using the collective @{text "t \<rightarrow> c\<^isub>\<sigma>"} as rules for 1.329 + higher-order rewriting. 1.331 \medskip Canonical operations on @{text "\<lambda>"}-terms include @{text 1.332 - "\<alpha>\<beta>\<eta>"}-conversion. @{text "\<alpha>"}-conversion refers to capture-free 1.333 + "\<alpha>\<beta>\<eta>"}-conversion: @{text "\<alpha>"}-conversion refers to capture-free 1.334 renaming of bound variables; @{text "\<beta>"}-conversion contracts an 1.335 - abstraction applied to some argument term, substituting the argument 1.336 + abstraction applied to an argument term, substituting the argument 1.337 in the body: @{text "(\<lambda>x. b)a"} becomes @{text "b[a/x]"}; @{text 1.338 "\<eta>"}-conversion contracts vacuous application-abstraction: @{text 1.339 "\<lambda>x. f x"} becomes @{text "f"}, provided that the bound variable 1.340 - @{text "0"} does not occur in @{text "f"}. 1.341 + does not occur in @{text "f"}. 1.343 - Terms are almost always treated module @{text "\<alpha>"}-conversion, which 1.344 - is implicit in the de-Bruijn representation. The names in 1.345 - abstractions of bound variables are maintained only as a comment for 1.346 - parsing and printing. Full @{text "\<alpha>\<beta>\<eta>"}-equivalence is usually 1.347 - taken for granted higher rules (\secref{sec:rules}), anything 1.348 - depending on higher-order unification or rewriting. 1.349 + Terms are normally treated modulo @{text "\<alpha>"}-conversion, which is 1.350 + implicit in the de-Bruijn representation. Names for bound variables 1.351 + in abstractions are maintained separately as (meaningless) comments, 1.352 + mostly for parsing and printing. Full @{text "\<alpha>\<beta>\<eta>"}-conversion is 1.353 + commonplace in various higher operations (\secref{sec:rules}) that 1.354 + are based on higher-order unification and matching. 1.355 *} 1.357 text %mlref {* 1.358 @@ -326,43 +332,43 @@ 1.360 \begin{description} 1.362 - \item @{ML_type term} represents de-Bruijn terms with comments in 1.363 - abstractions for bound variable names. This is a datatype with 1.364 - constructors @{ML Bound}, @{ML Free}, @{ML Var}, @{ML Const}, @{ML 1.365 - Abs}, @{ML "op "}. 1.366 + \item @{ML_type term} represents de-Bruijn terms, with comments in 1.367 + abstractions, and explicitly named free variables and constants; 1.368 + this is a datatype with constructors @{ML Bound}, @{ML Free}, @{ML 1.369 + Var}, @{ML Const}, @{ML Abs}, @{ML "op "}. 1.371 \item @{text "t"}~@{ML aconv}~@{text "u"} checks @{text 1.372 "\<alpha>"}-equivalence of two terms. This is the basic equality relation 1.373 on type @{ML_type term}; raw datatype equality should only be used 1.374 for operations related to parsing or printing! 1.376 - \item @{ML map_term_types}~@{text "f t"} applies mapping @{text "f"} 1.377 - to all types occurring in @{text "t"}. 1.378 + \item @{ML map_term_types}~@{text "f t"} applies the mapping @{text 1.379 + "f"} to all types occurring in @{text "t"}. 1.381 + \item @{ML fold_types}~@{text "f t"} iterates the operation @{text 1.382 + "f"} over all occurrences of types in @{text "t"}; the term 1.383 + structure is traversed from left to right. 1.385 - \item @{ML fold_types}~@{text "f t"} iterates operation @{text "f"} 1.386 - over all occurrences of types in @{text "t"}; the term structure is 1.387 + \item @{ML map_aterms}~@{text "f t"} applies the mapping @{text "f"} 1.388 + to all atomic terms (@{ML Bound}, @{ML Free}, @{ML Var}, @{ML 1.389 + Const}) occurring in @{text "t"}. 1.391 + \item @{ML fold_aterms}~@{text "f t"} iterates the operation @{text 1.392 + "f"} over all occurrences of atomic terms (@{ML Bound}, @{ML Free}, 1.393 + @{ML Var}, @{ML Const}) in @{text "t"}; the term structure is 1.394 traversed from left to right. 1.396 - \item @{ML map_aterms}~@{text "f t"} applies mapping @{text "f"} to 1.397 - all atomic terms (@{ML Bound}, @{ML Free}, @{ML Var}, @{ML Const}) 1.398 - occurring in @{text "t"}. 1.400 - \item @{ML fold_aterms}~@{text "f t"} iterates operation @{text "f"} 1.401 - over all occurrences of atomic terms in (@{ML Bound}, @{ML Free}, 1.402 - @{ML Var}, @{ML Const}) @{text "t"}; the term structure is traversed 1.403 - from left to right. 1.405 - \item @{ML fastype_of}~@{text "t"} recomputes the type of a 1.406 - well-formed term, while omitting any sanity checks. This operation 1.407 - is relatively slow. 1.408 + \item @{ML fastype_of}~@{text "t"} determines the type of a 1.409 + well-typed term. This operation is relatively slow, despite the 1.410 + omission of any sanity checks. 1.412 \item @{ML lambda}~@{text "a b"} produces an abstraction @{text 1.413 - "\<lambda>a. b"}, where occurrences of the original (atomic) term @{text 1.414 - "a"} in the body @{text "b"} are replaced by bound variables. 1.415 + "\<lambda>a. b"}, where occurrences of the atomic term @{text "a"} in the 1.416 + body @{text "b"} are replaced by bound variables. 1.418 - \item @{ML betapply}~@{text "t u"} produces an application @{text "t 1.419 - u"}, with topmost @{text "\<beta>"}-conversion if @{text "t"} happens to 1.420 - be an abstraction. 1.421 + \item @{ML betapply}~@{text "(t, u)"} produces an application @{text 1.422 + "t u"}, with topmost @{text "\<beta>"}-conversion if @{text "t"} is an 1.423 + abstraction. 1.425 \item @{ML Sign.add_consts_i}~@{text "[(c, \<sigma>, mx), \<dots>]"} declares a 1.426 new constant @{text "c :: \<sigma>"} with optional mixfix syntax. 1.427 @@ -373,9 +379,9 @@ 1.429 \item @{ML Sign.const_typargs}~@{text "thy (c, \<tau>)"} and @{ML 1.430 Sign.const_instance}~@{text "thy (c, [\<tau>\<^isub>1, \<dots>, \<tau>\<^isub>n])"} 1.431 - convert between the two representations of constants, namely full 1.432 - type instance vs.\ compact type arguments form (depending on the 1.433 - most general declaration given in the context). 1.434 + convert between the representations of polymorphic constants: the 1.435 + full type instance vs.\ the compact type arguments form (depending 1.436 + on the most general declaration given in the context). 1.438 \end{description} 1.439 *} 1.440 @@ -424,24 +430,23 @@ 1.441 \emph{theorem} is a proven proposition (depending on a context of 1.442 hypotheses and the background theory). Primitive inferences include 1.443 plain natural deduction rules for the primary connectives @{text 1.444 - "\<And>"} and @{text "\<Longrightarrow>"} of the framework. There are separate (derived) 1.445 - rules for equality/equivalence @{text "\<equiv>"} and internal conjunction 1.446 - @{text "&"}. 1.447 + "\<And>"} and @{text "\<Longrightarrow>"} of the framework. There is also a builtin 1.448 + notion of equality/equivalence @{text "\<equiv>"}. 1.449 *} 1.451 -subsection {* Standard connectives and rules *} 1.452 +subsection {* Primitive connectives and rules *} 1.454 text {* 1.455 - The basic theory is called @{text "Pure"}, it contains declarations 1.456 - for the standard logical connectives @{text "\<And>"}, @{text "\<Longrightarrow>"}, and 1.457 - @{text "\<equiv>"} of the framework, see \figref{fig:pure-connectives}. 1.458 - The derivability judgment @{text "A\<^isub>1, \<dots>, A\<^isub>n \<turnstile> B"} is 1.459 - defined inductively by the primitive inferences given in 1.460 - \figref{fig:prim-rules}, with the global syntactic restriction that 1.461 - hypotheses may never contain schematic variables. The builtin 1.462 - equality is conceptually axiomatized shown in 1.463 + The theory @{text "Pure"} contains declarations for the standard 1.464 + connectives @{text "\<And>"}, @{text "\<Longrightarrow>"}, and @{text "\<equiv>"} of the logical 1.465 + framework, see \figref{fig:pure-connectives}. The derivability 1.466 + judgment @{text "A\<^isub>1, \<dots>, A\<^isub>n \<turnstile> B"} is defined 1.467 + inductively by the primitive inferences given in 1.468 + \figref{fig:prim-rules}, with the global restriction that hypotheses 1.469 + @{text "\<Gamma>"} may \emph{not} contain schematic variables. The builtin 1.470 + equality is conceptually axiomatized as shown in 1.471 \figref{fig:pure-equality}, although the implementation works 1.472 - directly with (derived) inference rules. 1.473 + directly with derived inference rules. 1.475 \begin{figure}[htb] 1.476 \begin{center} 1.477 @@ -450,7 +455,7 @@ 1.478 @{text "\<Longrightarrow> :: prop \<Rightarrow> prop \<Rightarrow> prop"} & implication (right associative infix) \\ 1.479 @{text "\<equiv> :: \<alpha> \<Rightarrow> \<alpha> \<Rightarrow> prop"} & equality relation (infix) \\ 1.480 \end{tabular} 1.481 - \caption{Standard connectives of Pure}\label{fig:pure-connectives} 1.482 + \caption{Primitive connectives of Pure}\label{fig:pure-connectives} 1.483 \end{center} 1.484 \end{figure} 1.486 @@ -462,9 +467,9 @@ 1.487 \infer[@{text "(assume)"}]{@{text "A \<turnstile> A"}}{} 1.488$
1.489    $1.490 - \infer[@{text "(\<And>_intro)"}]{@{text "\<Gamma> \<turnstile> \<And>x. b x"}}{@{text "\<Gamma> \<turnstile> b x"} & @{text "x \<notin> \<Gamma>"}} 1.491 + \infer[@{text "(\<And>_intro)"}]{@{text "\<Gamma> \<turnstile> \<And>x. b[x]"}}{@{text "\<Gamma> \<turnstile> b[x]"} & @{text "x \<notin> \<Gamma>"}} 1.492 \qquad 1.493 - \infer[@{text "(\<And>_elim)"}]{@{text "\<Gamma> \<turnstile> b a"}}{@{text "\<Gamma> \<turnstile> \<And>x. b x"}} 1.494 + \infer[@{text "(\<And>_elim)"}]{@{text "\<Gamma> \<turnstile> b[a]"}}{@{text "\<Gamma> \<turnstile> \<And>x. b[x]"}} 1.495$
1.496    \[
1.497    \infer[@{text "(\<Longrightarrow>_intro)"}]{@{text "\<Gamma> - A \<turnstile> A \<Longrightarrow> B"}}{@{text "\<Gamma> \<turnstile> B"}}
1.498 @@ -478,34 +483,34 @@
1.499    \begin{figure}[htb]
1.500    \begin{center}
1.501    \begin{tabular}{ll}
1.502 -  @{text "\<turnstile> (\<lambda>x. b x) a \<equiv> b a"} & @{text "\<beta>"}-conversion \\
1.503 +  @{text "\<turnstile> (\<lambda>x. b[x]) a \<equiv> b[a]"} & @{text "\<beta>"}-conversion \\
1.504    @{text "\<turnstile> x \<equiv> x"} & reflexivity \\
1.505    @{text "\<turnstile> x \<equiv> y \<Longrightarrow> P x \<Longrightarrow> P y"} & substitution \\
1.506    @{text "\<turnstile> (\<And>x. f x \<equiv> g x) \<Longrightarrow> f \<equiv> g"} & extensionality \\
1.507 -  @{text "\<turnstile> (A \<Longrightarrow> B) \<Longrightarrow> (B \<Longrightarrow> A) \<Longrightarrow> A \<equiv> B"} & coincidence with equivalence \\
1.508 +  @{text "\<turnstile> (A \<Longrightarrow> B) \<Longrightarrow> (B \<Longrightarrow> A) \<Longrightarrow> A \<equiv> B"} & logical equivalence \\
1.509    \end{tabular}
1.510 -  \caption{Conceptual axiomatization of builtin equality}\label{fig:pure-equality}
1.511 +  \caption{Conceptual axiomatization of @{text "\<equiv>"}}\label{fig:pure-equality}
1.512    \end{center}
1.513    \end{figure}
1.515    The introduction and elimination rules for @{text "\<And>"} and @{text
1.516 -  "\<Longrightarrow>"} are analogous to formation of (dependently typed) @{text
1.517 +  "\<Longrightarrow>"} are analogous to formation of dependently typed @{text
1.518    "\<lambda>"}-terms representing the underlying proof objects.  Proof terms
1.519 -  are \emph{irrelevant} in the Pure logic, they may never occur within
1.520 -  propositions, i.e.\ the @{text "\<Longrightarrow>"} arrow is non-dependent.  The
1.521 -  system provides a runtime option to record explicit proof terms for
1.522 -  primitive inferences, cf.\ \cite{Berghofer-Nipkow:2000:TPHOL}.  Thus
1.523 -  the three-fold @{text "\<lambda>"}-structure can be made explicit.
1.524 +  are irrelevant in the Pure logic, though, they may never occur
1.525 +  within propositions.  The system provides a runtime option to record
1.526 +  explicit proof terms for primitive inferences.  Thus all three
1.527 +  levels of @{text "\<lambda>"}-calculus become explicit: @{text "\<Rightarrow>"} for
1.528 +  terms, and @{text "\<And>/\<Longrightarrow>"} for proofs (cf.\
1.529 +  \cite{Berghofer-Nipkow:2000:TPHOL}).
1.531 -  Observe that locally fixed parameters (as used in rule @{text
1.532 -  "\<And>_intro"}) need not be recorded in the hypotheses, because the
1.533 -  simple syntactic types of Pure are always inhabitable.  The typing
1.534 -  assumption'' @{text "x :: \<tau>"} is logically vacuous, it disappears
1.535 -  automatically whenever the statement body ceases to mention variable
1.536 -  @{text "x\<^isub>\<tau>"}.\footnote{This greatly simplifies many basic
1.537 -  reasoning steps, and is the key difference to the formulation of
1.538 -  this logic as @{text "\<lambda>HOL"}'' in the PTS framework
1.539 -  \cite{Barendregt-Geuvers:2001}.}
1.540 +  Observe that locally fixed parameters (as in @{text "\<And>_intro"}) need
1.541 +  not be recorded in the hypotheses, because the simple syntactic
1.542 +  types of Pure are always inhabitable.  Typing assumptions'' @{text
1.543 +  "x :: \<tau>"} are (implicitly) present only with occurrences of @{text
1.544 +  "x\<^isub>\<tau>"} in the statement body.\footnote{This is the key
1.545 +  difference @{text "\<lambda>HOL"}'' in the PTS framework
1.546 +  \cite{Barendregt-Geuvers:2001}, where @{text "x : A"} hypotheses are
1.547 +  treated explicitly for types, in the same way as propositions.}
1.549    \medskip FIXME @{text "\<alpha>\<beta>\<eta>"}-equivalence and primitive definitions
1.551 @@ -514,13 +519,11 @@
1.552    "\<alpha>\<beta>\<eta>"}-equivalence on terms, while coinciding with bi-implication.
1.554    \medskip The axiomatization of a theory is implicitly closed by
1.555 -  forming all instances of type and term variables: @{text "\<turnstile> A\<vartheta>"} for
1.556 -  any substitution instance of axiom @{text "\<turnstile> A"}.  By pushing
1.557 -  substitution through derivations inductively, we get admissible
1.558 -  substitution rules for theorems shown in \figref{fig:subst-rules}.
1.559 -  Alternatively, the term substitution rules could be derived from
1.560 -  @{text "\<And>_intro/elim"}.  The versions for types are genuine
1.561 -  admissible rules, due to the lack of true polymorphism in the logic.
1.562 +  forming all instances of type and term variables: @{text "\<turnstile>
1.563 +  A\<vartheta>"} holds for any substitution instance of an axiom
1.564 +  @{text "\<turnstile> A"}.  By pushing substitution through derivations
1.565 +  inductively, we get admissible @{text "generalize"} and @{text
1.566 +  "instance"} rules shown in \figref{fig:subst-rules}.
1.568    \begin{figure}[htb]
1.569    \begin{center}
1.570 @@ -538,11 +541,15 @@
1.571    \end{center}
1.572    \end{figure}
1.574 -  Since @{text "\<Gamma>"} may never contain any schematic variables, the
1.575 -  @{text "instantiate"} do not require an explicit side-condition.  In
1.576 -  principle, variables could be substituted in hypotheses as well, but
1.577 -  this could disrupt monotonicity of the basic calculus: derivations
1.578 -  could leave the current proof context.
1.579 +  Note that @{text "instantiate"} does not require an explicit
1.580 +  side-condition, because @{text "\<Gamma>"} may never contain schematic
1.581 +  variables.
1.583 +  In principle, variables could be substituted in hypotheses as well,
1.584 +  but this would disrupt monotonicity reasoning: deriving @{text
1.585 +  "\<Gamma>\<vartheta> \<turnstile> B\<vartheta>"} from @{text "\<Gamma> \<turnstile> B"} is correct, but
1.586 +  @{text "\<Gamma>\<vartheta> \<supseteq> \<Gamma>"} does not necessarily hold --- the result
1.587 +  belongs to a different proof context.
1.588  *}
1.590  text %mlref {*
1.591 @@ -567,16 +574,16 @@
1.592  subsection {* Auxiliary connectives *}
1.594  text {*
1.595 -  Pure also provides various auxiliary connectives based on primitive
1.596 -  definitions, see \figref{fig:pure-aux}.  These are normally not
1.597 -  exposed to the user, but appear in internal encodings only.
1.598 +  Theory @{text "Pure"} also defines a few auxiliary connectives, see
1.599 +  \figref{fig:pure-aux}.  These are normally not exposed to the user,
1.600 +  but appear in internal encodings only.
1.602    \begin{figure}[htb]
1.603    \begin{center}
1.604    \begin{tabular}{ll}
1.605    @{text "conjunction :: prop \<Rightarrow> prop \<Rightarrow> prop"} & (infix @{text "&"}) \\
1.606    @{text "\<turnstile> A & B \<equiv> (\<And>C. (A \<Longrightarrow> B \<Longrightarrow> C) \<Longrightarrow> C)"} \\[1ex]
1.607 -  @{text "prop :: prop \<Rightarrow> prop"} & (prefix @{text "#"}) \\
1.608 +  @{text "prop :: prop \<Rightarrow> prop"} & (prefix @{text "#"}, hidden) \\
1.609    @{text "#A \<equiv> A"} \\[1ex]
1.610    @{text "term :: \<alpha> \<Rightarrow> prop"} & (prefix @{text "TERM"}) \\
1.611    @{text "term x \<equiv> (\<And>A. A \<Longrightarrow> A)"} \\[1ex]
1.612 @@ -587,39 +594,38 @@
1.613    \end{center}
1.614    \end{figure}
1.616 -  Conjunction as an explicit connective allows to treat both
1.617 -  simultaneous assumptions and conclusions uniformly.  The definition
1.618 -  allows to derive the usual introduction @{text "\<turnstile> A \<Longrightarrow> B \<Longrightarrow> A & B"},
1.619 -  and destructions @{text "A & B \<Longrightarrow> A"} and @{text "A & B \<Longrightarrow> B"}.  For
1.620 -  example, several claims may be stated at the same time, which is
1.621 -  intermediately represented as an assumption, but the user only
1.622 -  encounters several sub-goals, and several resulting facts in the
1.623 -  very end (cf.\ \secref{sec:tactical-goals}).
1.624 +  Derived conjunction rules include introduction @{text "A \<Longrightarrow> B \<Longrightarrow> A &
1.625 +  B"}, and destructions @{text "A & B \<Longrightarrow> A"} and @{text "A & B \<Longrightarrow> B"}.
1.626 +  Conjunction allows to treat simultaneous assumptions and conclusions
1.627 +  uniformly.  For example, multiple claims are intermediately
1.628 +  represented as explicit conjunction, but this is usually refined
1.629 +  into separate sub-goals before the user continues the proof; the
1.630 +  final result is projected into a list of theorems (cf.\
1.631 +  \secref{sec:tactical-goals}).
1.633 -  The @{text "#"} marker allows complex propositions (nested @{text
1.634 -  "\<And>"} and @{text "\<Longrightarrow>"}) to appear formally as atomic, without changing
1.635 -  the meaning: @{text "\<Gamma> \<turnstile> A"} and @{text "\<Gamma> \<turnstile> #A"} are
1.636 -  interchangeable.  See \secref{sec:tactical-goals} for specific
1.637 -  operations.
1.638 +  The @{text "prop"} marker (@{text "#"}) makes arbitrarily complex
1.639 +  propositions appear as atomic, without changing the meaning: @{text
1.640 +  "\<Gamma> \<turnstile> A"} and @{text "\<Gamma> \<turnstile> #A"} are interchangeable.  See
1.641 +  \secref{sec:tactical-goals} for specific operations.
1.643 -  The @{text "TERM"} marker turns any well-formed term into a
1.644 -  derivable proposition: @{text "\<turnstile> TERM t"} holds
1.645 -  unconditionally.  Despite its logically vacous meaning, this is
1.646 -  occasionally useful to treat syntactic terms and proven propositions
1.647 -  uniformly, as in a type-theoretic framework.
1.648 +  The @{text "term"} marker turns any well-formed term into a
1.649 +  derivable proposition: @{text "\<turnstile> TERM t"} holds unconditionally.
1.650 +  Although this is logically vacuous, it allows to treat terms and
1.651 +  proofs uniformly, similar to a type-theoretic framework.
1.653 -  The @{text "TYPE"} constructor (which is the canonical
1.654 -  representative of the unspecified type @{text "\<alpha> itself"}) injects
1.655 -  the language of types into that of terms.  There is specific
1.656 -  notation @{text "TYPE(\<tau>)"} for @{text "TYPE\<^bsub>\<tau>
1.657 +  The @{text "TYPE"} constructor is the canonical representative of
1.658 +  the unspecified type @{text "\<alpha> itself"}; it essentially injects the
1.659 +  language of types into that of terms.  There is specific notation
1.660 +  @{text "TYPE(\<tau>)"} for @{text "TYPE\<^bsub>\<tau>
1.661   itself\<^esub>"}.
1.662 -  Although being devoid of any particular meaning, the term @{text
1.663 -  "TYPE(\<tau>)"} is able to carry the type @{text "\<tau>"} formally.  @{text
1.664 -  "TYPE(\<alpha>)"} may be used as an additional formal argument in primitive
1.665 -  definitions, in order to avoid hidden polymorphism (cf.\
1.666 -  \secref{sec:terms}).  For example, @{text "c TYPE(\<alpha>) \<equiv> A[\<alpha>]"} turns
1.667 -  out as a formally correct definition of some proposition @{text "A"}
1.668 -  that depends on an additional type argument.
1.669 +  Although being devoid of any particular meaning, the @{text
1.670 +  "TYPE(\<tau>)"} accounts for the type @{text "\<tau>"} within the term
1.671 +  language.  In particular, @{text "TYPE(\<alpha>)"} may be used as formal
1.672 +  argument in primitive definitions, in order to circumvent hidden
1.673 +  polymorphism (cf.\ \secref{sec:terms}).  For example, @{text "c
1.674 +  TYPE(\<alpha>) \<equiv> A[\<alpha>]"} defines @{text "c :: \<alpha> itself \<Rightarrow> prop"} in terms of
1.675 +  a proposition @{text "A"} that depends on an additional type
1.676 +  argument, which is essentially a predicate on types.
1.677  *}
1.679  text %mlref {*