src/Doc/Isar_Ref/Generic.thy
changeset 61458 987533262fc2
parent 61439 2bf52eec4e8a
child 61459 5f2ddeb15c06
equal deleted inserted replaced
61457:3e21699bb83b 61458:987533262fc2
    36     @@{command print_options} ('!'?)
    36     @@{command print_options} ('!'?)
    37     ;
    37     ;
    38     @{syntax name} ('=' ('true' | 'false' | @{syntax int} | @{syntax float} | @{syntax name}))?
    38     @{syntax name} ('=' ('true' | 'false' | @{syntax int} | @{syntax float} | @{syntax name}))?
    39   \<close>}
    39   \<close>}
    40 
    40 
    41   \begin{description}
       
    42   
       
    43   \<^descr> @{command "print_options"} prints the available configuration
    41   \<^descr> @{command "print_options"} prints the available configuration
    44   options, with names, types, and current values; the ``@{text "!"}'' option
    42   options, with names, types, and current values; the ``@{text "!"}'' option
    45   indicates extra verbosity.
    43   indicates extra verbosity.
    46   
    44   
    47   \<^descr> @{text "name = value"} as an attribute expression modifies the
    45   \<^descr> @{text "name = value"} as an attribute expression modifies the
    48   named option, with the syntax of the value depending on the option's
    46   named option, with the syntax of the value depending on the option's
    49   type.  For @{ML_type bool} the default value is @{text true}.  Any
    47   type.  For @{ML_type bool} the default value is @{text true}.  Any
    50   attempt to change a global option in a local context is ignored.
    48   attempt to change a global option in a local context is ignored.
    51 
       
    52   \end{description}
       
    53 \<close>
    49 \<close>
    54 
    50 
    55 
    51 
    56 section \<open>Basic proof tools\<close>
    52 section \<open>Basic proof tools\<close>
    57 
    53 
    81     (@@{method intro} | @@{method elim}) @{syntax thmrefs}?
    77     (@@{method intro} | @@{method elim}) @{syntax thmrefs}?
    82     ;
    78     ;
    83     @@{method sleep} @{syntax real}
    79     @@{method sleep} @{syntax real}
    84   \<close>}
    80   \<close>}
    85 
    81 
    86   \begin{description}
       
    87   
       
    88   \<^descr> @{method unfold}~@{text "a\<^sub>1 \<dots> a\<^sub>n"} and @{method fold}~@{text
    82   \<^descr> @{method unfold}~@{text "a\<^sub>1 \<dots> a\<^sub>n"} and @{method fold}~@{text
    89   "a\<^sub>1 \<dots> a\<^sub>n"} expand (or fold back) the given definitions throughout
    83   "a\<^sub>1 \<dots> a\<^sub>n"} expand (or fold back) the given definitions throughout
    90   all goals; any chained facts provided are inserted into the goal and
    84   all goals; any chained facts provided are inserted into the goal and
    91   subject to rewriting as well.
    85   subject to rewriting as well.
    92 
    86 
   127 
   121 
   128   \<^descr> @{method sleep}~@{text s} succeeds after a real-time delay of @{text
   122   \<^descr> @{method sleep}~@{text s} succeeds after a real-time delay of @{text
   129   s} seconds. This is occasionally useful for demonstration and testing
   123   s} seconds. This is occasionally useful for demonstration and testing
   130   purposes.
   124   purposes.
   131 
   125 
   132   \end{description}
       
   133 
   126 
   134   \begin{matharray}{rcl}
   127   \begin{matharray}{rcl}
   135     @{attribute_def tagged} & : & @{text attribute} \\
   128     @{attribute_def tagged} & : & @{text attribute} \\
   136     @{attribute_def untagged} & : & @{text attribute} \\[0.5ex]
   129     @{attribute_def untagged} & : & @{text attribute} \\[0.5ex]
   137     @{attribute_def THEN} & : & @{text attribute} \\
   130     @{attribute_def THEN} & : & @{text attribute} \\
   153     (@@{attribute unfolded} | @@{attribute folded}) @{syntax thmrefs}
   146     (@@{attribute unfolded} | @@{attribute folded}) @{syntax thmrefs}
   154     ;
   147     ;
   155     @@{attribute rotated} @{syntax int}?
   148     @@{attribute rotated} @{syntax int}?
   156   \<close>}
   149   \<close>}
   157 
   150 
   158   \begin{description}
       
   159 
       
   160   \<^descr> @{attribute tagged}~@{text "name value"} and @{attribute
   151   \<^descr> @{attribute tagged}~@{text "name value"} and @{attribute
   161   untagged}~@{text name} add and remove \emph{tags} of some theorem.
   152   untagged}~@{text name} add and remove \emph{tags} of some theorem.
   162   Tags may be any list of string pairs that serve as formal comment.
   153   Tags may be any list of string pairs that serve as formal comment.
   163   The first string is considered the tag name, the second its value.
   154   The first string is considered the tag name, the second its value.
   164   Note that @{attribute untagged} removes any tags of the same name.
   155   Note that @{attribute untagged} removes any tags of the same name.
   187   Note that the Classical Reasoner (\secref{sec:classical}) provides
   178   Note that the Classical Reasoner (\secref{sec:classical}) provides
   188   its own version of this operation.
   179   its own version of this operation.
   189 
   180 
   190   \<^descr> @{attribute no_vars} replaces schematic variables by free
   181   \<^descr> @{attribute no_vars} replaces schematic variables by free
   191   ones; this is mainly for tuning output of pretty printed theorems.
   182   ones; this is mainly for tuning output of pretty printed theorems.
   192 
       
   193   \end{description}
       
   194 \<close>
   183 \<close>
   195 
   184 
   196 
   185 
   197 subsection \<open>Low-level equational reasoning\<close>
   186 subsection \<open>Low-level equational reasoning\<close>
   198 
   187 
   213   that are intended for specialized applications only.  Normally,
   202   that are intended for specialized applications only.  Normally,
   214   single step calculations would be performed in a structured text
   203   single step calculations would be performed in a structured text
   215   (see also \secref{sec:calculation}), while the Simplifier methods
   204   (see also \secref{sec:calculation}), while the Simplifier methods
   216   provide the canonical way for automated normalization (see
   205   provide the canonical way for automated normalization (see
   217   \secref{sec:simplifier}).
   206   \secref{sec:simplifier}).
   218 
       
   219   \begin{description}
       
   220 
   207 
   221   \<^descr> @{method subst}~@{text eq} performs a single substitution step
   208   \<^descr> @{method subst}~@{text eq} performs a single substitution step
   222   using rule @{text eq}, which may be either a meta or object
   209   using rule @{text eq}, which may be either a meta or object
   223   equality.
   210   equality.
   224 
   211 
   255   structure of the rule.
   242   structure of the rule.
   256   
   243   
   257   Note that the @{method simp} method already involves repeated
   244   Note that the @{method simp} method already involves repeated
   258   application of split rules as declared in the current context, using
   245   application of split rules as declared in the current context, using
   259   @{attribute split}, for example.
   246   @{attribute split}, for example.
   260 
       
   261   \end{description}
       
   262 \<close>
   247 \<close>
   263 
   248 
   264 
   249 
   265 section \<open>The Simplifier \label{sec:simplifier}\<close>
   250 section \<open>The Simplifier \label{sec:simplifier}\<close>
   266 
   251 
   302     opt: '(' ('no_asm' | 'no_asm_simp' | 'no_asm_use' | 'asm_lr' ) ')'
   287     opt: '(' ('no_asm' | 'no_asm_simp' | 'no_asm_use' | 'asm_lr' ) ')'
   303     ;
   288     ;
   304     @{syntax_def simpmod}: ('add' | 'del' | 'only' | 'split' (() | 'add' | 'del') |
   289     @{syntax_def simpmod}: ('add' | 'del' | 'only' | 'split' (() | 'add' | 'del') |
   305       'cong' (() | 'add' | 'del')) ':' @{syntax thmrefs}
   290       'cong' (() | 'add' | 'del')) ':' @{syntax thmrefs}
   306   \<close>}
   291   \<close>}
   307 
       
   308   \begin{description}
       
   309 
   292 
   310   \<^descr> @{method simp} invokes the Simplifier on the first subgoal,
   293   \<^descr> @{method simp} invokes the Simplifier on the first subgoal,
   311   after inserting chained facts as additional goal premises; further
   294   after inserting chained facts as additional goal premises; further
   312   rule declarations may be included via @{text "(simp add: facts)"}.
   295   rule declarations may be included via @{text "(simp add: facts)"}.
   313   The proof method fails if the subgoal remains unchanged after
   296   The proof method fails if the subgoal remains unchanged after
   362   simplification.
   345   simplification.
   363 
   346 
   364   \<^descr> @{attribute simp_depth_limit} limits the number of recursive
   347   \<^descr> @{attribute simp_depth_limit} limits the number of recursive
   365   invocations of the Simplifier during conditional rewriting.
   348   invocations of the Simplifier during conditional rewriting.
   366 
   349 
   367   \end{description}
       
   368 
   350 
   369   By default the Simplifier methods above take local assumptions fully
   351   By default the Simplifier methods above take local assumptions fully
   370   into account, using equational assumptions in the subsequent
   352   into account, using equational assumptions in the subsequent
   371   normalization process, or simplifying assumptions themselves.
   353   normalization process, or simplifying assumptions themselves.
   372   Further options allow to fine-tune the behavior of the Simplifier
   354   Further options allow to fine-tune the behavior of the Simplifier
   511       (() | 'add' | 'del')
   493       (() | 'add' | 'del')
   512     ;
   494     ;
   513     @@{command print_simpset} ('!'?)
   495     @@{command print_simpset} ('!'?)
   514   \<close>}
   496   \<close>}
   515 
   497 
   516   \begin{description}
       
   517 
       
   518   \<^descr> @{attribute simp} declares rewrite rules, by adding or
   498   \<^descr> @{attribute simp} declares rewrite rules, by adding or
   519   deleting them from the simpset within the theory or proof context.
   499   deleting them from the simpset within the theory or proof context.
   520   Rewrite rules are theorems expressing some form of equality, for
   500   Rewrite rules are theorems expressing some form of equality, for
   521   example:
   501   example:
   522 
   502 
   541   The Simplifier accepts the following formats for the @{text "lhs"}
   521   The Simplifier accepts the following formats for the @{text "lhs"}
   542   term:
   522   term:
   543 
   523 
   544   \begin{enumerate}
   524   \begin{enumerate}
   545 
   525 
   546   \<^enum> First-order patterns, considering the sublanguage of
   526     \item First-order patterns, considering the sublanguage of
   547   application of constant operators to variable operands, without
   527     application of constant operators to variable operands, without
   548   @{text "\<lambda>"}-abstractions or functional variables.
   528     @{text "\<lambda>"}-abstractions or functional variables.
   549   For example:
   529     For example:
   550 
   530 
   551   @{text "(?x + ?y) + ?z \<equiv> ?x + (?y + ?z)"} \\
   531     @{text "(?x + ?y) + ?z \<equiv> ?x + (?y + ?z)"} \\
   552   @{text "f (f ?x ?y) ?z \<equiv> f ?x (f ?y ?z)"}
   532     @{text "f (f ?x ?y) ?z \<equiv> f ?x (f ?y ?z)"}
   553 
   533 
   554   \<^enum> Higher-order patterns in the sense of @{cite "nipkow-patterns"}.
   534     \item Higher-order patterns in the sense of @{cite "nipkow-patterns"}.
   555   These are terms in @{text "\<beta>"}-normal form (this will always be the
   535     These are terms in @{text "\<beta>"}-normal form (this will always be the
   556   case unless you have done something strange) where each occurrence
   536     case unless you have done something strange) where each occurrence
   557   of an unknown is of the form @{text "?F x\<^sub>1 \<dots> x\<^sub>n"}, where the
   537     of an unknown is of the form @{text "?F x\<^sub>1 \<dots> x\<^sub>n"}, where the
   558   @{text "x\<^sub>i"} are distinct bound variables.
   538     @{text "x\<^sub>i"} are distinct bound variables.
   559 
   539 
   560   For example, @{text "(\<forall>x. ?P x \<and> ?Q x) \<equiv> (\<forall>x. ?P x) \<and> (\<forall>x. ?Q x)"}
   540     For example, @{text "(\<forall>x. ?P x \<and> ?Q x) \<equiv> (\<forall>x. ?P x) \<and> (\<forall>x. ?Q x)"}
   561   or its symmetric form, since the @{text "rhs"} is also a
   541     or its symmetric form, since the @{text "rhs"} is also a
   562   higher-order pattern.
   542     higher-order pattern.
   563 
   543 
   564   \<^enum> Physical first-order patterns over raw @{text "\<lambda>"}-term
   544     \item Physical first-order patterns over raw @{text "\<lambda>"}-term
   565   structure without @{text "\<alpha>\<beta>\<eta>"}-equality; abstractions and bound
   545     structure without @{text "\<alpha>\<beta>\<eta>"}-equality; abstractions and bound
   566   variables are treated like quasi-constant term material.
   546     variables are treated like quasi-constant term material.
   567 
   547 
   568   For example, the rule @{text "?f ?x \<in> range ?f = True"} rewrites the
   548     For example, the rule @{text "?f ?x \<in> range ?f = True"} rewrites the
   569   term @{text "g a \<in> range g"} to @{text "True"}, but will fail to
   549     term @{text "g a \<in> range g"} to @{text "True"}, but will fail to
   570   match @{text "g (h b) \<in> range (\<lambda>x. g (h x))"}. However, offending
   550     match @{text "g (h b) \<in> range (\<lambda>x. g (h x))"}. However, offending
   571   subterms (in our case @{text "?f ?x"}, which is not a pattern) can
   551     subterms (in our case @{text "?f ?x"}, which is not a pattern) can
   572   be replaced by adding new variables and conditions like this: @{text
   552     be replaced by adding new variables and conditions like this: @{text
   573   "?y = ?f ?x \<Longrightarrow> ?y \<in> range ?f = True"} is acceptable as a conditional
   553     "?y = ?f ?x \<Longrightarrow> ?y \<in> range ?f = True"} is acceptable as a conditional
   574   rewrite rule of the second category since conditions can be
   554     rewrite rule of the second category since conditions can be
   575   arbitrary terms.
   555     arbitrary terms.
   576 
   556 
   577   \end{enumerate}
   557   \end{enumerate}
   578 
   558 
   579   \<^descr> @{attribute split} declares case split rules.
   559   \<^descr> @{attribute split} declares case split rules.
   580 
   560 
   632   other tools that might get invoked internally (e.g.\ simplification
   612   other tools that might get invoked internally (e.g.\ simplification
   633   procedures \secref{sec:simproc}).  A mismatch of the context of the
   613   procedures \secref{sec:simproc}).  A mismatch of the context of the
   634   simpset and the context of the problem being simplified may lead to
   614   simpset and the context of the problem being simplified may lead to
   635   unexpected results.
   615   unexpected results.
   636 
   616 
   637   \end{description}
       
   638 
   617 
   639   The implicit simpset of the theory context is propagated
   618   The implicit simpset of the theory context is propagated
   640   monotonically through the theory hierarchy: forming a new theory,
   619   monotonically through the theory hierarchy: forming a new theory,
   641   the union of the simpsets of its imports are taken as starting
   620   the union of the simpsets of its imports are taken as starting
   642   point.  Also note that definitional packages like @{command
   621   point.  Also note that definitional packages like @{command
   704 text \<open>Ordered rewriting is particularly effective in the case of
   683 text \<open>Ordered rewriting is particularly effective in the case of
   705   associative-commutative operators.  (Associativity by itself is not
   684   associative-commutative operators.  (Associativity by itself is not
   706   permutative.)  When dealing with an AC-operator @{text "f"}, keep
   685   permutative.)  When dealing with an AC-operator @{text "f"}, keep
   707   the following points in mind:
   686   the following points in mind:
   708 
   687 
   709   \begin{itemize}
       
   710 
       
   711   \<^item> The associative law must always be oriented from left to
   688   \<^item> The associative law must always be oriented from left to
   712   right, namely @{text "f (f x y) z = f x (f y z)"}.  The opposite
   689   right, namely @{text "f (f x y) z = f x (f y z)"}.  The opposite
   713   orientation, if used with commutativity, leads to looping in
   690   orientation, if used with commutativity, leads to looping in
   714   conjunction with the standard term order.
   691   conjunction with the standard term order.
   715 
   692 
   716   \<^item> To complete your set of rewrite rules, you must add not just
   693   \<^item> To complete your set of rewrite rules, you must add not just
   717   associativity (A) and commutativity (C) but also a derived rule
   694   associativity (A) and commutativity (C) but also a derived rule
   718   \emph{left-commutativity} (LC): @{text "f x (f y z) = f y (f x z)"}.
   695   \emph{left-commutativity} (LC): @{text "f x (f y z) = f y (f x z)"}.
   719 
   696 
   720   \end{itemize}
       
   721 
   697 
   722   Ordered rewriting with the combination of A, C, and LC sorts a term
   698   Ordered rewriting with the combination of A, C, and LC sorts a term
   723   lexicographically --- the rewriting engine imitates bubble-sort.
   699   lexicographically --- the rewriting engine imitates bubble-sort.
   724 \<close>
   700 \<close>
   725 
   701 
   792   \<close>}
   768   \<close>}
   793 
   769 
   794   These attributes and configurations options control various aspects of
   770   These attributes and configurations options control various aspects of
   795   Simplifier tracing and debugging.
   771   Simplifier tracing and debugging.
   796 
   772 
   797   \begin{description}
       
   798 
       
   799   \<^descr> @{attribute simp_trace} makes the Simplifier output internal
   773   \<^descr> @{attribute simp_trace} makes the Simplifier output internal
   800   operations.  This includes rewrite steps, but also bookkeeping like
   774   operations.  This includes rewrite steps, but also bookkeeping like
   801   modifications of the simpset.
   775   modifications of the simpset.
   802 
   776 
   803   \<^descr> @{attribute simp_trace_depth_limit} limits the effect of
   777   \<^descr> @{attribute simp_trace_depth_limit} limits the effect of
   823   \<^descr> @{attribute simp_break} declares term or theorem breakpoints for
   797   \<^descr> @{attribute simp_break} declares term or theorem breakpoints for
   824   @{attribute simp_trace_new} as described above. Term breakpoints are
   798   @{attribute simp_trace_new} as described above. Term breakpoints are
   825   patterns which are checked for matches on the redex of a rule application.
   799   patterns which are checked for matches on the redex of a rule application.
   826   Theorem breakpoints trigger when the corresponding theorem is applied in a
   800   Theorem breakpoints trigger when the corresponding theorem is applied in a
   827   rewrite step. For example:
   801   rewrite step. For example:
   828 
       
   829   \end{description}
       
   830 \<close>
   802 \<close>
   831 
   803 
   832 (*<*)experiment begin(*>*)
   804 (*<*)experiment begin(*>*)
   833 declare conjI [simp_break]
   805 declare conjI [simp_break]
   834 declare [[simp_break "?x \<and> ?y"]]
   806 declare [[simp_break "?x \<and> ?y"]]
   863       @{syntax text} \<newline> (@'identifier' (@{syntax nameref}+))?
   835       @{syntax text} \<newline> (@'identifier' (@{syntax nameref}+))?
   864     ;
   836     ;
   865 
   837 
   866     @@{attribute simproc} (('add' ':')? | 'del' ':') (@{syntax name}+)
   838     @@{attribute simproc} (('add' ':')? | 'del' ':') (@{syntax name}+)
   867   \<close>}
   839   \<close>}
   868 
       
   869   \begin{description}
       
   870 
   840 
   871   \<^descr> @{command "simproc_setup"} defines a named simplification
   841   \<^descr> @{command "simproc_setup"} defines a named simplification
   872   procedure that is invoked by the Simplifier whenever any of the
   842   procedure that is invoked by the Simplifier whenever any of the
   873   given term patterns match the current redex.  The implementation,
   843   given term patterns match the current redex.  The implementation,
   874   which is provided as ML source text, needs to be of type @{ML_type
   844   which is provided as ML source text, needs to be of type @{ML_type
   889 
   859 
   890   \<^descr> @{text "simproc add: name"} and @{text "simproc del: name"}
   860   \<^descr> @{text "simproc add: name"} and @{text "simproc del: name"}
   891   add or delete named simprocs to the current Simplifier context.  The
   861   add or delete named simprocs to the current Simplifier context.  The
   892   default is to add a simproc.  Note that @{command "simproc_setup"}
   862   default is to add a simproc.  Note that @{command "simproc_setup"}
   893   already adds the new simproc to the subsequent context.
   863   already adds the new simproc to the subsequent context.
   894 
       
   895   \end{description}
       
   896 \<close>
   864 \<close>
   897 
   865 
   898 
   866 
   899 subsubsection \<open>Example\<close>
   867 subsubsection \<open>Example\<close>
   900 
   868 
   942   be simplification itself.  In rare situations, this strategy may
   910   be simplification itself.  In rare situations, this strategy may
   943   need to be changed.  For example, if the premise of a conditional
   911   need to be changed.  For example, if the premise of a conditional
   944   rule is an instance of its conclusion, as in @{text "Suc ?m < ?n \<Longrightarrow>
   912   rule is an instance of its conclusion, as in @{text "Suc ?m < ?n \<Longrightarrow>
   945   ?m < ?n"}, the default strategy could loop.  % FIXME !??
   913   ?m < ?n"}, the default strategy could loop.  % FIXME !??
   946 
   914 
   947   \begin{description}
       
   948 
       
   949   \<^descr> @{ML Simplifier.set_subgoaler}~@{text "tac ctxt"} sets the
   915   \<^descr> @{ML Simplifier.set_subgoaler}~@{text "tac ctxt"} sets the
   950   subgoaler of the context to @{text "tac"}.  The tactic will
   916   subgoaler of the context to @{text "tac"}.  The tactic will
   951   be applied to the context of the running Simplifier instance.
   917   be applied to the context of the running Simplifier instance.
   952 
   918 
   953   \<^descr> @{ML Simplifier.prems_of}~@{text "ctxt"} retrieves the current
   919   \<^descr> @{ML Simplifier.prems_of}~@{text "ctxt"} retrieves the current
   954   set of premises from the context.  This may be non-empty only if
   920   set of premises from the context.  This may be non-empty only if
   955   the Simplifier has been told to utilize local assumptions in the
   921   the Simplifier has been told to utilize local assumptions in the
   956   first place (cf.\ the options in \secref{sec:simp-meth}).
   922   first place (cf.\ the options in \secref{sec:simp-meth}).
   957 
   923 
   958   \end{description}
       
   959 
   924 
   960   As an example, consider the following alternative subgoaler:
   925   As an example, consider the following alternative subgoaler:
   961 \<close>
   926 \<close>
   962 
   927 
   963 ML_val \<open>
   928 ML_val \<open>
  1012   still apply the ordinary unsafe one in nested simplifications for
   977   still apply the ordinary unsafe one in nested simplifications for
  1013   conditional rules or congruences. Note that in this way the overall
   978   conditional rules or congruences. Note that in this way the overall
  1014   tactic is not totally safe: it may instantiate unknowns that appear
   979   tactic is not totally safe: it may instantiate unknowns that appear
  1015   also in other subgoals.
   980   also in other subgoals.
  1016 
   981 
  1017   \begin{description}
       
  1018 
       
  1019   \<^descr> @{ML Simplifier.mk_solver}~@{text "name tac"} turns @{text
   982   \<^descr> @{ML Simplifier.mk_solver}~@{text "name tac"} turns @{text
  1020   "tac"} into a solver; the @{text "name"} is only attached as a
   983   "tac"} into a solver; the @{text "name"} is only attached as a
  1021   comment and has no further significance.
   984   comment and has no further significance.
  1022 
   985 
  1023   \<^descr> @{text "ctxt setSSolver solver"} installs @{text "solver"} as
   986   \<^descr> @{text "ctxt setSSolver solver"} installs @{text "solver"} as
  1032 
   995 
  1033   \<^descr> @{text "ctxt addSolver solver"} adds @{text "solver"} as an
   996   \<^descr> @{text "ctxt addSolver solver"} adds @{text "solver"} as an
  1034   additional unsafe solver; it will be tried after the solvers which
   997   additional unsafe solver; it will be tried after the solvers which
  1035   had already been present in @{text "ctxt"}.
   998   had already been present in @{text "ctxt"}.
  1036 
   999 
  1037   \end{description}
       
  1038 
  1000 
  1039   \<^medskip>
  1001   \<^medskip>
  1040   The solver tactic is invoked with the context of the
  1002   The solver tactic is invoked with the context of the
  1041   running Simplifier.  Further operations
  1003   running Simplifier.  Further operations
  1042   may be used to retrieve relevant information, such as the list of
  1004   may be used to retrieve relevant information, such as the list of
  1098 
  1060 
  1099   A typical looper is \emph{case splitting}: the expansion of a
  1061   A typical looper is \emph{case splitting}: the expansion of a
  1100   conditional.  Another possibility is to apply an elimination rule on
  1062   conditional.  Another possibility is to apply an elimination rule on
  1101   the assumptions.  More adventurous loopers could start an induction.
  1063   the assumptions.  More adventurous loopers could start an induction.
  1102 
  1064 
  1103   \begin{description}
       
  1104 
       
  1105   \<^descr> @{text "ctxt setloop tac"} installs @{text "tac"} as the only
  1065   \<^descr> @{text "ctxt setloop tac"} installs @{text "tac"} as the only
  1106   looper tactic of @{text "ctxt"}.
  1066   looper tactic of @{text "ctxt"}.
  1107 
  1067 
  1108   \<^descr> @{text "ctxt addloop (name, tac)"} adds @{text "tac"} as an
  1068   \<^descr> @{text "ctxt addloop (name, tac)"} adds @{text "tac"} as an
  1109   additional looper tactic with name @{text "name"}, which is
  1069   additional looper tactic with name @{text "name"}, which is
  1119 
  1079 
  1120   \<^descr> @{ML Splitter.del_split}~@{text "thm ctxt"} deletes the split
  1080   \<^descr> @{ML Splitter.del_split}~@{text "thm ctxt"} deletes the split
  1121   tactic corresponding to @{text thm} from the looper tactics of
  1081   tactic corresponding to @{text thm} from the looper tactics of
  1122   @{text "ctxt"}.
  1082   @{text "ctxt"}.
  1123 
  1083 
  1124   \end{description}
       
  1125 
  1084 
  1126   The splitter replaces applications of a given function; the
  1085   The splitter replaces applications of a given function; the
  1127   right-hand side of the replacement can be anything.  For example,
  1086   right-hand side of the replacement can be anything.  For example,
  1128   here is a splitting rule for conditional expressions:
  1087   here is a splitting rule for conditional expressions:
  1129 
  1088 
  1172     ;
  1131     ;
  1173 
  1132 
  1174     opt: '(' ('no_asm' | 'no_asm_simp' | 'no_asm_use') ')'
  1133     opt: '(' ('no_asm' | 'no_asm_simp' | 'no_asm_use') ')'
  1175   \<close>}
  1134   \<close>}
  1176 
  1135 
  1177   \begin{description}
       
  1178   
       
  1179   \<^descr> @{attribute simplified}~@{text "a\<^sub>1 \<dots> a\<^sub>n"} causes a theorem to
  1136   \<^descr> @{attribute simplified}~@{text "a\<^sub>1 \<dots> a\<^sub>n"} causes a theorem to
  1180   be simplified, either by exactly the specified rules @{text "a\<^sub>1, \<dots>,
  1137   be simplified, either by exactly the specified rules @{text "a\<^sub>1, \<dots>,
  1181   a\<^sub>n"}, or the implicit Simplifier context if no arguments are given.
  1138   a\<^sub>n"}, or the implicit Simplifier context if no arguments are given.
  1182   The result is fully simplified by default, including assumptions and
  1139   The result is fully simplified by default, including assumptions and
  1183   conclusion; the options @{text no_asm} etc.\ tune the Simplifier in
  1140   conclusion; the options @{text no_asm} etc.\ tune the Simplifier in
  1186   Note that forward simplification restricts the Simplifier to its
  1143   Note that forward simplification restricts the Simplifier to its
  1187   most basic operation of term rewriting; solver and looper tactics
  1144   most basic operation of term rewriting; solver and looper tactics
  1188   (\secref{sec:simp-strategies}) are \emph{not} involved here.  The
  1145   (\secref{sec:simp-strategies}) are \emph{not} involved here.  The
  1189   @{attribute simplified} attribute should be only rarely required
  1146   @{attribute simplified} attribute should be only rarely required
  1190   under normal circumstances.
  1147   under normal circumstances.
  1191 
       
  1192   \end{description}
       
  1193 \<close>
  1148 \<close>
  1194 
  1149 
  1195 
  1150 
  1196 section \<open>The Classical Reasoner \label{sec:classical}\<close>
  1151 section \<open>The Classical Reasoner \label{sec:classical}\<close>
  1197 
  1152 
  1434     @@{attribute rule} 'del'
  1389     @@{attribute rule} 'del'
  1435     ;
  1390     ;
  1436     @@{attribute iff} (((() | 'add') '?'?) | 'del')
  1391     @@{attribute iff} (((() | 'add') '?'?) | 'del')
  1437   \<close>}
  1392   \<close>}
  1438 
  1393 
  1439   \begin{description}
       
  1440 
       
  1441   \<^descr> @{command "print_claset"} prints the collection of rules
  1394   \<^descr> @{command "print_claset"} prints the collection of rules
  1442   declared to the Classical Reasoner, i.e.\ the @{ML_type claset}
  1395   declared to the Classical Reasoner, i.e.\ the @{ML_type claset}
  1443   within the context.
  1396   within the context.
  1444 
  1397 
  1445   \<^descr> @{attribute intro}, @{attribute elim}, and @{attribute dest}
  1398   \<^descr> @{attribute intro}, @{attribute elim}, and @{attribute dest}
  1485   \<^descr> @{attribute swapped} turns an introduction rule into an
  1438   \<^descr> @{attribute swapped} turns an introduction rule into an
  1486   elimination, by resolving with the classical swap principle @{text
  1439   elimination, by resolving with the classical swap principle @{text
  1487   "\<not> P \<Longrightarrow> (\<not> R \<Longrightarrow> P) \<Longrightarrow> R"} in the second position.  This is mainly for
  1440   "\<not> P \<Longrightarrow> (\<not> R \<Longrightarrow> P) \<Longrightarrow> R"} in the second position.  This is mainly for
  1488   illustrative purposes: the Classical Reasoner already swaps rules
  1441   illustrative purposes: the Classical Reasoner already swaps rules
  1489   internally as explained above.
  1442   internally as explained above.
  1490 
       
  1491   \end{description}
       
  1492 \<close>
  1443 \<close>
  1493 
  1444 
  1494 
  1445 
  1495 subsection \<open>Structured methods\<close>
  1446 subsection \<open>Structured methods\<close>
  1496 
  1447 
  1502 
  1453 
  1503   @{rail \<open>
  1454   @{rail \<open>
  1504     @@{method rule} @{syntax thmrefs}?
  1455     @@{method rule} @{syntax thmrefs}?
  1505   \<close>}
  1456   \<close>}
  1506 
  1457 
  1507   \begin{description}
       
  1508 
       
  1509   \<^descr> @{method rule} as offered by the Classical Reasoner is a
  1458   \<^descr> @{method rule} as offered by the Classical Reasoner is a
  1510   refinement over the Pure one (see \secref{sec:pure-meth-att}).  Both
  1459   refinement over the Pure one (see \secref{sec:pure-meth-att}).  Both
  1511   versions work the same, but the classical version observes the
  1460   versions work the same, but the classical version observes the
  1512   classical rule context in addition to that of Isabelle/Pure.
  1461   classical rule context in addition to that of Isabelle/Pure.
  1513 
  1462 
  1518 
  1467 
  1519   \<^descr> @{method contradiction} solves some goal by contradiction,
  1468   \<^descr> @{method contradiction} solves some goal by contradiction,
  1520   deriving any result from both @{text "\<not> A"} and @{text A}.  Chained
  1469   deriving any result from both @{text "\<not> A"} and @{text A}.  Chained
  1521   facts, which are guaranteed to participate, may appear in either
  1470   facts, which are guaranteed to participate, may appear in either
  1522   order.
  1471   order.
  1523 
       
  1524   \end{description}
       
  1525 \<close>
  1472 \<close>
  1526 
  1473 
  1527 
  1474 
  1528 subsection \<open>Fully automated methods\<close>
  1475 subsection \<open>Fully automated methods\<close>
  1529 
  1476 
  1562       ('cong' | 'split') (() | 'add' | 'del') |
  1509       ('cong' | 'split') (() | 'add' | 'del') |
  1563       'iff' (((() | 'add') '?'?) | 'del') |
  1510       'iff' (((() | 'add') '?'?) | 'del') |
  1564       (('intro' | 'elim' | 'dest') ('!' | () | '?') | 'del')) ':' @{syntax thmrefs}
  1511       (('intro' | 'elim' | 'dest') ('!' | () | '?') | 'del')) ':' @{syntax thmrefs}
  1565   \<close>}
  1512   \<close>}
  1566 
  1513 
  1567   \begin{description}
       
  1568 
       
  1569   \<^descr> @{method blast} is a separate classical tableau prover that
  1514   \<^descr> @{method blast} is a separate classical tableau prover that
  1570   uses the same classical rule declarations as explained before.
  1515   uses the same classical rule declarations as explained before.
  1571 
  1516 
  1572   Proof search is coded directly in ML using special data structures.
  1517   Proof search is coded directly in ML using special data structures.
  1573   A successful proof is then reconstructed using regular Isabelle
  1518   A successful proof is then reconstructed using regular Isabelle
  1574   inferences.  It is faster and more powerful than the other classical
  1519   inferences.  It is faster and more powerful than the other classical
  1575   reasoning tools, but has major limitations too.
  1520   reasoning tools, but has major limitations too.
  1576 
  1521 
  1577   \begin{itemize}
  1522   \begin{itemize}
  1578 
  1523 
  1579   \<^item> It does not use the classical wrapper tacticals, such as the
  1524     \item It does not use the classical wrapper tacticals, such as the
  1580   integration with the Simplifier of @{method fastforce}.
  1525     integration with the Simplifier of @{method fastforce}.
  1581 
  1526 
  1582   \<^item> It does not perform higher-order unification, as needed by the
  1527     \item It does not perform higher-order unification, as needed by the
  1583   rule @{thm [source=false] rangeI} in HOL.  There are often
  1528     rule @{thm [source=false] rangeI} in HOL.  There are often
  1584   alternatives to such rules, for example @{thm [source=false]
  1529     alternatives to such rules, for example @{thm [source=false]
  1585   range_eqI}.
  1530     range_eqI}.
  1586 
  1531 
  1587   \<^item> Function variables may only be applied to parameters of the
  1532     \item Function variables may only be applied to parameters of the
  1588   subgoal.  (This restriction arises because the prover does not use
  1533     subgoal.  (This restriction arises because the prover does not use
  1589   higher-order unification.)  If other function variables are present
  1534     higher-order unification.)  If other function variables are present
  1590   then the prover will fail with the message
  1535     then the prover will fail with the message
  1591   @{verbatim [display] \<open>Function unknown's argument not a bound variable\<close>}
  1536     @{verbatim [display] \<open>Function unknown's argument not a bound variable\<close>}
  1592 
  1537 
  1593   \<^item> Its proof strategy is more general than @{method fast} but can
  1538     \item Its proof strategy is more general than @{method fast} but can
  1594   be slower.  If @{method blast} fails or seems to be running forever,
  1539     be slower.  If @{method blast} fails or seems to be running forever,
  1595   try @{method fast} and the other proof tools described below.
  1540     try @{method fast} and the other proof tools described below.
  1596 
  1541 
  1597   \end{itemize}
  1542   \end{itemize}
  1598 
  1543 
  1599   The optional integer argument specifies a bound for the number of
  1544   The optional integer argument specifies a bound for the number of
  1600   unsafe steps used in a proof.  By default, @{method blast} starts
  1545   unsafe steps used in a proof.  By default, @{method blast} starts
  1647   to preserve the formula they act on, so that it be used repeatedly.
  1592   to preserve the formula they act on, so that it be used repeatedly.
  1648   This method can prove more goals than @{method fast}, but is much
  1593   This method can prove more goals than @{method fast}, but is much
  1649   slower, for example if the assumptions have many universal
  1594   slower, for example if the assumptions have many universal
  1650   quantifiers.
  1595   quantifiers.
  1651 
  1596 
  1652   \end{description}
       
  1653 
  1597 
  1654   Any of the above methods support additional modifiers of the context
  1598   Any of the above methods support additional modifiers of the context
  1655   of classical (and simplifier) rules, but the ones related to the
  1599   of classical (and simplifier) rules, but the ones related to the
  1656   Simplifier are explicitly prefixed by @{text simp} here.  The
  1600   Simplifier are explicitly prefixed by @{text simp} here.  The
  1657   semantics of these ad-hoc rule declarations is analogous to the
  1601   semantics of these ad-hoc rule declarations is analogous to the
  1677     (@@{method safe} | @@{method clarify}) (@{syntax clamod} * )
  1621     (@@{method safe} | @@{method clarify}) (@{syntax clamod} * )
  1678     ;
  1622     ;
  1679     @@{method clarsimp} (@{syntax clasimpmod} * )
  1623     @@{method clarsimp} (@{syntax clasimpmod} * )
  1680   \<close>}
  1624   \<close>}
  1681 
  1625 
  1682   \begin{description}
       
  1683 
       
  1684   \<^descr> @{method safe} repeatedly performs safe steps on all subgoals.
  1626   \<^descr> @{method safe} repeatedly performs safe steps on all subgoals.
  1685   It is deterministic, with at most one outcome.
  1627   It is deterministic, with at most one outcome.
  1686 
  1628 
  1687   \<^descr> @{method clarify} performs a series of safe steps without
  1629   \<^descr> @{method clarify} performs a series of safe steps without
  1688   splitting subgoals; see also @{method clarify_step}.
  1630   splitting subgoals; see also @{method clarify_step}.
  1689 
  1631 
  1690   \<^descr> @{method clarsimp} acts like @{method clarify}, but also does
  1632   \<^descr> @{method clarsimp} acts like @{method clarify}, but also does
  1691   simplification.  Note that if the Simplifier context includes a
  1633   simplification.  Note that if the Simplifier context includes a
  1692   splitter for the premises, the subgoal may still be split.
  1634   splitter for the premises, the subgoal may still be split.
  1693 
       
  1694   \end{description}
       
  1695 \<close>
  1635 \<close>
  1696 
  1636 
  1697 
  1637 
  1698 subsection \<open>Single-step tactics\<close>
  1638 subsection \<open>Single-step tactics\<close>
  1699 
  1639 
  1708 
  1648 
  1709   These are the primitive tactics behind the automated proof methods
  1649   These are the primitive tactics behind the automated proof methods
  1710   of the Classical Reasoner.  By calling them yourself, you can
  1650   of the Classical Reasoner.  By calling them yourself, you can
  1711   execute these procedures one step at a time.
  1651   execute these procedures one step at a time.
  1712 
  1652 
  1713   \begin{description}
       
  1714 
       
  1715   \<^descr> @{method safe_step} performs a safe step on the first subgoal.
  1653   \<^descr> @{method safe_step} performs a safe step on the first subgoal.
  1716   The safe wrapper tacticals are applied to a tactic that may include
  1654   The safe wrapper tacticals are applied to a tactic that may include
  1717   proof by assumption or Modus Ponens (taking care not to instantiate
  1655   proof by assumption or Modus Ponens (taking care not to instantiate
  1718   unknowns), or substitution.
  1656   unknowns), or substitution.
  1719 
  1657 
  1734   subgoal; no splitting step is applied.  For example, the subgoal
  1672   subgoal; no splitting step is applied.  For example, the subgoal
  1735   @{text "A \<and> B"} is left as a conjunction.  Proof by assumption,
  1673   @{text "A \<and> B"} is left as a conjunction.  Proof by assumption,
  1736   Modus Ponens, etc., may be performed provided they do not
  1674   Modus Ponens, etc., may be performed provided they do not
  1737   instantiate unknowns.  Assumptions of the form @{text "x = t"} may
  1675   instantiate unknowns.  Assumptions of the form @{text "x = t"} may
  1738   be eliminated.  The safe wrapper tactical is applied.
  1676   be eliminated.  The safe wrapper tactical is applied.
  1739 
       
  1740   \end{description}
       
  1741 \<close>
  1677 \<close>
  1742 
  1678 
  1743 
  1679 
  1744 subsection \<open>Modifying the search step\<close>
  1680 subsection \<open>Modifying the search step\<close>
  1745 
  1681 
  1788   modification of the step tactics. Safe and unsafe wrappers are added
  1724   modification of the step tactics. Safe and unsafe wrappers are added
  1789   to the context with the functions given below, supplying them with
  1725   to the context with the functions given below, supplying them with
  1790   wrapper names.  These names may be used to selectively delete
  1726   wrapper names.  These names may be used to selectively delete
  1791   wrappers.
  1727   wrappers.
  1792 
  1728 
  1793   \begin{description}
       
  1794 
       
  1795   \<^descr> @{text "ctxt addSWrapper (name, wrapper)"} adds a new wrapper,
  1729   \<^descr> @{text "ctxt addSWrapper (name, wrapper)"} adds a new wrapper,
  1796   which should yield a safe tactic, to modify the existing safe step
  1730   which should yield a safe tactic, to modify the existing safe step
  1797   tactic.
  1731   tactic.
  1798 
  1732 
  1799   \<^descr> @{text "ctxt addSbefore (name, tac)"} adds the given tactic as a
  1733   \<^descr> @{text "ctxt addSbefore (name, tac)"} adds the given tactic as a
  1826   rather safe way, after each safe step of the search.
  1760   rather safe way, after each safe step of the search.
  1827 
  1761 
  1828   \<^descr> @{text "addss"} adds the simpset of the context to its
  1762   \<^descr> @{text "addss"} adds the simpset of the context to its
  1829   classical set. The assumptions and goal will be simplified, before
  1763   classical set. The assumptions and goal will be simplified, before
  1830   the each unsafe step of the search.
  1764   the each unsafe step of the search.
  1831 
       
  1832   \end{description}
       
  1833 \<close>
  1765 \<close>
  1834 
  1766 
  1835 
  1767 
  1836 section \<open>Object-logic setup \label{sec:object-logic}\<close>
  1768 section \<open>Object-logic setup \label{sec:object-logic}\<close>
  1837 
  1769 
  1870     @@{attribute atomize} ('(' 'full' ')')?
  1802     @@{attribute atomize} ('(' 'full' ')')?
  1871     ;
  1803     ;
  1872     @@{attribute rule_format} ('(' 'noasm' ')')?
  1804     @@{attribute rule_format} ('(' 'noasm' ')')?
  1873   \<close>}
  1805   \<close>}
  1874 
  1806 
  1875   \begin{description}
       
  1876   
       
  1877   \<^descr> @{command "judgment"}~@{text "c :: \<sigma> (mx)"} declares constant
  1807   \<^descr> @{command "judgment"}~@{text "c :: \<sigma> (mx)"} declares constant
  1878   @{text c} as the truth judgment of the current object-logic.  Its
  1808   @{text c} as the truth judgment of the current object-logic.  Its
  1879   type @{text \<sigma>} should specify a coercion of the category of
  1809   type @{text \<sigma>} should specify a coercion of the category of
  1880   object-level propositions to @{text prop} of the Pure meta-logic;
  1810   object-level propositions to @{text prop} of the Pure meta-logic;
  1881   the mixfix annotation @{text "(mx)"} would typically just link the
  1811   the mixfix annotation @{text "(mx)"} would typically just link the
  1906 
  1836 
  1907   In common object-logics (HOL, FOL, ZF), the effect of @{attribute
  1837   In common object-logics (HOL, FOL, ZF), the effect of @{attribute
  1908   rule_format} is to replace (bounded) universal quantification
  1838   rule_format} is to replace (bounded) universal quantification
  1909   (@{text "\<forall>"}) and implication (@{text "\<longrightarrow>"}) by the corresponding
  1839   (@{text "\<forall>"}) and implication (@{text "\<longrightarrow>"}) by the corresponding
  1910   rule statements over @{text "\<And>"} and @{text "\<Longrightarrow>"}.
  1840   rule statements over @{text "\<And>"} and @{text "\<Longrightarrow>"}.
  1911 
       
  1912   \end{description}
       
  1913 \<close>
  1841 \<close>
  1914 
  1842 
  1915 
  1843 
  1916 section \<open>Tracing higher-order unification\<close>
  1844 section \<open>Tracing higher-order unification\<close>
  1917 
  1845 
  1926 
  1854 
  1927   Higher-order unification works well in most practical situations,
  1855   Higher-order unification works well in most practical situations,
  1928   but sometimes needs extra care to identify problems.  These tracing
  1856   but sometimes needs extra care to identify problems.  These tracing
  1929   options may help.
  1857   options may help.
  1930 
  1858 
  1931   \begin{description}
       
  1932 
       
  1933   \<^descr> @{attribute unify_trace_simp} controls tracing of the
  1859   \<^descr> @{attribute unify_trace_simp} controls tracing of the
  1934   simplification phase of higher-order unification.
  1860   simplification phase of higher-order unification.
  1935 
  1861 
  1936   \<^descr> @{attribute unify_trace_types} controls warnings of
  1862   \<^descr> @{attribute unify_trace_types} controls warnings of
  1937   incompleteness, when unification is not considering all possible
  1863   incompleteness, when unification is not considering all possible
  1947   unification cannot return an infinite sequence, though it can return
  1873   unification cannot return an infinite sequence, though it can return
  1948   an exponentially long one.  The search rarely approaches the default
  1874   an exponentially long one.  The search rarely approaches the default
  1949   value in practice.  If the search is cut off, unification prints a
  1875   value in practice.  If the search is cut off, unification prints a
  1950   warning ``Unification bound exceeded''.
  1876   warning ``Unification bound exceeded''.
  1951 
  1877 
  1952   \end{description}
       
  1953 
  1878 
  1954   \begin{warn}
  1879   \begin{warn}
  1955   Options for unification cannot be modified in a local context.  Only
  1880   Options for unification cannot be modified in a local context.  Only
  1956   the global theory content is taken into account.
  1881   the global theory content is taken into account.
  1957   \end{warn}
  1882   \end{warn}