src/Doc/Implementation/Isar.thy
changeset 57946 6a26aa5fa65e
parent 57342 1dc320dc2ada
child 58555 7975676c08c0
equal deleted inserted replaced
57945:cacb00a569e0 57946:6a26aa5fa65e
   434   assume b: "b = c"
   434   assume b: "b = c"
   435   have "a = c" and "c = b" by (my_simp_all a b)
   435   have "a = c" and "c = b" by (my_simp_all a b)
   436 end
   436 end
   437 
   437 
   438 text {* \medskip Apart from explicit arguments, common proof methods
   438 text {* \medskip Apart from explicit arguments, common proof methods
   439   typically work with a default configuration provided by the context.
   439   typically work with a default configuration provided by the context. As a
   440   As a shortcut to rule management we use a cheap solution via the
   440   shortcut to rule management we use a cheap solution via the @{command
   441   functor @{ML_functor Named_Thms} (see also @{file
   441   named_theorems} command to declare a dynamic fact in the context. *}
   442   "~~/src/Pure/Tools/named_thms.ML"}).  *}
   442 
   443 
   443 named_theorems my_simp
   444 ML {*
   444 
   445   structure My_Simps =
   445 text {* The proof method is now defined as before, but we append the
   446     Named_Thms(
   446   explicit arguments and the rules from the context. *}
   447       val name = @{binding my_simp}
       
   448       val description = "my_simp rule"
       
   449     )
       
   450 *}
       
   451 setup My_Simps.setup
       
   452 
       
   453 text {* This provides ML access to a list of theorems in canonical
       
   454   declaration order via @{ML My_Simps.get}.  The user can add or
       
   455   delete rules via the attribute @{attribute my_simp}.  The actual
       
   456   proof method is now defined as before, but we append the explicit
       
   457   arguments and the rules from the context.  *}
       
   458 
   447 
   459 method_setup my_simp' =
   448 method_setup my_simp' =
   460   \<open>Attrib.thms >> (fn thms => fn ctxt =>
   449   \<open>Attrib.thms >> (fn thms => fn ctxt =>
   461     SIMPLE_METHOD' (fn i =>
   450     let
   462       CHANGED (asm_full_simp_tac
   451       val my_simps = Named_Theorems.get ctxt @{named_theorems my_simp}
   463         (put_simpset HOL_basic_ss ctxt
   452     in
   464           addsimps (thms @ My_Simps.get ctxt)) i)))\<close>
   453       SIMPLE_METHOD' (fn i =>
       
   454         CHANGED (asm_full_simp_tac
       
   455           (put_simpset HOL_basic_ss ctxt
       
   456             addsimps (thms @ my_simps)) i))
       
   457     end)\<close>
   465   "rewrite subgoal by given rules and my_simp rules from the context"
   458   "rewrite subgoal by given rules and my_simp rules from the context"
   466 
   459 
   467 text {*
   460 text {*
   468   \medskip Method @{method my_simp'} can be used in Isar proofs
   461   \medskip Method @{method my_simp'} can be used in Isar proofs
   469   like this:
   462   like this:
   498   every invocation of the method.  This does not scale to really large
   491   every invocation of the method.  This does not scale to really large
   499   collections of rules, which easily emerges in the context of a big
   492   collections of rules, which easily emerges in the context of a big
   500   theory library, for example.
   493   theory library, for example.
   501 
   494 
   502   This is an inherent limitation of the simplistic rule management via
   495   This is an inherent limitation of the simplistic rule management via
   503   functor @{ML_functor Named_Thms}, because it lacks tool-specific
   496   @{command named_theorems}, because it lacks tool-specific
   504   storage and retrieval.  More realistic applications require
   497   storage and retrieval.  More realistic applications require
   505   efficient index-structures that organize theorems in a customized
   498   efficient index-structures that organize theorems in a customized
   506   manner, such as a discrimination net that is indexed by the
   499   manner, such as a discrimination net that is indexed by the
   507   left-hand sides of rewrite rules.  For variations on the Simplifier,
   500   left-hand sides of rewrite rules.  For variations on the Simplifier,
   508   re-use of the existing type @{ML_type simpset} is adequate, but
   501   re-use of the existing type @{ML_type simpset} is adequate, but