src/HOL/Tools/meson.ML
changeset 14744 7ccfc167e451
parent 14733 3eda95792083
child 14763 c1fd297712ba
equal deleted inserted replaced
14743:81001d6cb8c0 14744:7ccfc167e451
   266 (*Convert a list of clauses to (contrapositive) Horn clauses*)
   266 (*Convert a list of clauses to (contrapositive) Horn clauses*)
   267 fun make_horns ths =
   267 fun make_horns ths =
   268     name_thms "Horn#"
   268     name_thms "Horn#"
   269       (gen_distinct Drule.eq_thm_prop (foldr (add_contras clause_rules) (ths,[])));
   269       (gen_distinct Drule.eq_thm_prop (foldr (add_contras clause_rules) (ths,[])));
   270 
   270 
   271 (*Convert a list of clauses to meta-level clauses, with no contrapositives,
       
   272   for ordinary resolution.*)
       
   273 fun make_meta_clauses ths =
       
   274     name_thms "MClause#"
       
   275       (gen_distinct Drule.eq_thm_prop
       
   276        (map (make_horn resolution_clause_rules) ths));
       
   277 
       
   278 (*Could simply use nprems_of, which would count remaining subgoals -- no
   271 (*Could simply use nprems_of, which would count remaining subgoals -- no
   279   discrimination as to their size!  With BEST_FIRST, fails for problem 41.*)
   272   discrimination as to their size!  With BEST_FIRST, fails for problem 41.*)
   280 
   273 
   281 fun best_prolog_tac sizef horns =
   274 fun best_prolog_tac sizef horns =
   282     BEST_FIRST (has_fewer_prems 1, sizef) (prolog_step_tac horns 1);
   275     BEST_FIRST (has_fewer_prems 1, sizef) (prolog_step_tac horns 1);
   346   SELECT_GOAL (TRY (safe_tac cs) THEN TRYALL iter_deepen_meson_tac);
   339   SELECT_GOAL (TRY (safe_tac cs) THEN TRYALL iter_deepen_meson_tac);
   347 
   340 
   348 val meson_tac = CLASET' meson_claset_tac;
   341 val meson_tac = CLASET' meson_claset_tac;
   349 
   342 
   350 
   343 
   351 (* proof method setup *)
   344 (** Code to support ordinary resolution, rather than Model Elimination **)
       
   345 
       
   346 (*Convert a list of clauses to meta-level clauses, with no contrapositives,
       
   347   for ordinary resolution.*)
       
   348 
       
   349 (*Rules to convert the head literal into a negated assumption. If the head
       
   350   literal is already negated, then using notEfalse instead of notEfalse'
       
   351   prevents a double negation.*)
       
   352 val notEfalse = read_instantiate [("R","False")] notE;
       
   353 val notEfalse' = rotate_prems 1 notEfalse;
       
   354 
       
   355 fun negate_nead th = 
       
   356     th RS notEfalse handle THM _ => th RS notEfalse';
       
   357 
       
   358 (*Converting one clause*)
       
   359 fun make_meta_clause th = negate_nead (make_horn resolution_clause_rules th);
       
   360 
       
   361 fun make_meta_clauses ths =
       
   362     name_thms "MClause#"
       
   363       (gen_distinct Drule.eq_thm_prop (map make_meta_clause ths));
       
   364 
       
   365 (*Permute a rule's premises to move the i-th premise to the last position.*)
       
   366 fun make_last i th =
       
   367   let val n = nprems_of th 
       
   368   in  if 1 <= i andalso i <= n 
       
   369       then Thm.permute_prems (i-1) 1 th
       
   370       else raise THM("make_last", i, [th])
       
   371   end;
       
   372 
       
   373 (*Maps a rule that ends "... ==> P ==> False" to "... ==> ~P" while suppressing
       
   374   double-negations.*)
       
   375 val negate_head = rewrite_rule [atomize_not, not_not RS eq_reflection];
       
   376 
       
   377 (*Maps the clause  [P1,...Pn]==>False to [P1,...,P(i-1),P(i+1),...Pn] ==> ~P*)
       
   378 fun select_literal i cl = negate_head (make_last i cl);
       
   379 
       
   380 
       
   381 
       
   382 (** proof method setup **)
   352 
   383 
   353 local
   384 local
   354 
   385 
   355 fun meson_meth ctxt =
   386 fun meson_meth ctxt =
   356   Method.SIMPLE_METHOD' HEADGOAL
   387   Method.SIMPLE_METHOD' HEADGOAL