src/HOL/Tools/meson.ML
changeset 18194 940515d2fa26
parent 18175 7858b777569a
child 18389 8352b1d3b639
equal deleted inserted replaced
18193:54419506df9e 18194:940515d2fa26
    34   val meson_tac		: int -> tactic
    34   val meson_tac		: int -> tactic
    35   val negate_head	: thm -> thm
    35   val negate_head	: thm -> thm
    36   val select_literal	: int -> thm -> thm
    36   val select_literal	: int -> thm -> thm
    37   val skolemize_tac	: int -> tactic
    37   val skolemize_tac	: int -> tactic
    38   val make_clauses_tac	: int -> tactic
    38   val make_clauses_tac	: int -> tactic
       
    39   val check_is_fol : thm -> thm
       
    40   val check_is_fol_term : term -> term
    39 end
    41 end
    40 
    42 
    41 
    43 
    42 structure Meson =
    44 structure Meson =
    43 struct
    45 struct
   250         has_bool_arg_const prop  orelse  
   252         has_bool_arg_const prop  orelse  
   251         has_meta_conn prop
   253         has_meta_conn prop
   252   then raise THM ("check_is_fol", 0, [th]) else th
   254   then raise THM ("check_is_fol", 0, [th]) else th
   253   end;
   255   end;
   254 
   256 
       
   257 fun check_is_fol_term term =
       
   258     if exists (has_bool o fastype_of) (term_vars term)  orelse
       
   259         not (Term.is_first_order ["all","All","Ex"] term) orelse
       
   260         has_bool_arg_const term  orelse  
       
   261         has_meta_conn term
       
   262     then raise TERM("check_is_fol_term",[term]) else term;
       
   263 
       
   264 
   255 (*Create a meta-level Horn clause*)
   265 (*Create a meta-level Horn clause*)
   256 fun make_horn crules th = make_horn crules (tryres(th,crules))
   266 fun make_horn crules th = make_horn crules (tryres(th,crules))
   257 			  handle THM _ => th;
   267 			  handle THM _ => th;
   258 
   268 
   259 (*Generate Horn clauses for all contrapositives of a clause. The input, th,
   269 (*Generate Horn clauses for all contrapositives of a clause. The input, th,
   337 val tag_False = thm "tag_False";
   347 val tag_False = thm "tag_False";
   338 val nnf_simps = [Ex1_def,Ball_def,Bex_def,tag_True,tag_False]
   348 val nnf_simps = [Ex1_def,Ball_def,Bex_def,tag_True,tag_False]
   339 val nnf_ss = HOL_basic_ss addsimps nnf_simps@simp_thms;
   349 val nnf_ss = HOL_basic_ss addsimps nnf_simps@simp_thms;
   340 
   350 
   341 fun make_nnf th = th |> simplify nnf_ss
   351 fun make_nnf th = th |> simplify nnf_ss
   342                      |> check_is_fol |> make_nnf1
   352                      |> make_nnf1
   343 
   353 
   344 (*Pull existential quantifiers to front. This accomplishes Skolemization for
   354 (*Pull existential quantifiers to front. This accomplishes Skolemization for
   345   clauses that arise from a subgoal.*)
   355   clauses that arise from a subgoal.*)
   346 fun skolemize th =
   356 fun skolemize th =
   347   if not (has_consts ["Ex"] (prop_of th)) then th
   357   if not (has_consts ["Ex"] (prop_of th)) then th
   488   expressed as a tactic (or Isar method).  Each assumption of the selected 
   498   expressed as a tactic (or Isar method).  Each assumption of the selected 
   489   goal is converted to NNF and then its existential quantifiers are pulled
   499   goal is converted to NNF and then its existential quantifiers are pulled
   490   to the front. Finally, all existential quantifiers are eliminated, 
   500   to the front. Finally, all existential quantifiers are eliminated, 
   491   leaving !!-quantified variables. Perhaps Safe_tac should follow, but it
   501   leaving !!-quantified variables. Perhaps Safe_tac should follow, but it
   492   might generate many subgoals.*)
   502   might generate many subgoals.*)
       
   503 
       
   504 
       
   505 
   493 val skolemize_tac = 
   506 val skolemize_tac = 
   494   SUBGOAL
   507   SUBGOAL
   495     (fn (prop,_) =>
   508     (fn (prop,_) =>
   496      let val ts = Logic.strip_assums_hyp prop
   509      let val ts = Logic.strip_assums_hyp prop
   497      in EVERY1 
   510      in EVERY1 
   498 	 [METAHYPS
   511 	 [METAHYPS
   499 	    (fn hyps => (cut_facts_tac (map (skolemize o make_nnf) hyps) 1
   512 	    (fn hyps => (cut_facts_tac (map (skolemize o make_nnf) hyps) 1
   500                          THEN REPEAT (etac exE 1))),
   513                          THEN REPEAT (etac exE 1))),
   501 	  REPEAT_DETERM_N (length ts) o (etac thin_rl)]
   514 	  REPEAT_DETERM_N (length ts) o (etac thin_rl)]
   502      end);
   515      end);
       
   516 
       
   517 
   503 
   518 
   504 (*Top-level conversion to meta-level clauses. Each clause has  
   519 (*Top-level conversion to meta-level clauses. Each clause has  
   505   leading !!-bound universal variables, to express generality. To get 
   520   leading !!-bound universal variables, to express generality. To get 
   506   disjunctions instead of meta-clauses, remove "make_meta_clauses" below.*)
   521   disjunctions instead of meta-clauses, remove "make_meta_clauses" below.*)
   507 val make_clauses_tac = 
   522 val make_clauses_tac =