doc-src/IsarRef/pure.tex
changeset 9605 60d8c954390f
parent 9471 f778551af3ed
child 9695 ec7d7f877712
equal deleted inserted replaced
9604:abe51fcb2222 9605:60d8c954390f
   290   prefixed by the syntactic category to be used for parsing; the default is
   290   prefixed by the syntactic category to be used for parsing; the default is
   291   \texttt{logic}.
   291   \texttt{logic}.
   292 \end{descr}
   292 \end{descr}
   293 
   293 
   294 
   294 
   295 \subsection{Axioms and theorems}
   295 \subsection{Axioms and theorems}\label{sec:axms-thms}
   296 
   296 
   297 \indexisarcmd{axioms}\indexisarcmd{theorems}\indexisarcmd{lemmas}
   297 \indexisarcmd{axioms}\indexisarcmd{theorems}\indexisarcmd{lemmas}
   298 \begin{matharray}{rcl}
   298 \begin{matharray}{rcl}
   299   \isarcmd{axioms} & : & \isartrans{theory}{theory} \\
   299   \isarcmd{axioms} & : & \isartrans{theory}{theory} \\
   300   \isarcmd{theorems} & : & \isartrans{theory}{theory} \\
   300   \isarcmd{theorems} & : & \isartrans{theory}{theory} \\
   428   general.  The following simple examples are for methods without any explicit
   428   general.  The following simple examples are for methods without any explicit
   429   arguments, or a list of theorems, respectively.
   429   arguments, or a list of theorems, respectively.
   430 
   430 
   431 {\footnotesize
   431 {\footnotesize
   432 \begin{verbatim}
   432 \begin{verbatim}
   433 Method.no_args (Method.METHOD (fn facts => foobar_tac))
   433  Method.no_args (Method.METHOD (fn facts => foobar_tac))
   434 Method.thms_args (fn thms => (Method.METHOD (fn facts => foobar_tac)))
   434  Method.thms_args (fn thms => Method.METHOD (fn facts => foobar_tac))
   435 \end{verbatim}
   435 \end{verbatim}
   436 }
   436 }
   437 
   437 
   438 Note that mere tactic emulations may ignore the \texttt{facts} parameter
   438 Note that mere tactic emulations may ignore the \texttt{facts} parameter
   439 above.  Proper proof methods would do something ``appropriate'' with the list
   439 above.  Proper proof methods would do something ``appropriate'' with the list
  1024   $\PRESUMENAME$ in this mode of forward reasoning --- in contrast to plain
  1024   $\PRESUMENAME$ in this mode of forward reasoning --- in contrast to plain
  1025   backward reasoning with the result exported at $\SHOWNAME$ time.
  1025   backward reasoning with the result exported at $\SHOWNAME$ time.
  1026 \end{descr}
  1026 \end{descr}
  1027 
  1027 
  1028 
  1028 
  1029 \subsection{Emulating tactic scripts}\label{sec:tactical-proof}
  1029 \subsection{Emulating tactic scripts}\label{sec:tactic-commands}
  1030 
  1030 
  1031 The following elements emulate unstructured tactic scripts to some extent.
  1031 The Isar provides separate commands to accommodate tactic-style proof scripts
  1032 While these are anathema for writing proper Isar proof documents, they might
  1032 within the same system.  While being outside the orthodox Isar proof language,
  1033 come in handy for interactive exploration and debugging, or even actual
  1033 these might come in handy for interactive exploration and debugging, or even
  1034 tactical proof within new-style theories (to benefit from document
  1034 actual tactical proof within new-style theories (to benefit from document
  1035 preparation, for example).
  1035 preparation, for example).  See also \S\ref{sec:tactics} for actual tactics,
  1036 
  1036 that have been encapsulated as proof methods.  Proper proof methods may be
  1037 \indexisarcmd{apply}\indexisarcmd{done}\indexisarcmd{apply-end}
  1037 used in scripts, too.
       
  1038 
       
  1039 \indexisarcmd{apply}\indexisarcmd{apply-end}\indexisarcmd{done}
  1038 \indexisarcmd{defer}\indexisarcmd{prefer}\indexisarcmd{back}
  1040 \indexisarcmd{defer}\indexisarcmd{prefer}\indexisarcmd{back}
       
  1041 \indexisarcmd{declare}
  1039 \begin{matharray}{rcl}
  1042 \begin{matharray}{rcl}
  1040   \isarcmd{apply}^* & : & \isartrans{proof(prove)}{proof(prove)} \\
  1043   \isarcmd{apply}^* & : & \isartrans{proof(prove)}{proof(prove)} \\
       
  1044   \isarcmd{apply_end}^* & : & \isartrans{proof(state)}{proof(state)} \\
  1041   \isarcmd{done}^* & : & \isartrans{proof(prove)}{proof(state)} \\
  1045   \isarcmd{done}^* & : & \isartrans{proof(prove)}{proof(state)} \\
  1042   \isarcmd{apply_end}^* & : & \isartrans{proof(state)}{proof(state)} \\
       
  1043   \isarcmd{defer}^* & : & \isartrans{proof}{proof} \\
  1046   \isarcmd{defer}^* & : & \isartrans{proof}{proof} \\
  1044   \isarcmd{prefer}^* & : & \isartrans{proof}{proof} \\
  1047   \isarcmd{prefer}^* & : & \isartrans{proof}{proof} \\
  1045   \isarcmd{back}^* & : & \isartrans{proof}{proof} \\
  1048   \isarcmd{back}^* & : & \isartrans{proof}{proof} \\
       
  1049   \isarcmd{declare}^* & : & \isartrans{theory}{theory} \\
  1046 \end{matharray}
  1050 \end{matharray}
  1047 
  1051 
  1048 \railalias{applyend}{apply\_end}
  1052 \railalias{applyend}{apply\_end}
  1049 \railterm{applyend}
  1053 \railterm{applyend}
  1050 
  1054 
  1051 \begin{rail}
  1055 \begin{rail}
  1052   'apply' method comment?
  1056   ( 'apply' | applyend ) method comment?
  1053   ;
  1057   ;
  1054   'done' comment?
  1058   'done' comment?
  1055   ;
  1059   ;
  1056   applyend method comment?
       
  1057   ;
       
  1058   'defer' nat? comment?
  1060   'defer' nat? comment?
  1059   ;
  1061   ;
  1060   'prefer' nat comment?
  1062   'prefer' nat comment?
  1061   ;
  1063   ;
  1062   'back' comment?
  1064   'back' comment?
       
  1065   ;
       
  1066   'declare' thmrefs comment?
  1063   ;
  1067   ;
  1064 \end{rail}
  1068 \end{rail}
  1065 
  1069 
  1066 \begin{descr}
  1070 \begin{descr}
  1067 \item [$\isarkeyword{apply}~(m)$] applies proof method $m$ in initial
  1071 \item [$\isarkeyword{apply}~(m)$] applies proof method $m$ in initial
  1070   
  1074   
  1071   Facts are passed to $m$ as indicated by the goal's forward-chain mode, and
  1075   Facts are passed to $m$ as indicated by the goal's forward-chain mode, and
  1072   are \emph{consumed} afterwards.  Thus any further $\isarkeyword{apply}$
  1076   are \emph{consumed} afterwards.  Thus any further $\isarkeyword{apply}$
  1073   command would always work in a purely backward manner.
  1077   command would always work in a purely backward manner.
  1074   
  1078   
       
  1079 \item [$\isarkeyword{apply_end}~(m)$] applies proof method $m$ as if in
       
  1080   terminal position.  Basically, this simulates a multi-step tactic script for
       
  1081   $\QEDNAME$, but may be given anywhere within the proof body.
       
  1082   
       
  1083   No facts are passed to $m$.  Furthermore, the static context is that of the
       
  1084   enclosing goal (as for actual $\QEDNAME$).  Thus the proof method may not
       
  1085   refer to any assumptions introduced in the current body, for example.
       
  1086 
  1075 \item [$\isarkeyword{done}$] completes a proof script, provided that the
  1087 \item [$\isarkeyword{done}$] completes a proof script, provided that the
  1076   current goal state is already solved completely.  Note that actual
  1088   current goal state is already solved completely.  Note that actual
  1077   structured proof commands (e.g.\ ``$\DOT$'' or $\SORRY$) may be used to
  1089   structured proof commands (e.g.\ ``$\DOT$'' or $\SORRY$) may be used to
  1078   conclude proof scripts as well.
  1090   conclude proof scripts as well.
  1079 
  1091 
  1080 \item [$\isarkeyword{apply_end}~(m)$] applies proof method $m$ as if in
       
  1081   terminal position.  Basically, this simulates a multi-step tactic script for
       
  1082   $\QEDNAME$, but may be given anywhere within the proof body.
       
  1083   
       
  1084   No facts are passed to $m$.  Furthermore, the static context is that of the
       
  1085   enclosing goal (as for actual $\QEDNAME$).  Thus the proof method may not
       
  1086   refer to any assumptions introduced in the current body, for example.
       
  1087 \item [$\isarkeyword{defer}~n$ and $\isarkeyword{prefer}~n$] shuffle the list
  1092 \item [$\isarkeyword{defer}~n$ and $\isarkeyword{prefer}~n$] shuffle the list
  1088   of pending goals: $defer$ puts off goal $n$ to the end of the list ($n = 1$
  1093   of pending goals: $defer$ puts off goal $n$ to the end of the list ($n = 1$
  1089   by default), while $prefer$ brings goal $n$ to the top.
  1094   by default), while $prefer$ brings goal $n$ to the top.
       
  1095 
  1090 \item [$\isarkeyword{back}$] does back-tracking over the result sequence of
  1096 \item [$\isarkeyword{back}$] does back-tracking over the result sequence of
  1091   the latest proof command.\footnote{Unlike the ML function \texttt{back}
  1097   the latest proof command.\footnote{Unlike the ML function \texttt{back}
  1092     \cite{isabelle-ref}, the Isar command does not search upwards for further
  1098     \cite{isabelle-ref}, the Isar command does not search upwards for further
  1093     branch points.} Basically, any proof command may return multiple results.
  1099     branch points.} Basically, any proof command may return multiple results.
       
  1100   
       
  1101 \item [$\isarkeyword{declare}~thms$] declares theorems to the current theory
       
  1102   context.  No theorem binding is involved here, unlike
       
  1103   $\isarkeyword{theorems}$ or $\isarkeyword{lemmas}$ (cf.\ 
       
  1104   \S\ref{sec:axms-thms}).  So $\isarkeyword{declare}$ only has the effect of
       
  1105   applying attributes as included in the theorem specification.
  1094 \end{descr}
  1106 \end{descr}
  1095 
  1107 
  1096 Any proper Isar proof method may be used with tactic script commands such as
  1108 Any proper Isar proof method may be used with tactic script commands such as
  1097 $\isarkeyword{apply}$.  A few additional emulations of actual tactics are
  1109 $\isarkeyword{apply}$.  A few additional emulations of actual tactics are
  1098 provided as well; these would be never used in actual structured proofs, of
  1110 provided as well; these would be never used in actual structured proofs, of
  1099 course.
  1111 course.
  1100 
       
  1101 \indexisarmeth{tactic}\indexisarmeth{insert}
       
  1102 \indexisarmeth{res-inst-tac}\indexisarmeth{eres-inst-tac}
       
  1103 \indexisarmeth{dres-inst-tac}\indexisarmeth{forw-inst-tac}
       
  1104 \indexisarmeth{subgoal-tac}
       
  1105 \begin{matharray}{rcl}
       
  1106   tactic^* & : & \isarmeth \\
       
  1107   insert^* & : & \isarmeth \\
       
  1108   res_inst_tac^* & : & \isarmeth \\
       
  1109   eres_inst_tac^* & : & \isarmeth \\
       
  1110   dres_inst_tac^* & : & \isarmeth \\
       
  1111   forw_inst_tac^* & : & \isarmeth \\
       
  1112   subgoal_tac^* & : & \isarmeth \\
       
  1113 \end{matharray}
       
  1114 
       
  1115 \railalias{resinsttac}{res\_inst\_tac}
       
  1116 \railterm{resinsttac}
       
  1117 
       
  1118 \railalias{eresinsttac}{eres\_inst\_tac}
       
  1119 \railterm{eresinsttac}
       
  1120 
       
  1121 \railalias{dresinsttac}{dres\_inst\_tac}
       
  1122 \railterm{dresinsttac}
       
  1123 
       
  1124 \railalias{forwinsttac}{forw\_inst\_tac}
       
  1125 \railterm{forwinsttac}
       
  1126 
       
  1127 \railalias{subgoaltac}{subgoal\_tac}
       
  1128 \railterm{subgoaltac}
       
  1129 
       
  1130 \begin{rail}
       
  1131   'tactic' text
       
  1132   ;
       
  1133   'insert' thmrefs
       
  1134   ;
       
  1135   ( resinsttac | eresinsttac | dresinsttac | forwinsttac ) goalspec? \\
       
  1136     ((name '=' term) + 'and') 'in' thmref
       
  1137   ;
       
  1138   subgoaltac goalspec? prop
       
  1139   ;
       
  1140 \end{rail}
       
  1141 
       
  1142 \begin{descr}
       
  1143 \item [$tactic~text$] produces a proof method from any ML text of type
       
  1144   \texttt{tactic}.  Apart from the usual ML environment and the current
       
  1145   implicit theory context, the ML code may refer to the following locally
       
  1146   bound values:
       
  1147 
       
  1148 %%FIXME ttbox produces too much trailing space (why?)
       
  1149 {\footnotesize\begin{verbatim}
       
  1150 val ctxt  : Proof.context
       
  1151 val facts : thm list
       
  1152 val thm   : string -> thm
       
  1153 val thms  : string -> thm list
       
  1154 \end{verbatim}}
       
  1155   Here \texttt{ctxt} refers to the current proof context, \texttt{facts}
       
  1156   indicates any current facts for forward-chaining, and
       
  1157   \texttt{thm}~/~\texttt{thms} retrieve named facts (including global
       
  1158   theorems) from the context.
       
  1159 \item [$insert~\vec a$] inserts theorems as facts into all goals of the proof
       
  1160   state; the current facts indicated for forward chaining are ignored!
       
  1161 \item [$res_inst_tac$ etc.] do resolution of rules with explicit
       
  1162   instantiation.  This works the same way as the corresponding ML tactics, see
       
  1163   \cite[\S3]{isabelle-ref}.
       
  1164   
       
  1165   It is very important to note that the instantiations are read and
       
  1166   type-checked according to the dynamic goal state, rather than the static
       
  1167   proof context!  In particular, locally fixed variables and term
       
  1168   abbreviations may not be included in the term specifications.
       
  1169 \item [$subgoal_tac~\phi$] emulates the ML tactic of the same name, see
       
  1170   \cite[\S3]{isabelle-ref}.  Syntactically, the given proposition is handled
       
  1171   as the instantiations in $res_inst_tac$ etc.
       
  1172   
       
  1173   Note that the proper Isar command $\PRESUMENAME$ achieves a similar effect
       
  1174   as $subgoal_tac$.
       
  1175 \end{descr}
       
  1176 
  1112 
  1177 
  1113 
  1178 \subsection{Meta-linguistic features}
  1114 \subsection{Meta-linguistic features}
  1179 
  1115 
  1180 \indexisarcmd{oops}
  1116 \indexisarcmd{oops}
  1202 the opening of the proof.
  1138 the opening of the proof.
  1203 
  1139 
  1204 
  1140 
  1205 \section{Other commands}
  1141 \section{Other commands}
  1206 
  1142 
  1207 \subsection{Diagnostics}\label{sec:diag}
  1143 \subsection{Diagnostics}
  1208 
  1144 
  1209 \indexisarcmd{pr}\indexisarcmd{thm}\indexisarcmd{term}\indexisarcmd{prop}\indexisarcmd{typ}
  1145 \indexisarcmd{pr}\indexisarcmd{thm}\indexisarcmd{term}\indexisarcmd{prop}\indexisarcmd{typ}
  1210 \indexisarcmd{print-facts}\indexisarcmd{print-binds}
       
  1211 \begin{matharray}{rcl}
  1146 \begin{matharray}{rcl}
  1212   \isarcmd{pr}^* & : & \isarkeep{\cdot} \\
  1147   \isarcmd{pr}^* & : & \isarkeep{\cdot} \\
  1213   \isarcmd{thm}^* & : & \isarkeep{theory~|~proof} \\
  1148   \isarcmd{thm}^* & : & \isarkeep{theory~|~proof} \\
  1214   \isarcmd{term}^* & : & \isarkeep{theory~|~proof} \\
  1149   \isarcmd{term}^* & : & \isarkeep{theory~|~proof} \\
  1215   \isarcmd{prop}^* & : & \isarkeep{theory~|~proof} \\
  1150   \isarcmd{prop}^* & : & \isarkeep{theory~|~proof} \\
  1216   \isarcmd{typ}^* & : & \isarkeep{theory~|~proof} \\
  1151   \isarcmd{typ}^* & : & \isarkeep{theory~|~proof} \\
  1217   \isarcmd{print_facts}^* & : & \isarkeep{proof} \\
  1152 \end{matharray}
  1218   \isarcmd{print_binds}^* & : & \isarkeep{proof} \\
  1153 
  1219 \end{matharray}
  1154 These diagnostic commands assist interactive development.  Note that $undo$
  1220 
  1155 does not apply here, the theory or proof configuration is not changed.
  1221 These commands are not part of the actual Isabelle/Isar syntax, but assist
       
  1222 interactive development.  Also note that $undo$ does not apply here, since the
       
  1223 theory or proof configuration is not changed.
       
  1224 
  1156 
  1225 \begin{rail}
  1157 \begin{rail}
  1226   'pr' modes? nat?
  1158   'pr' modes? nat?
  1227   ;
  1159   ;
  1228   'thm' modes? thmrefs
  1160   'thm' modes? thmrefs
  1253   context; the inferred type of $t$ is output as well.  Note that these
  1185   context; the inferred type of $t$ is output as well.  Note that these
  1254   commands are also useful in inspecting the current environment of term
  1186   commands are also useful in inspecting the current environment of term
  1255   abbreviations.
  1187   abbreviations.
  1256 \item [$\isarkeyword{typ}~\tau$] reads and prints types of the meta-logic
  1188 \item [$\isarkeyword{typ}~\tau$] reads and prints types of the meta-logic
  1257   according to the current theory or proof context.
  1189   according to the current theory or proof context.
       
  1190 \end{descr}
       
  1191 
       
  1192 All of the diagnostic commands above admit a list of $modes$ to be specified,
       
  1193 which is appended to the current print mode (see also \cite{isabelle-ref}).
       
  1194 Thus the output behavior may be modified according particular print mode
       
  1195 features.  For example, $\isarkeyword{pr}~(latex~xsymbols~symbols)$ would
       
  1196 print the current proof state with mathematical symbols and special characters
       
  1197 represented in {\LaTeX} source, according to the Isabelle style
       
  1198 \cite{isabelle-sys}.
       
  1199 
       
  1200 Note that antiquotations (cf.\ \S\ref{sec:antiq}) provide a more systematic
       
  1201 way to include formal items into the printed text document.
       
  1202 
       
  1203 
       
  1204 \subsection{Inspecting the context}
       
  1205 
       
  1206 \indexisarcmd{print-facts}\indexisarcmd{print-binds}
       
  1207 \indexisarcmd{print-commands}\indexisarcmd{print-syntax}
       
  1208 \indexisarcmd{print-methods}\indexisarcmd{print-attributes}
       
  1209 \begin{matharray}{rcl}
       
  1210   \isarcmd{print_commands}^* & : & \isarkeep{\cdot} \\
       
  1211   \isarcmd{print_syntax}^* & : & \isarkeep{theory~|~proof} \\
       
  1212   \isarcmd{print_methods}^* & : & \isarkeep{theory~|~proof} \\
       
  1213   \isarcmd{print_attributes}^* & : & \isarkeep{theory~|~proof} \\
       
  1214   \isarcmd{print_facts}^* & : & \isarkeep{proof} \\
       
  1215   \isarcmd{print_binds}^* & : & \isarkeep{proof} \\
       
  1216 \end{matharray}
       
  1217 
       
  1218 These commands print parts of the theory and proof context.  Note that there
       
  1219 are some further ones available, such as for the set of rules declared for
       
  1220 simplifications.
       
  1221 
       
  1222 \begin{descr}
       
  1223 \item [$\isarkeyword{print_commands}$] prints Isabelle's outer theory syntax,
       
  1224   including keywords and command.
       
  1225 \item [$\isarkeyword{print_syntax}$] prints the inner syntax of types and
       
  1226   terms, depending on the current context.  The output can be very verbose,
       
  1227   including grammar tables and syntax translation rules.  See \cite[\S7,
       
  1228   \S8]{isabelle-ref} for further information on Isabelle's inner syntax.
       
  1229 \item [$\isarkeyword{print_methods}$] all proof methods available in the
       
  1230   current theory context.
       
  1231 \item [$\isarkeyword{print_attributes}$] all attributes available in the
       
  1232   current theory context.
  1258 \item [$\isarkeyword{print_facts}$] prints any named facts of the current
  1233 \item [$\isarkeyword{print_facts}$] prints any named facts of the current
  1259   context, including assumptions and local results.
  1234   context, including assumptions and local results.
  1260 \item [$\isarkeyword{print_binds}$] prints all term abbreviations present in
  1235 \item [$\isarkeyword{print_binds}$] prints all term abbreviations present in
  1261   the context.
  1236   the context.
  1262 \end{descr}
  1237 \end{descr}
  1263 
       
  1264 The basic diagnostic commands above admit a list of $modes$ to be specified,
       
  1265 which is appended to the current print mode (see also \cite{isabelle-ref}).
       
  1266 Thus the output behavior may be modified according particular print mode
       
  1267 features.
       
  1268 
       
  1269 For example, $\isarkeyword{pr}~(latex~xsymbols~symbols)$ would print the
       
  1270 current proof state with mathematical symbols and special characters
       
  1271 represented in {\LaTeX} source, according to the Isabelle style
       
  1272 \cite{isabelle-sys}.  The resulting text can be directly pasted into a
       
  1273 \verb,\begin{isabelle},\dots\verb,\end{isabelle}, environment.  Note that
       
  1274 $\isarkeyword{pr}~(latex)$ is sufficient to achieve the same output, if the
       
  1275 current Isabelle session has the other modes already activated, say due to
       
  1276 some particular user interface configuration such as Proof~General
       
  1277 \cite{proofgeneral,Aspinall:TACAS:2000} with X-Symbol mode \cite{x-symbol}.
       
  1278 
  1238 
  1279 
  1239 
  1280 \subsection{History commands}\label{sec:history}
  1240 \subsection{History commands}\label{sec:history}
  1281 
  1241 
  1282 \indexisarcmd{undo}\indexisarcmd{redo}\indexisarcmd{kill}
  1242 \indexisarcmd{undo}\indexisarcmd{redo}\indexisarcmd{kill}