src/Provers/simplifier.ML
changeset 5886 0373323180f5
parent 5842 1a708aa63ff0
child 5928 6e00a206a948
equal deleted inserted replaced
5885:6c920d876098 5886:0373323180f5
   161     setloop tac =
   161     setloop tac =
   162   make_ss (mss, subgoal_tac, [("",tac)], finish_tac, unsafe_finish_tac);
   162   make_ss (mss, subgoal_tac, [("",tac)], finish_tac, unsafe_finish_tac);
   163 
   163 
   164 fun (Simpset {mss, subgoal_tac, loop_tacs, finish_tac, unsafe_finish_tac})
   164 fun (Simpset {mss, subgoal_tac, loop_tacs, finish_tac, unsafe_finish_tac})
   165     addloop tac = make_ss (mss, subgoal_tac, 
   165     addloop tac = make_ss (mss, subgoal_tac, 
   166 	(case assoc_string (loop_tacs,(fst tac)) of None => () | Some x => 
   166         (case assoc_string (loop_tacs,(fst tac)) of None => () | Some x => 
   167 	 warning ("overwriting looper "^fst tac); overwrite(loop_tacs,tac)),
   167          warning ("overwriting looper "^fst tac); overwrite(loop_tacs,tac)),
   168            finish_tac, unsafe_finish_tac);
   168            finish_tac, unsafe_finish_tac);
   169 
   169 
   170 fun (ss as Simpset {mss,subgoal_tac,loop_tacs,finish_tac,unsafe_finish_tac})
   170 fun (ss as Simpset {mss,subgoal_tac,loop_tacs,finish_tac,unsafe_finish_tac})
   171     delloop name =
   171     delloop name =
   172   let val (del,rest) = partition (fn (n,_) => n=name) loop_tacs
   172   let val (del,rest) = partition (fn (n,_) => n=name) loop_tacs
   243   make_ss
   243   make_ss
   244     (Thm.del_simprocs (mss, map rep_simproc simprocs),
   244     (Thm.del_simprocs (mss, map rep_simproc simprocs),
   245       subgoal_tac, loop_tacs, finish_tac, unsafe_finish_tac);
   245       subgoal_tac, loop_tacs, finish_tac, unsafe_finish_tac);
   246 
   246 
   247 
   247 
   248 (* merge simpsets *)	(*NOTE: ignores tactics of 2nd simpset (except loopers)*)
   248 (* merge simpsets *)    (*NOTE: ignores tactics of 2nd simpset (except loopers)*)
   249 
   249 
   250 fun merge_ss
   250 fun merge_ss
   251    (Simpset {mss = mss1, loop_tacs = loop_tacs1, subgoal_tac, finish_tac, unsafe_finish_tac},
   251    (Simpset {mss = mss1, loop_tacs = loop_tacs1, subgoal_tac, finish_tac, unsafe_finish_tac},
   252     Simpset {mss = mss2, loop_tacs = loop_tacs2, ...}) =
   252     Simpset {mss = mss2, loop_tacs = loop_tacs2, ...}) =
   253   make_ss (Thm.merge_mss (mss1, mss2), subgoal_tac,
   253   make_ss (Thm.merge_mss (mss1, mss2), subgoal_tac,
   263 struct
   263 struct
   264   val name = "Provers/simpset";
   264   val name = "Provers/simpset";
   265   type T = simpset ref;
   265   type T = simpset ref;
   266 
   266 
   267   val empty = ref empty_ss;
   267   val empty = ref empty_ss;
   268   fun prep_ext (ref ss) = (ref ss): T;		  (*create new reference!*)
   268   fun prep_ext (ref ss) = (ref ss): T;            (*create new reference!*)
   269   fun merge (ref ss1, ref ss2) = ref (merge_ss (ss1, ss2));
   269   fun merge (ref ss1, ref ss2) = ref (merge_ss (ss1, ss2));
   270   fun print _ (ref ss) = print_ss ss;
   270   fun print _ (ref ss) = print_ss ss;
   271 end;
   271 end;
   272 
   272 
   273 structure GlobalSimpset = TheoryDataFun(GlobalSimpsetArgs);
   273 structure GlobalSimpset = TheoryDataFun(GlobalSimpsetArgs);
   310 
   310 
   311 structure LocalSimpset = ProofDataFun(LocalSimpsetArgs);
   311 structure LocalSimpset = ProofDataFun(LocalSimpsetArgs);
   312 val print_local_simpset = LocalSimpset.print;
   312 val print_local_simpset = LocalSimpset.print;
   313 val get_local_simpset = LocalSimpset.get;
   313 val get_local_simpset = LocalSimpset.get;
   314 val put_local_simpset = LocalSimpset.put;
   314 val put_local_simpset = LocalSimpset.put;
       
   315 
       
   316 
       
   317 (* attributes *)
       
   318 
       
   319 fun change_global_ss f (thy, th) =
       
   320   let val r = simpset_ref_of thy
       
   321   in r := f (! r, [Attribute.thm_of th]); (thy, th) end;
       
   322 
       
   323 fun change_local_ss f (ctxt, th) =
       
   324   let val ss = f (get_local_simpset ctxt, [Attribute.thm_of th])
       
   325   in (put_local_simpset ss ctxt, th) end;
       
   326 
       
   327 val simp_add_global = change_global_ss (op addsimps);
       
   328 val simp_del_global = change_global_ss (op delsimps);
       
   329 val simp_add_local = change_local_ss (op addsimps);
       
   330 val simp_del_local = change_local_ss (op delsimps);
   315 
   331 
   316 
   332 
   317 
   333 
   318 (** simplification tactics **)
   334 (** simplification tactics **)
   319 
   335 
   380 val     full_rewrite = simp_cterm (true, false, false);
   396 val     full_rewrite = simp_cterm (true, false, false);
   381 val asm_full_rewrite = simp_cterm (true, true, false);
   397 val asm_full_rewrite = simp_cterm (true, true, false);
   382 
   398 
   383 
   399 
   384 
   400 
   385 (** attributes **)
   401 (** concrete syntax of attributes **)
   386 
   402 
   387 (* add / del rules *)
   403 (* add / del *)
   388 
   404 
   389 val simp_addN = "add";
   405 val simp_addN = "add";
   390 val simp_delN = "del";
   406 val simp_delN = "del";
   391 
   407 val simp_ignoreN = "other";
   392 val addsimps' = Attribute.lift_modifier (op addsimps);
   408 
   393 val delsimps' = Attribute.lift_modifier (op delsimps);
   409 fun simp_att change =
   394 
   410   (Args.$$$ simp_addN >> K (op addsimps) ||
   395 local
   411     Args.$$$ simp_delN >> K (op delsimps) ||
   396   fun change_global_ss f (thy, tth) =
   412     Scan.succeed (op addsimps))
   397     let val r = simpset_ref_of thy
   413   >> change
   398     in r := f (! r, [tth]); (thy, tth) end;
   414   |> Scan.lift
   399 
   415   |> Attrib.syntax;
   400   fun change_local_ss f (ctxt, tth) =
   416 
   401     let val ss = f (get_local_simpset ctxt, [tth])
   417 val simp_attr = (simp_att change_global_ss, simp_att change_local_ss);
   402     in (put_local_simpset ss ctxt, tth) end;
       
   403 
       
   404   fun simp_att change = Attrib.syntax
       
   405     (Args.$$$ simp_delN >> K delsimps' ||
       
   406       Args.$$$ simp_addN >> K addsimps' || Scan.succeed addsimps') change;
       
   407 in
       
   408   val simp_add_global = change_global_ss addsimps';
       
   409   val simp_del_global = change_global_ss delsimps';
       
   410   val simp_add_local = change_local_ss addsimps';
       
   411   val simp_del_local = change_local_ss delsimps';
       
   412   val simp_attr = (simp_att change_global_ss, simp_att change_local_ss);
       
   413 end;
       
   414 
   418 
   415 
   419 
   416 (* conversions *)
   420 (* conversions *)
   417 
   421 
   418 fun conv_attr f =
   422 fun conv_attr f =
   419   (Attrib.no_args (Attribute.rule simpset_of f),
   423   (Attrib.no_args (Attribute.rule (f o simpset_of)),
   420     Attrib.no_args (Attribute.rule get_local_simpset f));
   424     Attrib.no_args (Attribute.rule (f o get_local_simpset)));
   421 
   425 
   422 
   426 
   423 (* setup_attrs *)
   427 (* setup_attrs *)
   424 
   428 
   425 val setup_attrs = Attrib.add_attributes
   429 val setup_attrs = Attrib.add_attributes
   433 
   437 
   434 (** proof methods **)
   438 (** proof methods **)
   435 
   439 
   436 (* simplification *)
   440 (* simplification *)
   437 
   441 
   438 fun smart_simp_tac [] ss i = simp_tac ss i
   442 val simp_args =
   439   | smart_simp_tac facts ss i =
   443   Method.only_sectioned_args
   440       REPEAT_DETERM (etac Drule.thin_rl i) THEN
   444    [Args.$$$ simp_addN >> K simp_add_local,
   441       metacuts_tac (map Attribute.thm_of facts) i THEN
   445     Args.$$$ simp_delN >> K simp_del_local,
   442       asm_full_simp_tac ss i;
   446     Args.$$$ simp_ignoreN >> K I];
   443 
   447 
   444 fun smart_simp ss = Method.METHOD (fn facts => FIRSTGOAL (smart_simp_tac facts ss));
   448 fun simp_meth tac ctxt = Method.METHOD (fn facts =>
   445 
   449   FIRSTGOAL (REPEAT_DETERM o etac Drule.thin_rl THEN'
   446 
   450     metacuts_tac (Attribute.thms_of facts) THEN'
   447 (* simp methods *)	(* FIXME !? *)
   451     tac (get_local_simpset ctxt)));
   448 
   452 
   449 fun simp_args meth =
   453 val simp_method = simp_args o simp_meth;
   450   Method.sectioned_args get_local_simpset addsimps'
       
   451     [(simp_addN, addsimps'), (simp_delN, delsimps')] meth;
       
   452 
       
   453 fun gen_simp tac =
       
   454   let
       
   455     fun tac' x = FIRSTGOAL (CHANGED o tac x);
       
   456     fun meth ss = Method.METHOD (fn facts => tac' (addsimps' (ss, facts)));
       
   457   in simp_args meth end;
       
   458 
   454 
   459 
   455 
   460 (* setup_methods *)
   456 (* setup_methods *)
   461 
   457 
   462 val setup_methods = Method.add_methods
   458 val setup_methods = Method.add_methods
   463  [("simp",          simp_args smart_simp, "simplification"),
   459  [("simp",              simp_method asm_full_simp_tac, "simplification"),
   464   ("simp_tac",      gen_simp simp_tac, "simp_tac"),
   460   ("simp_tac",          simp_method simp_tac, "simp_tac"),
   465   ("asm_simp",      gen_simp asm_simp_tac, "asm_simp_tac"),
   461   ("asm_simp_tac",      simp_method asm_simp_tac, "asm_simp_tac"),
   466   ("full_simp",     gen_simp full_simp_tac, "full_simp_tac"),
   462   ("full_simp_tac",     simp_method full_simp_tac, "full_simp_tac"),
   467   ("asm_full_simp", gen_simp asm_full_simp_tac, "asm_full_simp_tac"),
   463   ("asm_full_simp_tac", simp_method asm_full_simp_tac, "asm_full_simp_tac"),
   468   ("asm_lr_simp",   gen_simp asm_lr_simp_tac, "asm_lr_simp_tac")];
   464   ("asm_lr_simp_tac",   simp_method asm_lr_simp_tac, "asm_lr_simp_tac")];
   469 
   465 
   470 
   466 
   471 
   467 
   472 (** theory setup **)
   468 (** theory setup **)
   473 
   469