doc-src/IsarRef/Thy/Spec.thy
changeset 47483 3f704717a67f
parent 47482 a83b25e5bad3
child 47484 e94cc23d434a
equal deleted inserted replaced
47482:a83b25e5bad3 47483:3f704717a67f
   102 *}
   102 *}
   103 
   103 
   104 
   104 
   105 section {* Local theory targets \label{sec:target} *}
   105 section {* Local theory targets \label{sec:target} *}
   106 
   106 
   107 text {* A local theory target is a context managed separately within
   107 text {*
   108   the enclosing theory.  Contexts may introduce parameters (fixed
   108   \begin{matharray}{rcll}
       
   109     @{command_def "context"} & : & @{text "theory \<rightarrow> local_theory"} \\
       
   110     @{command_def (local) "end"} & : & @{text "local_theory \<rightarrow> theory"} \\
       
   111   \end{matharray}
       
   112 
       
   113   A local theory target is a context managed separately within the
       
   114   enclosing theory.  Contexts may introduce parameters (fixed
   109   variables) and assumptions (hypotheses).  Definitions and theorems
   115   variables) and assumptions (hypotheses).  Definitions and theorems
   110   depending on the context may be added incrementally later on.
   116   depending on the context may be added incrementally later on.
   111 
   117 
   112   \emph{Named contexts} refer to locales (cf.\ \secref{sec:locale}) or
   118   \emph{Named contexts} refer to locales (cf.\ \secref{sec:locale}) or
   113   type classes (cf.\ \secref{sec:class}); the name ``@{text "-"}''
   119   type classes (cf.\ \secref{sec:class}); the name ``@{text "-"}''
   116   \emph{Unnamed contexts} may introduce additional parameters and
   122   \emph{Unnamed contexts} may introduce additional parameters and
   117   assumptions, and results produced in the context are generalized
   123   assumptions, and results produced in the context are generalized
   118   accordingly.  Such auxiliary contexts may be nested within other
   124   accordingly.  Such auxiliary contexts may be nested within other
   119   targets, like @{command "locale"}, @{command "class"}, @{command
   125   targets, like @{command "locale"}, @{command "class"}, @{command
   120   "instantiation"}, @{command "overloading"}.
   126   "instantiation"}, @{command "overloading"}.
   121 
       
   122   \begin{matharray}{rcll}
       
   123     @{command_def "context"} & : & @{text "theory \<rightarrow> local_theory"} \\
       
   124     @{command_def (local) "end"} & : & @{text "local_theory \<rightarrow> theory"} \\
       
   125   \end{matharray}
       
   126 
   127 
   127   @{rail "
   128   @{rail "
   128     @@{command context} (@{syntax nameref} | (@{syntax context_elem}+)) @'begin'
   129     @@{command context} (@{syntax nameref} | (@{syntax context_elem}+)) @'begin'
   129     ;
   130     ;
   130 
   131 
   273 
   274 
   274 
   275 
   275 section {* Generic declarations *}
   276 section {* Generic declarations *}
   276 
   277 
   277 text {*
   278 text {*
       
   279   \begin{matharray}{rcl}
       
   280     @{command_def "declaration"} & : & @{text "local_theory \<rightarrow> local_theory"} \\
       
   281     @{command_def "syntax_declaration"} & : & @{text "local_theory \<rightarrow> local_theory"} \\
       
   282     @{command_def "declare"} & : & @{text "local_theory \<rightarrow> local_theory"} \\
       
   283   \end{matharray}
       
   284 
   278   Arbitrary operations on the background context may be wrapped-up as
   285   Arbitrary operations on the background context may be wrapped-up as
   279   generic declaration elements.  Since the underlying concept of local
   286   generic declaration elements.  Since the underlying concept of local
   280   theories may be subject to later re-interpretation, there is an
   287   theories may be subject to later re-interpretation, there is an
   281   additional dependency on a morphism that tells the difference of the
   288   additional dependency on a morphism that tells the difference of the
   282   original declaration context wrt.\ the application context
   289   original declaration context wrt.\ the application context
   283   encountered later on.  A fact declaration is an important special
   290   encountered later on.  A fact declaration is an important special
   284   case: it consists of a theorem which is applied to the context by
   291   case: it consists of a theorem which is applied to the context by
   285   means of an attribute.
   292   means of an attribute.
   286 
       
   287   \begin{matharray}{rcl}
       
   288     @{command_def "declaration"} & : & @{text "local_theory \<rightarrow> local_theory"} \\
       
   289     @{command_def "syntax_declaration"} & : & @{text "local_theory \<rightarrow> local_theory"} \\
       
   290     @{command_def "declare"} & : & @{text "local_theory \<rightarrow> local_theory"} \\
       
   291   \end{matharray}
       
   292 
   293 
   293   @{rail "
   294   @{rail "
   294     (@@{command declaration} | @@{command syntax_declaration})
   295     (@@{command declaration} | @@{command syntax_declaration})
   295       ('(' @'pervasive' ')')? \\ @{syntax target}? @{syntax text}
   296       ('(' @'pervasive' ')')? \\ @{syntax target}? @{syntax text}
   296     ;
   297     ;
   514 
   515 
   515 
   516 
   516 subsection {* Locale interpretations *}
   517 subsection {* Locale interpretations *}
   517 
   518 
   518 text {*
   519 text {*
       
   520   \begin{matharray}{rcl}
       
   521     @{command_def "interpretation"} & : & @{text "theory \<rightarrow> proof(prove)"} \\
       
   522     @{command_def "interpret"} & : & @{text "proof(state) | proof(chain) \<rightarrow> proof(prove)"} \\
       
   523     @{command_def "sublocale"} & : & @{text "theory \<rightarrow> proof(prove)"} \\
       
   524     @{command_def "print_dependencies"}@{text "\<^sup>*"} & : & @{text "context \<rightarrow>"} \\
       
   525     @{command_def "print_interps"}@{text "\<^sup>*"} & : & @{text "context \<rightarrow>"} \\
       
   526   \end{matharray}
       
   527 
   519   Locale expressions may be instantiated, and the instantiated facts
   528   Locale expressions may be instantiated, and the instantiated facts
   520   added to the current context.  This requires a proof of the
   529   added to the current context.  This requires a proof of the
   521   instantiated specification and is called \emph{locale
   530   instantiated specification and is called \emph{locale
   522   interpretation}.  Interpretation is possible in locales @{command
   531   interpretation}.  Interpretation is possible in locales @{command
   523   "sublocale"}, theories (command @{command "interpretation"}) and
   532   "sublocale"}, theories (command @{command "interpretation"}) and
   524   also within a proof body (command @{command "interpret"}).
   533   also within a proof body (command @{command "interpret"}).
   525 
       
   526   \begin{matharray}{rcl}
       
   527     @{command_def "interpretation"} & : & @{text "theory \<rightarrow> proof(prove)"} \\
       
   528     @{command_def "interpret"} & : & @{text "proof(state) | proof(chain) \<rightarrow> proof(prove)"} \\
       
   529     @{command_def "sublocale"} & : & @{text "theory \<rightarrow> proof(prove)"} \\
       
   530     @{command_def "print_dependencies"}@{text "\<^sup>*"} & : & @{text "context \<rightarrow>"} \\
       
   531     @{command_def "print_interps"}@{text "\<^sup>*"} & : & @{text "context \<rightarrow>"} \\
       
   532   \end{matharray}
       
   533 
   534 
   534   @{rail "
   535   @{rail "
   535     @@{command interpretation} @{syntax locale_expr} equations?
   536     @@{command interpretation} @{syntax locale_expr} equations?
   536     ;
   537     ;
   537     @@{command interpret} @{syntax locale_expr} equations?
   538     @@{command interpret} @{syntax locale_expr} equations?
   650 
   651 
   651 
   652 
   652 section {* Classes \label{sec:class} *}
   653 section {* Classes \label{sec:class} *}
   653 
   654 
   654 text {*
   655 text {*
   655   A class is a particular locale with \emph{exactly one} type variable
       
   656   @{text \<alpha>}.  Beyond the underlying locale, a corresponding type class
       
   657   is established which is interpreted logically as axiomatic type
       
   658   class \cite{Wenzel:1997:TPHOL} whose logical content are the
       
   659   assumptions of the locale.  Thus, classes provide the full
       
   660   generality of locales combined with the commodity of type classes
       
   661   (notably type-inference).  See \cite{isabelle-classes} for a short
       
   662   tutorial.
       
   663 
       
   664   \begin{matharray}{rcl}
   656   \begin{matharray}{rcl}
   665     @{command_def "class"} & : & @{text "theory \<rightarrow> local_theory"} \\
   657     @{command_def "class"} & : & @{text "theory \<rightarrow> local_theory"} \\
   666     @{command_def "instantiation"} & : & @{text "theory \<rightarrow> local_theory"} \\
   658     @{command_def "instantiation"} & : & @{text "theory \<rightarrow> local_theory"} \\
   667     @{command_def "instance"} & : & @{text "local_theory \<rightarrow> local_theory"} \\
   659     @{command_def "instance"} & : & @{text "local_theory \<rightarrow> local_theory"} \\
   668     @{command "instance"} & : & @{text "theory \<rightarrow> proof(prove)"} \\
   660     @{command "instance"} & : & @{text "theory \<rightarrow> proof(prove)"} \\
   670     @{command_def "print_classes"}@{text "\<^sup>*"} & : & @{text "context \<rightarrow>"} \\
   662     @{command_def "print_classes"}@{text "\<^sup>*"} & : & @{text "context \<rightarrow>"} \\
   671     @{command_def "class_deps"}@{text "\<^sup>*"} & : & @{text "context \<rightarrow>"} \\
   663     @{command_def "class_deps"}@{text "\<^sup>*"} & : & @{text "context \<rightarrow>"} \\
   672     @{method_def intro_classes} & : & @{text method} \\
   664     @{method_def intro_classes} & : & @{text method} \\
   673   \end{matharray}
   665   \end{matharray}
   674 
   666 
       
   667   A class is a particular locale with \emph{exactly one} type variable
       
   668   @{text \<alpha>}.  Beyond the underlying locale, a corresponding type class
       
   669   is established which is interpreted logically as axiomatic type
       
   670   class \cite{Wenzel:1997:TPHOL} whose logical content are the
       
   671   assumptions of the locale.  Thus, classes provide the full
       
   672   generality of locales combined with the commodity of type classes
       
   673   (notably type-inference).  See \cite{isabelle-classes} for a short
       
   674   tutorial.
       
   675 
   675   @{rail "
   676   @{rail "
   676     @@{command class} class_spec @'begin'?
   677     @@{command class} class_spec @'begin'?
   677     ;
   678     ;
   678     class_spec: @{syntax name} '='
   679     class_spec: @{syntax name} '='
   679       ((@{syntax nameref} '+' (@{syntax context_elem}+)) |
   680       ((@{syntax nameref} '+' (@{syntax context_elem}+)) |
   826 
   827 
   827 
   828 
   828 section {* Unrestricted overloading *}
   829 section {* Unrestricted overloading *}
   829 
   830 
   830 text {*
   831 text {*
       
   832   \begin{matharray}{rcl}
       
   833     @{command_def "overloading"} & : & @{text "theory \<rightarrow> local_theory"} \\
       
   834   \end{matharray}
       
   835 
   831   Isabelle/Pure's definitional schemes support certain forms of
   836   Isabelle/Pure's definitional schemes support certain forms of
   832   overloading (see \secref{sec:consts}).  Overloading means that a
   837   overloading (see \secref{sec:consts}).  Overloading means that a
   833   constant being declared as @{text "c :: \<alpha> decl"} may be
   838   constant being declared as @{text "c :: \<alpha> decl"} may be
   834   defined separately on type instances
   839   defined separately on type instances
   835   @{text "c :: (\<beta>\<^sub>1, \<dots>, \<beta>\<^sub>n) t decl"}
   840   @{text "c :: (\<beta>\<^sub>1, \<dots>, \<beta>\<^sub>n) t decl"}
   838   type classes by means of @{command "instantiation"} (see
   843   type classes by means of @{command "instantiation"} (see
   839   \secref{sec:class}).  Sometimes low-level overloading is desirable.
   844   \secref{sec:class}).  Sometimes low-level overloading is desirable.
   840   The @{command "overloading"} target provides a convenient view for
   845   The @{command "overloading"} target provides a convenient view for
   841   end-users.
   846   end-users.
   842 
   847 
   843   \begin{matharray}{rcl}
       
   844     @{command_def "overloading"} & : & @{text "theory \<rightarrow> local_theory"} \\
       
   845   \end{matharray}
       
   846 
       
   847   @{rail "
   848   @{rail "
   848     @@{command overloading} ( spec + ) @'begin'
   849     @@{command overloading} ( spec + ) @'begin'
   849     ;
   850     ;
   850     spec: @{syntax name} ( '==' | '\<equiv>' ) @{syntax term} ( '(' @'unchecked' ')' )?
   851     spec: @{syntax name} ( '==' | '\<equiv>' ) @{syntax term} ( '(' @'unchecked' ')' )?
   851   "}
   852   "}
  1057 
  1058 
  1058 
  1059 
  1059 subsection {* Constants and definitions \label{sec:consts} *}
  1060 subsection {* Constants and definitions \label{sec:consts} *}
  1060 
  1061 
  1061 text {*
  1062 text {*
       
  1063   \begin{matharray}{rcl}
       
  1064     @{command_def "consts"} & : & @{text "theory \<rightarrow> theory"} \\
       
  1065     @{command_def "defs"} & : & @{text "theory \<rightarrow> theory"} \\
       
  1066   \end{matharray}
       
  1067 
  1062   Definitions essentially express abbreviations within the logic.  The
  1068   Definitions essentially express abbreviations within the logic.  The
  1063   simplest form of a definition is @{text "c :: \<sigma> \<equiv> t"}, where @{text
  1069   simplest form of a definition is @{text "c :: \<sigma> \<equiv> t"}, where @{text
  1064   c} is a newly declared constant.  Isabelle also allows derived forms
  1070   c} is a newly declared constant.  Isabelle also allows derived forms
  1065   where the arguments of @{text c} appear on the left, abbreviating a
  1071   where the arguments of @{text c} appear on the left, abbreviating a
  1066   prefix of @{text \<lambda>}-abstractions, e.g.\ @{text "c \<equiv> \<lambda>x y. t"} may be
  1072   prefix of @{text \<lambda>}-abstractions, e.g.\ @{text "c \<equiv> \<lambda>x y. t"} may be
  1094   specification patterns impose global constraints on all occurrences,
  1100   specification patterns impose global constraints on all occurrences,
  1095   e.g.\ @{text "d :: \<alpha> \<times> \<alpha>"} on the left-hand side means that all
  1101   e.g.\ @{text "d :: \<alpha> \<times> \<alpha>"} on the left-hand side means that all
  1096   corresponding occurrences on some right-hand side need to be an
  1102   corresponding occurrences on some right-hand side need to be an
  1097   instance of this, general @{text "d :: \<alpha> \<times> \<beta>"} will be disallowed.
  1103   instance of this, general @{text "d :: \<alpha> \<times> \<beta>"} will be disallowed.
  1098 
  1104 
  1099   \begin{matharray}{rcl}
       
  1100     @{command_def "consts"} & : & @{text "theory \<rightarrow> theory"} \\
       
  1101     @{command_def "defs"} & : & @{text "theory \<rightarrow> theory"} \\
       
  1102   \end{matharray}
       
  1103 
       
  1104   @{rail "
  1105   @{rail "
  1105     @@{command consts} ((@{syntax name} '::' @{syntax type} @{syntax mixfix}?) +)
  1106     @@{command consts} ((@{syntax name} '::' @{syntax type} @{syntax mixfix}?) +)
  1106     ;
  1107     ;
  1107     @@{command defs} opt? (@{syntax axmdecl} @{syntax prop} +)
  1108     @@{command defs} opt? (@{syntax axmdecl} @{syntax prop} +)
  1108     ;
  1109     ;
  1174 *}
  1175 *}
  1175 
  1176 
  1176 
  1177 
  1177 section {* Oracles *}
  1178 section {* Oracles *}
  1178 
  1179 
  1179 text {* Oracles allow Isabelle to take advantage of external reasoners
  1180 text {*
  1180   such as arithmetic decision procedures, model checkers, fast
  1181   \begin{matharray}{rcll}
  1181   tautology checkers or computer algebra systems.  Invoked as an
  1182     @{command_def "oracle"} & : & @{text "theory \<rightarrow> theory"} & (axiomatic!) \\
  1182   oracle, an external reasoner can create arbitrary Isabelle theorems.
  1183   \end{matharray}
       
  1184 
       
  1185   Oracles allow Isabelle to take advantage of external reasoners such
       
  1186   as arithmetic decision procedures, model checkers, fast tautology
       
  1187   checkers or computer algebra systems.  Invoked as an oracle, an
       
  1188   external reasoner can create arbitrary Isabelle theorems.
  1183 
  1189 
  1184   It is the responsibility of the user to ensure that the external
  1190   It is the responsibility of the user to ensure that the external
  1185   reasoner is as trustworthy as the application requires.  Another
  1191   reasoner is as trustworthy as the application requires.  Another
  1186   typical source of errors is the linkup between Isabelle and the
  1192   typical source of errors is the linkup between Isabelle and the
  1187   external tool, not just its concrete implementation, but also the
  1193   external tool, not just its concrete implementation, but also the
  1188   required translation between two different logical environments.
  1194   required translation between two different logical environments.
  1189 
  1195 
  1190   Isabelle merely guarantees well-formedness of the propositions being
  1196   Isabelle merely guarantees well-formedness of the propositions being
  1191   asserted, and records within the internal derivation object how
  1197   asserted, and records within the internal derivation object how
  1192   presumed theorems depend on unproven suppositions.
  1198   presumed theorems depend on unproven suppositions.
  1193 
       
  1194   \begin{matharray}{rcll}
       
  1195     @{command_def "oracle"} & : & @{text "theory \<rightarrow> theory"} & (axiomatic!) \\
       
  1196   \end{matharray}
       
  1197 
  1199 
  1198   @{rail "
  1200   @{rail "
  1199     @@{command oracle} @{syntax name} '=' @{syntax text}
  1201     @@{command oracle} @{syntax name} '=' @{syntax text}
  1200   "}
  1202   "}
  1201 
  1203